01: package org.libtiff.jai.codecimpl;
02:
03: /*
04: * XTIFF: eXtensible TIFF libraries for JAI.
05: *
06: * The contents of this file are subject to the JAVA ADVANCED IMAGING
07: * SAMPLE INPUT-OUTPUT CODECS AND WIDGET HANDLING SOURCE CODE License
08: * Version 1.0 (the "License"); You may not use this file except in
09: * compliance with the License. You may obtain a copy of the License at
10: * http://www.sun.com/software/imaging/JAI/index.html
11: *
12: * Software distributed under the License is distributed on an "AS IS"
13: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14: * the License for the specific language governing rights and limitations
15: * under the License.
16: *
17: * The Original Code is JAVA ADVANCED IMAGING SAMPLE INPUT-OUTPUT CODECS
18: * AND WIDGET HANDLING SOURCE CODE.
19: * The Initial Developer of the Original Code is: Sun Microsystems, Inc..
20: * Portions created by: Niles Ritter
21: * are Copyright (C): Niles Ritter, GeoTIFF.org, 1999,2000.
22: * All Rights Reserved.
23: * Contributor(s): Niles Ritter
24: */
25:
26: import java.awt.image.RenderedImage;
27: import java.io.OutputStream;
28:
29: import com.sun.media.jai.codec.ImageCodec;
30: import com.sun.media.jai.codec.ImageDecodeParam;
31: import com.sun.media.jai.codec.ImageDecoder;
32: import com.sun.media.jai.codec.ImageEncodeParam;
33: import com.sun.media.jai.codec.ImageEncoder;
34: import com.sun.media.jai.codec.SeekableStream;
35: import com.sun.media.jai.codec.TIFFDecodeParam;
36: import com.sun.media.jai.codec.TIFFEncodeParam;
37:
38: /**
39: * TIFFCodec is declared final so we can't extend it
40: */
41: public class XTIFFCodec extends ImageCodec {
42:
43: public XTIFFCodec() {
44: }
45:
46: static {
47: // All built-in codec support should be here
48: (new XTIFFUncompTileCodec()).register();
49: (new XTIFFLZWTileCodec()).register();
50: (new XTIFFPackTileCodec()).register();
51: (new XTIFFFaxTileCodec()).register();
52: }
53:
54: public String getFormatName() {
55: return "tiff";
56: }
57:
58: public Class getEncodeParamClass() {
59: return TIFFEncodeParam.class;
60: }
61:
62: public Class getDecodeParamClass() {
63: return TIFFDecodeParam.class;
64: }
65:
66: public boolean canEncodeImage(RenderedImage im,
67: ImageEncodeParam param) {
68: return true;
69: }
70:
71: protected ImageEncoder createImageEncoder(OutputStream dst,
72: ImageEncodeParam param) {
73: return new XTIFFImageEncoder(dst, param);
74: }
75:
76: protected ImageDecoder createImageDecoder(SeekableStream src,
77: ImageDecodeParam param) {
78: return new XTIFFImageDecoder(src, param);
79: }
80:
81: public int getNumHeaderBytes() {
82: return 4;
83: }
84:
85: public boolean isFormatRecognized(byte[] header) {
86: if ((header[0] == 0x49) && (header[1] == 0x49)
87: && (header[2] == 0x2a) && (header[3] == 0x00)) {
88: return true;
89: }
90:
91: if ((header[0] == 0x4d) && (header[1] == 0x4d)
92: && (header[2] == 0x00) && (header[3] == 0x2a)) {
93: return true;
94: }
95:
96: return false;
97: }
98: }
|