The only thing I would add to your example is that there is no need to set 
channelformats at all if the channels are the same data type. In that case, you 
just need to set ImageSpec.format. Only when you have mixed data types for the 
channels is channelformats used (and regular ImageSpec.format is the "best" 
format that could hold any of the channels).

> Nowt this will write a nice file for me... but I'd like to understand... if I 
> have 100 channels.... and I might be reading channel from 1 file/ closing it 
> /writing it/etc... How can I eee... add a channel to existing file?


You can't. It's a limitation of the exr format and the underlying libOpenEXR 
that there is no way to add or alter a single channel in an existing file. You 
just have to read the whole thing and write a new file.

I'm not sure there's any image file format (or image file format reading 
library) that makes this easy. It could be done for uncompressed data, I guess 
-- just write over those bytes with new pixel values. But for any image file 
format that supports compression that could lead to varying size of the 
compressed data depending on the pixel values... I'm sure you can see why it's 
hard to change that without having to potentially shift all data in the file 
around.


> On Jan 29, 2022, at 11:45 AM, Dariusz <dari...@dariuszmakowski.com> wrote:
> 
> Hey
> 
> I'm fairly new to this amazing lib. Just trying to wrap my head around it.
> 
> I've opened one of exr files that has multiple layers, I did some edits to 
> few of them and now I'd like tow rite them out again in to file. Either 
> current one, or new one...
> 
> I've started with docs examples & started tweaking it...
> 
> int channels = 6;  // RGBA + 1 RGB channel
> 
> int xres = 640, yres = 480;
> 
> std::vector<float> pixelsOut(xres * yres * channels);
> 
> for (auto x = 1000; x < xres * yres * channels - 1000; ++x) {
>     pixelsOut[x] = (char) rand();
> }
> std::unique_ptr<OIIO::ImageOutput> out = OIIO::ImageOutput::create(filenamex);
> if (!out)
>     return;
> OIIO::ImageSpec spec(xres, yres, channels, OIIO::TypeDesc::FLOAT);
> spec.channelnames = {"R", "G", "B", "LALA","LOLOL", "LILI"};
> spec.channelformats = {OIIO::TypeDesc::FLOAT,
>                         OIIO::TypeDesc::FLOAT,
>                         OIIO::TypeDesc::FLOAT,
>                         OIIO::TypeDesc::FLOAT,
>                         OIIO::TypeDesc::FLOAT,
>                         OIIO::TypeDesc::FLOAT,
> 
>                         };
> out->open(filenamex, spec);
> out->write_image(OIIO::TypeDesc::FLOAT, pixelsOut.data());
> out->close();
> 
> Nowt this will write a nice file for me... but I'd like to understand... if I 
> have 100 channels.... and I might be reading channel from 1 file/ closing it 
> /writing it/etc... How can I eee... add a channel to existing file?
> 
> Regards
> Dariusz
> 
> 
> -- 
> DARIUSZ MAKOWSKi
> CGI-Photographer
> 07 590 530 854
> dari...@dariuszmakowski.com <mailto:dari...@dariuszmakowski.com>
> www.dariuszmakowski.com <http://www.dariuszmakowski.com/>
> 
>  
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
>     Virus-free. www.avast.com 
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
>  
> <x-msg://14/#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>_______________________________________________
> 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

Reply via email to