Ejemplo n.º 1
0
  /**
   * 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);
  }
Ejemplo n.º 2
0
  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;
  }
Ejemplo n.º 3
0
  /**
   * Returns a default rendering of this <code>RenderableImage</code>. In all cases the area of
   * interest will equal the image bounds. Any hints set on the node via <code>setRenderingHints()
   * </code> will be used.
   *
   * <p>The dimensions of the created <code>RenderedImage</code> are determined in the following
   * order of precedence:
   *
   * <ol>
   *   <li>If a <code>JAI.KEY_DEFAULT_RENDERING_SIZE</code> hint is set on the node it is used
   *       unless both its dimensions are non-positive.
   *   <li>The value returned by <code>JAI.getDefaultRenderingSize()</code> is used unless it is
   *       <code>null</code>.
   *   <li>An identity transform from renderable to rendered coordinates is applied.
   * </ol>
   *
   * Either dimension of the default rendering size set in the hints or on the default <code>JAI
   * </code> instance may be non-positive in which case the other dimension and the renderable
   * aspect ratio will be used to compute the rendered image size.
   *
   * <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.
   *
   * @return The default RenderedImage.
   */
  public RenderedImage createDefaultRendering() {
    // Get the default dimensions.
    Dimension defaultDimension = null;
    RenderingHints hints = nodeSupport.getRenderingHints();
    if (hints != null && hints.containsKey(JAI.KEY_DEFAULT_RENDERING_SIZE)) {
      defaultDimension = (Dimension) hints.get(JAI.KEY_DEFAULT_RENDERING_SIZE);
    }
    if (defaultDimension == null || (defaultDimension.width <= 0 && defaultDimension.height <= 0)) {
      defaultDimension = JAI.getDefaultRenderingSize();
    }

    // Initialize scale factors to represent the identify transform.
    double sx = 1.0;
    double sy = 1.0;

    // Reset the scale factors if a default dimension is set.
    if (defaultDimension != null && (defaultDimension.width > 0 || defaultDimension.height > 0)) {
      if (defaultDimension.width > 0 && defaultDimension.height > 0) {
        sx = defaultDimension.width / getWidth();
        sy = defaultDimension.height / getHeight();
      } else if (defaultDimension.width > 0) {
        sx = sy = defaultDimension.width / getWidth();
      } else { // defaultDimension.height > 0
        sx = sy = defaultDimension.height / getHeight();
      }
    }

    // Create the renderable-to-rendered scaling.
    AffineTransform transform = AffineTransform.getScaleInstance(sx, sy);

    // Return the rendering applying the computed transform.
    return createRendering(new RenderContext(transform));
  }
Ejemplo n.º 4
0
  /** Creates a <code>PropertySource</code> if none exists. */
  private synchronized void createPropertySource() {
    if (thePropertySource == null) {
      // Create a <code>PropertySource</code> encapsulating the
      // property environment of the node.
      thePropertySource = nodeSupport.getPropertySource(this, null);

      // Add the <code>PropertySource</code> to the helper object.
      properties.addProperties(thePropertySource);
    }
  }
Ejemplo n.º 5
0
 /**
  * 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);
 }
Ejemplo n.º 6
0
 /**
  * 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);
 }
Ejemplo n.º 7
0
 /**
  * Sets the <code>OperationRegistry</code> that is used by this node. If the specified registry is
  * <code>null</code>, the default registry is used.
  *
  * <p>If the supplied registry does not equal the current registry, a <code>PropertyChangeEventJAI
  * </code> named "OperationRegistry" will be fired
  */
 public synchronized void setRegistry(OperationRegistry registry) {
   nodeSupport.setRegistry(registry);
 }
Ejemplo n.º 8
0
 /**
  * Forces a property to be copied from the specified source node. By default, a property is copied
  * from the first source node that emits it. The result of specifying an invalid source is
  * undefined.
  *
  * @param propertyName the name of the property to be copied.
  * @param sourceIndex the index of the from which to copy the property.
  * @throws IllegalArgumentException if <code>propertyName</code> is <code>null</code>.
  * @since JAI 1.1
  */
 public synchronized void copyPropertyFromSource(String propertyName, int sourceIndex) {
   nodeSupport.copyPropertyFromSource(propertyName, sourceIndex);
 }
Ejemplo n.º 9
0
 /**
  * Removes a named property from the property environment of this node. Unless the property is
  * stored locally either due to having been set explicitly via <code>setProperty()</code> or to
  * having been cached for property synchronization purposes, subsequent calls to <code>
  * getProperty(name)</code> will return <code>java.awt.Image.UndefinedProperty</code>, and <code>
  * name</code> will not appear on the list of properties emitted by <code>getPropertyNames()
  * </code>. To delete the property from the local property set of the node, <code>removeProperty()
  * </code> should be used.
  *
  * @param name a String naming the property to be suppressed.
  * @throws <code>IllegalArgumentException</code> if <code>name</code> is <code>null</code>.
  */
 public void suppressProperty(String name) {
   nodeSupport.suppressProperty(name);
 }
Ejemplo n.º 10
0
 /** Returns a clone of the <code>ParameterBlock</code> of this node. */
 public ParameterBlock getParameterBlock() {
   return (ParameterBlock) nodeSupport.getParameterBlock().clone();
 }
Ejemplo n.º 11
0
 /**
  * Returns the <code>OperationRegistry</code> that is used by this node. If the registry had not
  * been set, the default registry is returned.
  */
 public synchronized OperationRegistry getRegistry() {
   return nodeSupport.getRegistry();
 }
Ejemplo n.º 12
0
 /**
  * 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);
 }
Ejemplo n.º 13
0
 /**
  * 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);
 }
Ejemplo n.º 14
0
 /** Returns the name of the operation this node represents as a <code>String</code>. */
 public String getOperationName() {
   return nodeSupport.getOperationName();
 }
Ejemplo n.º 15
0
 /** 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();
 }
Ejemplo n.º 16
0
 /**
  * Sets the common <code>RenderingHints</code> of this node. The supplied parameter is cloned if
  * non-<code>null</code>.
  *
  * <p>If the supplied <code>RenderingHints</code> does not equal the current <code>RenderingHints
  * </code>, a <code>PropertyChangeEventJAI</code> named "RenderingHints" will be fired.
  *
  * @param hints The new <code>RenderingHints</code> to be set; it may be <code>null</code>.
  * @since JAI 1.1
  */
 public synchronized void setRenderingHints(RenderingHints hints) {
   if (hints != null) {
     hints = (RenderingHints) hints.clone();
   }
   nodeSupport.setRenderingHints(hints);
 }
Ejemplo n.º 17
0
 /**
  * Returns a clone of the common <code>RenderingHints</code> of this node or <code>null</code>.
  *
  * @since JAI 1.1
  */
 public RenderingHints getRenderingHints() {
   RenderingHints hints = nodeSupport.getRenderingHints();
   return hints == null ? null : (RenderingHints) hints.clone();
 }
Ejemplo n.º 18
0
 /**
  * Sets the <code>ParameterBlock</code> of this node. If the specified new <code>ParameterBlock
  * </code> is <code>null</code>, it is assumed that this node has no input sources and parameters.
  * The supplied parameter is cloned.
  *
  * <p>This method does not validate the content of the supplied <code>ParameterBlock</code>. The
  * caller should ensure that the sources and parameters in the <code>ParameterBlock</code> are
  * suitable for the operation this node represents; otherwise some form of error or exception may
  * occur at the time of rendering.
  *
  * <p>If the supplied <code>ParameterBlock</code> does not equal the current <code>ParameterBlock
  * </code>, a <code>PropertyChangeEventJAI</code> named "ParameterBlock", "Sources", or
  * "Parameters" will be fired.
  *
  * <p>The <code>ParameterBlock</code> may include <code>DeferredData</code> parameters. These will
  * not be evaluated until their values are actually required, i.e., when a rendering of the node
  * is requested or the renderable dimensions are queried.
  *
  * @param pb The new <code>ParameterBlock</code> to be set; it may be <code>null</code>.
  */
 public synchronized void setParameterBlock(ParameterBlock pb) {
   nodeSupport.setParameterBlock(pb == null ? new ParameterBlock() : (ParameterBlock) pb.clone());
 }
Ejemplo n.º 19
0
 /**
  * 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);
 }
Ejemplo n.º 20
0
 /**
  * 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);
 }
Ejemplo n.º 21
0
 /**
  * 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);
 }
Ejemplo n.º 22
0
 /**
  * Sets the name of the operation this node represents. The parameter is saved by reference.
  *
  * <p>If the supplied name does not equal the current operation name, a <code>
  * PropertyChangeEventJAI</code> named "OperationName" will be fired.
  *
  * @param opName The new operation name to be set.
  * @throws IllegalArgumentException if <code>opName</code> is <code>null</code>.
  */
 public synchronized void setOperationName(String opName) {
   nodeSupport.setOperationName(opName);
 }
Ejemplo n.º 23
0
 /**
  * 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);
 }
Ejemplo n.º 24
0
  /**
   * 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;
    }
  }
Ejemplo n.º 25
0
 /**
  * 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);
 }
Ejemplo n.º 26
0
 /**
  * Adds a PropertyGenerator to the node. The property values emitted by this property generator
  * override any previous definitions.
  *
  * @param pg a PropertyGenerator to be added to this node's property environment.
  */
 public void addPropertyGenerator(PropertyGenerator pg) {
   nodeSupport.addPropertyGenerator(pg);
 }
Ejemplo n.º 27
0
 /**
  * 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);
 }
Ejemplo n.º 28
0
 /**
  * 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);
 }