Skip to content

Commit 94fc8f8

Browse files
authored
docs: Make an example of doc-to-test in the imagebufalgo chapter (#4012)
Slightly different set of issues, so I wanted to provide a full example for anyone who wants to work on this chapter. Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent 2e1e5f9 commit 94fc8f8

8 files changed

Lines changed: 179 additions & 15 deletions

File tree

src/doc/imagebufalgo.rst

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -998,19 +998,27 @@ Shuffling channels
998998

999999
.. tabs::
10001000

1001-
.. code-tab:: c++
1001+
.. tab:: C++
10021002

1003-
ImageBuf A ("grid.jpg");
1004-
ImageBuf B = ImageBufAlgo::circular_shift (A, 70, 30);
1003+
.. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp
1004+
:language: c++
1005+
:start-after: BEGIN-imagebufalgo-cshift
1006+
:end-before: END-imagebufalgo-cshift
1007+
:dedent: 4
10051008

1006-
.. code-tab:: py
1009+
.. tab:: Python
10071010

1008-
A = ImageBuf("tahoe.jpg")
1009-
A = ImageBufAlgo.circular_shift (A, 70, 30)
1011+
.. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py
1012+
:language: c++
1013+
:start-after: BEGIN-imagebufalgo-cshift
1014+
:end-before: END-imagebufalgo-cshift
1015+
:dedent: 4
10101016

1011-
.. code-tab:: bash oiiotool
1017+
.. tab:: oiiotool
1018+
1019+
.. code-block:: bash
10121020
1013-
oiiotool tahoe.jpg --cshift +70+30 -o out.jpg
1021+
oiiotool tahoe.jpg --cshift +70+30 -o out.jpg
10141022
10151023
.. |cshiftimg1| image:: figures/grid-small.jpg
10161024
:width: 2.0 in
@@ -1063,8 +1071,6 @@ Shuffling channels
10631071
.. doxygengroup:: resize
10641072
..
10651073
1066-
Examples::
1067-
10681074
Examples:
10691075

10701076
.. tabs::

testsuite/common/grid-small.exr

98.1 KB
Binary file not shown.

testsuite/docs-examples-cpp/ref/out.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
cshift.exr : 256 x 256, 4 channel, half openexr
2+
SHA-1: 000F95FDC44D4DBDA8B4041C2506149C7AE28ACA
13
Comparing "simple.tif" and "ref/simple.tif"
24
PASS
35
Comparing "scanlines.tif" and "ref/scanlines.tif"

testsuite/docs-examples-cpp/run.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,33 @@
66

77

88
if platform.system() == 'Windows' :
9-
prefix = "Release\\"
9+
prefix = ".\\build\\Release\\"
1010
else :
11-
prefix = "./"
11+
prefix = "./build/"
1212

13-
# command += "echo test_source_dir=" + test_source_dir + " >> build.txt ;"
14-
command += run_app("cmake " + test_source_dir + " -DCMAKE_BUILD_TYPE=Release >> build.txt 2>&1", silent=True)
15-
command += run_app("cmake --build . --config Release >> build.txt 2>&1", silent=True)
13+
# Prep:
14+
command += run_app("cmake -E copy ../common/grid-small.exr grid.exr")
15+
16+
# Build
17+
command += run_app("cmake -S " + test_source_dir + " -B build -DCMAKE_BUILD_TYPE=Release >> build.txt 2>&1", silent=True)
18+
command += run_app("cmake --build build --config Release >> build.txt 2>&1", silent=True)
1619

1720
# Run the examples for each chapter
1821
for chapter in [ "imageioapi", "imageoutput", "imageinput", "writingplugins",
1922
"imagecache", "texturesys", "imagebuf", "imagebufalgo" ] :
2023
command += run_app(prefix + "docs-examples-" + chapter)
2124

25+
# hashes merely check that the images don't change, but saves us the space
26+
# of checking in a full copy of the image if it's not needed.
27+
hashes = [
28+
# Outputs from the ImageBufAlgo chapter:
29+
"cshift.exr",
30+
]
31+
for file in hashes :
32+
command += info_command(file, verbose=False)
33+
34+
# outputs should contain all the images that need to be checked directly
35+
# and need the images checked into the ref directory.
2236
outputs = [
2337
# Outputs from the ImageOutput chapter:
2438
"simple.tif", "scanlines.tif",

testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
// BEGIN-imagebufalgo-example1
1414
#include <OpenImageIO/imageio.h>
15+
#include <OpenImageIO/imagebuf.h>
16+
#include <OpenImageIO/imagebufalgo.h>
1517
using namespace OIIO;
1618

1719
void example1()
@@ -31,11 +33,75 @@ void example1()
3133
///////////////////////////////////////////////////////////////////////////
3234

3335

36+
// Section: ImageBufAlgo common principles
37+
38+
39+
// Section: Pattern Generation
40+
41+
42+
// Section: Image transformation and data movement
43+
44+
void example_circular_shift()
45+
{
46+
// BEGIN-imagebufalgo-cshift
47+
ImageBuf A("grid.exr");
48+
ImageBuf B = ImageBufAlgo::circular_shift(A, 70, 30);
49+
B.write("cshift.exr");
50+
// END-imagebufalgo-cshift
51+
}
52+
53+
54+
55+
// Section: Image Arithmetic
56+
57+
58+
// Section: Image comparison and statistics
59+
60+
61+
// Section: Convolution and frequency-space algorithms
62+
63+
64+
// Section: Image enhancement / restoration
65+
66+
67+
// Section: Morphological filters
68+
69+
70+
// Section: Color space conversion
71+
72+
73+
// Section: Import / export
74+
75+
76+
77+
3478

3579
int main(int /*argc*/, char** /*argv*/)
3680
{
3781
// Each example function needs to get called here, or it won't execute
3882
// as part of the test.
3983
example1();
84+
85+
// Section: ImageBufAlgo common principles
86+
87+
// Section: Pattern Generation
88+
89+
// Section: Image transformation and data movement
90+
example_circular_shift();
91+
92+
// Section: Image Arithmetic
93+
94+
// Section: Image comparison and statistics
95+
96+
// Section: Convolution and frequency-space algorithms
97+
98+
// Section: Image enhancement / restoration
99+
100+
// Section: Morphological filters
101+
102+
// Section: Color space conversion
103+
104+
// Section: Import / export
105+
40106
return 0;
41107
}

testsuite/docs-examples-python/ref/out.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
cshift.exr : 256 x 256, 4 channel, half openexr
2+
SHA-1: 000F95FDC44D4DBDA8B4041C2506149C7AE28ACA
13
Comparing "simple.tif" and "ref/simple.tif"
24
PASS
35
Comparing "scanlines.tif" and "ref/scanlines.tif"

testsuite/docs-examples-python/run.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,25 @@
55
# https://github.com/AcademySoftwareFoundation/OpenImageIO
66

77

8+
# Prep:
9+
command += run_app("cmake -E copy ../common/grid-small.exr grid.exr")
10+
811
# Run the examples for each chapter
912
for chapter in [ "imageioapi", "imageoutput", "imageinput", "writingplugins",
1013
"imagecache", "texturesys", "imagebuf", "imagebufalgo" ] :
1114
command += pythonbin + " src/docs-examples-" + chapter + ".py >> out.txt ;"
1215

16+
# hashes merely check that the images don't change, but saves us the space
17+
# of checking in a full copy of the image if it's not needed.
18+
hashes = [
19+
# Outputs from the ImageBufAlgo chapter:
20+
"cshift.exr",
21+
]
22+
for file in hashes :
23+
command += info_command(file, verbose=False)
24+
25+
# outputs should contain all the images that need to be checked directly
26+
# and need the images checked into the ref directory.
1327
outputs = [
1428
# Outputs from the ImageOutput chapter:
1529
"simple.tif", "scanlines.tif",

testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
# BEGIN-imagebufalgo-example1
2020
import OpenImageIO as oiio
21+
from OpenImageIO import *
2122
import numpy as np
2223

2324
def example1() :
@@ -37,10 +38,69 @@ def example1() :
3738
############################################################################
3839

3940

41+
# Section: ImageBufAlgo common principles
42+
43+
44+
# Section: Pattern Generation
45+
46+
47+
# Section: Image transformation and data movement
48+
49+
def example_circular_shift() :
50+
# BEGIN-imagebufalgo-cshift
51+
A = ImageBuf("grid.exr")
52+
B = ImageBufAlgo.circular_shift(A, 70, 30)
53+
# END-imagebufalgo-cshift
54+
B.write("cshift.exr");
55+
56+
57+
# Section: Image Arithmetic
58+
59+
60+
# Section: Image comparison and statistics
61+
62+
63+
# Section: Convolution and frequency-space algorithms
64+
65+
66+
# Section: Image enhancement / restoration
67+
68+
69+
# Section: Morphological filters
70+
71+
72+
# Section: Color space conversion
73+
74+
75+
# Section: Import / export
76+
77+
78+
4079

4180

4281

4382
if __name__ == '__main__':
4483
# Each example function needs to get called here, or it won't execute
4584
# as part of the test.
4685
example1()
86+
87+
# Section: ImageBufAlgo common principles
88+
89+
# Section: Pattern Generation
90+
91+
# Section: Image transformation and data movement
92+
example_circular_shift()
93+
94+
# Section: Image Arithmetic
95+
96+
# Section: Image comparison and statistics
97+
98+
# Section: Convolution and frequency-space algorithms
99+
100+
# Section: Image enhancement / restoration
101+
102+
# Section: Morphological filters
103+
104+
# Section: Color space conversion
105+
106+
# Section: Import / export

0 commit comments

Comments
 (0)