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 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 #ifndef BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_IMAGE_VIEW_FACTORY_HPP
0009 #define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_IMAGE_VIEW_FACTORY_HPP
0010 
0011 #include <boost/gil/extension/dynamic_image/any_image_view.hpp>
0012 
0013 #include <boost/gil/dynamic_step.hpp>
0014 #include <boost/gil/image_view_factory.hpp>
0015 #include <boost/gil/point.hpp>
0016 #include <boost/gil/detail/mp11.hpp>
0017 
0018 #include <cstdint>
0019 
0020 namespace boost { namespace gil {
0021 
0022 // Methods for constructing any image views from other any image views
0023 // Extends image view factory to runtime type-specified views (any_image_view)
0024 
0025 namespace detail {
0026 
0027 template <typename ResultView>
0028 struct flipped_up_down_view_fn
0029 {
0030     using result_type = ResultView;
0031 
0032     template <typename View>
0033     auto operator()(View const& src) const -> result_type
0034     {
0035         return result_type{flipped_up_down_view(src)};
0036     }
0037 };
0038 
0039 template <typename ResultView>
0040 struct flipped_left_right_view_fn
0041 {
0042     using result_type = ResultView;
0043 
0044     template <typename View>
0045     auto operator()(View const& src) const -> result_type
0046     {
0047         return result_type{flipped_left_right_view(src)};
0048     }
0049 };
0050 
0051 template <typename ResultView>
0052 struct rotated90cw_view_fn
0053 {
0054     using result_type = ResultView;
0055 
0056     template <typename View>
0057     auto operator()(View const& src) const -> result_type
0058     {
0059         return result_type{rotated90cw_view(src)};
0060     }
0061 };
0062 
0063 template <typename ResultView>
0064 struct rotated90ccw_view_fn
0065 {
0066     using result_type = ResultView;
0067 
0068     template <typename View>
0069     auto operator()(View const& src) const -> result_type
0070     {
0071         return result_type{rotated90ccw_view(src)};
0072     }
0073 };
0074 
0075 template <typename ResultView>
0076 struct tranposed_view_fn
0077 {
0078     using result_type = ResultView;
0079 
0080     template <typename View>
0081     auto operator()(View const& src) const -> result_type
0082     {
0083         return result_type{tranposed_view(src)};
0084     }
0085 };
0086 
0087 template <typename ResultView>
0088 struct rotated180_view_fn
0089 {
0090     using result_type = ResultView;
0091 
0092     template <typename View>
0093     auto operator()(View const& src) const -> result_type
0094     {
0095         return result_type{rotated180_view(src)};
0096     }
0097 };
0098 
0099 template <typename ResultView>
0100 struct subimage_view_fn
0101 {
0102     using result_type = ResultView;
0103 
0104     subimage_view_fn(point_t const& topleft, point_t const& dimensions)
0105         : _topleft(topleft), _size2(dimensions)
0106     {}
0107 
0108     template <typename View>
0109     auto operator()(View const& src) const -> result_type
0110     {
0111         return result_type{subimage_view(src,_topleft,_size2)};
0112     }
0113 
0114     point_t _topleft;
0115     point_t _size2;
0116 };
0117 
0118 template <typename ResultView>
0119 struct subsampled_view_fn
0120 {
0121     using result_type = ResultView;
0122 
0123     subsampled_view_fn(point_t const& step) : _step(step) {}
0124 
0125     template <typename View>
0126     auto operator()(View const& src) const -> result_type
0127     {
0128         return result_type{subsampled_view(src,_step)};
0129     }
0130 
0131     point_t _step;
0132 };
0133 
0134 template <typename ResultView>
0135 struct nth_channel_view_fn
0136 {
0137     using result_type = ResultView;
0138 
0139     nth_channel_view_fn(int n) : _n(n) {}
0140 
0141     template <typename View>
0142     auto operator()(View const& src) const -> result_type
0143     {
0144         return result_type(nth_channel_view(src,_n));
0145     }
0146 
0147     int _n;
0148 };
0149 
0150 template <typename DstP, typename ResultView, typename CC = default_color_converter>
0151 struct color_converted_view_fn
0152 {
0153     using result_type = ResultView;
0154 
0155     color_converted_view_fn(CC cc = CC()): _cc(cc) {}
0156 
0157     template <typename View>
0158     auto operator()(View const& src) const -> result_type
0159     {
0160         return result_type{color_converted_view<DstP>(src, _cc)};
0161     }
0162 
0163 private:
0164     CC _cc;
0165 };
0166 
0167 } // namespace detail
0168 
0169 /// \ingroup ImageViewTransformationsFlipUD
0170 /// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept
0171 template <typename ...Views>
0172 inline
0173 auto flipped_up_down_view(any_image_view<Views...> const& src)
0174     -> typename dynamic_y_step_type<any_image_view<Views...>>::type
0175 {
0176     using result_view_t = typename dynamic_y_step_type<any_image_view<Views...>>::type;
0177     return variant2::visit(detail::flipped_up_down_view_fn<result_view_t>(), src);
0178 }
0179 
0180 /// \ingroup ImageViewTransformationsFlipLR
0181 /// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept
0182 template <typename ...Views>
0183 inline
0184 auto flipped_left_right_view(any_image_view<Views...> const& src)
0185     -> typename dynamic_x_step_type<any_image_view<Views...>>::type
0186 {
0187     using result_view_t = typename dynamic_x_step_type<any_image_view<Views...>>::type;
0188     return variant2::visit(detail::flipped_left_right_view_fn<result_view_t>(), src);
0189 }
0190 
0191 /// \ingroup ImageViewTransformationsTransposed
0192 /// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept
0193 template <typename ...Views>
0194 inline
0195 auto transposed_view(any_image_view<Views...> const& src)
0196     -> typename dynamic_xy_step_transposed_type<any_image_view<Views...>>::type
0197 {
0198     using result_view_t = typename dynamic_xy_step_transposed_type<any_image_view<Views...>>::type;
0199     return variant2::visit(detail::tranposed_view_fn<result_view_t>(), src);
0200 }
0201 
0202 /// \ingroup ImageViewTransformations90CW
0203 /// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept
0204 template <typename ...Views>
0205 inline
0206 auto rotated90cw_view(any_image_view<Views...> const& src)
0207     -> typename dynamic_xy_step_transposed_type<any_image_view<Views...>>::type
0208 {
0209     using result_view_t = typename dynamic_xy_step_transposed_type<any_image_view<Views...>>::type;
0210     return variant2::visit(detail::rotated90cw_view_fn<result_view_t>(), src);
0211 }
0212 
0213 /// \ingroup ImageViewTransformations90CCW
0214 /// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept
0215 template <typename ...Views>
0216 inline
0217 auto rotated90ccw_view(any_image_view<Views...> const& src)
0218     -> typename dynamic_xy_step_transposed_type<any_image_view<Views...>>::type
0219 {
0220     using result_view_t = typename dynamic_xy_step_transposed_type<any_image_view<Views...>>::type;
0221     return variant2::visit(detail::rotated90ccw_view_fn<result_view_t>(), src);
0222 }
0223 
0224 /// \ingroup ImageViewTransformations180
0225 /// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept
0226 template <typename ...Views>
0227 inline
0228 auto rotated180_view(any_image_view<Views...> const& src)
0229     -> typename dynamic_xy_step_type<any_image_view<Views...>>::type
0230 {
0231     using result_view_t = typename dynamic_xy_step_type<any_image_view<Views...>>::type;
0232     return variant2::visit(detail::rotated180_view_fn<result_view_t>(), src);
0233 }
0234 
0235 /// \ingroup ImageViewTransformationsSubimage
0236 /// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept
0237 template <typename ...Views>
0238 inline
0239 auto subimage_view(
0240     any_image_view<Views...> const& src,
0241     point_t const& topleft,
0242     point_t const& dimensions)
0243     -> any_image_view<Views...>
0244 {
0245     using subimage_view_fn = detail::subimage_view_fn<any_image_view<Views...>>;
0246     return variant2::visit(subimage_view_fn(topleft, dimensions), src);
0247 }
0248 
0249 /// \ingroup ImageViewTransformationsSubimage
0250 /// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept
0251 template <typename ...Views>
0252 inline
0253 auto subimage_view(
0254     any_image_view<Views...> const& src,
0255     std::ptrdiff_t x_min, std::ptrdiff_t y_min, std::ptrdiff_t width, std::ptrdiff_t height)
0256     -> any_image_view<Views...>
0257 {
0258     using subimage_view_fn = detail::subimage_view_fn<any_image_view<Views...>>;
0259     return variant2::visit(subimage_view_fn(point_t(x_min, y_min),point_t(width, height)), src);
0260 }
0261 
0262 /// \ingroup ImageViewTransformationsSubsampled
0263 /// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept
0264 template <typename ...Views>
0265 inline
0266 auto subsampled_view(any_image_view<Views...> const& src, point_t const& step)
0267     -> typename dynamic_xy_step_type<any_image_view<Views...>>::type
0268 {
0269     using step_type = typename dynamic_xy_step_type<any_image_view<Views...>>::type;
0270     using subsampled_view = detail::subsampled_view_fn<step_type>;
0271     return variant2::visit(subsampled_view(step), src);
0272 }
0273 
0274 /// \ingroup ImageViewTransformationsSubsampled
0275 /// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept
0276 template <typename ...Views>
0277 inline
0278 auto subsampled_view(any_image_view<Views...> const& src, std::ptrdiff_t x_step, std::ptrdiff_t y_step)
0279     -> typename dynamic_xy_step_type<any_image_view<Views...>>::type
0280 {
0281     using step_type = typename dynamic_xy_step_type<any_image_view<Views...>>::type;
0282     using subsampled_view_fn = detail::subsampled_view_fn<step_type>;
0283     return variant2::visit(subsampled_view_fn(point_t(x_step, y_step)), src);
0284 }
0285 
0286 namespace detail {
0287 
0288 template <typename View>
0289 struct get_nthchannel_type { using type = typename nth_channel_view_type<View>::type; };
0290 
0291 template <typename Views>
0292 struct views_get_nthchannel_type : mp11::mp_transform<get_nthchannel_type, Views> {};
0293 
0294 } // namespace detail
0295 
0296 /// \ingroup ImageViewTransformationsNthChannel
0297 /// \brief Given a runtime source image view, returns the type of a runtime image view over a single channel of the source view
0298 template <typename ...Views>
0299 struct nth_channel_view_type<any_image_view<Views...>>
0300 {
0301     using type = typename detail::views_get_nthchannel_type<any_image_view<Views...>>;
0302 };
0303 
0304 /// \ingroup ImageViewTransformationsNthChannel
0305 /// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept
0306 template <typename ...Views>
0307 inline
0308 auto nth_channel_view(any_image_view<Views...> const& src, int n)
0309     -> typename nth_channel_view_type<any_image_view<Views...>>::type
0310 {
0311     using result_view_t = typename nth_channel_view_type<any_image_view<Views...>>::type;
0312     return variant2::visit(detail::nth_channel_view_fn<result_view_t>(n), src);
0313 }
0314 
0315 namespace detail {
0316 
0317 template <typename View, typename DstP, typename CC>
0318 struct get_ccv_type : color_converted_view_type<View, DstP, CC> {};
0319 
0320 template <typename Views, typename DstP, typename CC>
0321 struct views_get_ccv_type
0322 {
0323 private:
0324     // FIXME: Remove class name injection with detail:: qualification
0325     // Required as workaround for MP11 issue that treats unqualified metafunction
0326     // in the class definition of the same name as the specialization (Peter Dimov):
0327     //    invalid template argument for template parameter 'F', expected a class template
0328     template <typename T>
0329     using ccvt = detail::get_ccv_type<T, DstP, CC>;
0330 
0331 public:
0332     using type = mp11::mp_transform<ccvt, Views>;
0333 };
0334 
0335 } // namespace detail
0336 
0337 /// \ingroup ImageViewTransformationsColorConvert
0338 /// \brief Returns the type of a runtime-specified view, color-converted to a given pixel type with user specified color converter
0339 template <typename ...Views, typename DstP, typename CC>
0340 struct color_converted_view_type<any_image_view<Views...>,DstP,CC>
0341 {
0342     //using type = any_image_view<typename detail::views_get_ccv_type<Views, DstP, CC>::type>;
0343     using type = detail::views_get_ccv_type<any_image_view<Views...>, DstP, CC>;
0344 };
0345 
0346 /// \ingroup ImageViewTransformationsColorConvert
0347 /// \brief overload of generic color_converted_view with user defined color-converter
0348 /// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept
0349 template <typename DstP, typename ...Views, typename CC>
0350 inline
0351 auto color_converted_view(any_image_view<Views...> const& src, CC)
0352     -> typename color_converted_view_type<any_image_view<Views...>, DstP, CC>::type
0353 {
0354     using cc_view_t = typename color_converted_view_type<any_image_view<Views...>, DstP, CC>::type;
0355     return variant2::visit(detail::color_converted_view_fn<DstP, cc_view_t>(), src);
0356 }
0357 
0358 /// \ingroup ImageViewTransformationsColorConvert
0359 /// \brief Returns the type of a runtime-specified view, color-converted to a given pixel type with the default coor converter
0360 template <typename ...Views, typename DstP>
0361 struct color_converted_view_type<any_image_view<Views...>,DstP>
0362 {
0363     using type = detail::views_get_ccv_type<any_image_view<Views...>, DstP, default_color_converter>;
0364 };
0365 
0366 /// \ingroup ImageViewTransformationsColorConvert
0367 /// \brief overload of generic color_converted_view with the default color-converter
0368 /// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept
0369 template <typename DstP, typename ...Views>
0370 inline
0371 auto color_converted_view(any_image_view<Views...> const& src)
0372     -> typename color_converted_view_type<any_image_view<Views...>, DstP>::type
0373 {
0374     using cc_view_t = typename color_converted_view_type<any_image_view<Views...>, DstP>::type;
0375     return variant2::visit(detail::color_converted_view_fn<DstP, cc_view_t>(), src);
0376 }
0377 
0378 /// \ingroup ImageViewTransformationsColorConvert
0379 /// \brief overload of generic color_converted_view with user defined color-converter
0380 ///        These are workarounds for GCC 3.4, which thinks color_converted_view is ambiguous with the same method for templated views (in gil/image_view_factory.hpp)
0381 /// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept
0382 template <typename DstP, typename ...Views, typename CC>
0383 [[deprecated("Use color_converted_view(const any_image_view<Views...>& src, CC) instead.")]]
0384 inline
0385 auto any_color_converted_view(const any_image_view<Views...>& src, CC cc)
0386     -> typename color_converted_view_type<any_image_view<Views...>, DstP, CC>::type
0387 {
0388     return color_converted_view(src, cc);
0389 }
0390 
0391 /// \ingroup ImageViewTransformationsColorConvert
0392 /// \brief overload of generic color_converted_view with the default color-converter
0393 ///        These are workarounds for GCC 3.4, which thinks color_converted_view is ambiguous with the same method for templated views (in gil/image_view_factory.hpp)
0394 /// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept
0395 template <typename DstP, typename ...Views>
0396 [[deprecated("Use color_converted_view(any_image_view<Views...> const& src) instead.")]]
0397 inline
0398 auto any_color_converted_view(const any_image_view<Views...>& src)
0399     -> typename color_converted_view_type<any_image_view<Views...>, DstP>::type
0400 {
0401     return color_converted_view(src);
0402 }
0403 
0404 /// \}
0405 
0406 }}  // namespace boost::gil
0407 
0408 #endif