/** * Sets this image equal to the specified image. Automatically resized to match the input image. * * @param orig The original image whose value is to be copied into this one */ @SuppressWarnings({"SuspiciousSystemArraycopy"}) @Override public void setTo(T orig) { if (orig.width != width || orig.height != height || orig.numBands != numBands ) reshape(orig.width,orig.height,orig.numBands); if (!orig.isSubimage() && !isSubimage()) { System.arraycopy(orig._getData(), orig.startIndex, _getData(), startIndex, stride * height); } else { int indexSrc = orig.startIndex; int indexDst = startIndex; for (int y = 0; y < height; y++) { System.arraycopy(orig._getData(), indexSrc, _getData(), indexDst, width * numBands); indexSrc += orig.stride; indexDst += stride; } } }
@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()); } }
/** * 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; }