Mercurial > octave-libtiff
comparison libinterp/corefcn/__tiff__.cc @ 31170:72a159bc5a4c
Tiff: added readRGBAImage method to read image using the RGBA interface
* __tiff__.cc(F__tiff_reag_rgba_image__): implemented logic for reading images
using LibTIFF's RGBA interface.
* Tiff.m: added method readRGBAImage and added unit tests for the new method.
author | magedrifaat <magedrifaat@gmail.com> |
---|---|
date | Sat, 13 Aug 2022 17:36:12 +0200 |
parents | 27ed758c1688 |
children | 8bf3fa6b6977 |
comparison
equal
deleted
inserted
replaced
31169:ae41e14bf5c7 | 31170:72a159bc5a4c |
---|---|
2270 { | 2270 { |
2271 #if defined (HAVE_TIFF) | 2271 #if defined (HAVE_TIFF) |
2272 int nargin = args.length (); | 2272 int nargin = args.length (); |
2273 | 2273 |
2274 if (nargin != 2) | 2274 if (nargin != 2) |
2275 error ("rong number of arguments"); | 2275 error ("Wrong number of arguments"); |
2276 | 2276 |
2277 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2277 TIFF *tif = (TIFF *)(args(0).uint64_value ()); |
2278 | 2278 |
2279 // TODO(maged): nargout and ycbcr | 2279 // TODO(maged): nargout and ycbcr |
2280 octave_unused_parameter (nargout); | 2280 octave_unused_parameter (nargout); |
2305 { | 2305 { |
2306 #if defined (HAVE_TIFF) | 2306 #if defined (HAVE_TIFF) |
2307 int nargin = args.length (); | 2307 int nargin = args.length (); |
2308 | 2308 |
2309 if (nargin != 2) | 2309 if (nargin != 2) |
2310 error ("rong number of arguments"); | 2310 error ("Wrong number of arguments"); |
2311 | 2311 |
2312 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2312 TIFF *tif = (TIFF *)(args(0).uint64_value ()); |
2313 | 2313 |
2314 // TODO(maged): nargout and ycbcr | 2314 // TODO(maged): nargout and ycbcr |
2315 octave_unused_parameter (nargout); | 2315 octave_unused_parameter (nargout); |
2328 | 2328 |
2329 // Convert from Octave's 1-based indexing to zero-based indexing | 2329 // Convert from Octave's 1-based indexing to zero-based indexing |
2330 tile_no--; | 2330 tile_no--; |
2331 | 2331 |
2332 return octave_value_list (handle_read_strip_or_tile (tif, tile_no)); | 2332 return octave_value_list (handle_read_strip_or_tile (tif, tile_no)); |
2333 #else | |
2334 err_disabled_feature ("readEncodedTile", "Tiff"); | |
2335 #endif | |
2336 } | |
2337 | |
2338 DEFUN (__tiff_read_rgba_image__, args, , | |
2339 "Read the image data in rgba mode") | |
2340 { | |
2341 #if defined (HAVE_TIFF) | |
2342 int nargin = args.length (); | |
2343 | |
2344 if (nargin != 1) | |
2345 error ("Wrong number of arguments"); | |
2346 | |
2347 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | |
2348 | |
2349 tiff_image_data image_data (tif); | |
2350 | |
2351 dim_vector img_dims (4, image_data.width, image_data.height); | |
2352 uint8NDArray img (img_dims); | |
2353 uint32_t *img_ptr = reinterpret_cast <uint32_t *> (img.fortran_vec ()); | |
2354 // Matlab (R2022a) uses a top-left orientation ignoring the tag if present | |
2355 if (! TIFFReadRGBAImageOriented (tif, image_data.width, image_data.height, | |
2356 img_ptr, 1)) | |
2357 error ("Failed to read image"); | |
2358 | |
2359 Array<octave_idx_type> perm (dim_vector (3, 1)); | |
2360 perm(0) = 2; | |
2361 perm(1) = 1; | |
2362 perm(2) = 0; | |
2363 img = img.permute (perm); | |
2364 | |
2365 Array<idx_vector> idx (dim_vector (3, 1)); | |
2366 idx(0) = idx_vector (':'); | |
2367 idx(1) = idx_vector (':'); | |
2368 idx(2) = idx_vector (0, 3); | |
2369 uint8NDArray rgb = uint8NDArray (img.index (idx)); | |
2370 idx(2) = idx_vector (3); | |
2371 uint8NDArray alpha = uint8NDArray (img.index (idx)); | |
2372 | |
2373 octave_value_list retval (2); | |
2374 retval(0) = octave_value (rgb); | |
2375 retval(1) = octave_value (alpha); | |
2376 return retval; | |
2333 #else | 2377 #else |
2334 err_disabled_feature ("readEncodedTile", "Tiff"); | 2378 err_disabled_feature ("readEncodedTile", "Tiff"); |
2335 #endif | 2379 #endif |
2336 } | 2380 } |
2337 | 2381 |