]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
added submission from Kelly Campbell that fixed synchronization problem with GifJpeg...
authorjtauber <jtauber@unknown>
Mon, 22 Nov 1999 04:51:56 +0000 (04:51 +0000)
committerjtauber <jtauber@unknown>
Mon, 22 Nov 1999 04:51:56 +0000 (04:51 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193233 13f79535-47bb-0310-9956-ffa450edef68

STATUS
src/org/apache/fop/image/GifJpegImage.java

diff --git a/STATUS b/STATUS
index 44ca9afee60c9012821e516588bbb8098f3dcbc6..e242d3073f586d886f0e6bcf3582aec142cc6fb7 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -10,7 +10,7 @@ Incorporate Arved Sandstrom's simple-link implementation
 Switch to using Status object as return from layout()
 Implement basic keeps
 Incorporate Eric Schaeffer's fix to tables in static-content
-Incorporate Kelly Campell's fixes to GifJpegImage
+[DONE] Incorporate Kelly Campell's fixes to GifJpegImage
 
 Other Bugs to fix:
 
index 4928ee3046fd8e6c24aaa07a66d46be955ef56dd..d04b6b915f0a52a8c3d24a887f0ab9fb8a21a424 100644 (file)
@@ -22,7 +22,7 @@
     Alternately, this  acknowledgment may  appear in the software itself,  if
     and wherever such third-party acknowledgments normally appear.
  
- 4. The names "Fop" and  "Apache Software Foundation"  must not be used to
+ 4. The names "FOP" and  "Apache Software Foundation"  must not be used to
     endorse  or promote  products derived  from this  software without  prior
     written permission. For written permission, please contact
     apache@apache.org.
  Software Foundation, please see <http://www.apache.org/>.
  
  */
-/* modified by JKT to integrate into 0.12.0 */
-
-//Title:        BoBoGi FOP
-//Version:      
-//Copyright:    Copyright (c) 1999
-//Author:       Sergio Botti
-//Company:      Dibe Elsag
-//Description:  xml to pdf converter
 
+/* originally contributed by Sergio Botti, with modifications by James
+   Tauber and Kelly Campbell */
 
 package org.apache.fop.image;
 
@@ -69,102 +63,166 @@ import java.awt.Image;
 import java.awt.Toolkit;
 
 public class GifJpegImage implements FopImage {
-  int X;
-  int Y;
-  int width;
-  int height;
-  int pixelwidth;
-  int pixelheight;
-  String ref;
-  boolean color=true;
-  int bitperpixel=8;
-  int[] imagemap;
-  int[] tempmap;
-    /*
-    Costructor read the header of the bmp file to get the size
-    and the other data
-    SB
-  */
-
-public GifJpegImage(String href,int x,int y,int w,int h)
-{
-  this.ref=href;
-  this.X=x;
-  this.Y=y;
-  this.pixelheight=-1;
-  this.pixelwidth=-1;
-  try {
+
+    int X;
+    int Y;
+    int width;
+    int height;
+    int pixelwidth;
+    int pixelheight;
+    String ref;
+    boolean color = true;
+    int bitperpixel = 8;
+    int[] imagemap;
+    int[] tempmap;
+
+    /** synchronization object */
+    protected Integer imageWait = new Integer(0);
+
+    public GifJpegImage(String href, int x, int y, int w, int h) {
+
+       this.ref = href;
+       this.X = x;
+       this.Y = y;
+       this.pixelheight = -1;
+       this.pixelwidth = -1;
+
+       try {
            URL url = new URL(href);
            ImageProducer ip = (ImageProducer)url.getContent();
-           FopImageConsumer consumer = new FopImageConsumer();
+           FopImageConsumer consumer = new FopImageConsumer(this);
            ip.startProduction(consumer);
-           while ((this.pixelheight = consumer.getHeight())==-1) {}
-           while ((this.pixelwidth = consumer.getWidth())==-1) {}
-           this.tempmap = new int[this.pixelwidth*this.pixelheight];
-      //Image img=Toolkit.getDefaultToolkit().getImage("prova.gif");
-    //  Image img=Toolkit.getDefaultToolkit().getImage(url);
-           PixelGrabber pg = new PixelGrabber(ip,0,0,this.pixelwidth,this.pixelheight,this.tempmap,0,w);
+           synchronized (imageWait) {
+               imageWait.wait();
+           }
+           /* this only works on windows, not on linux
+              while ((this.pixelheight = consumer.getHeight())==-1) {}
+              while ((this.pixelwidth = consumer.getWidth())==-1) {}
+           */
+           this.tempmap = new int[this.pixelwidth * this.pixelheight];
+
+           PixelGrabber pg = new
+               PixelGrabber(ip, 0, 0,
+                            this.pixelwidth, this.pixelheight,
+                            this.tempmap, 0, w);
            try {
-          pg.grabPixels();
-      }catch (InterruptedException e) {System.err.println("Image grabbing interrupted");}
-       } catch (ClassCastException e) {System.err.println("Image format not supported: " + href);
-       } catch (Exception e) {System.err.println("Error loading image " + href + " : " +e);
+               pg.grabPixels();
+           } catch (InterruptedException e) {
+               System.err.println("Image grabbing interrupted"); 
+           }
+       } catch (ClassCastException e) {
+           System.err.println("Image format not supported: " + href);
+       } catch (Exception e) {
+           System.err.println("Error loading image " + href +
+                              " : " + e);
        }
-  if (w==0)
-     this.width=this.pixelwidth*1000;
-  else
-      this.width=w;
-  if (h==0)
-     this.height=this.pixelheight*1000;
-  else
-      this.height=h;
-}
-//
-public static class FopImageConsumer implements ImageConsumer {
+
+       if (w==0) {
+           this.width=this.pixelwidth*1000;
+       } else {
+           this.width=w;
+       }
+
+       if (h==0) {
+           this.height=this.pixelheight*1000;
+       } else {
+           this.height=h;
+       }
+    }
+
+    public static class FopImageConsumer implements ImageConsumer {
        int width = -1;
        int height = -1;
-       public void imageComplete(int status) {}
+       GifJpegImage graphic;
+
+       public FopImageConsumer(GifJpegImage graphic) {
+           this.graphic = graphic;
+       }
+
+       public void imageComplete(int status) {
+           synchronized(graphic.imageWait) {
+               graphic.imageWait.notifyAll();
+           }
+       }
+
        public void setColorModel(ColorModel model) {}
+
        public void setDimensions(int width, int height) {
            this.width = width;
            this.height = height;
        }
+
        public void setHints(int hintflags) {}
-       public void setPixels(int x, int y, int w, int h,ColorModel model, byte[] pixels,int off, int scansize) {}
-       public void setPixels(int x, int y, int w, int h,ColorModel model, int[] pixels,int off, int scansize) {}
+
+       public void setPixels(int x, int y, int w, int h,
+                             ColorModel model, byte[] pixels,int off,
+                             int scansize) {}
+
+       public void setPixels(int x, int y, int w, int h,
+                             ColorModel model, int[] pixels, int off,
+                             int scansize) {}
+
        public void setProperties(Hashtable props) {}
-       public int getWidth() { return this.width; }
-       public int getHeight() { return this.height; }
-}
 
-//
-  public String gethref() {            return this.ref;        }
-  public int getWidth() {              return this.width;      }
-  public int getHeight() {             return this.height;     }
-  public int getpixelwidth() { return this.pixelwidth; }
-  public int getpixelheight() { return this.pixelheight; }
-  public int getX(){ return this.X; }
-  public int getY(){ return this.Y; }
-
-  public int[] getimagemap(){
-         this.imagemap=new int[this.pixelheight*this.pixelwidth*3];
-         int count=0;
-         int i;
-         for(i=0;i<(this.pixelheight*this.pixelwidth);i++)
-                 {
-                 int red   = ((this.tempmap[i]>>16) & 0xff);
-                 int green = ((this.tempmap[i]>> 8) & 0xff);
-                 int blue  = ((this.tempmap[i]    ) & 0xff);
-                 this.imagemap[count++]=red;
-                 this.imagemap[count++]=green;
-                 this.imagemap[count++]=blue;
-                 }
-  return imagemap;
-  }
-
-
-  public boolean getcolor(){return true;}
-  public int getbitperpixel() {return this.bitperpixel;}
-  }
+       public int getWidth() {
+           return this.width;
+       }
+
+       public int getHeight() {
+           return this.height;
+       }
+    }
+
+    public String gethref() {
+       return this.ref;
+    }
+
+    public int getWidth() {
+       return this.width;
+    }
+
+    public int getHeight() {
+       return this.height;
+    }
+
+    public int getpixelwidth() {
+       return this.pixelwidth;
+    }
+
+    public int getpixelheight() {
+       return this.pixelheight;
+    }
+
+    public int getX() {
+       return this.X;
+    }
+
+    public int getY() {
+       return this.Y;
+    }
+
+    public int[] getimagemap() {
+       this.imagemap=new int[this.pixelheight * this.pixelwidth * 3];
+       int count = 0;
+       int i;
+       for(i = 0; i < (this.pixelheight * this.pixelwidth); i++) {
+           int red   = ((this.tempmap[i]>>16) & 0xff);
+           int green = ((this.tempmap[i]>> 8) & 0xff);
+           int blue  = ((this.tempmap[i]    ) & 0xff);
+           this.imagemap[count++]=red;
+           this.imagemap[count++]=green;
+           this.imagemap[count++]=blue;
+       }
+       return imagemap;
+    }
+
+    public boolean getcolor() {
+       return true;
+    }
+
+    public int getbitperpixel() {
+       return this.bitperpixel;
+    }
+}