# HG changeset patch # User magedrifaat # Date 1659299522 -7200 # Node ID d4dbc69f301e63925ba89823f509a2b433b5d8ca # Parent 4bc9a1938f9a4e7d30e8c032ebecd72ef4c981d1 Tiff: implemented numberOfStrips method * Tiff.m: added numberOfStrips method and a test for the method. * __tiff__.cc(F__number_of_strips__): implemented the internal funciton with the logic for numberOfStrips. diff -r 4bc9a1938f9a -r d4dbc69f301e libinterp/dldfcn/__tiff__.cc --- a/libinterp/dldfcn/__tiff__.cc Sun Jul 31 21:29:15 2022 +0200 +++ b/libinterp/dldfcn/__tiff__.cc Sun Jul 31 22:32:02 2022 +0200 @@ -1531,4 +1531,24 @@ #endif } + DEFUN_DLD (__number_of_strips__, args, , + "Get the number of strips in the image") + { +#if defined (HAVE_TIFF) + int nargin = args.length (); + + if (nargin == 0) + error ("No handle provided\n"); + + TIFF *tif = (TIFF *)(args (0).uint64_value ()); + if (TIFFIsTiled (tif)) + error ("The image is tiled not stripped"); + + double strip_count = static_cast (TIFFNumberOfStrips (tif)); + return octave_value_list (octave_value (strip_count)); +#else + err_disabled_feature ("close", "Tiff"); +#endif + } + } diff -r 4bc9a1938f9a -r d4dbc69f301e scripts/io/Tiff.m --- a/scripts/io/Tiff.m Sun Jul 31 21:29:15 2022 +0200 +++ b/scripts/io/Tiff.m Sun Jul 31 22:32:02 2022 +0200 @@ -137,6 +137,13 @@ tf = __is_tiled__ (t.tiff_handle); endfunction + function numStrips = numberOfStrips (t) + if (t.closed) + error ("Image file was closed"); + endif + numStrips = __number_of_strips__ (t.tiff_handle); + endfunction + % TODO(maged): add documentation and make print_usage work endmethods endclassdef @@ -772,4 +779,20 @@ %! setTag (img, "TileWidth", 16); %! assert (isTiled (img), logical (1)); %! endfunction +%! file_wrapper (@test_fn); + +## test numberOfStrips returns the correct value +%!testif HAVE_TIFF +%! function test_fn (filename) +%! img = Tiff (filename, "w"); +%! setTag (img, struct ("ImageWidth", 10, "ImageLength", 10)); +%! assert (numberOfStrips (img), 1); +%! setTag (img, "RowsPerStrip", 2); +%! assert (numberOfStrips (img), 5); +%! setTag (img, "RowsPerStrip", 4); +%! assert (numberOfStrips (img), 3); +%! setTag (img, "TileLength", 16); +%! setTag (img, "TileWidth", 16); +%! fail ("numberOfStrips (img)", "The image is tiled not stripped"); +%! endfunction %! file_wrapper (@test_fn); \ No newline at end of file