/** * For testing: returns the source image bounds. * * @param destRect * @param sourceIndex * @return */ @Override public Rectangle mapDestRect(Rectangle destRect, int sourceIndex) { return getSourceImage(sourceIndex).getBounds(); }
/** * Create a new instance of JiffleOpImage in the rendered layer. * * @param paramBlock specifies the source image and the parameters WRITE ME */ public RenderedImage create(ParameterBlock paramBlock, RenderingHints renderHints) { String script = (String) paramBlock.getObjectParameter(JiffleDescriptor.SCRIPT_ARG); String destVarName = (String) paramBlock.getObjectParameter(JiffleDescriptor.DEST_NAME_ARG); Rectangle destBounds = (Rectangle) paramBlock.getObjectParameter(JiffleDescriptor.DEST_BOUNDS_ARG); int dataType = paramBlock.getIntParameter(JiffleDescriptor.DEST_TYPE_ARG); // Build an image layout based on the destination bounds, if provided, or the union of the // source bounds ImageLayout layout = (ImageLayout) renderHints.get(JAI.KEY_IMAGE_LAYOUT); if (destBounds != null) { layout = buildLayout(destBounds, getPreferredTileSize(paramBlock), dataType); } else if (layout == null) { destBounds = getSourceBounds(paramBlock); layout = buildLayout(destBounds, getPreferredTileSize(paramBlock), dataType); } Map<String, JiffleOpImage.ImageSpecification> sourceImages = buildSourceImageMap(paramBlock); return new JiffleOpImage(sourceImages, layout, renderHints, script, destVarName); }
@Test public void testCopyNonDefaults() { RenderedImage src = buildTestImage(10, 10); RenderedOp op = JiffleDescriptor.create(new RenderedImage[] {src}, new String[] {"a"}, "b", "b = a;", null, DataBuffer.TYPE_BYTE, null, null, null); assertCopy(src, op, DataBuffer.TYPE_BYTE); }
@Test public void testSum() { RenderedImage src1 = buildTestImage(10, 10); RenderedImage src2 = buildTestImage(10, 10); RenderedOp op = JiffleDescriptor.create(new RenderedImage[] {src1, src2}, new String[] {"a", "b"}, "res", "res = a + b;", null, DataBuffer.TYPE_INT, null, null, null); // check same size and expected assertEquals(src1.getMinX(), op.getMinX()); assertEquals(src1.getWidth(), op.getWidth()); assertEquals(src1.getMinY(), op.getMinY()); assertEquals(src1.getHeight(), op.getHeight()); assertEquals(DataBuffer.TYPE_INT, op.getSampleModel().getDataType()); RandomIter srcIter = RandomIterFactory.create(src1, null); RandomIter opIter = RandomIterFactory.create(op, null); for(int y = src1.getMinY(); y < src1.getMinY() + src1.getHeight(); y++) { for(int x = src1.getMinX(); x < src1.getMinX() + src1.getWidth(); x++) { double expected = srcIter.getSampleDouble(x, y, 0) * 2; double actual = opIter.getSampleDouble(x, y, 0); assertEquals(expected, actual, 0d); } } }
/** * Registers the MaskedConvolve operation and its * associated image factories across all supported operation modes. * * @param registry The registry with which to register the operations * and their factories. */ public void updateRegistry(OperationRegistry registry) { OperationDescriptor op = new JiffleDescriptor(); registry.registerDescriptor(op); String descName = op.getName(); RenderedImageFactory rif = new JiffleRIF(); registry.registerFactory(RenderedRegistryMode.MODE_NAME, descName, productName, rif); } }
JiffleDescriptor.create( sources, sourceNames,
specsToImages(sourceImages), layout, configuration, setProperty(NoDataContainer.GC_NODATA, new NoDataContainer(Double.NaN));
private Rectangle getSourceBounds(ParameterBlock pb) { Rectangle boundsUnion = null; if (pb.getNumSources() > 0) { boundsUnion = getSourceBounds(pb, 0); for (int i = 1; i < pb.getNumSources(); i++) { Rectangle imageBounds = getSourceBounds(pb, i); boundsUnion = boundsUnion.union(imageBounds); } } return boundsUnion; }
private JiffleOpImage.ImageSpecification getImageSpecification( Vector<Object> sources, CoordinateTransform[] cts, BandTransform[] bts, int i) { RenderedImage image = (RenderedImage) sources.get(i); CoordinateTransform ct = null; if (cts != null) { if (cts.length != sources.size()) { throw new IllegalArgumentException( String.format( "Have %d sources, but the coordinate transformation argument contains %d entries instead" + sources.size() + cts.length)); } ct = cts[i]; } BandTransform bt = null; if (bts != null) { if (bts.length != sources.size()) { throw new IllegalArgumentException( String.format( "Have %d sources, but the band transformation argument contains %d entries instead" + sources.size() + bts.length)); } bt = bts[i]; } return new JiffleOpImage.ImageSpecification(image, ct, bt); }
for (int i = 0; i < sources.size(); i++) { if (i == 0) { result.put("src", getImageSpecification(sources, cts, bts, i)); } else { result.put("src" + i, getImageSpecification(sources, cts, bts, i)); result.put(names[i], getImageSpecification(sources, cts, bts, i));
@Test public void createSequentialImage() throws Exception { ParameterBlockJAI pb = new ParameterBlockJAI("Jiffle"); String script = "dest = y() * width() + x();" ; pb.setParameter("script", script); pb.setParameter("destName", "dest"); Rectangle bounds = new Rectangle(0, 0, WIDTH, WIDTH); pb.setParameter("destBounds", bounds); RenderedOp op = JAI.create("Jiffle", pb); RenderedImage result = op.getRendering(); assertResult(result, script); }
/** * Create a new instance of JiffleOpImage in the rendered layer. * * @param paramBlock specifies the source image and the parameters WRITE ME */ public RenderedImage create(ParameterBlock paramBlock, RenderingHints renderHints) { String script = (String) paramBlock.getObjectParameter(JiffleDescriptor.SCRIPT_ARG); String destVarName = (String) paramBlock.getObjectParameter(JiffleDescriptor.DEST_NAME_ARG); Rectangle destBounds = (Rectangle) paramBlock.getObjectParameter(JiffleDescriptor.DEST_BOUNDS_ARG); int dataType = paramBlock.getIntParameter(JiffleDescriptor.DEST_TYPE_ARG); // Build an image layout based on the destination bounds, if provided, or the union of the // source bounds ImageLayout layout = (ImageLayout) renderHints.get(JAI.KEY_IMAGE_LAYOUT); if (destBounds != null) { layout = buildLayout(destBounds, getPreferredTileSize(paramBlock), dataType); } else if (layout == null) { destBounds = getSourceBounds(paramBlock); layout = buildLayout(destBounds, getPreferredTileSize(paramBlock), dataType); } Map<String, JiffleOpImage.ImageSpecification> sourceImages = buildSourceImageMap(paramBlock); return new JiffleOpImage(sourceImages, layout, renderHints, script, destVarName); }
@Test public void testCopyDefaults() { RenderedImage src = buildTestImage(10, 10); RenderedOp op = JiffleDescriptor.create(new RenderedImage[] {src}, null, null, "dest = src;", null, null, null, null, null); assertCopy(src, op, DataBuffer.TYPE_DOUBLE); }
/** * Registers the MaskedConvolve operation and its * associated image factories across all supported operation modes. * * @param registry The registry with which to register the operations * and their factories. */ public void updateRegistry(OperationRegistry registry) { OperationDescriptor op = new JiffleDescriptor(); registry.registerDescriptor(op); String descName = op.getName(); RenderedImageFactory rif = new JiffleRIF(); registry.registerFactory(RenderedRegistryMode.MODE_NAME, descName, productName, rif); } }
/** * For testing: returns the source image bounds. * * @param destRect * @param sourceIndex * @return */ @Override public Rectangle mapDestRect(Rectangle destRect, int sourceIndex) { return getSourceImage(sourceIndex).getBounds(); }
private Rectangle getSourceBounds(ParameterBlock pb) { Rectangle boundsUnion = null; if (pb.getNumSources() > 0) { boundsUnion = getSourceBounds(pb, 0); for (int i = 1; i < pb.getNumSources(); i++) { Rectangle imageBounds = getSourceBounds(pb, i); boundsUnion = boundsUnion.union(imageBounds); } } return boundsUnion; }
private JiffleOpImage.ImageSpecification getImageSpecification( Vector<Object> sources, CoordinateTransform[] cts, BandTransform[] bts, int i) { RenderedImage image = (RenderedImage) sources.get(i); CoordinateTransform ct = null; if (cts != null) { if (cts.length != sources.size()) { throw new IllegalArgumentException( String.format( "Have %d sources, but the coordinate transformation argument contains %d entries instead" + sources.size() + cts.length)); } ct = cts[i]; } BandTransform bt = null; if (bts != null) { if (bts.length != sources.size()) { throw new IllegalArgumentException( String.format( "Have %d sources, but the band transformation argument contains %d entries instead" + sources.size() + bts.length)); } bt = bts[i]; } return new JiffleOpImage.ImageSpecification(image, ct, bt); }
for (int i = 0; i < sources.size(); i++) { if (i == 0) { result.put("src", getImageSpecification(sources, cts, bts, i)); } else { result.put("src" + i, getImageSpecification(sources, cts, bts, i)); result.put(names[i], getImageSpecification(sources, cts, bts, i));
@Test public void testCopyRemappedDefaults() { RenderedImage src = buildTestImage(10, 10); BandTransform transform = (x, y, b) -> 0; RenderedOp op = JiffleDescriptor.create(new RenderedImage[] {src}, null, null, "dest = src[10];", null, null, null, new BandTransform[] {transform}, null); assertCopy(src, op, DataBuffer.TYPE_DOUBLE); }