summaryrefslogtreecommitdiff
path: root/gnu/java/awt/peer/gtk/CairoSurface.java
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/java/awt/peer/gtk/CairoSurface.java')
-rw-r--r--gnu/java/awt/peer/gtk/CairoSurface.java51
1 files changed, 34 insertions, 17 deletions
diff --git a/gnu/java/awt/peer/gtk/CairoSurface.java b/gnu/java/awt/peer/gtk/CairoSurface.java
index 3bf9a9ccf..91b10369d 100644
--- a/gnu/java/awt/peer/gtk/CairoSurface.java
+++ b/gnu/java/awt/peer/gtk/CairoSurface.java
@@ -38,15 +38,18 @@ exception statement from your version. */
package gnu.java.awt.peer.gtk;
-import java.awt.Point;
+import gnu.java.awt.Buffers;
+
import java.awt.Graphics2D;
-import java.awt.image.DataBuffer;
-import java.awt.image.Raster;
-import java.awt.image.WritableRaster;
+import java.awt.Point;
+import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
+import java.awt.image.DataBuffer;
import java.awt.image.DirectColorModel;
+import java.awt.image.SampleModel;
import java.awt.image.SinglePixelPackedSampleModel;
+import java.awt.image.WritableRaster;
import java.nio.ByteOrder;
import java.util.Hashtable;
@@ -69,11 +72,15 @@ public class CairoSurface extends WritableRaster
*/
long bufferPointer;
- static ColorModel nativeModel = new DirectColorModel(32,
- 0x00FF0000,
- 0x0000FF00,
- 0x000000FF,
- 0xFF000000);
+ // nativeGetPixels will return [0]=red, [1]=green, [2]=blue, [3]=alpha
+ static ColorModel nativeColorModel = new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
+ 32,
+ 0x000000FF,
+ 0x0000FF00,
+ 0x00FF0000,
+ 0xFF000000,
+ true,
+ Buffers.smallestAppropriateTransferType(32));
/**
* Allocates and clears the buffer and creates the cairo surface.
@@ -102,11 +109,13 @@ public class CairoSurface extends WritableRaster
* with an affine transform given by i2u.
*/
public native void nativeDrawSurface(long surfacePointer, long contextPointer,
- double[] i2u, double alpha);
+ double[] i2u, double alpha,
+ int interpolation);
- public void drawSurface(long contextPointer, double[] i2u, double alpha)
+ public void drawSurface(long contextPointer, double[] i2u, double alpha,
+ int interpolation)
{
- nativeDrawSurface(surfacePointer, contextPointer, i2u, alpha);
+ nativeDrawSurface(surfacePointer, contextPointer, i2u, alpha, interpolation);
}
/**
@@ -138,10 +147,8 @@ public class CairoSurface extends WritableRaster
*/
public CairoSurface(int width, int height)
{
- super( new SinglePixelPackedSampleModel
- (DataBuffer.TYPE_INT, width, height,
- new int[]{ 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }),
- null, new Point(0, 0) );
+ super(createNativeSampleModel(width, height),
+ null, new Point(0, 0));
if(width <= 0 || height <= 0)
throw new IllegalArgumentException("Image must be at least 1x1 pixels.");
@@ -253,7 +260,7 @@ public class CairoSurface extends WritableRaster
*/
public static BufferedImage getBufferedImage(CairoSurface surface)
{
- return new BufferedImage(nativeModel, surface, true, new Hashtable());
+ return new BufferedImage(nativeColorModel, surface, true, new Hashtable());
}
private class CairoDataBuffer extends DataBuffer
@@ -315,4 +322,14 @@ public class CairoSurface extends WritableRaster
{
copyAreaNative2(bufferPointer, x, y, width, height, dx, dy, stride);
}
+
+ /**
+ * Creates a SampleModel that matches Cairo's native format
+ */
+ protected static SampleModel createNativeSampleModel(int w, int h)
+ {
+ return new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, w, h,
+ new int[]{0x000000FF, 0x0000FF00,
+ 0x00FF0000, 0xFF000000});
+ }
}