Mercurial > hg > octave-nkf
changeset 18612: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 | 17baa684892c |
files | libinterp/dldfcn/__magick_read__.cc scripts/image/imwrite.m |
diffstat | 2 files changed, 41 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/dldfcn/__magick_read__.cc +++ b/libinterp/dldfcn/__magick_read__.cc @@ -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++;
--- a/scripts/image/imwrite.m +++ b/scripts/image/imwrite.m @@ -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) +