Index: bit_aligned_pixel_iterator.hpp
===================================================================
--- bit_aligned_pixel_iterator.hpp	(revision 49440)
+++ bit_aligned_pixel_iterator.hpp	(working copy)
@@ -1,26 +1,28 @@
 /*
-    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).
+   Copyright 2005-2007 Adobe Systems Incorporated
 
-    See http://opensource.adobe.com/gil for most recent version including documentation.
+   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).
+
+   See http://opensource.adobe.com/gil for most recent version including
+   documentation.
 */
 
-/*************************************************************************************************/
+/******************************************************************************/
 
 #ifndef GIL_BIT_ALIGNED_PIXEL_ITERATOR_HPP
 #define GIL_BIT_ALIGNED_PIXEL_ITERATOR_HPP
 
-////////////////////////////////////////////////////////////////////////////////////////
-/// \file               
-/// \brief A model of a heterogeneous pixel that is not byte aligned. Examples are bitmap (1-bit pixels) or 6-bit RGB (222)
+////////////////////////////////////////////////////////////////////////////////
+/// \file
+/// \brief A model of a heterogeneous pixel that is not byte aligned.
+///        Examples are bitmap (1-bit pixels) or 6-bit RGB (222)
 /// \author Lubomir Bourdev and Hailin Jin \n
 ///         Adobe Systems Incorporated
 /// \date   2005-2007 \n Last updated on September 28, 2006
 ///
-////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
 
 #include <functional>
 #include <boost/iterator/iterator_facade.hpp>
@@ -32,73 +34,127 @@
 
 /// \defgroup PixelIteratorNonAlignedPixelIterator bit_aligned_pixel_iterator
 /// \ingroup PixelIteratorModel
-/// \brief An iterator over non-byte-aligned pixels. Models PixelIteratorConcept, PixelBasedConcept, MemoryBasedIteratorConcept, HasDynamicXStepTypeConcept
+/// \brief An iterator over non-byte-aligned pixels.
+///        Models PixelIteratorConcept,
+///               PixelBasedConcept,
+///               MemoryBasedIteratorConcept,
+///               HasDynamicXStepTypeConcept
+///
 
-////////////////////////////////////////////////////////////////////////////////////////
-/// \brief An iterator over non-byte-aligned pixels. Models PixelIteratorConcept, PixelBasedConcept, MemoryBasedIteratorConcept, HasDynamicXStepTypeConcept
+////////////////////////////////////////////////////////////////////////////////
+/// \brief An iterator over non-byte-aligned pixels.
+///        Models PixelIteratorConcept,
+///               PixelBasedConcept,
+///               MemoryBasedIteratorConcept,
+///               HasDynamicXStepTypeConcept
 ///
-/// An iterator over pixels that correspond to non-byte-aligned bit ranges. Examples of such pixels are single bit grayscale pixel, or a 6-bit RGB 222 pixel.
-/// 
+/// An iterator over pixels that correspond to non-byte-aligned bit ranges.
+/// Examples of such pixels are single bit grayscale pixel,
+/// or a 6-bit RGB 222 pixel.
+///
 /// \ingroup PixelIteratorNonAlignedPixelIterator PixelBasedModel
 
 template <typename NonAlignedPixelReference>
-struct bit_aligned_pixel_iterator : public iterator_facade<bit_aligned_pixel_iterator<NonAlignedPixelReference>,
-                                                  typename NonAlignedPixelReference::value_type,
-                                                  random_access_traversal_tag,
-                                                  const NonAlignedPixelReference,
-                                                  typename NonAlignedPixelReference::bit_range_t::difference_type> {
+struct bit_aligned_pixel_iterator :
+    public iterator_facade<
+        bit_aligned_pixel_iterator<NonAlignedPixelReference>,
+        typename NonAlignedPixelReference::value_type,
+        random_access_traversal_tag,
+        const NonAlignedPixelReference,
+        typename NonAlignedPixelReference::bit_range_t::difference_type
+        >
+{
 private:
-    typedef iterator_facade<bit_aligned_pixel_iterator<NonAlignedPixelReference>,
-                            typename NonAlignedPixelReference::value_type,
-                            random_access_traversal_tag,
-                            const NonAlignedPixelReference,
-                            typename NonAlignedPixelReference::bit_range_t::difference_type> parent_t;
+    typedef iterator_facade<
+        bit_aligned_pixel_iterator< NonAlignedPixelReference >,
+        typename NonAlignedPixelReference::value_type,
+        random_access_traversal_tag,
+        const NonAlignedPixelReference,
+        typename NonAlignedPixelReference::bit_range_t::difference_type
+        >
+    parent_t;
+
     template <typename Ref> friend struct bit_aligned_pixel_iterator;
 
     typedef typename NonAlignedPixelReference::bit_range_t bit_range_t;
 public:
     typedef typename parent_t::difference_type             difference_type;
+
     typedef typename parent_t::reference                   reference;
 
     bit_aligned_pixel_iterator() {}
-    bit_aligned_pixel_iterator(const bit_aligned_pixel_iterator& p) : _bit_range(p._bit_range) {}
-    bit_aligned_pixel_iterator& operator=(const bit_aligned_pixel_iterator& p) { _bit_range=p._bit_range; return *this; }
 
-    template <typename Ref> bit_aligned_pixel_iterator(const bit_aligned_pixel_iterator<Ref>& p) : _bit_range(p._bit_range) {}
+    bit_aligned_pixel_iterator(const bit_aligned_pixel_iterator& p)
+        : _bit_range(p._bit_range)
+    {}
 
+    bit_aligned_pixel_iterator&
+    operator=(const bit_aligned_pixel_iterator& p) {
+        _bit_range=p._bit_range;
+        return *this;
+    }
+
+    template <typename Ref>
+    bit_aligned_pixel_iterator(const bit_aligned_pixel_iterator<Ref>& p)
+        : _bit_range(p._bit_range)
+    {}
+
     bit_aligned_pixel_iterator(reference* ref) : _bit_range(ref->bit_range()) {}
-    explicit bit_aligned_pixel_iterator(typename bit_range_t::byte_t* data, int bit_offset=0) : _bit_range(data,bit_offset) {}
 
-    /// For some reason operator[] provided by iterator_adaptor returns a custom class that is convertible to reference
-    /// We require our own reference because it is registered in iterator_traits
-    reference operator[](difference_type d) const { bit_aligned_pixel_iterator it=*this; it.advance(d); return *it; }
+    explicit
+    bit_aligned_pixel_iterator(typename bit_range_t::byte_t* data,
+                               int bit_offset=0
+                               )
+        : _bit_range(data,bit_offset)
+    {}
 
+    /// For some reason operator[] provided by iterator_adaptor returns a
+    /// custom class that is convertible to reference
+    /// We require our own reference because it is registered in
+    /// iterator_traits
+    reference operator[](difference_type d) const {
+        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; }
+
+    bit_range_t& bit_range()       { return _bit_range; }
 private:
     bit_range_t _bit_range;
     BOOST_STATIC_CONSTANT(int, bit_size = NonAlignedPixelReference::bit_size);
 
     friend class boost::iterator_core_access;
-    reference dereference()     const { return NonAlignedPixelReference(_bit_range); }
+
+    reference dereference()     const {
+        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; }
-    bool equal(const bit_aligned_pixel_iterator& it) const { return _bit_range==it._bit_range; }
+    difference_type distance_to(const bit_aligned_pixel_iterator& it) const {
+        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;
+    }
 };
 
-template <typename NonAlignedPixelReference> 
-struct const_iterator_type<bit_aligned_pixel_iterator<NonAlignedPixelReference> > { 
-    typedef bit_aligned_pixel_iterator<typename NonAlignedPixelReference::const_reference> type; 
+template <typename NonAlignedPixelReference>
+struct const_iterator_type<bit_aligned_pixel_iterator<NonAlignedPixelReference> > {
+    typedef bit_aligned_pixel_iterator<typename NonAlignedPixelReference::const_reference> type;
 };
 
-template <typename NonAlignedPixelReference> 
+template <typename NonAlignedPixelReference>
 struct iterator_is_mutable<bit_aligned_pixel_iterator<NonAlignedPixelReference> > : public mpl::bool_<NonAlignedPixelReference::is_mutable> {};
 
-template <typename NonAlignedPixelReference> 
+template <typename NonAlignedPixelReference>
 struct is_iterator_adaptor<bit_aligned_pixel_iterator<NonAlignedPixelReference> > : public mpl::false_ {};
 
 /////////////////////////////
@@ -122,17 +178,17 @@
 struct byte_to_memunit<bit_aligned_pixel_iterator<NonAlignedPixelReference> > : public mpl::int_<8> {};
 
 template <typename NonAlignedPixelReference>
-inline std::ptrdiff_t memunit_step(const bit_aligned_pixel_iterator<NonAlignedPixelReference>&) { 
-    return NonAlignedPixelReference::bit_size; 
+inline std::ptrdiff_t memunit_step(const bit_aligned_pixel_iterator<NonAlignedPixelReference>&) {
+    return NonAlignedPixelReference::bit_size;
 }
 
 template <typename NonAlignedPixelReference>
-inline std::ptrdiff_t memunit_distance(const bit_aligned_pixel_iterator<NonAlignedPixelReference>& p1, const bit_aligned_pixel_iterator<NonAlignedPixelReference>& p2) { 
-    return (p2.bit_range().current_byte() - p1.bit_range().current_byte())*8 + p2.bit_range().bit_offset() - p1.bit_range().bit_offset(); 
+inline std::ptrdiff_t memunit_distance(const bit_aligned_pixel_iterator<NonAlignedPixelReference>& p1, const bit_aligned_pixel_iterator<NonAlignedPixelReference>& p2) {
+    return (p2.bit_range().current_byte() - p1.bit_range().current_byte())*8 + p2.bit_range().bit_offset() - p1.bit_range().bit_offset();
 }
 
 template <typename NonAlignedPixelReference>
-inline void memunit_advance(bit_aligned_pixel_iterator<NonAlignedPixelReference>& p, std::ptrdiff_t diff) { 
+inline void memunit_advance(bit_aligned_pixel_iterator<NonAlignedPixelReference>& p, std::ptrdiff_t diff) {
     p.bit_range().bit_advance(diff);
 }
 
@@ -179,9 +235,9 @@
 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. 
+// which is not defined for bit_aligned_pixel_iterator.
 template <typename NonAlignedPixelReference>
-boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> uninitialized_copy(boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> first, 
+boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> uninitialized_copy(boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> first,
                                                                                    boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> last,
                                                                                    boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> dst) {
     return std::copy(first,last,dst);
Index: bit_aligned_pixel_reference.hpp
===================================================================
--- bit_aligned_pixel_reference.hpp	(revision 49440)
+++ bit_aligned_pixel_reference.hpp	(working copy)
@@ -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_BIT_ALIGNED_PIXEL_REFERENCE_HPP
 
 ////////////////////////////////////////////////////////////////////////////////////////
-/// \file               
+/// \file
 /// \brief A model of a heterogeneous pixel that is not byte aligned. Examples are bitmap (1-bit pixels) or 6-bit RGB (222)
 /// \author Lubomir Bourdev and Hailin Jin \n
 ///         Adobe Systems Incorporated
@@ -41,7 +41,7 @@
 //
 //  Represents a range of bits that can span multiple consecutive bytes. The range has a size fixed at compile time, but the offset is specified at run time.
 /////////////////////////////
- 
+
 template <int RangeSize, bool Mutable>
 class bit_range {
 public:
@@ -54,7 +54,7 @@
 
 public:
     bit_range() : _current_byte(NULL), _bit_offset(0) {}
-    bit_range(byte_t* current_byte, int bit_offset) : _current_byte(current_byte), _bit_offset(bit_offset) { assert(bit_offset>=0 && bit_offset<8); } 
+    bit_range(byte_t* current_byte, int bit_offset) : _current_byte(current_byte), _bit_offset(bit_offset) { assert(bit_offset>=0 && bit_offset<8); }
 
     bit_range(const bit_range& br) : _current_byte(br._current_byte), _bit_offset(br._bit_offset) {}
     template <bool M> bit_range(const bit_range<RangeSize,M>& br) : _current_byte(br._current_byte), _bit_offset(br._bit_offset) {}
@@ -86,12 +86,12 @@
 };
 
 
-/// \defgroup ColorBaseModelNonAlignedPixel bit_aligned_pixel_reference 
+/// \defgroup ColorBaseModelNonAlignedPixel bit_aligned_pixel_reference
 /// \ingroup ColorBaseModel
 /// \brief A heterogeneous color base representing pixel that may not be byte aligned, i.e. it may correspond to a bit range that does not start/end at a byte boundary. Models ColorBaseConcept.
 
 /**
-\defgroup PixelModelNonAlignedPixel bit_aligned_pixel_reference 
+\defgroup PixelModelNonAlignedPixel bit_aligned_pixel_reference
 \ingroup PixelModel
 \brief A heterogeneous pixel reference used to represent non-byte-aligned pixels. Models PixelConcept
 
@@ -104,7 +104,7 @@
 
 // create the pixel reference at bit offset 2
 // (i.e. red = [2], green = [3,4], blue = [5,6,7] bits)
-rgb123_ref_t ref(&data, 2); 
+rgb123_ref_t ref(&data, 2);
 get_color(ref, red_t()) = 1;
 assert(data == 0x04);
 get_color(ref, green_t()) = 3;
@@ -114,87 +114,200 @@
 \endcode
 */
 /// \ingroup ColorBaseModelNonAlignedPixel PixelModelNonAlignedPixel PixelBasedModel
-/// \brief Heterogeneous pixel reference corresponding to non-byte-aligned bit range. Models ColorBaseConcept, PixelConcept, PixelBasedConcept
+/// \brief Heterogeneous pixel reference corresponding to non-byte-aligned bit range.
+///        Models ColorBaseConcept, PixelConcept, PixelBasedConcept
 template <typename BitField,
-          typename ChannelBitSizes,  // MPL integral vector defining the number of bits for each channel. For example, for 565RGB, vector_c<int,5,6,5>
-          typename Layout, 
+          typename ChannelBitSizes,
+          // MPL integral vector defining the number of bits for each channel.
+          // For example, for 565RGB, vector_c<int,5,6,5>
+          typename Layout,
           bool IsMutable>
 struct bit_aligned_pixel_reference {
-    BOOST_STATIC_CONSTANT(int, bit_size = (mpl::accumulate<ChannelBitSizes, mpl::int_<0>, mpl::plus<mpl::_1, mpl::_2> >::type::value));
-    typedef boost::gil::bit_range<bit_size,IsMutable>                                           bit_range_t;
-    typedef BitField                                                                bitfield_t;  
-    typedef typename mpl::if_c<IsMutable,unsigned char*,const unsigned char*>::type data_ptr_t;
+    BOOST_STATIC_CONSTANT(int,
+                          bit_size = (mpl::accumulate<ChannelBitSizes,
+                                                      mpl::int_<0>,
+                                                      mpl::plus<mpl::_1,
+                                                                mpl::_2
+                                                                >
+                                                      >::type
+                                                      ::value
+                                      )
+                          );
 
+    typedef boost::gil::bit_range<bit_size,IsMutable>   bit_range_t;
+    typedef BitField bitfield_t;
+
+    typedef typename mpl::if_c<IsMutable,
+        unsigned char*,
+        const unsigned char*
+        >::type
+    data_ptr_t;
+
     typedef Layout layout_t;
 
-    typedef typename packed_pixel_type<bitfield_t,ChannelBitSizes,Layout>::type       value_type;
-    typedef const bit_aligned_pixel_reference                                         reference;
-    typedef const bit_aligned_pixel_reference<BitField,ChannelBitSizes,Layout,false>  const_reference;
+    typedef
+        typename packed_pixel_type<
+            bitfield_t,
+            ChannelBitSizes,
+            Layout
+            >::type
+    value_type;
 
+    typedef const bit_aligned_pixel_reference  reference;
+    typedef const bit_aligned_pixel_reference<
+        BitField,
+        ChannelBitSizes,
+        Layout,
+        false>
+    const_reference;
+
+
     BOOST_STATIC_CONSTANT(bool, is_mutable = IsMutable);
 
     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 <bool IsMutable2> bit_aligned_pixel_reference(const bit_aligned_pixel_reference<BitField,ChannelBitSizes,Layout,IsMutable2>& p) : _bit_range(p._bit_range) {}
 
+    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 <bool IsMutable2>
+    bit_aligned_pixel_reference(const bit_aligned_pixel_reference<
+                                    BitField,
+                                    ChannelBitSizes,
+                                    Layout,
+                                    IsMutable2>& p)
+        : _bit_range(p._bit_range)
+    {}
+
     // Grayscale references can be constructed from the channel reference
-    explicit bit_aligned_pixel_reference(const typename kth_element_type<bit_aligned_pixel_reference,0>::type channel0) : _bit_range(static_cast<data_ptr_t>(&channel0), channel0.first_bit()) {
+    explicit
+    bit_aligned_pixel_reference(const typename kth_element_type<
+                                     bit_aligned_pixel_reference,
+                                     0>::type channel0
+                                     )
+        : _bit_range(static_cast<data_ptr_t>(&channel0), channel0.first_bit())
+    {
         BOOST_STATIC_ASSERT((num_channels<bit_aligned_pixel_reference>::value==1));
     }
 
     // Construct from another compatible pixel type
-    bit_aligned_pixel_reference(const bit_aligned_pixel_reference& p) : _bit_range(p._bit_range) {}
-    template <typename BF, typename CR> bit_aligned_pixel_reference(packed_pixel<BF,CR,Layout>& p) : _bit_range(static_cast<data_ptr_t>(&at_c<0>(p)), at_c<0>(p).first_bit()) {
+    bit_aligned_pixel_reference(const bit_aligned_pixel_reference& p)
+        : _bit_range(p._bit_range)
+    {}
+
+
+    template <typename BF, typename CR>
+    bit_aligned_pixel_reference(packed_pixel<BF,CR,Layout>& p)
+        : _bit_range(static_cast<data_ptr_t>(&at_c<0>(p)),
+                     at_c<0>(p).first_bit())
+    {
         check_compatible<packed_pixel<BF,CR,Layout> >();
     }
 
-    const bit_aligned_pixel_reference& operator=(const bit_aligned_pixel_reference& p) const { static_copy(p,*this); return *this; }
-    template <typename P> const bit_aligned_pixel_reference& operator=(const P& p) const { assign(p, mpl::bool_<is_pixel<P>::value>()); return *this; } 
+    const bit_aligned_pixel_reference&
+    operator=(const bit_aligned_pixel_reference& p) const {
+        static_copy(p,*this);
+        return *this;
+    }
 
-    template <typename P> bool operator==(const P& p) const { return equal(p, mpl::bool_<is_pixel<P>::value>()); } 
-    template <typename P> bool operator!=(const P& p) const { return !(*this==p); }
 
+    template <typename P>
+        const bit_aligned_pixel_reference&
+    operator=(const P& p) const {
+        assign(p, mpl::bool_<is_pixel<P>::value>());
+        return *this;
+    }
+
+    template <typename P>
+    bool operator==(const P& p) const {
+        return equal(p, mpl::bool_<is_pixel<P>::value>());
+    }
+
+    template <typename P>
+    bool operator!=(const P& p) const {
+        return !(*this==p);
+    }
+
     const bit_aligned_pixel_reference* operator->()    const { return this; }
 
     const bit_range_t& bit_range() const { return _bit_range; }
 private:
     mutable bit_range_t _bit_range;
-    template <typename B, typename C, typename L, bool M> friend struct bit_aligned_pixel_reference;
 
-    template <typename Pixel> static void check_compatible() { gil_function_requires<PixelsCompatibleConcept<Pixel,bit_aligned_pixel_reference> >(); }
+    template <typename B, typename C, typename L, bool M>
+    friend struct bit_aligned_pixel_reference;
 
-    template <typename Pixel> void assign(const Pixel& p, mpl::true_) const { check_compatible<Pixel>(); static_copy(p,*this); } 
-    template <typename Pixel> bool  equal(const Pixel& p, mpl::true_) const { check_compatible<Pixel>(); return static_equal(*this,p); } 
+    template <typename Pixel>
+    static void check_compatible() {
+        gil_function_requires<
+            PixelsCompatibleConcept<Pixel,
+                                    bit_aligned_pixel_reference
+                                    >
+            >();
+    }
 
+    template <typename Pixel>
+    void assign(const Pixel& p, mpl::true_) const {
+        check_compatible<Pixel>();
+        static_copy(p,*this);
+    }
+
+
+    template <typename Pixel>
+    bool  equal(const Pixel& p, mpl::true_) const {
+        check_compatible<Pixel>();
+        return static_equal(*this,p);
+    }
+
 private:
-    static void check_gray() {  BOOST_STATIC_ASSERT((is_same<typename Layout::color_space_t, gray_t>::value)); }
-    template <typename Channel> void assign(const Channel& chan, mpl::false_) const { check_gray(); at_c<0>(*this)=chan; }
-    template <typename Channel> bool equal (const Channel& chan, mpl::false_) const { check_gray(); return at_c<0>(*this)==chan; }
+    static void check_gray() {
+        BOOST_STATIC_ASSERT((is_same<typename Layout::color_space_t,
+                                      gray_t
+                                      >::value
+                           ));
+    }
+
+    template <typename Channel>
+    void assign(const Channel& chan, mpl::false_) const {
+        check_gray();
+        at_c<0>(*this)=chan;
+    }
+
+
+    template <typename Channel>
+    bool equal (const Channel& chan, mpl::false_) const {
+        check_gray();
+        return at_c<0>(*this)==chan;
+    }
 };
 
 /////////////////////////////
 //  ColorBasedConcept
 /////////////////////////////
 
-template <typename BitField, typename ChannelBitSizes, typename L, bool IsMutable, int K>  
+template <typename BitField, typename ChannelBitSizes, typename L, bool IsMutable, int K>
 struct kth_element_type<bit_aligned_pixel_reference<BitField,ChannelBitSizes,L,IsMutable>, K> {
 public:
     typedef const packed_dynamic_channel_reference<BitField, mpl::at_c<ChannelBitSizes,K>::type::value, IsMutable> type;
 };
 
-template <typename B, typename C, typename L, bool M, int K>  
+template <typename B, typename C, typename L, bool M, int K>
 struct kth_element_reference_type<bit_aligned_pixel_reference<B,C,L,M>, K>
     : public kth_element_type<bit_aligned_pixel_reference<B,C,L,M>, K> {};
 
-template <typename B, typename C, typename L, bool M, int K>  
+template <typename B, typename C, typename L, bool M, int K>
 struct kth_element_const_reference_type<bit_aligned_pixel_reference<B,C,L,M>, K>
     : public kth_element_type<bit_aligned_pixel_reference<B,C,L,M>, K> {};
 
 
 namespace detail {
     // returns sum of IntegralVector[0] ... IntegralVector[K-1]
-    template <typename IntegralVector, int K> 
+    template <typename IntegralVector, int K>
     struct sum_k : public mpl::plus<sum_k<IntegralVector,K-1>, typename mpl::at_c<IntegralVector,K-1>::type > {};
 
     template <typename IntegralVector> struct sum_k<IntegralVector,0> : public mpl::int_<0> {};
@@ -203,7 +316,7 @@
 // at_c required by MutableColorBaseConcept
 template <int K, typename BitField, typename ChannelBitSizes, typename L, bool Mutable> inline
 typename kth_element_reference_type<bit_aligned_pixel_reference<BitField,ChannelBitSizes,L,Mutable>,K>::type
-at_c(const bit_aligned_pixel_reference<BitField,ChannelBitSizes,L,Mutable>& p) { 
+at_c(const bit_aligned_pixel_reference<BitField,ChannelBitSizes,L,Mutable>& p) {
     typedef bit_aligned_pixel_reference<BitField,ChannelBitSizes,L,Mutable> pixel_t;
     typedef typename kth_element_reference_type<pixel_t,K>::type channel_t;
     typedef typename pixel_t::bit_range_t bit_range_t;
@@ -211,7 +324,7 @@
     bit_range_t bit_range(p.bit_range());
     bit_range.bit_advance(detail::sum_k<ChannelBitSizes,K>::value);
 
-    return channel_t(bit_range.current_byte(), bit_range.bit_offset()); 
+    return channel_t(bit_range.current_byte(), bit_range.bit_offset());
 }
 
 /////////////////////////////
@@ -219,7 +332,7 @@
 /////////////////////////////
 
 /// Metafunction predicate that flags bit_aligned_pixel_reference as a model of PixelConcept. Required by PixelConcept
-template <typename B, typename C, typename L, bool M>  
+template <typename B, typename C, typename L, bool M>
 struct is_pixel<bit_aligned_pixel_reference<B,C,L,M> > : public mpl::true_{};
 
 /////////////////////////////
@@ -229,15 +342,15 @@
 template <typename B, typename C, typename L, bool M>
 struct color_space_type<bit_aligned_pixel_reference<B,C,L,M> > {
     typedef typename L::color_space_t type;
-}; 
+};
 
 template <typename B, typename C, typename L, bool M>
 struct channel_mapping_type<bit_aligned_pixel_reference<B,C,L,M> > {
     typedef typename L::channel_mapping_t type;
-}; 
+};
 
 template <typename B, typename C, typename L, bool M>
-struct is_planar<bit_aligned_pixel_reference<B,C,L,M> > : mpl::false_ {}; 
+struct is_planar<bit_aligned_pixel_reference<B,C,L,M> > : mpl::false_ {};
 
 /////////////////////////////
 //  pixel_reference_type
@@ -253,7 +366,7 @@
 }
 
 // Constructs a homogeneous bit_aligned_pixel_reference given a channel reference
-template <typename BitField, int NumBits, typename Layout> 
+template <typename BitField, int NumBits, typename Layout>
 struct pixel_reference_type<const packed_dynamic_channel_reference<BitField,NumBits,false>, Layout, false, false> {
 private:
     typedef typename mpl::size<typename Layout::color_space_t>::type size_t;
@@ -263,7 +376,7 @@
 };
 
 // Same but for the mutable case. We cannot combine the mutable and read-only cases because this triggers ambiguity
-template <typename BitField, int NumBits, typename Layout> 
+template <typename BitField, int NumBits, typename Layout>
 struct pixel_reference_type<const packed_dynamic_channel_reference<BitField,NumBits,true>, Layout, false, true> {
 private:
     typedef typename mpl::size<typename Layout::color_space_t>::type size_t;
@@ -276,27 +389,27 @@
 
 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
 // Having three overloads allows us to swap between different (but compatible) models of PixelConcept
 
 template <typename B, typename C, typename L, typename R> inline
-void swap(const boost::gil::bit_aligned_pixel_reference<B,C,L,true> x, R& y) { 
-    boost::gil::swap_proxy<typename boost::gil::bit_aligned_pixel_reference<B,C,L,true>::value_type>(x,y); 
+void swap(const boost::gil::bit_aligned_pixel_reference<B,C,L,true> x, R& y) {
+    boost::gil::swap_proxy<typename boost::gil::bit_aligned_pixel_reference<B,C,L,true>::value_type>(x,y);
 }
 
 
 template <typename B, typename C, typename L> inline
-void swap(typename boost::gil::bit_aligned_pixel_reference<B,C,L,true>::value_type& x, const boost::gil::bit_aligned_pixel_reference<B,C,L,true> y) { 
-    boost::gil::swap_proxy<typename boost::gil::bit_aligned_pixel_reference<B,C,L,true>::value_type>(x,y); 
+void swap(typename boost::gil::bit_aligned_pixel_reference<B,C,L,true>::value_type& x, const boost::gil::bit_aligned_pixel_reference<B,C,L,true> y) {
+    boost::gil::swap_proxy<typename boost::gil::bit_aligned_pixel_reference<B,C,L,true>::value_type>(x,y);
 }
 
 
 template <typename B, typename C, typename L> inline
-void swap(const boost::gil::bit_aligned_pixel_reference<B,C,L,true> x, const boost::gil::bit_aligned_pixel_reference<B,C,L,true> y) { 
-    boost::gil::swap_proxy<typename boost::gil::bit_aligned_pixel_reference<B,C,L,true>::value_type>(x,y); 
+void swap(const boost::gil::bit_aligned_pixel_reference<B,C,L,true> x, const boost::gil::bit_aligned_pixel_reference<B,C,L,true> y) {
+    boost::gil::swap_proxy<typename boost::gil::bit_aligned_pixel_reference<B,C,L,true>::value_type>(x,y);
 }
 }   // namespace std
 #endif
Index: extension/io/tiff_io.hpp
===================================================================
--- extension/io/tiff_io.hpp	(revision 49440)
+++ extension/io/tiff_io.hpp	(working copy)
@@ -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).
@@ -51,6 +51,12 @@
     BOOST_STATIC_CONSTANT(int,color_type=PHOTOMETRIC_RGB);
 };
 template <>
+struct tiff_read_support_private<bits8,rgba_t> {
+    BOOST_STATIC_CONSTANT(bool,is_supported=true);
+    BOOST_STATIC_CONSTANT(int,bit_depth=8);
+    BOOST_STATIC_CONSTANT(int,color_type=PHOTOMETRIC_RGB);
+};
+template <>
 struct tiff_read_support_private<bits16,gray_t> {
     BOOST_STATIC_CONSTANT(bool,is_supported=true);
     BOOST_STATIC_CONSTANT(int,bit_depth=16);
@@ -94,6 +100,12 @@
     BOOST_STATIC_CONSTANT(int,color_type=PHOTOMETRIC_RGB);
 };
 template <>
+struct tiff_write_support_private<bits8,rgba_t> {
+    BOOST_STATIC_CONSTANT(bool,is_supported=true);
+    BOOST_STATIC_CONSTANT(int,bit_depth=8);
+    BOOST_STATIC_CONSTANT(int,color_type=PHOTOMETRIC_RGB);
+};
+template <>
 struct tiff_write_support_private<bits16,gray_t> {
     BOOST_STATIC_CONSTANT(bool,is_supported=true);
     BOOST_STATIC_CONSTANT(int,bit_depth=16);
@@ -129,16 +141,18 @@
     ~tiff_reader() { TIFFClose(_tp); }
     template <typename View>
     void apply(const View& view) {
-        unsigned short bps,photometric;
+        unsigned short bps,spp, photometric;
         point2<std::ptrdiff_t> dims=get_dimensions();
         io_error_if(TIFFGetField(_tp,TIFFTAG_BITSPERSAMPLE,&bps)!=1);
         io_error_if(TIFFGetField(_tp,TIFFTAG_PHOTOMETRIC,&photometric)!=1);
+        io_error_if(TIFFGetField(_tp,TIFFTAG_SAMPLESPERPIXEL,&spp)!=1);
         io_error_if(dims!=view.dimensions(),
                     "tiff_read_view: input view size does not match TIFF file size");
         io_error_if(tiff_read_support_private<typename channel_type<View>::type,
                                               typename color_space_type<View>::type>::bit_depth!=bps ||
                     tiff_read_support_private<typename channel_type<View>::type,
-                                              typename color_space_type<View>::type>::color_type!=photometric,
+                                              typename color_space_type<View>::type>::color_type!=photometric ||
+                    mpl::size<typename color_space_type<View>::type>::value != spp,
                     "tiff_read_view: input view type is incompatible with the image type");
         std::size_t element_size=sizeof(pixel<typename channel_type<View>::type,
                                               layout<typename color_space_type<View>::type> >);
@@ -166,14 +180,14 @@
 };
 
 // This code will be simplified...
-template <typename CC>  
+template <typename CC>
 class tiff_reader_color_convert : public tiff_reader {
 private:
     CC _cc;
 public:
-    tiff_reader_color_convert(const char* filename) : 
+    tiff_reader_color_convert(const char* filename) :
         tiff_reader(filename) {}
-    tiff_reader_color_convert(const char* filename,CC cc_in) : 
+    tiff_reader_color_convert(const char* filename,CC cc_in) :
         tiff_reader(filename),_cc(cc_in) {}
     template <typename View>
     void apply(const View& view) {
@@ -273,7 +287,7 @@
         default: {
             // reads an image in incompatible format via TIFFReadRGBAImage
             rgba8_image_t rgbaImg(dims);
-            io_error_if(!TIFFReadRGBAImage(_tp, dims.x, dims.y, (uint32*)&gil::view(rgbaImg)(0,0), 0), 
+            io_error_if(!TIFFReadRGBAImage(_tp, dims.x, dims.y, (uint32*)&gil::view(rgbaImg)(0,0), 0),
                 "tiff_reader_color_convert::unsupported image format");
             copy_and_convert_pixels(flipped_up_down_view(const_view(rgbaImg)), view, _cc);
         }
@@ -353,7 +367,7 @@
 /// \ingroup TIFF_IO
 /// \brief Loads the image specified by the given tiff image file name into the given view.
 /// Triggers a compile assert if the view color space and channel depth are not supported by the TIFF library or by the I/O extension.
-/// Throws std::ios_base::failure if the file is not a valid TIFF file, or if its color space or channel depth are not 
+/// Throws std::ios_base::failure if the file is not a valid TIFF file, or if its color space or channel depth are not
 /// compatible with the ones specified by View, or if its dimensions don't match the ones of the view.
 template <typename View>
 inline void tiff_read_view(const char* filename,const View& view) {
@@ -372,7 +386,7 @@
 /// \ingroup TIFF_IO
 /// \brief Allocates a new image whose dimensions are determined by the given tiff image file, and loads the pixels into it.
 /// Triggers a compile assert if the image color space or channel depth are not supported by the TIFF library or by the I/O extension.
-/// Throws std::ios_base::failure if the file is not a valid TIFF file, or if its color space or channel depth are not 
+/// Throws std::ios_base::failure if the file is not a valid TIFF file, or if its color space or channel depth are not
 /// compatible with the ones specified by Image
 template <typename Image>
 void tiff_read_image(const char* filename,Image& im) {
@@ -468,13 +482,21 @@
     BOOST_STATIC_CONSTANT(bool, value=is_supported);
 };
 
+
+
 /// \ingroup TIFF_IO
 /// \brief Saves the view to a tiff file specified by the given tiff image file name.
-/// Triggers a compile assert if the view color space and channel depth are not supported by the TIFF library or by the I/O extension.
+///
+/// Triggers a compile assert if the view color space and channel depth are not
+/// supported by the TIFF library or by the I/O extension.
 /// Throws std::ios_base::failure if it fails to create the file.
 template <typename View>
 inline void tiff_write_view(const char* filename,const View& view) {
+    //You must typically transform a view into an integral type or
+    //a *scoped* float type before you can save it, or you will get
+    //an error here.
     BOOST_STATIC_ASSERT(tiff_write_support<View>::is_supported);
+
     detail::tiff_writer m(filename);
     m.apply(view);
 }
Index: image.hpp
===================================================================
--- image.hpp	(revision 49440)
+++ image.hpp	(working copy)
@@ -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).
@@ -13,7 +13,7 @@
 #define GIL_IMAGE_H
 
 ////////////////////////////////////////////////////////////////////////////////////////
-/// \file               
+/// \file
 /// \brief Templated image
 /// \author Lubomir Bourdev and Hailin Jin \n
 ///         Adobe Systems Incorporated
@@ -38,16 +38,18 @@
 ////////////////////////////////////////////////////////////////////////////////////////
 /// \ingroup ImageModel PixelBasedModel
 /// \brief container interface over image view. Models ImageConcept, PixelBasedConcept
-/// 
+///
 /// A 2D container whose elements are pixels. It is templated over the pixel type, a boolean
 /// indicating whether it should be planar, and an optional allocator.
 ///
-/// Note that its element type does not have to be a pixel. \p image can be instantiated with any Regular element, 
+/// Note that its element type does not have to be a pixel. \p image can be instantiated with any Regular element,
 /// in which case it models the weaker RandomAccess2DImageConcept and does not model PixelBasedConcept
 ///
 ////////////////////////////////////////////////////////////////////////////////////////
 
-template <typename Pixel, bool IsPlanar, typename Alloc=std::allocator<unsigned char> >    
+template <typename Pixel,
+          bool IsPlanar=false,
+          typename Alloc=std::allocator<unsigned char> >
 class image {
 public:
     typedef typename Alloc::template rebind<unsigned char>::other allocator_type;
@@ -64,7 +66,7 @@
     y_coord_t               height()                const { return _view.height(); }
 
     explicit image(std::size_t alignment=0,
-                   const Alloc alloc_in = Alloc()) : 
+                   const Alloc alloc_in = Alloc()) :
         _memory(0), _align_in_bytes(alignment), _alloc(alloc_in) {}
 
     // Create with dimensions and optional initial value and alignment
@@ -78,7 +80,7 @@
 		  const Alloc alloc_in = Alloc()) : _memory(0), _align_in_bytes(alignment), _alloc(alloc_in) {
         allocate_and_default_construct(point_t(width,height));
     }
-    image(const point_t& dimensions, 
+    image(const point_t& dimensions,
           const Pixel& p_in,
           std::size_t alignment,
           const Alloc alloc_in = Alloc())  :
@@ -99,7 +101,7 @@
     }
 
     template <typename P2, bool IP2, typename Alloc2>
-    image(const image<P2,IP2,Alloc2>& img) : 
+    image(const image<P2,IP2,Alloc2>& img) :
         _memory(0), _align_in_bytes(img._align_in_bytes), _alloc(img._alloc) {
        allocate_and_copy(img.dimensions(),img._view);
     }
@@ -136,9 +138,9 @@
         using std::swap;
         swap(_align_in_bytes, img._align_in_bytes);
         swap(_memory,         img._memory);
-        swap(_view,           img._view); 
+        swap(_view,           img._view);
         swap(_alloc,          img._alloc);
-    }    
+    }
 
     void recreate(const point_t& dims, std::size_t alignment=0, const Alloc alloc_in = Alloc()) {
         if (dims!=_view.dimensions() || _align_in_bytes!=alignment || alloc_in!=_alloc) {
@@ -149,14 +151,14 @@
     void recreate(x_coord_t width, y_coord_t height, std::size_t alignment=0, const Alloc alloc_in = Alloc()) {
         recreate(point_t(width,height),alignment,alloc_in);
     }
-    void recreate(const point_t& dims, 
+    void recreate(const point_t& dims,
                   const Pixel& p_in, std::size_t alignment, const Alloc alloc_in = Alloc()) {
         if (dims!=_view.dimensions() || _align_in_bytes!=alignment || alloc_in!=_alloc) {
             image tmp(dims, p_in, alignment, alloc_in);
             swap(tmp);
         }
     }
-    void recreate(x_coord_t width, y_coord_t height, 
+    void recreate(x_coord_t width, y_coord_t height,
                   const Pixel& p_in, std::size_t alignment, const Alloc alloc_in = Alloc()) {
         recreate(point_t(width,height),p_in,alignment,alloc_in);
     }
@@ -167,14 +169,14 @@
     std::size_t    _align_in_bytes;
     allocator_type _alloc;
 
-    void allocate_and_default_construct(const point_t& dimensions) { 
+    void allocate_and_default_construct(const point_t& dimensions) {
         try {
             allocate_(dimensions,mpl::bool_<IsPlanar>());
             default_construct_pixels(_view);
         } catch(...) { deallocate(dimensions); throw; }
     }
 
-    void allocate_and_fill(const point_t& dimensions, const Pixel& p_in) { 
+    void allocate_and_fill(const point_t& dimensions, const Pixel& p_in) {
         try {
             allocate_(dimensions,mpl::bool_<IsPlanar>());
             uninitialized_fill_pixels(_view, p_in);
@@ -182,25 +184,36 @@
     }
 
     template <typename View>
-    void allocate_and_copy(const point_t& dimensions, const View& v) { 
+    void allocate_and_copy(const point_t& dimensions, const View& v) {
         try {
             allocate_(dimensions,mpl::bool_<IsPlanar>());
             uninitialized_copy_pixels(v,_view);
         } catch(...) { deallocate(dimensions); throw; }
     }
 
-    void deallocate(const point_t& dimensions) { 
+    void deallocate(const point_t& dimensions) {
         if (_memory) _alloc.deallocate(_memory, total_allocated_size_in_bytes(dimensions));
     }
 
+    struct _channels_in_image :
+        mpl::eval_if<is_pixel<value_type>,
+            num_channels<view_t>,
+            mpl::int_<1>
+            >::type
+    {};
+
     std::size_t total_allocated_size_in_bytes(const point_t& dimensions) const {
         std::size_t size_in_units = get_row_size_in_memunits(dimensions.x)*dimensions.y;
-		if (IsPlanar)
-			size_in_units = size_in_units*num_channels<view_t>::value;
 
+        typedef typename view_t::x_iterator x_iterator;
+
+        if (IsPlanar)
+			size_in_units = size_in_units*_channels_in_image::value;
+
         // return the size rounded up to the nearest byte
-        return (size_in_units + byte_to_memunit<typename view_t::x_iterator>::value - 1) / byte_to_memunit<typename view_t::x_iterator>::value
-			+ (_align_in_bytes>0 ? _align_in_bytes-1:0);	// add extra padding in case we need to align the first image pixel
+        return (size_in_units + byte_to_memunit<x_iterator>::value - 1) / byte_to_memunit<x_iterator>::value
+			+ (_align_in_bytes>0 ? _align_in_bytes-1:0);
+        // add extra padding in case we need to align the first image pixel
     }
 
     std::size_t get_row_size_in_memunits(x_coord_t width) const {   // number of units per row
@@ -211,7 +224,7 @@
 		}
 		return size_in_memunits;
     }
-    
+
     void allocate_(const point_t& dimensions, mpl::false_) {  // if it throws and _memory!=0 the client must deallocate _memory
         _memory=_alloc.allocate(total_allocated_size_in_bytes(dimensions));
 		unsigned char* tmp=(_align_in_bytes>0) ? (unsigned char*)align((std::size_t)_memory,_align_in_bytes) : _memory;
@@ -223,7 +236,7 @@
         std::size_t plane_size=row_size*dimensions.y;
         _memory=_alloc.allocate(total_allocated_size_in_bytes(dimensions));
 		unsigned char* tmp=(_align_in_bytes>0) ? (unsigned char*)align((std::size_t)_memory,_align_in_bytes) : _memory;
-        typename view_t::x_iterator first; 
+        typename view_t::x_iterator first;
         for (int i=0; i<num_channels<view_t>::value; ++i) {
             dynamic_at_c(first,i) = (typename channel_type<view_t>::type*)tmp;
             memunit_advance(dynamic_at_c(first,i), plane_size*i);
@@ -234,7 +247,7 @@
 
 template <typename Pixel, bool IsPlanar, typename Alloc>
 void swap(image<Pixel, IsPlanar, Alloc>& im1,image<Pixel, IsPlanar, Alloc>& im2) {
-    im1.swap(im2); 
+    im1.swap(im2);
 }
 
 template <typename Pixel1, bool IsPlanar1, typename Alloc1, typename Pixel2, bool IsPlanar2, typename Alloc2>
@@ -253,13 +266,17 @@
 /// \ingroup ImageModel
 
 /// \brief Returns the non-constant-pixel view of an image
-template <typename Pixel, bool IsPlanar, typename Alloc> inline 
-const typename image<Pixel,IsPlanar,Alloc>::view_t& view(image<Pixel,IsPlanar,Alloc>& img) { return img._view; }
+template <typename Pixel, bool IsPlanar, typename Alloc>
+inline
+const typename image<Pixel,IsPlanar,Alloc>::view_t&
+view(image<Pixel,IsPlanar,Alloc>& img) {
+    return img._view;
+}
 
 /// \brief Returns the constant-pixel view of an image
-template <typename Pixel, bool IsPlanar, typename Alloc> inline 
-const typename image<Pixel,IsPlanar,Alloc>::const_view_t const_view(const image<Pixel,IsPlanar,Alloc>& img) { 
-    return static_cast<const typename image<Pixel,IsPlanar,Alloc>::const_view_t>(img._view); 
+template <typename Pixel, bool IsPlanar, typename Alloc> inline
+const typename image<Pixel,IsPlanar,Alloc>::const_view_t const_view(const image<Pixel,IsPlanar,Alloc>& img) {
+    return static_cast<const typename image<Pixel,IsPlanar,Alloc>::const_view_t>(img._view);
 }
 ///@}
 
@@ -268,7 +285,7 @@
 /////////////////////////////
 
 template <typename Pixel, bool IsPlanar, typename Alloc>
-struct channel_type<image<Pixel,IsPlanar,Alloc> > : public channel_type<Pixel> {}; 
+struct channel_type<image<Pixel,IsPlanar,Alloc> > : public channel_type<Pixel> {};
 
 template <typename Pixel, bool IsPlanar, typename Alloc>
 struct color_space_type<image<Pixel,IsPlanar,Alloc> >  : public color_space_type<Pixel> {};
Index: image_view.hpp
===================================================================
--- image_view.hpp	(revision 49440)
+++ image_view.hpp	(working copy)
@@ -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).
@@ -13,7 +13,7 @@
 #define GIL_IMAGE_VIEW_H
 
 ////////////////////////////////////////////////////////////////////////////////////////
-/// \file               
+/// \file
 /// \brief image view class
 /// \author Lubomir Bourdev and Hailin Jin \n
 ///         Adobe Systems Incorporated
@@ -45,8 +45,8 @@
 /// that don't own the pixels. It is the user's responsibility that the underlying data remains
 /// valid for the lifetime of the image view.
 ///
-/// Similar to iterators and ranges, constness of views does not extend to constness of pixels. 
-/// A const \p image_view does not allow changing its location in memory (resizing, moving) but does 
+/// Similar to iterators and ranges, constness of views does not extend to constness of pixels.
+/// A const \p image_view does not allow changing its location in memory (resizing, moving) but does
 /// not prevent one from changing the pixels. The latter requires an image view whose value_type
 /// is const.
 ///
@@ -82,6 +82,9 @@
         typedef typename Loc::template axis<D>::iterator iterator;       // 1D iterator type along each dimension
     };
     typedef iterator_from_2d<Loc>                    iterator;       // 1D iterator type for each pixel left-to-right inside top-to-bottom
+    typedef typename const_t::iterator               const_iterator;
+    typedef typename const_t::reference              const_reference;
+    typedef typename std::iterator_traits<iterator>::pointer pointer;
     typedef std::reverse_iterator<iterator>          reverse_iterator;
     typedef std::size_t                              size_type;
 
@@ -98,7 +101,10 @@
     };
 
     image_view() : _dimensions(0,0) {}
-    template <typename View> image_view(const View& iv)                                    : _dimensions(iv.dimensions()), _pixels(iv.pixels()) {}
+    template <typename View> image_view(const View& iv)
+        : _dimensions(iv.dimensions()),
+          _pixels(iv.pixels())
+    {}
 
     template <typename L2> image_view(const point_t& sz            , const L2& loc)        : _dimensions(sz),          _pixels(loc) {}
     template <typename L2> image_view(coord_t width, coord_t height, const L2& loc)        : _dimensions(x_coord_t(width),y_coord_t(height)), _pixels(loc) {}
@@ -111,6 +117,47 @@
 
     template <typename L2> friend void swap(image_view<L2>& x, image_view<L2>& y);
 
+    ///\brief Exchanges the elements of the current view with those of \a other
+    ///       in constant time.
+    ///
+    ///\note Required by concept
+    ///      http://www.boost.org/doc/libs/1_35_0/libs/utility/Collection.html
+    void swap(image_view<Loc>& other)
+    {
+        swap(*this, other);
+    }
+
+
+
+    ///\brief Returns true if the view has no elements, false otherwise.
+    ///
+    ///\note Required by concept
+    ///      http://www.boost.org/doc/libs/1_35_0/libs/utility/Collection.html
+    bool empty() const
+    {
+        return width() > 0 && height() > 0;
+    }
+
+    ///\brief Returns a reference to the first element in raster order.
+    ///
+    ///\note Required by concept
+    ///      http://www.boost.org/doc/libs/1_35_0/libs/utility/Collection.html
+    ///      since views model ForwardCollection
+    reference front() const
+    {
+        return *begin();
+    }
+
+    ///\brief Returns a reference to the last element in raster order.
+    ///
+    ///\note Required by concept
+    ///      http://www.boost.org/doc/libs/1_35_0/libs/utility/Collection.html
+    ///      since views model ReversibleCollection
+    reference back() const
+    {
+        return *rbegin();
+    }
+
     const point_t&   dimensions()            const { return _dimensions; }
     const locator&   pixels()                const { return _pixels; }
     x_coord_t        width()                 const { return dimensions().x; }
@@ -120,7 +167,7 @@
 
     //\{@
     /// \name 1D navigation
-    size_type           size()               const { return width()*height(); }  
+    size_type           size()               const { return width()*height(); }
     iterator            begin()              const { return iterator(_pixels,_dimensions.x); }
     iterator            end()                const { return begin()+(difference_type)size(); }    // potential performance problem!
     reverse_iterator    rbegin()             const { return reverse_iterator(end()); }
@@ -135,7 +182,11 @@
     //\{@
     /// \name 2-D navigation
     reference operator()(const point_t& p)        const { return _pixels(p.x,p.y); }
-    reference operator()(x_coord_t x, y_coord_t y)const { return _pixels(x,y); }
+
+    reference operator()(x_coord_t x, y_coord_t y)const {
+        return _pixels(x,y);
+    }
+
     template <std::size_t D> typename axis<D>::iterator axis_iterator(const point_t& p) const { return _pixels.axis_iterator<D>(p); }
     xy_locator xy_at(x_coord_t x, y_coord_t y)    const { return _pixels+point_t(x_coord_t(x),y_coord_t(y)); }
     locator    xy_at(const point_t& p)            const { return _pixels+p; }
@@ -164,10 +215,10 @@
     xy_locator _pixels;
 };
 
-template <typename L2> 
-inline void swap(image_view<L2>& x, image_view<L2>& y) { 
+template <typename L2>
+inline void swap(image_view<L2>& x, image_view<L2>& y) {
     using std::swap;
-    swap(x._dimensions,y._dimensions); 
+    swap(x._dimensions,y._dimensions);
     swap(x._pixels, y._pixels);            // TODO: Extend further
 }
 
@@ -176,16 +227,16 @@
 /////////////////////////////
 
 template <typename L>
-struct channel_type<image_view<L> > : public channel_type<L> {}; 
+struct channel_type<image_view<L> > : public channel_type<L> {};
 
 template <typename L>
-struct color_space_type<image_view<L> > : public color_space_type<L> {}; 
+struct color_space_type<image_view<L> > : public color_space_type<L> {};
 
 template <typename L>
-struct channel_mapping_type<image_view<L> > : public channel_mapping_type<L> {}; 
+struct channel_mapping_type<image_view<L> > : public channel_mapping_type<L> {};
 
 template <typename L>
-struct is_planar<image_view<L> > : public is_planar<L> {}; 
+struct is_planar<image_view<L> > : public is_planar<L> {};
 
 /////////////////////////////
 //  HasDynamicXStepTypeConcept
Index: locator.hpp
===================================================================
--- locator.hpp	(revision 49440)
+++ locator.hpp	(working copy)
@@ -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).
@@ -15,7 +15,7 @@
 
 
 ////////////////////////////////////////////////////////////////////////////////////////
-/// \file               
+/// \file
 /// \brief pixel 2D locator
 /// \author Lubomir Bourdev and Hailin Jin \n
 ///         Adobe Systems Incorporated
@@ -62,7 +62,7 @@
 /// \brief base class for models of PixelLocatorConcept
 /// \ingroup PixelLocatorModel PixelBasedModel
 ///
-/// Pixel locator is similar to a pixel iterator, but allows for 2D navigation of pixels within an image view. 
+/// Pixel locator is similar to a pixel iterator, but allows for 2D navigation of pixels within an image view.
 /// It has a 2D difference_type and supports random access operations like:
 /// \code
 ///     difference_type offset2(2,3);
@@ -76,7 +76,7 @@
 /// It is called a locator because it doesn't implement the complete interface of a random access iterator.
 /// For example, increment and decrement operations don't make sense (no way to specify dimension).
 /// Also 2D difference between two locators cannot be computed without knowledge of the X position within the image.
-/// 
+///
 /// This base class provides most of the methods and typedefs needed to create a model of a locator. GIL provides two
 /// locator models as subclasses of \p pixel_2d_locator_base. A memory-based locator, \p memory_based_2d_locator and a virtual
 /// locator, \p virtual_2d_locator.
@@ -108,7 +108,7 @@
 ///        // return the vertical distance to another locator. Some models need the horizontal distance to compute it
 ///        y_coord_t         y_distance_to(const my_locator& loc2, x_coord_t xDiff) const;
 ///
-///        // return true iff incrementing an x-iterator located at the last column will position it at the first 
+///        // return true iff incrementing an x-iterator located at the last column will position it at the first
 ///        // column of the next row. Some models need the image width to determine that.
 ///        bool              is_1d_traversable(x_coord_t width) const;
 /// };
@@ -159,12 +159,12 @@
 
     Loc&              operator+=(const difference_type& d)         { concrete().x()+=d.x; concrete().y()+=d.y; return concrete(); }
     Loc&              operator-=(const difference_type& d)         { concrete().x()-=d.x; concrete().y()-=d.y; return concrete(); }
-    
+
     Loc               operator+(const difference_type& d)    const { return xy_at(d); }
     Loc               operator-(const difference_type& d)    const { return xy_at(-d); }
 
     // Some locators can cache 2D coordinates for faster subsequent access. By default there is no caching
-    typedef difference_type    cached_location_t;    
+    typedef difference_type    cached_location_t;
     cached_location_t cache_location(const difference_type& d)  const { return d; }
     cached_location_t cache_location(x_coord_t dx, y_coord_t dy)const { return difference_type(dx,dy); }
 
@@ -177,7 +177,7 @@
 
 // helper classes for each axis of pixel_2d_locator_base
 namespace detail {
-    template <typename Loc> 
+    template <typename Loc>
     class locator_axis<0,Loc> {
         typedef typename Loc::point_t                       point_t;
     public:
@@ -190,7 +190,7 @@
         inline iterator         operator()(const Loc& loc, const point_t& d) const { return loc.x_at(d); }
     };
 
-    template <typename Loc> 
+    template <typename Loc>
     class locator_axis<1,Loc> {
         typedef typename Loc::point_t                       point_t;
     public:
@@ -224,10 +224,10 @@
 /// while its base iterator provides horizontal navigation.
 ///
 /// Each instantiation is optimal in terms of size and efficiency.
-/// For example, xy locator over interleaved rgb image results in a step iterator consisting of 
-/// one std::ptrdiff_t for the row size and one native pointer (8 bytes total). ++locator.x() resolves to pointer 
-/// increment. At the other extreme, a 2D navigation of the even pixels of a planar CMYK image results in a step 
-/// iterator consisting of one std::ptrdiff_t for the doubled row size, and one step iterator consisting of 
+/// For example, xy locator over interleaved rgb image results in a step iterator consisting of
+/// one std::ptrdiff_t for the row size and one native pointer (8 bytes total). ++locator.x() resolves to pointer
+/// increment. At the other extreme, a 2D navigation of the even pixels of a planar CMYK image results in a step
+/// iterator consisting of one std::ptrdiff_t for the doubled row size, and one step iterator consisting of
 /// one std::ptrdiff_t for the horizontal step of two and a CMYK planar_pixel_iterator consisting of 4 pointers (24 bytes).
 /// In this case ++locator.x() results in four native pointer additions.
 ///
@@ -238,7 +238,13 @@
 ////////////////////////////////////////////////////////////////////////////////////////
 
 template <typename StepIterator>
-class memory_based_2d_locator : public pixel_2d_locator_base<memory_based_2d_locator<StepIterator>, typename iterator_adaptor_get_base<StepIterator>::type, StepIterator> {
+class memory_based_2d_locator :
+    public pixel_2d_locator_base<
+        memory_based_2d_locator<StepIterator>,
+        typename iterator_adaptor_get_base<StepIterator>::type,
+        StepIterator
+        >
+{
     typedef memory_based_2d_locator<StepIterator>  this_t;
     GIL_CLASS_REQUIRE(StepIterator, boost::gil, StepIteratorConcept)
 public:
@@ -255,8 +261,8 @@
 
     template <typename Deref> struct add_deref {
         typedef memory_based_2d_locator<typename iterator_add_deref<StepIterator,Deref>::type> type;
-        static type make(const memory_based_2d_locator<StepIterator>& loc, const Deref& nderef) { 
-            return type(iterator_add_deref<StepIterator,Deref>::make(loc.y(),nderef)); 
+        static type make(const memory_based_2d_locator<StepIterator>& loc, const Deref& nderef) {
+            return type(iterator_add_deref<StepIterator,Deref>::make(loc.y(),nderef));
         }
     };
 
@@ -268,7 +274,10 @@
                                         (transpose ? loc.pixel_size() : loc.row_size())*y_step ) {}
 
     memory_based_2d_locator(x_iterator xit, std::ptrdiff_t row_bytes) : _p(xit,row_bytes) {}
-    template <typename X> memory_based_2d_locator(const memory_based_2d_locator<X>& pl) : _p(pl._p) {}
+
+    template <typename X>
+    memory_based_2d_locator(const memory_based_2d_locator<X>& pl) : _p(pl._p) {}
+
     memory_based_2d_locator(const memory_based_2d_locator& pl) : _p(pl._p) {}
 
     bool                  operator==(const this_t& p)  const { return _p==p._p; }
@@ -278,18 +287,23 @@
     x_iterator&           x()                                { return _p.base(); }
     y_iterator&           y()                                { return _p; }
 
-    // These are faster versions of functions already provided in the superclass 
-    x_iterator x_at      (x_coord_t dx, y_coord_t dy)  const { return memunit_advanced(x(), offset(dx,dy)); }    
+    // These are faster versions of functions already provided in the superclass
+    x_iterator x_at      (x_coord_t dx, y_coord_t dy)  const { return memunit_advanced(x(), offset(dx,dy)); }
     x_iterator x_at      (const difference_type& d)    const { return memunit_advanced(x(), offset(d.x,d.y)); }
     this_t     xy_at     (x_coord_t dx, y_coord_t dy)  const { return this_t(x_at( dx , dy ), row_size()); }
     this_t     xy_at     (const difference_type& d)    const { return this_t(x_at( d.x, d.y), row_size()); }
-    reference  operator()(x_coord_t dx, y_coord_t dy)  const { return memunit_advanced_ref(x(),offset(dx,dy)); }
+
+    reference  operator()(x_coord_t dx, y_coord_t dy)  const {
+        return memunit_advanced_ref(x(),offset(dx,dy));
+    }
+
     reference  operator[](const difference_type& d)    const { return memunit_advanced_ref(x(),offset(d.x,d.y)); }
     this_t&    operator+=(const difference_type& d)          { memunit_advance(x(),offset(d.x,d.y)); return *this; }
     this_t&    operator-=(const difference_type& d)          { memunit_advance(x(),offset(-d.x,-d.y)); return *this; }
 
     // Memory-based locators can have 1D caching of 2D relative coordinates
     typedef std::ptrdiff_t cached_location_t; // type used to store relative location (to allow for more efficient repeated access)
+
     cached_location_t cache_location(const difference_type& d)  const { return offset(d.x,d.y); }
     cached_location_t cache_location(x_coord_t dx, y_coord_t dy)const { return offset(dx,dy); }
     reference         operator[](const cached_location_t& loc)  const { return memunit_advanced_ref(x(),loc); }
@@ -301,7 +315,7 @@
     bool                   is_1d_traversable(x_coord_t width)   const { return row_size()-pixel_size()*width==0; }   // is there no gap at the end of each row?
 
     // Returns the vertical distance (it2.y-it1.y) between two x_iterators given the difference of their x positions
-    std::ptrdiff_t y_distance_to(const this_t& p2, x_coord_t xDiff) const { 
+    std::ptrdiff_t y_distance_to(const this_t& p2, x_coord_t xDiff) const {
         std::ptrdiff_t rowDiff=memunit_distance(x(),p2.x())-pixel_size()*xDiff;
         assert(( rowDiff % row_size())==0);
         return rowDiff / row_size();
Index: pixel.hpp
===================================================================
--- pixel.hpp	(revision 49440)
+++ pixel.hpp	(working copy)
@@ -42,7 +42,7 @@
 template <typename PixelBased> struct color_space_type;
 template <typename PixelBased> struct channel_mapping_type;
 template <typename PixelBased> struct channel_type;
-template <typename PixelBased> struct is_planar;
+template <typename PixelBased> struct is_planar : mpl::false_{}; //False by default
 
 template <typename PixelBased> struct color_space_type<const PixelBased> : public color_space_type<PixelBased> {};
 template <typename PixelBased> struct channel_mapping_type<const PixelBased> : public channel_mapping_type<PixelBased> {};
Index: pixel_iterator.hpp
===================================================================
--- pixel_iterator.hpp	(revision 49440)
+++ pixel_iterator.hpp	(working copy)
@@ -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_PIXEL_ITERATOR_H
 
 ////////////////////////////////////////////////////////////////////////////////////////
-/// \file               
+/// \file
 /// \brief pixel iterator support
 /// \author Lubomir Bourdev and Hailin Jin \n
 ///         Adobe Systems Incorporated
@@ -78,13 +78,13 @@
 //  HasDynamicXStepTypeConcept
 /////////////////////////////
 
-/// \ingroup PixelIteratorModelInterleavedPtr 
+/// \ingroup PixelIteratorModelInterleavedPtr
 template <typename Pixel>
 struct dynamic_x_step_type<Pixel*> {
     typedef memory_based_step_iterator<Pixel*> type;
 };
 
-/// \ingroup PixelIteratorModelInterleavedPtr 
+/// \ingroup PixelIteratorModelInterleavedPtr
 template <typename Pixel>
 struct dynamic_x_step_type<const Pixel*> {
     typedef memory_based_step_iterator<const Pixel*> type;
@@ -129,12 +129,12 @@
 inline std::ptrdiff_t memunit_step(const P*) { return sizeof(P); }
 
 template <typename P>
-inline std::ptrdiff_t memunit_distance(const P* p1, const P* p2) { 
-    return (gil_reinterpret_cast_c<const unsigned char*>(p2)-gil_reinterpret_cast_c<const unsigned char*>(p1)); 
+inline std::ptrdiff_t memunit_distance(const P* p1, const P* p2) {
+    return (gil_reinterpret_cast_c<const unsigned char*>(p2)-gil_reinterpret_cast_c<const unsigned char*>(p1));
 }
 
 template <typename P>
-inline void memunit_advance(P* &p, std::ptrdiff_t diff) { 
+inline void memunit_advance(P* &p, std::ptrdiff_t diff) {
     p=(P*)((unsigned char*)(p)+diff);
 }
 
Index: pixel_iterator_adaptor.hpp
===================================================================
--- pixel_iterator_adaptor.hpp	(revision 49440)
+++ pixel_iterator_adaptor.hpp	(working copy)
@@ -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_PIXEL_ITERATOR_ADAPTOR_H
 
 ////////////////////////////////////////////////////////////////////////////////////////
-/// \file               
+/// \file
 /// \brief pixel step iterator, pixel image iterator and pixel dereference iterator
 /// \author Lubomir Bourdev and Hailin Jin \n
 ///         Adobe Systems Incorporated
@@ -41,31 +41,46 @@
 
 template <typename Iterator,    // Models Iterator
           typename DFn>  // Models Returns the result of dereferencing a given iterator of type Iterator
-class dereference_iterator_adaptor : public iterator_adaptor<dereference_iterator_adaptor<Iterator,DFn>,
-                                                             Iterator,
-                                                             typename DFn::value_type,
-                                                             use_default,
-                                                             typename DFn::reference,
-                                                             use_default> {
+class dereference_iterator_adaptor :
+    public iterator_adaptor<
+        dereference_iterator_adaptor<Iterator,DFn>, //Derived
+        Iterator,   //Base
+        typename DFn::value_type, //Value
+        use_default, //CategoryOrTraversal
+        typename DFn::reference, //Reference
+        use_default //Difference
+        >
+{
     DFn _deref_fn;
 public:
-    typedef iterator_adaptor<dereference_iterator_adaptor<Iterator,DFn>,
-                                    Iterator,
-                                    typename DFn::value_type,
-                                    use_default,
-                                    typename DFn::reference,
-                                    use_default> parent_t;
-    typedef typename DFn::result_type                         reference;
-    typedef typename std::iterator_traits<Iterator>::difference_type difference_type;
-    typedef DFn                                               dereference_fn;
+    typedef iterator_adaptor<
+        dereference_iterator_adaptor<Iterator,DFn>,
+        Iterator,
+        typename DFn::value_type,
+        use_default,
+        typename DFn::reference,
+        use_default>
+    parent_t;
 
+    typedef typename DFn::reference            reference;
+    typedef typename parent_t::difference_type difference_type;
+    typedef DFn                                dereference_fn;
+
     dereference_iterator_adaptor() {}
-    template <typename Iterator1> 
-    dereference_iterator_adaptor(const dereference_iterator_adaptor<Iterator1,DFn>& dit) : parent_t(dit.base()), _deref_fn(dit._deref_fn) {}
-    dereference_iterator_adaptor(Iterator it, DFn deref_fn=DFn()) : parent_t(it), _deref_fn(deref_fn) {}
-    template <typename Iterator1, typename DFn1> 
-    dereference_iterator_adaptor(const dereference_iterator_adaptor<Iterator1,DFn1>& it) : parent_t(it.base()), _deref_fn(it._deref_fn) {}
-    /// For some reason operator[] provided by iterator_facade returns a custom class that is convertible to reference
+    template <typename Iterator1>
+    dereference_iterator_adaptor(const dereference_iterator_adaptor<Iterator1,DFn>& dit)
+        : parent_t(dit.base()), _deref_fn(dit._deref_fn)
+    {}
+    dereference_iterator_adaptor(Iterator it, DFn deref_fn=DFn())
+        : parent_t(it), _deref_fn(deref_fn)
+    {}
+    template <typename Iterator1, typename DFn1>
+    dereference_iterator_adaptor(const dereference_iterator_adaptor<Iterator1,DFn1>& it)
+    : parent_t(it.base()), _deref_fn(it._deref_fn)
+    {}
+
+    /// For some reason operator[] provided by iterator_facade returns a custom
+    /// class that is convertible to reference
     /// We require our own reference because it is registered in iterator_traits
     reference operator[](difference_type d) const { return *(*this+d);}
 
@@ -82,19 +97,21 @@
     const Iterator& base() const  { return this->base_reference(); }
     const DFn& deref_fn() const { return _deref_fn; }
 private:
-    template <typename Iterator1, typename DFn1> 
+    template <typename Iterator1, typename DFn1>
     friend class dereference_iterator_adaptor;
     friend class boost::iterator_core_access;
 
-    reference dereference() const { return _deref_fn(*(this->base_reference())); }
+    reference dereference() const {
+        return _deref_fn(*(this->base_reference()));
+    }
 };
 
-template <typename I, typename DFn> 
-struct const_iterator_type<dereference_iterator_adaptor<I,DFn> > { 
-    typedef dereference_iterator_adaptor<typename const_iterator_type<I>::type,typename DFn::const_t> type; 
+template <typename I, typename DFn>
+struct const_iterator_type<dereference_iterator_adaptor<I,DFn> > {
+    typedef dereference_iterator_adaptor<typename const_iterator_type<I>::type,typename DFn::const_t> type;
 };
 
-template <typename I, typename DFn> 
+template <typename I, typename DFn>
 struct iterator_is_mutable<dereference_iterator_adaptor<I,DFn> > : public mpl::bool_<DFn::is_mutable> {};
 
 
@@ -136,37 +153,42 @@
 struct byte_to_memunit<dereference_iterator_adaptor<Iterator,DFn> > : public byte_to_memunit<Iterator> {};
 
 template <typename Iterator, typename DFn>
-inline typename std::iterator_traits<Iterator>::difference_type 
-memunit_step(const dereference_iterator_adaptor<Iterator,DFn>& p) { 
+inline typename std::iterator_traits<Iterator>::difference_type
+memunit_step(const dereference_iterator_adaptor<Iterator,DFn>& p) {
     return memunit_step(p.base());
 }
 
 template <typename Iterator, typename DFn>
-inline typename std::iterator_traits<Iterator>::difference_type 
-memunit_distance(const dereference_iterator_adaptor<Iterator,DFn>& p1, 
-              const dereference_iterator_adaptor<Iterator,DFn>& p2) { 
-    return memunit_distance(p1.base(),p2.base()); 
+inline typename std::iterator_traits<Iterator>::difference_type
+memunit_distance(const dereference_iterator_adaptor<Iterator,DFn>& p1,
+              const dereference_iterator_adaptor<Iterator,DFn>& p2) {
+    return memunit_distance(p1.base(),p2.base());
 }
 
 template <typename Iterator, typename DFn>
-inline void memunit_advance(dereference_iterator_adaptor<Iterator,DFn>& p, 
-                         typename std::iterator_traits<Iterator>::difference_type diff) { 
+inline void memunit_advance(dereference_iterator_adaptor<Iterator,DFn>& p,
+                         typename std::iterator_traits<Iterator>::difference_type diff) {
     memunit_advance(p.base(), diff);
 }
 
 template <typename Iterator, typename DFn>
-inline dereference_iterator_adaptor<Iterator,DFn> 
-memunit_advanced(const dereference_iterator_adaptor<Iterator,DFn>& p, 
-              typename std::iterator_traits<Iterator>::difference_type diff) { 
-    return dereference_iterator_adaptor<Iterator,DFn>(memunit_advanced(p.base(), diff), p.deref_fn()); 
+inline dereference_iterator_adaptor<Iterator,DFn>
+memunit_advanced(const dereference_iterator_adaptor<Iterator,DFn>& p,
+              typename std::iterator_traits<Iterator>::difference_type diff)
+{
+    return dereference_iterator_adaptor<Iterator,DFn>(
+              memunit_advanced(p.base(), diff),
+              p.deref_fn()
+              );
 }
 
 
 template <typename Iterator, typename DFn>
-inline 
-typename std::iterator_traits<dereference_iterator_adaptor<Iterator,DFn> >::reference 
-memunit_advanced_ref(const dereference_iterator_adaptor<Iterator,DFn>& p, 
-                  typename std::iterator_traits<Iterator>::difference_type diff) { 
+inline
+typename std::iterator_traits<dereference_iterator_adaptor<Iterator,DFn> >::reference
+memunit_advanced_ref(const dereference_iterator_adaptor<Iterator,DFn>& p,
+                  typename std::iterator_traits<Iterator>::difference_type diff)
+{
     return *memunit_advanced(p, diff);
 }
 
@@ -198,8 +220,8 @@
 
     typedef dereference_iterator_adaptor<Iterator, deref_compose<Deref,PREV_DEREF> > type;
 
-    static type make(const dereference_iterator_adaptor<Iterator, PREV_DEREF>& it, const Deref& d) { 
-        return type(it.base(),deref_compose<Deref,PREV_DEREF>(d,it.deref_fn())); 
+    static type make(const dereference_iterator_adaptor<Iterator, PREV_DEREF>& it, const Deref& d) {
+        return type(it.base(),deref_compose<Deref,PREV_DEREF>(d,it.deref_fn()));
     }
 };
 
