diff options
Diffstat (limited to 'gnu/java/awt/peer/gtk/CairoSurface.java')
-rw-r--r-- | gnu/java/awt/peer/gtk/CairoSurface.java | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/gnu/java/awt/peer/gtk/CairoSurface.java b/gnu/java/awt/peer/gtk/CairoSurface.java index 91b10369d..d3b3d4504 100644 --- a/gnu/java/awt/peer/gtk/CairoSurface.java +++ b/gnu/java/awt/peer/gtk/CairoSurface.java @@ -72,16 +72,22 @@ public class CairoSurface extends WritableRaster */ long bufferPointer; - // nativeGetPixels will return [0]=red, [1]=green, [2]=blue, [3]=alpha - static ColorModel nativeColorModel = new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), - 32, - 0x000000FF, + // FIXME: use only the cairoCM_pre colormodel + // since that's what Cairo really uses (is there a way to do this cheaply? + // we use a non-multiplied model most of the time to avoid costly coercion + // operations...) + static ColorModel cairoColorModel = new DirectColorModel(32, 0x00FF0000, + 0x0000FF00, + 0x000000FF, + 0xFF000000); + + static ColorModel cairoCM_pre = new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), + 32, 0x00FF0000, 0x0000FF00, - 0x00FF0000, + 0x000000FF, 0xFF000000, true, Buffers.smallestAppropriateTransferType(32)); - /** * Allocates and clears the buffer and creates the cairo surface. * @param width, height - the image size @@ -147,7 +153,7 @@ public class CairoSurface extends WritableRaster */ public CairoSurface(int width, int height) { - super(createNativeSampleModel(width, height), + super(createCairoSampleModel(width, height), null, new Point(0, 0)); if(width <= 0 || height <= 0) @@ -260,7 +266,9 @@ public class CairoSurface extends WritableRaster */ public static BufferedImage getBufferedImage(CairoSurface surface) { - return new BufferedImage(nativeColorModel, surface, true, new Hashtable()); + return new BufferedImage(cairoColorModel, surface, + cairoColorModel.isAlphaPremultiplied(), + new Hashtable()); } private class CairoDataBuffer extends DataBuffer @@ -326,10 +334,10 @@ public class CairoSurface extends WritableRaster /** * Creates a SampleModel that matches Cairo's native format */ - protected static SampleModel createNativeSampleModel(int w, int h) + protected static SampleModel createCairoSampleModel(int w, int h) { return new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, w, h, - new int[]{0x000000FF, 0x0000FF00, - 0x00FF0000, 0xFF000000}); + new int[]{0x00FF0000, 0x0000FF00, + 0x000000FF, 0xFF000000}); } } |