diff --git a/src/doc/imageinput.rst b/src/doc/imageinput.rst index b03c057941..118caba08c 100644 --- a/src/doc/imageinput.rst +++ b/src/doc/imageinput.rst @@ -20,35 +20,16 @@ memory, even if that's not the way they're stored in the file): .. tabs:: - .. code-tab:: c++ - - #include - using namespace OIIO; - ... - - auto inp = ImageInput::open(filename); - if (! inp) - return; - const ImageSpec &spec = inp->spec(); - int xres = spec.width; - int yres = spec.height; - int nchannels = spec.nchannels; - auto pixels = std::unique_ptr(new unsigned char[xres * yres * nchannels]); - inp->read_image(0, 0, 0, nchannels, TypeDesc::UINT8, &pixels[0]); - inp->close(); - + .. tab:: C++ + .. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imageinput.cpp + :language: c++ + :start-after: BEGIN-imageinput-simple + :end-before: END-imageinput-simple .. code-tab:: py - - import OpenImageIO as oiio - - inp = oiio.ImageInput.open(filename) - if inp : - spec = inp.spec() - xres = spec.width - yres = spec.height - nchannels = spec.nchannels - pixels = inp.read_image(0, 0, 0, nchannels, "uint8") - inp.close() + .. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imageinput.py + :language: py + :start-after: BEGIN-imageinput-simple + :end-before: END-imageinput-simple Here is a breakdown of what work this code is doing: diff --git a/testsuite/docs-examples-cpp/src/docs-examples-imageinput.cpp b/testsuite/docs-examples-cpp/src/docs-examples-imageinput.cpp index 18aa9c4933..22832b7842 100644 --- a/testsuite/docs-examples-cpp/src/docs-examples-imageinput.cpp +++ b/testsuite/docs-examples-cpp/src/docs-examples-imageinput.cpp @@ -32,10 +32,34 @@ void example1() +// BEGIN-imageinput-simple +#include +using namespace OIIO; + +void simple_read() +{ + const char* filename = "tahoe.tif"; + + auto inp = ImageInput::open(filename); + if (! inp) + return; + const ImageSpec &spec = inp->spec(); + int xres = spec.width; + int yres = spec.height; + int nchannels = spec.nchannels; + auto pixels = std::unique_ptr(new unsigned char[xres * yres * nchannels]); + inp->read_image(0, 0, 0, nchannels, TypeDesc::UINT8, &pixels[0]); + inp->close(); +} + +// END-imageinput-simple + + + int main(int /*argc*/, char** /*argv*/) { // Each example function needs to get called here, or it won't execute // as part of the test. - example1(); + simple_read(); return 0; } diff --git a/testsuite/docs-examples-python/src/docs-examples-imageinput.py b/testsuite/docs-examples-python/src/docs-examples-imageinput.py index b9772fb800..9c16486a52 100644 --- a/testsuite/docs-examples-python/src/docs-examples-imageinput.py +++ b/testsuite/docs-examples-python/src/docs-examples-imageinput.py @@ -37,10 +37,24 @@ def example1() : ############################################################################ +# BEGIN-impageinput-simple +import OpenImageIO as oiio +def simple_read(): + filename = "tahoe.tif" + + inp = oiio.ImageInput.open(filename) + if inp : + spec = inp.spec() + xres = spec.width + yres = spec.height + nchannels = spec.nchannels + pixels = inp.read_image(0, 0, 0, nchannels, "uint8") + inp.close() +# END-imageinput-simple if __name__ == '__main__': # Each example function needs to get called here, or it won't execute # as part of the test. - example1() + simple_read()