annotate DEPENDENCIES/generic/include/boost/gil/pixel.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +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 #ifndef GIL_PIXEL_H
Chris@16 13 #define GIL_PIXEL_H
Chris@16 14
Chris@16 15 ////////////////////////////////////////////////////////////////////////////////////////
Chris@16 16 /// \file
Chris@16 17 /// \brief pixel class and related utilities
Chris@16 18 /// \author Lubomir Bourdev and Hailin Jin \n
Chris@16 19 /// Adobe Systems Incorporated
Chris@16 20 /// \date 2005-2007 \n Last updated on September 28, 2006
Chris@16 21 ///
Chris@16 22 ////////////////////////////////////////////////////////////////////////////////////////
Chris@16 23
Chris@16 24 #include <functional>
Chris@16 25 #include <boost/utility/enable_if.hpp>
Chris@16 26 #include <boost/mpl/bool.hpp>
Chris@16 27 #include <boost/mpl/front.hpp>
Chris@16 28 #include <boost/type_traits.hpp>
Chris@16 29 #include "gil_config.hpp"
Chris@16 30 #include "color_base.hpp"
Chris@16 31 #include "gil_concept.hpp"
Chris@16 32 #include "channel.hpp"
Chris@16 33 #include "metafunctions.hpp"
Chris@16 34 #include "utilities.hpp"
Chris@16 35 #include "color_base_algorithm.hpp"
Chris@16 36
Chris@16 37 namespace boost { namespace gil {
Chris@16 38
Chris@16 39 // Forward-declare gray_t
Chris@16 40 struct gray_color_t;
Chris@16 41 typedef mpl::vector1<gray_color_t> gray_t;
Chris@16 42 template <typename PixelBased> struct color_space_type;
Chris@16 43 template <typename PixelBased> struct channel_mapping_type;
Chris@16 44 template <typename PixelBased> struct channel_type;
Chris@16 45 template <typename PixelBased> struct is_planar;
Chris@16 46
Chris@16 47 template <typename PixelBased> struct color_space_type<const PixelBased> : public color_space_type<PixelBased> {};
Chris@16 48 template <typename PixelBased> struct channel_mapping_type<const PixelBased> : public channel_mapping_type<PixelBased> {};
Chris@16 49 template <typename PixelBased> struct channel_type<const PixelBased> : public channel_type<PixelBased> {};
Chris@16 50
Chris@16 51 template <typename PixelBased> struct is_planar : mpl::false_ {};
Chris@16 52 template <typename PixelBased> struct is_planar<const PixelBased> : public is_planar<PixelBased> {};
Chris@16 53
Chris@16 54
Chris@16 55 template <typename T> struct is_pixel : public mpl::false_{};
Chris@16 56 template <typename T> struct is_pixel<const T> : public is_pixel<T> {};
Chris@16 57
Chris@16 58 /// \ingroup PixelBasedAlgorithm
Chris@16 59 /// \brief Returns the number of channels of a pixel-based GIL construct
Chris@16 60 template <typename PixelBased>
Chris@16 61 struct num_channels : public mpl::size<typename color_space_type<PixelBased>::type> {};
Chris@16 62
Chris@16 63 /**
Chris@16 64 \addtogroup PixelBasedAlgorithm
Chris@16 65
Chris@16 66 Example:
Chris@16 67 \code
Chris@16 68 BOOST_STATIC_ASSERT((num_channels<rgb8_view_t>::value==3));
Chris@16 69 BOOST_STATIC_ASSERT((num_channels<cmyk16_planar_ptr_t>::value==4));
Chris@16 70
Chris@16 71 BOOST_STATIC_ASSERT((is_planar<rgb16_planar_image_t>::value));
Chris@16 72 BOOST_STATIC_ASSERT((is_same<color_space_type<rgb8_planar_ref_t>::type, rgb_t>::value));
Chris@16 73 BOOST_STATIC_ASSERT((is_same<channel_mapping_type<cmyk8_pixel_t>::type,
Chris@16 74 channel_mapping_type<rgba8_pixel_t>::type>::value));
Chris@16 75 BOOST_STATIC_ASSERT((is_same<channel_type<bgr8_pixel_t>::type, bits8>::value));
Chris@16 76 \endcode
Chris@16 77 */
Chris@16 78
Chris@16 79 /// \defgroup ColorBaseModelPixel pixel
Chris@16 80 /// \ingroup ColorBaseModel
Chris@16 81 /// \brief A homogeneous color base whose element is a channel value. Models HomogeneousColorBaseValueConcept
Chris@16 82
Chris@16 83 /// \defgroup PixelModelPixel pixel
Chris@16 84 /// \ingroup PixelModel
Chris@16 85 /// \brief A homogeneous pixel value. Models HomogeneousPixelValueConcept
Chris@16 86
Chris@16 87 /// \ingroup PixelModelPixel ColorBaseModelPixel PixelBasedModel
Chris@16 88 /// \brief Represents a pixel value (a container of channels). Models: HomogeneousColorBaseValueConcept, PixelValueConcept, HomogeneousPixelBasedConcept
Chris@16 89 ///
Chris@16 90 /// A pixel is a set of channels defining the color at a given point in an image. Conceptually, a pixel is little more than a color base whose elements
Chris@16 91 /// model \p ChannelConcept. The class \p pixel defines a simple, homogeneous pixel value. It is used to store
Chris@16 92 /// the value of a color. The built-in C++ references to \p pixel, \p pixel& and \p const \p pixel& are used to represent a reference to a pixel
Chris@16 93 /// inside an interleaved image view (a view in which all channels are together in memory). Similarly, built-in pointer types \p pixel* and \p const \p pixel*
Chris@16 94 /// are used as the standard iterator over a row of interleaved homogeneous pixels.
Chris@16 95 ///
Chris@16 96 /// Since \p pixel inherits the properties of color base, assigning, equality comparison and copy-construcion are allowed between compatible pixels.
Chris@16 97 /// This means that an 8-bit RGB pixel may be assigned to an 8-bit BGR pixel, or to an 8-bit planar reference. The channels are properly paired semantically.
Chris@16 98 ///
Chris@16 99 /// The single-channel (grayscale) instantiation of the class pixel, (i.e. \p pixel<T,gray_layout_t>) is also convertible to/from a channel value.
Chris@16 100 /// This allows grayscale pixels to be used in simpler expressions like *gray_pix1 = *gray_pix2 instead of more complicated at_c<0>(gray_pix1) = at_c<0>(gray_pix2)
Chris@16 101 /// or get_color<gray_color_t>(gray_pix1) = get_color<gray_color_t>(gray_pix2)
Chris@16 102
Chris@16 103 template <typename ChannelValue, typename Layout> // = mpl::range_c<int,0,ColorSpace::size> >
Chris@16 104 struct pixel : public detail::homogeneous_color_base<ChannelValue,Layout,mpl::size<typename Layout::color_space_t>::value> {
Chris@16 105 private:
Chris@16 106 typedef ChannelValue channel_t;
Chris@16 107 typedef detail::homogeneous_color_base<ChannelValue,Layout,mpl::size<typename Layout::color_space_t>::value> parent_t;
Chris@16 108 public:
Chris@16 109 typedef pixel value_type;
Chris@16 110 typedef value_type& reference;
Chris@16 111 typedef const value_type& const_reference;
Chris@16 112 BOOST_STATIC_CONSTANT(bool, is_mutable = channel_traits<channel_t>::is_mutable);
Chris@16 113
Chris@16 114 pixel(){}
Chris@16 115 explicit pixel(channel_t v) : parent_t(v) {} // sets all channels to v
Chris@16 116 pixel(channel_t v0, channel_t v1) : parent_t(v0,v1) {}
Chris@16 117 pixel(channel_t v0, channel_t v1, channel_t v2) : parent_t(v0,v1,v2) {}
Chris@16 118 pixel(channel_t v0, channel_t v1, channel_t v2, channel_t v3) : parent_t(v0,v1,v2,v3) {}
Chris@16 119 pixel(channel_t v0, channel_t v1, channel_t v2, channel_t v3, channel_t v4) : parent_t(v0,v1,v2,v3,v4) {}
Chris@16 120 pixel(channel_t v0, channel_t v1, channel_t v2, channel_t v3, channel_t v4, channel_t v5) : parent_t(v0,v1,v2,v3,v4,v5) {}
Chris@16 121
Chris@16 122 pixel(const pixel& p) : parent_t(p) {}
Chris@16 123 pixel& operator=(const pixel& p) { static_copy(p,*this); return *this; }
Chris@16 124
Chris@16 125 // Construct from another compatible pixel type
Chris@16 126 template <typename Pixel> pixel(const Pixel& p, typename enable_if_c<is_pixel<Pixel>::value>::type* dummy = 0) : parent_t(p) {
Chris@16 127 check_compatible<Pixel>();
Chris@16 128 }
Chris@16 129
Chris@16 130 template <typename P> pixel& operator=(const P& p) { assign(p, mpl::bool_<is_pixel<P>::value>()); return *this; }
Chris@16 131 template <typename P> bool operator==(const P& p) const { return equal(p, mpl::bool_<is_pixel<P>::value>()); }
Chris@16 132
Chris@16 133 template <typename P> bool operator!=(const P& p) const { return !(*this==p); }
Chris@16 134
Chris@16 135 // homogeneous pixels have operator[]
Chris@16 136 typename channel_traits<channel_t>::reference operator[](std::size_t i) { return dynamic_at_c(*this,i); }
Chris@16 137 typename channel_traits<channel_t>::const_reference operator[](std::size_t i) const { return dynamic_at_c(*this,i); }
Chris@16 138 private:
Chris@16 139 template <typename Pixel> void assign(const Pixel& p, mpl::true_) { check_compatible<Pixel>(); static_copy(p,*this); }
Chris@16 140 template <typename Pixel> bool equal(const Pixel& p, mpl::true_) const { check_compatible<Pixel>(); return static_equal(*this,p); }
Chris@16 141
Chris@16 142 template <typename Pixel> void check_compatible() const { gil_function_requires<PixelsCompatibleConcept<Pixel,pixel> >(); }
Chris@16 143
Chris@16 144 // Support for assignment/equality comparison of a channel with a grayscale pixel
Chris@16 145
Chris@16 146 private:
Chris@16 147 static void check_gray() { BOOST_STATIC_ASSERT((is_same<typename Layout::color_space_t, gray_t>::value)); }
Chris@16 148 template <typename Channel> void assign(const Channel& chan, mpl::false_) { check_gray(); gil::at_c<0>(*this)=chan; }
Chris@16 149 template <typename Channel> bool equal (const Channel& chan, mpl::false_) const { check_gray(); return gil::at_c<0>(*this)==chan; }
Chris@16 150 public:
Chris@16 151 pixel& operator= (channel_t chan) { check_gray(); gil::at_c<0>(*this)=chan; return *this; }
Chris@16 152 bool operator==(channel_t chan) const { check_gray(); return gil::at_c<0>(*this)==chan; }
Chris@16 153 };
Chris@16 154
Chris@16 155 /////////////////////////////
Chris@16 156 // ColorBasedConcept
Chris@16 157 /////////////////////////////
Chris@16 158
Chris@16 159 template <typename ChannelValue, typename Layout, int K>
Chris@16 160 struct kth_element_type<pixel<ChannelValue,Layout>, K> {
Chris@16 161 typedef ChannelValue type;
Chris@16 162 };
Chris@16 163
Chris@16 164 template <typename ChannelValue, typename Layout, int K>
Chris@16 165 struct kth_element_reference_type<pixel<ChannelValue,Layout>, K> {
Chris@16 166 typedef typename channel_traits<ChannelValue>::reference type;
Chris@16 167 };
Chris@16 168
Chris@16 169 template <typename ChannelValue, typename Layout, int K>
Chris@16 170 struct kth_element_reference_type<const pixel<ChannelValue,Layout>, K> {
Chris@16 171 typedef typename channel_traits<ChannelValue>::const_reference type;
Chris@16 172 };
Chris@16 173
Chris@16 174 template <typename ChannelValue, typename Layout, int K>
Chris@16 175 struct kth_element_const_reference_type<pixel<ChannelValue,Layout>, K> {
Chris@16 176 typedef typename channel_traits<ChannelValue>::const_reference type;
Chris@16 177 };
Chris@16 178
Chris@16 179 /////////////////////////////
Chris@16 180 // PixelConcept
Chris@16 181 /////////////////////////////
Chris@16 182
Chris@16 183 template <typename ChannelValue, typename Layout>
Chris@16 184 struct is_pixel<pixel<ChannelValue,Layout> > : public mpl::true_{};
Chris@16 185
Chris@16 186 /////////////////////////////
Chris@16 187 // HomogeneousPixelBasedConcept
Chris@16 188 /////////////////////////////
Chris@16 189
Chris@16 190 template <typename ChannelValue, typename Layout>
Chris@16 191 struct color_space_type<pixel<ChannelValue,Layout> > {
Chris@16 192 typedef typename Layout::color_space_t type;
Chris@16 193 };
Chris@16 194
Chris@16 195 template <typename ChannelValue, typename Layout>
Chris@16 196 struct channel_mapping_type<pixel<ChannelValue,Layout> > {
Chris@16 197 typedef typename Layout::channel_mapping_t type;
Chris@16 198 };
Chris@16 199
Chris@16 200 template <typename ChannelValue, typename Layout>
Chris@16 201 struct is_planar<pixel<ChannelValue,Layout> > : public mpl::false_ {};
Chris@16 202
Chris@16 203 template <typename ChannelValue, typename Layout>
Chris@16 204 struct channel_type<pixel<ChannelValue,Layout> > {
Chris@16 205 typedef ChannelValue type;
Chris@16 206 };
Chris@16 207
Chris@16 208 } } // namespace boost::gil
Chris@16 209
Chris@16 210 namespace boost {
Chris@16 211 template <typename ChannelValue, typename Layout>
Chris@16 212 struct has_trivial_constructor<gil::pixel<ChannelValue,Layout> > : public has_trivial_constructor<ChannelValue> {};
Chris@16 213 }
Chris@16 214 #endif