From 3099edb9c973d709f48b28ddceff0c67bcf0923c Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 17 Feb 2015 21:35:03 -0500 Subject: Next part of Table code: HBITMAP generation code migration. --- image_windows.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 image_windows.c (limited to 'image_windows.c') diff --git a/image_windows.c b/image_windows.c new file mode 100644 index 0000000..7e57bff --- /dev/null +++ b/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(void *bitmap) +{ + if (DeleteObject((HBITMAP) bitmap) == 0) + xpanic("error deleting bitmap in freeBitmap()", GetLastError()); +} -- cgit v1.2.3