Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Austrian Coder

Rgb2YCrCb

This topic is 5138 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I have here this funtion:
unsigned int Rgb2YCrCb(unsigned long rgb) 
{
    float Y,U,V;
    float R,G,B;
    unsigned int yuv = 0x0;

    B = ((rgb >> 16) & 0xFF) * 1.0;
    G = ((rgb >> 8) & 0xFF) * 1.0;
    R = (rgb & 0xFF) * 1.0;

    Y = (0.2578125 * R) + (0.50390625 * G) + (0.09765625 * B) + 16;
    U = (0.4375 * R) - (0.3671875 * G) - (0.0703125 * B) + 128;
    V =-(0.1484375 * R) - (0.2890625 * G) + (0.4375 * B) + 128;

    yuv = (int(Y) << 16) | (int(U) << 8) | int(V);

    return yuv;
}
 
Do you see any way, to optimize this funtion? Maybe there is floating around a MMX, 3DNow,.. example. Thanks, Christian

Share this post


Link to post
Share on other sites
Advertisement
www.stereopsis.com contains a nice article about floating conversion to integers.
Also has some code to demonstrate how to do it.

B = ((rgb >> 16) & 0xFF) * 1.0;
G = ((rgb >> 8) & 0xFF) * 1.0;
R = (rgb & 0xFF) * 1.0;

Then I would also suggest removing the multiplication by one since it doesn't do anything usefull if you are really touchy about it :D
Good luck with optimizations

- Patrik Willbo

Edit: HTML code for link

The Lord says He can get me out of this mess, but He's pretty sure you're fucked.
- Stephen (Braveheart)


[edited by - Willbo on May 26, 2004 6:49:21 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!