Mercurial > octave-libtiff
comparison libinterp/dldfcn/__tiff__.cc @ 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 | 7349994f30f8 |
children | b7ffe64e0287 |
comparison
equal
deleted
inserted
replaced
31132:c66f7c227e50 | 31133:e9925d528428 |
---|---|
877 error ("Failed to set tag value"); | 877 error ("Failed to set tag value"); |
878 } | 878 } |
879 | 879 |
880 template <typename T> | 880 template <typename T> |
881 void | 881 void |
882 write_strip (TIFF *tif, uint32_t strip_no, octave_value strip_data_ov, | 882 write_strip (TIFF *tif, uint32_t strip_no, T strip_data, |
883 tiff_image_data *image_data) | 883 tiff_image_data *image_data) |
884 { | 884 { |
885 T strip_data = T (strip_data_ov.array_value ()); | |
886 | |
887 uint32_t rows_in_strip; | 885 uint32_t rows_in_strip; |
888 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_ROWSPERSTRIP, &rows_in_strip)) | 886 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_ROWSPERSTRIP, &rows_in_strip)) |
889 error ("Failed to obtain the RowsPerStrip tag"); | 887 error ("Failed to obtain the RowsPerStrip tag"); |
890 | 888 |
891 // The tag has a default value of UINT32_MAX which means the entire | 889 // The tag has a default value of UINT32_MAX which means the entire |
923 expected_numel = rows_in_strip * image_data->width; | 921 expected_numel = rows_in_strip * image_data->width; |
924 } | 922 } |
925 else | 923 else |
926 error ("Planar configuration not supported"); | 924 error ("Planar configuration not supported"); |
927 | 925 |
926 // TODO(maged): check matlab behavior | |
928 if (strip_data.numel () != expected_numel) | 927 if (strip_data.numel () != expected_numel) |
929 error ("Size of strip data is different from the expected size of the strip"); | 928 error ("Size of strip data is different from the expected size of the strip"); |
930 | 929 |
931 | 930 |
932 // Put the strip in a consistent shape for the subsequent permutation | 931 // Put the strip in a consistent shape for the subsequent permutation |
980 std::string mode = "r"; | 979 std::string mode = "r"; |
981 | 980 |
982 if (nargin == 2) | 981 if (nargin == 2) |
983 mode = args (1).string_value (); | 982 mode = args (1).string_value (); |
984 | 983 |
984 // TODO(maged): look into const begin and end | |
985 std::vector<std::string> supported_modes {"r", "w", "w8", "a"}; | 985 std::vector<std::string> supported_modes {"r", "w", "w8", "a"}; |
986 | 986 |
987 if (std::find(supported_modes.begin(), supported_modes.end(), mode) | 987 if (std::find(supported_modes.begin(), supported_modes.end(), mode) |
988 == supported_modes.end()) | 988 == supported_modes.end()) |
989 { | 989 { |
1221 // The standard specifies that a SampleFormat of 4 should be treated | 1221 // The standard specifies that a SampleFormat of 4 should be treated |
1222 // the same as 1 (unsigned integer) | 1222 // the same as 1 (unsigned integer) |
1223 else if (sample_format != 1 && sample_format != 4) | 1223 else if (sample_format != 1 && sample_format != 4) |
1224 error ("Unsupported sample format"); | 1224 error ("Unsupported sample format"); |
1225 | 1225 |
1226 std::string type_name = args(2).type_name (); | |
1227 switch (image_data.bits_per_sample) | 1226 switch (image_data.bits_per_sample) |
1228 { | 1227 { |
1229 case 1: | 1228 case 1: |
1230 // Substrings are taken to support both the type and its matrix type | 1229 // We need to check for both scalar and matrix types to handle single |
1231 // i.e. "bool" and "bool matrix" to handle single element matrices | 1230 // element strip |
1232 if (type_name.substr (0, 4) == "bool") | 1231 if (args(2).is_bool_scalar () || args(2).is_bool_matrix ()) |
1233 write_strip<boolNDArray> (tif, strip_no, args(2), &image_data); | 1232 write_strip<boolNDArray> (tif, strip_no, |
1233 args(2).bool_array_value (), &image_data); | |
1234 else | 1234 else |
1235 error ("Expected logical matrix for BiLevel image"); | 1235 error ("Expected logical matrix for BiLevel image"); |
1236 break; | 1236 break; |
1237 case 4: | 1237 case 4: |
1238 case 8: | 1238 case 8: |
1239 if (type_name.substr (0, 5) == "uint8" | 1239 if (args(2).is_uint8_type () || args(2).is_int8_type ()) |
1240 || type_name.substr (0, 4) == "int8") | 1240 write_strip<uint8NDArray> (tif, strip_no, |
1241 write_strip<uint8NDArray> (tif, strip_no, args(2), &image_data); | 1241 args(2).uint8_array_value (), |
1242 &image_data); | |
1242 else | 1243 else |
1243 error ("Only uint8 and int8 data are allowed for images with bit depth of 8"); | 1244 error ("Only uint8 and int8 data are allowed for images with bit depth of 8"); |
1244 break; | 1245 break; |
1245 case 16: | 1246 case 16: |
1246 // Type conversion from signed to unsigned is handled in the function | |
1247 // TODO(maged): what is the behavior if the input matrix has | 1247 // TODO(maged): what is the behavior if the input matrix has |
1248 // negative numbers? | 1248 // negative numbers? |
1249 if (type_name.substr (0, 6) == "uint16" | 1249 if (args(2).is_uint16_type () || args(2).is_int16_type ()) |
1250 || type_name.substr (0, 5) == "int16") | 1250 write_strip<uint16NDArray> (tif, strip_no, |
1251 write_strip<uint16NDArray> (tif, strip_no, args(2), &image_data); | 1251 args(2).uint16_array_value (), |
1252 &image_data); | |
1252 else | 1253 else |
1253 error ("Only uint16 and int16 data are allowed for images with bit depth of 16"); | 1254 error ("Only uint16 and int16 data are allowed for images with bit depth of 16"); |
1254 break; | 1255 break; |
1255 case 32: | 1256 case 32: |
1256 if (sample_format == 3) | 1257 if (sample_format == 3) |
1257 if (type_name.substr (0, 5) == "float" || type_name == "double" | 1258 if (args(2).is_single_type () || args(2).is_double_type ()) |
1258 || type_name == "matrix") | 1259 write_strip<FloatNDArray> (tif, strip_no, |
1259 write_strip<FloatNDArray> (tif, strip_no, args(2), &image_data); | 1260 args(2).float_array_value (), |
1261 &image_data); | |
1260 else | 1262 else |
1261 error ("Only single and double data are allowed for floating-point images"); | 1263 error ("Only single and double data are allowed for floating-point images"); |
1262 else | 1264 else |
1263 if (type_name.substr (0, 6) == "uint32" | 1265 if (args(2).is_uint32_type () || args(2).is_int32_type ()) |
1264 || type_name.substr (0, 5) == "int32") | 1266 write_strip<uint32NDArray> (tif, strip_no, |
1265 write_strip<uint32NDArray> (tif, strip_no, args(2), &image_data); | 1267 args(2).uint32_array_value (), |
1268 &image_data); | |
1266 else | 1269 else |
1267 error ("Only uint32 and int32 data are allowed for images with bit depth of 32"); | 1270 error ("Only uint32 and int32 data are allowed for images with bit depth of 32"); |
1268 break; | 1271 break; |
1269 case 64: | 1272 case 64: |
1270 if (sample_format == 3) | 1273 if (sample_format == 3) |
1271 if (type_name.substr (0, 5) == "float" || type_name == "double" | 1274 if (args(2).is_single_type () || args(2).is_double_type ()) |
1272 || type_name == "matrix") | 1275 write_strip<NDArray> (tif, strip_no, |
1273 write_strip<NDArray> (tif, strip_no, args(2), &image_data); | 1276 args(2).array_value (), |
1277 &image_data); | |
1274 else | 1278 else |
1275 error ("Only single and double data are allowed for floating-point images"); | 1279 error ("Only single and double data are allowed for floating-point images"); |
1276 else | 1280 else |
1277 if (type_name.substr (0, 6) == "uint64" | 1281 if (args(2).is_uint64_type () || args(2).is_int64_type ()) |
1278 || type_name.substr (0, 5) == "int64") | 1282 write_strip<uint64NDArray> (tif, strip_no, |
1279 write_strip<uint64NDArray> (tif, strip_no, args(2), &image_data); | 1283 args(2).uint64_array_value (), |
1284 &image_data); | |
1280 else | 1285 else |
1281 error ("Only uint64 and int64 data are allowed for images with bit depth of 64"); | 1286 error ("Only uint64 and int64 data are allowed for images with bit depth of 64"); |
1282 break; | 1287 break; |
1283 default: | 1288 default: |
1284 error ("Unsupported bit depth"); | 1289 error ("Unsupported bit depth"); |