// ================================================================================== // YUV to RGB color transform functions // // SGI Indy R5000 PIII 500MHz // -O3 -O3 // Floating Point: 12.38 6.27 4.57 3.71 // Fixed Point: 7.44 2.78 1.45 0.55 // ================================================================================== #include #include #include #define CONV_NUM (640 * 480 * 30) // 640x480 pixels, 30 fps. // // Floating point defines // #define FP_C_1 (-1.40200) #define FP_C_2 (-0.34414) #define FP_C_3 ( 0.71414) #define FP_C_4 ( 1.77200) #define FP_HALF ( 0.50000) void FP_YUV_to_RGB(int Y, int U, int V, int *pR, int *pG, int *pB) { U -= 127; V -= 127; *pR = (int) (Y + FP_C_1 * V + FP_HALF); *pG = (int) (Y + FP_C_2 * U + FP_C_3 * V + FP_HALF); *pB = (int) (Y + FP_C_4 * U + FP_HALF); } // // Fixed point defines // #define YUV_SHIFT 16 #define YUV_ONE (1 << YUV_SHIFT) #define YUV_HALF (1 << (YUV_SHIFT - 1)) #define C_1 ((int)(-1.40200 * YUV_ONE)) #define C_2 ((int)(-0.34414 * YUV_ONE)) #define C_3 ((int)( 0.71414 * YUV_ONE)) #define C_4 ((int)( 1.77200 * YUV_ONE)) void YUV_to_RGB(int Y, int U, int V, int *pR, int *pG, int *pB) { U -= 127; V -= 127; *pR = Y + ((C_1 * V + YUV_HALF) >> YUV_SHIFT); *pG = Y + ((C_2 * U + C_3 * V + YUV_HALF) >> YUV_SHIFT); *pB = Y + ((C_4 * U + YUV_HALF ) >> YUV_SHIFT); } // // Test program // main() { int Y = rand() % 256; int U = rand() % 256; int V = rand() % 256; volatile int R, G, B; // Prevents code elimination with -O3 int i; clock_t start, finish; // Floating point math start = clock(); for(i=0; i