From c17d96f447438bb27d874f1440ed05f6493fde1f Mon Sep 17 00:00:00 2001 From: glennrp Date: Mon, 27 Jun 2011 01:20:11 +0000 Subject: [PATCH] Fixed Q32 handling of 16-bit transparent grayscale PNG input. --- coders/png.c | 50 +++++++++++++++----------------------------------- 1 file changed, 15 insertions(+), 35 deletions(-) diff --git a/coders/png.c b/coders/png.c index 7b07bc13d..b162de5e1 100644 --- a/coders/png.c +++ b/coders/png.c @@ -2976,6 +2976,10 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, /* Convert grayscale image to PseudoClass pixel packets. */ + + if (logging != MagickFalse) + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + " Converting grayscale pixels to pixel packets"); image->matte=ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA ? MagickTrue : MagickFalse; @@ -3088,55 +3092,32 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, { for (x=(ssize_t) image->columns-1; x >= 0; x--) { -#if (MAGICKCORE_QUANTUM_DEPTH == 16) +#if (MAGICKCORE_QUANTUM_DEPTH == 16) || (MAGICKCORE_QUANTUM_DEPTH == 32) size_t quantum; if (image->colors > 256) - *r=((*p++) << 8); + quantum=((*p++) << 8); else - *r=0; + quantum=0; - quantum=(*r); quantum|=(*p++); - *r=(Quantum) quantum; - r++; - - if (ping_color_type == 4) - { - quantum=((*p++) << 8); - quantum|=(*p++); - SetPixelAlpha(q,quantum); - if (GetPixelOpacity(q) != OpaqueOpacity) - found_transparent_pixel = MagickTrue; - q++; - } -#else -#if (MAGICKCORE_QUANTUM_DEPTH == 32) - size_t - quantum; - - if (image->colors > 256) - *r=((*p++) << 8); - - else - *r=0; - quantum=(*r); - quantum|=(*p++); - *r=quantum; + *r=ScaleShortToQuantum(quantum); r++; if (ping_color_type == 4) { - quantum=(*p << 8) | *(p+1); - quantum*=65537L; - SetPixelOpacity(q, - (Quantum) GetPixelAlpha(q)); + if (image->colors > 256) + quantum=((*p++) << 8); + else + quantum=0; + + quantum|=(*p++); + SetPixelAlpha(q,ScaleShortToQuantum(quantum)); if (GetPixelOpacity(q) != OpaqueOpacity) found_transparent_pixel = MagickTrue; - p+=2; q++; } @@ -3152,7 +3133,6 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, p++; q++; } -#endif #endif } -- 2.40.0