1 18 package org.apache.batik.apps.tiledTranscoder; 19 20 import java.awt.image.renderable.*; 21 import java.awt.image.*; 22 import java.io.*; 23 24 import org.apache.batik.transcoder.*; 25 import org.apache.batik.transcoder.image.*; 26 27 import org.apache.batik.ext.awt.image.*; 28 import org.apache.batik.ext.awt.image.codec.*; 29 import org.apache.batik.ext.awt.image.codec.tiff.*; 30 import org.apache.batik.ext.awt.image.rendered.*; 31 import org.apache.batik.ext.awt.image.renderable.*; 32 33 import org.w3c.dom.Document ; 34 35 public class TiledImageTranscoder extends SVGAbstractTranscoder { 36 37 40 protected TiledImageTranscoder() { 41 } 42 43 44 52 protected void transcode(Document document, 53 String uri, 54 TranscoderOutput output) 55 throws TranscoderException { 56 57 super.transcode(document, uri, output); 59 60 Filter f = this.root.getGraphicsNodeRable(true); 61 62 RenderContext rc = new RenderContext(curTxf, null, null); 63 RenderedImage img = f.createRendering(rc); 64 65 int w = img.getWidth(); 67 int h = img.getHeight(); 68 69 try { 70 int bands = img.getSampleModel().getNumBands(); 71 int [] off = new int[bands]; 72 for (int i=0; i<bands; i++) 73 off[i] = i; 74 SampleModel sm = new PixelInterleavedSampleModel 75 (DataBuffer.TYPE_BYTE, 76 w, (100000+w-1)/w, 77 bands, w*bands, off); 78 79 RenderedImage rimg = new FormatRed(GraphicsUtil.wrap(img), sm); 80 81 TIFFImageEncoder enc = new TIFFImageEncoder 82 (output.getOutputStream(), null); 83 enc.encode(rimg); 84 } catch (IOException ioe) { 85 ioe.printStackTrace(); 86 } 87 } 88 89 90 public static void main (String [] args) { 91 try { 92 FileOutputStream fos = new FileOutputStream(args[1]); 93 TiledImageTranscoder tit = new TiledImageTranscoder(); 94 tit.addTranscodingHint(KEY_WIDTH, new Float (10240)); 95 tit.transcode(new TranscoderInput("file:" + args[0]), 96 new TranscoderOutput(fos)); 97 } catch (IOException ioe) { 98 ioe.printStackTrace(); 99 } catch (TranscoderException te) { 100 te.printStackTrace(); 101 } 102 } 103 } 104 | Popular Tags |