Sorry, was on vacation last week and still catching up on email.
Is the issue that when you execute the code below, src.png and dst.png don't
match? Or are you confident that it is already wrong by the time it's read in,
even before the write?
I think that
> config.attribute("oiio:UnassociatedAlpha", 1)
is the one you want to ensure that the read does not convert the unassociated
alpha. The attribute name searches are case-insensitive.
> buf = oiio.ImageBuf(src)
> # Read the file with the config
> buf.reset(src, 0, 0, config)
That's a somewhat odd construct. Ick, it looks like Python lacks a constructor
that directly takes a config, like the C++ API has. I'll fix that. That's why
you're doing the reset(), right?
In theory, the file being kept unassociated will also set
"oiio:UnassociatedAlpha" to 1 in the input spec (describing the data), which is
also used for the output spec (thus, providing the "oiio:UnassociatedAlpha" = 1
to the ImageBuf.write. I'm not sure what's going wrong.
I'm worried about several issues:
1. If the 1.5 version you are using is too old or has bugs and this is long
since fixed.
2. If the problem is on the read or when you write it back.
3. Exactly how you know there is a problem (i.e., is there really a problem).
Perhaps you can clarify whether you think that the read values are wrong in
your Python script, or if it's only the written file that's wrong; exactly what
version of OIIO you are using (and better -- verify it it is broken or working
on the current 1.6 release and/or the current development 'master'); and maybe
you'd like to email me a png to try, just in case it's something specific to
one file, and I can try it on my end.
-- lg
> On Mar 17, 2016, at 6:08 PM, Scott Wilson <[email protected]> wrote:
>
> Hello,
>
> I am trying to open and save a PNG that contains RGB values that are not
> associated with the A (or non-premultiplied) with OIIO and Python. I am
> trying the following code to tell OIIO ImageBuf to read unassociated, but it
> appears that it isn't respecting it. I'm restricted to OIIO 1.5.x due to the
> only builds on Windows that I found with Python being from
> www.lfd.uci.edu/~gohlke/pythonlibs/#openimageio
> <http://www.lfd.uci.edu/~gohlke/pythonlibs/#openimageio>. Am I doing
> something wrong, or would I have to use ImageInput -> ImageBuf? If so, is
> there any way to convert the ImageInput to ImageBuf without doing
> ImageBuf.setpixel(x, y, z, pixel)?
>
> Thanks in advanced!
>
> # The code
> import OpenImageIO as oiio
>
> if __name__ == '__main__':
> src = "c:/temp/blah/src.png"
> dst = "c:/temp/blah/dst.png"
>
> config = oiio.ImageSpec()
> # Wasn't 100% sure what the attribute should be, so trying all possible ones.
> :)
> config.attribute("oiio:UnassociatedAlpha", 1)
> config.attribute("oiio:unassociatedalpha", 1)
> config.attribute("UnassociatedAlpha", 1)
> config.attribute("unassociatedalpha", 1)
> buf = oiio.ImageBuf(src)
> # Read the file with the config
> buf.reset(src, 0, 0, config)
> # Write to a new png
> buf.write(dst)
> _______________________________________________
> 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