changeset 31135:b7ffe64e0287

Tiff.m: added test for 16- and 32-bit grayscale and RGB images.
author magedrifaat <magedrifaat@gmail.com>
date Tue, 26 Jul 2022 20:44:24 +0200
parents fc0366e009dd
children be1a983981b2
files libinterp/dldfcn/__tiff__.cc scripts/io/Tiff.m
diffstat 2 files changed, 132 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/__tiff__.cc	Tue Jul 26 19:53:35 2022 +0200
+++ b/libinterp/dldfcn/__tiff__.cc	Tue Jul 26 20:44:24 2022 +0200
@@ -1144,7 +1144,7 @@
 
     if (sample_format == 3)
       {
-        if (false && image_data.bits_per_sample != 32 && image_data.bits_per_sample != 64)
+        if (image_data.bits_per_sample != 32 && image_data.bits_per_sample != 64)
           error ("Floating point images are only supported for bit depths of 32 and 64");
       }
     else if (sample_format != 1 && sample_format != 4)
--- a/scripts/io/Tiff.m	Tue Jul 26 19:53:35 2022 +0200
+++ b/scripts/io/Tiff.m	Tue Jul 26 20:44:24 2022 +0200
@@ -204,7 +204,7 @@
 %!    unlink (filename);
 %!  end_unwind_protect
 
-## test one strip grayscale image
+## test failure wrong height of strip
 %!testif HAVE_TIFF
 %!  filename = [tempname() ".tif"];
 %!  unwind_protect
@@ -217,7 +217,7 @@
 %!    unlink (filename);
 %!  end_unwind_protect
 
-## test one strip RGB image
+## test one strip RGB image chunky planes (RGBRGBRGB)
 %!testif HAVE_TIFF
 %!  filename = [tempname() ".tif"];
 %!  unwind_protect
@@ -237,7 +237,7 @@
 %!    unlink (filename);
 %!  end_unwind_protect
 
-## test one strip RGB image
+## test failure wrong number of channels
 %!testif HAVE_TIFF
 %!  filename = [tempname() ".tif"];
 %!  unwind_protect
@@ -251,3 +251,131 @@
 %!  unwind_protect_cleanup
 %!    unlink (filename);
 %!  end_unwind_protect
+
+## test one strip RGB image separate planes (RRRGGGBBB)
+%!testif HAVE_TIFF
+%!  filename = [tempname() ".tif"];
+%!  unwind_protect
+%!    a = Tiff (filename, "w");
+%!    set_configs (a, 10, 10, 3, 8);
+%!    setTag(a, "PlanarConfiguration", 2);
+%!    setTag(a, "PhotometricInterpretation", 2);
+%!    data = uint8 (randi (intmax ("uint8"), 10, 10, 3));
+%!    for i = 1:3
+%!      writeEncodedStrip (a, i, data(:,:,i));
+%!    endfor
+%!    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 failure of strip size in separate planes image
+%!testif HAVE_TIFF
+%!  filename = [tempname() ".tif"];
+%!  unwind_protect
+%!    a = Tiff (filename, "w");
+%!    set_configs (a, 10, 10, 3, 8);
+%!    setTag(a, "PlanarConfiguration", 2);
+%!    setTag(a, "PhotometricInterpretation", 2);
+%!    data = uint8 (randi (intmax ("uint8"), 10, 10, 3));
+%!    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 16-bit grayscale image
+%!testif HAVE_TIFF
+%!  filename = [tempname() ".tif"];
+%!  unwind_protect
+%!    a = Tiff (filename, "w");
+%!    set_configs (a, 20, 20, 1, 16);
+%!    data = uint16 (randi (intmax ("uint16"), 20, 20));
+%!    writeEncodedStrip (a, 1, data);
+%!    a.close ();
+%!    a = Tiff (filename, "r");
+%!    data2 = a.read ();
+%!    assert (size (data2), [20, 20]);
+%!    assert (data2, data);
+%!    a.close ();
+%!  unwind_protect_cleanup
+%!    unlink (filename);
+%!  end_unwind_protect
+
+## test 32-bit grayscale image
+%!testif HAVE_TIFF
+%!  filename = [tempname() ".tif"];
+%!  unwind_protect
+%!    a = Tiff (filename, "w");
+%!    set_configs (a, 20, 20, 1, 32);
+%!    data = uint32 (randi (intmax ("uint32"), 20, 20));
+%!    writeEncodedStrip (a, 1, data);
+%!    a.close ();
+%!    a = Tiff (filename, "r");
+%!    data2 = a.read ();
+%!    assert (size (data2), [20, 20]);
+%!    assert (data2, data);
+%!    a.close ();
+%!  unwind_protect_cleanup
+%!    unlink (filename);
+%!  end_unwind_protect
+
+## test 16-bit RGB image
+%!testif HAVE_TIFF
+%!  filename = [tempname() ".tif"];
+%!  unwind_protect
+%!    a = Tiff (filename, "w");
+%!    set_configs (a, 20, 20, 3, 16);
+%!    setTag(a, "PlanarConfiguration", 1);
+%!    setTag(a, "PhotometricInterpretation", 2);
+%!    data = uint16 (randi (intmax ("uint16"), 20, 20, 3));
+%!    writeEncodedStrip (a, 1, data);
+%!    a.close ();
+%!    a = Tiff (filename, "r");
+%!    data2 = a.read ();
+%!    assert (size (data2), [20, 20, 3]);
+%!    assert (data2, data);
+%!    a.close ();
+%!  unwind_protect_cleanup
+%!    unlink (filename);
+%!  end_unwind_protect
+
+## test 32-bit RGB image
+%!testif HAVE_TIFF
+%!  filename = [tempname() ".tif"];
+%!  unwind_protect
+%!    a = Tiff (filename, "w");
+%!    set_configs (a, 20, 20, 3, 32);
+%!    setTag(a, "PlanarConfiguration", 1);
+%!    setTag(a, "PhotometricInterpretation", 2);
+%!    data = uint32 (randi (intmax ("uint32"), 20, 20, 3));
+%!    writeEncodedStrip (a, 1, data);
+%!    a.close ();
+%!    a = Tiff (filename, "r");
+%!    data2 = a.read ();
+%!    assert (size (data2), [20, 20, 3]);
+%!    assert (data2, data);
+%!    a.close ();
+%!  unwind_protect_cleanup
+%!    unlink (filename);
+%!  end_unwind_protect
+
+## test failure data-type and bit-depth mismatch
+%!testif HAVE_TIFF
+%!  filename = [tempname() ".tif"];
+%!  unwind_protect
+%!    a = Tiff (filename, "w");
+%!    set_configs (a, 20, 20, 3, 16);
+%!    setTag(a, "PlanarConfiguration", 1);
+%!    setTag(a, "PhotometricInterpretation", 2);
+%!    data = uint8 (randi (intmax ("uint8"), 20, 20, 3));
+%!    fail ("writeEncodedStrip (a, 1, data)", "Only uint16 and int16 data are allowed for images with bit depth of 16");
+%!    a.close ();
+%!  unwind_protect_cleanup
+%!    unlink (filename);
+%!  end_unwind_protect