# HG changeset patch # User Carnë Draug # Date 1393962259 0 # Node ID 0bfbfb05b1585d64ac23615758918b27e85343a3 # Parent 30aa4e85f8d5ae43f6312338655ea2d74599fb44 imwrite.m: simplify test blocks by make use of shared %!function. diff -r 30aa4e85f8d5 -r 0bfbfb05b158 scripts/image/imwrite.m --- a/scripts/image/imwrite.m Tue Mar 04 16:52:00 2014 +0000 +++ b/scripts/image/imwrite.m Tue Mar 04 19:44:19 2014 +0000 @@ -125,52 +125,37 @@ %!error imwrite ([], "filename.jpg") # Empty img matrix %!error imwrite (spones (2), "filename.jpg") # Invalid sparse img -## test typical usage with normal grayscale and RGB uint8 images -%!testif HAVE_MAGICK -%! bw = randi (255, 10, "uint8"); -%! rgb = randi (255, 10, 10, 3, "uint8"); -%! filename = [tmpnam() ".png"]; -%! unwind_protect -%! imwrite (bw, filename); -%! bwr = imread (filename); -%! assert (bw, bwr) -%! -%! imwrite (rgb, filename); -%! rgbr = imread (filename); -%! assert (rgb, rgbr) -%! unwind_protect_cleanup -%! unlink (filename); -%! end_unwind_protect +%!function [r, cmap, a] = write_and_read (varargin) +%! filename = [tmpnam() ".tif"]; +%! unwind_protect +%! imwrite (varargin{1}, filename, varargin{2:end}); +%! [r, cmap, a] = imread (filename, "Index", "all"); +%! unwind_protect_cleanup +%! unlink (filename); +%! end_unwind_protect +%!endfunction -## Test writing of N dimensional images +## typical usage with grayscale uint8 images %!testif HAVE_MAGICK -%! bw = randi (255, 10, 10, 1, 5, "uint8"); -%! rgb = randi (255, 3, 3, 3, 3, "uint8"); -%! filename = [tmpnam() ".tif"]; -%! unwind_protect -%! imwrite (bw, filename); -%! bwr = imread (filename, "Index", "all"); -%! assert (bw, bwr) -%! -%! imwrite (rgb, filename); -%! rgbr = imread (filename, "Index", "all"); -%! assert (rgb, rgbr) -%! -%! unwind_protect_cleanup -%! unlink (filename); -%! end_unwind_protect +%! bw = randi (255, 10, 10, 1, "uint8"); +%! r = write_and_read (bw); +%! assert (r, bw) + +## multipage grayscale uint8 images +%!testif HAVE_MAGICK +%! bw = randi (255, 10, 10, 1, 5, "uint8"); +%! r = write_and_read (bw); +%! assert (r, bw) -## test reading and writing of the alpha channel +## typical usage with RGB uint8 images %!testif HAVE_MAGICK -%! imw = randi (255, 10, "uint8"); -%! alphaw = randi (255, 10, "uint8"); -%! filename = [tmpnam() ".png"]; -%! unwind_protect -%! imwrite (imw, filename, "Alpha", alphaw); -%! [imr, ~, alphar] = imread (filename); -%! assert (imw, imr) -%! assert (alphaw, alphar) -%! unwind_protect_cleanup -%! unlink (filename); -%! end_unwind_protect +%! rgb = randi (255, 10, 10, 3, "uint8"); +%! r = write_and_read (rgb); +%! assert (r, rgb) +## multipage RGB uint8 images +%!testif HAVE_MAGICK +%! rgb = randi (255, 10, 10, 3, 5, "uint8"); +%! r = write_and_read (rgb); +%! assert (r, rgb) +