TuttleOFX
1
|
00001 #ifndef _TERRY_COLOR_LAYOUT_YUV_HPP_ 00002 #define _TERRY_COLOR_LAYOUT_YUV_HPP_ 00003 00004 #include "rgb.hpp" 00005 00006 namespace terry { 00007 namespace color { 00008 namespace layout { 00009 00010 /// \addtogroup ColorNameModel 00011 /// \{ 00012 namespace yuv 00013 { 00014 /// \brief Luminance 00015 struct y_t {}; 00016 /// \brief U 00017 struct u_t {}; 00018 /// \brief V 00019 struct v_t {}; 00020 } 00021 /// \} 00022 00023 /// \ingroup ColorSpaceModel 00024 typedef boost::mpl::vector3< 00025 yuv::y_t, 00026 yuv::u_t, 00027 yuv::v_t 00028 > yuv_t; 00029 00030 /** 00031 * @brief RGB -> YUV 00032 */ 00033 template < typename SrcP, typename DstP > 00034 void layout_convert<rgb_t, yuv_t>( const SrcP& src, DstP& dst ) 00035 { 00036 //std::cout << "convert RGB to YUV" << std::endl; 00037 get_color( dst, yuv::y_t() ) = get_color( src, red_t() ) + 1.13983 * get_color( src, blue_t() ); 00038 get_color( dst, yuv::u_t() ) = get_color( src, red_t() ) - 0.39465 * get_color( src, green_t() ) - 0.58060 * get_color( src, blue_t() ); 00039 get_color( dst, yuv::v_t() ) = get_color( src, red_t() ) + 2.03211 * get_color( src, green_t() ) ; 00040 } 00041 00042 /** 00043 * @brief YUV -> RGB 00044 */ 00045 template < typename SrcP, typename DstP > 00046 void layout_convert<yuv_t, rgb_t>( const SrcP& src, DstP& dst ) 00047 { 00048 //std::cout << "convert YUV to RGB" << std::endl; 00049 get_color( dst, red_t() ) = 0.299 * get_color( src, yuv::y_t() ) + 0.587 * get_color( src, yuv::u_t() ) + 0.114 * get_color( src, yuv::v_t() ); 00050 get_color( dst, green_t() ) = -0.14713 * get_color( src, yuv::y_t() ) - 0.28886 * get_color( src, yuv::u_t() ) + 0.436 * get_color( src, yuv::v_t() ); 00051 get_color( dst, blue_t() ) = 0.615 * get_color( src, yuv::y_t() ) - 0.51499 * get_color( src, yuv::u_t() ) - 0.10001 * get_color( src, yuv::v_t() ); 00052 } 00053 00054 00055 } 00056 } 00057 } 00058 00059 00060 #endif