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>
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 ac2dfaf..b79fe46 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 @@
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 17cc993..1b38c70 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 @@
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 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 @@
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 @@
/* 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 @@
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) {