public static RenderedImage resize(RenderedImage sourceImage, float rescaleXfactor, float rescaleYfactor, Interpolation interp) { return ScaleDescriptor.create(sourceImage, rescaleXfactor, rescaleYfactor, 0.0f, 0.0f, interp, null); } }
public static BufferedImage resize(BufferedImage sourceImage, float rescaleXfactor, float rescaleYfactor, Interpolation interp) { return ScaleDescriptor.create(sourceImage, rescaleXfactor, rescaleYfactor, 0.0f, 0.0f, interp, null).getAsBufferedImage(); }
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); }
@Override protected PlanarImage execute (ScaleOp operation, final EditableImage image, PlanarImage planarImage) { RenderingHints hints = null; // FIXME Interpolation interpolation = Interpolation.getInstance(Interpolation.INTERP_BILINEAR); log.warn(">>>> ScaleJAIOp is not optimized"); log.debug(">>>> interpolation: {}", interpolation); double xScale = operation.getXScale(); double yScale = operation.getYScale(); planarImage = ScaleDescriptor.create(planarImage, new Float(xScale), new Float(yScale), new Float(0), new Float(0), interpolation, hints); JAIUtils.logImage(log, ">>>> ScaleJAIOp returning", planarImage); return planarImage; } }
/******************************************************************************* * * @inheritDoc * ******************************************************************************/ protected PlanarImage execute (ScaleOp operation, final EditableImage image, PlanarImage planarImage) { RenderingHints hints = null; // FIXME Interpolation interpolation = Interpolation.getInstance(Interpolation.INTERP_BILINEAR); logger.warning(">>>> ScaleJAIOp is not optimized"); logger.finer(">>>> interpolation: " + interpolation); double xScale = operation.getXScale(); double yScale = operation.getYScale(); planarImage = ScaleDescriptor.create(planarImage, new Float(xScale), new Float(yScale), new Float(0), new Float(0), interpolation, hints); JAIUtils.logImage(logger, ">>>> ScaleJAIOp returning", planarImage); return planarImage; } }
newHints.add(new RenderingHints(JAI.KEY_BORDER_EXTENDER, borderExtender)); return ScaleDescriptor.create(src, Float.valueOf(1.0f/downsampleStep), Float.valueOf(1.0f/downsampleStep),
@Override protected Image doInBackground() throws Exception { RenderedImage sourceImage = FileLoadDescriptor.create(imageFilePath, null, true, null); int width = sourceImage.getWidth(); int height = sourceImage.getHeight(); float scale = (float) (targetDimension.getWidth() / width); scale = (float) Math.min(scale, targetDimension.getHeight() / height); if (scale > 1) { scale = 1.0f; } Interpolation interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST); RenderedImage scaledImage = ScaleDescriptor.create(sourceImage, scale, scale, 0.0f, 0.0f, interpolation, null); PlanarImage planarImage = PlanarImage.wrapRenderedImage(scaledImage); BufferedImage bufferedImage = planarImage.getAsBufferedImage(); planarImage.dispose(); return bufferedImage; }
@Override protected Image doInBackground() throws Exception { RenderedImage sourceImage = FileLoadDescriptor.create(imageFilePath, null, true, null); int width = sourceImage.getWidth(); int height = sourceImage.getHeight(); float scale = (float) (targetDimension.getWidth() / width); scale = (float) Math.min(scale, targetDimension.getHeight() / height); if (scale > 1) { scale = 1.0f; } Interpolation interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST); RenderedImage scaledImage = ScaleDescriptor.create(sourceImage, scale, scale, 0.0f, 0.0f, interpolation, null); PlanarImage planarImage = PlanarImage.wrapRenderedImage(scaledImage); BufferedImage bufferedImage = planarImage.getAsBufferedImage(); planarImage.dispose(); return bufferedImage; }
result = ScaleDescriptor.create(source, fScale, fScale, fZero, fZero, interpolation, hints); logImage(logger, ">>>>>>>> planarImage", result);
result = ScaleDescriptor.create(source, fScale, fScale, fZero, fZero, interpolation, hints); logImage(log, ">>>>>>>> planarImage", result);
Interpolation interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST); logger.finer(">>>>>>>> Scale(" + scale + ", " + interpolation + ")"); result = ScaleDescriptor.create(result, fScale, fScale, ZERO, ZERO, interpolation, hints); break; result = ScaleDescriptor.create(result, fScale, fScale, ZERO, ZERO, interpolation, hints); result = ScaleDescriptor.create(result, fScale, fScale, ZERO, ZERO, interpolation, hints);
Interpolation interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST); log.debug(">>>>>>>> Scale({}, {})", scale, interpolation); result = ScaleDescriptor.create(result, fScale, fScale, ZERO, ZERO, interpolation, hints); break; result = ScaleDescriptor.create(result, fScale, fScale, ZERO, ZERO, interpolation, hints); result = ScaleDescriptor.create(result, fScale, fScale, ZERO, ZERO, interpolation, hints);
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); }
image = ScaleDescriptor.create(source, 1.0f, 1.0f, (float) Math.round(tx.getTranslateX()), (float) Math.round(tx.getTranslateY()), interpolation, localHints); } else { image = ScaleDescriptor.create(source, (float) tx.getScaleX(), (float) tx.getScaleY(), (float) tx.getTranslateX(), (float) tx.getTranslateY(), interpolation, commonHints);
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; }
protected void readMasks() { File file; if (metadata != null) { try { String maskFileName = metadata.getMaskFileName(); if (maskFileName != null) { file = productDirectory.getFile(maskFileName); if (file != null && file.exists()) { GeoTiffProductReader reader = new GeoTiffProductReader(getReaderPlugIn()); Product udmProduct = reader.readProductNodes(file, null); Band srcBand = udmProduct.getBandAt(0); float scaleX = (float)metadata.getRasterWidth() / (float)udmProduct.getSceneRasterWidth(); float scaleY = (float)metadata.getRasterHeight() / (float)udmProduct.getSceneRasterHeight(); RenderedOp renderedOp = ScaleDescriptor.create(srcBand.getSourceImage(), scaleX, scaleY, 0.0f, 0.0f, Interpolation.getInstance(Interpolation.INTERP_NEAREST), null); Band targetBand = product.addBand("unusable_data", srcBand.getDataType()); targetBand.setSourceImage(renderedOp); FlagCoding cloudsFlagCoding = createFlagCoding(product); targetBand.setSampleCoding(cloudsFlagCoding); List<Mask> cloudsMasks = createMasksFromFlagCodding(product, cloudsFlagCoding); for (Mask mask : cloudsMasks) { product.getMaskGroup().add(mask); } } } } catch (IOException e) { logger.warning(e.getMessage()); } } }
@Override protected RenderedImage createImage(int level) { RasterDataNode rdn = getRasterDataNode(); NetcdfFile lock = ctx.getNetcdfFile(); final Object object = ctx.getProperty(Constants.Y_FLIPPED_PROPERTY_NAME); boolean isYFlipped = object instanceof Boolean && (Boolean) object; int dataBufferType = ImageManager.getDataBufferType(rdn.getDataType()); int sourceWidth = (int) (rdn.getSceneRasterWidth() / scaleFactor); int sourceHeight = (int) (rdn.getSceneRasterHeight() / scaleFactor); ResolutionLevel resolutionLevel = ResolutionLevel.create(getModel(), level); Dimension imageTileSize = new Dimension(getTileWidth(), getTileHeight()); RenderedImage netcdfImg; if (variable.getDataType() == DataType.LONG) { if (rdn.getName().endsWith("_lsb")) { netcdfImg = NetcdfOpImage.createLsbImage(variable, imageOrigin, isYFlipped, lock, dataBufferType, sourceWidth, sourceHeight, imageTileSize, resolutionLevel); } else { netcdfImg = NetcdfOpImage.createMsbImage(variable, imageOrigin, isYFlipped, lock, dataBufferType, sourceWidth, sourceHeight, imageTileSize, resolutionLevel); } } else { netcdfImg = new NetcdfOpImage(variable, imageOrigin, isYFlipped, lock, dataBufferType, sourceWidth, sourceHeight, imageTileSize, resolutionLevel); } return ScaleDescriptor.create(netcdfImg, scaleFactor, scaleFactor, 0.5f, 0.5f, Interpolation.getInstance(Interpolation.INTERP_NEAREST), null); } }