rgb to yuv420 algorithm efficiency

后端 未结 5 2025
北荒
北荒 2021-01-30 10:05

I wrote an algorithm to convert a RGB image to a YUV420. I spend a long time trying to make it faster but I haven\'t find any other way to boost its efficiency, so now I turn to

5条回答
  •  遇见更好的自我
    2021-01-30 10:31

    Do not access pointers more then once, copy the value to the stack and then use the value on the stack. (Aliasing)

    ...
    int v_r = *r;
    int v_g = *g;
    int v_b = *b;
    
    *y = ((lookup66[v_r] + lookup129[v_g] + lookup25[v_b]) >> 8) + 16;
    ...
    

    On the other hand, you can do it in SSE without look-up tables and would do 8 pixels at once.

提交回复
热议问题