ReactOS  0.4.14-dev-41-g31d7680
init.c
Go to the documentation of this file.
1 
2 #include "precomp.h"
3 
4 #include "init.h"
5 
10 ULONG (*gpDIB32)[8][8];
11 HPALETTE ghpal;
12 
14 {
15  0x300, 8,
16  {
17  { 0x10, 0x20, 0x30, PC_NOCOLLAPSE },
18  { 0x20, 0x30, 0x40, PC_NOCOLLAPSE },
19  { 0x30, 0x40, 0x50, PC_NOCOLLAPSE },
20  { 0x40, 0x50, 0x60, PC_NOCOLLAPSE },
21  { 0x50, 0x60, 0x70, PC_NOCOLLAPSE },
22  { 0x60, 0x70, 0x80, PC_NOCOLLAPSE },
23  { 0x70, 0x80, 0x90, PC_NOCOLLAPSE },
24  { 0x80, 0x90, 0xA0, PC_NOCOLLAPSE },
25  }
26 };
27 
28 BOOL
30  _In_ ULONG cBitsPerPixel,
31  _In_ ULONG cx,
32  _In_ ULONG cy,
33  _Out_ HBITMAP *phbmp,
34  _Out_ HDC *phdcDIB,
35  _Out_ HBITMAP *phbmpDIB,
36  _Out_ PVOID *ppvBits)
37 {
38  struct
39  {
40  BITMAPINFOHEADER bmiHeader;
41  ULONG bmiColors[256];
42  } bmiBuffer;
43  LPBITMAPINFO pbmi = (LPBITMAPINFO)&bmiBuffer;
44 
45  /* Create a bitmap */
46  *phbmp = CreateBitmap(cx, cy, 1, cBitsPerPixel, NULL);
47  if (*phbmp == NULL)
48  {
49  printf("CreateBitmap failed %lu\n", cBitsPerPixel);
50  return FALSE;
51  }
52 
53  /* Setup bitmap info */
54  memset(&bmiBuffer, 0, sizeof(bmiBuffer));
58  pbmi->bmiHeader.biPlanes = 1;
59  pbmi->bmiHeader.biBitCount = cBitsPerPixel;
66 
67  if (cBitsPerPixel == 1)
68  {
69  bmiBuffer.bmiColors[0] = 0;
70  bmiBuffer.bmiColors[1] = 0xFFFFFF;
72  }
73 
74  /* Create a compatible DC for the DIB */
75  *phdcDIB = CreateCompatibleDC(0);
76  if (*phdcDIB == NULL)
77  {
78  printf("CreateCompatibleDC failed %lu\n", cBitsPerPixel);
79  return FALSE;
80  }
81 
82  /* Create the DIB section with the same values */
83  *phbmpDIB = CreateDIBSection(*phdcDIB, pbmi, DIB_RGB_COLORS, ppvBits, 0, 0 );
84  if (*phbmpDIB == NULL)
85  {
86  printf("CreateDIBSection failed. %lu\n", cBitsPerPixel);
87  return FALSE;
88  }
89 
90  SelectObject(*phdcDIB, *phbmpDIB);
91 
92  return TRUE;
93 }
94 
96 {
97 
98  /* Initialize a logical palette */
100  if (!ghpal)
101  {
102  printf("failed to create a palette \n");
103  return FALSE;
104  }
105 
106  if (!InitPerBitDepth(1, 9, 9, &ghbmp1, &ghdcDIB1, &ghbmpDIB1, &gpvDIB1) ||
107  !InitPerBitDepth(4, 5, 5, &ghbmp4, &ghdcDIB4, &ghbmpDIB4, &gpvDIB4) ||
108  !InitPerBitDepth(8, 5, 5, &ghbmp8, &ghdcDIB8, &ghbmpDIB8, &gpvDIB8) ||
109  !InitPerBitDepth(16, 8, 8, &ghbmp16, &ghdcDIB16, &ghbmpDIB16, &gpvDIB16) ||
110  !InitPerBitDepth(24, 8, 8, &ghbmp24, &ghdcDIB24, &ghbmpDIB24, &gpvDIB24) ||
112  {
113  printf("failed to create objects \n");
114  return FALSE;
115  }
116 
117  gpDIB32 = gpvDIB32;
118 
119  return TRUE;
120 }
HBITMAP ghbmp16
Definition: init.c:6
HBITMAP ghbmp4
Definition: init.c:6
#define TRUE
Definition: types.h:120
HBITMAP ghbmpDIB16
Definition: init.c:7
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1471
DWORD biClrImportant
Definition: amvideo.idl:40
struct tagBITMAPINFO * LPBITMAPINFO
HPALETTE ghpal
Definition: init.c:11
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
LONG biXPelsPerMeter
Definition: amvideo.idl:37
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
static HDC
Definition: imagelist.c:92
HBITMAP ghbmp1
Definition: init.c:6
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
PVOID gpvDIB4
Definition: init.c:9
LONG biYPelsPerMeter
Definition: amvideo.idl:38
HBITMAP ghbmp8
Definition: init.c:6
ULONG(* gpDIB32)[8][8]
Definition: init.c:10
HDC ghdcDIB1
Definition: init.c:8
HBITMAP ghbmp32
Definition: init.c:6
HBITMAP ghbmpDIB4
Definition: init.c:7
HBITMAP ghbmpDIB8
Definition: init.c:7
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
DWORD biCompression
Definition: amvideo.idl:35
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:570
PVOID gpvDIB32
Definition: init.c:9
smooth NULL
Definition: ftsmooth.c:416
#define _Out_
Definition: no_sal2.h:323
HBITMAP ghbmpDIB1
Definition: init.c:7
MYPAL gpal
Definition: init.c:13
BOOL InitPerBitDepth(_In_ ULONG cBitsPerPixel, _In_ ULONG cx, _In_ ULONG cy, _Out_ HBITMAP *phbmp, _Out_ HDC *phdcDIB, _Out_ HBITMAP *phbmpDIB, _Out_ PVOID *ppvBits)
Definition: init.c:29
HPALETTE WINAPI CreatePalette(_In_reads_(_Inexpressible_(2 *sizeof(WORD)+plpal->palNumEntries *sizeof(PALETTEENTRY))) const LOGPALETTE *)
PVOID gpvDIB24
Definition: init.c:9
PVOID gpvDIB16
Definition: init.c:9
DWORD biSizeImage
Definition: amvideo.idl:36
PVOID gpvDIB1
Definition: init.c:9
BOOL InitStuff(void)
Definition: init.c:95
#define PC_NOCOLLAPSE
Definition: wingdi.h:880
HDC ghdcDIB16
Definition: init.c:8
HBITMAP ghbmpDIB32
Definition: init.c:7
#define _In_
Definition: no_sal2.h:204
PVOID gpvDIB8
Definition: init.c:9
HDC ghdcDIB24
Definition: init.c:8
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:197
_Out_opt_ int * cx
Definition: commctrl.h:570
unsigned int ULONG
Definition: retypes.h:1
HDC ghdcDIB8
Definition: init.c:8
Definition: init.h:12
static HBITMAP
Definition: button.c:44
HDC ghdcDIB4
Definition: init.c:8
HDC ghdcDIB32
Definition: init.c:8
#define DIB_RGB_COLORS
Definition: wingdi.h:366
#define memset(x, y, z)
Definition: compat.h:39
#define BI_RGB
Definition: precomp.h:34
HBITMAP ghbmp24
Definition: init.c:6
HBITMAP ghbmpDIB24
Definition: init.c:7
#define printf
Definition: config.h:203
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)