If I understand your example correctly, you are laying out your pixel data in
memory as:
RRRRRRRRRR GGGGGGGGGG BBBBBBBBBB
but in general OIIO wants each pixel to be contiguous, like
RGB RGB RGB RGB RGB RGB RGB RGB RGB RGB
So like this:
int npixels = xres * yres;
for (auto pixel = 0; pixel < npixels; ++pixel) {
for (auto chan = 0; chan < channels; chan++) {
pixelsOut[pixel*channels + chan] = (float(chan % channels) * 20)*0.01;
}
}
> On Jan 29, 2022, at 4:02 PM, Dariusz <[email protected]> wrote:
>
> Hey
>
> Ok I'm giving up for today. I'm sure I'm missing comma somewhere or
> something... but here is what I get >
>
> <bUVVf1cOBGAIvRT9.png>
>
> It should be RGB with each channel incremented by 0.2 in value, so red 0,
> green 0.2, blur 0,4. Then remaining 3 channels increment in 0.6/0.8/1.0 as
> flat colours.
>
>
> int channels = 6; // RGB
> int xres = 640, yres = 480;
> auto imageoffset = xres * yres;
>
> std::vector<float> pixelsOut(imageoffset * channels);
> for (auto chan = 0; chan < channels; chan++) {
> for (auto pixel = 0; pixel < imageoffset; ++pixel) {
> pixelsOut[(chan * imageoffset) + pixel] = (float(chan % channels) *
> 20)*0.01;
> //qDebug()<<(float(chan % channels) * 20)*0.01;
> }
> }
>
>
> std::unique_ptr<OIIO::ImageOutput> out = OIIO::ImageOutput::create(filenamex);
> if (!out)
> return;
> OIIO::ImageSpec specx(xres, yres, channels, OIIO::TypeDesc::FLOAT);
> specx.channelnames = {"R", "G", "B", "PAINT", "GLASS", "DOOR"};
> specx.channelformats = {OIIO::TypeDesc::FLOAT,
> OIIO::TypeDesc::FLOAT,
> OIIO::TypeDesc::FLOAT,
> OIIO::TypeDesc::FLOAT,
> OIIO::TypeDesc::FLOAT,
> OIIO::TypeDesc::FLOAT,
> };
> out->open(filenamex, specx);
> out->write_image(OIIO::TypeDesc::FLOAT, pixelsOut.data());
> out->close();
>
> Any help would be legendary.I'm literally all out of ideas here :D
>
> Regards
> Dariusz
>
>
> On 29/01/2022 20:27, Dariusz wrote:
>> Hello
>>
>> Woa that was fast ! Thank you!!!
>>
>> Hmmm I just discovered OIIO::ImageOutput::AppendSubimage, I take this is not
>> what I want then... ?
>> Your explanation with compression/etc makes total sense. This subimage must
>> be something different then, gotta read in.
>>
>> for (auto &maskData: g.second.mMaskMap) {
>> //imageDataCombined.insert(imageDataCombined.end(),
>> maskData.second.second.begin(), maskData.second.second.end());
>> OIIO::ImageSpec specx(xres, yres, channelNames.size(),
>> OIIO::TypeDesc::FLOAT);
>> specx.channelnames = channelNames;
>> specx.extra_attribs.add_or_replace(OIIO::ParamValue("oiio:ColorSpace",
>> "Linear"));
>> specx.extra_attribs.add_or_replace(OIIO::ParamValue("compression",
>> "zips"));
>>
>> specx.extra_attribs.add_or_replace(OIIO::ParamValue("applied_color_corrections",
>> false));
>> specx.extra_attribs.add_or_replace(OIIO::ParamValue("oiio:subimages",
>> 1));
>> out->open(filenamex, specx, OIIO::ImageOutput::AppendSubimage);
>> out->write_image(OIIO::TypeDesc::FLOAT, maskData.second.second.data());
>> }
>> out->close();
>> This seems to be crashing atm... fairly sure I'm breaking something ^^.
>>
>>
>> 1 more issue...
>> After posting this post I started writing proper images to exr & opening in
>> PS and oh boy how I wish I didn't post before doing that test... Im now
>> stuck with weird layers!
>>
>> <tVzSl0kX4Zgv9vCr.png>
>> and
>> <X6Nvkexbu5WVSF6L.png>
>>
>> The top one looks "close" to being correct, it just looks like all 5
>> channels are squeezed in 1 layer from rotated 90deg & ordered left to
>> right... hmmm
>>
>> And many more, I went over different ways of building my "master buffer"
>> now, but so far I'm hitting walls...
>>
>> I tried it as scalines both width/height driven>
>> for (auto height = 0; height < yres; ++height) {
>> for (auto &maskData: g.second.mMaskMap) {
>> imageDataCombined.insert(imageDataCombined.end(),
>> maskData.second.second.begin() + (height * xres),
>> maskData.second.second.begin() + ((height + 1) * xres));
>> }
>> }
>> As well ass channel stacked >
>>
>>
>> for (auto &maskData: g.second.mMaskMap) {
>> imageDataCombined.insert(imageDataCombined.end(),
>> maskData.second.second.begin(), maskData.second.second.end());
>> }
>>
>> No matter how I build that buffer, it always comes out wrong...
>> Any ideas how to get it to... save properly? where am I making mistakes here?
>>
>> Big thanks !
>> Regards
>> Dariusz
>>
>>
>>
>> On 29/01/2022 20:17, Larry Gritz wrote:
>>> 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 <[email protected]
>>>> <mailto:[email protected]>> 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
>>>> [email protected] <mailto:[email protected]>
>>>> 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
>>>> [email protected] <mailto:[email protected]>
>>>> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
>>>> <http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org>
>>>
>>> --
>>> Larry Gritz
>>> [email protected] <mailto:[email protected]>
>>>
>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> Oiio-dev mailing list
>>> [email protected] <mailto:[email protected]>
>>> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
>>> <http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org>
>>
>> --
>> DARIUSZ MAKOWSKi
>> CGI-Photographer
>> 07 590 530 854
>> [email protected] <mailto:[email protected]>
>> www.dariuszmakowski.com <http://www.dariuszmakowski.com/>
>>
>> _______________________________________________
>> Oiio-dev mailing list
>> [email protected] <mailto:[email protected]>
>> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
>> <http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org>
>
> --
> DARIUSZ MAKOWSKi
> CGI-Photographer
> 07 590 530 854
> [email protected] <mailto:[email protected]>
> www.dariuszmakowski.com
> <http://www.dariuszmakowski.com/>_______________________________________________
> 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