Beispiel #1
0
void Image<T>::resize(const Bounds<int>& new_bounds) 
{
    if (!new_bounds.isDefined()) {
        // Then this is really a deallocation.  Clear out the existing memory.
        this->_owner.reset();
        this->_data = 0;
        this->_stride = 0;
    } else if (this->_bounds.isDefined() && 
               this->_bounds.area() <= new_bounds.area() && 
               this->_owner.unique()) {
        // Then safe to keep existing memory allocation.
        // Just redefine the bounds and stride.
        this->_stride = new_bounds.getXMax() - new_bounds.getXMin() + 1;
    } else {
        // Then we want to do the reallocation.
        this->_bounds = new_bounds;
        this->allocateMem();
    }
}