File indexing completed on 2025-01-18 09:37:05
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_GIL_CHANNEL_NUMERIC_OPERATIONS_HPP
0010 #define BOOST_GIL_CHANNEL_NUMERIC_OPERATIONS_HPP
0011
0012 #include <boost/gil/channel.hpp>
0013
0014 namespace boost { namespace gil {
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 template <typename Channel1, typename Channel2, typename ChannelResult>
0035 struct channel_plus_t
0036 {
0037 using ChannelRef1 = typename channel_traits<Channel1>::const_reference;
0038 using ChannelRef2 = typename channel_traits<Channel2>::const_reference;
0039 static_assert(std::is_convertible<ChannelRef1, ChannelResult>::value,
0040 "ChannelRef1 not convertible to ChannelResult");
0041 static_assert(std::is_convertible<ChannelRef2, ChannelResult>::value,
0042 "ChannelRef2 not convertible to ChannelResult");
0043
0044
0045
0046 auto operator()(ChannelRef1 ch1, ChannelRef2 ch2) const -> ChannelResult
0047 {
0048 return ChannelResult(ch1) + ChannelResult(ch2);
0049 }
0050 };
0051
0052
0053
0054
0055 template <typename Channel1, typename Channel2, typename ChannelResult>
0056 struct channel_minus_t
0057 {
0058 using ChannelRef1 = typename channel_traits<Channel1>::const_reference;
0059 using ChannelRef2 = typename channel_traits<Channel2>::const_reference;
0060 static_assert(std::is_convertible<ChannelRef1, ChannelResult>::value,
0061 "ChannelRef1 not convertible to ChannelResult");
0062 static_assert(std::is_convertible<ChannelRef2, ChannelResult>::value,
0063 "ChannelRef2 not convertible to ChannelResult");
0064
0065
0066
0067 auto operator()(ChannelRef1 ch1, ChannelRef2 ch2) const -> ChannelResult
0068 {
0069 return ChannelResult(ch1) - ChannelResult(ch2);
0070 }
0071 };
0072
0073
0074
0075
0076 template <typename Channel1, typename Channel2, typename ChannelResult>
0077 struct channel_multiplies_t
0078 {
0079 using ChannelRef1 = typename channel_traits<Channel1>::const_reference;
0080 using ChannelRef2 = typename channel_traits<Channel2>::const_reference;
0081 static_assert(std::is_convertible<ChannelRef1, ChannelResult>::value,
0082 "ChannelRef1 not convertible to ChannelResult");
0083 static_assert(std::is_convertible<ChannelRef2, ChannelResult>::value,
0084 "ChannelRef2 not convertible to ChannelResult");
0085
0086
0087
0088 auto operator()(ChannelRef1 ch1, ChannelRef2 ch2) const -> ChannelResult
0089 {
0090 return ChannelResult(ch1) * ChannelResult(ch2);
0091 }
0092 };
0093
0094
0095
0096
0097 template <typename Channel1, typename Channel2, typename ChannelResult>
0098 struct channel_divides_t
0099 {
0100 using ChannelRef1 = typename channel_traits<Channel1>::const_reference;
0101 using ChannelRef2 = typename channel_traits<Channel2>::const_reference;
0102 static_assert(std::is_convertible<ChannelRef1, ChannelResult>::value,
0103 "ChannelRef1 not convertible to ChannelResult");
0104 static_assert(std::is_convertible<ChannelRef2, ChannelResult>::value,
0105 "ChannelRef2 not convertible to ChannelResult");
0106
0107
0108
0109 auto operator()(ChannelRef1 ch1, ChannelRef2 ch2) const -> ChannelResult
0110 {
0111 return ChannelResult(ch1) / ChannelResult(ch2);
0112 }
0113 };
0114
0115
0116
0117
0118 template <typename Channel, typename Scalar, typename ChannelResult>
0119 struct channel_plus_scalar_t
0120 {
0121 using ChannelRef = typename channel_traits<Channel>::const_reference;
0122 static_assert(std::is_convertible<ChannelRef, ChannelResult>::value,
0123 "ChannelRef not convertible to ChannelResult");
0124 static_assert(std::is_scalar<Scalar>::value, "Scalar not a scalar");
0125 static_assert(std::is_convertible<Scalar, ChannelResult>::value,
0126 "Scalar not convertible to ChannelResult");
0127
0128 auto operator()(ChannelRef channel, Scalar const& scalar) const -> ChannelResult
0129 {
0130 return ChannelResult(channel) + ChannelResult(scalar);
0131 }
0132 };
0133
0134
0135
0136
0137 template <typename Channel, typename Scalar, typename ChannelResult>
0138 struct channel_minus_scalar_t
0139 {
0140 using ChannelRef = typename channel_traits<Channel>::const_reference;
0141 static_assert(std::is_convertible<ChannelRef, ChannelResult>::value,
0142 "ChannelRef not convertible to ChannelResult");
0143 static_assert(std::is_scalar<Scalar>::value, "Scalar not a scalar");
0144 static_assert(std::is_convertible<Scalar, ChannelResult>::value,
0145 "Scalar not convertible to ChannelResult");
0146
0147
0148
0149 auto operator()(ChannelRef channel, Scalar const& scalar) const -> ChannelResult
0150 {
0151
0152 return ChannelResult(channel - scalar);
0153 }
0154 };
0155
0156
0157
0158
0159 template <typename Channel, typename Scalar, typename ChannelResult>
0160 struct channel_multiplies_scalar_t
0161 {
0162 using ChannelRef = typename channel_traits<Channel>::const_reference;
0163 static_assert(std::is_convertible<ChannelRef, ChannelResult>::value,
0164 "ChannelRef not convertible to ChannelResult");
0165 static_assert(std::is_scalar<Scalar>::value, "Scalar not a scalar");
0166 static_assert(std::is_convertible<Scalar, ChannelResult>::value,
0167 "Scalar not convertible to ChannelResult");
0168
0169
0170
0171 auto operator()(ChannelRef channel, Scalar const& scalar) const -> ChannelResult
0172 {
0173 return ChannelResult(channel) * ChannelResult(scalar);
0174 }
0175 };
0176
0177
0178
0179
0180 template <typename Channel, typename Scalar, typename ChannelResult>
0181 struct channel_divides_scalar_t
0182 {
0183 using ChannelRef = typename channel_traits<Channel>::const_reference;
0184 static_assert(std::is_convertible<ChannelRef, ChannelResult>::value,
0185 "ChannelRef not convertible to ChannelResult");
0186 static_assert(std::is_scalar<Scalar>::value, "Scalar not a scalar");
0187 static_assert(std::is_convertible<Scalar, ChannelResult>::value,
0188 "Scalar not convertible to ChannelResult");
0189
0190
0191
0192 auto operator()(ChannelRef channel, Scalar const& scalar) const -> ChannelResult
0193 {
0194 return ChannelResult(channel) / ChannelResult(scalar);
0195 }
0196 };
0197
0198
0199
0200
0201 template <typename Channel>
0202 struct channel_halves_t
0203 {
0204 using ChannelRef = typename channel_traits<Channel>::reference;
0205
0206 auto operator()(ChannelRef channel) const -> ChannelRef
0207 {
0208
0209
0210
0211 channel /= 2.0;
0212 return channel;
0213 }
0214 };
0215
0216
0217
0218
0219 template <typename Channel>
0220 struct channel_zeros_t
0221 {
0222 using ChannelRef = typename channel_traits<Channel>::reference;
0223
0224 auto operator()(ChannelRef channel) const -> ChannelRef
0225 {
0226 channel = Channel(0);
0227 return channel;
0228 }
0229 };
0230
0231
0232
0233
0234 template <typename Channel1, typename Channel2>
0235 struct channel_assigns_t
0236 {
0237 using ChannelRef1 = typename channel_traits<Channel1>::const_reference;
0238 using ChannelRef2 = typename channel_traits<Channel2>::reference;
0239 static_assert(std::is_convertible<ChannelRef1, Channel2>::value,
0240 "ChannelRef1 not convertible to Channel2");
0241
0242
0243
0244 auto operator()(ChannelRef1 ch1, ChannelRef2 ch2) const -> ChannelRef2
0245 {
0246 ch2 = Channel2(ch1);
0247 return ch2;
0248 }
0249 };
0250
0251 }}
0252
0253 #endif