Chris@16: /* Chris@16: Copyright 2005-2007 Adobe Systems Incorporated Chris@16: Chris@16: Use, modification and distribution are subject to the Boost Software License, Chris@16: Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: http://www.boost.org/LICENSE_1_0.txt). Chris@16: Chris@16: See http://opensource.adobe.com/gil for most recent version including documentation. Chris@16: */ Chris@16: /*************************************************************************************************/ Chris@16: Chris@16: #ifndef GIL_DYNAMICIMAGE_ALGORITHM_HPP Chris@16: #define GIL_DYNAMICIMAGE_ALGORITHM_HPP Chris@16: Chris@16: #include "../../algorithm.hpp" Chris@16: #include "any_image.hpp" Chris@16: #include Chris@16: Chris@16: //////////////////////////////////////////////////////////////////////////////////////// Chris@16: /// \file Chris@16: /// \brief Some basic STL-style algorithms when applied to runtime type specified image views Chris@16: /// \author Lubomir Bourdev and Hailin Jin \n Chris@16: /// Adobe Systems Incorporated Chris@16: /// \date 2005-2007 \n Last updated on September 24, 2006 Chris@16: /// Chris@16: //////////////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: namespace boost { namespace gil { Chris@16: Chris@16: namespace detail { Chris@16: struct equal_pixels_fn : public binary_operation_obj { Chris@16: template Chris@16: GIL_FORCEINLINE bool apply_compatible(const V1& v1, const V2& v2) const { Chris@16: return equal_pixels(v1,v2); Chris@16: } Chris@16: }; Chris@16: } // namespace detail Chris@16: Chris@16: /// \ingroup ImageViewSTLAlgorithmsEqualPixels Chris@16: template // Model MutableImageViewConcept Chris@16: bool equal_pixels(const any_image_view& src, const View2& dst) { Chris@16: return apply_operation(src,boost::bind(detail::equal_pixels_fn(), _1, dst)); Chris@16: } Chris@16: Chris@16: /// \ingroup ImageViewSTLAlgorithmsEqualPixels Chris@16: template // Model MPL Random Access Container of models of MutableImageViewConcept Chris@16: bool equal_pixels(const View1& src, const any_image_view& dst) { Chris@16: return apply_operation(dst,boost::bind(detail::equal_pixels_fn(), src, _1)); Chris@16: } Chris@16: Chris@16: /// \ingroup ImageViewSTLAlgorithmsEqualPixels Chris@16: template // Model MPL Random Access Container of models of MutableImageViewConcept Chris@16: bool equal_pixels(const any_image_view& src, const any_image_view& dst) { Chris@16: return apply_operation(src,dst,detail::equal_pixels_fn()); Chris@16: } Chris@16: Chris@16: namespace detail { Chris@16: struct copy_pixels_fn : public binary_operation_obj { Chris@16: template Chris@16: GIL_FORCEINLINE void apply_compatible(const View1& src, const View2& dst) const { Chris@16: copy_pixels(src,dst); Chris@16: } Chris@16: }; Chris@16: } Chris@16: Chris@16: /// \ingroup ImageViewSTLAlgorithmsCopyPixels Chris@16: template // Model MutableImageViewConcept Chris@16: void copy_pixels(const any_image_view& src, const View2& dst) { Chris@16: apply_operation(src,boost::bind(detail::copy_pixels_fn(), _1, dst)); Chris@16: } Chris@16: Chris@16: /// \ingroup ImageViewSTLAlgorithmsCopyPixels Chris@16: template // Model MPL Random Access Container of models of MutableImageViewConcept Chris@16: void copy_pixels(const View1& src, const any_image_view& dst) { Chris@16: apply_operation(dst,boost::bind(detail::copy_pixels_fn(), src, _1)); Chris@16: } Chris@16: Chris@16: /// \ingroup ImageViewSTLAlgorithmsCopyPixels Chris@16: template // Model MPL Random Access Container of models of MutableImageViewConcept Chris@16: void copy_pixels(const any_image_view& src, const any_image_view& dst) { Chris@16: apply_operation(src,dst,detail::copy_pixels_fn()); Chris@16: } Chris@16: Chris@16: Chris@16: Chris@16: //forward declaration for default_color_converter (see full definition in color_convert.hpp) Chris@16: struct default_color_converter; Chris@16: Chris@16: /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels Chris@16: template // Model ColorConverterConcept Chris@16: void copy_and_convert_pixels(const any_image_view& src, const View2& dst, CC cc) { Chris@16: apply_operation(src,boost::bind(detail::copy_and_convert_pixels_fn(cc), _1, dst)); Chris@16: } Chris@16: Chris@16: /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels Chris@16: template // Model MutableImageViewConcept Chris@16: void copy_and_convert_pixels(const any_image_view& src, const View2& dst) { Chris@16: apply_operation(src,boost::bind(detail::copy_and_convert_pixels_fn(), _1, dst)); Chris@16: } Chris@16: Chris@16: /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels Chris@16: template // Model ColorConverterConcept Chris@16: void copy_and_convert_pixels(const View1& src, const any_image_view& dst, CC cc) { Chris@16: apply_operation(dst,boost::bind(detail::copy_and_convert_pixels_fn(cc), src, _1)); Chris@16: } Chris@16: Chris@16: /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels Chris@16: template // Model MPL Random Access Container of models of MutableImageViewConcept Chris@16: void copy_and_convert_pixels(const View1& src, const any_image_view& dst) { Chris@16: apply_operation(dst,boost::bind(detail::copy_and_convert_pixels_fn(), src, _1)); Chris@16: } Chris@16: Chris@16: /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels Chris@16: template // Model ColorConverterConcept Chris@16: void copy_and_convert_pixels(const any_image_view& src, const any_image_view& dst, CC cc) { Chris@16: apply_operation(src,dst,detail::copy_and_convert_pixels_fn(cc)); Chris@16: } Chris@16: Chris@16: /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels Chris@16: template // Model MPL Random Access Container of models of MutableImageViewConcept Chris@16: void copy_and_convert_pixels(const any_image_view& src, const any_image_view& dst) { Chris@16: apply_operation(src,dst,detail::copy_and_convert_pixels_fn()); Chris@16: } Chris@16: Chris@16: namespace detail { Chris@16: template struct fill_pixels_fn1 { Chris@16: template static void apply(const V& src, const Value& val) { fill_pixels(src,val); } Chris@16: }; Chris@16: Chris@16: // copy_pixels invoked on incompatible images Chris@16: template <> struct fill_pixels_fn1 { Chris@16: template static void apply(const V& src, const Value& val) { throw std::bad_cast();} Chris@16: }; Chris@16: Chris@16: template Chris@16: struct fill_pixels_fn { Chris@16: fill_pixels_fn(const Value& val) : _val(val) {} Chris@16: Chris@16: typedef void result_type; Chris@16: template result_type operator()(const V& img_view) const { Chris@16: fill_pixels_fn1::value>::apply(img_view,_val); Chris@16: } Chris@16: Value _val; Chris@16: }; Chris@16: } Chris@16: Chris@16: /// \ingroup ImageViewSTLAlgorithmsFillPixels Chris@16: /// \brief fill_pixels for any image view. The pixel to fill with must be compatible with the current view Chris@16: template Chris@16: void fill_pixels(const any_image_view& img_view, const Value& val) { Chris@16: apply_operation(img_view,detail::fill_pixels_fn(val)); Chris@16: } Chris@16: Chris@16: Chris@16: } } // namespace boost::gil Chris@16: Chris@16: #endif