changeset 31145:2e11f9cb30b8

Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
author magedrifaat <magedrifaat@gmail.com>
date Sun, 31 Jul 2022 03:55:42 +0200
parents 8ba9f2326ee9
children 50402b8dfb4a
files libinterp/dldfcn/__tiff__.cc scripts/io/Tiff.m
diffstat 2 files changed, 31 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/__tiff__.cc	Sun Jul 31 01:26:02 2022 +0200
+++ b/libinterp/dldfcn/__tiff__.cc	Sun Jul 31 03:55:42 2022 +0200
@@ -932,12 +932,33 @@
       }
     else
       error ("Planar configuration not supported");
+
+    if (strip_data.dim1 () > rows_in_strip)
+      warning ("The strip is composed of %ld rows but the input has %ld rows.",
+               rows_in_strip,
+               strip_data.dim1 ());
     
-    // TODO(maged): give a warning for a larger input strip
+    if (strip_data.dim2 () > image_data->width)
+      warning ("The image width is %ld but the input has %ld columns.",
+               image_data->width,
+               strip_data.dim2 ());
+    
+    if (strip_data.ndims () > 2)
+      {
+        if (image_data->planar_configuration == PLANARCONFIG_CONTIG
+            && strip_data.dim3 () > image_data->samples_per_pixel)
+          warning ("The strip is composed of %ld channels but the input has %ld channels.",
+                   image_data->samples_per_pixel,
+                   strip_data.dim3 ());
+        else if (image_data->planar_configuration == PLANARCONFIG_SEPARATE
+                && strip_data.dim3 () > 1)
+          warning ("The strip is composed of %ld channel but the input has %ld channels.",
+                   1, strip_data.dim3 ());
+      }
+
+    // TODO(maged): check dimesnions of boundary strips in matlab
     strip_data.resize (strip_dimensions);
 
-    //TODO(maged): add suppot for 1-bit images
-
     // Permute the dimesions of the strip to match the expected memory
     // arrangement of LibTIFF (channel x width x height)
     Array<octave_idx_type> perm (dim_vector (3, 1));
--- a/scripts/io/Tiff.m	Sun Jul 31 01:26:02 2022 +0200
+++ b/scripts/io/Tiff.m	Sun Jul 31 03:55:42 2022 +0200
@@ -237,8 +237,9 @@
 %!    img = Tiff (filename, "w");
 %!    setTag (img, struct ("ImageLength", 1, "ImageWidth", 10,
 %!                         "BitsPerSample", 8, "SamplesPerPixel", 1));
-%!    data = uint8 (reshape (1:9, [1, 9]));
-%!    writeEncodedStrip (img, 1, data);
+%!    data = uint8 (reshape (1:13, [1, 13]));
+%!    fail ("writeEncodedStrip (img, 1, data)", "warning",
+%!          "The image width is 10 but the input has 13 columns.");
 %!    img.close ();
 %!    verify_data (filename, data, [1, 10]);
 %!  endfunction
@@ -264,7 +265,8 @@
 %!    setTag (img, struct ("ImageLength", 10, "ImageWidth", 10,
 %!                         "BitsPerSample", 8, "SamplesPerPixel", 1));
 %!    data = uint8 (reshape (1:110, [11, 10]));
-%!    writeEncodedStrip (img, 1, data);
+%!    fail ("writeEncodedStrip (img, 1, data)", "warning",
+%!          "The strip is composed of 10 rows but the input has 11 rows.");
 %!    img.close ();
 %!    verify_data (filename, data, [10, 10]);
 %!  endfunction
@@ -294,7 +296,8 @@
 %!                         "PlanarConfiguration", 1,
 %!                         "PhotometricInterpretation", 2));
 %!    data = uint8 (reshape (1:400, [10, 10, 4]));
-%!    writeEncodedStrip (img, 1, data);
+%!    fail ("writeEncodedStrip (img, 1, data)", "warning",
+%!          "The strip is composed of 3 channels but the input has 4 channels.");
 %!    img.close ();
 %!    verify_data (filename, data, [10, 10, 3]);
 %!  endfunction