changeset 17122:59acfe9209dd

Do not read alpha channel from image if output not requested. * __magick_read__.cc (read_images): check nargout and change image type to its non-matte equivalent if alpha channel is not requested as output.
author Carnë Draug <carandraug@octave.org>
date Wed, 31 Jul 2013 13:14:09 +0100
parents 00985134145e
children 47b504503a3f
files libinterp/dldfcn/__magick_read__.cc
diffstat 1 files changed, 40 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/__magick_read__.cc
+++ b/libinterp/dldfcn/__magick_read__.cc
@@ -147,7 +147,8 @@
 template <class T>
 octave_value_list
 read_images (std::vector<Magick::Image>& imvec,
-             const Array<octave_idx_type>& frameidx)
+             const Array<octave_idx_type>& frameidx,
+             const octave_idx_type nargout)
 {
   typedef typename T::element_type P;
 
@@ -190,6 +191,40 @@
       type = Magick::GrayscaleMatteType;
     }
 
+  // If the alpha channel was not requested, treat images as if
+  // it doesn't exist.
+  if (nargout < 3)
+    {
+      switch (type)
+        {
+        case Magick::GrayscaleMatteType:
+          {
+            type = Magick::GrayscaleType;
+            break;
+          }
+        case Magick::PaletteMatteType:
+          {
+            type = Magick::PaletteType;
+            break;
+          }
+        case Magick::TrueColorMatteType:
+          {
+            type = Magick::TrueColorType;
+            break;
+          }
+        case Magick::ColorSeparationMatteType:
+          {
+            type = Magick::ColorSeparationType;
+            break;
+          }
+        default:
+          {
+            // do nothing, other than silencing warnings about enumeration
+            // values not being handled in switch.
+          }
+        }
+    }
+
   switch (type)
     {
     case Magick::BilevelType:           // Monochrome bi-level image
@@ -580,19 +615,19 @@
     {
       if (depth <= 1)
         {
-          output = read_images<boolNDArray> (imvec, frameidx);
+          output = read_images<boolNDArray> (imvec, frameidx, nargout);
         }
       else if (depth <= 8)
         {
-          output = read_images<uint8NDArray> (imvec, frameidx);
+          output = read_images<uint8NDArray> (imvec, frameidx, nargout);
         }
       else if (depth <= 16)
         {
-          output = read_images<uint16NDArray> (imvec, frameidx);
+          output = read_images<uint16NDArray> (imvec, frameidx, nargout);
         }
       else if (depth <= 32)
         {
-          output = read_images<FloatNDArray> (imvec, frameidx);
+          output = read_images<FloatNDArray> (imvec, frameidx, nargout);
         }
       else
         {