# HG changeset patch # User Carnë Draug # Date 1393963800 0 # Node ID e0cc67d5a462ef71b1a73358b5bdbd449e436a56 # Parent 0bfbfb05b1585d64ac23615758918b27e85343a3 Fix writing of grayscale images when there is an alpha channel. * __magick_read__.cc (encode_uint_image): create Magick::Color object for gray color with Alpha channel correctly, i.e., repeat the gray value 3 times as if it was an RGB image. * imwrite.m: add 4 new tests for writing of single page and multipage, grayscale and RGB images with alpha channel. diff -r 0bfbfb05b158 -r e0cc67d5a462 libinterp/dldfcn/__magick_read__.cc --- a/libinterp/dldfcn/__magick_read__.cc Tue Mar 04 19:44:19 2014 +0000 +++ b/libinterp/dldfcn/__magick_read__.cc Tue Mar 04 20:10:00 2014 +0000 @@ -1110,9 +1110,9 @@ { for (octave_idx_type row = 0; row < nRows; row++) { - Magick::Color c; - c.redQuantum (double (*img_fvec) / divisor); - c.alphaQuantum (MaxRGB - (double (*a_fvec) / divisor)); + double grey = double (*img_fvec) / divisor; + Magick::Color c (grey, grey, grey, + MaxRGB - (double (*a_fvec) / divisor)); pix[GM_idx] = c; img_fvec++; a_fvec++; diff -r 0bfbfb05b158 -r e0cc67d5a462 scripts/image/imwrite.m --- a/scripts/image/imwrite.m Tue Mar 04 19:44:19 2014 +0000 +++ b/scripts/image/imwrite.m Tue Mar 04 20:10:00 2014 +0000 @@ -137,15 +137,31 @@ ## typical usage with grayscale uint8 images %!testif HAVE_MAGICK -%! bw = randi (255, 10, 10, 1, "uint8"); -%! r = write_and_read (bw); -%! assert (r, bw) +%! gray = randi (255, 10, 10, 1, "uint8"); +%! r = write_and_read (gray); +%! assert (r, gray) + +## grayscale uint8 images with alpha channel +%!testif HAVE_MAGICK +%! gray = randi (255, 10, 10, 1, "uint8"); +%! alpha = randi (255, 10, 10, 1, "uint8"); +%! [r, ~, a] = write_and_read (gray, "Alpha", alpha); +%! assert (r, gray) +%! assert (a, alpha) ## multipage grayscale uint8 images %!testif HAVE_MAGICK -%! bw = randi (255, 10, 10, 1, 5, "uint8"); -%! r = write_and_read (bw); -%! assert (r, bw) +%! gray = randi (255, 10, 10, 1, 5, "uint8"); +%! r = write_and_read (gray); +%! assert (r, gray) + +## multipage RGB uint8 images with alpha channel +%!testif HAVE_MAGICK +%! gray = randi (255, 10, 10, 3, 5, "uint8"); +%! alpha = randi (255, 10, 10, 1, 5, "uint8"); +%! [r, ~, a] = write_and_read (gray, "Alpha", alpha); +%! assert (r, gray) +%! assert (a, alpha) ## typical usage with RGB uint8 images %!testif HAVE_MAGICK @@ -153,9 +169,25 @@ %! r = write_and_read (rgb); %! assert (r, rgb) +## RGB uint8 images with alpha channel +%!testif HAVE_MAGICK +%! rgb = randi (255, 10, 10, 3, "uint8"); +%! alpha = randi (255, 10, 10, 1, "uint8"); +%! [r, ~, a] = write_and_read (rgb, "Alpha", alpha); +%! assert (r, rgb) +%! assert (a, alpha) + ## multipage RGB uint8 images %!testif HAVE_MAGICK %! rgb = randi (255, 10, 10, 3, 5, "uint8"); %! r = write_and_read (rgb); %! assert (r, rgb) +## multipage RGB uint8 images with alpha channel +%!testif HAVE_MAGICK +%! rgb = randi (255, 10, 10, 3, 5, "uint8"); +%! alpha = randi (255, 10, 10, 1, 5, "uint8"); +%! [r, ~, a] = write_and_read (rgb, "Alpha", alpha); +%! assert (r, rgb) +%! assert (a, alpha) +