Oh, I see. If you just want the raw pixel data, you can declare a generic pointer for your buffer and essentially allocate untyped bytes. And the ImageSpec class has lots of utilities for you to figure out how many bytes each pixel is. So, something like:
size_t size = roi.npixels() * src.spec().nchannels * src.spec().pixel_bytes(); void* out_pix = malloc(size); src.get(roi, src.spec().format, out_pix); That just gives you a big byte array. If you want to do something to interpret that data, you will of course need to write your own code to handle every possible data type that you expect to encounter. For example, if (src.spec().format == TypeDesc::UINT8) { uint8_t* data = (uint8_t*)out_pix; // do things for unsigned 8 bit integer pixels... } else if (src.spec().format == TypeDesc::UINT16) { uint16_t* data = (uint16_t*)out_pix; // do things for unsigned 16 bit integer pixels... } else if (src.spec().format == TypeDesc::FLOAT) { float* data = (float*)out_pix; // do things for 32 bit float pixels... } // and so on, for every possible pixel type you might encounter There is one other wrinkle that I'm not sure if it will matter to you, which is this: ImageBuf makes the simplification (or limitation, if you view it this way) that it stores all color channels as the same data type. For most image file formats, all channels are required to be the same type, but a few image file formats allow per-channel data types, and the ImageBuf will promote them all to whatever is the type among them that has the most precision and range. For example, an OpenEXR file that is a mix of 'half' and 'float' channels will appear to be all float when read into an ImageBuf. If you truly need each channel in its original data type, then ImageBuf is not the right interface and you will want to use ImageInput directly, which is capable of returning the raw data even with per-channel data types. -- lg > On Jul 1, 2020, at 11:26 AM, Sven Steinbauer <s...@themill.com> wrote: > > Thanks for the reply. I understand what you are saying, but I want to > preserve the type from the spec whatever it may be. > What I am trying to achieve is to extract a region of an input image, based > on a precalculated ROI. So i have that part working now by hard coding it to > float, but if I wanted to preserve the type from the spec, I would need to > declare the result type as the same type right? > I think I can do this using a method listed in the docs though under the > heading of image buffers and types > > > — > ./Sven > > SVEN STEINBAUER > Senior R&D Engineer > T > +44 20 7287 4041 > <image515289.png> <http://www.themill.com/> > THE MILL 11‑14 WINDMILL STREET, LONDON, W1T 2JG > FOLLOW @MILLCHANNEL | FACEBOOK <http://www.facebook.com/millchannel> > | LINKEDIN <https://www.linkedin.com/company/9328> | > INSTAGRAM <https://www.instagram.com/millchannel> > | > THEMILL.COM <http://www.themill.com/> > > From: Oiio-dev <oiio-dev-boun...@lists.openimageio.org> on behalf of Larry > Gritz <l...@larrygritz.com> > Sent: Wednesday, July 1, 2020 7:13:36 PM > To: OpenImageIO developers <oiio-dev@lists.openimageio.org> > Subject: Re: [Oiio-dev] Getting TypeDesc from variable > > ** CAUTION: This email originated from outside of the organization. Do not > click links or open attachments unless you recognize the sender and know the > content is safe. ** > > I think you are looking at it backwards. > > You don't pass the type of the pixels in the file and magically need to know > what type of buffer to declare and allocate. > > You declare and allocate whatever data type your program wants to work with, > and the middle parameter tells OIIO what type of data you want, and it > translates for you. > > So if you want float values (no matter what's stored in the actual file): > > float *out_pix = new float[w*h*channels]; > src.get(roi, TypeDesc::FLOAT, out_pix); > > But instead, if you wanted 8 bit unsigned int values: > > unsigned char *out_pix = new unsigned char[w*h*channels]; > src.get(roi, TypeDesc::UINT8, out_pix); > > And so on, for any of the types. > > >> On Jul 1, 2020, at 8:46 AM, Sven Steinbauer <s...@themill.com >> <mailto:s...@themill.com>> wrote: >> >> Apologies for the earlier empty email. I accidentally pressed send too early. >> >> What I would like to do is call >> >> >> src.get_pixels(roi, TypeDesc::BASETYPE(spec.format.basetype), out_pix); >> >> However I am not sure how to declare `out_pix` as I cannot get the C type >> for the basetype from a variable due to it being template functions. >> What would be the correct way to declare out_pix from the specification's >> basetype, if that is possible? >> >> >> SVEN STEINBAUER >> Senior R&D Engineer >> T >> +44 20 7287 4041 >> <image930177.png> <http://www.themill.com/> >> THE MILL 11‑14 WINDMILL STREET, LONDON, W1T 2JG >> FOLLOW @MILLCHANNEL | FACEBOOK <http://www.facebook.com/millchannel> >> | LINKEDIN <https://www.linkedin.com/company/9328> | >> INSTAGRAM <https://www.instagram.com/millchannel> >> | >> THEMILL.COM <http://www.themill.com/> >> >> _______________________________________________ >> Oiio-dev mailing list >> Oiio-dev@lists.openimageio.org <mailto:Oiio-dev@lists.openimageio.org> >> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org >> <http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org> > -- > Larry Gritz > l...@larrygritz.com <mailto:l...@larrygritz.com> > > > > > _______________________________________________ > 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