Enlightenment CVS committal Author : raster Project : e17 Module : libs/evas
Dir : e17/libs/evas/src/modules/loaders/png Modified Files: evas_image_load_png.c Log Message: png loading changes to fix greyscale loads apparently on 1.2.19 libpng... =================================================================== RCS file: /cvs/e/e17/libs/evas/src/modules/loaders/png/evas_image_load_png.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- evas_image_load_png.c 5 Nov 2006 05:07:52 -0000 1.5 +++ evas_image_load_png.c 25 Aug 2007 02:36:18 -0000 1.6 @@ -31,11 +31,10 @@ png_infop info_ptr = NULL; int bit_depth, color_type, interlace_type; unsigned char buf[PNG_BYTES_TO_CHECK]; - char hasa, hasg; + char hasa; if ((!file)) return 0; hasa = 0; - hasg = 0; f = fopen(file, "rb"); if (!f) return 0; @@ -87,18 +86,9 @@ } 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 (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) hasa = 1; + if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) hasa = 1; + if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) hasa = 1; if (hasa) im->flags |= RGBA_IMAGE_HAS_ALPHA; png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL); fclose(f); @@ -117,12 +107,11 @@ int bit_depth, color_type, interlace_type; unsigned char buf[PNG_BYTES_TO_CHECK]; unsigned char **lines; - char hasa, hasg; + char hasa; int i; if ((!file)) return 0; hasa = 0; - hasg = 0; f = fopen(file, "rb"); if (!f) return 0; @@ -164,32 +153,39 @@ fclose(f); return 0; } - 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 (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) hasa = 1; + if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) hasa = 1; + if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) hasa = 1; if (hasa) im->flags |= RGBA_IMAGE_HAS_ALPHA; + /* Prep for transformations... ultimately we want ARGB */ + /* expand palette -> RGB if necessary */ + if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(png_ptr); + /* expand gray (w/reduced bits) -> 8-bit RGB if necessary */ + if ((color_type == PNG_COLOR_TYPE_GRAY) || + (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)) + { + png_set_gray_to_rgb(png_ptr); + if (bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr); + } + /* expand transparency entry -> alpha channel if present */ + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) + png_set_tRNS_to_alpha(png_ptr); + /* reduce 16bit color -> 8bit color if necessary */ + if (bit_depth > 8) png_set_strip_16(png_ptr); + /* pack all pixels to byte boundaries */ + png_set_packing(png_ptr); + 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); + if (!hasa) png_set_filler(png_ptr, 0xff, PNG_FILLER_BEFORE); #else png_set_bgr(png_ptr); - png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); + if (!hasa) 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) { @@ -200,12 +196,6 @@ } 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); ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs