transparency with alpha channel RGBA

View: New views
4 Messages — Rating Filter:   Alert me  

transparency with alpha channel RGBA

by uray meiviar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hello,

few question, i'am trying to build openGL application which most of the textures are generated by Cairo, I create cairo surface using cairo_image_surface_create_for_data() with CAIRO_FORMAT_ARGB32 format and fetch the data to the GPU texture, but my problem is, on these codes:

cairo_set_source_rgba (this->canvas, 1.0, 1.0, 1.0, 0.5);
cairo_set_operator (this->canvas, CAIRO_OPERATOR_SOURCE);
cairo_paint (this->canvas);

I got grayed texture instead of white texture with half transparency, on the cairo surface data I got 0x808080808080...
instead of 0xFFFFFF80FFFFFF80FF.... it seems that the white color (1.0,1.0,1.0) are premultiplied by its alpha channel value of (0.5) resulting to (0.5,0.5,0.5,0.5 = 0x80808080...).

how do I get, non-premultiplied color so my openGL texture will have correct alpha channel values?

thank you.


_______________________________________________
cairo mailing list
cairo@...
http://lists.cairographics.org/mailman/listinfo/cairo

Re: transparency with alpha channel RGBA

by M Joonas Pihlaja :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi,

On Tue, 27 Oct 2009, uray meiviar wrote:

> how do I get, non-premultiplied color so my openGL texture will have
> correct alpha channel values?

I believe you can use premultiplied textures with OpenGL by
configuring the right blend function.  For the cases where using
unpremultiplied data is unavoidable you'll need to convert the
premultiplied data yourself before uploading the textures.  Various
implementations of unpremultipliers are available here:

http://cgit.freedesktop.org/~joonas/unpremultiply/tree/

Generally the overhead from unpremultiplication is fairly low as long
as you don't implement it using three divisions per pixel.

Cheers,

Joonas
_______________________________________________
cairo mailing list
cairo@...
http://lists.cairographics.org/mailman/listinfo/cairo

Re: transparency with alpha channel RGBA

by uray meiviar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
thank you for your reply,

currently I solved it by un-multiply the RGB value (divide RGB values by A) on fragment shader, which is no significant penalty since it was done on GPU, but now my concern is the wasted CPU cycle for RGB*A multiplication by Cairo (since CPU is far too slow compared to GPU), is there any switch to turn off premultiplied RGB process?


From: M Joonas Pihlaja <jpihlaja@...>
To: uray meiviar <uraymeiviar@...>
Cc: cairo@...
Sent: Thu, October 29, 2009 4:00:01 AM
Subject: Re: [cairo] transparency with alpha channel RGBA


Hi,

On Tue, 27 Oct 2009, uray meiviar wrote:

> how do I get, non-premultiplied color so my openGL texture will have
> correct alpha channel values?

I believe you can use premultiplied textures with OpenGL by
configuring the right blend function.  For the cases where using
unpremultiplied data is unavoidable you'll need to convert the
premultiplied data yourself before uploading the textures.  Various
implementations of unpremultipliers are available here:

http://cgit.freedesktop.org/~joonas/unpremultiply/tree/

Generally the overhead from unpremultiplication is fairly low as long
as you don't implement it using three divisions per pixel.

Cheers,

Joonas


_______________________________________________
cairo mailing list
cairo@...
http://lists.cairographics.org/mailman/listinfo/cairo

Re: transparency with alpha channel RGBA

by M Joonas Pihlaja :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Thu, 29 Oct 2009, uray meiviar wrote:

> currently I solved it by un-multiply the RGB value (divide RGB
> values by A) on fragment shader, which is no significant penalty
> since it was done on GPU,

Ah, sounds good!

> but now my concern is the wasted CPU cycle
> for RGB*A multiplication by Cairo (since CPU is far too slow
> compared to GPU), is there any switch to turn off premultiplied RGB
> process?

No, sorry.  I wouldn't worry about it though.

Cheers,

Joonas
_______________________________________________
cairo mailing list
cairo@...
http://lists.cairographics.org/mailman/listinfo/cairo