KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > image > spi > TIFFRegistryEntry


1 /*
2
3    Copyright 2001,2003 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.spi;
19
20 import java.io.IOException JavaDoc;
21 import java.io.InputStream JavaDoc;
22
23 import org.apache.batik.ext.awt.image.codec.SeekableStream;
24 import org.apache.batik.ext.awt.image.codec.tiff.TIFFDecodeParam;
25 import org.apache.batik.ext.awt.image.codec.tiff.TIFFImage;
26 import org.apache.batik.ext.awt.image.renderable.DeferRable;
27 import org.apache.batik.ext.awt.image.renderable.Filter;
28 import org.apache.batik.ext.awt.image.renderable.RedRable;
29 import org.apache.batik.ext.awt.image.rendered.Any2sRGBRed;
30 import org.apache.batik.ext.awt.image.rendered.CachableRed;
31 import org.apache.batik.util.ParsedURL;
32
33 public class TIFFRegistryEntry
34     extends MagicNumberRegistryEntry {
35
36     static final byte [] sig1 = {(byte)0x49, (byte)0x49, 42, 0};
37     static final byte [] sig2 = {(byte)0x4D, (byte)0x4D, 0, 42};
38
39     static MagicNumberRegistryEntry.MagicNumber [] magicNumbers = {
40         new MagicNumberRegistryEntry.MagicNumber(0, sig1),
41         new MagicNumberRegistryEntry.MagicNumber(0, sig2) };
42
43     static final String JavaDoc [] exts = {"tiff", "tif" };
44     static final String JavaDoc [] mimeTypes = {"image/tiff", "image/tif" };
45
46     public TIFFRegistryEntry() {
47         super("TIFF", exts, mimeTypes, magicNumbers);
48     }
49
50     /**
51      * Decode the Stream into a RenderableImage
52      *
53      * @param inIS The input stream that contains the image.
54      * @param origURL The original URL, if any, for documentation
55      * purposes only. This may be null.
56      * @param needRawData If true the image returned should not have
57      * any default color correction the file may
58      * specify applied. */

59     public Filter handleStream(InputStream JavaDoc inIS,
60                                ParsedURL origURL,
61                                boolean needRawData) {
62
63         final DeferRable dr = new DeferRable();
64         final InputStream JavaDoc is = inIS;
65         final String JavaDoc errCode;
66         final Object JavaDoc [] errParam;
67         if (origURL != null) {
68             errCode = ERR_URL_FORMAT_UNREADABLE;
69             errParam = new Object JavaDoc[] {"TIFF", origURL};
70         } else {
71             errCode = ERR_STREAM_FORMAT_UNREADABLE;
72             errParam = new Object JavaDoc[] {"TIFF"};
73         }
74
75         Thread JavaDoc t = new Thread JavaDoc() {
76                 public void run() {
77                     Filter filt;
78                     try {
79                         TIFFDecodeParam param = new TIFFDecodeParam();
80                         SeekableStream ss =
81                             SeekableStream.wrapInputStream(is, true);
82                         CachableRed cr = new TIFFImage(ss, param, 0);
83                         cr = new Any2sRGBRed(cr);
84                         filt = new RedRable(cr);
85                     } catch (IOException JavaDoc ioe) {
86                         filt = ImageTagRegistry.getBrokenLinkImage
87                             (this, errCode, errParam);
88                     } catch (ThreadDeath JavaDoc td) {
89                         throw td;
90                     } catch (Throwable JavaDoc t) {
91                         filt = ImageTagRegistry.getBrokenLinkImage
92                             (this, errCode, errParam);
93                     }
94
95                     dr.setSource(filt);
96                 }
97             };
98         t.start();
99         return dr;
100     }
101 }
102
Popular Tags