/** * Open a JPEG image by filename. * @param file The file path to open. * @return A handle to the opened JPEG file, with the header decoded. * * This function opens the file indicated by the @p file parameter, and * attempts to decode it as a jpeg file. If this failes, NULL is returned. * Otherwise a valid handle to an open JPEG file is returned that can be used * by other Epeg calls. * * The @p file must be a pointer to a valid C string, NUL (0 byte) terminated * thats is a relative or absolute file path. If not results are not * determined. * * See also: epeg_memory_open(), epeg_close() */ EAPI Epeg_Image * epeg_file_open(const char *file) { Epeg_Image *im; im = calloc(1, sizeof(Epeg_Image)); if (!im) return NULL; im->in.file = strdup(file); if (!im->in.file) { free(im); return NULL; } im->in.f = fopen(im->in.file, "rb"); if (!im->in.f) { epeg_close(im); return NULL; } fstat(fileno(im->in.f), &(im->stat_info)); im->out.quality = 75; return _epeg_open_header(im); }
/** * Open a JPEG image stored in memory. * @param data A pointer to the memory containing the JPEG data. * @param size The size of the memory segment containing the JPEG. * @return A handle to the opened JPEG, with the header decoded. * * This function opens a JPEG file that is stored in memory pointed to by * @p data, and that is @p size bytes in size. If successful a valid handle * is returned, or on failure NULL is returned. * * See also: epeg_file_open(), epeg_close() */ Epeg_Image * epeg_memory_open(unsigned char *data, int size) { Epeg_Image *im; im = calloc(1, sizeof(Epeg_Image)); if (!im) return NULL; im->in.mem.data = (unsigned char **)data; im->in.mem.size = size; im->in.f = NULL; im->in.w = 0; im->in.h = 0; return _epeg_open_header(im); }