# HG changeset patch # User magedrifaat # Date 1662146456 -7200 # Node ID be6ccdcd5775782452663aa89c8635d9f919bf5b # Parent e5e8cb049b4b3ea62e8e42ffc38adcea987b8836 Tiff: added isBigEndian and getDirectoryOffset methods to the class * scripts/io/Tiff.m: added isBigEndian and getDirectoryOffset methods to the class. * libtinterp/corefcn/tiff.cc: added __tiff_is_big_endian__ and __tiff_get_directory_offset__ as internal functions for isBigEndian and getDirectoryOffset repectively. * scripts/image/private/__tiff_imfinfo__.m: used the two new methods to get the corresponding info fields. diff -r e5e8cb049b4b -r be6ccdcd5775 libinterp/corefcn/__tiff__.cc --- a/libinterp/corefcn/__tiff__.cc Fri Sep 02 20:52:47 2022 +0200 +++ b/libinterp/corefcn/__tiff__.cc Fri Sep 02 21:20:56 2022 +0200 @@ -3348,6 +3348,31 @@ #endif } + DEFUN (__tiff_is_big_endian__, args, , + "Get the whether the tiff file is big-endian") + { +#if defined (HAVE_TIFF) + int nargin = args.length (); + + if (nargin != 1) + error ("Wrong number of arguments\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 (); + + bool is_big_endian = TIFFIsBigEndian (tif); + + return ovl (is_big_endian); +#else + err_disabled_feature ("isBigEndian", "Tiff"); +#endif + } + DEFUN (__tiff_current_directory__, args, , "Get the index of the current directory") { @@ -3559,6 +3584,31 @@ #endif } + DEFUN (__tiff_get_directory_offset__, args, , + "Get the offset of the current directory in file") + { +#if defined (HAVE_TIFF) + int nargin = args.length (); + + if (nargin != 1) + error ("Wrong number of arguments\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 (); + + uint64_t offset = TIFFCurrentDirOffset (tif); + + return ovl (offset); +#else + err_disabled_feature ("getDirectoryOffset", "Tiff"); +#endif + } + DEFUN (__tiff_version__, , , "Get the version stamp of LibTIFF") { diff -r e5e8cb049b4b -r be6ccdcd5775 scripts/image/private/__tiff_imfinfo__.m --- a/scripts/image/private/__tiff_imfinfo__.m Fri Sep 02 20:52:47 2022 +0200 +++ b/scripts/image/private/__tiff_imfinfo__.m Fri Sep 02 21:20:56 2022 +0200 @@ -17,7 +17,7 @@ for dir_idx = 1:dir_count info(dir_idx).Filename = filename; info(dir_idx).FileModDate = strftime ("%e-%b-%Y %H:%M:%S", - localtime (file_stat.ctime)); + localtime (file_stat.mtime)); info(dir_idx).FileSize = file_stat.size; info(dir_idx).Format = "tif"; info(dir_idx).FormatVersion = ""; @@ -73,12 +73,11 @@ endif endif - ## FIXME: implement isBigEndian - # if (tif.isBigEndian ()) - # info(dir_idx).ByteOrder = "big-endian"; - # else - # info(dir_idx).ByteOrder = "little-endian"; - # endif + if (tif.isBigEndian ()) + info(dir_idx).ByteOrder = "big-endian"; + else + info(dir_idx).ByteOrder = "little-endian"; + endif info(dir_idx).NewSubFileType ... = get_tag_defaulted (tif, Tiff.TagID.SubFileType, @@ -153,8 +152,7 @@ = get_tag_defaulted (tif, Tiff.TagID.Thresholding, Tiff.Thresholding.BiLevel); - ## FIXME: implement getDirectoryOffset method - # info(dir_idx).Offset = tif.getDirectoryOffset (); + info(dir_idx).Offset = tif.getDirectoryOffset (); info(dir_idx).ImageDescription ... = get_tag_defaulted (tif, Tiff.TagID.ImageDescription, ""); diff -r e5e8cb049b4b -r be6ccdcd5775 scripts/io/Tiff.m --- a/scripts/io/Tiff.m Fri Sep 02 20:52:47 2022 +0200 +++ b/scripts/io/Tiff.m Fri Sep 02 21:20:56 2022 +0200 @@ -227,6 +227,10 @@ stripLength = __tiff_default_strip_length__ (t.tiff_handle); endfunction + function tf = isBigEndian (t) + tf = __tiff_is_big_endian__ (t.tiff_handle); + endfunction + function dirNum = currentDirectory (t) dirNum = __tiff_current_directory__ (t.tiff_handle); endfunction @@ -255,6 +259,10 @@ __tiff_set_sub_directory__ (t.tiff_handle, offset); endfunction + function offset = getDirectoryOffset (t) + offset = __tiff_get_directory_offset__ (t.tiff_handle); + endfunction + % TODO(maged): add documentation and make print_usage work endmethods