Hello all,

I am struggling to read images into a buffer that organises channels
in a planar memory layout (i.e. all red scanlines before all blue
before all green etc...). It appeared to me like specifying the
strides for `ImageInput::read_image` would be the thing to do here.
However, upon playing with it for a while I realised that it seems
to be impossible to specify the stride for the channel values within
a pixel.

For example the following results in the red channel correctly set
but all the other channel values set to 0 (untouched from the
default initialisation I suppose):

```
std::vector<T> img_data(spec.width * spec.height * spec.nchannels);

auto column_stride = sizeof(img_data[0]);
auto row_stride = column_stride * spec.width;
// initially I assumed that the z-stride would be the one to use
// to rearrange the channels - now I realise that this is only
// relevant for volumetric images
auto slice_stride = row_stride * spec.height;

// helpers::type_to_typedesc<T> returns the OIIO typedesc
// corresponding to T
file->read_image(helpers::type_to_typedesc<T>(),
    img_data.data(),
    column_stride,
    row_stride,
    slice_stride
    );
```

I suspect that in this case green and blue values are written but
then immediately overwritten by the red channel in the next two
pixels.

I could of course just accept the interleaved memory layout and then
copy the pixels into the right place afterwards.

Another way might be writing a clever adapter that "looks" like an
array to OIIO but actually just re-routes the writes to a real buffer
with modified positions. However, this would strongly couple my code
to implementation details of `read_image`.

Is there a method to specify a planar memory layout for the target
buffer in order to avoid such workarounds?

Thanks a lot in advance for your help!

With kind regards,
Jan Hettenkofer

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

Reply via email to