38 #include "nsStringGlue.h"
40 #include "gfxImageSurface.h"
57 NS_ENSURE_ARG(aImage);
60 BITMAPV4HEADER infoHeader;
61 ::ZeroMemory(&infoHeader,
sizeof(infoHeader));
62 infoHeader.bV4Size =
sizeof(infoHeader);
63 infoHeader.bV4Width = aImage->Width();
64 infoHeader.bV4Height = -aImage->Height();
65 infoHeader.bV4Planes = 1;
66 infoHeader.bV4BitCount = 32;
67 infoHeader.bV4V4Compression = BI_BITFIELDS;
68 infoHeader.bV4SizeImage = aImage->Height() * aImage->Stride();
69 infoHeader.bV4XPelsPerMeter = 0;
70 infoHeader.bV4YPelsPerMeter = 0;
71 infoHeader.bV4ClrUsed = 0;
72 infoHeader.bV4ClrImportant = 0;
73 infoHeader.bV4RedMask = 0x00FF0000;
74 infoHeader.bV4GreenMask = 0x0000FF00;
75 infoHeader.bV4BlueMask = 0x000000FF;
76 infoHeader.bV4AlphaMask = 0xFF000000;
78 HBITMAP tBitmap = NULL, oldbits = NULL, bitmap = NULL;
79 HDC dc = ::CreateCompatibleDC(NULL);
80 if (!dc)
return NS_ERROR_FAILURE;
83 tBitmap = ::CreateBitmap(1, 1, 1, 32, NULL);
84 if (!tBitmap)
goto loser;
85 oldbits = (
HBITMAP)::SelectObject(dc, tBitmap);
86 if (!oldbits)
goto loser;
88 PRUint8 *bits = aImage->Data();
90 bitmap = ::CreateDIBitmap(dc,
91 reinterpret_cast<CONST BITMAPINFOHEADER*>(&infoHeader),
94 reinterpret_cast<CONST BITMAPINFO*>(&infoHeader),
105 ::SelectObject(dc, oldbits);
107 ::DeleteObject(tBitmap);
110 return outBitmap ?
NS_OK : NS_ERROR_FAILURE;
116 return ImageToIcon(aImage, PR_TRUE, 0, 0, outIcon);
120 PRUint32 aHotspotX, PRUint32 aHotspotY,
HCURSOR& outCursor)
122 return ImageToIcon(aImage, PR_FALSE, aHotspotX, aHotspotY, outCursor);
126 PRBool aIcon, PRUint32 aHotspotX, PRUint32 aHotspotY,
138 info.xHotspot = aHotspotX;
139 info.yHotspot = aHotspotY;
141 info.hbmColor = hBMP;
143 _retval = ::CreateIconIndirect(&info);
144 ::DeleteObject(hBMP);
146 if (_retval == NULL) {
147 return NS_ERROR_FAILURE;
NS_IMETHOD ConvertImageToBitmap(gfxImageSurface *aImage, HBITMAP &outBitmap)
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
struct HBITMAP__ * HBITMAP
NS_IMETHOD ConvertImageToCursor(gfxImageSurface *aImage, PRUint32 aHotspotX, PRUint32 aHotspotY, HCURSOR &outCursor)
NS_IMETHOD ConvertImageToIcon(gfxImageSurface *aImage, HICON &outIcon)
nsresult ImageToIcon(gfxImageSurface *aImage, PRBool aIcon, PRUint32 aHotspotX, PRUint32 aHotspotY, HICON &_retval)