diff --git "a/C:\\DOCUME~1\\tongari\\LOCALS~1\\Temp\\TortoiseGit\\chaE5E.tmp\\channel-86d1d5e-left.hpp" "b/C:\\boost-dev\\gil\\include\\boost\\gil\\channel.hpp" index d8cf78c..4cf70ee 100644 --- "a/C:\\DOCUME~1\\tongari\\LOCALS~1\\Temp\\TortoiseGit\\chaE5E.tmp\\channel-86d1d5e-left.hpp" +++ "b/C:\\boost-dev\\gil\\include\\boost\\gil\\channel.hpp" @@ -1,6 +1,6 @@ /* Copyright 2005-2007 Adobe Systems Incorporated - + Use, modification and distribution are subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt). @@ -14,7 +14,7 @@ #define GIL_CHANNEL_HPP //////////////////////////////////////////////////////////////////////////////////////// -/// \file +/// \file /// \brief Channel utilities /// \author Lubomir Bourdev and Hailin Jin \n /// Adobe Systems Incorporated @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "gil_config.hpp" #include "utilities.hpp" @@ -36,24 +37,24 @@ namespace boost { namespace gil { /////////////////////////////////////////// //// channel_traits -//// +//// //// \ingroup ChannelModel //// \class channel_traits //// \brief defines properties of channels, such as their range and associated types //// //// The channel traits must be defined for every model of ChannelConcept //// Default traits are provided. For built-in types the default traits use -//// built-in pointer and reference and the channel range is the physical +//// built-in pointer and reference and the channel range is the physical //// range of the type. For classes, the default traits forward the associated types //// and range to the class. -//// +//// /////////////////////////////////////////// namespace detail { template struct channel_traits_impl; // channel traits for custom class - template + template struct channel_traits_impl { typedef typename T::value_type value_type; typedef typename T::reference reference; @@ -66,7 +67,7 @@ namespace detail { }; // channel traits implementation for built-in integral or floating point channel type - template + template struct channel_traits_impl { typedef T value_type; typedef T& reference; @@ -79,7 +80,7 @@ namespace detail { }; // channel traits implementation for constant built-in scalar or floating point type - template + template struct channel_traits_impl : public channel_traits_impl { typedef const T& reference; typedef const T* pointer; @@ -98,7 +99,7 @@ struct channel_traits { typedef ... pointer; typedef ... const_reference; typedef ... const_pointer; - + static const bool is_mutable; static value_type min_value(); static value_type max_value(); @@ -199,12 +200,12 @@ struct float_one { static float apply() { return 1.0f; } }; namespace detail { // returns the smallest fast unsigned integral type that has at least NumBits bits template - struct min_fast_uint : public mpl::if_c< (NumBits<=8), - uint_least8_t, - typename mpl::if_c< (NumBits<=16), - uint_least16_t, - typename mpl::if_c< (NumBits<=32), - uint_least32_t, + struct min_fast_uint : public mpl::if_c< (NumBits<=8), + uint_least8_t, + typename mpl::if_c< (NumBits<=16), + uint_least16_t, + typename mpl::if_c< (NumBits<=32), + uint_least32_t, uintmax_t >::type >::type @@ -246,7 +247,7 @@ class packed_channel_value { typedef typename detail::num_value_fn< NumBits >::type num_value_t; static const num_value_t num_values = static_cast< num_value_t >( 1 ) << NumBits ; - + public: typedef typename detail::min_fast_uint::type integer_t; @@ -262,9 +263,8 @@ public: BOOST_STATIC_CONSTANT(bool, is_mutable=true); packed_channel_value() {} - packed_channel_value(integer_t v) { _value = static_cast< integer_t >( v % num_values ); } + packed_channel_value(integer_t v) : _value(v & low_bits_mask_t::sig_bits_fast) {} packed_channel_value(const packed_channel_value& v) : _value(v._value) {} - template packed_channel_value(Scalar v) { _value = static_cast< integer_t >( v ) % num_values; } static unsigned int num_bits() { return NumBits; } @@ -311,7 +311,6 @@ public: packed_channel_reference_base(data_ptr_t data_ptr) : _data_ptr(data_ptr) {} packed_channel_reference_base(const packed_channel_reference_base& ref) : _data_ptr(ref._data_ptr) {} - const Derived& operator=(integer_t v) const { set(v); return derived(); } const Derived& operator++() const { set(get()+1); return derived(); } const Derived& operator--() const { set(get()-1); return derived(); } @@ -324,16 +323,17 @@ public: template const Derived& operator*=(Scalar2 v) const { set(get()*v); return derived(); } template const Derived& operator/=(Scalar2 v) const { set(get()/v); return derived(); } + integer_t get() const { return value_type(*this); } operator integer_t() const { return get(); } data_ptr_t operator &() const {return _data_ptr;} protected: typedef typename detail::num_value_fn< NumBits >::type num_value_t; typedef typename detail::max_value_fn< NumBits >::type max_value_t; - + static const num_value_t num_values = static_cast< num_value_t >( 1 ) << NumBits ; static const max_value_t max_val = static_cast< max_value_t >( num_values - 1 ); - + #ifdef GIL_NONWORD_POINTER_ALIGNMENT_SUPPORTED const bitfield_t& get_data() const { return *static_cast(_data_ptr); } void set_data(const bitfield_t& val) const { *static_cast< bitfield_t*>(_data_ptr) = val; } @@ -349,11 +349,10 @@ protected: #endif private: - void set(integer_t value) const { // can this be done faster?? - const integer_t num_values = max_val+1; - this->derived().set_unsafe(((value % num_values) + num_values) % num_values); + void set(integer_t value) const { // it's faster now ;-) + this->derived().set_unsafe(value); } - integer_t get() const { return derived().get(); } + const Derived& derived() const { return static_cast(*this); } }; } // namespace detail @@ -375,19 +374,19 @@ assert(data == 6); // == 3<<1 == 6 */ template // true if the reference is mutable + int FirstBit, int NumBits,// Defines the sequence of bits in the data value that contain the channel + bool Mutable> // true if the reference is mutable class packed_channel_reference; template // true if the reference is mutable + int NumBits, // Defines the sequence of bits in the data value that contain the channel + bool Mutable> // true if the reference is mutable class packed_dynamic_channel_reference; /// \ingroup PackedChannelReferenceModel /// \brief A constant subbyte channel reference whose bit offset is fixed at compile time. Models ChannelConcept template -class packed_channel_reference +class packed_channel_reference : public detail::packed_channel_reference_base,BitField,NumBits,false> { typedef detail::packed_channel_reference_base,BitField,NumBits,false> parent_t; friend class packed_channel_reference; @@ -398,6 +397,7 @@ class packed_channel_reference public: typedef const packed_channel_reference const_reference; typedef const packed_channel_reference mutable_reference; + typedef typename parent_t::value_type value_type; typedef typename parent_t::integer_t integer_t; explicit packed_channel_reference(const void* data_ptr) : parent_t(data_ptr) {} @@ -406,13 +406,13 @@ public: unsigned first_bit() const { return FirstBit; } - integer_t get() const { return integer_t((this->get_data()&channel_mask) >> FirstBit); } + operator value_type() const { return this->get_data() >> FirstBit; } }; /// \ingroup PackedChannelReferenceModel /// \brief A mutable subbyte channel reference whose bit offset is fixed at compile time. Models ChannelConcept template -class packed_channel_reference +class packed_channel_reference : public detail::packed_channel_reference_base,BitField,NumBits,true> { typedef detail::packed_channel_reference_base,BitField,NumBits,true> parent_t; friend class packed_channel_reference; @@ -422,12 +422,13 @@ class packed_channel_reference public: typedef const packed_channel_reference const_reference; typedef const packed_channel_reference mutable_reference; + typedef typename parent_t::value_type value_type; typedef typename parent_t::integer_t integer_t; explicit packed_channel_reference(void* data_ptr) : parent_t(data_ptr) {} packed_channel_reference(const packed_channel_reference& ref) : parent_t(ref._data_ptr) {} - const packed_channel_reference& operator=(integer_t value) const { assert(value<=parent_t::max_val); set_unsafe(value); return *this; } + const packed_channel_reference& operator=(value_type value) const { set_unsafe(value); return *this; } const packed_channel_reference& operator=(const mutable_reference& ref) const { set_from_reference(ref.get_data()); return *this; } const packed_channel_reference& operator=(const const_reference& ref) const { set_from_reference(ref.get_data()); return *this; } @@ -436,7 +437,7 @@ public: unsigned first_bit() const { return FirstBit; } - integer_t get() const { return integer_t((this->get_data()&channel_mask) >> FirstBit); } + operator value_type() const { return this->get_data() >> FirstBit; } void set_unsafe(integer_t value) const { this->set_data((this->get_data() & ~channel_mask) | (( static_cast< BitField >( value )<set_data((this->get_data() & ~channel_mask) | (other_bits & channel_mask)); } @@ -446,7 +447,7 @@ private: namespace std { // We are forced to define swap inside std namespace because on some platforms (Visual Studio 8) STL calls swap qualified. -// swap with 'left bias': +// swap with 'left bias': // - swap between proxy and anything // - swap between value type and proxy // - swap between proxy and proxy @@ -454,24 +455,24 @@ namespace std { /// \ingroup PackedChannelReferenceModel /// \brief swap for packed_channel_reference template inline -void swap(const boost::gil::packed_channel_reference x, R& y) { - boost::gil::swap_proxy::value_type>(x,y); +void swap(const boost::gil::packed_channel_reference x, R& y) { + boost::gil::swap_proxy::value_type>(x,y); } /// \ingroup PackedChannelReferenceModel /// \brief swap for packed_channel_reference template inline -void swap(typename boost::gil::packed_channel_reference::value_type& x, const boost::gil::packed_channel_reference y) { - boost::gil::swap_proxy::value_type>(x,y); +void swap(typename boost::gil::packed_channel_reference::value_type& x, const boost::gil::packed_channel_reference y) { + boost::gil::swap_proxy::value_type>(x,y); } /// \ingroup PackedChannelReferenceModel /// \brief swap for packed_channel_reference template inline -void swap(const boost::gil::packed_channel_reference x, const boost::gil::packed_channel_reference y) { - boost::gil::swap_proxy::value_type>(x,y); +void swap(const boost::gil::packed_channel_reference x, const boost::gil::packed_channel_reference y) { + boost::gil::swap_proxy::value_type>(x,y); } } // namespace std @@ -497,7 +498,7 @@ assert(data == 6); // == (3<<1) /// \brief Models a constant subbyte channel reference whose bit offset is a runtime parameter. Models ChannelConcept /// Same as packed_channel_reference, except that the offset is a runtime parameter /// \ingroup PackedChannelDynamicReferenceModel -template +template class packed_dynamic_channel_reference : public detail::packed_channel_reference_base,BitField,NumBits,false> { typedef detail::packed_channel_reference_base,BitField,NumBits,false> parent_t; @@ -509,6 +510,7 @@ class packed_dynamic_channel_reference public: typedef const packed_dynamic_channel_reference const_reference; typedef const packed_dynamic_channel_reference mutable_reference; + typedef typename parent_t::value_type value_type; typedef typename parent_t::integer_t integer_t; packed_dynamic_channel_reference(const void* data_ptr, unsigned first_bit) : parent_t(data_ptr), _first_bit(first_bit) {} @@ -517,16 +519,13 @@ public: unsigned first_bit() const { return _first_bit; } - integer_t get() const { - const BitField channel_mask = static_cast< integer_t >( parent_t::max_val ) <<_first_bit; - return static_cast< integer_t >(( this->get_data()&channel_mask ) >> _first_bit ); - } + operator value_type() const { return this->get_data() >> _first_bit; } }; /// \brief Models a mutable subbyte channel reference whose bit offset is a runtime parameter. Models ChannelConcept /// Same as packed_channel_reference, except that the offset is a runtime parameter /// \ingroup PackedChannelDynamicReferenceModel -template +template class packed_dynamic_channel_reference : public detail::packed_channel_reference_base,BitField,NumBits,true> { typedef detail::packed_channel_reference_base,BitField,NumBits,true> parent_t; @@ -537,36 +536,34 @@ class packed_dynamic_channel_reference public: typedef const packed_dynamic_channel_reference const_reference; typedef const packed_dynamic_channel_reference mutable_reference; + typedef typename parent_t::value_type value_type; typedef typename parent_t::integer_t integer_t; packed_dynamic_channel_reference(void* data_ptr, unsigned first_bit) : parent_t(data_ptr), _first_bit(first_bit) {} packed_dynamic_channel_reference(const packed_dynamic_channel_reference& ref) : parent_t(ref._data_ptr), _first_bit(ref._first_bit) {} - const packed_dynamic_channel_reference& operator=(integer_t value) const { assert(value<=parent_t::max_val); set_unsafe(value); return *this; } + const packed_dynamic_channel_reference& operator=(value_type value) const { set_unsafe(value); return *this; } const packed_dynamic_channel_reference& operator=(const mutable_reference& ref) const { set_unsafe(ref.get()); return *this; } const packed_dynamic_channel_reference& operator=(const const_reference& ref) const { set_unsafe(ref.get()); return *this; } template - const packed_dynamic_channel_reference& operator=(const packed_channel_reference& ref) const + const packed_dynamic_channel_reference& operator=(const packed_channel_reference& ref) const { set_unsafe(ref.get()); return *this; } unsigned first_bit() const { return _first_bit; } - integer_t get() const { - const BitField channel_mask = static_cast< integer_t >( parent_t::max_val ) << _first_bit; - return static_cast< integer_t >(( this->get_data()&channel_mask ) >> _first_bit ); - } + operator value_type() const { return this->get_data() >> _first_bit; } - void set_unsafe(integer_t value) const { + void set_unsafe(integer_t value) const { const BitField channel_mask = static_cast< integer_t >( parent_t::max_val ) << _first_bit; - this->set_data((this->get_data() & ~channel_mask) | value<<_first_bit); + this->set_data((this->get_data() & ~channel_mask) | value<<_first_bit); } }; } } // namespace boost::gil namespace std { // We are forced to define swap inside std namespace because on some platforms (Visual Studio 8) STL calls swap qualified. -// swap with 'left bias': +// swap with 'left bias': // - swap between proxy and anything // - swap between value type and proxy // - swap between proxy and proxy @@ -575,24 +572,24 @@ namespace std { /// \ingroup PackedChannelDynamicReferenceModel /// \brief swap for packed_dynamic_channel_reference template inline -void swap(const boost::gil::packed_dynamic_channel_reference x, R& y) { - boost::gil::swap_proxy::value_type>(x,y); +void swap(const boost::gil::packed_dynamic_channel_reference x, R& y) { + boost::gil::swap_proxy::value_type>(x,y); } /// \ingroup PackedChannelDynamicReferenceModel /// \brief swap for packed_dynamic_channel_reference template inline -void swap(typename boost::gil::packed_dynamic_channel_reference::value_type& x, const boost::gil::packed_dynamic_channel_reference y) { - boost::gil::swap_proxy::value_type>(x,y); +void swap(typename boost::gil::packed_dynamic_channel_reference::value_type& x, const boost::gil::packed_dynamic_channel_reference y) { + boost::gil::swap_proxy::value_type>(x,y); } /// \ingroup PackedChannelDynamicReferenceModel /// \brief swap for packed_dynamic_channel_reference template inline -void swap(const boost::gil::packed_dynamic_channel_reference x, const boost::gil::packed_dynamic_channel_reference y) { - boost::gil::swap_proxy::value_type>(x,y); +void swap(const boost::gil::packed_dynamic_channel_reference x, const boost::gil::packed_dynamic_channel_reference y) { + boost::gil::swap_proxy::value_type>(x,y); } } // namespace std @@ -665,7 +662,7 @@ struct is_integral struct is_integral > : public mpl::true_ {}; -template +template struct is_integral > : public is_integral {}; }