JDK-6552827 : add 8-bit alpha channel support for TrayIcon on Windows
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows
  • CPU: x86
  • Submitted: 2007-05-02
  • Updated: 2011-01-19
  • Resolved: 2010-12-30
Related Reports
Duplicate :  
Description
TrayIcon implementation lacks for ability to use scaled transparency.
Currently it uses only 1 bit to convey transprency of a pixel.
Thus it can't convert GIF/JPEG/PNG image that uses alpha channel
into an icon without imformation loss.

In order to fully support alpha channel we should use
BITMAPV4HEADER/BITMAPV5HEADER Windows native structure instead of
BITMAPINFOHEADER. The latter was used by Windows of old versions.

Originally, the issue has been risen in the JDIC project:
https://jdic.dev.java.net/issues/show_bug.cgi?id=350
The fix it provides is put into the Suggested Fix area.

Comments
EVALUATION We should port the fix suggested into the JDK.
02-05-2007

SUGGESTED FIX Below is the fix contributed to the JDIC: Index: Tray.cpp =================================================================== RCS file: /cvs/jdic/src/jdic/src/win32/native/jni/Tray.cpp,v retrieving revision 1.8 diff -u -r1.8 Tray.cpp --- Tray.cpp 27 Jun 2005 03:37:59 -0000 1.8 +++ Tray.cpp 11 Jan 2006 16:29:24 -0000 @@ -52,7 +52,7 @@ typedef struct tagBitmapheader { - BITMAPINFOHEADER bmiHeader; + BITMAPV5HEADER bmiHeader; DWORD dwMasks[256]; } Bitmapheader, *LPBITMAPHEADER; @@ -194,7 +194,7 @@ HBITMAP hbmpBitmap; HBITMAP hBitmap; - int nNumChannels = 3; + int nNumChannels = 4; if (!hW) { hW = ::GetDesktopWindow(); @@ -203,15 +203,21 @@ if (!hDC) { return NULL; } - + memset(&bmhHeader, 0, sizeof(Bitmapheader)); - bmhHeader.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bmhHeader.bmiHeader.biWidth = nW; - bmhHeader.bmiHeader.biHeight = -nH; - bmhHeader.bmiHeader.biPlanes = 1; - - bmhHeader.bmiHeader.biBitCount = 24; - bmhHeader.bmiHeader.biCompression = BI_RGB; + bmhHeader.bmiHeader.bV5Size = sizeof(BITMAPV5HEADER); + bmhHeader.bmiHeader.bV5Width = nW; + bmhHeader.bmiHeader.bV5Height = -nH; + bmhHeader.bmiHeader.bV5Planes = 1; + + bmhHeader.bmiHeader.bV5BitCount = 32; + bmhHeader.bmiHeader.bV5Compression = BI_BITFIELDS; + // The following mask specification specifies a supported 32 BPP + // alpha format for Windows XP. + bmhHeader.bmiHeader.bV5RedMask = 0x00FF0000; + bmhHeader.bmiHeader.bV5GreenMask = 0x0000FF00; + bmhHeader.bmiHeader.bV5BlueMask = 0x000000FF; + bmhHeader.bmiHeader.bV5AlphaMask = 0xFF000000; hbmpBitmap = ::CreateDIBSection(hDC, (BITMAPINFO*)&(bmhHeader), DIB_RGB_COLORS, @@ -225,6 +231,7 @@ } for (int nOutern = 0; nOutern < nH; nOutern++ ) { for (int nInner = 0; nInner < nSS; nInner++ ) { + dstPtr[3] = (*srcPtr >> 0x18) & 0xFF; dstPtr[2] = (*srcPtr >> 0x10) & 0xFF; dstPtr[1] = (*srcPtr >> 0x08) & 0xFF; dstPtr[0] = *srcPtr & 0xFF;
02-05-2007