changeset 31148:4bc9a1938f9a

Tiff: added isTiled method to check if the image is tiled or stripped * Tiff.m: added the isTiled method and a test for isTiled. * __tiff__.cc(F__is_tiled__): implemented the internal function for isTiled.
author magedrifaat <magedrifaat@gmail.com>
date Sun, 31 Jul 2022 21:29:15 +0200
parents 7af78a63d3c3
children d4dbc69f301e
files libinterp/dldfcn/__tiff__.cc scripts/io/Tiff.m
diffstat 2 files changed, 36 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/__tiff__.cc	Sun Jul 31 20:41:02 2022 +0200
+++ b/libinterp/dldfcn/__tiff__.cc	Sun Jul 31 21:29:15 2022 +0200
@@ -1513,4 +1513,22 @@
     err_disabled_feature ("writeEncodedTile", "Tiff");
 #endif
   }
+  
+  DEFUN_DLD (__is_tiled__, args, ,
+             "Get whether the image is tiled")
+  {
+#if defined (HAVE_TIFF)
+    int nargin = args.length ();
+
+    if (nargin == 0)
+      error ("No handle provided\n");
+    
+    TIFF *tif = (TIFF *)(args (0).uint64_value ());
+    bool is_tiled = static_cast<bool> (TIFFIsTiled (tif));
+    return octave_value_list (octave_value (is_tiled));
+#else
+    err_disabled_feature ("close", "Tiff");
+#endif
+  }
+
 }
--- a/scripts/io/Tiff.m	Sun Jul 31 20:41:02 2022 +0200
+++ b/scripts/io/Tiff.m	Sun Jul 31 21:29:15 2022 +0200
@@ -130,6 +130,13 @@
       __tiff_write_encoded_tile__ (t.tiff_handle, tileNumber, imageData);
     endfunction
 
+    function tf = isTiled (t)
+      if (t.closed)
+        error ("Image file was closed");
+      endif
+      tf = __is_tiled__ (t.tiff_handle);
+    endfunction
+
     % TODO(maged): add documentation and make print_usage work
   endmethods
 endclassdef
@@ -755,3 +762,14 @@
 %!    img.close ();
 %!  endfunction
 %!  file_wrapper (@test_fn);
+
+## test isTiled returns the correct value
+%!testif HAVE_TIFF
+%!  function test_fn (filename)
+%!    img = Tiff (filename, "w");
+%!    assert (isTiled (img), logical (0));
+%!    setTag (img, "TileLength", 16);
+%!    setTag (img, "TileWidth", 16);
+%!    assert (isTiled (img), logical (1));
+%!  endfunction
+%!  file_wrapper (@test_fn);
\ No newline at end of file