changeset 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
files libinterp/corefcn/__tiff__.cc scripts/io/Tiff.m
diffstat 2 files changed, 16 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/__tiff__.cc	Thu Aug 18 17:23:43 2022 +0200
+++ b/libinterp/corefcn/__tiff__.cc	Thu Aug 18 20:44:06 2022 +0200
@@ -1105,7 +1105,6 @@
     octave_value tag_data_ov;
     uint32_t tag_id = TIFFFieldTag (fip);
 
-    // TODO(maged): find/create images to test the special tags
     switch (tag_id)
       {
       case TIFFTAG_STRIPBYTECOUNTS:
@@ -1267,14 +1266,19 @@
                                             TIFFFieldDataType (fip));
           break;
         }
-      // TODO(maged): These tags are more complex to implement
-      //  will be implemented and tested later.
       case TIFFTAG_XMLPACKET:
       case TIFFTAG_RICHTIFFIPTC:
       case TIFFTAG_PHOTOSHOP:
       case TIFFTAG_ICCPROFILE:
         {
-          error ("Complex Tags not implemented");
+          uint32_t count;
+          uint8_t *data;
+          validate_tiff_get_field (TIFFGetField (tif, tag_id,
+                                                 &count, &data));
+          tag_data_ov = interpret_tag_data (data, count, TIFF_BYTE);
+          // Matlab returns XMP tag as char array not byte array
+          if (tag_id == TIFFTAG_XMLPACKET)
+            tag_data_ov = octave_value (tag_data_ov.char_array_value ());
           break;
         }
       // These tags are not mentioned in the LibTIFF documentation
@@ -1456,7 +1460,6 @@
   {
     uint32_t tag_id = TIFFFieldTag (fip);
     
-    // TODO(maged): find/create images to test the special tags
     switch (tag_id)
       {
       case TIFFTAG_YCBCRCOEFFICIENTS:
@@ -1588,14 +1591,15 @@
             error ("Failed to set field");
           break;
         }
-      // TODO(maged): These tags are more complex to implement
-      //  will be implemented and tested later.
       case TIFFTAG_XMLPACKET:
       case TIFFTAG_RICHTIFFIPTC:
       case TIFFTAG_PHOTOSHOP:
       case TIFFTAG_ICCPROFILE:
         {
-          error ("Complex Tags not implemented");
+          uint8NDArray data_array = tag_ov.uint8_array_value ();
+          uint32_t count = data_array.numel ();
+          if (! TIFFSetField (tif, tag_id, count, data_array.data ()))
+            error ("Failed to set field");
           break;
         }
       // These tags are not mentioned in the LibTIFF documentation
@@ -2035,8 +2039,8 @@
             strip_size = rows_in_strip * image_data->width * sizeof (P);
             if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
               strip_size *= image_data->samples_per_pixel;
-            if (! TIFFWriteEncodedStrip (tif, strip, pixel_fvec, strip_size))
-              error ("Failed to rite strip data");
+            if (TIFFWriteEncodedStrip (tif, strip, pixel_fvec, strip_size) == -1)
+              error ("Failed to write strip data");
             pixel_fvec += strip_size;
           }
         else if (image_data->bits_per_sample == 1)
@@ -2149,7 +2153,7 @@
             || image_data->bits_per_sample == 32
             || image_data->bits_per_sample == 64)
           {
-            if (! TIFFWriteEncodedTile (tif, tile, pixel_fvec, tile_size))
+            if (TIFFWriteEncodedTile (tif, tile, pixel_fvec, tile_size) == -1)
               error ("Failed to write tile data");
             pixel_fvec += tile_size;
           }
--- a/scripts/io/Tiff.m	Thu Aug 18 17:23:43 2022 +0200
+++ b/scripts/io/Tiff.m	Thu Aug 18 20:44:06 2022 +0200
@@ -28,9 +28,8 @@
       "JBIG", 34661,
       "SGILog", 34676,
       "SGILog24", 34677,
+      # Not implemented in LibTIFF
       "JPEG2000", 34712,
-      # Not defined in LibTIFF, only in matlab
-      # TODO(maged): test these compression methods
       "JPEG2000_SVS_YCbCr", 33003,
       "JPEG2000_SVS_RGB", 33005
     );