#endif
#if !defined(RGBColorMatchExact)
#define IsPNGColorEqual(color,target) \
- (((color).red == (target).red) && \
- ((color).green == (target).green) && \
- ((color).blue == (target).blue))
+ (((color).red == (target).red) && \
+ ((color).green == (target).green) && \
+ ((color).blue == (target).blue))
#endif
+/* Convenience macros for copying RGB or RGB+opacity components
+ * between a pixel and a PixelPacket.
+ */
+
+#define GetRGBOPixelComponents(pixel, packet) \
+ (packet).red = GetRedPixelComponent((pixel)); \
+ (packet).green = GetGreenPixelComponent((pixel)); \
+ (packet).red = GetBluePixelComponent((pixel)); \
+ (packet).opacity = GetOpacityPixelComponent((pixel)); \
+
+#define SetRGBOPixelComponents(pixel, packet) \
+ SetRedPixelComponent((pixel),(packet).red); \
+ SetGreenPixelComponent((pixel),(packet).green); \
+ SetBluePixelComponent((pixel),(packet).blue); \
+ SetOpacityPixelComponent((pixel),(packet).opacity); \
+
+
+#define GetRGBPixelComponents(pixel, packet) \
+ (packet).red = GetRedPixelComponent((pixel)); \
+ (packet).green = GetGreenPixelComponent((pixel)); \
+ (packet).red = GetBluePixelComponent((pixel));
+
+#define SetRGBPixelComponents(pixel, packet) \
+ SetRedPixelComponent((pixel),(packet).red); \
+ SetGreenPixelComponent((pixel),(packet).green); \
+ SetBluePixelComponent((pixel),(packet).blue);
+
/*
Establish thread safety.
setjmp/longjmp is claimed to be safe on these platforms:
background.blue=(png_uint_16)
mng_info->global_plte[background.index].blue;
+ background.gray=(png_uint_16)
+ mng_info->global_plte[background.index].green;
+
png_set_bKGD(ping,ping_info,&background);
}
#endif
r=quantum_scanline;
for (x=0; x < (ssize_t) image->columns; x++)
- indexes[x]=(IndexPacket) (*r++);
+ SetIndexPixelComponent(indexes+x,*r++);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if ((image->previous == (Image *) NULL) && (num_passes == 1))
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
- image->rows);
+ image->rows);
if (status == MagickFalse)
break;
#if 0 /* I have not found a case where this is needed. */
else
{
- q->opacity=(Quantum) OpaqueOpacity;
+ SetOpacityPixelComponent(q)=(Quantum) OpaqueOpacity;
}
#endif
if (image->matte != MagickFalse)
for (x=(ssize_t) image->columns; x != 0; x--,q++,s++)
- q->opacity=(Quantum) QuantumRange-
- GetRedPixelComponent(s);
+ SetOpacityPixelComponent(q,(Quantum) QuantumRange-
+ GetRedPixelComponent(s));
else
for (x=(ssize_t) image->columns; x != 0; x--,q++,s++)
pixels=prev;
n=next;
q=GetAuthenticPixels(large_image,0,yy,large_image->columns,
- 1,exception);
+ 1,exception);
q+=(large_image->columns-image->columns);
for (x=(ssize_t) image->columns-1; x >= 0; x--)
*pixels;
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
+ /* To do: Rewrite using Get/Set***PixelComponent() */
pixels=q+(image->columns-length);
n=pixels+1;
if (magn_methx <= 1)
{
/* replicate previous */
+ /* To do: Rewrite using Get/Set***PixelComponent() */
*q=(*pixels);
}
" storage_class=PseudoClass");
}
- if (image->storage_class != PseudoClass && image->colormap != NULL)
+ if (ping_preserve_colormap == MagickFalse)
{
- /* Free the bogus colormap; it can cause trouble later */
- if (logging != MagickFalse)
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Freeing bogus colormap");
- (void *) RelinquishMagickMemory(image->colormap);
- image->colormap=NULL;
+ if (image->storage_class != PseudoClass && image->colormap != NULL)
+ {
+ /* Free the bogus colormap; it can cause trouble later */
+ if (logging != MagickFalse)
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " Freeing bogus colormap");
+ (void *) RelinquishMagickMemory(image->colormap);
+ image->colormap=NULL;
+ }
}
if (image->colorspace != RGBColorspace)
for (x=0; x < (ssize_t) image->columns; x++)
{
- if (image->matte == MagickFalse || q->opacity == OpaqueOpacity)
+ if (image->matte == MagickFalse ||
+ GetOpacityPixelComponent(q) == OpaqueOpacity)
{
if (number_opaque < 259)
{
if (number_opaque == 0)
{
- opaque[0]=*q;
+ GetRGBPixelComponents(q, opaque[0]);
opaque[0].opacity=OpaqueOpacity;
number_opaque=1;
}
for (i=0; i< (ssize_t) number_opaque; i++)
{
- if (IsColorEqual(opaque+i, (PixelPacket *) q))
+ if (IsColorEqual(q, opaque+i))
break;
}
number_opaque < 259)
{
number_opaque++;
- opaque[i] = *q;
- opaque[i].opacity = OpaqueOpacity;
+ GetRGBPixelComponents(q, opaque[i]);
+ opaque[i].opacity=OpaqueOpacity;
}
}
}
{
if (number_transparent == 0)
{
- transparent[0]=*q;
+ GetRGBOPixelComponents(q, transparent[0]);
ping_trans_color.red=
(unsigned short) GetRedPixelComponent(q);
ping_trans_color.green=
for (i=0; i< (ssize_t) number_transparent; i++)
{
- if (IsColorEqual(transparent+i, (PixelPacket *) q))
+ if (IsColorEqual(q, transparent+i))
break;
}
number_transparent < 259)
{
number_transparent++;
- transparent[i] = *q;
+ GetRGBOPixelComponents(q, transparent[i]);
}
}
}
{
if (number_semitransparent == 0)
{
- semitransparent[0]=*q;
+ GetRGBOPixelComponents(q, semitransparent[0]);
number_semitransparent = 1;
}
for (i=0; i< (ssize_t) number_semitransparent; i++)
{
- if (IsColorEqual(semitransparent+i,
- (PixelPacket *) q) &&
- q->opacity == semitransparent[i].opacity)
+ if (IsColorEqual(q, semitransparent+i)
+ && GetOpacityPixelComponent(q) ==
+ semitransparent[i].opacity)
break;
}
number_semitransparent < 259)
{
number_semitransparent++;
- semitransparent[i] = *q;
+ GetRGBOPixelComponents(q, semitransparent[i]);
}
}
}
/* Add the background color to the palette, if it
* isn't already there.
*/
+ if (logging != MagickFalse)
+ {
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " Check colormap for background (%d,%d,%d)",
+ (int) image->background_color.red,
+ (int) image->background_color.green,
+ (int) image->background_color.blue);
+ }
for (i=0; i<number_opaque; i++)
{
- if (IsColorEqual(opaque+i, &image->background_color))
- break;
+ if (opaque[i].red == image->background_color.red &&
+ opaque[i].green == image->background_color.green &&
+ opaque[i].blue == image->background_color.blue)
+ break;
}
-
if (number_opaque < 259 && i == number_opaque)
{
- opaque[i]=image->background_color;
- opaque[i].opacity = OpaqueOpacity;
- number_opaque++;
+ opaque[i] = image->background_color;
+ ping_background.index = i;
+ if (logging != MagickFalse)
+ {
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " background_color index is %d",(int) i);
+ }
+
}
else if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
for (i=0; i<number_opaque; i++)
colormap[n++] = opaque[i];
+ ping_background.index +=
+ (number_transparent + number_semitransparent);
/* image_colors < 257; search the colormap instead of the pixels
* to get ping_have_color and ping_have_non_bw
for (i=0; i< (ssize_t) image_colors; i++)
{
if ((image->matte == MagickFalse ||
- image->colormap[i].opacity == q->opacity) &&
- (IsColorEqual(&image->colormap[i],
- (PixelPacket *) q)))
+ image->colormap[i].opacity ==
+ GetOpacityPixelComponent(q)) &&
+ image->colormap[i].red ==
+ GetRedPixelComponent(q) &&
+ image->colormap[i].green ==
+ GetGreenPixelComponent(q) &&
+ image->colormap[i].blue ==
+ GetBluePixelComponent(q))
{
- indexes[x]=(IndexPacket) i;
+ SetIndexPixelComponent(indexes+x,i);
break;
}
}
for (x=0; x < (ssize_t) image->columns; x++)
{
- if (r->opacity == TransparentOpacity)
+ if (GetOpacityPixelComponent(r) == TransparentOpacity)
{
- r->red = image->background_color.red;
- r->green = image->background_color.green;
- r->blue = image->background_color.blue;
+ SetRGBPixelComponents(r,image->background_color);
}
else
{
- r->red=ScaleCharToQuantum(
- (ScaleQuantumToChar(r->red) & 0xf0) |
- (ScaleQuantumToChar(r->red) & 0xf0) >> 4);
- r->green=ScaleCharToQuantum(
- (ScaleQuantumToChar(r->green) & 0xf0) |
- (ScaleQuantumToChar(r->green) & 0xf0) >> 4);
- r->blue=ScaleCharToQuantum(
- (ScaleQuantumToChar(r->blue) & 0xf0) |
- (ScaleQuantumToChar(r->blue) & 0xf0) >> 4);
+ SetRedPixelComponent(r,ScaleCharToQuantum(
+ (ScaleQuantumToChar(GetRedPixelComponent(r)) & 0xf0) |
+ (ScaleQuantumToChar(GetRedPixelComponent(r)) & 0xf0) >> 4));
+ SetGreenPixelComponent(r,ScaleCharToQuantum(
+ (ScaleQuantumToChar(GetGreenPixelComponent(r)) & 0xf0) |
+ (ScaleQuantumToChar(GetGreenPixelComponent(r)) & 0xf0) >>
+ 4));
+ SetBluePixelComponent(r,ScaleCharToQuantum(
+ (ScaleQuantumToChar(GetBluePixelComponent(r)) & 0xf0) |
+ (ScaleQuantumToChar(GetBluePixelComponent(r)) & 0xf0) >>
+ 4));
}
r++;
}
for (x=0; x < (ssize_t) image->columns; x++)
{
- if (r->opacity == TransparentOpacity)
+ if (GetOpacityPixelComponent(r) == TransparentOpacity)
{
- r->red = image->background_color.red;
- r->green = image->background_color.green;
- r->blue = image->background_color.blue;
+ SetRGBPixelComponents(r,image->background_color);
}
else
{
- r->red=ScaleCharToQuantum(
- (ScaleQuantumToChar(r->red) & 0xe0) |
- (ScaleQuantumToChar(r->red) & 0xe0) >> 3 |
- (ScaleQuantumToChar(r->red) & 0xc0) >> 6);
- r->green=ScaleCharToQuantum(
- (ScaleQuantumToChar(r->green) & 0xe0) |
- (ScaleQuantumToChar(r->green) & 0xe0) >> 3 |
- (ScaleQuantumToChar(r->green) & 0xc0) >> 6);
- r->blue=ScaleCharToQuantum(
- (ScaleQuantumToChar(r->blue) & 0xe0) |
- (ScaleQuantumToChar(r->blue) & 0xe0) >> 3 |
- (ScaleQuantumToChar(r->blue) & 0xc0) >> 6);
+ SetRedPixelComponent(r,ScaleCharToQuantum(
+ (ScaleQuantumToChar(GetRedPixelComponent(r)) & 0xe0) |
+ (ScaleQuantumToChar(GetRedPixelComponent(r)) & 0xe0) >> 3 |
+ (ScaleQuantumToChar(GetRedPixelComponent(r)) & 0xc0) >>
+ 6));
+ SetGreenPixelComponent(r,ScaleCharToQuantum(
+ (ScaleQuantumToChar(GetGreenPixelComponent(r)) & 0xe0) |
+ (ScaleQuantumToChar(GetGreenPixelComponent(r)) & 0xe0) >>
+ 3 |
+ (ScaleQuantumToChar(GetGreenPixelComponent(r)) & 0xc0) >>
+ 6));
+ SetBluePixelComponent(r,ScaleCharToQuantum(
+ (ScaleQuantumToChar(GetBluePixelComponent(r)) & 0xe0) |
+ (ScaleQuantumToChar(GetBluePixelComponent(r)) & 0xe0) >> 3 |
+ (ScaleQuantumToChar(GetBluePixelComponent(r)) & 0xc0) >>
+ 6));
}
r++;
}
for (x=0; x < (ssize_t) image->columns; x++)
{
- if (r->opacity == TransparentOpacity)
+ if (GetOpacityPixelComponent(r) == TransparentOpacity)
{
- r->red = image->background_color.red;
- r->green = image->background_color.green;
- r->blue = image->background_color.blue;
+ SetRGBPixelComponents(r,image->background_color);
}
else
{
- r->blue=ScaleCharToQuantum(
- (ScaleQuantumToChar(r->blue) & 0xc0) |
- (ScaleQuantumToChar(r->blue) & 0xc0) >> 2 |
- (ScaleQuantumToChar(r->blue) & 0xc0) >> 4 |
- (ScaleQuantumToChar(r->blue) & 0xc0) >> 6);
+ SetBluePixelComponent(r,ScaleCharToQuantum(
+ (ScaleQuantumToChar(GetBluePixelComponent(r)) & 0xc0) |
+ (ScaleQuantumToChar(GetBluePixelComponent(r)) & 0xc0) >> 2 |
+ (ScaleQuantumToChar(GetBluePixelComponent(r)) & 0xc0) >> 4 |
+ (ScaleQuantumToChar(GetBluePixelComponent(r)) & 0xc0) >>
+ 6));
}
r++;
}
if (mng_info->ping_exclude_tRNS != MagickFalse &&
(number_transparent != 0 || number_semitransparent != 0))
{
- int colortype=mng_info->write_png_colortype;
+ unsigned int colortype=mng_info->write_png_colortype;
if (ping_have_color == MagickFalse)
mng_info->write_png_colortype = 5;
mng_info->write_png_colortype = 7;
if (colortype != 0 &&
- mng_info->write_png_colortype != (ssize_t) colortype)
+ mng_info->write_png_colortype != colortype)
ping_need_colortype_warning=MagickTrue;
}
ping_background.blue=(png_uint_16)
(ScaleQuantumToShort(image->background_color.blue) & mask);
+
+ ping_background.gray=(png_uint_16) ping_background.green;
}
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Setting up bKGD chunk (1)");
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " background_color index is %d",
+ (int) ping_background.index);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" ping_bit_depth=%d",ping_bit_depth);
break;
ping_background.index=(png_byte) i;
+
+ if (logging != MagickFalse)
+ {
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " background_color index is %d",
+ (int) ping_background.index);
+ }
}
} /* end of write_png8 */
if (image_depth > MAGICKCORE_QUANTUM_DEPTH)
image_depth=MAGICKCORE_QUANTUM_DEPTH;
- if ((image_colors == 0) || ((ssize_t) (image_colors-1) > MaxColormapSize))
+ if ((image_colors == 0) ||
+ ((ssize_t) (image_colors-1) > (ssize_t) MaxColormapSize))
image_colors=(int) (one << image_depth);
if (image_depth > 8)
ping_bit_depth=1;
one=1;
- while ((one << ping_bit_depth) < number_colors)
+ while ((one << ping_bit_depth) < (ssize_t) number_colors)
ping_bit_depth <<= 1;
}
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Setting up bKGD chunk (2)");
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " background_color index is %d",
+ (int) ping_background.index);
ping_have_bKGD = MagickTrue;
}
if (ping_exclude_bKGD == MagickFalse)
{
if (ping_have_bKGD != MagickFalse)
+ {
png_set_bKGD(ping,ping_info,&ping_background);
+ if (logging)
+ {
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " Setting up bKGD chunk");
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " background color = (%d,%d,%d)",
+ (int) ping_background.red,
+ (int) ping_background.green,
+ (int) ping_background.blue);
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " index = %d, gray=%d",
+ (int) ping_background.index,
+ (int) ping_background.gray);
+ }
+ }
}
if (ping_exclude_pHYs == MagickFalse)