From: Enlightenment S. <no-...@en...> - 2011-11-19 15:09:33
|
Log: TGA loader gets fixed alpha decode - real life tga's have proper alpha values. also reduce false positive tga file detection Author: raster Date: 2011-11-19 07:09:27 -0800 (Sat, 19 Nov 2011) New Revision: 65411 Trac: http://trac.enlightenment.org/e/changeset/65411 Modified: trunk/evas/ChangeLog trunk/evas/NEWS trunk/evas/src/modules/loaders/tga/evas_image_load_tga.c Modified: trunk/evas/ChangeLog =================================================================== --- trunk/evas/ChangeLog 2011-11-19 14:57:42 UTC (rev 65410) +++ trunk/evas/ChangeLog 2011-11-19 15:09:27 UTC (rev 65411) @@ -504,3 +504,9 @@ * JPEG encode and decode in eet now uses ISLOW (not IFAST) due to noticable quality losses in the chase for speed. It will use IFAST for quality less than 60 when encoding + +2011-11-20 Carsten Haitzler (The Rasterman) + + * TGA loader gets fixed alpha decode - real life tga's have + proper alpha values. also reduce false positive tga file + detection Modified: trunk/evas/NEWS =================================================================== --- trunk/evas/NEWS 2011-11-19 14:57:42 UTC (rev 65410) +++ trunk/evas/NEWS 2011-11-19 15:09:27 UTC (rev 65411) @@ -85,6 +85,7 @@ * grab count and hide bug * infintie loop bug when re-inserting objects during pre-render calc * evas_object_image_data_convert + * TGA loader detects false positives less and handles alpha TGAs better Improvements: Modified: trunk/evas/src/modules/loaders/tga/evas_image_load_tga.c =================================================================== --- trunk/evas/src/modules/loaders/tga/evas_image_load_tga.c 2011-11-19 14:57:42 UTC (rev 65410) +++ trunk/evas/src/modules/loaders/tga/evas_image_load_tga.c 2011-11-19 15:09:27 UTC (rev 65411) @@ -74,6 +74,7 @@ tga_footer *footer, tfooter; char hasa = 0, footer_present = 0, vinverted = 0; int w = 0, h = 0, bpp; + int x, y; f = eina_file_open(file, EINA_FALSE); *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; @@ -116,8 +117,29 @@ if (!((bpp == 32) || (bpp == 24) || (bpp == 16) || (bpp == 8))) goto close_file; if ((bpp == 32) && (header->descriptor & TGA_DESC_ABITS)) hasa = 1; + // don't handle colormapped images + if ((header->colorMapType) != 0) + goto close_file; + // if colormap size is anything other than legal sizes or 0 - not real tga + if (!((header->colorMapSize == 0) || + (header->colorMapSize == 15) || + (header->colorMapSize == 16) || + (header->colorMapSize == 24) || + (header->colorMapSize == 32))) + goto close_file; + x = (header->xOriginHi << 8) | (header->xOriginLo); + y = (header->yOriginHi << 8) | (header->yOriginLo); w = (header->widthHi << 8) | header->widthLo; h = (header->heightHi << 8) | header->heightLo; + // x origin gerater that width, y origin greater than height - wrong file + if ((x >= w) || (y >= h)) + goto close_file; + // if descriptor has either of the top 2 bits set... not tga + if (header->descriptor & 0xc0) + goto close_file; + // if its not 32bit then it cant have alpha bits set - so invalid + if (!((bpp == 32) && (header->descriptor & TGA_DESC_ABITS))) + goto close_file; if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) || IMG_TOO_BIG(w, h)) @@ -194,8 +216,29 @@ if (!((bpp == 32) || (bpp == 24) || (bpp == 16) || (bpp == 8))) goto close_file; if ((bpp == 32) && (header->descriptor & TGA_DESC_ABITS)) hasa = 1; + // don't handle colormapped images + if ((header->colorMapType) != 0) + goto close_file; + // if colormap size is anything other than legal sizes or 0 - not real tga + if (!((header->colorMapSize == 0) || + (header->colorMapSize == 15) || + (header->colorMapSize == 16) || + (header->colorMapSize == 24) || + (header->colorMapSize == 32))) + goto close_file; + x = (header->xOriginHi << 8) | (header->xOriginLo); + y = (header->yOriginHi << 8) | (header->yOriginLo); w = (header->widthHi << 8) | header->widthLo; h = (header->heightHi << 8) | header->heightLo; + // x origin gerater that width, y origin greater than height - wrong file + if ((x >= w) || (y >= h)) + goto close_file; + // if descriptor has either of the top 2 bits set... not tga + if (header->descriptor & 0xc0) + goto close_file; + // if its not 32bit then it cant have alpha bits set - so invalid + if (!((bpp == 32) && (header->descriptor & TGA_DESC_ABITS))) + goto close_file; if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) || IMG_TOO_BIG(w, h)) @@ -237,7 +280,8 @@ for (x = 0; (x < w) && ((bufptr + 4) <= bufend); x++) { if (hasa) - *dataptr = ARGB_JOIN(255 - bufptr[3], bufptr[2], bufptr[1], bufptr[0]); +// *dataptr = ARGB_JOIN(255 - bufptr[3], bufptr[2], bufptr[1], bufptr[0]); + *dataptr = ARGB_JOIN(bufptr[3], bufptr[2], bufptr[1], bufptr[0]); else *dataptr = ARGB_JOIN(0xff, bufptr[2], bufptr[1], bufptr[0]); dataptr++; @@ -306,7 +350,8 @@ { unsigned char r, g, b, a; - a = 255 - bufptr[3]; +// a = 255 - bufptr[3]; + a = bufptr[3]; r = bufptr[2]; g = bufptr[1]; b = bufptr[0]; @@ -383,7 +428,8 @@ for (i = 0; (i < count) && (bufptr < (bufend - 4)) && (dataptr < dataend); i++) { if (hasa) - *dataptr = ARGB_JOIN(255 - bufptr[3], bufptr[2], bufptr[1], bufptr[0]); +// *dataptr = ARGB_JOIN(255 - bufptr[3], bufptr[2], bufptr[1], bufptr[0]); + *dataptr = ARGB_JOIN(bufptr[3], bufptr[2], bufptr[1], bufptr[0]); else *dataptr = ARGB_JOIN(0xff, bufptr[2], bufptr[1], bufptr[0]); dataptr++; |