Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

oxp_yuv_to_rgb.h

Go to the documentation of this file.
00001 // This is oxl/oxp/oxp_yuv_to_rgb.h
00002 #ifndef oxp_yuv_to_rgb_h_
00003 #define oxp_yuv_to_rgb_h_
00004 //:
00005 // \file
00006 // \author fsm
00007 //
00008 // RGB to YUV Conversion
00009 // \code
00010 //      Y  =      (0.257 * R) + (0.504 * G) + (0.098 * B) + 16
00011 //      Cr = V =  (0.439 * R) - (0.368 * G) - (0.071 * B) + 128
00012 //      Cb = U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128
00013 // \endcode
00014 // YUV to RGB Conversion
00015 // \code
00016 //      B = 1.164(Y - 16)                  + 2.018(U - 128)
00017 //      G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128)
00018 //      R = 1.164(Y - 16) + 1.596(V - 128)
00019 // \endcode
00020 // Alternative:
00021 // \code
00022 //      Y = 0.299R + 0.587G + 0.114B
00023 //      U'= (B-Y)*0.565
00024 //      V'= (R-Y)*0.713
00025 // \endcode
00026 // with reciprocal versions:
00027 // \code
00028 //      R = Y + 1.403V'
00029 //      G = Y - 0.344U' - 0.714V'
00030 //      B = Y + 1.770U'
00031 // \endcode
00032 //
00033 // \verbatim
00034 //  Modifications
00035 //   10 Sep. 2004 Peter Vanroose  Inlined all 1-line methods in class decl
00036 // \endverbatim
00037 
00038 inline
00039 unsigned char oxp_yuv_to_rgb_byte_clamp(int x)
00040 {
00041   x = x / 1024;
00042   if (x < 0) return 0;
00043   if (x > 255) return 255;
00044   return (unsigned char) x;
00045 }
00046 
00047 inline
00048 void oxp_yuv_to_rgb(unsigned char y, unsigned char u, unsigned char v, unsigned char* rgb)
00049 {
00050   const int c1164 = int(1.164 * 1024);
00051   const int c1596 = int(1.596 * 1024);
00052   const int c0813 = int(0.813 * 1024);
00053   const int c0391 = int(0.391 * 1024);
00054   const int c2018 = int(2.018 * 1024);
00055   rgb[0] = oxp_yuv_to_rgb_byte_clamp(c1164 * (y - 16) + c1596 * (v - 128));
00056   rgb[1] = oxp_yuv_to_rgb_byte_clamp(c1164 * (y - 16) - c0813 * (v - 128) - c0391 * (u - 128));
00057   rgb[2] = oxp_yuv_to_rgb_byte_clamp(c1164 * (y - 16) + c2018 * (u - 128));
00058 }
00059 
00060 #endif // oxp_yuv_to_rgb_h_

Generated on Thu Jan 10 14:46:06 2008 for contrib/oxl/oxp by  doxygen 1.4.4