TuttleOFX
1
|
00001 #ifndef _TERRY_NUMERIC_ASSIGN_HPP_ 00002 #define _TERRY_NUMERIC_ASSIGN_HPP_ 00003 00004 #include <terry/algorithm/for_each.hpp> 00005 #include <terry/pixel_proxy.hpp> 00006 00007 namespace terry { 00008 using namespace boost::gil; 00009 00010 namespace numeric { 00011 00012 /// \ingroup ChannelNumericOperations 00013 /// structure for assigning one channel to another 00014 /// this is a generic implementation; user should specialize it for better performance 00015 template <typename Channel1,typename Channel2> 00016 struct channel_assigns_t : public std::binary_function<Channel1,Channel2,Channel2> 00017 { 00018 GIL_FORCEINLINE 00019 typename channel_traits<Channel2>::reference 00020 operator()( typename channel_traits<Channel1>::const_reference ch1, 00021 typename channel_traits<Channel2>::reference ch2 ) const 00022 { 00023 return ch2=Channel2(ch1); 00024 } 00025 }; 00026 00027 /// \ingroup PixelNumericOperations 00028 ///definition and a generic implementation for casting and assigning a pixel to another 00029 ///user should specialize it for better performance 00030 template <typename PixelRef, // models pixel concept 00031 typename PixelRefR> // models pixel concept 00032 struct pixel_assigns_t 00033 { 00034 GIL_FORCEINLINE 00035 PixelRefR& operator()( const PixelRef& src, 00036 PixelRefR& dst ) const 00037 { 00038 static_for_each( 00039 src, dst, 00040 channel_assigns_t<typename channel_type<PixelRef>::type, 00041 typename channel_type<PixelRefR>::type>() 00042 ); 00043 return dst; 00044 } 00045 }; 00046 00047 template <typename PixelRef, // models pixel concept 00048 typename PixelRefR = PixelRef> // models pixel concept 00049 struct pixel_assigns_color_t 00050 { 00051 PixelRefR _color; 00052 00053 pixel_assigns_color_t( const PixelRef& color ) 00054 : _color( color ) 00055 {} 00056 00057 GIL_FORCEINLINE 00058 PixelRefR& operator()( PixelRefR& dst ) const 00059 { 00060 static_for_each( 00061 _color, dst, 00062 channel_assigns_t<typename channel_type<PixelRef>::type, 00063 typename channel_type<PixelRefR>::type>() 00064 ); 00065 return dst; 00066 } 00067 }; 00068 00069 template <typename Pixel, // models pixel concept 00070 typename PixelR> // models pixel concept 00071 GIL_FORCEINLINE 00072 void pixel_assigns(const Pixel& src, Pixel& dst) 00073 { 00074 pixel_assigns_t<Pixel,PixelR>()( src, dst ); 00075 } 00076 00077 00078 /// \ingroup PixelNumericOperations 00079 ///definition and a generic implementation for casting and assigning a pixel to another 00080 ///user should specialize it for better performance 00081 template <typename Scalar, // models pixel concept 00082 typename PixelR> // models pixel concept 00083 struct pixel_assigns_scalar_t 00084 { 00085 GIL_FORCEINLINE 00086 PixelR& operator()( const Scalar s, 00087 PixelR& dst ) const 00088 { 00089 static_for_each( 00090 dst, 00091 std::bind1st( channel_assigns_t<Scalar, typename channel_type<PixelR>::type>(), s ) 00092 ); 00093 return dst; 00094 } 00095 }; 00096 00097 template< typename Scalar, // models pixel concept 00098 typename PixelR > // models pixel concept 00099 GIL_FORCEINLINE 00100 void pixel_assigns_scalar( const Scalar s, PixelR& dst ) 00101 { 00102 pixel_assigns_scalar_t<Scalar,PixelR>()( s, dst ); 00103 } 00104 00105 00106 template< typename SrcIterator, typename DstIterator > 00107 GIL_FORCEINLINE 00108 DstIterator assign_pixels( SrcIterator src, SrcIterator src_end, DstIterator dst ) 00109 { 00110 algorithm::for_each( 00111 src, src_end, dst, 00112 pixel_assigns_t< typename pixel_proxy<typename std::iterator_traits<SrcIterator>::value_type>::type, 00113 typename pixel_proxy<typename std::iterator_traits<DstIterator>::value_type>::type >() 00114 ); 00115 00116 return dst + ( src_end - src ); 00117 } 00118 00119 00120 } 00121 } 00122 00123 #endif