From: glennrp Date: Wed, 20 Jul 2011 14:44:40 +0000 (+0000) Subject: Exit test loop immediately when a non-gray pixel is found. X-Git-Tag: 7.0.1-0~7287 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e5e6b80f72d72eb8dc5be1bd1425b4ad504f0ef7;p=imagemagick Exit test loop immediately when a non-gray pixel is found. --- diff --git a/coders/png.c b/coders/png.c index 92dfe2f20..4198c90ba 100644 --- a/coders/png.c +++ b/coders/png.c @@ -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); } - } + } } } }