Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84600 - trunk/boost/gil
From: chhenning_at_[hidden]
Date: 2013-06-01 11:05:24


Author: chhenning
Date: 2013-06-01 11:05:23 EDT (Sat, 01 Jun 2013)
New Revision: 84600
URL: http://svn.boost.org/trac/boost/changeset/84600

Log:
Fixing image recreate.
Text files modified:
   trunk/boost/gil/image.hpp | 128 ++++++++++++++++++++++++++++++++-------
   1 files changed, 103 insertions(+), 25 deletions(-)

Modified: trunk/boost/gil/image.hpp
==============================================================================
--- trunk/boost/gil/image.hpp (original)
+++ trunk/boost/gil/image.hpp 2013-06-01 11:05:23 EDT (Sat, 01 Jun 2013)
@@ -96,7 +96,7 @@
     }
     image(x_coord_t width, y_coord_t height,
           const Pixel& p_in,
- std::size_t alignment,
+ std::size_t alignment = 0,
           const Alloc alloc_in = Alloc()) : _memory(0), _align_in_bytes(alignment), _alloc(alloc_in)
                                            , _allocated_bytes ( 0 ) {
         allocate_and_fill(point_t(width,height),p_in);
@@ -151,7 +151,78 @@
         swap(_allocated_bytes, img._allocated_bytes );
     }
 
- void recreate(const point_t& dims, std::size_t alignment=0, const Alloc alloc_in = Alloc())
+ /////////////////////
+ // recreate
+ /////////////////////
+
+ // without Allocator
+
+ void recreate( const point_t& dims, std::size_t alignment = 0 )
+ {
+ if( dims == _view.dimensions() && _align_in_bytes == alignment )
+ {
+ return;
+ }
+
+ _align_in_bytes = alignment;
+
+ if( _allocated_bytes >= total_allocated_size_in_bytes( dims ) )
+ {
+ destruct_pixels( _view );
+
+ create_view( dims
+ , typename boost::conditional< IsPlanar, mpl::true_, mpl::false_ >::type()
+ );
+
+ default_construct_pixels( _view );
+ }
+ else
+ {
+ image tmp( dims, alignment );
+ swap( tmp );
+ }
+ }
+
+ void recreate( x_coord_t width, y_coord_t height, std::size_t alignment = 0 )
+ {
+ recreate( point_t( width, height ), alignment );
+ }
+
+
+ void recreate( const point_t& dims, const Pixel& p_in, std::size_t alignment = 0 )
+ {
+ if( dims == _view.dimensions() && _align_in_bytes == alignment )
+ {
+ return;
+ }
+
+ _align_in_bytes = alignment;
+
+ if( _allocated_bytes >= total_allocated_size_in_bytes( dims ) )
+ {
+ destruct_pixels( _view );
+
+ create_view( dims
+ , typename boost::conditional< IsPlanar, mpl::true_, mpl::false_ >::type()
+ );
+
+ uninitialized_fill_pixels(_view, p_in);
+ }
+ else
+ {
+ image tmp( dims, p_in, alignment );
+ swap( tmp );
+ }
+ }
+
+ void recreate( x_coord_t width, y_coord_t height, const Pixel& p_in, std::size_t alignment = 0 )
+ {
+ recreate( point_t( width, height ), p_in, alignment );
+ }
+
+
+ // with Allocator
+ void recreate(const point_t& dims, std::size_t alignment, const Alloc alloc_in )
     {
         if( dims == _view.dimensions()
           && _align_in_bytes == alignment
@@ -161,10 +232,9 @@
             return;
         }
 
- if( _allocated_bytes >= total_allocated_size_in_bytes( dims )
- && _align_in_bytes == alignment
- && alloc_in == _alloc
- )
+ _align_in_bytes = alignment;
+
+ if( _allocated_bytes >= total_allocated_size_in_bytes( dims ) )
         {
             destruct_pixels( _view );
 
@@ -176,17 +246,17 @@
         }
         else
         {
- image tmp(dims, alignment, alloc_in);
- swap(tmp);
+ image tmp( dims, alignment, alloc_in );
+ swap( tmp );
         }
     }
 
- 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( x_coord_t width, y_coord_t height, std::size_t alignment, const Alloc alloc_in )
+ {
+ recreate( point_t( width, height ), alignment, alloc_in );
     }
 
- void recreate(const point_t& dims,
- const Pixel& p_in, std::size_t alignment = 0, const Alloc alloc_in = Alloc())
+ void recreate(const point_t& dims, const Pixel& p_in, std::size_t alignment, const Alloc alloc_in )
     {
         if( dims == _view.dimensions()
           && _align_in_bytes == alignment
@@ -196,10 +266,9 @@
             return;
         }
 
- if( _allocated_bytes >= total_allocated_size_in_bytes( dims )
- && _align_in_bytes == alignment
- && alloc_in == _alloc
- )
+ _align_in_bytes = alignment;
+
+ if( _allocated_bytes >= total_allocated_size_in_bytes( dims ) )
         {
             destruct_pixels( _view );
 
@@ -211,16 +280,18 @@
         }
         else
         {
- image tmp(dims, p_in, alignment, alloc_in);
- swap(tmp);
+ image tmp( dims, p_in, alignment, alloc_in );
+ swap( tmp );
         }
     }
 
- void recreate(x_coord_t width, y_coord_t height,
- const Pixel& p_in, std::size_t alignment = 0, const Alloc alloc_in = Alloc()) {
- recreate(point_t(width,height),p_in,alignment,alloc_in);
+ void recreate(x_coord_t width, y_coord_t height, const Pixel& p_in, std::size_t alignment, const Alloc alloc_in )
+ {
+ recreate( point_t( width, height ), p_in,alignment, alloc_in );
     }
 
+
+
     view_t _view; // contains pointer to the pixels, the image size and ways to navigate pixels
 private:
     unsigned char* _memory;
@@ -338,8 +409,10 @@
         std::size_t row_size=get_row_size_in_memunits(dims.x);
         std::size_t plane_size=row_size*dims.y;
 
- unsigned char* tmp= ( _align_in_bytes > 0 ) ? (unsigned char*) align( (std::size_t) _memory,_align_in_bytes)
- : _memory;
+ unsigned char* tmp = ( _align_in_bytes > 0 ) ? (unsigned char*) align( (std::size_t) _memory
+ ,_align_in_bytes
+ )
+ : _memory;
         typename view_t::x_iterator first;
 
         for (int i = 0; i < num_channels< view_t >::value; ++i )
@@ -362,11 +435,16 @@
                     , mpl::false_ // is planar
                     )
     {
+ unsigned char* tmp = ( _align_in_bytes > 0 ) ? ( unsigned char* ) align( (std::size_t) _memory
+ , _align_in_bytes
+ )
+ : _memory;
+
         _view = view_t( dims
- , typename view_t::locator( typename view_t::x_iterator( _memory )
+ , typename view_t::locator( typename view_t::x_iterator( tmp )
                                                 , get_row_size_in_memunits( dims.x )
                                                 )
- );
+ );
     }
 };
 


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