Mercurial > octave-libtiff
changeset 31136:be1a983981b2
Tiff writeEncodedStrip: fixed bug to disallow signed types for unsigned images
* __tiff__.cc(F__tiff_write_encoded_strip): removed support for passing signed
integer data to unsigned images.
* Tiff.m: changed error message in test to reflect the new error message.
author | magedrifaat <magedrifaat@gmail.com> |
---|---|
date | Wed, 27 Jul 2022 00:18:57 +0200 |
parents | b7ffe64e0287 |
children | 233130c0b1f6 |
files | libinterp/dldfcn/__tiff__.cc scripts/io/Tiff.m |
diffstat | 2 files changed, 10 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/dldfcn/__tiff__.cc Tue Jul 26 20:44:24 2022 +0200 +++ b/libinterp/dldfcn/__tiff__.cc Wed Jul 27 00:18:57 2022 +0200 @@ -1213,6 +1213,7 @@ if (! TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLEFORMAT, &sample_format)) error ("Failed to obtain a value for sample format"); + // TODO(maged): add support for signed integer images if (sample_format == 3) { if (image_data.bits_per_sample != 32 && image_data.bits_per_sample != 64) @@ -1236,22 +1237,22 @@ break; case 4: case 8: - if (args(2).is_uint8_type () || args(2).is_int8_type ()) + if (args(2).is_uint8_type ()) write_strip<uint8NDArray> (tif, strip_no, args(2).uint8_array_value (), &image_data); else - error ("Only uint8 and int8 data are allowed for images with bit depth of 8"); + error ("Only uint8 data is allowed for uint images with bit depth of 8"); break; case 16: // TODO(maged): what is the behavior if the input matrix has // negative numbers? - if (args(2).is_uint16_type () || args(2).is_int16_type ()) + if (args(2).is_uint16_type ()) write_strip<uint16NDArray> (tif, strip_no, args(2).uint16_array_value (), &image_data); else - error ("Only uint16 and int16 data are allowed for images with bit depth of 16"); + error ("Only uint16 data is allowed for uint images with bit depth of 16"); break; case 32: if (sample_format == 3) @@ -1262,12 +1263,12 @@ else error ("Only single and double data are allowed for floating-point images"); else - if (args(2).is_uint32_type () || args(2).is_int32_type ()) + if (args(2).is_uint32_type ()) write_strip<uint32NDArray> (tif, strip_no, args(2).uint32_array_value (), &image_data); else - error ("Only uint32 and int32 data are allowed for images with bit depth of 32"); + error ("Only uint32 data is allowed for uint images with bit depth of 32"); break; case 64: if (sample_format == 3) @@ -1278,12 +1279,12 @@ else error ("Only single and double data are allowed for floating-point images"); else - if (args(2).is_uint64_type () || args(2).is_int64_type ()) + if (args(2).is_uint64_type ()) write_strip<uint64NDArray> (tif, strip_no, args(2).uint64_array_value (), &image_data); else - error ("Only uint64 and int64 data are allowed for images with bit depth of 64"); + error ("Only uint64 data is allowed for uint images with bit depth of 64"); break; default: error ("Unsupported bit depth");
--- a/scripts/io/Tiff.m Tue Jul 26 20:44:24 2022 +0200 +++ b/scripts/io/Tiff.m Wed Jul 27 00:18:57 2022 +0200 @@ -374,7 +374,7 @@ %! setTag(a, "PlanarConfiguration", 1); %! setTag(a, "PhotometricInterpretation", 2); %! data = uint8 (randi (intmax ("uint8"), 20, 20, 3)); -%! fail ("writeEncodedStrip (a, 1, data)", "Only uint16 and int16 data are allowed for images with bit depth of 16"); +%! fail ("writeEncodedStrip (a, 1, data)", "Only uint16 data is allowed for uint images with bit depth of 16"); %! a.close (); %! unwind_protect_cleanup %! unlink (filename);