diff --git a/legacy/evas/configure.in b/legacy/evas/configure.in index 96ebf43a30..6876188652 100644 --- a/legacy/evas/configure.in +++ b/legacy/evas/configure.in @@ -613,6 +613,8 @@ if test "x$have_png" = "xyes"; then png_libs="-lpng -lz -lm" fi +AM_CONDITIONAL(BUILD_LOADER_PNG, test x$have_png = xyes) + ####################################### ## JPEG have_jpeg="no"; @@ -646,6 +648,8 @@ if test "x$have_jpeg" = "xyes"; then jpeg_libs="-ljpeg" fi +AM_CONDITIONAL(BUILD_LOADER_JPEG, test x$have_jpeg = xyes) + ####################################### ## EET AC_ARG_WITH(eet-config, [ --with-eet-config=EET_CONFIG use eet-config specified ], @@ -712,6 +716,8 @@ else AC_MSG_RESULT(no) fi +AM_CONDITIONAL(BUILD_LOADER_EET, test x$have_eet = xyes) + ####################################### ## EDB AC_ARG_WITH(edb-config, [ --with-edb-config=EDB_CONFIG use edb-config specified ], @@ -760,6 +766,8 @@ else AC_MSG_RESULT(no) fi +AM_CONDITIONAL(BUILD_LOADER_EDB, test x$have_edb = xyes) + ##################################################################### ## Cpu based optimizations @@ -1642,6 +1650,11 @@ src/modules/engines/gl_x11/Makefile src/modules/engines/cairo_common/Makefile src/modules/engines/cairo_x11/Makefile src/modules/engines/xrender_x11/Makefile +src/modules/loaders/Makefile +src/modules/loaders/edb/Makefile +src/modules/loaders/eet/Makefile +src/modules/loaders/jpeg/Makefile +src/modules/loaders/png/Makefile src/lib/include/Makefile proj/Makefile proj/win32_gdi/Makefile diff --git a/legacy/evas/src/lib/Evas.h b/legacy/evas/src/lib/Evas.h index f53fd55b0c..923074d895 100644 --- a/legacy/evas/src/lib/Evas.h +++ b/legacy/evas/src/lib/Evas.h @@ -36,6 +36,7 @@ typedef enum _Evas_Module_Type { EVAS_MODULE_TYPE_ENGINE, + EVAS_MODULE_TYPE_IMAGE_LOADER, EVAS_MODULE_TYPE_OBJECT } Evas_Module_Type; @@ -86,6 +87,12 @@ struct _Evas_Module_Engine int id; }; +typedef struct _Evas_Module_Image_Loader Evas_Module_Image_Loader; +struct _Evas_Module_Image_Loader +{ + int id; +}; + /* end of evas module api */ /**************************/ diff --git a/legacy/evas/src/lib/engines/common/evas_image_load.c b/legacy/evas/src/lib/engines/common/evas_image_load.c index f204a5c6c3..69bff34a9e 100644 --- a/legacy/evas/src/lib/engines/common/evas_image_load.c +++ b/legacy/evas/src/lib/engines/common/evas_image_load.c @@ -1,833 +1,19 @@ -#include "config.h" -#include "evas_options.h" - -#define SWAP32(x) (x) = ((((x) & 0x000000ff ) << 24) | (((x) & 0x0000ff00 ) << 8) | (((x) & 0x00ff0000 ) >> 8) | (((x) & 0xff000000 ) >> 24)) - -#ifdef BUILD_LOADER_PNG -#include -#include -#define PNG_BYTES_TO_CHECK 4 -#endif - -#ifdef BUILD_LOADER_JPEG -#include -#include -#include -#endif - -#ifdef BUILD_LOADER_EET -#include -#endif - -#ifdef BUILD_LOADER_EDB -#include -#include -#endif - -#ifdef BUILD_LOADER_TEMPLATE -#include -#endif - #include "evas_common.h" #include "evas_private.h" -#ifdef BUILD_LOADER_PNG -static int load_image_file_head_png(RGBA_Image *im, const char *file, const char *key); -static int -load_image_file_head_png(RGBA_Image *im, const char *file, const char *key) -{ - png_uint_32 w32, h32; - FILE *f; - png_structp png_ptr = NULL; - png_infop info_ptr = NULL; - int bit_depth, color_type, interlace_type; - unsigned char buf[PNG_BYTES_TO_CHECK]; - char hasa, hasg; +extern Evas_List *evas_modules; - if ((!file)) return -1; - hasa = 0; - hasg = 0; - f = fopen(file, "rb"); - if (!f) return -1; +static Evas_Image_Load_Func *evas_image_load_func = NULL; - /* if we havent read the header before, set the header data */ - fread(buf, 1, PNG_BYTES_TO_CHECK, f); - if (!png_check_sig(buf, PNG_BYTES_TO_CHECK)) - { - fclose(f); - return -1; - } - rewind(f); - png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (!png_ptr) - { - fclose(f); - return -1; - } - info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) - { - png_destroy_read_struct(&png_ptr, NULL, NULL); - fclose(f); - return -1; - } - if (setjmp(png_ptr->jmpbuf)) - { - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - fclose(f); - return -1; - } - png_init_io(png_ptr, f); - png_read_info(png_ptr, info_ptr); - png_get_IHDR(png_ptr, info_ptr, (png_uint_32 *) (&w32), - (png_uint_32 *) (&h32), &bit_depth, &color_type, - &interlace_type, NULL, NULL); - if (!im->image) - im->image = evas_common_image_surface_new(im); - if (!im->image) - { - png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL); - fclose(f); - return -1; - } - im->image->w = (int) w32; - im->image->h = (int) h32; - if (color_type == PNG_COLOR_TYPE_PALETTE) - { - png_set_expand(png_ptr); - if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) hasa = 1; - } - if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) hasa = 1; - if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - { - hasa = 1; - hasg = 1; - } - if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY) hasg = 1; - if (hasa) im->flags |= RGBA_IMAGE_HAS_ALPHA; - png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL); - fclose(f); - return 1; - key = 0; -} - -static int load_image_file_data_png(RGBA_Image *im, const char *file, const char *key); -static int -load_image_file_data_png(RGBA_Image *im, const char *file, const char *key) -{ - png_uint_32 w32, h32; - int w, h; - FILE *f; - png_structp png_ptr = NULL; - png_infop info_ptr = NULL; - int bit_depth, color_type, interlace_type; - unsigned char buf[PNG_BYTES_TO_CHECK]; - unsigned char **lines; - char hasa, hasg; - int i; - - if ((!file)) return -1; - hasa = 0; - hasg = 0; - f = fopen(file, "rb"); - if (!f) return -1; - - /* if we havent read the header before, set the header data */ - fread(buf, 1, PNG_BYTES_TO_CHECK, f); - if (!png_check_sig(buf, PNG_BYTES_TO_CHECK)) - { - fclose(f); - return -1; - } - rewind(f); - png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (!png_ptr) - { - fclose(f); - return -1; - } - info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) - { - png_destroy_read_struct(&png_ptr, NULL, NULL); - fclose(f); - return -1; - } - if (setjmp(png_ptr->jmpbuf)) - { - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - fclose(f); - return -1; - } - png_init_io(png_ptr, f); - png_read_info(png_ptr, info_ptr); - png_get_IHDR(png_ptr, info_ptr, (png_uint_32 *) (&w32), - (png_uint_32 *) (&h32), &bit_depth, &color_type, - &interlace_type, NULL, NULL); - im->image->w = (int) w32; - im->image->h = (int) h32; - if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_expand(png_ptr); - if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) hasa = 1; - if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - { - hasa = 1; - hasg = 1; - } - if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY) hasg = 1; - if (hasa) im->flags |= RGBA_IMAGE_HAS_ALPHA; - - w = im->image->w; - h = im->image->h; - if (hasa) png_set_expand(png_ptr); - /* we want ARGB */ -#ifdef WORDS_BIGENDIAN - png_set_swap_alpha(png_ptr); - png_set_filler(png_ptr, 0xff, PNG_FILLER_BEFORE); -#else - png_set_bgr(png_ptr); - png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); -#endif - /* 16bit color -> 8bit color */ - png_set_strip_16(png_ptr); - /* pack all pixels to byte boundaires */ - png_set_packing(png_ptr); - if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) png_set_expand(png_ptr); - evas_common_image_surface_alloc(im->image); - if (!im->image->data) - { - evas_common_image_surface_free(im->image); - png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL); - fclose(f); - return -1; - } - lines = (unsigned char **) alloca(h * sizeof(unsigned char *)); - - if (hasg) - { - png_set_gray_to_rgb(png_ptr); - if (png_get_bit_depth(png_ptr, info_ptr) < 8) - png_set_gray_1_2_4_to_8(png_ptr); - } - for (i = 0; i < h; i++) - lines[i] = ((unsigned char *)(im->image->data)) + (i * w * sizeof(DATA32)); - png_read_image(png_ptr, lines); - png_read_end(png_ptr, info_ptr); - png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL); - fclose(f); - return 1; - key = 0; -} -#endif - -#ifdef BUILD_LOADER_JPEG -struct _JPEG_error_mgr -{ - struct jpeg_error_mgr pub; - jmp_buf setjmp_buffer; -}; -typedef struct _JPEG_error_mgr *emptr; - -static void _JPEGFatalErrorHandler(j_common_ptr cinfo); -static void -_JPEGFatalErrorHandler(j_common_ptr cinfo) -{ - emptr errmgr; - - errmgr = (emptr) cinfo->err; - /* cinfo->err->output_message(cinfo);*/ - longjmp(errmgr->setjmp_buffer, 1); - return; -} - -static void _JPEGErrorHandler(j_common_ptr cinfo); -static void -_JPEGErrorHandler(j_common_ptr cinfo) -{ - emptr errmgr; - - errmgr = (emptr) cinfo->err; - /* cinfo->err->output_message(cinfo);*/ - /* longjmp(errmgr->setjmp_buffer, 1);*/ - return; -} - -static void _JPEGErrorHandler2(j_common_ptr cinfo, int msg_level); -static void -_JPEGErrorHandler2(j_common_ptr cinfo, int msg_level) -{ - emptr errmgr; - - errmgr = (emptr) cinfo->err; - /* cinfo->err->output_message(cinfo);*/ - /* longjmp(errmgr->setjmp_buffer, 1);*/ - return; - msg_level = 0; -} - -static int load_image_file_head_jpeg_internal(RGBA_Image *im, FILE *f); -static int -load_image_file_head_jpeg_internal(RGBA_Image *im, FILE *f) -{ - int w, h; - struct jpeg_decompress_struct cinfo; - struct _JPEG_error_mgr jerr; - - if (!f) return -1; - cinfo.err = jpeg_std_error(&(jerr.pub)); - jerr.pub.error_exit = _JPEGFatalErrorHandler; - jerr.pub.emit_message = _JPEGErrorHandler2; - jerr.pub.output_message = _JPEGErrorHandler; - if (setjmp(jerr.setjmp_buffer)) - { - jpeg_destroy_decompress(&cinfo); - return -1; - } - jpeg_create_decompress(&cinfo); - jpeg_stdio_src(&cinfo, f); - jpeg_read_header(&cinfo, TRUE); - cinfo.do_fancy_upsampling = FALSE; - cinfo.do_block_smoothing = FALSE; - jpeg_start_decompress(&cinfo); - -/* head decoding */ - if (!im->image) - im->image = evas_common_image_surface_new(im); - if (!im->image) - { - jpeg_destroy_decompress(&cinfo); - return -1; - } - im->image->w = w = cinfo.output_width; - im->image->h = h = cinfo.output_height; -/* end head decoding */ - - jpeg_destroy_decompress(&cinfo); - return 1; -} - -static int load_image_file_data_jpeg_internal(RGBA_Image *im, FILE *f); -static int -load_image_file_data_jpeg_internal(RGBA_Image *im, FILE *f) -{ - int w, h; - struct jpeg_decompress_struct cinfo; - struct _JPEG_error_mgr jerr; - DATA8 *ptr, *line[16], *data; - DATA32 *ptr2; - int x, y, l, i, scans, count, prevy; - - if (!f) return -1; - cinfo.err = jpeg_std_error(&(jerr.pub)); - jerr.pub.error_exit = _JPEGFatalErrorHandler; - jerr.pub.emit_message = _JPEGErrorHandler2; - jerr.pub.output_message = _JPEGErrorHandler; - if (setjmp(jerr.setjmp_buffer)) - { - jpeg_destroy_decompress(&cinfo); - return -1; - } - jpeg_create_decompress(&cinfo); - jpeg_stdio_src(&cinfo, f); - jpeg_read_header(&cinfo, TRUE); - cinfo.do_fancy_upsampling = FALSE; - cinfo.do_block_smoothing = FALSE; - jpeg_start_decompress(&cinfo); - -/* head decoding */ - im->image->w = w = cinfo.output_width; - im->image->h = h = cinfo.output_height; -/* end head decoding */ -/* data decoding */ - if (cinfo.rec_outbuf_height > 16) - { - jpeg_destroy_decompress(&cinfo); - return -1; - } - data = alloca(w * 16 * 3); - evas_common_image_surface_alloc(im->image); - if (!im->image->data) - { - jpeg_destroy_decompress(&cinfo); - return -1; - } - ptr2 = im->image->data; - count = 0; - prevy = 0; - if (cinfo.output_components == 3) - { - for (i = 0; i < cinfo.rec_outbuf_height; i++) - line[i] = data + (i * w * 3); - for (l = 0; l < h; l += cinfo.rec_outbuf_height) - { - jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); - scans = cinfo.rec_outbuf_height; - if ((h - l) < scans) scans = h - l; - ptr = data; - for (y = 0; y < scans; y++) - { - for (x = 0; x < w; x++) - { - *ptr2 = - (0xff000000) | ((ptr[0]) << 16) | ((ptr[1]) << 8) | (ptr[2]); - ptr += 3; - ptr2++; - } - } - } - } - else if (cinfo.output_components == 1) - { - for (i = 0; i < cinfo.rec_outbuf_height; i++) - line[i] = data + (i * w); - for (l = 0; l < h; l += cinfo.rec_outbuf_height) - { - jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); - scans = cinfo.rec_outbuf_height; - if ((h - l) < scans) scans = h - l; - ptr = data; - for (y = 0; y < scans; y++) - { - for (x = 0; x < w; x++) - { - *ptr2 = - (0xff000000) | ((ptr[0]) << 16) | ((ptr[0]) << 8) | (ptr[0]); - ptr++; - ptr2++; - } - } - } - } -/* end data decoding */ - jpeg_finish_decompress(&cinfo); - jpeg_destroy_decompress(&cinfo); - return 1; -} - -#if 0 /* not used at the moment */ -static int load_image_file_data_jpeg_alpha_internal(RGBA_Image *im, FILE *f); -static int -load_image_file_data_jpeg_alpha_internal(RGBA_Image *im, FILE *f) -{ - int w, h; - struct jpeg_decompress_struct cinfo; - struct _JPEG_error_mgr jerr; - DATA8 *ptr, *line[16], *data; - DATA32 *ptr2; - int x, y, l, i, scans, count, prevy; - - if (!f) return -1; - cinfo.err = jpeg_std_error(&(jerr.pub)); - jerr.pub.error_exit = _JPEGFatalErrorHandler; - jerr.pub.emit_message = _JPEGErrorHandler2; - jerr.pub.output_message = _JPEGErrorHandler; - if (setjmp(jerr.setjmp_buffer)) - { - jpeg_destroy_decompress(&cinfo); - return -1; - } - jpeg_create_decompress(&cinfo); - jpeg_stdio_src(&cinfo, f); - jpeg_read_header(&cinfo, TRUE); - cinfo.do_fancy_upsampling = FALSE; - cinfo.do_block_smoothing = FALSE; - jpeg_start_decompress(&cinfo); - -/* head decoding */ - im->image->w = w = cinfo.output_width; - im->image->h = h = cinfo.output_height; -/* end head decoding */ -/* data decoding */ - if (cinfo.rec_outbuf_height > 16) - { - jpeg_destroy_decompress(&cinfo); - return -1; - } - data = alloca(w * 16 * 3); - if (!im->image->data) - { - jpeg_destroy_decompress(&cinfo); - return -1; - } - ptr2 = im->image->data; - count = 0; - prevy = 0; - if (cinfo.output_components == 3) - { - for (i = 0; i < cinfo.rec_outbuf_height; i++) - line[i] = data + (i * w * 3); - for (l = 0; l < h; l += cinfo.rec_outbuf_height) - { - jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); - scans = cinfo.rec_outbuf_height; - if ((h - l) < scans) scans = h - l; - ptr = data; - for (y = 0; y < scans; y++) - { - for (x = 0; x < w; x++) - { - *ptr2 = - ((*ptr2) & 0x00ffffff) | - (((ptr[0] + ptr[1] + ptr[2]) / 3) << 24); - ptr += 3; - ptr2++; - } - } - } - } - else if (cinfo.output_components == 1) - { - for (i = 0; i < cinfo.rec_outbuf_height; i++) - line[i] = data + (i * w); - for (l = 0; l < h; l += cinfo.rec_outbuf_height) - { - jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); - scans = cinfo.rec_outbuf_height; - if ((h - l) < scans) scans = h - l; - ptr = data; - for (y = 0; y < scans; y++) - { - for (x = 0; x < w; x++) - { - *ptr2 = - ((*ptr2) & 0x00ffffff) | - ((ptr[0]) << 24); - ptr++; - ptr2++; - } - } - } - } -/* end data decoding */ - jpeg_finish_decompress(&cinfo); - jpeg_destroy_decompress(&cinfo); - return 1; -} -#endif - -static int load_image_file_head_jpeg(RGBA_Image *im, const char *file, const char *key); -static int -load_image_file_head_jpeg(RGBA_Image *im, const char *file, const char *key) -{ - int val; - FILE *f; - - if ((!file)) return -1; - f = fopen(file, "rb"); - if (!f) return -1; - val = load_image_file_head_jpeg_internal(im, f); - fclose(f); - return val; - key = 0; -} - -static int load_image_file_data_jpeg(RGBA_Image *im, const char *file, const char *key); -static int -load_image_file_data_jpeg(RGBA_Image *im, const char *file, const char *key) -{ - int val; - FILE *f; - - if ((!file)) return -1; - f = fopen(file, "rb"); - if (!f) return -1; - val = load_image_file_data_jpeg_internal(im, f); - fclose(f); - return val; - key = 0; -} -#endif - -#ifdef BUILD_LOADER_EET -static int load_image_file_head_eet(RGBA_Image *im, const char *file, const char *key); -static int -load_image_file_head_eet(RGBA_Image *im, const char *file, const char *key) -{ - int alpha, compression, quality, lossy; - unsigned int w, h; - Eet_File *ef; - int ok; - - if ((!file) || (!key)) return -1; - ef = eet_open((char *)file, EET_FILE_MODE_READ); - if (!ef) return -1; - ok = eet_data_image_header_read(ef, (char *)key, - &w, &h, &alpha, &compression, &quality, &lossy); - if (!ok) - { - eet_close(ef); - return -1; - } - if ((w > 8192) || (h > 8192)) - { - eet_close(ef); - return -1; - } - if (alpha) im->flags |= RGBA_IMAGE_HAS_ALPHA; - if (!im->image) - im->image = evas_common_image_surface_new(im); - if (!im->image) - { - eet_close(ef); - return -1; - } - im->image->w = w; - im->image->h = h; - eet_close(ef); - return 1; -} - -static int load_image_file_data_eet(RGBA_Image *im, const char *file, const char *key); -static int -load_image_file_data_eet(RGBA_Image *im, const char *file, const char *key) -{ - unsigned int w, h; - int alpha, compression, quality, lossy; - Eet_File *ef; - DATA32 *body; - - if ((!file) || (!key)) return -1; - if ((im->image) && (im->image->data)) return 1; - ef = eet_open((char *)file, EET_FILE_MODE_READ); - if (!ef) return -1; - body = eet_data_image_read(ef, (char *)key, - &w, &h, &alpha, &compression, &quality, &lossy); - if (!body) - { - eet_close(ef); - return -1; - } - if ((w > 8192) || (h > 8192)) - { - free(body); - eet_close(ef); - return -1; - } - if (alpha) im->flags |= RGBA_IMAGE_HAS_ALPHA; - if (!im->image) - im->image = evas_common_image_surface_new(im); - if (!im->image) - { - free(body); - eet_close(ef); - return -1; - } - im->image->w = w; - im->image->h = h; - im->image->data = body; - im->image->no_free = 0; - eet_close(ef); - return 1; -} -#endif - -#ifdef BUILD_LOADER_EDB -static int load_image_file_head_edb(RGBA_Image *im, const char *file, const char *key); -static int -load_image_file_head_edb(RGBA_Image *im, const char *file, const char *key) -{ - int w, h, alpha, compression, size; - E_DB_File *db; - DATA32 *ret; - DATA32 header[8]; - - if ((!file) || (!key)) return -1; - db = e_db_open_read((char *)file); - if (!db) return -1; - ret = e_db_data_get(db, (char *)key, &size); - if (!ret) - { - e_db_close(db); - return -1; - } - if (size < 32) - { - free(ret); - e_db_close(db); - return -1; - } - memcpy(header, ret, 32); -#ifdef WORDS_BIGENDIAN - { - int i; - - for (i = 0; i < 8; i++) SWAP32(header[i]); - } -#endif - if (header[0] != 0xac1dfeed) - { - free(ret); - e_db_close(db); - return -1; - } - w = header[1]; - h = header[2]; - alpha = header[3]; - compression = header[4]; - if ((w > 8192) || (h > 8192)) - { - free(ret); - e_db_close(db); - return -1; - } - if ((compression == 0) && (size < ((w * h * 4) + 32))) - { - free(ret); - e_db_close(db); - return -1; - } - if (alpha) im->flags |= RGBA_IMAGE_HAS_ALPHA; - if (!im->image) - im->image = evas_common_image_surface_new(im); - if (!im->image) - { - free(ret); - e_db_close(db); - return -1; - } - im->image->w = w; - im->image->h = h; - free(ret); - e_db_close(db); - return 1; -} - -static int load_image_file_data_edb(RGBA_Image *im, const char *file, const char *key); -static int -load_image_file_data_edb(RGBA_Image *im, const char *file, const char *key) -{ - int w, h, alpha, compression, size; - E_DB_File *db; - DATA32 *ret; - DATA32 *body; - DATA32 header[8]; - - if ((!file) || (!key)) return -1; - db = e_db_open_read((char *)file); - if (!db) return -1; - ret = e_db_data_get(db, (char *)key, &size); - if (!ret) - { - e_db_close(db); - return -1; - } - if (size < 32) - { - free(ret); - e_db_close(db); - return -1; - } - memcpy(header, ret, 32); -#ifdef WORDS_BIGENDIAN - { - int i; - - for (i = 0; i < 8; i++) SWAP32(header[i]); - } -#endif - if (header[0] != 0xac1dfeed) - { - free(ret); - e_db_close(db); - return -1; - } - w = header[1]; - h = header[2]; - alpha = header[3]; - compression = header[4]; - if ((w > 8192) || (h > 8192)) - { - free(ret); - e_db_close(db); - return -1; - } - if ((compression == 0) && (size < ((w * h * 4) + 32))) - { - free(ret); - e_db_close(db); - return -1; - } - if (alpha) im->flags |= RGBA_IMAGE_HAS_ALPHA; - if (!im->image) - im->image = evas_common_image_surface_new(im); - if (!im->image) - { - free(ret); - e_db_close(db); - return -1; - } - im->image->w = w; - im->image->h = h; - body = &(ret[8]); - evas_common_image_surface_alloc(im->image); - if (!im->image->data) - { - free(ret); - e_db_close(db); - return -1; - } - if (!compression) - { -#ifdef WORDS_BIGENDIAN - { - int x; - - memcpy(im->image->data, body, w * h * sizeof(DATA32)); - for (x = 0; x < (w * h); x++) SWAP32(im->image->data[x]); - } -#else - memcpy(im->image->data, body, w * h * sizeof(DATA32)); -#endif - } - else - { - uLongf dlen; - - dlen = w * h * sizeof(DATA32); - uncompress((Bytef *)im->image->data, &dlen, (Bytef *)body, - (uLongf)(size - 32)); -#ifdef WORDS_BIGENDIAN - { - int x; - - for (x = 0; x < (w * h); x++) SWAP32(im->image->data[x]); - } -#endif - } - free(ret); - e_db_close(db); - return 1; -} -#endif - -#ifdef BUILD_LOADER_TEMPLATE -static int load_image_file_head_template(RGBA_Image *im, const char *file, const char *key); -static int -load_image_file_head_template(RGBA_Image *im, const char *file, const char *key) -{ - return -1; -} - -static int load_image_file_data_template(RGBA_Image *im, const char *file, const char *key); -static int -load_image_file_data_template(RGBA_Image *im, const char *file, const char *key) -{ - return -1; -} -#endif +static int evas_common_load_image_lookup(const char *name); RGBA_Image * evas_common_load_image_from_file(const char *file, const char *key) { -// char *real_file; + Evas_List *l; RGBA_Image *im; - int ok; char *p; -// DATA64 mod_time; - -// real_file = evas_file_path_resolve(file); -// mod_time = 0; -// if (real_file) mod_time = evas_file_modified_time(real_file); -// else if (file) mod_time = evas_file_modified_time(file); + char *loader = NULL; if (file == NULL) return NULL; @@ -835,115 +21,69 @@ evas_common_load_image_from_file(const char *file, const char *key) im = evas_common_image_find(file, key, 0); if (im) { -// printf("CACHED %s %s found\n", file, key); evas_common_image_ref(im); -// if (real_file) free(real_file); return im; } -// printf("LOAD IMAGE %s %s\n", file, key); im = evas_common_image_new(); if (!im) { -// if (real_file) free(real_file); return NULL; } - ok = -1; + + p = strrchr(file, '.'); + if (p) { - p = strrchr(file, '.'); - if (p) - { - p++; + p++; #ifdef BUILD_LOADER_PNG - if (ok == -1) - { - if (!strcasecmp(p, "png")) - { - ok = load_image_file_head_png(im, file, key); - if (ok != -1) im->info.format = 1; - } - } + if (!strcasecmp(p, "png")) + loader = "png"; #endif #ifdef BUILD_LOADER_JPEG - if (ok == -1) - { - if ((!strcasecmp(p, "jpg")) || - (!strcasecmp(p, "jpeg")) || - (!strcasecmp(p, "jfif"))) - { - ok = load_image_file_head_jpeg(im, file, key); - if (ok != -1) im->info.format = 2; - } - } + if ((!strcasecmp(p, "jpg")) || + (!strcasecmp(p, "jpeg")) || + (!strcasecmp(p, "jfif"))) + loader = "jpeg"; #endif #ifdef BUILD_LOADER_EET - if (ok == -1) - { - if (!strcasecmp(p, "eet")) - { - ok = load_image_file_head_eet(im, file, key); - if (ok != -1) im->info.format = 3; - } - } + if (!strcasecmp(p, "eet")) + loader = "eet"; #endif #ifdef BUILD_LOADER_EDB - if (ok == -1) - { - if (!strcasecmp(p, "edb")) - { - ok = load_image_file_head_edb(im, file, key); - if (ok != -1) im->info.format = 4; - } - } + if (!strcasecmp(p, "edb")) + loader = "edb"; #endif - } } -#ifdef BUILD_LOADER_PNG - if (ok == -1) + if (!loader) + return NULL; + + for (l = evas_modules; l; l = l->next) { - ok = load_image_file_head_png(im, file, key); - if (ok != -1) im->info.format = 1; + Evas_Module *em; + Evas_Module_Image_Loader *emil; + + em = l->data; + if (em->type != EVAS_MODULE_TYPE_IMAGE_LOADER) continue; + if (!em->data) continue; + emil = (Evas_Module_Image_Loader *)em->data; + if (emil->id != evas_common_load_image_lookup(loader)) continue; + if (!evas_module_load(em)) return NULL; + evas_image_load_func = em->functions; + goto beach; } -#endif -#ifdef BUILD_LOADER_JPEG - if (ok == -1) + return NULL; + + beach: + if (!evas_image_load_func->file_head(im, file, key)) { - ok = load_image_file_head_jpeg(im, file, key); - if (ok != -1) im->info.format = 2; + evas_common_image_free(im); + return NULL; } -#endif -#ifdef BUILD_LOADER_EET - if (ok == -1) - { - ok = load_image_file_head_eet(im, file, key); - if (ok != -1) im->info.format = 3; - } -#endif -#ifdef BUILD_LOADER_EDB - if (ok == -1) - { - ok = load_image_file_head_edb(im, file, key); - if (ok != -1) im->info.format = 4; - } -#endif - if (ok == -1) - { - evas_common_image_free(im); -// if (real_file) free(real_file); - return NULL; - } -// im->timestamp = mod_time; - if (file) - { - im->info.file = evas_stringshare_add(file); -// im->info.real_file = real_file; - } - else - { -// if (real_file) free(real_file); - } - if (key) im->info.key = evas_stringshare_add(key); + + im->info.file = (char *)evas_stringshare_add(file); + + if (key) im->info.key = (char *)evas_stringshare_add(key); evas_common_image_ref(im); return im; } @@ -951,27 +91,9 @@ evas_common_load_image_from_file(const char *file, const char *key) void evas_common_load_image_data_from_file(RGBA_Image *im) { - int ok; - if (im->image->data) return; - ok = -1; -#ifdef BUILD_LOADER_PNG - if (im->info.format == 1) - ok = load_image_file_data_png(im, im->info.file, im->info.key); -#endif -#ifdef BUILD_LOADER_JPEG - if (im->info.format == 2) - ok = load_image_file_data_jpeg(im, im->info.file, im->info.key); -#endif -#ifdef BUILD_LOADER_EET - if (im->info.format == 3) - ok = load_image_file_data_eet(im, im->info.file, im->info.key); -#endif -#ifdef BUILD_LOADER_EDB - if (im->info.format == 4) - ok = load_image_file_data_edb(im, im->info.file, im->info.key); -#endif - if (ok == -1) + + if (!evas_image_load_func->file_data(im, im->info.file, im->info.key)) { evas_common_image_surface_alloc(im->image); if (!im->image->data) @@ -985,3 +107,27 @@ evas_common_load_image_data_from_file(RGBA_Image *im) } } } + +static int +evas_common_load_image_lookup(const char *name) +{ + static int i = 1; + Evas_Module *em; + Evas_Module_Image_Loader *emil; + + if (!name) return RENDER_METHOD_INVALID; + /* search on the engines list for the name */ + em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, name); + + if(!em) return RENDER_METHOD_INVALID; + + emil = (Evas_Module_Image_Loader *)em->data; + if(!emil) + { + emil = (Evas_Module_Image_Loader *)malloc(sizeof(Evas_Module_Image_Loader)); + em->data = emil; + emil->id = i; + i++; + } + return emil->id; +} diff --git a/legacy/evas/src/lib/file/evas_module.c b/legacy/evas/src/lib/file/evas_module.c index c43e2dd76c..a337f45075 100644 --- a/legacy/evas/src/lib/file/evas_module.c +++ b/legacy/evas/src/lib/file/evas_module.c @@ -10,8 +10,8 @@ # endif #endif -#include // DIR, dirent -#include // dlopen,dlclose,etc +#include /* DIR, dirent */ +#include /* dlopen,dlclose,etc */ #include #include @@ -110,6 +110,7 @@ evas_module_paths_init(void) /* do this on a separate function */ /* 1. engines */ _evas_module_path_append(EVAS_MODULE_TYPE_ENGINE, paths->data, "engines"); + _evas_module_path_append(EVAS_MODULE_TYPE_IMAGE_LOADER, paths->data, "loaders"); _evas_module_path_append(EVAS_MODULE_TYPE_OBJECT, paths->data, "objects"); free(paths->data); paths = evas_list_remove_list(paths, paths); @@ -122,9 +123,10 @@ void evas_module_init(void) { Evas_List *l; - int new_id = 1; + int new_id_engine = 1; + int new_id_loader = 1; -// printf("[init modules]\n"); + /* printf("[init modules]\n"); */ evas_module_paths_init(); for (l = evas_module_paths; l; l = l->next) { @@ -135,7 +137,7 @@ evas_module_init(void) mp = l->data; if (!(dir = opendir(mp->path))) break; -// printf("[evas module] searching modules on %s\n", mp->path); + /* printf("[evas module] searching modules on %s\n", mp->path); */ while ((de = readdir(dir))) { char *buf; @@ -162,12 +164,24 @@ evas_module_init(void) eme = malloc(sizeof(Evas_Module_Engine)); if (eme) { - eme->id = new_id; + eme->id = new_id_engine; em->data = eme; - new_id++; + new_id_engine++; } } -// printf("[evas module] including module path %s/%s of type %d\n",em->path, em->name, em->type); + else if (em->type == EVAS_MODULE_TYPE_IMAGE_LOADER) + { + Evas_Module_Image_Loader *emil; + + emil = malloc(sizeof(Evas_Module_Image_Loader)); + if (emil) + { + emil->id = new_id_loader; + em->data = emil; + new_id_loader++; + } + } + /* printf("[evas module] including module path %s/%s of type %d\n",em->path, em->name, em->type); */ evas_modules = evas_list_append(evas_modules, em); } free(buf); diff --git a/legacy/evas/src/lib/include/evas_private.h b/legacy/evas/src/lib/include/evas_private.h index be0742794a..4609408f54 100644 --- a/legacy/evas/src/lib/include/evas_private.h +++ b/legacy/evas/src/lib/include/evas_private.h @@ -19,6 +19,7 @@ typedef struct _Evas_Font_Alias Evas_Font_Alias; typedef struct _Evas_Data_Node Evas_Data_Node; typedef struct _Evas_Func_Node Evas_Func_Node; typedef struct _Evas_Func Evas_Func; +typedef struct _Evas_Image_Load_Func Evas_Image_Load_Func; typedef struct _Evas_Object_Func Evas_Object_Func; typedef struct _Evas_Intercept_Func Evas_Intercept_Func; typedef struct _Evas_Intercept_Func_Basic Evas_Intercept_Func_Basic; @@ -524,9 +525,17 @@ struct _Evas_Func void (*font_cache_set) (void *data, int bytes); int (*font_cache_get) (void *data); +/* void (*image_rotation_set) (void *data, void *image); */ + /* Engine functions will over time expand from here */ }; +struct _Evas_Image_Load_Func +{ + int (*file_head) (RGBA_Image *im, const char *file, const char *key); + int (*file_data) (RGBA_Image *im, const char *file, const char *key); +}; + #ifdef __cplusplus extern "C" { #endif diff --git a/legacy/evas/src/modules/Makefile.am b/legacy/evas/src/modules/Makefile.am index 87cbd60410..133def93c1 100644 --- a/legacy/evas/src/modules/Makefile.am +++ b/legacy/evas/src/modules/Makefile.am @@ -1,3 +1,3 @@ MAINTAINERCLEANFILES = Makefile.in -SUBDIRS = engines +SUBDIRS = engines loaders diff --git a/legacy/evas/src/modules/loaders/Makefile.am b/legacy/evas/src/modules/loaders/Makefile.am new file mode 100644 index 0000000000..50fe0a0701 --- /dev/null +++ b/legacy/evas/src/modules/loaders/Makefile.am @@ -0,0 +1,19 @@ +MAINTAINERCLEANFILES = Makefile.in + +if BUILD_LOADER_EDB +edb_subdir = edb +endif + +if BUILD_LOADER_EET +eet_subdir = eet +endif + +if BUILD_LOADER_JPEG +jpeg_subdir = jpeg +endif + +if BUILD_LOADER_PNG +png_subdir = png +endif + +SUBDIRS = $(edb_subdir) $(eet_subdir) $(jpeg_subdir) $(png_subdir) diff --git a/legacy/evas/src/modules/loaders/edb/Makefile.am b/legacy/evas/src/modules/loaders/edb/Makefile.am new file mode 100644 index 0000000000..4937b46c3f --- /dev/null +++ b/legacy/evas/src/modules/loaders/edb/Makefile.am @@ -0,0 +1,24 @@ +## Process this file with automake to produce Makefile.in + +AUTOMAKE_OPTIONS = 1.4 foreign + +# A list of all the files in the current directory which can be regenerated +MAINTAINERCLEANFILES = Makefile.in + +INCLUDES = -I. \ + -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib/include \ + @FREETYPE_CFLAGS@ @edb_cflags@ + +pkgdir = $(libdir)/evas/modules/loaders/edb/$(MODULE_ARCH) + +pkg_LTLIBRARIES = module.la + +module_la_SOURCES = evas_image_load_edb.c + +module_la_LIBADD = +module_la_LDFLAGS = -module -avoid-version -L$(top_builddir)/src/lib -L$(top_builddir)/src/lib/.libs + +module_la_DEPENDENCIES = $(top_builddir)/config.h + +EXTRA_DIST = evas_image_load_edb.c diff --git a/legacy/evas/src/modules/loaders/edb/evas_image_load_edb.c b/legacy/evas/src/modules/loaders/edb/evas_image_load_edb.c new file mode 100644 index 0000000000..78b932793e --- /dev/null +++ b/legacy/evas/src/modules/loaders/edb/evas_image_load_edb.c @@ -0,0 +1,214 @@ +#include +#include + +#include "evas_common.h" +#include "evas_private.h" + + +#define SWAP32(x) (x) = ((((x) & 0x000000ff ) << 24) | (((x) & 0x0000ff00 ) << 8) | (((x) & 0x00ff0000 ) >> 8) | (((x) & 0xff000000 ) >> 24)) + + +int evas_image_load_file_head_edb(RGBA_Image *im, const char *file, const char *key); +int evas_image_load_file_data_edb(RGBA_Image *im, const char *file, const char *key); + +Evas_Image_Load_Func evas_image_load_edb_func = +{ + evas_image_load_file_head_edb, + evas_image_load_file_data_edb +}; + + +int +evas_image_load_file_head_edb(RGBA_Image *im, const char *file, const char *key) +{ + int w, h, alpha, compression, size; + E_DB_File *db; + DATA32 *ret; + DATA32 header[8]; + + if ((!file) || (!key)) return 0; + db = e_db_open_read((char *)file); + if (!db) return 0; + ret = e_db_data_get(db, (char *)key, &size); + if (!ret) + { + e_db_close(db); + return 0; + } + if (size < 32) + { + free(ret); + e_db_close(db); + return 0; + } + memcpy(header, ret, 32); +#ifdef WORDS_BIGENDIAN + { + int i; + + for (i = 0; i < 8; i++) SWAP32(header[i]); + } +#endif + if (header[0] != 0xac1dfeed) + { + free(ret); + e_db_close(db); + return 0; + } + w = header[1]; + h = header[2]; + alpha = header[3]; + compression = header[4]; + if ((w > 8192) || (h > 8192)) + { + free(ret); + e_db_close(db); + return 0; + } + if ((compression == 0) && (size < ((w * h * 4) + 32))) + { + free(ret); + e_db_close(db); + return 0; + } + if (alpha) im->flags |= RGBA_IMAGE_HAS_ALPHA; + if (!im->image) + im->image = evas_common_image_surface_new(im); + if (!im->image) + { + free(ret); + e_db_close(db); + return 0; + } + im->image->w = w; + im->image->h = h; + free(ret); + e_db_close(db); + return 1; +} + +int +evas_image_load_file_data_edb(RGBA_Image *im, const char *file, const char *key) +{ + int w, h, alpha, compression, size; + E_DB_File *db; + DATA32 *ret; + DATA32 *body; + DATA32 header[8]; + + if ((!file) || (!key)) return 0; + db = e_db_open_read((char *)file); + if (!db) return 0; + ret = e_db_data_get(db, (char *)key, &size); + if (!ret) + { + e_db_close(db); + return 0; + } + if (size < 32) + { + free(ret); + e_db_close(db); + return 0; + } + memcpy(header, ret, 32); +#ifdef WORDS_BIGENDIAN + { + int i; + + for (i = 0; i < 8; i++) SWAP32(header[i]); + } +#endif + if (header[0] != 0xac1dfeed) + { + free(ret); + e_db_close(db); + return 0; + } + w = header[1]; + h = header[2]; + alpha = header[3]; + compression = header[4]; + if ((w > 8192) || (h > 8192)) + { + free(ret); + e_db_close(db); + return 0; + } + if ((compression == 0) && (size < ((w * h * 4) + 32))) + { + free(ret); + e_db_close(db); + return 0; + } + if (alpha) im->flags |= RGBA_IMAGE_HAS_ALPHA; + if (!im->image) + im->image = evas_common_image_surface_new(im); + if (!im->image) + { + free(ret); + e_db_close(db); + return 0; + } + im->image->w = w; + im->image->h = h; + body = &(ret[8]); + evas_common_image_surface_alloc(im->image); + if (!im->image->data) + { + free(ret); + e_db_close(db); + return 0; + } + if (!compression) + { +#ifdef WORDS_BIGENDIAN + { + int x; + + memcpy(im->image->data, body, w * h * sizeof(DATA32)); + for (x = 0; x < (w * h); x++) SWAP32(im->image->data[x]); + } +#else + memcpy(im->image->data, body, w * h * sizeof(DATA32)); +#endif + } + else + { + uLongf dlen; + + dlen = w * h * sizeof(DATA32); + uncompress((Bytef *)im->image->data, &dlen, (Bytef *)body, + (uLongf)(size - 32)); +#ifdef WORDS_BIGENDIAN + { + int x; + + for (x = 0; x < (w * h); x++) SWAP32(im->image->data[x]); + } +#endif + } + free(ret); + e_db_close(db); + return 1; +} + +int module_open(Evas_Module *em) +{ + if (!em) return 0; + em->functions = (void *)(&evas_image_load_edb_func); + return 1; +} + +void module_close(void) +{ + +} + +Evas_Module_Api evas_modapi = +{ + EVAS_MODULE_API_VERSION, + EVAS_MODULE_TYPE_IMAGE_LOADER, + "edb", + "none" +}; diff --git a/legacy/evas/src/modules/loaders/eet/Makefile.am b/legacy/evas/src/modules/loaders/eet/Makefile.am new file mode 100644 index 0000000000..b66f952652 --- /dev/null +++ b/legacy/evas/src/modules/loaders/eet/Makefile.am @@ -0,0 +1,24 @@ +## Process this file with automake to produce Makefile.in + +AUTOMAKE_OPTIONS = 1.4 foreign + +# A list of all the files in the current directory which can be regenerated +MAINTAINERCLEANFILES = Makefile.in + +INCLUDES = -I. \ + -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib/include \ + @FREETYPE_CFLAGS@ @eet_cflags@ + +pkgdir = $(libdir)/evas/modules/loaders/eet/$(MODULE_ARCH) + +pkg_LTLIBRARIES = module.la + +module_la_SOURCES = evas_image_load_eet.c + +module_la_LIBADD = +module_la_LDFLAGS = -module -avoid-version -L$(top_builddir)/src/lib -L$(top_builddir)/src/lib/.libs + +module_la_DEPENDENCIES = $(top_builddir)/config.h + +EXTRA_DIST = evas_image_load_eet.c diff --git a/legacy/evas/src/modules/loaders/eet/evas_image_load_eet.c b/legacy/evas/src/modules/loaders/eet/evas_image_load_eet.c new file mode 100644 index 0000000000..8065be9b74 --- /dev/null +++ b/legacy/evas/src/modules/loaders/eet/evas_image_load_eet.c @@ -0,0 +1,114 @@ +#include + +#include "evas_common.h" +#include "evas_private.h" + + +int evas_image_load_file_head_eet(RGBA_Image *im, const char *file, const char *key); +int evas_image_load_file_data_eet(RGBA_Image *im, const char *file, const char *key); + +Evas_Image_Load_Func evas_image_load_eet_func = +{ + evas_image_load_file_head_eet, + evas_image_load_file_data_eet +}; + + +int +evas_image_load_file_head_eet(RGBA_Image *im, const char *file, const char *key) +{ + int alpha, compression, quality, lossy; + unsigned int w, h; + Eet_File *ef; + int ok; + + if ((!file) || (!key)) return 0; + ef = eet_open((char *)file, EET_FILE_MODE_READ); + if (!ef) return 0; + ok = eet_data_image_header_read(ef, (char *)key, + &w, &h, &alpha, &compression, &quality, &lossy); + if (!ok) + { + eet_close(ef); + return 0; + } + if ((w > 8192) || (h > 8192)) + { + eet_close(ef); + return 0; + } + if (alpha) im->flags |= RGBA_IMAGE_HAS_ALPHA; + if (!im->image) + im->image = evas_common_image_surface_new(im); + if (!im->image) + { + eet_close(ef); + return 0; + } + im->image->w = w; + im->image->h = h; + eet_close(ef); + return 1; +} + +int +evas_image_load_file_data_eet(RGBA_Image *im, const char *file, const char *key) +{ + unsigned int w, h; + int alpha, compression, quality, lossy; + Eet_File *ef; + DATA32 *body; + + if ((!file) || (!key)) return 0; + if ((im->image) && (im->image->data)) return 1; + ef = eet_open((char *)file, EET_FILE_MODE_READ); + if (!ef) return 0; + body = eet_data_image_read(ef, (char *)key, + &w, &h, &alpha, &compression, &quality, &lossy); + if (!body) + { + eet_close(ef); + return 0; + } + if ((w > 8192) || (h > 8192)) + { + free(body); + eet_close(ef); + return 0; + } + if (alpha) im->flags |= RGBA_IMAGE_HAS_ALPHA; + if (!im->image) + im->image = evas_common_image_surface_new(im); + if (!im->image) + { + free(body); + eet_close(ef); + return 0; + } + im->image->w = w; + im->image->h = h; + im->image->data = body; + im->image->no_free = 0; + eet_close(ef); + return 1; +} + +int module_open(Evas_Module *em) +{ + if (!em) return 0; + em->functions = (void *)(&evas_image_load_eet_func); + return 1; +} + +void module_close(void) +{ + +} + +Evas_Module_Api evas_modapi = +{ + EVAS_MODULE_API_VERSION, + EVAS_MODULE_TYPE_IMAGE_LOADER, + "eet", + "none" +}; diff --git a/legacy/evas/src/modules/loaders/jpeg/Makefile.am b/legacy/evas/src/modules/loaders/jpeg/Makefile.am new file mode 100644 index 0000000000..0e9789b770 --- /dev/null +++ b/legacy/evas/src/modules/loaders/jpeg/Makefile.am @@ -0,0 +1,24 @@ +## Process this file with automake to produce Makefile.in + +AUTOMAKE_OPTIONS = 1.4 foreign + +# A list of all the files in the current directory which can be regenerated +MAINTAINERCLEANFILES = Makefile.in + +INCLUDES = -I. \ + -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib/include \ + @FREETYPE_CFLAGS@ + +pkgdir = $(libdir)/evas/modules/loaders/jpeg/$(MODULE_ARCH) + +pkg_LTLIBRARIES = module.la + +module_la_SOURCES = evas_image_load_jpeg.c + +module_la_LIBADD = +module_la_LDFLAGS = -module -avoid-version -L$(top_builddir)/src/lib -L$(top_builddir)/src/lib/.libs + +module_la_DEPENDENCIES = $(top_builddir)/config.h + +EXTRA_DIST = evas_image_load_jpeg.c diff --git a/legacy/evas/src/modules/loaders/jpeg/evas_image_load_jpeg.c b/legacy/evas/src/modules/loaders/jpeg/evas_image_load_jpeg.c new file mode 100644 index 0000000000..fefecfe7b9 --- /dev/null +++ b/legacy/evas/src/modules/loaders/jpeg/evas_image_load_jpeg.c @@ -0,0 +1,355 @@ +#include +#include +#include + +#include "evas_common.h" +#include "evas_private.h" + + +typedef struct _JPEG_error_mgr *emptr; +struct _JPEG_error_mgr +{ + struct jpeg_error_mgr pub; + jmp_buf setjmp_buffer; +}; + +static void _JPEGFatalErrorHandler(j_common_ptr cinfo); +static void _JPEGErrorHandler(j_common_ptr cinfo); +static void _JPEGErrorHandler2(j_common_ptr cinfo, int msg_level); + +static int evas_image_load_file_head_jpeg_internal(RGBA_Image *im, FILE *f); +static int evas_image_load_file_data_jpeg_internal(RGBA_Image *im, FILE *f); +#if 0 /* not used at the moment */ +static int evas_image_load_file_data_jpeg_alpha_internal(RGBA_Image *im, FILE *f); +#endif + +int evas_image_load_file_head_jpeg(RGBA_Image *im, const char *file, const char *key); +int evas_image_load_file_data_jpeg(RGBA_Image *im, const char *file, const char *key); + +Evas_Image_Load_Func evas_image_load_jpeg_func = +{ + evas_image_load_file_head_jpeg, + evas_image_load_file_data_jpeg +}; + + +static void +_JPEGFatalErrorHandler(j_common_ptr cinfo) +{ + emptr errmgr; + + errmgr = (emptr) cinfo->err; + /* cinfo->err->output_message(cinfo);*/ + longjmp(errmgr->setjmp_buffer, 1); + return; +} + +static void +_JPEGErrorHandler(j_common_ptr cinfo) +{ + emptr errmgr; + + errmgr = (emptr) cinfo->err; + /* cinfo->err->output_message(cinfo);*/ + /* longjmp(errmgr->setjmp_buffer, 1);*/ + return; +} + +static void +_JPEGErrorHandler2(j_common_ptr cinfo, int msg_level) +{ + emptr errmgr; + + errmgr = (emptr) cinfo->err; + /* cinfo->err->output_message(cinfo);*/ + /* longjmp(errmgr->setjmp_buffer, 1);*/ + return; + msg_level = 0; +} + +static int +evas_image_load_file_head_jpeg_internal(RGBA_Image *im, FILE *f) +{ + int w, h; + struct jpeg_decompress_struct cinfo; + struct _JPEG_error_mgr jerr; + + if (!f) return 0; + cinfo.err = jpeg_std_error(&(jerr.pub)); + jerr.pub.error_exit = _JPEGFatalErrorHandler; + jerr.pub.emit_message = _JPEGErrorHandler2; + jerr.pub.output_message = _JPEGErrorHandler; + if (setjmp(jerr.setjmp_buffer)) + { + jpeg_destroy_decompress(&cinfo); + return 0; + } + jpeg_create_decompress(&cinfo); + jpeg_stdio_src(&cinfo, f); + jpeg_read_header(&cinfo, TRUE); + cinfo.do_fancy_upsampling = FALSE; + cinfo.do_block_smoothing = FALSE; + jpeg_start_decompress(&cinfo); + +/* head decoding */ + if (!im->image) + im->image = evas_common_image_surface_new(im); + if (!im->image) + { + jpeg_destroy_decompress(&cinfo); + return 0; + } + im->image->w = w = cinfo.output_width; + im->image->h = h = cinfo.output_height; +/* end head decoding */ + + jpeg_destroy_decompress(&cinfo); + return 1; +} + +static int +evas_image_load_file_data_jpeg_internal(RGBA_Image *im, FILE *f) +{ + int w, h; + struct jpeg_decompress_struct cinfo; + struct _JPEG_error_mgr jerr; + DATA8 *ptr, *line[16], *data; + DATA32 *ptr2; + int x, y, l, i, scans, count, prevy; + + if (!f) return 0; + cinfo.err = jpeg_std_error(&(jerr.pub)); + jerr.pub.error_exit = _JPEGFatalErrorHandler; + jerr.pub.emit_message = _JPEGErrorHandler2; + jerr.pub.output_message = _JPEGErrorHandler; + if (setjmp(jerr.setjmp_buffer)) + { + jpeg_destroy_decompress(&cinfo); + return 0; + } + jpeg_create_decompress(&cinfo); + jpeg_stdio_src(&cinfo, f); + jpeg_read_header(&cinfo, TRUE); + cinfo.do_fancy_upsampling = FALSE; + cinfo.do_block_smoothing = FALSE; + jpeg_start_decompress(&cinfo); + +/* head decoding */ + im->image->w = w = cinfo.output_width; + im->image->h = h = cinfo.output_height; +/* end head decoding */ +/* data decoding */ + if (cinfo.rec_outbuf_height > 16) + { + jpeg_destroy_decompress(&cinfo); + return 0; + } + data = alloca(w * 16 * 3); + evas_common_image_surface_alloc(im->image); + if (!im->image->data) + { + jpeg_destroy_decompress(&cinfo); + return 0; + } + ptr2 = im->image->data; + count = 0; + prevy = 0; + if (cinfo.output_components == 3) + { + for (i = 0; i < cinfo.rec_outbuf_height; i++) + line[i] = data + (i * w * 3); + for (l = 0; l < h; l += cinfo.rec_outbuf_height) + { + jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); + scans = cinfo.rec_outbuf_height; + if ((h - l) < scans) scans = h - l; + ptr = data; + for (y = 0; y < scans; y++) + { + for (x = 0; x < w; x++) + { + *ptr2 = + (0xff000000) | ((ptr[0]) << 16) | ((ptr[1]) << 8) | (ptr[2]); + ptr += 3; + ptr2++; + } + } + } + } + else if (cinfo.output_components == 1) + { + for (i = 0; i < cinfo.rec_outbuf_height; i++) + line[i] = data + (i * w); + for (l = 0; l < h; l += cinfo.rec_outbuf_height) + { + jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); + scans = cinfo.rec_outbuf_height; + if ((h - l) < scans) scans = h - l; + ptr = data; + for (y = 0; y < scans; y++) + { + for (x = 0; x < w; x++) + { + *ptr2 = + (0xff000000) | ((ptr[0]) << 16) | ((ptr[0]) << 8) | (ptr[0]); + ptr++; + ptr2++; + } + } + } + } +/* end data decoding */ + jpeg_finish_decompress(&cinfo); + jpeg_destroy_decompress(&cinfo); + return 1; +} + +#if 0 /* not used at the moment */ +static int +evas_image_load_file_data_jpeg_alpha_internal(RGBA_Image *im, FILE *f) +{ + int w, h; + struct jpeg_decompress_struct cinfo; + struct _JPEG_error_mgr jerr; + DATA8 *ptr, *line[16], *data; + DATA32 *ptr2; + int x, y, l, i, scans, count, prevy; + + if (!f) return 0; + cinfo.err = jpeg_std_error(&(jerr.pub)); + jerr.pub.error_exit = _JPEGFatalErrorHandler; + jerr.pub.emit_message = _JPEGErrorHandler2; + jerr.pub.output_message = _JPEGErrorHandler; + if (setjmp(jerr.setjmp_buffer)) + { + jpeg_destroy_decompress(&cinfo); + return 0; + } + jpeg_create_decompress(&cinfo); + jpeg_stdio_src(&cinfo, f); + jpeg_read_header(&cinfo, TRUE); + cinfo.do_fancy_upsampling = FALSE; + cinfo.do_block_smoothing = FALSE; + jpeg_start_decompress(&cinfo); + +/* head decoding */ + im->image->w = w = cinfo.output_width; + im->image->h = h = cinfo.output_height; +/* end head decoding */ +/* data decoding */ + if (cinfo.rec_outbuf_height > 16) + { + jpeg_destroy_decompress(&cinfo); + return 0; + } + data = alloca(w * 16 * 3); + if (!im->image->data) + { + jpeg_destroy_decompress(&cinfo); + return 0; + } + ptr2 = im->image->data; + count = 0; + prevy = 0; + if (cinfo.output_components == 3) + { + for (i = 0; i < cinfo.rec_outbuf_height; i++) + line[i] = data + (i * w * 3); + for (l = 0; l < h; l += cinfo.rec_outbuf_height) + { + jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); + scans = cinfo.rec_outbuf_height; + if ((h - l) < scans) scans = h - l; + ptr = data; + for (y = 0; y < scans; y++) + { + for (x = 0; x < w; x++) + { + *ptr2 = + ((*ptr2) & 0x00ffffff) | + (((ptr[0] + ptr[1] + ptr[2]) / 3) << 24); + ptr += 3; + ptr2++; + } + } + } + } + else if (cinfo.output_components == 1) + { + for (i = 0; i < cinfo.rec_outbuf_height; i++) + line[i] = data + (i * w); + for (l = 0; l < h; l += cinfo.rec_outbuf_height) + { + jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); + scans = cinfo.rec_outbuf_height; + if ((h - l) < scans) scans = h - l; + ptr = data; + for (y = 0; y < scans; y++) + { + for (x = 0; x < w; x++) + { + *ptr2 = + ((*ptr2) & 0x00ffffff) | + ((ptr[0]) << 24); + ptr++; + ptr2++; + } + } + } + } +/* end data decoding */ + jpeg_finish_decompress(&cinfo); + jpeg_destroy_decompress(&cinfo); + return 1; +} +#endif + +int +evas_image_load_file_head_jpeg(RGBA_Image *im, const char *file, const char *key) +{ + int val; + FILE *f; + + if ((!file)) return 0; + f = fopen(file, "rb"); + if (!f) return 0; + val = evas_image_load_file_head_jpeg_internal(im, f); + fclose(f); + return val; + key = 0; +} + +int +evas_image_load_file_data_jpeg(RGBA_Image *im, const char *file, const char *key) +{ + int val; + FILE *f; + + if ((!file)) return 0; + f = fopen(file, "rb"); + if (!f) return 0; + val = evas_image_load_file_data_jpeg_internal(im, f); + fclose(f); + return val; + key = 0; +} + +int module_open(Evas_Module *em) +{ + if (!em) return 0; + em->functions = (void *)(&evas_image_load_jpeg_func); + return 1; +} + +void module_close(void) +{ + +} + +Evas_Module_Api evas_modapi = +{ + EVAS_MODULE_API_VERSION, + EVAS_MODULE_TYPE_IMAGE_LOADER, + "jpeg", + "none" +}; diff --git a/legacy/evas/src/modules/loaders/png/Makefile.am b/legacy/evas/src/modules/loaders/png/Makefile.am new file mode 100644 index 0000000000..50ff5f381b --- /dev/null +++ b/legacy/evas/src/modules/loaders/png/Makefile.am @@ -0,0 +1,24 @@ +## Process this file with automake to produce Makefile.in + +AUTOMAKE_OPTIONS = 1.4 foreign + +# A list of all the files in the current directory which can be regenerated +MAINTAINERCLEANFILES = Makefile.in + +INCLUDES = -I. \ + -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib/include \ + @FREETYPE_CFLAGS@ @png_cflags@ + +pkgdir = $(libdir)/evas/modules/loaders/png/$(MODULE_ARCH) + +pkg_LTLIBRARIES = module.la + +module_la_SOURCES = evas_image_load_png.c + +module_la_LIBADD = +module_la_LDFLAGS = -module -avoid-version -L$(top_builddir)/src/lib -L$(top_builddir)/src/lib/.libs + +module_la_DEPENDENCIES = $(top_builddir)/config.h + +EXTRA_DIST = evas_image_load_png.c diff --git a/legacy/evas/src/modules/loaders/png/evas_image_load_png.c b/legacy/evas/src/modules/loaders/png/evas_image_load_png.c new file mode 100644 index 0000000000..1b50269a84 --- /dev/null +++ b/legacy/evas/src/modules/loaders/png/evas_image_load_png.c @@ -0,0 +1,223 @@ +#include +#include + +#include "evas_common.h" +#include "evas_private.h" + + +#define PNG_BYTES_TO_CHECK 4 + + +int evas_image_load_file_head_png(RGBA_Image *im, const char *file, const char *key); +int evas_image_load_file_data_png(RGBA_Image *im, const char *file, const char *key); + +Evas_Image_Load_Func evas_image_load_png_func = +{ + evas_image_load_file_head_png, + evas_image_load_file_data_png +}; + + +int +evas_image_load_file_head_png(RGBA_Image *im, const char *file, const char *key) +{ + png_uint_32 w32, h32; + FILE *f; + png_structp png_ptr = NULL; + png_infop info_ptr = NULL; + int bit_depth, color_type, interlace_type; + unsigned char buf[PNG_BYTES_TO_CHECK]; + char hasa, hasg; + + if ((!file)) return 0; + hasa = 0; + hasg = 0; + f = fopen(file, "rb"); + if (!f) return 0; + + /* if we havent read the header before, set the header data */ + fread(buf, 1, PNG_BYTES_TO_CHECK, f); + if (!png_check_sig(buf, PNG_BYTES_TO_CHECK)) + { + fclose(f); + return 0; + } + rewind(f); + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png_ptr) + { + fclose(f); + return 0; + } + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + png_destroy_read_struct(&png_ptr, NULL, NULL); + fclose(f); + return 0; + } + if (setjmp(png_ptr->jmpbuf)) + { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + fclose(f); + return 0; + } + png_init_io(png_ptr, f); + png_read_info(png_ptr, info_ptr); + png_get_IHDR(png_ptr, info_ptr, (png_uint_32 *) (&w32), + (png_uint_32 *) (&h32), &bit_depth, &color_type, + &interlace_type, NULL, NULL); + if (!im->image) + im->image = evas_common_image_surface_new(im); + if (!im->image) + { + png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL); + fclose(f); + return 0; + } + im->image->w = (int) w32; + im->image->h = (int) h32; + if (color_type == PNG_COLOR_TYPE_PALETTE) + { + png_set_expand(png_ptr); + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) hasa = 1; + } + if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) hasa = 1; + if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + hasa = 1; + hasg = 1; + } + if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY) hasg = 1; + if (hasa) im->flags |= RGBA_IMAGE_HAS_ALPHA; + png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL); + fclose(f); + return 1; + key = 0; +} + +int +evas_image_load_file_data_png(RGBA_Image *im, const char *file, const char *key) +{ + png_uint_32 w32, h32; + int w, h; + FILE *f; + png_structp png_ptr = NULL; + png_infop info_ptr = NULL; + int bit_depth, color_type, interlace_type; + unsigned char buf[PNG_BYTES_TO_CHECK]; + unsigned char **lines; + char hasa, hasg; + int i; + + if ((!file)) return 0; + hasa = 0; + hasg = 0; + f = fopen(file, "rb"); + if (!f) return 0; + + /* if we havent read the header before, set the header data */ + fread(buf, 1, PNG_BYTES_TO_CHECK, f); + if (!png_check_sig(buf, PNG_BYTES_TO_CHECK)) + { + fclose(f); + return 0; + } + rewind(f); + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png_ptr) + { + fclose(f); + return 0; + } + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + png_destroy_read_struct(&png_ptr, NULL, NULL); + fclose(f); + return 0; + } + if (setjmp(png_ptr->jmpbuf)) + { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + fclose(f); + return 0; + } + png_init_io(png_ptr, f); + png_read_info(png_ptr, info_ptr); + png_get_IHDR(png_ptr, info_ptr, (png_uint_32 *) (&w32), + (png_uint_32 *) (&h32), &bit_depth, &color_type, + &interlace_type, NULL, NULL); + im->image->w = (int) w32; + im->image->h = (int) h32; + if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_expand(png_ptr); + if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) hasa = 1; + if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + hasa = 1; + hasg = 1; + } + if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY) hasg = 1; + if (hasa) im->flags |= RGBA_IMAGE_HAS_ALPHA; + + w = im->image->w; + h = im->image->h; + if (hasa) png_set_expand(png_ptr); + /* we want ARGB */ +#ifdef WORDS_BIGENDIAN + png_set_swap_alpha(png_ptr); + png_set_filler(png_ptr, 0xff, PNG_FILLER_BEFORE); +#else + png_set_bgr(png_ptr); + png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); +#endif + /* 16bit color -> 8bit color */ + png_set_strip_16(png_ptr); + /* pack all pixels to byte boundaires */ + png_set_packing(png_ptr); + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) png_set_expand(png_ptr); + evas_common_image_surface_alloc(im->image); + if (!im->image->data) + { + evas_common_image_surface_free(im->image); + png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL); + fclose(f); + return 0; + } + lines = (unsigned char **) alloca(h * sizeof(unsigned char *)); + + if (hasg) + { + png_set_gray_to_rgb(png_ptr); + if (png_get_bit_depth(png_ptr, info_ptr) < 8) + png_set_gray_1_2_4_to_8(png_ptr); + } + for (i = 0; i < h; i++) + lines[i] = ((unsigned char *)(im->image->data)) + (i * w * sizeof(DATA32)); + png_read_image(png_ptr, lines); + png_read_end(png_ptr, info_ptr); + png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL); + fclose(f); + return 1; + key = 0; +} + +int module_open(Evas_Module *em) +{ + if (!em) return 0; + em->functions = (void *)(&evas_image_load_png_func); + return 1; +} + +void module_close(void) +{ + +} + +Evas_Module_Api evas_modapi = +{ + EVAS_MODULE_API_VERSION, + EVAS_MODULE_TYPE_IMAGE_LOADER, + "png", + "none" +};