From 8d7263cdb382cb6d9ea17db1422f7b5806bbc901 Mon Sep 17 00:00:00 2001 From: Danny Greenstein Date: Tue, 17 Oct 2023 19:56:03 -0700 Subject: [PATCH] docs: convert make_texture doc examples to tests (#4027) Takes the make_texture section of the imagebufalgo doc and turns it into a unit test in both python and c++. This adds a make_texture section to the `docs-examples-cpp` test and the `docs-examples-python` test. Signed-off-by: Danny Greenstein --- src/doc/imagebufalgo.rst | 50 ++++++++----------- testsuite/docs-examples-cpp/ref/out.txt | 2 + testsuite/docs-examples-cpp/run.py | 1 + .../src/docs-examples-imagebufalgo.cpp | 18 +++++++ testsuite/docs-examples-python/ref/out.txt | 2 + testsuite/docs-examples-python/run.py | 1 + .../src/docs-examples-imagebufalgo.py | 16 ++++++ 7 files changed, 60 insertions(+), 30 deletions(-) diff --git a/src/doc/imagebufalgo.rst b/src/doc/imagebufalgo.rst index 8f6c3068fc..8eb7d6a5ee 100644 --- a/src/doc/imagebufalgo.rst +++ b/src/doc/imagebufalgo.rst @@ -2925,41 +2925,31 @@ Import / export Examples: - .. tabs:: - - .. code-tab:: c++ - - ImageBuf Input ("in.exr"); - ImageSpec config; - config["maketx:highlightcomp"] = 1; - config["maketx:filtername"] = "lanczos3"; - config["maketx:opaque_detect"] = 1; - - bool ok = ImageBufAlgo::make_texture (ImageBufAlgo::MakeTxTexture, - Input, "texture.exr", config); - if (! ok) - std::cout << "make_texture error: " << OIIO::geterror() << "\n"; - - .. code-tab:: py + .. tabs:: - Input = ImageBuf("in.exr") - config = ImageSpec() - config["maketx:highlightcomp"] = 1 - config["maketx:filtername"] = "lanczos3" - config["maketx:opaque_detect"] = 1 - - ok = ImageBufAlgo.make_texture (OpenImageIO.MakeTxTexture, - Input, "texture.exr", config) - if not ok : - print("make_texture error:", OpenImageIO.geterror()) + .. tab:: C++ + .. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp + :language: c++ + :start-after: BEGIN-imagebufalgo-make-texture + :end-before: END-imagebufalgo-make-texture + :dedent: 4 - .. code-tab:: bash oiiotool + .. tab:: Python + .. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py + :language: py + :start-after: BEGIN-imagebufalgo-make-texture + :end-before: END-imagebufalgo-make-texture + :dedent: 4 - oiiotool in.exr -otex:hilightcomp=1:filtername=lanczos3:opaque_detect=1 texture.exr + .. tab:: oiiotool + .. sourcecode:: bash + + oiiotool in.exr -otex:hilightcomp=1:filtername=lanczos3:opaque_detect=1 texture.exr - .. code-tab:: bash maketx + .. tab:: maketx + .. sourcecode:: bash - maketx in.exr --hicomp --filter lanczos3 --opaque-detect -o texture.exr + maketx in.exr --hicomp --filter lanczos3 --opaque-detect -o texture.exr | diff --git a/testsuite/docs-examples-cpp/ref/out.txt b/testsuite/docs-examples-cpp/ref/out.txt index c2e31b2ba9..7c7b8c2d38 100644 --- a/testsuite/docs-examples-cpp/ref/out.txt +++ b/testsuite/docs-examples-cpp/ref/out.txt @@ -34,6 +34,8 @@ text2.exr : 640 x 480, 3 channel, float openexr SHA-1: 53359E96A286F909A89ACC99A67A9ED3BADC4A7A cshift.exr : 256 x 256, 4 channel, half openexr SHA-1: 000F95FDC44D4DBDA8B4041C2506149C7AE28ACA +texture.exr : 256 x 256, 3 channel, half openexr (+mipmap) + SHA-1: 4074B050432CE7C664CEC4546A46E74F9A310CDC Comparing "simple.tif" and "ref/simple.tif" PASS Comparing "scanlines.tif" and "ref/scanlines.tif" diff --git a/testsuite/docs-examples-cpp/run.py b/testsuite/docs-examples-cpp/run.py index b3b02cf760..50fbdc1340 100755 --- a/testsuite/docs-examples-cpp/run.py +++ b/testsuite/docs-examples-cpp/run.py @@ -44,6 +44,7 @@ "text1.exr", "text2.exr", "cshift.exr", + "texture.exr" ] for file in hashes : command += info_command(file, verbose=False) diff --git a/testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp b/testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp index da3c11e391..f75b5987ed 100644 --- a/testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp +++ b/testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp @@ -267,6 +267,23 @@ void example_circular_shift() // Section: Import / export +void example_make_texture() +{ + // BEGIN-imagebufalgo-make-texture + ImageBuf Input ("grid.exr"); + ImageSpec config; + config["maketx:highlightcomp"] = 1; + config["maketx:filtername"] = "lanczos3"; + config["maketx:opaque_detect"] = 1; + + bool ok = ImageBufAlgo::make_texture (ImageBufAlgo::MakeTxTexture, + Input, "texture.exr", config); + if (! ok) + std::cout << "make_texture error: " << OIIO::geterror() << "\n"; + // END-imagebufalgo-make-texture +} + + @@ -308,6 +325,7 @@ int main(int /*argc*/, char** /*argv*/) // Section: Color space conversion // Section: Import / export + example_make_texture(); return 0; } diff --git a/testsuite/docs-examples-python/ref/out.txt b/testsuite/docs-examples-python/ref/out.txt index c2e31b2ba9..7c7b8c2d38 100644 --- a/testsuite/docs-examples-python/ref/out.txt +++ b/testsuite/docs-examples-python/ref/out.txt @@ -34,6 +34,8 @@ text2.exr : 640 x 480, 3 channel, float openexr SHA-1: 53359E96A286F909A89ACC99A67A9ED3BADC4A7A cshift.exr : 256 x 256, 4 channel, half openexr SHA-1: 000F95FDC44D4DBDA8B4041C2506149C7AE28ACA +texture.exr : 256 x 256, 3 channel, half openexr (+mipmap) + SHA-1: 4074B050432CE7C664CEC4546A46E74F9A310CDC Comparing "simple.tif" and "ref/simple.tif" PASS Comparing "scanlines.tif" and "ref/scanlines.tif" diff --git a/testsuite/docs-examples-python/run.py b/testsuite/docs-examples-python/run.py index 8e48f26989..4a312764cc 100755 --- a/testsuite/docs-examples-python/run.py +++ b/testsuite/docs-examples-python/run.py @@ -35,6 +35,7 @@ "text1.exr", "text2.exr", "cshift.exr", + "texture.exr" ] for file in hashes : command += info_command(file, verbose=False) diff --git a/testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py b/testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py index 9590ece844..aba6ea753c 100644 --- a/testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py +++ b/testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py @@ -255,6 +255,21 @@ def example_circular_shift() : # Section: Import / export +def example_make_texture(): + # BEGIN-imagebufalgo-make-texture + Input = ImageBuf("grid.exr") + config = ImageSpec() + config["maketx:highlightcomp"] = 1 + config["maketx:filtername"] = "lanczos3" + config["maketx:opaque_detect"] = 1 + + ok = ImageBufAlgo.make_texture (OpenImageIO.MakeTxTexture, + Input, "texture.exr", config) + if not ok : + print("make_texture error:", OpenImageIO.geterror()) + + # END-imagebufalgo-make-texture + @@ -297,3 +312,4 @@ def example_circular_shift() : # Section: Color space conversion # Section: Import / export + example_make_texture()