private Vector getRenderableSources() { Vector sources = null; int numSrcs = nodeSupport.getParameterBlock().getNumSources(); if (numSrcs > 0) { sources = new Vector(); for (int i = 0; i < numSrcs; i++) { Object o = nodeSupport.getParameterBlock().getSource(i); if (o instanceof RenderableImage) { sources.add(o); } } } return sources; }
/** * Sets one of the node's sources to an Object. This is a convenience method that invokes <code> * setParameterBlock()</code> and so adheres to the same event firing behavior. * * @param source the source, as an Object. * @param index the index of the source. * @throws IllegalArgumentException if <code>source</code> is <code>null</code>. */ public void setSource(Object source, int index) { if (source == null) throw new IllegalArgumentException(JaiI18N.getString("Generic0")); ParameterBlock pb = (ParameterBlock) nodeSupport.getParameterBlock().clone(); pb.setSource(source, index); nodeSupport.setParameterBlock(pb); }
/** * Returns one of the node's parameters, as an Object. * * @param index the index of the parameter. */ public Object getObjectParameter(int index) { return nodeSupport.getParameterBlock().getObjectParameter(index); }
/** * Returns one of the node's parameters, as a double. * * @param index the index of the parameter. */ public double getDoubleParameter(int index) { return nodeSupport.getParameterBlock().getDoubleParameter(index); }
/** * Returns one of the node's parameters, as a float. * * @param index the index of the parameter. */ public float getFloatParameter(int index) { return nodeSupport.getParameterBlock().getFloatParameter(index); }
/** * Returns one of the node's parameters, as a long. * * @param index the index of the parameter. */ public long getLongParameter(int index) { return nodeSupport.getParameterBlock().getLongParameter(index); }
/** * Returns one of the node's parameters, as an int. * * @param index the index of the parameter. */ public int getIntParameter(int index) { return nodeSupport.getParameterBlock().getIntParameter(index); }
/** * Returns one of the node's parameters, as a short. * * @param index the index of the parameter. */ public short getShortParameter(int index) { return nodeSupport.getParameterBlock().getShortParameter(index); }
/** * Returns one of the node's parameters, as a char. * * @param index the index of the parameter. */ public char getCharParameter(int index) { return nodeSupport.getParameterBlock().getCharParameter(index); }
/** * Returns one of the node's parameters, as a byte. * * @param index the index of the parameter. */ public byte getByteParameter(int index) { return nodeSupport.getParameterBlock().getByteParameter(index); }
/** * Removes all the node's sources. This is a convenience method that invokes <code> * setParameterBlock()</code> and so adheres to the same event firing behavior. * * @since JAI 1.1 */ public void removeSources() { ParameterBlock pb = (ParameterBlock) nodeSupport.getParameterBlock().clone(); pb.removeSources(); nodeSupport.setParameterBlock(pb); }
/** * Returns one of the node's sources as an Object. * * @param index the index of the source. */ public Object getSource(int index) { Vector sources = nodeSupport.getParameterBlock().getSources(); return sources.elementAt(index); }
/** * 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(); }
/** Returns a clone of the <code>ParameterBlock</code> of this node. */ public ParameterBlock getParameterBlock() { return (ParameterBlock) nodeSupport.getParameterBlock().clone(); }
/** * Sets one of the node's parameters to an Object. This is a convenience method that invokes * <code>setParameterBlock()</code> and so adheres to the same event firing behavior. * * <p>The <code>Object</code> may be a <code>DeferredData</code> instance. It will not be * evaluated until its value is actually required, i.e., when a rendering of the node is requested * or the renderable dimensions are queried. * * @param param the parameter, as an Object. * @param index the index of the parameter. */ public void setParameter(Object param, int index) { ParameterBlock pb = (ParameterBlock) nodeSupport.getParameterBlock().clone(); pb.set(param, index); nodeSupport.setParameterBlock(pb); }