OpenImageIO/oiio — pull request #418 by lgritz (2012-08-05 19:04:42+00:00)
Title: Review: Channel manipulation

ImageBufAlgo::channels() provides a general way to copy one ImageBuf to another with arbitrary channel reordering, truncation, or addition/insertion of black channels.

It's exposed through oiiotool as the new "--ch" command, where the argument is a comma-separated list of channel numbers and/or names (you can mix and match).

Here are some examples of how it can be used:

Turn a single channel image into gray RGB:

oiiotool gray.tif --ch 0,0,0 -o rgb.tif

Copy just the color from an RGBA file, truncating the A, yielding RGB only:

oiiotool rgba.tif --ch R,G,B -o rgb.tif

Zero out the red and green channels:

oiiotool rgb.tif --ch -1,-1,B -o justblue.tif

Swap the red and blue channels from an RGBA image:

oiiotool rgba.tif --ch 2,1,0,3 -o bgra.tif

Extract just the named channels from a complicted many-channel image:

oiiotool allmyaovs.exr --ch spec.R,spec.G,spec.B -o spec.exr

Along the way I also fixed a bug I recently introduced when I refactored IB::get_pixel_channels that messed up iv single channel viewing.