# HG changeset patch # User magedrifaat # Date 1660783787 -7200 # Node ID 4c8b8c400a3bc4167772b2e97fc0d9057e22e739 # Parent 8a4ef572077d322d435b244378f1d38d4c644ed5 __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well. diff -r 8a4ef572077d -r 4c8b8c400a3b libinterp/corefcn/__tiff__.cc --- a/libinterp/corefcn/__tiff__.cc Thu Aug 18 00:25:42 2022 +0200 +++ b/libinterp/corefcn/__tiff__.cc Thu Aug 18 02:49:47 2022 +0200 @@ -105,6 +105,93 @@ } }; + // A map of tag names supported by matlab, there are some differences + // than LibTIFF's names (e.g. Photometric vs PhotometricInerpretation) + // TODO(maged): use this to initialize TagID to avoid having two copies + static const std::map tag_name_map = { + {"SubFileType", 254}, + {"ImageWidth", 256}, + {"ImageLength", 257}, + {"BitsPerSample", 258}, + {"Compression", 259}, + {"Photometric", 262}, + {"Thresholding", 263}, + {"FillOrder", 266}, + {"DocumentName", 269}, + {"ImageDescription", 270}, + {"Make", 271}, + {"Model", 272}, + {"StripOffsets", 273}, + {"Orientation", 274}, + {"SamplesPerPixel", 277}, + {"RowsPerStrip", 278}, + {"StripByteCounts", 279}, + {"MinSampleValue", 280}, + {"MaxSampleValue", 281}, + {"XResolution", 282}, + {"YResolution", 283}, + {"PlanarConfiguration", 284}, + {"PageName", 285}, + {"XPosition", 286}, + {"YPosition", 287}, + {"GrayResponseUnit", 290}, + {"GrayResponseCurve", 291}, + {"Group3Options", 292}, + {"Group4Options", 293}, + {"ResolutionUnit", 296}, + {"PageNumber", 297}, + {"TransferFunction", 301}, + {"Software", 305}, + {"DateTime", 306}, + {"Artist", 315}, + {"HostComputer", 316}, + {"WhitePoint", 318}, + {"PrimaryChromaticities", 319}, + {"ColorMap", 320}, + {"HalfToneHints", 321}, + {"TileWidth", 322}, + {"TileLength", 323}, + {"TileOffsets", 324}, + {"TileByteCounts", 325}, + {"SubIFD", 330}, + {"InkSet", 332}, + {"InkNames", 333}, + {"NumberOfInks", 334}, + {"DotRange", 336}, + {"TargetPrinter", 337}, + {"ExtraSamples", 338}, + {"SampleFormat", 339}, + {"SMinSampleValue", 340}, + {"SMaxSampleValue", 341}, + {"YCbCrCoefficients", 529}, + {"YCbCrSubSampling", 530}, + {"YCbCrPositioning", 531}, + {"ReferenceBlackWhite", 532}, + {"XMP", 700}, + {"ImageDepth", 32997}, + {"Copyright", 33432}, + {"RichTIFFIPTC", 33723}, + {"Photoshop", 34377}, + {"ICCProfile", 34675}, + {"SToNits", 37439}, + {"JPEGQuality", 65537}, + {"JPEGColorMode", 65538}, + {"ZipQuality", 65557}, + {"SGILogDataFmt", 6556} + }; + + const TIFFField *get_fip_with_name (TIFF *tif, std::string& tag_name) + { + const TIFFField *fip = TIFFFieldWithName (tif, tag_name.c_str ()); + + // If the tag name is not found, fallback to the names defined + // in our name map. + if (! fip && tag_name_map.find (tag_name) != tag_name_map.cend ()) + fip = TIFFFieldWithTag (tif, tag_name_map.at (tag_name)); + + return fip; + } + void check_readonly (TIFF *tif) { @@ -2322,7 +2409,6 @@ if (nargin == 0 || nargin > 2) { - // TODO(maged): return invalid object instead?? error ("No filename supplied\n"); } @@ -2414,21 +2500,18 @@ TIFF *tif = tiff_handle->get_file (); - uint32_t tag_id; const TIFFField *fip; if (args(1).is_string ()) { - std::string tagName = args(1).string_value (); - fip = TIFFFieldWithName (tif, tagName.c_str ()); + std::string tag_name = args(1).string_value (); + fip = get_fip_with_name (tif, tag_name); if (! fip) error ("Tiff tag not found"); - - tag_id = TIFFFieldTag (fip); } else { - tag_id = args(1).int_value (); + ttag_t tag_id = args(1).int_value (); fip = TIFFFieldWithTag (tif, tag_id); if (! fip) @@ -2469,7 +2552,7 @@ for (octave_idx_type i = 0; i < keys.numel (); i++) { std::string key = keys[i]; - const TIFFField *fip = TIFFFieldWithName (tif, key.c_str ()); + const TIFFField *fip = get_fip_with_name (tif, key); if (! fip) error ("Tag %s not found", key.c_str ()); set_field_data (tif, fip, tags.contents (key)); @@ -2485,8 +2568,8 @@ // Make it work in both ways if (args(1).is_string ()) { - std::string tagName = args(1).string_value (); - fip = TIFFFieldWithName (tif, tagName.c_str ()); + std::string tag_name = args(1).string_value (); + fip = get_fip_with_name (tif, tag_name); if (! fip) error ("Tiff tag not found"); }