TuttleOFX
1
|
00001 #ifndef _TERRY_NUMERIC_CLAMP_HPP_ 00002 #define _TERRY_NUMERIC_CLAMP_HPP_ 00003 00004 00005 namespace terry { 00006 namespace numeric { 00007 00008 template <typename Channel> 00009 struct channel_clamp_lower_than_t : public std::unary_function<Channel, Channel> 00010 { 00011 Channel _threshold; 00012 Channel _replace; 00013 00014 channel_clamp_lower_than_t( const Channel threshold, const Channel replace ) 00015 : _threshold( threshold ) 00016 , _replace( replace ) 00017 { } 00018 00019 GIL_FORCEINLINE 00020 Channel operator( )( typename channel_traits<Channel>::const_reference ch ) const 00021 { 00022 if( ch < _threshold ) 00023 return _replace; 00024 return Channel( ch ); 00025 } 00026 }; 00027 00028 template <typename Pixel> // models pixel concept 00029 struct pixel_clamp_lower_than_t 00030 { 00031 typedef typename channel_type<Pixel>::type Channel; 00032 Channel _threshold; 00033 Channel _replace; 00034 00035 pixel_clamp_lower_than_t( const Channel threshold, const Channel replace ) 00036 : _threshold( threshold ) 00037 , _replace( replace ) 00038 {} 00039 00040 GIL_FORCEINLINE 00041 Pixel operator()( const Pixel & p ) const 00042 { 00043 Pixel result; 00044 static_transform( p, result, channel_clamp_lower_than_t<typename channel_type<Pixel>::type>( _threshold, _replace ) ); 00045 return result; 00046 } 00047 }; 00048 00049 00050 } 00051 } 00052 00053 #endif