diff options
Diffstat (limited to 'prev/image_windows.c')
| -rw-r--r-- | prev/image_windows.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/prev/image_windows.c b/prev/image_windows.c new file mode 100644 index 0000000..bcea3c4 --- /dev/null +++ b/prev/image_windows.c @@ -0,0 +1,35 @@ +// 16 august 2014 + +#include "winapi_windows.h" +#include "_cgo_export.h" + +// TODO rename to images_windows.c? + +HBITMAP toBitmap(void *i, intptr_t dx, intptr_t dy) +{ + BITMAPINFO bi; + VOID *ppvBits; + HBITMAP bitmap; + + ZeroMemory(&bi, sizeof (BITMAPINFO)); + bi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); + bi.bmiHeader.biWidth = (LONG) dx; + bi.bmiHeader.biHeight = -((LONG) dy); // negative height to force top-down drawing; + bi.bmiHeader.biPlanes = 1; + bi.bmiHeader.biBitCount = 32; + bi.bmiHeader.biCompression = BI_RGB; + bi.bmiHeader.biSizeImage = (DWORD) (dx * dy * 4); + bitmap = CreateDIBSection(NULL, &bi, DIB_RGB_COLORS, &ppvBits, 0, 0); + if (bitmap == NULL) + xpanic("error creating HBITMAP in toBitmap()", GetLastError()); + // image lists use non-premultiplied RGBA - see http://stackoverflow.com/a/25578789/3408572 + // the TRUE here does the conversion + dotoARGB(i, (void *) ppvBits, TRUE); + return bitmap; +} + +void freeBitmap(uintptr_t bitmap) +{ + if (DeleteObject((HBITMAP) bitmap) == 0) + xpanic("error deleting bitmap in freeBitmap()", GetLastError()); +} |
