Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84040 - trunk/boost/gil
From: chhenning_at_[hidden]
Date: 2013-04-24 20:12:56


Author: chhenning
Date: 2013-04-24 20:12:55 EDT (Wed, 24 Apr 2013)
New Revision: 84040
URL: http://svn.boost.org/trac/boost/changeset/84040

Log:
Fix for reusing memory when recreating an image.
Text files modified:
   trunk/boost/gil/image.hpp | 28 ++++++++++++++++++++++++++--
   1 files changed, 26 insertions(+), 2 deletions(-)

Modified: trunk/boost/gil/image.hpp
==============================================================================
--- trunk/boost/gil/image.hpp (original)
+++ trunk/boost/gil/image.hpp 2013-04-24 20:12:55 EDT (Wed, 24 Apr 2013)
@@ -145,15 +145,39 @@
         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) {
+ void recreate(const point_t& dims, std::size_t alignment=0, const Alloc alloc_in = Alloc())
+ {
+ if( dims == _view.dimensions() && _align_in_bytes == alignment )
+ {
+ return;
+ }
+
+ std::size_t old_size = total_allocated_size_in_bytes( _view.dimensions() );
+ std::size_t new_size = total_allocated_size_in_bytes( dims );
+
+ if( old_size >= new_size )
+ {
+ destruct_pixels( _view );
+
+ _view = view_t( point_t( width, height )
+ , typename view_t::locator( typename view_t::x_iterator( _memory )
+ , get_row_size_in_memunits( width )
+ )
+ );
+
+ default_construct_pixels( _view );
+ }
+ else
+ {
             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(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) {


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