# HG changeset patch # User magedrifaat # Date 1658610403 -7200 # Node ID 0d9633ee715eb7d47e80dfd8bb446d560b48a76b # Parent 7851c5b9c950d5fd95bcd332f088cae65087d281 Tiff: fixed a bug where the default value of some tags was ignored * __tif__.cc: modified the call to TIFFGetField for some tags to make use of the default value of the tag. diff -r 7851c5b9c950 -r 0d9633ee715e libinterp/dldfcn/__tiff__.cc --- a/libinterp/dldfcn/__tiff__.cc Sat Jul 23 21:34:47 2022 +0200 +++ b/libinterp/dldfcn/__tiff__.cc Sat Jul 23 23:06:43 2022 +0200 @@ -40,13 +40,16 @@ if (! TIFFGetField (tif, TIFFTAG_IMAGELENGTH, &height)) error ("Failed to read image height"); - if (! TIFFGetField (tif, TIFFTAG_SAMPLESPERPIXEL, &samples_per_pixel)) + if (! TIFFGetFieldDefaulted (tif, TIFFTAG_SAMPLESPERPIXEL, + &samples_per_pixel)) error ("Failed to read the SamplesPerPixel tag"); - if (! TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, &bits_per_sample)) + if (! TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE, + &bits_per_sample)) error ("Failed to read the BitsPerSample tag"); - if (! TIFFGetField (tif, TIFFTAG_PLANARCONFIG, &planar_configuration)) + if (! TIFFGetFieldDefaulted (tif, TIFFTAG_PLANARCONFIG, + &planar_configuration)) error ("Failed to read the PlanarConfiguration tag"); is_tiled = TIFFIsTiled(tif); @@ -643,10 +646,10 @@ if (TIFFFieldPassCount (fip)) error ("Unsupported tag"); - // TODO(maged): test this function vs actual data type size int type_size = TIFFDataWidth (TIFFFieldDataType (fip)); // TODO(maged): use shared pointer instead of malloc void *data = _TIFFmalloc (type_size); + // TODO(maged): check if this should be GetFieldDefaulted instead validate_tiff_get_field (TIFFGetField (tif, tag_id, data), data); octave_value tag_data_ov = interpret_tag_data (data, 1, TIFFFieldDataType (fip)); @@ -691,7 +694,8 @@ case TIFFTAG_GRAYRESPONSECURVE: { uint16_t bits_per_sample; - if (! TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, &bits_per_sample)) + if (! TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE, + &bits_per_sample)) error ("Failed to obtain the bit depth"); tag_data_ov = get_array_field_data (tif, fip, 1< 24) @@ -743,11 +748,13 @@ case TIFFTAG_TRANSFERFUNCTION: { uint16_t samples_per_pixel; - if (! TIFFGetField (tif, TIFFTAG_SAMPLESPERPIXEL, &samples_per_pixel)) + if (! TIFFGetFieldDefaulted (tif, TIFFTAG_SAMPLESPERPIXEL, + &samples_per_pixel)) error ("Failed to obtain the number of samples per pixel"); uint16_t bits_per_sample; - if (! TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, &bits_per_sample)) + if (! TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE, + &bits_per_sample)) error ("Failed to obtain the number of samples per pixel"); uint32_t count = 1 << bits_per_sample; @@ -872,9 +879,14 @@ T strip_data = T (strip_data_ov.array_value ()); uint32_t rows_in_strip; - if (! TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rows_in_strip)) + if (! TIFFGetFieldDefaulted (tif, TIFFTAG_ROWSPERSTRIP, &rows_in_strip)) error ("Failed to obtain the RowsPerStrip tag"); + // The tag has a default value of UINT32_MAX which means the entire + // image, but we need to cap it to the height for later calculations + if (rows_in_strip > image_data->height) + rows_in_strip = image_data->height; + uint32_t strip_count = TIFFNumberOfStrips (tif); uint32_t expected_numel; @@ -924,6 +936,8 @@ image_data->width, 1)); } + //TODO(maged): add suppot for 1-bit and 4-bit images + // Permute the dimesions of the strip to match the expected memory // arrangement of LibTIFF (channel x width x height) Array perm (dim_vector (3, 1));