/** * Creates a new image with all of its parameters initialized, including the * data array. * * @param width Image's width. * @param height Image's height. * @param numBands Number of bands/colors. */ protected ImageInterleaved(int width, int height, int numBands) { _setData(Array.newInstance(getPrimitiveDataType(), width * height * numBands)); this.startIndex = 0; this.stride = width * numBands; this.numBands = numBands; this.width = width; this.height = height; this.imageType.numBands = numBands; }
/** * Creates a sub-image from 'this' image. The subimage will share the same internal array * that stores each pixel's value, but will only pertain to an axis-aligned rectangular segment * of the original. * * * @param x0 x-coordinate of top-left corner of the sub-image. * @param y0 y-coordinate of top-left corner of the sub-image. * @param x1 x-coordinate of bottom-right corner of the sub-image. * @param y1 y-coordinate of bottom-right corner of the sub-image. * @param subimage * @return A sub-image of this image. */ @Override public T subimage(int x0, int y0, int x1, int y1, T subimage) { T ret = createNew(-1, -1); ret._setData(_getData()); ret.stride = Math.max(width * numBands, stride); // ok why is this done?!?! Shouldn't it always be stride? ret.width = x1 - x0; ret.height = y1 - y0; ret.numBands = numBands; ret.startIndex = startIndex + y0 * stride + x0 * numBands; ret.subImage = true; ret.imageType = imageType; return ret; }
@Override public void reshape(int width, int height) { if( this.width == width && this.height == height ) return; if( isSubimage() ) throw new IllegalArgumentException("Can't reshape sub-images"); Object data = _getData(); if( Array.getLength(data) < width*height*numBands ) { ImageInterleaved<?> a = createNew(width,height); _setData(a._getData()); } this.width = width; this.height = height; this.stride = width*numBands; }
@Override public final void setNumberOfBands(int numBands) { if( this.numBands == numBands ) return; if( isSubimage() ) throw new IllegalArgumentException("Can't reshape sub-images"); this.imageType.numBands = numBands; this.numBands = numBands; this.stride = width*numBands; Object data = _getData(); if( data == null || Array.getLength(data) < width*height*numBands ) { ImageInterleaved<?> a = createNew(width,height); _setData(a._getData()); } }