/* ImageMagick differences */
#define first_scene scene
-#if PNG_LIBPNG_VER > 10011
+#if PNG_LIBPNG_VER < 10400
+# define trans_color trans_values /* Changed at libpng-1.4.0beta35 */
+# define trans_alpha trans /* Changed at libpng-1.4.0beta74 */
+#else
+ /* We could parse PNG_LIBPNG_VER_STRING here but it's too much bother..
+ * Just don't use libpng-1.4.0beta32-34 or beta67-73
+ */
+# ifndef PNG_USER_CHUNK_CACHE_MAX /* Added at libpng-1.4.0beta32 */
+# define trans_color trans_values /* Changed at libpng-1.4.0beta35 */
+# endif
+# ifndef PNG_TRANSFORM_GRAY_TO_RGB /* Added at libpng-1.4.0beta67 */
+# define trans_alpha trans /* Changed at libpng-1.4.0beta74 */
+# endif
+#endif
+
+#if PNG_LIBPNG_VER > 95
/*
Optional declarations. Define or undefine them as you like.
*/
PNG_MNG_FEATURES_SUPPORTED is disabled by default in libpng-1.0.9 and
will be enabled by default in libpng-1.2.0.
*/
+#if (PNG_LIBPNG_VER == 10009) /* work around libpng-1.0.9 bug */
+# undef PNG_READ_EMPTY_PLTE_SUPPORTED
+# undef PNG_WRITE_EMPTY_PLTE_SUPPORTED
+#endif
#ifdef PNG_MNG_FEATURES_SUPPORTED
# ifndef PNG_READ_EMPTY_PLTE_SUPPORTED
# define PNG_READ_EMPTY_PLTE_SUPPORTED
return(y);
}
\f
-#if PNG_LIBPNG_VER > 10111
+#if PNG_LIBPNG_VER > 95
#if defined(PNG_SORT_PALETTE)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
}
return(MagickTrue);
}
-#endif /* PNG_LIBPNG_VER > 10011 */
+#endif /* PNG_LIBPNG_VER > 95 */
#endif /* MAGICKCORE_PNG_DELEGATE */
\f
/*
extern "C" {
#endif
-#if (PNG_LIBPNG_VER > 10011)
+#if (PNG_LIBPNG_VER > 95)
static size_t WriteBlobMSBULong(Image *image,const unsigned long value)
{
unsigned char
" Writing %c%c%c%c chunk, length: %lu",
type[0],type[1],type[2],type[3],(unsigned long) length);
}
-#endif /* PNG_LIBPNG_VER > 10011 */
+#endif /* PNG_LIBPNG_VER > 95 */
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
-#if PNG_LIBPNG_VER > 10011
+#if PNG_LIBPNG_VER > 95
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
logging,
num_text,
num_passes,
- pass,
- ping_info_bit_depth,
- ping_info_color_type,
- ping_info_interlace_method,
- ping_info_compression_method,
- ping_info_filter_method,
- ping_info_num_trans;
+ pass;
MagickBooleanType
status;
PixelPacket
transparent_color;
- png_bytep
- ping_trans_alpha;
-
- png_color_16p
- ping_background,
- ping_trans_color;
-
png_info
*end_info,
*ping_info;
png_struct
*ping;
- png_uint_32
- ping_info_height,
- ping_info_width,
- ping_rowbytes;
-
png_textp
text;
/*
Prepare PNG for reading.
*/
-
mng_info->image_found++;
png_set_sig_bytes(ping,8);
if (LocaleCompare(image_info->magick,"MNG") == 0)
#endif
png_read_info(ping,ping_info);
-
- png_get_IHDR(ping,ping_info,&ping_info_width,&ping_info_height,
- &ping_info_bit_depth,&ping_info_color_type,
- &ping_info_interlace_method,&ping_info_compression_method,
- &ping_info_filter_method);
-
- (void) png_get_tRNS(ping, ping_info, &ping_trans_alpha, &ping_info_num_trans,
- &ping_trans_color);
-
- (void) png_get_bKGD(ping, ping_info, &ping_background);
-
- ping_rowbytes=png_get_rowbytes(ping,ping_info);
-
- if (ping_info_bit_depth < 8)
+ if (ping_info->bit_depth < 8)
{
- if (((int) ping_info_color_type == PNG_COLOR_TYPE_PALETTE))
+ if (((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE))
png_set_packing(ping);
}
- image->depth=ping_info_bit_depth;
+ image->depth=ping_info->bit_depth;
image->depth=GetImageQuantumDepth(image,MagickFalse);
- image->interlace=ping_info_interlace_method != 0 ? PNGInterlace : NoInterlace;
+ image->interlace=ping_info->interlace_type != 0 ? PNGInterlace : NoInterlace;
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" PNG width: %lu, height: %lu",
- ping_info_width, ping_info_height);
+ ping_info->width, ping_info->height);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" PNG color_type: %d, bit_depth: %d",
- ping_info_color_type, ping_info_bit_depth);
+ ping_info->color_type, ping_info->bit_depth);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" PNG compression_method: %d",
- ping_info_compression_method);
+ ping_info->compression_type);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" PNG interlace_method: %d, filter_method: %d",
- ping_info_interlace_method,ping_info_filter_method);
+ ping_info->interlace_type,ping_info->filter_type);
}
#if (PNG_LIBPNG_VER > 10008) && defined(PNG_READ_iCCP_SUPPORTED)
- if (png_get_valid(ping,ping_info,PNG_INFO_iCCP))
+ if (ping_info->valid & PNG_INFO_iCCP)
{
int
compression;
double
file_gamma;
- if (!png_get_gAMA(ping,ping_info,&file_gamma))
- if (mng_info->have_global_gama)
- png_set_gAMA(ping,ping_info,mng_info->global_gamma);
+ if (mng_info->have_global_gama)
+ image->gamma=mng_info->global_gamma;
if (png_get_gAMA(ping,ping_info,&file_gamma))
{
image->gamma=(float) file_gamma;
" Reading PNG gAMA chunk: gamma: %f",file_gamma);
}
}
- if (!png_get_valid(ping,ping_info,PNG_INFO_cHRM))
- {
- if (mng_info->have_global_chrm != MagickFalse)
- {
- (void) png_set_cHRM(ping,ping_info,
- mng_info->global_chrm.white_point.x,
- mng_info->global_chrm.white_point.y,
- mng_info->global_chrm.red_primary.x,
- mng_info->global_chrm.red_primary.y,
- mng_info->global_chrm.green_primary.x,
- mng_info->global_chrm.green_primary.y,
- mng_info->global_chrm.blue_primary.x,
- mng_info->global_chrm.blue_primary.y);
- }
- }
- if (png_get_valid(ping,ping_info,PNG_INFO_cHRM))
+ if (mng_info->have_global_chrm != MagickFalse)
+ image->chromaticity=mng_info->global_chrm;
+ if (ping_info->valid & PNG_INFO_cHRM)
{
(void) png_get_cHRM(ping,ping_info,
&image->chromaticity.white_point.x,
}
if (image->rendering_intent)
{
- png_set_sRGB(ping,ping_info,image->rendering_intent-1);
- png_set_gAMA(ping,ping_info,0.45455f);
- png_set_cHRM(ping,ping_info,
- 0.6400f, 0.3300f, 0.3000f, 0.6000f,
- 0.1500f, 0.0600f, 0.3127f, 0.3290f);
+ image->gamma=0.45455f;
+ image->chromaticity.red_primary.x=0.6400f;
+ image->chromaticity.red_primary.y=0.3300f;
+ image->chromaticity.green_primary.x=0.3000f;
+ image->chromaticity.green_primary.y=0.6000f;
+ image->chromaticity.blue_primary.x=0.1500f;
+ image->chromaticity.blue_primary.y=0.0600f;
+ image->chromaticity.white_point.x=0.3127f;
+ image->chromaticity.white_point.y=0.3290f;
}
+ if ((mng_info->have_global_gama != MagickFalse) || image->rendering_intent)
+ ping_info->valid|=PNG_INFO_gAMA;
+ if ((mng_info->have_global_chrm != MagickFalse) || image->rendering_intent)
+ ping_info->valid|=PNG_INFO_cHRM;
#if defined(PNG_oFFs_SUPPORTED)
- if (png_get_valid(ping,ping_info,PNG_INFO_oFFs))
+ if (ping_info->valid & PNG_INFO_oFFs)
{
image->page.x=png_get_x_offset_pixels(ping, ping_info);
image->page.y=png_get_y_offset_pixels(ping, ping_info);
}
#endif
#if defined(PNG_pHYs_SUPPORTED)
- if (!png_get_valid(ping,ping_info,PNG_INFO_pHYs))
- {
- if (mng_info->have_global_phys)
- {
- png_set_pHYs(ping,ping_info,
- mng_info->global_x_pixels_per_unit,
- mng_info->global_y_pixels_per_unit,
- mng_info->global_phys_unit_type);
- }
- }
-
- if (png_get_valid(ping,ping_info,PNG_INFO_pHYs))
+ if (ping_info->valid & PNG_INFO_pHYs)
{
int
unit_type;
" Reading PNG pHYs chunk: xres: %lu, yres: %lu, units: %d.",
x_resolution, y_resolution, unit_type);
}
+ else
+ {
+ if (mng_info->have_global_phys)
+ {
+ image->x_resolution=(float) mng_info->global_x_pixels_per_unit;
+ image->y_resolution=(float) mng_info->global_y_pixels_per_unit;
+ if (mng_info->global_phys_unit_type == PNG_RESOLUTION_METER)
+ {
+ image->units=PixelsPerCentimeterResolution;
+ image->x_resolution=(double)
+ mng_info->global_x_pixels_per_unit/100.0;
+ image->y_resolution=(double)
+ mng_info->global_y_pixels_per_unit/100.0;
+ }
+ ping_info->valid|=PNG_INFO_pHYs;
+ }
+ }
#endif
- if (png_get_valid(ping,ping_info,PNG_INFO_PLTE))
+ if (ping_info->valid & PNG_INFO_PLTE)
{
int
number_colors;
(void) png_get_PLTE(ping,ping_info,&palette,&number_colors);
if ((number_colors == 0) &&
- ((int) ping_info_color_type == PNG_COLOR_TYPE_PALETTE))
+ ((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE))
{
if (mng_info->global_plte_length)
{
png_set_PLTE(ping,ping_info,mng_info->global_plte,
(int) mng_info->global_plte_length);
- if (!png_get_valid(ping,ping_info,PNG_INFO_tRNS))
+ if ((ping_info->valid & PNG_INFO_tRNS) == 0)
if (mng_info->global_trns_length)
{
if (mng_info->global_trns_length >
#ifndef PNG_READ_EMPTY_PLTE_SUPPORTED
mng_info->have_saved_bkgd_index ||
#endif
- png_get_valid(ping,ping_info,PNG_INFO_bKGD))
+ ping_info->valid & PNG_INFO_bKGD)
{
png_color_16
background;
#ifndef PNG_READ_EMPTY_PLTE_SUPPORTED
if (mng_info->have_saved_bkgd_index)
background.index=mng_info->saved_bkgd_index;
+ else
#endif
- if (png_get_valid(ping, ping_info, PNG_INFO_bKGD))
- background.index=ping_background->index;
+ background.index=ping_info->background.index;
background.red=(png_uint_16)
mng_info->global_plte[background.index].red;
background.green=(png_uint_16)
}
#if defined(PNG_READ_bKGD_SUPPORTED)
- if (mng_info->have_global_bkgd &&
- (!png_get_valid(ping,ping_info,PNG_INFO_bKGD)))
+ if (mng_info->have_global_bkgd && !(ping_info->valid & PNG_INFO_bKGD))
image->background_color=mng_info->mng_global_bkgd;
- if (png_get_valid(ping,ping_info,PNG_INFO_bKGD))
+ if (ping_info->valid & PNG_INFO_bKGD)
{
/*
Set image background color.
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Reading PNG bKGD chunk.");
- if (ping_info_bit_depth <= MAGICKCORE_QUANTUM_DEPTH)
+ if (ping_info->bit_depth <= MAGICKCORE_QUANTUM_DEPTH)
{
- image->background_color.red=ping_background->red;
- image->background_color.green=ping_background->green;
- image->background_color.blue=ping_background->blue;
+ image->background_color.red=ping_info->background.red;
+ image->background_color.green=ping_info->background.green;
+ image->background_color.blue=ping_info->background.blue;
}
else
{
image->background_color.red=
- ScaleShortToQuantum(ping_background->red);
+ ScaleShortToQuantum(ping_info->background.red);
image->background_color.green=
- ScaleShortToQuantum(ping_background->green);
+ ScaleShortToQuantum(ping_info->background.green);
image->background_color.blue=
- ScaleShortToQuantum(ping_background->blue);
+ ScaleShortToQuantum(ping_info->background.blue);
}
}
#endif
transparent_color.green=0;
transparent_color.blue=0;
transparent_color.opacity=0;
- if (png_get_valid(ping,ping_info,PNG_INFO_tRNS))
+ if (ping_info->valid & PNG_INFO_tRNS)
{
/*
Image has a transparent background.
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Reading PNG tRNS chunk.");
- max_sample = (1 << ping_info_bit_depth) - 1;
+ max_sample = (1 << ping_info->bit_depth) - 1;
- if ((ping_info_color_type == PNG_COLOR_TYPE_GRAY &&
- (int)ping_trans_color->gray > max_sample) ||
- (ping_info_color_type == PNG_COLOR_TYPE_RGB &&
- ((int)ping_trans_color->red > max_sample ||
- (int)ping_trans_color->green > max_sample ||
- (int)ping_trans_color->blue > max_sample)))
+ if ((ping_info->color_type == PNG_COLOR_TYPE_GRAY &&
+ (int)ping_info->trans_color.gray > max_sample) ||
+ (ping_info->color_type == PNG_COLOR_TYPE_RGB &&
+ ((int)ping_info->trans_color.red > max_sample ||
+ (int)ping_info->trans_color.green > max_sample ||
+ (int)ping_info->trans_color.blue > max_sample)))
{
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Ignoring PNG tRNS chunk with out-of-range sample.");
+#if (PNG_LIBPNG_VER < 10007)
+ ping_info->trans_alpha=(unsigned char *) RelinquishMagickMemory(
+ ping_info->trans_alpha);
+ ping_info->valid&=(~PNG_INFO_tRNS);
+#else
png_free_data(ping, ping_info, PNG_FREE_TRNS, 0);
+#endif
image->matte=MagickFalse;
}
else
{
- transparent_color.red= (Quantum)(ping_trans_color->red);
- transparent_color.green= (Quantum) (ping_trans_color->green);
- transparent_color.blue= (Quantum) (ping_trans_color->blue);
- transparent_color.opacity= (Quantum) (ping_trans_color->gray);
- if (ping_info_color_type == PNG_COLOR_TYPE_GRAY)
+ transparent_color.red= (Quantum)(ping_info->trans_color.red);
+ transparent_color.green= (Quantum) (ping_info->trans_color.green);
+ transparent_color.blue= (Quantum) (ping_info->trans_color.blue);
+ transparent_color.opacity= (Quantum) (ping_info->trans_color.gray);
+ if (ping_info->color_type == PNG_COLOR_TYPE_GRAY)
{
- if (ping_info_bit_depth < 8)
+ if (ping_info->bit_depth < 8)
{
transparent_color.opacity=(Quantum) (((
- ping_trans_color->gray)*255)/max_sample);
+ ping_info->trans_color.gray)*255)/max_sample);
}
transparent_color.red=transparent_color.opacity;
transparent_color.green=transparent_color.opacity;
#if defined(PNG_READ_sBIT_SUPPORTED)
if (mng_info->have_global_sbit)
{
- if (!png_get_valid(ping,ping_info,PNG_INFO_sBIT))
+ if (!(ping_info->valid & PNG_INFO_sBIT))
png_set_sBIT(ping,ping_info,&mng_info->global_sbit);
}
#endif
Initialize image structure.
*/
mng_info->image_box.left=0;
- mng_info->image_box.right=(long) ping_info_width;
+ mng_info->image_box.right=(long) ping_info->width;
mng_info->image_box.top=0;
- mng_info->image_box.bottom=(long) ping_info_height;
+ mng_info->image_box.bottom=(long) ping_info->height;
if (mng_info->mng_type == 0)
{
- mng_info->mng_width=ping_info_width;
- mng_info->mng_height=ping_info_height;
+ mng_info->mng_width=ping_info->width;
+ mng_info->mng_height=ping_info->height;
mng_info->frame=mng_info->image_box;
mng_info->clip=mng_info->image_box;
}
image->page.y=mng_info->y_off[mng_info->object_id];
}
image->compression=ZipCompression;
- image->columns=ping_info_width;
- image->rows=ping_info_height;
- if (((int) ping_info_color_type == PNG_COLOR_TYPE_PALETTE) ||
- ((int) ping_info_color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ||
- ((int) ping_info_color_type == PNG_COLOR_TYPE_GRAY))
+ image->columns=ping_info->width;
+ image->rows=ping_info->height;
+ if (((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE) ||
+ ((int) ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ||
+ ((int) ping_info->color_type == PNG_COLOR_TYPE_GRAY))
{
image->storage_class=PseudoClass;
- image->colors=1UL << ping_info_bit_depth;
+ image->colors=1UL << ping_info->bit_depth;
#if (MAGICKCORE_QUANTUM_DEPTH == 8)
if (image->colors > 256)
image->colors=256;
if (image->colors > 65536L)
image->colors=65536L;
#endif
- if ((int) ping_info_color_type == PNG_COLOR_TYPE_PALETTE)
+ if ((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE)
{
int
number_colors;
*/
if (AcquireImageColormap(image,image->colors) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- if ((int) ping_info_color_type == PNG_COLOR_TYPE_PALETTE)
+ if ((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE)
{
int
number_colors;
unsigned long
scale;
- scale=(QuantumRange/((1UL << ping_info_bit_depth)-1));
+ scale=(QuantumRange/((1UL << ping_info->bit_depth)-1));
if (scale < 1)
scale=1;
for (i=0; i < (long) image->colors; i++)
" Reading PNG IDAT chunk(s)");
if (num_passes > 1)
png_pixels=(unsigned char *) AcquireQuantumMemory(image->rows,
- ping_rowbytes*sizeof(*png_pixels));
+ ping_info->rowbytes*sizeof(*png_pixels));
else
- png_pixels=(unsigned char *) AcquireQuantumMemory(ping_rowbytes,
+ png_pixels=(unsigned char *) AcquireQuantumMemory(ping_info->rowbytes,
sizeof(*png_pixels));
if (png_pixels == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
int
depth;
- depth=(long) ping_info_bit_depth;
+ depth=(long) ping_info->bit_depth;
#endif
- image->matte=(((int) ping_info_color_type == PNG_COLOR_TYPE_RGB_ALPHA) ||
- ((int) ping_info_color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ||
- (png_get_valid(ping,ping_info,PNG_INFO_tRNS))) ?
- MagickTrue : MagickFalse;
+ image->matte=(((int) ping_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) ||
+ ((int) ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ||
+ (ping_info->valid & PNG_INFO_tRNS)) ? MagickTrue : MagickFalse;
for (y=0; y < (long) image->rows; y++)
{
if (num_passes > 1)
- row_offset=ping_rowbytes*y;
+ row_offset=ping_info->rowbytes*y;
else
row_offset=0;
png_read_row(ping,png_pixels+row_offset,NULL);
r=png_pixels+row_offset;
p=r;
- if (ping_info_color_type == PNG_COLOR_TYPE_GRAY)
+ if (ping_info->color_type == PNG_COLOR_TYPE_GRAY)
{
for (x=(long) image->columns-1; x >= 0; x--)
{
*r++=*p++;
p++;
- if (png_get_valid(ping,ping_info,PNG_INFO_tRNS)) &&
+ if ((ping_info->valid & PNG_INFO_tRNS) &&
(((*(p-2) << 8)|*(p-1)) == transparent_color.opacity))
{
/* Cheap transparency */
*r++=OpaqueOpacity;
}
}
- else if (ping_info_color_type == PNG_COLOR_TYPE_RGB)
+ else if (ping_info->color_type == PNG_COLOR_TYPE_RGB)
{
- if (png_get_valid(ping,ping_info,PNG_INFO_tRNS))
+ if (ping_info->valid & PNG_INFO_tRNS)
for (x=(long) image->columns-1; x >= 0; x--)
{
*r++=*p++;
*r++=OpaqueOpacity;
}
}
- else if (ping_info_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ else if (ping_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
for (x=(long) (4*image->columns); x != 0; x--)
{
*r++=*p++;
p++;
}
- else if (ping_info_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ else if (ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
for (x=(long) (2*image->columns); x != 0; x--)
{
*r++=*p++;
p++;
}
}
- if (depth == 8 && ping_info_color_type == PNG_COLOR_TYPE_GRAY)
+ if (depth == 8 && ping_info->color_type == PNG_COLOR_TYPE_GRAY)
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
GrayQuantum,png_pixels+row_offset);
- if (ping_info_color_type == PNG_COLOR_TYPE_GRAY ||
- ping_info_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ if (ping_info->color_type == PNG_COLOR_TYPE_GRAY ||
+ ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
quantum_info->depth=8;
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
GrayAlphaQuantum,png_pixels+row_offset);
}
- else if (depth == 8 && ping_info_color_type == PNG_COLOR_TYPE_RGB)
+ else if (depth == 8 && ping_info->color_type == PNG_COLOR_TYPE_RGB)
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
RGBQuantum,png_pixels+row_offset);
- else if (ping_info_color_type == PNG_COLOR_TYPE_RGB ||
- ping_info_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ else if (ping_info->color_type == PNG_COLOR_TYPE_RGB ||
+ ping_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
{
quantum_info->depth=8;
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
RGBAQuantum,png_pixels+row_offset);
}
- else if (ping_info_color_type == PNG_COLOR_TYPE_PALETTE)
+ else if (ping_info->color_type == PNG_COLOR_TYPE_PALETTE)
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
IndexQuantum,png_pixels+row_offset);
#else /* (MAGICKCORE_QUANTUM_DEPTH != 8) */
- if ((int) ping_info_color_type == PNG_COLOR_TYPE_GRAY)
+ if ((int) ping_info->color_type == PNG_COLOR_TYPE_GRAY)
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
GrayQuantum,png_pixels+row_offset,exception);
- else if ((int) ping_info_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ else if ((int) ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
GrayAlphaQuantum,png_pixels+row_offset,exception);
- else if ((int) ping_info_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ else if ((int) ping_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
RGBAQuantum,png_pixels+row_offset,exception);
- else if ((int) ping_info_color_type == PNG_COLOR_TYPE_PALETTE)
+ else if ((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE)
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
IndexQuantum,png_pixels+row_offset,exception);
else
/*
Convert grayscale image to PseudoClass pixel packets.
*/
- image->matte=ping_info_color_type == PNG_COLOR_TYPE_GRAY_ALPHA ?
+ image->matte=ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA ?
MagickTrue : MagickFalse;
quantum_scanline=(Quantum *) AcquireQuantumMemory(image->columns,
(image->matte ? 2 : 1)*sizeof(*quantum_scanline));
for (y=0; y < (long) image->rows; y++)
{
if (num_passes > 1)
- row_offset=ping_rowbytes*y;
+ row_offset=ping_info->rowbytes*y;
else
row_offset=0;
png_read_row(ping,png_pixels+row_offset,NULL);
indices=GetAuthenticIndexQueue(image);
p=png_pixels+row_offset;
r=quantum_scanline;
- switch (ping_info_bit_depth)
+ switch (ping_info->bit_depth)
{
case 1:
{
}
case 8:
{
- if (ping_info_color_type == 4)
+ if (ping_info->color_type == 4)
for (x=(long) image->columns-1; x >= 0; x--)
{
*r++=*p++;
quantum|=(*p++);
*r=(Quantum) quantum;
r++;
- if (ping_info_color_type == 4)
+ if (ping_info->color_type == 4)
{
quantum=((*p++) << 8);
quantum|=(*p++);
quantum|=(*p++);
*r=quantum;
r++;
- if (ping_info_color_type == 4)
+ if (ping_info->color_type == 4)
{
q->opacity=(*p << 8) | *(p+1);
q->opacity*=65537L;
#else /* MAGICKCORE_QUANTUM_DEPTH == 8 */
*r++=(*p++);
p++; /* strip low byte */
- if (ping_info_color_type == 4)
+ if (ping_info->color_type == 4)
{
q->opacity=(Quantum) (QuantumRange-(*p++));
p++;
" exit ReadOnePNGImage() early.");
return(image);
}
- if (png_get_valid(ping,ping_info,PNG_INFO_tRNS))
+ if (ping_info->valid & PNG_INFO_tRNS)
{
ClassType
storage_class;
if (storage_class == PseudoClass)
{
- if ((int) ping_info_color_type == PNG_COLOR_TYPE_PALETTE)
+ if ((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE)
{
- for (x=0; x < ping_info_num_trans; x++)
+ for (x=0; x < ping_info->num_trans; x++)
{
- image->colormap[x].opacity = ScaleCharToQuantum((unsigned char)(255-ping_trans_alpha[x]));
+ image->colormap[x].opacity = ScaleCharToQuantum((unsigned char)(255-ping_info->trans_alpha[x]));
}
}
- else if (ping_info_color_type == PNG_COLOR_TYPE_GRAY)
+ else if (ping_info->color_type == PNG_COLOR_TYPE_GRAY)
{
- for (x=0; x < (int) image->colors; x++)
+ for (x=0; x < image->colors; x++)
{
if (image->colormap[x].red == transparent_color.opacity)
{
IndexPacket
indexpacket;
- if ((int) ping_info_color_type == PNG_COLOR_TYPE_PALETTE)
+ if ((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE)
for (x=0; x < (long) image->columns; x++)
{
indexpacket=indices[x];
- if (indexpacket < ping_info_num_trans)
+ if (indexpacket < ping_info->num_trans)
q->opacity=ScaleCharToQuantum((unsigned char)
- (255-ping_trans_alpha[(long) indexpacket]));
+ (255-ping_info->trans_alpha[(long) indexpacket]));
else
SetOpacityPixelComponent(q,OpaqueOpacity);
q++;
}
- else if (ping_info_color_type == PNG_COLOR_TYPE_GRAY)
+ else if (ping_info->color_type == PNG_COLOR_TYPE_GRAY)
for (x=0; x < (long) image->columns; x++)
{
indexpacket=indices[x];
}
else
{
+ png_uint_32
+ width,
+ height;
+
+ int
+ bit_depth,
+ color_type,
+ interlace_method,
+ compression_method,
+ filter_method;
if (mng_info->ob[object_id]->image != (Image *) NULL)
mng_info->ob[object_id]->image=DestroyImage
(void) ThrowMagickException(&image->exception,GetMagickModule(),
ResourceLimitError,"Cloning image for object buffer failed",
"`%s'",image->filename);
- if (ping_info_width > 250000L || ping_info_height > 250000L)
+ png_get_IHDR(ping,ping_info,&width,&height,&bit_depth,&color_type,
+ &interlace_method,&compression_method,&filter_method);
+ if (width > 250000L || height > 250000L)
png_error(ping,"PNG Image dimensions are too large.");
- mng_info->ob[object_id]->width=ping_info_width;
- mng_info->ob[object_id]->height=ping_info_height;
- mng_info->ob[object_id]->color_type=ping_info_color_type;
- mng_info->ob[object_id]->sample_depth=ping_info_bit_depth;
- mng_info->ob[object_id]->interlace_method=ping_info_interlace_method;
- mng_info->ob[object_id]->compression_method=
- ping_info_compression_method;
- mng_info->ob[object_id]->filter_method=ping_info_filter_method;
- if (png_get_valid(ping,ping_info,PNG_INFO_PLTE))
+ mng_info->ob[object_id]->width=width;
+ mng_info->ob[object_id]->height=height;
+ mng_info->ob[object_id]->color_type=color_type;
+ mng_info->ob[object_id]->sample_depth=bit_depth;
+ mng_info->ob[object_id]->interlace_method=interlace_method;
+ mng_info->ob[object_id]->compression_method=compression_method;
+ mng_info->ob[object_id]->filter_method=filter_method;
+ if (ping_info->valid & PNG_INFO_PLTE)
{
int
number_colors;
num_passes,
pass;
- png_bytep
- ping_trans_alpha;
-
png_colorp
palette;
- png_color_16
- ping_background,
- ping_trans_color;
-
png_info
*ping_info;
png_struct
*ping;
- png_uint_32
- ping_info_height,
- ping_info_width;
-
long
y;
logging,
matte;
- volatile int
- ping_info_bit_depth,
- ping_info_color_type,
- ping_info_interlace_method,
- ping_info_compression_method,
- ping_info_filter_method,
- ping_info_num_trans;
-
volatile unsigned long
image_colors,
- image_depth,
- old_bit_depth;
+ image_depth;
unsigned long
+ old_bit_depth,
quality,
rowbytes,
save_image_depth;
LockSemaphoreInfo(png_semaphore);
#endif
- /* Initialize some stuff */
- ping_info_bit_depth=0,
- ping_info_color_type=0,
- ping_info_interlace_method=0,
- ping_info_compression_method=0,
- ping_info_filter_method=0,
- ping_info_num_trans = 0;
-
- ping_background.red = 0;
- ping_background.green = 0;
- ping_background.blue = 0;
- ping_background.gray = 0;
- ping_background.index = 0;
-
- ping_trans_color.red=0;
- ping_trans_color.green=0;
- ping_trans_color.blue=0;
- ping_trans_color.gray=0;
-
- ping_trans_alpha = NULL;
-
quantum_info = (QuantumInfo *) NULL;
image_colors=image->colors;
image_depth=image->depth;
# endif
#endif
x=0;
- ping_info_width=image->columns;
- ping_info_height=image->rows;
+ ping_info->width=image->columns;
+ ping_info->height=image->rows;
if (mng_info->write_png8 || mng_info->write_png24 || mng_info->write_png32)
image_depth=8;
if (mng_info->write_png_depth != 0)
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " width=%lu",ping_info_width);
+ " width=%lu",ping_info->width);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " height=%lu",ping_info_height);
+ " height=%lu",ping_info->height);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" image_matte=%u",image->matte);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" requested PNG image_depth=%lu",image->depth);
}
save_image_depth=image_depth;
- ping_info_bit_depth=(png_byte) save_image_depth;
+ ping_info->bit_depth=(png_byte) save_image_depth;
#if defined(PNG_pHYs_SUPPORTED)
if ((image->x_resolution != 0) && (image->y_resolution != 0) &&
(!mng_info->write_mng || !mng_info->equal_physs))
old_bit_depth=0;
if (mng_info->write_png8)
{
- ping_info_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
- ping_info_bit_depth=8;
- image_depth=ping_info_bit_depth;
+ ping_info->color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
+ ping_info->bit_depth=8;
+ image_depth=ping_info->bit_depth;
{
/* TO DO: make this a function cause it's used twice, except
for reducing the sample depth from 8. */
/*
Set image palette.
*/
- ping_info_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
+ ping_info->color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
ping_info->valid|=PNG_INFO_PLTE;
#if defined(PNG_SORT_PALETTE)
save_number_colors=image_colors;
#if (PNG_LIBPNG_VER > 10008)
palette=(png_colorp) RelinquishMagickMemory(palette);
#endif
- image_depth=ping_info_bit_depth;
- ping_info_num_trans=0;
+ image_depth=ping_info->bit_depth;
+ ping_info->num_trans=0;
if (matte)
{
ExceptionInfo
*exception;
- int
- trans_alpha[256];
-
/*
Identify which colormap entry is transparent.
*/
+ ping_info->trans_alpha=(unsigned char *) AcquireQuantumMemory(
+ number_colors,sizeof(*ping_info->trans_alpha));
+ if (ping_info->trans_alpha == (unsigned char *) NULL)
+ ThrowWriterException(ResourceLimitError,
+ "MemoryAllocationFailed");
assert(number_colors <= 256);
for (i=0; i < (long) number_colors; i++)
- trans_alpha[i]=255;
+ ping_info->trans_alpha[i]=255;
exception=(&image->exception);
for (y=0; y < (long) image->rows; y++)
{
if (p->opacity != OpaqueOpacity)
{
indices[x]=(IndexPacket) (number_colors-1);
- trans_alpha[(long) indices[x]]=(png_byte) (255-
+ ping_info->trans_alpha[(long) indices[x]]=(png_byte) (255-
ScaleQuantumToChar(GetOpacityPixelComponent(p)));
}
p++;
break;
}
for (i=0; i < (long) number_colors; i++)
- if (trans_alpha[i] != 255)
- ping_info_num_trans=(unsigned short) (i+1);
-
- if (ping_info_num_trans == 0)
- png_set_invalid(ping, ping_info, PNG_INFO_tRNS);
- if (!png_get_valid(ping, ping_info, PNG_INFO_tRNS))
- ping_info_num_trans=0;
- if (ping_info_num_trans != 0)
- {
- for (i=0; i<256; i++)
- ping_trans_alpha[i]=(png_byte) trans_alpha[i];
- }
-
- (void) png_set_tRNS(ping, ping_info,
- ping_trans_alpha,
- ping_info_num_trans,
- &ping_trans_color);
+ if (ping_info->trans_alpha[i] != 255)
+ ping_info->num_trans=(unsigned short) (i+1);
+ if (ping_info->num_trans == 0)
+ ping_info->valid&=(~PNG_INFO_tRNS);
+ if (!(ping_info->valid & PNG_INFO_tRNS))
+ ping_info->num_trans=0;
+ if (ping_info->num_trans == 0)
+ ping_info->trans_alpha=(unsigned char *)
+ RelinquishMagickMemory(ping_info->trans_alpha);
}
/*
Identify which colormap entry is the background color.
*/
for (i=0; i < (long) MagickMax(1L*number_colors-1L,1L); i++)
- if (IsPNGColorEqual(ping_background,image->colormap[i]))
+ if (IsPNGColorEqual(ping_info->background,image->colormap[i]))
break;
- ping_background.index=(png_byte) i;
+ ping_info->background.index=(png_byte) i;
}
if (image_matte != MagickFalse)
{
else if (mng_info->write_png24)
{
image_matte=MagickFalse;
- ping_info_color_type=(png_byte) PNG_COLOR_TYPE_RGB;
+ ping_info->color_type=(png_byte) PNG_COLOR_TYPE_RGB;
}
else if (mng_info->write_png32)
{
image_matte=MagickTrue;
- ping_info_color_type=(png_byte) PNG_COLOR_TYPE_RGB_ALPHA;
+ ping_info->color_type=(png_byte) PNG_COLOR_TYPE_RGB_ALPHA;
}
else
{
- image_depth=ping_info_bit_depth;
+ image_depth=ping_info->bit_depth;
if (mng_info->write_png_colortype)
{
- ping_info_color_type=(png_byte) mng_info->write_png_colortype-1;
- if (ping_info_color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
- ping_info_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ ping_info->color_type=(png_byte) mng_info->write_png_colortype-1;
+ if (ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
+ ping_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
image_matte=MagickTrue;
}
else
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
"Selecting PNG colortype");
- ping_info_color_type=(png_byte) ((matte == MagickTrue)?
+ ping_info->color_type=(png_byte) ((matte == MagickTrue)?
PNG_COLOR_TYPE_RGB_ALPHA:PNG_COLOR_TYPE_RGB);
if(image_info->type == TrueColorType)
{
- ping_info_color_type=(png_byte) PNG_COLOR_TYPE_RGB;
+ ping_info->color_type=(png_byte) PNG_COLOR_TYPE_RGB;
image_matte=MagickFalse;
}
if(image_info->type == TrueColorMatteType)
{
- ping_info_color_type=(png_byte) PNG_COLOR_TYPE_RGB_ALPHA;
+ ping_info->color_type=(png_byte) PNG_COLOR_TYPE_RGB_ALPHA;
image_matte=MagickTrue;
}
if ((image_info->type == UndefinedType ||
image_info->type == GrayscaleType) &&
image_matte == MagickFalse && ImageIsGray(image))
{
- ping_info_color_type=(png_byte) PNG_COLOR_TYPE_GRAY;
+ ping_info->color_type=(png_byte) PNG_COLOR_TYPE_GRAY;
image_matte=MagickFalse;
}
if ((image_info->type == UndefinedType ||
image_info->type == GrayscaleMatteType) &&
image_matte == MagickTrue && ImageIsGray(image))
{
- ping_info_color_type=(png_byte) PNG_COLOR_TYPE_GRAY_ALPHA;
+ ping_info->color_type=(png_byte) PNG_COLOR_TYPE_GRAY_ALPHA;
image_matte=MagickTrue;
}
}
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- "Selected PNG colortype=%d",ping_info_color_type);
+ "Selected PNG colortype=%d",ping_info->color_type);
- if (ping_info_bit_depth < 8)
+ if (ping_info->bit_depth < 8)
{
- if (ping_info_color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
- ping_info_color_type == PNG_COLOR_TYPE_RGB ||
- ping_info_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
- ping_info_bit_depth=8;
+ if (ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
+ ping_info->color_type == PNG_COLOR_TYPE_RGB ||
+ ping_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ ping_info->bit_depth=8;
}
- if (ping_info_color_type == PNG_COLOR_TYPE_GRAY)
+ if (ping_info->color_type == PNG_COLOR_TYPE_GRAY)
{
if (image->matte == MagickFalse && image->colors < 256)
{
if (ImageIsMonochrome(image))
{
- ping_info_bit_depth=1;
- if (ping_info_bit_depth < (int)mng_info->write_png_depth)
- ping_info_bit_depth = mng_info->write_png_depth;
+ ping_info->bit_depth=1;
+ if (ping_info->bit_depth < mng_info->write_png_depth)
+ ping_info->bit_depth = mng_info->write_png_depth;
}
}
}
- if (ping_info_color_type == PNG_COLOR_TYPE_PALETTE)
+ if (ping_info->color_type == PNG_COLOR_TYPE_PALETTE)
{
- ping_info_bit_depth=1;
- while ((int) (1 << ping_info_bit_depth) < (long) image_colors)
- ping_info_bit_depth <<= 1;
+ ping_info->bit_depth=1;
+ while ((int) (1 << ping_info->bit_depth) < (long) image_colors)
+ ping_info->bit_depth <<= 1;
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Number of colors: %lu",image_colors);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Tentative PNG bit depth: %d",ping_info_bit_depth);
+ " Tentative PNG bit depth: %d",ping_info->bit_depth);
}
if (mng_info->write_png_depth)
{
- old_bit_depth=ping_info_bit_depth;
- if (ping_info_bit_depth < (int)mng_info->write_png_depth)
+ old_bit_depth=ping_info->bit_depth;
+ if (ping_info->bit_depth < mng_info->write_png_depth)
{
- ping_info_bit_depth = mng_info->write_png_depth;
- if (ping_info_bit_depth > 8)
- ping_info_bit_depth = 8;
- if (ping_info_bit_depth != (int) old_bit_depth)
+ ping_info->bit_depth = mng_info->write_png_depth;
+ if (ping_info->bit_depth > 8)
+ ping_info->bit_depth = 8;
+ if (ping_info->bit_depth != old_bit_depth)
{
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
}
}
}
- image_depth=ping_info_bit_depth;
+ image_depth=ping_info->bit_depth;
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Tentative PNG color type: %d",ping_info_color_type);
+ " Tentative PNG color type: %d",ping_info->color_type);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" image_info->type: %d",image_info->type);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" image_depth: %lu",image_depth);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " ping_info_bit_depth: %d",ping_info_bit_depth);
+ " ping_info->bit_depth: %d",ping_info->bit_depth);
}
if (matte && (mng_info->optimize || mng_info->IsPalette))
*p;
p=GetVirtualPixels(image,0,0,image->columns,1,&image->exception);
- ping_info_color_type=PNG_COLOR_TYPE_GRAY_ALPHA;
+ ping_info->color_type=PNG_COLOR_TYPE_GRAY_ALPHA;
for (y=0; y < (long) image->rows; y++)
{
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
{
if (IsGray(p) == MagickFalse)
{
- ping_info_color_type=(png_byte) PNG_COLOR_TYPE_RGB_ALPHA;
+ ping_info->color_type=(png_byte) PNG_COLOR_TYPE_RGB_ALPHA;
break;
}
p++;
and do not set the PNG_INFO_tRNS flag in ping_info->valid.
*/
image_matte=MagickFalse;
- ping_info_color_type&=0x03;
+ ping_info->color_type&=0x03;
}
else
{
mask;
mask=0xffff;
- if (ping_info_bit_depth == 8)
+ if (ping_info->bit_depth == 8)
mask=0x00ff;
- if (ping_info_bit_depth == 4)
+ if (ping_info->bit_depth == 4)
mask=0x000f;
- if (ping_info_bit_depth == 2)
+ if (ping_info->bit_depth == 2)
mask=0x0003;
- if (ping_info_bit_depth == 1)
+ if (ping_info->bit_depth == 1)
mask=0x0001;
ping_info->valid|=PNG_INFO_tRNS;
- ping_trans_color.red=(png_uint_16)
+ ping_info->trans_color.red=(png_uint_16)
(ScaleQuantumToShort(GetRedPixelComponent(p)) & mask);
- ping_trans_color.green=(png_uint_16)
+ ping_info->trans_color.green=(png_uint_16)
(ScaleQuantumToShort(GetGreenPixelComponent(p)) & mask);
- ping_trans_color.blue=(png_uint_16)
+ ping_info->trans_color.blue=(png_uint_16)
(ScaleQuantumToShort(GetBluePixelComponent(p)) & mask);
- ping_trans_color.gray=(png_uint_16)
+ ping_info->trans_color.gray=(png_uint_16)
(ScaleQuantumToShort(PixelIntensityToQuantum(p)) & mask);
- ping_trans_color.index=(png_byte)
+ ping_info->trans_color.index=(png_byte)
(ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p))));
}
if (ping_info->valid & PNG_INFO_tRNS)
{
if (p->opacity != OpaqueOpacity)
{
- if (IsPNGColorEqual(ping_trans_color,*p) == 0)
+ if (IsPNGColorEqual(ping_info->trans_color,*p) == 0)
{
break; /* Can't use RGB + tRNS for multiple
transparent colors. */
}
else
{
- if (IsPNGColorEqual(ping_trans_color,*p))
+ if (IsPNGColorEqual(ping_info->trans_color,*p))
break; /* Can't use RGB + tRNS when another pixel
having the same RGB samples is
transparent. */
}
if (ping_info->valid & PNG_INFO_tRNS)
{
- ping_info_color_type &= 0x03; /* changes 4 or 6 to 0 or 2 */
+ ping_info->color_type &= 0x03; /* changes 4 or 6 to 0 or 2 */
if (image_depth == 8)
{
- ping_trans_color.red&=0xff;
- ping_trans_color.green&=0xff;
- ping_trans_color.blue&=0xff;
- ping_trans_color.gray&=0xff;
+ ping_info->trans_color.red&=0xff;
+ ping_info->trans_color.green&=0xff;
+ ping_info->trans_color.blue&=0xff;
+ ping_info->trans_color.gray&=0xff;
}
}
}
ImageIsGray(image) && (!image_matte || image_depth >= 8))
{
if (image_matte != MagickFalse)
- ping_info_color_type=PNG_COLOR_TYPE_GRAY_ALPHA;
+ ping_info->color_type=PNG_COLOR_TYPE_GRAY_ALPHA;
else
{
- ping_info_color_type=PNG_COLOR_TYPE_GRAY;
+ ping_info->color_type=PNG_COLOR_TYPE_GRAY;
if (save_image_depth == 16 && image_depth == 8)
- ping_trans_color.gray*=0x0101;
+ ping_info->trans_color.gray*=0x0101;
}
if (image_depth > MAGICKCORE_QUANTUM_DEPTH)
image_depth=MAGICKCORE_QUANTUM_DEPTH;
if (image_colors == 0 || image_colors-1 > MaxColormapSize)
image_colors=1 << image_depth;
if (image_depth > 8)
- ping_info_bit_depth=16;
+ ping_info->bit_depth=16;
else
{
- ping_info_bit_depth=8;
- if ((int) ping_info_color_type == PNG_COLOR_TYPE_PALETTE)
+ ping_info->bit_depth=8;
+ if ((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE)
{
if(!mng_info->write_png_depth)
{
- ping_info_bit_depth=1;
- while ((int) (1 << ping_info_bit_depth)
+ ping_info->bit_depth=1;
+ while ((int) (1 << ping_info->bit_depth)
< (long) image_colors)
- ping_info_bit_depth <<= 1;
+ ping_info->bit_depth <<= 1;
}
}
- else if (mng_info->optimize && ping_info_color_type ==
+ else if (mng_info->optimize && ping_info->color_type ==
PNG_COLOR_TYPE_GRAY && image_colors < 17 &&
mng_info->IsPalette)
{
depth_1_ok=MagickFalse;
}
if (depth_1_ok && mng_info->write_png_depth <= 1)
- ping_info_bit_depth=1;
+ ping_info->bit_depth=1;
else if (depth_2_ok && mng_info->write_png_depth <= 2)
- ping_info_bit_depth=2;
+ ping_info->bit_depth=2;
else if (depth_4_ok && mng_info->write_png_depth <= 4)
- ping_info_bit_depth=4;
+ ping_info->bit_depth=4;
}
}
- image_depth=ping_info_bit_depth;
+ image_depth=ping_info->bit_depth;
}
else
if (mng_info->IsPalette)
/*
Set image palette.
*/
- ping_info_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
+ ping_info->color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
ping_info->valid|=PNG_INFO_PLTE;
if (mng_info->have_write_global_plte && !matte)
{
{
ping_info->bit_depth=1;
while ((1UL << ping_info->bit_depth) < number_colors)
- ping_info_bit_depth <<= 1;
+ ping_info->bit_depth <<= 1;
}
- ping_info_num_trans=0;
+ ping_info->num_trans=0;
if (matte)
{
ExceptionInfo
if (trans[(long) packet_index] != (png_byte) (255-
ScaleQuantumToChar(GetOpacityPixelComponent(p))))
{
- ping_info_color_type=(png_byte)
+ ping_info->color_type=(png_byte)
PNG_COLOR_TYPE_RGB_ALPHA;
break;
}
}
p++;
}
- if ((int) ping_info_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ if ((int) ping_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
{
- ping_info_num_trans=0;
+ ping_info->num_trans=0;
ping_info->valid&=(~PNG_INFO_tRNS);
ping_info->valid&=(~PNG_INFO_PLTE);
mng_info->IsPalette=MagickFalse;
if (trans[i] == 256)
trans[i]=255;
if (trans[i] != 255)
- ping_info_num_trans=(unsigned short) (i+1);
+ ping_info->num_trans=(unsigned short) (i+1);
}
}
- if (ping_info_num_trans == 0)
+ if (ping_info->num_trans == 0)
ping_info->valid&=(~PNG_INFO_tRNS);
if (!(ping_info->valid & PNG_INFO_tRNS))
- ping_info_num_trans=0;
- if (ping_info_num_trans != 0)
+ ping_info->num_trans=0;
+ if (ping_info->num_trans != 0)
{
- ping_trans_alpha=(unsigned char *) AcquireQuantumMemory(
- number_colors,sizeof(*ping_trans_alpha));
- if (ping_trans_alpha == (unsigned char *) NULL)
+ ping_info->trans_alpha=(unsigned char *) AcquireQuantumMemory(
+ number_colors,sizeof(*ping_info->trans_alpha));
+ if (ping_info->trans_alpha == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,
"MemoryAllocationFailed");
for (i=0; i < (long) number_colors; i++)
- ping_trans_alpha[i]=(png_byte) trans[i];
+ ping_info->trans_alpha[i]=(png_byte) trans[i];
}
}
Identify which colormap entry is the background color.
*/
for (i=0; i < (long) MagickMax(1L*number_colors-1L,1L); i++)
- if (IsPNGColorEqual(ping_background,image->colormap[i]))
+ if (IsPNGColorEqual(ping_info->background,image->colormap[i]))
break;
- ping_background.index=(png_byte) i;
+ ping_info->background.index=(png_byte) i;
}
}
else
image_depth=8;
if ((save_image_depth == 16) && (image_depth == 8))
{
- ping_trans_color.red*=0x0101;
- ping_trans_color.green*=0x0101;
- ping_trans_color.blue*=0x0101;
- ping_trans_color.gray*=0x0101;
+ ping_info->trans_color.red*=0x0101;
+ ping_info->trans_color.green*=0x0101;
+ ping_info->trans_color.blue*=0x0101;
+ ping_info->trans_color.gray*=0x0101;
}
}
/*
Adjust background and transparency samples in sub-8-bit grayscale files.
*/
- if (ping_info_bit_depth < 8 && ping_info_color_type ==
+ if (ping_info->bit_depth < 8 && ping_info->color_type ==
PNG_COLOR_TYPE_GRAY)
{
png_uint_16
png_color_16
background;
- maxval=(png_uint_16) ((1 << ping_info_bit_depth)-1);
+ maxval=(png_uint_16) ((1 << ping_info->bit_depth)-1);
background.gray=(png_uint_16)
" Setting up bKGD chunk");
png_set_bKGD(ping,ping_info,&background);
- ping_trans_color.gray=(png_uint_16) (QuantumScale*(maxval*
- ping_trans_color.gray));
+ ping_info->trans_color.gray=(png_uint_16) (QuantumScale*(maxval*
+ ping_info->trans_color.gray));
}
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " PNG color type: %d",ping_info_color_type);
+ " PNG color type: %d",ping_info->color_type);
/*
Initialize compression level and filtering.
*/
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Filter_type: PNG_INTRAPIXEL_DIFFERENCING");
- ping_info_filter_method=PNG_INTRAPIXEL_DIFFERENCING;
+ ping_info->filter_type=PNG_INTRAPIXEL_DIFFERENCING;
}
else
if (logging != MagickFalse)
if ((quality % 10) != 5)
base_filter=(int) quality % 10;
else
- if (((int) ping_info_color_type == PNG_COLOR_TYPE_GRAY) ||
- ((int) ping_info_color_type == PNG_COLOR_TYPE_PALETTE) ||
+ if (((int) ping_info->color_type == PNG_COLOR_TYPE_GRAY) ||
+ ((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE) ||
(quality < 50))
base_filter=PNG_NO_FILTERS;
else
bp.x,bp.y);
}
}
- ping_info_interlace_method=image_info->interlace != NoInterlace;
+ ping_info->interlace_type=image_info->interlace != NoInterlace;
if (mng_info->write_mng)
png_set_sig_bytes(ping,8);
if (mng_info->write_png_colortype-1 == PNG_COLOR_TYPE_GRAY)
if (ImageIsGray(image) == MagickFalse)
{
- ping_info_color_type = PNG_COLOR_TYPE_RGB;
- if (ping_info_bit_depth < 8)
- ping_info_bit_depth=8;
+ ping_info->color_type = PNG_COLOR_TYPE_RGB;
+ if (ping_info->bit_depth < 8)
+ ping_info->bit_depth=8;
}
if (mng_info->write_png_colortype-1 == PNG_COLOR_TYPE_GRAY_ALPHA)
if (ImageIsGray(image) == MagickFalse)
- ping_info_color_type = PNG_COLOR_TYPE_RGB_ALPHA;
+ ping_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
}
if ((mng_info->write_png_depth &&
- (int) mng_info->write_png_depth != ping_info_bit_depth) ||
+ mng_info->write_png_depth != ping_info->bit_depth) ||
(mng_info->write_png_colortype &&
- ((int) mng_info->write_png_colortype-1 != ping_info_color_type &&
+ (mng_info->write_png_colortype-1 != ping_info->color_type &&
mng_info->write_png_colortype != 7 &&
- !(mng_info->write_png_colortype == 5 && ping_info_color_type == 0))))
+ !(mng_info->write_png_colortype == 5 && ping_info->color_type == 0))))
{
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Defined PNG:bit-depth=%u, Computed depth=%u",
mng_info->write_png_depth,
- ping_info_bit_depth);
+ ping_info->bit_depth);
}
if (mng_info->write_png_colortype)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Defined PNG:color-type=%u, Computed color type=%u",
mng_info->write_png_colortype-1,
- ping_info_color_type);
+ ping_info->color_type);
}
}
png_error(ping,
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing PNG header chunks");
- png_set_IHDR(ping,ping_info,ping_info_width,ping_info_height,
- ping_info_bit_depth,ping_info_color_type,
- ping_info_interlace_method,ping_info_compression_method,
- ping_info_filter_method);
-
png_write_info_before_PLTE(ping, ping_info);
/* write any png-chunk-b profiles */
(void) png_write_chunk_from_profile(image,"PNG-chunk-b",(int) logging);
if ((!mng_info->write_png8 && !mng_info->write_png24 &&
!mng_info->write_png32) &&
(image_matte ||
- (ping_info_bit_depth >= MAGICKCORE_QUANTUM_DEPTH)) &&
+ (ping_info->bit_depth >= MAGICKCORE_QUANTUM_DEPTH)) &&
(mng_info->optimize || mng_info->IsPalette) && ImageIsGray(image))
{
for (y=0; y < (long) image->rows; y++)
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (const PixelPacket *) NULL)
break;
- if (ping_info_color_type == PNG_COLOR_TYPE_GRAY)
+ if (ping_info->color_type == PNG_COLOR_TYPE_GRAY)
{
if (mng_info->IsPalette)
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (const PixelPacket *) NULL)
break;
- if (ping_info_color_type == PNG_COLOR_TYPE_GRAY)
+ if (ping_info->color_type == PNG_COLOR_TYPE_GRAY)
{
if (image->storage_class == DirectClass)
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,GrayQuantum,png_pixels,&image->exception);
}
- else if (ping_info_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ else if (ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,GrayAlphaQuantum,png_pixels,&image->exception);
else if (image_matte != MagickFalse)
mng_info->write_png32 ||
(!mng_info->write_png8 && !mng_info->IsPalette))) */
{
- if ((ping_info_color_type != PNG_COLOR_TYPE_GRAY) &&
- (ping_info_color_type != PNG_COLOR_TYPE_GRAY_ALPHA))
+ if ((ping_info->color_type != PNG_COLOR_TYPE_GRAY) &&
+ (ping_info->color_type != PNG_COLOR_TYPE_GRAY_ALPHA))
{
if (logging)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (const PixelPacket *) NULL)
break;
- if (ping_info_color_type == PNG_COLOR_TYPE_GRAY)
+ if (ping_info->color_type == PNG_COLOR_TYPE_GRAY)
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,GrayQuantum,png_pixels,&image->exception);
- else if (ping_info_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ else if (ping_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
(void) ExportQuantumPixels(image,(const CacheView *) NULL,
quantum_info,GrayAlphaQuantum,png_pixels,&image->exception);
else
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing PNG image data");
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Width: %lu",ping_info_width);
+ " Width: %lu",ping_info->width);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Height: %lu",ping_info_height);
+ " Height: %lu",ping_info->height);
if (mng_info->write_png_depth)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Defined PNG:bit-depth: %d",mng_info->write_png_depth);
}
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " PNG bit-depth written: %d",ping_info_bit_depth);
+ " PNG bit-depth written: %d",ping_info->bit_depth);
if (mng_info->write_png_colortype)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Defined PNG:color-type: %d",mng_info->write_png_colortype-1);
}
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " PNG color-type written: %d",ping_info_color_type);
+ " PNG color-type written: %d",ping_info->color_type);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " PNG Interlace method: %d",ping_info_interlace_method);
+ " PNG Interlace method: %d",ping_info->interlace_type);
}
/*
Generate text chunks.
value=GetImageProperty(image,property);
if (value != (const char *) NULL)
{
+#if (PNG_LIBPNG_VER > 10005)
text=(png_textp) png_malloc(ping,(png_uint_32) sizeof(png_text));
text[0].key=(char *) property;
text[0].text=(char *) value;
}
png_set_text(ping,ping_info,text,1);
png_free(ping,text);
+#else
+/* Work directly with ping_info struct; png_set_text before libpng version
+ * 1.0.5a is leaky */
+ if (ping_info->num_text == 0)
+ {
+ ping_info->text=(png_text *) AcquireQuantumMemory(256,
+ sizeof(*ping_info->text));
+ if (ping_info->text == (png_text *) NULL)
+ (void) ThrowMagickException(&image->exception,GetMagickModule(),
+ ResourceLimitError,"MemoryAllocationFailed","`%s'",
+ image->filename);
+ }
+ i=ping_info->num_text++;
+ if (i > 255)
+ (void) ThrowMagickException(&image->exception,GetMagickModule(),
+ ResourceLimitError,"Cannot write more than 256 PNG text chunks",
+ "`%s'",image->filename);
+ ping_info->text[i].key=(char *) property;
+ ping_info->text[i].text=(char *) value;
+ ping_info->text[i].text_length=strlen(value);
+ ping_info->text[i].compression=
+ image_info->compression == NoCompression ||
+ (image_info->compression == UndefinedCompression &&
+ ping_info->text[i].text_length < 128) ? -1 : 0;
+ if (logging != MagickFalse)
+ {
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " Setting up text chunk");
+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+ " keyword: %s",ping_info->text[i].key);
+ }
+#endif
}
property=GetNextImageProperty(image);
}
if (mng_info->need_fram && (int) image->dispose == BackgroundDispose)
{
if (mng_info->page.x || mng_info->page.y ||
- (ping_info_width != mng_info->page.width) ||
- (ping_info_height != mng_info->page.height))
+ (ping_info->width != mng_info->page.width) ||
+ (ping_info->height != mng_info->page.height))
{
unsigned char
chunk[32];
chunk[14]=0; /* clipping boundaries delta type */
PNGLong(chunk+15,(png_uint_32) (mng_info->page.x)); /* left cb */
PNGLong(chunk+19,
- (png_uint_32) (mng_info->page.x + ping_info_width));
+ (png_uint_32) (mng_info->page.x + ping_info->width));
PNGLong(chunk+23,(png_uint_32) (mng_info->page.y)); /* top cb */
PNGLong(chunk+27,
- (png_uint_32) (mng_info->page.y + ping_info_height));
+ (png_uint_32) (mng_info->page.y + ping_info->height));
(void) WriteBlob(image,31,chunk);
(void) WriteBlobMSBULong(image,crc32(0,chunk,31));
mng_info->old_framing_mode=4;
/* Save depth actually written */
- s[0]=(char) ping_info_bit_depth;
+ s[0]=(char) ping_info->bit_depth;
s[1]='\0';
(void) SetImageProperty(image,"png:bit-depth-written",s);
/*
Free PNG resources.
*/
+#if (PNG_LIBPNG_VER < 10007)
+ if (ping_info->valid & PNG_INFO_PLTE)
+ {
+ ping_info->palette=(png_colorp)
+ RelinquishMagickMemory(ping_info->palette);
+ ping_info->valid&=(~PNG_INFO_PLTE);
+ }
+ if (ping_info->valid & PNG_INFO_tRNS)
+ {
+ ping_info->trans_alpha=(unsigned char *) RelinquishMagickMemory(
+ ping_info->trans_alpha);
+ ping_info->valid&=(~PNG_INFO_tRNS);
+ }
+#endif
png_destroy_write_struct(&ping,&ping_info);
final_delay=0,
initial_delay;
-#if (PNG_LIBPNG_VER < 10200)
+#if (PNG_LIBPNG_VER < 10007)
if (image_info->verbose)
printf("Your PNG library (libpng-%s) is rather old.\n",
PNG_LIBPNG_VER_STRING);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit WriteMNGImage()");
return(MagickTrue);
}
-#else /* PNG_LIBPNG_VER > 10011 */
+#else /* PNG_LIBPNG_VER > 95 */
static MagickBooleanType WritePNGImage(const ImageInfo *image_info,Image *image)
{
image=image;
{
return(WritePNGImage(image_info,image));
}
-#endif /* PNG_LIBPNG_VER > 10011 */
+#endif /* PNG_LIBPNG_VER > 95 */
#endif