]> granicus.if.org Git - imagemagick/commitdiff
Exit test loop immediately when a non-gray pixel is found.
authorglennrp <glennrp@git.imagemagick.org>
Wed, 20 Jul 2011 14:44:40 +0000 (14:44 +0000)
committerglennrp <glennrp@git.imagemagick.org>
Wed, 20 Jul 2011 14:44:40 +0000 (14:44 +0000)
coders/png.c

index 92dfe2f208fe25be4d49d1d214369cfdc99d4d71..4198c90bae94b40a761179fe170ba9b5007844bf 100644 (file)
@@ -8132,26 +8132,26 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
                if (q == (const Quantum *) NULL)
                  break;
 
+               s=q;
+               for (x=0; x < (ssize_t) image->columns; x++)
+               {
+                 if (GetPixelRed(image,s) != GetPixelGreen(image,s) ||
+                     GetPixelRed(image,s) != GetPixelBlue(image,s))
+                   {
+                      ping_have_color=MagickTrue;
+                      ping_have_non_bw=MagickTrue;
+                      break;
+                   }
+                 s+=GetPixelChannels(image);
+               }
+
+               if (ping_have_color != MagickFalse)
+                 break;
+
                /* Worst case is black-and-white; we are looking at every
                 * pixel twice.
                 */
 
-               if (ping_have_color == MagickFalse)
-                 {
-                   s=q;
-                   for (x=0; x < (ssize_t) image->columns; x++)
-                   {
-                     if (GetPixelRed(image,s) != GetPixelGreen(image,s) ||
-                         GetPixelRed(image,s) != GetPixelBlue(image,s))
-                       {
-                          ping_have_color=MagickTrue;
-                          ping_have_non_bw=MagickTrue;
-                          break;
-                       }
-                     s+=GetPixelChannels(image);
-                   }
-                 }
-
                if (ping_have_non_bw == MagickFalse)
                  {
                    s=q;
@@ -8161,10 +8161,11 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
                          GetPixelRed(image,s) != QuantumRange)
                        {
                          ping_have_non_bw=MagickTrue;
+                         break;
                        }
                      s+=GetPixelChannels(image);
                    }
-                 }
+               }
              }
            }
        }