001: /*
002: * $RCSfile: JPEGTileDecoderFactory.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:56:57 $
010: * $State: Exp $
011: */package com.sun.media.jai.tilecodec;
012:
013: import java.io.InputStream;
014: import java.util.Vector;
015: import javax.media.jai.JAI;
016: import javax.media.jai.ParameterListDescriptor;
017: import javax.media.jai.ParameterListDescriptorImpl;
018: import javax.media.jai.remote.NegotiableCapability;
019: import javax.media.jai.remote.NegotiableNumericRange;
020: import javax.media.jai.remote.NegotiableCollection;
021: import javax.media.jai.tilecodec.TileCodecParameterList;
022: import javax.media.jai.tilecodec.TileDecoder;
023: import javax.media.jai.tilecodec.TileDecoderFactory;
024:
025: /**
026: * A factory for creating <code>JPEGTileDecoder</code>s.
027: *
028: * <p> This class stipulates that the capabilities of the
029: * <code>TileDecoder</code> be specified by implementing the
030: * <code>getDecodingCapability()</code> method.
031: *
032: * @see javax.media.jai.remote.NegotiableCapability
033: */
034: public class JPEGTileDecoderFactory implements TileDecoderFactory {
035:
036: /**
037: * Creates a <code>JPEGTileDecoder</code> capable of decoding the encoded
038: * data from the given <code>InputStream</code> using the specified
039: * <code>TileCodecParameterList</code> containing the decoding
040: * parameters to be used.
041: *
042: * <p> This method can return null if the <code>TileDecoder</code> is not
043: * capable of producing output for the given set of parameters.
044: * For example, if a <code>TileDecoder</code> is only capable of dealing
045: * with a jpeg quality factor of 0.5, and the associated
046: * <code>TileCodecParameterList</code> specifies a quality factor of 0.75,
047: * null should be returned.
048: *
049: * <p>It is recommended that the data in the supplied
050: * <code>InputStream</code> not be used as a factor in determining
051: * whether this <code>InputStream</code> can be successfully decoded,
052: * unless the supplied <code>InputStream</code> is known to be rewindable
053: * (i.e. its <code>markSupported()</code> method returns true or it has
054: * additional functionality that allows backward seeking). It is required
055: * that <code>the</code> InputStream contain the same data on
056: * returning from this method as before this method was called.
057: * In other words, the <code>InputStream</code> should only be used as a
058: * discriminator if it can be rewound to its starting position
059: * before returning from this method. Note that wrapping the
060: * incoming <code>InputStream</code> in a <code>PushbackInputStream</code>
061: * and then rewinding the <code>PushbackInputStream</code> before returning
062: * does not rewind the wrapped <code>InputStream</code>.
063: *
064: * <p> If the supplied <code>TileCodecParameterList</code> is null,
065: * a default <code>TileCodecParameterList</code> from the
066: * <code>TileCodecDescriptor</code> will be used to create the decoder.
067: *
068: * <p> Exceptions thrown by the <code>TileDecoder</code> will be
069: * caught by this method and will not be propagated.
070: *
071: * @param input The <code>InputStream</code> containing the encoded data
072: * to decode.
073: * @param param The parameters to be be used in the decoding process.
074: * @throws IllegalArgumentException if input is null.
075: */
076: public TileDecoder createDecoder(InputStream input,
077: TileCodecParameterList param) {
078:
079: if (input == null)
080: throw new IllegalArgumentException(JaiI18N
081: .getString("TileDecoder0"));
082:
083: return new JPEGTileDecoder(input, param);
084: }
085:
086: /**
087: * Returns the capabilities of this <code>TileDecoder</code> as a
088: * <code>NegotiableCapability</code>.
089: */
090: public NegotiableCapability getDecodeCapability() {
091:
092: Vector generators = new Vector();
093: generators.add(JPEGTileDecoderFactory.class);
094:
095: ParameterListDescriptor jpegPld = JAI.getDefaultInstance()
096: .getOperationRegistry().getDescriptor("tileDecoder",
097: "jpeg").getParameterListDescriptor(
098: "tileDecoder");
099:
100: Class paramClasses[] = {
101: NegotiableNumericRange.class,
102: NegotiableCollection.class,
103: // XXX Find a way to create a negotiable representing integer
104: // arrays
105: // integer array, horizontal subsampling
106: // integer array, vertical subsampling
107: // integer array, quantization table mapping
108: // integer array, quantizationTable0
109: // integer array, quantizationTable1
110: // integer array, quantizationTable2
111: // integer array, quantizationTable3
112: NegotiableNumericRange.class,
113: NegotiableCollection.class, NegotiableCollection.class,
114: NegotiableCollection.class };
115:
116: String paramNames[] = { "quality", "qualitySet",
117: "restartInterval", "writeImageInfo", "writeTableInfo",
118: "writeJFIFHeader" };
119:
120: // A collection containing the valid values for a boolean valued
121: // parameters
122: Vector v = new Vector();
123: v.add(new Boolean(true));
124: v.add(new Boolean(false));
125: NegotiableCollection negCollection = new NegotiableCollection(v);
126:
127: NegotiableNumericRange nnr1 = new NegotiableNumericRange(
128: jpegPld.getParamValueRange(paramNames[0]));
129:
130: NegotiableNumericRange nnr2 = new NegotiableNumericRange(
131: jpegPld.getParamValueRange(paramNames[2]));
132:
133: // The default values
134: Object defaults[] = { nnr1, negCollection, nnr2, negCollection,
135: negCollection, negCollection };
136:
137: NegotiableCapability decodeCap = new NegotiableCapability(
138: "tileCodec", "jpeg", generators,
139: new ParameterListDescriptorImpl(null, //descriptor
140: paramNames, paramClasses, defaults, null), // validValues
141: false); // non-preference
142:
143: // Set the Negotiables representing the valid values on the capability
144: decodeCap.setParameter(paramNames[0], nnr1);
145: decodeCap.setParameter(paramNames[1], negCollection);
146: decodeCap.setParameter(paramNames[2], nnr2);
147: decodeCap.setParameter(paramNames[3], negCollection);
148: decodeCap.setParameter(paramNames[4], negCollection);
149: decodeCap.setParameter(paramNames[5], negCollection);
150:
151: return decodeCap;
152: }
153: }
|