Boost GIL


extension/dynamic_image/algorithm.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2005-2007 Adobe Systems Incorporated
3 //
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
7 //
8 #ifndef BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ALGORITHM_HPP
9 #define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ALGORITHM_HPP
10 
11 #include <boost/gil/extension/dynamic_image/any_image.hpp>
12 
13 #include <boost/gil/algorithm.hpp>
14 
15 #include <functional>
16 
25 
26 namespace boost { namespace gil {
27 
28 namespace detail {
29 
30 struct equal_pixels_fn : binary_operation_obj<equal_pixels_fn, bool>
31 {
32  template <typename V1, typename V2>
33  BOOST_FORCEINLINE
34  bool apply_compatible(V1 const& v1, V2 const& v2) const
35  {
36  return equal_pixels(v1, v2);
37  }
38 };
39 
40 } // namespace detail
41 
45 template <typename Types, typename View>
46 bool equal_pixels(any_image_view<Types> const& src, View const& dst)
47 {
48  return apply_operation(
49  src,
50  std::bind(detail::equal_pixels_fn(), std::placeholders::_1, dst));
51 }
52 
56 template <typename View, typename Types>
57 bool equal_pixels(View const& src, any_image_view<Types> const& dst)
58 {
59  return apply_operation(
60  dst,
61  std::bind(detail::equal_pixels_fn(), src, std::placeholders::_1));
62 }
63 
67 template <typename Types1, typename Types2>
69 {
70  return apply_operation(src, dst, detail::equal_pixels_fn());
71 }
72 
73 namespace detail {
74 
75 struct copy_pixels_fn : public binary_operation_obj<copy_pixels_fn>
76 {
77  template <typename View1, typename View2>
78  BOOST_FORCEINLINE
79  void apply_compatible(View1 const& src, View2 const& dst) const
80  {
81  copy_pixels(src,dst);
82  }
83 };
84 
85 } // namespace detail
86 
90 template <typename Types, typename View>
91 void copy_pixels(any_image_view<Types> const& src, View const& dst)
92 {
93  apply_operation(src, std::bind(detail::copy_pixels_fn(), std::placeholders::_1, dst));
94 }
95 
99 template <typename Types, typename View>
100 void copy_pixels(View const& src, any_image_view<Types> const& dst)
101 {
102  apply_operation(dst, std::bind(detail::copy_pixels_fn(), src, std::placeholders::_1));
103 }
104 
108 template <typename Types1, typename Types2>
110 {
111  apply_operation(src, dst, detail::copy_pixels_fn());
112 }
113 
114 //forward declaration for default_color_converter (see full definition in color_convert.hpp)
115 struct default_color_converter;
116 
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)
123 {
124  using cc_fn = detail::copy_and_convert_pixels_fn<CC>;
125  apply_operation(src, std::bind(cc_fn{cc}, std::placeholders::_1, dst));
126 }
127 
131 template <typename Types, typename View>
132 void copy_and_convert_pixels(any_image_view<Types> const& src, View const& dst)
133 {
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));
136 }
137 
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)
144 {
145  using cc_fn = detail::copy_and_convert_pixels_fn<CC>;
146  apply_operation(dst, std::bind(cc_fn{cc}, src, std::placeholders::_1));
147 }
148 
152 template <typename View, typename Types>
153 void copy_and_convert_pixels(View const& src, any_image_view<Types> const& dst)
154 {
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));
157 }
158 
163 template <typename Types1, typename Types2, typename CC>
165  any_image_view<Types1> const& src,
166  any_image_view<Types2> const& dst, CC cc)
167 {
168  apply_operation(src, dst, detail::copy_and_convert_pixels_fn<CC>(cc));
169 }
170 
174 template <typename Types1, typename Types2>
176  any_image_view<Types1> const& src,
177  any_image_view<Types2> const& dst)
178 {
179  apply_operation(src, dst,
180  detail::copy_and_convert_pixels_fn<default_color_converter>());
181 }
182 
183 namespace detail {
184 
185 template <bool IsCompatible>
186 struct fill_pixels_fn1
187 {
188  template <typename V, typename Value>
189  static void apply(V const &src, Value const &val) { fill_pixels(src, val); }
190 };
191 
192 // copy_pixels invoked on incompatible images
193 template <>
194 struct fill_pixels_fn1<false>
195 {
196  template <typename V, typename Value>
197  static void apply(V const &, Value const &) { throw std::bad_cast();}
198 };
199 
200 template <typename Value>
201 struct fill_pixels_fn
202 {
203  fill_pixels_fn(Value const& val) : val_(val) {}
204 
205  using result_type = void;
206  template <typename V>
207  result_type operator()(V const& view) const
208  {
209  fill_pixels_fn1
210  <
211  pixels_are_compatible
212  <
213  typename V::value_type,
214  Value
215  >::value
216  >::apply(view, val_);
217  }
218 
219  Value val_;
220 };
221 
222 } // namespace detail
223 
227 template <typename Types, typename Value>
228 void fill_pixels(any_image_view<Types> const& view, Value const& val)
229 {
230  apply_operation(view, detail::fill_pixels_fn<Value>(val));
231 }
232 
233 }} // namespace boost::gil
234 
235 #endif
void copy_pixels(any_image_view< Types1 > const &src, any_image_view< Types2 > const &dst)
Definition: extension/dynamic_image/algorithm.hpp:109
BOOST_FORCEINLINE auto apply_operation(variant< Types > &arg, UnaryOp op)
Invokes a generic mutable operation (represented as a unary function object) on a variant.
Definition: apply_operation.hpp:33
void fill_pixels(any_image_view< Types > const &view, Value const &val)
fill_pixels for any image view. The pixel to fill with must be compatible with the current view
Definition: extension/dynamic_image/algorithm.hpp:228
Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeCon...
Definition: any_image_view.hpp:66
const image< Pixel, IsPlanar, Alloc >::view_t & view(image< Pixel, IsPlanar, Alloc > &img)
Returns the non-constant-pixel view of an image.
Definition: image.hpp:443
bool equal_pixels(any_image_view< Types1 > const &src, any_image_view< Types2 > const &dst)
Definition: extension/dynamic_image/algorithm.hpp:68
void copy_and_convert_pixels(any_image_view< Types1 > const &src, any_image_view< Types2 > const &dst)
Definition: extension/dynamic_image/algorithm.hpp:175