Mercurial > octave-libtiff
changeset 31149:d4dbc69f301e
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.
author | magedrifaat <magedrifaat@gmail.com> |
---|---|
date | Sun, 31 Jul 2022 22:32:02 +0200 |
parents | 4bc9a1938f9a |
children | 6bede2d6f273 |
files | libinterp/dldfcn/__tiff__.cc scripts/io/Tiff.m |
diffstat | 2 files changed, 43 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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<double> (TIFFNumberOfStrips (tif)); + return octave_value_list (octave_value (strip_count)); +#else + err_disabled_feature ("close", "Tiff"); +#endif + } + }
--- 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