TuttleOFX
1
|
00001 #ifndef _TERRY_COLOR_LAYOUT_YPBPR_HPP_ 00002 #define _TERRY_COLOR_LAYOUT_YPBPR_HPP_ 00003 00004 #include "rgb.hpp" 00005 00006 namespace terry { 00007 namespace color { 00008 namespace layout { 00009 00010 //////////////////////////////////////////////////////////////////////////////// 00011 // YPbPr // 00012 00013 /// \addtogroup ColorNameModel 00014 /// \{ 00015 namespace YPbPr 00016 { 00017 /// \brief Luminance 00018 struct Y_t {}; 00019 /// \brief Pb 00020 struct Pb_t {}; 00021 /// \brief Pr 00022 struct Pr_t {}; 00023 } 00024 /// \} 00025 00026 /// \ingroup ColorSpaceModel 00027 typedef boost::mpl::vector3< 00028 YPbPr::Y_t, 00029 YPbPr::Pb_t, 00030 YPbPr::Pr_t 00031 > YPbPr_t; 00032 00033 00034 /** 00035 * @brief YPbPr -> RGB 00036 */ 00037 template < typename SrcP, typename DstP > 00038 void convertYPbPrToRgb( const SrcP& src, DstP& dst ) 00039 { 00040 get_color( dst, red_t() ) = get_color( src, YPbPr::Y_t() ) + 1.402 * get_color( src, YPbPr::Pr_t() ); 00041 get_color( dst, green_t() ) = get_color( src, YPbPr::Y_t() ) - 0.344136 * get_color( src, YPbPr::Pb_t() ) - 0.714136 * get_color( src, YPbPr::Pr_t() ); 00042 get_color( dst, blue_t() ) = get_color( src, YPbPr::Y_t() ) + 1.772 * get_color( src, YPbPr::Pb_t() ) ; 00043 } 00044 00045 /** 00046 * @brief RGB -> YPbPr 00047 */ 00048 template < typename SrcP, typename DstP > 00049 void convertRgbToYPbPr( const SrcP& src, DstP& dst ) 00050 { 00051 get_color( dst, YPbPr::Y_t() ) = 0.299 * get_color( src, red_t() ) + 0.587 * get_color( src, green_t() ) + 0.114 * get_color( src, blue_t() ); 00052 get_color( dst, YPbPr::Pb_t() ) = -0.168736 * get_color( src, red_t() ) - 0.331264 * get_color( src, green_t() ) + 0.5 * get_color( src, blue_t() ); 00053 get_color( dst, YPbPr::Pr_t() ) = 0.5 * get_color( src, red_t() ) - 0.418688 * get_color( src, green_t() ) - 0.081312 * get_color( src, blue_t() ); 00054 } 00055 00056 } 00057 } 00058 } 00059 00060 00061 #endif