diff scripts/image/imwrite.m @ 18544:e0cc67d5a462 stable

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.
author Carnë Draug <carandraug@octave.org>
date Tue, 04 Mar 2014 20:10:00 +0000
parents 0bfbfb05b158
children b83fca22bb4c
line wrap: on
line diff
--- 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)
+