# HG changeset patch # User magedrifaat # Date 1659490770 -7200 # Node ID 2244617f4da57034e3431e9ff14bc003ab4baad1 # Parent 6fb54834aa930d1ff5c1d855cbd7bed5e5a781ae Tiff computeStrip: fixed inconsistency in checking plane argument. diff -r 6fb54834aa93 -r 2244617f4da5 libinterp/dldfcn/__tiff__.cc --- a/libinterp/dldfcn/__tiff__.cc Mon Aug 01 00:56:19 2022 +0200 +++ b/libinterp/dldfcn/__tiff__.cc Wed Aug 03 03:39:30 2022 +0200 @@ -956,7 +956,6 @@ 1, strip_data.dim3 ()); } - // TODO(maged): check dimesnions of boundary strips in matlab strip_data.resize (strip_dimensions); // Permute the dimesions of the strip to match the expected memory @@ -1022,17 +1021,19 @@ write_tile (TIFF *tif, uint32_t tile_no, T tile_data, tiff_image_data *image_data) { - // TODO(maged): error for tiles not divisible by 16? uint32_t tile_width, tile_height; if (! TIFFGetField (tif, TIFFTAG_TILEWIDTH, &tile_width)) error ("Failed to get the tile width"); if (! TIFFGetField (tif, TIFFTAG_TILELENGTH, &tile_height)) error ("Failed to get the tile length"); + + if (tile_height == 0 || tile_height % 16 != 0 + || tile_width == 0 || tile_width % 16 != 0) + error ("Tile dimesion tags are invalid"); if (tile_no < 1 || tile_no > TIFFNumberOfTiles (tif)) error ("Tile number out of bounds"); - // TODO(maged): what does matlab do for boundary tiles? if (tile_data.dim1 () > tile_height) warning ("The tile is composed of %u rows but input has %ld rows", tile_height, tile_data.dim1 ()); @@ -1332,7 +1333,7 @@ if (args(1).isstruct ()) { - octave_scalar_map tags = args(1).scalar_map_value (); + octave_scalar_map tags = args(1).xscalar_map_value ("__tiff_set_tag__: struct argument must be a scalar structure"); string_vector keys = tags.fieldnames (); // Using iterators instead of this loop method seems to process // the elements of the struct in a different order than they were @@ -1541,7 +1542,7 @@ error ("No handle provided\n"); TIFF *tif = (TIFF *)(args(0).uint64_value ()); - // What is the behavior in matlab? + if (TIFFIsTiled (tif)) error ("The image is tiled not stripped"); @@ -1562,7 +1563,7 @@ error ("No handle provided\n"); TIFF *tif = (TIFF *)(args(0).uint64_value ()); - // What is the behavior in matlab? + if (! TIFFIsTiled (tif)) error ("The image is stripped not tiled"); @@ -1583,7 +1584,7 @@ error ("Wrong number of arguments\n"); TIFF *tif = (TIFF *)(args(0).uint64_value ()); - // What is the behavior in matlab? + if (TIFFIsTiled (tif)) error ("The image is tiled not stripped"); @@ -1600,6 +1601,8 @@ uint16_t plane; if (nargin > 2) { + if (image_data.planar_configuration == PLANARCONFIG_CONTIG) + error ("Can't use plane argument for images with chunky PlanarConfiguration"); plane = args(2).uint16_scalar_value (); if (plane > image_data.samples_per_pixel) plane = image_data.samples_per_pixel; @@ -1608,11 +1611,11 @@ } else { + if (image_data.planar_configuration == PLANARCONFIG_SEPARATE) + error ("The plane argument is required for images with separate PlanarConfiguration"); plane = 0; } - // TODO(maged): What is the behavior in matlab for using/not using plane? - // TODO(maged): what is the behavior for out of bounds? double strip_number = TIFFComputeStrip (tif, row, plane) + 1; if (strip_number > TIFFNumberOfStrips (tif)) strip_number = TIFFNumberOfStrips (tif); @@ -1632,7 +1635,7 @@ error ("Wrong number of arguments\n"); TIFF *tif = (TIFF *)(args(0).uint64_value ()); - // What is the behavior in matlab? + if (! TIFFIsTiled (tif)) error ("The image is stripped not tiled"); @@ -1658,6 +1661,8 @@ uint16_t plane; if (nargin > 2) { + if (image_data.planar_configuration == PLANARCONFIG_CONTIG) + error ("Can't use plane argument for images with chunky PlanarConfiguration"); plane = args(2).uint16_scalar_value (); if (plane > image_data.samples_per_pixel) plane = image_data.samples_per_pixel; @@ -1666,11 +1671,11 @@ } else { + if (image_data.planar_configuration == PLANARCONFIG_SEPARATE) + error ("The plane argument is required for images with separate PlanarConfiguration"); plane = 0; } - // TODO(maged): What is the behavior in matlab for using/not using plane? - // TODO(maged): what is the behavior for out of bounds? double tile_number = TIFFComputeTile (tif, col, row, 0, plane) + 1; if (tile_number > TIFFNumberOfTiles (tif)) tile_number = TIFFNumberOfTiles (tif);