Skip to content

Commit

Permalink
docs: convert make_texture doc examples to tests (#4027)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
grdanny authored and lgritz committed Oct 19, 2023
1 parent d91ac03 commit 8d7263c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 30 deletions.
50 changes: 20 additions & 30 deletions src/doc/imagebufalgo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

|
Expand Down
2 changes: 2 additions & 0 deletions testsuite/docs-examples-cpp/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions testsuite/docs-examples-cpp/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"text1.exr",
"text2.exr",
"cshift.exr",
"texture.exr"
]
for file in hashes :
command += info_command(file, verbose=False)
Expand Down
18 changes: 18 additions & 0 deletions testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}





Expand Down Expand Up @@ -308,6 +325,7 @@ int main(int /*argc*/, char** /*argv*/)
// Section: Color space conversion

// Section: Import / export
example_make_texture();

return 0;
}
2 changes: 2 additions & 0 deletions testsuite/docs-examples-python/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions testsuite/docs-examples-python/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"text1.exr",
"text2.exr",
"cshift.exr",
"texture.exr"
]
for file in hashes :
command += info_command(file, verbose=False)
Expand Down
16 changes: 16 additions & 0 deletions testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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




Expand Down Expand Up @@ -297,3 +312,4 @@ def example_circular_shift() :
# Section: Color space conversion

# Section: Import / export
example_make_texture()

0 comments on commit 8d7263c

Please sign in to comment.