There is not a read_image variant that lets you read a single channel.  
However, there are read_scanlines() and read_tiles() variants that accept a 
channel range.  So you'd need to do something like this:

// Assume you've allocated the buffer, of a type described by TypeDesc 
bufferformat,
// and that you've already opened ImageInput *input.
ImageSpec spec = input->spec();
stride_t xstride = bufferformat.size();  // just one channel
stride_t ystride = xstride * spec.width;  // one scanline
bool ok;
if (spec.tile_width /* nonzero means it's a tiled image */) {
    ok = input->read_tiles (spec.x, spec.x+spec.width, spec.y, 
spec.y+spec.height,
                            spec.z, spec.z+spec.depth, mychannel, mychannel+1,
                            bufferformat, buffer, xstride, ystride);
} else {
    ok = input = read_scanlines (spec.y, spec.y+spec.height, spec.z, mychannel, 
mychannel+1,
                                 bufferformat, buffer, xstride, ystride);
}


That's really all read_image is doing underneath, anyway.

Notes:

* I just typed that more or less from the top of my head -- consulting 
imageio.h, but not compiling or testing it. So please excuse any typos.

* This is all assuming a 2D image; for volumes you'd need to add a z loop to 
all this.



On Jul 2, 2013, at 9:01 PM, Mark Davies wrote:

> Hi,
> 
> I was curious if it is possible with OIIO to read a single channel using 
> 'ImageInput::read_image()'? The X stride is exposed, however I would also 
> like to add a pixel-relative offset (eg. '+1' would read just the green 
> channel). Thanks for any suggestions.
> 
> Regards,
> Mark
> 
> _______________________________________________
> Oiio-dev mailing list
> [email protected]
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

--
Larry Gritz
[email protected]


_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to