comparison libinterp/corefcn/__tiff__.cc @ 31186:90eccc78d958

__tiff__.cc (get_field_data, set_field_data): added support for complex tags.
author magedrifaat <magedrifaat@gmail.com>
date Thu, 18 Aug 2022 20:44:06 +0200
parents a1145ac2ce9b
children 2bff8446484c
comparison
equal deleted inserted replaced
31185:a1145ac2ce9b 31186:90eccc78d958
1103 get_field_data (TIFF *tif, const TIFFField *fip) 1103 get_field_data (TIFF *tif, const TIFFField *fip)
1104 { 1104 {
1105 octave_value tag_data_ov; 1105 octave_value tag_data_ov;
1106 uint32_t tag_id = TIFFFieldTag (fip); 1106 uint32_t tag_id = TIFFFieldTag (fip);
1107 1107
1108 // TODO(maged): find/create images to test the special tags
1109 switch (tag_id) 1108 switch (tag_id)
1110 { 1109 {
1111 case TIFFTAG_STRIPBYTECOUNTS: 1110 case TIFFTAG_STRIPBYTECOUNTS:
1112 case TIFFTAG_STRIPOFFSETS: 1111 case TIFFTAG_STRIPOFFSETS:
1113 tag_data_ov = get_array_field_data (tif, fip, 1112 tag_data_ov = get_array_field_data (tif, fip,
1265 &count, &types)); 1264 &count, &types));
1266 tag_data_ov = interpret_tag_data (types, count, 1265 tag_data_ov = interpret_tag_data (types, count,
1267 TIFFFieldDataType (fip)); 1266 TIFFFieldDataType (fip));
1268 break; 1267 break;
1269 } 1268 }
1270 // TODO(maged): These tags are more complex to implement
1271 // will be implemented and tested later.
1272 case TIFFTAG_XMLPACKET: 1269 case TIFFTAG_XMLPACKET:
1273 case TIFFTAG_RICHTIFFIPTC: 1270 case TIFFTAG_RICHTIFFIPTC:
1274 case TIFFTAG_PHOTOSHOP: 1271 case TIFFTAG_PHOTOSHOP:
1275 case TIFFTAG_ICCPROFILE: 1272 case TIFFTAG_ICCPROFILE:
1276 { 1273 {
1277 error ("Complex Tags not implemented"); 1274 uint32_t count;
1275 uint8_t *data;
1276 validate_tiff_get_field (TIFFGetField (tif, tag_id,
1277 &count, &data));
1278 tag_data_ov = interpret_tag_data (data, count, TIFF_BYTE);
1279 // Matlab returns XMP tag as char array not byte array
1280 if (tag_id == TIFFTAG_XMLPACKET)
1281 tag_data_ov = octave_value (tag_data_ov.char_array_value ());
1278 break; 1282 break;
1279 } 1283 }
1280 // These tags are not mentioned in the LibTIFF documentation 1284 // These tags are not mentioned in the LibTIFF documentation
1281 // but are handled correctly by the library 1285 // but are handled correctly by the library
1282 case TIFFTAG_ZIPQUALITY: 1286 case TIFFTAG_ZIPQUALITY:
1454 void 1458 void
1455 set_field_data (TIFF *tif, const TIFFField *fip, octave_value tag_ov) 1459 set_field_data (TIFF *tif, const TIFFField *fip, octave_value tag_ov)
1456 { 1460 {
1457 uint32_t tag_id = TIFFFieldTag (fip); 1461 uint32_t tag_id = TIFFFieldTag (fip);
1458 1462
1459 // TODO(maged): find/create images to test the special tags
1460 switch (tag_id) 1463 switch (tag_id)
1461 { 1464 {
1462 case TIFFTAG_YCBCRCOEFFICIENTS: 1465 case TIFFTAG_YCBCRCOEFFICIENTS:
1463 set_array_field_data (tif, fip, tag_ov, 3); 1466 set_array_field_data (tif, fip, tag_ov, 3);
1464 break; 1467 break;
1586 static_cast<uint16_t> (data_array.numel ()), 1589 static_cast<uint16_t> (data_array.numel ()),
1587 data_array.data ())) 1590 data_array.data ()))
1588 error ("Failed to set field"); 1591 error ("Failed to set field");
1589 break; 1592 break;
1590 } 1593 }
1591 // TODO(maged): These tags are more complex to implement
1592 // will be implemented and tested later.
1593 case TIFFTAG_XMLPACKET: 1594 case TIFFTAG_XMLPACKET:
1594 case TIFFTAG_RICHTIFFIPTC: 1595 case TIFFTAG_RICHTIFFIPTC:
1595 case TIFFTAG_PHOTOSHOP: 1596 case TIFFTAG_PHOTOSHOP:
1596 case TIFFTAG_ICCPROFILE: 1597 case TIFFTAG_ICCPROFILE:
1597 { 1598 {
1598 error ("Complex Tags not implemented"); 1599 uint8NDArray data_array = tag_ov.uint8_array_value ();
1600 uint32_t count = data_array.numel ();
1601 if (! TIFFSetField (tif, tag_id, count, data_array.data ()))
1602 error ("Failed to set field");
1599 break; 1603 break;
1600 } 1604 }
1601 // These tags are not mentioned in the LibTIFF documentation 1605 // These tags are not mentioned in the LibTIFF documentation
1602 // but are handled correctly by the library 1606 // but are handled correctly by the library
1603 case TIFFTAG_ZIPQUALITY: 1607 case TIFFTAG_ZIPQUALITY:
2033 || image_data->bits_per_sample == 64) 2037 || image_data->bits_per_sample == 64)
2034 { 2038 {
2035 strip_size = rows_in_strip * image_data->width * sizeof (P); 2039 strip_size = rows_in_strip * image_data->width * sizeof (P);
2036 if (image_data->planar_configuration == PLANARCONFIG_CONTIG) 2040 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
2037 strip_size *= image_data->samples_per_pixel; 2041 strip_size *= image_data->samples_per_pixel;
2038 if (! TIFFWriteEncodedStrip (tif, strip, pixel_fvec, strip_size)) 2042 if (TIFFWriteEncodedStrip (tif, strip, pixel_fvec, strip_size) == -1)
2039 error ("Failed to rite strip data"); 2043 error ("Failed to write strip data");
2040 pixel_fvec += strip_size; 2044 pixel_fvec += strip_size;
2041 } 2045 }
2042 else if (image_data->bits_per_sample == 1) 2046 else if (image_data->bits_per_sample == 1)
2043 { 2047 {
2044 if (image_data->samples_per_pixel != 1) 2048 if (image_data->samples_per_pixel != 1)
2147 if (image_data->bits_per_sample == 8 2151 if (image_data->bits_per_sample == 8
2148 || image_data->bits_per_sample == 16 2152 || image_data->bits_per_sample == 16
2149 || image_data->bits_per_sample == 32 2153 || image_data->bits_per_sample == 32
2150 || image_data->bits_per_sample == 64) 2154 || image_data->bits_per_sample == 64)
2151 { 2155 {
2152 if (! TIFFWriteEncodedTile (tif, tile, pixel_fvec, tile_size)) 2156 if (TIFFWriteEncodedTile (tif, tile, pixel_fvec, tile_size) == -1)
2153 error ("Failed to write tile data"); 2157 error ("Failed to write tile data");
2154 pixel_fvec += tile_size; 2158 pixel_fvec += tile_size;
2155 } 2159 }
2156 else if (image_data->bits_per_sample == 1) 2160 else if (image_data->bits_per_sample == 1)
2157 { 2161 {