00001 // This is core/vil/algo/vil_colour_space.h 00002 #ifndef vil_colour_space_h_ 00003 #define vil_colour_space_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \brief Functions to convert between different colour spaces. 00010 // 00011 // Functions to convert between different colour spaces. 00012 // See Foley and van Dam, "Computer Graphics, Principles and Practice". 00013 // 00014 // \author fsm 00015 00016 //: Linear transformation from RGB to YIQ colour spaces 00017 template <class T> 00018 void vil_colour_space_RGB_to_YIQ(T const in[3], T out[3]); 00019 00020 //: Linear transformation from YIQ to RGB colour spaces 00021 template <class T> 00022 void vil_colour_space_YIQ_to_RGB(T const in[3], T out[3]); 00023 00024 00025 //: Transform from RGB to HSV colour spaces 00026 // The input RGB values must lie in [0, L], for some positive L. Usually 00027 // L=1 or 255. 00028 // 00029 // The output HSV values will lie in the ranges: 00030 // H : [0, 360) (an angle, in bloody degrees) 00031 // S : [0, 1] 00032 // V : [0, L] 00033 // 00034 // [HSV is also known as HSB] 00035 template <class T> 00036 void vil_colour_space_RGB_to_HSV(T r, T g, T b, T *h, T *s, T *v); 00037 00038 //: Transform from HSV to RGB colour space 00039 // 00040 // The input HSV values will lie in the ranges: 00041 // H : [0, 360) (an angle, in bloody degrees) 00042 // S : [0, 1] 00043 // V : [0, 255] 00044 // 00045 // The output RGB values will lie in [0, 255] 00046 // 00047 // [HSV is also known as HSB] 00048 template <class T> 00049 void vil_colour_space_HSV_to_RGB(T h, T s, T v, T *r, T *g, T *b); 00050 00051 00052 //: Linear transformation from RGB to YUV colour spaces 00053 template <class T> 00054 void vil_colour_space_RGB_to_YUV(T const in[3], T out[3]); 00055 00056 //: Linear transformation from YUV to RGB colour spaces 00057 template <class T> 00058 void vil_colour_space_YUV_to_RGB(T const in[3], T out[3]); 00059 00060 //: Transformation from analog RGB to analog YPbPr colour spaces 00061 // The input and out value lie in the ranges: 00062 // - R', G', B' in [0; 1] 00063 // - Y' in [0; 1] 00064 // - Pb in [-0.5; 0.5] 00065 // - Pr in [-0.5; 0.5] 00066 template <class T> 00067 void vil_colour_space_RGB_to_YPbPr_601(T const RGB[3], T YPbPr[3]); 00068 00069 //: Transformation from analog YPbPr to RGB colour spaces 00070 // The input and out value lie in the ranges: 00071 // - Y' in [0; 1] 00072 // - Pb in [-0.5; 0.5] 00073 // - Pr in [-0.5; 0.5] 00074 // - R', G', B' in [0; 1] 00075 template <class T> 00076 void vil_colour_space_YPbPr_601_to_RGB(T const YPbPr[3], T RGB[3]); 00077 00078 //: Transformation from 8 bit RGB to 8 bit YCbCr colour spaces 00079 // The input and out value lie in the ranges: 00080 // - R'd, G'd, B'd in {0, 1, 2, ..., 255} 00081 // - Y' in {16, 17, ..., 235} 00082 // with 00083 // * footroom in {1, 2, ..., 15} 00084 // * headroom in {236, 237, ..., 254} 00085 // * sync. in {0, 255} 00086 // - Cb, Cr in {16, 17, ..., 240} 00087 void vil_colour_space_RGB_to_YCbCr_601(const unsigned char RGB[3], unsigned char YCbCr[3]); 00088 00089 //: Transformation from 8 bit YCbCr to 8 bit RGB colour spaces 00090 // The input and out value lie in the ranges: 00091 // - Y' in {16, 17, ..., 235} 00092 // with 00093 // * footroom in {1, 2, ..., 15} 00094 // * headroom in {236, 237, ..., 254} 00095 // * sync. in {0, 255} 00096 // - Cb, Cr in {16, 17, ..., 240} 00097 // - R'd, G'd, B'd in {0, 1, 2, ..., 255} 00098 void vil_colour_space_YCbCr_601_to_RGB(const unsigned char YCbCr[3], unsigned char RGB[3]); 00099 00100 #endif // vil_colour_space_h_