001: /*
002: * $RCSfile: TIFFImageDecoder.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.2 $
009: * $Date: 2006/08/22 00:12:04 $
010: * $State: Exp $
011: */
012: package com.sun.media.jai.codecimpl;
013:
014: import java.awt.Point;
015: import java.awt.Rectangle;
016: import java.awt.Transparency;
017: import java.awt.color.ColorSpace;
018: import java.awt.image.ColorModel;
019: import java.awt.image.DataBuffer;
020: import java.awt.image.DataBufferByte;
021: import java.awt.image.DataBufferShort;
022: import java.awt.image.DataBufferUShort;
023: import java.awt.image.Raster;
024: import java.awt.image.WritableRaster;
025: import java.awt.image.RenderedImage;
026: import java.awt.image.SampleModel;
027: import java.awt.image.IndexColorModel;
028: import java.awt.image.MultiPixelPackedSampleModel;
029: import java.awt.image.PixelInterleavedSampleModel;
030: import java.awt.image.ComponentColorModel;
031: import java.io.File;
032: import java.io.InputStream;
033: import java.io.IOException;
034: import com.sun.media.jai.codec.ImageCodec;
035: import com.sun.media.jai.codec.ImageDecoder;
036: import com.sun.media.jai.codec.ImageDecoderImpl;
037: import com.sun.media.jai.codec.ImageDecodeParam;
038: import com.sun.media.jai.codec.SeekableStream;
039: import com.sun.media.jai.codec.TIFFDecodeParam;
040: import com.sun.media.jai.codec.TIFFDirectory;
041: import com.sun.media.jai.codec.TIFFField;
042: import com.sun.media.jai.codecimpl.util.RasterFactory;
043:
044: /**
045: * A baseline TIFF reader. The reader has some functionality in addition to
046: * the baseline specifications for Bilevel images, for which the group 3 and
047: * group 4 decompression schemes have been implemented. Support for LZW
048: * decompression has also been added. Support for Horizontal differencing
049: * predictor decoding is also included, when used with LZW compression.
050: * However, this support is limited to data with bitsPerSample value of 8.
051: * When reading in RGB images, support for alpha and extraSamples being
052: * present has been added. Support for reading in images with 16 bit samples
053: * has been added. Support for the SampleFormat tag (signed samples as well
054: * as floating-point samples) has also been added. In all other cases, support
055: * is limited to Baseline specifications.
056: *
057: * @since EA3
058: *
059: */
060: public class TIFFImageDecoder extends ImageDecoderImpl {
061:
062: // All the TIFF tags that we care about
063: public static final int TIFF_IMAGE_WIDTH = 256;
064: public static final int TIFF_IMAGE_LENGTH = 257;
065: public static final int TIFF_BITS_PER_SAMPLE = 258;
066: public static final int TIFF_COMPRESSION = 259;
067: public static final int TIFF_PHOTOMETRIC_INTERPRETATION = 262;
068: public static final int TIFF_FILL_ORDER = 266;
069: public static final int TIFF_STRIP_OFFSETS = 273;
070: public static final int TIFF_SAMPLES_PER_PIXEL = 277;
071: public static final int TIFF_ROWS_PER_STRIP = 278;
072: public static final int TIFF_STRIP_BYTE_COUNTS = 279;
073: public static final int TIFF_X_RESOLUTION = 282;
074: public static final int TIFF_Y_RESOLUTION = 283;
075: public static final int TIFF_PLANAR_CONFIGURATION = 284;
076: public static final int TIFF_T4_OPTIONS = 292;
077: public static final int TIFF_T6_OPTIONS = 293;
078: public static final int TIFF_RESOLUTION_UNIT = 296;
079: public static final int TIFF_PREDICTOR = 317;
080: public static final int TIFF_COLORMAP = 320;
081: public static final int TIFF_TILE_WIDTH = 322;
082: public static final int TIFF_TILE_LENGTH = 323;
083: public static final int TIFF_TILE_OFFSETS = 324;
084: public static final int TIFF_TILE_BYTE_COUNTS = 325;
085: public static final int TIFF_EXTRA_SAMPLES = 338;
086: public static final int TIFF_SAMPLE_FORMAT = 339;
087: public static final int TIFF_S_MIN_SAMPLE_VALUE = 340;
088: public static final int TIFF_S_MAX_SAMPLE_VALUE = 341;
089:
090: public TIFFImageDecoder(SeekableStream input, ImageDecodeParam param) {
091: super (input, param);
092: }
093:
094: public int getNumPages() throws IOException {
095: try {
096: return TIFFDirectory.getNumDirectories(input);
097: } catch (Exception e) {
098: throw CodecUtils.toIOException(e);
099: }
100: }
101:
102: public RenderedImage decodeAsRenderedImage(int page)
103: throws IOException {
104: if ((page < 0) || (page >= getNumPages())) {
105: throw new IOException(JaiI18N
106: .getString("TIFFImageDecoder0"));
107: }
108: try {
109: return new TIFFImage(input, (TIFFDecodeParam) param, page);
110: } catch (Exception e) {
111: throw CodecUtils.toIOException(e);
112: }
113: }
114: }
|