|
12 | 12 |
|
13 | 13 | OIIO_TESTSUITE_IMAGEDIR = os.getenv('OIIO_TESTSUITE_IMAGEDIR', |
14 | 14 | '../oiio-images') |
| 15 | +OIIO_TESTSUITE_ROOT = os.getenv('OIIO_TESTSUITE_ROOT', '') |
15 | 16 |
|
16 | 17 | # Print the contents of an ImageSpec |
17 | 18 | def print_imagespec (spec: oiio.ImageSpec, subimage=0, mip=0, msg="") : |
@@ -257,6 +258,83 @@ def test_tiff_cmyk() : |
257 | 258 |
|
258 | 259 |
|
259 | 260 |
|
| 261 | +def test_imageinput_api () : |
| 262 | + print ("Testing ImageInput.create:") |
| 263 | + probe = oiio.ImageInput.create ("testu16.tif") |
| 264 | + print (" create succeeded:", probe is not None) |
| 265 | + if probe : |
| 266 | + print (" format_name is tiff:", probe.format_name() == "tiff") |
| 267 | + invalid = oiio.ImageInput.create ("no_such_format.zzz") |
| 268 | + print (" create invalid returns None:", invalid is None) |
| 269 | + oiio.geterror() # clear global error from failed create |
| 270 | + print ("") |
| 271 | + |
| 272 | + print ("Testing valid_file and supports:") |
| 273 | + tahoe = OIIO_TESTSUITE_IMAGEDIR + "/tahoe-gps.jpg" |
| 274 | + ii = oiio.ImageInput.open (tahoe) |
| 275 | + assert ii is not None |
| 276 | + print (" valid_file good:", ii.valid_file (tahoe)) |
| 277 | + print (" valid_file bad:", not ii.valid_file ("badname.tif")) |
| 278 | + print (" supports returns numeric:", |
| 279 | + isinstance (ii.supports ("mipmap"), (int, bool))) |
| 280 | + ii.close () |
| 281 | + ii = oiio.ImageInput.open ("grid.tx") |
| 282 | + assert ii is not None |
| 283 | + print (" grid supports mipmap:", bool (ii.supports ("mipmap"))) |
| 284 | + ii.close () |
| 285 | + print ("") |
| 286 | + |
| 287 | + print ("Testing seek_subimage state:") |
| 288 | + ii = oiio.ImageInput.open ("grid.tx") |
| 289 | + assert ii is not None |
| 290 | + print (" initial sub/mip:", ii.current_subimage(), ii.current_miplevel()) |
| 291 | + ok = ii.seek_subimage (0, 2) |
| 292 | + print (" seek mip 2:", ok) |
| 293 | + print (" after seek sub/mip:", ii.current_subimage(), ii.current_miplevel()) |
| 294 | + spec_m2 = ii.spec (0, 2) |
| 295 | + print (" spec(0,2) width:", spec_m2.width) |
| 296 | + data = ii.read_image (0, 2, 0, 2, oiio.UINT8) |
| 297 | + print (" read_image sub/mip/ch ndim:", |
| 298 | + data.ndim if data is not None else -1) |
| 299 | + ii.close () |
| 300 | + print ("") |
| 301 | + |
| 302 | + print ("Testing read_native_deep_image:") |
| 303 | + deep_path = OIIO_TESTSUITE_ROOT + "/oiiotool-deep/src/deepalpha.exr" |
| 304 | + ii = oiio.ImageInput.open (deep_path) |
| 305 | + assert ii is not None |
| 306 | + print (" deep file:", ii.spec().deep) |
| 307 | + dd = ii.read_native_deep_image () |
| 308 | + print (" read_native_deep_image ok:", dd is not None) |
| 309 | + if dd : |
| 310 | + print (" deep pixels:", dd.pixels, "channels:", dd.channels) |
| 311 | + ii.close () |
| 312 | + print ("") |
| 313 | + |
| 314 | + print ("Testing get_thumbnail:") |
| 315 | + ii = oiio.ImageInput.open (OIIO_TESTSUITE_IMAGEDIR + "/tahoe-gps.jpg") |
| 316 | + assert ii is not None |
| 317 | + thumb = ii.get_thumbnail () |
| 318 | + print (" get_thumbnail returns ImageBuf:", isinstance (thumb, oiio.ImageBuf)) |
| 319 | + print (" thumbnail initialized:", thumb.initialized) |
| 320 | + ii.close () |
| 321 | + print ("") |
| 322 | + |
| 323 | + print ("Testing has_error/geterror:") |
| 324 | + ii = oiio.ImageInput.open ("grid.tx") |
| 325 | + assert ii is not None |
| 326 | + data = ii.read_scanline (0, 0, oiio.UINT8) |
| 327 | + print (" scanline on tiled None:", data is None) |
| 328 | + print (" has_error:", ii.has_error) |
| 329 | + err1 = ii.geterror (clear=False) |
| 330 | + err2 = ii.geterror (clear=False) |
| 331 | + print (" geterror persists:", len (err1) > 0 and err1 == err2) |
| 332 | + ii.geterror (clear=True) |
| 333 | + print (" has_error after clear:", ii.has_error) |
| 334 | + ii.close () |
| 335 | + print ("") |
| 336 | + |
| 337 | + |
260 | 338 |
|
261 | 339 | ###################################################################### |
262 | 340 | # main test starts here |
@@ -321,6 +399,8 @@ def test_tiff_cmyk() : |
321 | 399 | test_tiff_remembering_config() |
322 | 400 | test_tiff_cmyk() |
323 | 401 |
|
| 402 | + test_imageinput_api () |
| 403 | + |
324 | 404 | # Test is_imageio_format_name |
325 | 405 | print ("is_imageio_format_name('tiff') =", oiio.is_imageio_format_name('tiff')) |
326 | 406 | print ("is_imageio_format_name('txff') =", oiio.is_imageio_format_name('txff')) |
|
0 commit comments