### Description Convert C++ and Python example from the [ImageOutput: Copying an entire image](https://openimageio.readthedocs.io/en/latest/imageoutput.html#copying-an-entire-image) chapter into tests within the `docs-examples-{cpp,python}` test suites. This was done following the steps outlined in [Converting documentation examples to tests](https://github.com/AcademySoftwareFoundation/OpenImageIO/wiki/Converting-documentation-examples-to-tests). ---- * This PR contributes to addressing issue https://github.com/AcademySoftwareFoundation/OpenImageIO/issues/3992. * This PR supersedes the closed PR https://github.com/AcademySoftwareFoundation/OpenImageIO/pull/5195. ---- #### Notes - In both `python` and `cpp` I have replaced the file `{input,output}.jpg` mentioned in the example with `{input,output}.exr` in the test, so to reuse existing resource files (i.e. `testsuite/common/grid-small.exr`): do let me know if you prefer the tests also use a `.jpg`, in which case I'll add a new resource to that effect. - The `cpp` example code was further modified to: 1. pass the requirements of `clang-format` (see original failing output [here](https://github.com/demiaster/OpenImageIO/actions/runs/25871058187/job/76026144354)) 2. successfully run `ImageOutput.copy_image` - The `python` example code was further modified to remove unnecessary whitespace before the brackets of function calls. Finally, when following the [conversion docs](https://github.com/AcademySoftwareFoundation/OpenImageIO/wiki/Converting-documentation-examples-to-tests), I have not addressed point `5`: again, let me know if you prefer to have a positive fixture to compare the test output against. ### Tests I have checked that, on my fork: * The CI passes successfully: https://github.com/demiaster/OpenImageIO/actions/runs/25888576608 * The docs build successfully: https://github.com/demiaster/OpenImageIO/actions/runs/25888576599 * The replaced docs examples render correctly (see excerpt from above build here: [imageoutput.html](https://github.com/user-attachments/files/27781020/imageoutput.html)) Signed-off-by: Marta Feriani <marta.celeste.feriani@gmail.com>
112 lines
3.7 KiB
Python
Executable File
112 lines
3.7 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
# Copyright Contributors to the OpenImageIO project.
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
# https://github.com/AcademySoftwareFoundation/OpenImageIO
|
|
|
|
redirect = " >> out.txt 2>&1 "
|
|
|
|
# To avoid duplicating example images between the C++ and Python tests,
|
|
# they all live with the C++ ones.
|
|
refdirlist += [ "../docs-examples-cpp/ref" ]
|
|
|
|
# Prep:
|
|
command += run_app("cmake -E copy " + test_source_dir + "/../common/grid-small.exr grid.exr")
|
|
command += run_app("cmake -E copy " + test_source_dir + "/../common/tahoe-small.tif tahoe.tif")
|
|
command += run_app("cmake -E copy " + test_source_dir + "/../common/grid-small.exr A.exr")
|
|
command += run_app("cmake -E copy " + test_source_dir + "/../common/grid-small.exr B.exr")
|
|
command += run_app("cmake -E copy " + test_source_dir + "/../common/with_nans.tif with_nans.tif")
|
|
command += run_app("cmake -E copy " + test_source_dir + "/../common/checker_with_alpha.exr checker_with_alpha.exr")
|
|
command += run_app("cmake -E copy " + test_source_dir + "/../common/unpremult.tif unpremult.tif")
|
|
command += run_app("cmake -E copy " + test_source_dir + "/../common/bayer.png bayer.png")
|
|
command += run_app("cmake -E copy " + test_source_dir + "/../common/grid-small.exr input.exr")
|
|
|
|
command += oiio_app("oiiotool") + "--pattern fill:top=0:bottom=1 256x256 1 -o mono.exr > out.txt ;"
|
|
|
|
# Copy the grid to both a tiled and scanline version
|
|
command += oiio_app("iconvert") + "../common/grid.tif --scanline scanline.tif > out.txt ;"
|
|
command += oiio_app("iconvert") + "../common/grid.tif --tile 64 64 tiled.tif > out.txt ;"
|
|
|
|
# Run the examples for each chapter
|
|
for chapter in [ "imageioapi", "imageoutput", "imageinput", "writingplugins",
|
|
"imagecache", "texturesys", "imagebuf", "imagebufalgo" ] :
|
|
command += pythonbin + " src/docs-examples-" + chapter + ".py " + redirect + " ;"
|
|
|
|
# hashes merely check that the images don't change, but saves us the space
|
|
# of checking in a full copy of the image if it's not needed. This is not
|
|
# suitable if the image may change slightly from platform to platform or
|
|
# with different versions of dependencies, for that we should use the
|
|
# full reference image comparison with appropriate thresholds.
|
|
hashes = [
|
|
# Outputs from the ImageBufAlgo chapter:
|
|
"zero1.exr",
|
|
"zero2.exr",
|
|
"zero3.exr",
|
|
"zero4.exr",
|
|
"fill.exr",
|
|
"checker.exr",
|
|
"noise1.exr",
|
|
"noise2.exr",
|
|
"noise3.exr",
|
|
"noise4.exr",
|
|
"blue-noise.exr",
|
|
"point.exr",
|
|
"lines.exr",
|
|
"box.exr",
|
|
"text1.exr",
|
|
"text2.exr",
|
|
"channels-rgba.exr",
|
|
"channels-rgb.exr",
|
|
"channels-brga.exr",
|
|
"channels-alpha.exr",
|
|
"channel-append.exr",
|
|
"copy.exr",
|
|
"crop.exr",
|
|
"cut.exr",
|
|
"paste.exr",
|
|
"rotate-90.exr",
|
|
"rotate-180.exr",
|
|
"rotate-270.exr",
|
|
"flip.exr",
|
|
"flop.exr",
|
|
"rotate-45.tif",
|
|
"resize.tif",
|
|
"resample.exr",
|
|
"fit.tif",
|
|
"warp.exr",
|
|
"transpose.exr",
|
|
"reorient.exr",
|
|
"cshift.exr",
|
|
"texture.exr",
|
|
"add.exr",
|
|
"add_cspan.exr",
|
|
"sub.exr",
|
|
"absdiff.exr",
|
|
"abs.exr",
|
|
"mul.exr",
|
|
"div.exr",
|
|
"checker_with_alpha_filled.exr",
|
|
"tahoe_median_filter.tif",
|
|
"tahoe_unsharp_mask.tif"
|
|
]
|
|
for file in hashes :
|
|
command += info_command(file, verbose=False)
|
|
|
|
# outputs should contain all the images that need to be checked directly
|
|
# and need the images checked into the ref directory.
|
|
outputs = [
|
|
# Outputs from the ImageOutput chapter:
|
|
"simple.tif", "scanlines.tif", "tiles.tif",
|
|
# Outputs from the ImageInput chapter:
|
|
|
|
# Outputs from the ImageBuf chapter:
|
|
|
|
# Outputs from the ImageBufAlgo chapter:
|
|
|
|
# ... etc ... other chapters ...
|
|
|
|
# Last, we have the out.txt that captures console output of the test
|
|
# programs.
|
|
"out.txt"
|
|
]
|