private static RenderedImage getSourceImage(ProductSubsetDef subsetDef, Band band) { RenderedImage sourceImage = band.getSourceImage(); if (subsetDef != null) { final Rectangle region = subsetDef.getRegion(); if (region != null) { float x = region.x; float y = region.y; float width = region.width; float height = region.height; sourceImage = CropDescriptor.create(sourceImage, x, y, width, height, null); } final int subSamplingX = subsetDef.getSubSamplingX(); final int subSamplingY = subsetDef.getSubSamplingY(); if (mustSubSample(subSamplingX, subSamplingY) || mustTranslate(region)) { float scaleX = 1.0f / subSamplingX; float scaleY = 1.0f / subSamplingY; float transX = region != null ? -region.x : 0; float transY = region != null ? -region.y : 0; Interpolation interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST); sourceImage = ScaleDescriptor.create(sourceImage, scaleX, scaleY, transX, transY, interpolation, null); } } return sourceImage; }