feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,143 @@
/*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* ********************************************************************
**********************************************************************
**********************************************************************
*** COPYRIGHT (c) Eastman Kodak Company, 1997 ***
*** As an unpublished work pursuant to Title 17 of the United ***
*** States Code. All rights reserved. ***
**********************************************************************
**********************************************************************
**********************************************************************/
package java.awt.image.renderable;
import java.awt.geom.Rectangle2D;
import java.awt.image.RenderedImage;
/**
* ContextualRenderedImageFactory provides an interface for the
* functionality that may differ between instances of
* RenderableImageOp. Thus different operations on RenderableImages
* may be performed by a single class such as RenderedImageOp through
* the use of multiple instances of ContextualRenderedImageFactory.
* The name ContextualRenderedImageFactory is commonly shortened to
* "CRIF."
*
* <p> All operations that are to be used in a rendering-independent
* chain must implement ContextualRenderedImageFactory.
*
* <p> Classes that implement this interface must provide a
* constructor with no arguments.
*/
public interface ContextualRenderedImageFactory extends RenderedImageFactory {
/**
* Maps the operation's output RenderContext into a RenderContext
* for each of the operation's sources. This is useful for
* operations that can be expressed in whole or in part simply as
* alterations in the RenderContext, such as an affine mapping, or
* operations that wish to obtain lower quality renderings of
* their sources in order to save processing effort or
* transmission bandwith. Some operations, such as blur, can also
* use this mechanism to avoid obtaining sources of higher quality
* than necessary.
*
* @param i the index of the source image.
* @param renderContext the RenderContext being applied to the operation.
* @param paramBlock a ParameterBlock containing the operation's
* sources and parameters.
* @param image the RenderableImage being rendered.
* @return a <code>RenderContext</code> for
* the source at the specified index of the parameters
* Vector contained in the specified ParameterBlock.
*/
RenderContext mapRenderContext(int i,
RenderContext renderContext,
ParameterBlock paramBlock,
RenderableImage image);
/**
* Creates a rendering, given a RenderContext and a ParameterBlock
* containing the operation's sources and parameters. The output
* is a RenderedImage that takes the RenderContext into account to
* determine its dimensions and placement on the image plane.
* This method houses the "intelligence" that allows a
* rendering-independent operation to adapt to a specific
* RenderContext.
*
* @param renderContext The RenderContext specifying the rendering
* @param paramBlock a ParameterBlock containing the operation's
* sources and parameters
* @return a <code>RenderedImage</code> from the sources and parameters
* in the specified ParameterBlock and according to the
* rendering instructions in the specified RenderContext.
*/
RenderedImage create(RenderContext renderContext,
ParameterBlock paramBlock);
/**
* Returns the bounding box for the output of the operation,
* performed on a given set of sources, in rendering-independent
* space. The bounds are returned as a Rectangle2D, that is, an
* axis-aligned rectangle with floating-point corner coordinates.
*
* @param paramBlock a ParameterBlock containing the operation's
* sources and parameters.
* @return a Rectangle2D specifying the rendering-independent
* bounding box of the output.
*/
Rectangle2D getBounds2D(ParameterBlock paramBlock);
/**
* Gets the appropriate instance of the property specified by the name
* parameter. This method must determine which instance of a property to
* return when there are multiple sources that each specify the property.
*
* @param paramBlock a ParameterBlock containing the operation's
* sources and parameters.
* @param name a String naming the desired property.
* @return an object reference to the value of the property requested.
*/
Object getProperty(ParameterBlock paramBlock, String name);
/**
* Returns a list of names recognized by getProperty.
* @return the list of property names.
*/
String[] getPropertyNames();
/**
* Returns true if successive renderings (that is, calls to
* create(RenderContext, ParameterBlock)) with the same arguments
* may produce different results. This method may be used to
* determine whether an existing rendering may be cached and
* reused. It is always safe to return true.
* @return <code>true</code> if successive renderings with the
* same arguments might produce different results;
* <code>false</code> otherwise.
*/
boolean isDynamic();
}

View File

@@ -0,0 +1,725 @@
/*
* Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.image.renderable;
import java.awt.image.RenderedImage;
import java.io.Serializable;
import java.util.Vector;
/**
* A <code>ParameterBlock</code> encapsulates all the information about sources and
* parameters (Objects) required by a RenderableImageOp, or other
* classes that process images.
*
* <p> Although it is possible to place arbitrary objects in the
* source Vector, users of this class may impose semantic constraints
* such as requiring all sources to be RenderedImages or
* RenderableImage. <code>ParameterBlock</code> itself is merely a container and
* performs no checking on source or parameter types.
*
* <p> All parameters in a <code>ParameterBlock</code> are objects; convenience
* add and set methods are available that take arguments of base type and
* construct the appropriate subclass of Number (such as
* Integer or Float). Corresponding get methods perform a
* downward cast and have return values of base type; an exception
* will be thrown if the stored values do not have the correct type.
* There is no way to distinguish between the results of
* "short s; add(s)" and "add(new Short(s))".
*
* <p> Note that the get and set methods operate on references.
* Therefore, one must be careful not to share references between
* <code>ParameterBlock</code>s when this is inappropriate. For example, to create
* a new <code>ParameterBlock</code> that is equal to an old one except for an
* added source, one might be tempted to write:
*
* <pre>
* ParameterBlock addSource(ParameterBlock pb, RenderableImage im) {
* ParameterBlock pb1 = new ParameterBlock(pb.getSources());
* pb1.addSource(im);
* return pb1;
* }
* </pre>
*
* <p> This code will have the side effect of altering the original
* <code>ParameterBlock</code>, since the getSources operation returned a reference
* to its source Vector. Both pb and pb1 share their source Vector,
* and a change in either is visible to both.
*
* <p> A correct way to write the addSource function is to clone
* the source Vector:
*
* <pre>
* ParameterBlock addSource (ParameterBlock pb, RenderableImage im) {
* ParameterBlock pb1 = new ParameterBlock(pb.getSources().clone());
* pb1.addSource(im);
* return pb1;
* }
* </pre>
*
* <p> The clone method of <code>ParameterBlock</code> has been defined to
* perform a clone of both the source and parameter Vectors for
* this reason. A standard, shallow clone is available as
* shallowClone.
*
* <p> The addSource, setSource, add, and set methods are
* defined to return 'this' after adding their argument. This allows
* use of syntax like:
*
* <pre>
* ParameterBlock pb = new ParameterBlock();
* op = new RenderableImageOp("operation", pb.add(arg1).add(arg2));
* </pre>
* */
public class ParameterBlock implements Cloneable, Serializable {
/** A Vector of sources, stored as arbitrary Objects. */
protected Vector<Object> sources = new Vector<Object>();
/** A Vector of non-source parameters, stored as arbitrary Objects. */
protected Vector<Object> parameters = new Vector<Object>();
/** A dummy constructor. */
public ParameterBlock() {}
/**
* Constructs a <code>ParameterBlock</code> with a given Vector
* of sources.
* @param sources a <code>Vector</code> of source images
*/
public ParameterBlock(Vector<Object> sources) {
setSources(sources);
}
/**
* Constructs a <code>ParameterBlock</code> with a given Vector of sources and
* Vector of parameters.
* @param sources a <code>Vector</code> of source images
* @param parameters a <code>Vector</code> of parameters to be used in the
* rendering operation
*/
public ParameterBlock(Vector<Object> sources,
Vector<Object> parameters)
{
setSources(sources);
setParameters(parameters);
}
/**
* Creates a shallow copy of a <code>ParameterBlock</code>. The source and
* parameter Vectors are copied by reference -- additions or
* changes will be visible to both versions.
*
* @return an Object clone of the <code>ParameterBlock</code>.
*/
public Object shallowClone() {
try {
return super.clone();
} catch (Exception e) {
// We can't be here since we implement Cloneable.
return null;
}
}
/**
* Creates a copy of a <code>ParameterBlock</code>. The source and parameter
* Vectors are cloned, but the actual sources and parameters are
* copied by reference. This allows modifications to the order
* and number of sources and parameters in the clone to be invisible
* to the original <code>ParameterBlock</code>. Changes to the shared sources or
* parameters themselves will still be visible.
*
* @return an Object clone of the <code>ParameterBlock</code>.
*/
public Object clone() {
ParameterBlock theClone;
try {
theClone = (ParameterBlock) super.clone();
} catch (Exception e) {
// We can't be here since we implement Cloneable.
return null;
}
if (sources != null) {
theClone.setSources((Vector)sources.clone());
}
if (parameters != null) {
theClone.setParameters((Vector)parameters.clone());
}
return (Object) theClone;
}
/**
* Adds an image to end of the list of sources. The image is
* stored as an object in order to allow new node types in the
* future.
*
* @param source an image object to be stored in the source list.
* @return a new <code>ParameterBlock</code> containing the specified
* <code>source</code>.
*/
public ParameterBlock addSource(Object source) {
sources.addElement(source);
return this;
}
/**
* Returns a source as a general Object. The caller must cast it into
* an appropriate type.
*
* @param index the index of the source to be returned.
* @return an <code>Object</code> that represents the source located
* at the specified index in the <code>sources</code>
* <code>Vector</code>.
* @see #setSource(Object, int)
*/
public Object getSource(int index) {
return sources.elementAt(index);
}
/**
* Replaces an entry in the list of source with a new source.
* If the index lies beyond the current source list,
* the list is extended with nulls as needed.
* @param source the specified source image
* @param index the index into the <code>sources</code>
* <code>Vector</code> at which to
* insert the specified <code>source</code>
* @return a new <code>ParameterBlock</code> that contains the
* specified <code>source</code> at the specified
* <code>index</code>.
* @see #getSource(int)
*/
public ParameterBlock setSource(Object source, int index) {
int oldSize = sources.size();
int newSize = index + 1;
if (oldSize < newSize) {
sources.setSize(newSize);
}
sources.setElementAt(source, index);
return this;
}
/**
* Returns a source as a <code>RenderedImage</code>. This method is
* a convenience method.
* An exception will be thrown if the source is not a RenderedImage.
*
* @param index the index of the source to be returned
* @return a <code>RenderedImage</code> that represents the source
* image that is at the specified index in the
* <code>sources</code> <code>Vector</code>.
*/
public RenderedImage getRenderedSource(int index) {
return (RenderedImage) sources.elementAt(index);
}
/**
* Returns a source as a RenderableImage. This method is a
* convenience method.
* An exception will be thrown if the sources is not a RenderableImage.
*
* @param index the index of the source to be returned
* @return a <code>RenderableImage</code> that represents the source
* image that is at the specified index in the
* <code>sources</code> <code>Vector</code>.
*/
public RenderableImage getRenderableSource(int index) {
return (RenderableImage) sources.elementAt(index);
}
/**
* Returns the number of source images.
* @return the number of source images in the <code>sources</code>
* <code>Vector</code>.
*/
public int getNumSources() {
return sources.size();
}
/**
* Returns the entire Vector of sources.
* @return the <code>sources</code> <code>Vector</code>.
* @see #setSources(Vector)
*/
public Vector<Object> getSources() {
return sources;
}
/**
* Sets the entire Vector of sources to a given Vector.
* @param sources the <code>Vector</code> of source images
* @see #getSources
*/
public void setSources(Vector<Object> sources) {
this.sources = sources;
}
/** Clears the list of source images. */
public void removeSources() {
sources = new Vector();
}
/**
* Returns the number of parameters (not including source images).
* @return the number of parameters in the <code>parameters</code>
* <code>Vector</code>.
*/
public int getNumParameters() {
return parameters.size();
}
/**
* Returns the entire Vector of parameters.
* @return the <code>parameters</code> <code>Vector</code>.
* @see #setParameters(Vector)
*/
public Vector<Object> getParameters() {
return parameters;
}
/**
* Sets the entire Vector of parameters to a given Vector.
* @param parameters the specified <code>Vector</code> of
* parameters
* @see #getParameters
*/
public void setParameters(Vector<Object> parameters) {
this.parameters = parameters;
}
/** Clears the list of parameters. */
public void removeParameters() {
parameters = new Vector();
}
/**
* Adds an object to the list of parameters.
* @param obj the <code>Object</code> to add to the
* <code>parameters</code> <code>Vector</code>
* @return a new <code>ParameterBlock</code> containing
* the specified parameter.
*/
public ParameterBlock add(Object obj) {
parameters.addElement(obj);
return this;
}
/**
* Adds a Byte to the list of parameters.
* @param b the byte to add to the
* <code>parameters</code> <code>Vector</code>
* @return a new <code>ParameterBlock</code> containing
* the specified parameter.
*/
public ParameterBlock add(byte b) {
return add(new Byte(b));
}
/**
* Adds a Character to the list of parameters.
* @param c the char to add to the
* <code>parameters</code> <code>Vector</code>
* @return a new <code>ParameterBlock</code> containing
* the specified parameter.
*/
public ParameterBlock add(char c) {
return add(new Character(c));
}
/**
* Adds a Short to the list of parameters.
* @param s the short to add to the
* <code>parameters</code> <code>Vector</code>
* @return a new <code>ParameterBlock</code> containing
* the specified parameter.
*/
public ParameterBlock add(short s) {
return add(new Short(s));
}
/**
* Adds a Integer to the list of parameters.
* @param i the int to add to the
* <code>parameters</code> <code>Vector</code>
* @return a new <code>ParameterBlock</code> containing
* the specified parameter.
*/
public ParameterBlock add(int i) {
return add(new Integer(i));
}
/**
* Adds a Long to the list of parameters.
* @param l the long to add to the
* <code>parameters</code> <code>Vector</code>
* @return a new <code>ParameterBlock</code> containing
* the specified parameter.
*/
public ParameterBlock add(long l) {
return add(new Long(l));
}
/**
* Adds a Float to the list of parameters.
* @param f the float to add to the
* <code>parameters</code> <code>Vector</code>
* @return a new <code>ParameterBlock</code> containing
* the specified parameter.
*/
public ParameterBlock add(float f) {
return add(new Float(f));
}
/**
* Adds a Double to the list of parameters.
* @param d the double to add to the
* <code>parameters</code> <code>Vector</code>
* @return a new <code>ParameterBlock</code> containing
* the specified parameter.
*/
public ParameterBlock add(double d) {
return add(new Double(d));
}
/**
* Replaces an Object in the list of parameters.
* If the index lies beyond the current source list,
* the list is extended with nulls as needed.
* @param obj the parameter that replaces the
* parameter at the specified index in the
* <code>parameters</code> <code>Vector</code>
* @param index the index of the parameter to be
* replaced with the specified parameter
* @return a new <code>ParameterBlock</code> containing
* the specified parameter.
*/
public ParameterBlock set(Object obj, int index) {
int oldSize = parameters.size();
int newSize = index + 1;
if (oldSize < newSize) {
parameters.setSize(newSize);
}
parameters.setElementAt(obj, index);
return this;
}
/**
* Replaces an Object in the list of parameters with a Byte.
* If the index lies beyond the current source list,
* the list is extended with nulls as needed.
* @param b the parameter that replaces the
* parameter at the specified index in the
* <code>parameters</code> <code>Vector</code>
* @param index the index of the parameter to be
* replaced with the specified parameter
* @return a new <code>ParameterBlock</code> containing
* the specified parameter.
*/
public ParameterBlock set(byte b, int index) {
return set(new Byte(b), index);
}
/**
* Replaces an Object in the list of parameters with a Character.
* If the index lies beyond the current source list,
* the list is extended with nulls as needed.
* @param c the parameter that replaces the
* parameter at the specified index in the
* <code>parameters</code> <code>Vector</code>
* @param index the index of the parameter to be
* replaced with the specified parameter
* @return a new <code>ParameterBlock</code> containing
* the specified parameter.
*/
public ParameterBlock set(char c, int index) {
return set(new Character(c), index);
}
/**
* Replaces an Object in the list of parameters with a Short.
* If the index lies beyond the current source list,
* the list is extended with nulls as needed.
* @param s the parameter that replaces the
* parameter at the specified index in the
* <code>parameters</code> <code>Vector</code>
* @param index the index of the parameter to be
* replaced with the specified parameter
* @return a new <code>ParameterBlock</code> containing
* the specified parameter.
*/
public ParameterBlock set(short s, int index) {
return set(new Short(s), index);
}
/**
* Replaces an Object in the list of parameters with an Integer.
* If the index lies beyond the current source list,
* the list is extended with nulls as needed.
* @param i the parameter that replaces the
* parameter at the specified index in the
* <code>parameters</code> <code>Vector</code>
* @param index the index of the parameter to be
* replaced with the specified parameter
* @return a new <code>ParameterBlock</code> containing
* the specified parameter.
*/
public ParameterBlock set(int i, int index) {
return set(new Integer(i), index);
}
/**
* Replaces an Object in the list of parameters with a Long.
* If the index lies beyond the current source list,
* the list is extended with nulls as needed.
* @param l the parameter that replaces the
* parameter at the specified index in the
* <code>parameters</code> <code>Vector</code>
* @param index the index of the parameter to be
* replaced with the specified parameter
* @return a new <code>ParameterBlock</code> containing
* the specified parameter.
*/
public ParameterBlock set(long l, int index) {
return set(new Long(l), index);
}
/**
* Replaces an Object in the list of parameters with a Float.
* If the index lies beyond the current source list,
* the list is extended with nulls as needed.
* @param f the parameter that replaces the
* parameter at the specified index in the
* <code>parameters</code> <code>Vector</code>
* @param index the index of the parameter to be
* replaced with the specified parameter
* @return a new <code>ParameterBlock</code> containing
* the specified parameter.
*/
public ParameterBlock set(float f, int index) {
return set(new Float(f), index);
}
/**
* Replaces an Object in the list of parameters with a Double.
* If the index lies beyond the current source list,
* the list is extended with nulls as needed.
* @param d the parameter that replaces the
* parameter at the specified index in the
* <code>parameters</code> <code>Vector</code>
* @param index the index of the parameter to be
* replaced with the specified parameter
* @return a new <code>ParameterBlock</code> containing
* the specified parameter.
*/
public ParameterBlock set(double d, int index) {
return set(new Double(d), index);
}
/**
* Gets a parameter as an object.
* @param index the index of the parameter to get
* @return an <code>Object</code> representing the
* the parameter at the specified index
* into the <code>parameters</code>
* <code>Vector</code>.
*/
public Object getObjectParameter(int index) {
return parameters.elementAt(index);
}
/**
* A convenience method to return a parameter as a byte. An
* exception is thrown if the parameter is
* <code>null</code> or not a <code>Byte</code>.
*
* @param index the index of the parameter to be returned.
* @return the parameter at the specified index
* as a <code>byte</code> value.
* @throws ClassCastException if the parameter at the
* specified index is not a <code>Byte</code>
* @throws NullPointerException if the parameter at the specified
* index is <code>null</code>
* @throws ArrayIndexOutOfBoundsException if <code>index</code>
* is negative or not less than the current size of this
* <code>ParameterBlock</code> object
*/
public byte getByteParameter(int index) {
return ((Byte)parameters.elementAt(index)).byteValue();
}
/**
* A convenience method to return a parameter as a char. An
* exception is thrown if the parameter is
* <code>null</code> or not a <code>Character</code>.
*
* @param index the index of the parameter to be returned.
* @return the parameter at the specified index
* as a <code>char</code> value.
* @throws ClassCastException if the parameter at the
* specified index is not a <code>Character</code>
* @throws NullPointerException if the parameter at the specified
* index is <code>null</code>
* @throws ArrayIndexOutOfBoundsException if <code>index</code>
* is negative or not less than the current size of this
* <code>ParameterBlock</code> object
*/
public char getCharParameter(int index) {
return ((Character)parameters.elementAt(index)).charValue();
}
/**
* A convenience method to return a parameter as a short. An
* exception is thrown if the parameter is
* <code>null</code> or not a <code>Short</code>.
*
* @param index the index of the parameter to be returned.
* @return the parameter at the specified index
* as a <code>short</code> value.
* @throws ClassCastException if the parameter at the
* specified index is not a <code>Short</code>
* @throws NullPointerException if the parameter at the specified
* index is <code>null</code>
* @throws ArrayIndexOutOfBoundsException if <code>index</code>
* is negative or not less than the current size of this
* <code>ParameterBlock</code> object
*/
public short getShortParameter(int index) {
return ((Short)parameters.elementAt(index)).shortValue();
}
/**
* A convenience method to return a parameter as an int. An
* exception is thrown if the parameter is
* <code>null</code> or not an <code>Integer</code>.
*
* @param index the index of the parameter to be returned.
* @return the parameter at the specified index
* as a <code>int</code> value.
* @throws ClassCastException if the parameter at the
* specified index is not a <code>Integer</code>
* @throws NullPointerException if the parameter at the specified
* index is <code>null</code>
* @throws ArrayIndexOutOfBoundsException if <code>index</code>
* is negative or not less than the current size of this
* <code>ParameterBlock</code> object
*/
public int getIntParameter(int index) {
return ((Integer)parameters.elementAt(index)).intValue();
}
/**
* A convenience method to return a parameter as a long. An
* exception is thrown if the parameter is
* <code>null</code> or not a <code>Long</code>.
*
* @param index the index of the parameter to be returned.
* @return the parameter at the specified index
* as a <code>long</code> value.
* @throws ClassCastException if the parameter at the
* specified index is not a <code>Long</code>
* @throws NullPointerException if the parameter at the specified
* index is <code>null</code>
* @throws ArrayIndexOutOfBoundsException if <code>index</code>
* is negative or not less than the current size of this
* <code>ParameterBlock</code> object
*/
public long getLongParameter(int index) {
return ((Long)parameters.elementAt(index)).longValue();
}
/**
* A convenience method to return a parameter as a float. An
* exception is thrown if the parameter is
* <code>null</code> or not a <code>Float</code>.
*
* @param index the index of the parameter to be returned.
* @return the parameter at the specified index
* as a <code>float</code> value.
* @throws ClassCastException if the parameter at the
* specified index is not a <code>Float</code>
* @throws NullPointerException if the parameter at the specified
* index is <code>null</code>
* @throws ArrayIndexOutOfBoundsException if <code>index</code>
* is negative or not less than the current size of this
* <code>ParameterBlock</code> object
*/
public float getFloatParameter(int index) {
return ((Float)parameters.elementAt(index)).floatValue();
}
/**
* A convenience method to return a parameter as a double. An
* exception is thrown if the parameter is
* <code>null</code> or not a <code>Double</code>.
*
* @param index the index of the parameter to be returned.
* @return the parameter at the specified index
* as a <code>double</code> value.
* @throws ClassCastException if the parameter at the
* specified index is not a <code>Double</code>
* @throws NullPointerException if the parameter at the specified
* index is <code>null</code>
* @throws ArrayIndexOutOfBoundsException if <code>index</code>
* is negative or not less than the current size of this
* <code>ParameterBlock</code> object
*/
public double getDoubleParameter(int index) {
return ((Double)parameters.elementAt(index)).doubleValue();
}
/**
* Returns an array of Class objects describing the types
* of the parameters.
* @return an array of <code>Class</code> objects.
*/
public Class [] getParamClasses() {
int numParams = getNumParameters();
Class [] classes = new Class[numParams];
int i;
for (i = 0; i < numParams; i++) {
Object obj = getObjectParameter(i);
if (obj instanceof Byte) {
classes[i] = byte.class;
} else if (obj instanceof Character) {
classes[i] = char.class;
} else if (obj instanceof Short) {
classes[i] = short.class;
} else if (obj instanceof Integer) {
classes[i] = int.class;
} else if (obj instanceof Long) {
classes[i] = long.class;
} else if (obj instanceof Float) {
classes[i] = float.class;
} else if (obj instanceof Double) {
classes[i] = double.class;
} else {
classes[i] = obj.getClass();
}
}
return classes;
}
}

View File

@@ -0,0 +1,272 @@
/*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* ********************************************************************
**********************************************************************
**********************************************************************
*** COPYRIGHT (c) Eastman Kodak Company, 1997 ***
*** As an unpublished work pursuant to Title 17 of the United ***
*** States Code. All rights reserved. ***
**********************************************************************
**********************************************************************
**********************************************************************/
package java.awt.image.renderable;
import java.util.*;
import java.awt.geom.*;
import java.awt.*;
import java.awt.image.*;
/**
* A RenderContext encapsulates the information needed to produce a
* specific rendering from a RenderableImage. It contains the area to
* be rendered specified in rendering-independent terms, the
* resolution at which the rendering is to be performed, and hints
* used to control the rendering process.
*
* <p> Users create RenderContexts and pass them to the
* RenderableImage via the createRendering method. Most of the methods of
* RenderContexts are not meant to be used directly by applications,
* but by the RenderableImage and operator classes to which it is
* passed.
*
* <p> The AffineTransform parameter passed into and out of this class
* are cloned. The RenderingHints and Shape parameters are not
* necessarily cloneable and are therefore only reference copied.
* Altering RenderingHints or Shape instances that are in use by
* instances of RenderContext may have undesired side effects.
*/
public class RenderContext implements Cloneable {
/** Table of hints. May be null. */
RenderingHints hints;
/** Transform to convert user coordinates to device coordinates. */
AffineTransform usr2dev;
/** The area of interest. May be null. */
Shape aoi;
// Various constructors that allow different levels of
// specificity. If the Shape is missing the whole renderable area
// is assumed. If hints is missing no hints are assumed.
/**
* Constructs a RenderContext with a given transform.
* The area of interest is supplied as a Shape,
* and the rendering hints are supplied as a RenderingHints object.
*
* @param usr2dev an AffineTransform.
* @param aoi a Shape representing the area of interest.
* @param hints a RenderingHints object containing rendering hints.
*/
public RenderContext(AffineTransform usr2dev,
Shape aoi,
RenderingHints hints) {
this.hints = hints;
this.aoi = aoi;
this.usr2dev = (AffineTransform)usr2dev.clone();
}
/**
* Constructs a RenderContext with a given transform.
* The area of interest is taken to be the entire renderable area.
* No rendering hints are used.
*
* @param usr2dev an AffineTransform.
*/
public RenderContext(AffineTransform usr2dev) {
this(usr2dev, null, null);
}
/**
* Constructs a RenderContext with a given transform and rendering hints.
* The area of interest is taken to be the entire renderable area.
*
* @param usr2dev an AffineTransform.
* @param hints a RenderingHints object containing rendering hints.
*/
public RenderContext(AffineTransform usr2dev, RenderingHints hints) {
this(usr2dev, null, hints);
}
/**
* Constructs a RenderContext with a given transform and area of interest.
* The area of interest is supplied as a Shape.
* No rendering hints are used.
*
* @param usr2dev an AffineTransform.
* @param aoi a Shape representing the area of interest.
*/
public RenderContext(AffineTransform usr2dev, Shape aoi) {
this(usr2dev, aoi, null);
}
/**
* Gets the rendering hints of this <code>RenderContext</code>.
* @return a <code>RenderingHints</code> object that represents
* the rendering hints of this <code>RenderContext</code>.
* @see #setRenderingHints(RenderingHints)
*/
public RenderingHints getRenderingHints() {
return hints;
}
/**
* Sets the rendering hints of this <code>RenderContext</code>.
* @param hints a <code>RenderingHints</code> object that represents
* the rendering hints to assign to this <code>RenderContext</code>.
* @see #getRenderingHints
*/
public void setRenderingHints(RenderingHints hints) {
this.hints = hints;
}
/**
* Sets the current user-to-device AffineTransform contained
* in the RenderContext to a given transform.
*
* @param newTransform the new AffineTransform.
* @see #getTransform
*/
public void setTransform(AffineTransform newTransform) {
usr2dev = (AffineTransform)newTransform.clone();
}
/**
* Modifies the current user-to-device transform by prepending another
* transform. In matrix notation the operation is:
* <pre>
* [this] = [modTransform] x [this]
* </pre>
*
* @param modTransform the AffineTransform to prepend to the
* current usr2dev transform.
* @since 1.3
*/
public void preConcatenateTransform(AffineTransform modTransform) {
this.preConcetenateTransform(modTransform);
}
/**
* Modifies the current user-to-device transform by prepending another
* transform. In matrix notation the operation is:
* <pre>
* [this] = [modTransform] x [this]
* </pre>
* This method does the same thing as the preConcatenateTransform
* method. It is here for backward compatibility with previous releases
* which misspelled the method name.
*
* @param modTransform the AffineTransform to prepend to the
* current usr2dev transform.
* @deprecated replaced by
* <code>preConcatenateTransform(AffineTransform)</code>.
*/
@Deprecated
public void preConcetenateTransform(AffineTransform modTransform) {
usr2dev.preConcatenate(modTransform);
}
/**
* Modifies the current user-to-device transform by appending another
* transform. In matrix notation the operation is:
* <pre>
* [this] = [this] x [modTransform]
* </pre>
*
* @param modTransform the AffineTransform to append to the
* current usr2dev transform.
* @since 1.3
*/
public void concatenateTransform(AffineTransform modTransform) {
this.concetenateTransform(modTransform);
}
/**
* Modifies the current user-to-device transform by appending another
* transform. In matrix notation the operation is:
* <pre>
* [this] = [this] x [modTransform]
* </pre>
* This method does the same thing as the concatenateTransform
* method. It is here for backward compatibility with previous releases
* which misspelled the method name.
*
* @param modTransform the AffineTransform to append to the
* current usr2dev transform.
* @deprecated replaced by
* <code>concatenateTransform(AffineTransform)</code>.
*/
@Deprecated
public void concetenateTransform(AffineTransform modTransform) {
usr2dev.concatenate(modTransform);
}
/**
* Gets the current user-to-device AffineTransform.
*
* @return a reference to the current AffineTransform.
* @see #setTransform(AffineTransform)
*/
public AffineTransform getTransform() {
return (AffineTransform)usr2dev.clone();
}
/**
* Sets the current area of interest. The old area is discarded.
*
* @param newAoi The new area of interest.
* @see #getAreaOfInterest
*/
public void setAreaOfInterest(Shape newAoi) {
aoi = newAoi;
}
/**
* Gets the ares of interest currently contained in the
* RenderContext.
*
* @return a reference to the area of interest of the RenderContext,
* or null if none is specified.
* @see #setAreaOfInterest(Shape)
*/
public Shape getAreaOfInterest() {
return aoi;
}
/**
* Makes a copy of a RenderContext. The area of interest is copied
* by reference. The usr2dev AffineTransform and hints are cloned,
* while the area of interest is copied by reference.
*
* @return the new cloned RenderContext.
*/
public Object clone() {
RenderContext newRenderContext = new RenderContext(usr2dev,
aoi, hints);
return newRenderContext;
}
}

View File

@@ -0,0 +1,198 @@
/*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* ********************************************************************
**********************************************************************
**********************************************************************
*** COPYRIGHT (c) Eastman Kodak Company, 1997 ***
*** As an unpublished work pursuant to Title 17 of the United ***
*** States Code. All rights reserved. ***
**********************************************************************
**********************************************************************
**********************************************************************/
package java.awt.image.renderable;
import java.util.Vector;
import java.awt.RenderingHints;
import java.awt.image.*;
/**
* A RenderableImage is a common interface for rendering-independent
* images (a notion which subsumes resolution independence). That is,
* images which are described and have operations applied to them
* independent of any specific rendering of the image. For example, a
* RenderableImage can be rotated and cropped in
* resolution-independent terms. Then, it can be rendered for various
* specific contexts, such as a draft preview, a high-quality screen
* display, or a printer, each in an optimal fashion.
*
* <p> A RenderedImage is returned from a RenderableImage via the
* createRendering() method, which takes a RenderContext. The
* RenderContext specifies how the RenderedImage should be
* constructed. Note that it is not possible to extract pixels
* directly from a RenderableImage.
*
* <p> The createDefaultRendering() and createScaledRendering() methods are
* convenience methods that construct an appropriate RenderContext
* internally. All of the rendering methods may return a reference to a
* previously produced rendering.
*/
public interface RenderableImage {
/**
* String constant that can be used to identify a property on
* a RenderedImage obtained via the createRendering or
* createScaledRendering methods. If such a property exists,
* the value of the property will be a RenderingHints object
* specifying which hints were observed in creating the rendering.
*/
static final String HINTS_OBSERVED = "HINTS_OBSERVED";
/**
* Returns a vector of RenderableImages that are the sources of
* image data for this RenderableImage. Note that this method may
* return an empty vector, to indicate that the image has no sources,
* or null, to indicate that no information is available.
*
* @return a (possibly empty) Vector of RenderableImages, or null.
*/
Vector<RenderableImage> getSources();
/**
* Gets a property from the property set of this image.
* If the property name is not recognized, java.awt.Image.UndefinedProperty
* will be returned.
*
* @param name the name of the property to get, as a String.
* @return a reference to the property Object, or the value
* java.awt.Image.UndefinedProperty.
*/
Object getProperty(String name);
/**
* Returns a list of names recognized by getProperty.
* @return a list of property names.
*/
String[] getPropertyNames();
/**
* Returns true if successive renderings (that is, calls to
* createRendering() or createScaledRendering()) with the same arguments
* may produce different results. This method may be used to
* determine whether an existing rendering may be cached and
* reused. It is always safe to return true.
* @return <code>true</code> if successive renderings with the
* same arguments might produce different results;
* <code>false</code> otherwise.
*/
boolean isDynamic();
/**
* Gets the width in user coordinate space. By convention, the
* usual width of a RenderableImage is equal to the image's aspect
* ratio (width divided by height).
*
* @return the width of the image in user coordinates.
*/
float getWidth();
/**
* Gets the height in user coordinate space. By convention, the
* usual height of a RenderedImage is equal to 1.0F.
*
* @return the height of the image in user coordinates.
*/
float getHeight();
/**
* Gets the minimum X coordinate of the rendering-independent image data.
* @return the minimum X coordinate of the rendering-independent image
* data.
*/
float getMinX();
/**
* Gets the minimum Y coordinate of the rendering-independent image data.
* @return the minimum Y coordinate of the rendering-independent image
* data.
*/
float getMinY();
/**
* Creates a RenderedImage instance of this image with width w, and
* height h in pixels. The RenderContext is built automatically
* with an appropriate usr2dev transform and an area of interest
* of the full image. All the rendering hints come from hints
* passed in.
*
* <p> If w == 0, it will be taken to equal
* Math.round(h*(getWidth()/getHeight())).
* Similarly, if h == 0, it will be taken to equal
* Math.round(w*(getHeight()/getWidth())). One of
* w or h must be non-zero or else an IllegalArgumentException
* will be thrown.
*
* <p> The created RenderedImage may have a property identified
* by the String HINTS_OBSERVED to indicate which RenderingHints
* were used to create the image. In addition any RenderedImages
* that are obtained via the getSources() method on the created
* RenderedImage may have such a property.
*
* @param w the width of rendered image in pixels, or 0.
* @param h the height of rendered image in pixels, or 0.
* @param hints a RenderingHints object containing hints.
* @return a RenderedImage containing the rendered data.
*/
RenderedImage createScaledRendering(int w, int h, RenderingHints hints);
/**
* Returnd a RenderedImage instance of this image with a default
* width and height in pixels. The RenderContext is built
* automatically with an appropriate usr2dev transform and an area
* of interest of the full image. The rendering hints are
* empty. createDefaultRendering may make use of a stored
* rendering for speed.
*
* @return a RenderedImage containing the rendered data.
*/
RenderedImage createDefaultRendering();
/**
* Creates a RenderedImage that represented a rendering of this image
* using a given RenderContext. This is the most general way to obtain a
* rendering of a RenderableImage.
*
* <p> The created RenderedImage may have a property identified
* by the String HINTS_OBSERVED to indicate which RenderingHints
* (from the RenderContext) were used to create the image.
* In addition any RenderedImages
* that are obtained via the getSources() method on the created
* RenderedImage may have such a property.
*
* @param renderContext the RenderContext to use to produce the rendering.
* @return a RenderedImage containing the rendered data.
*/
RenderedImage createRendering(RenderContext renderContext);
}

View File

@@ -0,0 +1,350 @@
/*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* ********************************************************************
**********************************************************************
**********************************************************************
*** COPYRIGHT (c) Eastman Kodak Company, 1997 ***
*** As an unpublished work pursuant to Title 17 of the United ***
*** States Code. All rights reserved. ***
**********************************************************************
**********************************************************************
**********************************************************************/
package java.awt.image.renderable;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.RenderedImage;
import java.awt.RenderingHints;
import java.util.Hashtable;
import java.util.Vector;
/**
* This class handles the renderable aspects of an operation with help
* from its associated instance of a ContextualRenderedImageFactory.
*/
public class RenderableImageOp implements RenderableImage {
/** A ParameterBlock containing source and parameters. */
ParameterBlock paramBlock;
/** The associated ContextualRenderedImageFactory. */
ContextualRenderedImageFactory myCRIF;
/** The bounding box of the results of this RenderableImageOp. */
Rectangle2D boundingBox;
/**
* Constructs a RenderedImageOp given a
* ContextualRenderedImageFactory object, and
* a ParameterBlock containing RenderableImage sources and other
* parameters. Any RenderedImage sources referenced by the
* ParameterBlock will be ignored.
*
* @param CRIF a ContextualRenderedImageFactory object
* @param paramBlock a ParameterBlock containing this operation's source
* images and other parameters necessary for the operation
* to run.
*/
public RenderableImageOp(ContextualRenderedImageFactory CRIF,
ParameterBlock paramBlock) {
this.myCRIF = CRIF;
this.paramBlock = (ParameterBlock) paramBlock.clone();
}
/**
* Returns a vector of RenderableImages that are the sources of
* image data for this RenderableImage. Note that this method may
* return an empty vector, to indicate that the image has no sources,
* or null, to indicate that no information is available.
*
* @return a (possibly empty) Vector of RenderableImages, or null.
*/
public Vector<RenderableImage> getSources() {
return getRenderableSources();
}
private Vector getRenderableSources() {
Vector sources = null;
if (paramBlock.getNumSources() > 0) {
sources = new Vector();
int i = 0;
while (i < paramBlock.getNumSources()) {
Object o = paramBlock.getSource(i);
if (o instanceof RenderableImage) {
sources.add((RenderableImage)o);
i++;
} else {
break;
}
}
}
return sources;
}
/**
* Gets a property from the property set of this image.
* If the property name is not recognized, java.awt.Image.UndefinedProperty
* will be returned.
*
* @param name the name of the property to get, as a String.
* @return a reference to the property Object, or the value
* java.awt.Image.UndefinedProperty.
*/
public Object getProperty(String name) {
return myCRIF.getProperty(paramBlock, name);
}
/**
* Return a list of names recognized by getProperty.
* @return a list of property names.
*/
public String[] getPropertyNames() {
return myCRIF.getPropertyNames();
}
/**
* Returns true if successive renderings (that is, calls to
* createRendering() or createScaledRendering()) with the same arguments
* may produce different results. This method may be used to
* determine whether an existing rendering may be cached and
* reused. The CRIF's isDynamic method will be called.
* @return <code>true</code> if successive renderings with the
* same arguments might produce different results;
* <code>false</code> otherwise.
*/
public boolean isDynamic() {
return myCRIF.isDynamic();
}
/**
* Gets the width in user coordinate space. By convention, the
* usual width of a RenderableImage is equal to the image's aspect
* ratio (width divided by height).
*
* @return the width of the image in user coordinates.
*/
public float getWidth() {
if (boundingBox == null) {
boundingBox = myCRIF.getBounds2D(paramBlock);
}
return (float)boundingBox.getWidth();
}
/**
* Gets the height in user coordinate space. By convention, the
* usual height of a RenderedImage is equal to 1.0F.
*
* @return the height of the image in user coordinates.
*/
public float getHeight() {
if (boundingBox == null) {
boundingBox = myCRIF.getBounds2D(paramBlock);
}
return (float)boundingBox.getHeight();
}
/**
* Gets the minimum X coordinate of the rendering-independent image data.
*/
public float getMinX() {
if (boundingBox == null) {
boundingBox = myCRIF.getBounds2D(paramBlock);
}
return (float)boundingBox.getMinX();
}
/**
* Gets the minimum Y coordinate of the rendering-independent image data.
*/
public float getMinY() {
if (boundingBox == null) {
boundingBox = myCRIF.getBounds2D(paramBlock);
}
return (float)boundingBox.getMinY();
}
/**
* Change the current ParameterBlock of the operation, allowing
* editing of image rendering chains. The effects of such a
* change will be visible when a new rendering is created from
* this RenderableImageOp or any dependent RenderableImageOp.
*
* @param paramBlock the new ParameterBlock.
* @return the old ParameterBlock.
* @see #getParameterBlock
*/
public ParameterBlock setParameterBlock(ParameterBlock paramBlock) {
ParameterBlock oldParamBlock = this.paramBlock;
this.paramBlock = (ParameterBlock)paramBlock.clone();
return oldParamBlock;
}
/**
* Returns a reference to the current parameter block.
* @return the <code>ParameterBlock</code> of this
* <code>RenderableImageOp</code>.
* @see #setParameterBlock(ParameterBlock)
*/
public ParameterBlock getParameterBlock() {
return paramBlock;
}
/**
* Creates a RenderedImage instance of this image with width w, and
* height h in pixels. The RenderContext is built automatically
* with an appropriate usr2dev transform and an area of interest
* of the full image. All the rendering hints come from hints
* passed in.
*
* <p> If w == 0, it will be taken to equal
* Math.round(h*(getWidth()/getHeight())).
* Similarly, if h == 0, it will be taken to equal
* Math.round(w*(getHeight()/getWidth())). One of
* w or h must be non-zero or else an IllegalArgumentException
* will be thrown.
*
* <p> The created RenderedImage may have a property identified
* by the String HINTS_OBSERVED to indicate which RenderingHints
* were used to create the image. In addition any RenderedImages
* that are obtained via the getSources() method on the created
* RenderedImage may have such a property.
*
* @param w the width of rendered image in pixels, or 0.
* @param h the height of rendered image in pixels, or 0.
* @param hints a RenderingHints object containing hints.
* @return a RenderedImage containing the rendered data.
*/
public RenderedImage createScaledRendering(int w, int h,
RenderingHints hints) {
// DSR -- code to try to get a unit scale
double sx = (double)w/getWidth();
double sy = (double)h/getHeight();
if (Math.abs(sx/sy - 1.0) < 0.01) {
sx = sy;
}
AffineTransform usr2dev = AffineTransform.getScaleInstance(sx, sy);
RenderContext newRC = new RenderContext(usr2dev, hints);
return createRendering(newRC);
}
/**
* Gets a RenderedImage instance of this image with a default
* width and height in pixels. The RenderContext is built
* automatically with an appropriate usr2dev transform and an area
* of interest of the full image. All the rendering hints come
* from hints passed in. Implementors of this interface must be
* sure that there is a defined default width and height.
*
* @return a RenderedImage containing the rendered data.
*/
public RenderedImage createDefaultRendering() {
AffineTransform usr2dev = new AffineTransform(); // Identity
RenderContext newRC = new RenderContext(usr2dev);
return createRendering(newRC);
}
/**
* Creates a RenderedImage which represents this
* RenderableImageOp (including its Renderable sources) rendered
* according to the given RenderContext.
*
* <p> This method supports chaining of either Renderable or
* RenderedImage operations. If sources in
* the ParameterBlock used to construct the RenderableImageOp are
* RenderableImages, then a three step process is followed:
*
* <ol>
* <li> mapRenderContext() is called on the associated CRIF for
* each RenderableImage source;
* <li> createRendering() is called on each of the RenderableImage sources
* using the backwards-mapped RenderContexts obtained in step 1,
* resulting in a rendering of each source;
* <li> ContextualRenderedImageFactory.create() is called
* with a new ParameterBlock containing the parameters of
* the RenderableImageOp and the RenderedImages that were created by the
* createRendering() calls.
* </ol>
*
* <p> If the elements of the source Vector of
* the ParameterBlock used to construct the RenderableImageOp are
* instances of RenderedImage, then the CRIF.create() method is
* called immediately using the original ParameterBlock.
* This provides a basis case for the recursion.
*
* <p> The created RenderedImage may have a property identified
* by the String HINTS_OBSERVED to indicate which RenderingHints
* (from the RenderContext) were used to create the image.
* In addition any RenderedImages
* that are obtained via the getSources() method on the created
* RenderedImage may have such a property.
*
* @param renderContext The RenderContext to use to perform the rendering.
* @return a RenderedImage containing the desired output image.
*/
public RenderedImage createRendering(RenderContext renderContext) {
RenderedImage image = null;
RenderContext rcOut = null;
// Clone the original ParameterBlock; if the ParameterBlock
// contains RenderableImage sources, they will be replaced by
// RenderedImages.
ParameterBlock renderedParamBlock = (ParameterBlock)paramBlock.clone();
Vector sources = getRenderableSources();
try {
// This assumes that if there is no renderable source, that there
// is a rendered source in paramBlock
if (sources != null) {
Vector renderedSources = new Vector();
for (int i = 0; i < sources.size(); i++) {
rcOut = myCRIF.mapRenderContext(i, renderContext,
paramBlock, this);
RenderedImage rdrdImage =
((RenderableImage)sources.elementAt(i)).createRendering(rcOut);
if (rdrdImage == null) {
return null;
}
// Add this rendered image to the ParameterBlock's
// list of RenderedImages.
renderedSources.addElement(rdrdImage);
}
if (renderedSources.size() > 0) {
renderedParamBlock.setSources(renderedSources);
}
}
return myCRIF.create(renderContext, renderedParamBlock);
} catch (ArrayIndexOutOfBoundsException e) {
// This should never happen
return null;
}
}
}

View File

@@ -0,0 +1,219 @@
/*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* ********************************************************************
**********************************************************************
**********************************************************************
*** COPYRIGHT (c) Eastman Kodak Company, 1997 ***
*** As an unpublished work pursuant to Title 17 of the United ***
*** States Code. All rights reserved. ***
**********************************************************************
**********************************************************************
**********************************************************************/
package java.awt.image.renderable;
import java.awt.color.ColorSpace;
import java.awt.image.ColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DirectColorModel;
import java.awt.image.ImageConsumer;
import java.awt.image.ImageProducer;
import java.awt.image.Raster;
import java.awt.image.RenderedImage;
import java.awt.image.SampleModel;
import java.util.Enumeration;
import java.util.Vector;
/**
* An adapter class that implements ImageProducer to allow the
* asynchronous production of a RenderableImage. The size of the
* ImageConsumer is determined by the scale factor of the usr2dev
* transform in the RenderContext. If the RenderContext is null, the
* default rendering of the RenderableImage is used. This class
* implements an asynchronous production that produces the image in
* one thread at one resolution. This class may be subclassed to
* implement versions that will render the image using several
* threads. These threads could render either the same image at
* progressively better quality, or different sections of the image at
* a single resolution.
*/
public class RenderableImageProducer implements ImageProducer, Runnable {
/** The RenderableImage source for the producer. */
RenderableImage rdblImage;
/** The RenderContext to use for producing the image. */
RenderContext rc;
/** A Vector of image consumers. */
Vector ics = new Vector();
/**
* Constructs a new RenderableImageProducer from a RenderableImage
* and a RenderContext.
*
* @param rdblImage the RenderableImage to be rendered.
* @param rc the RenderContext to use for producing the pixels.
*/
public RenderableImageProducer(RenderableImage rdblImage,
RenderContext rc) {
this.rdblImage = rdblImage;
this.rc = rc;
}
/**
* Sets a new RenderContext to use for the next startProduction() call.
*
* @param rc the new RenderContext.
*/
public synchronized void setRenderContext(RenderContext rc) {
this.rc = rc;
}
/**
* Adds an ImageConsumer to the list of consumers interested in
* data for this image.
*
* @param ic an ImageConsumer to be added to the interest list.
*/
public synchronized void addConsumer(ImageConsumer ic) {
if (!ics.contains(ic)) {
ics.addElement(ic);
}
}
/**
* Determine if an ImageConsumer is on the list of consumers
* currently interested in data for this image.
*
* @param ic the ImageConsumer to be checked.
* @return true if the ImageConsumer is on the list; false otherwise.
*/
public synchronized boolean isConsumer(ImageConsumer ic) {
return ics.contains(ic);
}
/**
* Remove an ImageConsumer from the list of consumers interested in
* data for this image.
*
* @param ic the ImageConsumer to be removed.
*/
public synchronized void removeConsumer(ImageConsumer ic) {
ics.removeElement(ic);
}
/**
* Adds an ImageConsumer to the list of consumers interested in
* data for this image, and immediately starts delivery of the
* image data through the ImageConsumer interface.
*
* @param ic the ImageConsumer to be added to the list of consumers.
*/
public synchronized void startProduction(ImageConsumer ic) {
addConsumer(ic);
// Need to build a runnable object for the Thread.
Thread thread = new Thread(this, "RenderableImageProducer Thread");
thread.start();
}
/**
* Requests that a given ImageConsumer have the image data delivered
* one more time in top-down, left-right order.
*
* @param ic the ImageConsumer requesting the resend.
*/
public void requestTopDownLeftRightResend(ImageConsumer ic) {
// So far, all pixels are already sent in TDLR order
}
/**
* The runnable method for this class. This will produce an image using
* the current RenderableImage and RenderContext and send it to all the
* ImageConsumer currently registered with this class.
*/
public void run() {
// First get the rendered image
RenderedImage rdrdImage;
if (rc != null) {
rdrdImage = rdblImage.createRendering(rc);
} else {
rdrdImage = rdblImage.createDefaultRendering();
}
// And its ColorModel
ColorModel colorModel = rdrdImage.getColorModel();
Raster raster = rdrdImage.getData();
SampleModel sampleModel = raster.getSampleModel();
DataBuffer dataBuffer = raster.getDataBuffer();
if (colorModel == null) {
colorModel = ColorModel.getRGBdefault();
}
int minX = raster.getMinX();
int minY = raster.getMinY();
int width = raster.getWidth();
int height = raster.getHeight();
Enumeration icList;
ImageConsumer ic;
// Set up the ImageConsumers
icList = ics.elements();
while (icList.hasMoreElements()) {
ic = (ImageConsumer)icList.nextElement();
ic.setDimensions(width,height);
ic.setHints(ImageConsumer.TOPDOWNLEFTRIGHT |
ImageConsumer.COMPLETESCANLINES |
ImageConsumer.SINGLEPASS |
ImageConsumer.SINGLEFRAME);
}
// Get RGB pixels from the raster scanline by scanline and
// send to consumers.
int pix[] = new int[width];
int i,j;
int numBands = sampleModel.getNumBands();
int tmpPixel[] = new int[numBands];
for (j = 0; j < height; j++) {
for(i = 0; i < width; i++) {
sampleModel.getPixel(i, j, tmpPixel, dataBuffer);
pix[i] = colorModel.getDataElement(tmpPixel, 0);
}
// Now send the scanline to the Consumers
icList = ics.elements();
while (icList.hasMoreElements()) {
ic = (ImageConsumer)icList.nextElement();
ic.setPixels(0, j, width, 1, colorModel, pix, 0, width);
}
}
// Now tell the consumers we're done.
icList = ics.elements();
while (icList.hasMoreElements()) {
ic = (ImageConsumer)icList.nextElement();
ic.imageComplete(ImageConsumer.STATICIMAGEDONE);
}
}
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* ********************************************************************
**********************************************************************
**********************************************************************
*** COPYRIGHT (c) Eastman Kodak Company, 1997 ***
*** As an unpublished work pursuant to Title 17 of the United ***
*** States Code. All rights reserved. ***
**********************************************************************
**********************************************************************
**********************************************************************/
package java.awt.image.renderable;
import java.awt.image.RenderedImage;
import java.awt.RenderingHints;
/**
* The RenderedImageFactory interface (often abbreviated RIF) is
* intended to be implemented by classes that wish to act as factories
* to produce different renderings, for example by executing a series
* of BufferedImageOps on a set of sources, depending on a specific
* set of parameters, properties, and rendering hints.
*/
public interface RenderedImageFactory {
/**
* Creates a RenderedImage representing the results of an imaging
* operation (or chain of operations) for a given ParameterBlock and
* RenderingHints. The RIF may also query any source images
* referenced by the ParameterBlock for their dimensions,
* SampleModels, properties, etc., as necessary.
*
* <p> The create() method can return null if the
* RenderedImageFactory is not capable of producing output for the
* given set of source images and parameters. For example, if a
* RenderedImageFactory is only capable of performing a 3x3
* convolution on single-banded image data, and the source image has
* multiple bands or the convolution Kernel is 5x5, null should be
* returned.
*
* <p> Hints should be taken into account, but can be ignored.
* The created RenderedImage may have a property identified
* by the String HINTS_OBSERVED to indicate which RenderingHints
* were used to create the image. In addition any RenderedImages
* that are obtained via the getSources() method on the created
* RenderedImage may have such a property.
*
* @param paramBlock a ParameterBlock containing sources and parameters
* for the RenderedImage to be created.
* @param hints a RenderingHints object containing hints.
* @return A RenderedImage containing the desired output.
*/
RenderedImage create(ParameterBlock paramBlock,
RenderingHints hints);
}