TIFFImageDecoder.java
上传用户:btjssb159
上传日期:2018-01-04
资源大小:241k
文件大小:6k
- /*
- * Copyright (c) 2001 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:
- *
- * -Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * -Redistribution in binary form must reproduct 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 AND ITS LICENSORS SHALL NOT BE
- * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
- * OR DISTRIBUTING THE 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 SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that Software is not designed,licensed or intended for use in
- * the design, construction, operation or maintenance of any nuclear facility.
- */
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.Transparency;
- import java.awt.color.ColorSpace;
- import java.awt.image.ColorModel;
- import java.awt.image.DataBuffer;
- import java.awt.image.DataBufferByte;
- import java.awt.image.DataBufferShort;
- import java.awt.image.DataBufferUShort;
- import java.awt.image.Raster;
- import java.awt.image.WritableRaster;
- import java.awt.image.RenderedImage;
- import java.awt.image.SampleModel;
- import java.awt.image.IndexColorModel;
- import java.awt.image.MultiPixelPackedSampleModel;
- import java.awt.image.PixelInterleavedSampleModel;
- import java.awt.image.ComponentColorModel;
- import java.io.File;
- import java.io.InputStream;
- import java.io.IOException;
- /**
- * A baseline TIFF reader. The reader has some functionality in addition to
- * the baseline specifications for Bilevel images, for which the group 3 and
- * group 4 decompression schemes have been implemented. Support for LZW
- * decompression has also been added. Support for Horizontal differencing
- * predictor decoding is also included, when used with LZW compression.
- * However, this support is limited to data with bitsPerSample value of 8.
- * When reading in RGB images, support for alpha and extraSamples being
- * present has been added. Support for reading in images with 16 bit samples
- * has been added. Support for the SampleFormat tag (signed samples as well
- * as floating-point samples) has also been added. In all other cases, support
- * is limited to Baseline specifications.
- *
- *
- */
- public class TIFFImageDecoder extends ImageDecoderImpl {
- // All the TIFF tags that we care about
- public static final int TIFF_IMAGE_WIDTH = 256;
- public static final int TIFF_IMAGE_LENGTH = 257;
- public static final int TIFF_BITS_PER_SAMPLE = 258;
- public static final int TIFF_COMPRESSION = 259;
- public static final int TIFF_PHOTOMETRIC_INTERPRETATION = 262;
- public static final int TIFF_FILL_ORDER = 266;
- public static final int TIFF_STRIP_OFFSETS = 273;
- public static final int TIFF_SAMPLES_PER_PIXEL = 277;
- public static final int TIFF_ROWS_PER_STRIP = 278;
- public static final int TIFF_STRIP_BYTE_COUNTS = 279;
- public static final int TIFF_X_RESOLUTION = 282;
- public static final int TIFF_Y_RESOLUTION = 283;
- public static final int TIFF_PLANAR_CONFIGURATION = 284;
- public static final int TIFF_T4_OPTIONS = 292;
- public static final int TIFF_T6_OPTIONS = 293;
- public static final int TIFF_RESOLUTION_UNIT = 296;
- public static final int TIFF_PREDICTOR = 317;
- public static final int TIFF_COLORMAP = 320;
- public static final int TIFF_TILE_WIDTH = 322;
- public static final int TIFF_TILE_LENGTH = 323;
- public static final int TIFF_TILE_OFFSETS = 324;
- public static final int TIFF_TILE_BYTE_COUNTS = 325;
- public static final int TIFF_EXTRA_SAMPLES = 338;
- public static final int TIFF_SAMPLE_FORMAT = 339;
- public static final int TIFF_S_MIN_SAMPLE_VALUE = 340;
- public static final int TIFF_S_MAX_SAMPLE_VALUE = 341;
- public TIFFImageDecoder(SeekableStream input,
- ImageDecodeParam param) {
- super(input, param);
- }
- public int getNumPages() throws IOException {
- return TIFFDirectory.getNumDirectories(input);
- }
- public RenderedImage decodeAsRenderedImage(int page) throws IOException {
- if ((page < 0) || (page >= getNumPages())) {
- throw new IOException(JaiI18N.getString("TIFFImageDecoder0"));
- }
- return new TIFFImage(input, (TIFFDecodeParam)param, page);
- }
- }