File indexing completed on 2025-01-18 09:36:55
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ALGORITHM_HPP
0010 #define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ALGORITHM_HPP
0011
0012 #include <boost/gil/extension/dynamic_image/any_image.hpp>
0013
0014 #include <boost/gil/algorithm.hpp>
0015
0016 #include <boost/variant2/variant.hpp>
0017
0018 #include <functional>
0019 #include <utility>
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 namespace boost { namespace gil {
0031
0032 namespace detail {
0033
0034 struct equal_pixels_fn : binary_operation_obj<equal_pixels_fn, bool>
0035 {
0036 template <typename V1, typename V2>
0037 BOOST_FORCEINLINE
0038 bool apply_compatible(V1 const& v1, V2 const& v2) const
0039 {
0040 return equal_pixels(v1, v2);
0041 }
0042 };
0043
0044 }
0045
0046
0047
0048
0049 template <typename ...Types, typename View>
0050 auto equal_pixels(any_image_view<Types...> const& src, View const& dst) -> bool
0051 {
0052 return variant2::visit(
0053 std::bind(detail::equal_pixels_fn(), std::placeholders::_1, dst),
0054 src);
0055 }
0056
0057
0058
0059
0060 template <typename View, typename ...Types>
0061 auto equal_pixels(View const& src, any_image_view<Types...> const& dst) -> bool
0062 {
0063 return variant2::visit(
0064 std::bind(detail::equal_pixels_fn(), src, std::placeholders::_1),
0065 dst);
0066 }
0067
0068
0069
0070
0071 template <typename ...Types1, typename ...Types2>
0072 auto equal_pixels(any_image_view<Types1...> const& src, any_image_view<Types2...> const& dst) -> bool
0073 {
0074 return variant2::visit(detail::equal_pixels_fn(), src, dst);
0075 }
0076
0077 namespace detail {
0078
0079 struct copy_pixels_fn : public binary_operation_obj<copy_pixels_fn>
0080 {
0081 template <typename View1, typename View2>
0082 BOOST_FORCEINLINE
0083 void apply_compatible(View1 const& src, View2 const& dst) const
0084 {
0085 copy_pixels(src,dst);
0086 }
0087 };
0088
0089 }
0090
0091
0092
0093
0094 template <typename ...Types, typename View>
0095 void copy_pixels(any_image_view<Types...> const& src, View const& dst)
0096 {
0097 variant2::visit(std::bind(detail::copy_pixels_fn(), std::placeholders::_1, dst), src);
0098 }
0099
0100
0101
0102
0103 template <typename ...Types, typename View>
0104 void copy_pixels(View const& src, any_image_view<Types...> const& dst)
0105 {
0106 variant2::visit(std::bind(detail::copy_pixels_fn(), src, std::placeholders::_1), dst);
0107 }
0108
0109
0110
0111
0112 template <typename ...Types1, typename ...Types2>
0113 void copy_pixels(any_image_view<Types1...> const& src, any_image_view<Types2...> const& dst)
0114 {
0115 variant2::visit(detail::copy_pixels_fn(), src, dst);
0116 }
0117
0118
0119 struct default_color_converter;
0120
0121
0122
0123
0124
0125 template <typename ...Types, typename View, typename CC>
0126 void copy_and_convert_pixels(any_image_view<Types...> const& src, View const& dst, CC cc)
0127 {
0128 using cc_fn = detail::copy_and_convert_pixels_fn<CC>;
0129 variant2::visit(std::bind(cc_fn{cc}, std::placeholders::_1, dst), src);
0130 }
0131
0132
0133
0134
0135 template <typename ...Types, typename View>
0136 void copy_and_convert_pixels(any_image_view<Types...> const& src, View const& dst)
0137 {
0138 using cc_fn = detail::copy_and_convert_pixels_fn<default_color_converter>;
0139 variant2::visit(std::bind(cc_fn{}, std::placeholders::_1, dst), src);
0140 }
0141
0142
0143
0144
0145
0146 template <typename View, typename ...Types, typename CC>
0147 void copy_and_convert_pixels(View const& src, any_image_view<Types...> const& dst, CC cc)
0148 {
0149 using cc_fn = detail::copy_and_convert_pixels_fn<CC>;
0150 variant2::visit(std::bind(cc_fn{cc}, src, std::placeholders::_1), dst);
0151 }
0152
0153
0154
0155
0156 template <typename View, typename ...Types>
0157 void copy_and_convert_pixels(View const& src, any_image_view<Types...> const& dst)
0158 {
0159 using cc_fn = detail::copy_and_convert_pixels_fn<default_color_converter>;
0160 variant2::visit(std::bind(cc_fn{}, src, std::placeholders::_1), dst);
0161 }
0162
0163
0164
0165
0166
0167 template <typename ...Types1, typename ...Types2, typename CC>
0168 void copy_and_convert_pixels(
0169 any_image_view<Types1...> const& src,
0170 any_image_view<Types2...> const& dst, CC cc)
0171 {
0172 variant2::visit(detail::copy_and_convert_pixels_fn<CC>(cc), src, dst);
0173 }
0174
0175
0176
0177
0178 template <typename ...Types1, typename ...Types2>
0179 void copy_and_convert_pixels(
0180 any_image_view<Types1...> const& src,
0181 any_image_view<Types2...> const& dst)
0182 {
0183 variant2::visit(
0184 detail::copy_and_convert_pixels_fn<default_color_converter>(), src, dst);
0185 }
0186
0187 namespace detail {
0188
0189 template <bool IsCompatible>
0190 struct fill_pixels_fn1
0191 {
0192 template <typename V, typename Value>
0193 static void apply(V const& src, Value const& val) { fill_pixels(src, val); }
0194 };
0195
0196
0197 template <>
0198 struct fill_pixels_fn1<false>
0199 {
0200 template <typename V, typename Value>
0201 static void apply(V const&, Value const&) { throw std::bad_cast();}
0202 };
0203
0204 template <typename Value>
0205 struct fill_pixels_fn
0206 {
0207 fill_pixels_fn(Value const& val) : val_(val) {}
0208
0209 using result_type = void;
0210 template <typename V>
0211 result_type operator()(V const& view) const
0212 {
0213 fill_pixels_fn1
0214 <
0215 pixels_are_compatible
0216 <
0217 typename V::value_type,
0218 Value
0219 >::value
0220 >::apply(view, val_);
0221 }
0222
0223 Value val_;
0224 };
0225
0226 }
0227
0228
0229
0230
0231 template <typename ...Types, typename Value>
0232 void fill_pixels(any_image_view<Types...> const& view, Value const& val)
0233 {
0234 variant2::visit(detail::fill_pixels_fn<Value>(val), view);
0235 }
0236
0237 namespace detail {
0238
0239 template <typename F>
0240 struct for_each_pixel_fn
0241 {
0242 for_each_pixel_fn(F&& fun) : fun_(std::move(fun)) {}
0243
0244 template <typename View>
0245 auto operator()(View const& view) -> F
0246 {
0247 return for_each_pixel(view, fun_);
0248 }
0249
0250 F fun_;
0251 };
0252
0253 }
0254
0255
0256
0257
0258
0259
0260 template <typename ...Types, typename F>
0261 auto for_each_pixel(any_image_view<Types...> const& view, F fun) -> F
0262 {
0263 return variant2::visit(detail::for_each_pixel_fn<F>(std::move(fun)), view);
0264 }
0265
0266 }}
0267
0268 #endif