Boost GIL


extension/dynamic_image/algorithm.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2005-2007 Adobe Systems Incorporated
3 
4  Use, modification and distribution are subject to the Boost Software License,
5  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6  http://www.boost.org/LICENSE_1_0.txt).
7 
8  See http://opensource.adobe.com/gil for most recent version including documentation.
9 */
10 /*************************************************************************************************/
11 
12 #ifndef GIL_DYNAMICIMAGE_ALGORITHM_HPP
13 #define GIL_DYNAMICIMAGE_ALGORITHM_HPP
14 
15 #include "../../algorithm.hpp"
16 #include "any_image.hpp"
17 #include <boost/bind.hpp>
18 
27 
28 namespace boost { namespace gil {
29 
30 namespace detail {
31  struct equal_pixels_fn : public binary_operation_obj<equal_pixels_fn,bool> {
32  template <typename V1, typename V2>
33  BOOST_FORCEINLINE bool apply_compatible(const V1& v1, const V2& v2) const {
34  return equal_pixels(v1,v2);
35  }
36  };
37 } // namespace detail
38 
40 template <typename Types1, // Model MPL Random Access Container of models of ImageViewConcept
41  typename View2> // Model MutableImageViewConcept
42 bool equal_pixels(const any_image_view<Types1>& src, const View2& dst) {
43  return apply_operation(src,boost::bind(detail::equal_pixels_fn(), _1, dst));
44 }
45 
47 template <typename View1, // Model ImageViewConcept
48  typename Types2> // Model MPL Random Access Container of models of MutableImageViewConcept
49 bool equal_pixels(const View1& src, const any_image_view<Types2>& dst) {
50  return apply_operation(dst,boost::bind(detail::equal_pixels_fn(), src, _1));
51 }
52 
54 template <typename Types1, // Model MPL Random Access Container of models of ImageViewConcept
55  typename Types2> // Model MPL Random Access Container of models of MutableImageViewConcept
56 bool equal_pixels(const any_image_view<Types1>& src, const any_image_view<Types2>& dst) {
57  return apply_operation(src,dst,detail::equal_pixels_fn());
58 }
59 
60 namespace detail {
61  struct copy_pixels_fn : public binary_operation_obj<copy_pixels_fn> {
62  template <typename View1, typename View2>
63  BOOST_FORCEINLINE void apply_compatible(const View1& src, const View2& dst) const {
64  copy_pixels(src,dst);
65  }
66  };
67 }
68 
70 template <typename Types1, // Model MPL Random Access Container of models of ImageViewConcept
71  typename View2> // Model MutableImageViewConcept
72 void copy_pixels(const any_image_view<Types1>& src, const View2& dst) {
73  apply_operation(src,boost::bind(detail::copy_pixels_fn(), _1, dst));
74 }
75 
77 template <typename View1, // Model ImageViewConcept
78  typename Types2> // Model MPL Random Access Container of models of MutableImageViewConcept
79 void copy_pixels(const View1& src, const any_image_view<Types2>& dst) {
80  apply_operation(dst,boost::bind(detail::copy_pixels_fn(), src, _1));
81 }
82 
84 template <typename Types1, // Model MPL Random Access Container of models of ImageViewConcept
85  typename Types2> // Model MPL Random Access Container of models of MutableImageViewConcept
86 void copy_pixels(const any_image_view<Types1>& src, const any_image_view<Types2>& dst) {
87  apply_operation(src,dst,detail::copy_pixels_fn());
88 }
89 
90 
91 
92 //forward declaration for default_color_converter (see full definition in color_convert.hpp)
93 struct default_color_converter;
94 
96 template <typename Types1, // Model MPL Random Access Container of models of ImageViewConcept
97  typename View2, // Model MutableImageViewConcept
98  typename CC> // Model ColorConverterConcept
99 void copy_and_convert_pixels(const any_image_view<Types1>& src, const View2& dst, CC cc) {
100  apply_operation(src,boost::bind(detail::copy_and_convert_pixels_fn<CC>(cc), _1, dst));
101 }
102 
104 template <typename Types1, // Model MPL Random Access Container of models of ImageViewConcept
105  typename View2> // Model MutableImageViewConcept
106 void copy_and_convert_pixels(const any_image_view<Types1>& src, const View2& dst) {
107  apply_operation(src,boost::bind(detail::copy_and_convert_pixels_fn<default_color_converter>(), _1, dst));
108 }
109 
111 template <typename View1, // Model ImageViewConcept
112  typename Types2, // Model MPL Random Access Container of models of MutableImageViewConcept
113  typename CC> // Model ColorConverterConcept
114 void copy_and_convert_pixels(const View1& src, const any_image_view<Types2>& dst, CC cc) {
115  apply_operation(dst,boost::bind(detail::copy_and_convert_pixels_fn<CC>(cc), src, _1));
116 }
117 
119 template <typename View1, // Model ImageViewConcept
120  typename Types2> // Model MPL Random Access Container of models of MutableImageViewConcept
121 void copy_and_convert_pixels(const View1& src, const any_image_view<Types2>& dst) {
122  apply_operation(dst,boost::bind(detail::copy_and_convert_pixels_fn<default_color_converter>(), src, _1));
123 }
124 
126 template <typename Types1, // Model MPL Random Access Container of models of ImageViewConcept
127  typename Types2, // Model MPL Random Access Container of models of MutableImageViewConcept
128  typename CC> // Model ColorConverterConcept
129 void copy_and_convert_pixels(const any_image_view<Types1>& src, const any_image_view<Types2>& dst, CC cc) {
130  apply_operation(src,dst,detail::copy_and_convert_pixels_fn<CC>(cc));
131 }
132 
134 template <typename Types1, // Model MPL Random Access Container of models of ImageViewConcept
135  typename Types2> // Model MPL Random Access Container of models of MutableImageViewConcept
136 void copy_and_convert_pixels(const any_image_view<Types1>& src, const any_image_view<Types2>& dst) {
137  apply_operation(src,dst,detail::copy_and_convert_pixels_fn<default_color_converter>());
138 }
139 
140 namespace detail {
141 template <bool COMPATIBLE> struct fill_pixels_fn1 {
142  template <typename V, typename Value> static void apply(const V& src, const Value& val) { fill_pixels(src,val); }
143 };
144 
145 // copy_pixels invoked on incompatible images
146 template <> struct fill_pixels_fn1<false> {
147  template <typename V, typename Value> static void apply(const V& src, const Value& val) { throw std::bad_cast();}
148 };
149 
150 template <typename Value>
151 struct fill_pixels_fn {
152  fill_pixels_fn(const Value& val) : _val(val) {}
153 
154  typedef void result_type;
155  template <typename V> result_type operator()(const V& img_view) const {
156  fill_pixels_fn1<pixels_are_compatible<typename V::value_type, Value>::value>::apply(img_view,_val);
157  }
158  Value _val;
159 };
160 }
161 
164 template <typename Types, // Model MPL Random Access Container of models of MutableImageViewConcept
165  typename Value>
166 void fill_pixels(const any_image_view<Types>& img_view, const Value& val) {
167  apply_operation(img_view,detail::fill_pixels_fn<Value>(val));
168 }
169 
170 
171 } } // namespace boost::gil
172 
173 #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:166
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:35
BOOST_FORCEINLINE bool equal_pixels(const View1 &v1, const View2 &v2)
std::equal for image views
Definition: algorithm.hpp:956
BOOST_FORCEINLINE void copy_pixels(const View1 &src, const View2 &dst)
std::copy for image views
Definition: algorithm.hpp:289
Support for run-time instantiated images and image views.
Represents a run-time specified image view. Models HasDynamicXStepTypeConcept, HasDynamicYStepTypeCon...
Definition: any_image_view.hpp:64