public static <T extends ImageInterleaved<T>> T createSubImageOf_I(T input) { // create the larger image T ret = (T) input.createNew(input.width + 10, input.height + 12); // create a sub-image of the inner portion ret = (T) ret.subimage(5, 7, input.width + 5, input.height + 7, null); // copy input image into the subimage ret.setTo(input); return ret; }
/** * 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()); } }