File indexing completed on 2024-11-15 09:12:42
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_GIL_PLANAR_PIXEL_REFERENCE_HPP
0009 #define BOOST_GIL_PLANAR_PIXEL_REFERENCE_HPP
0010
0011 #include <boost/gil/channel.hpp>
0012 #include <boost/gil/color_base.hpp>
0013 #include <boost/gil/concepts.hpp>
0014 #include <boost/gil/pixel.hpp>
0015 #include <boost/gil/planar_pixel_iterator.hpp>
0016 #include <boost/gil/detail/mp11.hpp>
0017
0018 #include <type_traits>
0019
0020 namespace boost { namespace gil {
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 template <typename ChannelReference, typename ColorSpace>
0040 struct planar_pixel_reference : detail::homogeneous_color_base
0041 <
0042 ChannelReference,
0043 layout<ColorSpace>,
0044 mp11::mp_size<ColorSpace>::value
0045 >
0046 {
0047 using parent_t =detail::homogeneous_color_base
0048 <
0049 ChannelReference,
0050 layout<ColorSpace>,
0051 mp11::mp_size<ColorSpace>::value
0052 >;
0053
0054 private:
0055
0056 using channel_t = typename channel_traits<ChannelReference>::value_type;
0057 using channel_const_reference = typename channel_traits<ChannelReference>::const_reference;
0058
0059 public:
0060 static constexpr bool is_mutable = channel_traits<ChannelReference>::is_mutable;
0061 using value_type = pixel<channel_t,layout<ColorSpace>>;
0062 using reference = planar_pixel_reference<ChannelReference, ColorSpace>;
0063 using const_reference = planar_pixel_reference<channel_const_reference,ColorSpace>;
0064
0065 planar_pixel_reference(ChannelReference v0, ChannelReference v1)
0066 : parent_t(v0, v1)
0067 {}
0068
0069 planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2)
0070 : parent_t(v0, v1, v2)
0071 {}
0072
0073 planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3)
0074 : parent_t(v0, v1, v2, v3)
0075 {}
0076
0077 planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4)
0078 : parent_t(v0, v1, v2, v3, v4)
0079 {}
0080
0081 planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4, ChannelReference v5)
0082 : parent_t(v0, v1, v2, v3, v4, v5)
0083 {}
0084
0085 planar_pixel_reference(planar_pixel_reference const& p) : parent_t(p) {}
0086
0087
0088 auto operator=(planar_pixel_reference const& p) const -> planar_pixel_reference const&
0089 {
0090 static_copy(p, *this);
0091 return *this;
0092 }
0093
0094 template <typename Pixel>
0095 planar_pixel_reference(Pixel const& p) : parent_t(p)
0096 {
0097 check_compatible<Pixel>();
0098 }
0099
0100
0101 template <typename Pixel>
0102 auto operator=(Pixel const& p) const -> planar_pixel_reference const&
0103 {
0104 check_compatible<Pixel>();
0105 static_copy(p, *this);
0106 return *this;
0107 }
0108
0109
0110 template <typename ChannelV, typename Mapping>
0111 planar_pixel_reference(pixel<ChannelV, layout<ColorSpace, Mapping>>& p)
0112 : parent_t(p)
0113 {
0114 check_compatible<pixel<ChannelV, layout<ColorSpace, Mapping>>>();
0115 }
0116
0117
0118 template <typename ChannelPtr>
0119 planar_pixel_reference(planar_pixel_iterator<ChannelPtr, ColorSpace> const& p, std::ptrdiff_t diff)
0120 : parent_t(p, diff)
0121 {}
0122
0123
0124
0125
0126
0127
0128
0129
0130 #if BOOST_WORKAROUND(__HP_aCC, >= 61700) || BOOST_WORKAROUND(__INTEL_COMPILER, >= 1000)
0131 const planar_pixel_reference& operator=(const planar_pixel_reference& p) { static_copy(p,*this); return *this; }
0132 template <typename P> const planar_pixel_reference& operator=(const P& p) { check_compatible<P>(); static_copy(p,*this); return *this; }
0133 #endif
0134
0135 template <typename Pixel>
0136 bool operator==(Pixel const& p) const
0137 {
0138 check_compatible<Pixel>();
0139 return static_equal(*this, p);
0140 }
0141
0142 template <typename Pixel>
0143 bool operator!=(Pixel const &p) const { return !(*this == p); }
0144
0145 auto operator[](std::size_t i) const -> ChannelReference { return this->at_c_dynamic(i); }
0146 auto operator->() const -> planar_pixel_reference const* { return this; }
0147
0148 private:
0149 template <typename Pixel>
0150 static void check_compatible()
0151 {
0152 gil_function_requires<PixelsCompatibleConcept<Pixel, planar_pixel_reference>>();
0153 }
0154 };
0155
0156
0157
0158
0159
0160 template <typename ChannelReference, typename ColorSpace, int K>
0161 struct kth_element_type<planar_pixel_reference<ChannelReference, ColorSpace>, K>
0162 {
0163 using type = ChannelReference;
0164 };
0165
0166 template <typename ChannelReference, typename ColorSpace, int K>
0167 struct kth_element_reference_type
0168 <
0169 planar_pixel_reference<ChannelReference, ColorSpace>,
0170 K
0171 >
0172 {
0173 using type = ChannelReference;
0174 };
0175
0176 template <typename ChannelReference, typename ColorSpace, int K>
0177 struct kth_element_const_reference_type
0178 <
0179 planar_pixel_reference<ChannelReference, ColorSpace>,
0180 K
0181 >
0182 : std::add_lvalue_reference<typename std::add_const<ChannelReference>::type>
0183 {
0184
0185 };
0186
0187
0188
0189
0190
0191
0192
0193 template <typename ChannelReference, typename ColorSpace>
0194 struct is_pixel< planar_pixel_reference<ChannelReference, ColorSpace>>
0195 : std::true_type
0196 {};
0197
0198
0199
0200
0201
0202
0203
0204 template <typename ChannelReference, typename ColorSpace>
0205 struct color_space_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
0206 using type = ColorSpace;
0207 };
0208
0209
0210
0211 template <typename ChannelReference, typename ColorSpace>
0212 struct channel_mapping_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
0213 using type = typename layout<ColorSpace>::channel_mapping_t;
0214 };
0215
0216
0217
0218 template <typename ChannelReference, typename ColorSpace>
0219 struct is_planar<planar_pixel_reference<ChannelReference, ColorSpace>>
0220 : std::true_type
0221 {};
0222
0223
0224
0225 template <typename ChannelReference, typename ColorSpace>
0226 struct channel_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
0227 using type = typename channel_traits<ChannelReference>::value_type;
0228 };
0229
0230 }}
0231
0232 namespace std {
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242 template <typename CR, typename CS, typename R> inline
0243 void swap(const boost::gil::planar_pixel_reference<CR,CS> x, R& y) {
0244 boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
0245 }
0246
0247
0248
0249 template <typename CR, typename CS> inline
0250 void swap(typename boost::gil::planar_pixel_reference<CR,CS>::value_type& x, const boost::gil::planar_pixel_reference<CR,CS> y) {
0251 boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
0252 }
0253
0254
0255
0256 template <typename CR, typename CS> inline
0257 void swap(const boost::gil::planar_pixel_reference<CR,CS> x, const boost::gil::planar_pixel_reference<CR,CS> y) {
0258 boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
0259 }
0260
0261 }
0262
0263 #endif