Skip to content

Commit a7367a0

Browse files
authored
docs: Added tests for Simple Image input and updated rst (#4019)
Added the simple input tests from the ImageInput chapter of the docs as C++ and Python examples, a part of the larger issue #3992 . Followed prototype (https://github.com/AcademySoftwareFoundation/OpenImageIO/wiki/Converting-documentation-examples-to-tests) approach. --------- Signed-off-by: CalvinSch <[email protected]>
1 parent 1484315 commit a7367a0

File tree

3 files changed

+49
-30
lines changed

3 files changed

+49
-30
lines changed

src/doc/imageinput.rst

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,16 @@ memory, even if that's not the way they're stored in the file):
2020

2121
.. tabs::
2222

23-
.. code-tab:: c++
24-
25-
#include <OpenImageIO/imageio.h>
26-
using namespace OIIO;
27-
...
28-
29-
auto inp = ImageInput::open(filename);
30-
if (! inp)
31-
return;
32-
const ImageSpec &spec = inp->spec();
33-
int xres = spec.width;
34-
int yres = spec.height;
35-
int nchannels = spec.nchannels;
36-
auto pixels = std::unique_ptr<unsigned char[]>(new unsigned char[xres * yres * nchannels]);
37-
inp->read_image(0, 0, 0, nchannels, TypeDesc::UINT8, &pixels[0]);
38-
inp->close();
39-
23+
.. tab:: C++
24+
.. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imageinput.cpp
25+
:language: c++
26+
:start-after: BEGIN-imageinput-simple
27+
:end-before: END-imageinput-simple
4028
.. code-tab:: py
41-
42-
import OpenImageIO as oiio
43-
44-
inp = oiio.ImageInput.open(filename)
45-
if inp :
46-
spec = inp.spec()
47-
xres = spec.width
48-
yres = spec.height
49-
nchannels = spec.nchannels
50-
pixels = inp.read_image(0, 0, 0, nchannels, "uint8")
51-
inp.close()
29+
.. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imageinput.py
30+
:language: py
31+
:start-after: BEGIN-imageinput-simple
32+
:end-before: END-imageinput-simple
5233

5334
Here is a breakdown of what work this code is doing:
5435

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,34 @@ void example1()
3232

3333

3434

35+
// BEGIN-imageinput-simple
36+
#include <OpenImageIO/imageio.h>
37+
using namespace OIIO;
38+
39+
void simple_read()
40+
{
41+
const char* filename = "tahoe.tif";
42+
43+
auto inp = ImageInput::open(filename);
44+
if (! inp)
45+
return;
46+
const ImageSpec &spec = inp->spec();
47+
int xres = spec.width;
48+
int yres = spec.height;
49+
int nchannels = spec.nchannels;
50+
auto pixels = std::unique_ptr<unsigned char[]>(new unsigned char[xres * yres * nchannels]);
51+
inp->read_image(0, 0, 0, nchannels, TypeDesc::UINT8, &pixels[0]);
52+
inp->close();
53+
}
54+
55+
// END-imageinput-simple
56+
57+
58+
3559
int main(int /*argc*/, char** /*argv*/)
3660
{
3761
// Each example function needs to get called here, or it won't execute
3862
// as part of the test.
39-
example1();
63+
simple_read();
4064
return 0;
4165
}

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,24 @@ def example1() :
3737
############################################################################
3838

3939

40+
# BEGIN-impageinput-simple
41+
import OpenImageIO as oiio
42+
def simple_read():
43+
filename = "tahoe.tif"
44+
45+
inp = oiio.ImageInput.open(filename)
46+
if inp :
47+
spec = inp.spec()
48+
xres = spec.width
49+
yres = spec.height
50+
nchannels = spec.nchannels
51+
pixels = inp.read_image(0, 0, 0, nchannels, "uint8")
52+
inp.close()
53+
# END-imageinput-simple
4054

4155

4256

4357
if __name__ == '__main__':
4458
# Each example function needs to get called here, or it won't execute
4559
# as part of the test.
46-
example1()
60+
simple_read()

0 commit comments

Comments
 (0)