Results 1 to 7 of 7

Thread: Premultiplication of RGB by Alpha.

  1. #1
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default Premultiplication of RGB by Alpha.

    I have created a new example in SVN called "Blend"

    It was my attempt into understanding using premultiplied alpha.

    I gave up!

    I expected the premultiplied version of the texture using a different blend mode to look identical. Instead itís a lot brighter.

    I came to the conclusion, that Iím not clever enough!

    Initially I thought that an "image filter" would be useful in ClanLib for pre-processing images.

    That is not required. Because CL_Image and CL_Texture both accept CL_PixelBuffers as inputs.

    Also the question whether we should premultiply all textures automatically was mentioned on IRC. But I donít know the answer to it (since I canít get the example to work).

    The worry I have, is that if we do premultiply all textures, then all the graphics in my previous projects using clanlib will need adjusting to counteract any differences.

    Although, I could feed the CL_Images with CL_Pixelbuffers instead of the filename to overcome it.

  2. #2
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    I think we need an option when constructing sprites or images if they are to be premultiplied or not - and Clanlib handles this automatically by doing the necessary conversions..

  3. #3
    Master Sorcerer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    You got strange behavior in the blend example because you used the wrong blend mode for premultiplied alpha.

    The correct blend mode is:

    blend_mode.set_blend_function(cl_blend_one, cl_blend_one_minus_src_alpha, cl_blend_one, cl_blend_one_minus_src_alpha);

    The resulting blend operation then becomes:

    dest.red = 1*src.red + (1-src.alpha)*dest.red
    dest.green = 1*src.green + (1-src.alpha)*dest.red
    dest.blue = 1*src.blue + (1-src.alpha)*dest.blue
    dest.alpha = 1*src.alpha + (1-src.alpha)*dest.alpha

    After this change your blend example works like you expected it to.

  4. #4
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Quote Originally Posted by sphair View Post
    I think we need an option when constructing sprites or images if they are to be premultiplied or not - and Clanlib handles this automatically by doing the necessary conversions..
    This has now been implemented in SVN

  5. #5
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    Cool, can't wait to go home and try it on my own translucent theme! Thanks for fixing this!

  6. #6
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Nothing has changed in "CL_GUIWindowManagerProvider_Texture::begin_paint( )"

    And (by default), the gui images are still loaded without premultiplied alpha

    So, the gui should not have changed

  7. #7
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Note:

    CL_GUIWindowManagerProvider_Texture::begin_paint()

    contains:

    Code:
    	// TODO: CL_Draw::fill() is slightly slower than gc.clear() - but it works with a cliprect on the GDI target
    	CL_Draw::fill(gc, clip_rect, CL_Colorf::transparent);
    	gc.set_cliprect(clip_rect);
    	//gc.clear(CL_Colorf::transparent);
    This may not be correct, because fill depends on the blend mode.

    The blend mode is current set to (in the same function)

    CL_BlendMode blendmode;
    blendmode.enable_blending(true);
    gc.set_blend_mode(blendmode);

Similar Threads

  1. problem to launch Novashell 0.32 alpha
    By Planescape in forum Novashell Game Creation System
    Replies: 3
    Last Post: 12-06-2008, 09:36 PM
  2. Canvas and alpha
    By marcr in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 02-09-2008, 04:36 AM
  3. Weirdness with alpha
    By madmark in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 12-12-2007, 11:08 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •