[GDI32_APITEST]
[reactos.git] / rostests / apitests / gdi32 / init.c
1
2 #include <stdio.h>
3 #include <windef.h>
4 #include <wingdi.h>
5 #include "init.h"
6
7 HBITMAP ghbmp1, ghbmp4, ghbmp8, ghbmp16, ghbmp24, ghbmp32;
8 HBITMAP ghbmpDIB1, ghbmpDIB4, ghbmpDIB8, ghbmpDIB16, ghbmpDIB24, ghbmpDIB32;
9 HDC ghdcDIB1, ghdcDIB4, ghdcDIB8, ghdcDIB16, ghdcDIB24, ghdcDIB32;
10 PVOID gpvDIB1, gpvDIB4, gpvDIB8, gpvDIB16, gpvDIB24, gpvDIB32;
11 ULONG (*gpDIB32)[8][8];
12 HPALETTE ghpal;
13
14 MYPAL gpal =
15 {
16 0x300, 8,
17 {
18 { 0x10, 0x20, 0x30, PC_NOCOLLAPSE },
19 { 0x20, 0x30, 0x40, PC_NOCOLLAPSE },
20 { 0x30, 0x40, 0x50, PC_NOCOLLAPSE },
21 { 0x40, 0x50, 0x60, PC_NOCOLLAPSE },
22 { 0x50, 0x60, 0x70, PC_NOCOLLAPSE },
23 { 0x60, 0x70, 0x80, PC_NOCOLLAPSE },
24 { 0x70, 0x80, 0x90, PC_NOCOLLAPSE },
25 { 0x80, 0x90, 0xA0, PC_NOCOLLAPSE },
26 }
27 };
28
29 BOOL
30 InitPerBitDepth(
31 _In_ ULONG cBitsPerPixel,
32 _In_ ULONG cx,
33 _In_ ULONG cy,
34 _Out_ HBITMAP *phbmp,
35 _Out_ HDC *phdcDIB,
36 _Out_ HBITMAP *phbmpDIB,
37 _Out_ PVOID *ppvBits)
38 {
39 struct
40 {
41 BITMAPINFOHEADER bmiHeader;
42 ULONG bmiColors[256];
43 } bmiBuffer;
44 LPBITMAPINFO pbmi = (LPBITMAPINFO)&bmiBuffer;
45
46 /* Create a bitmap */
47 *phbmp = CreateBitmap(cx, cy, 1, cBitsPerPixel, NULL);
48 if (*phbmp == NULL)
49 {
50 printf("CreateBitmap failed %lu\n", cBitsPerPixel);
51 return FALSE;
52 }
53
54 /* Setup bitmap info */
55 memset(&bmiBuffer, 0, sizeof(bmiBuffer));
56 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
57 pbmi->bmiHeader.biWidth = cx;
58 pbmi->bmiHeader.biHeight = -(LONG)cy;
59 pbmi->bmiHeader.biPlanes = 1;
60 pbmi->bmiHeader.biBitCount = cBitsPerPixel;
61 pbmi->bmiHeader.biCompression = BI_RGB;
62 pbmi->bmiHeader.biSizeImage = 0;
63 pbmi->bmiHeader.biXPelsPerMeter = 0;
64 pbmi->bmiHeader.biYPelsPerMeter = 0;
65 pbmi->bmiHeader.biClrUsed = 0;
66 pbmi->bmiHeader.biClrImportant = 0;
67
68 if (cBitsPerPixel == 1)
69 {
70 bmiBuffer.bmiColors[0] = 0;
71 bmiBuffer.bmiColors[1] = 0xFFFFFF;
72 pbmi->bmiHeader.biClrUsed = 2;
73 }
74
75 /* Create a compatible DC for the DIB */
76 *phdcDIB = CreateCompatibleDC(0);
77 if (*phdcDIB == NULL)
78 {
79 printf("CreateCompatibleDC failed %lu\n", cBitsPerPixel);
80 return FALSE;
81 }
82
83 /* Create the DIB section with the same values */
84 *phbmpDIB = CreateDIBSection(*phdcDIB, pbmi, DIB_RGB_COLORS, ppvBits, 0, 0 );
85 if (*phbmpDIB == NULL)
86 {
87 printf("CreateDIBSection failed. %lu\n", cBitsPerPixel);
88 return FALSE;
89 }
90
91 SelectObject(*phdcDIB, *phbmpDIB);
92
93 return TRUE;
94 }
95
96 BOOL InitStuff(void)
97 {
98
99 /* Initialize a logical palette */
100 ghpal = CreatePalette((LOGPALETTE*)&gpal);
101 if (!ghpal)
102 {
103 printf("failed to create a palette \n");
104 return FALSE;
105 }
106
107 if (!InitPerBitDepth(1, 9, 9, &ghbmp1, &ghdcDIB1, &ghbmpDIB1, &gpvDIB1) ||
108 !InitPerBitDepth(4, 5, 5, &ghbmp4, &ghdcDIB4, &ghbmpDIB4, &gpvDIB4) ||
109 !InitPerBitDepth(8, 5, 5, &ghbmp8, &ghdcDIB8, &ghbmpDIB8, &gpvDIB8) ||
110 !InitPerBitDepth(16, 8, 8, &ghbmp16, &ghdcDIB16, &ghbmpDIB16, &gpvDIB16) ||
111 !InitPerBitDepth(24, 8, 8, &ghbmp24, &ghdcDIB24, &ghbmpDIB24, &gpvDIB24) ||
112 !InitPerBitDepth(32, 8, 8, &ghbmp32, &ghdcDIB32, &ghbmpDIB32, &gpvDIB32))
113 {
114 printf("failed to create objects \n");
115 return FALSE;
116 }
117
118 gpDIB32 = gpvDIB32;
119
120 return TRUE;
121 }