KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > image > codec > tiff > TIFFDecodeParam


1 /*
2
3    Copyright 2001 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.ext.awt.image.codec.tiff;
19
20 import org.apache.batik.ext.awt.image.codec.ImageDecodeParam;
21
22 /**
23  * An instance of <code>ImageDecodeParam</code> for decoding images in
24  * the TIFF format.
25  *
26  * <p> To determine the number of images present in a TIFF file, use
27  * the <code>getNumPages()</code> method on the
28  * <code>ImageDecoder</code> object that will be used to perform the
29  * decoding. The desired page number may be passed as an argument to
30  * the <code>ImageDecoder.decodeAsRaster)()</code> or
31  * <code>decodeAsRenderedImage()</code> methods.
32  *
33  * <p> For TIFF Palette color images, the colorMap always has entries
34  * of short data type, the color Black being represented by 0,0,0 and
35  * White by 65536,65536,65536. In order to display these images, the
36  * default behavior is to dither the short values down to 8 bits.
37  * The dithering is done by calling the <code>decode16BitsTo8Bits</code>
38  * method for each short value that needs to be dithered. The method has
39  * the following implementation:
40  * <code>
41  * byte b;
42  * short s;
43  * s = s & 0xffff;
44  * b = (byte)((s >> 8) & 0xff);
45  * </code>
46  * If a different algorithm is to be used for the dithering, this class
47  * should be subclassed and an appropriate implementation should be
48  * provided for the <code>decode16BitsTo8Bits</code> method in the subclass.
49  *
50  * <p>If the palette contains image data that is signed short, as specified
51  * by the SampleFormat tag, the dithering is done by calling
52  * <code>decodeSigned16BitsTo8Bits</code> instead. The method has the
53  * following implementation:
54  * <code>
55  * byte b;
56  * short s;
57  * b = (byte)((s + Short.MIN_VALUE) >> 8);
58  * </code>
59  * In order to use a different algorithm for the dithering, this class
60  * should be subclassed and the method overridden.
61  *
62  * <p> If it is desired that the Palette be decoded such that the output
63  * image is of short data type and no dithering is performed, the
64  * <code>setDecodePaletteAsShorts</code> method should be used.
65  *
66  * <p><b> This class is not a committed part of the JAI API. It may
67  * be removed or changed in future releases of JAI.</b>
68  *
69  * @see TIFFDirectory
70  */

71 public class TIFFDecodeParam implements ImageDecodeParam {
72
73     private boolean decodePaletteAsShorts = false;
74     private Long JavaDoc ifdOffset = null;
75     private boolean convertJPEGYCbCrToRGB = true;
76     
77     /** Constructs a default instance of <code>TIFFDecodeParam</code>. */
78     public TIFFDecodeParam() {
79     }
80
81     /**
82      * If set, the entries in the palette will be decoded as shorts
83      * and no short to byte lookup will be applied to them.
84      */

85     public void setDecodePaletteAsShorts(boolean decodePaletteAsShorts) {
86     this.decodePaletteAsShorts = decodePaletteAsShorts;
87     }
88     
89     /**
90      * Returns <code>true</code> if palette entries will be decoded as
91      * shorts, resulting in an output image with short datatype.
92      */

93     public boolean getDecodePaletteAsShorts() {
94     return decodePaletteAsShorts;
95     }
96
97     /**
98      * Returns an unsigned 8 bit value computed by dithering the unsigned
99      * 16 bit value. Note that the TIFF specified short datatype is an
100      * unsigned value, while Java's <code>short</code> datatype is a
101      * signed value. Therefore the Java <code>short</code> datatype cannot
102      * be used to store the TIFF specified short value. A Java
103      * <code>int</code> is used as input instead to this method. The method
104      * deals correctly only with 16 bit unsigned values.
105      */

106     public byte decode16BitsTo8Bits(int s) {
107     return (byte)((s >> 8) & 0xffff);
108     }
109
110     /**
111      * Returns an unsigned 8 bit value computed by dithering the signed
112      * 16 bit value. This method deals correctly only with values in the
113      * 16 bit signed range.
114      */

115     public byte decodeSigned16BitsTo8Bits(short s) {
116     return (byte)((s + Short.MIN_VALUE) >> 8);
117     }
118
119     /**
120      * Sets the offset in the stream from which to read the image. There
121      * must be an Image File Directory (IFD) at that position or an error
122      * will occur. If <code>setIFDOffset()</code> is never invoked then
123      * the decoder will assume that the TIFF stream is at the beginning of
124      * the 8-byte image header. If the directory offset is set and a page
125      * number is supplied to the TIFF <code>ImageDecoder</code> then the
126      * page will be the zero-relative index of the IFD in linked list of
127      * IFDs beginning at the specified offset with a page of zero indicating
128      * the directory at that offset.
129      */

130     public void setIFDOffset(long offset) {
131         ifdOffset = new Long JavaDoc(offset);
132     }
133
134     /**
135      * Returns the value set by <code>setIFDOffset()</code> or
136      * <code>null</code> if no value has been set.
137      */

138     public Long JavaDoc getIFDOffset() {
139         return ifdOffset;
140     }
141
142     /**
143      * Sets a flag indicating whether to convert JPEG-compressed YCbCr data
144      * to RGB. The default value is <code>true</code>. This flag is
145      * ignored if the image data are not JPEG-compressed.
146      */

147     public void setJPEGDecompressYCbCrToRGB(boolean convertJPEGYCbCrToRGB) {
148         this.convertJPEGYCbCrToRGB = convertJPEGYCbCrToRGB;
149     }
150
151     /**
152      * Whether JPEG-compressed YCbCr data will be converted to RGB.
153      */

154     public boolean getJPEGDecompressYCbCrToRGB() {
155         return convertJPEGYCbCrToRGB;
156     }
157 }
158
Popular Tags