2 Copyright 2005-2007 Adobe Systems Incorporated
4 Use, modification and distribution are subject to the Boost Software License,
5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt).
8 See http://stlab.adobe.com/gil for most recent version including documentation.
11 /*************************************************************************************************/
13 #ifndef GIL_CHANNEL_HPP
14 #define GIL_CHANNEL_HPP
16 ////////////////////////////////////////////////////////////////////////////////////////
18 /// \brief Channel utilities
19 /// \author Lubomir Bourdev and Hailin Jin \n
20 /// Adobe Systems Incorporated
21 /// \date 2005-2007 \n Last updated on May 6, 2007
23 /// Definitions of standard GIL channel models
25 ////////////////////////////////////////////////////////////////////////////////////////
29 #include <boost/cstdint.hpp>
30 #include "gil_config.hpp"
31 #include "utilities.hpp"
33 namespace boost { namespace gil {
36 ///////////////////////////////////////////
39 //// \ingroup ChannelModel
40 //// \class channel_traits
41 //// \brief defines properties of channels, such as their range and associated types
43 //// The channel traits must be defined for every model of ChannelConcept
44 //// Default traits are provided. For built-in types the default traits use
45 //// built-in pointer and reference and the channel range is the physical
46 //// range of the type. For classes, the default traits forward the associated types
47 //// and range to the class.
49 ///////////////////////////////////////////
52 template <typename T, bool is_class> struct channel_traits_impl;
54 // channel traits for custom class
56 struct channel_traits_impl<T, true> {
57 typedef typename T::value_type value_type;
58 typedef typename T::reference reference;
59 typedef typename T::pointer pointer;
60 typedef typename T::const_reference const_reference;
61 typedef typename T::const_pointer const_pointer;
62 BOOST_STATIC_CONSTANT(bool, is_mutable=T::is_mutable);
63 static value_type min_value() { return T::min_value(); }
64 static value_type max_value() { return T::max_value(); }
67 // channel traits implementation for built-in integral or floating point channel type
69 struct channel_traits_impl<T, false> {
73 typedef const T& const_reference;
74 typedef T const* const_pointer;
75 BOOST_STATIC_CONSTANT(bool, is_mutable=true);
76 static value_type min_value() { return (std::numeric_limits<T>::min)(); }
77 static value_type max_value() { return (std::numeric_limits<T>::max)(); }
80 // channel traits implementation for constant built-in scalar or floating point type
82 struct channel_traits_impl<const T, false> : public channel_traits_impl<T, false> {
83 typedef const T& reference;
84 typedef const T* pointer;
85 BOOST_STATIC_CONSTANT(bool, is_mutable=false);
91 \brief Traits for channels. Contains the following members:
93 template <typename Channel>
94 struct channel_traits {
95 typedef ... value_type;
96 typedef ... reference;
98 typedef ... const_reference;
99 typedef ... const_pointer;
101 static const bool is_mutable;
102 static value_type min_value();
103 static value_type max_value();
107 template <typename T>
108 struct channel_traits : public detail::channel_traits_impl<T, is_class<T>::value> {};
110 // Channel traits for C++ reference type - remove the reference
111 template <typename T> struct channel_traits< T&> : public channel_traits<T> {};
113 // Channel traits for constant C++ reference type
114 template <typename T> struct channel_traits<const T&> : public channel_traits<T> {
115 typedef typename channel_traits<T>::const_reference reference;
116 typedef typename channel_traits<T>::const_pointer pointer;
117 BOOST_STATIC_CONSTANT(bool, is_mutable=false);
120 ///////////////////////////////////////////
122 //// scoped_channel_value
124 ///////////////////////////////////////////
127 \defgroup ScopedChannelValue scoped_channel_value
128 \ingroup ChannelModel
129 \brief A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept
133 // Create a double channel with range [-0.5 .. 0.5]
134 struct double_minus_half { static double apply() { return -0.5; } };
135 struct double_plus_half { static double apply() { return 0.5; } };
136 typedef scoped_channel_value<double, double_minus_half, double_plus_half> bits64custom_t;
138 // channel_convert its maximum should map to the maximum
139 bits64custom_t x = channel_traits<bits64custom_t>::max_value();
141 bits16 y = channel_convert<bits16>(x);
146 /// \ingroup ScopedChannelValue
147 /// \brief A channel adaptor that modifies the range of the source channel. Models: ChannelValueConcept
148 template <typename BaseChannelValue, // base channel (models ChannelValueConcept)
149 typename MinVal, typename MaxVal> // classes with a static apply() function returning the minimum/maximum channel values
150 struct scoped_channel_value {
151 typedef scoped_channel_value value_type;
152 typedef value_type& reference;
153 typedef value_type* pointer;
154 typedef const value_type& const_reference;
155 typedef const value_type* const_pointer;
156 BOOST_STATIC_CONSTANT(bool, is_mutable=channel_traits<BaseChannelValue>::is_mutable);
158 typedef BaseChannelValue base_channel_t;
160 static value_type min_value() { return MinVal::apply(); }
161 static value_type max_value() { return MaxVal::apply(); }
163 scoped_channel_value() {}
164 scoped_channel_value(const scoped_channel_value& c) : _value(c._value) {}
165 scoped_channel_value(BaseChannelValue val) : _value(val) {}
167 scoped_channel_value& operator++() { ++_value; return *this; }
168 scoped_channel_value& operator--() { --_value; return *this; }
170 scoped_channel_value operator++(int) { scoped_channel_value tmp=*this; this->operator++(); return tmp; }
171 scoped_channel_value operator--(int) { scoped_channel_value tmp=*this; this->operator--(); return tmp; }
173 template <typename Scalar2> scoped_channel_value& operator+=(Scalar2 v) { _value+=v; return *this; }
174 template <typename Scalar2> scoped_channel_value& operator-=(Scalar2 v) { _value-=v; return *this; }
175 template <typename Scalar2> scoped_channel_value& operator*=(Scalar2 v) { _value*=v; return *this; }
176 template <typename Scalar2> scoped_channel_value& operator/=(Scalar2 v) { _value/=v; return *this; }
178 scoped_channel_value& operator=(BaseChannelValue v) { _value=v; return *this; }
179 operator BaseChannelValue() const { return _value; }
181 BaseChannelValue _value;
184 struct float_zero { static float apply() { return 0.0f; } };
185 struct float_one { static float apply() { return 1.0f; } };
188 ///////////////////////////////////////////
190 //// Support for sub-byte channels. These are integral channels whose value is contained in a range of bits inside an integral type
192 ///////////////////////////////////////////
194 // It is necessary for packed channels to have their own value type. They cannot simply use an integral large enough to store the data. Here is why:
195 // - Any operation that requires returning the result by value will otherwise return the built-in integral type, which will have incorrect range
196 // That means that after getting the value of the channel we cannot properly do channel_convert, channel_invert, etc.
197 // - Two channels are declared compatible if they have the same value type. That means that a packed channel is incorrectly declared compatible with an integral type
199 // returns the smallest fast unsigned integral type that has at least NumBits bits
200 template <int NumBits>
201 struct min_fast_uint : public mpl::if_c< (NumBits<=8),
203 typename mpl::if_c< (NumBits<=16),
205 typename mpl::if_c< (NumBits<=32),
212 template <int NumBits>
213 struct num_value_fn : public mpl::if_c< ( NumBits < 32 )
218 template <int NumBits>
219 struct max_value_fn : public mpl::if_c< ( NumBits <= 32 )
226 \defgroup PackedChannelValueModel packed_channel_value
227 \ingroup ChannelModel
228 \brief Represents the value of an unsigned integral channel operating over a bit range. Models: ChannelValueConcept
231 // A 4-bit unsigned integral channel.
232 typedef packed_channel_value<4> bits4;
234 assert(channel_traits<bits4>::min_value()==0);
235 assert(channel_traits<bits4>::max_value()==15);
236 assert(sizeof(bits4)==1);
237 BOOST_STATIC_ASSERT((boost::is_integral<bits4>::value));
241 /// \ingroup PackedChannelValueModel
242 /// \brief The value of a subbyte channel. Models: ChannelValueConcept
243 template <int NumBits>
244 class packed_channel_value {
246 typedef typename detail::num_value_fn< NumBits >::type num_value_t;
247 static const num_value_t num_values = static_cast< num_value_t >( 1 ) << NumBits ;
250 typedef typename detail::min_fast_uint<NumBits>::type integer_t;
253 typedef packed_channel_value value_type;
254 typedef value_type& reference;
255 typedef const value_type& const_reference;
256 typedef value_type* pointer;
257 typedef const value_type* const_pointer;
259 static value_type min_value() { return value_type(0); }
260 static value_type max_value() { return value_type(num_values-1); }
261 BOOST_STATIC_CONSTANT(bool, is_mutable=true);
263 packed_channel_value() {}
264 packed_channel_value(integer_t v) { _value = static_cast< integer_t >( v % num_values ); }
265 packed_channel_value(const packed_channel_value& v) : _value(v._value) {}
266 template <typename Scalar> packed_channel_value(Scalar v) { _value = static_cast< integer_t >( v ) % num_values; }
268 static unsigned int num_bits() { return NumBits; }
271 operator integer_t() const { return _value; }
278 template <std::size_t K>
279 struct static_copy_bytes {
280 void operator()(const unsigned char* from, unsigned char* to) const {
282 static_copy_bytes<K-1>()(++from,++to);
287 struct static_copy_bytes<0> {
288 void operator()(const unsigned char* , unsigned char*) const {}
291 template <typename Derived, typename BitField, int NumBits, bool Mutable>
292 class packed_channel_reference_base {
294 typedef typename mpl::if_c<Mutable,void*,const void*>::type data_ptr_t;
296 data_ptr_t _data_ptr; // void* pointer to the first byte of the bit range
298 typedef packed_channel_value<NumBits> value_type;
299 typedef const Derived reference;
300 typedef value_type* pointer;
301 typedef const value_type* const_pointer;
302 BOOST_STATIC_CONSTANT(int, num_bits=NumBits);
303 BOOST_STATIC_CONSTANT(bool, is_mutable=Mutable);
305 static value_type min_value() { return channel_traits<value_type>::min_value(); }
306 static value_type max_value() { return channel_traits<value_type>::max_value(); }
308 typedef BitField bitfield_t;
309 typedef typename value_type::integer_t integer_t;
311 packed_channel_reference_base(data_ptr_t data_ptr) : _data_ptr(data_ptr) {}
312 packed_channel_reference_base(const packed_channel_reference_base& ref) : _data_ptr(ref._data_ptr) {}
313 const Derived& operator=(integer_t v) const { set(v); return derived(); }
315 const Derived& operator++() const { set(get()+1); return derived(); }
316 const Derived& operator--() const { set(get()-1); return derived(); }
318 Derived operator++(int) const { Derived tmp=derived(); this->operator++(); return tmp; }
319 Derived operator--(int) const { Derived tmp=derived(); this->operator--(); return tmp; }
321 template <typename Scalar2> const Derived& operator+=(Scalar2 v) const { set(get()+v); return derived(); }
322 template <typename Scalar2> const Derived& operator-=(Scalar2 v) const { set(get()-v); return derived(); }
323 template <typename Scalar2> const Derived& operator*=(Scalar2 v) const { set(get()*v); return derived(); }
324 template <typename Scalar2> const Derived& operator/=(Scalar2 v) const { set(get()/v); return derived(); }
326 operator integer_t() const { return get(); }
327 data_ptr_t operator &() const {return _data_ptr;}
330 typedef typename detail::num_value_fn< NumBits >::type num_value_t;
331 typedef typename detail::max_value_fn< NumBits >::type max_value_t;
333 static const num_value_t num_values = static_cast< num_value_t >( 1 ) << NumBits ;
334 static const max_value_t max_val = static_cast< max_value_t >( num_values - 1 );
336 #ifdef GIL_NONWORD_POINTER_ALIGNMENT_SUPPORTED
337 const bitfield_t& get_data() const { return *static_cast<const bitfield_t*>(_data_ptr); }
338 void set_data(const bitfield_t& val) const { *static_cast< bitfield_t*>(_data_ptr) = val; }
340 bitfield_t get_data() const {
342 static_copy_bytes<sizeof(bitfield_t) >()(gil_reinterpret_cast_c<const unsigned char*>(_data_ptr),gil_reinterpret_cast<unsigned char*>(&ret));
345 void set_data(const bitfield_t& val) const {
346 static_copy_bytes<sizeof(bitfield_t) >()(gil_reinterpret_cast_c<const unsigned char*>(&val),gil_reinterpret_cast<unsigned char*>(_data_ptr));
351 void set(integer_t value) const { // can this be done faster??
352 const integer_t num_values = max_val+1;
353 this->derived().set_unsafe(((value % num_values) + num_values) % num_values);
355 integer_t get() const { return derived().get(); }
356 const Derived& derived() const { return static_cast<const Derived&>(*this); }
358 } // namespace detail
361 \defgroup PackedChannelReferenceModel packed_channel_reference
362 \ingroup ChannelModel
363 \brief Represents a reference proxy to a channel operating over a bit range whose offset is fixed at compile time. Models ChannelConcept
366 // Reference to a 2-bit channel starting at bit 1 (i.e. the second bit)
367 typedef const packed_channel_reference<uint16_t,1,2,true> bits2_1_ref_t;
370 bits2_1_ref_t channel_ref(&data);
371 channel_ref = channel_traits<bits2_1_ref_t>::max_value(); // == 3
372 assert(data == 6); // == 3<<1 == 6
376 template <typename BitField, // A type that holds the bits of the pixel from which the channel is referenced. Typically an integral type, like boost::uint16_t
377 int FirstBit, int NumBits,// Defines the sequence of bits in the data value that contain the channel
378 bool Mutable> // true if the reference is mutable
379 class packed_channel_reference;
381 template <typename BitField, // A type that holds the bits of the pixel from which the channel is referenced. Typically an integral type, like boost::uint16_t
382 int NumBits, // Defines the sequence of bits in the data value that contain the channel
383 bool Mutable> // true if the reference is mutable
384 class packed_dynamic_channel_reference;
386 /// \ingroup PackedChannelReferenceModel
387 /// \brief A constant subbyte channel reference whose bit offset is fixed at compile time. Models ChannelConcept
388 template <typename BitField, int FirstBit, int NumBits>
389 class packed_channel_reference<BitField,FirstBit,NumBits,false>
390 : public detail::packed_channel_reference_base<packed_channel_reference<BitField,FirstBit,NumBits,false>,BitField,NumBits,false> {
391 typedef detail::packed_channel_reference_base<packed_channel_reference<BitField,FirstBit,NumBits,false>,BitField,NumBits,false> parent_t;
392 friend class packed_channel_reference<BitField,FirstBit,NumBits,true>;
394 static const BitField channel_mask = static_cast< BitField >( parent_t::max_val ) << FirstBit;
396 void operator=(const packed_channel_reference&);
398 typedef const packed_channel_reference<BitField,FirstBit,NumBits,false> const_reference;
399 typedef const packed_channel_reference<BitField,FirstBit,NumBits,true> mutable_reference;
400 typedef typename parent_t::integer_t integer_t;
402 explicit packed_channel_reference(const void* data_ptr) : parent_t(data_ptr) {}
403 packed_channel_reference(const packed_channel_reference& ref) : parent_t(ref._data_ptr) {}
404 packed_channel_reference(const mutable_reference& ref) : parent_t(ref._data_ptr) {}
406 unsigned first_bit() const { return FirstBit; }
408 integer_t get() const { return integer_t((this->get_data()&channel_mask) >> FirstBit); }
411 /// \ingroup PackedChannelReferenceModel
412 /// \brief A mutable subbyte channel reference whose bit offset is fixed at compile time. Models ChannelConcept
413 template <typename BitField, int FirstBit, int NumBits>
414 class packed_channel_reference<BitField,FirstBit,NumBits,true>
415 : public detail::packed_channel_reference_base<packed_channel_reference<BitField,FirstBit,NumBits,true>,BitField,NumBits,true> {
416 typedef detail::packed_channel_reference_base<packed_channel_reference<BitField,FirstBit,NumBits,true>,BitField,NumBits,true> parent_t;
417 friend class packed_channel_reference<BitField,FirstBit,NumBits,false>;
419 static const BitField channel_mask = static_cast< BitField >( parent_t::max_val ) << FirstBit;
422 typedef const packed_channel_reference<BitField,FirstBit,NumBits,false> const_reference;
423 typedef const packed_channel_reference<BitField,FirstBit,NumBits,true> mutable_reference;
424 typedef typename parent_t::integer_t integer_t;
426 explicit packed_channel_reference(void* data_ptr) : parent_t(data_ptr) {}
427 packed_channel_reference(const packed_channel_reference& ref) : parent_t(ref._data_ptr) {}
429 const packed_channel_reference& operator=(integer_t value) const { assert(value<=parent_t::max_val); set_unsafe(value); return *this; }
430 const packed_channel_reference& operator=(const mutable_reference& ref) const { set_from_reference(ref.get_data()); return *this; }
431 const packed_channel_reference& operator=(const const_reference& ref) const { set_from_reference(ref.get_data()); return *this; }
433 template <bool Mutable1>
434 const packed_channel_reference& operator=(const packed_dynamic_channel_reference<BitField,NumBits,Mutable1>& ref) const { set_unsafe(ref.get()); return *this; }
436 unsigned first_bit() const { return FirstBit; }
438 integer_t get() const { return integer_t((this->get_data()&channel_mask) >> FirstBit); }
439 void set_unsafe(integer_t value) const { this->set_data((this->get_data() & ~channel_mask) | (( static_cast< BitField >( value )<<FirstBit))); }
441 void set_from_reference(const BitField& other_bits) const { this->set_data((this->get_data() & ~channel_mask) | (other_bits & channel_mask)); }
444 } } // namespace boost::gil
447 // We are forced to define swap inside std namespace because on some platforms (Visual Studio 8) STL calls swap qualified.
448 // swap with 'left bias':
449 // - swap between proxy and anything
450 // - swap between value type and proxy
451 // - swap between proxy and proxy
453 /// \ingroup PackedChannelReferenceModel
454 /// \brief swap for packed_channel_reference
455 template <typename BF, int FB, int NB, bool M, typename R> inline
456 void swap(const boost::gil::packed_channel_reference<BF,FB,NB,M> x, R& y) {
457 boost::gil::swap_proxy<typename boost::gil::packed_channel_reference<BF,FB,NB,M>::value_type>(x,y);
461 /// \ingroup PackedChannelReferenceModel
462 /// \brief swap for packed_channel_reference
463 template <typename BF, int FB, int NB, bool M> inline
464 void swap(typename boost::gil::packed_channel_reference<BF,FB,NB,M>::value_type& x, const boost::gil::packed_channel_reference<BF,FB,NB,M> y) {
465 boost::gil::swap_proxy<typename boost::gil::packed_channel_reference<BF,FB,NB,M>::value_type>(x,y);
469 /// \ingroup PackedChannelReferenceModel
470 /// \brief swap for packed_channel_reference
471 template <typename BF, int FB, int NB, bool M> inline
472 void swap(const boost::gil::packed_channel_reference<BF,FB,NB,M> x, const boost::gil::packed_channel_reference<BF,FB,NB,M> y) {
473 boost::gil::swap_proxy<typename boost::gil::packed_channel_reference<BF,FB,NB,M>::value_type>(x,y);
477 namespace boost { namespace gil {
480 \defgroup PackedChannelDynamicReferenceModel packed_dynamic_channel_reference
481 \ingroup ChannelModel
482 \brief Represents a reference proxy to a channel operating over a bit range whose offset is specified at run time. Models ChannelConcept
486 // Reference to a 2-bit channel whose offset is specified at construction time
487 typedef const packed_dynamic_channel_reference<uint8_t,2,true> bits2_dynamic_ref_t;
490 bits2_dynamic_ref_t channel_ref(&data,1);
491 channel_ref = channel_traits<bits2_dynamic_ref_t>::max_value(); // == 3
492 assert(data == 6); // == (3<<1) == 6
496 /// \brief Models a constant subbyte channel reference whose bit offset is a runtime parameter. Models ChannelConcept
497 /// Same as packed_channel_reference, except that the offset is a runtime parameter
498 /// \ingroup PackedChannelDynamicReferenceModel
499 template <typename BitField, int NumBits>
500 class packed_dynamic_channel_reference<BitField,NumBits,false>
501 : public detail::packed_channel_reference_base<packed_dynamic_channel_reference<BitField,NumBits,false>,BitField,NumBits,false> {
502 typedef detail::packed_channel_reference_base<packed_dynamic_channel_reference<BitField,NumBits,false>,BitField,NumBits,false> parent_t;
503 friend class packed_dynamic_channel_reference<BitField,NumBits,true>;
505 unsigned _first_bit; // 0..7
507 void operator=(const packed_dynamic_channel_reference&);
509 typedef const packed_dynamic_channel_reference<BitField,NumBits,false> const_reference;
510 typedef const packed_dynamic_channel_reference<BitField,NumBits,true> mutable_reference;
511 typedef typename parent_t::integer_t integer_t;
513 packed_dynamic_channel_reference(const void* data_ptr, unsigned first_bit) : parent_t(data_ptr), _first_bit(first_bit) {}
514 packed_dynamic_channel_reference(const const_reference& ref) : parent_t(ref._data_ptr), _first_bit(ref._first_bit) {}
515 packed_dynamic_channel_reference(const mutable_reference& ref) : parent_t(ref._data_ptr), _first_bit(ref._first_bit) {}
517 unsigned first_bit() const { return _first_bit; }
519 integer_t get() const {
520 const BitField channel_mask = static_cast< integer_t >( parent_t::max_val ) <<_first_bit;
521 return static_cast< integer_t >(( this->get_data()&channel_mask ) >> _first_bit );
525 /// \brief Models a mutable subbyte channel reference whose bit offset is a runtime parameter. Models ChannelConcept
526 /// Same as packed_channel_reference, except that the offset is a runtime parameter
527 /// \ingroup PackedChannelDynamicReferenceModel
528 template <typename BitField, int NumBits>
529 class packed_dynamic_channel_reference<BitField,NumBits,true>
530 : public detail::packed_channel_reference_base<packed_dynamic_channel_reference<BitField,NumBits,true>,BitField,NumBits,true> {
531 typedef detail::packed_channel_reference_base<packed_dynamic_channel_reference<BitField,NumBits,true>,BitField,NumBits,true> parent_t;
532 friend class packed_dynamic_channel_reference<BitField,NumBits,false>;
537 typedef const packed_dynamic_channel_reference<BitField,NumBits,false> const_reference;
538 typedef const packed_dynamic_channel_reference<BitField,NumBits,true> mutable_reference;
539 typedef typename parent_t::integer_t integer_t;
541 packed_dynamic_channel_reference(void* data_ptr, unsigned first_bit) : parent_t(data_ptr), _first_bit(first_bit) {}
542 packed_dynamic_channel_reference(const packed_dynamic_channel_reference& ref) : parent_t(ref._data_ptr), _first_bit(ref._first_bit) {}
544 const packed_dynamic_channel_reference& operator=(integer_t value) const { assert(value<=parent_t::max_val); set_unsafe(value); return *this; }
545 const packed_dynamic_channel_reference& operator=(const mutable_reference& ref) const { set_unsafe(ref.get()); return *this; }
546 const packed_dynamic_channel_reference& operator=(const const_reference& ref) const { set_unsafe(ref.get()); return *this; }
548 template <typename BitField1, int FirstBit1, bool Mutable1>
549 const packed_dynamic_channel_reference& operator=(const packed_channel_reference<BitField1, FirstBit1, NumBits, Mutable1>& ref) const
550 { set_unsafe(ref.get()); return *this; }
552 unsigned first_bit() const { return _first_bit; }
554 integer_t get() const {
555 const BitField channel_mask = static_cast< integer_t >( parent_t::max_val ) << _first_bit;
556 return static_cast< integer_t >(( this->get_data()&channel_mask ) >> _first_bit );
559 void set_unsafe(integer_t value) const {
560 const BitField channel_mask = static_cast< integer_t >( parent_t::max_val ) << _first_bit;
561 this->set_data((this->get_data() & ~channel_mask) | value<<_first_bit);
564 } } // namespace boost::gil
567 // We are forced to define swap inside std namespace because on some platforms (Visual Studio 8) STL calls swap qualified.
568 // swap with 'left bias':
569 // - swap between proxy and anything
570 // - swap between value type and proxy
571 // - swap between proxy and proxy
574 /// \ingroup PackedChannelDynamicReferenceModel
575 /// \brief swap for packed_dynamic_channel_reference
576 template <typename BF, int NB, bool M, typename R> inline
577 void swap(const boost::gil::packed_dynamic_channel_reference<BF,NB,M> x, R& y) {
578 boost::gil::swap_proxy<typename boost::gil::packed_dynamic_channel_reference<BF,NB,M>::value_type>(x,y);
582 /// \ingroup PackedChannelDynamicReferenceModel
583 /// \brief swap for packed_dynamic_channel_reference
584 template <typename BF, int NB, bool M> inline
585 void swap(typename boost::gil::packed_dynamic_channel_reference<BF,NB,M>::value_type& x, const boost::gil::packed_dynamic_channel_reference<BF,NB,M> y) {
586 boost::gil::swap_proxy<typename boost::gil::packed_dynamic_channel_reference<BF,NB,M>::value_type>(x,y);
590 /// \ingroup PackedChannelDynamicReferenceModel
591 /// \brief swap for packed_dynamic_channel_reference
592 template <typename BF, int NB, bool M> inline
593 void swap(const boost::gil::packed_dynamic_channel_reference<BF,NB,M> x, const boost::gil::packed_dynamic_channel_reference<BF,NB,M> y) {
594 boost::gil::swap_proxy<typename boost::gil::packed_dynamic_channel_reference<BF,NB,M>::value_type>(x,y);
598 namespace boost { namespace gil {
599 ///////////////////////////////////////////
601 //// Built-in channel models
603 ///////////////////////////////////////////
605 /// \defgroup bits8 bits8
606 /// \ingroup ChannelModel
607 /// \brief 8-bit unsigned integral channel type (typedef from uint8_t). Models ChannelValueConcept
610 typedef uint8_t bits8;
612 /// \defgroup bits16 bits16
613 /// \ingroup ChannelModel
614 /// \brief 16-bit unsigned integral channel type (typedef from uint16_t). Models ChannelValueConcept
617 typedef uint16_t bits16;
619 /// \defgroup bits32 bits32
620 /// \ingroup ChannelModel
621 /// \brief 32-bit unsigned integral channel type (typedef from uint32_t). Models ChannelValueConcept
624 typedef uint32_t bits32;
626 /// \defgroup bits8s bits8s
627 /// \ingroup ChannelModel
628 /// \brief 8-bit signed integral channel type (typedef from int8_t). Models ChannelValueConcept
631 typedef int8_t bits8s;
633 /// \defgroup bits16s bits16s
634 /// \ingroup ChannelModel
635 /// \brief 16-bit signed integral channel type (typedef from int16_t). Models ChannelValueConcept
638 typedef int16_t bits16s;
640 /// \defgroup bits32s bits32s
641 /// \ingroup ChannelModel
642 /// \brief 32-bit signed integral channel type (typedef from int32_t). Models ChannelValueConcept
645 typedef int32_t bits32s;
647 /// \defgroup bits32f bits32f
648 /// \ingroup ChannelModel
649 /// \brief 32-bit floating point channel type with range [0.0f ... 1.0f]. Models ChannelValueConcept
652 typedef scoped_channel_value<float,float_zero,float_one> bits32f;
654 } } // namespace boost::gil
658 template <int NumBits>
659 struct is_integral<gil::packed_channel_value<NumBits> > : public mpl::true_ {};
661 template <typename BitField, int FirstBit, int NumBits, bool IsMutable>
662 struct is_integral<gil::packed_channel_reference<BitField,FirstBit,NumBits,IsMutable> > : public mpl::true_ {};
664 template <typename BitField, int NumBits, bool IsMutable>
665 struct is_integral<gil::packed_dynamic_channel_reference<BitField,NumBits,IsMutable> > : public mpl::true_ {};
667 template <typename BaseChannelValue, typename MinVal, typename MaxVal>
668 struct is_integral<gil::scoped_channel_value<BaseChannelValue,MinVal,MaxVal> > : public is_integral<BaseChannelValue> {};