usp10/test: Add Tibetan shaping test.
[wine] / dlls / gdi32 / tests / dib.c
1 /*
2  * DIB driver tests.
3  *
4  * Copyright 2011 Huw Davies
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <math.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "wincrypt.h"
30
31 #include "wine/test.h"
32
33 static HCRYPTPROV crypt_prov;
34 static DWORD (WINAPI *pSetLayout)(HDC hdc, DWORD layout);
35
36 static const DWORD rop3[256] =
37 {
38     0x000042, 0x010289, 0x020C89, 0x0300AA, 0x040C88, 0x0500A9, 0x060865, 0x0702C5,
39     0x080F08, 0x090245, 0x0A0329, 0x0B0B2A, 0x0C0324, 0x0D0B25, 0x0E08A5, 0x0F0001,
40     0x100C85, 0x1100A6, 0x120868, 0x1302C8, 0x140869, 0x1502C9, 0x165CCA, 0x171D54,
41     0x180D59, 0x191CC8, 0x1A06C5, 0x1B0768, 0x1C06CA, 0x1D0766, 0x1E01A5, 0x1F0385,
42     0x200F09, 0x210248, 0x220326, 0x230B24, 0x240D55, 0x251CC5, 0x2606C8, 0x271868,
43     0x280369, 0x2916CA, 0x2A0CC9, 0x2B1D58, 0x2C0784, 0x2D060A, 0x2E064A, 0x2F0E2A,
44     0x30032A, 0x310B28, 0x320688, 0x330008, 0x3406C4, 0x351864, 0x3601A8, 0x370388,
45     0x38078A, 0x390604, 0x3A0644, 0x3B0E24, 0x3C004A, 0x3D18A4, 0x3E1B24, 0x3F00EA,
46     0x400F0A, 0x410249, 0x420D5D, 0x431CC4, 0x440328, 0x450B29, 0x4606C6, 0x47076A,
47     0x480368, 0x4916C5, 0x4A0789, 0x4B0605, 0x4C0CC8, 0x4D1954, 0x4E0645, 0x4F0E25,
48     0x500325, 0x510B26, 0x5206C9, 0x530764, 0x5408A9, 0x550009, 0x5601A9, 0x570389,
49     0x580785, 0x590609, 0x5A0049, 0x5B18A9, 0x5C0649, 0x5D0E29, 0x5E1B29, 0x5F00E9,
50     0x600365, 0x6116C6, 0x620786, 0x630608, 0x640788, 0x650606, 0x660046, 0x6718A8,
51     0x6858A6, 0x690145, 0x6A01E9, 0x6B178A, 0x6C01E8, 0x6D1785, 0x6E1E28, 0x6F0C65,
52     0x700CC5, 0x711D5C, 0x720648, 0x730E28, 0x740646, 0x750E26, 0x761B28, 0x7700E6,
53     0x7801E5, 0x791786, 0x7A1E29, 0x7B0C68, 0x7C1E24, 0x7D0C69, 0x7E0955, 0x7F03C9,
54     0x8003E9, 0x810975, 0x820C49, 0x831E04, 0x840C48, 0x851E05, 0x8617A6, 0x8701C5,
55     0x8800C6, 0x891B08, 0x8A0E06, 0x8B0666, 0x8C0E08, 0x8D0668, 0x8E1D7C, 0x8F0CE5,
56     0x900C45, 0x911E08, 0x9217A9, 0x9301C4, 0x9417AA, 0x9501C9, 0x960169, 0x97588A,
57     0x981888, 0x990066, 0x9A0709, 0x9B07A8, 0x9C0704, 0x9D07A6, 0x9E16E6, 0x9F0345,
58     0xA000C9, 0xA11B05, 0xA20E09, 0xA30669, 0xA41885, 0xA50065, 0xA60706, 0xA707A5,
59     0xA803A9, 0xA90189, 0xAA0029, 0xAB0889, 0xAC0744, 0xAD06E9, 0xAE0B06, 0xAF0229,
60     0xB00E05, 0xB10665, 0xB21974, 0xB30CE8, 0xB4070A, 0xB507A9, 0xB616E9, 0xB70348,
61     0xB8074A, 0xB906E6, 0xBA0B09, 0xBB0226, 0xBC1CE4, 0xBD0D7D, 0xBE0269, 0xBF08C9,
62     0xC000CA, 0xC11B04, 0xC21884, 0xC3006A, 0xC40E04, 0xC50664, 0xC60708, 0xC707AA,
63     0xC803A8, 0xC90184, 0xCA0749, 0xCB06E4, 0xCC0020, 0xCD0888, 0xCE0B08, 0xCF0224,
64     0xD00E0A, 0xD1066A, 0xD20705, 0xD307A4, 0xD41D78, 0xD50CE9, 0xD616EA, 0xD70349,
65     0xD80745, 0xD906E8, 0xDA1CE9, 0xDB0D75, 0xDC0B04, 0xDD0228, 0xDE0268, 0xDF08C8,
66     0xE003A5, 0xE10185, 0xE20746, 0xE306EA, 0xE40748, 0xE506E5, 0xE61CE8, 0xE70D79,
67     0xE81D74, 0xE95CE6, 0xEA02E9, 0xEB0849, 0xEC02E8, 0xED0848, 0xEE0086, 0xEF0A08,
68     0xF00021, 0xF10885, 0xF20B05, 0xF3022A, 0xF40B0A, 0xF50225, 0xF60265, 0xF708C5,
69     0xF802E5, 0xF90845, 0xFA0089, 0xFB0A09, 0xFC008A, 0xFD0A0A, 0xFE02A9, 0xFF0062
70 };
71
72 static inline BOOL rop_uses_src(DWORD rop)
73 {
74     return (((rop & 0xcc0000) >> 2) != (rop & 0x330000));
75 }
76
77 static const char *sha1_graphics_a8r8g8b8[] =
78 {
79     "a3cadd34d95d3d5cc23344f69aab1c2e55935fcf",
80     "2426172d9e8fec27d9228088f382ef3c93717da9",
81     "9e8f27ca952cdba01dbf25d07c34e86a7820c012",
82     "664fac17803859a4015c6ae29e5538e314d5c827",
83     "17b2c177bdce5e94433574a928bda5c94a8cdfa5",
84     "fe6cc678fb13a3ead67839481bf22348adc69f52",
85     "d51bd330cec510cdccf5394328bd8e5411901e9e",
86     "df4aebf98d91f11be560dd232123b3ae327303d7",
87     "f2af53dd073a09b1031d0032d28da35c82adc566",
88     "eb5a963a6f7b25533ddfb8915e70865d037bd156",
89     "c387917268455017aa0b28bed73aa6554044bbb3",
90     "dcae44fee010dbf7a107797a503923fd8b1abe2e",
91     "6c530622a025d872a642e8f950867884d7b136cb",
92     "7c07d91b8f68fb31821701b3dcb96de018bf0c66",
93     "b2261353decda2712b83538ab434a49ce21f3172",
94     "a8b59f25984b066fc6b91cae6bf983a78028ba7f",
95     "3d95adb85b9673a932ac847a4b5451fa59885f74",
96     "e2a8eef4aeda3a0f6c950075acba38f1f9e0814d",
97     "8b66f14d51ecdeea12bc993302bb9b7d3ec085a1",
98     "7da9dd3d40d44d92deb9883fb7110443c2d5769a",
99     NULL
100 };
101
102 static inline DWORD get_stride(BITMAPINFO *bmi)
103 {
104     return ((bmi->bmiHeader.biBitCount * bmi->bmiHeader.biWidth + 31) >> 3) & ~3;
105 }
106
107 static inline DWORD get_dib_size(BITMAPINFO *bmi)
108 {
109     return get_stride(bmi) * abs(bmi->bmiHeader.biHeight);
110 }
111
112 static char *hash_dib(BITMAPINFO *bmi, void *bits)
113 {
114     DWORD dib_size = get_dib_size(bmi);
115     HCRYPTHASH hash;
116     char *buf;
117     BYTE hash_buf[20];
118     DWORD hash_size = sizeof(hash_buf);
119     int i;
120     static const char *hex = "0123456789abcdef";
121
122     if(!crypt_prov) return NULL;
123
124     if(!CryptCreateHash(crypt_prov, CALG_SHA1, 0, 0, &hash)) return NULL;
125
126     CryptHashData(hash, bits, dib_size, 0);
127
128     CryptGetHashParam(hash, HP_HASHVAL, NULL, &hash_size, 0);
129     if(hash_size != sizeof(hash_buf)) return NULL;
130
131     CryptGetHashParam(hash, HP_HASHVAL, hash_buf, &hash_size, 0);
132     CryptDestroyHash(hash);
133
134     buf = HeapAlloc(GetProcessHeap(), 0, hash_size * 2 + 1);
135
136     for(i = 0; i < hash_size; i++)
137     {
138         buf[i * 2] = hex[hash_buf[i] >> 4];
139         buf[i * 2 + 1] = hex[hash_buf[i] & 0xf];
140     }
141     buf[i * 2] = '\0';
142
143     return buf;
144 }
145
146 static void compare_hash(BITMAPINFO *bmi, BYTE *bits, const char ***sha1, const char *info)
147 {
148     char *hash = hash_dib(bmi, bits);
149
150     if(!hash)
151     {
152         skip("SHA1 hashing unavailable on this platform\n");
153         return;
154     }
155
156     if(**sha1)
157     {
158         ok(!strcmp(hash, **sha1), "%d: %s: expected hash %s got %s\n",
159            bmi->bmiHeader.biBitCount, info, **sha1, hash);
160         (*sha1)++;
161     }
162     else ok(**sha1 != NULL, "missing hash, got \"%s\",\n", hash);
163
164     HeapFree(GetProcessHeap(), 0, hash);
165 }
166
167 static const RECT bias_check[] =
168 {
169     {100, 100, 200, 150},
170     {100, 100, 150, 200},
171     {100, 100,  50, 200},
172     {100, 100,   0, 150},
173     {100, 100,   0,  50},
174     {100, 100,  50,   0},
175     {100, 100, 150,   0},
176     {100, 100, 200,  50}
177 };
178
179 static const RECT hline_clips[] =
180 {
181     {120, 120, 140, 120}, /* unclipped */
182     {100, 122, 140, 122}, /* l edgecase */
183     { 99, 124, 140, 124}, /* l edgecase clipped */
184     {120, 126, 200, 126}, /* r edgecase */
185     {120, 128, 201, 128}, /* r edgecase clipped */
186     { 99, 130, 201, 130}, /* l and r clipped */
187     {120, 100, 140, 100}, /* t edgecase */
188     {120,  99, 140,  99}, /* t edgecase clipped */
189     {120, 199, 140, 199}, /* b edgecase */
190     {120, 200, 140, 200}, /* b edgecase clipped */
191     {120, 132, 310, 132}, /* inside two clip rects */
192     { 10, 134, 101, 134}, /* r end on l edgecase */
193     { 10, 136, 100, 136}, /* r end on l edgecase clipped */
194     {199, 138, 220, 138}, /* l end on r edgecase */
195     {200, 140, 220, 140}  /* l end on r edgecase clipped */
196 };
197
198 static const RECT vline_clips[] =
199 {
200     {120, 120, 120, 140}, /* unclipped */
201     {100, 120, 100, 140}, /* l edgecase */
202     { 99, 120,  99, 140}, /* l edgecase clipped */
203     {199, 120, 199, 140}, /* r edgecase */
204     {200, 120, 200, 140}, /* r edgecase clipped */
205     {122,  99, 122, 201}, /* t and b clipped */
206     {124, 100, 124, 140}, /* t edgecase */
207     {126,  99, 126, 140}, /* t edgecase clipped */
208     {128, 120, 128, 200}, /* b edgecase */
209     {130, 120, 130, 201}, /* b edgecase clipped */
210     {132,  12, 132, 140}, /* inside two clip rects */
211     {134,  90, 134, 101}, /* b end on t edgecase */
212     {136,  90, 136, 100}, /* b end on t edgecase clipped */
213     {138, 199, 138, 220}, /* t end on b edgecase */
214     {140, 200, 140, 220}  /* t end on b edgecase clipped */
215 };
216
217 static const RECT line_clips[] =
218 {
219     { 90, 110, 310, 120},
220     { 90, 120, 295, 130},
221     { 90, 190, 110, 240}, /* totally clipped, moving outcodes */
222     { 90, 130, 100, 135}, /* totally clipped, end pt on l edge */
223     { 90, 132, 101, 137}, /* end pt just inside l edge */
224     {200, 140, 210, 141}, /* totally clipped, start pt on r edge */
225     {199, 142, 210, 143}  /* start pt just inside r edge */
226 };
227
228 static const RECT patblt_clips[] =
229 {
230     {120, 120, 140, 126}, /* unclipped */
231     {100, 130, 140, 136}, /* l edgecase */
232     { 99, 140, 140, 146}, /* l edgecase clipped */
233     {180, 130, 200, 136}, /* r edgecase */
234     {180, 140, 201, 146}, /* r edgecase clipped */
235     {120, 100, 130, 110}, /* t edgecase */
236     {140,  99, 150, 110}, /* t edgecase clipped */
237     {120, 180, 130, 200}, /* b edgecase */
238     {140, 180, 150, 201}, /* b edgecase */
239     {199, 150, 210, 156}, /* l edge on r edgecase */
240     {200, 160, 210, 166}, /* l edge on r edgecase clipped */
241     { 90, 150, 101, 156}, /* r edge on l edgecase */
242     { 90, 160, 100, 166}, /* r edge on l edgecase clipped */
243     {160,  90, 166, 101}, /* b edge on t edgecase */
244     {170,  90, 176, 101}, /* b edge on t edgecase clipped */
245     {160, 199, 166, 210}, /* t edge on b edgecase */
246     {170, 200, 176, 210}, /* t edge on b edgecase clipped */
247 };
248
249 static const RECT rectangles[] =
250 {
251     {10,   11, 100, 101},
252     {250, 100, 350,  10},
253     {120,  10, 120,  20}, /* zero width */
254     {120,  10, 130,  10}, /* zero height */
255     {120,  40, 121,  41}, /* 1 x 1 */
256     {130,  50, 132,  52}, /* 2 x 2 */
257     {140,  60, 143,  63}, /* 3 x 3 */
258     {150,  70, 154,  74}, /* 4 x 4 */
259     {120,  20, 121,  30}, /* width == 1 */
260     {130,  20, 132,  30}, /* width == 2 */
261     {140,  20, 143,  30}, /* width == 3 */
262     {200,  20, 210,  21}, /* height == 1 */
263     {200,  30, 210,  32}, /* height == 2 */
264     {200,  40, 210,  43} /* height == 3 */
265 };
266
267 static const BITMAPINFOHEADER dib_brush_header_32 = {sizeof(BITMAPINFOHEADER), 16, -16, 1, 32, BI_RGB, 0, 0, 0, 0, 0};
268
269 static void draw_graphics(HDC hdc, BITMAPINFO *bmi, BYTE *bits, const char ***sha1)
270 {
271     DWORD dib_size = get_dib_size(bmi);
272     HPEN solid_pen, dashed_pen, orig_pen;
273     HBRUSH solid_brush, dib_brush, orig_brush;
274     INT i, y;
275     HRGN hrgn, hrgn2;
276     BYTE dib_brush_buf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD) + 16 * 16 * sizeof(DWORD)]; /* Enough for 16 x 16 at 32 bpp */
277     BITMAPINFO *brush_bi = (BITMAPINFO*)dib_brush_buf;
278     BYTE *brush_bits;
279
280     memset(bits, 0xcc, dib_size);
281     compare_hash(bmi, bits, sha1, "empty");
282
283     solid_pen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0xff));
284     orig_pen = SelectObject(hdc, solid_pen);
285     SetBrushOrgEx(hdc, 0, 0, NULL);
286
287     /* horizontal and vertical lines */
288     for(i = 1; i <= 16; i++)
289     {
290         SetROP2(hdc, i);
291         MoveToEx(hdc, 10, i * 3, NULL);
292         LineTo(hdc, 100, i * 3); /* l -> r */
293         MoveToEx(hdc, 100, 50 + i * 3, NULL);
294         LineTo(hdc, 10, 50 + i * 3); /* r -> l */
295         MoveToEx(hdc, 120 + i * 3, 10, NULL);
296         LineTo(hdc, 120 + i * 3, 100); /* t -> b */
297         MoveToEx(hdc, 170 + i * 3, 100, NULL);
298         LineTo(hdc, 170 + i * 3, 10); /* b -> t */
299     }
300     compare_hash(bmi, bits, sha1, "h and v solid lines");
301     memset(bits, 0xcc, dib_size);
302
303     /* diagonal lines */
304     SetROP2(hdc, R2_COPYPEN);
305     for(i = 0; i < 16; i++)
306     {
307         double s = sin(M_PI * i / 8.0);
308         double c = cos(M_PI * i / 8.0);
309
310         MoveToEx(hdc, 200.5 + 10 * c, 200.5 + 10 * s, NULL);
311         LineTo(hdc, 200.5 + 100 * c, 200.5 + 100 * s);
312     }
313     compare_hash(bmi, bits, sha1, "diagonal solid lines");
314     memset(bits, 0xcc, dib_size);
315
316     for(i = 0; i < sizeof(bias_check) / sizeof(bias_check[0]); i++)
317     {
318         MoveToEx(hdc, bias_check[i].left, bias_check[i].top, NULL);
319         LineTo(hdc, bias_check[i].right, bias_check[i].bottom);
320     }
321     compare_hash(bmi, bits, sha1, "more diagonal solid lines");
322     memset(bits, 0xcc, dib_size);
323
324     /* solid brush PatBlt */
325     solid_brush = CreateSolidBrush(RGB(0x33, 0xaa, 0xff));
326     orig_brush = SelectObject(hdc, solid_brush);
327
328     for(i = 0, y = 10; i < 256; i++)
329     {
330         BOOL ret;
331
332         ret = PatBlt(hdc, 10, y, 100, 10, rop3[i]);
333
334         if(rop_uses_src(rop3[i]))
335             ok(ret == FALSE, "got TRUE for %x\n", rop3[i]);
336         else
337         {
338             ok(ret, "got FALSE for %x\n", rop3[i]);
339             y += 20;
340         }
341
342     }
343     compare_hash(bmi, bits, sha1, "solid patblt");
344     memset(bits, 0xcc, dib_size);
345
346     /* clipped lines */
347     hrgn = CreateRectRgn(10, 10, 200, 20);
348     hrgn2 = CreateRectRgn(100, 100, 200, 200);
349     CombineRgn(hrgn, hrgn, hrgn2, RGN_OR);
350     SetRectRgn(hrgn2, 290, 100, 300, 200);
351     CombineRgn(hrgn, hrgn, hrgn2, RGN_OR);
352     ExtSelectClipRgn(hdc, hrgn, RGN_COPY);
353     DeleteObject(hrgn2);
354
355     for(i = 0; i < sizeof(hline_clips)/sizeof(hline_clips[0]); i++)
356     {
357         MoveToEx(hdc, hline_clips[i].left, hline_clips[i].top, NULL);
358         LineTo(hdc, hline_clips[i].right, hline_clips[i].bottom);
359     }
360     compare_hash(bmi, bits, sha1, "clipped solid hlines");
361     memset(bits, 0xcc, dib_size);
362
363     for(i = 0; i < sizeof(vline_clips)/sizeof(vline_clips[0]); i++)
364     {
365         MoveToEx(hdc, vline_clips[i].left, vline_clips[i].top, NULL);
366         LineTo(hdc, vline_clips[i].right, vline_clips[i].bottom);
367     }
368     compare_hash(bmi, bits, sha1, "clipped solid vlines");
369     memset(bits, 0xcc, dib_size);
370
371     for(i = 0; i < sizeof(line_clips)/sizeof(line_clips[0]); i++)
372     {
373         MoveToEx(hdc, line_clips[i].left, line_clips[i].top, NULL);
374         LineTo(hdc, line_clips[i].right, line_clips[i].bottom);
375     }
376     compare_hash(bmi, bits, sha1, "clipped solid diagonal lines");
377     memset(bits, 0xcc, dib_size);
378
379     /* clipped PatBlt */
380     for(i = 0; i < sizeof(patblt_clips) / sizeof(patblt_clips[0]); i++)
381     {
382         PatBlt(hdc, patblt_clips[i].left, patblt_clips[i].top,
383                patblt_clips[i].right - patblt_clips[i].left,
384                patblt_clips[i].bottom - patblt_clips[i].top, PATCOPY);
385     }
386     compare_hash(bmi, bits, sha1, "clipped patblt");
387     memset(bits, 0xcc, dib_size);
388
389     /* clipped dashed lines */
390     dashed_pen = CreatePen(PS_DASH, 1, RGB(0xff, 0, 0));
391     SelectObject(hdc, dashed_pen);
392     SetBkMode(hdc, TRANSPARENT);
393     SetBkColor(hdc, RGB(0, 0xff, 0));
394
395     for(i = 0; i < sizeof(hline_clips)/sizeof(hline_clips[0]); i++)
396     {
397         MoveToEx(hdc, hline_clips[i].left, hline_clips[i].top, NULL);
398         LineTo(hdc, hline_clips[i].right, hline_clips[i].bottom);
399     }
400     compare_hash(bmi, bits, sha1, "clipped dashed hlines");
401     memset(bits, 0xcc, dib_size);
402
403     for(i = 0; i < sizeof(hline_clips)/sizeof(hline_clips[0]); i++)
404     {
405         MoveToEx(hdc, hline_clips[i].right - 1, hline_clips[i].bottom, NULL);
406         LineTo(hdc, hline_clips[i].left - 1, hline_clips[i].top);
407     }
408     compare_hash(bmi, bits, sha1, "clipped dashed hlines r -> l");
409     memset(bits, 0xcc, dib_size);
410
411     for(i = 0; i < sizeof(vline_clips)/sizeof(vline_clips[0]); i++)
412     {
413         MoveToEx(hdc, vline_clips[i].left, vline_clips[i].top, NULL);
414         LineTo(hdc, vline_clips[i].right, vline_clips[i].bottom);
415     }
416     compare_hash(bmi, bits, sha1, "clipped dashed vlines");
417     memset(bits, 0xcc, dib_size);
418
419     for(i = 0; i < sizeof(vline_clips)/sizeof(vline_clips[0]); i++)
420     {
421         MoveToEx(hdc, vline_clips[i].right, vline_clips[i].bottom - 1, NULL);
422         LineTo(hdc, vline_clips[i].left, vline_clips[i].top - 1);
423     }
424     compare_hash(bmi, bits, sha1, "clipped dashed vlines b -> t");
425     memset(bits, 0xcc, dib_size);
426
427     for(i = 0; i < sizeof(line_clips)/sizeof(line_clips[0]); i++)
428     {
429         MoveToEx(hdc, line_clips[i].left, line_clips[i].top, NULL);
430         LineTo(hdc, line_clips[i].right, line_clips[i].bottom);
431     }
432     compare_hash(bmi, bits, sha1, "clipped dashed diagonal lines");
433     memset(bits, 0xcc, dib_size);
434
435     SetBkMode(hdc, OPAQUE);
436
437     for(i = 0; i < sizeof(line_clips)/sizeof(line_clips[0]); i++)
438     {
439         MoveToEx(hdc, line_clips[i].left, line_clips[i].top, NULL);
440         LineTo(hdc, line_clips[i].right, line_clips[i].bottom);
441     }
442     compare_hash(bmi, bits, sha1, "clipped opaque dashed diagonal lines");
443     memset(bits, 0xcc, dib_size);
444
445     ExtSelectClipRgn(hdc, NULL, RGN_COPY);
446
447     /* DIB pattern brush */
448
449     brush_bi->bmiHeader = dib_brush_header_32;
450     brush_bits = (BYTE*)brush_bi + sizeof(BITMAPINFOHEADER);
451     memset(brush_bits, 0, 16 * 16 * sizeof(DWORD));
452     brush_bits[2] = 0xff;
453     brush_bits[6] = 0xff;
454     brush_bits[65] = 0xff;
455     brush_bits[69] = 0xff;
456
457     dib_brush = CreateDIBPatternBrushPt(brush_bi, DIB_RGB_COLORS);
458
459     SelectObject(hdc, dib_brush);
460     SetBrushOrgEx(hdc, 1, 1, NULL);
461
462     for(i = 0, y = 10; i < 256; i++)
463     {
464         BOOL ret;
465
466         if(!rop_uses_src(rop3[i]))
467         {
468             ret = PatBlt(hdc, 10 + i, y, 100, 20, rop3[i]);
469             ok(ret, "got FALSE for %x\n", rop3[i]);
470             y += 25;
471         }
472     }
473     compare_hash(bmi, bits, sha1, "top-down dib brush patblt");
474     memset(bits, 0xcc, dib_size);
475
476     SelectObject(hdc, orig_brush);
477     DeleteObject(dib_brush);
478
479     /* Bottom-up DIB pattern brush */
480
481     brush_bi->bmiHeader.biHeight = -brush_bi->bmiHeader.biHeight;
482
483     dib_brush = CreateDIBPatternBrushPt(brush_bi, DIB_RGB_COLORS);
484
485     SelectObject(hdc, dib_brush);
486     SetBrushOrgEx(hdc, 100, 100, NULL);
487
488     for(i = 0, y = 10; i < 256; i++)
489     {
490         BOOL ret;
491
492         if(!rop_uses_src(rop3[i]))
493         {
494             ret = PatBlt(hdc, 10 + i, y, 100, 20, rop3[i]);
495             ok(ret, "got FALSE for %x\n", rop3[i]);
496             y += 25;
497         }
498     }
499     compare_hash(bmi, bits, sha1, "bottom-up dib brush patblt");
500     memset(bits, 0xcc, dib_size);
501
502     SetBrushOrgEx(hdc, 0, 0, NULL);
503
504     /* Rectangle */
505
506     SelectObject(hdc, solid_pen);
507     SelectObject(hdc, solid_brush);
508
509     for(i = 0; i < sizeof(rectangles)/sizeof(rectangles[0]); i++)
510     {
511         Rectangle(hdc, rectangles[i].left, rectangles[i].top, rectangles[i].right, rectangles[i].bottom);
512     }
513
514     SelectObject(hdc, dashed_pen);
515     for(i = 0; i < sizeof(rectangles)/sizeof(rectangles[0]); i++)
516     {
517         Rectangle(hdc, rectangles[i].left, rectangles[i].top + 150, rectangles[i].right, rectangles[i].bottom + 150);
518     }
519
520     compare_hash(bmi, bits, sha1, "rectangles");
521     memset(bits, 0xcc, dib_size);
522     SelectObject(hdc, solid_pen);
523
524     /* PaintRgn */
525
526     PaintRgn(hdc, hrgn);
527     compare_hash(bmi, bits, sha1, "PaintRgn");
528     memset(bits, 0xcc, dib_size);
529
530     /* RTL rectangles */
531
532     if( !pSetLayout )
533     {
534         win_skip("Don't have SetLayout\n");
535         (*sha1)++;
536     }
537     else
538     {
539         pSetLayout(hdc, LAYOUT_RTL);
540         PaintRgn(hdc, hrgn);
541         PatBlt(hdc, 10, 250, 10, 10, PATCOPY);
542         Rectangle(hdc, 100, 250, 110, 260);
543         compare_hash(bmi, bits, sha1, "rtl");
544         memset(bits, 0xcc, dib_size);
545
546         pSetLayout(hdc, LAYOUT_LTR);
547     }
548
549     SelectObject(hdc, orig_brush);
550     SelectObject(hdc, orig_pen);
551     DeleteObject(hrgn);
552     DeleteObject(dib_brush);
553     DeleteObject(dashed_pen);
554     DeleteObject(solid_brush);
555     DeleteObject(solid_pen);
556 }
557
558 static void test_simple_graphics(void)
559 {
560     char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
561     BITMAPINFO *bmi = (BITMAPINFO *)bmibuf;
562     DWORD *bit_fields = (DWORD*)(bmibuf + sizeof(BITMAPINFOHEADER));
563     HDC mem_dc;
564     BYTE *bits;
565     HBITMAP dib, orig_bm;
566     const char **sha1;
567     DIBSECTION ds;
568
569     mem_dc = CreateCompatibleDC(NULL);
570
571     /* a8r8g8b8 */
572     trace("8888\n");
573     memset(bmi, 0, sizeof(bmibuf));
574     bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader);
575     bmi->bmiHeader.biHeight = 512;
576     bmi->bmiHeader.biWidth = 512;
577     bmi->bmiHeader.biBitCount = 32;
578     bmi->bmiHeader.biPlanes = 1;
579     bmi->bmiHeader.biCompression = BI_RGB;
580
581     dib = CreateDIBSection(0, bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
582     ok(dib != NULL, "ret NULL\n");
583     ok(GetObjectW( dib, sizeof(ds), &ds ), "GetObject failed\n");
584     ok(ds.dsBitfields[0] == 0, "got %08x\n", ds.dsBitfields[0]);
585     ok(ds.dsBitfields[1] == 0, "got %08x\n", ds.dsBitfields[1]);
586     ok(ds.dsBitfields[2] == 0, "got %08x\n", ds.dsBitfields[2]);
587     ok(ds.dsBmih.biCompression == BI_RGB ||
588        broken(ds.dsBmih.biCompression == BI_BITFIELDS), /* nt4 sp1 and 2 */
589        "got %x\n", ds.dsBmih.biCompression);
590
591     orig_bm = SelectObject(mem_dc, dib);
592
593     sha1 = sha1_graphics_a8r8g8b8;
594     draw_graphics(mem_dc, bmi, bits, &sha1);
595
596     SelectObject(mem_dc, orig_bm);
597     DeleteObject(dib);
598
599     /* a8r8g8b8 - bitfields.  Should be the same as the regular 32 bit case.*/
600     trace("8888 - bitfields\n");
601     bmi->bmiHeader.biBitCount = 32;
602     bmi->bmiHeader.biCompression = BI_BITFIELDS;
603     bit_fields[0] = 0xff0000;
604     bit_fields[1] = 0x00ff00;
605     bit_fields[2] = 0x0000ff;
606
607     dib = CreateDIBSection(mem_dc, bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
608     ok(dib != NULL, "ret NULL\n");
609     ok(GetObjectW( dib, sizeof(ds), &ds ), "GetObject failed\n");
610     ok(ds.dsBitfields[0] == 0xff0000, "got %08x\n", ds.dsBitfields[0]);
611     ok(ds.dsBitfields[1] == 0x00ff00, "got %08x\n", ds.dsBitfields[1]);
612     ok(ds.dsBitfields[2] == 0x0000ff, "got %08x\n", ds.dsBitfields[2]);
613     ok(ds.dsBmih.biCompression == BI_BITFIELDS, "got %x\n", ds.dsBmih.biCompression);
614
615     orig_bm = SelectObject(mem_dc, dib);
616
617     sha1 = sha1_graphics_a8r8g8b8;
618     draw_graphics(mem_dc, bmi, bits, &sha1);
619
620     SelectObject(mem_dc, orig_bm);
621     DeleteObject(dib);
622
623
624     /* r5g5b5 */
625     bmi->bmiHeader.biBitCount = 16;
626     bmi->bmiHeader.biCompression = BI_RGB;
627
628     dib = CreateDIBSection(0, bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
629     ok(dib != NULL, "ret NULL\n");
630     ok(GetObjectW( dib, sizeof(ds), &ds ), "GetObject failed\n");
631     ok(ds.dsBitfields[0] == 0x7c00, "got %08x\n", ds.dsBitfields[0]);
632     ok(ds.dsBitfields[1] == 0x03e0, "got %08x\n", ds.dsBitfields[1]);
633     ok(ds.dsBitfields[2] == 0x001f, "got %08x\n", ds.dsBitfields[2]);
634 todo_wine
635     ok(ds.dsBmih.biCompression == BI_BITFIELDS, "got %x\n", ds.dsBmih.biCompression);
636
637     DeleteObject(dib);
638
639     DeleteDC(mem_dc);
640 }
641
642 START_TEST(dib)
643 {
644     HMODULE mod = GetModuleHandleA("gdi32.dll");
645     pSetLayout = (void *)GetProcAddress( mod, "SetLayout" );
646
647     CryptAcquireContextW(&crypt_prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
648
649     test_simple_graphics();
650
651     CryptReleaseContext(crypt_prov, 0);
652 }