2 // Copyright 2005-2007 Adobe Systems Incorporated
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 #ifndef BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ALGORITHM_HPP
9 #define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ALGORITHM_HPP
11 #include <boost/gil/extension/dynamic_image/any_image.hpp>
13 #include <boost/gil/algorithm.hpp>
17 ////////////////////////////////////////////////////////////////////////////////////////
19 /// \brief Some basic STL-style algorithms when applied to runtime type specified image views
20 /// \author Lubomir Bourdev and Hailin Jin \n
21 /// Adobe Systems Incorporated
22 /// \date 2005-2007 \n Last updated on September 24, 2006
24 ////////////////////////////////////////////////////////////////////////////////////////
26 namespace boost { namespace gil {
30 struct equal_pixels_fn : binary_operation_obj<equal_pixels_fn, bool>
32 template <typename V1, typename V2>
34 bool apply_compatible(V1 const& v1, V2 const& v2) const
36 return equal_pixels(v1, v2);
42 /// \ingroup ImageViewSTLAlgorithmsEqualPixels
43 /// \tparam Types Model Boost.MP11-compatible list of models of ImageViewConcept
44 /// \tparam View Model MutableImageViewConcept
45 template <typename Types, typename View>
46 bool equal_pixels(any_image_view<Types> const& src, View const& dst)
48 return apply_operation(
50 std::bind(detail::equal_pixels_fn(), std::placeholders::_1, dst));
53 /// \ingroup ImageViewSTLAlgorithmsEqualPixels
54 /// \tparam View Model ImageViewConcept
55 /// \tparam Types Model Boost.MP11-compatible list of models of MutableImageViewConcept
56 template <typename View, typename Types>
57 bool equal_pixels(View const& src, any_image_view<Types> const& dst)
59 return apply_operation(
61 std::bind(detail::equal_pixels_fn(), src, std::placeholders::_1));
64 /// \ingroup ImageViewSTLAlgorithmsEqualPixels
65 /// \tparam Types1 Model Boost.MP11-compatible list of models of ImageViewConcept
66 /// \tparam Types2 Model Boost.MP11-compatible list of models of MutableImageViewConcept
67 template <typename Types1, typename Types2>
68 bool equal_pixels(any_image_view<Types1> const& src, any_image_view<Types2> const& dst)
70 return apply_operation(src, dst, detail::equal_pixels_fn());
75 struct copy_pixels_fn : public binary_operation_obj<copy_pixels_fn>
77 template <typename View1, typename View2>
79 void apply_compatible(View1 const& src, View2 const& dst) const
87 /// \ingroup ImageViewSTLAlgorithmsCopyPixels
88 /// \tparam Types Model Boost.MP11-compatible list of models of ImageViewConcept
89 /// \tparam View Model MutableImageViewConcept
90 template <typename Types, typename View>
91 void copy_pixels(any_image_view<Types> const& src, View const& dst)
93 apply_operation(src, std::bind(detail::copy_pixels_fn(), std::placeholders::_1, dst));
96 /// \ingroup ImageViewSTLAlgorithmsCopyPixels
97 /// \tparam Types Model Boost.MP11-compatible list of models of MutableImageViewConcept
98 /// \tparam View Model ImageViewConcept
99 template <typename Types, typename View>
100 void copy_pixels(View const& src, any_image_view<Types> const& dst)
102 apply_operation(dst, std::bind(detail::copy_pixels_fn(), src, std::placeholders::_1));
105 /// \ingroup ImageViewSTLAlgorithmsCopyPixels
106 /// \tparam Types1 Model Boost.MP11-compatible list of models of ImageViewConcept
107 /// \tparam Types2 Model Boost.MP11-compatible list of models of MutableImageViewConcept
108 template <typename Types1, typename Types2>
109 void copy_pixels(any_image_view<Types1> const& src, any_image_view<Types2> const& dst)
111 apply_operation(src, dst, detail::copy_pixels_fn());
114 //forward declaration for default_color_converter (see full definition in color_convert.hpp)
115 struct default_color_converter;
117 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
118 /// \tparam Types Model Boost.MP11-compatible list of models of ImageViewConcept
119 /// \tparam View Model MutableImageViewConcept
120 /// \tparam CC Model ColorConverterConcept
121 template <typename Types, typename View, typename CC>
122 void copy_and_convert_pixels(any_image_view<Types> const& src, View const& dst, CC cc)
124 using cc_fn = detail::copy_and_convert_pixels_fn<CC>;
125 apply_operation(src, std::bind(cc_fn{cc}, std::placeholders::_1, dst));
128 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
129 /// \tparam Types Model Boost.MP11-compatible list of models of ImageViewConcept
130 /// \tparam View Model MutableImageViewConcept
131 template <typename Types, typename View>
132 void copy_and_convert_pixels(any_image_view<Types> const& src, View const& dst)
134 using cc_fn = detail::copy_and_convert_pixels_fn<default_color_converter>;
135 apply_operation(src, std::bind(cc_fn{}, std::placeholders::_1, dst));
138 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
139 /// \tparam View Model ImageViewConcept
140 /// \tparam Types Model Boost.MP11-compatible list of models of MutableImageViewConcept
141 /// \tparam CC Model ColorConverterConcept
142 template <typename View, typename Types, typename CC>
143 void copy_and_convert_pixels(View const& src, any_image_view<Types> const& dst, CC cc)
145 using cc_fn = detail::copy_and_convert_pixels_fn<CC>;
146 apply_operation(dst, std::bind(cc_fn{cc}, src, std::placeholders::_1));
149 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
150 /// \tparam View Model ImageViewConcept
151 /// \tparam Type Model Boost.MP11-compatible list of models of MutableImageViewConcept
152 template <typename View, typename Types>
153 void copy_and_convert_pixels(View const& src, any_image_view<Types> const& dst)
155 using cc_fn = detail::copy_and_convert_pixels_fn<default_color_converter>;
156 apply_operation(dst, std::bind(cc_fn{}, src, std::placeholders::_1));
159 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
160 /// \tparam Types1 Model Boost.MP11-compatible list of models of ImageViewConcept
161 /// \tparam Types2 Model Boost.MP11-compatible list of models of MutableImageViewConcept
162 /// \tparam CC Model ColorConverterConcept
163 template <typename Types1, typename Types2, typename CC>
164 void copy_and_convert_pixels(
165 any_image_view<Types1> const& src,
166 any_image_view<Types2> const& dst, CC cc)
168 apply_operation(src, dst, detail::copy_and_convert_pixels_fn<CC>(cc));
171 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
172 /// \tparam Types1 Model Boost.MP11-compatible list of models of ImageViewConcept
173 /// \tparam Types2 Model Boost.MP11-compatible list of models of MutableImageViewConcept
174 template <typename Types1, typename Types2>
175 void copy_and_convert_pixels(
176 any_image_view<Types1> const& src,
177 any_image_view<Types2> const& dst)
179 apply_operation(src, dst,
180 detail::copy_and_convert_pixels_fn<default_color_converter>());
185 template <bool IsCompatible>
186 struct fill_pixels_fn1
188 template <typename V, typename Value>
189 static void apply(V const &src, Value const &val) { fill_pixels(src, val); }
192 // copy_pixels invoked on incompatible images
194 struct fill_pixels_fn1<false>
196 template <typename V, typename Value>
197 static void apply(V const &, Value const &) { throw std::bad_cast();}
200 template <typename Value>
201 struct fill_pixels_fn
203 fill_pixels_fn(Value const& val) : val_(val) {}
205 using result_type = void;
206 template <typename V>
207 result_type operator()(V const& view) const
211 pixels_are_compatible
213 typename V::value_type,
216 >::apply(view, val_);
222 } // namespace detail
224 /// \ingroup ImageViewSTLAlgorithmsFillPixels
225 /// \brief fill_pixels for any image view. The pixel to fill with must be compatible with the current view
226 /// \tparam Types Model Boost.MP11-compatible list of models of MutableImageViewConcept
227 template <typename Types, typename Value>
228 void fill_pixels(any_image_view<Types> const& view, Value const& val)
230 apply_operation(view, detail::fill_pixels_fn<Value>(val));
233 }} // namespace boost::gil