2012-05-04 18:56:43 +00:00
|
|
|
|
2017-12-02 20:00:06 +00:00
|
|
|
#include "precomp.h"
|
|
|
|
|
2015-02-10 22:31:17 +00:00
|
|
|
#include "init.h"
|
2012-05-04 18:56:43 +00:00
|
|
|
|
2015-02-10 22:31:17 +00:00
|
|
|
HBITMAP ghbmp1, ghbmp4, ghbmp8, ghbmp16, ghbmp24, ghbmp32;
|
|
|
|
HBITMAP ghbmpDIB1, ghbmpDIB4, ghbmpDIB8, ghbmpDIB16, ghbmpDIB24, ghbmpDIB32;
|
|
|
|
HDC ghdcDIB1, ghdcDIB4, ghdcDIB8, ghdcDIB16, ghdcDIB24, ghdcDIB32;
|
|
|
|
PVOID gpvDIB1, gpvDIB4, gpvDIB8, gpvDIB16, gpvDIB24, gpvDIB32;
|
2015-02-14 11:25:02 +00:00
|
|
|
ULONG (*gpDIB32)[8][8];
|
2012-05-04 18:56:43 +00:00
|
|
|
HPALETTE ghpal;
|
|
|
|
|
2015-02-10 22:31:17 +00:00
|
|
|
MYPAL gpal =
|
2012-05-04 18:56:43 +00:00
|
|
|
{
|
|
|
|
0x300, 8,
|
|
|
|
{
|
|
|
|
{ 0x10, 0x20, 0x30, PC_NOCOLLAPSE },
|
|
|
|
{ 0x20, 0x30, 0x40, PC_NOCOLLAPSE },
|
|
|
|
{ 0x30, 0x40, 0x50, PC_NOCOLLAPSE },
|
|
|
|
{ 0x40, 0x50, 0x60, PC_NOCOLLAPSE },
|
|
|
|
{ 0x50, 0x60, 0x70, PC_NOCOLLAPSE },
|
|
|
|
{ 0x60, 0x70, 0x80, PC_NOCOLLAPSE },
|
|
|
|
{ 0x70, 0x80, 0x90, PC_NOCOLLAPSE },
|
|
|
|
{ 0x80, 0x90, 0xA0, PC_NOCOLLAPSE },
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-10 22:31:17 +00:00
|
|
|
BOOL
|
|
|
|
InitPerBitDepth(
|
|
|
|
_In_ ULONG cBitsPerPixel,
|
|
|
|
_In_ ULONG cx,
|
|
|
|
_In_ ULONG cy,
|
|
|
|
_Out_ HBITMAP *phbmp,
|
|
|
|
_Out_ HDC *phdcDIB,
|
|
|
|
_Out_ HBITMAP *phbmpDIB,
|
|
|
|
_Out_ PVOID *ppvBits)
|
2012-05-04 18:56:43 +00:00
|
|
|
{
|
2015-02-10 22:31:17 +00:00
|
|
|
struct
|
|
|
|
{
|
2015-02-13 09:06:00 +00:00
|
|
|
BITMAPINFOHEADER bmiHeader;
|
2015-02-14 13:19:02 +00:00
|
|
|
ULONG bmiColors[256];
|
2015-02-10 22:31:17 +00:00
|
|
|
} bmiBuffer;
|
|
|
|
LPBITMAPINFO pbmi = (LPBITMAPINFO)&bmiBuffer;
|
2012-05-04 18:56:43 +00:00
|
|
|
|
2015-02-10 22:31:17 +00:00
|
|
|
/* Create a bitmap */
|
|
|
|
*phbmp = CreateBitmap(cx, cy, 1, cBitsPerPixel, NULL);
|
|
|
|
if (*phbmp == NULL)
|
|
|
|
{
|
|
|
|
printf("CreateBitmap failed %lu\n", cBitsPerPixel);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-05-04 18:56:43 +00:00
|
|
|
|
2015-02-14 11:25:02 +00:00
|
|
|
/* Setup bitmap info */
|
2015-02-10 22:31:17 +00:00
|
|
|
memset(&bmiBuffer, 0, sizeof(bmiBuffer));
|
|
|
|
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
2015-02-14 11:25:02 +00:00
|
|
|
pbmi->bmiHeader.biWidth = cx;
|
|
|
|
pbmi->bmiHeader.biHeight = -(LONG)cy;
|
|
|
|
pbmi->bmiHeader.biPlanes = 1;
|
|
|
|
pbmi->bmiHeader.biBitCount = cBitsPerPixel;
|
|
|
|
pbmi->bmiHeader.biCompression = BI_RGB;
|
|
|
|
pbmi->bmiHeader.biSizeImage = 0;
|
|
|
|
pbmi->bmiHeader.biXPelsPerMeter = 0;
|
|
|
|
pbmi->bmiHeader.biYPelsPerMeter = 0;
|
|
|
|
pbmi->bmiHeader.biClrUsed = 0;
|
|
|
|
pbmi->bmiHeader.biClrImportant = 0;
|
2015-02-10 22:31:17 +00:00
|
|
|
|
2015-02-14 13:19:02 +00:00
|
|
|
if (cBitsPerPixel == 1)
|
|
|
|
{
|
|
|
|
bmiBuffer.bmiColors[0] = 0;
|
|
|
|
bmiBuffer.bmiColors[1] = 0xFFFFFF;
|
|
|
|
pbmi->bmiHeader.biClrUsed = 2;
|
|
|
|
}
|
|
|
|
|
2015-02-10 22:31:17 +00:00
|
|
|
/* Create a compatible DC for the DIB */
|
|
|
|
*phdcDIB = CreateCompatibleDC(0);
|
|
|
|
if (*phdcDIB == NULL)
|
|
|
|
{
|
|
|
|
printf("CreateCompatibleDC failed %lu\n", cBitsPerPixel);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-05-17 18:56:00 +00:00
|
|
|
|
2015-02-10 22:31:17 +00:00
|
|
|
/* Create the DIB section with the same values */
|
|
|
|
*phbmpDIB = CreateDIBSection(*phdcDIB, pbmi, DIB_RGB_COLORS, ppvBits, 0, 0 );
|
|
|
|
if (*phbmpDIB == NULL)
|
|
|
|
{
|
|
|
|
printf("CreateDIBSection failed. %lu\n", cBitsPerPixel);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectObject(*phdcDIB, *phbmpDIB);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL InitStuff(void)
|
|
|
|
{
|
2012-05-04 18:56:43 +00:00
|
|
|
|
|
|
|
/* Initialize a logical palette */
|
|
|
|
ghpal = CreatePalette((LOGPALETTE*)&gpal);
|
|
|
|
if (!ghpal)
|
|
|
|
{
|
2021-09-12 17:49:54 +00:00
|
|
|
printf("failed to create a palette\n");
|
2012-05-04 18:56:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-02-14 11:25:02 +00:00
|
|
|
if (!InitPerBitDepth(1, 9, 9, &ghbmp1, &ghdcDIB1, &ghbmpDIB1, &gpvDIB1) ||
|
|
|
|
!InitPerBitDepth(4, 5, 5, &ghbmp4, &ghdcDIB4, &ghbmpDIB4, &gpvDIB4) ||
|
|
|
|
!InitPerBitDepth(8, 5, 5, &ghbmp8, &ghdcDIB8, &ghbmpDIB8, &gpvDIB8) ||
|
|
|
|
!InitPerBitDepth(16, 8, 8, &ghbmp16, &ghdcDIB16, &ghbmpDIB16, &gpvDIB16) ||
|
|
|
|
!InitPerBitDepth(24, 8, 8, &ghbmp24, &ghdcDIB24, &ghbmpDIB24, &gpvDIB24) ||
|
|
|
|
!InitPerBitDepth(32, 8, 8, &ghbmp32, &ghdcDIB32, &ghbmpDIB32, &gpvDIB32))
|
2015-02-10 22:31:17 +00:00
|
|
|
{
|
2021-09-12 17:49:54 +00:00
|
|
|
printf("failed to create objects\n");
|
2015-02-10 22:31:17 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-02-14 11:25:02 +00:00
|
|
|
gpDIB32 = gpvDIB32;
|
2015-02-10 22:31:17 +00:00
|
|
|
|
2012-05-04 18:56:43 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|