diff --git a/src/doc/imagebufalgo.rst b/src/doc/imagebufalgo.rst index 8eb7d6a5ee..a2d27d364e 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, "", 0, 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 tahoe.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, "", 0, true, 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, "", 0, True, 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 tahoe.exr --fit 640x480 -o out.exr | @@ -1083,26 +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"); - ImageBuf Dst = ImageBufAlgo::warp (dst, src, M, "lanczos3"); - .. 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 (dst, src, M, "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 tahoe.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/ref/out.txt b/testsuite/docs-examples-cpp/ref/out.txt index 7c7b8c2d38..e85770e361 100644 --- a/testsuite/docs-examples-cpp/ref/out.txt +++ b/testsuite/docs-examples-cpp/ref/out.txt @@ -32,6 +32,38 @@ text1.exr : 640 x 480, 3 channel, float openexr SHA-1: 014ECFC5EBF07F77DF24A592F43BC7CB101534AE text2.exr : 640 x 480, 3 channel, float openexr SHA-1: 53359E96A286F909A89ACC99A67A9ED3BADC4A7A +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, float openexr + SHA-1: F7ECA3179B1ABD2C45141DCEF0C17ECFE7E5A91F +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 +transpose.exr : 256 x 256, 4 channel, float openexr + SHA-1: 2E0E9151C138EA26A331AA4C1FB39DA70815D4F7 +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..8ea8692ebb 100755 --- a/testsuite/docs-examples-cpp/run.py +++ b/testsuite/docs-examples-cpp/run.py @@ -43,6 +43,22 @@ "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", + "transpose.exr", + "reorient.exr", "cshift.exr", "texture.exr" ] diff --git a/testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp b/testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp index f75b5987ed..0d3ba6d5b1 100644 --- a/testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp +++ b/testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // https://github.com/AcademySoftwareFoundation/OpenImageIO +#include /////////////////////////////////////////////////////////////////////////// // This file contains code examples from the ImageBufAlgo chapter of the @@ -235,6 +236,138 @@ void example_text2() // Section: Image transformation and data movement +void example_channels() +{ + 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() +{ + 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"); +} + +void example_copy() +{ + // 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() +{ + // 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() +{ + // 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() +{ + // 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() +{ + // 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() +{ + // 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() +{ + 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() { // BEGIN-imagebufalgo-cshift @@ -244,6 +377,54 @@ void example_circular_shift() // END-imagebufalgo-cshift } +void example_rotate() +{ + // BEGIN-imagebufalgo-rotate-angle + ImageBuf Src ("grid.exr"); + ImageBuf Dst = ImageBufAlgo::rotate (Src, 45.0); + // END-imagebufalgo-rotate-angle +} + +void example_resize() +{ + // BEGIN-imagebufalgo-resize + // Resize the image to 640x480, using the default filter + ImageBuf Src ("grid.exr"); + ROI roi (0, 640, 0, 480, 0, 1, /*chans:*/ 0, Src.nchannels()); + ImageBuf Dst = ImageBufAlgo::resize (Src, "", 0, roi); + // END-imagebufalgo-resize +} + +void example_resample() +{ + // 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 +} + +void example_fit() +{ + // BEGIN-imagebufalgo-fit + // Resize to fit into a max of 640x480, preserving the aspect ratio + ImageBuf Src ("grid.exr"); + ROI roi (0, 640, 0, 480, 0, 1, /*chans:*/ 0, Src.nchannels()); + ImageBuf Dst = ImageBufAlgo::fit (Src, "", 0, true, roi); + // END-imagebufalgo-fit +} + +void example_warp() +{ + // 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, "lanczos3"); + // END-imagebufalgo-warp +} // Section: Image Arithmetic @@ -284,9 +465,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 +488,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.txt b/testsuite/docs-examples-python/ref/out.txt index 7c7b8c2d38..e85770e361 100644 --- a/testsuite/docs-examples-python/ref/out.txt +++ b/testsuite/docs-examples-python/ref/out.txt @@ -32,6 +32,38 @@ text1.exr : 640 x 480, 3 channel, float openexr SHA-1: 014ECFC5EBF07F77DF24A592F43BC7CB101534AE text2.exr : 640 x 480, 3 channel, float openexr SHA-1: 53359E96A286F909A89ACC99A67A9ED3BADC4A7A +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, float openexr + SHA-1: F7ECA3179B1ABD2C45141DCEF0C17ECFE7E5A91F +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 +transpose.exr : 256 x 256, 4 channel, float openexr + SHA-1: 2E0E9151C138EA26A331AA4C1FB39DA70815D4F7 +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-python/run.py b/testsuite/docs-examples-python/run.py index 4a312764cc..d08ee3e180 100755 --- a/testsuite/docs-examples-python/run.py +++ b/testsuite/docs-examples-python/run.py @@ -34,6 +34,22 @@ "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", + "transpose.exr", + "reorient.exr", "cshift.exr", "texture.exr" ] diff --git a/testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py b/testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py index aba6ea753c..c9cc6dd8cc 100644 --- a/testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py +++ b/testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py @@ -17,11 +17,12 @@ # BEGIN-imagebufalgo-example1 -import OpenImageIO as oiio +import OpenImageIO from OpenImageIO import * import numpy as np -def example1() : + +def example1(): # # Example code fragment from the docs goes here. # @@ -211,7 +212,7 @@ def example_text1(): ImgB.write("text2.exr") -def example_test2(): +def 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. @@ -227,7 +228,130 @@ def example_test2(): # Section: Image transformation and data movement -def example_circular_shift() : +def 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") + RGB.write("channels-rgb.exr") + Alpha.write("channels-alpha.exr") + BRGA.write("channels-brga.exr") + + +def 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") + + +def 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") + + +def 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") + + +def 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") + + +def 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") + + +def 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") + R180.write("rotate-180.exr") + R270.write("rotate-270.exr") + + +def 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") + B2.write("flop.exr") + B3.write("transpose.exr") + + +def example_reorient(): + tmp = ImageBuf("grid.exr") + tmp.specmod().attribute("Orientation", 8) + tmp.write("grid-vertical.exr") + + # BEGIN-imagebufalgo-reorient + A = ImageBuf("grid-vertical.exr") + A = ImageBufAlgo.reorient(A) + # END-imagebufalgo-reorient + + A.write("reorient.exr") + + +def example_circular_shift(): # BEGIN-imagebufalgo-cshift A = ImageBuf("grid.exr") B = ImageBufAlgo.circular_shift(A, 70, 30) @@ -235,6 +359,50 @@ def example_circular_shift() : B.write("cshift.exr") +def example_rotate(): + # BEGIN-imagebufalgo-rotate-angle + Src = ImageBuf("grid.exr") + Dst = ImageBufAlgo.rotate(Src, 45.0) + # END-imagebufalgo-rotate-angle + + +def example_resize(): + # BEGIN-imagebufalgo-resize + # Resize the image to 640x480, using the default filter + Src = ImageBuf("grid.exr") + roi = ROI(0, 640, 0, 480, 0, 1, 0, Src.nchannels) + Dst = ImageBufAlgo.resize(Src, roi=roi) + # END-imagebufalgo-resize + + +def 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 + + +def example_fit(): + # BEGIN-imagebufalgo-fit + # Resize to fit into a max of 640x480, preserving the aspect ratio + Src = ImageBuf("grid.exr") + roi = ROI(0, 640, 0, 480, 0, 1, 0, Src.nchannels) + Dst = ImageBufAlgo.fit(Src, "", 0, True, roi) + # END-imagebufalgo-fit + + +def 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, "lanczos3") + # END-imagebufalgo-warp + + # Section: Image Arithmetic @@ -271,10 +439,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. @@ -294,10 +458,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