From 924fb3cc8a761a234fd85d8d868f789566bc8686 Mon Sep 17 00:00:00 2001 From: Marta Feriani Date: Thu, 14 May 2026 18:10:16 -0400 Subject: [PATCH] docs: Conversion of ImageOutput docs to tests for the copy image examples Signed-off-by: Marta Feriani --- src/doc/imageoutput.rst | 46 +++++-------------- testsuite/docs-examples-cpp/run.py | 1 + .../src/docs-examples-imageoutput.cpp | 25 ++++++++++ testsuite/docs-examples-python/run.py | 1 + .../src/docs-examples-imageoutput.py | 22 +++++++++ 5 files changed, 61 insertions(+), 34 deletions(-) diff --git a/src/doc/imageoutput.rst b/src/doc/imageoutput.rst index e6d2e7d20b..e67af26685 100644 --- a/src/doc/imageoutput.rst +++ b/src/doc/imageoutput.rst @@ -1438,41 +1438,19 @@ without alteration while modifying the image description metadata: .. tabs:: - .. code-tab:: c++ - - // Open the input file - auto in = ImageInput::open ("input.jpg"); - - // Make an output spec, identical to the input except for metadata - ImageSpec out_spec = in->spec(); - out_spec.attribute ("ImageDescription", "My Title"); - - // Create the output file and copy the image - auto out = ImageOutput::create ("output.jpg"); - out->open ("output.jpg", out_spec); - out->copy_image (in); - - // Clean up - out->close (); - in->close (); - - .. code-tab:: py + .. tab:: C++ + .. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imageoutput.cpp + :language: c++ + :start-after: BEGIN-imageoutput-copy + :end-before: END-imageoutput-copy + :dedent: 4 - # Open the input file - inp = ImageInput.open ("input.jpg") - - # Make an output spec, identical to the input except for metadata - out_spec = inp.spec() - out_spec.attribute ("ImageDescription", "My Title") - - # Create the output file and copy the image - out = ImageOutput.create ("output.jpg") - out.open ("output.jpg", out_spec) - out.copy_image (inp) - - # Clean up - out.close () - inp.close () + .. tab:: Python + .. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imageoutput.py + :language: py + :start-after: BEGIN-imageoutput-copy + :end-before: END-imageoutput-copy + :dedent: 4 diff --git a/testsuite/docs-examples-cpp/run.py b/testsuite/docs-examples-cpp/run.py index e856d190ef..ac03f2e32d 100755 --- a/testsuite/docs-examples-cpp/run.py +++ b/testsuite/docs-examples-cpp/run.py @@ -19,6 +19,7 @@ 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 ;" diff --git a/testsuite/docs-examples-cpp/src/docs-examples-imageoutput.cpp b/testsuite/docs-examples-cpp/src/docs-examples-imageoutput.cpp index d771cb92c4..11f9773dbf 100644 --- a/testsuite/docs-examples-cpp/src/docs-examples-imageoutput.cpp +++ b/testsuite/docs-examples-cpp/src/docs-examples-imageoutput.cpp @@ -125,11 +125,36 @@ tiles_write() +void +copy_write() +{ + // BEGIN-imageoutput-copy + // Open the input file + auto in = ImageInput::open("input.exr"); + + // Make an output spec, identical to the input except for metadata + ImageSpec out_spec = in->spec(); + out_spec.attribute("ImageDescription", "My Title"); + + // Create the output file and copy the image + auto out = ImageOutput::create("output.exr"); + out->open("output.exr", out_spec); + out->copy_image(in.get()); + + // Clean up + out->close(); + in->close(); + // END-imageoutput-copy +} + + + int main(int /*argc*/, char** /*argv*/) { simple_write(); scanlines_write(); tiles_write(); + copy_write(); return 0; } diff --git a/testsuite/docs-examples-python/run.py b/testsuite/docs-examples-python/run.py index 01993676a5..3d6d84d236 100755 --- a/testsuite/docs-examples-python/run.py +++ b/testsuite/docs-examples-python/run.py @@ -19,6 +19,7 @@ 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 ;" diff --git a/testsuite/docs-examples-python/src/docs-examples-imageoutput.py b/testsuite/docs-examples-python/src/docs-examples-imageoutput.py index 980ed3259d..0b9b8ada0b 100644 --- a/testsuite/docs-examples-python/src/docs-examples-imageoutput.py +++ b/testsuite/docs-examples-python/src/docs-examples-imageoutput.py @@ -102,6 +102,27 @@ def tiles_write() -> None: # END-imageoutput-tiles +def copy_write() -> None: + from OpenImageIO import ImageInput, ImageOutput + + # BEGIN-imageoutput-copy + # Open the input file + inp = ImageInput.open("input.exr") + + # Make an output spec, identical to the input except for metadata + out_spec = inp.spec() + out_spec.attribute("ImageDescription", "My Title") + + # Create the output file and copy the image + out = ImageOutput.create("output.exr") + out.open("output.exr", out_spec) + out.copy_image(inp) + + # Clean up + out.close() + inp.close() + # END-imageoutput-copy + if __name__ == '__main__': # Each example function needs to get called here, or it won't execute @@ -109,3 +130,4 @@ def tiles_write() -> None: simple_write() scanlines_write() tiles_write() + copy_write()