annotate DEPENDENCIES/generic/include/boost/gil/packed_pixel.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 /*
Chris@16 2 Copyright 2005-2007 Adobe Systems Incorporated
Chris@16 3
Chris@16 4 Use, modification and distribution are subject to the Boost Software License,
Chris@16 5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 6 http://www.boost.org/LICENSE_1_0.txt).
Chris@16 7
Chris@16 8 See http://opensource.adobe.com/gil for most recent version including documentation.
Chris@16 9 */
Chris@16 10
Chris@16 11 /*************************************************************************************************/
Chris@16 12
Chris@16 13 #ifndef GIL_PACKED_PIXEL_H
Chris@16 14 #define GIL_PACKED_PIXEL_H
Chris@16 15
Chris@16 16 ////////////////////////////////////////////////////////////////////////////////////////
Chris@16 17 /// \file
Chris@16 18 /// \brief A model of a heterogeneous pixel whose channels are bit ranges. For example 16-bit RGB in '565' format
Chris@16 19 /// \author Lubomir Bourdev and Hailin Jin \n
Chris@16 20 /// Adobe Systems Incorporated
Chris@16 21 /// \date 2005-2009 \n Last updated on February 20, 2009
Chris@16 22 ///
Chris@16 23 ////////////////////////////////////////////////////////////////////////////////////////
Chris@16 24
Chris@16 25 #include <functional>
Chris@16 26 #include <boost/utility/enable_if.hpp>
Chris@16 27 #include <boost/mpl/bool.hpp>
Chris@16 28 #include <boost/mpl/front.hpp>
Chris@16 29 #include "gil_config.hpp"
Chris@16 30 #include "pixel.hpp"
Chris@16 31
Chris@16 32 namespace boost { namespace gil {
Chris@16 33
Chris@16 34 /// \defgroup ColorBaseModelPackedPixel packed_pixel
Chris@16 35 /// \ingroup ColorBaseModel
Chris@16 36 /// \brief A heterogeneous color base whose elements are reference proxies to channels in a pixel. Models ColorBaseValueConcept. This class is used to model packed pixels, such as 16-bit packed RGB.
Chris@16 37
Chris@16 38 /**
Chris@16 39 \defgroup PixelModelPackedPixel packed_pixel
Chris@16 40 \ingroup PixelModel
Chris@16 41 \brief A heterogeneous pixel used to represent packed pixels with non-byte-aligned channels. Models PixelValueConcept
Chris@16 42
Chris@16 43 Example:
Chris@16 44 \code
Chris@16 45 typedef packed_pixel_type<uint16_t, mpl::vector3_c<unsigned,5,6,5>, rgb_layout_t>::type rgb565_pixel_t;
Chris@16 46 BOOST_STATIC_ASSERT((sizeof(rgb565_pixel_t)==2));
Chris@16 47
Chris@16 48 rgb565_pixel_t r565;
Chris@16 49 get_color(r565,red_t()) = 31;
Chris@16 50 get_color(r565,green_t()) = 63;
Chris@16 51 get_color(r565,blue_t()) = 31;
Chris@16 52 assert(r565 == rgb565_pixel_t((uint16_t)0xFFFF));
Chris@16 53 \endcode
Chris@16 54 */
Chris@16 55
Chris@16 56 /// \ingroup ColorBaseModelPackedPixel PixelModelPackedPixel PixelBasedModel
Chris@16 57 /// \brief Heterogeneous pixel value whose channel references can be constructed from the pixel bitfield and their index. Models ColorBaseValueConcept, PixelValueConcept, PixelBasedConcept
Chris@16 58 /// Typical use for this is a model of a packed pixel (like 565 RGB)
Chris@16 59 template <typename BitField, // A type that holds the bits of the pixel. Typically an integral type, like boost::uint16_t
Chris@16 60 typename ChannelRefVec, // An MPL vector whose elements are packed channels. They must be constructible from BitField. GIL uses packed_channel_reference
Chris@16 61 typename Layout> // Layout defining the color space and ordering of the channels. Example value: rgb_layout_t
Chris@16 62 struct packed_pixel {
Chris@16 63 BitField _bitfield;
Chris@16 64
Chris@16 65 typedef Layout layout_t;
Chris@16 66 typedef packed_pixel value_type;
Chris@16 67 typedef value_type& reference;
Chris@16 68 typedef const value_type& const_reference;
Chris@16 69
Chris@16 70 BOOST_STATIC_CONSTANT(bool, is_mutable = channel_traits<typename mpl::front<ChannelRefVec>::type>::is_mutable);
Chris@16 71
Chris@16 72 packed_pixel(){}
Chris@16 73 explicit packed_pixel(const BitField& bitfield) : _bitfield(bitfield) {}
Chris@16 74
Chris@16 75 // Construct from another compatible pixel type
Chris@16 76 packed_pixel(const packed_pixel& p) : _bitfield(p._bitfield) {}
Chris@16 77 template <typename P> packed_pixel(const P& p, typename enable_if_c<is_pixel<P>::value>::type* d=0) { check_compatible<P>(); static_copy(p,*this); }
Chris@16 78 packed_pixel(int chan0, int chan1) : _bitfield(0) {
Chris@16 79 BOOST_STATIC_ASSERT((num_channels<packed_pixel>::value==2));
Chris@16 80 at_c<0>(*this)=chan0; at_c<1>(*this)=chan1;
Chris@16 81 }
Chris@16 82 packed_pixel(int chan0, int chan1, int chan2) : _bitfield(0) {
Chris@16 83 BOOST_STATIC_ASSERT((num_channels<packed_pixel>::value==3));
Chris@16 84 gil::at_c<0>(*this)=chan0; gil::at_c<1>(*this)=chan1; gil::at_c<2>(*this)=chan2;
Chris@16 85 }
Chris@16 86 packed_pixel(int chan0, int chan1, int chan2, int chan3) : _bitfield(0) {
Chris@16 87 BOOST_STATIC_ASSERT((num_channels<packed_pixel>::value==4));
Chris@16 88 gil::at_c<0>(*this)=chan0; gil::at_c<1>(*this)=chan1; gil::at_c<2>(*this)=chan2; gil::at_c<3>(*this)=chan3;
Chris@16 89 }
Chris@16 90 packed_pixel(int chan0, int chan1, int chan2, int chan3, int chan4) : _bitfield(0) {
Chris@16 91 BOOST_STATIC_ASSERT((num_channels<packed_pixel>::value==5));
Chris@16 92 gil::at_c<0>(*this)=chan0; gil::at_c<1>(*this)=chan1; gil::at_c<2>(*this)=chan2; gil::at_c<3>(*this)=chan3; gil::at_c<4>(*this)=chan4;
Chris@16 93 }
Chris@16 94
Chris@16 95 packed_pixel& operator=(const packed_pixel& p) { _bitfield=p._bitfield; return *this; }
Chris@16 96
Chris@16 97 template <typename P> packed_pixel& operator=(const P& p) { assign(p, mpl::bool_<is_pixel<P>::value>()); return *this; }
Chris@16 98 template <typename P> bool operator==(const P& p) const { return equal(p, mpl::bool_<is_pixel<P>::value>()); }
Chris@16 99
Chris@16 100 template <typename P> bool operator!=(const P& p) const { return !(*this==p); }
Chris@16 101
Chris@16 102 private:
Chris@16 103 template <typename Pixel> static void check_compatible() { gil_function_requires<PixelsCompatibleConcept<Pixel,packed_pixel> >(); }
Chris@16 104 template <typename Pixel> void assign(const Pixel& p, mpl::true_) { check_compatible<Pixel>(); static_copy(p,*this); }
Chris@16 105 template <typename Pixel> bool equal(const Pixel& p, mpl::true_) const { check_compatible<Pixel>(); return static_equal(*this,p); }
Chris@16 106
Chris@16 107 // Support for assignment/equality comparison of a channel with a grayscale pixel
Chris@16 108 static void check_gray() { BOOST_STATIC_ASSERT((is_same<typename Layout::color_space_t, gray_t>::value)); }
Chris@16 109 template <typename Channel> void assign(const Channel& chan, mpl::false_) { check_gray(); at_c<0>(*this)=chan; }
Chris@16 110 template <typename Channel> bool equal (const Channel& chan, mpl::false_) const { check_gray(); return at_c<0>(*this)==chan; }
Chris@16 111 public:
Chris@16 112 packed_pixel& operator= (int chan) { check_gray(); at_c<0>(*this)=chan; return *this; }
Chris@16 113 bool operator==(int chan) const { check_gray(); return at_c<0>(*this)==chan; }
Chris@16 114 };
Chris@16 115
Chris@16 116 /////////////////////////////
Chris@16 117 // ColorBasedConcept
Chris@16 118 /////////////////////////////
Chris@16 119
Chris@16 120 template <typename BitField, typename ChannelRefVec, typename Layout, int K>
Chris@16 121 struct kth_element_type<packed_pixel<BitField,ChannelRefVec,Layout>,K> : public mpl::at_c<ChannelRefVec,K> {};
Chris@16 122
Chris@16 123 template <typename BitField, typename ChannelRefVec, typename Layout, int K>
Chris@16 124 struct kth_element_reference_type<packed_pixel<BitField,ChannelRefVec,Layout>,K> : public mpl::at_c<ChannelRefVec,K> {};
Chris@16 125
Chris@16 126 template <typename BitField, typename ChannelRefVec, typename Layout, int K>
Chris@16 127 struct kth_element_const_reference_type<packed_pixel<BitField,ChannelRefVec,Layout>,K> {
Chris@16 128 typedef typename channel_traits<typename mpl::at_c<ChannelRefVec,K>::type>::const_reference type;
Chris@16 129 };
Chris@16 130
Chris@16 131 template <int K, typename P, typename C, typename L> inline
Chris@16 132 typename kth_element_reference_type<packed_pixel<P,C,L>, K>::type
Chris@16 133 at_c(packed_pixel<P,C,L>& p) {
Chris@16 134 return typename kth_element_reference_type<packed_pixel<P,C,L>, K>::type(&p._bitfield);
Chris@16 135 }
Chris@16 136
Chris@16 137 template <int K, typename P, typename C, typename L> inline
Chris@16 138 typename kth_element_const_reference_type<packed_pixel<P,C,L>, K>::type
Chris@16 139 at_c(const packed_pixel<P,C,L>& p) {
Chris@16 140 return typename kth_element_const_reference_type<packed_pixel<P,C,L>, K>::type(&p._bitfield);
Chris@16 141 }
Chris@16 142
Chris@16 143 /////////////////////////////
Chris@16 144 // PixelConcept
Chris@16 145 /////////////////////////////
Chris@16 146
Chris@16 147 // Metafunction predicate that flags packed_pixel as a model of PixelConcept. Required by PixelConcept
Chris@16 148 template <typename BitField, typename ChannelRefVec, typename Layout>
Chris@16 149 struct is_pixel<packed_pixel<BitField,ChannelRefVec,Layout> > : public mpl::true_{};
Chris@16 150
Chris@16 151 /////////////////////////////
Chris@16 152 // PixelBasedConcept
Chris@16 153 /////////////////////////////
Chris@16 154
Chris@16 155 template <typename P, typename C, typename Layout>
Chris@16 156 struct color_space_type<packed_pixel<P,C,Layout> > {
Chris@16 157 typedef typename Layout::color_space_t type;
Chris@16 158 };
Chris@16 159
Chris@16 160 template <typename P, typename C, typename Layout>
Chris@16 161 struct channel_mapping_type<packed_pixel<P,C,Layout> > {
Chris@16 162 typedef typename Layout::channel_mapping_t type;
Chris@16 163 };
Chris@16 164
Chris@16 165 template <typename P, typename C, typename Layout>
Chris@16 166 struct is_planar<packed_pixel<P,C,Layout> > : mpl::false_ {};
Chris@16 167
Chris@16 168
Chris@16 169 ////////////////////////////////////////////////////////////////////////////////
Chris@16 170 ///
Chris@16 171 /// Support for interleaved iterators over packed pixel
Chris@16 172 ///
Chris@16 173 ////////////////////////////////////////////////////////////////////////////////
Chris@16 174
Chris@16 175 /// \defgroup PixelIteratorModelPackedInterleavedPtr Pointer to packed_pixel<P,CR,Layout>
Chris@16 176 /// \ingroup PixelIteratorModel
Chris@16 177 /// \brief Iterators over interleaved pixels.
Chris@16 178 /// The pointer packed_pixel<P,CR,Layout>* is used as an iterator over interleaved pixels of packed format. Models PixelIteratorConcept, HasDynamicXStepTypeConcept, MemoryBasedIteratorConcept
Chris@16 179
Chris@16 180 template <typename P, typename C, typename L>
Chris@16 181 struct iterator_is_mutable<packed_pixel<P,C,L>*> : public mpl::bool_<packed_pixel<P,C,L>::is_mutable> {};
Chris@16 182 template <typename P, typename C, typename L>
Chris@16 183 struct iterator_is_mutable<const packed_pixel<P,C,L>*> : public mpl::false_ {};
Chris@16 184
Chris@16 185
Chris@16 186
Chris@16 187 } } // namespace boost::gil
Chris@16 188
Chris@16 189 namespace boost {
Chris@16 190 template <typename P, typename C, typename L>
Chris@16 191 struct has_trivial_constructor<gil::packed_pixel<P,C,L> > : public has_trivial_constructor<P> {};
Chris@16 192 }
Chris@16 193 #endif