comparison libinterp/corefcn/__tiff__.cc @ 31185:a1145ac2ce9b

Tiff: populated TagID from the C++ map to avoid having two copies * __tiff__.cc (F__tiff_make_tagid__): implemented internal function as initializer for TagID. * Tiff.m: changed the initialization for TagID to use the internal function.
author magedrifaat <magedrifaat@gmail.com>
date Thu, 18 Aug 2022 17:23:43 +0200
parents 86f91ea7a642
children 90eccc78d958
comparison
equal deleted inserted replaced
31184:86f91ea7a642 31185:a1145ac2ce9b
91 91
92 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE, 92 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE,
93 &bits_per_sample)) 93 &bits_per_sample))
94 error ("Failed to read the BitsPerSample tag"); 94 error ("Failed to read the BitsPerSample tag");
95 95
96 // TODO(maged): this doesn't really work for writing as LibTIFF will
97 // refuse to write unless the tag is set
98 if (! TIFFGetField (tif, TIFFTAG_PLANARCONFIG, 96 if (! TIFFGetField (tif, TIFFTAG_PLANARCONFIG,
99 &planar_configuration)) 97 &planar_configuration))
100 // LibTIFF has a bug where it incorrectly returns 0 as a default 98 // LibTIFF has a bug where it incorrectly returns 0 as a default
101 // value for PlanarConfiguration although the default value is 1 99 // value for PlanarConfiguration although the default value is 1
100 // This doesn't completely solve the issue as LibTIFF will refuse
101 // to write data to images of the tag is not set.
102 // see: https://www.asmail.be/msg0054918184.html
102 planar_configuration = 1; 103 planar_configuration = 1;
103 104
104 is_tiled = TIFFIsTiled(tif); 105 is_tiled = TIFFIsTiled(tif);
105 } 106 }
106 }; 107 };
107 108
108 // A map of tag names supported by matlab, there are some differences 109 // A map of tag names supported by matlab, there are some differences
109 // than LibTIFF's names (e.g. Photometric vs PhotometricInerpretation) 110 // than LibTIFF's names (e.g. Photometric vs PhotometricInerpretation)
110 // TODO(maged): use this to initialize TagID to avoid having two copies
111 static const std::map<std::string, ttag_t> tag_name_map = { 111 static const std::map<std::string, ttag_t> tag_name_map = {
112 {"SubFileType", 254}, 112 {"SubFileType", 254},
113 {"ImageWidth", 256}, 113 {"ImageWidth", 256},
114 {"ImageLength", 257}, 114 {"ImageLength", 257},
115 {"BitsPerSample", 258}, 115 {"BitsPerSample", 258},
1071 uint8_t *data_ptr = data.get (); 1071 uint8_t *data_ptr = data.get ();
1072 if (tag_id == TIFFTAG_PLANARCONFIG) 1072 if (tag_id == TIFFTAG_PLANARCONFIG)
1073 { 1073 {
1074 // Workaround for a bug in LibTIFF where it incorrectly returns 1074 // Workaround for a bug in LibTIFF where it incorrectly returns
1075 // zero as the default value for PlanaConfiguration 1075 // zero as the default value for PlanaConfiguration
1076 // See: https://www.asmail.be/msg0054918184.html
1076 if (! TIFFGetField(tif, tag_id, data_ptr)) 1077 if (! TIFFGetField(tif, tag_id, data_ptr))
1077 *reinterpret_cast<uint16_t *> (data_ptr) = 1; 1078 *reinterpret_cast<uint16_t *> (data_ptr) = 1;
1078 } 1079 }
1079 else 1080 else
1080 validate_tiff_get_field (TIFFGetFieldDefaulted (tif, tag_id, data_ptr)); 1081 validate_tiff_get_field (TIFFGetFieldDefaulted (tif, tag_id, data_ptr));
3469 #else 3470 #else
3470 err_disabled_feature ("setErrorEnabled", "Tiff"); 3471 err_disabled_feature ("setErrorEnabled", "Tiff");
3471 #endif 3472 #endif
3472 } 3473 }
3473 3474
3475 DEFUN (__tiff_make_tagid__, , ,
3476 "Create the TagID structure from the internal map")
3477 {
3478 std::map<std::string, octave_value> tag_ov_map;
3479 for (auto it = tag_name_map.cbegin (); it != tag_name_map.cend (); it++)
3480 tag_ov_map[it->first] = octave_value (it->second);
3481 return octave_value_list(octave_scalar_map (tag_ov_map));
3482 }
3474 } 3483 }