00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef GIL_DYNAMICIMAGE_ALGORITHM_HPP
00013 #define GIL_DYNAMICIMAGE_ALGORITHM_HPP
00014
00015 #include "../../algorithm.hpp"
00016 #include "any_image.hpp"
00017 #include <boost/bind.hpp>
00018
00027
00028 namespace boost { namespace gil {
00029
00030 namespace detail {
00031 struct equal_pixels_fn : public binary_operation_obj<equal_pixels_fn,bool> {
00032 template <typename V1, typename V2>
00033 GIL_FORCEINLINE bool apply_compatible(const V1& v1, const V2& v2) const {
00034 return equal_pixels(v1,v2);
00035 }
00036 };
00037 }
00038
00040 template <typename Types1,
00041 typename View2>
00042 bool equal_pixels(const any_image_view<Types1>& src, const View2& dst) {
00043 return apply_operation(src,boost::bind(detail::equal_pixels_fn(), _1, dst));
00044 }
00045
00047 template <typename View1,
00048 typename Types2>
00049 bool equal_pixels(const View1& src, const any_image_view<Types2>& dst) {
00050 return apply_operation(dst,boost::bind(detail::equal_pixels_fn(), src, _1));
00051 }
00052
00054 template <typename Types1,
00055 typename Types2>
00056 bool equal_pixels(const any_image_view<Types1>& src, const any_image_view<Types2>& dst) {
00057 return apply_operation(src,dst,detail::equal_pixels_fn());
00058 }
00059
00060 namespace detail {
00061 struct copy_pixels_fn : public binary_operation_obj<copy_pixels_fn> {
00062 template <typename View1, typename View2>
00063 GIL_FORCEINLINE void apply_compatible(const View1& src, const View2& dst) const {
00064 copy_pixels(src,dst);
00065 }
00066 };
00067 }
00068
00070 template <typename Types1,
00071 typename View2>
00072 void copy_pixels(const any_image_view<Types1>& src, const View2& dst) {
00073 apply_operation(src,boost::bind(detail::copy_pixels_fn(), _1, dst));
00074 }
00075
00077 template <typename View1,
00078 typename Types2>
00079 void copy_pixels(const View1& src, const any_image_view<Types2>& dst) {
00080 apply_operation(dst,boost::bind(detail::copy_pixels_fn(), src, _1));
00081 }
00082
00084 template <typename Types1,
00085 typename Types2>
00086 void copy_pixels(const any_image_view<Types1>& src, const any_image_view<Types2>& dst) {
00087 apply_operation(src,dst,detail::copy_pixels_fn());
00088 }
00089
00090
00091
00092
00093 struct default_color_converter;
00094
00096 template <typename Types1,
00097 typename View2,
00098 typename CC>
00099 void copy_and_convert_pixels(const any_image_view<Types1>& src, const View2& dst, CC cc) {
00100 apply_operation(src,boost::bind(detail::copy_and_convert_pixels_fn<CC>(cc), _1, dst));
00101 }
00102
00104 template <typename Types1,
00105 typename View2>
00106 void copy_and_convert_pixels(const any_image_view<Types1>& src, const View2& dst) {
00107 apply_operation(src,boost::bind(detail::copy_and_convert_pixels_fn<default_color_converter>(), _1, dst));
00108 }
00109
00111 template <typename View1,
00112 typename Types2,
00113 typename CC>
00114 void copy_and_convert_pixels(const View1& src, const any_image_view<Types2>& dst, CC cc) {
00115 apply_operation(dst,boost::bind(detail::copy_and_convert_pixels_fn<CC>(cc), src, _1));
00116 }
00117
00119 template <typename View1,
00120 typename Types2>
00121 void copy_and_convert_pixels(const View1& src, const any_image_view<Types2>& dst) {
00122 apply_operation(dst,boost::bind(detail::copy_and_convert_pixels_fn<default_color_converter>(), src, _1));
00123 }
00124
00126 template <typename Types1,
00127 typename Types2,
00128 typename CC>
00129 void copy_and_convert_pixels(const any_image_view<Types1>& src, const any_image_view<Types2>& dst, CC cc) {
00130 apply_operation(src,dst,detail::copy_and_convert_pixels_fn<CC>(cc));
00131 }
00132
00134 template <typename Types1,
00135 typename Types2>
00136 void copy_and_convert_pixels(const any_image_view<Types1>& src, const any_image_view<Types2>& dst) {
00137 apply_operation(src,dst,detail::copy_and_convert_pixels_fn<default_color_converter>());
00138 }
00139
00140 namespace detail {
00141 template <bool COMPATIBLE> struct fill_pixels_fn1 {
00142 template <typename V, typename Value> static void apply(const V& src, const Value& val) { fill_pixels(src,val); }
00143 };
00144
00145
00146 template <> struct fill_pixels_fn1<false> {
00147 template <typename V, typename Value> static void apply(const V& src, const Value& val) { throw std::bad_cast();}
00148 };
00149
00150 template <typename Value>
00151 struct fill_pixels_fn {
00152 fill_pixels_fn(const Value& val) : _val(val) {}
00153
00154 typedef void result_type;
00155 template <typename V> result_type operator()(const V& img_view) const {
00156 fill_pixels_fn1<pixels_are_compatible<typename V::value_type, Value>::value>::apply(img_view,_val);
00157 }
00158 Value _val;
00159 };
00160 }
00161
00164 template <typename Types,
00165 typename Value>
00166 void fill_pixels(const any_image_view<Types>& img_view, const Value& val) {
00167 apply_operation(img_view,detail::fill_pixels_fn<Value>(val));
00168 }
00169
00170
00171 } }
00172
00173 #endif