[GDI32_APITEST] Properly add CreateDIBPatternBrush.c to the source files list instead...
[reactos.git] / modules / rostests / apitests / gdi32 / init.c
1
2 #include "precomp.h"
3
4 #include "init.h"
5
6 HBITMAP ghbmp1, ghbmp4, ghbmp8, ghbmp16, ghbmp24, ghbmp32;
7 HBITMAP ghbmpDIB1, ghbmpDIB4, ghbmpDIB8, ghbmpDIB16, ghbmpDIB24, ghbmpDIB32;
8 HDC ghdcDIB1, ghdcDIB4, ghdcDIB8, ghdcDIB16, ghdcDIB24, ghdcDIB32;
9 PVOID gpvDIB1, gpvDIB4, gpvDIB8, gpvDIB16, gpvDIB24, gpvDIB32;
10 ULONG (*gpDIB32)[8][8];
11 HPALETTE ghpal;
12
13 MYPAL gpal =
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
29 InitPerBitDepth(
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));
55 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
56 pbmi->bmiHeader.biWidth = cx;
57 pbmi->bmiHeader.biHeight = -(LONG)cy;
58 pbmi->bmiHeader.biPlanes = 1;
59 pbmi->bmiHeader.biBitCount = cBitsPerPixel;
60 pbmi->bmiHeader.biCompression = BI_RGB;
61 pbmi->bmiHeader.biSizeImage = 0;
62 pbmi->bmiHeader.biXPelsPerMeter = 0;
63 pbmi->bmiHeader.biYPelsPerMeter = 0;
64 pbmi->bmiHeader.biClrUsed = 0;
65 pbmi->bmiHeader.biClrImportant = 0;
66
67 if (cBitsPerPixel == 1)
68 {
69 bmiBuffer.bmiColors[0] = 0;
70 bmiBuffer.bmiColors[1] = 0xFFFFFF;
71 pbmi->bmiHeader.biClrUsed = 2;
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
95 BOOL InitStuff(void)
96 {
97
98 /* Initialize a logical palette */
99 ghpal = CreatePalette((LOGPALETTE*)&gpal);
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) ||
111 !InitPerBitDepth(32, 8, 8, &ghbmp32, &ghdcDIB32, &ghbmpDIB32, &gpvDIB32))
112 {
113 printf("failed to create objects \n");
114 return FALSE;
115 }
116
117 gpDIB32 = gpvDIB32;
118
119 return TRUE;
120 }