# HG changeset patch # User magedrifaat # Date 1662490670 -7200 # Node ID e83a62df599b560204ed80fce5e510b920fa2466 # Parent bbb41a5f377a300efe0d86c33cc6fbc00e22f7f7 __magick_read__: appended alpha to the rest of the channels for Tiff images * libinterp/corefcn/__magick_read__.cc (read_images, read_indexed_images): added logic to append the alpha channel to the rest of the channels and return an empty alpha for TIFF images for matlab compatibility. diff -r bbb41a5f377a -r e83a62df599b libinterp/corefcn/__magick_read__.cc --- a/libinterp/corefcn/__magick_read__.cc Sun Sep 04 15:57:47 2022 +0200 +++ b/libinterp/corefcn/__magick_read__.cc Tue Sep 06 20:57:50 2022 +0200 @@ -263,6 +263,21 @@ octave_idx_type m_col_out; }; +template +static octave_value +append_alpha (octave_value channels, octave_value alpha) +{ + // ASSUMES the dimensions of channels and alpha are already validated + typedef typename T::element_type P; + + OCTAVE_LOCAL_BUFFER (Array

, array_list, 2); + array_list[0] = octave_value_extract (channels); + array_list[1] = octave_value_extract (alpha); + + // Concatenate the two arrays on the 3rd dimensions + return octave_value (Array

::cat (2, 2, array_list)); +} + static octave_value_list read_maps (Magick::Image& img) { @@ -374,6 +389,15 @@ } } + // For TIFF images, matlab doesn't return a separate alpha channel but + // appends tha alpha channel to the rest of the channels in the first + // return value, and returns an empty alpha channel + if (imvec[0].magick () == "TIFF" && ! retval(2).isempty ()) + { + retval (0) = append_alpha (retval (0), retval (2)); + retval (2) = Matrix (); + } + return retval; } @@ -757,6 +781,14 @@ retval(0) = img; + // For TIFF images, matlab doesn't return a separate alpha channel but + // appends tha alpha channel to the rest of the channels in the first + // return value, and returns an empty alpha channel + if (imvec[0].magick () == "TIFF" && ! retval(2).isempty ()) + { + retval (0) = append_alpha (retval (0), retval (2)); + retval (2) = Matrix (); + } return retval; }