Optimize BGRA conversion by writing directly to the DIB section

This commit is contained in:
Ioannis Tsakpinis 2015-09-07 16:04:27 +03:00
parent cc340c7c72
commit 9323778a15

View File

@ -733,7 +733,6 @@ static HICON createIcon(GLFWimage* image)
{ {
BITMAPV5HEADER header; BITMAPV5HEADER header;
HDC hdc; HDC hdc;
unsigned char* BGRAData;
HBITMAP bitmap, mask; HBITMAP bitmap, mask;
ICONINFO iconinfo; ICONINFO iconinfo;
HICON icon; HICON icon;
@ -757,26 +756,18 @@ static HICON createIcon(GLFWimage* image)
bitmap = CreateDIBSection(hdc, (BITMAPINFO*) &header, DIB_RGB_COLORS, (void**) &dibData, NULL, 0); bitmap = CreateDIBSection(hdc, (BITMAPINFO*) &header, DIB_RGB_COLORS, (void**) &dibData, NULL, 0);
ReleaseDC(NULL, hdc); ReleaseDC(NULL, hdc);
// first we need to convert RGBA to BGRA (yay Windows!)
BGRAData = calloc(1, image->width * image->height * 4);
for (i = 0; i < image->width * image->height; i++) for (i = 0; i < image->width * image->height; i++)
{ {
unsigned char* dst = BGRAData + 4 * i; unsigned char* dst = dibData + 4 * i;
unsigned char *src = image->pixels + 4 * i; unsigned char *src = image->pixels + 4 * i;
// convert RGBA to BGRA
dst[0] = src[2]; // copy blue channel dst[0] = src[2]; // copy blue channel
dst[1] = src[1]; // copy green channel dst[1] = src[1]; // copy green channel
dst[2] = src[0]; // copy red channel dst[2] = src[0]; // copy red channel
dst[3] = src[3]; // copy alpha channel dst[3] = src[3]; // copy alpha channel
} }
// copy the BGRA data into dibData
memcpy(dibData, BGRAData, image->width * image->height * 4);
// free the BGRA data
free(BGRAData);
// create a mask that we don't use (but needed for iconinfo) // create a mask that we don't use (but needed for iconinfo)
mask = CreateBitmap(image->width, image->height, 1, 1, NULL); mask = CreateBitmap(image->width, image->height, 1, 1, NULL);