Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Meier2022-02-11 14:58:27 +0000
committerAndrey Loskutov2022-02-12 12:03:21 +0000
commitdbdc293578b21c6aa23f33d9a3175f4f457f31d0 (patch)
tree505c7e5aa96c20f22498cbbd658bfdc2e364f927
parente27c6f84925e88344322e285abe0ee7de8954466 (diff)
downloadeclipse.platform.swt-dbdc293578b21c6aa23f33d9a3175f4f457f31d0.tar.gz
eclipse.platform.swt-dbdc293578b21c6aa23f33d9a3175f4f457f31d0.tar.xz
eclipse.platform.swt-dbdc293578b21c6aa23f33d9a3175f4f457f31d0.zip
Bug 493455 - [win32] always treat empty images as opaque
An empty image is an image constructed only from width and height but without any pixel data. Depending on the system and the image size the underlying BITMAP may be allocated with a depth of 32-bit. In that case we just ignore its additional channel. This fixes a regression introduced in 8d21781c6b65b49d2f30db28ada54be673b5925c. Change-Id: I3afaa578f8a8867e7e960de9a176a0d99ff24456 Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/190727 Tested-by: Platform Bot <platform-bot@eclipse.org> Reviewed-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java4
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java11
2 files changed, 10 insertions, 5 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java
index ac2dfafd25..b79fe461f5 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java
@@ -1220,7 +1220,9 @@ void drawBitmap(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight,
data.hNullBitmap = 0;
}
}
- if (bm.bmPlanes * bm.bmBitsPixel == 32) {
+ boolean isDib = bm.bmBits != 0;
+ int depth = bm.bmPlanes * bm.bmBitsPixel;
+ if (isDib && depth == 32) {
drawBitmapAlpha(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);
} else if (srcImage.transparentPixel != -1) {
drawBitmapTransparent(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, bm, imgWidth, imgHeight);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
index 17cc99356a..1b38c70d27 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
@@ -965,7 +965,9 @@ long [] createGdipImage() {
BITMAP bm = new BITMAP();
OS.GetObject(handle, BITMAP.sizeof, bm);
int depth = bm.bmPlanes * bm.bmBitsPixel;
- if (depth == 32 || transparentPixel != -1) {
+ boolean isDib = bm.bmBits != 0;
+ boolean hasAlpha = isDib && depth == 32;
+ if (hasAlpha || transparentPixel != -1) {
int imgWidth = bm.bmWidth;
int imgHeight = bm.bmHeight;
long hDC = device.internal_new_GC(null);
@@ -983,7 +985,7 @@ long [] createGdipImage() {
long pixels = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, sizeInBytes);
if (pixels == 0) SWT.error(SWT.ERROR_NO_HANDLES);
byte red = 0, green = 0, blue = 0;
- if (depth == 32) {
+ if (hasAlpha) {
OS.MoveMemory(pixels, bm.bmBits, sizeInBytes);
}
else {
@@ -1040,7 +1042,7 @@ long [] createGdipImage() {
OS.DeleteObject(srcHdc);
OS.DeleteObject(memHdc);
OS.DeleteObject(memDib);
- int pixelFormat = depth == 32 ? Gdip.PixelFormat32bppPARGB : Gdip.PixelFormat32bppARGB;
+ int pixelFormat = hasAlpha ? Gdip.PixelFormat32bppPARGB : Gdip.PixelFormat32bppARGB;
return new long []{Gdip.Bitmap_new(imgWidth, imgHeight, dibBM.bmWidthBytes, pixelFormat, pixels), pixels};
}
return new long []{Gdip.Bitmap_new(handle, 0), 0};
@@ -1606,7 +1608,7 @@ public ImageData getImageDataAtCurrentZoom() {
/* Construct and return the ImageData */
ImageData imageData = new ImageData(width, height, depth, palette, 4, data);
imageData.transparentPixel = this.transparentPixel;
- if (depth == 32) {
+ if (isDib && depth == 32) {
byte straightData[] = new byte[imageSize];
byte alphaData[] = new byte[width * height];
boolean validAlpha = true;
@@ -1679,6 +1681,7 @@ void init(int width, int height) {
int planes = OS.GetDeviceCaps(hDC, OS.PLANES);
int depth = bits * planes;
if (depth < 16) depth = 16;
+ if (depth > 24) depth = 24;
handle = createDIB(width, height, depth);
}
if (handle != 0) {

Back to the top