Mercurial > octave-libtiff
comparison scripts/io/Tiff.m @ 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 | ae41e14bf5c7 |
children | 8bf3fa6b6977 |
comparison
equal
deleted
inserted
replaced
31169:ae41e14bf5c7 | 31170:72a159bc5a4c |
---|---|
251 error ("Image file was closed"); | 251 error ("Image file was closed"); |
252 endif | 252 endif |
253 tileData = __tiff_read_encoded_tile__ (t.tiff_handle, tileNumber); | 253 tileData = __tiff_read_encoded_tile__ (t.tiff_handle, tileNumber); |
254 endfunction | 254 endfunction |
255 | 255 |
256 function [RGB, alpha] = readRGBAImage (t) | |
257 if (t.closed) | |
258 error ("Image file was closed"); | |
259 endif | |
260 [RGB, alpha] = __tiff_read_rgba_image__ (t.tiff_handle); | |
261 endfunction | |
262 | |
256 function write (t, imageData) | 263 function write (t, imageData) |
257 if (t.closed) | 264 if (t.closed) |
258 error ("Image file was closed"); | 265 error ("Image file was closed"); |
259 endif | 266 endif |
260 __tiff_write__ (t.tiff_handle, imageData); | 267 __tiff_write__ (t.tiff_handle, imageData); |
1448 %! endfor | 1455 %! endfor |
1449 %! assert (data2, data); | 1456 %! assert (data2, data); |
1450 %! img.close(); | 1457 %! img.close(); |
1451 %! endfunction | 1458 %! endfunction |
1452 %! file_wrapper (@test_fn); | 1459 %! file_wrapper (@test_fn); |
1460 | |
1461 ## test readRGBAImage | |
1462 %!testif HAVE_TIFF | |
1463 %! function test_fn (filename) | |
1464 %! img = Tiff (filename, "w"); | |
1465 %! setTag(img, struct ( | |
1466 %! "ImageLength", 10, "ImageWidth", 10, | |
1467 %! "BitsPerSample", 8, "SamplesPerPixel", 3, | |
1468 %! "PhotometricInterpretation", 2, | |
1469 %! "PlanarConfiguration", 1 | |
1470 %! )); | |
1471 %! data = uint8 (reshape (1:300, [10, 10, 3])); | |
1472 %! write (img, data); | |
1473 %! [rgb, alpha] = readRGBAImage (img); | |
1474 %! assert (rgb, data); | |
1475 %! assert (alpha, uint8 (repmat ([255], [10, 10]))); | |
1476 %! endfunction | |
1477 %! file_wrapper (@test_fn); | |
1478 | |
1479 ## test readRGBAImage with alpha | |
1480 %!testif HAVE_TIFF | |
1481 %! function test_fn (filename) | |
1482 %! img = Tiff (filename, "w"); | |
1483 %! setTag(img, struct ( | |
1484 %! "ImageLength", 10, "ImageWidth", 10, | |
1485 %! "BitsPerSample", 8, "SamplesPerPixel", 4, | |
1486 %! "PhotometricInterpretation", 2, | |
1487 %! "PlanarConfiguration", 1, | |
1488 %! "ExtraSamples", 1 | |
1489 %! )); | |
1490 %! data = uint8 (randi ([0,255], [10, 10, 4])); | |
1491 %! write (img, data); | |
1492 %! [rgb, alpha] = readRGBAImage (img); | |
1493 %! assert (rgb, data(:,:,1:3)); | |
1494 %! assert (alpha, data(:,:,4)); | |
1495 %! endfunction | |
1496 %! file_wrapper (@test_fn); |