changeset 31121:341796f9efb6

Tiff getTag: converted colormap tag data to the correct type and range * __tiff.cc__(get_field_data): fixed the output data for the ColorMap tag to be double and in range between 0 and 1.
author magedrifaat <magedrifaat@gmail.com>
date Wed, 20 Jul 2022 03:44:08 +0200
parents 46bb98cec195
children 1662939a7a49
files libinterp/dldfcn/__tiff__.cc
diffstat 1 files changed, 23 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/__tiff__.cc	Wed Jul 20 02:48:22 2022 +0200
+++ b/libinterp/dldfcn/__tiff__.cc	Wed Jul 20 03:44:08 2022 +0200
@@ -674,8 +674,6 @@
         }
       case TIFFTAG_COLORMAP:
         {
-          // TODO(maged): Fix output formatting to be consistent with matlab
-          // Matlab returns a float colormap?
           uint16_t bits_per_sample;
           if (! TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, &bits_per_sample))
             error ("Failed to obtain the bit depth");
@@ -688,27 +686,30 @@
           validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_COLORMAP,
                                                  &red, &green, &blue));
           
-          uint16NDArray mat_out (dim_vector (count, 3));
+          Matrix mat_out (count, 3);
+          
+          Matrix red_array (interpret_tag_data (red,
+                                                count,
+                                                TIFFFieldDataType (fip))
+                                                .uint16_array_value ());
+          Matrix green_array (interpret_tag_data (green,
+                                                  count,
+                                                  TIFFFieldDataType (fip))
+                                                  .uint16_array_value ());
+          Matrix blue_array (interpret_tag_data (blue,
+                                                 count,
+                                                 TIFFFieldDataType (fip))
+                                                 .uint16_array_value ());
+          
+          double *out_ptr = mat_out.fortran_vec ();
+          memcpy (out_ptr, red_array.fortran_vec (), sizeof(double)*count);
+          out_ptr += count;
+          memcpy (out_ptr, green_array.fortran_vec (), sizeof(double)*count);
+          out_ptr += count;
+          memcpy (out_ptr, blue_array.fortran_vec (), sizeof(double)*count);
 
-          uint16NDArray red_array
-            = interpret_tag_data (red,
-                                  count,
-                                  TIFFFieldDataType (fip)).uint16_array_value ();
-          uint16NDArray green_array
-            = interpret_tag_data (green,
-                                  count,
-                                  TIFFFieldDataType (fip)).uint16_array_value ();
-          uint16NDArray blue_array
-            = interpret_tag_data (blue,
-                                  count,
-                                  TIFFFieldDataType (fip)).uint16_array_value ();
-          
-          octave_uint16 *out_ptr = mat_out.fortran_vec ();
-          memcpy (out_ptr, red_array.fortran_vec (), sizeof(uint16_t) * count);
-          out_ptr += count;
-          memcpy (out_ptr, green_array.fortran_vec (), sizeof(uint16_t) * count);
-          out_ptr += count;
-          memcpy (out_ptr, blue_array.fortran_vec (), sizeof(uint16_t) * count);
+          // Normalize the range to be between 0 and 1
+          mat_out /= UINT16_MAX;
 
           tag_data_ov = octave_value (mat_out);
           break;