private static RenderedOp createScaledImage(int targetWidth, int targetHeight, int sourceWidth, int sourceHeight, RenderedImage srcImg, RenderingHints renderingHints) { float xScale = (float) targetWidth / (float) sourceWidth; float yScale = (float) targetHeight / (float) sourceHeight; RenderedOp tempImg = ScaleDescriptor.create(srcImg, xScale, yScale, 0.5f, 0.5f, Interpolation.getInstance(Interpolation.INTERP_NEAREST), renderingHints); return CropDescriptor.create(tempImg, 0f, 0f, (float) targetWidth, (float) targetHeight, renderingHints); }
CropDescriptor.create( metaTileImage, Float.valueOf(minX),
int y = (tileSize * (metaFactor - 1)) - (i * tileSize); tile = CropDescriptor.create(metaTile, new Float(x), new Float( y), new Float(tileSize), new Float(tileSize), no_cache); tiles[(i * key.getMetaFactor()) + j] = tile;
/** * The origin of planarImage and sceneLayout must be the same. * Compute the number of the pixels needed to cover the scene and remove the rows and columns outside the scene in planarImage. * @param planarImage * @param resX * @param resY * @param sceneLayout * @return */ public static PlanarImage cropBordersOutsideScene (PlanarImage planarImage, float resX, float resY, S2OrthoSceneLayout sceneLayout) { int sceneHeight = 0; int sceneWidth = 0; if(sceneLayout.sceneDimensions.size()<=0) { return planarImage; } for(S2SpatialResolution resolution : S2SpatialResolution.values()) { if (sceneLayout.sceneDimensions.get(resolution) != null) { sceneHeight = sceneLayout.getSceneDimension(resolution).height*resolution.resolution; sceneWidth = sceneLayout.getSceneDimension(resolution).width*resolution.resolution; break; } } int rowNumber = (int) Math.ceil(sceneHeight/resY); int colNumber = (int) Math.ceil(sceneWidth/resX); planarImage = CropDescriptor.create(planarImage, planarImage.getMinX() + 0.0f, planarImage.getMinY() + 0.0f, (float) colNumber, (float) rowNumber, null); return planarImage; }
private RenderedImage crop(RenderedImage source, Rectangle cropArea) { ImageLayout layout = new ImageLayout(); layout.setMinX(cropArea.x); layout.setMinY(cropArea.y); layout.setWidth(cropArea.width); layout.setHeight(cropArea.height); return CropDescriptor.create(source, (float) cropArea.getX(), (float) cropArea.getY(), (float) cropArea.getWidth(), (float) cropArea.getHeight(), new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout)).getRendering(); }
private static RenderedOp createScaledImage(int targetWidth, int targetHeight, int sourceWidth, int sourceHeight, int sourceSampling, ProductData data, Dimension tileSize) { int tempW = sourceWidth * sourceSampling + 1; int tempH = sourceHeight * sourceSampling + 1; float xScale = (float) tempW / (float) sourceWidth; float yScale = (float) tempH / (float) sourceHeight; RenderingHints renderingHints = new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(BorderExtender.BORDER_COPY)); RenderedImage srcImg = ImageUtils.createRenderedImage(sourceWidth, sourceHeight, data); ImageLayout imageLayout = new ImageLayout(0, 0, targetWidth, targetHeight, 0, 0, tileSize.width, tileSize.height, null, null); renderingHints.put(JAI.KEY_IMAGE_LAYOUT, imageLayout); RenderedOp tempImg = ScaleDescriptor.create(srcImg, xScale, yScale, -0.5f * sourceSampling + 1, -0.5f * sourceSampling + 1, Interpolation.getInstance(Interpolation.INTERP_BILINEAR), renderingHints); return CropDescriptor.create(tempImg, 0f, 0f, (float) targetWidth, (float) targetHeight, null); }
getModel().getScale(level)); RenderedOp croppedMosaic = CropDescriptor.create(mosaicOp, 0.0f, 0.0f, (float) bandRectangle.width, (float) bandRectangle.height, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, imageLayout));
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; }
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; }
getModel().getScale(level)); RenderedOp croppedMosaic = CropDescriptor.create(mosaicOp, 0.0f, 0.0f, (float) bandRectangle.width, (float) bandRectangle.height, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, imageLayout));
imageCrop = javax.media.jai.operator.CropDescriptor.create(image, cropX, cropY, cropWidth, cropHeight, null); } else {
planarImage = CropDescriptor.create(planarImage, planarImage.getMinX() + 0.0f, planarImage.getMinY() + 1.0f, (float) planarImage.getWidth(), (float) planarImage.getHeight()-1, null); planarImage = CropDescriptor.create(planarImage, planarImage.getMinX() + 0.0f, planarImage.getMinY() + 0.0f, (float) planarImage.getWidth(), (float) planarImage.getHeight()-1, null); planarImage = CropDescriptor.create(planarImage, planarImage.getMinX() + 1.0f, planarImage.getMinY() + 0.0f, (float) planarImage.getWidth()-1, (float) planarImage.getHeight(), null); planarImage = CropDescriptor.create(planarImage, planarImage.getMinX() + 0.0f, planarImage.getMinY() + 0.0f, (float) planarImage.getWidth()-1, (float) planarImage.getHeight(), null);
@Test public void testThatImageMinXYAreImportant() throws Exception { int minX = 4; int minY = 3; final RenderedOp src = ConstantDescriptor.create(16F, 16F, new Short[]{(short) 33}, null); final RenderedOp dst = CropDescriptor.create(src, (float) minX, (float) minY, 8F, 8F, null); assertEquals(minX, dst.getMinX()); assertEquals(minY, dst.getMinY()); // Test that we have to use the min X and Y try { dst.getData(new Rectangle(0, 0, 1, 1)); fail("IllegalArgumentException thrown by JAI expected"); } catch (IllegalArgumentException e) { // ok } final Raster data = dst.getData(new Rectangle(minX, minY, 1, 1)); final short[] outData = new short[1]; // Test that we have to use the min X and Y try { data.getDataElements(0, 0, outData); fail("ArrayIndexOutOfBoundsException thrown by AWT expected"); } catch (ArrayIndexOutOfBoundsException e) { // ok } data.getDataElements(minX, minY, outData); assertEquals(33, outData[0]); // In many cases, we use the tile rectangles in order to retrieve pixel data // So make sure it also considers the min X and Y assertEquals(new Rectangle(minX, minY, 8, 8), dst.getTileRect(0, 0)); }