aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKeiron Liddle <keiron@apache.org>2002-12-05 10:29:12 +0000
committerKeiron Liddle <keiron@apache.org>2002-12-05 10:29:12 +0000
commit221e730a6dd57756b207abb60b728cf288f3eb7a (patch)
treeef6d01da7157ca18d3a4e22516f31747eef46fc7 /src
parent8f52de9da2fe64b86895a3cee3ae3a979ef830fe (diff)
downloadxmlgraphics-fop-221e730a6dd57756b207abb60b728cf288f3eb7a.tar.gz
xmlgraphics-fop-221e730a6dd57756b207abb60b728cf288f3eb7a.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/org/apache/fop/image/GifImage.java66
1 files 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;
+ }
+
+ }
}