diff --git a/include/boost/gil/algorithm.hpp b/include/boost/gil/algorithm.hpp index cbd1716868..82ac9450ae 100644 --- a/include/boost/gil/algorithm.hpp +++ b/include/boost/gil/algorithm.hpp @@ -83,22 +83,22 @@ struct binary_operation_obj using result_type = Result; template BOOST_FORCEINLINE - result_type operator()(const std::pair& p) const { + auto operator()(const std::pair& p) const -> result_type { return apply(*p.first, *p.second, typename views_are_compatible::type()); } template BOOST_FORCEINLINE - result_type operator()(const V1& v1, const V2& v2) const { + auto operator()(const V1& v1, const V2& v2) const -> result_type { return apply(v1, v2, typename views_are_compatible::type()); } - result_type operator()(const error_t&) const { throw std::bad_cast(); } + auto operator()(const error_t&) const -> result_type { throw std::bad_cast(); } private: // dispatch from apply overload to a function with distinct name template BOOST_FORCEINLINE - result_type apply(V1 const& v1, V2 const& v2, std::false_type) const + auto apply(V1 const& v1, V2 const& v2, std::false_type) const -> result_type { return ((const Derived*)this)->apply_incompatible(v1, v2); } @@ -106,7 +106,7 @@ struct binary_operation_obj // dispatch from apply overload to a function with distinct name template BOOST_FORCEINLINE - result_type apply(V1 const& v1, V2 const& v2, std::true_type) const + auto apply(V1 const& v1, V2 const& v2, std::true_type) const -> result_type { return ((const Derived*)this)->apply_compatible(v1, v2); } @@ -114,7 +114,7 @@ struct binary_operation_obj // function with distinct name - it can be overloaded by subclasses template BOOST_FORCEINLINE - result_type apply_incompatible(V1 const& /*v1*/, V2 const& /*v2*/) const + auto apply_incompatible(V1 const& /*v1*/, V2 const& /*v2*/) const -> result_type { throw std::bad_cast(); } @@ -149,9 +149,10 @@ auto copy( /// \ingroup STLOptimizations /// \brief Copy when both src and dst are interleaved and of the same type can be just memmove template -BOOST_FORCEINLINE boost::gil::pixel* -copy(const boost::gil::pixel* first, const boost::gil::pixel* last, - boost::gil::pixel* dst) { +BOOST_FORCEINLINE +auto copy(const boost::gil::pixel* first, const boost::gil::pixel* last, + boost::gil::pixel* dst) -> boost::gil::pixel* +{ return (boost::gil::pixel*)std::copy((unsigned char*)first,(unsigned char*)last, (unsigned char*)dst); } } // namespace std @@ -168,7 +169,8 @@ namespace std { /// \ingroup STLOptimizations /// \brief Copy when both src and dst are planar pointers is copy for each channel template BOOST_FORCEINLINE -boost::gil::planar_pixel_iterator copy(boost::gil::planar_pixel_iterator first, boost::gil::planar_pixel_iterator last, boost::gil::planar_pixel_iterator dst) { +auto copy(boost::gil::planar_pixel_iterator first, boost::gil::planar_pixel_iterator last, boost::gil::planar_pixel_iterator dst) -> boost::gil::planar_pixel_iterator +{ boost::gil::gil_function_requires::value_type,typename std::iterator_traits::value_type>>(); static_for_each(first,last,dst,boost::gil::detail::copy_fn()); return dst+(last-first); @@ -244,7 +246,7 @@ struct copier_n,iterator_from_2d
    > { }; template -BOOST_FORCEINLINE DstIterator copy_with_2d_iterators(SrcIterator first, SrcIterator last, DstIterator dst) { +BOOST_FORCEINLINE auto copy_with_2d_iterators(SrcIterator first, SrcIterator last, DstIterator dst) -> DstIterator { using src_x_iterator = typename SrcIterator::x_iterator; using dst_x_iterator = typename DstIterator::x_iterator; @@ -270,9 +272,11 @@ namespace std { /// \ingroup STLOptimizations /// \brief std::copy(I1,I1,I2) with I1 and I2 being a iterator_from_2d template -BOOST_FORCEINLINE boost::gil::iterator_from_2d
      copy1(boost::gil::iterator_from_2d first, boost::gil::iterator_from_2d last, boost::gil::iterator_from_2d
        dst) { +BOOST_FORCEINLINE auto copy1(boost::gil::iterator_from_2d first, boost::gil::iterator_from_2d last, boost::gil::iterator_from_2d
          dst) -> boost::gil::iterator_from_2d
            +{ return boost::gil::detail::copy_with_2d_iterators(first,last,dst); } + } // namespace std namespace boost { namespace gil { @@ -307,13 +311,13 @@ class copy_and_convert_pixels_fn : public binary_operation_obj BOOST_FORCEINLINE - result_type apply_incompatible(const V1& src, const V2& dst) const { + auto apply_incompatible(const V1& src, const V2& dst) const -> result_type { copy_pixels(color_converted_view(src,_cc),dst); } // If the two color spaces are compatible, copy_and_convert is just copy template BOOST_FORCEINLINE - result_type apply_compatible(const V1& src, const V2& dst) const { + auto apply_compatible(const V1& src, const V2& dst) const -> result_type { copy_pixels(src,dst); } }; diff --git a/include/boost/gil/bit_aligned_pixel_iterator.hpp b/include/boost/gil/bit_aligned_pixel_iterator.hpp index e65a6a92ee..7d3059b66e 100644 --- a/include/boost/gil/bit_aligned_pixel_iterator.hpp +++ b/include/boost/gil/bit_aligned_pixel_iterator.hpp @@ -63,22 +63,22 @@ struct bit_aligned_pixel_iterator : public iterator_facade reference { bit_aligned_pixel_iterator it=*this; it.advance(d); return *it; } - reference operator->() const { return **this; } - const bit_range_t& bit_range() const { return _bit_range; } - bit_range_t& bit_range() { return _bit_range; } + auto operator->() const -> reference { return **this; } + auto bit_range() const -> bit_range_t const& { return _bit_range; } + auto bit_range() -> bit_range_t& { return _bit_range; } private: bit_range_t _bit_range; static constexpr int bit_size = NonAlignedPixelReference::bit_size; friend class boost::iterator_core_access; - reference dereference() const { return NonAlignedPixelReference(_bit_range); } + auto dereference() const -> reference { return NonAlignedPixelReference(_bit_range); } void increment() { ++_bit_range; } void decrement() { --_bit_range; } void advance(difference_type d) { _bit_range.bit_advance(d*bit_size); } - difference_type distance_to(const bit_aligned_pixel_iterator& it) const { return _bit_range.bit_distance_to(it._bit_range) / bit_size; } + auto distance_to(bit_aligned_pixel_iterator const& it) const -> difference_type { return _bit_range.bit_distance_to(it._bit_range) / bit_size; } bool equal(const bit_aligned_pixel_iterator& it) const { return _bit_range==it._bit_range; } }; @@ -122,12 +122,14 @@ struct byte_to_memunit> {}; template -inline std::ptrdiff_t memunit_step(const bit_aligned_pixel_iterator&) { +inline auto memunit_step(const bit_aligned_pixel_iterator&) -> std::ptrdiff_t +{ return NonAlignedPixelReference::bit_size; } template -inline std::ptrdiff_t memunit_distance(const bit_aligned_pixel_iterator& p1, const bit_aligned_pixel_iterator& p2) { +inline auto memunit_distance(bit_aligned_pixel_iterator const& p1, bit_aligned_pixel_iterator const& p2) -> std::ptrdiff_t +{ return (p2.bit_range().current_byte() - p1.bit_range().current_byte())*8 + p2.bit_range().bit_offset() - p1.bit_range().bit_offset(); } @@ -137,14 +139,15 @@ inline void memunit_advance(bit_aligned_pixel_iterator } template -inline bit_aligned_pixel_iterator memunit_advanced(const bit_aligned_pixel_iterator& p, std::ptrdiff_t diff) { +inline auto memunit_advanced(bit_aligned_pixel_iterator const& p, std::ptrdiff_t diff) -> bit_aligned_pixel_iterator { bit_aligned_pixel_iterator ret=p; memunit_advance(ret, diff); return ret; } template inline -NonAlignedPixelReference memunit_advanced_ref(bit_aligned_pixel_iterator it, std::ptrdiff_t diff) { +auto memunit_advanced_ref(bit_aligned_pixel_iterator it, std::ptrdiff_t diff) -> NonAlignedPixelReference +{ return *memunit_advanced(it,diff); } ///////////////////////////// @@ -183,11 +186,14 @@ namespace std { // It is important to provide an overload of uninitialized_copy for bit_aligned_pixel_iterator. The default STL implementation calls placement new, // which is not defined for bit_aligned_pixel_iterator. template -boost::gil::bit_aligned_pixel_iterator uninitialized_copy(boost::gil::bit_aligned_pixel_iterator first, - boost::gil::bit_aligned_pixel_iterator last, - boost::gil::bit_aligned_pixel_iterator dst) { +auto uninitialized_copy(boost::gil::bit_aligned_pixel_iterator first, + boost::gil::bit_aligned_pixel_iterator last, + boost::gil::bit_aligned_pixel_iterator dst) + -> boost::gil::bit_aligned_pixel_iterator +{ return std::copy(first,last,dst); } -} // namespace std +} // namespace std + #endif diff --git a/include/boost/gil/bit_aligned_pixel_reference.hpp b/include/boost/gil/bit_aligned_pixel_reference.hpp index 094ef4b951..3069de3d56 100644 --- a/include/boost/gil/bit_aligned_pixel_reference.hpp +++ b/include/boost/gil/bit_aligned_pixel_reference.hpp @@ -49,18 +49,18 @@ class bit_range { BOOST_ASSERT(bit_offset >= 0 && bit_offset < 8); } - bit_range(const bit_range& br) : _current_byte(br._current_byte), _bit_offset(br._bit_offset) {} + bit_range(bit_range const& br) : _current_byte(br._current_byte), _bit_offset(br._bit_offset) {} template bit_range(const bit_range& br) : _current_byte(br._current_byte), _bit_offset(br._bit_offset) {} - bit_range& operator=(const bit_range& br) { _current_byte = br._current_byte; _bit_offset=br._bit_offset; return *this; } - bool operator==(const bit_range& br) const { return _current_byte==br._current_byte && _bit_offset==br._bit_offset; } + auto operator=(bit_range const& br) -> bit_range& { _current_byte = br._current_byte; _bit_offset=br._bit_offset; return *this; } + bool operator==(bit_range const& br) const { return _current_byte==br._current_byte && _bit_offset==br._bit_offset; } - bit_range& operator++() { + auto operator++() -> bit_range& { _current_byte += (_bit_offset+RangeSize) / 8; _bit_offset = (_bit_offset+RangeSize) % 8; return *this; } - bit_range& operator--() { bit_advance(-RangeSize); return *this; } + auto operator--() -> bit_range& { bit_advance(-RangeSize); return *this; } void bit_advance(difference_type num_bits) { int new_offset = int(_bit_offset+num_bits); @@ -71,11 +71,13 @@ class bit_range { --_current_byte; } } - difference_type bit_distance_to(const bit_range& b) const { + + auto bit_distance_to(bit_range const& b) const -> difference_type + { return (b.current_byte() - current_byte())*8 + b.bit_offset()-bit_offset(); } - byte_t* current_byte() const { return _current_byte; } - int bit_offset() const { return _bit_offset; } + auto current_byte() const -> byte_t* { return _current_byte; } + auto bit_offset() const -> int { return _bit_offset; } }; /// \defgroup ColorBaseModelNonAlignedPixel bit_aligned_pixel_reference @@ -136,8 +138,10 @@ struct bit_aligned_pixel_reference bit_aligned_pixel_reference(){} bit_aligned_pixel_reference(data_ptr_t data_ptr, int bit_offset) : _bit_range(data_ptr, bit_offset) {} - explicit bit_aligned_pixel_reference(const bit_range_t& bit_range) : _bit_range(bit_range) {} - template bit_aligned_pixel_reference(const bit_aligned_pixel_reference& p) : _bit_range(p._bit_range) {} + explicit bit_aligned_pixel_reference(bit_range_t const& bit_range) : _bit_range(bit_range) {} + + template + bit_aligned_pixel_reference(bit_aligned_pixel_reference const& p) : _bit_range(p._bit_range) {} // Grayscale references can be constructed from the channel reference explicit bit_aligned_pixel_reference(typename kth_element_type::type const channel0) @@ -183,11 +187,12 @@ struct bit_aligned_pixel_reference auto operator->() const -> bit_aligned_pixel_reference const* { return this; } - bit_range_t const& bit_range() const { return _bit_range; } + auto bit_range() const -> bit_range_t const& { return _bit_range; } private: mutable bit_range_t _bit_range; - template friend struct bit_aligned_pixel_reference; + template + friend struct bit_aligned_pixel_reference; template static void check_compatible() { gil_function_requires >(); } @@ -369,7 +374,7 @@ namespace std { // Having three overloads allows us to swap between different (but compatible) models of PixelConcept template inline -void swap(const boost::gil::bit_aligned_pixel_reference x, R& y) { +void swap(boost::gil::bit_aligned_pixel_reference const x, R& y) { boost::gil::swap_proxy::value_type>(x,y); } @@ -381,7 +386,7 @@ void swap(typename boost::gil::bit_aligned_pixel_reference::value_ty template inline -void swap(const boost::gil::bit_aligned_pixel_reference x, const boost::gil::bit_aligned_pixel_reference y) { +void swap(boost::gil::bit_aligned_pixel_reference const x, const boost::gil::bit_aligned_pixel_reference y) { boost::gil::swap_proxy::value_type>(x,y); } diff --git a/include/boost/gil/channel.hpp b/include/boost/gil/channel.hpp index 39ea65eaca..eb2bde1f65 100644 --- a/include/boost/gil/channel.hpp +++ b/include/boost/gil/channel.hpp @@ -198,16 +198,32 @@ struct scoped_channel_value return *this; } - scoped_channel_value& operator++() { ++value_; return *this; } - scoped_channel_value& operator--() { --value_; return *this; } + auto operator++() -> scoped_channel_value& { ++value_; return *this; } + auto operator--() -> scoped_channel_value& { --value_; return *this; } - scoped_channel_value operator++(int) { scoped_channel_value tmp=*this; this->operator++(); return tmp; } - scoped_channel_value operator--(int) { scoped_channel_value tmp=*this; this->operator--(); return tmp; } + auto operator++(int) -> scoped_channel_value + { + scoped_channel_value tmp=*this; + this->operator++(); return tmp; + } + + auto operator--(int) -> scoped_channel_value + { + scoped_channel_value tmp=*this; + this->operator--(); return tmp; + } - template scoped_channel_value& operator+=(Scalar2 v) { value_+=v; return *this; } - template scoped_channel_value& operator-=(Scalar2 v) { value_-=v; return *this; } - template scoped_channel_value& operator*=(Scalar2 v) { value_*=v; return *this; } - template scoped_channel_value& operator/=(Scalar2 v) { value_/=v; return *this; } + template + auto operator+=(Scalar2 v) -> scoped_channel_value& { value_+=v; return *this; } + + template + auto operator-=(Scalar2 v) -> scoped_channel_value& { value_-=v; return *this; } + + template + auto operator*=(Scalar2 v) -> scoped_channel_value& { value_*=v; return *this; } + + template + auto operator/=(Scalar2 v) -> scoped_channel_value& { value_/=v; return *this; } operator BaseChannelValue() const { return value_; } private: @@ -313,7 +329,7 @@ class packed_channel_value value_ = packed_channel_value(static_cast(v)); } - static unsigned int num_bits() { return NumBits; } + static auto num_bits() -> unsigned int { return NumBits; } operator integer_t() const { return value_; } @@ -348,35 +364,69 @@ class packed_channel_reference_base data_ptr_t _data_ptr; // void* pointer to the first byte of the bit range using value_type = packed_channel_value; - using reference = const Derived; - using pointer = value_type *; - using const_pointer = const value_type *; + using reference = Derived const; + using pointer = value_type*; + using const_pointer = value_type const*; static constexpr int num_bits = NumBits; static constexpr bool is_mutable = IsMutable; - static value_type min_value() { return channel_traits::min_value(); } - static value_type max_value() { return channel_traits::max_value(); } + static auto min_value() -> value_type { return channel_traits::min_value(); } + static auto max_value() -> value_type { return channel_traits::max_value(); } using bitfield_t = BitField; using integer_t = typename value_type::integer_t; 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(); } + packed_channel_reference_base(packed_channel_reference_base const& ref) : _data_ptr(ref._data_ptr) {} + + auto operator=(integer_t v) const -> Derived const& { set(v); return derived(); } - const Derived& operator++() const { set(get()+1); return derived(); } - const Derived& operator--() const { set(get()-1); return derived(); } + auto operator++() const -> Derived const& { set(get()+1); return derived(); } + auto operator--() const -> Derived const& { set(get()-1); return derived(); } - Derived operator++(int) const { Derived tmp=derived(); this->operator++(); return tmp; } - Derived operator--(int) const { Derived tmp=derived(); this->operator--(); return tmp; } + auto operator++(int) const -> Derived + { + Derived tmp=derived(); + this->operator++(); return tmp; + } + + auto operator--(int) const -> Derived + { + Derived tmp=derived(); + this->operator--(); + return tmp; + } - template const Derived& operator+=(Scalar2 v) const { set( static_cast( get() + v )); return derived(); } - template const Derived& operator-=(Scalar2 v) const { set( static_cast( get() - v )); return derived(); } - template const Derived& operator*=(Scalar2 v) const { set( static_cast( get() * v )); return derived(); } - template const Derived& operator/=(Scalar2 v) const { set( static_cast( get() / v )); return derived(); } + template + auto operator+=(Scalar2 v) const -> Derived const& + { + set( static_cast( get() + v )); + return derived(); + } + + template + auto operator-=(Scalar2 v) const -> Derived const& + { + set( static_cast( get() - v )); return derived(); + } + + template + auto operator*=(Scalar2 v) const -> Derived const& + { + set( static_cast( get() * v )); + return derived(); + } + + template + auto operator/=(Scalar2 v) const -> Derived const& + { + set( static_cast( get() / v )); + return derived(); + } operator integer_t() const { return get(); } - data_ptr_t operator &() const {return _data_ptr;} + auto operator&() const -> data_ptr_t {return _data_ptr;} + protected: using num_value_t = typename detail::num_value_fn::type; @@ -389,12 +439,15 @@ class packed_channel_reference_base 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; } #else - bitfield_t get_data() const { + auto get_data() const -> bitfield_t + { bitfield_t ret; static_copy_bytes()(gil_reinterpret_cast_c(_data_ptr),gil_reinterpret_cast(&ret)); return ret; } - void set_data(const bitfield_t& val) const { + + void set_data(bitfield_t const& val) const + { static_copy_bytes()(gil_reinterpret_cast_c(&val),gil_reinterpret_cast(_data_ptr)); } #endif @@ -403,8 +456,8 @@ class packed_channel_reference_base void set(integer_t value) const { // can this be done faster?? this->derived().set_unsafe(((value % num_values) + num_values) % num_values); } - integer_t get() const { return derived().get(); } - const Derived& derived() const { return static_cast(*this); } + auto get() const -> integer_t { return derived().get(); } + auto derived() const -> Derived const& { return static_cast(*this); } }; } // namespace detail @@ -468,9 +521,9 @@ class packed_channel_reference packed_channel_reference(const packed_channel_reference& ref) : parent_t(ref._data_ptr) {} packed_channel_reference(const mutable_reference& ref) : parent_t(ref._data_ptr) {} - unsigned first_bit() const { return FirstBit; } + auto first_bit() const -> unsigned int { return FirstBit; } - integer_t get() const { return integer_t((this->get_data()&channel_mask) >> FirstBit); } + auto get() const -> integer_t { return integer_t((this->get_data()&channel_mask) >> FirstBit); } }; /// \ingroup PackedChannelReferenceModel @@ -499,16 +552,17 @@ class packed_channel_reference 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; } + auto operator=(mutable_reference const& ref) const -> packed_channel_reference const& { set_from_reference(ref.get_data()); return *this; } + auto operator=(const_reference const& ref) const -> packed_channel_reference const& { set_from_reference(ref.get_data()); return *this; } template - const packed_channel_reference& operator=(const packed_dynamic_channel_reference& ref) const { set_unsafe(ref.get()); return *this; } + auto operator=(packed_dynamic_channel_reference const& ref) const -> packed_channel_reference const& { set_unsafe(ref.get()); return *this; } - unsigned first_bit() const { return FirstBit; } + auto first_bit() const -> unsigned int { return FirstBit; } - integer_t get() const { return integer_t((this->get_data()&channel_mask) >> FirstBit); } + auto get() const -> integer_t { 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 )<set_data((this->get_data() & ~channel_mask) | (other_bits & channel_mask)); } }; @@ -599,13 +653,14 @@ class packed_dynamic_channel_reference using mutable_reference = packed_dynamic_channel_reference const; using integer_t = typename parent_t::integer_t; - packed_dynamic_channel_reference(const void* data_ptr, unsigned first_bit) : parent_t(data_ptr), _first_bit(first_bit) {} - packed_dynamic_channel_reference(const const_reference& ref) : parent_t(ref._data_ptr), _first_bit(ref._first_bit) {} - packed_dynamic_channel_reference(const mutable_reference& ref) : parent_t(ref._data_ptr), _first_bit(ref._first_bit) {} + packed_dynamic_channel_reference(void const* data_ptr, unsigned first_bit) : parent_t(data_ptr), _first_bit(first_bit) {} + packed_dynamic_channel_reference(const_reference const& ref) : parent_t(ref._data_ptr), _first_bit(ref._first_bit) {} + packed_dynamic_channel_reference(mutable_reference const& ref) : parent_t(ref._data_ptr), _first_bit(ref._first_bit) {} - unsigned first_bit() const { return _first_bit; } + auto first_bit() const -> unsigned int { return _first_bit; } - integer_t get() const { + auto get() const -> integer_t + { 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 ); } @@ -629,26 +684,30 @@ class packed_dynamic_channel_reference using integer_t = typename parent_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) {} + packed_dynamic_channel_reference(packed_dynamic_channel_reference const& ref) : parent_t(ref._data_ptr), _first_bit(ref._first_bit) {} - packed_dynamic_channel_reference const& operator=(integer_t value) const + auto operator=(integer_t value) const -> packed_dynamic_channel_reference const& { BOOST_ASSERT(value <= parent_t::max_val); 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; } + auto operator=(mutable_reference const& ref) const -> packed_dynamic_channel_reference const& { set_unsafe(ref.get()); return *this; } + auto operator=(const_reference const& ref) const -> packed_dynamic_channel_reference const& { set_unsafe(ref.get()); return *this; } template - const packed_dynamic_channel_reference& operator=(const packed_channel_reference& ref) const - { set_unsafe(ref.get()); return *this; } + auto operator=(packed_channel_reference const& ref) const -> packed_dynamic_channel_reference const& + { + set_unsafe(ref.get()); + return *this; + } - unsigned first_bit() const { return _first_bit; } + auto first_bit() const -> unsigned int { return _first_bit; } - integer_t get() const { - const BitField channel_mask = static_cast< integer_t >( parent_t::max_val ) << _first_bit; + auto get() const -> integer_t + { + BitField const channel_mask = static_cast< integer_t >( parent_t::max_val ) << _first_bit; return static_cast< integer_t >(( this->get_data()&channel_mask ) >> _first_bit ); } diff --git a/include/boost/gil/channel_algorithm.hpp b/include/boost/gil/channel_algorithm.hpp index 848c9652ad..47496662fc 100644 --- a/include/boost/gil/channel_algorithm.hpp +++ b/include/boost/gil/channel_algorithm.hpp @@ -148,13 +148,16 @@ template DstChannelV + { return DstChannelV(channel_traits::min_value() + (src - channel_traits::min_value()) / channel_range() * channel_range()); } + private: template - static double channel_range() { + static auto channel_range() -> double + { return double(channel_traits::max_value()) - double(channel_traits::min_value()); } }; @@ -198,7 +201,8 @@ struct channel_converter_unsigned_integral // and the dst max value is divisible by the src max value template struct channel_converter_unsigned_integral_impl { - DstChannelV operator()(SrcChannelV src) const { + auto operator()(SrcChannelV src) const -> DstChannelV + { using integer_t = typename unsigned_integral_max_value::value_type; static const integer_t mul = unsigned_integral_max_value::value / unsigned_integral_max_value::value; return DstChannelV(src * mul); @@ -210,7 +214,8 @@ struct channel_converter_unsigned_integral_impl struct channel_converter_unsigned_integral_impl { - DstChannelV operator()(SrcChannelV src) const { + auto operator()(SrcChannelV src) const -> DstChannelV + { using integer_t = typename unsigned_integral_max_value::value_type; static const integer_t div = unsigned_integral_max_value::value / unsigned_integral_max_value::value; static const integer_t div2 = div/2; @@ -221,7 +226,8 @@ struct channel_converter_unsigned_integral_impl struct channel_converter_unsigned_integral_impl { - DstChannelV operator()(uintmax_t src) const { + auto operator()(uintmax_t src) const -> DstChannelV + { static const uintmax_t div = unsigned_integral_max_value::value / unsigned_integral_max_value::value; static const uintmax_t div2 = div/2; if (src > unsigned_integral_max_value::value - div2) @@ -259,7 +265,7 @@ struct channel_converter_unsigned_integral_impl struct channel_converter_unsigned_integral_nondivisible { - DstChannelV operator()(SrcChannelV src) const + auto operator()(SrcChannelV src) const -> DstChannelV { using dest_t = typename base_channel_type::type; return DstChannelV( @@ -275,7 +281,7 @@ struct channel_converter_unsigned_integral_nondivisible struct channel_converter_unsigned_integral_nondivisible { - DstChannelV operator()(SrcChannelV src) const + auto operator()(SrcChannelV src) const -> DstChannelV { static const double mul = unsigned_integral_max_value::value @@ -288,9 +294,10 @@ struct channel_converter_unsigned_integral_nondivisible -struct channel_converter_unsigned_integral_nondivisible { - DstChannelV operator()(SrcChannelV src) const { - +struct channel_converter_unsigned_integral_nondivisible +{ + auto operator()(SrcChannelV src) const -> DstChannelV + { using src_integer_t = typename detail::unsigned_integral_max_value::value_type; using dst_integer_t = typename detail::unsigned_integral_max_value::value_type; @@ -312,7 +319,7 @@ struct channel_converter_unsigned_integral_nondivisible struct channel_converter_unsigned { using argument_type = float32_t; using result_type = DstChannelV; - DstChannelV operator()(float32_t x) const + auto operator()(float32_t x) const -> DstChannelV { using dst_integer_t = typename detail::unsigned_integral_max_value::value_type; return DstChannelV( static_cast< dst_integer_t >(x*channel_traits::max_value()+0.5f )); @@ -322,13 +329,13 @@ template struct channel_converter_unsigned struct channel_converter_unsigned { using argument_type = float32_t; using result_type = SrcChannelV; - float32_t operator()(SrcChannelV x) const { return float32_t(x/float(channel_traits::max_value())); } + auto operator()(SrcChannelV x) const -> float32_t { return float32_t(x/float(channel_traits::max_value())); } }; template <> struct channel_converter_unsigned { using argument_type = float32_t; using result_type = float32_t; - float32_t operator()(float32_t x) const { return x; } + auto operator()(float32_t x) const -> float32_t { return x; } }; @@ -336,7 +343,8 @@ template <> struct channel_converter_unsigned { template <> struct channel_converter_unsigned { using argument_type = uint32_t; using result_type = float32_t; - float32_t operator()(uint32_t x) const { + auto operator()(uint32_t x) const -> float32_t + { // unfortunately without an explicit check it is possible to get a round-off error. We must ensure that max_value of uint32_t matches max_value of float32_t if (x>=channel_traits::max_value()) return channel_traits::max_value(); return float(x) / float(channel_traits::max_value()); @@ -346,7 +354,8 @@ template <> struct channel_converter_unsigned { template <> struct channel_converter_unsigned { using argument_type = float32_t; using result_type = uint32_t; - uint32_t operator()(float32_t x) const { + auto operator()(float32_t x) const -> uint32_t + { // unfortunately without an explicit check it is possible to get a round-off error. We must ensure that max_value of uint32_t matches max_value of float32_t if (x>=channel_traits::max_value()) return channel_traits::max_value(); @@ -406,7 +415,7 @@ template <> struct channel_convert_from_unsigned { using argument_type = uint8_t; using result_type = int8_t; using type = int8_t; - type operator()(uint8_t val) const { + type operator()(uint8_t val) const { return static_cast(static_cast(val) - 128); } }; @@ -437,7 +446,8 @@ template // Model ChannelValueConce struct channel_converter { using argument_type = SrcChannelV; using result_type = DstChannelV; - DstChannelV operator()(const SrcChannelV& src) const { + auto operator()(SrcChannelV const& src) const -> DstChannelV + { using to_unsigned = detail::channel_convert_to_unsigned; using from_unsigned = detail::channel_convert_from_unsigned; using converter_unsigned = channel_converter_unsigned; @@ -448,7 +458,8 @@ struct channel_converter { /// \ingroup ChannelConvertAlgorithm /// \brief Converting from one channel type to another. template // Model ChannelConcept (could be channel references) -inline typename channel_traits::value_type channel_convert(const SrcChannel& src) { +inline auto channel_convert(SrcChannel const& src) -> typename channel_traits::value_type +{ return channel_converter::value_type, typename channel_traits::value_type>()(src); } @@ -459,17 +470,26 @@ inline typename channel_traits::value_type channel_convert(const Src /// on heterogeneous pixels. struct default_channel_converter { template - void operator()(const Ch1& src, Ch2& dst) const { + void operator()(Ch1 const& src, Ch2& dst) const + { dst=channel_convert(src); } }; -namespace detail { +namespace detail +{ // fast integer division by 255 - inline uint32_t div255(uint32_t in) { uint32_t tmp=in+128; return (tmp + (tmp>>8))>>8; } + inline auto div255(uint32_t in) -> uint32_t + { + uint32_t tmp = in + 128; + return (tmp + (tmp >> 8)) >> 8; + } // fast integer divison by 32768 - inline uint32_t div32768(uint32_t in) { return (in+16384)>>15; } + inline auto div32768(uint32_t in) -> uint32_t + { + return (in + 16384) >> 15; + } } /// \defgroup ChannelMultiplyAlgorithm channel_multiply @@ -491,7 +511,8 @@ struct channel_multiplier_unsigned { using first_argument_type = ChannelValue; using second_argument_type = ChannelValue; using result_type = ChannelValue; - ChannelValue operator()(ChannelValue a, ChannelValue b) const { + auto operator()(ChannelValue a, ChannelValue b) const -> ChannelValue + { return ChannelValue(static_cast::type>(a / double(channel_traits::max_value()) * b)); } }; @@ -501,7 +522,7 @@ template<> struct channel_multiplier_unsigned { using first_argument_type = uint8_t; using second_argument_type = uint8_t; using result_type = uint8_t; - uint8_t operator()(uint8_t a, uint8_t b) const { return uint8_t(detail::div255(uint32_t(a) * uint32_t(b))); } + auto operator()(uint8_t a, uint8_t b) const -> uint8_t { return uint8_t(detail::div255(uint32_t(a) * uint32_t(b))); } }; /// \brief Specialization of channel_multiply for 16-bit unsigned channels @@ -509,7 +530,7 @@ template<> struct channel_multiplier_unsigned { using first_argument_type = uint16_t; using second_argument_type = uint16_t; using result_type = uint16_t; - uint16_t operator()(uint16_t a, uint16_t b) const { return uint16_t((uint32_t(a) * uint32_t(b))/65535); } + auto operator()(uint16_t a, uint16_t b) const -> uint16_t { return uint16_t((uint32_t(a) * uint32_t(b))/65535); } }; /// \brief Specialization of channel_multiply for float 0..1 channels @@ -517,7 +538,7 @@ template<> struct channel_multiplier_unsigned { using first_argument_type = float32_t; using second_argument_type = float32_t; using result_type = float32_t; - float32_t operator()(float32_t a, float32_t b) const { return a*b; } + auto operator()(float32_t a, float32_t b) const -> float32_t { return a*b; } }; /// \brief A function object to multiply two channels. result = a * b / max_value @@ -526,7 +547,8 @@ struct channel_multiplier { using first_argument_type = ChannelValue; using second_argument_type = ChannelValue; using result_type = ChannelValue; - ChannelValue operator()(ChannelValue a, ChannelValue b) const { + auto operator()(ChannelValue a, ChannelValue b) const -> ChannelValue + { using to_unsigned = detail::channel_convert_to_unsigned; using from_unsigned = detail::channel_convert_from_unsigned; using multiplier_unsigned = channel_multiplier_unsigned; @@ -536,7 +558,8 @@ struct channel_multiplier { /// \brief A function multiplying two channels. result = a * b / max_value template // Models ChannelConcept (could be a channel reference) -inline typename channel_traits::value_type channel_multiply(Channel a, Channel b) { +inline auto channel_multiply(Channel a, Channel b) -> typename channel_traits::value_type +{ return channel_multiplier::value_type>()(a,b); } /// @} @@ -556,8 +579,8 @@ inline typename channel_traits::value_type channel_multiply(Channel a, /// \brief Default implementation. Provide overloads for performance /// \ingroup ChannelInvertAlgorithm channel_invert template // Models ChannelConcept (could be a channel reference) -inline typename channel_traits::value_type channel_invert(Channel x) { - +inline auto channel_invert(Channel x) -> typename channel_traits::value_type +{ using base_t = typename base_channel_type::type; using promoted_t = typename promote_integral::type; promoted_t const promoted_x = x; @@ -568,6 +591,6 @@ inline typename channel_traits::value_type channel_invert(Channel x) { return inverted_x; } -} } // namespace boost::gil +}} // namespace boost::gil #endif diff --git a/include/boost/gil/cmyk.hpp b/include/boost/gil/cmyk.hpp index 7b03c199f5..50c1abfa25 100644 --- a/include/boost/gil/cmyk.hpp +++ b/include/boost/gil/cmyk.hpp @@ -40,13 +40,13 @@ using cmyk_layout_t = layout; /// \ingroup ImageViewConstructors /// \brief from raw CMYK planar data template -inline typename type_from_x_iterator >::view_t -planar_cmyk_view(std::size_t width, std::size_t height, IC c, IC m, IC y, IC k, std::ptrdiff_t rowsize_in_bytes) +inline auto planar_cmyk_view(std::size_t width, std::size_t height, IC c, IC m, IC y, IC k, std::ptrdiff_t rowsize_in_bytes) + -> typename type_from_x_iterator>::view_t { using view_t = typename type_from_x_iterator >::view_t; return view_t(width, height, typename view_t::locator(planar_pixel_iterator(c,m,y,k), rowsize_in_bytes)); } -} } // namespace gil +}} // namespace gil #endif diff --git a/include/boost/gil/color_base_algorithm.hpp b/include/boost/gil/color_base_algorithm.hpp index 6746f83002..233009827b 100644 --- a/include/boost/gil/color_base_algorithm.hpp +++ b/include/boost/gil/color_base_algorithm.hpp @@ -187,14 +187,18 @@ struct color_element_const_reference_type : public kth_semantic_element_const_re /// \brief Mutable accessor to the element associated with a given color name /// \ingroup ColorBaseAlgorithmColor template -typename color_element_reference_type::type get_color(ColorBase& cb, Color=Color()) { +auto get_color(ColorBase& cb, Color=Color()) + -> typename color_element_reference_type::type +{ return color_element_reference_type::get(cb); } /// \brief Constant accessor to the element associated with a given color name /// \ingroup ColorBaseAlgorithmColor template -typename color_element_const_reference_type::type get_color(const ColorBase& cb, Color=Color()) { +auto get_color(const ColorBase& cb, Color=Color()) + -> typename color_element_const_reference_type::type +{ return color_element_const_reference_type::get(cb); } @@ -435,36 +439,63 @@ template<> struct element_recursion<0> { }; // std::min and std::max don't have the mutable overloads... -template inline const Q& mutable_min(const Q& x, const Q& y) { return x inline Q& mutable_min( Q& x, Q& y) { return x inline const Q& mutable_max(const Q& x, const Q& y) { return x inline Q& mutable_max( Q& x, Q& y) { return x +inline auto mutable_min(Q const& x, Q const& y) -> Q const& { return x +inline auto mutable_min(Q& x, Q& y) -> Q& { return x +inline auto mutable_max(Q const& x, Q const& y) -> Q const& { return x +inline auto mutable_max(Q& x, Q& y) -> Q& { return x -struct min_max_recur { - template static typename element_const_reference_type

            ::type max_(const P& p) { +struct min_max_recur +{ + template + static auto max_(P const& p) -> typename element_const_reference_type

            ::type + { return mutable_max(min_max_recur::max_(p),semantic_at_c(p)); } - template static typename element_reference_type

            ::type max_( P& p) { + + template + static auto max_(P& p) -> typename element_reference_type

            ::type + { return mutable_max(min_max_recur::max_(p),semantic_at_c(p)); } - template static typename element_const_reference_type

            ::type min_(const P& p) { + + template + static auto min_(P const& p) -> typename element_const_reference_type

            ::type + { return mutable_min(min_max_recur::min_(p),semantic_at_c(p)); } - template static typename element_reference_type

            ::type min_( P& p) { + + template + static auto min_(P& p) -> typename element_reference_type

            ::type + { return mutable_min(min_max_recur::min_(p),semantic_at_c(p)); } }; // termination condition of the compile-time recursion for min/max element template <> -struct min_max_recur<1> { - template static typename element_const_reference_type

            ::type max_(const P& p) { return semantic_at_c<0>(p); } - template static typename element_reference_type

            ::type max_( P& p) { return semantic_at_c<0>(p); } - template static typename element_const_reference_type

            ::type min_(const P& p) { return semantic_at_c<0>(p); } - template static typename element_reference_type

            ::type min_( P& p) { return semantic_at_c<0>(p); } +struct min_max_recur<1> +{ + template + static auto max_(P const& p) -> typename element_const_reference_type

            ::type { return semantic_at_c<0>(p); } + + template + static auto max_(P& p) -> typename element_reference_type

            ::type { return semantic_at_c<0>(p); } + + template + static auto min_(P const& p) -> typename element_const_reference_type

            ::type { return semantic_at_c<0>(p); } + + template + static auto min_(P& p) -> typename element_reference_type

            ::type { return semantic_at_c<0>(p); } }; } // namespace detail @@ -483,19 +514,19 @@ struct min_max_recur<1> { template BOOST_FORCEINLINE -typename element_const_reference_type

            ::type static_max(const P& p) { return detail::min_max_recur::value>::max_(p); } +auto static_max(P const& p) -> typename element_const_reference_type

            ::type { return detail::min_max_recur::value>::max_(p); } template BOOST_FORCEINLINE -typename element_reference_type

            ::type static_max( P& p) { return detail::min_max_recur::value>::max_(p); } +auto static_max(P& p) -> typename element_reference_type

            ::type { return detail::min_max_recur::value>::max_(p); } template BOOST_FORCEINLINE -typename element_const_reference_type

            ::type static_min(const P& p) { return detail::min_max_recur::value>::min_(p); } +auto static_min(P const& p) -> typename element_const_reference_type

            ::type { return detail::min_max_recur::value>::min_(p); } template BOOST_FORCEINLINE -typename element_reference_type

            ::type static_min( P& p) { return detail::min_max_recur::value>::min_(p); } +auto static_min(P& p) -> typename element_reference_type

            ::type { return detail::min_max_recur::value>::min_(p); } /// \} /// \defgroup ColorBaseAlgorithmEqual static_equal @@ -515,7 +546,7 @@ typename element_reference_type

            ::type static_min( P& p) { return d template BOOST_FORCEINLINE -bool static_equal(const P1& p1, const P2& p2) { return detail::element_recursion::value>::static_equal(p1,p2); } +bool static_equal(P1 const& p1, const P2& p2) { return detail::element_recursion::value>::static_equal(p1,p2); } /// \} @@ -708,6 +739,6 @@ BOOST_FORCEINLINE Op static_for_each(const P1& p1,const P2& p2,const P3& p3,Op op) { return detail::element_recursion::value>::static_for_each(p1,p2,p3,op); } ///\} -} } // namespace boost::gil +}} // namespace boost::gil #endif