# HG changeset patch # User magedrifaat # Date 1660168533 -7200 # Node ID 3155aa74c62efaed32cfeb2d7109be64b1cfe7df # Parent d701c6a4cda1a4454619e114283a749172ec5da3 Tiff write: modified handling incorrect dimensions to match matlab. diff -r d701c6a4cda1 -r 3155aa74c62e libinterp/corefcn/__tiff__.cc --- a/libinterp/corefcn/__tiff__.cc Wed Aug 10 20:59:51 2022 +0200 +++ b/libinterp/corefcn/__tiff__.cc Wed Aug 10 23:55:33 2022 +0200 @@ -1179,9 +1179,7 @@ void set_field_data (TIFF *tif, const TIFFField *fip, octave_value tag_ov) - { - // TODO(maged): prevent calling here for read-only images - + { // TODO(maged): complete the implementation of this function uint32_t tag_id = TIFFFieldTag (fip); uint32_t tag_data = tag_ov.double_value (); @@ -1503,7 +1501,7 @@ void write_stripped_image (TIFF *tif, T pixel_data, tiff_image_data *image_data) { - // TODO(maged): remove this? ASSUMES pixel data dimensions are already validated + // ASSUMES pixel data dimensions are already validated typedef typename T::element_type P; @@ -1590,7 +1588,7 @@ void write_tiled_image (TIFF *tif, T pixel_data, tiff_image_data *image_data) { - // TODO(maged): remove this? ASSUMES pixel data dimensions are already validated + // ASSUMES pixel data dimensions are already validated uint32_t tile_width, tile_height; if (! TIFFGetField (tif, TIFFTAG_TILEWIDTH, &tile_width)) @@ -1710,14 +1708,21 @@ { // TODO(maged): matlab sets the remaining to zero for less width and height // and issues a warning for larger widths but not for larger height? (we should error) + // and doesnt issue a warning for larger width for tiled images and produces zeros // and errors for less or more number of channels - if (image_data->height != pixel_data.dim1 () - || image_data->width != pixel_data.dim2 () - || pixel_data.ndims () > 3 - || (image_data->samples_per_pixel > 1 && pixel_data.ndims () < 3) + if ((image_data->samples_per_pixel > 1 && pixel_data.ndims () < 3) || (pixel_data.ndims () > 2 && image_data->samples_per_pixel != pixel_data.dim3 ())) - error ("Dimensions of the input don't match image dimenions"); + error ("Incorrect number of channels, expected %u", + image_data->samples_per_pixel); + + if (pixel_data.dim1 () > image_data->height) + warning ("Input has more rows than the image length, data will be truncated"); + if (pixel_data.dim2 () > image_data->width) + warning ("Input has more columns than the image width, data will be truncated"); + + pixel_data.resize (dim_vector (image_data->height, image_data->width, + image_data->samples_per_pixel)); if (image_data->is_tiled) write_tiled_image (tif, pixel_data, image_data);