# HG changeset patch # User magedrifaat # Date 1658694250 -7200 # Node ID 8475bdb70457893201b94afe3076892df8ec5d13 # Parent dfab9c6982bf6583e0a755639155238a06cca974 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy * __tiff__.cc(get_field_data): changed ColorMap and TransferFunction tags to use Array::cat for concatenating vectors instead of memcpy. diff -r dfab9c6982bf -r 8475bdb70457 libinterp/dldfcn/__tiff__.cc --- a/libinterp/dldfcn/__tiff__.cc Sun Jul 24 21:53:25 2022 +0200 +++ b/libinterp/dldfcn/__tiff__.cc Sun Jul 24 22:24:10 2022 +0200 @@ -652,7 +652,7 @@ void *data = _TIFFmalloc (type_size); validate_tiff_get_field (TIFFGetFieldDefaulted (tif, tag_id, data), data); - octave_value tag_data_ov = interpret_tag_data (data,TODO 1, + octave_value tag_data_ov = interpret_tag_data (data, 1, TIFFFieldDataType (fip)); _TIFFfree (data); @@ -717,29 +717,27 @@ validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_COLORMAP, &red, &green, &blue)); - // TODO(maged): use Array::cat - 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); + // Retrieving the data of the three channels and concatenating + // them together + OCTAVE_LOCAL_BUFFER (NDArray, array_list, 3); + dim_vector col_dims(count, 1); + array_list[0] = NDArray (interpret_tag_data (red, + count, + TIFFFieldDataType(fip)) + .uint16_array_value () + .reshape (col_dims)); + array_list[1] = NDArray (interpret_tag_data (green, + count, + TIFFFieldDataType(fip)) + .uint16_array_value () + .reshape (col_dims)); + array_list[2] = NDArray (interpret_tag_data (blue, + count, + TIFFFieldDataType(fip)) + .uint16_array_value () + .reshape (col_dims)); + NDArray mat_out = NDArray::cat(1, 3, array_list); // Normalize the range to be between 0 and 1 mat_out /= UINT16_MAX; @@ -771,29 +769,25 @@ validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_COLORMAP, &ch1, &ch2, &ch3)); - uint16NDArray mat_out (dim_vector (count, 3)); - - uint16NDArray ch1_array - = interpret_tag_data (ch1, - count, - TIFFFieldDataType (fip)).uint16_array_value (); - uint16NDArray ch2_array - = interpret_tag_data (ch2, - count, - TIFFFieldDataType (fip)).uint16_array_value (); - uint16NDArray ch3_array - = interpret_tag_data (ch3, - count, - TIFFFieldDataType (fip)).uint16_array_value (); + OCTAVE_LOCAL_BUFFER (uint16NDArray, array_list, 3); + dim_vector col_dims(count, 1); + array_list[0] = interpret_tag_data (ch1, + count, + TIFFFieldDataType (fip)) + .uint16_array_value () + .reshape (col_dims); + array_list[1] = interpret_tag_data (ch2, + count, + TIFFFieldDataType (fip)) + .uint16_array_value () + .reshape (col_dims); + array_list[2] = interpret_tag_data (ch3, + count, + TIFFFieldDataType (fip)) + .uint16_array_value () + .reshape (col_dims); - octave_uint16 *out_ptr = mat_out.fortran_vec (); - memcpy (out_ptr, ch1_array.fortran_vec (), sizeof(uint16_t) * count); - out_ptr += count; - memcpy (out_ptr, ch2_array.fortran_vec (), sizeof(uint16_t) * count); - out_ptr += count; - memcpy (out_ptr, ch3_array.fortran_vec (), sizeof(uint16_t) * count); - - tag_data_ov = octave_value (mat_out); + tag_data_ov = octave_value (uint16NDArray::cat (1, 3, array_list)); } break; } @@ -806,7 +800,7 @@ validate_tiff_get_field (TIFFGetField (tif, tag_id, &tag_part1, &tag_part2)); - Matrix mat_out (1, 2); + NDArray mat_out (dim_vector (1, 2)); mat_out(0) = interpret_tag_data (&tag_part1, 1, TIFFFieldDataType (fip)).double_value ();