[GDI32_APITEST]
[reactos.git] / rostests / apitests / gdi32 / MaskBlt.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for GdiReleaseLocalDC
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include <stdio.h>
9 #include <wine/test.h>
10 #include <windows.h>
11
12 void Test_MaskBlt_1bpp()
13 {
14 HDC hdcDst, hdcSrc;
15 BITMAPINFO bmi = {{sizeof(BITMAPINFOHEADER), 8, 1, 1, 1, BI_RGB, 0, 10, 10, 0,0}};
16 HBITMAP hbmDst, hbmSrc, hbmMsk;
17 PUCHAR pjBitsDst, pjBitsSrc, pjBitsMsk;
18 BOOL ret;
19
20 /* Create a dest dc and bitmap */
21 hdcDst = CreateCompatibleDC(NULL);
22 hbmDst = CreateDIBSection(hdcDst, &bmi, DIB_RGB_COLORS, (PVOID*)&pjBitsDst, NULL, 0);
23 SelectObject(hdcDst, hbmDst);
24
25 /* Create a source dc and bitmap */
26 hdcSrc = CreateCompatibleDC(NULL);
27 hbmSrc = CreateDIBSection(hdcSrc, &bmi, DIB_RGB_COLORS, (PVOID*)&pjBitsSrc, NULL, 0);
28 SelectObject(hdcSrc, hbmSrc);
29
30 /* Create a 1 bpp mask bitmap */
31 hbmMsk = CreateDIBSection(hdcDst, &bmi, DIB_RGB_COLORS, (PVOID*)&pjBitsMsk, NULL, 0);
32
33 /* Do the masking */
34 pjBitsDst[0] = 0xAA;
35 pjBitsSrc[0] = 0xCC;
36 pjBitsMsk[0] = 0xF0;
37 ret = MaskBlt(hdcDst, 0, 0, 8, 1, hdcSrc, 0, 0, hbmMsk, 0, 0, MAKEROP4(SRCCOPY, 0xAA0000));
38 ok(ret == 1, "MaskBlt failed (%d)\n", ret);
39 ok (pjBitsDst[0] == 0xCA, "pjBitsDst[0] == 0x%x\n", pjBitsDst[0]);
40
41 pjBitsDst[0] = 0x00;
42 pjBitsSrc[0] = 0xFF;
43 pjBitsMsk[0] = 0xF0;
44 ret = MaskBlt(hdcDst, 0, 0, 8, 1, hdcSrc, 0, 0, hbmMsk, 0, 0, MAKEROP4(SRCCOPY, 0xAA0000));
45 ok(ret == 1, "MaskBlt failed (%d)\n", ret);
46 ok (pjBitsDst[0] == 0xF0, "pjBitsDst[0] == 0x%x\n", pjBitsDst[0]);
47
48 }
49
50 void Test_MaskBlt_16bpp()
51 {
52 HDC hdcDst, hdcSrc;
53 BITMAPINFO bmi1 = {{sizeof(BITMAPINFOHEADER), 8, 1, 1, 1, BI_RGB, 0, 10, 10, 0,0}};
54 BITMAPINFO bmi32 = {{sizeof(BITMAPINFOHEADER), 8, 1, 1, 16, BI_RGB, 0, 10, 10, 0,0}};
55 HBITMAP hbmDst, hbmSrc, hbmMsk;
56 PUCHAR pjBitsMsk;
57 PUSHORT pusBitsDst, pusBitsSrc;
58 BOOL ret;
59
60 /* Create a dest dc and bitmap */
61 hdcDst = CreateCompatibleDC(NULL);
62 hbmDst = CreateDIBSection(hdcDst, &bmi32, DIB_RGB_COLORS, (PVOID*)&pusBitsDst, NULL, 0);
63 SelectObject(hdcDst, hbmDst);
64
65 /* Create a source dc and bitmap */
66 hdcSrc = CreateCompatibleDC(NULL);
67 hbmSrc = CreateDIBSection(hdcSrc, &bmi32, DIB_RGB_COLORS, (PVOID*)&pusBitsSrc, NULL, 0);
68 SelectObject(hdcSrc, hbmSrc);
69 ok(hdcSrc && hbmSrc, "\n");
70
71 /* Create a 1 bpp mask bitmap */
72 hbmMsk = CreateDIBSection(hdcDst, &bmi1, DIB_RGB_COLORS, (PVOID*)&pjBitsMsk, NULL, 0);
73 ok(hbmMsk != 0, "CreateDIBSection failed\n");
74
75 /* Do the masking */
76 pusBitsDst[0] = 0x1234;
77 pusBitsDst[1] = 0x5678;
78 pusBitsSrc[0] = 0x4321;
79 pusBitsSrc[1] = 0x8765;
80 pjBitsMsk[0] = 0x80;
81 ret = MaskBlt(hdcDst, 0, 0, 8, 1, hdcSrc, 0, 0, hbmMsk, 0, 0, MAKEROP4(SRCCOPY, 0xAA0000));
82 ok(ret == 1, "MaskBlt failed (%d)\n", ret);
83 ok (pusBitsDst[0] == 0x4321, "pusBitsDst[0] == 0x%x\n", pusBitsDst[0]);
84 ok (pusBitsDst[1] == 0x5678, "pusBitsDst[0] == 0x%x\n", pusBitsDst[1]);
85
86 pusBitsDst[0] = 0x1234;
87 pusBitsDst[1] = 0x5678;
88 ret = MaskBlt(hdcDst, 0, 0, 8, 1, hdcSrc, 0, 0, hbmMsk, 0, 0, MAKEROP4(SRCPAINT, MERGEPAINT));
89 ok(ret == 1, "MaskBlt failed (%d)\n", ret);
90 ok (pusBitsDst[0] == 0x5335, "pusBitsDst[0] == 0x%x\n", pusBitsDst[0]);
91 ok (pusBitsDst[1] == 0x7efa, "pusBitsDst[0] == 0x%x\n", pusBitsDst[1]);
92 }
93
94 void Test_MaskBlt_32bpp()
95 {
96 HDC hdcDst, hdcSrc;
97 BITMAPINFO bmi1 = {{sizeof(BITMAPINFOHEADER), 8, 1, 1, 1, BI_RGB, 0, 10, 10, 0,0}};
98 BITMAPINFO bmi32 = {{sizeof(BITMAPINFOHEADER), 8, 1, 1, 32, BI_RGB, 0, 10, 10, 0,0}};
99 HBITMAP hbmDst, hbmSrc, hbmMsk;
100 PUCHAR pjBitsMsk;
101 PULONG pulBitsDst, pulBitsSrc;
102 BOOL ret;
103
104 /* Create a dest dc and bitmap */
105 hdcDst = CreateCompatibleDC(NULL);
106 hbmDst = CreateDIBSection(hdcDst, &bmi32, DIB_RGB_COLORS, (PVOID*)&pulBitsDst, NULL, 0);
107 SelectObject(hdcDst, hbmDst);
108
109 /* Create a source dc and bitmap */
110 hdcSrc = CreateCompatibleDC(NULL);
111 hbmSrc = CreateDIBSection(hdcSrc, &bmi32, DIB_RGB_COLORS, (PVOID*)&pulBitsSrc, NULL, 0);
112 SelectObject(hdcSrc, hbmSrc);
113 ok(hdcSrc && hbmSrc, "\n");
114
115 /* Create a 1 bpp mask bitmap */
116 hbmMsk = CreateDIBSection(hdcDst, &bmi1, DIB_RGB_COLORS, (PVOID*)&pjBitsMsk, NULL, 0);
117 ok(hbmMsk != 0, "CreateDIBSection failed\n");
118
119 /* Do the masking */
120 pulBitsDst[0] = 0x12345678;
121 pulBitsDst[1] = 0x9abcdef0;
122 pulBitsSrc[0] = 0x87684321;
123 pulBitsSrc[1] = 0x0fedcba9;
124 pjBitsMsk[0] = 0x80;
125 ret = MaskBlt(hdcDst, 0, 0, 8, 1, hdcSrc, 0, 0, hbmMsk, 0, 0, MAKEROP4(SRCCOPY, 0xAA0000));
126 ok(ret == 1, "MaskBlt failed (%d)\n", ret);
127 ok (pulBitsDst[0] == 0x87684321, "pulBitsDst[0] == 0x%lx\n", pulBitsDst[0]);
128 ok (pulBitsDst[1] == 0x9abcdef0, "pulBitsDst[0] == 0x%lx\n", pulBitsDst[1]);
129
130 pulBitsDst[0] = 0x12345678;
131 pulBitsDst[1] = 0x9abcdef0;
132 ret = MaskBlt(hdcDst, 0, 0, 8, 1, hdcSrc, 0, 0, hbmMsk, 0, 0, MAKEROP4(SRCPAINT, MERGEPAINT));
133 ok(ret == 1, "MaskBlt failed (%d)\n", ret);
134 ok (pulBitsDst[0] == 0x977c5779, "pulBitsDst[0] == 0x%lx\n", pulBitsDst[0]);
135 ok (pulBitsDst[1] == 0xfabefef6, "pulBitsDst[0] == 0x%lx\n", pulBitsDst[1]);
136 }
137
138 START_TEST(MaskBlt)
139 {
140 Test_MaskBlt_1bpp();
141 switch (GetDeviceCaps(GetDC(NULL), BITSPIXEL))
142 {
143 case 16: Test_MaskBlt_16bpp(); break;
144 case 32: Test_MaskBlt_32bpp(); break;
145 }
146
147 }
148