/* ImageMagick differences */
#define first_scene scene
-#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 > 10011
/*
Optional declarations. Define or undefine them as you like.
logging,
num_text,
num_passes,
- pass;
+ pass,
+ ping_bit_depth,
+ ping_color_type,
+ ping_interlace_method,
+ ping_compression_method,
+ ping_filter_method,
+ ping_num_trans;
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_textp
text;
+ png_uint_32
+ ping_height,
+ ping_width,
+ ping_rowbytes;
+
QuantumInfo
*quantum_info;
LockSemaphoreInfo(png_semaphore);
#endif
-#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);
/*
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);
- if (ping_info->bit_depth < 8)
+
+ png_get_IHDR(ping,ping_info,&ping_width,&ping_height,
+ &ping_bit_depth,&ping_color_type,
+ &ping_interlace_method,&ping_compression_method,
+ &ping_filter_method);
+
+ (void) png_get_tRNS(ping, ping_info, &ping_trans_alpha, &ping_num_trans,
+ &ping_trans_color);
+
+ (void) png_get_bKGD(ping, ping_info, &ping_background);
+
+ if (ping_bit_depth < 8)
{
- if (((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE))
+ if (((int) ping_color_type == PNG_COLOR_TYPE_PALETTE))
png_set_packing(ping);
}
- image->depth=ping_info->bit_depth;
+ image->depth=ping_bit_depth;
image->depth=GetImageQuantumDepth(image,MagickFalse);
- image->interlace=ping_info->interlace_type != 0 ? PNGInterlace : NoInterlace;
+ image->interlace=ping_interlace_method != 0 ? PNGInterlace : NoInterlace;
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" PNG width: %lu, height: %lu",
- ping_info->width, ping_info->height);
+ ping_width, ping_height);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" PNG color_type: %d, bit_depth: %d",
- ping_info->color_type, ping_info->bit_depth);
+ ping_color_type, ping_bit_depth);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" PNG compression_method: %d",
- ping_info->compression_type);
+ ping_compression_method);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" PNG interlace_method: %d, filter_method: %d",
- ping_info->interlace_type,ping_info->filter_type);
+ ping_interlace_method,ping_filter_method);
}
-#if defined(PNG_READ_iCCP_SUPPORTED)
- if (ping_info->valid & PNG_INFO_iCCP)
+#if (PNG_LIBPNG_VER > 10008) && defined(PNG_READ_iCCP_SUPPORTED)
+ if (png_get_valid(ping,ping_info,PNG_INFO_iCCP))
{
int
compression;
double
file_gamma;
- if (mng_info->have_global_gama)
- image->gamma=mng_info->global_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 (png_get_gAMA(ping,ping_info,&file_gamma))
{
image->gamma=(float) file_gamma;
" Reading PNG gAMA chunk: gamma: %f",file_gamma);
}
}
- if (mng_info->have_global_chrm != MagickFalse)
- image->chromaticity=mng_info->global_chrm;
- if (ping_info->valid & PNG_INFO_cHRM)
+ 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))
{
(void) png_get_cHRM(ping,ping_info,
&image->chromaticity.white_point.x,
}
if (image->rendering_intent)
{
- 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;
+ 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);
}
- 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 (ping_info->valid & PNG_INFO_oFFs)
+ if (png_get_valid(ping,ping_info,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 (ping_info->valid & PNG_INFO_pHYs)
+ 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))
{
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 (ping_info->valid & PNG_INFO_PLTE)
+ if (png_get_valid(ping,ping_info,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_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 ((ping_info->valid & PNG_INFO_tRNS) == 0)
+ if (!png_get_valid(ping,ping_info,PNG_INFO_tRNS))
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
- ping_info->valid & PNG_INFO_bKGD)
+ png_get_valid(ping,ping_info,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
- background.index=ping_info->background.index;
+ if (png_get_valid(ping, ping_info, PNG_INFO_bKGD))
+ background.index=ping_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 && !(ping_info->valid & PNG_INFO_bKGD))
+ if (mng_info->have_global_bkgd &&
+ (!png_get_valid(ping,ping_info,PNG_INFO_bKGD)))
image->background_color=mng_info->mng_global_bkgd;
- if (ping_info->valid & PNG_INFO_bKGD)
+ if (png_get_valid(ping,ping_info,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_bit_depth <= MAGICKCORE_QUANTUM_DEPTH)
{
- image->background_color.red=ping_info->background.red;
- image->background_color.green=ping_info->background.green;
- image->background_color.blue=ping_info->background.blue;
+ image->background_color.red=ping_background->red;
+ image->background_color.green=ping_background->green;
+ image->background_color.blue=ping_background->blue;
}
else
{
image->background_color.red=
- ScaleShortToQuantum(ping_info->background.red);
+ ScaleShortToQuantum(ping_background->red);
image->background_color.green=
- ScaleShortToQuantum(ping_info->background.green);
+ ScaleShortToQuantum(ping_background->green);
image->background_color.blue=
- ScaleShortToQuantum(ping_info->background.blue);
+ ScaleShortToQuantum(ping_background->blue);
}
}
#endif
transparent_color.green=0;
transparent_color.blue=0;
transparent_color.opacity=0;
- if (ping_info->valid & PNG_INFO_tRNS)
+ if (png_get_valid(ping,ping_info,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_bit_depth) - 1;
- 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 ((ping_color_type == PNG_COLOR_TYPE_GRAY &&
+ (int)ping_trans_color->gray > max_sample) ||
+ (ping_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 (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
}
else
{
- 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)
+ 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_color_type == PNG_COLOR_TYPE_GRAY)
{
- if (ping_info->bit_depth < 8)
+ if (ping_bit_depth < 8)
{
transparent_color.opacity=(Quantum) (((
- ping_info->trans_color.gray)*255)/max_sample);
+ ping_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 (!(ping_info->valid & PNG_INFO_sBIT))
+ if (!png_get_valid(ping,ping_info,PNG_INFO_sBIT))
png_set_sBIT(ping,ping_info,&mng_info->global_sbit);
}
#endif
num_passes=png_set_interlace_handling(ping);
+
png_read_update_info(ping,ping_info);
+
+ ping_rowbytes=png_get_rowbytes(ping,ping_info);
+
/*
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_width;
mng_info->image_box.top=0;
- mng_info->image_box.bottom=(long) ping_info->height;
+ mng_info->image_box.bottom=(long) ping_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_width;
+ mng_info->mng_height=ping_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_width;
+ image->rows=ping_height;
+ if (((int) ping_color_type == PNG_COLOR_TYPE_PALETTE) ||
+ ((int) ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ||
+ ((int) ping_color_type == PNG_COLOR_TYPE_GRAY))
{
image->storage_class=PseudoClass;
- image->colors=1UL << ping_info->bit_depth;
+ image->colors=1UL << ping_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_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_color_type == PNG_COLOR_TYPE_PALETTE)
{
int
number_colors;
unsigned long
scale;
- scale=(QuantumRange/((1UL << ping_info->bit_depth)-1));
+ scale=(QuantumRange/((1UL << ping_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_info->rowbytes*sizeof(*png_pixels));
+ ping_rowbytes*sizeof(*png_pixels));
else
- png_pixels=(unsigned char *) AcquireQuantumMemory(ping_info->rowbytes,
+ png_pixels=(unsigned char *) AcquireQuantumMemory(ping_rowbytes,
sizeof(*png_pixels));
if (png_pixels == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
int
depth;
- depth=(long) ping_info->bit_depth;
+ depth=(long) ping_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) ||
- (ping_info->valid & PNG_INFO_tRNS)) ? MagickTrue : MagickFalse;
+ image->matte=(((int) ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA) ||
+ ((int) ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ||
+ (png_get_valid(ping,ping_info,PNG_INFO_tRNS))) ?
+ MagickTrue : MagickFalse;
for (y=0; y < (long) image->rows; y++)
{
if (num_passes > 1)
- row_offset=ping_info->rowbytes*y;
+ row_offset=ping_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_color_type == PNG_COLOR_TYPE_GRAY)
{
for (x=(long) image->columns-1; x >= 0; x--)
{
*r++=*p++;
p++;
- if ((ping_info->valid & PNG_INFO_tRNS) &&
+ if (png_get_valid(ping,ping_info,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_color_type == PNG_COLOR_TYPE_RGB)
{
- if (ping_info->valid & PNG_INFO_tRNS)
+ if (png_get_valid(ping,ping_info,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_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_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_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_color_type == PNG_COLOR_TYPE_GRAY ||
+ ping_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_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_color_type == PNG_COLOR_TYPE_RGB ||
+ ping_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_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_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_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_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_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_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_info->rowbytes*y;
+ row_offset=ping_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_bit_depth)
{
case 1:
{
}
case 8:
{
- if (ping_info->color_type == 4)
+ if (ping_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_color_type == 4)
{
quantum=((*p++) << 8);
quantum|=(*p++);
quantum|=(*p++);
*r=quantum;
r++;
- if (ping_info->color_type == 4)
+ if (ping_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_color_type == 4)
{
q->opacity=(Quantum) (QuantumRange-(*p++));
p++;
" exit ReadOnePNGImage() early.");
return(image);
}
- if (ping_info->valid & PNG_INFO_tRNS)
+ if (png_get_valid(ping,ping_info,PNG_INFO_tRNS))
{
ClassType
storage_class;
if (storage_class == PseudoClass)
{
- if ((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE)
+ if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE)
{
- for (x=0; x < ping_info->num_trans; x++)
+ for (x=0; x < ping_num_trans; x++)
{
- image->colormap[x].opacity = ScaleCharToQuantum((unsigned char)(255-ping_info->trans_alpha[x]));
+ image->colormap[x].opacity = ScaleCharToQuantum((unsigned char)(255-ping_trans_alpha[x]));
}
}
- else if (ping_info->color_type == PNG_COLOR_TYPE_GRAY)
+ else if (ping_color_type == PNG_COLOR_TYPE_GRAY)
{
- for (x=0; x < image->colors; x++)
+ for (x=0; x < (int) 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_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_num_trans)
q->opacity=ScaleCharToQuantum((unsigned char)
- (255-ping_info->trans_alpha[(long) indexpacket]));
+ (255-ping_trans_alpha[(long) indexpacket]));
else
SetOpacityPixelComponent(q,OpaqueOpacity);
q++;
}
- else if (ping_info->color_type == PNG_COLOR_TYPE_GRAY)
+ else if (ping_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);
- png_get_IHDR(ping,ping_info,&width,&height,&bit_depth,&color_type,
- &interlace_method,&compression_method,&filter_method);
- if (width > 250000L || height > 250000L)
+ if (ping_width > 250000L || ping_height > 250000L)
png_error(ping,"PNG Image dimensions are too large.");
- 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)
+ mng_info->ob[object_id]->width=ping_width;
+ mng_info->ob[object_id]->height=ping_height;
+ mng_info->ob[object_id]->color_type=ping_color_type;
+ mng_info->ob[object_id]->sample_depth=ping_bit_depth;
+ mng_info->ob[object_id]->interlace_method=ping_interlace_method;
+ mng_info->ob[object_id]->compression_method=
+ ping_compression_method;
+ mng_info->ob[object_id]->filter_method=ping_filter_method;
+ if (png_get_valid(ping,ping_info,PNG_INFO_PLTE))
{
int
number_colors;
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit ReadMNGImage()");
return(GetFirstImageInList(image));
}
-#else /* PNG_LIBPNG_VER > 10011 */
+#else /* PNG_LIBPNG_VER > 95 */
static Image *ReadPNGImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
printf("Your PNG library is too old: You have libpng-%s\n",
{
return(ReadPNGImage(image_info,exception));
}
-#endif /* PNG_LIBPNG_VER > 10011 */
+#endif /* PNG_LIBPNG_VER > 95 */
#endif
\f
/*
#if defined(PNG_LIBPNG_VER_STRING)
(void) ConcatenateMagickString(version,"libpng ",MaxTextExtent);
(void) ConcatenateMagickString(version,PNG_LIBPNG_VER_STRING,MaxTextExtent);
+#if (PNG_LIBPNG_VER > 10005)
if (LocaleCompare(PNG_LIBPNG_VER_STRING,png_get_header_ver(NULL)) != 0)
{
(void) ConcatenateMagickString(version,",",MaxTextExtent);
(void) ConcatenateMagickString(version,png_get_libpng_ver(NULL),
MaxTextExtent);
}
+#endif
#endif
entry=SetMagickInfo("MNG");
entry->seekable_stream=MagickTrue; /* To do: eliminate this. */
}
\f
#if defined(MAGICKCORE_PNG_DELEGATE)
-#if PNG_LIBPNG_VER > 10011
+#if PNG_LIBPNG_VER > 95
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% transparent region at the top and/or left.
*/
+#if (PNG_LIBPNG_VER > 99 && PNG_LIBPNG_VER < 10007)
+/* This function became available in libpng version 1.0.6g. */
+static void
+png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
+{
+ if (png_ptr->zbuf)
+ png_free(png_ptr, png_ptr->zbuf); png_ptr->zbuf=NULL;
+ png_ptr->zbuf_size=(png_size_t) size;
+ png_ptr->zbuf=(png_bytep) png_malloc(png_ptr, size);
+ if (png_ptr->zbuf == 0)
+ png_error(png_ptr,"Unable to allocate zbuf");
+}
+#endif
+
static void
png_write_raw_profile(const ImageInfo *image_info,png_struct *ping,
png_info *ping_info, unsigned char *profile_type, unsigned char
*profile_description, unsigned char *profile_data, png_uint_32 length)
{
+#if (PNG_LIBPNG_VER > 10005)
png_textp
text;
unsigned char
hex[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
+#endif
+#if (PNG_LIBPNG_VER <= 10005)
+ if (image_info->verbose)
+ (void) printf("Not ");
+ image_info=image_info;
+ ping=ping;
+ ping_info=ping_info;
+ profile_type=profile_type;
+ profile_description=profile_description;
+ profile_data=profile_data;
+ length=length;
+#endif
if (LocaleNCompare((char *) profile_type+1, "ng-chunk-",9) == 0)
return;
(void) printf("writing raw profile: type=%s, length=%lu\n",
(char *) profile_type, length);
}
+#if (PNG_LIBPNG_VER > 10005)
text=(png_textp) png_malloc(ping,(png_uint_32) sizeof(png_text));
description_length=(png_uint_32) strlen((const char *) profile_description);
allocated_length=(png_uint_32) (length*2 + (length >> 5) + 20
png_free(ping,text[0].text);
png_free(ping,text[0].key);
png_free(ping,text);
+#endif
}
static MagickBooleanType png_write_chunk_from_profile(Image *image,
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_height,
+ ping_width;
+
long
y;
logging,
matte;
+ volatile int
+ ping_bit_depth,
+ ping_color_type,
+ ping_interlace_method,
+ ping_compression_method,
+ ping_filter_method,
+ ping_num_trans;
+
volatile unsigned long
image_colors,
- image_depth;
+ image_depth,
+ old_bit_depth;
unsigned long
- old_bit_depth,
quality,
rowbytes,
save_image_depth;
LockSemaphoreInfo(png_semaphore);
#endif
+ /* Initialize some stuff */
+ ping_bit_depth=0,
+ ping_color_type=0,
+ ping_interlace_method=0,
+ ping_compression_method=0,
+ ping_filter_method=0,
+ ping_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_width=image->columns;
+ ping_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_width);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " height=%lu",ping_info->height);
+ " height=%lu",ping_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_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_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
+ ping_bit_depth=8;
+ image_depth=ping_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_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
ping_info->valid|=PNG_INFO_PLTE;
#if defined(PNG_SORT_PALETTE)
save_number_colors=image_colors;
palette[i].blue=ScaleQuantumToChar((Quantum) QuantumRange);
}
png_set_PLTE(ping,ping_info,palette,(int) number_colors);
+#if (PNG_LIBPNG_VER > 10008)
palette=(png_colorp) RelinquishMagickMemory(palette);
- image_depth=ping_info->bit_depth;
- ping_info->num_trans=0;
+#endif
+ image_depth=ping_bit_depth;
+ ping_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++)
- ping_info->trans_alpha[i]=255;
+ 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);
- ping_info->trans_alpha[(long) indices[x]]=(png_byte) (255-
+ trans_alpha[(long) indices[x]]=(png_byte) (255-
ScaleQuantumToChar(GetOpacityPixelComponent(p)));
}
p++;
break;
}
for (i=0; i < (long) number_colors; i++)
- 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);
+ if (trans_alpha[i] != 255)
+ ping_num_trans=(unsigned short) (i+1);
+
+ if (ping_num_trans == 0)
+ png_set_invalid(ping, ping_info, PNG_INFO_tRNS);
+ if (!png_get_valid(ping, ping_info, PNG_INFO_tRNS))
+ ping_num_trans=0;
+ if (ping_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_num_trans,
+ &ping_trans_color);
}
/*
Identify which colormap entry is the background color.
*/
for (i=0; i < (long) MagickMax(1L*number_colors-1L,1L); i++)
- if (IsPNGColorEqual(ping_info->background,image->colormap[i]))
+ if (IsPNGColorEqual(ping_background,image->colormap[i]))
break;
- ping_info->background.index=(png_byte) i;
+ ping_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_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_color_type=(png_byte) PNG_COLOR_TYPE_RGB_ALPHA;
}
else
{
- image_depth=ping_info->bit_depth;
+ image_depth=ping_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_color_type=(png_byte) mng_info->write_png_colortype-1;
+ if (ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
+ ping_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_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_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_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_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_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_color_type);
- if (ping_info->bit_depth < 8)
+ if (ping_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_color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
+ ping_color_type == PNG_COLOR_TYPE_RGB ||
+ ping_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ ping_bit_depth=8;
}
- if (ping_info->color_type == PNG_COLOR_TYPE_GRAY)
+ if (ping_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 < mng_info->write_png_depth)
- ping_info->bit_depth = mng_info->write_png_depth;
+ ping_bit_depth=1;
+ if (ping_bit_depth < (int)mng_info->write_png_depth)
+ ping_bit_depth = mng_info->write_png_depth;
}
}
}
- if (ping_info->color_type == PNG_COLOR_TYPE_PALETTE)
+ if (ping_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_bit_depth=1;
+ while ((int) (1 << ping_bit_depth) < (long) image_colors)
+ ping_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_bit_depth);
}
if (mng_info->write_png_depth)
{
- old_bit_depth=ping_info->bit_depth;
- if (ping_info->bit_depth < mng_info->write_png_depth)
+ old_bit_depth=ping_bit_depth;
+ if (ping_bit_depth < (int)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 != old_bit_depth)
+ ping_bit_depth = mng_info->write_png_depth;
+ if (ping_bit_depth > 8)
+ ping_bit_depth = 8;
+ if (ping_bit_depth != (int) old_bit_depth)
{
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
}
}
}
- image_depth=ping_info->bit_depth;
+ image_depth=ping_bit_depth;
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Tentative PNG color type: %d",ping_info->color_type);
+ " Tentative PNG color type: %d",ping_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_bit_depth: %d",ping_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_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_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_color_type&=0x03;
}
else
{
mask;
mask=0xffff;
- if (ping_info->bit_depth == 8)
+ if (ping_bit_depth == 8)
mask=0x00ff;
- if (ping_info->bit_depth == 4)
+ if (ping_bit_depth == 4)
mask=0x000f;
- if (ping_info->bit_depth == 2)
+ if (ping_bit_depth == 2)
mask=0x0003;
- if (ping_info->bit_depth == 1)
+ if (ping_bit_depth == 1)
mask=0x0001;
ping_info->valid|=PNG_INFO_tRNS;
- ping_info->trans_color.red=(png_uint_16)
+ ping_trans_color.red=(png_uint_16)
(ScaleQuantumToShort(GetRedPixelComponent(p)) & mask);
- ping_info->trans_color.green=(png_uint_16)
+ ping_trans_color.green=(png_uint_16)
(ScaleQuantumToShort(GetGreenPixelComponent(p)) & mask);
- ping_info->trans_color.blue=(png_uint_16)
+ ping_trans_color.blue=(png_uint_16)
(ScaleQuantumToShort(GetBluePixelComponent(p)) & mask);
- ping_info->trans_color.gray=(png_uint_16)
+ ping_trans_color.gray=(png_uint_16)
(ScaleQuantumToShort(PixelIntensityToQuantum(p)) & mask);
- ping_info->trans_color.index=(png_byte)
+ ping_trans_color.index=(png_byte)
(ScaleQuantumToChar((Quantum) (GetAlphaPixelComponent(p))));
}
if (ping_info->valid & PNG_INFO_tRNS)
{
if (p->opacity != OpaqueOpacity)
{
- if (IsPNGColorEqual(ping_info->trans_color,*p) == 0)
+ if (IsPNGColorEqual(ping_trans_color,*p) == 0)
{
break; /* Can't use RGB + tRNS for multiple
transparent colors. */
}
else
{
- if (IsPNGColorEqual(ping_info->trans_color,*p))
+ if (IsPNGColorEqual(ping_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_color_type &= 0x03; /* changes 4 or 6 to 0 or 2 */
if (image_depth == 8)
{
- ping_info->trans_color.red&=0xff;
- ping_info->trans_color.green&=0xff;
- ping_info->trans_color.blue&=0xff;
- ping_info->trans_color.gray&=0xff;
+ ping_trans_color.red&=0xff;
+ ping_trans_color.green&=0xff;
+ ping_trans_color.blue&=0xff;
+ ping_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_color_type=PNG_COLOR_TYPE_GRAY_ALPHA;
else
{
- ping_info->color_type=PNG_COLOR_TYPE_GRAY;
+ ping_color_type=PNG_COLOR_TYPE_GRAY;
if (save_image_depth == 16 && image_depth == 8)
- ping_info->trans_color.gray*=0x0101;
+ ping_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_bit_depth=16;
else
{
- ping_info->bit_depth=8;
- if ((int) ping_info->color_type == PNG_COLOR_TYPE_PALETTE)
+ ping_bit_depth=8;
+ if ((int) ping_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_bit_depth=1;
+ while ((int) (1 << ping_bit_depth)
< (long) image_colors)
- ping_info->bit_depth <<= 1;
+ ping_bit_depth <<= 1;
}
}
- else if (mng_info->optimize && ping_info->color_type ==
+ else if (mng_info->optimize && ping_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_bit_depth=1;
else if (depth_2_ok && mng_info->write_png_depth <= 2)
- ping_info->bit_depth=2;
+ ping_bit_depth=2;
else if (depth_4_ok && mng_info->write_png_depth <= 4)
- ping_info->bit_depth=4;
+ ping_bit_depth=4;
}
}
- image_depth=ping_info->bit_depth;
+ image_depth=ping_bit_depth;
}
else
if (mng_info->IsPalette)
/*
Set image palette.
*/
- ping_info->color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
+ ping_color_type=(png_byte) PNG_COLOR_TYPE_PALETTE;
ping_info->valid|=PNG_INFO_PLTE;
if (mng_info->have_write_global_plte && !matte)
{
" Setting up PLTE chunk with %d colors",
(int) number_colors);
png_set_PLTE(ping,ping_info,palette,(int) number_colors);
+#if (PNG_LIBPNG_VER > 10008)
palette=(png_colorp) RelinquishMagickMemory(palette);
+#endif
}
/* color_type is PNG_COLOR_TYPE_PALETTE */
if (!mng_info->write_png_depth)
{
ping_info->bit_depth=1;
while ((1UL << ping_info->bit_depth) < number_colors)
- ping_info->bit_depth <<= 1;
+ ping_bit_depth <<= 1;
}
- ping_info->num_trans=0;
+ ping_num_trans=0;
if (matte)
{
ExceptionInfo
if (trans[(long) packet_index] != (png_byte) (255-
ScaleQuantumToChar(GetOpacityPixelComponent(p))))
{
- ping_info->color_type=(png_byte)
+ ping_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_color_type == PNG_COLOR_TYPE_RGB_ALPHA)
{
- ping_info->num_trans=0;
+ ping_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_num_trans=(unsigned short) (i+1);
}
}
- if (ping_info->num_trans == 0)
+ if (ping_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_num_trans=0;
+ if (ping_num_trans != 0)
{
- ping_info->trans_alpha=(unsigned char *) AcquireQuantumMemory(
- number_colors,sizeof(*ping_info->trans_alpha));
- if (ping_info->trans_alpha == (unsigned char *) NULL)
+ ping_trans_alpha=(unsigned char *) AcquireQuantumMemory(
+ number_colors,sizeof(*ping_trans_alpha));
+ if (ping_trans_alpha == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,
"MemoryAllocationFailed");
for (i=0; i < (long) number_colors; i++)
- ping_info->trans_alpha[i]=(png_byte) trans[i];
+ ping_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_info->background,image->colormap[i]))
+ if (IsPNGColorEqual(ping_background,image->colormap[i]))
break;
- ping_info->background.index=(png_byte) i;
+ ping_background.index=(png_byte) i;
}
}
else
image_depth=8;
if ((save_image_depth == 16) && (image_depth == 8))
{
- ping_info->trans_color.red*=0x0101;
- ping_info->trans_color.green*=0x0101;
- ping_info->trans_color.blue*=0x0101;
- ping_info->trans_color.gray*=0x0101;
+ ping_trans_color.red*=0x0101;
+ ping_trans_color.green*=0x0101;
+ ping_trans_color.blue*=0x0101;
+ ping_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_bit_depth < 8 && ping_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_bit_depth)-1);
background.gray=(png_uint_16)
" Setting up bKGD chunk");
png_set_bKGD(ping,ping_info,&background);
- ping_info->trans_color.gray=(png_uint_16) (QuantumScale*(maxval*
- ping_info->trans_color.gray));
+ ping_trans_color.gray=(png_uint_16) (QuantumScale*(maxval*
+ ping_trans_color.gray));
}
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " PNG color type: %d",ping_info->color_type);
+ " PNG color type: %d",ping_color_type);
/*
Initialize compression level and filtering.
*/
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Setting up deflate compression");
+#if (PNG_LIBPNG_VER > 99)
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Compression buffer size: 32768");
png_set_compression_buffer_size(ping,32768L);
+#endif
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Compression mem level: 9");
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Filter_type: PNG_INTRAPIXEL_DIFFERENCING");
- ping_info->filter_type=PNG_INTRAPIXEL_DIFFERENCING;
+ ping_filter_method=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_color_type == PNG_COLOR_TYPE_GRAY) ||
+ ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE) ||
(quality < 50))
base_filter=PNG_NO_FILTERS;
else
profile=GetImageProfile(image,name);
if (profile != (StringInfo *) NULL)
{
-#if defined(PNG_WRITE_iCCP_SUPPORTED)
+#if (PNG_LIBPNG_VER > 10008) && defined(PNG_WRITE_iCCP_SUPPORTED)
if ((LocaleCompare(name,"ICC") == 0) ||
(LocaleCompare(name,"ICM") == 0))
png_set_iCCP(ping,ping_info,(const png_charp) name,0,(png_charp)
bp.x,bp.y);
}
}
- ping_info->interlace_type=image_info->interlace != NoInterlace;
+ ping_interlace_method=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_color_type = PNG_COLOR_TYPE_RGB;
+ if (ping_bit_depth < 8)
+ ping_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_color_type = PNG_COLOR_TYPE_RGB_ALPHA;
}
if ((mng_info->write_png_depth &&
- mng_info->write_png_depth != ping_info->bit_depth) ||
+ (int) mng_info->write_png_depth != ping_bit_depth) ||
(mng_info->write_png_colortype &&
- (mng_info->write_png_colortype-1 != ping_info->color_type &&
+ ((int) mng_info->write_png_colortype-1 != ping_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_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_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_color_type);
}
}
png_error(ping,
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Writing PNG header chunks");
+ png_set_IHDR(ping,ping_info,ping_width,ping_height,
+ ping_bit_depth,ping_color_type,
+ ping_interlace_method,ping_compression_method,
+ ping_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_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_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_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_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_color_type != PNG_COLOR_TYPE_GRAY) &&
+ (ping_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_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_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_width);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Height: %lu",ping_info->height);
+ " Height: %lu",ping_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_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_color_type);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " PNG Interlace method: %d",ping_info->interlace_type);
+ " PNG Interlace method: %d",ping_interlace_method);
}
/*
Generate text chunks.
*/
+#if (PNG_LIBPNG_VER <= 10005)
+ ping_info->num_text=0;
+#endif
ResetImagePropertyIterator(image);
property=GetNextImageProperty(image);
while (property != (const char *) NULL)
{
+#if (PNG_LIBPNG_VER > 10005)
png_textp
text;
+#endif
value=GetImageProperty(image,property);
if (value != (const char *) NULL)
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_width != mng_info->page.width) ||
+ (ping_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_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_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_bit_depth;
s[1]='\0';
(void) SetImageProperty(image,"png:bit-depth-written",s);
/*
Free PNG resources.
*/
+
png_destroy_write_struct(&ping,&ping_info);
png_pixels=(unsigned char *) RelinquishMagickMemory(png_pixels);