Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64621 - trunk/boost/gil
From: chhenning_at_[hidden]
Date: 2010-08-05 14:41:02


Author: chhenning
Date: 2010-08-05 14:40:50 EDT (Thu, 05 Aug 2010)
New Revision: 64621
URL: http://svn.boost.org/trac/boost/changeset/64621

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

Modified: trunk/boost/gil/image.hpp
==============================================================================
--- trunk/boost/gil/image.hpp (original)
+++ trunk/boost/gil/image.hpp 2010-08-05 14:40:50 EDT (Thu, 05 Aug 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 >
+ >::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

Modified: trunk/boost/gil/pixel.hpp
==============================================================================
--- trunk/boost/gil/pixel.hpp (original)
+++ trunk/boost/gil/pixel.hpp 2010-08-05 14:40:50 EDT (Thu, 05 Aug 2010)
@@ -47,6 +47,8 @@
 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> {};
 template <typename PixelBased> struct channel_type<const PixelBased> : public channel_type<PixelBased> {};
+
+template <typename PixelBased> struct is_planar : mpl::false_ {};
 template <typename PixelBased> struct is_planar<const PixelBased> : public is_planar<PixelBased> {};
 
 


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