1 18 package org.apache.batik.ext.awt.image.spi; 19 20 import java.io.IOException ; 21 import java.io.InputStream ; 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 [] exts = {"tiff", "tif" }; 44 static final String [] mimeTypes = {"image/tiff", "image/tif" }; 45 46 public TIFFRegistryEntry() { 47 super("TIFF", exts, mimeTypes, magicNumbers); 48 } 49 50 59 public Filter handleStream(InputStream inIS, 60 ParsedURL origURL, 61 boolean needRawData) { 62 63 final DeferRable dr = new DeferRable(); 64 final InputStream is = inIS; 65 final String errCode; 66 final Object [] errParam; 67 if (origURL != null) { 68 errCode = ERR_URL_FORMAT_UNREADABLE; 69 errParam = new Object [] {"TIFF", origURL}; 70 } else { 71 errCode = ERR_STREAM_FORMAT_UNREADABLE; 72 errParam = new Object [] {"TIFF"}; 73 } 74 75 Thread t = new Thread () { 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 ioe) { 86 filt = ImageTagRegistry.getBrokenLinkImage 87 (this, errCode, errParam); 88 } catch (ThreadDeath td) { 89 throw td; 90 } catch (Throwable 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 |