Archived

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

Austrian Coder

Rgb2YCrCb

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
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