Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:36:55

0001 //
0002 // Copyright 2005-2007 Adobe Systems Incorporated
0003 // Copyright 2022 Marco Langer <langer.m86 at gmail dot com>
0004 //
0005 // Distributed under the Boost Software License, Version 1.0
0006 // See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt
0008 //
0009 #ifndef BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ALGORITHM_HPP
0010 #define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ALGORITHM_HPP
0011 
0012 #include <boost/gil/extension/dynamic_image/any_image.hpp>
0013 
0014 #include <boost/gil/algorithm.hpp>
0015 
0016 #include <boost/variant2/variant.hpp>
0017 
0018 #include <functional>
0019 #include <utility>
0020 
0021 ////////////////////////////////////////////////////////////////////////////////////////
0022 /// \file
0023 /// \brief Some basic STL-style algorithms when applied to runtime type specified image views
0024 /// \author Lubomir Bourdev and Hailin Jin \n
0025 ///         Adobe Systems Incorporated
0026 /// \date 2005-2007 \n Last updated on September 24, 2006
0027 ///
0028 ////////////////////////////////////////////////////////////////////////////////////////
0029 
0030 namespace boost { namespace gil {
0031 
0032 namespace detail {
0033 
0034 struct equal_pixels_fn : binary_operation_obj<equal_pixels_fn, bool>
0035 {
0036     template <typename V1, typename V2>
0037     BOOST_FORCEINLINE
0038     bool apply_compatible(V1 const& v1, V2 const& v2) const
0039     {
0040         return equal_pixels(v1, v2);
0041     }
0042 };
0043 
0044 } // namespace detail
0045 
0046 /// \ingroup ImageViewSTLAlgorithmsEqualPixels
0047 /// \tparam Types Model Boost.MP11-compatible list of models of ImageViewConcept
0048 /// \tparam View Model MutableImageViewConcept
0049 template <typename ...Types, typename View>
0050 auto equal_pixels(any_image_view<Types...> const& src, View const& dst) -> bool
0051 {
0052     return variant2::visit(
0053         std::bind(detail::equal_pixels_fn(), std::placeholders::_1, dst),
0054         src);
0055 }
0056 
0057 /// \ingroup ImageViewSTLAlgorithmsEqualPixels
0058 /// \tparam View Model ImageViewConcept
0059 /// \tparam Types Model Boost.MP11-compatible list of models of MutableImageViewConcept
0060 template <typename View, typename ...Types>
0061 auto equal_pixels(View const& src, any_image_view<Types...> const& dst) -> bool
0062 {
0063     return variant2::visit(
0064         std::bind(detail::equal_pixels_fn(), src, std::placeholders::_1),
0065         dst);
0066 }
0067 
0068 /// \ingroup ImageViewSTLAlgorithmsEqualPixels
0069 /// \tparam Types1 Model Boost.MP11-compatible list of models of ImageViewConcept
0070 /// \tparam Types2 Model Boost.MP11-compatible list of models of MutableImageViewConcept
0071 template <typename ...Types1, typename ...Types2>
0072 auto equal_pixels(any_image_view<Types1...> const& src, any_image_view<Types2...> const& dst) -> bool
0073 {
0074     return variant2::visit(detail::equal_pixels_fn(), src, dst);
0075 }
0076 
0077 namespace detail {
0078 
0079 struct copy_pixels_fn : public binary_operation_obj<copy_pixels_fn>
0080 {
0081     template <typename View1, typename View2>
0082     BOOST_FORCEINLINE
0083     void apply_compatible(View1 const& src, View2 const& dst) const
0084     {
0085         copy_pixels(src,dst);
0086     }
0087 };
0088 
0089 } // namespace detail
0090 
0091 /// \ingroup ImageViewSTLAlgorithmsCopyPixels
0092 /// \tparam Types Model Boost.MP11-compatible list of models of ImageViewConcept
0093 /// \tparam View Model MutableImageViewConcept
0094 template <typename ...Types, typename View>
0095 void copy_pixels(any_image_view<Types...> const& src, View const& dst)
0096 {
0097     variant2::visit(std::bind(detail::copy_pixels_fn(), std::placeholders::_1, dst), src);
0098 }
0099 
0100 /// \ingroup ImageViewSTLAlgorithmsCopyPixels
0101 /// \tparam Types Model Boost.MP11-compatible list of models of MutableImageViewConcept
0102 /// \tparam View Model ImageViewConcept
0103 template <typename ...Types, typename View>
0104 void copy_pixels(View const& src, any_image_view<Types...> const& dst)
0105 {
0106     variant2::visit(std::bind(detail::copy_pixels_fn(), src, std::placeholders::_1), dst);
0107 }
0108 
0109 /// \ingroup ImageViewSTLAlgorithmsCopyPixels
0110 /// \tparam Types1 Model Boost.MP11-compatible list of models of ImageViewConcept
0111 /// \tparam Types2 Model Boost.MP11-compatible list of models of MutableImageViewConcept
0112 template <typename ...Types1, typename ...Types2>
0113 void copy_pixels(any_image_view<Types1...> const& src, any_image_view<Types2...> const& dst)
0114 {
0115     variant2::visit(detail::copy_pixels_fn(), src, dst);
0116 }
0117 
0118 //forward declaration for default_color_converter (see full definition in color_convert.hpp)
0119 struct default_color_converter;
0120 
0121 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
0122 /// \tparam Types Model Boost.MP11-compatible list of models of ImageViewConcept
0123 /// \tparam View Model MutableImageViewConcept
0124 /// \tparam CC Model ColorConverterConcept
0125 template <typename ...Types, typename View, typename CC>
0126 void copy_and_convert_pixels(any_image_view<Types...> const& src, View const& dst, CC cc)
0127 {
0128     using cc_fn = detail::copy_and_convert_pixels_fn<CC>;
0129     variant2::visit(std::bind(cc_fn{cc}, std::placeholders::_1, dst), src);
0130 }
0131 
0132 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
0133 /// \tparam Types Model Boost.MP11-compatible list of models of ImageViewConcept
0134 /// \tparam View Model MutableImageViewConcept
0135 template <typename ...Types, typename View>
0136 void copy_and_convert_pixels(any_image_view<Types...> const& src, View const& dst)
0137 {
0138     using cc_fn = detail::copy_and_convert_pixels_fn<default_color_converter>;
0139     variant2::visit(std::bind(cc_fn{}, std::placeholders::_1, dst), src);
0140 }
0141 
0142 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
0143 /// \tparam View Model ImageViewConcept
0144 /// \tparam Types Model Boost.MP11-compatible list of models of MutableImageViewConcept
0145 /// \tparam CC Model ColorConverterConcept
0146 template <typename View, typename ...Types, typename CC>
0147 void copy_and_convert_pixels(View const& src, any_image_view<Types...> const& dst, CC cc)
0148 {
0149     using cc_fn = detail::copy_and_convert_pixels_fn<CC>;
0150     variant2::visit(std::bind(cc_fn{cc}, src, std::placeholders::_1), dst);
0151 }
0152 
0153 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
0154 /// \tparam View Model ImageViewConcept
0155 /// \tparam Type Model Boost.MP11-compatible list of models of MutableImageViewConcept
0156 template <typename View, typename ...Types>
0157 void copy_and_convert_pixels(View const& src, any_image_view<Types...> const& dst)
0158 {
0159     using cc_fn = detail::copy_and_convert_pixels_fn<default_color_converter>;
0160     variant2::visit(std::bind(cc_fn{}, src, std::placeholders::_1), dst);
0161 }
0162 
0163 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
0164 /// \tparam Types1 Model Boost.MP11-compatible list of models of ImageViewConcept
0165 /// \tparam Types2 Model Boost.MP11-compatible list of models of MutableImageViewConcept
0166 /// \tparam CC Model ColorConverterConcept
0167 template <typename ...Types1, typename ...Types2, typename CC>
0168 void copy_and_convert_pixels(
0169     any_image_view<Types1...> const& src,
0170     any_image_view<Types2...> const& dst, CC cc)
0171 {
0172     variant2::visit(detail::copy_and_convert_pixels_fn<CC>(cc), src, dst);
0173 }
0174 
0175 /// \ingroup ImageViewSTLAlgorithmsCopyAndConvertPixels
0176 /// \tparam Types1 Model Boost.MP11-compatible list of models of ImageViewConcept
0177 /// \tparam Types2 Model Boost.MP11-compatible list of models of MutableImageViewConcept
0178 template <typename ...Types1, typename ...Types2>
0179 void copy_and_convert_pixels(
0180     any_image_view<Types1...> const& src,
0181     any_image_view<Types2...> const& dst)
0182 {
0183     variant2::visit(
0184         detail::copy_and_convert_pixels_fn<default_color_converter>(), src, dst);
0185 }
0186 
0187 namespace detail {
0188 
0189 template <bool IsCompatible>
0190 struct fill_pixels_fn1
0191 {
0192     template <typename V, typename Value>
0193     static void apply(V const& src, Value const& val) { fill_pixels(src, val); }
0194 };
0195 
0196 // copy_pixels invoked on incompatible images
0197 template <>
0198 struct fill_pixels_fn1<false>
0199 {
0200     template <typename V, typename Value>
0201     static void apply(V const&, Value const&) { throw std::bad_cast();}
0202 };
0203 
0204 template <typename Value>
0205 struct fill_pixels_fn
0206 {
0207     fill_pixels_fn(Value const& val) : val_(val) {}
0208 
0209     using result_type = void;
0210     template <typename V>
0211     result_type operator()(V const& view) const
0212     {
0213         fill_pixels_fn1
0214         <
0215             pixels_are_compatible
0216             <
0217                 typename V::value_type,
0218                 Value
0219             >::value
0220         >::apply(view, val_);
0221     }
0222 
0223     Value val_;
0224 };
0225 
0226 } // namespace detail
0227 
0228 /// \ingroup ImageViewSTLAlgorithmsFillPixels
0229 /// \brief fill_pixels for any image view. The pixel to fill with must be compatible with the current view
0230 /// \tparam Types Model Boost.MP11-compatible list of models of MutableImageViewConcept
0231 template <typename ...Types, typename Value>
0232 void fill_pixels(any_image_view<Types...> const& view, Value const& val)
0233 {
0234     variant2::visit(detail::fill_pixels_fn<Value>(val), view);
0235 }
0236 
0237 namespace detail {
0238 
0239 template <typename F>
0240 struct for_each_pixel_fn
0241 {
0242     for_each_pixel_fn(F&& fun) : fun_(std::move(fun)) {}
0243 
0244     template <typename View>
0245     auto operator()(View const& view) -> F
0246     {
0247         return for_each_pixel(view, fun_);
0248     }
0249 
0250     F fun_;
0251 };
0252 
0253 } // namespace detail
0254 
0255 /// \defgroup ImageViewSTLAlgorithmsForEachPixel for_each_pixel
0256 /// \ingroup ImageViewSTLAlgorithms
0257 /// \brief std::for_each for any image views
0258 ///
0259 /// \ingroup ImageViewSTLAlgorithmsForEachPixel
0260 template <typename ...Types, typename F>
0261 auto for_each_pixel(any_image_view<Types...> const& view, F fun) -> F
0262 {
0263     return variant2::visit(detail::for_each_pixel_fn<F>(std::move(fun)), view);
0264 }
0265 
0266 }}  // namespace boost::gil
0267 
0268 #endif