int maxColors = 1 << bm.bmBitsPixel; byte[] oldColors = new byte[maxColors * 4]; if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED); int numColors = OS.GetDIBColorTable(srcHdc, 0, maxColors, oldColors); int offset = srcImage.transparentPixel * 4; byte[] newColors = new byte[oldColors.length]; transRed = transGreen = transBlue = 0xff; newColors[offset] = (byte)transBlue; newColors[offset+1] = (byte)transGreen; newColors[offset+2] = (byte)transRed; if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED); OS.SetDIBColorTable(srcHdc, 0, maxColors, newColors); originalColors = oldColors;
if (OS.IsWinCE) { byte[] pBits = new byte[1]; OS.MoveMemory(pBits, bm.bmBits, 1); byte oldValue = pBits[0]; int mask = (0xFF << (8 - bm.bmBitsPixel)) & 0x00FF; pBits[0] = (byte)((srcImage.transparentPixel << (8 - bm.bmBitsPixel)) | (pBits[0] & ~mask)); OS.MoveMemory(bm.bmBits, pBits, 1); int color = OS.GetPixel(srcHdc, 0, 0); pBits[0] = oldValue; OS.MoveMemory(bm.bmBits, pBits, 1); transBlue = (color & 0xFF0000) >> 16; transGreen = (color & 0xFF00) >> 8; transRed = color & 0xFF; } else { int maxColors = 1 << bm.bmBitsPixel; byte[] oldColors = new byte[maxColors * 4]; int numColors = OS.GetDIBColorTable(srcHdc, 0, maxColors, oldColors); int offset = srcImage.transparentPixel * 4; byte[] newColors = new byte[oldColors.length]; transRed = transGreen = transBlue = 0xff; newColors[offset] = (byte)transBlue; newColors[offset+1] = (byte)transGreen; newColors[offset+2] = (byte)transRed; OS.SetDIBColorTable(srcHdc, 0, maxColors, newColors); originalColors = oldColors; }
void drawBitmapTransparent(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, BITMAP bm, int imgWidth, int imgHeight) {	/* Get the HDC for the device */	Device device = data.device; 	int hDC = device.internal_new_GC(null); 			/* Find the RGB values for the transparent pixel. */	int transBlue = 0, transGreen = 0, transRed = 0;	boolean isDib = bm.bmBits != 0;	int hBitmap = srcImage.handle;	int srcHdc = OS.CreateCompatibleDC(handle);	int oldSrcBitmap = OS.SelectObject(srcHdc, hBitmap);	byte[] originalColors = null;	if (bm.bmBitsPixel <= 8) {		if (isDib) {			/* Palette-based DIBSECTION */			int maxColors = 1 << bm.bmBitsPixel;			byte[] oldColors = new byte[maxColors * 4];			if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);			int numColors = OS.GetDIBColorTable(srcHdc, 0, maxColors, oldColors);			int offset = srcImage.transparentPixel * 4;			byte[] newColors = new byte[oldColors.length];			transRed = transGreen = transBlue = 0xff;			newColors[offset] = (byte)transBlue;			newColors[offset+1] = (byte)transGreen;			newColors[offset+2] = (byte)transRed;			if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);			OS.SetDIBColorTable(srcHdc, 0, maxColors, newColors);			originalColors = oldColors;		} else {			/* Palette-based bitmap */			int numColors = 1 << bm.bmBitsPixel;			byte[] bmi = new byte[40 + numColors * 4];			/* Set the few fields necessary to get the RGB data out */			bmi[0] = 40;			bmi[12] = (byte)(bm.bmPlanes & 0xFF);			bmi[13] = (byte)((bm.bmPlanes >> 8) & 0xFF);			bmi[14] = (byte)(bm.bmBitsPixel & 0xFF);			bmi[15] = (byte)((bm.bmBitsPixel >> 8) & 0xFF);			if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);			OS.GetDIBits(srcHdc, srcImage.handle, 0, 0, 0, bmi, OS.DIB_RGB_COLORS);			int offset = 40 + 4 * srcImage.transparentPixel;			transRed = bmi[offset + 2] & 0xFF;			transGreen = bmi[offset + 1] & 0xFF;			transBlue = bmi[offset] & 0xFF;		}	} else {		/* Direct color image */		int pixel = srcImage.transparentPixel;		switch (bm.bmBitsPixel) {			case 16:				transBlue = (pixel & 0x1F) << 3;				transGreen = (pixel & 0x3E0) >> 2;				transRed = (pixel & 0x7C00) >> 7;				break;			case 24:				transBlue = (pixel & 0xFF0000) >> 16;				transGreen = (pixel & 0xFF00) >> 8;				transRed = pixel & 0xFF;				break;			case 32:				transBlue = (pixel & 0xFF000000) >>> 24;				transGreen = (pixel & 0xFF0000) >> 16;				transRed = (pixel & 0xFF00) >> 8;				break;		}	}	/* Create the mask for the source image */	int maskHdc = OS.CreateCompatibleDC(hDC);	int maskBitmap = OS.CreateBitmap(imgWidth, imgHeight, 1, 1, null);	int oldMaskBitmap = OS.SelectObject(maskHdc, maskBitmap);	OS.SetBkColor(srcHdc, (transBlue << 16) | (transGreen << 8) | transRed);	OS.BitBlt(maskHdc, 0, 0, imgWidth, imgHeight, srcHdc, 0, 0, OS.SRCCOPY);	if (originalColors != null) OS.SetDIBColorTable(srcHdc, 0, 1 << bm.bmBitsPixel, originalColors);	/* Draw the source bitmap transparently using invert/and mask/invert */	int tempHdc = OS.CreateCompatibleDC(hDC);	int tempBitmap = OS.CreateCompatibleBitmap(hDC, destWidth, destHeight);		int oldTempBitmap = OS.SelectObject(tempHdc, tempBitmap);	OS.BitBlt(tempHdc, 0, 0, destWidth, destHeight, handle, destX, destY, OS.SRCCOPY);	if (!OS.IsWinCE) OS.SetStretchBltMode(tempHdc, OS.COLORONCOLOR);	OS.StretchBlt(tempHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, OS.SRCINVERT);	OS.StretchBlt(tempHdc, 0, 0, destWidth, destHeight, maskHdc, srcX, srcY, srcWidth, srcHeight, OS.SRCAND);	OS.StretchBlt(tempHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, OS.SRCINVERT);	OS.BitBlt(handle, destX, destY, destWidth, destHeight, tempHdc, 0, 0, OS.SRCCOPY);	/* Release resources */	OS.SelectObject(tempHdc, oldTempBitmap);	OS.DeleteDC(tempHdc);	OS.DeleteObject(tempBitmap);	OS.SelectObject(maskHdc, oldMaskBitmap);	OS.DeleteDC(maskHdc);	OS.DeleteObject(maskBitmap);	OS.SelectObject(srcHdc, oldSrcBitmap);	if (hBitmap != srcImage.handle) OS.DeleteObject(hBitmap);	OS.DeleteDC(srcHdc);		/* Release the HDC for the device */	device.internal_dispose_GC(hDC, null);}