TuttleOFX
1
|
00001 #ifndef _TERRY_BASICCOLORS_HPP_ 00002 #define _TERRY_BASICCOLORS_HPP_ 00003 00004 #include <boost/gil/pixel.hpp> 00005 #include <boost/gil/typedefs.hpp> 00006 #include <boost/gil/color_convert.hpp> 00007 00008 namespace terry { 00009 00010 /** 00011 * @todo tuttle: to rewrite !!! 00012 */ 00013 struct alpha_max_filler 00014 { 00015 template< class P> 00016 inline P operator()( const P& p ) const 00017 { 00018 using namespace boost::gil; 00019 gil_function_requires<ColorSpacesCompatibleConcept< 00020 typename color_space_type<P>::type, 00021 rgba_t> >( ); 00022 P p2; 00023 p2[3] = channel_traits< typename channel_type< P >::type >::max_value(); 00024 return p2; 00025 } 00026 00027 }; 00028 00029 /** 00030 * @todo tuttle: to rewrite !!! 00031 */ 00032 struct black_filler 00033 { 00034 template< class P> 00035 inline P operator()( const P& p ) const 00036 { 00037 using namespace boost::gil; 00038 P p2; 00039 for( int v = 0; v < num_channels<P>::value; ++v ) 00040 { 00041 p2[v] = 0; 00042 } 00043 return p2; 00044 } 00045 00046 }; 00047 00048 /** 00049 * @brief Get black color value 00050 */ 00051 template<class Pixel> 00052 static inline const Pixel get_black() 00053 { 00054 using namespace boost::gil; 00055 Pixel black; 00056 /// @todo tuttle: to rewrite !!! 00057 boost::gil::color_convert( gray32f_pixel_t( 0.0 ), black ); 00058 return black; 00059 } 00060 00061 template<class View> 00062 static inline const typename View::value_type get_black( const View& ) 00063 { 00064 return get_black<typename View::value_type>(); 00065 } 00066 00067 template<class View> 00068 static inline typename View::value_type get_white() 00069 { 00070 using namespace boost::gil; 00071 typename View::value_type white; 00072 /// @todo tuttle: to rewrite !!! 00073 boost::gil::color_convert( gray32f_pixel_t( 1.0 ), white ); 00074 return white; 00075 } 00076 00077 template<class View> 00078 static inline typename View::value_type get_white( const View& ) 00079 { 00080 return get_white<View>(); 00081 } 00082 00083 template <class View> 00084 void fill_alpha_max( const View& v ) 00085 { 00086 using namespace boost::gil; 00087 transform_pixels( v, v, alpha_max_filler() ); 00088 } 00089 00090 /** 00091 * @brief Fill an image in black, all channels to 0.0 value and alpha channel to 1.0 (if exists) 00092 * @todo tuttle: to rewrite !!! 00093 */ 00094 template <class View> 00095 void fill_black( View& v ) 00096 { 00097 using namespace boost::gil; 00098 transform_pixels( v, v, black_filler() ); 00099 // Following doesn't work for built-in pixel types 00100 // fill_pixels( v, get_black( v ) ); 00101 } 00102 00103 00104 } 00105 00106 #endif 00107