[GM-commit] GraphicsMagick: Eliminated PNG palette-optimization when image->...
Swiss army knife of image processing
Brought to you by:
bfriesen
From: GraphicsMagick C. <gra...@li...> - 2014-08-09 00:29:22
|
changeset ceabe42d7f51 in /hg/GraphicsMagick details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=ceabe42d7f51 summary: Eliminated PNG palette-optimization when image->type is OptimizeType. diffstat: ChangeLog | 5 + coders/png.c | 310 ----------------------------------------------------------- 2 files changed, 5 insertions(+), 310 deletions(-) diffs (truncated from 353 to 300 lines): diff -r 9e2efd471a8c -r ceabe42d7f51 ChangeLog --- a/ChangeLog Wed Aug 06 22:19:04 2014 -0500 +++ b/ChangeLog Fri Aug 08 19:29:02 2014 -0500 @@ -1,3 +1,8 @@ +2014-08-08 Glenn Randers-Pehrson <gl...@si...> + + * coders/png.c: Eliminated palette-optimization (see + https://sourceforge.net/p/graphicsmagick/feature-requests/35/). + 2014-08-06 Bob Friesenhahn <bfr...@si...> * dcraw/dcraw.c: Fix dcraw build for x64 target when only WIN64 is diff -r 9e2efd471a8c -r ceabe42d7f51 coders/png.c --- a/coders/png.c Wed Aug 06 22:19:04 2014 -0500 +++ b/coders/png.c Fri Aug 08 19:29:02 2014 -0500 @@ -102,7 +102,6 @@ #define MNG_COALESCE_LAYERS /* In 5.4.4, this interfered with MMAP'ed files. */ #define MNG_INSERT_LAYERS /* Troublesome, but seem to work as of 5.4.4 */ #define GMPNG_BUILD_PALETTE /* This works as of 5.4.3. */ -#define GMPNG_SORT_PALETTE /* This works as of 5.4.0. */ #if defined(HasJPEG) # define JNG_SUPPORTED /* Not finished as of 5.5.2. See "To do" comments. */ #endif @@ -484,299 +483,6 @@ return result; } - -#if defined(GMPNG_SORT_PALETTE) -/* -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % -% % -% % -% C o m p r e s s C o l o r m a p T r a n s F i r s t % -% % -% % -% % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% Method CompressColormapTransFirst compresses an image colormap removing -% any duplicate and unused color entries and putting the transparent colors -% first. -% -% The format of the CompressColormapTransFirst method is: -% -% unsigned int CompressColormapTransFirst(Image *image) -% -% A description of each parameter follows: -% -% o image: The address of a structure of type Image. -% This function updates image->colors and image->colormap. -% -% -*/ -static MagickPassFail CompressColormapTransFirst(Image *image) -{ - int - remap_needed, - k; - - long - j, - new_number_colors, - number_colors, - y; - - PixelPacket - *colormap; - - register const PixelPacket - *p; - - IndexPacket - top_used; - - register long - i, - x; - - IndexPacket - *map, - *opacity; - - unsigned char - *marker, - have_transparency; - - /* - Determine if colormap can be compressed. - */ - assert(image != (Image *) NULL); - (void) LogMagickEvent(CoderEvent,GetMagickModule(), - " CompressColorMapTransFirst %s (%ld colors)", - image->filename,(long)image->colors); - if (image->storage_class != PseudoClass || image->colors > 256 || - image->colors < 2) - { - (void) LogMagickEvent(CoderEvent,GetMagickModule(), - " Could not compress colormap"); - if (image->colors > 256 || image->colors == 0) - return(MagickFalse); - else - return(MagickTrue); - } - marker=MagickAllocateMemory(unsigned char *,image->colors); - if (marker == (unsigned char *) NULL) - ThrowBinaryException(ResourceLimitError,MemoryAllocationFailed, - "Unable to compress image colormap") - opacity=MagickAllocateMemory(IndexPacket *, - image->colors*sizeof(IndexPacket)); - if (opacity == (IndexPacket *) NULL) - { - MagickFreeMemory(marker); - ThrowBinaryException(ResourceLimitError,MemoryAllocationFailed, - "Unable to compress image colormap") - } - /* - Mark colors that are present. - */ - number_colors=(long) image->colors; - for (i=0; i < number_colors; i++) - { - marker[i]=MagickFalse; - opacity[i]=OpaqueOpacity; - } - top_used=0; - for (y=0; y < (long) image->rows; y++) - { - register const IndexPacket - *indexes; - - p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception); - if (p == (const PixelPacket *) NULL) - break; - indexes=AccessImmutableIndexes(image); - if (image->matte) - for (x=0; x < (long) image->columns; x++) - { - marker[(int) indexes[x]]=MagickTrue; - opacity[(int) indexes[x]]=p->opacity; - if (indexes[x] > top_used) - top_used=indexes[x]; - p++; - } - else - for (x=0; x < (long) image->columns; x++) - { - marker[(int) indexes[x]]=MagickTrue; - if (indexes[x] > top_used) - top_used=indexes[x]; - } - } - - if (image->matte) - { - /* - Mark background color, topmost occurrence if more than one. - */ - for (i=number_colors-1; i; i--) - { - if (RGBColorMatchExact(image->colormap[i],image->background_color)) - { - marker[i]=MagickTrue; - break; - } - } - } - /* - Unmark duplicates. - */ - for (i=0; i < number_colors-1; i++) - if (marker[i]) - { - for (j=i+1; j < number_colors; j++) - if ((opacity[i] == opacity[j]) && - (RGBColorMatchExact(image->colormap[i],image->colormap[j]))) - marker[j]=MagickFalse; - } - /* - Count colors that still remain. - */ - have_transparency=MagickFalse; - new_number_colors=0; - for (i=0; i < number_colors; i++) - if (marker[i]) - { - new_number_colors++; - if (opacity[i] != OpaqueOpacity) - have_transparency=MagickTrue; - } - if ((!have_transparency || (marker[0] && (opacity[0] == TransparentOpacity))) - && (new_number_colors == number_colors)) - { - /* - No duplicate or unused entries, and transparency-swap not needed - */ - MagickFreeMemory(marker); - MagickFreeMemory(opacity); - return(MagickPass); - } - - remap_needed=MagickFalse; - if ((long) top_used >= new_number_colors) - remap_needed=MagickTrue; - - /* - Compress colormap. - */ - - colormap=MagickAllocateMemory(PixelPacket *, - image->colors*sizeof(PixelPacket)); - if (colormap == (PixelPacket *) NULL) - { - MagickFreeMemory(marker); - MagickFreeMemory(opacity); - ThrowBinaryException(ResourceLimitError,MemoryAllocationFailed, - "Unable to compress image colormap") - } - /* - Eliminate unused colormap entries. - */ - map=MagickAllocateMemory(IndexPacket *,number_colors*sizeof(IndexPacket)); - if (map == (IndexPacket *) NULL) - { - MagickFreeMemory(marker); - MagickFreeMemory(opacity); - MagickFreeMemory(colormap); - ThrowBinaryException(ResourceLimitError,MemoryAllocationFailed, - "Unable to compress image colormap") - } - k=0; - for (i=0; i < number_colors; i++) - { - map[i]=(IndexPacket) k; - if (marker[i]) - { - for (j=i+1; j < number_colors; j++) - { - if ((opacity[i] == opacity[j]) && - (RGBColorMatchExact(image->colormap[i],image->colormap[j]))) - { - map[j]=(IndexPacket) k; - marker[j]=MagickFalse; - } - } - k++; - } - } - j=0; - for (i=0; i < number_colors; i++) - { - if (marker[i]) - { - colormap[j]=image->colormap[i]; - j++; - } - } - if (have_transparency && (opacity[0] != TransparentOpacity)) - { - /* - Move the first transparent color to palette entry 0. - */ - for (i=1; i < number_colors; i++) - { - if (marker[i] && opacity[i] == TransparentOpacity) - { - PixelPacket - temp_colormap; - - temp_colormap=colormap[0]; - colormap[0]=colormap[(int) map[i]]; - colormap[map[i]]=temp_colormap; - for (j=0; j < number_colors; j++) - { - if (map[j] == 0) - map[j]=map[i]; - else if (map[j] == map[i]) - map[j]=0; - } - remap_needed=MagickTrue; - break; - } - } - } - - MagickFreeMemory(opacity); - MagickFreeMemory(marker); - - if (remap_needed) - { - /* - Remap pixels. - */ - for (y=0; y < (long) image->rows; y++) - { - register IndexPacket - *indexes; - - p=GetImagePixelsEx(image,0,y,image->columns,1,&image->exception); |