Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65909 - branches/release/boost/gil
From: chhenning_at_[hidden]
Date: 2010-10-11 11:54:52


Author: chhenning
Date: 2010-10-11 11:54:49 EDT (Mon, 11 Oct 2010)
New Revision: 65909
URL: http://svn.boost.org/trac/boost/changeset/65909

Log:
Allow for image creating with non-pixel types, like int or float, that satisfy the regular type concept.
Text files modified:
   branches/release/boost/gil/image.hpp | 19 +++++++++++++++----
   1 files changed, 15 insertions(+), 4 deletions(-)

Modified: branches/release/boost/gil/image.hpp
==============================================================================
--- branches/release/boost/gil/image.hpp (original)
+++ branches/release/boost/gil/image.hpp 2010-10-11 11:54:49 EDT (Mon, 11 Oct 2010)
@@ -47,7 +47,7 @@
 ///
 ////////////////////////////////////////////////////////////////////////////////////////
 
-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;
@@ -194,13 +194,24 @@
     }
 
     std::size_t total_allocated_size_in_bytes(const point_t& dimensions) const {
+
+ typedef typename view_t::x_iterator x_iterator;
+
+ // when value_type is a non-pixel, like int or float, num_channels< ... > doesn't work.
+ const std::size_t _channels_in_image = mpl::eval_if< is_pixel< value_type >
+ , num_channels< view_t >
+ , mpl::int_< 1 >
+ >::type::value;
+
         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;
+ size_in_units = size_in_units * _channels_in_image ;
 
         // 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


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk