Mercurial > octave-libtiff
changeset 31142:97e7ee3b27b7
Tiff setTag: modify the behavior with structs to be compatible with matlab
* __tiff__.cc(F_tiff_set_tag__): change the way structs are handled so that
elements are processed in the same order they were assigned for matlab compatibility.
author | magedrifaat <magedrifaat@gmail.com> |
---|---|
date | Fri, 29 Jul 2022 01:16:02 +0200 |
parents | af4519cbfcae |
children | a68f2dadafee |
files | libinterp/dldfcn/__tiff__.cc |
diffstat | 1 files changed, 15 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/dldfcn/__tiff__.cc Fri Jul 29 00:46:44 2022 +0200 +++ b/libinterp/dldfcn/__tiff__.cc Fri Jul 29 01:16:02 2022 +0200 @@ -931,7 +931,7 @@ else error ("Planar configuration not supported"); - // TODO(maged): give a warning for a larger inpput strip + // TODO(maged): give a warning for a larger input strip strip_data.resize (strip_dimensions); //TODO(maged): add suppot for 1-bit images @@ -974,11 +974,10 @@ if (nargin == 2) mode = args (1).string_value (); - // TODO(maged): look into const begin and end - std::vector<std::string> supported_modes {"r", "w", "w8", "a"}; + const std::vector<std::string> supported_modes {"r", "w", "w8", "a"}; - if (std::find(supported_modes.begin(), supported_modes.end(), mode) - == supported_modes.end()) + if (std::find (supported_modes.cbegin (), supported_modes.cend (), mode) + == supported_modes.cend ()) { if (mode == "r+") error ("Openning files in r+ mode is not yet supported"); @@ -1010,7 +1009,6 @@ if (nargin == 0) error ("No handle provided\n"); - // TODO: mark object as closed to prevent segfault/ check matlab behavior TIFF *tif = (TIFF *)(args (0).uint64_value ()); TIFFClose (tif); @@ -1074,23 +1072,21 @@ TIFF *tif = (TIFF *)(args (0).uint64_value ()); - // TODO(maged): should all tags be verified first? if (args (1).isstruct ()) { octave_scalar_map tags = args (1).scalar_map_value (); - // Verify existance of all tags first - for (auto tag_it = tags.cbegin (); tag_it != tags.cend (); tag_it++) + string_vector keys = tags.fieldnames (); + // Using iterators instead of this loop method seems to process + // the elements of the struct in a different order than they were + // assigned which makes the behavior here incompatible with matlab + // in case of errors. + for (octave_idx_type i = 0; i < keys.numel (); i++) { - std::string key = tags.key (tag_it); - if (! TIFFFieldWithName (tif, key.c_str ())) + std::string key = keys[i]; + const TIFFField *fip = TIFFFieldWithName (tif, key.c_str ()); + if (! fip) error ("Tag %s not found", key.c_str ()); - } - - for (auto tag_it = tags.cbegin (); tag_it != tags.cend (); tag_it++) - { - std::string key = tags.key (tag_it); - const TIFFField *fip = TIFFFieldWithName (tif, key.c_str ()); - set_field_data (tif, fip, tags.contents (tag_it)); + set_field_data (tif, fip, tags.contents (key)); } } else @@ -1099,6 +1095,7 @@ error ("Too few arguments provided"); const TIFFField *fip; + // TODO(maged): matlab actually checks for its own strings not LibTIFF's if (args (1).is_string ()) { std::string tagName = args (1).string_value ();