Yes, piece of cake. I'm going to assume that you're using ImageInput. (If you are using an ImageBuf-based pipeline, let me know.) You probably have an open sequence that looks something like this:
auto inp = ImageInput::open("foo.tif"); ImageSpec spec = inp->spec(0, 0); Let's say you have allocated a 4-channel buffer, float *buf = new float [yres * xres * 4]; and you want to read the first 3 channels of the image into the right positions of this buffer, but leave the 4th channel of each pixel's slot in the buffer unaltered. All of the ImageInput::read_* functions take optional stride parameters. So you just specify the right strides: inp->read_image(/*subimage*/ 0, /*miplevel*/ 0, /*chbegin*/ 0, /*chend*/ 3, OIIO::TypeFloat, buf, /*xstride*/ 4 * sizeof(float)); this will leave the [3] positions in each pixel untouched. You can fill them in with 1.0 or whatever on your own, maybe like for (int i = 0; i < xres * yres; ++i) buf[i*4 + 3] = 1.0f; > On Sep 7, 2022, at 3:15 AM, Bartłomiej Styczeń <bart.styc...@cine.dev> wrote: > > Hi, > > OIIO is an amazing piece of software, saving me an enormous amount of time > and headache. In my case it unfortunately has to be interfaced with QT's > QImage container, which is quite limited in what image formats it > understands. The one I'm lacking is a 3-channel float image. Floats are > crucial for the use case. > > I need to be able to read all kinds of images into an uniform buffer - RGBA > float. > For example, if an image only has 3 channels, I'd fill the A values with > 1.0f. So far I am doing this by just copying the RGB buffer into a RGBA one > pixel by pixel and adding the alpha values. This of course is absolutely > wasteful and slow, it would be perfect if I could somehow instruct OCIO to > read any images into an RGBA format buffer. > > Trying to simply set the ImageSpec to the desired channel number and ordering > results in images being read improperly. > > Is there a straightforward way to do this? Any help is greatly appreciated. > > Best regards, > > Bart Styczen, > CineDev > > _______________________________________________ > Oiio-dev mailing list > Oiio-dev@lists.openimageio.org > http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org -- Larry Gritz l...@larrygritz.com
_______________________________________________ Oiio-dev mailing list Oiio-dev@lists.openimageio.org http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org