]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/gil/extension/dynamic_image/algorithm.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / gil / extension / dynamic_image / algorithm.hpp
CommitLineData
92f5a8d4
TL
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
7c673cae 10
92f5a8d4 11#include <boost/gil/extension/dynamic_image/any_image.hpp>
7c673cae 12
92f5a8d4 13#include <boost/gil/algorithm.hpp>
7c673cae 14
92f5a8d4 15#include <functional>
7c673cae
FG
16
17////////////////////////////////////////////////////////////////////////////////////////
92f5a8d4 18/// \file
7c673cae
FG
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
23///
24////////////////////////////////////////////////////////////////////////////////////////
25
26namespace boost { namespace gil {
27
28namespace detail {
92f5a8d4
TL
29
30struct 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
7c673cae
FG
40} // namespace detail
41
42/// \ingroup ImageViewSTLAlgorithmsEqualPixels
92f5a8d4
TL
43/// \tparam Types Model Boost.MP11-compatible list of models of ImageViewConcept
44/// \tparam View Model MutableImageViewConcept
45template <typename Types, typename View>
46bool 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));
7c673cae
FG
51}
52
53/// \ingroup ImageViewSTLAlgorithmsEqualPixels
92f5a8d4
TL
54/// \tparam View Model ImageViewConcept
55/// \tparam Types Model Boost.MP11-compatible list of models of MutableImageViewConcept
56template <typename View, typename Types>
57bool 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));
7c673cae
FG
62}
63
64/// \ingroup ImageViewSTLAlgorithmsEqualPixels
92f5a8d4
TL
65/// \tparam Types1 Model Boost.MP11-compatible list of models of ImageViewConcept
66/// \tparam Types2 Model Boost.MP11-compatible list of models of MutableImageViewConcept
67template <typename Types1, typename Types2>
68bool equal_pixels(any_image_view<Types1> const& src, any_image_view<Types2> const& dst)
69{
70 return apply_operation(src, dst, detail::equal_pixels_fn());
7c673cae
FG
71}
72
73namespace detail {
92f5a8d4
TL
74
75struct 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
7c673cae
FG
86
87/// \ingroup ImageViewSTLAlgorithmsCopyPixels
92f5a8d4
TL
88/// \tparam Types Model Boost.MP11-compatible list of models of ImageViewConcept
89/// \tparam View Model MutableImageViewConcept
90template <typename Types, typename View>
91void 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));
7c673cae
FG
94}
95
96/// \ingroup ImageViewSTLAlgorithmsCopyPixels
92f5a8d4
TL
97/// \tparam Types Model Boost.MP11-compatible list of models of MutableImageViewConcept
98/// \tparam View Model ImageViewConcept
99template <typename Types, typename View>
100void 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));
7c673cae
FG
103}
104
105/// \ingroup ImageViewSTLAlgorithmsCopyPixels
92f5a8d4
TL
106/// \tparam Types1 Model Boost.MP11-compatible list of models of ImageViewConcept
107/// \tparam Types2 Model Boost.MP11-compatible list of models of MutableImageViewConcept
108template <typename Types1, typename Types2>
109void copy_pixels(any_image_view<Types1> const& src, any_image_view<Types2> const& dst)
110{
111 apply_operation(src, dst, detail::copy_pixels_fn());
7c673cae
FG
112}
113
7c673cae
FG
114//forward declaration for default_color_converter (see full definition in color_convert.hpp)
115struct default_color_converter;
116
117/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
92f5a8d4
TL
118/// \tparam Types Model Boost.MP11-compatible list of models of ImageViewConcept
119/// \tparam View Model MutableImageViewConcept
120/// \tparam CC Model ColorConverterConcept
121template <typename Types, typename View, typename CC>
122void 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));
7c673cae
FG
126}
127
128/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
92f5a8d4
TL
129/// \tparam Types Model Boost.MP11-compatible list of models of ImageViewConcept
130/// \tparam View Model MutableImageViewConcept
131template <typename Types, typename View>
132void 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));
7c673cae
FG
136}
137
138/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
92f5a8d4
TL
139/// \tparam View Model ImageViewConcept
140/// \tparam Types Model Boost.MP11-compatible list of models of MutableImageViewConcept
141/// \tparam CC Model ColorConverterConcept
142template <typename View, typename Types, typename CC>
143void 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));
7c673cae
FG
147}
148
149/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
92f5a8d4
TL
150/// \tparam View Model ImageViewConcept
151/// \tparam Type Model Boost.MP11-compatible list of models of MutableImageViewConcept
152template <typename View, typename Types>
153void 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));
7c673cae
FG
157}
158
159/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
92f5a8d4
TL
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
163template <typename Types1, typename Types2, typename CC>
164void copy_and_convert_pixels(
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));
7c673cae
FG
169}
170
171/// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
92f5a8d4
TL
172/// \tparam Types1 Model Boost.MP11-compatible list of models of ImageViewConcept
173/// \tparam Types2 Model Boost.MP11-compatible list of models of MutableImageViewConcept
174template <typename Types1, typename Types2>
175void copy_and_convert_pixels(
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>());
7c673cae
FG
181}
182
183namespace detail {
92f5a8d4
TL
184
185template <bool IsCompatible>
186struct fill_pixels_fn1
187{
188 template <typename V, typename Value>
189 static void apply(V const &src, Value const &val) { fill_pixels(src, val); }
7c673cae
FG
190};
191
192// copy_pixels invoked on incompatible images
92f5a8d4
TL
193template <>
194struct fill_pixels_fn1<false>
195{
196 template <typename V, typename Value>
197 static void apply(V const &, Value const &) { throw std::bad_cast();}
7c673cae
FG
198};
199
200template <typename Value>
92f5a8d4
TL
201struct 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_);
7c673cae 217 }
92f5a8d4
TL
218
219 Value val_;
7c673cae 220};
92f5a8d4
TL
221
222} // namespace detail
7c673cae
FG
223
224/// \ingroup ImageViewSTLAlgorithmsFillPixels
225/// \brief fill_pixels for any image view. The pixel to fill with must be compatible with the current view
92f5a8d4
TL
226/// \tparam Types Model Boost.MP11-compatible list of models of MutableImageViewConcept
227template <typename Types, typename Value>
228void fill_pixels(any_image_view<Types> const& view, Value const& val)
229{
230 apply_operation(view, detail::fill_pixels_fn<Value>(val));
7c673cae
FG
231}
232
92f5a8d4 233}} // namespace boost::gil
7c673cae
FG
234
235#endif