}
#endif /* MAGICKCORE_QUANTUM_DEPTH >= 16 */
+static const char* PngColorTypeToString(const unsigned int color_type)
+{
+ const char
+ *result = "Unknown";
+
+ switch (color_type)
+ {
+ case PNG_COLOR_TYPE_GRAY:
+ result = "Gray";
+ break;
+ case PNG_COLOR_TYPE_GRAY_ALPHA:
+ result = "Gray+Alpha";
+ break;
+ case PNG_COLOR_TYPE_PALETTE:
+ result = "Palette";
+ break;
+ case PNG_COLOR_TYPE_RGB:
+ result = "RGB";
+ break;
+ case PNG_COLOR_TYPE_RGB_ALPHA:
+ result = "RGB+Alpha";
+ break;
+ }
+
+ return result;
+}
+
static int
Magick_RenderingIntent_to_PNG_RenderingIntent(const RenderingIntent intent)
{
return(y);
}
-static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)
+static const char *
+Magick_ColorType_from_PNG_ColorType(const int ping_colortype)
{
- if (x < y)
- return(x);
+ switch (ping_colortype)
+ {
+ case 0:
+ return "Grayscale";
- return(y);
-}
+ case 2:
+ return "Truecolor";
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
-% I m a g e I s G r a y %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% Like IsImageGray except does not change DirectClass to PseudoClass %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-*/
-static MagickBooleanType ImageIsGray(Image *image,ExceptionInfo *exception)
-{
- register const Quantum
- *p;
+ case 3:
+ return "Indexed";
- register ssize_t
- i,
- x,
- y;
+ case 4:
+ return "GrayAlpha";
- assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- if (image->debug != MagickFalse)
- (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+ case 6:
+ return "RGBA";
- if (image->storage_class == PseudoClass)
- {
- for (i=0; i < (ssize_t) image->colors; i++)
- if (IsPixelInfoGray(image->colormap+i) == MagickFalse)
- return(MagickFalse);
- return(MagickTrue);
- }
- for (y=0; y < (ssize_t) image->rows; y++)
- {
- p=GetVirtualPixels(image,0,y,image->columns,1,exception);
- if (p == (const Quantum *) NULL)
- return(MagickFalse);
- for (x=(ssize_t) image->columns-1; x >= 0; x--)
- {
- if (IsPixelGray(image,p) == MagickFalse)
- return(MagickFalse);
- p+=GetPixelChannels(image);
+ default:
+ return "UndefinedColorType";
}
- }
- return(MagickTrue);
+}
+
+
+static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)
+{
+ if (x < y)
+ return(x);
+
+ return(y);
}
#endif /* PNG_LIBPNG_VER > 10011 */
#endif /* MAGICKCORE_PNG_DELEGATE */
num_text,
num_text_total,
num_passes,
+ number_colors,
pass,
ping_bit_depth,
ping_color_type,
ssize_t
j;
-#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
+#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
png_byte unused_chunks[]=
{
104, 73, 83, 84, (png_byte) '\0', /* hIST */
115, 67, 65, 76, (png_byte) '\0', /* sCAL */
115, 80, 76, 84, (png_byte) '\0', /* sPLT */
116, 73, 77, 69, (png_byte) '\0', /* tIME */
+#ifdef PNG_APNG_SUPPORTED /* libpng was built with APNG patch; */
+ /* ignore the APNG chunks */
+ 97, 99, 84, 76, (png_byte) '\0', /* acTL */
+ 102, 99, 84, 76, (png_byte) '\0', /* fcTL */
+ 102, 100, 65, 84, (png_byte) '\0', /* fdAT */
+#endif
};
#endif
transparent_color.blue=65537;
transparent_color.alpha=65537;
+ number_colors=0;
num_text = 0;
num_text_total = 0;
num_raw_profiles = 0;
png_set_read_user_chunk_fn(ping, image, read_vpag_chunk_callback);
#endif
+#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
+ /* Disable new libpng-1.5.10 feature */
+ png_set_check_for_invalid_index (ping, 0);
+#endif
+
#if (PNG_LIBPNG_VER < 10400)
# if defined(PNG_USE_PNGGCCRD) && defined(PNG_ASSEMBLER_CODE_SUPPORTED) && \
(PNG_LIBPNG_VER >= 10200) && (PNG_LIBPNG_VER < 10220) && defined(__i386__)
image->depth=ping_bit_depth;
image->depth=GetImageQuantumDepth(image,MagickFalse);
image->interlace=ping_interlace_method != 0 ? PNGInterlace : NoInterlace;
+ if (((int) ping_color_type == PNG_COLOR_TYPE_GRAY) ||
+ ((int) ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
+ {
+ image->rendering_intent=UndefinedIntent;
+ image->gamma=1.000;
+ (void) ResetMagickMemory(&image->chromaticity,0,
+ sizeof(image->chromaticity));
+ }
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
png_set_sRGB(ping,ping_info,
Magick_RenderingIntent_to_PNG_RenderingIntent
(image->rendering_intent));
- png_set_gAMA(ping,ping_info,0.45455f);
+ png_set_gAMA(ping,ping_info,1.000f/2.200f);
png_set_cHRM(ping,ping_info,
0.6400f, 0.3300f, 0.3000f, 0.6000f,
0.1500f, 0.0600f, 0.3127f, 0.3290f);
if (png_get_valid(ping,ping_info,PNG_INFO_PLTE))
{
- int
- number_colors;
-
png_colorp
palette;
image->compression=ZipCompression;
image->columns=ping_width;
image->rows=ping_height;
+
if (((int) ping_color_type == PNG_COLOR_TYPE_GRAY) ||
((int) ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
- image->colorspace=GRAYColorspace;
+ {
+ if (!png_get_valid(ping,ping_info,PNG_INFO_gAMA) &&
+ !png_get_valid(ping,ping_info,PNG_INFO_cHRM) &&
+ !png_get_valid(ping,ping_info,PNG_INFO_sRGB))
+ {
+ /* Set image->gamma to 1.0, image->rendering_intent to Undefined,
+ * and reset image->chromaticity.
+ */
+ SetImageColorspace(image,GRAYColorspace,exception);
+ }
+ }
+
if (((int) ping_color_type == PNG_COLOR_TYPE_PALETTE) ||
((int) ping_color_type == PNG_COLOR_TYPE_GRAY))
{
#endif
if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE)
{
- int
- number_colors;
-
png_colorp
palette;
if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE)
{
- int
- number_colors;
-
png_colorp
palette;
(void) FormatLocaleString(msg,MaxTextExtent,"%d",(int) ping_bit_depth);
(void) SetImageProperty(image,"png:IHDR.bit_depth ",msg,exception);
- (void) FormatLocaleString(msg,MaxTextExtent,"%d",(int) ping_color_type);
+ (void) FormatLocaleString(msg,MaxTextExtent,"%d (%s)",
+ (int) ping_color_type,
+ Magick_ColorType_from_PNG_ColorType((int)ping_color_type));
(void) SetImageProperty(image,"png:IHDR.color_type ",msg,exception);
- (void) FormatLocaleString(msg,MaxTextExtent,"%d",
- (int) ping_interlace_method);
- (void) SetImageProperty(image,"png:IHDR.interlace_method",msg,exception);
+ if (ping_interlace_method == 0)
+ {
+ (void) FormatLocaleString(msg,MaxTextExtent,"%d (Not interlaced)",
+ (int) ping_interlace_method);
+ }
+ else if (ping_interlace_method == 1)
+ {
+ (void) FormatLocaleString(msg,MaxTextExtent,"%d (Adam7 method)",
+ (int) ping_interlace_method);
+ }
+ else
+ {
+ (void) FormatLocaleString(msg,MaxTextExtent,"%d (Unknown method)",
+ (int) ping_interlace_method);
+ }
+ (void) SetImageProperty(image,"png:IHDR.interlace_method",msg,exception);
+
+ if (number_colors != 0)
+ {
+ (void) FormatLocaleString(msg,MaxTextExtent,"%d",
+ (int) number_colors);
+ (void) SetImageProperty(image,"png:PLTE.number_colors ",msg,
+ exception);
+ }
}
/*
row_offset=0;
png_read_row(ping,ping_pixels+row_offset,NULL);
- q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
+ q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
break;
if (png_get_valid(ping,ping_info,PNG_INFO_PLTE))
{
- int
- number_colors;
-
png_colorp
plte;
ThrowReaderException(CorruptImageError,"CorruptImage");
}
+ if ((IssRGBColorspace(image->colorspace) != MagickFalse) &&
+ (image->gamma == 1.0))
+ SetImageColorspace(image,RGBColorspace,exception);
+
if (LocaleCompare(image_info->magick,"PNG24") == 0)
{
(void) SetImageType(image,TrueColorType,exception);
{
image->rendering_intent=
Magick_RenderingIntent_from_PNG_RenderingIntent(p[0]);
- image->gamma=0.45455f;
+ image->gamma=1.000f/2.200f;
image->chromaticity.red_primary.x=0.6400f;
image->chromaticity.red_primary.y=0.3300f;
image->chromaticity.green_primary.x=0.3000f;
}
}
- if (IssRGBColorspace(image->colorspace) == MagickFalse)
+ if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace,exception);
/*
{
opaque[i] = image->background_color;
ping_background.index = i;
+ number_opaque++;
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
if (mng_info->write_png_colortype != 7) /* We won't need this info */
{
ping_have_color=MagickFalse;
+ if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+ ping_have_color=MagickTrue;
ping_have_non_bw=MagickFalse;
if(image_colors > 256)
/*
Prepare PNG for writing.
*/
+
#if defined(PNG_MNG_FEATURES_SUPPORTED)
if (mng_info->write_mng)
+ {
(void) png_permit_mng_features(ping,PNG_ALL_MNG_FEATURES);
+# ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED
+ /* Disable new libpng-1.5.10 feature when writing a MNG because
+ * zero-length PLTE is OK
+ */
+ png_set_check_for_invalid_index (ping, 0);
+# endif
+ }
#else
# ifdef PNG_WRITE_EMPTY_PLTE_SUPPORTED
if (logging != MagickFalse)
{
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " Tentative PNG color type: %.20g",(double) ping_color_type);
+ " Tentative PNG color type: %s (%.20g)",
+ PngColorTypeToString(ping_color_type),
+ (double) ping_color_type);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" image_info->type: %.20g",(double) image_info->type);
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " PNG color type: %d",ping_color_type);
+ " PNG color type: %s (%d)", PngColorTypeToString(ping_color_type),
+ ping_color_type);
/*
Initialize compression level and filtering.
*/
if (mng_info->write_png_compression_strategy == 0)
{
if ((quality %10) == 8 || (quality %10) == 9)
- mng_info->write_png_compression_strategy=Z_RLE;
+#ifdef Z_RLE /* Z_RLE was added to zlib-1.2.0 */
+ mng_info->write_png_compression_strategy=Z_RLE+1;
+#else
+ mng_info->write_png_compression_strategy = Z_DEFAULT_STRATEGY+1;
+#endif
}
if (mng_info->write_png_compression_filter == 0)
#if defined(PNG_WRITE_sRGB_SUPPORTED)
if ((mng_info->have_write_global_srgb == 0) &&
- ((image->rendering_intent != UndefinedIntent) ||
- (image->colorspace == sRGBColorspace)))
+ (image->rendering_intent != UndefinedIntent))
{
if (ping_exclude_sRGB == MagickFalse)
{
{
for (y=0; y < (ssize_t) image->rows; y++)
{
- p=GetVirtualPixels(image,0,y,image->columns,1,
- exception);
+ p=GetVirtualPixels(image,0,y,image->columns,1, exception);
if (p == (const Quantum *) NULL)
break;
/* Check if image is grayscale. */
if (image_info->type != TrueColorMatteType && image_info->type !=
- TrueColorType && ImageIsGray(image,exception))
+ TrueColorType && IsImageGray(image,exception))
jng_color_type-=2;
if (logging != MagickFalse)
if (need_local_plte == 0)
{
- if (ImageIsGray(image,exception) == MagickFalse)
+ if (IsImageGray(image,exception) == MagickFalse)
all_images_are_gray=MagickFalse;
mng_info->equal_palettes=PalettesAreEqual(image,next_image);
if (use_global_plte == 0)