2 Copyright 2005-2007 Adobe Systems Incorporated
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).
8 See http://opensource.adobe.com/gil for most recent version including documentation.
10 /*************************************************************************************************/
12 #ifndef GIL_DYNAMICIMAGE_ALGORITHM_HPP
13 #define GIL_DYNAMICIMAGE_ALGORITHM_HPP
15 #include "../../algorithm.hpp"
16 #include "any_image.hpp"
17 #include <boost/bind.hpp>
19 ////////////////////////////////////////////////////////////////////////////////////////
21 /// \brief Some basic STL-style algorithms when applied to runtime type specified image views
22 /// \author Lubomir Bourdev and Hailin Jin \n
23 /// Adobe Systems Incorporated
24 /// \date 2005-2007 \n Last updated on September 24, 2006
26 ////////////////////////////////////////////////////////////////////////////////////////
28 namespace boost { namespace gil {
31 struct equal_pixels_fn : public binary_operation_obj<equal_pixels_fn,bool> {
32 template <typename V1, typename V2>
33 GIL_FORCEINLINE bool apply_compatible(const V1& v1, const V2& v2) const {
34 return equal_pixels(v1,v2);
39 /// \ingroup ImageViewSTLAlgorithmsEqualPixels
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));
46 /// \ingroup ImageViewSTLAlgorithmsEqualPixels
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));
53 /// \ingroup ImageViewSTLAlgorithmsEqualPixels
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());
61 struct copy_pixels_fn : public binary_operation_obj<copy_pixels_fn> {
62 template <typename View1, typename View2>
63 GIL_FORCEINLINE void apply_compatible(const View1& src, const View2& dst) const {
69 /// \ingroup ImageViewSTLAlgorithmsCopyPixels
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));
76 /// \ingroup ImageViewSTLAlgorithmsCopyPixels
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));
83 /// \ingroup ImageViewSTLAlgorithmsCopyPixels
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());
92 //forward declaration for default_color_converter (see full definition in color_convert.hpp)
93 struct default_color_converter;
95 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
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));
103 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
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));
110 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
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));
118 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
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));
125 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
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));
133 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
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>());
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); }
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();}
150 template <typename Value>
151 struct fill_pixels_fn {
152 fill_pixels_fn(const Value& val) : _val(val) {}
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);
162 /// \ingroup ImageViewSTLAlgorithmsFillPixels
163 /// \brief fill_pixels for any image view. The pixel to fill with must be compatible with the current view
164 template <typename Types, // Model MPL Random Access Container of models of MutableImageViewConcept
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));
171 } } // namespace boost::gil