/** * Gets a RenderedImage that represents a rendering of this image using a given RenderContext. * This is the most general way to obtain a rendering of a RenderableImage. * * <p>This method does not validate sources and parameters supplied in the <code>ParameterBlock * </code> supplied at construction against the specification of the operation this node * represents. It is the caller's responsibility to ensure that the data in the <code> * ParameterBlock</code> are suitable for this operation. Otherwise, some kind of exception or * error will occur. Invoking this method will cause any <code>DeferredData</code> parameters to * be evaluated. * * <p>The <code>RenderContext</code> may contain a <code>Shape</code> that represents the * area-of-interest (aoi). If the aoi is specifed, it is still legal to return an image that's * larger than this aoi. Therefore, by default, the aoi, if specified, is ignored at the * rendering. * * <p>Any hints in the <code>RenderContext</code> will be merged with any set on the node via * <code>setRenderingHints()</code> with the hints in the <code>RenderContext</code> taking * precedence. * * @param renderContext the RenderContext to use to produce the rendering. * @return a RenderedImage containing the rendered data. */ public RenderedImage createRendering(RenderContext renderContext) { findCRIF(); // Clone the original ParameterBlock; if the ParameterBlock // contains RenderableImage sources, they will be replaced by // RenderedImages. ParameterBlock nodePB = nodeSupport.getParameterBlock(); Vector nodeParams = ImageUtil.evaluateParameters(nodePB.getParameters()); ParameterBlock renderedPB = new ParameterBlock((Vector) nodePB.getSources().clone(), nodeParams); Vector sources = getRenderableSources(); try { // This assumes that if there is no renderable source, that there // is a rendered source in the ParameterBlock. // If there are any hints set on the node, create a new // RenderContext which merges them with those in the RenderContext // passed in with the passed in hints taking precedence. RenderContext rcIn = renderContext; RenderingHints nodeHints = nodeSupport.getRenderingHints(); if (nodeHints != null) { RenderingHints hints = renderContext.getRenderingHints(); RenderingHints mergedHints = JAI.mergeRenderingHints(nodeHints, hints); if (mergedHints != hints) { rcIn = new RenderContext( renderContext.getTransform(), renderContext.getAreaOfInterest(), mergedHints); } } if (sources != null) { Vector renderedSources = new Vector(); for (int i = 0; i < sources.size(); i++) { RenderContext rcOut = crif.mapRenderContext(i, rcIn, renderedPB, this); RenderableImage src = (RenderableImage) sources.elementAt(i); RenderedImage renderedImage = src.createRendering(rcOut); if (renderedImage == null) { return null; } // Add this rendered image to the ParameterBlock's // list of RenderedImages. renderedSources.addElement(renderedImage); } if (renderedSources.size() > 0) { renderedPB.setSources(renderedSources); } } RenderedImage rendering = crif.create(rcIn, renderedPB); // Replace with the actual rendering if a RenderedOp. if (rendering instanceof RenderedOp) { rendering = ((RenderedOp) rendering).getRendering(); } // Copy properties to the rendered node. if (rendering != null && rendering instanceof WritablePropertySource) { String[] propertyNames = getPropertyNames(); if (propertyNames != null) { WritablePropertySource wps = (WritablePropertySource) rendering; // Save the names of rendered properties. HashSet wpsNameSet = null; String[] wpsNames = wps.getPropertyNames(); if (wpsNames != null) { wpsNameSet = new HashSet(); for (int j = 0; j < wpsNames.length; j++) { wpsNameSet.add(new CaselessStringKey(wpsNames[j])); } } // Copy any properties not already defined by the rendering. for (int j = 0; j < propertyNames.length; j++) { String name = propertyNames[j]; if (wpsNameSet == null || !wpsNameSet.contains(new CaselessStringKey(name))) { Object value = getProperty(name); if (value != null && value != java.awt.Image.UndefinedProperty) { wps.setProperty(name, value); } } } } } return rendering; } catch (ArrayIndexOutOfBoundsException e) { // This should never happen return null; } }
/** Gets the minimum Y coordinate of the rendering-independent image data. */ public float getMinY() { findCRIF(); ParameterBlock paramBlock = ImageUtil.evaluateParameters(nodeSupport.getParameterBlock()); Rectangle2D boundingBox = crif.getBounds2D(paramBlock); return (float) boundingBox.getY(); }