keiron 2002/12/05 02:29:12 Modified: src/org/apache/fop/image GifImage.java Log: use a dummy url connection to enable loading of gif image Revision Changes Path 1.7 +58 -10 xml-fop/src/org/apache/fop/image/GifImage.java Index: GifImage.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/GifImage.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- GifImage.java 14 Nov 2002 15:19:41 -0000 1.6 +++ GifImage.java 5 Dec 2002 10:29:12 -0000 1.7 @@ -12,6 +12,9 @@ import java.awt.image.ColorModel; import java.awt.image.IndexColorModel; import java.awt.color.ColorSpace; +import java.io.InputStream; +import java.io.IOException; +import java.net.URLConnection; // FOP import org.apache.fop.pdf.PDFColor; @@ -26,26 +29,36 @@ * @see FopImage */ public class GifImage extends AbstractFopImage { - public GifImage(FopImage.ImageInfo imgReader) { - super(imgReader); + /** + * Create a new gif image. + * + * @param imgInfo the image info for this gif image + */ + public GifImage(FopImage.ImageInfo imgInfo) { + super(imgInfo); } + /** + * Load the bitmap for this gif image. + * This loads the data and creates a bitmap byte array + * of the image data. + * To decode the image a dummy URLConnection is used that + * will do the conversion. + * + * @param ua the user agent for loading + */ protected boolean loadBitmap(FOUserAgent ua) { int[] tmpMap = null; - try { - ImageProducer ip = null; - // todo: how to load gif image from stream - //ip = (ImageProducer) inputStream.getContent(); - inputStream.close(); - inputStream = null; + URLConnection con = new DummyConnection(inputStream); + + ImageProducer ip = (ImageProducer) con.getContent(); if (ip == null) { return false; } FopImageConsumer consumer = new FopImageConsumer(ip); ip.startProduction(consumer); - //Load the image into memory while (!consumer.isImageReady()) { Thread.sleep(500); @@ -62,6 +75,9 @@ return false; } + inputStream.close(); + inputStream = null; + ColorModel cm = consumer.getColorModel(); this.bitsPerPixel = 8; // this.bitsPerPixel = cm.getPixelSize(); @@ -144,5 +160,37 @@ return true; } + /** + * A dummy url connection for a gif image in an input stream. + */ + protected static class DummyConnection extends URLConnection { + InputStream inputStream; + DummyConnection(InputStream is) { + super(null); + inputStream = is; + } + + public InputStream getInputStream() throws IOException { + return inputStream; + } + + public void connect() throws IOException { + // do nothing + } + + public String getContentType() { + return "image/gif"; + } + + public int getContentLength() { + try { + return inputStream.available(); + } catch (IOException e) { + + } + return -1; + } + + } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]