classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] An imageio/ImageDecoder hack


From: Mark Wielaard
Subject: [cp-patches] An imageio/ImageDecoder hack
Date: Mon, 21 Nov 2005 21:30:15 +0100

Hi list, Hi Tom,

While playing a bit with Caliph & Emir I found that our imageio and
ImageDecoder/GdkPixBufDecoder don't play well. The attached patch is a
quick hack to make the Emir splash-screen show up. Should I make a
real/full DataInputStreamWrapper to make a bridge between the two or
will this part be so completely rewritten that even such a hack isn't
worth it?

Cheers,

Mark
Index: gnu/java/awt/image/ImageDecoder.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/image/ImageDecoder.java,v
retrieving revision 1.15
diff -u -r1.15 ImageDecoder.java
--- gnu/java/awt/image/ImageDecoder.java        2 Jul 2005 20:32:11 -0000       
1.15
+++ gnu/java/awt/image/ImageDecoder.java        21 Nov 2005 20:27:51 -0000
@@ -40,6 +40,8 @@
 import java.awt.image.ImageConsumer;
 import java.awt.image.ImageProducer;
 import java.io.ByteArrayInputStream;
+import java.io.DataInput;
+import java.io.EOFException;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -55,6 +57,7 @@
   int offset;
   int length;
   InputStream input;
+  DataInput datainput;
 
   static
   {
@@ -79,6 +82,11 @@
     this.input = is;
   }
 
+  public ImageDecoder (DataInput datainput)
+  {
+    this.datainput = datainput;
+  }
+
   public ImageDecoder (byte[] imagedata, int imageoffset, int imagelength)
   {
     data = imagedata;
@@ -119,6 +127,8 @@
               {
                 if (url != null)
                   input = url.openStream();
+               else if (datainput != null)
+                 input = new DataInputStreamWrapper(datainput);
                 else
                   {
                     if (filename != null)
@@ -153,4 +163,26 @@
   }
 
   public abstract void produce (Vector v, InputStream is) throws IOException;
+
+  private static class DataInputStreamWrapper extends InputStream
+  {
+    private final DataInput datainput;
+
+    DataInputStreamWrapper(DataInput datainput)
+    {
+      this.datainput = datainput;
+    }
+
+    public int read() throws IOException
+    {
+      try
+       {
+         return datainput.readByte() & 0xFF;
+       }
+      catch (EOFException eofe)
+       {
+         return -1;
+       }
+    }
+  }
 }
Index: gnu/java/awt/peer/gtk/GdkPixbufDecoder.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java,v
retrieving revision 1.17
diff -u -r1.17 GdkPixbufDecoder.java
--- gnu/java/awt/peer/gtk/GdkPixbufDecoder.java 21 Aug 2005 02:39:41 -0000      
1.17
+++ gnu/java/awt/peer/gtk/GdkPixbufDecoder.java 21 Nov 2005 20:27:51 -0000
@@ -47,6 +47,7 @@
 import java.awt.image.ImageProducer;
 import java.awt.image.Raster;
 import java.awt.image.RenderedImage;
+import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
 import java.io.InputStream;
@@ -102,6 +103,11 @@
                                                      0x00ff0000, 
                                                      0x0000ff00, 
                                                      0x000000ff);
+  public GdkPixbufDecoder (DataInput datainput)
+  {
+    super (datainput);
+  }
+
   public GdkPixbufDecoder (InputStream in)
   {
     super (in);
@@ -630,7 +636,14 @@
                          boolean ignoreMetadata)
     {
       super.setInput(input, seekForwardOnly, ignoreMetadata);
-      dec = new GdkPixbufDecoder((InputStream) getInput());
+      Object get = getInput();
+      if (get instanceof InputStream)
+        dec = new GdkPixbufDecoder((InputStream) get);
+      else if (get instanceof DataInput)
+        dec = new GdkPixbufDecoder((DataInput) get);
+      else
+       throw new IllegalArgumentException("input object not supported: "
+                                          + get);
     }
 
     public BufferedImage read(int imageIndex, ImageReadParam param)

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]