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 <boost/bind.hpp>
16 
25 
26 namespace boost { namespace gil {
27 
28 namespace detail {
29  struct equal_pixels_fn : public binary_operation_obj<equal_pixels_fn,bool> {
30  template <typename V1, typename V2>
31  BOOST_FORCEINLINE bool apply_compatible(const V1& v1, const V2& v2) const {
32  return equal_pixels(v1,v2);
33  }
34  };
35 } // namespace detail
36 
38 template <typename Types1, // Model MPL Random Access Container of models of ImageViewConcept
39  typename View2> // Model MutableImageViewConcept
40 bool equal_pixels(const any_image_view<Types1>& src, const View2& dst) {
41  return apply_operation(src,boost::bind(detail::equal_pixels_fn(), _1, dst));
42 }
43 
45 template <typename View1, // Model ImageViewConcept
46  typename Types2> // Model MPL Random Access Container of models of MutableImageViewConcept
47 bool equal_pixels(const View1& src, const any_image_view<Types2>& dst) {
48  return apply_operation(dst,boost::bind(detail::equal_pixels_fn(), src, _1));
49 }
50 
52 template <typename Types1, // Model MPL Random Access Container of models of ImageViewConcept
53  typename Types2> // Model MPL Random Access Container of models of MutableImageViewConcept
54 bool equal_pixels(const any_image_view<Types1>& src, const any_image_view<Types2>& dst) {
55  return apply_operation(src,dst,detail::equal_pixels_fn());
56 }
57 
58 namespace detail {
59  struct copy_pixels_fn : public binary_operation_obj<copy_pixels_fn> {
60  template <typename View1, typename View2>
61  BOOST_FORCEINLINE void apply_compatible(const View1& src, const View2& dst) const {
62  copy_pixels(src,dst);
63  }
64  };
65 }
66 
68 template <typename Types1, // Model MPL Random Access Container of models of ImageViewConcept
69  typename View2> // Model MutableImageViewConcept
70 void copy_pixels(const any_image_view<Types1>& src, const View2& dst) {
71  apply_operation(src,boost::bind(detail::copy_pixels_fn(), _1, dst));
72 }
73 
75 template <typename View1, // Model ImageViewConcept
76  typename Types2> // Model MPL Random Access Container of models of MutableImageViewConcept
77 void copy_pixels(const View1& src, const any_image_view<Types2>& dst) {
78  apply_operation(dst,boost::bind(detail::copy_pixels_fn(), src, _1));
79 }
80 
82 template <typename Types1, // Model MPL Random Access Container of models of ImageViewConcept
83  typename Types2> // Model MPL Random Access Container of models of MutableImageViewConcept
84 void copy_pixels(const any_image_view<Types1>& src, const any_image_view<Types2>& dst) {
85  apply_operation(src,dst,detail::copy_pixels_fn());
86 }
87 
88 
89 
90 //forward declaration for default_color_converter (see full definition in color_convert.hpp)
91 struct default_color_converter;
92 
94 template <typename Types1, // Model MPL Random Access Container of models of ImageViewConcept
95  typename View2, // Model MutableImageViewConcept
96  typename CC> // Model ColorConverterConcept
97 void copy_and_convert_pixels(const any_image_view<Types1>& src, const View2& dst, CC cc) {
98  apply_operation(src,boost::bind(detail::copy_and_convert_pixels_fn<CC>(cc), _1, dst));
99 }
100 
102 template <typename Types1, // Model MPL Random Access Container of models of ImageViewConcept
103  typename View2> // Model MutableImageViewConcept
104 void copy_and_convert_pixels(const any_image_view<Types1>& src, const View2& dst) {
105  apply_operation(src,boost::bind(detail::copy_and_convert_pixels_fn<default_color_converter>(), _1, dst));
106 }
107 
109 template <typename View1, // Model ImageViewConcept
110  typename Types2, // Model MPL Random Access Container of models of MutableImageViewConcept
111  typename CC> // Model ColorConverterConcept
112 void copy_and_convert_pixels(const View1& src, const any_image_view<Types2>& dst, CC cc) {
113  apply_operation(dst,boost::bind(detail::copy_and_convert_pixels_fn<CC>(cc), src, _1));
114 }
115 
117 template <typename View1, // Model ImageViewConcept
118  typename Types2> // Model MPL Random Access Container of models of MutableImageViewConcept
119 void copy_and_convert_pixels(const View1& src, const any_image_view<Types2>& dst) {
120  apply_operation(dst,boost::bind(detail::copy_and_convert_pixels_fn<default_color_converter>(), src, _1));
121 }
122 
124 template <typename Types1, // Model MPL Random Access Container of models of ImageViewConcept
125  typename Types2, // Model MPL Random Access Container of models of MutableImageViewConcept
126  typename CC> // Model ColorConverterConcept
127 void copy_and_convert_pixels(const any_image_view<Types1>& src, const any_image_view<Types2>& dst, CC cc) {
128  apply_operation(src,dst,detail::copy_and_convert_pixels_fn<CC>(cc));
129 }
130 
132 template <typename Types1, // Model MPL Random Access Container of models of ImageViewConcept
133  typename Types2> // Model MPL Random Access Container of models of MutableImageViewConcept
134 void copy_and_convert_pixels(const any_image_view<Types1>& src, const any_image_view<Types2>& dst) {
135  apply_operation(src,dst,detail::copy_and_convert_pixels_fn<default_color_converter>());
136 }
137 
138 namespace detail {
139 template <bool COMPATIBLE> struct fill_pixels_fn1 {
140  template <typename V, typename Value> static void apply(const V& src, const Value& val) { fill_pixels(src,val); }
141 };
142 
143 // copy_pixels invoked on incompatible images
144 template <> struct fill_pixels_fn1<false> {
145  template <typename V, typename Value> static void apply(const V&, const Value&) { throw std::bad_cast();}
146 };
147 
148 template <typename Value>
149 struct fill_pixels_fn {
150  fill_pixels_fn(const Value& val) : _val(val) {}
151 
152  typedef void result_type;
153  template <typename V> result_type operator()(const V& img_view) const {
154  fill_pixels_fn1<pixels_are_compatible<typename V::value_type, Value>::value>::apply(img_view,_val);
155  }
156  Value _val;
157 };
158 }
159 
162 template <typename Types, // Model MPL Random Access Container of models of MutableImageViewConcept
163  typename Value>
164 void fill_pixels(const any_image_view<Types>& img_view, const Value& val) {
165  apply_operation(img_view,detail::fill_pixels_fn<Value>(val));
166 }
167 
168 
169 }} // namespace boost::gil
170 
171 #endif
void fill_pixels(const any_image_view< Types > &img_view, const Value &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:164
BOOST_FORCEINLINE UnaryOp::result_type 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:31
BOOST_FORCEINLINE bool equal_pixels(const View1 &v1, const View2 &v2)
std::equal for image views
Definition: algorithm.hpp:937
BOOST_FORCEINLINE void copy_pixels(const View1 &src, const View2 &dst)
std::copy for image views
Definition: algorithm.hpp:270
Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeCon...
Definition: any_image_view.hpp:60