File indexing completed on 2025-01-18 09:36:55
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_VIEW_HPP
0010 #define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_VIEW_HPP
0011
0012 #include <boost/gil/dynamic_step.hpp>
0013 #include <boost/gil/image.hpp>
0014 #include <boost/gil/image_view.hpp>
0015 #include <boost/gil/point.hpp>
0016 #include <boost/gil/detail/mp11.hpp>
0017
0018 #include <boost/variant2/variant.hpp>
0019
0020 namespace boost { namespace gil {
0021
0022 template <typename View>
0023 struct dynamic_xy_step_transposed_type;
0024
0025 namespace detail {
0026
0027 template <typename View>
0028 using get_const_t = typename View::const_t;
0029
0030 template <typename Views>
0031 using views_get_const_t = mp11::mp_transform<get_const_t, Views>;
0032
0033
0034 struct any_type_get_num_channels
0035 {
0036 using result_type = int;
0037 template <typename T>
0038 result_type operator()(const T&) const { return num_channels<T>::value; }
0039 };
0040
0041
0042 struct any_type_get_dimensions
0043 {
0044 using result_type = point<std::ptrdiff_t>;
0045 template <typename T>
0046 result_type operator()(const T& v) const { return v.dimensions(); }
0047 };
0048
0049
0050 struct any_type_get_size
0051 {
0052 using result_type = std::size_t;
0053 template <typename T>
0054 result_type operator()(const T& v) const { return v.size(); }
0055 };
0056
0057 }
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074 template <typename ...Views>
0075 class any_image_view : public variant2::variant<Views...>
0076 {
0077 using parent_t = variant2::variant<Views...>;
0078
0079 public:
0080 using const_t = detail::views_get_const_t<any_image_view>;
0081 using x_coord_t = std::ptrdiff_t;
0082 using y_coord_t = std::ptrdiff_t;
0083 using point_t = point<std::ptrdiff_t>;
0084 using size_type = std::size_t;
0085
0086 using parent_t::parent_t;
0087
0088 any_image_view& operator=(any_image_view const& view)
0089 {
0090 parent_t::operator=((parent_t const&)view);
0091 return *this;
0092 }
0093
0094 template <typename View>
0095 any_image_view& operator=(View const& view)
0096 {
0097 parent_t::operator=(view);
0098 return *this;
0099 }
0100
0101 template <typename ...OtherViews>
0102 any_image_view& operator=(any_image_view<OtherViews...> const& view)
0103 {
0104 parent_t::operator=((variant2::variant<OtherViews...> const&)view);
0105 return *this;
0106 }
0107
0108 std::size_t num_channels() const { return variant2::visit(detail::any_type_get_num_channels(), *this); }
0109 point_t dimensions() const { return variant2::visit(detail::any_type_get_dimensions(), *this); }
0110 size_type size() const { return variant2::visit(detail::any_type_get_size(), *this); }
0111 x_coord_t width() const { return dimensions().x; }
0112 y_coord_t height() const { return dimensions().y; }
0113 };
0114
0115
0116
0117
0118
0119 template <typename ...Views>
0120 struct dynamic_x_step_type<any_image_view<Views...>>
0121 {
0122 private:
0123
0124
0125
0126
0127 template <typename T>
0128 using dynamic_step_view = typename gil::dynamic_x_step_type<T>::type;
0129
0130 public:
0131 using type = mp11::mp_transform<dynamic_step_view, any_image_view<Views...>>;
0132 };
0133
0134
0135
0136
0137
0138 template <typename ...Views>
0139 struct dynamic_y_step_type<any_image_view<Views...>>
0140 {
0141 private:
0142
0143
0144
0145
0146 template <typename T>
0147 using dynamic_step_view = typename gil::dynamic_y_step_type<T>::type;
0148
0149 public:
0150 using type = mp11::mp_transform<dynamic_step_view, any_image_view<Views...>>;
0151 };
0152
0153 template <typename ...Views>
0154 struct dynamic_xy_step_type<any_image_view<Views...>>
0155 {
0156 private:
0157
0158
0159
0160
0161 template <typename T>
0162 using dynamic_step_view = typename gil::dynamic_xy_step_type<T>::type;
0163
0164 public:
0165 using type = mp11::mp_transform<dynamic_step_view, any_image_view<Views...>>;
0166 };
0167
0168 template <typename ...Views>
0169 struct dynamic_xy_step_transposed_type<any_image_view<Views...>>
0170 {
0171 private:
0172
0173
0174
0175
0176 template <typename T>
0177 using dynamic_step_view = typename gil::dynamic_xy_step_type<T>::type;
0178
0179 public:
0180 using type = mp11::mp_transform<dynamic_step_view, any_image_view<Views...>>;
0181 };
0182
0183 }}
0184
0185 #endif