]> granicus.if.org Git - imagemagick/commitdiff
Simplified the PNG encoder's LosslessReduceDepthOK() function.
authorglennrp <glennrp@git.imagemagick.org>
Fri, 22 Apr 2011 15:12:34 +0000 (15:12 +0000)
committerglennrp <glennrp@git.imagemagick.org>
Fri, 22 Apr 2011 15:12:34 +0000 (15:12 +0000)
ChangeLog
coders/png.c

index 3b1579519d923e632f5a7f0be0a39f4457b3f715..94f0989f1fd191cfc9f75f597f397f168e5725d3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,7 +5,7 @@
     ImageListOptions parsing table. This is part of development to produce
     a "convert" replacement that can read options from both command line and
     from files or pipelines, in "Do it Immediately" handling.
-  * Crop Bug Fix. Prevent infinate loop with "+repage -crop 0x40"
+  * Crop Bug Fix. Prevent infinite loop with "+repage -crop 0x40"
 
 2011-04-18  6.6.9-6 Glenn Randers-Pehrson <glennrp@image...>
   * Added "date" to the things that can appear on the -define PNG:exclude-chunk
@@ -14,6 +14,9 @@
     text chunks.
   * Added "-define PNG:preserve-colormap" option (reference
     http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=18564).
+  * Simplified the LosslessReduceDepthOK() function.
+
+2011-04-18  6.6.9-6 Cristy  <quetzlzacatenango@image...>
   * Add support for writing RGB FITS images as separate planes.
 
 2011-04-16  6.6.9-6 Cristy  <quetzlzacatenango@image...>
index 89f3b3e3e8af704f6c85726bfefc770743d018d4..3d83b80c0f5934148bf0c84fcd2d417d2ec450d5 100644 (file)
@@ -501,14 +501,16 @@ LosslessReduceDepthOK(Image *image)
      *
      * This is true if the high byte and the next highest byte of
      * each sample of the image, the colormap, and the background color
-     * are equal to each other.
+     * are equal to each other.  We check this by seeing if the samples
+     * are unchanged when we scale them down to 8 and back up to Quantum.
      *
      * We don't use the method GetImageDepth() because it doesn't check
-     * background * and doesn't handle PseudoClass specially.  Also
-     * GetImageDepth() uses multiplication and division by 257 instead of
-     * shifting, so it might be slower.
+     * background and doesn't handle PseudoClass specially.
      */
 
+#define ScaleQuantumToCharToQuantum(quantum) \
+        (ScaleCharToQuantum((unsigned char) ScaleQuantumToChar(quantum)))
+
     MagickBooleanType
       ok_to_reduce=MagickFalse;
 
@@ -518,17 +520,13 @@ LosslessReduceDepthOK(Image *image)
         const PixelPacket
           *p;
 
-        const int
-          pnghi= MAGICKCORE_QUANTUM_DEPTH - 8,
-          pnglo= MAGICKCORE_QUANTUM_DEPTH - 16;
-
         ok_to_reduce=
-          (((((size_t) image->background_color.red >> pnghi) & 0xff)
-          == (((size_t) image->background_color.red >> pnglo) & 0xff)) &&
-           ((((size_t) image->background_color.green >> pnghi) & 0xff)
-          == (((size_t) image->background_color.green >> pnglo) & 0xff)) &&
-           ((((size_t) image->background_color.blue >> pnghi) & 0xff)
-          == (((size_t) image->background_color.blue >> pnglo) & 0xff))) ?
+          (image->background_color.red == 
+             ScaleQuantumToCharToQuantum(image->background_color.red) &&
+          image->background_color.green == 
+             ScaleQuantumToCharToQuantum(image->background_color.green) &&
+          image->background_color.blue == 
+             ScaleQuantumToCharToQuantum(image->background_color.blue)) ? 
           MagickTrue : MagickFalse;
 
         if (ok_to_reduce != MagickFalse && image->storage_class == PseudoClass)
@@ -537,19 +535,20 @@ LosslessReduceDepthOK(Image *image)
 
             for (indx=0; indx < (ssize_t) image->colors; indx++)
               {
-                ok_to_reduce=
-                 (((((size_t) image->colormap[indx].red >> pnghi) & 0xff)
-                  == (((size_t) image->colormap[indx].red >> pnglo) & 0xff)) &&
-                  ((((size_t) image->colormap[indx].green >> pnghi) & 0xff)
-                  == (((size_t) image->colormap[indx].green >> pnglo) & 0xff))
-                  && ((((size_t) image->colormap[indx].blue >> pnghi) & 0xff)
-                  == (((size_t) image->colormap[indx].blue >> pnglo) & 0xff)) &&
-                  (image->matte == MagickFalse ||
-                  (((size_t) image->colormap[indx].opacity >> pnghi) & 0xff)
-                  == (((size_t) image->colormap[indx].opacity >> pnglo)
-                  & 0xff))) ?  MagickTrue : MagickFalse;
+                ok_to_reduce=(
+                   image->colormap[indx].red == 
+                   ScaleQuantumToCharToQuantum(image->colormap[indx].red) &&
+                   image->colormap[indx].green == 
+                   ScaleQuantumToCharToQuantum(image->colormap[indx].green) &&
+                   image->colormap[indx].blue == 
+                   ScaleQuantumToCharToQuantum(image->colormap[indx].blue) &&
+                   (image->matte == MagickFalse ||
+                   image->colormap[indx].opacity == 
+                   ScaleQuantumToCharToQuantum(image->colormap[indx].opacity)))
+                   ? MagickTrue : MagickFalse;
+
                 if (ok_to_reduce == MagickFalse)
-                  break;
+                   break;
               }
           }
 
@@ -574,17 +573,13 @@ LosslessReduceDepthOK(Image *image)
 
               for (x=(ssize_t) image->columns-1; x >= 0; x--)
               {
-                ok_to_reduce=(
-                  ((((size_t) p->red >> pnghi) & 0xff) ==
-                  (((size_t) p->red >> pnglo) & 0xff)) &&
-                  ((((size_t) p->green >> pnghi) & 0xff) ==
-                  (((size_t) p->green >> pnglo) & 0xff)) &&
-                  ((((size_t) p->blue >> pnghi) & 0xff) ==
-                  (((size_t) p->blue >> pnglo) & 0xff)) &&
-                  (((image->matte == MagickFalse ||
-                  (((size_t) p->opacity >> pnghi) & 0xff) ==
-                  (((size_t) p->opacity >> pnglo) & 0xff))))) ?
-                  MagickTrue : MagickFalse;
+                ok_to_reduce=
+                  (p->red == ScaleQuantumToCharToQuantum(p->red) &&
+                  p->green == ScaleQuantumToCharToQuantum(p->green) &&
+                  p->blue == ScaleQuantumToCharToQuantum(p->blue) &&
+                  (image->matte == MagickFalse ||
+                  p->opacity == ScaleQuantumToCharToQuantum(p->opacity)))
+                  ? MagickTrue : MagickFalse;
 
                 if (ok_to_reduce == MagickFalse)
                   break;