You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by jt...@hyperreal.org on 1999/11/22 05:51:58 UTC

cvs commit: xml-fop/src/org/apache/fop/image GifJpegImage.java

jtauber     99/11/21 20:51:57

  Modified:    .        STATUS
               src/org/apache/fop/image GifJpegImage.java
  Log:
  added submission from Kelly Campbell that fixed synchronization problem with GifJpeg image handling. Also cleaned up code to follow existing coding conventions.
  
  Revision  Changes    Path
  1.5       +2 -2      xml-fop/STATUS
  
  Index: STATUS
  ===================================================================
  RCS file: /home/cvs/xml-fop/STATUS,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- STATUS	1999/11/22 03:47:48	1.4
  +++ STATUS	1999/11/22 04:51:55	1.5
  @@ -1,4 +1,4 @@
  -$Id: STATUS,v 1.4 1999/11/22 03:47:48 jtauber Exp $
  +$Id: STATUS,v 1.5 1999/11/22 04:51:55 jtauber Exp $
   
   STATUS
   
  @@ -10,7 +10,7 @@
   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:
   
  
  
  
  1.6       +151 -93   xml-fop/src/org/apache/fop/image/GifJpegImage.java
  
  Index: GifJpegImage.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/GifJpegImage.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- GifJpegImage.java	1999/11/22 02:31:43	1.5
  +++ GifJpegImage.java	1999/11/22 04:51:56	1.6
  @@ -1,4 +1,4 @@
  -/*-- $Id: GifJpegImage.java,v 1.5 1999/11/22 02:31:43 jtauber Exp $ -- 
  +/*-- $Id: GifJpegImage.java,v 1.6 1999/11/22 04:51:56 jtauber Exp $ -- 
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -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.
  @@ -48,16 +48,10 @@
    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;
   
   import java.util.Hashtable;
  @@ -69,102 +63,166 @@
   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);
  -	}
  -  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 {
  +		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 {
   	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;
  +    }
  +}