Skip to content

Commit

Permalink
docs: Convert examples within the imagebufalgo chapter.
Browse files Browse the repository at this point in the history
- Update the run.py scripts to use the OIIO_TESTSUITE_ROOT
  environment variable instead of a relative path to fetch common
  images, to ensure tests can be run using ctest;
- Convert C++ and Python examples into tests within the "docs-examples"
  testsuites.
  • Loading branch information
buddly27 committed Oct 12, 2023
1 parent 94fc8f8 commit dc7bccb
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 18 deletions.
28 changes: 12 additions & 16 deletions src/doc/imagebufalgo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,19 @@ Most ImageBufAlgo functions that produce image data come in two forms:
error, the result image returned can have any error conditions checked with
`has_error()` and `geterror()`.

.. tabs::

.. code-tab:: c++
.. tabs::

// Method 1: Return an image result
ImageBuf dst = ImageBufAlgo::over (fg, bg);
if (dst.has_error())
std::cout << "error: " << dst.geterror() << "\n";
.. tab:: C++
.. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp
:language: c++
:start-after: BEGIN-imagebufalgo-output-error1
:end-before: END-imagebufalgo-output-error1

.. code-tab:: py

# Method 1: Return an image result
fg = ImageBuf("fg.exr")
bg = ImageBuf("bg.exr")
dst = ImageBufAlgo.over (fg, bg)
if dst.has_error() :
print("error:", dst.geterror())
.. tab:: Python
.. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py
:language: py
:start-after: BEGIN-imagebufalgo-output-error1
:end-before: END-imagebufalgo-output-error1


2. Pass a destination ImageBuf reference as the first parameter.
Expand Down Expand Up @@ -1075,7 +1071,7 @@ Shuffling channels

.. tabs::

.. code-tab:: c++
.. code-tab:: c++`

// Resize the image to 640x480, using the default filter
ImageBuf Src ("tahoe.exr");
Expand Down
1 change: 1 addition & 0 deletions testsuite/docs-examples-cpp/ref/out.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
error: Uninitialized input image
cshift.exr : 256 x 256, 4 channel, half openexr
SHA-1: 000F95FDC44D4DBDA8B4041C2506149C7AE28ACA
Comparing "simple.tif" and "ref/simple.tif"
Expand Down
2 changes: 1 addition & 1 deletion testsuite/docs-examples-cpp/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
prefix = "./build/"

# Prep:
command += run_app("cmake -E copy ../common/grid-small.exr grid.exr")
command += run_app("cmake -E copy ${OIIO_TESTSUITE_ROOT}/common/grid-small.exr grid.exr")

# Build
command += run_app("cmake -S " + test_source_dir + " -B build -DCMAKE_BUILD_TYPE=Release >> build.txt 2>&1", silent=True)
Expand Down
13 changes: 13 additions & 0 deletions testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ void example1()

// Section: ImageBufAlgo common principles

void example_output_error1()
{
ImageBuf fg, bg;

// BEGIN-imagebufalgo-output-error1
// Method 1: Return an image result
ImageBuf dst = ImageBufAlgo::over (fg, bg);
if (dst.has_error())
std::cout << "error: " << dst.geterror() << "\n";
// END-imagebufalgo-output-error1
}


// Section: Pattern Generation

Expand Down Expand Up @@ -83,6 +95,7 @@ int main(int /*argc*/, char** /*argv*/)
example1();

// Section: ImageBufAlgo common principles
example_output_error1();

// Section: Pattern Generation

Expand Down
1 change: 1 addition & 0 deletions testsuite/docs-examples-python/ref/out.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
error: Uninitialized input image
cshift.exr : 256 x 256, 4 channel, half openexr
SHA-1: 000F95FDC44D4DBDA8B4041C2506149C7AE28ACA
Comparing "simple.tif" and "ref/simple.tif"
Expand Down
2 changes: 1 addition & 1 deletion testsuite/docs-examples-python/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


# Prep:
command += run_app("cmake -E copy ../common/grid-small.exr grid.exr")
command += run_app("cmake -E copy ${OIIO_TESTSUITE_ROOT}/common/grid-small.exr grid.exr")

# Run the examples for each chapter
for chapter in [ "imageioapi", "imageoutput", "imageinput", "writingplugins",
Expand Down
12 changes: 12 additions & 0 deletions testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ def example1() :

# Section: ImageBufAlgo common principles

def example_output_error1():
fg = ImageBuf()
bg = ImageBuf()

# BEGIN-imagebufalgo-output-error1
# Method 1: Return an image result
dst = ImageBufAlgo.over(fg, bg)
if dst.has_error:
print("error:", dst.geterror())
# END-imagebufalgo-output-error1


# Section: Pattern Generation

Expand Down Expand Up @@ -85,6 +96,7 @@ def example_circular_shift() :
example1()

# Section: ImageBufAlgo common principles
example_output_error1()

# Section: Pattern Generation

Expand Down

0 comments on commit dc7bccb

Please sign in to comment.