280 views
in Platform Packages by
Hi EW friends,

I am a little confused about the EW_PREMULTIPLY_COLOR_CHANNELS behavior.  If we defined the macro. And then we need to load some extern bitmap, I have seen your tutorial, it says we need to premutiply the rgb with alpha, that's ok. The extern bitmap will be  then blended with some gui component maybe a layer of semi transparency, then the whole frame of gui will be rendered out. The question is after blending , what kind of format should the result be?  Is the result's rgb also premutiplied or they are just the straight color?

By the way, if we want to undef EW_PREMULTIPLY, what should we do, is there some side effects on opengl package?

BR

Arnold

1 Answer

0 votes
by

Hi Arnold,

most of the GPUs operates with pre-multiplied colors as this allows the proper blending of semi-transparent objects. Therefore it is highly recommended to use pre-multiplied colors where ever this is possible by setting the define EW_PREMULTIPLY_COLOR_CHANNELS = 1

Only in case that a GPU expects non-pre-multiplied colors it is advisable to set EW_PREMULTIPLY_COLOR_CHANNELS = 0. But in this case it might happen that semi-transparent objects are not blended correctly.

If you set EW_PREMULTIPLY_COLOR_CHANNELS = 0 but the hardware expects colors in pre-multiplied format the results can be undefined, because colors might be invalid. For example a semi-transparent white is non-pre-multiplied RGBA 0xFFFFFF80 and pre-multiplied 0x80808080. However, 0xFFFFFF80 as pre-multiplied color does not exist (RGB has to be equal or lower than A).

The advantage of using pre-multiplied colors is, that you can blend several (pre-multiplied) objects over another and the result is still pre-multiplied.

Btw: If the destination is fully opaque (as it is typically the case within a framebuffer), it does not matter whether you interpret that as pre-mulitplied or not.

Does this answer your questions?

Best regards,

Manfred.

 

by
Hi Manfred,

Actually, we have made a test on 9.30 ogl package about the alpha blending, with  . We load an ext bmp which is filled with 0x60504030 (alpha = 0x30) , then blend it with a gui rectangle backgroud with its color defined as 0x0000004C, and then we dumped the gui frame and found the result to be 0x6050406E. It seems to be unconformable with what you said above,  if the result is still pre-multiplied, it should be 0x29221C6E . Is it right?

BTW, why we care about it is that the blended gui frame will then be blended with a video frame, while our hardware can only support non-premultipiled alpha.  And now the rendered result seems not confusing.

BR

Arnold
by

Hi Arnold,

this is the alpha-blending operation for pre-multiplied colors:

    aout = as + ad * (1 - as)
    Cout = Cs + Cd * (1 - as)

Remark:
    Cd: Color of destination pixel (= R, G, B value)
    Cs: Color of source pixel (= R, G, B value)
    Cout: Color of destination pixel after the operation
    ad: Alpha value of destination pixel
    as: Alpha value of source pixel
    aout: Alpha value of destination pixel after the operation

If your destination is 0x60504030 and the source is 0x0000004C the result should be 0x43382C6D. The destination becomes more opaque and more dark after the blend operation with the semitransparent black rectangle.

Best regards,

Manfred.

by

Hi Manfred,

Yes, I understand the caculations, I just make 0x60504030 the src , and 0x0000004c the dst.  So according to your answer, after blending, the RGB will be stored without multiplied alpha. And when it then be blended with another dst frame for example 0x808080ff, what kind of blending func should we adapt. Shall we use the 

aout = as + ad * (1 - as)
Cout = Cs + Cd * (1 - as)

or

aout = as + ad * (1 - as)
Cout = Cs * as + Cd * (1 - as)

BR

Arnold

by

Hi Arnold,

this is the alpha-blending operation for pre-multiplied colors:

    aout = as + ad * (1 - as)
    Cout = Cs + Cd * (1 - as)

This means, the source is expected to have pre-multiplied colors, the destination is expected to have pre-multiplied colors before the operation and the destination will contain pre-multiplied colors after the operation. There is no need to make additional pre-multiplications or post-divisions. I did not mention that after blending the RGB will be stored without multiplied alpha.

Best regards,

Manfred.

 

by
Thx, got it.

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...