diff -urN jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/I18N.java zzx2/src/share/classes/com/sun/media/jai/imageioimpl/I18N.java
--- jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/I18N.java 2005-02-11 00:01:54.000000000 -0500
+++ zzx2/src/share/classes/com/sun/media/jai/imageioimpl/I18N.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,53 +0,0 @@
-/*
- * $RCSfile: I18N.java,v $
- *
- *
- * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for
- * use in the design, construction, operation or maintenance of any
- * nuclear facility.
- *
- * $Revision: 1.1 $
- * $Date: 2005/02/11 05:01:54 $
- * $State: Exp $
- */
-package com.sun.media.jai.imageioimpl;
-
-import com.sun.media.imageioimpl.common.I18NImpl;
-
-final class I18N extends I18NImpl {
- static String getString(String key) {
- return getString("com.sun.media.jai.imageioimpl.I18N", key);
- }
-}
diff -urN jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/ImageIOCollectionImage.java zzx2/src/share/classes/com/sun/media/jai/imageioimpl/ImageIOCollectionImage.java
--- jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/ImageIOCollectionImage.java 2005-02-11 00:01:54.000000000 -0500
+++ zzx2/src/share/classes/com/sun/media/jai/imageioimpl/ImageIOCollectionImage.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,74 +0,0 @@
-/*
- * $RCSfile: ImageIOCollectionImage.java,v $
- *
- *
- * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for
- * use in the design, construction, operation or maintenance of any
- * nuclear facility.
- *
- * $Revision: 1.1 $
- * $Date: 2005/02/11 05:01:54 $
- * $State: Exp $
- */
-package com.sun.media.jai.imageioimpl;
-
-import java.util.ArrayList;
-import javax.media.jai.CollectionImage;
-
-/**
- * A CollectionImage
to be used as the return value from
- * ImageReadCIF.create()
and ImageWriteCIF.create()
.
- * The imageCollection
instance variable is a List
.
- */
-class ImageIOCollectionImage extends CollectionImage {
- /**
- * Creates an ImageIOCollectionImage
with the specified
- * capacity.
- *
- * @exception IllegalArgumentException if capacity
is
- * not positive.
- */
- ImageIOCollectionImage(int capacity) {
- super();
-
- if(capacity <= 0) {
- // No message as this is not at the API level and it is
- // the unique exception.
- throw new IllegalArgumentException();
- }
-
- imageCollection = new ArrayList(capacity);
- }
-}
diff -urN jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/ImageReadCIF.java zzx2/src/share/classes/com/sun/media/jai/imageioimpl/ImageReadCIF.java
--- jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/ImageReadCIF.java 2005-02-11 00:01:54.000000000 -0500
+++ zzx2/src/share/classes/com/sun/media/jai/imageioimpl/ImageReadCIF.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,168 +0,0 @@
-/*
- * $RCSfile: ImageReadCIF.java,v $
- *
- *
- * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for
- * use in the design, construction, operation or maintenance of any
- * nuclear facility.
- *
- * $Revision: 1.1 $
- * $Date: 2005/02/11 05:01:54 $
- * $State: Exp $
- */
-package com.sun.media.jai.imageioimpl;
-
-import java.awt.Dimension;
-import java.awt.RenderingHints;
-import java.awt.image.renderable.ParameterBlock;
-import java.util.ArrayList;
-import java.util.List;
-import javax.imageio.ImageReader;
-import javax.media.jai.CollectionImage;
-import javax.media.jai.CollectionImageFactory;
-import javax.media.jai.CollectionOp;
-import javax.media.jai.JAI;
-import javax.media.jai.PlanarImage;
-import com.sun.media.jai.operator.ImageReadDescriptor;
-
-public class ImageReadCIF implements CollectionImageFactory {
-
- static CollectionImage createStatic(ParameterBlock args,
- RenderingHints hints) {
-
- // Clone the ParameterBlock as the ImageChoice will be overwritten.
- ParameterBlock renderedPB = (ParameterBlock)args.clone();
-
- // Get the ImageChoice.
- int[] imageIndices = (int[])args.getObjectParameter(1);
-
- // Variables to be set in the subsequent "if" block.
- // XXX Could probably collapse the if block into a single code seq.
- int numSources;
- ImageIOCollectionImage imageList = null;
-
- if(imageIndices == null) {
- // null-valued ImageChoice: load all images.
-
- // Load the first image.
- renderedPB.set(0, 1);
- PlanarImage image = JAI.create("ImageRead", renderedPB, hints);
-
- // Get the ImageReader property.
- Object readerProperty =
- image.getProperty(
- ImageReadDescriptor.PROPERTY_NAME_IMAGE_READER);
-
- // Try to read the number of images.
- if(readerProperty instanceof ImageReader) {
- try {
- // XXX Really should not allow search here. If search
- // is disallowed and -1 is returned from getNumImages(),
- // then "ImageRead" should just be called until an
- // IndexOutOfBoundsException is caught.
- numSources =
- ((ImageReader)readerProperty).getNumImages(true);
- } catch(Exception e) { // IOException
- // Default to one source.
- numSources = 1;
- }
- } else {
- numSources = 1;
- }
-
- // Allocate and fill index array.
- imageIndices = new int[numSources];
- for(int i = 0; i < numSources; i++) {
- imageIndices[i] = i;
- }
-
- // Allocate list and add first image.
- imageList = new ImageIOCollectionImage(numSources);
- imageList.add(image);
- } else {
- // Set the number of sources and create the list.
- numSources = imageIndices.length;
- imageList = new ImageIOCollectionImage(numSources);
-
- // Load the first image requested.
- renderedPB.set(imageIndices[0], 1);
- PlanarImage image = JAI.create("ImageRead", renderedPB, hints);
-
- // Add the first image to the list.
- imageList.add(image);
- }
-
- // Read subsequent images and add to the list.
- for(int idx = 1; idx < numSources; idx++) {
- renderedPB.set(imageIndices[idx], 1);
- PlanarImage image = JAI.create("ImageRead", renderedPB, hints);
- imageList.add(image);
- }
-
- // Get the first image in the Collection.
- PlanarImage firstImage = (PlanarImage)imageList.get(0);
-
- // Transfer properties to the Collection.
- ImageReadCRIF.copyProperty(firstImage,
- imageList,
- ImageReadDescriptor.PROPERTY_NAME_IMAGE_READ_PARAM);
- ImageReadCRIF.copyProperty(firstImage,
- imageList,
- ImageReadDescriptor.PROPERTY_NAME_IMAGE_READER);
- ImageReadCRIF.copyProperty(firstImage,
- imageList,
- ImageReadDescriptor.PROPERTY_NAME_METADATA_STREAM);
-
- return imageList;
- }
-
- /** Constructor. */
- public ImageReadCIF() {}
-
- public CollectionImage create(ParameterBlock args,
- RenderingHints hints) {
- return createStatic(args, hints);
- }
-
- // Forget it.
- public CollectionImage update(ParameterBlock oldParamBlock,
- RenderingHints oldHints,
- ParameterBlock newParamBlock,
- RenderingHints newHints,
- CollectionImage oldRendering,
- CollectionOp op) {
- return null;
- }
-}
diff -urN jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/ImageReadCRIF.java zzx2/src/share/classes/com/sun/media/jai/imageioimpl/ImageReadCRIF.java
--- jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/ImageReadCRIF.java 2005-11-30 19:39:04.000000000 -0500
+++ zzx2/src/share/classes/com/sun/media/jai/imageioimpl/ImageReadCRIF.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,434 +0,0 @@
-/*
- * $RCSfile: ImageReadCRIF.java,v $
- *
- *
- * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for
- * use in the design, construction, operation or maintenance of any
- * nuclear facility.
- *
- * $Revision: 1.2 $
- * $Date: 2005/12/01 00:39:04 $
- * $State: Exp $
- */
-package com.sun.media.jai.imageioimpl;
-
-import java.awt.Dimension;
-import java.awt.RenderingHints;
-import java.awt.geom.Rectangle2D;
-import java.awt.image.RenderedImage;
-import java.awt.image.renderable.ParameterBlock;
-import java.awt.image.renderable.RenderableImage;
-import java.awt.image.renderable.RenderContext;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.net.Socket;
-import java.net.URL;
-import java.nio.channels.Channel;
-import java.nio.channels.Channels;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.EventListener;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.TreeMap;
-import java.util.Vector;
-import javax.imageio.ImageIO;
-import javax.imageio.ImageReader;
-import javax.imageio.ImageReadParam;
-import javax.imageio.event.IIOReadProgressListener;
-import javax.imageio.event.IIOReadUpdateListener;
-import javax.imageio.event.IIOReadWarningListener;
-import javax.imageio.spi.ImageReaderSpi;
-import javax.imageio.stream.ImageInputStream;
-import javax.media.jai.CRIFImpl;
-import javax.media.jai.ImageLayout;
-import javax.media.jai.JAI;
-import javax.media.jai.MultiResolutionRenderableImage;
-import javax.media.jai.PropertySource;
-import javax.media.jai.WritablePropertySource;
-import com.sun.media.jai.operator.ImageReadDescriptor;
-
-public final class ImageReadCRIF extends CRIFImpl {
- public ImageReadCRIF() {
- super(); // Pass up the name?
- }
-
- /**
- * Attempt to create an {@link ImageInputStream} for the supplied
- * input. The following sequence is effected:
- *
input
is an ImageInputStream
it
- * is cast and returned.input
is a String
it is converted
- * to a read-only RandomAccessFile
.RandomAccessFile
fails, the
- * String
input
is converted to an
- * InputStream
by accessing it as a resource bundled
- * in a JAR file.input
is a URL
it is converted
- * to an InputStream
.input
is a Socket
it is converted
- * to an InputStream
.ImageIO.createImageInputStream()
is invoked
- * with parameter set to the (possibly converted) input and the
- * value it returns (which could be null
) is returned
- * to the caller.Object
to be used as the source,
- * such as a String
, URL
, File
,
- * readable RandomAccessFile
, InputStream
,
- * readable Socket
, or readable Channel
.
- *
- * @return An ImageInputStream
or null
.
- */
- private static ImageInputStream getImageInputStream(Object input) {
- // The value to be returned.
- ImageInputStream stream = null;
-
- // If already an ImageInputStream cast and return.
- if(input instanceof ImageInputStream) {
- stream = (ImageInputStream)input;
- } else {
- // If the input is a String replace it with a RandomAccessFile.
- if(input instanceof String) {
- try {
- // 'input' is conditionally checked for readability
- // in the OperationDescriptor.
- input = new RandomAccessFile((String)input, "r");
- } catch(Exception e) {
- // Try to get the file as an InputStream resource. This
- // would happen when the application and image file are
- // packaged in a JAR file
- input = ImageReadCRIF.class.getClassLoader().getResourceAsStream((String)input);
- if (input == null)
- throw new RuntimeException
- (I18N.getString("ImageReadCRIF0")+" "+input);
- }
- } else if(input instanceof URL) {
- // If the input is a URL replace it with an InputStream.
- try {
- input = ((URL)input).openStream();
- } catch(Exception e) {
- throw new RuntimeException
- (I18N.getString("ImageReadCRIF1")+" "+input);
- }
- } else if(input instanceof Socket) {
- // If output is a Socket replace it with an InputStream.
- try {
- Socket socket = (Socket)input;
- // XXX check binding, connection, closed, shutdown
- // as these could have changed.
- input = socket.getInputStream();
- } catch(Exception e) {
- throw new RuntimeException
- (I18N.getString("ImageReadCRIF2")+" "+input);
- }
- }
- }
-
- // Create the ImageInputStream.
- try {
- stream = ImageIO.createImageInputStream(input);
- } catch(Exception e) {
- throw new RuntimeException(e);
- }
-
- return stream;
- }
-
- /**
- * Get the ImageReader
and set its input and metadata flag.
- * The input set on the reader might not be the same object as the input
- * passed in if the latter was replaced by getImageInputStream().
- */
- static ImageReader getImageReader(ParameterBlock pb) {
- // Get the input.
- Object input = pb.getObjectParameter(0);
-
- // Get the reader parameter.
- ImageReader reader = (ImageReader)pb.getObjectParameter(8);
-
- // Attempt to create an ImageInputStream from the input.
- ImageInputStream stream = getImageInputStream(input);
-
- // If no reader passed in, try to find one.
- if(reader == null) {
- // Get all compatible readers.
- Iterator readers = ImageIO.getImageReaders(stream != null ?
- stream : input);
-
- // If any readers, take the first one whose originating
- // service provider indicates that it can decode the input.
- if(readers != null && readers.hasNext()) {
- do {
- ImageReader tmpReader = (ImageReader)readers.next();
- ImageReaderSpi readerSpi =
- tmpReader.getOriginatingProvider();
- try {
- if(readerSpi.canDecodeInput(stream != null ?
- stream : input)) {
- reader = tmpReader;
- }
- } catch(IOException ioe) {
- // XXX Ignore it?
- }
- } while(reader == null && readers.hasNext());
- }
- }
-
- // If reader found, set its input and metadata flag.
- if(reader != null) {
- // Get the locale parameter and set on the reader.
- Locale locale = (Locale)pb.getObjectParameter(6);
- if(locale != null) {
- reader.setLocale(locale);
- }
-
- // Get the listeners parameter and set on the reader.
- EventListener[] listeners =
- (EventListener[])pb.getObjectParameter(5);
- if(listeners != null) {
- for(int i = 0; i < listeners.length; i++) {
- EventListener listener = listeners[i];
- if(listener instanceof IIOReadProgressListener) {
- reader.addIIOReadProgressListener(
- (IIOReadProgressListener)listener);
- }
- if(listener instanceof IIOReadUpdateListener) {
- reader.addIIOReadUpdateListener(
- (IIOReadUpdateListener)listener);
- }
- if(listener instanceof IIOReadWarningListener) {
- reader.addIIOReadWarningListener(
- (IIOReadWarningListener)listener);
- }
- }
- }
-
- // Get the metadata reading flag.
- boolean readMetadata =
- ((Boolean)pb.getObjectParameter(2)).booleanValue();
-
- // Set the input and indicate metadata reading state.
- reader.setInput(stream != null ? stream : input,
- false, // seekForwardOnly
- !readMetadata); // ignoreMetadata
- }
-
- return reader;
- }
-
- static void copyProperty(PropertySource ps,
- WritablePropertySource wps,
- String propertyName) {
- Object propertyValue = ps.getProperty(propertyName);
-
- if(propertyValue != null &&
- !propertyValue.equals(java.awt.Image.UndefinedProperty)) {
- wps.setProperty(propertyName, propertyValue);
-
- }
- }
-
- public RenderedImage create(ParameterBlock pb,
- RenderingHints rh) {
-
- // Value to be returned.
- RenderedImage image = null;
-
- // Get the reader.
- ImageReader reader = getImageReader(pb);
-
- // Proceed if a compatible reader was found.
- if(reader != null) {
- // Get the remaining parameters required.
- int imageIndex = pb.getIntParameter(1);
- ImageReadParam param =
- (ImageReadParam)pb.getObjectParameter(7);
- boolean readThumbnails =
- ((Boolean)pb.getObjectParameter(3)).booleanValue();
-
- // Initialize the layout.
- ImageLayout layout =
- (rh != null && rh.containsKey(JAI.KEY_IMAGE_LAYOUT)) ?
- (ImageLayout)rh.get(JAI.KEY_IMAGE_LAYOUT) :
- new ImageLayout();
-
- try {
- // Get the parameter input.
- Object paramInput = pb.getObjectParameter(0);
-
- // Get the reader input.
- Object readerInput = reader.getInput();
-
- // Set the stream to close when the OpImage is disposed.
- ImageInputStream streamToClose = null;
- if(readerInput != paramInput &&
- readerInput instanceof ImageInputStream) {
- streamToClose = (ImageInputStream)readerInput;
- }
-
- // Create the rendering.
- image = new ImageReadOpImage(layout,
- rh,
- param,
- reader,
- imageIndex,
- readThumbnails,
- streamToClose);
- } catch(Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- return image;
- }
-
- // XXX This implementation of renderable mode is incredibly lame
- // but the architecture and implementation allow for nothing else.
- // It would be better if the CRIFs had some kind of state that
- // could be associated with them. As it standards getBounds2D()
- // will create a new MultiResolutionRenderableImage and so will
- // the second create() below. Actually what is needed is a
- // RenderableImageFactory definition.
- // XXX There is also a problem with multiple invocations of the
- // rendered mode case. Without saving and seeking back to the
- // same offset it appears to have problems. Should ImageReadOpImage
- // save the initial position and always seek back to it?
-
- public RenderableImage createRenderable(ParameterBlock pb,
- RenderingHints rh) {
-
- // Read the collection.
- Collection sequence = ImageReadCIF.createStatic(pb, rh);
-
- // Create a SortedMap which sorts on the basis of inverse area.
- // The keys will be Dimensions and the objects RenderedImages.
- TreeMap sourceMap = new TreeMap(new Comparator() {
- public int compare(Object o1, Object o2) {
- Dimension d1 = (Dimension)o1;
- Dimension d2 = (Dimension)o2;
-
- int area1 = d1.width*d1.height;
- int area2 = d2.width*d2.height;
-
- double inverse1 = area1 == 0 ?
- Double.MAX_VALUE : 1.0/area1;
- double inverse2 = area2 == 0 ?
- Double.MAX_VALUE : 1.0/area2;
-
- if(inverse1 < inverse2) {
- return -1;
- } else if(inverse1 > inverse2) {
- return 1;
- } else {
- return 0;
- }
- }
-
- public boolean equals(Object o1, Object o2) {
- return o1.equals(o2);
- }
- });
-
- Iterator images = sequence.iterator();
- while(images.hasNext()) {
- RenderedImage image = (RenderedImage)images.next();
- sourceMap.put(new Dimension(image.getWidth(), image.getHeight()),
- image);
- }
-
- // Create the rendered source list sorted by inverse area.
- Vector renderedSources = new Vector(sourceMap.size());
- Iterator keys = sourceMap.keySet().iterator();
- while(keys.hasNext()) {
- renderedSources.add(sourceMap.get(keys.next()));
- }
-
- // Create the RenderableImage from the sorted RenderedImages.
- MultiResolutionRenderableImage renderableImage =
- new MultiResolutionRenderableImage(renderedSources,
- 0.0F, 0.0F, 1.0F);
-
- // Set properties from those of the first rendered source.
- PropertySource firstSource = (PropertySource)renderedSources.get(0);
- copyProperty(firstSource,
- renderableImage,
- ImageReadDescriptor.PROPERTY_NAME_IMAGE_READ_PARAM);
- copyProperty(firstSource,
- renderableImage,
- ImageReadDescriptor.PROPERTY_NAME_IMAGE_READER);
- copyProperty(firstSource,
- renderableImage,
- ImageReadDescriptor.PROPERTY_NAME_METADATA_STREAM);
- copyProperty(firstSource,
- renderableImage,
- ImageReadDescriptor.PROPERTY_NAME_METADATA_IMAGE);
-
- // Return the RenderableImage.
- return renderableImage;
- }
-
- public RenderedImage create(RenderContext rc,
- ParameterBlock pb) {
-
- RenderableImage renderableImage =
- createRenderable(pb, rc.getRenderingHints());
-
- RenderedImage renderedImage = renderableImage.createRendering(rc);
-
- ((WritablePropertySource)renderedImage).setProperty(
- ImageReadDescriptor.PROPERTY_NAME_RENDERABLE_INPUT,
- (PropertySource)renderableImage);
-
- return renderedImage;
- }
-
- public Rectangle2D getBounds2D(ParameterBlock pb) {
- // XXX Should just get the aspect ratio of the first image and use it.
- // Otherwise this will be very inefficient.
- RenderableImage renderable = createRenderable(pb, null);
-
- return new Rectangle2D.Float(renderable.getMinX(),
- renderable.getMinY(),
- renderable.getWidth(),
- renderable.getHeight());
- }
-}
diff -urN jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/ImageReadOpImage.java zzx2/src/share/classes/com/sun/media/jai/imageioimpl/ImageReadOpImage.java
--- jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/ImageReadOpImage.java 2006-07-14 17:43:57.000000000 -0400
+++ zzx2/src/share/classes/com/sun/media/jai/imageioimpl/ImageReadOpImage.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,914 +0,0 @@
-/*
- * $RCSfile: ImageReadOpImage.java,v $
- *
- *
- * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for
- * use in the design, construction, operation or maintenance of any
- * nuclear facility.
- *
- * $Revision: 1.2 $
- * $Date: 2006/07/14 21:43:57 $
- * $State: Exp $
- */
-package com.sun.media.jai.imageioimpl;
-
-import java.awt.Dimension;
-import java.awt.Point;
-import java.awt.Rectangle;
-import java.awt.image.BufferedImage;
-import java.awt.image.ColorModel;
-import java.awt.image.Raster;
-import java.awt.image.SampleModel;
-import java.awt.image.WritableRaster;
-import java.io.InputStream;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.Map;
-import javax.imageio.ImageReader;
-import javax.imageio.ImageReadParam;
-import javax.imageio.ImageTypeSpecifier;
-import javax.imageio.metadata.IIOMetadata;
-import javax.imageio.spi.ImageReaderSpi;
-import javax.imageio.stream.ImageInputStream;
-import javax.media.jai.ImageLayout;
-import javax.media.jai.OpImage;
-import com.sun.media.jai.operator.ImageReadDescriptor;
-
-/**
- * Implementation of the OpImage
of the "ImageRead" operation.
- */
-final class ImageReadOpImage extends OpImage {
-
- /**
- * XXX For testing only.
- */
- /* XXX
- public static void main(String[] args) throws Throwable {
- java.io.File file = new java.io.File(args[0]);
- int imageIndex = args.length > 1 ?
- Integer.valueOf(args[1]).intValue() : 0;
- int tileSize = args.length > 2 ?
- Integer.valueOf(args[2]).intValue() : 128;
-
- javax.imageio.stream.ImageInputStream stream =
- new javax.imageio.stream.FileImageInputStream(file);
-
- Iterator iter = javax.imageio.ImageIO.getImageReaders(stream);
- ImageReader imageReader = (ImageReader)iter.next();
- imageReader.setInput(stream,
- true, // seekForwardOnly
- false); // ignoreMetadata
-
- ImageLayout layout = new ImageLayout();
- layout.setTileWidth(tileSize).setTileHeight(tileSize);
- //layout.setTileGridXOffset(42).setTileGridYOffset(7);
-
- ImageReadParam param = imageReader.getDefaultReadParam();
- param.setSourceSubsampling(2, 2, 0, 0);
- param.setSourceRegion(new Rectangle(128, 0, 256, 256));
- param.setSourceBands(new int[] {2, 1, 0});
- param.setDestinationBands(new int[] {0, 1, 2});
-
- OpImage image = new ImageReadOpImage(layout, // ImageLayout
- null, // Map
- param, // ImageReadParam
- imageReader,
- imageIndex,
- true,
- null); // streamToClose
-
- System.out.println(new ImageLayout(image));
-
- System.out.println("\nImage Properties:");
- String[] propNames = image.getPropertyNames();
- if(propNames != null) {
- for(int i = 0; i < propNames.length; i++) {
- System.out.println(i+" "+propNames[i]+" = "+
- image.getProperty(propNames[i]));
- }
- }
- System.out.println("");
-
- BufferedImage[] thumbnails = null;
- Object thumbnailProp =
- image.getProperty(ImageReadDescriptor.PROPERTY_NAME_THUMBNAILS);
- if(thumbnailProp != java.awt.Image.UndefinedProperty) {
- thumbnails = (BufferedImage[])thumbnailProp;
- }
-
- java.awt.Frame frame =
- new java.awt.Frame("ImageReadOpImage Test: "+file);
- if(thumbnails != null) {
- frame.setLayout(new java.awt.GridLayout(1, thumbnails.length+1));
- }
-
- frame.add(new javax.media.jai.widget.ScrollingImagePanel(image,
- image.getWidth(),
- image.getHeight()));
- if(thumbnails != null) {
- for(int i= 0; i < thumbnails.length; i++) {
- frame.add(new javax.media.jai.widget.ScrollingImagePanel(thumbnails[i],
- thumbnails[i].getWidth(),
- thumbnails[i].getHeight()));
- }
- }
- frame.pack();
- frame.show();
- }
- */
-
- /**
- * The ImageReadParam
used in reading the image.
- */
- private ImageReadParam param;
-
- /**
- * The ImageReader
used to read the image.
- */
- private ImageReader reader;
-
- /**
- * The index of the image to be read.
- */
- private int imageIndex;
-
- /**
- * Whether thumbnails are to be read.
- */
- private boolean readThumbnails;
-
- /**
- * Whether stream metadata have been be read.
- */
- private boolean streamMetadataRead = false;
-
- /**
- * Whether image metadata have been be read.
- */
- private boolean imageMetadataRead = false;
-
- /**
- * A stream to be closed when the instance is disposed; may be null.
- */
- private ImageInputStream streamToClose;
-
- /**
- * Destination to source X scale factor.
- */
- private int scaleX;
-
- /**
- * Destination to source Y scale factor.
- */
- private int scaleY;
-
- /**
- * Destination to source X translation factor.
- */
- private int transX;
-
- /**
- * Destination to source Y translation factor.
- */
- private int transY;
-
- /**
- * Derive the image layout based on the user-supplied layout,
- * reading parameters, and image index.
- */
- private static ImageLayout layoutHelper(ImageLayout il,
- ImageReadParam param,
- ImageReader reader,
- int imageIndex)
- throws IOException {
- ImageLayout layout = (il == null) ?
- new ImageLayout() : (ImageLayout)il.clone();
-
- // --- Determine the image type. ---
-
- // If not provided in the original layout, set the SampleModel
- // and ColorModel from the ImageReadParam, if supplied.
- if(!layout.isValid(ImageLayout.SAMPLE_MODEL_MASK) &&
- !layout.isValid(ImageLayout.COLOR_MODEL_MASK)) {
- // If an ImageReadParam has been supplied and has its
- // destinationType set then use it. Otherwise default to
- // the raw image type.
- ImageTypeSpecifier imageType =
- (param != null && param.getDestinationType() != null) ?
- param.getDestinationType() :
- reader.getRawImageType(imageIndex);
-
- // XXX The following block of code should not be necessary
- // but for J2SE 1.4.0 FCS ImageReader.getRawImageType(0)
- // returns null for earth.jpg, Bas-noir.jpg, etc.
- if(imageType == null) {
- Iterator imageTypes = reader.getImageTypes(imageIndex);
- while(imageType == null && imageTypes.hasNext()) {
- imageType = (ImageTypeSpecifier)imageTypes.next();
- }
- }
-
- // XXX Should an exception be thrown if imageType is null?
- if(imageType != null) {
- // Set the SampleModel and ColorModel.
- layout.setSampleModel(imageType.getSampleModel());
- layout.setColorModel(imageType.getColorModel());
- }
- }
-
- // --- Set up the destination bounds. ---
-
- // Calculate the computable destination bounds.
- Dimension sourceSize = getSourceSize(param, reader, imageIndex);
- Rectangle srcRegion = new Rectangle();
- Rectangle destRegion = new Rectangle();
- computeRegions(param,
- sourceSize.width,
- sourceSize.height,
- layout.getMinX(null), // valid value or 0
- layout.getMinY(null), // valid value or 0
- false,
- srcRegion,
- destRegion);
-
- if(!destRegion.isEmpty()) {
- // Backup layout image bounds with computable bounds.
- if(!layout.isValid(ImageLayout.WIDTH_MASK)) {
- layout.setWidth(destRegion.width);
- }
- if(!layout.isValid(ImageLayout.HEIGHT_MASK)) {
- layout.setHeight(destRegion.height);
- }
- if(!layout.isValid(ImageLayout.MIN_X_MASK)) {
- layout.setMinX(destRegion.x);
- }
- if(!layout.isValid(ImageLayout.MIN_Y_MASK)) {
- layout.setMinY(destRegion.y);
- }
-
- // Ensure the layout bounds intersect computable bounds.
- Rectangle destBounds = new Rectangle(layout.getMinX(null),
- layout.getMinY(null),
- layout.getWidth(null),
- layout.getHeight(null));
- if(destRegion.intersection(destBounds).isEmpty()) {
- throw new IllegalArgumentException
- (I18N.getString("ImageReadOpImage0"));
- }
- }
-
- // --- Set up the tile grid. ---
-
- if(!layout.isValid(ImageLayout.TILE_GRID_X_OFFSET_MASK)) {
- layout.setTileGridXOffset(reader.getTileGridXOffset(imageIndex));
- }
- if(!layout.isValid(ImageLayout.TILE_GRID_Y_OFFSET_MASK)) {
- layout.setTileGridYOffset(reader.getTileGridYOffset(imageIndex));
- }
- if(!layout.isValid(ImageLayout.TILE_WIDTH_MASK)) {
- layout.setTileWidth(reader.getTileWidth(imageIndex));
- }
- if(!layout.isValid(ImageLayout.TILE_HEIGHT_MASK)) {
- layout.setTileHeight(reader.getTileHeight(imageIndex));
- }
-
- return layout;
- }
-
- /**
- * Returns whether an ImageTypeSpecifier
may be used
- * to read in the image at a specified index.
- *
- * XXX
- */
- private static boolean isCompatibleType(ImageTypeSpecifier imageType,
- ImageReader reader,
- int imageIndex)
- throws IOException {
- Iterator imageTypes = reader.getImageTypes(imageIndex);
-
- boolean foundIt = false;
- while (imageTypes.hasNext()) {
- ImageTypeSpecifier type =
- (ImageTypeSpecifier)imageTypes.next();
- if (type.equals(imageType)) {
- foundIt = true;
- break;
- }
- }
-
- return foundIt;
- }
-
- /**
- * Returns the source region to be read. If the sourceRenderSize
- * is being used it is returned; otherwise the raw source dimensions
- * are returned.
- *
- * XXX
- */
- private static Dimension getSourceSize(ImageReadParam param,
- ImageReader reader,
- int imageIndex)
- throws IOException {
- Dimension sourceSize = null;
- if(param != null && param.canSetSourceRenderSize()) {
- sourceSize = param.getSourceRenderSize();
- }
- if(sourceSize == null) {
- sourceSize = new Dimension(reader.getWidth(imageIndex),
- reader.getHeight(imageIndex));
- }
- return sourceSize;
- }
-
- /**
- * XXX
- */
- // Code copied from ImageReader.java
- private static Rectangle getSourceRegion(ImageReadParam param,
- int srcWidth,
- int srcHeight) {
- Rectangle sourceRegion = new Rectangle(0, 0, srcWidth, srcHeight);
- if (param != null) {
- Rectangle region = param.getSourceRegion();
- if (region != null) {
- sourceRegion = sourceRegion.intersection(region);
- }
-
- int subsampleXOffset = param.getSubsamplingXOffset();
- int subsampleYOffset = param.getSubsamplingYOffset();
- sourceRegion.x += subsampleXOffset;
- sourceRegion.y += subsampleYOffset;
- sourceRegion.width -= subsampleXOffset;
- sourceRegion.height -= subsampleYOffset;
- }
-
- return sourceRegion;
- }
-
- /**
- * XXX
- */
- // clipDestRegion: whether to clip destRegion to positive coordinates.
- // Code based on method of same name in ImageReader.java
- private static void computeRegions(ImageReadParam param,
- int srcWidth,
- int srcHeight,
- int destMinX,
- int destMinY,
- boolean clipDestRegion,
- Rectangle srcRegion,
- Rectangle destRegion) {
- if (srcRegion == null) {
- throw new IllegalArgumentException("srcRegion == null");
- }
- if (destRegion == null) {
- throw new IllegalArgumentException("destRegion == null");
- }
-
- // Start with the entire source image
- srcRegion.setBounds(0, 0, srcWidth, srcHeight);
-
- // Destination also starts with source image, as that is the
- // maximum extent if there is no subsampling
- destRegion.setBounds(destMinX, destMinY, srcWidth, srcHeight);
-
- // Clip that to the param region, if there is one
- int periodX = 1;
- int periodY = 1;
- int gridX = 0;
- int gridY = 0;
- if (param != null) {
- Rectangle paramSrcRegion = param.getSourceRegion();
- if (paramSrcRegion != null) {
- srcRegion.setBounds(srcRegion.intersection(paramSrcRegion));
- }
- periodX = param.getSourceXSubsampling();
- periodY = param.getSourceYSubsampling();
- gridX = param.getSubsamplingXOffset();
- gridY = param.getSubsamplingYOffset();
- srcRegion.translate(gridX, gridY);
- srcRegion.width -= gridX;
- srcRegion.height -= gridY;
- Point destinationOffset = param.getDestinationOffset();
- destRegion.translate(destinationOffset.x, destinationOffset.y);
- }
-
- if(clipDestRegion) {
- // Now clip any negative destination offsets, i.e. clip
- // to the top and left of the destination image
- if (destRegion.x < 0) {
- int delta = -destRegion.x*periodX;
- srcRegion.x += delta;
- srcRegion.width -= delta;
- destRegion.x = 0;
- }
- if (destRegion.y < 0) {
- int delta = -destRegion.y*periodY;
- srcRegion.y += delta;
- srcRegion.height -= delta;
- destRegion.y = 0;
- }
- }
-
- // Now clip the destination Region to the subsampled width and height
- int subsampledWidth = (srcRegion.width + periodX - 1)/periodX;
- int subsampledHeight = (srcRegion.height + periodY - 1)/periodY;
- destRegion.width = subsampledWidth;
- destRegion.height = subsampledHeight;
-
- if (srcRegion.isEmpty() || destRegion.isEmpty()) {
- throw new IllegalArgumentException
- (I18N.getString("ImageReadOpImage1"));
- }
- }
-
- /**
- * XXX
- * NB: This class may reset the following fields of the ImageReadParam
- * destinationOffset
- * destinationType
- * sourceRegion
- */
- ImageReadOpImage(ImageLayout layout,
- Map configuration,
- ImageReadParam param,
- ImageReader reader,
- int imageIndex,
- boolean readThumbnails,
- ImageInputStream streamToClose) throws IOException {
- super(null,
- layoutHelper(layout, param, reader, imageIndex),
- configuration,
- false);
-
- // Revise parameter 'param' as needed.
- if(param == null) {
- // Get the ImageReadParam from the ImageReader.
- param = reader.getDefaultReadParam();
- } else if(param instanceof Cloneable) {
- this.param = param;
- } else if(param.getClass().getName().equals(
- "javax.imageio.ImageReadParam")) {
- // The ImageReadParam passed in is non-null. As the
- // ImageReadParam class is not Cloneable, if the param
- // class is simply ImageReadParam, then create a new
- // ImageReadParam instance and set all its fields
- // which were set in param. This will eliminate problems
- // with concurrent modification of param for the cases
- // in which there is not a special ImageReadparam used.
-
- // Create a new ImageReadParam instance.
- ImageReadParam newParam = new ImageReadParam();
-
- // Set all fields which need to be set.
-
- // IIOParamController field.
- if(param.hasController()) {
- newParam.setController(param.getController());
- }
-
- // Destination fields.
- newParam.setDestination(param.getDestination());
- if(param.getDestinationType() != null) {
- // Set the destination type only if non-null as the
- // setDestinationType() clears the destination field.
- newParam.setDestinationType(param.getDestinationType());
- }
- newParam.setDestinationBands(param.getDestinationBands());
- newParam.setDestinationOffset(param.getDestinationOffset());
-
- // Source fields.
- newParam.setSourceBands(param.getSourceBands());
- newParam.setSourceRegion(param.getSourceRegion());
- if(param.getSourceMaxProgressivePass() != Integer.MAX_VALUE) {
- newParam.setSourceProgressivePasses(
- param.getSourceMinProgressivePass(),
- param.getSourceNumProgressivePasses());
- }
- if(param.canSetSourceRenderSize()) {
- newParam.setSourceRenderSize(param.getSourceRenderSize());
- }
- newParam.setSourceSubsampling(param.getSourceXSubsampling(),
- param.getSourceYSubsampling(),
- param.getSubsamplingXOffset(),
- param.getSubsamplingYOffset());
-
- // Replace the local variable with the new ImageReadParam.
- param = newParam;
- }
-
- // Revise parameter 'readThumbnails' as needed.
- if(readThumbnails && !reader.hasThumbnails(imageIndex)) {
- // Unset thumbnail flag if not supported by ImageReader.
- readThumbnails = false;
- }
-
- // Set instance variables from (possibly revised) parameters.
- this.param = param;
- this.reader = reader;
- this.imageIndex = imageIndex;
- this.readThumbnails = readThumbnails;
- this.streamToClose = streamToClose;
-
- // If an ImageTypeSpecifier is specified in the ImageReadParam
- // but it is incompatible with the ImageReader, then attempt to
- // replace it with a compatible one derived from this image.
- if(param.getDestinationType() != null &&
- !isCompatibleType(param.getDestinationType(), reader, imageIndex) &&
- sampleModel != null && colorModel != null) {
- ImageTypeSpecifier newImageType =
- new ImageTypeSpecifier(colorModel, sampleModel);
- if(isCompatibleType(newImageType, reader, imageIndex)) {
- param.setDestinationType(newImageType);
- }
- }
-
- // --- Compute the destination to source mapping coefficients. ---
-
- Dimension sourceSize = getSourceSize(param, reader, imageIndex);
-
- Rectangle srcRegion = getSourceRegion(param,
- sourceSize.width,
- sourceSize.height);
-
- Point destinationOffset = this.param.getDestinationOffset();
-
- this.scaleX = this.param.getSourceXSubsampling();
- this.scaleY = this.param.getSourceYSubsampling();
- this.transX =
- srcRegion.x + this.param.getSubsamplingXOffset() -
- this.param.getSourceXSubsampling()*(minX + destinationOffset.x);
- this.transY =
- srcRegion.y + this.param.getSubsamplingYOffset() -
- this.param.getSourceYSubsampling()*(minY + destinationOffset.y);
-
- // Replace the original destination offset with (0,0) as the
- // destination-to-source mapping assimilates this value.
- this.param.setDestinationOffset(new Point());
- // XXX Need to unset other ImageReadParam settings either here
- // or in computeTile(). Examine this issue taking into account
- // synchronization.
-
- // Set the ImageReadParam property.
- setProperty(ImageReadDescriptor.PROPERTY_NAME_IMAGE_READ_PARAM, param);
-
- // Set the ImageReader property.
- setProperty(ImageReadDescriptor.PROPERTY_NAME_IMAGE_READER, reader);
-
- // If metadata are being read, set the value of the metadata
- // properties to UndefinedProperty so that the property
- // names will appear in the array of property names. The actual
- // values will be retrieved when getProperty() is invoked.
- if(!reader.isIgnoringMetadata()) {
- // Get the service provider interface, if any.
- ImageReaderSpi provider = reader.getOriginatingProvider();
-
- // Stream metadata.
- if(provider == null ||
- provider.isStandardStreamMetadataFormatSupported() ||
- provider.getNativeStreamMetadataFormatName() != null) {
- // Assume an ImageReader with a null provider supports
- // stream metadata.
- setProperty(ImageReadDescriptor.PROPERTY_NAME_METADATA_STREAM,
- java.awt.Image.UndefinedProperty);
- } else {
- // Provider supports neither standard nor native stream
- // metadata so set flag to suppress later reading attempt.
- streamMetadataRead = true;
- }
-
- // Image metadata.
- if(provider == null ||
- provider.isStandardImageMetadataFormatSupported() ||
- provider.getNativeImageMetadataFormatName() != null) {
- // Assume an ImageReader with a null provider supports
- // image metadata.
- setProperty(ImageReadDescriptor.PROPERTY_NAME_METADATA_IMAGE,
- java.awt.Image.UndefinedProperty);
- } else {
- // Provider supports neither standard nor native image
- // metadata so set flag to suppress later reading attempt.
- imageMetadataRead = true;
- }
- }
-
- // If thumbnail read flag is set, set the value of the thumbnail
- // property to UndefinedProperty so that the thumbnail property
- // name will appear in the array of property names. The actual
- // value will be retrieved when getProperty() is invoked.
- if(readThumbnails && reader.readerSupportsThumbnails()) {
- setProperty(ImageReadDescriptor.PROPERTY_NAME_THUMBNAILS,
- java.awt.Image.UndefinedProperty);
- }
- }
-
- /**
- * Returns false as ImageReaders might return Rasters
- * via computeTile() tile that are internally cached.
- */
- public boolean computesUniqueTiles() {
- return false;
- }
-
- /**
- * XXX
- */
- private Rectangle computeSourceRect(Rectangle destRect) {
- Rectangle sourceRect = new Rectangle();
-
- sourceRect.x = scaleX*destRect.x + transX;
- sourceRect.y = scaleY*destRect.y + transY;
-
- sourceRect.width =
- scaleX*(destRect.x + destRect.width) + transX - sourceRect.x;
- sourceRect.height =
- scaleY*(destRect.y + destRect.height) + transY - sourceRect.y;
-
- return sourceRect;
- }
-
- /**
- * Computes a tile.
- *
- * @param tileX The X index of the tile.
- * @param tileY The Y index of the tile.
- */
- public Raster computeTile(int tileX, int tileY) {
- //XXX System.out.println("Tile ("+tileX+","+tileY+")");
- // Create a new WritableRaster to represent this tile.
- Point org = new Point(tileXToX(tileX), tileYToY(tileY));
- //WritableRaster dest = Raster.createWritableRaster(sampleModel, org);
- Rectangle rect = new Rectangle(org.x, org.y, tileWidth, tileHeight);
-
- // Clip output rectangle to image bounds.
- // Not sure what will happen here with the bounds intersection.
- Rectangle destRect = rect.intersection(getBounds());
- // XXX Check for destRect.isEmpty()?
-
- /* XXX delete
- java.awt.geom.AffineTransform transform =
- new java.awt.geom.AffineTransform(scaleX, 0, 0, scaleY,
- transX, transY);
- */
- Rectangle srcRect =
- computeSourceRect(destRect);
- /* XXX delete
- transform.createTransformedShape(destRect).getBounds();
- */
-
- WritableRaster readerTile = null;
- try {
- synchronized(reader) {
- param.setSourceRegion(srcRect);
- BufferedImage bi = reader.read(imageIndex, param);
- WritableRaster ras = bi.getRaster();
- readerTile = ras.createWritableChild(0, 0,
- ras.getWidth(),
- ras.getHeight(),
- org.x, org.y,
- null);
- }
- } catch(IOException e) {
- throw new RuntimeException(e);
- }
-
- WritableRaster tile = null;
- if(sampleModel == readerTile.getSampleModel()) {
- tile = readerTile;
- } else {
- // XXX As this method is synchronized, could a single
- // destination be supplied to the reader instead of
- // creating a new one?
- tile = Raster.createWritableRaster(sampleModel, org);
- tile.setRect(readerTile);
- }
-
- return tile;
- }
-
- /**
- * Throws an IllegalArgumentException since the image has no image
- * sources.
- *
- * @param sourceRect ignored.
- * @param sourceIndex ignored.
- *
- * @throws IllegalArgumentException since the image has no sources.
- */
- public Rectangle mapSourceRect(Rectangle sourceRect,
- int sourceIndex) {
- throw new IllegalArgumentException
- (I18N.getString("ImageReadOpImage2"));
- }
-
- /**
- * Throws an IllegalArgumentException since the image has no image
- * sources.
- *
- * @param destRect ignored.
- * @param sourceIndex ignored.
- *
- * @throws IllegalArgumentException since the image has no sources.
- */
- public Rectangle mapDestRect(Rectangle destRect,
- int sourceIndex) {
- throw new IllegalArgumentException
- (I18N.getString("ImageReadOpImage2"));
- }
-
- /**
- * Gets a property from the property set of this image. If the
- * property name is not recognized,
- * java.awt.Image.UndefinedProperty
will be returned.
- *
- * This implementation first attempts to retrieve the property - * using the equivalent superclass method. If the returned value - * is not a valid property value, the requested property name is - * that of the image thumbnails property, the stream metadata - * property, or the image metadata property, and there has been no - * prior attempt to read the corresponding property value, then its - * reads the value and set the property. This implementation therefore - * defers reading of the image thumbnails, stream metadata, and image - * metadata values until the correpsonding property is actually - * requested.
- * - * @param name the name of the property to get, as aString
.
- *
- * @return A reference to the property Object
, or the value
- * java.awt.Image.UndefinedProperty
.
- *
- * @exception IllegalArgumentException if propertyName
- * is null
.
- */
- public Object getProperty(String name) {
- // Attempt to get property from superclass method.
- Object property = super.getProperty(name);
-
- // If thumbnail property name with undefined value and thumbnails
- // are being read and an attempt to read them has not already been
- // made, then read the thumbnails and set the property.
- if((property == null ||
- property == java.awt.Image.UndefinedProperty)) {
-
- // Thumbnails
- if(readThumbnails &&
- name.equalsIgnoreCase(
- ImageReadDescriptor.PROPERTY_NAME_THUMBNAILS)) {
-
- // Lock the class to avoid a race condition here
- // and with computeTile().
- synchronized(reader) {
- // First re-check the flag in case another thread
- // got here first.
- if(readThumbnails) {
- try {
- // Get number of thumbnails.
- int numThumbnails =
- reader.getNumThumbnails(imageIndex);
-
- if(numThumbnails > 0) {
- // Read all thumbnails.
- BufferedImage[] thumbnails =
- new BufferedImage[numThumbnails];
- for(int i = 0; i < numThumbnails; i++) {
- thumbnails[i] =
- reader.readThumbnail(imageIndex, i);
- }
-
- // Set thumbnail property.
- setProperty(
- ImageReadDescriptor.PROPERTY_NAME_THUMBNAILS,
- thumbnails);
-
- // Update return value.
- property = thumbnails;
- }
- } catch(IOException e) {
- throw new RuntimeException(e);
- } finally {
- // If return value is somehow null set it
- // to UndefinedProperty.
- if(property == null) {
- property = java.awt.Image.UndefinedProperty;
- }
-
- // Unset thumbnail flag to avert subsequent
- // reading attempts in case this one failed.
- readThumbnails = false;
- }
- }
- }
- } else if(!reader.isIgnoringMetadata() &&
- ((!streamMetadataRead &&
- name.equalsIgnoreCase(
- ImageReadDescriptor.PROPERTY_NAME_METADATA_STREAM)) ||
- (!imageMetadataRead &&
- name.equalsIgnoreCase(
- ImageReadDescriptor.PROPERTY_NAME_METADATA_IMAGE)))) {
-
- // Lock the class to avoid a race condition here
- // and with computeTile().
- synchronized(reader) {
-
- // Set flag to indicate stream or image metadata.
- boolean isStreamMetadata =
- name.equalsIgnoreCase(
- ImageReadDescriptor.PROPERTY_NAME_METADATA_STREAM);
-
- // Recheck the appropriate flag.
- if(!(isStreamMetadata ?
- streamMetadataRead : imageMetadataRead)) {
-
- // Set property name.
- String propertyName = isStreamMetadata ?
- ImageReadDescriptor.PROPERTY_NAME_METADATA_STREAM :
- ImageReadDescriptor.PROPERTY_NAME_METADATA_IMAGE;
-
- IIOMetadata metadata = null;
- try {
- // Read metadata.
- metadata = isStreamMetadata ?
- reader.getStreamMetadata() :
- reader.getImageMetadata(imageIndex);
-
- // Set metadata property.
- if(metadata != null) {
- setProperty(propertyName, metadata);
- }
-
- // Update return value.
- property = metadata;
- } catch(IOException e) {
- throw new RuntimeException(e);
- } finally {
- // If return value is somehow null set it
- // to UndefinedProperty.
- if(property == null) {
- property = java.awt.Image.UndefinedProperty;
- }
-
- // Set appropriate flag to avert subsequent
- // reading attempts in case this one failed.
- if(isStreamMetadata) {
- streamMetadataRead = true;
- } else {
- imageMetadataRead = true;
- }
- }
- }
- }
- }
- }
-
- return property;
- }
-
- /**
- * Closes an ImageInputStream
passed in, if any.
- */
- public void dispose() {
- if(streamToClose != null) {
- try {
- streamToClose.close();
- } catch(IOException e) {
- // Ignore it.
- }
- }
-
- super.dispose();
- }
-}
diff -urN jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/ImageReadWriteSpi.java zzx2/src/share/classes/com/sun/media/jai/imageioimpl/ImageReadWriteSpi.java
--- jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/ImageReadWriteSpi.java 2005-02-11 00:01:55.000000000 -0500
+++ zzx2/src/share/classes/com/sun/media/jai/imageioimpl/ImageReadWriteSpi.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,142 +0,0 @@
-/*
- * $RCSfile: ImageReadWriteSpi.java,v $
- *
- *
- * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for
- * use in the design, construction, operation or maintenance of any
- * nuclear facility.
- *
- * $Revision: 1.1 $
- * $Date: 2005/02/11 05:01:55 $
- * $State: Exp $
- */
-package com.sun.media.jai.imageioimpl;
-
-import java.awt.image.renderable.ContextualRenderedImageFactory;
-import javax.media.jai.CollectionImageFactory;
-import javax.media.jai.OperationDescriptor;
-import javax.media.jai.OperationRegistry;
-import javax.media.jai.OperationRegistrySpi;
-import com.sun.media.jai.operator.ImageReadDescriptor;
-import com.sun.media.jai.operator.ImageWriteDescriptor;
-import javax.media.jai.registry.CollectionRegistryMode;
-import javax.media.jai.registry.RenderableRegistryMode;
-import javax.media.jai.registry.RenderedRegistryMode;
-
-/**
- * {@link OperationRegistrySpi} implementation to register the "ImageRead"
- * and "ImageWrite" operations and their associated image factories.
- */
-public class ImageReadWriteSpi implements OperationRegistrySpi {
-
- /** The name of the product to which these operations belong. */
- private String productName = "com.sun.media.jai";
-
- /** Default constructor. */
- public ImageReadWriteSpi() {}
-
- /**
- * Registers the "ImageRead" and "ImageWrite" operations and their
- * associated image factories across all supported operation modes.
- * An {@link OperationDescriptor} is created for each operation and
- * registered with the supplied {@link OperationRegistry}. An image
- * factory is then created for each supported mode of each operation
- * registered for that operation with the registry.
- *
- * @param registry The registry with which to register the operations
- * and their factories.
- */
- public void updateRegistry(OperationRegistry registry) {
- // Create the "ImageRead" descriptor instance.
- OperationDescriptor readDescriptor = new ImageReadDescriptor();
-
- // Register the "ImageRead" descriptor.
- registry.registerDescriptor(readDescriptor);
-
- // Create the "ImageRead" CRIF.
- ContextualRenderedImageFactory readCRIF = new ImageReadCRIF();
-
- // Get the "ImageRead" operation name.
- String imageReadName = readDescriptor.getName();
-
- // Register the "ImageRead" factory for rendered mode.
- registry.registerFactory(RenderedRegistryMode.MODE_NAME,
- imageReadName,
- productName,
- readCRIF);
-
- // Register the "ImageRead" factory for renderable mode.
- registry.registerFactory(RenderableRegistryMode.MODE_NAME,
- imageReadName,
- productName,
- readCRIF);
-
- // Create and register the "ImageRead" factory for collection mode.
- registry.registerFactory(CollectionRegistryMode.MODE_NAME,
- imageReadName,
- productName,
- new ImageReadCIF());
-
- // Create the "ImageWrite" descriptor instance.
- OperationDescriptor writeDescriptor = new ImageWriteDescriptor();
-
- // Register the "ImageWrite" descriptor.
- registry.registerDescriptor(writeDescriptor);
-
- // Create the "ImageWrite" CRIF.
- ContextualRenderedImageFactory writeCRIF = new ImageWriteCRIF();
-
- // Get the "ImageWrite" operation name.
- String imageWriteName = writeDescriptor.getName();
-
- // Register the "ImageWrite" factory for rendered mode.
- registry.registerFactory(RenderedRegistryMode.MODE_NAME,
- imageWriteName,
- productName,
- writeCRIF);
-
- // Register the "ImageWrite" factory for renderable mode.
- registry.registerFactory(RenderableRegistryMode.MODE_NAME,
- imageWriteName,
- productName,
- writeCRIF);
-
- // Create and register the "ImageWrite" factory for collection mode.
- registry.registerFactory(CollectionRegistryMode.MODE_NAME,
- imageWriteName,
- productName,
- new ImageWriteCIF());
- }
-}
diff -urN jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/ImageWriteCIF.java zzx2/src/share/classes/com/sun/media/jai/imageioimpl/ImageWriteCIF.java
--- jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/ImageWriteCIF.java 2005-02-11 00:01:55.000000000 -0500
+++ zzx2/src/share/classes/com/sun/media/jai/imageioimpl/ImageWriteCIF.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,296 +0,0 @@
-/*
- * $RCSfile: ImageWriteCIF.java,v $
- *
- *
- * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for
- * use in the design, construction, operation or maintenance of any
- * nuclear facility.
- *
- * $Revision: 1.1 $
- * $Date: 2005/02/11 05:01:55 $
- * $State: Exp $
- */
-package com.sun.media.jai.imageioimpl;
-
-import java.awt.RenderingHints;
-import java.awt.image.BufferedImage;
-import java.awt.image.RenderedImage;
-import java.awt.image.renderable.ParameterBlock;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import javax.imageio.ImageIO;
-import javax.imageio.ImageWriteParam;
-import javax.imageio.ImageWriter;
-import javax.imageio.metadata.IIOMetadata;
-import javax.imageio.stream.ImageOutputStream;
-import javax.media.jai.CollectionImage;
-import javax.media.jai.CollectionImageFactory;
-import javax.media.jai.CollectionOp;
-import javax.media.jai.PropertySource;
-import com.sun.media.jai.operator.ImageWriteDescriptor;
-
-public final class ImageWriteCIF implements CollectionImageFactory {
- /** Constructor. */
- public ImageWriteCIF() {}
-
- public CollectionImage create(ParameterBlock args,
- RenderingHints hints) {
-
- // Get the writer.
- ImageWriter writer = (ImageWriter)args.getObjectParameter(13);
-
- // Find a writer if null.
- if(writer == null) {
- // Get the format. Should be non-null from OperationDescriptor.
- String format = (String)args.getObjectParameter(1);
-
- // Find a writer.
- Iterator writers = ImageIO.getImageWritersByFormatName(format);
-
- // Get the writer.
- if(writers != null) {
- writer = (ImageWriter)writers.next();
- } else {
- throw new RuntimeException
- (I18N.getString("ImageWriteCIF0")+" "+format);
- }
- }
-
- // Get the source Collection.
- Collection collection = (Collection)args.getSource(0);
-
- // Determine the number of RenderedImages in the Collection.
- int numRenderedImages = 0;
- Iterator iter = collection.iterator();
- while(iter.hasNext()) {
- if(iter.next() instanceof RenderedImage) {
- numRenderedImages++;
- }
- }
-
- // Set the sequence flag.
- boolean writeToSequence = writer.canWriteSequence();
-
- // Check that the writer can write sequences.
- if(numRenderedImages > 1 && !writeToSequence) {
- throw new RuntimeException
- (I18N.getString("ImageWriteCIF1"));
- }
-
- // Get the stream metadata.
- IIOMetadata streamMetadata =
- (IIOMetadata)args.getObjectParameter(7);
-
- // Get the property use flag.
- boolean useProperties =
- ((Boolean)args.getObjectParameter(2)).booleanValue();
-
- // If null, get stream metadata from source properties if allowed.
- if(streamMetadata == null &&
- useProperties &&
- collection instanceof PropertySource) {
- Object streamMetadataProperty =
- ((PropertySource)collection).getProperty(
- ImageWriteDescriptor.PROPERTY_NAME_METADATA_STREAM);
- if(streamMetadataProperty instanceof IIOMetadata) {
- streamMetadata = (IIOMetadata)streamMetadataProperty;
- }
- }
-
- // Get the writer parameters.
- ImageWriteParam param = (ImageWriteParam)args.getObjectParameter(12);
-
- // Transcode the stream metadata if requested.
- if(streamMetadata != null) {
- // Get the transcoding flag.
- boolean transcode =
- ((Boolean)args.getObjectParameter(3)).booleanValue();
-
- if(transcode) {
- // Overwrite the stream metadata with transcoded metadata.
- streamMetadata =
- writer.convertStreamMetadata(streamMetadata,
- param);
- }
- }
-
- if(writeToSequence) {
- // Write the stream metadata to the sequence.
- try {
- // Get the output.
- Object output = args.getObjectParameter(0);
-
- // Try to get an ImageOutputStream.
- ImageOutputStream stream =
- ImageWriteCRIF.getImageOutputStream(output);
-
- // Set the writer's output.
- writer.setOutput(stream != null ? stream : output);
-
- // Prepare the sequence.
- writer.prepareWriteSequence(streamMetadata);
- } catch(IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- // Clone the ParameterBlock as the writer, image metadata, and
- // thumbnail parameters will be replaced.
- ParameterBlock imagePB = (ParameterBlock)args.clone();
-
- // Clear the stream metadata.
- imagePB.set(null, 7);
-
- // Set the ImageWriter.
- imagePB.set(writer, 13);
-
- // Get the image metadata array.
- IIOMetadata[] imageMetadata =
- (IIOMetadata[])args.getObjectParameter(8);
-
- // Get the thumbnail array.
- BufferedImage[] thumbnails =
- (BufferedImage[])args.getObjectParameter(9);
-
- // Create a new Iterator.
- iter = collection.iterator();
-
- // Create an ImageIOCollectionImage to contain the result:
- ImageIOCollectionImage imageList =
- new ImageIOCollectionImage(collection.size());
-
- // Iterate over the collection.
- int imageIndex = 0;
- while(iter.hasNext()) {
- // Get the next element.
- Object nextElement = iter.next();
-
- // Process if a RenderedImage.
- if(nextElement instanceof RenderedImage) {
- // Replace source with current RenderedImage.
- imagePB.setSource((RenderedImage)nextElement, 0);
-
- // Replace image metadata.
- if(imageMetadata != null) {
- imagePB.set(imageMetadata[imageIndex], 8);
- }
-
- // Replace thumbnail array.
- if(thumbnails != null) {
- imagePB.set(thumbnails[imageIndex], 9);
- }
-
- // Write the image to the sequence
- RenderedImage nextImage =
- ImageWriteCRIF.create(imageIndex,
- writeToSequence,
- imagePB, hints);
-
- // If the ImageWriteParam passed in was null, replace it
- // with the first non-null ImageWriteParam property value
- // and set the value in the local ParameterBlock.
- if(param == null) {
- Object paramPropertyValue =
- nextImage.getProperty(
- ImageWriteDescriptor.PROPERTY_NAME_IMAGE_WRITE_PARAM);
-
- if(paramPropertyValue instanceof ImageWriteParam) {
- param = (ImageWriteParam)paramPropertyValue;
-
- // Replace the ImageWriteParam so the CRIF doesn't
- // have to re-do the tile size initialization.
- imagePB.set(param, 12);
- }
- }
-
- // Add the image to the collection to be returned.
- imageList.add(nextImage);
-
- // Increment the index.
- imageIndex++;
- }
- }
-
- // Get the pixel replacement parameter.
- boolean allowPixelReplacement =
- ((Boolean)args.getObjectParameter(5)).booleanValue();
-
- if(writeToSequence && !allowPixelReplacement) {
- // Complete writing the sequence.
- try {
- // XXX What about pixel replacement? If this is invoked here
- // it will not be possible. How can this be invoked such that
- // pixel replacement can occur but the user is not obliged to
- // call this method manually?
- // Answer: document that the user must obtain the writer from
- // the collection-level ImageWriter property and invoke
- // endWriteSequence() on it.
- writer.endWriteSequence();
- } catch(IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- // Set collection-level properties.
- if(param != null) {
- imageList.setProperty(
- ImageWriteDescriptor.PROPERTY_NAME_IMAGE_WRITE_PARAM,
- param);
- }
- imageList.setProperty(
- ImageWriteDescriptor.PROPERTY_NAME_IMAGE_WRITER,
- writer);
- if(streamMetadata != null) {
- imageList.setProperty(
- ImageWriteDescriptor.PROPERTY_NAME_METADATA_STREAM,
- streamMetadata);
- }
-
- // Return CollectionImage.
- return imageList;
- }
-
- // Forget it.
- public CollectionImage update(ParameterBlock oldParamBlock,
- RenderingHints oldHints,
- ParameterBlock newParamBlock,
- RenderingHints newHints,
- CollectionImage oldRendering,
- CollectionOp op) {
- return null;
- }
-}
diff -urN jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/ImageWriteCRIF.java zzx2/src/share/classes/com/sun/media/jai/imageioimpl/ImageWriteCRIF.java
--- jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/ImageWriteCRIF.java 2005-02-11 00:01:55.000000000 -0500
+++ zzx2/src/share/classes/com/sun/media/jai/imageioimpl/ImageWriteCRIF.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,663 +0,0 @@
-/*
- * $RCSfile: ImageWriteCRIF.java,v $
- *
- *
- * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for
- * use in the design, construction, operation or maintenance of any
- * nuclear facility.
- *
- * $Revision: 1.1 $
- * $Date: 2005/02/11 05:01:55 $
- * $State: Exp $
- */
-package com.sun.media.jai.imageioimpl;
-
-import java.awt.Dimension;
-import java.awt.RenderingHints;
-import java.awt.image.BufferedImage;
-import java.awt.image.RenderedImage;
-import java.awt.image.renderable.ParameterBlock;
-import java.awt.image.renderable.RenderableImage;
-import java.awt.image.renderable.RenderContext;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.RandomAccessFile;
-import java.net.Socket;
-import java.util.Arrays;
-import java.util.EventListener;
-import java.util.Iterator;
-import java.util.Locale;
-import javax.imageio.IIOImage;
-import javax.imageio.ImageIO;
-import javax.imageio.ImageTypeSpecifier;
-import javax.imageio.ImageWriter;
-import javax.imageio.ImageWriteParam;
-import javax.imageio.event.IIOWriteProgressListener;
-import javax.imageio.event.IIOWriteWarningListener;
-import javax.imageio.metadata.IIOMetadata;
-import javax.imageio.stream.ImageOutputStream;
-import javax.media.jai.CRIFImpl;
-import javax.media.jai.PlanarImage;
-import javax.media.jai.RenderedImageAdapter;
-import javax.media.jai.WritablePropertySource;
-import com.sun.media.jai.operator.ImageWriteDescriptor;
-
-public final class ImageWriteCRIF extends CRIFImpl {
- public static void main(String[] args) throws Throwable {
- java.io.File inFile = new java.io.File(args[0]);
- java.io.File outFile = new java.io.File(args[1]);
- String format = args.length > 2 ? args[2] : "png";
- String mode = args.length > 3 ? args[3] : "rendered";
-
- int imageIndex = 0;
-
- javax.imageio.stream.ImageInputStream inStream =
- javax.imageio.ImageIO.createImageInputStream(inFile);
-
- java.util.Iterator iter =
- javax.imageio.ImageIO.getImageReaders(inStream);
- javax.imageio.ImageReader reader =
- (javax.imageio.ImageReader)iter.next();
-
- reader.setInput(inStream);
-
- RenderedImage image = reader.read(imageIndex);
-
- javax.imageio.metadata.IIOMetadata streamMetadata =
- reader.getStreamMetadata();
- javax.imageio.metadata.IIOMetadata imageMetadata =
- reader.getImageMetadata(imageIndex);
-
- java.awt.image.BufferedImage[] thumbnails = null;
- if(reader.hasThumbnails(imageIndex)) {
- int numThumbnails = reader.getNumThumbnails(imageIndex);
- thumbnails = new java.awt.image.BufferedImage[numThumbnails];
- for(int i = 0; i < numThumbnails; i++) {
- thumbnails[i] = reader.readThumbnail(imageIndex, i);
- }
- }
-
- ImageWriteCRIF crif = new ImageWriteCRIF();
-
- ParameterBlock pb = new ParameterBlock();
-
- if(mode.equalsIgnoreCase("rendered")) {
- pb.addSource(image);
- } else if(mode.equalsIgnoreCase("renderable")) {
- ParameterBlock renderablePB = new ParameterBlock();
- renderablePB.addSource(image);
- RenderableImage renderable =
- javax.media.jai.JAI.createRenderable("renderable",
- renderablePB);
- pb.addSource(renderable);
- }
-
- pb.add(outFile); // Output
- pb.add(format); // Format
-
- pb.add(Boolean.TRUE); // UseProperties
- pb.add(Boolean.TRUE); // Transcode
- pb.add(Boolean.TRUE); // VerifyOutput
- pb.add(Boolean.TRUE); // AllowPixelReplacement
-
- pb.add(null); // TileSize
-
- pb.add(streamMetadata);
- pb.add(imageMetadata);
- pb.add(thumbnails);
-
- pb.add(null); // EventListener[]
- pb.add(null); // Locale
-
- pb.add(null); // ImageWriteParam
- pb.add(null); // ImageWriter
-
- if(mode.equalsIgnoreCase("rendered")) {
- crif.create(pb, null);
- } else if(mode.equalsIgnoreCase("renderable")) {
- java.awt.geom.AffineTransform transform =
- new java.awt.geom.AffineTransform(256, 0, 0, 512, 0, 0);
- crif.create(new RenderContext(transform), pb);
- }
- }
-
- public ImageWriteCRIF() {
- super();
- }
-
- /**
- * Attempt to create an {@link ImageOutputStream} for the supplied
- * output. The following sequence is effected:
- * output
is an ImageOutputStream
it
- * is cast and returned.output
is a String
it is converted
- * to a read-write RandomAccessFile
.output
is a Socket
it is converted
- * to an OutputStream
.ImageIO.createImageOutputStream()
is invoked
- * with parameter set to the (possibly converted) output and the
- * value it returns (which could be null
) is returned
- * to the caller.Object
to be used as the destination,
- * such as a String
, File
, writable
- * RandomAccessFile
, OutputStream
, writable
- * Socket
, or writable Channel
.
- *
- * @return An ImageOutputStream
or null
.
- */
- static ImageOutputStream getImageOutputStream(Object output) {
- // The value to be returned.
- ImageOutputStream stream = null;
-
- // If already an ImageOutputStream just cast.
- if(output instanceof ImageOutputStream) {
- stream = (ImageOutputStream)output;
- } else {
- if(output instanceof String) {
- // If output is a String replace it with a RandomAccessFile.
- try {
- // 'output' is conditionally checked for writability
- // in the OperationDescriptor.
- output = new RandomAccessFile((String)output, "rw");
- } catch(Exception e) {
- throw new RuntimeException
- (I18N.getString("ImageWriteCRIF0")+" "+output);
- }
- } else if(output instanceof Socket) {
- // If output is a Socket replace it with an OutputStream.
- try {
- // XXX check binding, connection, closed, shutdown
- // as these could have changed.
- output = ((Socket)output).getOutputStream();
- } catch(Exception e) {
- throw new RuntimeException
- (I18N.getString("ImageWriteCRIF1")+" "+output);
- }
- }
-
- // Create the ImageOutputStream.
- try {
- stream = ImageIO.createImageOutputStream(output);
- } catch(IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- return stream;
- }
-
- /**
- * {@link RenderedImageFactory} implementation.
- */
- public RenderedImage create(ParameterBlock pb,
- RenderingHints rh) {
- return create(0, false, pb, rh);
- }
-
- private static ImageWriteParam getWriteParam(ImageWriteParam param,
- ImageWriter writer) {
- // Set default to original ImageWriteParam.
- ImageWriteParam newParam = param;
-
- if(param == null) {
- newParam = writer.getDefaultWriteParam();
- } else if(param.getClass().getName().equals(
- "javax.imageio.ImageWriteParam")) {
- // The ImageWriteParam passed in is non-null. As the
- // ImageWriteParam class is not Cloneable, if the param
- // class is simply ImageWriteParam, then create a new
- // ImageWriteParam instance and set all its fields
- // which were set in param. This will eliminate problems
- // with concurrent modification of param for the cases
- // in which there is not a special ImageWriteParam used.
-
- // Create a new ImageWriteParam instance.
- newParam = writer.getDefaultWriteParam();
-
- // Set all fields which need to be set.
-
- // IIOParamController field.
- if(param.hasController()) {
- newParam.setController(param.getController());
- }
-
- // Destination fields.
- newParam.setDestinationOffset(param.getDestinationOffset());
- newParam.setDestinationType(param.getDestinationType());
-
- // Source fields.
- newParam.setSourceBands(param.getSourceBands());
- newParam.setSourceRegion(param.getSourceRegion());
- newParam.setSourceSubsampling(param.getSourceXSubsampling(),
- param.getSourceYSubsampling(),
- param.getSubsamplingXOffset(),
- param.getSubsamplingYOffset());
-
- // Compression.
- if(param.canWriteCompressed()) {
- int compressionMode = param.getCompressionMode();
- newParam.setCompressionMode(compressionMode);
- if(compressionMode == ImageWriteParam.MODE_EXPLICIT) {
- newParam.setCompressionQuality(param.getCompressionQuality());
- newParam.setCompressionType(param.getCompressionType());
- }
- }
-
- // Progressive
- if(param.canWriteProgressive()) {
- newParam.setProgressiveMode(param.getProgressiveMode());
- }
-
- // Tiling
- if(param.canWriteTiles()) {
- int tilingMode = param.getTilingMode();
- newParam.setTilingMode(tilingMode);
- if(tilingMode == ImageWriteParam.MODE_EXPLICIT) {
- newParam.setTiling(param.getTileWidth(),
- param.getTileHeight(),
- param.getTileGridXOffset(),
- param.getTileGridYOffset());
- }
- }
- }
-
- return newParam;
- }
-
- /**
- * If tiling is supported, determine the appropriate tile size and
- * set it on the returned param if necessary. The returned param
- * will either be a new ImageWriteParam or the one passed in with
- * its tiling settings possibly modified.
- */
- private static ImageWriteParam setTileSize(ImageWriteParam param,
- ImageWriter writer,
- Dimension tileSize,
- RenderedImage source) {
-
- ImageWriteParam returnParam = getWriteParam(param, writer);
-
- // If tiling possible set tile size if needed.
- if(returnParam.canWriteTiles()) {
- if(tileSize != null) {
- // Check tile size.
- if(tileSize.width <= 0 || tileSize.height <= 0) {
- throw new IllegalArgumentException
- ("tileSize.width <= 0 || tileSize.height <= 0");
- }
-
- // Use specified tile size.
- returnParam.setTilingMode(ImageWriteParam.MODE_EXPLICIT);
- returnParam.setTiling(tileSize.width,
- tileSize.height,
- 0, 0); // XXX set tile offsets?
- } else if(param == null) {
- if(source.getNumXTiles() > 1 || source.getNumYTiles() > 1) {
- // Null tile size and param args: use source tile size.
- returnParam.setTilingMode(ImageWriteParam.MODE_EXPLICIT);
- returnParam.setTiling(source.getTileWidth(),
- source.getTileHeight(),
- 0, 0); // XXX set tile offsets?
- }
- } else if(returnParam.getTilingMode() ==
- ImageWriteParam.MODE_EXPLICIT) {
- // Param passed in has explicit mode set but the tile
- // grid might not actually be set.
- boolean setTileSize = false;
-
- // Save reference to preferred tile size array.
- Dimension[] preferredTileSizes =
- returnParam.getPreferredTileSizes();
-
- // Set the tile width.
- int tileWidth = 0;
- try {
- // Try to get it from the param.
- tileWidth = returnParam.getTileWidth();
- } catch(IllegalStateException e) {
- // Not set in the param.
- setTileSize = true;
-
- if(preferredTileSizes != null &&
- preferredTileSizes.length >= 2 &&
- preferredTileSizes[0].width > 0 &&
- preferredTileSizes[1].width > 0) {
- // Use average of first two preferred tile widths.
- tileWidth = (preferredTileSizes[0].width +
- preferredTileSizes[1].width) / 2;
- } else {
- // Use source image tile width.
- tileWidth = source.getTileWidth();
- }
- }
-
- // Set the tile height.
- int tileHeight = 0;
- try {
- // Try to get it from the param.
- tileHeight = returnParam.getTileHeight();
- } catch(IllegalStateException e) {
- // Not set in the param.
- setTileSize = true;
-
- if(preferredTileSizes != null &&
- preferredTileSizes.length >= 2 &&
- preferredTileSizes[0].height > 0 &&
- preferredTileSizes[1].height > 0) {
- // Use average of first two preferred tile heights.
- tileHeight = (preferredTileSizes[0].height +
- preferredTileSizes[1].height) / 2;
- } else {
- // Use source image tile height.
- tileHeight = source.getTileHeight();
- }
- }
-
- // Set the tile size if not previously set in the param.
- if(setTileSize) {
- returnParam.setTiling(tileWidth,
- tileHeight,
- 0, 0); // XXX set tile offsets?
- }
- }
- }
-
- return returnParam;
- }
-
- static RenderedImage create(int imageIndex,
- boolean writeToSequence,
- ParameterBlock pb,
- RenderingHints rh) {
-
- // Value to be returned.
- RenderedImage image = null;
-
- // Get the source image.
- RenderedImage source = pb.getRenderedSource(0);
-
- // Get the writer parameters.
- ImageWriteParam param = (ImageWriteParam)pb.getObjectParameter(12);
-
- // Set the target image type.
- ImageTypeSpecifier destinationType = null;
- if(param != null) {
- destinationType = param.getDestinationType();
- }
- if(destinationType == null) {
- destinationType = new ImageTypeSpecifier(source);
- }
-
- // Get the writer.
- ImageWriter writer = (ImageWriter)pb.getObjectParameter(13);
-
- if(writer == null) {
- // Get the format. Should be non-null from OperationDescriptor.
- String format = (String)pb.getObjectParameter(1);
-
- // Find a writer.
- Iterator writers = ImageIO.getImageWriters(destinationType,
- format);
-
- // Get the writer.
- if(writers != null && writers.hasNext()) {
- writer = (ImageWriter)writers.next();
- }
- }
-
- // XXX What if no writer? Exception?
- if(writer != null) {
- // XXX Replace ImageWriter parameter in ParameterBlock?
-
- ImageOutputStream streamToClose = null;
-
- // Set the output if not writing to a sequence (in which
- // case the output should already be set.
- if(!writeToSequence) {
- // Get the output.
- Object output = pb.getObjectParameter(0);
-
- // Try to get an ImageOutputStream.
- ImageOutputStream stream = getImageOutputStream(output);
-
- // Set stream to close if not writing to a sequence.
- streamToClose = stream != output ? stream : null;
-
- // Set the writer's output.
- writer.setOutput(stream != null ? stream : output);
- }
-
- // Get the property use flag.
- boolean useProperties =
- ((Boolean)pb.getObjectParameter(2)).booleanValue();
-
- // Get the transcoding flag.
- boolean transcode =
- ((Boolean)pb.getObjectParameter(3)).booleanValue();
-
- IIOMetadata streamMetadata = null;
- if(!writeToSequence) {
- // Get the stream metadata.
- streamMetadata = (IIOMetadata)pb.getObjectParameter(7);
-
- // If null, get stream metadata from source properties
- // if allowed.
- if(streamMetadata == null && useProperties) {
- Object streamMetadataProperty =
- source.getProperty(
- ImageWriteDescriptor.PROPERTY_NAME_METADATA_STREAM);
- if(streamMetadataProperty instanceof IIOMetadata) {
- streamMetadata = (IIOMetadata)streamMetadataProperty;
- }
- }
-
- // Transcode the stream metadata if requested.
- if(streamMetadata != null && transcode) {
- // Overwrite the stream metadata with transcoded metadata.
- streamMetadata =
- writer.convertStreamMetadata(streamMetadata,
- param);
- }
- }
-
- // Get the image metadata.
- IIOMetadata imageMetadata =
- (IIOMetadata)pb.getObjectParameter(8);
-
- // If null, get image metadata from source properties if allowed.
- if(imageMetadata == null && useProperties) {
- Object imageMetadataProperty =
- source.getProperty(
- ImageWriteDescriptor.PROPERTY_NAME_METADATA_IMAGE);
- if(imageMetadataProperty instanceof IIOMetadata) {
- imageMetadata = (IIOMetadata)imageMetadataProperty;
- }
- }
-
- // Transcode the image metadata if requested.
- if(imageMetadata != null && transcode) {
- // Overwrite the image metadata with transcoded metadata.
- imageMetadata = writer.convertImageMetadata(imageMetadata,
- destinationType,
- param);
- }
-
- // Get the thumbnails if supported by the writer.
- BufferedImage[] thumbnails = null;
- if(writer.getNumThumbnailsSupported(destinationType,
- param,
- streamMetadata,
- imageMetadata) > 0) {
- thumbnails = (BufferedImage[])pb.getObjectParameter(9);
-
- // If null, get thumbnails from source properties if allowed.
- if(thumbnails == null && useProperties) {
- Object thumbnailsProperty =
- source.getProperty(
- ImageWriteDescriptor.PROPERTY_NAME_METADATA_IMAGE);
- if(thumbnailsProperty instanceof BufferedImage[]) {
- thumbnails = (BufferedImage[])thumbnailsProperty;
- }
- }
- }
-
- // Get the locale parameter and set on the writer.
- Locale locale = (Locale)pb.getObjectParameter(11);
- if(locale != null) {
- writer.setLocale(locale);
- }
-
- // Get the listeners parameter and set on the writer.
- EventListener[] listeners =
- (EventListener[])pb.getObjectParameter(10);
- if(listeners != null) {
- for(int i = 0; i < listeners.length; i++) {
- EventListener listener = listeners[i];
- if(listener instanceof IIOWriteProgressListener) {
- writer.addIIOWriteProgressListener(
- (IIOWriteProgressListener)listener);
- }
- if(listener instanceof IIOWriteWarningListener) {
- writer.addIIOWriteWarningListener(
- (IIOWriteWarningListener)listener);
- }
- }
- }
-
- // Set the tile size.
- // XXX Replace ImageWriteParam parameter in ParameterBlock?
- param = setTileSize(param, writer,
- (Dimension)pb.getObjectParameter(6),
- source);
-
- // Create the IIOImage container.
- IIOImage iioImage = new IIOImage(source,
- thumbnails != null ?
- Arrays.asList(thumbnails) : null,
- imageMetadata);
-
- try {
- // Write the image.
- if(writeToSequence) {
- writer.writeToSequence(iioImage, param);
- } else {
- writer.write(streamMetadata, iioImage, param);
- }
-
- // Get the pixel replacement parameter.
- boolean allowPixelReplacement =
- ((Boolean)pb.getObjectParameter(5)).booleanValue();
-
- // Set the return value.
- if(allowPixelReplacement &&
- source instanceof PlanarImage &&
- writer.canReplacePixels(imageIndex)) {
-
- // Create an image which is a PropertyChangeListener of
- // "invalidregion" events including RenderingChangeEvents.
- image = new PixelReplacementImage(source,
- rh,
- param,
- writer,
- imageIndex,
- streamToClose);
-
- // Register the image as a sink of its source so that
- // it automatically receives events.
- ((PlanarImage)source).addSink(image);
- } else if(!writeToSequence) {
- Object writerOutput = writer.getOutput();
- if(writerOutput != pb.getObjectParameter(0) &&
- writerOutput instanceof ImageOutputStream) {
- // This block is executed if and only if pixel
- // replacement is not occurring, a sequence is
- // not being written, and an ImageOutputStream
- // inaccessible to the application is set on the
- // ImageWriter.
- ((ImageOutputStream)writerOutput).flush();
- }
-
- // Set the return value to the original image or
- // a wrapped version thereof.
- image = source instanceof WritablePropertySource ?
- source : new RenderedImageAdapter(source);
- }
-
- // Set required properties.
- WritablePropertySource wps = (WritablePropertySource)image;
-
- // Set the ImageWriteParam property.
- wps.setProperty(
- ImageWriteDescriptor.PROPERTY_NAME_IMAGE_WRITE_PARAM,
- param);
-
- // Set the ImageWriter property.
- wps.setProperty(
- ImageWriteDescriptor.PROPERTY_NAME_IMAGE_WRITER,
- writer);
-
- // Set the stream metadata property.
- if(streamMetadata != null) {
- wps.setProperty(
- ImageWriteDescriptor.PROPERTY_NAME_METADATA_STREAM,
- streamMetadata);
- }
-
- // Set the image metadata property.
- if(imageMetadata != null) {
- wps.setProperty(
- ImageWriteDescriptor.PROPERTY_NAME_METADATA_IMAGE,
- imageMetadata);
- }
-
- // Set the thumbnail property.
- if(thumbnails != null) {
- wps.setProperty(
- ImageWriteDescriptor.PROPERTY_NAME_THUMBNAILS,
- thumbnails);
- }
- } catch(IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- return image;
- }
-}
diff -urN jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/PixelReplacementImage.java zzx2/src/share/classes/com/sun/media/jai/imageioimpl/PixelReplacementImage.java
--- jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/PixelReplacementImage.java 2005-02-11 00:01:55.000000000 -0500
+++ zzx2/src/share/classes/com/sun/media/jai/imageioimpl/PixelReplacementImage.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,293 +0,0 @@
-/*
- * $RCSfile: PixelReplacementImage.java,v $
- *
- *
- * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for
- * use in the design, construction, operation or maintenance of any
- * nuclear facility.
- *
- * $Revision: 1.1 $
- * $Date: 2005/02/11 05:01:55 $
- * $State: Exp $
- */
-package com.sun.media.jai.imageioimpl;
-
-import java.awt.Point;
-import java.awt.Rectangle;
-import java.awt.Shape;
-import java.awt.image.Raster;
-import java.awt.image.RenderedImage;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Map;
-import java.util.Vector;
-import javax.media.jai.ImageLayout;
-import javax.media.jai.OpImage;
-import javax.media.jai.PlanarImage;
-import javax.media.jai.RenderedOp;
-import javax.media.jai.PropertyChangeEventJAI;
-import javax.media.jai.RenderingChangeEvent;
-import javax.imageio.ImageWriter;
-import javax.imageio.ImageWriteParam;
-import javax.imageio.stream.ImageOutputStream;
-
-/**
- * Implementation of PlanarImage
for the "ImageWrite" operation
- * for the case of ImageWriter
s which can replace pixels. The
- * sole purpose of this class is to respond to "invalidregion" events so
- * as to update the written image.
- */
-final class PixelReplacementImage extends PlanarImage
- implements PropertyChangeListener {
-
- /**
- * The ImageWriteParam
used in writing the image.
- */
- private ImageWriteParam param;
-
- /**
- * The ImageWriter
used to write the image.
- */
- private ImageWriter writer;
-
- /**
- * The index of the image to be write.
- */
- private int imageIndex;
-
- /**
- * A stream to be closed when the instance is disposed; may be null.
- */
- private ImageOutputStream streamToClose;
-
- /**
- * Creates a Vector
containing a single element.
- */
- private static Vector createVector(Object element) {
- Vector v = new Vector(1);
- v.add(element);
- return v;
- }
-
- /**
- * XXX
- */
- PixelReplacementImage(RenderedImage source,
- Map configuration,
- ImageWriteParam param,
- ImageWriter writer,
- int imageIndex,
- ImageOutputStream streamToClose) throws IOException {
- super(new ImageLayout(source), // Layout same as source.
- createVector(source),
- configuration);
-
- // Verify that the writer can replace pixels.
- if(!writer.canReplacePixels(imageIndex)) {
- throw new IllegalArgumentException
- ("!writer.canReplacePixels(imageIndex)");
- }
-
- // Set the instance variables from the parameters.
- // XXX Should ImageWriteParam original settings be cached for
- // testing later to see whether anything important has changed?
- this.param = param;
- this.writer = writer;
- this.imageIndex = imageIndex;
- this.streamToClose = streamToClose;
- }
-
- /**
- * Close an ImageOutputStream
passed in.
- */
- public void dispose() {
- if(streamToClose != null) {
- try {
- streamToClose.close();
- } catch(IOException e) {
- // Ignore it.
- }
- }
-
- super.dispose();
- }
-
- /**
- * Gets a tile.
- *
- * @param tileX The X index of the tile.
- * @param tileY The Y index of the tile.
- */
- public Raster getTile(int tileX, int tileY) {
- return getSourceImage(0).getTile(tileX, tileY);
- }
-
- // --- PropertyChangeListener implementation ---
-
- // XXX Doc
- public void propertyChange(PropertyChangeEvent evt) {
- PlanarImage source = getSourceImage(0);
- Object eventSource = evt.getSource();
-
- //
- // Process the event if the writer can replace pixels,
- // the event source is the source of this OpImage,
- // and the event name is "invalidregion".
- //
- if((evt instanceof PropertyChangeEventJAI &&
- evt.getPropertyName().equalsIgnoreCase("invalidregion") &&
- eventSource.equals(source)) ||
- (evt instanceof RenderingChangeEvent &&
- evt.getOldValue().equals(source) &&
- eventSource instanceof RenderedOp &&
- evt.getNewValue().equals(((RenderedOp)eventSource).getRendering()))) {
-
- // Get the invalid region information.
- Shape srcInvalidRegion = null;
-
- if(evt instanceof RenderingChangeEvent) {
- // RenderingChangeEvent presumably from a source RenderedOp.
- RenderingChangeEvent rcEvent = (RenderingChangeEvent)evt;
-
- // Get the invalidated region of the source.
- srcInvalidRegion = rcEvent.getInvalidRegion();
-
- // Reset this image's source.
- source = (PlanarImage)evt.getNewValue();
- setSource(source, 0);
-
- // If entire source is invalid replace with source bounds.
- if(srcInvalidRegion == null) {
- srcInvalidRegion =
- ((PlanarImage)rcEvent.getOldValue()).getBounds();
- }
- } else {
- // Get the invalidated region of the source.
- Object evtNewValue = (Shape)evt.getNewValue();
-
- // Continue if the value class is correct.
- if(evtNewValue instanceof Shape) {
- srcInvalidRegion = (Shape)evtNewValue;
-
- // If entire source is invalid replace with source bounds.
- if(srcInvalidRegion == null) {
- srcInvalidRegion = source.getBounds();
- }
- }
- }
-
- // Return if the invalid portion could not be determined.
- if(srcInvalidRegion == null) {
- return;
- }
-
- // Return if the invalid region does not overlap the param region.
- if(param != null) {
- Rectangle sourceRegion = param.getSourceRegion();
- if(sourceRegion != null &&
- !srcInvalidRegion.intersects(sourceRegion)) {
- return;
- }
- } else {
- param = writer.getDefaultWriteParam();
- }
-
- // Get indices of all tiles overlapping the invalid region.
- Point[] tileIndices =
- source.getTileIndices(srcInvalidRegion.getBounds());
-
- // Should not happen but return if tileIndices is null.
- if(tileIndices == null) return;
-
- // Get subsampling values.
- int gridX = minX + param.getSubsamplingXOffset();
- int gridY = minY + param.getSubsamplingYOffset();
- int stepX = param.getSourceXSubsampling();
- int stepY = param.getSourceYSubsampling();
- boolean isSubsampling =
- stepX != 1 || stepY != 1 || gridX != minX || gridY != minY;
-
- // Loop over affected tiles.
- int numTiles = tileIndices.length;
- for(int i = 0; i < numTiles; i++) {
- // Save the next tile index.
- Point tileIndex = tileIndices[i];
-
- // Compute tile bounds.
- Rectangle tileRect =
- source.getTileRect(tileIndex.x, tileIndex.y);
-
- // Replace if bounds intersect invalid region.
- if(srcInvalidRegion.intersects(tileRect)) {
- // Get the source tile.
- Raster raster = source.getTile(tileIndex.x, tileIndex.y);
-
- Rectangle destRect;
- if(isSubsampling) {
- int destMinX =
- (tileRect.x - gridX + stepX - 1)/stepX;
- int destMinY =
- (tileRect.y - gridY + stepY - 1)/stepY;
- int destMaxX =
- (tileRect.x + tileRect.width -
- gridX + stepX - 1)/stepX;
- int destMaxY =
- (tileRect.y + tileRect.height -
- gridY + stepY - 1)/stepY;
- destRect = new Rectangle(destMinX, destMinY,
- destMaxX - destMinX,
- destMaxY - destMinY);
- } else {
- destRect = tileRect;
- }
-
- // Replace the pixels.
- try {
- synchronized(writer) {
- writer.prepareReplacePixels(imageIndex, destRect);
- param.setDestinationOffset(destRect.getLocation());
- writer.replacePixels(raster, param);
- writer.endReplacePixels();
- }
- } catch(IOException e) {
- throw new RuntimeException(e);
- }
- }
- }
- }
- }
-}
diff -urN jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/properties zzx2/src/share/classes/com/sun/media/jai/imageioimpl/properties
--- jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/imageioimpl/properties 2005-02-11 00:01:56.000000000 -0500
+++ zzx2/src/share/classes/com/sun/media/jai/imageioimpl/properties 1969-12-31 19:00:00.000000000 -0500
@@ -1,26 +0,0 @@
-#
-# $RCSfile: properties,v $
-#
-# Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
-#
-# Use is subject to license terms.
-#
-# $Revision: 1.1 $
-# $Date: 2005/02/11 05:01:56 $
-# $State: Exp $
-#
-# Internationalization file for com.sun.media.jai.imageioimpl
-
-ImageReadCRIF0=Cannot create read-only RandomAccessFile for path
-ImageReadCRIF1=Cannot create InputStream for URL
-ImageReadCRIF2=Cannot create InputStream for Socket
-
-ImageReadOpImage0=Destination bounds do not intersect available destination data region.
-ImageReadOpImage1=Source or destination region is empty.
-ImageReadOpImage2=Cannot perform rectangle mapping between source and destination because the image has no sources.
-
-ImageWriteCIF0=Unable to find an ImageWriter for format
-ImageWriteCIF1=Source Collection has more than one image and ImageWriter cannot write sequences.
-
-ImageWriteCRIF0=Cannot create read-write RandomAccessFile for path
-ImageWriteCRIF1=Cannot create OutputStream for Socket
diff -urN jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/operator/I18N.java zzx2/src/share/classes/com/sun/media/jai/operator/I18N.java
--- jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/operator/I18N.java 2005-02-11 00:01:56.000000000 -0500
+++ zzx2/src/share/classes/com/sun/media/jai/operator/I18N.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,54 +0,0 @@
-/*
- * $RCSfile: I18N.java,v $
- *
- *
- * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for
- * use in the design, construction, operation or maintenance of any
- * nuclear facility.
- *
- * $Revision: 1.1 $
- * $Date: 2005/02/11 05:01:56 $
- * $State: Exp $
- */
-package com.sun.media.jai.operator;
-
-import com.sun.media.imageioimpl.common.I18NImpl;
-
-final class I18N extends I18NImpl {
- static String getString(String key) {
- return getString("com.sun.media.jai.operator.I18N", key);
- }
-}
-
diff -urN jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/operator/ImageReadDescriptor.java zzx2/src/share/classes/com/sun/media/jai/operator/ImageReadDescriptor.java
--- jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/operator/ImageReadDescriptor.java 2005-11-30 19:40:32.000000000 -0500
+++ zzx2/src/share/classes/com/sun/media/jai/operator/ImageReadDescriptor.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,1100 +0,0 @@
-/*
- * $RCSfile: ImageReadDescriptor.java,v $
- *
- *
- * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for
- * use in the design, construction, operation or maintenance of any
- * nuclear facility.
- *
- * $Revision: 1.2 $
- * $Date: 2005/12/01 00:40:32 $
- * $State: Exp $
- */
-package com.sun.media.jai.operator;
-
-import java.awt.RenderingHints;
-import java.awt.image.RenderedImage;
-import java.awt.image.renderable.ContextualRenderedImageFactory;
-import java.awt.image.renderable.ParameterBlock;
-import java.awt.image.renderable.RenderableImage;
-import java.io.File;
-import java.io.InputStream;
-import java.net.Socket;
-import java.util.Collection;
-import java.util.EventListener;
-import java.util.Locale;
-import javax.imageio.ImageReadParam;
-import javax.imageio.ImageReader;
-import javax.imageio.stream.ImageInputStream;
-import javax.media.jai.JAI;
-import javax.media.jai.OperationDescriptorImpl;
-import javax.media.jai.OperationRegistry;
-import javax.media.jai.PropertyGenerator;
-import javax.media.jai.RenderedOp;
-import javax.media.jai.RenderableOp;
-import javax.media.jai.registry.CollectionRegistryMode;
-import javax.media.jai.registry.RenderableRegistryMode;
-import javax.media.jai.registry.RenderedRegistryMode;
-import com.sun.media.jai.util.PropertyGeneratorImpl;
-
-/**
- * An OperationDescriptor
describing the "ImageRead" operation.
- *
- * The "ImageRead" operation uses the - * Java - * Image I/O Framework to read images from an input source. Which formats - * may be read depends on which {@link javax.imageio.ImageReader} plug-ins are - * registered with the Image I/O Framework when the operation is invoked.
- * - *The input source will usually be an
- * {@link javax.imageio.stream.ImageInputStream}, but may be a
- * {@link java.io.File}, {@link java.io.RandomAccessFile},
- * {@link java.io.InputStream}, {@link java.net.URL},
- * {@link java.net.Socket}, {@link java.nio.channels.ReadableByteChannel},
- * file path represented as a String
or some other type
- * compatible with a reader plug-in. The
- * {@link javax.imageio.ImageIO} class should be used to specify the location
- * and enable the use of cache files via its setCacheDirectory()
- * and setUseCache()
methods, respectively. Note that this cache
- * pertains to image stream caching and is unrelated to the JAI
- * TileCache
.
The "ImageRead" operation supports rendered,
- * renderable, and
- * collection modes and requires no source image.
- * A {@link java.awt.RenderingHints} object may be supplied when the operation
- * is created. In addition to the {@link java.awt.RenderingHints.Key} hints
- * recognized by the eventual OpImage
constructor, an
- * ImageLayout
hint may also be
- * supplied. The settings of this ImageLayout
override any other
- * possible derivation of its components. In particular, it is possible that
- * the generated image(s) have a different tile layout than that present in
- * the image read from the input source.
Image properties are used to make available metadata and other - * information. Property provision is mode-specific.
- * - *Name | Value |
---|---|
GlobalName | ImageRead |
LocalName | ImageRead |
Vendor | com.sun.media.jai |
Description | Reads an image using the Java Image I/O Framework. |
DocURL | http://java.sun.com/products/java-media/jai/forDevelopers/jai-imageio-1_0-rc-docs/com/sun/media/jai/operator/ImageReadDescriptor.html |
Version | 1.0 |
arg0Desc | The input source. |
arg1Desc | The index or indices of the image(s) to read. |
arg2Desc | Whether metadata should be read if available. |
arg3Desc | Whether thumbnails should be read if available. |
arg4Desc | Whether to verify the validity of the input source. |
arg5Desc | EventListeners to be registered with the ImageReader. |
arg6Desc | The Locale for the ImageReader to use. |
arg7Desc | Java Image I/O read parameter instance. |
arg8Desc | Java Image I/O reader instance. |
Name | Class Type | - *Default Value |
---|---|---|
- * Input | java.lang.Object.class | - *NO_PARAMETER_DEFAULT | - *
- * ImageChoice | java.lang.Integer | - *0 | - *
- * ReadMetadata | java.lang.Boolean | - *TRUE | - *
- * ReadThumbnails | java.lang.Boolean | - *TRUE | - *
- * VerifyInput | java.lang.Boolean | - *TRUE | - *
- * Listeners | java.util.EventListener[] | - *null | - *
- * Locale | java.util.Locale | - *null | - *
- * ReadParam | javax.imageio.ImageReadParam | - *null | - *
- * Reader | javax.imageio.ImageReader | - *null | - *
The rendered mode parameters are handled as follows: - * - *
The foregoing policy regarding modification of any supplied ImageReadParam - * or ImageReader is necessary as neither of these classes is cloneable. Given - * that as a starting point there are in effect three possibilities: (A) do not - * accept them as parameters, (B) accept them via alternate parameters which do - * not pose these problems (for example an ImageReaderSpi and a long list of - * settings represented by the ImageReadParam), or (C) accept them explicitly. - * Option C has been deemed preferable despite the potential race condition - * issues.
- * - *In the Sun Microsystems implementation of this operation these potential - * conflicts have been mitigated to a certain extent: - * - *
Any fields of the supplied ImageLayout which are not set will be set to - * default values as follows. The ImageLayout will be cloned before it is - * modified.
- * - *Each value defaults to the corresponding value of the destination - * which would be derived on the basis of the source image dimensions - * and the settings of the ImageReadParam, i.e., source region, - * subsampling offsets and factors, and destination offset.
- * - *It should be noted that unlike in the Java Image I/O API itself, - * negative coordinates are permitted and the image origin is not - * required to be at (0,0) as for BufferedImages. Therefore it is - * possible that a given image be loaded using the same ImageReadParam - * by an ImageReader and by the "ImageRead" operation with different - * results. Possible differences would be that the portion of the - * image with negative coordinates is not clipped as it would be with - * direct Image I/O access, and no empty extent between (0,0) and the - * start of the data will be present.
- * - *For example, if the ImageReadParam had sourceRegion [0,0,w,h], - * destinationOffset [-w/2,-h/2], and no subsampling, then the Java - * Image I/O API would compute the effective source and destination - * regions to be [w/2,h/2,w/2,h/2] and [0,0,w/2,h/2], respectively. - * The JAI ImageRead operation would compute the effective source and - * destination regions to be [0,0,w,h] and [-w/2,-h/2,w,h], respectively. - * The Image I/O result would therefore be equal to the bottom right - * quadrant of the JAI result.
- * tileGridXOffset = ImageReader.getTileGridXOffset(imageIndex); - * tileGridYOffset = ImageReader.getTileGridYOffset(imageIndex); - * tileWidth = ImageReader.getTileWidth(imageIndex); - * tileHeight = ImageReader.getTileHeight(imageIndex); - *
- * ImageReader.getRawImageType(imageIndex).getColorModel(); - *
- * ImageReader.getRawImageType(imageIndex).getSampleModel().createCompatibleSampleModel(tileWidth, tileHeight); - *
Property Name | - *Type | - *Comment | - *
---|---|---|
JAI.ImageReadParam | - *ImageReadParam | - *Set to ImageReadParam actually used which may differ from the one passed in. | - *
JAI.ImageReader | - *ImageReader | - *Set to ImageReader actually used. | - *
JAI.ImageMetadata | - *IIOMetadata | - *Set if and only if ReadMetadata parameter is TRUE and image metadata are available. | - *
JAI.StreamMetadata | - *IIOMetadata | - *Set if and only if ReadMetadata parameter is TRUE and stream metadata are available. | - *
JAI.Thumbnails | - *BufferedImage[] | - *Set if and only if ReadThumbnails parameter is TRUE and thumbnails are available. | - *
If a given property is not set, this implies of course that the names of - * absent properties will not appear in the array returned by getPropertyNames() - * and getProperty() invoked to obtain absent properties will return - * java.awt.Image.UndefinedProperty as usual.
- * - *The ImageReader and ImageReadParam may be used for subsequent invocations - * of the operation (for example to obtain different images in a multi-page file) - * or for informational purposes. Care should be taken in using these property - * values with respect to the synchronization issues previously discussed.
- * - *In all cases image metadata properties will be set when the node is rendered, - * i.e., metadata reading is not subject to the same deferred execution as is - * image data reading. The thumbnail property value will not be set however until - * its value is actually requested.
- * - *It should be noted that although they are discussed in the context of - * rendered mode, the parameter synchronization - * policy and ImageLayout handling methodology - * apply to renderable mode as well.
- * - *Name | Class Type | - *Default Value |
---|---|---|
ImageChoice | int[] | - *int[] {0,...,NumImages-1} | - *
In the Sun Microsystems renderable mode implementation of the "ImageRead" - * operation, when createRendering() is invoked on the RenderableImage created - * by the operation, a MultiResolutionRenderableImage is constructed from a - * Vector of RenderedImages consisting of the images at the specified indices. - * These images will be sorted into order of decreasing resolution (as - * determined by the product of width and height for each image) and inserted - * in this order in the Vector of images used to construct the - * MultiResolutionRenderableImage. Metadata will be set on the component - * RenderedImages as usual for rendered mode. Finally the - * createRendering() invocation will be forwarded to the underlying - * MultiResolutionRenderableImage and the resulting RenderedImage returned.
- * - *Note that using this approach the entire MultiResolutionRenderableImage - * must be regenerated for each invocation of createRendering(). If multiple - * renderings are to be created from the RenderableImage without changing - * the operation parameters, then a more efficient approach would be to use the - * "JAI.RenderableInput" property to be described.
- * - *Property Name | - *Type | - *Comment | - *
---|---|---|
JAI.RenderableInput | - *RenderableImage | - *A RenderableImage derived from the input source according to the supplied set of parameters. | - *
The RenderableImage which is the value of the foregoing property may have - * set on it any of the properties previously described for rendered mode - * contingent on parameter settings and data availability. The image metadata - * and thumbnail properties would be copied from the highest resolution image - * among those specified by the ImageChoice parameter.
- * - *If multiple renderings are to be created from the RenderableImage - * without changing the operation parameters, then an efficient alternative - * approach to multiple invocations of createRendering() on the RenderableImage - * is to obtain the RenderableImage value of the "JAI.RenderableInput" property - * and invoke createRendering() on this value.
- * - *Collection
of RenderedImage
s from the specified
- * input source. This could be used for example to load an animated GIF
- * image or a multi-page TIFF image.
- *
- * It should be noted that although they are discussed in the context of - * rendered mode, the parameter synchronization - * policy and ImageLayout handling methodology - * apply to collection mode as well.
- * - *ParameterBlock
- * and invokes {@link JAI#create(String,ParameterBlock,RenderingHints)}.
- *
- * @param input The input source.
- * @param imageChoice The index of the image to read.
- * @param readMetadata Whether metadata should be read if available.
- * @param readThumbnails Whether thumbnails should be read if available.
- * @param verifyInput Whether to verify the validity of the input source.
- * @param listeners EventListeners to be registered with the ImageReader.
- * @param locale The Locale for the ImageReader to use.
- * @param readParam Java Image I/O read parameter instance.
- * @param reader Java Image I/O reader instance.
- * @param hints Hints possibly including an ImageLayout
.
- * @return an image derived from the input source.
- */
- public static RenderedOp create(ImageInputStream input,
- Integer imageChoice,
- Boolean readMetadata,
- Boolean readThumbnails,
- Boolean verifyInput,
- EventListener[] listeners,
- Locale locale,
- ImageReadParam readParam,
- ImageReader reader,
- RenderingHints hints) {
-
- ParameterBlock args = new ParameterBlock();
-
- args.add(input);
- args.add(imageChoice);
- args.add(readMetadata);
- args.add(readThumbnails);
- args.add(verifyInput);
- args.add(listeners);
- args.add(locale);
- args.add(readParam);
- args.add(reader);
-
- return JAI.create(OPERATION_NAME, args, hints);
- }
-
- /**
- * Type-safe convenience method for creating a {@link Collection}
- * representing the "ImageRead" operation in collection mode. The
- * method packs the parameters into a new ParameterBlock
- * and invokes
- * {@link JAI#createCollection(String,ParameterBlock, RenderingHints)}.
- *
- * @param input The input source.
- * @param imageChoice The indices of the images to read.
- * @param readMetadata Whether metadata should be read if available.
- * @param readThumbnails Whether thumbnails should be read if available.
- * @param verifyInput Whether to verify the validity of the input source.
- * @param listeners EventListeners to be registered with the ImageReader.
- * @param locale The Locale for the ImageReader to use.
- * @param readParam Java Image I/O read parameter instance.
- * @param reader Java Image I/O reader instance.
- * @param hints Hints possibly including an ImageLayout
.
- * @return a collection of images derived from the input source.
- */
- public static Collection createCollection(ImageInputStream input,
- int[] imageChoice,
- Boolean readMetadata,
- Boolean readThumbnails,
- Boolean verifyInput,
- EventListener[] listeners,
- Locale locale,
- ImageReadParam readParam,
- ImageReader reader,
- RenderingHints hints) {
-
- ParameterBlock args = new ParameterBlock();
-
- args.add(input);
- args.add(imageChoice);
- args.add(readMetadata);
- args.add(readThumbnails);
- args.add(verifyInput);
- args.add(listeners);
- args.add(locale);
- args.add(readParam);
- args.add(reader);
-
- return JAI.createCollection(OPERATION_NAME, args, hints);
- }
-
- /**
- * Type-safe convenience method for creating a {@link RenderableOp}
- * representing the "ImageRead" operation in renderable mode. The
- * method packs the parameters into a new ParameterBlock
- * and invokes
- * {@link JAI#createRenderable(String,ParameterBlock,RenderingHints)}.
- *
- * @param input The input source.
- * @param imageChoice The indices of the images to read.
- * @param readMetadata Whether metadata should be read if available.
- * @param readThumbnails Whether thumbnails should be read if available.
- * @param verifyInput Whether to verify the validity of the input source.
- * @param listeners EventListeners to be registered with the ImageReader.
- * @param locale The Locale for the ImageReader to use.
- * @param readParam Java Image I/O read parameter instance.
- * @param reader Java Image I/O reader instance.
- * @param hints Hints possibly including an ImageLayout
.
- * @return an image capable of rendering an image from those in the
- * input source.
- */
- public static RenderableOp createRenderable(ImageInputStream input,
- int[] imageChoice,
- Boolean readMetadata,
- Boolean readThumbnails,
- Boolean verifyInput,
- EventListener[] listeners,
- Locale locale,
- ImageReadParam readParam,
- ImageReader reader,
- RenderingHints hints) {
-
- ParameterBlock args = new ParameterBlock();
-
- args.add(input);
- args.add(imageChoice);
- args.add(readMetadata);
- args.add(readThumbnails);
- args.add(verifyInput);
- args.add(listeners);
- args.add(locale);
- args.add(readParam);
- args.add(reader);
-
- return JAI.createRenderable(OPERATION_NAME, args, hints);
- }
-
- /**
- * Returns the array of {@link PropertyGenerator}s for the specified
- * mode of this operation.
- *
- * For renderable mode returns an array containing a single
- * PropertyGenerator
which defines a
- * {@link RenderableImage}-valued property named "JAI.RenderableInput".
- * For all other modes null
is returned.
PropertyGenerator
- * if modeName
is "renderable" (case-insensitive) or
- * null
otherwise.
- */
- public PropertyGenerator[] getPropertyGenerators(String modeName) {
- return modeName.equalsIgnoreCase(RenderableRegistryMode.MODE_NAME) ?
- new PropertyGenerator[] { new ImageReadPropertyGenerator() } :
- null;
- }
-
- /**
- * Validates the parameters in the supplied ParameterBlock
.
- *
- * In addition to the standard validation performed by the - * corresponding superclass method, this method verifies the following: - *
TRUE
and Input
- * is a File
or String
, whether the
- * corresponding physical file exists and is readable; andTRUE
and Input
- * is a String
, converting which to a
- * corresponding physical file failed, whether it can be converted
- * to an InputStream accessed as a resource from a JAR file; andTRUE
and Input
- * is a Socket
, whether it is bound, connected, open,
- * and the read-half is not shut down.msg
and
- * false
will be returned; otherwise true
will
- * be returned.
- *
- * The file existence and readability verification may be suppressed
- * by setting the VerifyInput parameter to FALSE
.
- * This might be desirable for example if the operation is being
- * created for remote rendering and Input is a file which is at
- * a location visible on the remote peer but not on the host on which
- * the operation is created.
OperationDescriptor
describing the "ImageWrite" operation.
- *
- * The "ImageWrite" operation uses the - * Java - * Image I/O Framework to write images to an output destination. Which - * formats may be written depends on which {@link javax.imageio.ImageWriter} - * plug-ins are registered with the Image I/O Framework when the operation is - * invoked.
- * - *The output destination will usually be an
- * {@link javax.imageio.stream.ImageOutputStream}, but may be a
- * {@link java.io.File}, {@link java.io.RandomAccessFile},
- * {@link java.io.OutputStream}, {@link java.net.Socket},
- * {@link java.nio.channels.WritableByteChannel}, file path represented as a
- * String
or some other type compatible with a writer plug-in. The
- * {@link javax.imageio.ImageIO} class should be used to specify the location
- * and enable the use of cache files via its setCacheDirectory()
- * and setUseCache()
methods, respectively. Note that this cache
- * pertains to image stream caching and is unrelated to the JAI
- * TileCache
. If an {@link javax.imageio.stream.ImageOutputStream}
- * is created internally by the operation, for example from a
- * {@link java.io.File}-valued Output parameter,
- * then it will be flushed automatically if and only if the operation is not
- * in collection mode and pixel replacement is
- * not occurring.
The "ImageWrite" operation supports rendered,
- * renderable, and
- * collection modes and requires a single
- * source. The operation is "immediate" for all modes as specified by
- * OperationDescriptor.isImmediate()
so that
- * {@link #isImmediate()} returns true
. The operation will
- * therefore be rendered when created via either JAI.create[NS]()
- * or JAI.createCollection[NS]()
.
- * A {@link java.awt.RenderingHints} object supplied when the
- * operation is created will have no effect except with respect to the
- * mapping of JAI.KEY_INTERPOLATION
and then only in renderable
- * mode.
Image properties are used to pass metadata and other information to the - * writer plug-in and to make available metadata as actually written to the - * output destination. Property handling is mode-specific.
- * - *Name | Value |
---|---|
GlobalName | ImageWrite |
LocalName | ImageWrite |
Vendor | com.sun.media.jai |
Description | Writes an image using the Java Image I/O Framework. |
DocURL | http://java.sun.com/products/java-media/jai/forDevelopers/jai-imageio-1_0-rc-docs/com/sun/media/jai/operator/ImageWriteDescriptor.html |
Version | 1.0 |
arg0Desc | The output destination. |
arg1Desc | The format name of the output. |
arg2Desc | Whether to use image metadata properties as fallbacks. |
arg3Desc | Whether to transcode metadata before writing. |
arg4Desc | Whether to verify the validity of the output destination. |
arg5Desc | Whether to allow pixel replacement in the output image. |
arg6Desc | The tile size of the output image. |
arg7Desc | Stream metadata to write to the output. |
arg8Desc | Image metadata to write to the output. |
arg9Desc | Thumbnails to write to the output. |
arg10Desc | EventListeners to be registered with the ImageWriter. |
arg11Desc | The Locale for the ImageWriter to use. |
arg12Desc | Java Image I/O write parameter instance. |
arg13Desc | Java Image I/O writer instance. |
Name | Class Type | - *Default Value |
---|---|---|
- * Output | java.lang.Object.class | - *NO_PARAMETER_DEFAULT | - *
- * Format | java.lang.String | - *null | - *
- * UseProperties | java.lang.Boolean | - *TRUE | - *
- * Transcode | java.lang.Boolean | - *TRUE | - *
- * VerifyOutput | java.lang.Boolean | - *TRUE | - *
- * AllowPixelReplacement | java.lang.Boolean | - *FALSE | - *
- * TileSize | java.awt.Dimension | - *null | - *
- * StreamMetadata | javax.imageio.metadata.IIOMetadata | - *null | - *
- * ImageMetadata | javax.imageio.metadata.IIOMetadata | - *null | - *
- * Thumbnails | java.awt.BufferedImage[] | - *null | - *
- * Listeners | java.util.EventListener[] | - *null | - *
- * Locale | java.util.Locale | - *null | - *
- * WriteParam | javax.imageio.ImageWriteParam | - *null | - *
- * Writer | javax.imageio.ImageWriter | - *null | - *
The rendered mode parameters are handled as follows: - * - *
In the Sun Microsystems implementation of this operation these potential - * conflicts have been mitigated to a certain extent: - * - *
- * if ImageWriter cannot write tiles - * output is untiled - * else - * if TileSize parameter is non-null - * set tile size to TileSize - * else - * if WriteParam is null - * set tile size to source tile size - * else - * if tilingMode is ImageWriteParam.MODE_EXPLICIT - * if tile dimension is set in WriteParam - * set tile size to tile dimension from WriteParam - * else - * if preferred tile dimension is set in WriteParam - * set tile size to average of first two preferred dimensions - * else - * set tile size to source tile size - * else // tilingMode is not ImageWriteParam.MODE_EXPLICIT - * the plug-in decides the tile size - *- * - * There is no mechanism to set the tile grid offsets of the output. - * - *
Note that this behavior differs from what would happen if the RenderedOp - * created by the operation received a RenderingChangeEvent: in this case a - * new rendering of the node would be created using the ParameterBlock and - * RenderingHints currently in effect. This would cause the entire image to be - * rewritten at the current position of the output. This will also happen - * when AllowPixelReplacement is FALSE. In effect in both of these cases the - * behavior in response to a RenderingChangeEvent is unspecified and the result - * will likely be unexpected.
- * - *To avoid any inadvertent overwriting of the destination as a result of - * events received by the RenderedOp, the following usage is recommended when - * the objective is automatic pixel replacement: - * - *
- * // Sources, parameters, and hints. - * ParameterBlock args; - * RenderingHints hints; - * - * // Create the OperationNode. - * RenderedOp imageWriteNode = JAI.create("ImageWrite", args, hints); - * - * // Get the rendering which already exists due to "immediate" status. - * RenderedImage imageWriteRendering = imageWriteNode.getRendering(); - * - * // Unhook the OperationNode as a sink of its source OperationNode. - * imageWriteNode.getSourceImage(0).removeSink(imageWriteNode); - * - * // Add the rendering as a sink of the source OperationNode. - * imageWriteNode.getSourceImage(0).addSink(imageWriteRendering); - * - * // Free the OperationNode for garbage collection. - * imageWriteNode = null; - *- * - * At this point a reference to imageWriteRendering must be held as long as the - * data of the source of the operation may change. Then provided the events are - * correctly propagated to imageWriteRendering, the data in the output file - * will be automatically updated to match the source data. - * - *
If pixel replacement is not the objective and inadvertent overwriting is - * to be avoided then the safest approach would be the following: - * - *
- * // Create the OperationNode. - * RenderedOp imageWriteNode = JAI.create("ImageWrite", args, hints); - * - * // Unhook the OperationNode as a sink of its source - * imageWriteNode.getSourceImage(0).removeSink(imageWriteNode); - *- * - * The image is written by the first statement and no reference to the - * rendering need be retained as before. - * - *
Property Name | - *Type | - *Comment | - *
---|---|---|
JAI.ImageWriteParam | - *ImageWriteParam | - *Set to ImageWriteParam actually used which may differ from the one passed in. | - *
JAI.ImageWriter | - *ImageWriter | - *Set to ImageWriter actually used. | - *
JAI.ImageMetadata | - *IIOMetadata | - *Set if and only if image metadata are available; may be transcoded. | - *
JAI.StreamMetadata | - *IIOMetadata | - *Set if and only if stream metadata are available; may be transcoded. | - *
JAI.Thumbnails | - *BufferedImage[] | - *Set if and only thumbnails are provided and the writer supportes writing them. | - *
If a given property is not set, this implies of course that the names of - * absent properties will not appear in the array returned by getPropertyNames() - * and getProperty() invoked to obtain absent properties will return - * java.awt.Image.UndefinedProperty as usual.
- * - *The ImageWriter and ImageWriteParam may be used for subsequent invocations - * of the operation or for informational purposes. Care should be taken in using - * these property values with respect to the synchronization issues previously - * discussed.
- * - *Metadata properties will be set to those actually written to the output. They - * may be derived either from input parameters or source properties depending on - * the values of the StreamMetadata, ImageMetadata, and UseProperties parameters. - * They will be transcoded data if Transcode is TRUE and the ImageWriter supports - * transcoding.
- * - *All properties will be set when the node is rendered.
- * - *JAI.KEY_INTERPOLATION
is supplied via a
- * RenderingHints
passed to the operation, then the interpolation
- * type it specifies will be used to create the rendering if interpolation is
- * required.
- *
- * The Collection is treated as a sequence of images which will be - * extracted from the Collection in the order returned by a new Iterator. - * Elements in the Collection which are not RenderedImages will be ignored. - * The derived sequence of images will then be written to the output.
- * - *If there is only one RenderedImage in the source Collection, this image - * will be written as done in rendered mode operation. If there is more than - * one RenderedImage, the sequence of RenderedImages will be written as an - * image sequence. In the latter case the ImageWriter must be able to write - * sequences.
- * - *Name | Class Type | - *Default Value |
---|---|---|
ImageMetadata | javax.imageio.metadataIIOMetadata[] | - *null | - *
Thumbnails | java.awt.image.BufferedImage[][] | - *null | - *
- * The change to the ImageMetadata and Thumbnails parameters is that there can - * now be a distinct image metadata object and thumbnail array for each image - * in the Collection. The components of these respective arrays will be indexed - * using the sequence of RenderedImages extracted from the source Collection by - * the Iterator. It is the responsibility of the caller to ensure that this - * sequencing is correct. In this context it is advisable to use a source - * Collection which maintains the order of its elements such as a List. - *
- * - *- * To ensure proper termination of the image sequence and avoid any inadvertent - * overwriting of the destination as a result of events received by the - * CollectionOp, the following usage is recommended when the objective is - * automatic pixel replacement: - * - *
- * // Sources, parameters, and hints. - * ParameterBlock args; - * RenderingHints hints; - * - * // Create the Collection. - * CollectionImage imageWriteCollection = - * (CollectionImage)JAI.createCollection("ImageWrite", args, hints); - * - * // Unhook the Collection node from the source to avoid - * // re-renderings caused by CollectionChangeEvents. - * if(args.getSource(0) instanceof CollectionImage) { - * CollectionImage sourceCollection = - * (CollectionImage)args.getSource(0); - * sourceCollection.removeSink(imageWriteCollection); - * } - * - * // !!! Pixel replacement activity happens here ... !!! - * - * // Get the ImageWriter. - * ImageWriter writer = - * (ImageWriter)imageWriteCollection.getProperty("JAI.ImageWriter"); - * - * // End the sequence if necessary. - * if(writer.canWriteSequence()) { - * writer.endWriteSequence(); - * } - *- * - * - *
- * Using the foregoing construct, all pixels in all images written to the output - * sequence will remain current with the in-memory data of their respective - * source provided all events are propagated as expected. Note that it is not - * necessary to end the sequence manually if pixel replacement is not allowed or - * is not supported. Also the sequence must be manually ended if and only if the - * writer is capable of writing sequences. This permits pixel replacement to - * work in the case where the source collection contains only a single image - * and the writer supports pixel replacement but cannot write sequences. - *
- * - *- * If pixel replacement is not the objective, i.e., AllowPixelReplacement is - * FALSE, and inadvertent overwriting is to be avoided then the safest approach - * would be the following: - * - *
- * // Create the Collection. - * Collection imageWriteCollection = - * JAI.create("ImageWrite", args, hints); - * - * // Unhook the Collection node from the source to avoid - * // re-renderings caused by CollectionChangeEvents. - * if(args.getSource(0) instanceof CollectionImage) { - * CollectionImage sourceCollection = - * (CollectionImage)args.getSource(0); - * sourceCollection.removeSink(imageWriteCollection); - * } - *- * - * The image is written by the first statement and no reference to the - * rendering need be retained. - * - *
ParameterBlock
and invokes
- * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
- *
- * @param source The image to be written.
- * @param output The output destination.
- * @param format The format name of the output.
- * @param useProperties Whether to use image metadata properties as
- * fallbacks.
- * @param transcode Whether to transcode metadata before writing.
- * @param verifyOutput Whether to verify the validity of the output
- * destination.
- * @param allowPixelReplacement Whether to allow pixel replacement
- * in the output image.
- * @param tileSize The tile size of the output image.
- * @param streamMetadata Stream metadata to write to the output.
- * @param imageMetadata Image metadata to write to the output.
- * @param thumbnails Thumbnails to write to the output.
- * @param listeners EventListeners to be registered with the ImageWriter.
- * @param locale The Locale for the ImageWriter to use.
- * @param writeParam Java Image I/O write parameter instance.
- * @param writer Java Image I/O writer instance.
- * @param hints Operation hints.
- * @return a reference to the operation source.
- */
- public static RenderedOp create(RenderedImage source,
- ImageOutputStream output,
- String format,
- Boolean useProperties,
- Boolean transcode,
- Boolean verifyOutput,
- Boolean allowPixelReplacement,
- Dimension tileSize,
- IIOMetadata streamMetadata,
- IIOMetadata imageMetadata,
- BufferedImage[] thumbnails,
- EventListener[] listeners,
- Locale locale,
- ImageWriteParam writeParam,
- ImageWriter writer,
- RenderingHints hints) {
-
- ParameterBlock args = new ParameterBlock();
-
- args.addSource(source);
-
- args.add(output);
- args.add(format);
- args.add(useProperties);
- args.add(transcode);
- args.add(verifyOutput);
- args.add(allowPixelReplacement);
- args.add(tileSize);
- args.add(streamMetadata);
- args.add(imageMetadata);
- args.add(thumbnails);
- args.add(listeners);
- args.add(locale);
- args.add(writeParam);
- args.add(writer);
-
- return JAI.create(OPERATION_NAME, args, hints);
- }
-
- /**
- * Type-safe convenience method for creating a {@link Collection}
- * representing the "ImageWrite" operation in collection mode. The
- * method packs the source and parameters into a new
- * ParameterBlock
and invokes
- * {@link JAI#createCollection(String,ParameterBlock,RenderingHints)}.
- *
- * @param source The collection to be written.
- * @param output The output destination.
- * @param format The format name of the output.
- * @param useProperties Whether to use image metadata properties as
- * fallbacks.
- * @param transcode Whether to transcode metadata before writing.
- * @param verifyOutput Whether to verify the validity of the output
- * destination.
- * @param allowPixelReplacement Whether to allow pixel replacement
- * in the output image.
- * @param tileSize The tile size of the output image.
- * @param streamMetadata Stream metadata to write to the output.
- * @param imageMetadata Image metadata to write to the output.
- * @param thumbnails Thumbnails to write to the output.
- * @param listeners EventListeners to be registered with the ImageWriter.
- * @param locale The Locale for the ImageWriter to use.
- * @param writeParam Java Image I/O write parameter instance.
- * @param writer Java Image I/O writer instance.
- * @param hints Operation hints.
- * @return a reference to the operation source.
- */
- public static Collection createCollection(Collection source,
- ImageOutputStream output,
- String format,
- Boolean useProperties,
- Boolean transcode,
- Boolean verifyOutput,
- Boolean allowPixelReplacement,
- Dimension tileSize,
- IIOMetadata streamMetadata,
- IIOMetadata[] imageMetadata,
- BufferedImage[][] thumbnails,
- EventListener[] listeners,
- Locale locale,
- ImageWriteParam writeParam,
- ImageWriter writer,
- RenderingHints hints) {
-
- ParameterBlock args = new ParameterBlock();
-
- args.addSource(source);
-
- args.add(output);
- args.add(format);
- args.add(useProperties);
- args.add(transcode);
- args.add(verifyOutput);
- args.add(allowPixelReplacement);
- args.add(tileSize);
- args.add(streamMetadata);
- args.add(imageMetadata);
- args.add(thumbnails);
- args.add(listeners);
- args.add(locale);
- args.add(writeParam);
- args.add(writer);
-
- return JAI.createCollection(OPERATION_NAME, args, hints);
- }
-
- /**
- * Type-safe convenience method for creating a {@link RenderableOp}
- * representing the "ImageWrite" operation in renderable mode. The
- * method packs the source and parameters into a new
- * ParameterBlock
and invokes
- * {@link JAI#createRenderable(String,ParameterBlock,RenderingHints)}.
- *
- * @param source The renderable source to be written.
- * @param output The output destination.
- * @param format The format name of the output.
- * @param useProperties Whether to use image metadata properties as
- * fallbacks.
- * @param transcode Whether to transcode metadata before writing.
- * @param verifyOutput Whether to verify the validity of the output
- * destination.
- * @param allowPixelReplacement Whether to allow pixel replacement
- * in the output image.
- * @param tileSize The tile size of the output image.
- * @param streamMetadata Stream metadata to write to the output.
- * @param imageMetadata Image metadata to write to the output.
- * @param thumbnails Thumbnails to write to the output.
- * @param listeners EventListeners to be registered with the ImageWriter.
- * @param locale The Locale for the ImageWriter to use.
- * @param writeParam Java Image I/O write parameter instance.
- * @param writer Java Image I/O writer instance.
- * @param hints Operation hints.
- * @return a reference to the operation source.
- */
- public static RenderableOp createRenderable(RenderableImage source,
- ImageOutputStream output,
- String format,
- Boolean useProperties,
- Boolean transcode,
- Boolean verifyOutput,
- Boolean allowPixelReplacement,
- Dimension tileSize,
- IIOMetadata streamMetadata,
- IIOMetadata imageMetadata,
- BufferedImage[] thumbnails,
- EventListener[] listeners,
- Locale locale,
- ImageWriteParam writeParam,
- ImageWriter writer,
- RenderingHints hints) {
- ParameterBlock args = new ParameterBlock();
-
- args.addSource(source);
-
- args.add(output);
- args.add(format);
- args.add(useProperties);
- args.add(transcode);
- args.add(verifyOutput);
- args.add(allowPixelReplacement);
- args.add(tileSize);
- args.add(streamMetadata);
- args.add(imageMetadata);
- args.add(thumbnails);
- args.add(listeners);
- args.add(locale);
- args.add(writeParam);
- args.add(writer);
-
- return JAI.createRenderable(OPERATION_NAME, args, hints);
- }
-
- /**
- * Returns true indicating that the operation should be rendered
- * immediately during a call to JAI.create[]()
or
- * JAI.createCollection[NS]()
.
- *
- * @see javax.media.jai.OperationDescriptor
- */
- public boolean isImmediate() {
- return true;
- }
-
- /**
- * Validates the parameters in the supplied ParameterBlock
.
- *
- * In addition to the standard validation performed by the - * corresponding superclass method, this method verifies the following: - *
TRUE
and Output
- * is a File
or String
, whether the
- * corresponding physical file is writable, i.e., exists and may
- * be overwritten or does not exist and may be created; andTRUE
and Output
- * is a Socket
, whether it is bound, connected, open,
- * and the write-half is not shut down; andmodeName
equals
- * {@link CollectionRegistryMode#MODE_NAME}), the source is not a
- * {@link CollectionOp}, and the size of the source
- * {@link Collection} is greater than unity, whether the
- * {@link ImageWriter} cannot write sequences.msg
and
- * false
will be returned; otherwise true
will
- * be returned.
- *
- * @param modeName The operation mode.
- * @param args The source and parameters of the operation.
- * @param msg A container for any error messages.
- *
- * @return Whether the supplied parameters are valid.
- */
- protected boolean validateParameters(String modeName,
- ParameterBlock args,
- StringBuffer msg) {
- if (!super.validateParameters(modeName, args, msg)) {
- return false;
- }
-
- // Get the Output parameter.
- Object output = args.getObjectParameter(0);
-
- // Check the output if so requested by "VerifyOutput".
- Boolean verifyOutput = (Boolean)args.getObjectParameter(4);
- if (verifyOutput.booleanValue()){
- if(output instanceof File || output instanceof String) {
- // Set file and path variables.
- File file = null;
- String path = null;
- if(output instanceof File) {
- file = (File)output;
- path = file.getPath();
- } else if(output instanceof String) {
- path = (String)output;
- file = new File(path);
- }
-
- // Perform non-destructive test that the file
- // may be created and written.
- try {
- if (file.exists()) {
- if (!file.canWrite()) {
- // Cannot write to existing file.
- msg.append(file.getPath() + " " +
- I18N.getString("ImageWriteDescriptor15"));
- return false;
- }
- } else {
- if (!file.createNewFile()) {
- // Cannot create file.
- msg.append(file.getPath() + " " +
- I18N.getString("ImageWriteDescriptor16"));
- return false;
- }
- file.delete();
- }
- } catch (IOException ioe) {
- // I/O exception during createNewFile().
- msg.append(file.getPath() + " " +
- I18N.getString("ImageWriteDescriptor17") + " " +
- ioe.getMessage());
- return false;
- } catch (SecurityException se) {
- // Security exception during exists(), canWrite(),
- // createNewFile(), or delete().
- msg.append(file.getPath() + " " +
- I18N.getString("ImageWriteDescriptor18") + " " +
- se.getMessage());
- return false;
- }
- } else if(output instanceof Socket) {
- Socket socket = (Socket)output;
-
- if(socket.isOutputShutdown()) {
- msg.append("\"" + socket + "\": " +
- I18N.getString("ImageWriteDescriptor19"));
- return false;
- } else if(socket.isClosed()) {
- msg.append("\"" + socket + "\": " +
- I18N.getString("ImageWriteDescriptor20"));
- return false;
- } else if(!socket.isBound()) {
- msg.append("\"" + socket + "\": " +
- I18N.getString("ImageWriteDescriptor21"));
- return false;
- } else if(!socket.isConnected()) {
- msg.append("\"" + socket + "\": " +
- I18N.getString("ImageWriteDescriptor22"));
- return false;
- }
- }
- }
-
- // Get the Format parameter.
- String format = (String)args.getObjectParameter(1);
-
- // Get the ImageWriter parameter.
- ImageWriter writer = (ImageWriter)args.getObjectParameter(13);
-
- if(format == null) {
- // Attempt to get the format from the ImageWriter provider.
- if(writer != null) {
-
- // Get the SPI.
- ImageWriterSpi spi = writer.getOriginatingProvider();
-
- // Set from the SPI.
- if(spi != null) {
- format = spi.getFormatNames()[0];
- }
- }
-
- // Attempt to deduce the format from the file suffix.
- if(format == null &&
- (output instanceof File || output instanceof String)) {
-
- // Set the file name string.
- String name = output instanceof File ?
- ((File)output).getName() : (String)output;
-
- // Extract the suffix.
- String suffix = name.substring(name.lastIndexOf(".") + 1);
-
- // Get the writers of that suffix.
- Iterator writers = ImageIO.getImageWritersBySuffix(suffix);
-
- if(writers != null) {
- // Get the first writer.
- writer = (ImageWriter)writers.next();
-
- if(writer != null) {
- // Get the SPI.
- ImageWriterSpi spi = writer.getOriginatingProvider();
-
- // Set from the SPI.
- if(spi != null) {
- format = spi.getFormatNames()[0];
- }
- }
- }
- }
-
- // Default to the most versatile core Java Image I/O writer.
- if(format == null) {
- format = "PNG";
- }
-
- // Replace the format setting.
- if(format != null) {
- args.set(format, 1);
- }
- }
-
- // Check the tile size parameter if present.
- Dimension tileSize = (Dimension)args.getObjectParameter(6);
- if(tileSize != null && (tileSize.width <= 0 || tileSize.height <= 0)) {
- msg.append(I18N.getString("ImageWriteDescriptor23"));
- return false;
- }
-
- // For collection mode, verify that the source collection contains
- // at least one RenderedImage and that the writer can handle sequences
- // if there is more than one RenderedImage in the source collection.
- if(modeName.equalsIgnoreCase(CollectionRegistryMode.MODE_NAME)) {
- // Get the source collection.
- Collection source = (Collection)args.getSource(0);
-
- // If the source collection is a CollectionOp do not perform this
- // check as invoking source.size() will render the node.
- if(!(source instanceof CollectionOp)) {
-
- // Determine the number of RenderedImages in the Collection.
- int numRenderedImages = 0;
- Iterator iter = source.iterator();
- while(iter.hasNext()) {
- if(iter.next() instanceof RenderedImage) {
- numRenderedImages++;
- }
- }
-
- if(numRenderedImages == 0) {
- msg.append(I18N.getString("ImageWriteDescriptor24"));
- return false;
- } else if(numRenderedImages > 1) {
- // Get the writer parameter.
- writer = (ImageWriter)args.getObjectParameter(13);
-
- // If the parameter writer is null, get one based on the
- // format.
- if(writer == null && format != null) {
- // Get the writers of that format.
- Iterator writers =
- ImageIO.getImageWritersByFormatName(format);
-
- if(writers != null) {
- // Get the first writer.
- writer = (ImageWriter)writers.next();
- }
- }
-
- if(writer != null) {
- // Check that the writer can write sequences.
- if(!writer.canWriteSequence()) {
- msg.append(I18N.getString("ImageWriteDescriptor25"));
- return false;
- }
- }
- }
- }
- }
-
- return true;
- }
-}
diff -urN jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/operator/package.html zzx2/src/share/classes/com/sun/media/jai/operator/package.html
--- jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/operator/package.html 2005-02-11 00:01:57.000000000 -0500
+++ zzx2/src/share/classes/com/sun/media/jai/operator/package.html 1969-12-31 19:00:00.000000000 -0500
@@ -1,52 +0,0 @@
-
-
-
-Provides JAI operations which read and write images using the Java Image
-I/O Framework. These operations are plug-ins which are automatically loaded
-using the javax.media.jai.OperationRegistrySpi
mechanism of JAI.
-
-@since 1.0
-
diff -urN jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/operator/PrintProps.java zzx2/src/share/classes/com/sun/media/jai/operator/PrintProps.java
--- jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/operator/PrintProps.java 2005-02-11 00:01:57.000000000 -0500
+++ zzx2/src/share/classes/com/sun/media/jai/operator/PrintProps.java 1969-12-31 19:00:00.000000000 -0500
@@ -1,85 +0,0 @@
-/*
- * $RCSfile: PrintProps.java,v $
- *
- *
- * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for
- * use in the design, construction, operation or maintenance of any
- * nuclear facility.
- *
- * $Revision: 1.1 $
- * $Date: 2005/02/11 05:01:57 $
- * $State: Exp $
- */
-package com.sun.media.jai.operator;
-
-import java.util.Collection;
-import java.util.Iterator;
-import javax.media.jai.PropertySource;
-
-final class PrintProps {
- static final void print(PropertySource ps) {
- String[] propNames = ps.getPropertyNames();
- if(propNames != null) {
- System.out.println("\nPROPERTIES OF "+
- ps.getClass().getName()+"@"+
- ps.hashCode()+":\n");
- for(int j = 0; j < propNames.length; j++) {
- Object propVal = ps.getProperty(propNames[j]);
- if(propVal == null) {
- System.out.println(propNames[j]+" is NULL.");
- } else if(propVal == java.awt.Image.UndefinedProperty) {
- System.out.println(propNames[j]+" is UNDEFINED.");
- } else {
- System.out.println(propNames[j]+" = "+
- propVal.getClass().getName()+"@"+
- propVal.hashCode());
- }
- }
- } else {
- System.out.println("\n"+ps+" has no properties.");
- }
- System.out.println("\n");
-
- if(ps instanceof Collection) {
- Iterator iter = ((Collection)ps).iterator();
- while(iter.hasNext()) {
- Object nextElement = iter.next();
- if(nextElement instanceof PropertySource) {
- print((PropertySource)nextElement);
- }
- }
- }
- }
-}
diff -urN jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/operator/properties zzx2/src/share/classes/com/sun/media/jai/operator/properties
--- jai-imageio-core-cvs20091111-CLEANED/src/share/classes/com/sun/media/jai/operator/properties 2005-02-11 00:01:57.000000000 -0500
+++ zzx2/src/share/classes/com/sun/media/jai/operator/properties 1969-12-31 19:00:00.000000000 -0500
@@ -1,60 +0,0 @@
-#
-# $RCSfile: properties,v $
-#
-# Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
-#
-# Use is subject to license terms.
-#
-# $Revision: 1.1 $
-# $Date: 2005/02/11 05:01:57 $
-# $State: Exp $
-#
-# Internationalization file for com.sun.media.jai.operator
-
-DescriptorVersion=1.0
-
-ImageReadDescriptor0=Reads an image using the Java Image I/O Framework.
-ImageReadDescriptor1=The input source.
-ImageReadDescriptor2=The index or indices of the image(s) to read.
-ImageReadDescriptor3=Whether metadata should be read if available.
-ImageReadDescriptor4=Whether thumbnails should be read if available.
-ImageReadDescriptor5=Whether to verify the validity of the input source.
-ImageReadDescriptor6=EventListeners to be registered with the ImageReader.
-ImageReadDescriptor7=The Locale for the ImageReader to use.
-ImageReadDescriptor8=Java Image I/O read parameter instance.
-ImageReadDescriptor9=Java Image I/O reader instance.
-ImageReadDescriptor10=Image index parameter must be non-negative.
-ImageReadDescriptor11=does not exist.
-ImageReadDescriptor12=is not readable.
-ImageReadDescriptor13=has its read-half shut down.
-ImageReadDescriptor14=is closed.
-ImageReadDescriptor15=is not bound to an address.
-ImageReadDescriptor16=is not connected.
-
-ImageWriteDescriptor0=Writes an image using the Java Image I/O Framework.
-ImageWriteDescriptor1=The output destination.
-ImageWriteDescriptor2=The format name of the output.
-ImageWriteDescriptor3=Whether to use image metadata properties as fallbacks.
-ImageWriteDescriptor4=Whether to transcode metadata before writing.
-ImageWriteDescriptor5=Whether to verify the validity of the output destination.
-ImageWriteDescriptor6=Whether to allow pixel replacement in the output image.
-ImageWriteDescriptor7=The tile size of the output image.
-ImageWriteDescriptor8=Stream metadata to write to the output.
-ImageWriteDescriptor9=Image metadata to write to the output.
-ImageWriteDescriptor10=Thumbnails to write to the output.
-ImageWriteDescriptor11=EventListeners to be registered with the ImageWriter.
-ImageWriteDescriptor12=The Locale for the ImageWriter to use.
-ImageWriteDescriptor13=Java Image I/O write parameter instance.
-ImageWriteDescriptor14=Java Image I/O writer instance.
-ImageWriteDescriptor15=exists but is not writable.
-ImageWriteDescriptor16=does not exist and cannot be created.
-ImageWriteDescriptor17=encountered IOException during createNewFile:
-ImageWriteDescriptor18=access denied by security manager:
-ImageWriteDescriptor19=has its write-half shut down.
-ImageWriteDescriptor20=is closed.
-ImageWriteDescriptor21=is not bound to an address.
-ImageWriteDescriptor22=is not connected.
-ImageWriteDescriptor23=Non-positive tile dimension specified.
-ImageWriteDescriptor24=No RenderedImages in the source Collection.
-ImageWriteDescriptor25=There is more than one RenderedImage in the source \
-Collection and the supplied ImageWriter cannot write sequences.
diff -urN jai-imageio-core-cvs20091111-CLEANED/src/share/services/javax.imageio.spi.ImageReaderSpi zzx2/src/share/services/javax.imageio.spi.ImageReaderSpi
--- jai-imageio-core-cvs20091111-CLEANED/src/share/services/javax.media.jai.OperationRegistrySpi 2005-02-11 00:02:44.000000000 -0500
+++ zzx2/src/share/services/javax.media.jai.OperationRegistrySpi 1969-12-31 19:00:00.000000000 -0500
@@ -1,47 +0,0 @@
-#
-# $RCSfile: javax.media.jai.OperationRegistrySpi,v $
-#
-#
-# Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistribution of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#
-# - Redistribution in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in
-# the documentation and/or other materials provided with the
-# distribution.
-#
-# Neither the name of Sun Microsystems, Inc. or the names of
-# contributors may be used to endorse or promote products derived
-# from this software without specific prior written permission.
-#
-# This software is provided "AS IS," without a warranty of any
-# kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
-# WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
-# EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
-# NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
-# USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
-# DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
-# ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
-# CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
-# REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
-# INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGES.
-#
-# You acknowledge that this software is not designed or intended for
-# use in the design, construction, operation or maintenance of any
-# nuclear facility.
-#
-# $Revision: 1.1 $
-# $Date: 2005/02/11 05:02:44 $
-# $State: Exp $
-#
-# --- JAI-Image I/O operations registration ---
-#
-com.sun.media.jai.imageioimpl.ImageReadWriteSpi