Results 1 to 9 of 9

Thread: Anyway to manipulate hue/saturation?

  1. #1

    Smile Anyway to manipulate hue/saturation?

    I've been reviewing Clanlib for an upcoming project that requires hue rotation when drawing images. I've found a way to manipulate hue/saturation during image loading(posted previously), but not while drawing it (at least not without preforming a bunch of CPU intensive operations). My app will be drawing a lot of the same images, except that they need to differ in color--and just changing hue values while drawing them could greatly reduce video memory usage.

    Maybe I've missed something in the documentation . Can anyone help me?

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

    Default

    To manipulate to HSV in realtime, I would do it in a GLSL shader, so the graphics card does it for you.

    I'm not sure if there are any tricks to this, but search for "hsv" and "glsl" in google - it returns many hits.

    Also see http://en.wikipedia.org/wiki/HSL_and_HSV for details to convert it mathematically.

  3. #3
    Lesser Wizard
    Join Date
    Jun 2007
    Posts
    109

    Default

    You just need to adjust color?

    Why not set the gl state color then draw it?

    The API within clanlib would be from a CL_Image or CL_Sprite:


    mysprite.set_color(CL_Colorf::lime);



    If you must adjust the actual hue/sat values, then definitely use a GL shader.

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

    Default

    Yeah, i forgot about that (Silly me!)

    Nearly all draw functions (from fonts to sprites), you can provide a colour.

    In the Form: CL_Colorf( Red, Green, Blue, Alpha)

    CL_Colorf(1.0f, 0.0f, 0.0f, 1.0f) - Only red shows through (Red appears red, 0 Green, 0 Blue, Fully opaque)

    CL_Colorf(1.0f, 1.0f, 1.0f, 0.5f) - All colors shows through, half transparency.

  5. #5

    Default

    Using CL_Colorf unfortunately won't get me the results needed.

    But, thanks for the information about GLSL. I've been trying to get it working with ClanLib, but no success thus far. I have worked with OpenGL in the past, but GLSL is completely new to me, so my lack of results is unsurprising. At least I see a way of getting the functionally I need. Any further advice would be appreciated, however I may be able to hack this thing into doing what I want it to eventually.

  6. #6
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    I've added a HSVExample to the Examples in the SVN version of 2.0, which shows how you can use a shader to offset the hue with ClanLib.

  7. #7

    Default

    Wow, thanks Magnus! That's even better then what I was looking for. After messing around with the GLSL portion of the example, I must say it's extremely cool, and certainly worth learning. There's just one little problem with the example though. Some of the color spectrum is not being converted correctly(only noticeable with an image with the full spectrum of colors). Have a look at the attachments.

    I tried fixing it myself, but it's going to take a bit more time for me to comb though GLSL.
    Attached Images Attached Images   

  8. #8
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    I'm afraid I do not know why it has that bug.

    After looking at the wikipedia article Rombust suggested, I quickly realized I couldn't really be bothered to do this RGB to HSV calculations, so I cheated by looting the math from the "Post RGB from HSV" article at Nvidia's shader library:

    http://developer.download.nvidia.com...r_library.html

    Unfortunately the conversion functions was in DirectX's HLSL, so I simply translated it into GLSL by hand. I cannot spot any error in my translation, so that pretty much leaves two possible options:

    • There is an error in the translation, but I am too blind to spot it!
    • The error is also in the original conversion routines from the Nvidia example

  9. #9

    Default

    Found the problem:
    Line 50 in fragment.glsl originally reads:
    Code:
    if (rgb.x = max_val)
    When it should be:
    Code:
    if (rgb.x >= max_val)
    And that's it! I can move forward with ClanLib now.
    Thanks for all the help

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
  •