public void setSize(int width, int height) {
        if (width < 0 || height < 0
                || width > RASTER_MAX_WIDTH || height > RASTER_MAX_HEIGHT) {
            // Invalid width or height.
            throw new ExceptionInvalidParam();
        } else if (width == 0 || height == 0) {
            // An empty noise map was specified.  Delete it and zero out the size
            // member variables.
            deleteNoiseMapAndReset();
        } else {
            // A new noise map size was specified.  Allocate a new noise map buffer
            // unless the current buffer is large enough for the new noise map (we
            // don't want costly reallocations going on.)
            long newMemUsage = calcMinMemUsage(width, height);
            if (memUsed < newMemUsage) {
                // The new size is too big for the current noise map buffer.  We need to
                // reallocate.
                deleteNoiseMapAndReset();
                try {
                    noiseMap = new float[(int) newMemUsage];
                } catch (Exception e) {
                    throw new ExceptionOutOfMemory();
                }
                memUsed = newMemUsage;
            }
            stride = (int) calcStride(width);
            this.width = width;
            this.height = height;
        }
    }