# HG changeset patch # User Carnë Draug # Date 1375272849 -3600 # Node ID 59acfe9209dd425d412f6045efac240ac9cbfb2a # Parent 00985134145e02ac3c14983177589a4606ab844b 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. diff -r 00985134145e -r 59acfe9209dd libinterp/dldfcn/__magick_read__.cc --- a/libinterp/dldfcn/__magick_read__.cc Tue Jul 30 21:29:57 2013 -0400 +++ b/libinterp/dldfcn/__magick_read__.cc Wed Jul 31 13:14:09 2013 +0100 @@ -147,7 +147,8 @@ template octave_value_list read_images (std::vector& imvec, - const Array& frameidx) + const Array& 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 (imvec, frameidx); + output = read_images (imvec, frameidx, nargout); } else if (depth <= 8) { - output = read_images (imvec, frameidx); + output = read_images (imvec, frameidx, nargout); } else if (depth <= 16) { - output = read_images (imvec, frameidx); + output = read_images (imvec, frameidx, nargout); } else if (depth <= 32) { - output = read_images (imvec, frameidx); + output = read_images (imvec, frameidx, nargout); } else {