# HG changeset patch # User magedrifaat # Date 1658281448 -7200 # Node ID 341796f9efb6054f80bcf91748bcc32d4bbe085a # Parent 46bb98cec195492198597fb421ec30066d650c5a 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. diff -r 46bb98cec195 -r 341796f9efb6 libinterp/dldfcn/__tiff__.cc --- 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;