TuttleOFX
1
|
00001 #ifndef _TERRY_NUMERIC_OPERATIONS_ASSIGN_HPP_ 00002 #define _TERRY_NUMERIC_OPERATIONS_ASSIGN_HPP_ 00003 00004 #include <boost/gil/gil_config.hpp> 00005 #include <boost/gil/channel.hpp> 00006 #include <boost/gil/pixel_iterator.hpp> 00007 00008 #include <functional> 00009 00010 namespace terry { 00011 using namespace boost::gil; 00012 00013 namespace numeric { 00014 00015 00016 /// \ingroup ChannelNumericOperations 00017 /// \brief ch2 += ch1 00018 /// structure for adding one channel to another 00019 /// this is a generic implementation; user should specialize it for better performance 00020 template <typename ChannelSrc,typename ChannelDst> 00021 struct channel_plus_assign_t : public std::binary_function<ChannelSrc,ChannelDst,ChannelDst> 00022 { 00023 GIL_FORCEINLINE 00024 typename channel_traits<ChannelDst>::reference 00025 operator()( typename channel_traits<ChannelSrc>::const_reference ch1, 00026 typename channel_traits<ChannelDst>::reference ch2 ) const 00027 { 00028 return ch2 += ChannelDst( ch1 ); 00029 } 00030 }; 00031 00032 /// \ingroup PixelNumericOperations 00033 /// \brief p2 += p1 00034 template <typename PixelSrc, // models pixel concept 00035 typename PixelDst = PixelSrc> // models pixel concept 00036 struct pixel_plus_assign_t 00037 { 00038 GIL_FORCEINLINE 00039 PixelDst& operator()( const PixelSrc& p1, 00040 PixelDst& p2 ) const 00041 { 00042 static_for_each( p1, p2, 00043 channel_plus_assign_t<typename channel_type<PixelSrc>::type, 00044 typename channel_type<PixelDst>::type>() ); 00045 return p2; 00046 } 00047 }; 00048 00049 /// \ingroup ChannelNumericOperations 00050 /// \brief ch2 -= ch1 00051 /// structure for subtracting one channel from another 00052 /// this is a generic implementation; user should specialize it for better performance 00053 template <typename ChannelSrc,typename ChannelDst> 00054 struct channel_minus_assign_t : public std::binary_function<ChannelSrc,ChannelDst,ChannelDst> 00055 { 00056 GIL_FORCEINLINE 00057 typename channel_traits<ChannelDst>::reference 00058 operator()( typename channel_traits<ChannelSrc>::const_reference ch1, 00059 typename channel_traits<ChannelDst>::reference ch2 ) const 00060 { 00061 return ch2 -= ChannelDst( ch1 ); 00062 } 00063 }; 00064 00065 /// \ingroup PixelNumericOperations 00066 /// \brief p2 -= p1 00067 template <typename PixelSrc, // models pixel concept 00068 typename PixelDst = PixelSrc> // models pixel concept 00069 struct pixel_minus_assign_t 00070 { 00071 GIL_FORCEINLINE 00072 PixelDst& operator()( const PixelSrc& p1, 00073 PixelDst& p2 ) const 00074 { 00075 static_for_each( p1, p2, 00076 channel_minus_assign_t<typename channel_type<PixelSrc>::type, 00077 typename channel_type<PixelDst>::type>() ); 00078 return p2; 00079 } 00080 }; 00081 00082 /// \ingroup ChannelNumericOperations 00083 /// \brief ch2 *= ch1 00084 /// structure for multiplying one channel to another 00085 /// this is a generic implementation; user should specialize it for better performance 00086 template <typename ChannelSrc,typename ChannelDst> 00087 struct channel_multiplies_assign_t : public std::binary_function<ChannelSrc,ChannelDst,ChannelDst> 00088 { 00089 GIL_FORCEINLINE 00090 typename channel_traits<ChannelDst>::reference 00091 operator()( typename channel_traits<ChannelSrc>::const_reference ch1, 00092 typename channel_traits<ChannelDst>::reference ch2 ) const 00093 { 00094 return ch2 *= ch1; 00095 } 00096 }; 00097 00098 /// \ingroup ChannelNumericOperations 00099 /// \brief ch2 /= ch1 00100 /// structure for dividing channels 00101 /// this is a generic implementation; user should specialize it for better performance 00102 template <typename ChannelSrc,typename ChannelDst> 00103 struct channel_divides_assign_t : public std::binary_function<ChannelSrc,ChannelDst,ChannelDst> 00104 { 00105 GIL_FORCEINLINE 00106 typename channel_traits<ChannelDst>::reference 00107 operator()( typename channel_traits<ChannelSrc>::const_reference ch1, 00108 typename channel_traits<ChannelDst>::reference ch2 ) const 00109 { 00110 return ch2 /= ch1; 00111 } 00112 }; 00113 00114 00115 /// \ingroup ChannelNumericOperations 00116 /// \brief ch += s 00117 /// structure for adding a scalar to a channel 00118 /// this is a generic implementation; user should specialize it for better performance 00119 template <typename Scalar, typename ChannelDst> 00120 struct channel_plus_scalar_assign_t : public std::binary_function<Scalar,ChannelDst,ChannelDst> 00121 { 00122 GIL_FORCEINLINE 00123 typename channel_traits<ChannelDst>::reference 00124 operator()( const Scalar s, 00125 typename channel_traits<ChannelDst>::reference ch ) const 00126 { 00127 return ch += ChannelDst(s); 00128 } 00129 }; 00130 00131 /// \ingroup ChannelNumericOperations 00132 /// \brief ch -= s 00133 /// structure for subtracting a scalar from a channel 00134 /// this is a generic implementation; user should specialize it for better performance 00135 template <typename Scalar, typename ChannelDst> 00136 struct channel_minus_scalar_assign_t : public std::binary_function<Scalar,ChannelDst,ChannelDst> 00137 { 00138 GIL_FORCEINLINE 00139 typename channel_traits<ChannelDst>::reference 00140 operator()( const Scalar s, 00141 typename channel_traits<ChannelDst>::reference ch ) const 00142 { 00143 return ch -= ChannelDst(s); 00144 } 00145 }; 00146 00147 /// \ingroup ChannelNumericOperations 00148 /// \brief ch *= s 00149 /// structure for multiplying a scalar to one channel 00150 /// this is a generic implementation; user should specialize it for better performance 00151 template <typename Scalar, typename ChannelDst> 00152 struct channel_multiplies_scalar_assign_t : public std::binary_function<Scalar,ChannelDst,ChannelDst> 00153 { 00154 GIL_FORCEINLINE 00155 typename channel_traits<ChannelDst>::reference 00156 operator()( const Scalar s, 00157 typename channel_traits<ChannelDst>::reference ch ) const 00158 { 00159 return ch *= s; 00160 } 00161 }; 00162 00163 /// \ingroup PixelNumericOperations 00164 /// \brief p *= s 00165 template <typename Scalar, // models a scalar type 00166 typename PixelDst> // models pixel concept 00167 struct pixel_multiplies_scalar_assign_t 00168 { 00169 GIL_FORCEINLINE 00170 PixelDst& operator()( const Scalar s, 00171 PixelDst& p ) const 00172 { 00173 static_for_each( p, 00174 std::bind1st( channel_multiplies_scalar_assign_t<Scalar, typename channel_type<PixelDst>::type>(), s ) 00175 ); 00176 return p; 00177 } 00178 }; 00179 00180 /// \ingroup ChannelNumericOperations 00181 /// \brief ch /= s 00182 /// structure for dividing a channel by a scalar 00183 /// this is a generic implementation; user should specialize it for better performance 00184 template <typename Scalar, typename ChannelDst> 00185 struct channel_divides_scalar_assign_t : public std::binary_function<Scalar,ChannelDst,ChannelDst> 00186 { 00187 GIL_FORCEINLINE 00188 typename channel_traits<ChannelDst>::reference 00189 operator()( const Scalar s, 00190 typename channel_traits<ChannelDst>::reference ch ) const 00191 { 00192 return ch /= s; 00193 } 00194 }; 00195 00196 /// \ingroup PixelNumericOperations 00197 /// \brief p /= s 00198 template <typename Scalar, // models a scalar type 00199 typename PixelDst> // models pixel concept 00200 struct pixel_divides_scalar_assign_t 00201 { 00202 GIL_FORCEINLINE 00203 PixelDst& operator()( const Scalar s, 00204 PixelDst& p ) const 00205 { 00206 static_for_each( p, 00207 std::bind1st( channel_divides_scalar_assign_t<Scalar, typename channel_type<PixelDst>::type>(), s ) 00208 ); 00209 return p; 00210 } 00211 }; 00212 00213 } 00214 } 00215 00216 #endif