changeset 31199:30b28458bb06

Tiff: added method getDefaultStripLength * scripts/io/Tiff.m: added class method getDefaultStripLength to obtain the number of rows of a reasonably sized strip. * libtinterp/corefcn/__tiff__.cc: added internal function __tiff_default_strip_length__ to implement logic for getDefaultStripLength method. * scripts/image/private/__tiff_imwrite__.m: used the added method to obtain a default value for RowsPerStrip tag.
author magedrifaat <magedrifaat@gmail.com>
date Fri, 02 Sep 2022 03:30:45 +0200
parents 93eb0d6e7f62
children 4e8152ccc61a
files libinterp/corefcn/__tiff__.cc scripts/image/private/__tiff_imwrite__.m scripts/io/Tiff.m
diffstat 3 files changed, 34 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/__tiff__.cc	Fri Sep 02 03:06:29 2022 +0200
+++ b/libinterp/corefcn/__tiff__.cc	Fri Sep 02 03:30:45 2022 +0200
@@ -3322,6 +3322,33 @@
 #endif
   }
 
+  DEFUN (__tiff_default_strip_length__, args, ,
+         "Get the number of rows of a reasonable strip")
+  {
+#if defined (HAVE_TIFF)
+    int nargin = args.length ();
+
+    if (nargin == 0)
+      error ("No handle provided\n");
+    
+    octave_tiff_handle *tiff_handle
+      = octave_tiff_handle::get_tiff_handle (args(0));
+    check_closed (tiff_handle);
+
+    set_internal_handlers ();
+
+    TIFF *tif = tiff_handle->get_file ();
+    
+    if (TIFFIsTiled (tif))
+      error ("getDefaultStripLength: the image is tiled not stripped");
+
+    double strip_len = static_cast<double> (TIFFDefaultStripSize (tif, 0));
+    return ovl (strip_len);
+#else
+    err_disabled_feature ("getDefaultStripLength", "Tiff");
+#endif
+  }
+
   DEFUN (__tiff_current_directory__, args, ,
          "Get the index of the current directory")
   {
--- a/scripts/image/private/__tiff_imwrite__.m	Fri Sep 02 03:06:29 2022 +0200
+++ b/scripts/image/private/__tiff_imwrite__.m	Fri Sep 02 03:30:45 2022 +0200
@@ -213,12 +213,10 @@
     ## Try to get a reasonable size for RowsPerStrip if not set
     ## This must be done after the other tags are set so LibTIFF
     ## can make an informed calculation.
-    % if (rows_per_strip == -1)
-    %   rows_per_strip = tif.getDefaultStripLength ();
-    % endif
-    if (rows_per_strip != -1)
-      tif.setTag (Tiff.TagID.RowsPerStrip, rows_per_strip);
+    if (rows_per_strip == -1)
+      rows_per_strip = tif.getDefaultStripLength ();
     endif
+    tif.setTag (Tiff.TagID.RowsPerStrip, rows_per_strip);
 
     tif.write (img(:,:,:, dir_idx));
 
--- a/scripts/io/Tiff.m	Fri Sep 02 03:06:29 2022 +0200
+++ b/scripts/io/Tiff.m	Fri Sep 02 03:30:45 2022 +0200
@@ -223,6 +223,10 @@
       tileNumber = __tiff_compute_tile__ (t.tiff_handle, varargin{:});
     endfunction
 
+    function stripLength = getDefaultStripLength (t)
+      stripLength = __tiff_default_strip_length__ (t.tiff_handle);
+    endfunction
+
     function dirNum = currentDirectory (t)
       dirNum = __tiff_current_directory__ (t.tiff_handle);
     endfunction