001: package org.libtiff.jai.operator;
002:
003: /*
004: * XTIFF: eXtensible TIFF libraries for JAI.
005: *
006: * The contents of this file are subject to the JAVA ADVANCED IMAGING
007: * SAMPLE INPUT-OUTPUT CODECS AND WIDGET HANDLING SOURCE CODE License
008: * Version 1.0 (the "License"); You may not use this file except in
009: * compliance with the License. You may obtain a copy of the License at
010: * http://www.sun.com/software/imaging/JAI/index.html
011: *
012: * Software distributed under the License is distributed on an "AS IS"
013: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
014: * the License for the specific language governing rights and limitations
015: * under the License.
016: *
017: * The Original Code is JAVA ADVANCED IMAGING SAMPLE INPUT-OUTPUT CODECS
018: * AND WIDGET HANDLING SOURCE CODE.
019: * The Initial Developer of the Original Code is: Sun Microsystems, Inc..
020: * Portions created by: Niles Ritter
021: * are Copyright (C): Niles Ritter, GeoTIFF.org, 1999,2000.
022: * All Rights Reserved.
023: * Contributor(s): Niles Ritter
024: */
025:
026: // Sun does not expose this in the API, but
027: // its interface is described in the jai examples.
028: import org.libtiff.jai.codecimpl.XTIFFImage;
029: import org.libtiff.jai.codecimpl.XTIFFCodec;
030:
031: import org.libtiff.jai.codec.XTIFFDirectory;
032:
033: // the volatile media stuff
034: import com.sun.media.jai.codec.TIFFDecodeParam;
035: import com.sun.media.jai.codec.SeekableStream;
036: import com.sun.media.jai.codec.ImageCodec;
037:
038: import java.awt.RenderingHints;
039: import java.awt.image.RenderedImage;
040: import java.awt.image.renderable.ParameterBlock;
041: import java.awt.image.renderable.RenderedImageFactory;
042: import javax.media.jai.OperationRegistry;
043: import javax.media.jai.OperationDescriptorImpl;
044: import javax.media.jai.OperationDescriptor;
045: import javax.media.jai.JAI;
046:
047: /** XTIFFDescriptor: A single class that is both an OperationDescriptor and
048: * a RenderedImageFactory for overriding the JAI "tiff" operation.
049: * @see XTIFFDirectory
050: * @see XTIFFTileCodecImpl
051: */
052:
053: public class XTIFFDescriptor extends OperationDescriptorImpl implements
054: RenderedImageFactory {
055:
056: // The resource strings that provide the general documentation
057: // and specify the parameter list for the GeoTIFF operation.
058: private static final String[][] resources = {
059: { "GlobalName", "tiff" },
060: { "LocalName", "tiff" },
061: { "Vendor", "libtiff.org" },
062: { "Description",
063: "A TIFF parser, extending the TIFF operation." },
064: { "DocURL",
065: "http://www.geotiff.org/javadocs/XTIFFDescriptor.html" },
066: { "Version", "1.0" }, { "arg0Desc", "param1" },
067: { "arg1Desc", "param2" } };
068:
069: // The parameter names for the GeoTIFF operation. Extenders may
070: // want to rename them to something more meaningful.
071: private static final String[] paramNames = { "stream", "param" };
072:
073: // The class types for the parameters of the GeoTIFF operation.
074: // User defined classes can be used here as long as the fully
075: // qualified name is used and the classes can be loaded.
076: private static final Class[] paramClasses = {
077: com.sun.media.jai.codec.SeekableStream.class,
078: com.sun.media.jai.codec.TIFFDecodeParam.class };
079:
080: // The default parameter values for the GeoTIFF operation
081: // when using a ParameterBlockJAI.
082: private static final Object[] paramDefaults = { null, null };
083:
084: /**
085: * Standard public constructor
086: */
087: public XTIFFDescriptor() {
088: super (resources, 0, paramClasses, paramNames, paramDefaults);
089: }
090:
091: /**
092: * Create an XTIFFImage with the given ParameterBlock if the
093: * XTIFFImage can handle the particular ParameterBlock. Otherwise,
094: * null image is returned.
095: */
096: public RenderedImage create(ParameterBlock paramBlock,
097: RenderingHints renderHints) {
098: StringBuffer msg = new StringBuffer();
099: if (!validateParameters(paramBlock, msg)) {
100: return null;
101: }
102: try {
103: SeekableStream in = (SeekableStream) paramBlock
104: .getObjectParameter(0);
105: XTIFFImage image = new XTIFFImage(in,
106: (TIFFDecodeParam) paramBlock.getObjectParameter(1),
107: 0);
108: return image;
109: } catch (Exception e) {
110: return null;
111: }
112: }
113:
114: /**
115: * A convenience method for registering XTIFF methods into JAI,
116: * for extended classes of XTIFFDescriptor.
117: */
118: public static void register(XTIFFDescriptor odesc) {
119:
120: OperationRegistry reg = JAI.getDefaultInstance()
121: .getOperationRegistry();
122:
123: // override tiff operation
124: reg.unregisterOperationDescriptor("tiff");
125:
126: // ...and register tiff with the new desc
127: reg.registerOperationDescriptor(odesc, "tiff");
128: reg.registerRIF("tiff", "org.libtiff.jai", odesc);
129:
130: // re-register the tiff codec
131: ImageCodec.unregisterCodec("tiff");
132: ImageCodec.registerCodec(new XTIFFCodec());
133:
134: }
135:
136: /**
137: * A convenience method for registering the default XTIFF
138: * methods into JAI.
139: */
140: public static void register() {
141:
142: // Create the objects
143: XTIFFDescriptor odesc = new XTIFFDescriptor();
144: register(odesc);
145: }
146: }
|