changeset 17239:d6467d6dfb83

Fix reading of alpha channel stored as tRNS chunk in PNG files. * __magick_read__ (read_images): because we are checking the original color type for PNG values (to make sure we identify an RGB or grayscale image correctly), we need to also check the alpha channel separately since it may be stored as a tRNS chunk and not as color.
author Carnë Draug <carandraug@octave.org>
date Tue, 13 Aug 2013 18:41:41 +0100
parents 3fd617363762
children d757c98636d8
files libinterp/dldfcn/__magick_read__.cc
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/__magick_read__.cc	Tue Aug 13 16:38:25 2013 -0700
+++ b/libinterp/dldfcn/__magick_read__.cc	Tue Aug 13 18:41:41 2013 +0100
@@ -270,6 +270,18 @@
         type = Magick::TrueColorMatteType;
       else if (type_str == "4")
         type = Magick::GrayscaleMatteType;
+      // Color types 0, 2, and 3 can also have alpha channel, conveyed
+      // via the "tRNS" chunk.  For 0 and 2, it's limited to GIF-style
+      // binary transparency, while 3 can have any level of alpha per
+      // palette entry. We thus must check matte() to see if the image
+      // really doesn't have an alpha channel.
+      if (imvec[0].matte ())
+        {
+          if (type == Magick::GrayscaleType)
+            type = Magick::GrayscaleMatteType;
+          else if (type == Magick::TrueColorType)
+            type = Magick::TrueColorMatteType;
+        }
     }
 
   // If the alpha channel was not requested, treat images as if