Mercurial > octave-libtiff
changeset 31134:fc0366e009dd
Tiff.m: added tests for 8-bit grayscale and RGB images.
author | magedrifaat <magedrifaat@gmail.com> |
---|---|
date | Tue, 26 Jul 2022 19:53:35 +0200 |
parents | e9925d528428 |
children | b7ffe64e0287 |
files | scripts/io/Tiff.m |
diffstat | 1 files changed, 72 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/io/Tiff.m Tue Jul 26 18:37:55 2022 +0200 +++ b/scripts/io/Tiff.m Tue Jul 26 19:53:35 2022 +0200 @@ -125,13 +125,13 @@ %! endif %!endfunction -## test one-pixel image +## test one-pixel grayscale image %!testif HAVE_TIFF %! filename = [tempname() ".tif"]; %! unwind_protect %! a = Tiff (filename, "w"); %! set_configs (a, 1, 1, 1, 8); -%! data = uint8 ([255]); +%! data = uint8 (randi (intmax ("uint8"), 1, 1)); %! writeEncodedStrip (a, 1, data); %! a.close (); %! a = Tiff (filename, "r"); @@ -148,20 +148,20 @@ %! filename = [tempname() ".tif"]; %! unwind_protect %! a = Tiff (filename, "w"); -%! data = uint8 ([255]); +%! data = uint8 (randi (intmax ("uint8"), 1, 1)); %! fail ("writeEncodedStrip (a, 1, data)", "Failed to read image width"); %! a.close (); %! unwind_protect_cleanup %! unlink (filename); %! end_unwind_protect -## test one row image +## test one row grayscale image %!testif HAVE_TIFF %! filename = [tempname() ".tif"]; %! unwind_protect %! a = Tiff (filename, "w"); %! set_configs (a, 1, 10, 1, 8); -%! data = uint8 (randi (255, 1, 10)); +%! data = uint8 (randi (intmax ("uint8"), 1, 10)); %! writeEncodedStrip (a, 1, data); %! a.close (); %! a = Tiff (filename, "r"); @@ -179,9 +179,75 @@ %! unwind_protect %! a = Tiff (filename, "w"); %! set_configs (a, 1, 10, 1, 8); -%! data = uint8 (randi (255, 1, 9)); +%! data = uint8 (randi (intmax ("uint8"), 1, 9)); %! fail ("writeEncodedStrip (a, 1, data)", "Size of strip data is different from the expected size of the strip"); %! a.close (); %! unwind_protect_cleanup %! unlink (filename); %! end_unwind_protect + +## test one strip grayscale image +%!testif HAVE_TIFF +%! filename = [tempname() ".tif"]; +%! unwind_protect +%! a = Tiff (filename, "w"); +%! set_configs (a, 10, 10, 1, 8); +%! data = uint8 (randi (intmax ("uint8"), 10, 10)); +%! writeEncodedStrip (a, 1, data); +%! a.close (); +%! a = Tiff (filename, "r"); +%! data2 = a.read (); +%! assert (size (data2), [10, 10]); +%! assert (data2, data); +%! a.close (); +%! unwind_protect_cleanup +%! unlink (filename); +%! end_unwind_protect + +## test one strip grayscale image +%!testif HAVE_TIFF +%! filename = [tempname() ".tif"]; +%! unwind_protect +%! a = Tiff (filename, "w"); +%! set_configs (a, 10, 10, 1, 8); +%! data = uint8 (randi (intmax ("uint8"), 11, 10)); +%! fail ("writeEncodedStrip (a, 1, data)", "Size of strip data is different from the expected size of the strip"); +%! a.close (); +%! unwind_protect_cleanup +%! unlink (filename); +%! end_unwind_protect + +## test one strip RGB image +%!testif HAVE_TIFF +%! filename = [tempname() ".tif"]; +%! unwind_protect +%! a = Tiff (filename, "w"); +%! set_configs (a, 10, 10, 3, 8); +%! setTag(a, "PlanarConfiguration", 1); +%! setTag(a, "PhotometricInterpretation", 2); +%! data = uint8 (randi (intmax ("uint8"), 10, 10, 3)); +%! writeEncodedStrip (a, 1, data); +%! a.close (); +%! a = Tiff (filename, "r"); +%! data2 = a.read (); +%! assert (size (data2), [10, 10, 3]); +%! assert (data2, data); +%! a.close (); +%! unwind_protect_cleanup +%! unlink (filename); +%! end_unwind_protect + +## test one strip RGB image +%!testif HAVE_TIFF +%! filename = [tempname() ".tif"]; +%! unwind_protect +%! a = Tiff (filename, "w"); +%! set_configs (a, 10, 10, 3, 8); +%! setTag(a, "PlanarConfiguration", 1); +%! setTag(a, "PhotometricInterpretation", 2); +%! data = uint8 (randi (intmax ("uint8"), 10, 10, 4)); +%! fail ("writeEncodedStrip (a, 1, data)", "Size of strip data is different from the expected size of the strip"); +%! a.close (); +%! unwind_protect_cleanup +%! unlink (filename); +%! end_unwind_protect