public synchronized void readBandData( Band destBand, int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, int sourceStepX, int sourceStepY, ProductData destBuffer, ProgressMonitor pm) throws IOException, InvalidRangeException { if (mustFlipY) { sourceOffsetY = destBand.getSceneRasterHeight() - (sourceOffsetY + sourceHeight); } if (mustFlipX) { sourceOffsetX = destBand.getSceneRasterWidth() - (sourceOffsetX + sourceWidth); } sourceOffsetY += leadLineSkip; start[0] = sourceOffsetY; start[1] = sourceOffsetX; stride[0] = sourceStepY; stride[1] = sourceStepX; count[0] = sourceHeight; count[1] = sourceWidth; Object buffer = destBuffer.getElems(); Variable variable = variableMap.get(destBand); pm.beginTask("Reading band '" + variable.getShortName() + "'...", sourceHeight); try { Section section = new Section(start, count, stride); Array array; int[] newshape = {sourceHeight, sourceWidth}; array = variable.read(section); if (array.getRank() == 3) { array = array.reshapeNoCopy(newshape); } Object storage; if (mustFlipX && !mustFlipY) { storage = array.flip(1).copyTo1DJavaArray(); } else if (!mustFlipX && mustFlipY) { storage = array.flip(0).copyTo1DJavaArray(); } else if (mustFlipX && mustFlipY) { storage = array.flip(0).flip(1).copyTo1DJavaArray(); } else { storage = array.copyTo1DJavaArray(); } arraycopy(storage, 0, buffer, 0, destBuffer.getNumElems()); } finally { pm.done(); } }
private void checkBufferSize(int sourceWidth, int sourceHeight, ProductData sourceBuffer) { int expectedBufferSize = sourceWidth * sourceHeight; int actualBufferSize = sourceBuffer.getNumElems(); Guardian.assertEquals("wrong sourceBuffer size", actualBufferSize, expectedBufferSize); }