diff --git a/src/doc/imagebufalgo.rst b/src/doc/imagebufalgo.rst index 2a277faf12..eaf288e256 100644 --- a/src/doc/imagebufalgo.rst +++ b/src/doc/imagebufalgo.rst @@ -196,21 +196,22 @@ zero() -- create a black image :end-before: END-imagebufalgo-zero :dedent: 4 - .. code-tab:: bash oiiotool + .. tab:: oiiotool + .. code-block:: bash - # Create a new 3-channel, 512x512 float image filled with 0.0 values. - oiiotool --create 512x512 3 -d float -o out.exr + # Create a new 3-channel, 512x512 float image filled with 0.0 values. + oiiotool --create 512x512 3 -d float -o out.exr - # Zero out an existing image, keeping it the same size and data type. - # For simplicity, just scale all values by 0.0 - oiiotool in.exr --mulc 0.0 -o out.exr + # Zero out an existing image, keeping it the same size and data type. + # For simplicity, just scale all values by 0.0 + oiiotool in.exr --mulc 0.0 -o out.exr - # Zero out just the green channel, leave everything else the same. - # Again, rely on --mulc to scale the channels - oiiotool in.exr --mulc 1,0,1 -o out.exr + # Zero out just the green channel, leave everything else the same. + # Again, rely on --mulc to scale the channels + oiiotool in.exr --mulc 1,0,1 -o out.exr - # Zero out a rectangular region of an existing image - oiiotool in.exr --fill:color=0,0,0 100x100+0+0 -o out.exr + # Zero out a rectangular region of an existing image + oiiotool in.exr --fill:color=0,0,0 100x100+0+0 -o out.exr | @@ -238,14 +239,15 @@ fill() -- fill a region with a solid color or gradient :end-before: END-imagebufalgo-fill :dedent: 4 - .. code-tab:: bash oiiotool - - # Create a new 640x480 RGB image, with a top-to-bottom gradient - # from red to pink - oiiotool --pattern fill:top=1,0.7,0.7:bottom=1,0,0 640x480 3 -o A.exr + .. tab:: oiiotool + .. code-block:: bash - # Draw a filled red rectangle overtop existing image A.exr - oiiotool A.exr --pattern fill:color=1,0,0 25x75 3 --paste +50+100 -o A.exr + # Create a new 640x480 RGB image, with a top-to-bottom gradient + # from red to pink + oiiotool --pattern fill:top=1,0.7,0.7:bottom=1,0,0 640x480 3 -o A.exr + + # Draw a filled red rectangle overtop existing image A.exr + oiiotool A.exr --pattern fill:color=1,0,0 25x75 3 --paste +50+100 -o A.exr .. image:: figures/fill.jpg :align: center @@ -281,11 +283,12 @@ checker() -- make a checker pattern :end-before: END-imagebufalgo-checker :dedent: 4 - .. code-tab:: bash oiiotool - - # Create a new 640x480 RGB image, fill it with a two-toned gray - # checkerboard, the checkers being 64x64 pixels each. - oiiotool --pattern checker:width=64:color1=0.1,0.1,0.1:color2=0.4,0.4,0.4 640x480 3 -o A.exr + .. tab:: oiiotool + .. code-block:: bash + + # Create a new 640x480 RGB image, fill it with a two-toned gray + # checkerboard, the checkers being 64x64 pixels each. + oiiotool --pattern checker:width=64:color1=0.1,0.1,0.1:color2=0.4,0.4,0.4 640x480 3 -o A.exr .. image:: figures/checker.jpg :align: center @@ -322,19 +325,20 @@ Noise patterns :end-before: END-imagebufalgo-noise1 :dedent: 4 - .. code-tab:: bash oiiotool - - # Create a new 256x256 field of grayscale white noise on [0,1) - oiiotool --pattern noise:type=uniform:mono=1:seed=1 256x256 3 -o A.exr - - # Create a new 256x256 field of grayscale blue noise on [0,1) - oiiotool --pattern noise:type=blue:mono=1:seed=1 256x256 3 -o B.exr - - # Add color Gaussian noise to an existing image - oiiotool tahoe.jpg --noise:type=gaussian:stddev=0.1 -o C.exr - - # Use salt and pepper noise to make occasional random dropouts - oiiotool tahoe.jpg --noise:type=salt:value=0:portion=0.01:mono=1 -o D.exr + .. tab:: oiiotool + .. code-block:: bash + + # Create a new 256x256 field of grayscale white noise on [0,1) + oiiotool --pattern noise:type=uniform:mono=1:seed=1 256x256 3 -o A.exr + + # Create a new 256x256 field of grayscale blue noise on [0,1) + oiiotool --pattern noise:type=blue:mono=1:seed=1 256x256 3 -o B.exr + + # Add color Gaussian noise to an existing image + oiiotool tahoe.jpg --noise:type=gaussian:stddev=0.1 -o C.exr + + # Use salt and pepper noise to make occasional random dropouts + oiiotool tahoe.jpg --noise:type=salt:value=0:portion=0.01:mono=1 -o D.exr .. @@ -404,9 +408,10 @@ Drawing shapes: points, lines, boxes :end-before: END-imagebufalgo-point :dedent: 4 - .. code-tab:: bash oiiotool - - oiiotool A.exr -point:color=1,0,0,1 50,100 -o out.exr + .. tab:: oiiotool + .. code-block:: bash + + oiiotool A.exr -point:color=1,0,0,1 50,100 -o out.exr | @@ -432,9 +437,10 @@ Drawing shapes: points, lines, boxes :end-before: END-imagebufalgo-lines :dedent: 4 - .. code-tab:: bash oiiotool - - oiiotool A.exr -line:color=1,0,0,1 10,60,20,100 -o out.exr + .. tab:: oiiotool + .. code-block:: bash + + oiiotool A.exr -line:color=1,0,0,1 10,60,20,100 -o out.exr .. image:: figures/lines.png :align: center @@ -463,10 +469,11 @@ Drawing shapes: points, lines, boxes :end-before: END-imagebufalgo-box :dedent: 4 - .. code-tab:: bash oiiotool + .. tab:: oiiotool + .. code-block:: bash - oiiotool A.exr -box:color=0,1,1,1 150,100,240,180 \ - -box:color=0.5,0.5,0,0.5 100,50,180,140 -o out.exr + oiiotool A.exr -box:color=0,1,1,1 150,100,240,180 \ + -box:color=0.5,0.5,0,0.5 100,50,180,140 -o out.exr .. image:: figures/box.png :align: center @@ -499,15 +506,16 @@ Drawing text :end-before: END-imagebufalgo-text1 :dedent: 4 - .. code-tab:: bash oiiotool + .. tab:: oiiotool + .. code-block:: bash - oiiotool ImgA.exr --text:x=50:y=100 "Hello, world" \ - --text:x=100:y=200:fontsize=60:fontname="Arial Bold":color=1,0,0,1 "Go Big Red!" \ - -o out.exr + oiiotool ImgA.exr --text:x=50:y=100 "Hello, world" \ + --text:x=100:y=200:fontsize=60:fontname="Arial Bold":color=1,0,0,1 "Go Big Red!" \ + -o out.exr - oiiotool ImgB.exr \ - --text:x=320:y=240:fontsize=60:fontname="Arial Bold":color=1,1,1,1:alignx=center:aligny=center "Centered" \ - -o out.exr + oiiotool ImgB.exr \ + --text:x=320:y=240:fontsize=60:fontname="Arial Bold":color=1,1,1,1:alignx=center:aligny=center "Centered" \ + -o out.exr .. |textimg1| image:: figures/text.jpg :width: 2.5 in @@ -565,63 +573,38 @@ Shuffling channels Examples: .. tabs:: - - .. code-tab:: c++ - - // Copy the first 3 channels of an RGBA, drop the alpha - ImageBuf RGBA (...); // assume it's initialized, 4 chans - ImageBuf RGB = ImageBufAlgo::channels (RGBA, 3, {} /*default ordering*/); - - // Copy just the alpha channel, making a 1-channel image - ImageBuf Alpha = ImageBufAlgo::channels (RGBA, 1, 3 /*alpha_channel*/); - - // Swap the R and B channels - int channelorder[] = { 2 /*B*/, 1 /*G*/, 0 /*R*/, 3 /*A*/ }; - ImageBuf BRGA = ImageBufAlgo::channels (BRGA, RGBA, 4, channelorder); - - // Add an alpha channel with value 1.0 everywhere to an RGB image, - // keep the other channels with their old ordering, values, and - // names. - int channelorder[] = { 0, 1, 2, -1 /*use a float value*/ }; - float channelvalues[] = { 0 /*ignore*/, 0 /*ignore*/, 0 /*ignore*/, 1.0 }; - std::string channelnames[] = { "", "", "", "A" }; - ImageBuf RGBA = ImageBufAlgo::channels (RGB, 4, channelorder, - channelvalues, channelnames); - - .. code-tab:: py - # Copy the first 3 channels of an RGBA, drop the alpha - RGBA = ImageBuf(...) # assume it's initialized, 4 chans - RGB = ImageBufAlgo.channels (RGBA, (0, 1, 2)) - - # Copy just the alpha channel, making a 1-channel image - Alpha = ImageBufAlgo.channels (RGBA, ("A",)) - - # Swap the R and B channels - BRGA = ImageBufAlgo.channels (BRGA, RGBA, (2, 1, 0, 3)) - - # Add an alpha channel with value 1.0 everywhere to an RGB image, - # keep the other channels with their old ordering, values, and - # names. - RGBA = ImageBufAlgo.channels (RGB, (0, 1, 2, 1.0), - newchannelnames=("", "", "", "A")) - - .. code-tab:: bash oiiotool + .. tab:: C++ + .. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp + :language: c++ + :start-after: BEGIN-imagebufalgo-channels + :end-before: END-imagebufalgo-channels + :dedent: 4 - # Copy the first 3 channels of an RGBA, drop the alpha - oiiotool RGBA.exr -ch R,G,B -o RGB.exr - - # Copy just the alpha channel, making a 1-channel image - oiiotool RGBA.exr -ch A -o A.exr - - # Swap the R and B channels - oiiotool RGBA.exr -ch R=B,G,B=R,A -o BGRA.exr - - # Add an alpha channel with value 1.0 everywhere to an RGB image, - # keep the other channels with their old ordering, values, and - # names. - oiiotool RGB.exr -ch 0,1,2,1.0 -o RGBA.exr + .. tab:: Python + .. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py + :language: py + :start-after: BEGIN-imagebufalgo-channels + :end-before: END-imagebufalgo-channels + :dedent: 4 + .. tab:: oiiotool + .. code-block:: bash + + # Copy the first 3 channels of an RGBA, drop the alpha + oiiotool RGBA.exr -ch R,G,B -o RGB.exr + + # Copy just the alpha channel, making a 1-channel image + oiiotool RGBA.exr -ch A -o A.exr + + # Swap the R and B channels + oiiotool RGBA.exr -ch R=B,G,B=R,A -o BGRA.exr + + # Add an alpha channel with value 1.0 everywhere to an RGB image, + # keep the other channels with their old ordering, values, and + # names. + oiiotool RGB.exr -ch 0,1,2,1.0 -o RGBA.exr + | @@ -635,22 +618,25 @@ Shuffling channels Examples: .. tabs:: - - .. code-tab:: c++ - - ImageBuf RGBA ("rgba.exr"); - ImageBuf Z ("z.exr"); - ImageBuf RGBAZ = ImageBufAlgo::channel_append (RGBA, Z); - .. code-tab:: py - - RGBA = ImageBuf("rgba.exr") - Z = ImageBuf("z.exr") - RGBAZ = ImageBufAlgo.channel_append (RGBA, Z) + .. tab:: C++ + .. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp + :language: c++ + :start-after: BEGIN-imagebufalgo-channel-append + :end-before: END-imagebufalgo-channel-append + :dedent: 4 - .. code-tab:: bash oiiotool + .. tab:: Python + .. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py + :language: py + :start-after: BEGIN-imagebufalgo-channel-append + :end-before: END-imagebufalgo-channel-append + :dedent: 4 + + .. tab:: oiiotool + .. code-block:: bash - oiiotool rgba.exr z.exr --chappend -o rgbaz.exr + oiiotool rgba.exr z.exr --chappend -o rgbaz.exr | @@ -665,23 +651,26 @@ Shuffling channels Examples: .. tabs:: - - .. code-tab:: c++ - - // Set B to be a copy of A, but converted to float - ImageBuf A ("A.exr"); - ImageBuf B = ImageBufAlgo::copy (A, TypeDesc::FLOAT); - .. code-tab:: py - - # Set B to be a copy of A, but converted to float - A = ImageBuf("A.exr") - B = ImageBufAlgo.copy (A, convert="float") + .. tab:: C++ + .. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp + :language: c++ + :start-after: BEGIN-imagebufalgo-copy + :end-before: END-imagebufalgo-copy + :dedent: 4 - .. code-tab:: bash oiiotool - - # Convert A to float pixels - oiiotool A.exr -d float -o B.exr + .. tab:: Python + .. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py + :language: py + :start-after: BEGIN-imagebufalgo-copy + :end-before: END-imagebufalgo-copy + :dedent: 4 + + .. tab:: oiiotool + .. code-block:: bash + + # Convert A to float pixels + oiiotool A.exr -d float -o B.exr | @@ -696,26 +685,27 @@ Shuffling channels Examples: .. tabs:: - - .. code-tab:: c++ - - // Set B to be a 200x100 region of A starting at (50,50), trimming - // the exterior away but leaving that region in its original position. - ImageBuf A ("A.exr"); - ImageBuf B = ImageBufAlgo::crop (A, ROI(50,250,50,150)); - .. code-tab:: py - - # Set B to be a 200x100 region of A starting at (50,50), trimming - # the exterior away but leaving that region in its original position. - A = ImageBuf("A.exr") - B = ImageBufAlgo.crop (A, ROI(50,250,50,150)); + .. tab:: C++ + .. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp + :language: c++ + :start-after: BEGIN-imagebufalgo-crop + :end-before: END-imagebufalgo-crop + :dedent: 4 - .. code-tab:: bash oiiotool - - # Set B to be a 200x100 region of A starting at (50,50), trimming - # the exterior away but leaving that region in its original position. - oiiotool A.exr --crop 200x100+50+50 -o B.exr + .. tab:: Python + .. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py + :language: py + :start-after: BEGIN-imagebufalgo-crop + :end-before: END-imagebufalgo-crop + :dedent: 4 + + .. tab:: oiiotool + .. code-block:: bash + + # Set B to be a 200x100 region of A starting at (50,50), trimming + # the exterior away but leaving that region in its original position. + oiiotool A.exr --crop 200x100+50+50 -o B.exr | @@ -730,26 +720,27 @@ Shuffling channels Examples: .. tabs:: - - .. code-tab:: c++ - - // Set B to be a 200x100 region of A starting at (50,50), but - // moved to the upper left corner so its new origin is (0,0). - ImageBuf A ("A.exr"); - ImageBuf B = ImageBufAlgo::cut (A, ROI(50,250,50,150)); - .. code-tab:: py - - # Set B to be a 200x100 region of A starting at (50,50), but - # moved to the upper left corner so its new origin is (0,0). - A = ImageBuf("A.exr") - B = ImageBufAlgo.cut (A, ROI(50,250,50,150)) + .. tab:: C++ + .. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp + :language: c++ + :start-after: BEGIN-imagebufalgo-cut + :end-before: END-imagebufalgo-cut + :dedent: 4 - .. code-tab:: bash oiiotool - - # Set B to be a 200x100 region of A starting at (50,50), but - # moved to the upper left corner so its new origin is (0,0). - oiiotool A.exr --cut 200x100+50+50 -o B.exr + .. tab:: Python + .. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py + :language: py + :start-after: BEGIN-imagebufalgo-cut + :end-before: END-imagebufalgo-cut + :dedent: 4 + + .. tab:: oiiotool + .. code-block:: bash + + # Set B to be a 200x100 region of A starting at (50,50), but + # moved to the upper left corner so its new origin is (0,0). + oiiotool A.exr --cut 200x100+50+50 -o B.exr | @@ -760,25 +751,26 @@ Shuffling channels Examples: .. tabs:: - - .. code-tab:: c++ - - // Paste fg.exr on top of bg.exr, offset by (100,100) - ImageBuf Bg ("bg.exr"); - ImageBuf Fg ("fg.exr"); - ImageBufAlgo::paste (Bg, 100, 100, 0, 0, fg); - .. code-tab:: py - - # Paste fg.exr on top of bg.exr, offset by (100,100) - Bg = ImageBuf("bg.exr") - Fg = ImageBuf("fg.exr") - ImageBufAlgo.paste (Bg, 100, 100, 0, 0, Fg) + .. tab:: C++ + .. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp + :language: c++ + :start-after: BEGIN-imagebufalgo-paste + :end-before: END-imagebufalgo-paste + :dedent: 4 - .. code-tab:: bash oiiotool - - # Paste fg.exr on top of bg.exr, offset by (100,100) - oiiotool bg.exr fg.exr --paste +100+100 -o bg.exr + .. tab:: Python + .. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py + :language: py + :start-after: BEGIN-imagebufalgo-paste + :end-before: END-imagebufalgo-paste + :dedent: 4 + + .. tab:: oiiotool + .. code-block:: bash + + # Paste fg.exr on top of bg.exr, offset by (100,100) + oiiotool bg.exr fg.exr --paste +100+100 -o bg.exr .. doxygengroup:: rotateN @@ -787,26 +779,27 @@ Shuffling channels Examples: .. tabs:: - - .. code-tab:: c++ - - ImageBuf A ("grid.jpg"); - ImageBuf R90 = ImageBufAlgo::rotate90 (A); - ImageBuf R180 = ImageBufAlgo::rotate180 (A); - ImageBuf R270 = ImageBufAlgo::rotate270 (A); - .. code-tab:: py - - A = ImageBuf("grid.jpg") - R90 = ImageBufAlgo.rotate90 (A) - R180 = ImageBufAlgo.rotate180 (A) - R270 = ImageBufAlgo.rotate270 (A) + .. tab:: C++ + .. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp + :language: c++ + :start-after: BEGIN-imagebufalgo-rotate-n + :end-before: END-imagebufalgo-rotate-n + :dedent: 4 - .. code-tab:: bash oiiotool - - oiiotool grid.jpg -rotate 90 -o R90.jpg - oiiotool grid.jpg -rotate 180 -o R180.jpg - oiiotool grid.jpg -rotate 270 -o R270.jpg + .. tab:: Python + .. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py + :language: py + :start-after: BEGIN-imagebufalgo-rotate-n + :end-before: END-imagebufalgo-rotate-n + :dedent: 4 + + .. tab:: oiiotool + .. code-block:: bash + + oiiotool grid.jpg -rotate 90 -o R90.jpg + oiiotool grid.jpg -rotate 180 -o R180.jpg + oiiotool grid.jpg -rotate 270 -o R270.jpg .. |rotimg1| image:: figures/grid-small.jpg :width: 1.5 in @@ -832,27 +825,27 @@ Shuffling channels Examples: .. tabs:: - - .. code-tab:: c++ - - ImageBuf A ("grid.jpg"); - ImageBuf B; - B = ImageBufAlgo::flip (A); - B = ImageBufAlgo::flop (A); - B = ImageBufAlgo::transpose (A); - .. code-tab:: py - - A = ImageBuf("grid.jpg") - B = ImageBufAlgo.flip (A) - B = ImageBufAlgo.flop (A) - B = ImageBufAlgo.transpose (A) + .. tab:: C++ + .. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp + :language: c++ + :start-after: BEGIN-imagebufalgo-flip-flop-transpose + :end-before: END-imagebufalgo-flip-flop-transpose + :dedent: 4 - .. code-tab:: bash oiiotool - - oiiotool grid.jpg --flip -o flip.jpg - oiiotool grid.jpg --flop -o flop.jpg - oiiotool grid.jpg --transpose -o transpose.jpg + .. tab:: Python + .. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py + :language: py + :start-after: BEGIN-imagebufalgo-flip-flop-transpose + :end-before: END-imagebufalgo-flip-flop-transpose + :dedent: 4 + + .. tab:: oiiotool + .. code-block:: bash + + oiiotool grid.jpg --flip -o flip.jpg + oiiotool grid.jpg --flop -o flop.jpg + oiiotool grid.jpg --transpose -o transpose.jpg .. |flipimg1| image:: figures/grid-small.jpg :width: 1.5 in @@ -883,20 +876,25 @@ Shuffling channels Examples: .. tabs:: - - .. code-tab:: c++ - - ImageBuf A ("tahoe.jpg"); - A = ImageBufAlgo::reorient (A); - .. code-tab:: py + .. tab:: C++ + .. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp + :language: c++ + :start-after: BEGIN-imagebufalgo-reorient + :end-before: END-imagebufalgo-reorient + :dedent: 4 - A = ImageBuf("tahoe.jpg") - A = ImageBufAlgo.reorient (A) + .. tab:: Python + .. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py + :language: py + :start-after: BEGIN-imagebufalgo-reorient + :end-before: END-imagebufalgo-reorient + :dedent: 4 - .. code-tab:: bash oiiotool + .. tab:: oiiotool + .. code-block:: bash - oiiotool tahoe.jpg --reorient -o out.jpg + oiiotool tahoe.jpg --reorient -o out.jpg | @@ -956,20 +954,25 @@ Shuffling channels Examples: .. tabs:: - - .. code-tab:: c++ - ImageBuf Src ("tahoe.exr"); - ImageBuf Dst = ImageBufAlgo::rotate (Src, 45.0); - - .. code-tab:: py + .. tab:: C++ + .. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp + :language: c++ + :start-after: BEGIN-imagebufalgo-rotate-angle + :end-before: END-imagebufalgo-rotate-angle + :dedent: 4 - Src = ImageBuf("tahoe.exr") - Dst = ImageBufAlgo.rotate (Src, 45.0) + .. tab:: Python + .. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py + :language: py + :start-after: BEGIN-imagebufalgo-rotate-angle + :end-before: END-imagebufalgo-rotate-angle + :dedent: 4 - .. code-tab:: bash oiiotool + .. tab:: oiiotool + .. code-block:: bash - oiiotool tahoe.exr --rotate 45.0 -o out.exr + oiiotool tahoe.exr --rotate 45.0 -o out.exr .. |rotateimg1| image:: figures/grid-small.jpg :width: 2.0 in @@ -990,25 +993,26 @@ Shuffling channels Examples: .. tabs:: - - .. code-tab:: c++ - - // Resize the image to 640x480, using the default filter - ImageBuf Src ("tahoe.exr"); - ROI roi (0, 640, 0, 480, 0, 1, /*chans:*/ 0, Src.nchannels()); - ImageBuf Dst = ImageBufAlgo::resize (Src, {}, roi); - .. code-tab:: py + .. tab:: C++ + .. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp + :language: c++ + :start-after: BEGIN-imagebufalgo-resize + :end-before: END-imagebufalgo-resize + :dedent: 4 - # Resize the image to 640x480, using the default filter - Src = ImageBuf("tahoe.exr") - roi = ROI(0, 640, 0, 480, 0, 1, 0, Src.nchannels) - Dst = ImageBufAlgo.resize (Src, roi=roi) + .. tab:: Python + .. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py + :language: py + :start-after: BEGIN-imagebufalgo-resize + :end-before: END-imagebufalgo-resize + :dedent: 4 - .. code-tab:: bash oiiotool + .. tab:: oiiotool + .. code-block:: bash - # Resize the image to 640x480, using the default filter - oiiotool tahoe.exr --resize 640x480 -o out.exr + # Resize the image to 640x480, using the default filter + oiiotool grid.exr --resize 640x480 -o out.exr | @@ -1024,25 +1028,26 @@ Shuffling channels Examples: .. tabs:: - - .. code-tab:: c++ - - // Resample quickly to 320x240, with default interpolation - ImageBuf Src ("tahoe.exr"); - ROI roi (0, 320, 0, 240, 0, 1, /*chans:*/ 0, Src.nchannels()); - ImageBuf Dst = ImageBufAlgo::resiresampleze (Src, true, roi); - .. code-tab:: py + .. tab:: C++ + .. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp + :language: c++ + :start-after: BEGIN-imagebufalgo-resample + :end-before: END-imagebufalgo-resample + :dedent: 4 - # Resample quickly to 320x240, with default interpolation - Src = ImageBuf("tahoe.exr") - roi = ROI(0, 320, 0, 240, 0, 1, 0, Src.nchannels) - Dst = ImageBufAlgo.resample (Src, roi=roi) + .. tab:: Python + .. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py + :language: py + :start-after: BEGIN-imagebufalgo-resample + :end-before: END-imagebufalgo-resample + :dedent: 4 - .. code-tab:: bash oiiotool + .. tab:: oiiotool + .. code-block:: bash - # Resample quickly to 320x240, with default interpolation - oiiotool tahoe.exr --resample 320x240 -o out.exr + # Resample quickly to 320x240, with default interpolation + oiiotool tahoe.exr --resample 320x240 -o out.exr | @@ -1054,25 +1059,26 @@ Shuffling channels Examples: .. tabs:: - - .. code-tab:: c++ - // Resize to fit into a max of 640x480, preserving the aspect ratio - ImageBuf Src ("tahoe.exr"); - ROI roi (0, 640, 0, 480, 0, 1, /*chans:*/ 0, Src.nchannels()); - ImageBuf Dst = ImageBufAlgo::fit (Src, {}, roi); - - .. code-tab:: py + .. tab:: C++ + .. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp + :language: c++ + :start-after: BEGIN-imagebufalgo-fit + :end-before: END-imagebufalgo-fit + :dedent: 4 - # Resize to fit into a max of 640x480, preserving the aspect ratio - Src = ImageBuf("tahoe.exr") - roi = ROI(0, 640, 0, 480, 0, 1, 0, Src.nchannels) - Dst = ImageBufAlgo.fit (Src, roi=roi) + .. tab:: Python + .. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py + :language: py + :start-after: BEGIN-imagebufalgo-fit + :end-before: END-imagebufalgo-fit + :dedent: 4 - .. code-tab:: bash oiiotool + .. tab:: oiiotool + .. code-block:: bash - # Resize to fit into a max of 640x480, preserving the aspect ratio - oiiotool tahoe.exr --fit 640x480 -o out.exr + # Resize to fit into a max of 640x480, preserving the aspect ratio + oiiotool grid.exr --fit 640x480 -o out.exr | @@ -1083,27 +1089,25 @@ Shuffling channels Examples: .. tabs:: - - .. code-tab:: c++ - - Imath::M33f M ( 0.7071068, 0.7071068, 0, - -0.7071068, 0.7071068, 0, - 20, -8.284271, 1); - ImageBuf Src ("tahoe.exr"); - ParamValue options[] = { { "filtername", "lanczos3" } }; - ImageBuf Dst = ImageBufAlgo::warp (dst, src, M, options); - .. code-tab:: py + .. tab:: C++ + .. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp + :language: c++ + :start-after: BEGIN-imagebufalgo-warp + :end-before: END-imagebufalgo-warp + :dedent: 4 - M = ( 0.7071068, 0.7071068, 0, - -0.7071068, 0.7071068, 0, - 20, -8.284271, 1) - Src = ImageBuf("tahoe.exr") - Dst = ImageBufAlgo.warp (Src, M, filtername="lanczos3") + .. tab:: Python + .. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py + :language: py + :start-after: BEGIN-imagebufalgo-warp + :end-before: END-imagebufalgo-warp + :dedent: 4 - .. code-tab:: bash oiiotool + .. tab:: oiiotool + .. code-block:: bash - oiiotool tahoe.exr --warp 0.7071068,0.7071068,0,-0.7071068,0.7071068,0,20,-8.284271,1 -o out.exr + oiiotool grid.exr --warp 0.7071068,0.7071068,0,-0.7071068,0.7071068,0,20,-8.284271,1 -o out.exr | diff --git a/testsuite/docs-examples-cpp/CMakeLists.txt b/testsuite/docs-examples-cpp/CMakeLists.txt index 27b4a1cdd7..e93b9439d5 100644 --- a/testsuite/docs-examples-cpp/CMakeLists.txt +++ b/testsuite/docs-examples-cpp/CMakeLists.txt @@ -20,6 +20,7 @@ set (CMAKE_CXX_EXTENSIONS OFF) # Make sure we have dependencies we need find_package (OpenImageIO CONFIG REQUIRED) +find_package (Imath CONFIG REQUIRED) # Special for OIIO testsuite when running in sanitize mode if (DEFINED ENV{SANITIZE}) @@ -34,5 +35,5 @@ set (chapters imageioapi imageoutput imageinput writingplugins foreach (chapter ${chapters}) add_executable(docs-examples-${chapter} src/docs-examples-${chapter}.cpp) target_link_libraries (docs-examples-${chapter} - PRIVATE OpenImageIO::OpenImageIO) + PRIVATE OpenImageIO::OpenImageIO Imath::Imath) endforeach () diff --git a/testsuite/docs-examples-cpp/ref/out-arm.txt b/testsuite/docs-examples-cpp/ref/out-arm.txt new file mode 100644 index 0000000000..1de718a808 --- /dev/null +++ b/testsuite/docs-examples-cpp/ref/out-arm.txt @@ -0,0 +1,112 @@ +example_output_error1 +error: Uninitialized input image +example_output_error2 +error: Uninitialized input image +example_zero +example_fill +example_checker +example_noise1 +example_noise2 +example_point +example_lines +example_box +example_text1 +example_text2 +example_channels +example_channel_append +example_copy +example_crop +example_cut +example_paste +example_rotate_n +example_flip_flop_transpose +example_reorient +example_circular_shift +example_rotate +example_resize +example_resample +example_fit +example_warp +example_make_texture +zero1.exr : 512 x 512, 3 channel, half openexr + SHA-1: 95823C334FCE55968E8D2827CCD1CF77CEE19ABD +zero2.exr : 256 x 256, 4 channel, half openexr + SHA-1: 6A521E1D2A632C26E53B83D2CC4B0EDECFC1E68C +zero3.exr : 256 x 256, 4 channel, half openexr + SHA-1: 1254F2956229777B721576B94A6A944ECB806A37 +zero4.exr : 256 x 256, 4 channel, half openexr + SHA-1: 36EB49C5102703693C078717CE82AE05D4904680 +fill.exr : 640 x 480, 3 channel, half openexr + SHA-1: 1BBCA1D5966D02554C13C1FAEF01F6E6E6169356 +checker.exr : 640 x 480, 3 channel, half openexr + SHA-1: 64508259AE242B593B906C848A2D69C443A3FBFD +noise1.exr : 256 x 256, 3 channel, half openexr + SHA-1: 66FF64DDAFDDE290031C20FAA208A193908EE9D4 +noise2.exr : 256 x 256, 3 channel, half openexr + SHA-1: 06011F9D59106096F4742A3DAB458D506A08E34C +noise3.exr : 512 x 384, 3 channel, half openexr + SHA-1: 95EDBCA9953281CE63A3E18C7C04BCCB07CB4C8A +noise4.exr : 512 x 384, 3 channel, half openexr + SHA-1: 43BC1FDFA1F18635B635A57D71DB08BB347CBD46 +blue-noise.exr : 256 x 256, 4 channel, half openexr + SHA-1: 5A0A51D1AD3F34633B781AFF9B90E59996C31AD0 +point.exr : 640 x 480, 4 channel, half openexr + SHA-1: 56E2BDBE03826F203132BD9E80AF44450307BDCE +lines.exr : 640 x 480, 4 channel, half openexr + SHA-1: 177C4C5C61ACDD54F198A45E52836DE897C4CE96 +box.exr : 640 x 480, 4 channel, half openexr + SHA-1: 984273B0A06E54873E24A732651490117E40410C +text1.exr : 640 x 480, 3 channel, half openexr + SHA-1: 1CF68F9B099A30EFF06850CEFBEDD3C2F861A654 +text2.exr : 640 x 480, 3 channel, half openexr + SHA-1: 00C96AE28FD12752AD1968D3D07EE30F1F218D76 +channels-rgba.exr : 256 x 256, 4 channel, half openexr + SHA-1: C823E3701152B4B3C20DD79EA8A20CF4293F4B71 +channels-rgb.exr : 256 x 256, 3 channel, half openexr + SHA-1: 4074B050432CE7C664CEC4546A46E74F9A310CDC +channels-brga.exr : 256 x 256, 4 channel, half openexr + SHA-1: 04E09E64C61CEA1634D26FB2E6C733875D163671 +channels-alpha.exr : 256 x 256, 1 channel, half openexr + SHA-1: 99C332E70F321F0EA47C0F70AF8B0E3E6524F91F +channel-append.exr : 640 x 480, 5 channel, half openexr + SHA-1: E6A50C80C051F0F587FCB68B515B50E4DC3E9359 +copy.exr : 256 x 256, 4 channel, float openexr + SHA-1: 7044589C8B904DAF6A2BA3246224E97DD460AC93 +crop.exr : 200 x 100, 4 channel, half openexr + SHA-1: 4DA3918566D087A9D2D9E93B2A7BABE971FE6BBD +cut.exr : 200 x 100, 4 channel, half openexr + SHA-1: 4DA3918566D087A9D2D9E93B2A7BABE971FE6BBD +paste.exr : 256 x 256, 4 channel, half openexr + SHA-1: 67A4C36DEAED98A5A8ABA5F0E0EDE697345DC22A +rotate-90.exr : 256 x 256, 4 channel, half openexr + SHA-1: AFFAEA876E8E7760226B017B0A89A3549B7A5895 +rotate-180.exr : 256 x 256, 4 channel, half openexr + SHA-1: A5E42C5F18177DA146EC7E4567E4AE3AE2816C3C +rotate-270.exr : 256 x 256, 4 channel, half openexr + SHA-1: 46C803894186457376A0C590768C9DB4877737BB +flip.exr : 256 x 256, 4 channel, half openexr + SHA-1: A9EB9A8762BCD8DD161C00B01E2DF39E5C91B0D4 +flop.exr : 256 x 256, 4 channel, half openexr + SHA-1: 7C10717DB4F2E21F0B4F6D5404C660CA8B504F5E +rotate-45.tif : 256 x 256, 4 channel, uint8 tiff + SHA-1: E2E41264B7BD250C3AACF9F6161A0FA86B22FA57 +resize.tif : 320 x 240, 4 channel, uint8 tiff + SHA-1: 6FD1A7A97729CD6D51A22ADE0709CC4DFDC3C826 +resample.exr : 320 x 240, 4 channel, half openexr + SHA-1: 16FC7DCFE01DC312593B00B9F90D71BAF3D52450 +fit.tif : 240 x 240, 4 channel, uint8 tiff + SHA-1: 5474A93DED5F9F44E561B70A53F509677961AB34 +warp.exr : 256 x 256, 4 channel, half openexr + SHA-1: 7EA7EB6798E051B5F4EB3722498371E55869BC91 +transpose.exr : 256 x 256, 4 channel, half openexr + SHA-1: FAD57FB60460383D3D2D24B346F35A44846CCC39 +reorient.exr : 256 x 256, 4 channel, half openexr + SHA-1: 46C803894186457376A0C590768C9DB4877737BB +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" +PASS diff --git a/testsuite/docs-examples-cpp/ref/out.txt b/testsuite/docs-examples-cpp/ref/out.txt index 7c7b8c2d38..a4518b73d6 100644 --- a/testsuite/docs-examples-cpp/ref/out.txt +++ b/testsuite/docs-examples-cpp/ref/out.txt @@ -1,37 +1,107 @@ +example_output_error1 error: Uninitialized input image +example_output_error2 error: Uninitialized input image -zero1.exr : 512 x 512, 3 channel, float openexr - SHA-1: 1E5F8DEF40BB0CB0F7156B9C2BAB9EFB49CFB699 +example_zero +example_fill +example_checker +example_noise1 +example_noise2 +example_point +example_lines +example_box +example_text1 +example_text2 +example_channels +example_channel_append +example_copy +example_crop +example_cut +example_paste +example_rotate_n +example_flip_flop_transpose +example_reorient +example_circular_shift +example_rotate +example_resize +example_resample +example_fit +example_warp +example_make_texture +zero1.exr : 512 x 512, 3 channel, half openexr + SHA-1: 95823C334FCE55968E8D2827CCD1CF77CEE19ABD zero2.exr : 256 x 256, 4 channel, half openexr SHA-1: 6A521E1D2A632C26E53B83D2CC4B0EDECFC1E68C zero3.exr : 256 x 256, 4 channel, half openexr SHA-1: 1254F2956229777B721576B94A6A944ECB806A37 zero4.exr : 256 x 256, 4 channel, half openexr SHA-1: 36EB49C5102703693C078717CE82AE05D4904680 -fill.exr : 640 x 480, 3 channel, float openexr - SHA-1: D517EA07CB6DB931AE4BF6D9E9957EEF9228734E -checker.exr : 640 x 480, 3 channel, float openexr - SHA-1: 87A4424581AAFCE31E6D1134E5025B620B48BBB3 -noise1.exr : 256 x 256, 3 channel, float openexr - SHA-1: 9E9278C8F5460068363D36DBD395FA59CA5986DC -noise2.exr : 256 x 256, 3 channel, float openexr - SHA-1: 0A75E8EF38846D8DC5D8BA997EB54F7A36058288 +fill.exr : 640 x 480, 3 channel, half openexr + SHA-1: 1BBCA1D5966D02554C13C1FAEF01F6E6E6169356 +checker.exr : 640 x 480, 3 channel, half openexr + SHA-1: 64508259AE242B593B906C848A2D69C443A3FBFD +noise1.exr : 256 x 256, 3 channel, half openexr + SHA-1: 66FF64DDAFDDE290031C20FAA208A193908EE9D4 +noise2.exr : 256 x 256, 3 channel, half openexr + SHA-1: 06011F9D59106096F4742A3DAB458D506A08E34C noise3.exr : 512 x 384, 3 channel, half openexr SHA-1: 95EDBCA9953281CE63A3E18C7C04BCCB07CB4C8A noise4.exr : 512 x 384, 3 channel, half openexr SHA-1: 43BC1FDFA1F18635B635A57D71DB08BB347CBD46 -blue-noise.exr : 256 x 256, 4 channel, float openexr - SHA-1: 36F448FE29C9DE6CFA65FC0BFCF4178DC66581C4 -point.exr : 640 x 480, 4 channel, float openexr - SHA-1: A2AC7CC98AB44798EEEA76C253DE44F6E49FFB8D -lines.exr : 640 x 480, 4 channel, float openexr - SHA-1: 69C0317F92256FD30415D1FE12419DC1C514D818 -box.exr : 640 x 480, 4 channel, float openexr - SHA-1: 6CBE5E98B145C5975CB930A91BAEE981C30E6B32 -text1.exr : 640 x 480, 3 channel, float openexr - SHA-1: 014ECFC5EBF07F77DF24A592F43BC7CB101534AE -text2.exr : 640 x 480, 3 channel, float openexr - SHA-1: 53359E96A286F909A89ACC99A67A9ED3BADC4A7A +blue-noise.exr : 256 x 256, 4 channel, half openexr + SHA-1: 5A0A51D1AD3F34633B781AFF9B90E59996C31AD0 +point.exr : 640 x 480, 4 channel, half openexr + SHA-1: 56E2BDBE03826F203132BD9E80AF44450307BDCE +lines.exr : 640 x 480, 4 channel, half openexr + SHA-1: 177C4C5C61ACDD54F198A45E52836DE897C4CE96 +box.exr : 640 x 480, 4 channel, half openexr + SHA-1: 984273B0A06E54873E24A732651490117E40410C +text1.exr : 640 x 480, 3 channel, half openexr + SHA-1: 1CF68F9B099A30EFF06850CEFBEDD3C2F861A654 +text2.exr : 640 x 480, 3 channel, half openexr + SHA-1: 00C96AE28FD12752AD1968D3D07EE30F1F218D76 +channels-rgba.exr : 256 x 256, 4 channel, half openexr + SHA-1: C823E3701152B4B3C20DD79EA8A20CF4293F4B71 +channels-rgb.exr : 256 x 256, 3 channel, half openexr + SHA-1: 4074B050432CE7C664CEC4546A46E74F9A310CDC +channels-brga.exr : 256 x 256, 4 channel, half openexr + SHA-1: 04E09E64C61CEA1634D26FB2E6C733875D163671 +channels-alpha.exr : 256 x 256, 1 channel, half openexr + SHA-1: 99C332E70F321F0EA47C0F70AF8B0E3E6524F91F +channel-append.exr : 640 x 480, 5 channel, half openexr + SHA-1: E6A50C80C051F0F587FCB68B515B50E4DC3E9359 +copy.exr : 256 x 256, 4 channel, float openexr + SHA-1: 7044589C8B904DAF6A2BA3246224E97DD460AC93 +crop.exr : 200 x 100, 4 channel, half openexr + SHA-1: 4DA3918566D087A9D2D9E93B2A7BABE971FE6BBD +cut.exr : 200 x 100, 4 channel, half openexr + SHA-1: 4DA3918566D087A9D2D9E93B2A7BABE971FE6BBD +paste.exr : 256 x 256, 4 channel, half openexr + SHA-1: 67A4C36DEAED98A5A8ABA5F0E0EDE697345DC22A +rotate-90.exr : 256 x 256, 4 channel, half openexr + SHA-1: AFFAEA876E8E7760226B017B0A89A3549B7A5895 +rotate-180.exr : 256 x 256, 4 channel, half openexr + SHA-1: A5E42C5F18177DA146EC7E4567E4AE3AE2816C3C +rotate-270.exr : 256 x 256, 4 channel, half openexr + SHA-1: 46C803894186457376A0C590768C9DB4877737BB +flip.exr : 256 x 256, 4 channel, half openexr + SHA-1: A9EB9A8762BCD8DD161C00B01E2DF39E5C91B0D4 +flop.exr : 256 x 256, 4 channel, half openexr + SHA-1: 7C10717DB4F2E21F0B4F6D5404C660CA8B504F5E +rotate-45.tif : 256 x 256, 4 channel, uint8 tiff + SHA-1: 2D4AECFD398F9E0AA0051888D0EE7CDC1E438A5A +resize.tif : 320 x 240, 4 channel, uint8 tiff + SHA-1: 6FD1A7A97729CD6D51A22ADE0709CC4DFDC3C826 +resample.exr : 320 x 240, 4 channel, half openexr + SHA-1: 5C0CC0A293FCD30B2AE44A0BED7D27DB9B8C8E50 +fit.tif : 240 x 240, 4 channel, uint8 tiff + SHA-1: AC77B6A4BFF3E42EB207CFDADEE6BCED4653D2B4 +warp.exr : 256 x 256, 4 channel, half openexr + SHA-1: EEB460766F07B47C647D630B568F25FFEEBF5A62 +transpose.exr : 256 x 256, 4 channel, half openexr + SHA-1: FAD57FB60460383D3D2D24B346F35A44846CCC39 +reorient.exr : 256 x 256, 4 channel, half openexr + SHA-1: 46C803894186457376A0C590768C9DB4877737BB cshift.exr : 256 x 256, 4 channel, half openexr SHA-1: 000F95FDC44D4DBDA8B4041C2506149C7AE28ACA texture.exr : 256 x 256, 3 channel, half openexr (+mipmap) diff --git a/testsuite/docs-examples-cpp/run.py b/testsuite/docs-examples-cpp/run.py index 50fbdc1340..d63b8cd668 100755 --- a/testsuite/docs-examples-cpp/run.py +++ b/testsuite/docs-examples-cpp/run.py @@ -24,7 +24,10 @@ command += run_app(prefix + "docs-examples-" + chapter) # hashes merely check that the images don't change, but saves us the space -# of checking in a full copy of the image if it's not needed. +# of checking in a full copy of the image if it's not needed. This is not +# suitable if the image may change slightly from platform to platform or +# with different versions of dependencies, for that we should use the +# full reference image comparison with appropriate thresholds. hashes = [ # Outputs from the ImageBufAlgo chapter: "zero1.exr", @@ -43,6 +46,27 @@ "box.exr", "text1.exr", "text2.exr", + "channels-rgba.exr", + "channels-rgb.exr", + "channels-brga.exr", + "channels-alpha.exr", + "channel-append.exr", + "copy.exr", + "crop.exr", + "cut.exr", + "paste.exr", + "rotate-90.exr", + "rotate-180.exr", + "rotate-270.exr", + "flip.exr", + "flop.exr", + "rotate-45.tif", + "resize.tif", + "resample.exr", + "fit.tif", + "warp.exr", + "transpose.exr", + "reorient.exr", "cshift.exr", "texture.exr" ] @@ -56,6 +80,10 @@ "simple.tif", "scanlines.tif", # Outputs from the ImageInput chapter: + # Outputs from the ImageBuf chapter: + + # Outputs from the ImageBufAlgo chapter: + # ... etc ... other chapters ... # Last, we have the out.txt that captures console output of the test diff --git a/testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp b/testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp index f75b5987ed..8004e70369 100644 --- a/testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp +++ b/testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp @@ -3,6 +3,13 @@ // https://github.com/AcademySoftwareFoundation/OpenImageIO +// TRICK: skip deprecated functions in IBA +#define DOXYGEN_SHOULD_SKIP_THIS + +#include + + + /////////////////////////////////////////////////////////////////////////// // This file contains code examples from the ImageBufAlgo chapter of the // main OpenImageIO documentation. @@ -16,6 +23,7 @@ #include using namespace OIIO; + void example1() { // @@ -37,6 +45,7 @@ void example1() void example_output_error1() { + print("example_output_error1\n"); ImageBuf fg, bg; // BEGIN-imagebufalgo-output-error1 @@ -47,8 +56,10 @@ void example_output_error1() // END-imagebufalgo-output-error1 } + void example_output_error2() { + print("example_output_error2\n"); ImageBuf fg, bg; // BEGIN-imagebufalgo-output-error2 @@ -65,6 +76,7 @@ void example_output_error2() void example_zero() { + print("example_zero\n"); ImageBuf A("grid.exr"); ImageBuf B("grid.exr"); ImageBuf C("grid.exr"); @@ -86,44 +98,52 @@ void example_zero() ImageBufAlgo::zero (C, ROI (0, 100, 0, 100)); // END-imagebufalgo-zero - zero.write("zero1.exr"); - A.write("zero2.exr"); - B.write("zero3.exr"); - C.write("zero4.exr"); + zero.write("zero1.exr", TypeHalf); + A.write("zero2.exr", TypeHalf); + B.write("zero3.exr", TypeHalf); + C.write("zero4.exr", TypeHalf); } + void example_fill() { + print("example_fill\n"); // BEGIN-imagebufalgo-fill // Create a new 640x480 RGB image, with a top-to-bottom gradient // from red to pink float pink[3] = { 1, 0.7, 0.7 }; - float red[3] = { 1, 0, 0 }; - ImageBuf A = ImageBufAlgo::fill (red, pink, ROI(0, 640, 0, 480, 0, 1, 0, 3)); + float red[3] = { 1, 0, 0 }; + ImageBuf A = ImageBufAlgo::fill(red, cspan(pink), + ROI(0, 640, 0, 480, 0, 1, 0, 3)); // Draw a filled red rectangle overtop existing image A. - ImageBufAlgo::fill (A, red, ROI(50, 100, 75, 175)); + ImageBufAlgo::fill (A, cspan(red), ROI(50, 100, 75, 175)); // END-imagebufalgo-fill - A.write("fill.exr"); + A.write("fill.exr", TypeHalf); } + void example_checker() { + print("example_checker\n"); // BEGIN-imagebufalgo-checker // Create a new 640x480 RGB image, fill it with a two-toned gray // checkerboard, the checkers being 64x64 pixels each. - ImageBuf A (ImageSpec(640, 480, 3, TypeDesc::FLOAT)); - float dark[3] = { 0.1, 0.1, 0.1 }; + ImageBuf A(ImageSpec(640, 480, 3, TypeDesc::FLOAT)); + float dark[3] = { 0.1, 0.1, 0.1 }; float light[3] = { 0.4, 0.4, 0.4 }; - ImageBufAlgo::checker (A, 64, 64, 1, dark, light, 0, 0, 0); + ImageBufAlgo::checker(A, 64, 64, 1, cspan(dark), cspan(light), + 0, 0, 0); // END-imagebufalgo-checker - A.write("checker.exr"); + A.write("checker.exr", TypeHalf); } + void example_noise1() { + print("example_noise1\n"); // BEGIN-imagebufalgo-noise1 // Create a new 256x256 field of grayscale white noise on [0,1) ImageBuf A = ImageBufAlgo::noise ("uniform", 0.0f /*min*/, 1.0f /*max*/, @@ -144,34 +164,40 @@ void example_noise1() true /*mono*/, 1 /*seed*/); // END-imagebufalgo-noise1 - A.write("noise1.exr"); - B.write("noise2.exr"); - C.write("noise3.exr"); - D.write("noise4.exr"); + A.write("noise1.exr", TypeHalf); + B.write("noise2.exr", TypeHalf); + C.write("noise3.exr", TypeHalf); + D.write("noise4.exr", TypeHalf); } + void example_noise2() { + print("example_noise2\n"); // BEGIN-imagebufalgo-noise2 const ImageBuf& A = ImageBufAlgo::bluenoise_image(); // END-imagebufalgo-noise2 - A.write("blue-noise.exr"); + A.write("blue-noise.exr", TypeHalf); } + void example_point() { + print("example_point\n"); // BEGIN-imagebufalgo-point ImageBuf A (ImageSpec (640, 480, 4, TypeDesc::FLOAT)); float red[4] = { 1, 0, 0, 1 }; ImageBufAlgo::render_point (A, 50, 100, red); // END-imagebufalgo-point - A.write("point.exr"); + A.write("point.exr", TypeHalf); } + void example_lines() { + print("example_lines\n"); // BEGIN-imagebufalgo-lines ImageBuf A (ImageSpec (640, 480, 4, TypeDesc::FLOAT)); float red[4] = { 1, 0, 0, 1 }; @@ -179,11 +205,13 @@ void example_lines() ImageBufAlgo::render_line (A, 250, 20, 100, 190, red, true); // END-imagebufalgo-lines - A.write("lines.exr"); + A.write("lines.exr", TypeHalf); } + void example_box() { + print("example_box\n"); // BEGIN-imagebufalgo-box ImageBuf A (ImageSpec (640, 480, 4, TypeDesc::FLOAT)); float cyan[4] = { 0, 1, 1, 1 }; @@ -192,33 +220,37 @@ void example_box() ImageBufAlgo::render_box (A, 100, 50, 180, 140, yellow_transparent, true); // END-imagebufalgo-box - A.write("box.exr"); + A.write("box.exr", TypeHalf); } + void example_text1() { + print("example_text1\n"); ImageBuf ImgA = ImageBufAlgo::zero(ROI(0, 640, 0, 480, 0, 1, 0, 3)); ImageBuf ImgB = ImageBufAlgo::zero(ROI(0, 640, 0, 480, 0, 1, 0, 3)); // BEGIN-imagebufalgo-text1 - ImageBufAlgo::render_text (ImgA, 50, 100, "Hello, world"); + ImageBufAlgo::render_text(ImgA, 50, 100, "Hello, world"); float red[] = { 1, 0, 0, 1 }; - ImageBufAlgo::render_text (ImgA, 100, 200, "Go Big Red!", - 60, "" /*font name*/, red); + ImageBufAlgo::render_text(ImgA, 100, 200, "Go Big Red!", 60, + "" /*font name*/, cspan(red)); float white[] = { 1, 1, 1, 1 }; - ImageBufAlgo::render_text (ImgB, 320, 240, "Centered", - 60, "" /*font name*/, white, + ImageBufAlgo::render_text(ImgB, 320, 240, "Centered", 60, "" /*font name*/, + cspan(white), ImageBufAlgo::TextAlignX::Center, ImageBufAlgo::TextAlignY::Center); // END-imagebufalgo-text1 - ImgA.write("text1.exr"); - ImgB.write("text2.exr"); + ImgA.write("text1.exr", TypeHalf); + ImgB.write("text2.exr", TypeHalf); } + void example_text2() { + print("example_text2\n"); // BEGIN-imagebufalgo-text2 // Render text centered in the image, using text_size to find out // the size we will need and adjusting the coordinates. @@ -233,18 +265,233 @@ void example_text2() // END-imagebufalgo-text2 } + // Section: Image transformation and data movement +void example_channels() +{ + print("example_channels\n"); + ImageBuf RGBA("grid.exr"); + + // BEGIN-imagebufalgo-channels + // Copy the first 3 channels of an RGBA, drop the alpha + ImageBuf RGB = ImageBufAlgo::channels(RGBA, 3, {} /*default ordering*/); + + // Copy just the alpha channel, making a 1-channel image + ImageBuf Alpha = ImageBufAlgo::channels(RGBA, 1, 3 /*alpha_channel*/); + + // Swap the R and B channels + ImageBuf BRGA; + bool success = ImageBufAlgo::channels(BRGA, RGBA, 4, { 2, 1, 0, 3 }, {}, + { "R", "G", "B", "A" }); + + // Add an alpha channel with value 1.0 everywhere to an RGB image, + // keep the other channels with their old ordering, values, and + // names. + RGBA = ImageBufAlgo::channels(RGB, 4, { 0, 1, 2, -1 }, + { 0 /*ignore*/, 0 /*ignore*/, 0 /*ignore*/, + 1.0 }, + { "", "", "", "A" }); + // END-imagebufalgo-channels + + RGBA.write("channels-rgba.exr"); + RGB.write("channels-rgb.exr"); + Alpha.write("channels-alpha.exr"); + BRGA.write("channels-brga.exr"); +} + + +void example_channel_append() +{ + print("example_channel_append\n"); + ImageBuf Z(ImageSpec(640, 480, 1, TypeDesc::FLOAT)); + + // BEGIN-imagebufalgo-channel-append + ImageBuf RGBA("grid.exr"); + ImageBuf RGBAZ = ImageBufAlgo::channel_append(RGBA, Z); + // END-imagebufalgo-channel-append + + RGBAZ.write("channel-append.exr", TypeHalf); +} + + +void example_copy() +{ + print("example_copy\n"); + // BEGIN-imagebufalgo-copy + // Set B to be a copy of A, but converted to float + ImageBuf A("grid.exr"); + ImageBuf B = ImageBufAlgo::copy(A, TypeDesc::FLOAT); + // END-imagebufalgo-copy + + B.write("copy.exr"); +} + + +void example_crop() +{ + print("example_crop\n"); + // BEGIN-imagebufalgo-crop + // Set B to be a 200x100 region of A starting at (50,50), trimming + // the exterior away but leaving that region in its original position. + ImageBuf A("grid.exr"); + ImageBuf B = ImageBufAlgo::crop(A, ROI(50, 250, 50, 150)); + // END-imagebufalgo-crop + + B.write("crop.exr"); +} + + +void example_cut() +{ + print("example_cut\n"); + // BEGIN-imagebufalgo-cut + // Set B to be a 200x100 region of A starting at (50,50), but + // moved to the upper left corner so its new origin is (0,0). + ImageBuf A("grid.exr"); + ImageBuf B = ImageBufAlgo::cut(A, ROI(50, 250, 50, 150)); + // END-imagebufalgo-cut + + B.write("cut.exr"); +} + + +void example_paste() +{ + print("example_paste\n"); + // BEGIN-imagebufalgo-paste + // Paste Fg on top of Bg, offset by (100,100) + ImageBuf Bg("grid.exr"); + ImageBuf Fg("tahoe.tif"); + ImageBufAlgo::paste(Bg, 100, 100, 0, 0, Fg); + // END-imagebufalgo-paste + + Bg.write("paste.exr"); +} + + +void example_rotate_n() +{ + print("example_rotate_n\n"); + // BEGIN-imagebufalgo-rotate-n + ImageBuf A("grid.exr"); + ImageBuf R90 = ImageBufAlgo::rotate90(A); + ImageBuf R180 = ImageBufAlgo::rotate180(A); + ImageBuf R270 = ImageBufAlgo::rotate270(A); + // END-imagebufalgo-rotate-n + + R90.write("rotate-90.exr"); + R180.write("rotate-180.exr"); + R270.write("rotate-270.exr"); +} + + +void example_flip_flop_transpose() +{ + print("example_flip_flop_transpose\n"); + // BEGIN-imagebufalgo-flip-flop-transpose + ImageBuf A("grid.exr"); + ImageBuf B1 = ImageBufAlgo::flip(A); + ImageBuf B2 = ImageBufAlgo::flop(A); + ImageBuf B3 = ImageBufAlgo::transpose(A); + // END-imagebufalgo-flip-flop-transpose + + B1.write("flip.exr"); + B2.write("flop.exr"); + B3.write("transpose.exr"); +} + + +void example_reorient() +{ + print("example_reorient\n"); + ImageBuf tmp("grid.exr"); + tmp.specmod().attribute("Orientation", 8); + tmp.write("grid-vertical.exr"); + + // BEGIN-imagebufalgo-reorient + ImageBuf A("grid-vertical.exr"); + A = ImageBufAlgo::reorient(A); + // END-imagebufalgo-reorient + + A.write("reorient.exr"); +} + + void example_circular_shift() { + print("example_circular_shift\n"); // BEGIN-imagebufalgo-cshift ImageBuf A("grid.exr"); ImageBuf B = ImageBufAlgo::circular_shift(A, 70, 30); - B.write("cshift.exr"); // END-imagebufalgo-cshift + B.write("cshift.exr"); } +void example_rotate() +{ + print("example_rotate\n"); + // BEGIN-imagebufalgo-rotate-angle + ImageBuf Src ("grid.exr"); + ImageBuf Dst = ImageBufAlgo::rotate (Src, 45.0); + // END-imagebufalgo-rotate-angle + Dst.write("rotate-45.tif", TypeUInt8); +} + + +void example_resize() +{ + print("example_resize\n"); + // BEGIN-imagebufalgo-resize + // Resize the image to 640x480, using the default filter + ImageBuf Src("grid.exr"); + ROI roi(0, 320, 0, 240, 0, 1, /*chans:*/ 0, Src.nchannels()); + ImageBuf Dst = ImageBufAlgo::resize(Src, {}, roi); + // END-imagebufalgo-resize + Dst.write("resize.tif", TypeUInt8); +} + + +void example_resample() +{ + print("example_resample\n"); + // BEGIN-imagebufalgo-resample + // Resample quickly to 320x240, with default interpolation + ImageBuf Src("grid.exr"); + ROI roi(0, 320, 0, 240, 0, 1, /*chans:*/ 0, Src.nchannels()); + ImageBuf Dst = ImageBufAlgo::resample(Src, true, roi); + // END-imagebufalgo-resample + Dst.write("resample.exr"); +} + + +void example_fit() +{ + print("example_fit\n"); + // BEGIN-imagebufalgo-fit + // Resize to fit into a max of 640x480, preserving the aspect ratio + ImageBuf Src("grid.exr"); + ROI roi(0, 320, 0, 240, 0, 1, /*chans:*/ 0, Src.nchannels()); + ImageBuf Dst = ImageBufAlgo::fit(Src, {}, roi); + // END-imagebufalgo-fit + Dst.write("fit.tif", TypeUInt8); +} + + +void example_warp() +{ + print("example_warp\n"); + // BEGIN-imagebufalgo-warp + Imath::M33f M( 0.7071068, 0.7071068, 0, + -0.7071068, 0.7071068, 0, + 20, -8.284271, 1); + ImageBuf Src("grid.exr"); + ImageBuf Dst = ImageBufAlgo::warp(Src, M, { { "filtername", "lanczos3" } }); + // END-imagebufalgo-warp + Dst.write("warp.exr"); +} + // Section: Image Arithmetic @@ -269,6 +516,7 @@ void example_circular_shift() void example_make_texture() { + print("example_make_texture\n"); // BEGIN-imagebufalgo-make-texture ImageBuf Input ("grid.exr"); ImageSpec config; @@ -284,9 +532,6 @@ void example_make_texture() } - - - int main(int /*argc*/, char** /*argv*/) { // Each example function needs to get called here, or it won't execute @@ -310,7 +555,21 @@ int main(int /*argc*/, char** /*argv*/) example_text2(); // Section: Image transformation and data movement + example_channels(); + example_channel_append(); + example_copy(); + example_crop(); + example_cut(); + example_paste(); + example_rotate_n(); + example_flip_flop_transpose(); + example_reorient(); example_circular_shift(); + example_rotate(); + example_resize(); + example_resample(); + example_fit(); + example_warp(); // Section: Image Arithmetic diff --git a/testsuite/docs-examples-python/ref/out-arm.txt b/testsuite/docs-examples-python/ref/out-arm.txt new file mode 100644 index 0000000000..39d2584e0e --- /dev/null +++ b/testsuite/docs-examples-python/ref/out-arm.txt @@ -0,0 +1,113 @@ +example1 +example_output_error1 +error: Uninitialized input image +example_output_error2 +error: Uninitialized input image +example_zero +example_fill +example_checker +example_noise1 +example_noise2 +example_point +example_lines +example_box +example_text1 +example_text2 +example_channels +example_channel_append +example_copy +example_crop +example_cut +example_paste +example_rotate_n +example_flip_flop_transpose +example_reorient +example_circular_shift +example_rotate +example_resize +example_resample +example_fit +example_warp +example_make_texture +zero1.exr : 512 x 512, 3 channel, half openexr + SHA-1: 95823C334FCE55968E8D2827CCD1CF77CEE19ABD +zero2.exr : 256 x 256, 4 channel, half openexr + SHA-1: 6A521E1D2A632C26E53B83D2CC4B0EDECFC1E68C +zero3.exr : 256 x 256, 4 channel, half openexr + SHA-1: 1254F2956229777B721576B94A6A944ECB806A37 +zero4.exr : 256 x 256, 4 channel, half openexr + SHA-1: 36EB49C5102703693C078717CE82AE05D4904680 +fill.exr : 640 x 480, 3 channel, half openexr + SHA-1: 1BBCA1D5966D02554C13C1FAEF01F6E6E6169356 +checker.exr : 640 x 480, 3 channel, half openexr + SHA-1: 64508259AE242B593B906C848A2D69C443A3FBFD +noise1.exr : 256 x 256, 3 channel, half openexr + SHA-1: 66FF64DDAFDDE290031C20FAA208A193908EE9D4 +noise2.exr : 256 x 256, 3 channel, half openexr + SHA-1: 06011F9D59106096F4742A3DAB458D506A08E34C +noise3.exr : 512 x 384, 3 channel, half openexr + SHA-1: 95EDBCA9953281CE63A3E18C7C04BCCB07CB4C8A +noise4.exr : 512 x 384, 3 channel, half openexr + SHA-1: 43BC1FDFA1F18635B635A57D71DB08BB347CBD46 +blue-noise.exr : 256 x 256, 4 channel, half openexr + SHA-1: 5A0A51D1AD3F34633B781AFF9B90E59996C31AD0 +point.exr : 640 x 480, 4 channel, half openexr + SHA-1: 56E2BDBE03826F203132BD9E80AF44450307BDCE +lines.exr : 640 x 480, 4 channel, half openexr + SHA-1: 177C4C5C61ACDD54F198A45E52836DE897C4CE96 +box.exr : 640 x 480, 4 channel, half openexr + SHA-1: 984273B0A06E54873E24A732651490117E40410C +text1.exr : 640 x 480, 3 channel, half openexr + SHA-1: 1CF68F9B099A30EFF06850CEFBEDD3C2F861A654 +text2.exr : 640 x 480, 3 channel, half openexr + SHA-1: 00C96AE28FD12752AD1968D3D07EE30F1F218D76 +channels-rgba.exr : 256 x 256, 4 channel, half openexr + SHA-1: C823E3701152B4B3C20DD79EA8A20CF4293F4B71 +channels-rgb.exr : 256 x 256, 3 channel, half openexr + SHA-1: 4074B050432CE7C664CEC4546A46E74F9A310CDC +channels-brga.exr : 256 x 256, 4 channel, half openexr + SHA-1: 04E09E64C61CEA1634D26FB2E6C733875D163671 +channels-alpha.exr : 256 x 256, 1 channel, half openexr + SHA-1: 99C332E70F321F0EA47C0F70AF8B0E3E6524F91F +channel-append.exr : 640 x 480, 5 channel, half openexr + SHA-1: E6A50C80C051F0F587FCB68B515B50E4DC3E9359 +copy.exr : 256 x 256, 4 channel, half openexr + SHA-1: C823E3701152B4B3C20DD79EA8A20CF4293F4B71 +crop.exr : 200 x 100, 4 channel, half openexr + SHA-1: 4DA3918566D087A9D2D9E93B2A7BABE971FE6BBD +cut.exr : 200 x 100, 4 channel, half openexr + SHA-1: 4DA3918566D087A9D2D9E93B2A7BABE971FE6BBD +paste.exr : 256 x 256, 4 channel, half openexr + SHA-1: 67A4C36DEAED98A5A8ABA5F0E0EDE697345DC22A +rotate-90.exr : 256 x 256, 4 channel, half openexr + SHA-1: AFFAEA876E8E7760226B017B0A89A3549B7A5895 +rotate-180.exr : 256 x 256, 4 channel, half openexr + SHA-1: A5E42C5F18177DA146EC7E4567E4AE3AE2816C3C +rotate-270.exr : 256 x 256, 4 channel, half openexr + SHA-1: 46C803894186457376A0C590768C9DB4877737BB +flip.exr : 256 x 256, 4 channel, half openexr + SHA-1: A9EB9A8762BCD8DD161C00B01E2DF39E5C91B0D4 +flop.exr : 256 x 256, 4 channel, half openexr + SHA-1: 7C10717DB4F2E21F0B4F6D5404C660CA8B504F5E +rotate-45.tif : 256 x 256, 4 channel, uint8 tiff + SHA-1: E2E41264B7BD250C3AACF9F6161A0FA86B22FA57 +resize.tif : 320 x 240, 4 channel, uint8 tiff + SHA-1: 6FD1A7A97729CD6D51A22ADE0709CC4DFDC3C826 +resample.exr : 320 x 240, 4 channel, half openexr + SHA-1: 16FC7DCFE01DC312593B00B9F90D71BAF3D52450 +fit.tif : 240 x 240, 4 channel, uint8 tiff + SHA-1: 5474A93DED5F9F44E561B70A53F509677961AB34 +warp.exr : 256 x 256, 4 channel, half openexr + SHA-1: 7EA7EB6798E051B5F4EB3722498371E55869BC91 +transpose.exr : 256 x 256, 4 channel, half openexr + SHA-1: FAD57FB60460383D3D2D24B346F35A44846CCC39 +reorient.exr : 256 x 256, 4 channel, half openexr + SHA-1: 46C803894186457376A0C590768C9DB4877737BB +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 "../docs-examples-cpp/ref/simple.tif" +PASS +Comparing "scanlines.tif" and "../docs-examples-cpp/ref/scanlines.tif" +PASS diff --git a/testsuite/docs-examples-python/ref/out.txt b/testsuite/docs-examples-python/ref/out.txt index 7c7b8c2d38..b45d96794c 100644 --- a/testsuite/docs-examples-python/ref/out.txt +++ b/testsuite/docs-examples-python/ref/out.txt @@ -1,42 +1,113 @@ +example1 +example_output_error1 error: Uninitialized input image +example_output_error2 error: Uninitialized input image -zero1.exr : 512 x 512, 3 channel, float openexr - SHA-1: 1E5F8DEF40BB0CB0F7156B9C2BAB9EFB49CFB699 +example_zero +example_fill +example_checker +example_noise1 +example_noise2 +example_point +example_lines +example_box +example_text1 +example_text2 +example_channels +example_channel_append +example_copy +example_crop +example_cut +example_paste +example_rotate_n +example_flip_flop_transpose +example_reorient +example_circular_shift +example_rotate +example_resize +example_resample +example_fit +example_warp +example_make_texture +zero1.exr : 512 x 512, 3 channel, half openexr + SHA-1: 95823C334FCE55968E8D2827CCD1CF77CEE19ABD zero2.exr : 256 x 256, 4 channel, half openexr SHA-1: 6A521E1D2A632C26E53B83D2CC4B0EDECFC1E68C zero3.exr : 256 x 256, 4 channel, half openexr SHA-1: 1254F2956229777B721576B94A6A944ECB806A37 zero4.exr : 256 x 256, 4 channel, half openexr SHA-1: 36EB49C5102703693C078717CE82AE05D4904680 -fill.exr : 640 x 480, 3 channel, float openexr - SHA-1: D517EA07CB6DB931AE4BF6D9E9957EEF9228734E -checker.exr : 640 x 480, 3 channel, float openexr - SHA-1: 87A4424581AAFCE31E6D1134E5025B620B48BBB3 -noise1.exr : 256 x 256, 3 channel, float openexr - SHA-1: 9E9278C8F5460068363D36DBD395FA59CA5986DC -noise2.exr : 256 x 256, 3 channel, float openexr - SHA-1: 0A75E8EF38846D8DC5D8BA997EB54F7A36058288 +fill.exr : 640 x 480, 3 channel, half openexr + SHA-1: 1BBCA1D5966D02554C13C1FAEF01F6E6E6169356 +checker.exr : 640 x 480, 3 channel, half openexr + SHA-1: 64508259AE242B593B906C848A2D69C443A3FBFD +noise1.exr : 256 x 256, 3 channel, half openexr + SHA-1: 66FF64DDAFDDE290031C20FAA208A193908EE9D4 +noise2.exr : 256 x 256, 3 channel, half openexr + SHA-1: 06011F9D59106096F4742A3DAB458D506A08E34C noise3.exr : 512 x 384, 3 channel, half openexr SHA-1: 95EDBCA9953281CE63A3E18C7C04BCCB07CB4C8A noise4.exr : 512 x 384, 3 channel, half openexr SHA-1: 43BC1FDFA1F18635B635A57D71DB08BB347CBD46 -blue-noise.exr : 256 x 256, 4 channel, float openexr - SHA-1: 36F448FE29C9DE6CFA65FC0BFCF4178DC66581C4 -point.exr : 640 x 480, 4 channel, float openexr - SHA-1: A2AC7CC98AB44798EEEA76C253DE44F6E49FFB8D -lines.exr : 640 x 480, 4 channel, float openexr - SHA-1: 69C0317F92256FD30415D1FE12419DC1C514D818 -box.exr : 640 x 480, 4 channel, float openexr - SHA-1: 6CBE5E98B145C5975CB930A91BAEE981C30E6B32 -text1.exr : 640 x 480, 3 channel, float openexr - SHA-1: 014ECFC5EBF07F77DF24A592F43BC7CB101534AE -text2.exr : 640 x 480, 3 channel, float openexr - SHA-1: 53359E96A286F909A89ACC99A67A9ED3BADC4A7A +blue-noise.exr : 256 x 256, 4 channel, half openexr + SHA-1: 5A0A51D1AD3F34633B781AFF9B90E59996C31AD0 +point.exr : 640 x 480, 4 channel, half openexr + SHA-1: 56E2BDBE03826F203132BD9E80AF44450307BDCE +lines.exr : 640 x 480, 4 channel, half openexr + SHA-1: 177C4C5C61ACDD54F198A45E52836DE897C4CE96 +box.exr : 640 x 480, 4 channel, half openexr + SHA-1: 984273B0A06E54873E24A732651490117E40410C +text1.exr : 640 x 480, 3 channel, half openexr + SHA-1: 1CF68F9B099A30EFF06850CEFBEDD3C2F861A654 +text2.exr : 640 x 480, 3 channel, half openexr + SHA-1: 00C96AE28FD12752AD1968D3D07EE30F1F218D76 +channels-rgba.exr : 256 x 256, 4 channel, half openexr + SHA-1: C823E3701152B4B3C20DD79EA8A20CF4293F4B71 +channels-rgb.exr : 256 x 256, 3 channel, half openexr + SHA-1: 4074B050432CE7C664CEC4546A46E74F9A310CDC +channels-brga.exr : 256 x 256, 4 channel, half openexr + SHA-1: 04E09E64C61CEA1634D26FB2E6C733875D163671 +channels-alpha.exr : 256 x 256, 1 channel, half openexr + SHA-1: 99C332E70F321F0EA47C0F70AF8B0E3E6524F91F +channel-append.exr : 640 x 480, 5 channel, half openexr + SHA-1: E6A50C80C051F0F587FCB68B515B50E4DC3E9359 +copy.exr : 256 x 256, 4 channel, half openexr + SHA-1: C823E3701152B4B3C20DD79EA8A20CF4293F4B71 +crop.exr : 200 x 100, 4 channel, half openexr + SHA-1: 4DA3918566D087A9D2D9E93B2A7BABE971FE6BBD +cut.exr : 200 x 100, 4 channel, half openexr + SHA-1: 4DA3918566D087A9D2D9E93B2A7BABE971FE6BBD +paste.exr : 256 x 256, 4 channel, half openexr + SHA-1: 67A4C36DEAED98A5A8ABA5F0E0EDE697345DC22A +rotate-90.exr : 256 x 256, 4 channel, half openexr + SHA-1: AFFAEA876E8E7760226B017B0A89A3549B7A5895 +rotate-180.exr : 256 x 256, 4 channel, half openexr + SHA-1: A5E42C5F18177DA146EC7E4567E4AE3AE2816C3C +rotate-270.exr : 256 x 256, 4 channel, half openexr + SHA-1: 46C803894186457376A0C590768C9DB4877737BB +flip.exr : 256 x 256, 4 channel, half openexr + SHA-1: A9EB9A8762BCD8DD161C00B01E2DF39E5C91B0D4 +flop.exr : 256 x 256, 4 channel, half openexr + SHA-1: 7C10717DB4F2E21F0B4F6D5404C660CA8B504F5E +rotate-45.tif : 256 x 256, 4 channel, uint8 tiff + SHA-1: 2D4AECFD398F9E0AA0051888D0EE7CDC1E438A5A +resize.tif : 320 x 240, 4 channel, uint8 tiff + SHA-1: 6FD1A7A97729CD6D51A22ADE0709CC4DFDC3C826 +resample.exr : 320 x 240, 4 channel, half openexr + SHA-1: 5C0CC0A293FCD30B2AE44A0BED7D27DB9B8C8E50 +fit.tif : 240 x 240, 4 channel, uint8 tiff + SHA-1: AC77B6A4BFF3E42EB207CFDADEE6BCED4653D2B4 +warp.exr : 256 x 256, 4 channel, half openexr + SHA-1: EEB460766F07B47C647D630B568F25FFEEBF5A62 +transpose.exr : 256 x 256, 4 channel, half openexr + SHA-1: FAD57FB60460383D3D2D24B346F35A44846CCC39 +reorient.exr : 256 x 256, 4 channel, half openexr + SHA-1: 46C803894186457376A0C590768C9DB4877737BB 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" +Comparing "simple.tif" and "../docs-examples-cpp/ref/simple.tif" PASS -Comparing "scanlines.tif" and "ref/scanlines.tif" +Comparing "scanlines.tif" and "../docs-examples-cpp/ref/scanlines.tif" PASS diff --git a/testsuite/docs-examples-python/ref/scanlines.tif b/testsuite/docs-examples-python/ref/scanlines.tif deleted file mode 100644 index a1d410fbec..0000000000 Binary files a/testsuite/docs-examples-python/ref/scanlines.tif and /dev/null differ diff --git a/testsuite/docs-examples-python/ref/simple.tif b/testsuite/docs-examples-python/ref/simple.tif deleted file mode 100644 index a1d410fbec..0000000000 Binary files a/testsuite/docs-examples-python/ref/simple.tif and /dev/null differ diff --git a/testsuite/docs-examples-python/run.py b/testsuite/docs-examples-python/run.py index fbfdd75926..2595b3f9a6 100755 --- a/testsuite/docs-examples-python/run.py +++ b/testsuite/docs-examples-python/run.py @@ -6,6 +6,10 @@ redirect = " >> out.txt 2>&1 " +# To avoid duplicating example images between the C++ and Python tests, +# they all live with the C++ ones. +refdirlist += [ "../docs-examples-cpp/ref" ] + # Prep: command += run_app("cmake -E copy " + test_source_dir + "/../common/grid-small.exr grid.exr") command += run_app("cmake -E copy " + test_source_dir + "/../common/tahoe-small.tif tahoe.tif") @@ -16,7 +20,10 @@ command += pythonbin + " src/docs-examples-" + chapter + ".py " + redirect + " ;" # hashes merely check that the images don't change, but saves us the space -# of checking in a full copy of the image if it's not needed. +# of checking in a full copy of the image if it's not needed. This is not +# suitable if the image may change slightly from platform to platform or +# with different versions of dependencies, for that we should use the +# full reference image comparison with appropriate thresholds. hashes = [ # Outputs from the ImageBufAlgo chapter: "zero1.exr", @@ -35,6 +42,27 @@ "box.exr", "text1.exr", "text2.exr", + "channels-rgba.exr", + "channels-rgb.exr", + "channels-brga.exr", + "channels-alpha.exr", + "channel-append.exr", + "copy.exr", + "crop.exr", + "cut.exr", + "paste.exr", + "rotate-90.exr", + "rotate-180.exr", + "rotate-270.exr", + "flip.exr", + "flop.exr", + "rotate-45.tif", + "resize.tif", + "resample.exr", + "fit.tif", + "warp.exr", + "transpose.exr", + "reorient.exr", "cshift.exr", "texture.exr" ] @@ -48,10 +76,13 @@ "simple.tif", "scanlines.tif", # Outputs from the ImageInput chapter: + # Outputs from the ImageBuf chapter: + + # Outputs from the ImageBufAlgo chapter: + # ... etc ... other chapters ... # Last, we have the out.txt that captures console output of the test # programs. "out.txt" ] - diff --git a/testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py b/testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py index 25077fddf5..dda5d32558 100644 --- a/testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py +++ b/testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py @@ -19,7 +19,9 @@ from OpenImageIO import * import numpy as np -def example1() : + +def example1(): + print("example1") # # Example code fragment from the docs goes here. # @@ -39,6 +41,7 @@ def example1() : # Section: ImageBufAlgo common principles def example_output_error1(): + print("example_output_error1") fg = ImageBuf() bg = ImageBuf() @@ -51,6 +54,7 @@ def example_output_error1(): def example_output_error2(): + print("example_output_error2") fg = ImageBuf() bg = ImageBuf() @@ -66,6 +70,7 @@ def example_output_error2(): # Section: Pattern Generation def example_zero(): + print("example_zero") A = ImageBuf("grid.exr") B = ImageBuf("grid.exr") C = ImageBuf("grid.exr") @@ -87,13 +92,14 @@ def example_zero(): ImageBufAlgo.zero(C, ROI(0, 100, 0, 100)) # END-imagebufalgo-zero - zero.write("zero1.exr") - A.write("zero2.exr") - B.write("zero3.exr") - C.write("zero4.exr") + zero.write("zero1.exr", "half") + A.write("zero2.exr", "half") + B.write("zero3.exr", "half") + C.write("zero4.exr", "half") def example_fill(): + print("example_fill") # BEGIN-imagebufalgo-fill # Create a new 640x480 RGB image, with a top-to-bottom gradient # from red to pink @@ -106,10 +112,11 @@ def example_fill(): ImageBufAlgo.fill(A, red, ROI(50, 100, 75, 175)) # END-imagebufalgo-fill - A.write("fill.exr") + A.write("fill.exr", "half") def example_checker(): + print("example_checker") # BEGIN-imagebufalgo-checker # Create a new 640x480 RGB image, fill it with a two-toned gray # checkerboard, the checkers being 64x64 pixels each. @@ -120,10 +127,11 @@ def example_checker(): roi=ROI(0, 640, 0, 480, 0, 1, 0, 3)) # END-imagebufalgo-checker - A.write("checker.exr") + A.write("checker.exr", "half") def example_noise1(): + print("example_noise1") # BEGIN-imagebufalgo-noise1 # Create a new 256x256 field of grayscale white noise on [0,1) A = ImageBufAlgo.noise("uniform", A=0.0, B=1.0, mono=True, seed=1, @@ -142,31 +150,34 @@ def example_noise1(): ImageBufAlgo.noise(D, "salt", A=0.0, B=0.01, mono=True, seed=1) # END-imagebufalgo-noise1 - A.write("noise1.exr") - B.write("noise2.exr") - C.write("noise3.exr") - D.write("noise4.exr") + A.write("noise1.exr", "half") + B.write("noise2.exr", "half") + C.write("noise3.exr", "half") + D.write("noise4.exr", "half") def example_noise2(): + print("example_noise2") # BEGIN-imagebufalgo-noise2 A = ImageBufAlgo.bluenoise_image() # END-imagebufalgo-noise2 - A.write("blue-noise.exr") + A.write("blue-noise.exr", "half") def example_point(): + print("example_point") # BEGIN-imagebufalgo-point A = ImageBuf(ImageSpec(640, 480, 4, "float")) red = (1, 0, 0, 1) ImageBufAlgo.render_point(A, 50, 100, red) # END-imagebufalgo-point - A.write("point.exr") + A.write("point.exr", "half") def example_lines(): + print("example_lines") # BEGIN-imagebufalgo-lines A = ImageBuf(ImageSpec(640, 480, 4, "float")) red = (1, 0, 0, 1) @@ -174,10 +185,11 @@ def example_lines(): ImageBufAlgo.render_line(A, 250, 20, 100, 190, red, True) # END-imagebufalgo-lines - A.write("lines.exr") + A.write("lines.exr", "half") def example_box(): + print("example_box") # BEGIN-imagebufalgo-box A = ImageBuf(ImageSpec(640, 480, 4, "float")) cyan = (0, 1, 1, 1) @@ -186,10 +198,11 @@ def example_box(): ImageBufAlgo.render_box(A, 100, 50, 180, 140, yellow_transparent, fill=True) # END-imagebufalgo-box - A.write("box.exr") + A.write("box.exr", "half") def example_text1(): + print("example_text1") ImgA = ImageBufAlgo.zero(ROI(0, 640, 0, 480, 0, 1, 0, 3)) ImgB = ImageBufAlgo.zero(ROI(0, 640, 0, 480, 0, 1, 0, 3)) @@ -205,11 +218,12 @@ def example_text1(): alignx="center", aligny="center") # END-imagebufalgo-text1 - ImgA.write("text1.exr") - ImgB.write("text2.exr") + ImgA.write("text1.exr", "half") + ImgB.write("text2.exr", "half") -def example_test2(): +def example_text2(): + print("example_text2") # BEGIN-imagebufalgo-text2 # Render text centered in the image, using text_size to find out # the size we will need and adjusting the coordinates. @@ -225,12 +239,200 @@ def example_test2(): # Section: Image transformation and data movement -def example_circular_shift() : +def example_channels(): + print("example_channels") + RGBA = ImageBuf("grid.exr") + BRGA = ImageBuf() + + # BEGIN-imagebufalgo-channels + # Copy the first 3 channels of an RGBA, drop the alpha + RGB = ImageBufAlgo.channels(RGBA, (0, 1, 2)) + + # Copy just the alpha channel, making a 1-channel image + Alpha = ImageBufAlgo.channels(RGBA, ("A",)) + + # Swap the R and B channels + success = ImageBufAlgo.channels(BRGA, RGBA, + channelorder=(2, 1, 0, 3), + newchannelnames=("R", "G", "B", "A")) + + # Add an alpha channel with value 1.0 everywhere to an RGB image, + # keep the other channels with their old ordering, values, and + # names. + RGBA = ImageBufAlgo.channels(RGB, + channelorder=(0, 1, 2, 1.0), + newchannelnames=("", "", "", "A")) + # END-imagebufalgo-channels + + RGBA.write("channels-rgba.exr", "half") + RGB.write("channels-rgb.exr", "half") + Alpha.write("channels-alpha.exr", "half") + BRGA.write("channels-brga.exr", "half") + + +def example_channel_append(): + print("example_channel_append") + Z = ImageBuf(ImageSpec(640, 480, 1, "float")) + + # BEGIN-imagebufalgo-channel-append + RGBA = ImageBuf("grid.exr") + RGBAZ = ImageBufAlgo.channel_append(RGBA, Z) + # END-imagebufalgo-channel-append + + RGBAZ.write("channel-append.exr", "half") + + +def example_copy(): + print("example_copy") + # BEGIN-imagebufalgo-copy + # Set B to be a copy of A, but converted to float + A = ImageBuf("grid.exr") + B = ImageBufAlgo.copy(A, convert="float") + # END-imagebufalgo-copy + + B.write("copy.exr", "half") + + +def example_crop(): + print("example_crop") + # BEGIN-imagebufalgo-crop + # Set B to be a 200x100 region of A starting at (50,50), trimming + # the exterior away but leaving that region in its original position. + A = ImageBuf("grid.exr") + B = ImageBufAlgo.crop(A, ROI(50, 250, 50, 150)) + # END-imagebufalgo-crop + + B.write("crop.exr", "half") + + +def example_cut(): + print("example_cut") + # BEGIN-imagebufalgo-cut + # Set B to be a 200x100 region of A starting at (50,50), but + # moved to the upper left corner so its new origin is (0,0). + A = ImageBuf("grid.exr") + B = ImageBufAlgo.cut(A, ROI(50, 250, 50, 150)) + # END-imagebufalgo-cut + + B.write("cut.exr", "half") + + +def example_paste(): + print("example_paste") + # BEGIN-imagebufalgo-paste + # Paste Fg on top of Bg, offset by (100,100) + Bg = ImageBuf("grid.exr") + Fg = ImageBuf("tahoe.tif") + ImageBufAlgo.paste(Bg, 100, 100, 0, 0, Fg) + # END-imagebufalgo-paste + + Bg.write("paste.exr", "half") + + +def example_rotate_n(): + print("example_rotate_n") + # BEGIN-imagebufalgo-rotate-n + A = ImageBuf("grid.exr") + R90 = ImageBufAlgo.rotate90(A) + R180 = ImageBufAlgo.rotate180(A) + R270 = ImageBufAlgo.rotate270(A) + # END-imagebufalgo-rotate-n + + R90.write("rotate-90.exr", "half") + R180.write("rotate-180.exr", "half") + R270.write("rotate-270.exr", "half") + + +def example_flip_flop_transpose(): + print("example_flip_flop_transpose") + # BEGIN-imagebufalgo-flip-flop-transpose + A = ImageBuf("grid.exr") + B1 = ImageBufAlgo.flip(A) + B2 = ImageBufAlgo.flop(A) + B3 = ImageBufAlgo.transpose(A) + # END-imagebufalgo-flip-flop-transpose + + B1.write("flip.exr", "half") + B2.write("flop.exr", "half") + B3.write("transpose.exr", "half") + + +def example_reorient(): + print("example_reorient") + tmp = ImageBuf("grid.exr") + tmp.specmod().attribute("Orientation", 8) + tmp.write("grid-vertical.exr", "half") + + # BEGIN-imagebufalgo-reorient + A = ImageBuf("grid-vertical.exr") + A = ImageBufAlgo.reorient(A) + # END-imagebufalgo-reorient + + A.write("reorient.exr", "half") + + +def example_circular_shift(): + print("example_circular_shift") # BEGIN-imagebufalgo-cshift A = ImageBuf("grid.exr") B = ImageBufAlgo.circular_shift(A, 70, 30) # END-imagebufalgo-cshift - B.write("cshift.exr") + B.write("cshift.exr", "half") + + +def example_rotate(): + print("example_rotate") + # BEGIN-imagebufalgo-rotate-angle + Src = ImageBuf("grid.exr") + Dst = ImageBufAlgo.rotate(Src, 45.0) + # END-imagebufalgo-rotate-angle + Dst.write("rotate-45.tif", "uint8") + + +def example_resize(): + print("example_resize") + # BEGIN-imagebufalgo-resize + # Resize the image to 640x480, using the default filter + Src = ImageBuf("grid.exr") + roi = ROI(0, 320, 0, 240, 0, 1, 0, Src.nchannels) + Dst = ImageBufAlgo.resize(Src, roi=roi) + # END-imagebufalgo-resize + Dst.write("resize.tif", "uint8") + + +def example_resample(): + print("example_resample") + + # BEGIN-imagebufalgo-resample + # Resample quickly to 320x240, with default interpolation + Src = ImageBuf("grid.exr") + roi = ROI(0, 320, 0, 240, 0, 1, 0, Src.nchannels) + Dst = ImageBufAlgo.resample(Src, roi=roi) + # END-imagebufalgo-resample + Dst.write("resample.exr", "half") + + +def example_fit(): + print("example_fit") + # BEGIN-imagebufalgo-fit + # Resize to fit into a max of 640x480, preserving the aspect ratio + Src = ImageBuf("grid.exr") + roi = ROI(0, 320, 0, 240, 0, 1, 0, Src.nchannels) + Dst = ImageBufAlgo.fit(Src, "", roi=roi) + # END-imagebufalgo-fit + Dst.write("fit.tif", "uint8") + + +def example_warp(): + print("example_warp") + # BEGIN-imagebufalgo-warp + M = (0.7071068, 0.7071068, 0, + -0.7071068, 0.7071068, 0, + 20, -8.284271, 1) + Src = ImageBuf("grid.exr") + Dst = ImageBufAlgo.warp(Src, M, filtername="lanczos3") + # END-imagebufalgo-warp + Dst.write("warp.exr", "half") # Section: Image Arithmetic @@ -254,6 +456,7 @@ def example_circular_shift() : # Section: Import / export def example_make_texture(): + print("example_make_texture") # BEGIN-imagebufalgo-make-texture Input = ImageBuf("grid.exr") config = ImageSpec() @@ -269,10 +472,6 @@ def example_make_texture(): # END-imagebufalgo-make-texture - - - - if __name__ == '__main__': # Each example function needs to get called here, or it won't execute # as part of the test. @@ -292,10 +491,24 @@ def example_make_texture(): example_lines() example_box() example_text1() - example_test2() + example_text2() # Section: Image transformation and data movement + example_channels() + example_channel_append() + example_copy() + example_crop() + example_cut() + example_paste() + example_rotate_n() + example_flip_flop_transpose() + example_reorient() example_circular_shift() + example_rotate() + example_resize() + example_resample() + example_fit() + example_warp() # Section: Image Arithmetic