aboutsummaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authorScott Gilbertson <scottg@mantatest.com>2004-07-12 16:26:07 +0000
committerScott Gilbertson <sgilbertson@gcc.gnu.org>2004-07-12 16:26:07 +0000
commit717b209147986b24d6c73dbdcbbc09b24baaac00 (patch)
tree1efe02e68e033589728d6cc19a9a1e9e107a2380 /libjava
parentccb14335ce321105a0d0a131f8236334d2fa72e8 (diff)
downloadgcc-717b209147986b24d6c73dbdcbbc09b24baaac00.zip
gcc-717b209147986b24d6c73dbdcbbc09b24baaac00.tar.gz
gcc-717b209147986b24d6c73dbdcbbc09b24baaac00.tar.bz2
XCanvasPeer.java (createImage): Implement.
2004-07-12 Scott Gilbertson <scottg@mantatest.com> * gnu/awt/xlib/XCanvasPeer.java (createImage): Implement. * gnu/awt/xlib/XOffScreenImage.java (XOffScreenImage): Add ImageConsumer interface. Add ColorModel constructor argument. Add constructor using ImageProducer. (getSource): Implement. (imageComplete): New method. (setColorModel): New method. (setDimensions): New method. (setHints): New method. (setPixels): New method. (setProperties): New method. * gnu/gcj/xlib/GC.java (drawPoint): New native method. * gnu/gcj/xlib/natGC.cc (drawPoint): New native method. From-SVN: r84564
Diffstat (limited to 'libjava')
-rw-r--r--libjava/ChangeLog16
-rw-r--r--libjava/gnu/awt/xlib/XCanvasPeer.java4
-rw-r--r--libjava/gnu/awt/xlib/XOffScreenImage.java111
-rw-r--r--libjava/gnu/gcj/xlib/GC.java5
-rw-r--r--libjava/gnu/gcj/xlib/natGC.cc9
5 files changed, 140 insertions, 5 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 34f5a85..e8b80b6 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,19 @@
+2004-07-12 Scott Gilbertson <scottg@mantatest.com>
+
+ * gnu/awt/xlib/XCanvasPeer.java (createImage): Implement.
+ * gnu/awt/xlib/XOffScreenImage.java
+ (XOffScreenImage): Add ImageConsumer interface. Add ColorModel
+ constructor argument. Add constructor using ImageProducer.
+ (getSource): Implement.
+ (imageComplete): New method.
+ (setColorModel): New method.
+ (setDimensions): New method.
+ (setHints): New method.
+ (setPixels): New method.
+ (setProperties): New method.
+ * gnu/gcj/xlib/GC.java (drawPoint): New native method.
+ * gnu/gcj/xlib/natGC.cc (drawPoint): New native method.
+
2004-07-11 Bryce McKinlay <mckinlay@redhat.com>
PR libgcj/16478
diff --git a/libjava/gnu/awt/xlib/XCanvasPeer.java b/libjava/gnu/awt/xlib/XCanvasPeer.java
index d8a00db..5daee59 100644
--- a/libjava/gnu/awt/xlib/XCanvasPeer.java
+++ b/libjava/gnu/awt/xlib/XCanvasPeer.java
@@ -210,11 +210,11 @@ public class XCanvasPeer implements CanvasPeer
}
public Image createImage(ImageProducer prod)
{
- throw new UnsupportedOperationException("FIXME, not implemented");
+ return new XOffScreenImage (config, window, prod, config.getColorModel());
}
public Image createImage(int width, int height)
{
- return new XOffScreenImage (config, window, width, height);
+ return new XOffScreenImage (config, window, width, height, config.getColorModel());
}
public void dispose()
{
diff --git a/libjava/gnu/awt/xlib/XOffScreenImage.java b/libjava/gnu/awt/xlib/XOffScreenImage.java
index 71791c1..0ea6c1b 100644
--- a/libjava/gnu/awt/xlib/XOffScreenImage.java
+++ b/libjava/gnu/awt/xlib/XOffScreenImage.java
@@ -15,6 +15,7 @@ import java.awt.GraphicsConfiguration;
import java.awt.image.ColorModel;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
+import java.awt.image.ImageConsumer;
import java.util.Hashtable;
import gnu.awt.j2d.DirectRasterGraphics;
import gnu.awt.j2d.Graphics2DImpl;
@@ -23,6 +24,7 @@ import gnu.gcj.xlib.Drawable;
import gnu.gcj.xlib.Pixmap;
import gnu.gcj.xlib.Screen;
import gnu.gcj.xlib.Visual;
+import gnu.gcj.xlib.GC;
/** Image class for xlib off-screen buffers.
* The image is stored in a server-side pixmap for best performance.
@@ -34,12 +36,17 @@ import gnu.gcj.xlib.Visual;
* @author scott gilbertson <scottg@mantatest.com> <sgilbertson@cogeco.ca>
*/
public class XOffScreenImage extends Image
- implements IntegerGraphicsState.ScreenCoupledImage
+ implements IntegerGraphicsState.ScreenCoupledImage,
+ ImageConsumer
{
private Pixmap pixmap;
private XGraphicsConfiguration config;
private int width;
private int height;
+ private Drawable drawable;
+ private ImageProducer prod;
+ private GC gc;
+ private ColorModel pixmapColorModel;
/** Create a new XOffScreenImage
* @param config Graphics configuration, to compare against on-screen
@@ -47,13 +54,35 @@ public class XOffScreenImage extends Image
* @param drawable The drawable with which the image is compatible
* @param width The width of the image
* @param height The height of the image
+ * @param cm The ColorModel associated with drawable
*/
- XOffScreenImage (XGraphicsConfiguration config, Drawable drawable, int width, int height)
+ XOffScreenImage (XGraphicsConfiguration config, Drawable drawable, int width, int height, ColorModel cm)
{
this.config = config;
this.width = width;
this.height = height;
+ this.drawable = drawable;
+ pixmapColorModel = cm;
pixmap = new Pixmap (drawable, width, height, drawable.getDepth ());
+ gc = GC.create (pixmap);
+ }
+
+ /** Create a new XOffScreenImage and obtain image data from an ImageProducer
+ * @param config Graphics configuration, to compare against on-screen
+ * components and to create the appropriate Graphics
+ * @param drawable The drawable with which the image is compatible
+ * @param prod The source of image data for this image
+ * @param cm The ColorModel associated with drawable
+ */
+ XOffScreenImage (XGraphicsConfiguration config, Drawable drawable, ImageProducer prod, ColorModel cm)
+ {
+ this.config = config;
+ this.width = 0; // size will be overridden in a moment
+ this.height = 0;
+ this.drawable = drawable;
+ this.prod = prod;
+ pixmapColorModel = cm;
+ prod.startProduction (this);
}
/** Get the pixmap which contains this image
@@ -120,7 +149,10 @@ public class XOffScreenImage extends Image
*/
public ImageProducer getSource ()
{
- throw new UnsupportedOperationException ("getSource not supported");
+ if (prod == null)
+ throw new UnsupportedOperationException ("getSource not supported");
+ else
+ return prod;
}
/** Returns the width of the image, or -1 if it is unknown. If the
@@ -172,4 +204,77 @@ public class XOffScreenImage extends Image
{
return config;
}
+
+ public void imageComplete (int status)
+ {
+ }
+
+ public void setColorModel (ColorModel model)
+ {
+ }
+
+ public void setDimensions (int width, int height)
+ {
+ this.width = width;
+ this.height = height;
+ pixmap = new Pixmap (drawable, width, height, drawable.getDepth ());
+ gc = GC.create (pixmap);
+ }
+
+ public void setHints (int flags)
+ {
+ }
+
+ public void setPixels (int x, int y, int w, int h, ColorModel model, int[] pixels, int offset, int scansize)
+ {
+ int idx = 0;
+ float[] normalizedComponents = new float [4];
+ int[] unnormalizedComponents = { 0, 0, 0, 0xff };
+ normalizedComponents[3] = 1;
+ for (int yp=y; yp < (y + h); yp++)
+ {
+ for (int xp=x; xp < (x + w); xp++)
+ {
+ int p = (yp - y) * scansize + (xp - x) + offset;
+ // FIXME: there HAS to be a more efficient mechanism for color mapping
+ normalizedComponents[0] = (float)model.getRed (pixels[p]) / 255F;
+ normalizedComponents[1] = (float)model.getGreen (pixels[p]) / 255F;
+ normalizedComponents[2] = (float)model.getBlue (pixels[p]) / 255F;
+ pixmapColorModel.getUnnormalizedComponents (normalizedComponents, 0,
+ unnormalizedComponents, 0);
+ int pixelColor = pixmapColorModel.getDataElement (unnormalizedComponents, 0);
+ gc.setForeground (pixelColor);
+ gc.drawPoint (xp, yp);
+ }
+ }
+ }
+
+ public void setPixels (int x, int y, int w, int h, ColorModel model, byte[] pixels, int offset, int scansize)
+ {
+ int idx = 0;
+ float[] normalizedComponents = new float [4];
+ int[] unnormalizedComponents = { 0, 0, 0, 0xff };
+ normalizedComponents[3] = 1;
+ for (int yp=y; yp < (y + h); yp++)
+ {
+ for (int xp=x; xp < (x + w); xp++)
+ {
+ // FIXME: there HAS to be a more efficient mechanism for color mapping
+ int p = (yp - y) * scansize + (xp - x) + offset;
+ normalizedComponents[0] = (float)model.getRed (pixels[p]) / 255F;
+ normalizedComponents[1] = (float)model.getGreen (pixels[p]) / 255F;
+ normalizedComponents[2] = (float)model.getBlue (pixels[p]) / 255F;
+ pixmapColorModel.getUnnormalizedComponents (normalizedComponents, 0,
+ unnormalizedComponents, 0);
+ int pixelColor = pixmapColorModel.getDataElement (unnormalizedComponents, 0);
+ gc.setForeground (pixelColor);
+ gc.drawPoint (xp, yp);
+ }
+ }
+ }
+
+ public void setProperties (Hashtable props)
+ {
+ }
+
}
diff --git a/libjava/gnu/gcj/xlib/GC.java b/libjava/gnu/gcj/xlib/GC.java
index da427c9..1a47cf6 100644
--- a/libjava/gnu/gcj/xlib/GC.java
+++ b/libjava/gnu/gcj/xlib/GC.java
@@ -132,6 +132,11 @@ public class GC implements Cloneable
public native void clearArea(int x, int y, int w, int h,
boolean exposures);
+ /** Draw a point using the current foreground color
+ * @param x The x coordinate at which to draw
+ * @param t The y coordinate at which to draw
+ */
+ public native void drawPoint (int x, int y);
public native void putImage(XImage image,
int srcX, int srcY,
diff --git a/libjava/gnu/gcj/xlib/natGC.cc b/libjava/gnu/gcj/xlib/natGC.cc
index 3819da4..4529ebb 100644
--- a/libjava/gnu/gcj/xlib/natGC.cc
+++ b/libjava/gnu/gcj/xlib/natGC.cc
@@ -117,6 +117,15 @@ void gnu::gcj::xlib::GC::drawString(jstring text, jint x, jint y)
XDrawString16(dpy, drawableXID, gc, x, y, xwchars, length);
}
+void gnu::gcj::xlib::GC::drawPoint(jint x, jint y)
+{
+ Display* display = target->getDisplay();
+ ::Display* dpy = (::Display*) (display->display);
+ ::Drawable drawableXID = target->getXID();
+ ::GC gc = (::GC) structure;
+ XDrawPoint (dpy, drawableXID, gc, x, y);
+}
+
void gnu::gcj::xlib::GC::drawLine(jint x1, jint y1, jint x2, jint y2)
{
Display* display = target->getDisplay();