From 4aeac0567803e57aca59364dd47fa6962d862ea3 Mon Sep 17 00:00:00 2001 From: Christian Henning Date: Mon, 11 Oct 2010 15:59:24 +0000 Subject: [PATCH] Changes suppress compiler warnings when dealing with on-the-edge bit_aligned images, for instance rgb31 or rgb63. [SVN r65912] --- include/boost/gil/channel.hpp | 49 +++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/include/boost/gil/channel.hpp b/include/boost/gil/channel.hpp index 4b34d0496..823691b35 100644 --- a/include/boost/gil/channel.hpp +++ b/include/boost/gil/channel.hpp @@ -208,6 +208,18 @@ namespace detail { >::type >::type > {}; + + template + struct num_value_fn : public mpl::if_c< ( NumBits < 32 ) + , uint32_t + , uint64_t + > {}; + + template + struct max_value_fn : public mpl::if_c< ( NumBits <= 32 ) + , uint32_t + , uint64_t + > {}; } /** @@ -230,10 +242,14 @@ BOOST_STATIC_ASSERT((boost::is_integral::value)); /// \brief The value of a subbyte channel. Models: ChannelValueConcept template class packed_channel_value { - static const std::size_t num_values = 1<::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; + typedef packed_channel_value value_type; typedef value_type& reference; typedef const value_type& const_reference; @@ -245,9 +261,12 @@ public: BOOST_STATIC_CONSTANT(bool, is_mutable=true); packed_channel_value() {} - packed_channel_value(integer_t v) : _value(v % num_values) {} + packed_channel_value(integer_t v) { _value = static_cast< integer_t >( v % num_values ); } packed_channel_value(const packed_channel_value& v) : _value(v._value) {} - template packed_channel_value(Scalar v) : _value(integer_t(v) % num_values) {} // suppress GCC implicit conversion warnings in channel regression file + template packed_channel_value(Scalar v) { _value = static_cast< integer_t >( v ) % num_values; } + + static unsigned int num_bits() { return NumBits; } + operator integer_t() const { return _value; } private: @@ -307,8 +326,13 @@ public: operator integer_t() const { return get(); } data_ptr_t operator &() const {return _data_ptr;} protected: - static const integer_t max_val = (1<::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; } @@ -368,6 +392,7 @@ class packed_channel_reference friend class packed_channel_reference; static const BitField channel_mask = static_cast< BitField >( parent_t::max_val ) << FirstBit; + void operator=(const packed_channel_reference&); public: typedef const packed_channel_reference const_reference; @@ -392,6 +417,7 @@ class packed_channel_reference friend class packed_channel_reference; static const BitField channel_mask = static_cast< BitField >( parent_t::max_val ) << FirstBit; + public: typedef const packed_channel_reference const_reference; typedef const packed_channel_reference mutable_reference; @@ -409,8 +435,8 @@ public: unsigned first_bit() const { return FirstBit; } - integer_t get() const { return integer_t((this->get_data()&channel_mask) >> FirstBit); } - void set_unsafe(integer_t value) const { this->set_data((this->get_data() & ~channel_mask) | (( static_cast< BitField >( value )<get_data()&channel_mask) >> 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)); } }; @@ -491,8 +517,8 @@ public: unsigned first_bit() const { return _first_bit; } integer_t get() const { - const BitField channel_mask = parent_t::max_val<<_first_bit; - return ( static_cast< integer_t >( this->get_data()&channel_mask ) >> _first_bit ); + 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 ); } }; @@ -526,11 +552,12 @@ public: unsigned first_bit() const { return _first_bit; } integer_t get() const { - const BitField channel_mask = parent_t::max_val<<_first_bit; - return ( static_cast< integer_t >( this->get_data()&channel_mask ) >> _first_bit ); + 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 ); } + void set_unsafe(integer_t value) const { - const BitField channel_mask = parent_t::max_val<<_first_bit; + 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); } };