From 221e730a6dd57756b207abb60b728cf288f3eb7a Mon Sep 17 00:00:00 2001 From: Keiron Liddle Date: Thu, 5 Dec 2002 10:29:12 +0000 Subject: [PATCH] use a dummy url connection to enable loading of gif image git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195733 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/image/GifImage.java | 66 ++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/src/org/apache/fop/image/GifImage.java b/src/org/apache/fop/image/GifImage.java index 2a96271f9..6753584ae 100644 --- a/src/org/apache/fop/image/GifImage.java +++ b/src/org/apache/fop/image/GifImage.java @@ -12,6 +12,9 @@ import java.awt.image.ImageProducer; 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 @@ import org.apache.fop.fo.FOUserAgent; * @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 @@ public class GifImage extends AbstractFopImage { return false; } + inputStream.close(); + inputStream = null; + ColorModel cm = consumer.getColorModel(); this.bitsPerPixel = 8; // this.bitsPerPixel = cm.getPixelSize(); @@ -144,5 +160,37 @@ public class GifImage extends AbstractFopImage { 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; + } + + } } -- 2.39.5