/**
* Returns a copy of the pixel data as a java array.
+ * Should be called with the GdkPixbufDecoder.pixbufLock held.
*/
private native int[] getPixels();
/**
* Sets the pixel data from a java array.
+ * Should be called with the GdkPixbufDecoder.pixbufLock held.
*/
private native void setPixels(int[] pixels);
/**
* Loads an image using gdk-pixbuf from a file.
+ * Should be called with the GdkPixbufDecoder.pixbufLock held.
*/
private native boolean loadPixbuf(String name);
/**
* Loads an image using gdk-pixbuf from data.
+ * Should be called with the GdkPixbufDecoder.pixbufLock held.
*/
private native boolean loadImageFromData(byte[] data);
/**
* Allocates a Gtk Pixbuf or pixmap
+ * Should be called with the GdkPixbufDecoder.pixbufLock held.
*/
private native void createPixmap();
/**
* Frees the above.
+ * Should be called with the GdkPixbufDecoder.pixbufLock held.
*/
private native void freePixmap();
/**
* Sets the pixmap to scaled copy of src image. hints are rendering hints.
+ * Should be called with the GdkPixbufDecoder.pixbufLock held.
*/
private native void createScaledPixmap(GtkImage src, int hints);
/**
* Draws the image, optionally scaled and composited.
+ * Should be called with the GdkPixbufDecoder.pixbufLock held.
+ * Also acquires global gdk lock for drawing.
*/
private native void drawPixelsScaled (GdkGraphics gc,
int bg_red, int bg_green, int bg_blue,
/**
* Draws the image, optionally scaled flipped and composited.
+ * Should be called with the GdkPixbufDecoder.pixbufLock held.
+ * Also acquires global gdk lock for drawing.
*/
private native void drawPixelsScaledFlipped (GdkGraphics gc,
int bg_red, int bg_green,
File f = new File(filename);
try
{
- if (loadPixbuf(f.getCanonicalPath()) != true)
- throw new IllegalArgumentException("Couldn't load image: "+filename);
+ String path = f.getCanonicalPath();
+ synchronized(GdkPixbufDecoder.pixbufLock)
+ {
+ if (loadPixbuf(f.getCanonicalPath()) != true)
+ throw new IllegalArgumentException("Couldn't load image: "
+ + filename);
+ }
}
catch(IOException e)
{
- throw new IllegalArgumentException("Couldn't load image: "+filename);
+ IllegalArgumentException iae;
+ iae = new IllegalArgumentException("Couldn't load image: "
+ + filename);
+ iae.initCause(e);
+ throw iae;
}
isLoaded = true;
*/
public GtkImage (byte[] data)
{
- if (loadImageFromData (data) != true)
- throw new IllegalArgumentException ("Couldn't load image.");
+ synchronized(GdkPixbufDecoder.pixbufLock)
+ {
+ if (loadImageFromData (data) != true)
+ throw new IllegalArgumentException ("Couldn't load image.");
+ }
isLoaded = true;
observers = null;
{
throw new IllegalArgumentException ("Couldn't load image.");
}
- if (loadImageFromData (baos.toByteArray()) != true)
- throw new IllegalArgumentException ("Couldn't load image.");
+ byte[] array = baos.toByteArray();
+ synchronized(GdkPixbufDecoder.pixbufLock)
+ {
+ if (loadImageFromData(array) != true)
+ throw new IllegalArgumentException ("Couldn't load image.");
+ }
isLoaded = true;
observers = null;
isLoaded = true;
observers = null;
offScreen = true;
- createPixmap();
+ synchronized(GdkPixbufDecoder.pixbufLock)
+ {
+ createPixmap();
+ }
}
/**
offScreen = false;
// Use the GDK scaling method.
- createScaledPixmap(src, hints);
+ synchronized(GdkPixbufDecoder.pixbufLock)
+ {
+ createScaledPixmap(src, hints);
+ }
}
/**
GtkImage (Pointer pixbuf)
{
pixmap = pixbuf;
- createFromPixbuf();
+ synchronized(GdkPixbufDecoder.pixbufLock)
+ {
+ createFromPixbuf();
+ }
isLoaded = true;
observers = null;
offScreen = false;
/**
* Native helper function for constructor that takes a pixbuf Pointer.
+ * Should be called with the GdkPixbufDecoder.pixbufLock held.
*/
private native void createFromPixbuf();
isLoaded = true;
deliver();
- createPixmap();
- setPixels(pixels);
+ synchronized(GdkPixbufDecoder.pixbufLock)
+ {
+ createPixmap();
+ setPixels(pixels);
+ }
}
// java.awt.Image methods ////////////////////////////////////////////////
{
if (!isLoaded)
return null;
- return new MemoryImageSource(width, height, nativeModel, getPixels(),
+
+ int[] pixels;
+ synchronized(GdkPixbufDecoder.pixbufLock)
+ {
+ pixels = getPixels();
+ }
+ return new MemoryImageSource(width, height, nativeModel, pixels,
0, width);
}
{
observers = new Vector();
isLoaded = false;
- freePixmap();
+ synchronized(GdkPixbufDecoder.pixbufLock)
+ {
+ freePixmap();
+ }
source.startProduction(new GtkImageConsumer(this, source));
}
}
public void finalize()
{
if (isLoaded)
- freePixmap();
+ {
+ synchronized(GdkPixbufDecoder.pixbufLock)
+ {
+ freePixmap();
+ }
+ }
}
/**
srcHeight = height - srcY;
}
+ if ( this.width <= 0 || this.height <= 0 )
+ return true;
+
if ( srcWidth <= 0 || srcHeight <= 0 || dstWidth <= 0 || dstHeight <= 0)
return true;
- if(bgcolor != null)
- drawPixelsScaledFlipped (g, bgcolor.getRed (), bgcolor.getGreen (),
- bgcolor.getBlue (),
- flipX, flipY,
- srcX, srcY,
- srcWidth, srcHeight,
- dstX, dstY,
- dstWidth, dstHeight,
- true);
- else
- drawPixelsScaledFlipped (g, 0, 0, 0, flipX, flipY,
- srcX, srcY, srcWidth, srcHeight,
- dstX, dstY, dstWidth, dstHeight,
- false);
+ synchronized(GdkPixbufDecoder.pixbufLock)
+ {
+ if(bgcolor != null)
+ drawPixelsScaledFlipped (g, bgcolor.getRed (), bgcolor.getGreen (),
+ bgcolor.getBlue (),
+ flipX, flipY,
+ srcX, srcY,
+ srcWidth, srcHeight,
+ dstX, dstY,
+ dstWidth, dstHeight,
+ true);
+ else
+ drawPixelsScaledFlipped (g, 0, 0, 0, flipX, flipY,
+ srcX, srcY, srcWidth, srcHeight,
+ dstX, dstY, dstWidth, dstHeight,
+ false);
+ }
return true;
}
if (addObserver(observer))
return false;
- if(bgcolor != null)
- drawPixelsScaled(g, bgcolor.getRed (), bgcolor.getGreen (),
- bgcolor.getBlue (), x, y, width, height, true);
- else
- drawPixelsScaled(g, 0, 0, 0, x, y, width, height, false);
+ if ( this.width <= 0 || this.height <= 0 )
+ return true;
+
+ synchronized(GdkPixbufDecoder.pixbufLock)
+ {
+ if(bgcolor != null)
+ drawPixelsScaled(g, bgcolor.getRed (), bgcolor.getGreen (),
+ bgcolor.getBlue (), x, y, width, height, true);
+ else
+ drawPixelsScaled(g, 0, 0, 0, x, y, width, height, false);
+ }
return true;
}