Revert "Revert "Bug 493455 - [win32] always treat empty images as opaque""
This reverts commit ea4b8cc806c63249a242e661cf00aa4b9f2150cc.
Reason for revert: Considering for 4.24 M1
Change-Id: If8571d135a1fb7e2e05d60be2f470885e2e87d2c
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/190430
Tested-by: Niraj Modi <niraj.modi@in.ibm.com>
Reviewed-by: Niraj Modi <niraj.modi@in.ibm.com>
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) {