TuttleOFX
1
|
00001 #ifndef _BOOST_GIL_COLOR_SCALE_HPP_ 00002 #define _BOOST_GIL_COLOR_SCALE_HPP_ 00003 00004 #include <terry/numeric/minmax.hpp> 00005 00006 namespace boost { namespace gil { 00007 00008 /** 00009 * @brief Scale pixel values. 00010 * Usefull to normalize an image. 00011 */ 00012 template<typename Pixel, typename CPixel = Pixel> 00013 struct pixel_scale_t 00014 { 00015 typedef typename boost::gil::channel_type<Pixel>::type Channel; 00016 typedef typename terry::channel_base_type<Channel>::type ChannelBaseType; 00017 00018 const CPixel _ratio; 00019 CPixel _shift; 00020 00021 pixel_scale_t( const CPixel& ratio, const CPixel& sCenter, const CPixel& dCenter ) 00022 : _ratio(ratio) 00023 { 00024 BOOST_STATIC_ASSERT( boost::is_floating_point<ChannelBaseType>::value ); 00025 // res = ( ( src - sCenter ) * _ratio ) + dCenter; 00026 // res = (src * _ratio) + (dCenter - (sCenter*ratio)) 00027 // shift = (dCenter - (sCenter*ratio)) 00028 pixel_assigns_t<CPixel,CPixel>()( 00029 pixel_minus_t<CPixel,CPixel,CPixel>()( 00030 dCenter, 00031 pixel_multiplies_t<CPixel,CPixel,CPixel>()( 00032 sCenter, 00033 ratio 00034 ) 00035 ), 00036 _shift ); 00037 } 00038 00039 pixel_scale_t( const CPixel& ratio, const CPixel& shift ) 00040 : _ratio(ratio) 00041 , _shift(shift) 00042 { 00043 BOOST_STATIC_ASSERT( boost::is_floating_point<ChannelBaseType>::value ); 00044 } 00045 00046 Pixel operator()( const Pixel& src ) const 00047 { 00048 Pixel res; 00049 // res = (src * _ratio) + _shift 00050 pixel_assigns_t<CPixel,Pixel>()( 00051 pixel_plus_t<CPixel,CPixel,CPixel>()( 00052 pixel_multiplies_t<Pixel,CPixel,CPixel>()( 00053 src, 00054 _ratio 00055 ), 00056 _shift ), 00057 res ); 00058 00059 return res; 00060 } 00061 }; 00062 00063 } 00064 } 00065 00066 #endif