]> granicus.if.org Git - imagemagick/commitdiff
Implemented PNG00 subformat
authorglennrp <glennrp@git.imagemagick.org>
Sun, 27 Jan 2013 06:11:45 +0000 (06:11 +0000)
committerglennrp <glennrp@git.imagemagick.org>
Sun, 27 Jan 2013 06:11:45 +0000 (06:11 +0000)
coders/png.c
tests/validate.h

index 080c2f4862598e8e07ec1eab34f683cff44d12d3..9b0967fbf3197051538e760fd68d2bb1449023cb 100644 (file)
@@ -2331,6 +2331,18 @@ static Image *ReadOnePNGImage(MngInfo *mng_info,
 
   ping_file_depth = ping_bit_depth;
 
+  /* Save bit-depth and color-type in case we later want to write a PNG00 */
+  {
+      char
+        msg[MaxTextExtent];
+
+      (void) FormatLocaleString(msg,MaxTextExtent,"%d",(int) ping_color_type);
+      (void) SetImageProperty(image,"png:IHDR.color-type-orig ",msg,exception);
+
+      (void) FormatLocaleString(msg,MaxTextExtent,"%d",(int) ping_bit_depth);
+      (void) SetImageProperty(image,"png:IHDR.bit-depth-orig  ",msg,exception);
+  }
+
   (void) png_get_tRNS(ping, ping_info, &ping_trans_alpha, &ping_num_trans,
                       &ping_trans_color);
 
@@ -3603,6 +3615,30 @@ static Image *ReadOnePNGImage(MngInfo *mng_info,
         (png_get_valid(ping,ping_info,PNG_INFO_tRNS))) ?
         BlendPixelTrait : UndefinedPixelTrait;
 
+    if (image->alpha_trait == BlendPixelTrait)
+    {
+      if (ping_color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+        (void) SetImageType(image,GrayscaleMatteType,exception);
+
+      else if (ping_color_type == PNG_COLOR_TYPE_PALETTE)
+        (void) SetImageType(image,PaletteMatteType,exception);
+
+      else
+        (void) SetImageType(image,TrueColorMatteType,exception);
+    }
+
+    else
+    {
+      if (ping_color_type == PNG_COLOR_TYPE_GRAY)
+        (void) SetImageType(image,GrayscaleType,exception);
+
+      else if (ping_color_type == PNG_COLOR_TYPE_PALETTE)
+        (void) SetImageType(image,PaletteType,exception);
+
+      else
+        (void) SetImageType(image,TrueColorType,exception);
+    }
+
    /* Set more properties for identify to retrieve */
    {
      char
@@ -3832,17 +3868,6 @@ static Image *ReadPNGImage(const ImageInfo *image_info,ExceptionInfo *exception)
       ((image->gamma < .45) || (image->gamma > .46)))
     SetImageColorspace(image,RGBColorspace,exception);
 
-  if ((LocaleCompare(image_info->magick,"PNG24") == 0) ||
-      (LocaleCompare(image_info->magick,"PNG48") == 0))
-    {
-      (void) SetImageType(image,TrueColorType,exception);
-      image->alpha_trait=UndefinedPixelTrait;
-    }
-
-  if ((LocaleCompare(image_info->magick,"PNG32") == 0) ||
-      (LocaleCompare(image_info->magick,"PNG64") == 0))
-    (void) SetImageType(image,TrueColorMatteType,exception);
-
   if (logging != MagickFalse)
     (void) LogMagickEvent(CoderEvent,GetMagickModule(),
         "  page.w: %.20g, page.h: %.20g,page.x: %.20g, page.y: %.20g.",
@@ -7320,6 +7345,19 @@ ModuleExport size_t RegisterPNGImage(void)
   entry->module=ConstantString("PNG");
   (void) RegisterMagickInfo(entry);
 
+  entry=SetMagickInfo("PNG00");
+
+#if defined(MAGICKCORE_PNG_DELEGATE)
+  entry->decoder=(DecodeImageHandler *) ReadPNGImage;
+  entry->encoder=(EncodeImageHandler *) WritePNGImage;
+#endif
+
+  entry->magick=(IsImageFormatHandler *) IsPNG;
+  entry->adjoin=MagickFalse;
+  entry->description=ConstantString("PNG inheriting subformat from original");
+  entry->module=ConstantString("PNG");
+  (void) RegisterMagickInfo(entry);
+
   entry=SetMagickInfo("JNG");
 
 #if defined(JNG_SUPPORTED)
@@ -7371,6 +7409,7 @@ ModuleExport void UnregisterPNGImage(void)
   (void) UnregisterMagickInfo("PNG32");
   (void) UnregisterMagickInfo("PNG48");
   (void) UnregisterMagickInfo("PNG64");
+  (void) UnregisterMagickInfo("PNG00");
   (void) UnregisterMagickInfo("JNG");
 
 #ifdef PNG_SETJMP_NOT_THREAD_SAFE
@@ -11086,6 +11125,11 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
 %               each pixel can have any value from 0 to 65535. The alpha
 %               channel is present even if the image is fully opaque.
 %
+%    o PNG00:   A PNG that inherits its colortype and bit-depth from the input
+%               image, if the input was a PNG, is written.  If these values
+%               cannot be found, then "PNG00" falls back to the regular "PNG"
+%               format.
+%
 %    o -define: For more precise control of the PNG output, you can use the
 %               Image options "png:bit-depth" and "png:color-type".  These
 %               can be set from the commandline with "-define" and also
@@ -11239,6 +11283,63 @@ static MagickBooleanType WritePNGImage(const ImageInfo *image_info,
       else if (LocaleCompare(value,"png64") == 0)
         mng_info->write_png64 = MagickTrue;
     }
+
+  if (LocaleCompare(value,"png00") == 0)
+    {
+      /* Retrieve png:IHDR.bit-depth-orig and png:IHDR.color-type-orig
+         Note that whitespace at the end of the property names must match
+         that in the corresponding SetImageProperty() calls.
+       */
+      (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+         "  Format=%s",value);
+
+      value=GetImageProperty(image,"png:IHDR.bit-depth-orig  ",exception);
+
+      (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+         "  png00 inherited bit depth=%s",value);
+
+      if (value != (char *) NULL)
+        {
+          if (LocaleCompare(value,"1") == 0)
+            mng_info->write_png_depth = 1;
+
+          else if (LocaleCompare(value,"1") == 0)
+            mng_info->write_png_depth = 2;
+
+          else if (LocaleCompare(value,"2") == 0)
+            mng_info->write_png_depth = 4;
+
+          else if (LocaleCompare(value,"8") == 0)
+            mng_info->write_png_depth = 8;
+
+          else if (LocaleCompare(value,"16") == 0)
+            mng_info->write_png_depth = 16;
+        }
+
+      value=GetImageProperty(image,"png:IHDR.color-type-orig ",exception);
+
+      (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+         "  png00 inherited color type=%s",value);
+
+      if (value != (char *) NULL)
+        {
+          if (LocaleCompare(value,"0") == 0)
+            mng_info->write_png_colortype = 1;
+
+          else if (LocaleCompare(value,"2") == 0)
+            mng_info->write_png_colortype = 3;
+
+          else if (LocaleCompare(value,"3") == 0)
+            mng_info->write_png_colortype = 4;
+
+          else if (LocaleCompare(value,"4") == 0)
+            mng_info->write_png_colortype = 5;
+
+          else if (LocaleCompare(value,"6") == 0)
+            mng_info->write_png_colortype = 7;
+        }
+    }
+
   if (mng_info->write_png8)
     {
       mng_info->write_png_colortype = /* 3 */ 4;
index 6e63fe6557cf0f0c3dcbbc6272ea1a1980c9c73b..c82bfe31197e632a564e22ba78db1d528ad5ba64 100644 (file)
@@ -308,6 +308,7 @@ static const struct ReferenceFormats
     { "PNG32", UndefinedCompression, 0.0 },
     { "PNG48", UndefinedCompression, 0.0 },
     { "PNG64", UndefinedCompression, 0.0 },
+    { "PNG00", UndefinedCompression, 0.0 },
     { "PNM", UndefinedCompression, 0.0 },
     { "PPM", UndefinedCompression, 0.0 },
     { "PREVIEW", UndefinedCompression, 0.0 },