Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSilenio Quarti2007-05-15 21:20:31 +0000
committerSilenio Quarti2007-05-15 21:20:31 +0000
commit6d82b41e49943a9b4edcc7793f7d74b1be0c636a (patch)
tree25fc3ca4364fc1b6f7161f397f68671a1e4af7e9
parentd5cf1c396dd6fc70c2ff1691fe757ac2af91424f (diff)
downloadeclipse.platform.swt-6d82b41e49943a9b4edcc7793f7d74b1be0c636a.tar.gz
eclipse.platform.swt-6d82b41e49943a9b4edcc7793f7d74b1be0c636a.tar.xz
eclipse.platform.swt-6d82b41e49943a9b4edcc7793f7d74b1be0c636a.zip
177711 - Grayed PNG image displayed white background in some Linux
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java90
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java57
2 files changed, 66 insertions, 81 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
index a550cc51f8..492666ad0e 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
@@ -255,6 +255,7 @@ public Image(Device device, Image srcImage, int flag) {
alphaData = new byte[srcImage.alphaData.length];
System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length);
}
+ createAlphaMask(width, height);
/* Create the new pixmap */
int /*long*/ pixmap = OS.gdk_pixmap_new (OS.GDK_ROOT_PARENT(), width, height, -1);
@@ -328,12 +329,6 @@ public Image(Device device, Image srcImage, int flag) {
}
OS.memmove(pixels + (y * stride), line, stride);
}
- transparentPixel = srcImage.transparentPixel;
- alpha = srcImage.alpha;
- if (srcImage.alphaData != null) {
- alphaData = new byte[srcImage.alphaData.length];
- System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length);
- }
break;
}
}
@@ -568,28 +563,7 @@ public Image(Device device, String filename) {
}
OS.memmove(pixels + (y * stride), line, stride);
}
- if (device.useXRender) {
- mask = OS.gdk_pixmap_new(0, width, height, 8);
- if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- GdkImage gdkImage = new GdkImage();
- int /*long*/ imagePtr = OS.gdk_drawable_get_image(mask, 0, 0, width, height);
- if (imagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.memmove(gdkImage, imagePtr);
- if (gdkImage.bpl == width) {
- OS.memmove(gdkImage.mem, alphaData, alphaData.length);
- } else {
- line = new byte[gdkImage.bpl];
- for (int y = 0; y < height; y++) {
- System.arraycopy(alphaData, width * y, line, 0, width);
- OS.memmove(gdkImage.mem + (gdkImage.bpl * y), line, gdkImage.bpl);
- }
- }
- int /*long*/ gc = OS.gdk_gc_new(mask);
- if (gc == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.gdk_draw_image(mask, gc, imagePtr, 0, 0, 0, 0, width, height);
- OS.g_object_unref(imagePtr);
- OS.g_object_unref(gc);
- }
+ createAlphaMask(width, height);
}
int /*long*/ [] pixmap_return = new int /*long*/ [1];
OS.gdk_pixbuf_render_pixmap_and_mask(pixbuf, pixmap_return, null, 0);
@@ -604,6 +578,37 @@ public Image(Device device, String filename) {
if (device.tracking) device.new_Object(this);
}
+void createAlphaMask (int width, int height) {
+ if (device.useXRender && (alpha != -1 || alphaData != null)) {
+ mask = OS.gdk_pixmap_new(0, alpha != -1 ? 1 : width, alpha != -1 ? 1 : height, 8);
+ if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ int /*long*/ gc = OS.gdk_gc_new(mask);
+ if (alpha != -1) {
+ GdkColor color = new GdkColor();
+ color.pixel = (alpha & 0xFF) << 8 | (alpha & 0xFF);
+ OS.gdk_gc_set_foreground(gc, color);
+ OS.gdk_draw_rectangle(mask, gc, 1, 0, 0, 1, 1);
+ } else {
+ int /*long*/ imagePtr = OS.gdk_drawable_get_image(mask, 0, 0, width, height);
+ if (imagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ GdkImage gdkImage = new GdkImage();
+ OS.memmove(gdkImage, imagePtr);
+ if (gdkImage.bpl == width) {
+ OS.memmove(gdkImage.mem, alphaData, alphaData.length);
+ } else {
+ byte[] line = new byte[gdkImage.bpl];
+ for (int y = 0; y < height; y++) {
+ System.arraycopy(alphaData, width * y, line, 0, width);
+ OS.memmove(gdkImage.mem + (gdkImage.bpl * y), line, gdkImage.bpl);
+ }
+ }
+ OS.gdk_draw_image(mask, gc, imagePtr, 0, 0, 0, 0, width, height);
+ OS.g_object_unref(imagePtr);
+ }
+ OS.g_object_unref(gc);
+ }
+}
+
/**
* Create the receiver's mask if necessary.
*/
@@ -1046,34 +1051,7 @@ void init(Device device, ImageData image) {
this.alphaData = new byte[image.alphaData.length];
System.arraycopy(image.alphaData, 0, this.alphaData, 0, alphaData.length);
}
- if (device.useXRender && (alpha != -1 || alphaData != null)) {
- mask = OS.gdk_pixmap_new(0, alpha != -1 ? 1 : width, alpha != -1 ? 1 : height, 8);
- if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ gc = OS.gdk_gc_new(mask);
- if (alpha != -1) {
- GdkColor color = new GdkColor();
- color.pixel = (alpha & 0xFF) << 8 | (alpha & 0xFF);
- OS.gdk_gc_set_foreground(gc, color);
- OS.gdk_draw_rectangle(mask, gc, 1, 0, 0, 1, 1);
- } else {
- int /*long*/ imagePtr = OS.gdk_drawable_get_image(mask, 0, 0, width, height);
- if (imagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- GdkImage gdkImage = new GdkImage();
- OS.memmove(gdkImage, imagePtr);
- if (gdkImage.bpl == width) {
- OS.memmove(gdkImage.mem, alphaData, alphaData.length);
- } else {
- byte[] line = new byte[gdkImage.bpl];
- for (int y = 0; y < height; y++) {
- System.arraycopy(alphaData, width * y, line, 0, width);
- OS.memmove(gdkImage.mem + (gdkImage.bpl * y), line, gdkImage.bpl);
- }
- }
- OS.gdk_draw_image(mask, gc, imagePtr, 0, 0, 0, 0, width, height);
- OS.g_object_unref(imagePtr);
- }
- OS.g_object_unref(gc);
- }
+ createAlphaMask(width, height);
}
this.pixmap = pixmap;
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java
index 481716e68f..674fa3c882 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java
@@ -249,6 +249,7 @@ public Image(Device device, Image srcImage, int flag) {
alphaData = new byte[srcImage.alphaData.length];
System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length);
}
+ createAlphaMask(width, height);
if (device.tracking) device.new_Object(this);
return;
case SWT.IMAGE_DISABLE:
@@ -425,6 +426,7 @@ public Image(Device device, Image srcImage, int flag) {
alphaData = new byte[srcImage.alphaData.length];
System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length);
}
+ createAlphaMask(width, height);
this.pixmap = destPixmap;
if (device.tracking) device.new_Object(this);
return;
@@ -684,6 +686,35 @@ public Image(Device device, String filename) {
init(device, new ImageData(filename));
if (device.tracking) device.new_Object(this);
}
+void createAlphaMask(int width, int height) {
+ if (device.useXRender && (alpha != -1 || alphaData != null)) {
+ int xDisplay = device.xDisplay;
+ int drawable = OS.XDefaultRootWindow(xDisplay);
+ mask = OS.XCreatePixmap(xDisplay, drawable, alpha != -1 ? 1 : width, alpha != -1 ? 1 : height, 8);
+ if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ int gc = OS.XCreateGC(xDisplay, mask, 0, null);
+ if (alpha != -1) {
+ OS.XSetForeground(xDisplay, gc, (alpha & 0xFF) << 8 | (alpha & 0xFF));
+ OS.XFillRectangle(xDisplay, mask, gc, 0, 0, 1, 1);
+ } else {
+ int imagePtr = OS.XGetImage(xDisplay, mask, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap);
+ XImage xImage = new XImage();
+ OS.memmove(xImage, imagePtr, XImage.sizeof);
+ if (xImage.bytes_per_line == width) {
+ OS.memmove(xImage.data, alphaData, alphaData.length);
+ } else {
+ byte[] line = new byte[xImage.bytes_per_line];
+ for (int y = 0; y < height; y++) {
+ System.arraycopy(alphaData, width * y, line, 0, width);
+ OS.memmove(xImage.data + (xImage.bytes_per_line * y), line, xImage.bytes_per_line);
+ }
+ }
+ OS.XPutImage(xDisplay, mask, gc, imagePtr, 0, 0, 0, 0, width, height);
+ OS.XDestroyImage(imagePtr);
+ }
+ OS.XFreeGC(xDisplay, gc);
+ }
+}
/**
* Create the receiver's mask if necessary.
*/
@@ -1097,31 +1128,7 @@ void init(Device device, ImageData image) {
this.alphaData = new byte[image.alphaData.length];
System.arraycopy(image.alphaData, 0, this.alphaData, 0, alphaData.length);
}
- if (device.useXRender && (alpha != -1 || alphaData != null)) {
- mask = OS.XCreatePixmap(xDisplay, drawable, alpha != -1 ? 1 : image.width, alpha != -1 ? 1 : image.height, 8);
- if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- gc = OS.XCreateGC(xDisplay, mask, 0, null);
- if (alpha != -1) {
- OS.XSetForeground(xDisplay, gc, (alpha & 0xFF) << 8 | (alpha & 0xFF));
- OS.XFillRectangle(xDisplay, mask, gc, 0, 0, 1, 1);
- } else {
- int imagePtr = OS.XGetImage(xDisplay, mask, 0, 0, image.width, image.height, OS.AllPlanes, OS.ZPixmap);
- XImage xImage = new XImage();
- OS.memmove(xImage, imagePtr, XImage.sizeof);
- if (xImage.bytes_per_line == image.width) {
- OS.memmove(xImage.data, alphaData, alphaData.length);
- } else {
- byte[] line = new byte[xImage.bytes_per_line];
- for (int y = 0; y < image.height; y++) {
- System.arraycopy(alphaData, image.width * y, line, 0, image.width);
- OS.memmove(xImage.data + (xImage.bytes_per_line * y), line, xImage.bytes_per_line);
- }
- }
- OS.XPutImage(xDisplay, mask, gc, imagePtr, 0, 0, 0, 0, image.width, image.height);
- OS.XDestroyImage(imagePtr);
- }
- OS.XFreeGC(xDisplay, gc);
- }
+ createAlphaMask(image.width, image.height);
}
this.pixmap = pixmap;
}

Back to the top