Mercurial > octave-libtiff
changeset 31133:e9925d528428
Tiff writeEncodedStrip: used octave_value functions instead of type_name
* __tiff__.cc(F__tiff_write_encoded_strip__): changed type checking from
checking type_name strings to octave_value methods.
author | magedrifaat <magedrifaat@gmail.com> |
---|---|
date | Tue, 26 Jul 2022 18:37:55 +0200 |
parents | c66f7c227e50 |
children | fc0366e009dd |
files | libinterp/dldfcn/__tiff__.cc |
diffstat | 1 files changed, 33 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/dldfcn/__tiff__.cc Tue Jul 26 17:26:48 2022 +0200 +++ b/libinterp/dldfcn/__tiff__.cc Tue Jul 26 18:37:55 2022 +0200 @@ -879,11 +879,9 @@ template <typename T> void - write_strip (TIFF *tif, uint32_t strip_no, octave_value strip_data_ov, + write_strip (TIFF *tif, uint32_t strip_no, T strip_data, tiff_image_data *image_data) - { - T strip_data = T (strip_data_ov.array_value ()); - + { uint32_t rows_in_strip; if (! TIFFGetFieldDefaulted (tif, TIFFTAG_ROWSPERSTRIP, &rows_in_strip)) error ("Failed to obtain the RowsPerStrip tag"); @@ -925,6 +923,7 @@ else error ("Planar configuration not supported"); + // TODO(maged): check matlab behavior if (strip_data.numel () != expected_numel) error ("Size of strip data is different from the expected size of the strip"); @@ -982,6 +981,7 @@ if (nargin == 2) mode = args (1).string_value (); + // TODO(maged): look into const begin and end std::vector<std::string> supported_modes {"r", "w", "w8", "a"}; if (std::find(supported_modes.begin(), supported_modes.end(), mode) @@ -1223,60 +1223,65 @@ else if (sample_format != 1 && sample_format != 4) error ("Unsupported sample format"); - std::string type_name = args(2).type_name (); switch (image_data.bits_per_sample) { case 1: - // Substrings are taken to support both the type and its matrix type - // i.e. "bool" and "bool matrix" to handle single element matrices - if (type_name.substr (0, 4) == "bool") - write_strip<boolNDArray> (tif, strip_no, args(2), &image_data); + // We need to check for both scalar and matrix types to handle single + // element strip + if (args(2).is_bool_scalar () || args(2).is_bool_matrix ()) + write_strip<boolNDArray> (tif, strip_no, + args(2).bool_array_value (), &image_data); else error ("Expected logical matrix for BiLevel image"); break; case 4: case 8: - if (type_name.substr (0, 5) == "uint8" - || type_name.substr (0, 4) == "int8") - write_strip<uint8NDArray> (tif, strip_no, args(2), &image_data); + if (args(2).is_uint8_type () || args(2).is_int8_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"); break; case 16: - // Type conversion from signed to unsigned is handled in the function // TODO(maged): what is the behavior if the input matrix has // negative numbers? - if (type_name.substr (0, 6) == "uint16" - || type_name.substr (0, 5) == "int16") - write_strip<uint16NDArray> (tif, strip_no, args(2), &image_data); + if (args(2).is_uint16_type () || args(2).is_int16_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"); break; case 32: if (sample_format == 3) - if (type_name.substr (0, 5) == "float" || type_name == "double" - || type_name == "matrix") - write_strip<FloatNDArray> (tif, strip_no, args(2), &image_data); + if (args(2).is_single_type () || args(2).is_double_type ()) + write_strip<FloatNDArray> (tif, strip_no, + args(2).float_array_value (), + &image_data); else error ("Only single and double data are allowed for floating-point images"); else - if (type_name.substr (0, 6) == "uint32" - || type_name.substr (0, 5) == "int32") - write_strip<uint32NDArray> (tif, strip_no, args(2), &image_data); + if (args(2).is_uint32_type () || args(2).is_int32_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"); break; case 64: if (sample_format == 3) - if (type_name.substr (0, 5) == "float" || type_name == "double" - || type_name == "matrix") - write_strip<NDArray> (tif, strip_no, args(2), &image_data); + if (args(2).is_single_type () || args(2).is_double_type ()) + write_strip<NDArray> (tif, strip_no, + args(2).array_value (), + &image_data); else error ("Only single and double data are allowed for floating-point images"); else - if (type_name.substr (0, 6) == "uint64" - || type_name.substr (0, 5) == "int64") - write_strip<uint64NDArray> (tif, strip_no, args(2), &image_data); + if (args(2).is_uint64_type () || args(2).is_int64_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"); break;