AWTTextureIO premultiplying colors with alpha?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

AWTTextureIO premultiplying colors with alpha?

Robert
Hi,

I need to be able to create textures from BufferedImages but I'm running into this problem where the RGB components are premultiplied by the alpha component. This is not the behaviour I desire. This is the code I'm using:


                TextureData td = AWTTextureIO.newTextureData(gl.getGLProfile(),bi, config.useMipMaps);

after this call when I check the byte array in the TextureData object, the RGB values have all been premultiplied.
Reply | Threaded
Open this post in threaded view
|

Re: AWTTextureIO premultiplying colors with alpha?

Robert
it looks like you can't turn off pre-multiplying in JOGL... am I wrong?
Reply | Threaded
Open this post in threaded view
|

Re: AWTTextureIO premultiplying colors with alpha?

Sven Gothel
Administrator
On 07/16/2013 09:37 PM, Robert [via jogamp] wrote:> Hi,

>
> I need to be able to create textures from BufferedImages but I'm running into
> this problem where the RGB components are premultiplied by the alpha
> component. This is not the behaviour I desire. This is the code I'm using:
>
>
>                 TextureData td =
> AWTTextureIO.newTextureData(gl.getGLProfile(),bi, config.useMipMaps);
>
> after this call when I check the byte array in the TextureData object, the RGB
> values have all been premultiplied.
Texture class does not alter the image data,
i.e. no premultiplication performed here.
I just have fixed the API doc .. (thx for kicking in this direction)
  <http://jogamp.org/git/?p=jogl.git;a=commitdiff;h=55e480cd487e3089fae9b836eb213cd7c6b3d79a>


AWTTextureIO uses AWT's image pipeline, which may perform this task.
It may also be possible that we do - I would need to verify this code.

Default is TextureIO, not the AWT specialization.
TextureIO uses our decoder for JPEG and PNG, both do _not_
perform any premultiplication.
Both also deliver the data in proper GL orientation,
and hence are more efficient!

On 07/16/2013 10:19 PM, Robert [via jogamp] wrote:
> it looks like you can't turn off pre-multiplying in JOGL... am I wrong?

.. use TextureIO ..

~Sven



signature.asc (911 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: AWTTextureIO premultiplying colors with alpha?

Sven Gothel
Administrator
In reply to this post by Robert
On 07/17/2013 12:09 AM, Sven Gothel wrote:
>
> AWTTextureIO uses AWT's image pipeline, which may perform this task.
> It may also be possible that we do - I would need to verify this code.

I do not see AWTTextureIO/AWTTextureData premultiplying the data,
it keeps the alpha channels intact AFAIK, see 'hasAlpha' in latter class.

AFAIK I have seen this proper behavior in our unit tests as well..

However, I still recommend using the default TextureIO impl.

~Sven


signature.asc (911 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: AWTTextureIO premultiplying colors with alpha?

Robert
The reason I'm using AWTTextureIO is that I'm passing a BufferedImage that I did not load in from a file (I created the image in my application and shouldn't have to save it to file in order to create an OpenGL texture). TextureIO does not have the option of passing a BufferedImage. What method do you suggest? I don't have to use a BufferedImage specifically, but it would be convenient.
Reply | Threaded
Open this post in threaded view
|

Re: AWTTextureIO premultiplying colors with alpha?

Robert
this worked:
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                ImageIO.write(bufferedImage, "png", os);
                InputStream is = new ByteArrayInputStream(os.toByteArray());
                TextureData td = TextureIO.newTextureData(gl.getGLProfile(),is, config.useMipMaps, "png");

Thanks for your help!