[CMAKE]
[reactos.git] / rostests / winetests / gdiplus / image.c
1 /*
2 * Unit test suite for images
3 *
4 * Copyright (C) 2007 Google (Evan Stade)
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 #define COBJMACROS
22
23 #include <math.h>
24
25 #include "initguid.h"
26 #include "windows.h"
27 #include "gdiplus.h"
28 #include "wine/test.h"
29
30 #define expect(expected, got) ok((UINT)(got) == (UINT)(expected), "Expected %.8x, got %.8x\n", (UINT)(expected), (UINT)(got))
31 #define expectf(expected, got) ok(fabs(expected - got) < 0.0001, "Expected %.2f, got %.2f\n", expected, got)
32
33 static BOOL color_match(ARGB c1, ARGB c2, BYTE max_diff)
34 {
35 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
36 c1 >>= 8; c2 >>= 8;
37 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
38 c1 >>= 8; c2 >>= 8;
39 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
40 c1 >>= 8; c2 >>= 8;
41 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
42 return TRUE;
43 }
44
45 static void expect_guid(REFGUID expected, REFGUID got, int line, BOOL todo)
46 {
47 WCHAR bufferW[39];
48 char buffer[39];
49 char buffer2[39];
50
51 StringFromGUID2(got, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
52 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer, sizeof(buffer), NULL, NULL);
53 StringFromGUID2(expected, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
54 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer2, sizeof(buffer2), NULL, NULL);
55 if(todo)
56 todo_wine ok_(__FILE__, line)(IsEqualGUID(expected, got), "Expected %s, got %s\n", buffer2, buffer);
57 else
58 ok_(__FILE__, line)(IsEqualGUID(expected, got), "Expected %s, got %s\n", buffer2, buffer);
59 }
60
61 static void expect_rawformat(REFGUID expected, GpImage *img, int line, BOOL todo)
62 {
63 GUID raw;
64 GpStatus stat;
65
66 stat = GdipGetImageRawFormat(img, &raw);
67 ok_(__FILE__, line)(stat == Ok, "GdipGetImageRawFormat failed with %d\n", stat);
68 if(stat != Ok) return;
69 expect_guid(expected, &raw, line, todo);
70 }
71
72 static void test_bufferrawformat(void* buff, int size, REFGUID expected, int line, BOOL todo)
73 {
74 LPSTREAM stream;
75 HGLOBAL hglob;
76 LPBYTE data;
77 HRESULT hres;
78 GpStatus stat;
79 GpImage *img;
80
81 hglob = GlobalAlloc (0, size);
82 data = GlobalLock (hglob);
83 memcpy(data, buff, size);
84 GlobalUnlock(hglob); data = NULL;
85
86 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
87 ok_(__FILE__, line)(hres == S_OK, "Failed to create a stream\n");
88 if(hres != S_OK) return;
89
90 stat = GdipLoadImageFromStream(stream, &img);
91 ok_(__FILE__, line)(stat == Ok, "Failed to create a Bitmap\n");
92 if(stat != Ok){
93 IStream_Release(stream);
94 return;
95 }
96
97 expect_rawformat(expected, img, line, todo);
98
99 GdipDisposeImage(img);
100 IStream_Release(stream);
101 }
102
103 static void test_Scan0(void)
104 {
105 GpBitmap *bm;
106 GpStatus stat;
107 BYTE buff[360];
108
109 bm = NULL;
110 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
111 expect(Ok, stat);
112 ok(NULL != bm, "Expected bitmap to be initialized\n");
113 if (stat == Ok)
114 GdipDisposeImage((GpImage*)bm);
115
116 bm = (GpBitmap*)0xdeadbeef;
117 stat = GdipCreateBitmapFromScan0(10, -10, 10, PixelFormat24bppRGB, NULL, &bm);
118 expect(InvalidParameter, stat);
119 ok( !bm, "expected null bitmap\n" );
120
121 bm = (GpBitmap*)0xdeadbeef;
122 stat = GdipCreateBitmapFromScan0(-10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
123 expect(InvalidParameter, stat);
124 ok( !bm, "expected null bitmap\n" );
125
126 bm = (GpBitmap*)0xdeadbeef;
127 stat = GdipCreateBitmapFromScan0(10, 0, 10, PixelFormat24bppRGB, NULL, &bm);
128 expect(InvalidParameter, stat);
129 ok( !bm, "expected null bitmap\n" );
130
131 bm = NULL;
132 stat = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, buff, &bm);
133 expect(Ok, stat);
134 ok(NULL != bm, "Expected bitmap to be initialized\n");
135 if (stat == Ok)
136 GdipDisposeImage((GpImage*)bm);
137
138 bm = (GpBitmap*) 0xdeadbeef;
139 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, buff, &bm);
140 expect(InvalidParameter, stat);
141 ok( !bm, "expected null bitmap\n" );
142
143 bm = (GpBitmap*)0xdeadbeef;
144 stat = GdipCreateBitmapFromScan0(10, 10, 0, PixelFormat24bppRGB, buff, &bm);
145 expect(InvalidParameter, stat);
146 ok( bm == (GpBitmap*)0xdeadbeef, "expected deadbeef bitmap\n" );
147
148 bm = NULL;
149 stat = GdipCreateBitmapFromScan0(10, 10, -8, PixelFormat24bppRGB, buff, &bm);
150 expect(Ok, stat);
151 ok(NULL != bm, "Expected bitmap to be initialized\n");
152 if (stat == Ok)
153 GdipDisposeImage((GpImage*)bm);
154
155 bm = (GpBitmap*)0xdeadbeef;
156 stat = GdipCreateBitmapFromScan0(10, 10, -10, PixelFormat24bppRGB, buff, &bm);
157 expect(InvalidParameter, stat);
158 ok( !bm, "expected null bitmap\n" );
159 }
160
161 static void test_FromGdiDib(void)
162 {
163 GpBitmap *bm;
164 GpStatus stat;
165 BYTE buff[400];
166 BYTE rbmi[sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)];
167 BITMAPINFO *bmi = (BITMAPINFO*)rbmi;
168 PixelFormat format;
169
170 bm = NULL;
171
172 memset(rbmi, 0, sizeof(rbmi));
173
174 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
175 bmi->bmiHeader.biWidth = 10;
176 bmi->bmiHeader.biHeight = 10;
177 bmi->bmiHeader.biPlanes = 1;
178 bmi->bmiHeader.biBitCount = 32;
179 bmi->bmiHeader.biCompression = BI_RGB;
180
181 stat = GdipCreateBitmapFromGdiDib(NULL, buff, &bm);
182 expect(InvalidParameter, stat);
183
184 stat = GdipCreateBitmapFromGdiDib(bmi, NULL, &bm);
185 expect(InvalidParameter, stat);
186
187 stat = GdipCreateBitmapFromGdiDib(bmi, buff, NULL);
188 expect(InvalidParameter, stat);
189
190 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
191 expect(Ok, stat);
192 ok(NULL != bm, "Expected bitmap to be initialized\n");
193 if (stat == Ok)
194 {
195 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
196 expect(Ok, stat);
197 expect(PixelFormat32bppRGB, format);
198
199 GdipDisposeImage((GpImage*)bm);
200 }
201
202 bmi->bmiHeader.biBitCount = 24;
203 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
204 expect(Ok, stat);
205 ok(NULL != bm, "Expected bitmap to be initialized\n");
206 if (stat == Ok)
207 {
208 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
209 expect(Ok, stat);
210 expect(PixelFormat24bppRGB, format);
211
212 GdipDisposeImage((GpImage*)bm);
213 }
214
215 bmi->bmiHeader.biBitCount = 16;
216 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
217 expect(Ok, stat);
218 ok(NULL != bm, "Expected bitmap to be initialized\n");
219 if (stat == Ok)
220 {
221 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
222 expect(Ok, stat);
223 expect(PixelFormat16bppRGB555, format);
224
225 GdipDisposeImage((GpImage*)bm);
226 }
227
228 bmi->bmiHeader.biBitCount = 8;
229 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
230 expect(Ok, stat);
231 ok(NULL != bm, "Expected bitmap to be initialized\n");
232 if (stat == Ok)
233 {
234 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
235 expect(Ok, stat);
236 expect(PixelFormat8bppIndexed, format);
237
238 GdipDisposeImage((GpImage*)bm);
239 }
240
241 bmi->bmiHeader.biBitCount = 4;
242 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
243 expect(Ok, stat);
244 ok(NULL != bm, "Expected bitmap to be initialized\n");
245 if (stat == Ok)
246 {
247 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
248 expect(Ok, stat);
249 expect(PixelFormat4bppIndexed, format);
250
251 GdipDisposeImage((GpImage*)bm);
252 }
253
254 bmi->bmiHeader.biBitCount = 1;
255 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
256 expect(Ok, stat);
257 ok(NULL != bm, "Expected bitmap to be initialized\n");
258 if (stat == Ok)
259 {
260 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
261 expect(Ok, stat);
262 expect(PixelFormat1bppIndexed, format);
263
264 GdipDisposeImage((GpImage*)bm);
265 }
266
267 bmi->bmiHeader.biBitCount = 0;
268 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
269 expect(InvalidParameter, stat);
270 }
271
272 static void test_GetImageDimension(void)
273 {
274 GpBitmap *bm;
275 GpStatus stat;
276 const REAL WIDTH = 10.0, HEIGHT = 20.0;
277 REAL w,h;
278
279 bm = (GpBitmap*)0xdeadbeef;
280 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
281 expect(Ok,stat);
282 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
283 ok(NULL != bm, "Expected bitmap to not be NULL\n");
284
285 stat = GdipGetImageDimension(NULL,&w,&h);
286 expect(InvalidParameter, stat);
287
288 stat = GdipGetImageDimension((GpImage*)bm,NULL,&h);
289 expect(InvalidParameter, stat);
290
291 stat = GdipGetImageDimension((GpImage*)bm,&w,NULL);
292 expect(InvalidParameter, stat);
293
294 w = -1;
295 h = -1;
296 stat = GdipGetImageDimension((GpImage*)bm,&w,&h);
297 expect(Ok, stat);
298 expectf(WIDTH, w);
299 expectf(HEIGHT, h);
300 GdipDisposeImage((GpImage*)bm);
301 }
302
303 static void test_GdipImageGetFrameDimensionsCount(void)
304 {
305 GpBitmap *bm;
306 GpStatus stat;
307 const REAL WIDTH = 10.0, HEIGHT = 20.0;
308 UINT w;
309 GUID dimension = {0};
310 UINT count;
311 ARGB color;
312
313 bm = (GpBitmap*)0xdeadbeef;
314 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
315 expect(Ok,stat);
316 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
317 ok(NULL != bm, "Expected bitmap to not be NULL\n");
318
319 stat = GdipImageGetFrameDimensionsCount(NULL,&w);
320 expect(InvalidParameter, stat);
321
322 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,NULL);
323 expect(InvalidParameter, stat);
324
325 w = -1;
326 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,&w);
327 expect(Ok, stat);
328 expect(1, w);
329
330 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 1);
331 expect(Ok, stat);
332 expect_guid(&FrameDimensionPage, &dimension, __LINE__, FALSE);
333
334 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 2);
335 expect(InvalidParameter, stat);
336
337 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 0);
338 expect(InvalidParameter, stat);
339
340 stat = GdipImageGetFrameCount(NULL, &dimension, &count);
341 expect(InvalidParameter, stat);
342
343 /* WinXP crashes on this test */
344 if(0)
345 {
346 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, NULL);
347 expect(InvalidParameter, stat);
348 }
349
350 stat = GdipImageGetFrameCount((GpImage*)bm, NULL, &count);
351 expect(Ok, stat);
352
353 count = 12345;
354 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, &count);
355 expect(Ok, stat);
356 expect(1, count);
357
358 GdipBitmapSetPixel(bm, 0, 0, 0xffffffff);
359
360 stat = GdipImageSelectActiveFrame((GpImage*)bm, &dimension, 0);
361 expect(Ok, stat);
362
363 /* SelectActiveFrame has no effect on image data of memory bitmaps */
364 color = 0xdeadbeef;
365 GdipBitmapGetPixel(bm, 0, 0, &color);
366 expect(0xffffffff, color);
367
368 GdipDisposeImage((GpImage*)bm);
369 }
370
371 static void test_LoadingImages(void)
372 {
373 GpStatus stat;
374
375 stat = GdipCreateBitmapFromFile(0, 0);
376 expect(InvalidParameter, stat);
377
378 stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
379 expect(InvalidParameter, stat);
380
381 stat = GdipLoadImageFromFile(0, 0);
382 expect(InvalidParameter, stat);
383
384 stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
385 expect(InvalidParameter, stat);
386
387 stat = GdipLoadImageFromFileICM(0, 0);
388 expect(InvalidParameter, stat);
389
390 stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
391 expect(InvalidParameter, stat);
392 }
393
394 static void test_SavingImages(void)
395 {
396 GpStatus stat;
397 GpBitmap *bm;
398 UINT n;
399 UINT s;
400 const REAL WIDTH = 10.0, HEIGHT = 20.0;
401 REAL w, h;
402 ImageCodecInfo *codecs;
403 static const CHAR filenameA[] = "a.bmp";
404 static const WCHAR filename[] = { 'a','.','b','m','p',0 };
405
406 codecs = NULL;
407
408 stat = GdipSaveImageToFile(0, 0, 0, 0);
409 expect(InvalidParameter, stat);
410
411 bm = NULL;
412 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
413 expect(Ok, stat);
414 if (!bm)
415 return;
416
417 /* invalid params */
418 stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
419 expect(InvalidParameter, stat);
420
421 stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
422 expect(InvalidParameter, stat);
423
424 /* encoder tests should succeed -- already tested */
425 stat = GdipGetImageEncodersSize(&n, &s);
426 if (stat != Ok || n == 0) goto cleanup;
427
428 codecs = GdipAlloc(s);
429 if (!codecs) goto cleanup;
430
431 stat = GdipGetImageEncoders(n, s, codecs);
432 if (stat != Ok) goto cleanup;
433
434 stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
435 expect(stat, Ok);
436
437 GdipDisposeImage((GpImage*)bm);
438 bm = 0;
439
440 /* re-load and check image stats */
441 stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
442 expect(stat, Ok);
443 if (stat != Ok) goto cleanup;
444
445 stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
446 if (stat != Ok) goto cleanup;
447
448 expectf(WIDTH, w);
449 expectf(HEIGHT, h);
450
451 cleanup:
452 GdipFree(codecs);
453 if (bm)
454 GdipDisposeImage((GpImage*)bm);
455 ok(DeleteFileA(filenameA), "Delete failed.\n");
456 }
457
458 static void test_encoders(void)
459 {
460 GpStatus stat;
461 UINT n;
462 UINT s;
463 ImageCodecInfo *codecs;
464 int i;
465 int bmp_found;
466
467 static const CHAR bmp_format[] = "BMP";
468
469 stat = GdipGetImageEncodersSize(&n, &s);
470 expect(stat, Ok);
471
472 codecs = GdipAlloc(s);
473 if (!codecs)
474 return;
475
476 stat = GdipGetImageEncoders(n, s, NULL);
477 expect(GenericError, stat);
478
479 stat = GdipGetImageEncoders(0, s, codecs);
480 expect(GenericError, stat);
481
482 stat = GdipGetImageEncoders(n, s-1, codecs);
483 expect(GenericError, stat);
484
485 stat = GdipGetImageEncoders(n, s+1, codecs);
486 expect(GenericError, stat);
487
488 stat = GdipGetImageEncoders(n, s, codecs);
489 expect(stat, Ok);
490
491 bmp_found = FALSE;
492 for (i = 0; i < n; i++)
493 {
494 CHAR desc[32];
495
496 WideCharToMultiByte(CP_ACP, 0, codecs[i].FormatDescription, -1,
497 desc, 32, 0, 0);
498
499 if (CompareStringA(LOCALE_SYSTEM_DEFAULT, 0,
500 desc, -1,
501 bmp_format, -1) == CSTR_EQUAL) {
502 bmp_found = TRUE;
503 break;
504 }
505 }
506 if (!bmp_found)
507 ok(FALSE, "No BMP codec found.\n");
508
509 GdipFree(codecs);
510 }
511
512 static void test_LockBits(void)
513 {
514 GpStatus stat;
515 GpBitmap *bm;
516 GpRect rect;
517 BitmapData bd;
518 const INT WIDTH = 10, HEIGHT = 20;
519
520 bm = NULL;
521 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
522 expect(Ok, stat);
523
524 rect.X = 2;
525 rect.Y = 3;
526 rect.Width = 4;
527 rect.Height = 5;
528
529 /* read-only */
530 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
531 expect(Ok, stat);
532
533 if (stat == Ok) {
534 stat = GdipBitmapUnlockBits(bm, &bd);
535 expect(Ok, stat);
536 }
537
538 /* read-only, with NULL rect -> whole bitmap lock */
539 stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
540 expect(Ok, stat);
541 expect(bd.Width, WIDTH);
542 expect(bd.Height, HEIGHT);
543
544 if (stat == Ok) {
545 stat = GdipBitmapUnlockBits(bm, &bd);
546 expect(Ok, stat);
547 }
548
549 /* read-only, consecutive */
550 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
551 expect(Ok, stat);
552
553 if (stat == Ok) {
554 stat = GdipBitmapUnlockBits(bm, &bd);
555 expect(Ok, stat);
556 }
557
558 stat = GdipDisposeImage((GpImage*)bm);
559 expect(Ok, stat);
560 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
561 expect(Ok, stat);
562
563 /* read x2 */
564 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
565 expect(Ok, stat);
566 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
567 expect(WrongState, stat);
568
569 stat = GdipBitmapUnlockBits(bm, &bd);
570 expect(Ok, stat);
571
572 stat = GdipDisposeImage((GpImage*)bm);
573 expect(Ok, stat);
574 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
575 expect(Ok, stat);
576
577 /* write, no modification */
578 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
579 expect(Ok, stat);
580
581 if (stat == Ok) {
582 stat = GdipBitmapUnlockBits(bm, &bd);
583 expect(Ok, stat);
584 }
585
586 /* write, consecutive */
587 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
588 expect(Ok, stat);
589
590 if (stat == Ok) {
591 stat = GdipBitmapUnlockBits(bm, &bd);
592 expect(Ok, stat);
593 }
594
595 stat = GdipDisposeImage((GpImage*)bm);
596 expect(Ok, stat);
597 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
598 expect(Ok, stat);
599
600 /* write, modify */
601 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
602 expect(Ok, stat);
603
604 if (stat == Ok) {
605 if (bd.Scan0)
606 ((char*)bd.Scan0)[2] = 0xff;
607
608 stat = GdipBitmapUnlockBits(bm, &bd);
609 expect(Ok, stat);
610 }
611
612 stat = GdipDisposeImage((GpImage*)bm);
613 expect(Ok, stat);
614
615 /* dispose locked */
616 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
617 expect(Ok, stat);
618 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
619 expect(Ok, stat);
620 stat = GdipDisposeImage((GpImage*)bm);
621 expect(Ok, stat);
622 }
623
624 static void test_GdipCreateBitmapFromHBITMAP(void)
625 {
626 GpBitmap* gpbm = NULL;
627 HBITMAP hbm = NULL;
628 HPALETTE hpal = NULL;
629 GpStatus stat;
630 BYTE buff[1000];
631 LOGPALETTE* LogPal = NULL;
632 REAL width, height;
633 const REAL WIDTH1 = 5;
634 const REAL HEIGHT1 = 15;
635 const REAL WIDTH2 = 10;
636 const REAL HEIGHT2 = 20;
637 HDC hdc;
638 BITMAPINFO bmi;
639 BYTE *bits;
640
641 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
642 expect(InvalidParameter, stat);
643
644 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
645 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
646 expect(InvalidParameter, stat);
647
648 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
649 expect(Ok, stat);
650 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
651 expectf(WIDTH1, width);
652 expectf(HEIGHT1, height);
653 if (stat == Ok)
654 GdipDisposeImage((GpImage*)gpbm);
655 DeleteObject(hbm);
656
657 memset(buff, 0, sizeof(buff));
658 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
659 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
660 expect(Ok, stat);
661 /* raw format */
662 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
663
664 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
665 expectf(WIDTH2, width);
666 expectf(HEIGHT2, height);
667 if (stat == Ok)
668 GdipDisposeImage((GpImage*)gpbm);
669 DeleteObject(hbm);
670
671 hdc = CreateCompatibleDC(0);
672 ok(hdc != NULL, "CreateCompatibleDC failed\n");
673 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
674 bmi.bmiHeader.biHeight = HEIGHT1;
675 bmi.bmiHeader.biWidth = WIDTH1;
676 bmi.bmiHeader.biBitCount = 24;
677 bmi.bmiHeader.biPlanes = 1;
678 bmi.bmiHeader.biCompression = BI_RGB;
679
680 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
681 ok(hbm != NULL, "CreateDIBSection failed\n");
682
683 bits[0] = 0;
684
685 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
686 expect(Ok, stat);
687 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
688 expectf(WIDTH1, width);
689 expectf(HEIGHT1, height);
690 if (stat == Ok)
691 {
692 /* test whether writing to the bitmap affects the original */
693 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
694 expect(Ok, stat);
695
696 expect(0, bits[0]);
697
698 GdipDisposeImage((GpImage*)gpbm);
699 }
700
701 LogPal = GdipAlloc(sizeof(LOGPALETTE));
702 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
703 LogPal->palVersion = 0x300;
704 LogPal->palNumEntries = 1;
705 hpal = CreatePalette(LogPal);
706 ok(hpal != NULL, "CreatePalette failed\n");
707 GdipFree(LogPal);
708
709 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
710 todo_wine
711 {
712 expect(Ok, stat);
713 }
714 if (stat == Ok)
715 GdipDisposeImage((GpImage*)gpbm);
716
717 DeleteObject(hpal);
718 DeleteObject(hbm);
719 }
720
721 static void test_GdipGetImageFlags(void)
722 {
723 GpImage *img;
724 GpStatus stat;
725 UINT flags;
726
727 img = (GpImage*)0xdeadbeef;
728
729 stat = GdipGetImageFlags(NULL, NULL);
730 expect(InvalidParameter, stat);
731
732 stat = GdipGetImageFlags(NULL, &flags);
733 expect(InvalidParameter, stat);
734
735 stat = GdipGetImageFlags(img, NULL);
736 expect(InvalidParameter, stat);
737 }
738
739 static void test_GdipCloneImage(void)
740 {
741 GpStatus stat;
742 GpRectF rectF;
743 GpUnit unit;
744 GpBitmap *bm;
745 GpImage *image_src, *image_dest = NULL;
746 const INT WIDTH = 10, HEIGHT = 20;
747
748 /* Create an image, clone it, delete the original, make sure the copy works */
749 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
750 expect(Ok, stat);
751 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
752
753 image_src = ((GpImage*)bm);
754 stat = GdipCloneImage(image_src, &image_dest);
755 expect(Ok, stat);
756 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
757
758 stat = GdipDisposeImage((GpImage*)bm);
759 expect(Ok, stat);
760 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
761 expect(Ok, stat);
762
763 /* Treat FP values carefully */
764 expectf((REAL)WIDTH, rectF.Width);
765 expectf((REAL)HEIGHT, rectF.Height);
766
767 stat = GdipDisposeImage(image_dest);
768 expect(Ok, stat);
769 }
770
771 static void test_testcontrol(void)
772 {
773 GpStatus stat;
774 DWORD param;
775
776 param = 0;
777 stat = GdipTestControl(TestControlGetBuildNumber, &param);
778 expect(Ok, stat);
779 ok(param != 0, "Build number expected, got %u\n", param);
780 }
781
782 static void test_fromhicon(void)
783 {
784 static const BYTE bmp_bits[1024];
785 HBITMAP hbmMask, hbmColor;
786 ICONINFO info;
787 HICON hIcon;
788 GpStatus stat;
789 GpBitmap *bitmap = NULL;
790 UINT dim;
791 ImageType type;
792 PixelFormat format;
793
794 /* NULL */
795 stat = GdipCreateBitmapFromHICON(NULL, NULL);
796 expect(InvalidParameter, stat);
797 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
798 expect(InvalidParameter, stat);
799
800 /* color icon 1 bit */
801 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
802 ok(hbmMask != 0, "CreateBitmap failed\n");
803 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
804 ok(hbmColor != 0, "CreateBitmap failed\n");
805 info.fIcon = TRUE;
806 info.xHotspot = 8;
807 info.yHotspot = 8;
808 info.hbmMask = hbmMask;
809 info.hbmColor = hbmColor;
810 hIcon = CreateIconIndirect(&info);
811 ok(hIcon != 0, "CreateIconIndirect failed\n");
812 DeleteObject(hbmMask);
813 DeleteObject(hbmColor);
814
815 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
816 ok(stat == Ok ||
817 broken(stat == InvalidParameter), /* Win98 */
818 "Expected Ok, got %.8x\n", stat);
819 if(stat == Ok){
820 /* check attributes */
821 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
822 expect(Ok, stat);
823 expect(16, dim);
824 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
825 expect(Ok, stat);
826 expect(16, dim);
827 stat = GdipGetImageType((GpImage*)bitmap, &type);
828 expect(Ok, stat);
829 expect(ImageTypeBitmap, type);
830 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
831 expect(PixelFormat32bppARGB, format);
832 /* raw format */
833 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
834 GdipDisposeImage((GpImage*)bitmap);
835 }
836 DestroyIcon(hIcon);
837
838 /* color icon 8 bpp */
839 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
840 ok(hbmMask != 0, "CreateBitmap failed\n");
841 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
842 ok(hbmColor != 0, "CreateBitmap failed\n");
843 info.fIcon = TRUE;
844 info.xHotspot = 8;
845 info.yHotspot = 8;
846 info.hbmMask = hbmMask;
847 info.hbmColor = hbmColor;
848 hIcon = CreateIconIndirect(&info);
849 ok(hIcon != 0, "CreateIconIndirect failed\n");
850 DeleteObject(hbmMask);
851 DeleteObject(hbmColor);
852
853 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
854 expect(Ok, stat);
855 if(stat == Ok){
856 /* check attributes */
857 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
858 expect(Ok, stat);
859 expect(16, dim);
860 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
861 expect(Ok, stat);
862 expect(16, dim);
863 stat = GdipGetImageType((GpImage*)bitmap, &type);
864 expect(Ok, stat);
865 expect(ImageTypeBitmap, type);
866 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
867 expect(PixelFormat32bppARGB, format);
868 /* raw format */
869 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
870 GdipDisposeImage((GpImage*)bitmap);
871 }
872 DestroyIcon(hIcon);
873 }
874
875 /* 1x1 pixel png */
876 static const unsigned char pngimage[285] = {
877 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
878 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
879 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
880 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
881 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
882 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
883 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
884 };
885 /* 1x1 pixel gif */
886 static const unsigned char gifimage[35] = {
887 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
888 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
889 0x01,0x00,0x3b
890 };
891 /* 1x1 pixel bmp */
892 static const unsigned char bmpimage[66] = {
893 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
894 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
895 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
896 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
897 0x00,0x00
898 };
899 /* 1x1 pixel jpg */
900 static const unsigned char jpgimage[285] = {
901 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
902 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
903 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
904 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
905 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
906 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
907 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
908 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
909 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
910 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
911 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
912 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
913 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
914 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
915 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
916 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
917 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
918 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
919 };
920 /* 1x1 pixel tiff */
921 static const unsigned char tiffimage[] = {
922 0x49,0x49,0x2a,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xfe,0x00,
923 0x04,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x00,0x01,0x00,
924 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
925 0x00,0x00,0x02,0x01,0x03,0x00,0x03,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0x03,0x01,
926 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,0x01,0x03,0x00,0x01,0x00,
927 0x00,0x00,0x02,0x00,0x00,0x00,0x0d,0x01,0x02,0x00,0x1b,0x00,0x00,0x00,0xd8,0x00,
928 0x00,0x00,0x11,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x12,0x01,
929 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x01,0x03,0x00,0x01,0x00,
930 0x00,0x00,0x03,0x00,0x00,0x00,0x16,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x40,0x00,
931 0x00,0x00,0x17,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1a,0x01,
932 0x05,0x00,0x01,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x1b,0x01,0x05,0x00,0x01,0x00,
933 0x00,0x00,0xfc,0x00,0x00,0x00,0x1c,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
934 0x00,0x00,0x28,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
935 0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x6d,0x65,
936 0x68,0x2f,0x44,0x65,0x73,0x6b,0x74,0x6f,0x70,0x2f,0x74,0x65,0x73,0x74,0x2e,0x74,
937 0x69,0x66,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,
938 0x00,0x00,0x00,0x01
939 };
940 /* 320x320 twip wmf */
941 static const unsigned char wmfimage[180] = {
942 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
943 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
944 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
945 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
946 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
947 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
948 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
949 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
950 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
951 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
952 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
953 0x00,0x00,0x00,0x00
954 };
955 static void test_getrawformat(void)
956 {
957 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
958 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
959 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
960 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
961 test_bufferrawformat((void*)tiffimage, sizeof(tiffimage), &ImageFormatTIFF, __LINE__, FALSE);
962 test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
963 }
964
965 static void test_loadwmf(void)
966 {
967 LPSTREAM stream;
968 HGLOBAL hglob;
969 LPBYTE data;
970 HRESULT hres;
971 GpStatus stat;
972 GpImage *img;
973 GpRectF bounds;
974 GpUnit unit;
975 REAL res = 12345.0;
976 MetafileHeader header;
977
978 hglob = GlobalAlloc (0, sizeof(wmfimage));
979 data = GlobalLock (hglob);
980 memcpy(data, wmfimage, sizeof(wmfimage));
981 GlobalUnlock(hglob); data = NULL;
982
983 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
984 ok(hres == S_OK, "Failed to create a stream\n");
985 if(hres != S_OK) return;
986
987 stat = GdipLoadImageFromStream(stream, &img);
988 ok(stat == Ok, "Failed to create a Bitmap\n");
989 if(stat != Ok){
990 IStream_Release(stream);
991 return;
992 }
993
994 IStream_Release(stream);
995
996 stat = GdipGetImageBounds(img, &bounds, &unit);
997 expect(Ok, stat);
998 todo_wine expect(UnitPixel, unit);
999 expectf(0.0, bounds.X);
1000 expectf(0.0, bounds.Y);
1001 todo_wine expectf(320.0, bounds.Width);
1002 todo_wine expectf(320.0, bounds.Height);
1003
1004 stat = GdipGetImageHorizontalResolution(img, &res);
1005 expect(Ok, stat);
1006 todo_wine expectf(1440.0, res);
1007
1008 stat = GdipGetImageVerticalResolution(img, &res);
1009 expect(Ok, stat);
1010 todo_wine expectf(1440.0, res);
1011
1012 memset(&header, 0, sizeof(header));
1013 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1014 expect(Ok, stat);
1015 if (stat == Ok)
1016 {
1017 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1018 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1019 todo_wine expect(0x300, header.Version);
1020 expect(0, header.EmfPlusFlags);
1021 todo_wine expectf(1440.0, header.DpiX);
1022 todo_wine expectf(1440.0, header.DpiY);
1023 expect(0, header.X);
1024 expect(0, header.Y);
1025 todo_wine expect(320, header.Width);
1026 todo_wine expect(320, header.Height);
1027 todo_wine expect(1, U(header).WmfHeader.mtType);
1028 expect(0, header.EmfPlusHeaderSize);
1029 expect(0, header.LogicalDpiX);
1030 expect(0, header.LogicalDpiY);
1031 }
1032
1033 GdipDisposeImage(img);
1034 }
1035
1036 static void test_createfromwmf(void)
1037 {
1038 HMETAFILE hwmf;
1039 GpImage *img;
1040 GpStatus stat;
1041 GpRectF bounds;
1042 GpUnit unit;
1043 REAL res = 12345.0;
1044 MetafileHeader header;
1045
1046 hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
1047 wmfimage+sizeof(WmfPlaceableFileHeader));
1048 ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
1049
1050 stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
1051 (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
1052 expect(Ok, stat);
1053
1054 stat = GdipGetImageBounds(img, &bounds, &unit);
1055 expect(Ok, stat);
1056 expect(UnitPixel, unit);
1057 expectf(0.0, bounds.X);
1058 expectf(0.0, bounds.Y);
1059 expectf(320.0, bounds.Width);
1060 expectf(320.0, bounds.Height);
1061
1062 stat = GdipGetImageHorizontalResolution(img, &res);
1063 expect(Ok, stat);
1064 expectf(1440.0, res);
1065
1066 stat = GdipGetImageVerticalResolution(img, &res);
1067 expect(Ok, stat);
1068 expectf(1440.0, res);
1069
1070 memset(&header, 0, sizeof(header));
1071 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1072 expect(Ok, stat);
1073 if (stat == Ok)
1074 {
1075 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1076 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1077 todo_wine expect(0x300, header.Version);
1078 expect(0, header.EmfPlusFlags);
1079 todo_wine expectf(1440.0, header.DpiX);
1080 todo_wine expectf(1440.0, header.DpiY);
1081 expect(0, header.X);
1082 expect(0, header.Y);
1083 todo_wine expect(320, header.Width);
1084 todo_wine expect(320, header.Height);
1085 todo_wine expect(1, U(header).WmfHeader.mtType);
1086 expect(0, header.EmfPlusHeaderSize);
1087 expect(0, header.LogicalDpiX);
1088 expect(0, header.LogicalDpiY);
1089 }
1090
1091 GdipDisposeImage(img);
1092 }
1093
1094 static void test_resolution(void)
1095 {
1096 GpStatus stat;
1097 GpBitmap *bitmap;
1098 REAL res=-1.0;
1099 HDC screendc;
1100 int screenxres, screenyres;
1101
1102 /* create Bitmap */
1103 stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
1104 expect(Ok, stat);
1105
1106 /* test invalid values */
1107 stat = GdipGetImageHorizontalResolution(NULL, &res);
1108 expect(InvalidParameter, stat);
1109
1110 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
1111 expect(InvalidParameter, stat);
1112
1113 stat = GdipGetImageVerticalResolution(NULL, &res);
1114 expect(InvalidParameter, stat);
1115
1116 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
1117 expect(InvalidParameter, stat);
1118
1119 stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
1120 expect(InvalidParameter, stat);
1121
1122 stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
1123 expect(InvalidParameter, stat);
1124
1125 /* defaults to screen resolution */
1126 screendc = GetDC(0);
1127
1128 screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
1129 screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
1130
1131 ReleaseDC(0, screendc);
1132
1133 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1134 expect(Ok, stat);
1135 expectf((REAL)screenxres, res);
1136
1137 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1138 expect(Ok, stat);
1139 expectf((REAL)screenyres, res);
1140
1141 /* test changing the resolution */
1142 stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
1143 expect(Ok, stat);
1144
1145 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1146 expect(Ok, stat);
1147 expectf(screenxres*2.0, res);
1148
1149 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1150 expect(Ok, stat);
1151 expectf(screenyres*3.0, res);
1152
1153 stat = GdipDisposeImage((GpImage*)bitmap);
1154 expect(Ok, stat);
1155 }
1156
1157 static void test_createhbitmap(void)
1158 {
1159 GpStatus stat;
1160 GpBitmap *bitmap;
1161 HBITMAP hbitmap, oldhbitmap;
1162 BITMAP bm;
1163 int ret;
1164 HDC hdc;
1165 COLORREF pixel;
1166 BYTE bits[640];
1167
1168 memset(bits, 0x68, 640);
1169
1170 /* create Bitmap */
1171 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
1172 expect(Ok, stat);
1173
1174 /* test NULL values */
1175 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
1176 expect(InvalidParameter, stat);
1177
1178 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
1179 expect(InvalidParameter, stat);
1180
1181 /* create HBITMAP */
1182 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
1183 expect(Ok, stat);
1184
1185 if (stat == Ok)
1186 {
1187 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
1188 expect(sizeof(BITMAP), ret);
1189
1190 expect(0, bm.bmType);
1191 expect(10, bm.bmWidth);
1192 expect(20, bm.bmHeight);
1193 expect(40, bm.bmWidthBytes);
1194 expect(1, bm.bmPlanes);
1195 expect(32, bm.bmBitsPixel);
1196 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1197
1198 hdc = CreateCompatibleDC(NULL);
1199
1200 oldhbitmap = SelectObject(hdc, hbitmap);
1201 pixel = GetPixel(hdc, 5, 5);
1202 SelectObject(hdc, oldhbitmap);
1203
1204 DeleteDC(hdc);
1205
1206 expect(0x686868, pixel);
1207
1208 DeleteObject(hbitmap);
1209 }
1210
1211 stat = GdipDisposeImage((GpImage*)bitmap);
1212 expect(Ok, stat);
1213 }
1214
1215 static void test_getthumbnail(void)
1216 {
1217 GpStatus stat;
1218 GpImage *bitmap1, *bitmap2;
1219 UINT width, height;
1220
1221 stat = GdipGetImageThumbnail(NULL, 0, 0, &bitmap2, NULL, NULL);
1222 expect(InvalidParameter, stat);
1223
1224 stat = GdipCreateBitmapFromScan0(128, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1225 expect(Ok, stat);
1226
1227 stat = GdipGetImageThumbnail(bitmap1, 0, 0, NULL, NULL, NULL);
1228 expect(InvalidParameter, stat);
1229
1230 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1231 expect(Ok, stat);
1232
1233 if (stat == Ok)
1234 {
1235 stat = GdipGetImageWidth(bitmap2, &width);
1236 expect(Ok, stat);
1237 expect(120, width);
1238
1239 stat = GdipGetImageHeight(bitmap2, &height);
1240 expect(Ok, stat);
1241 expect(120, height);
1242
1243 GdipDisposeImage(bitmap2);
1244 }
1245
1246 GdipDisposeImage(bitmap1);
1247
1248
1249 stat = GdipCreateBitmapFromScan0(64, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1250 expect(Ok, stat);
1251
1252 stat = GdipGetImageThumbnail(bitmap1, 32, 32, &bitmap2, NULL, NULL);
1253 expect(Ok, stat);
1254
1255 if (stat == Ok)
1256 {
1257 stat = GdipGetImageWidth(bitmap2, &width);
1258 expect(Ok, stat);
1259 expect(32, width);
1260
1261 stat = GdipGetImageHeight(bitmap2, &height);
1262 expect(Ok, stat);
1263 expect(32, height);
1264
1265 GdipDisposeImage(bitmap2);
1266 }
1267
1268 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1269 expect(Ok, stat);
1270
1271 if (stat == Ok)
1272 {
1273 stat = GdipGetImageWidth(bitmap2, &width);
1274 expect(Ok, stat);
1275 expect(120, width);
1276
1277 stat = GdipGetImageHeight(bitmap2, &height);
1278 expect(Ok, stat);
1279 expect(120, height);
1280
1281 GdipDisposeImage(bitmap2);
1282 }
1283
1284 GdipDisposeImage(bitmap1);
1285 }
1286
1287 static void test_getsetpixel(void)
1288 {
1289 GpStatus stat;
1290 GpBitmap *bitmap;
1291 ARGB color;
1292 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1293 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1294
1295 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1296 expect(Ok, stat);
1297
1298 /* null parameters */
1299 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1300 expect(InvalidParameter, stat);
1301
1302 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1303 expect(InvalidParameter, stat);
1304
1305 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1306 expect(InvalidParameter, stat);
1307
1308 /* out of bounds */
1309 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1310 expect(InvalidParameter, stat);
1311
1312 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1313 expect(InvalidParameter, stat);
1314
1315 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1316 ok(stat == InvalidParameter ||
1317 broken(stat == Ok), /* Older gdiplus */
1318 "Expected InvalidParameter, got %.8x\n", stat);
1319
1320 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1321 ok(stat == InvalidParameter ||
1322 broken(stat == Ok), /* Older gdiplus */
1323 "Expected InvalidParameter, got %.8x\n", stat);
1324
1325 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1326 expect(InvalidParameter, stat);
1327
1328 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1329 expect(InvalidParameter, stat);
1330
1331 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1332 expect(InvalidParameter, stat);
1333
1334 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1335 expect(InvalidParameter, stat);
1336
1337 /* valid use */
1338 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1339 expect(Ok, stat);
1340 expect(0xffffffff, color);
1341
1342 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1343 expect(Ok, stat);
1344 expect(0xff0000ff, color);
1345
1346 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1347 expect(Ok, stat);
1348
1349 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1350 expect(Ok, stat);
1351
1352 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1353 expect(Ok, stat);
1354 expect(0xff676869, color);
1355
1356 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1357 expect(Ok, stat);
1358 expect(0xff474849, color);
1359
1360 stat = GdipDisposeImage((GpImage*)bitmap);
1361 expect(Ok, stat);
1362 }
1363
1364 static void check_halftone_palette(ColorPalette *palette)
1365 {
1366 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1367 UINT i;
1368
1369 for (i=0; i<palette->Count; i++)
1370 {
1371 ARGB expected=0xff000000;
1372 if (i<8)
1373 {
1374 if (i&1) expected |= 0x800000;
1375 if (i&2) expected |= 0x8000;
1376 if (i&4) expected |= 0x80;
1377 }
1378 else if (i == 8)
1379 {
1380 expected = 0xffc0c0c0;
1381 }
1382 else if (i < 16)
1383 {
1384 if (i&1) expected |= 0xff0000;
1385 if (i&2) expected |= 0xff00;
1386 if (i&4) expected |= 0xff;
1387 }
1388 else if (i < 40)
1389 {
1390 expected = 0x00000000;
1391 }
1392 else
1393 {
1394 expected |= halftone_values[(i-40)%6];
1395 expected |= halftone_values[((i-40)/6)%6] << 8;
1396 expected |= halftone_values[((i-40)/36)%6] << 16;
1397 }
1398 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1399 expected, palette->Entries[i], i, palette->Count);
1400 }
1401 }
1402
1403 static void test_palette(void)
1404 {
1405 GpStatus stat;
1406 GpBitmap *bitmap;
1407 INT size;
1408 BYTE buffer[1040];
1409 ColorPalette *palette=(ColorPalette*)buffer;
1410 ARGB color=0;
1411
1412 /* test initial palette from non-indexed bitmap */
1413 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1414 expect(Ok, stat);
1415
1416 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1417 expect(Ok, stat);
1418 expect(sizeof(UINT)*2+sizeof(ARGB), size);
1419
1420 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1421 expect(Ok, stat);
1422 expect(0, palette->Count);
1423
1424 /* test setting palette on not-indexed bitmap */
1425 palette->Count = 3;
1426
1427 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1428 expect(Ok, stat);
1429
1430 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1431 expect(Ok, stat);
1432 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1433
1434 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1435 expect(Ok, stat);
1436 expect(3, palette->Count);
1437
1438 GdipDisposeImage((GpImage*)bitmap);
1439
1440 /* test initial palette on 1-bit bitmap */
1441 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1442 expect(Ok, stat);
1443
1444 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1445 expect(Ok, stat);
1446 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1447
1448 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1449 expect(Ok, stat);
1450 expect(PaletteFlagsGrayScale, palette->Flags);
1451 expect(2, palette->Count);
1452
1453 expect(0xff000000, palette->Entries[0]);
1454 expect(0xffffffff, palette->Entries[1]);
1455
1456 /* test getting/setting pixels */
1457 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1458 expect(Ok, stat);
1459 expect(0xff000000, color);
1460
1461 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1462 todo_wine ok((stat == Ok) ||
1463 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1464
1465 if (stat == Ok)
1466 {
1467 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1468 expect(Ok, stat);
1469 expect(0xffffffff, color);
1470 }
1471
1472 GdipDisposeImage((GpImage*)bitmap);
1473
1474 /* test initial palette on 4-bit bitmap */
1475 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1476 expect(Ok, stat);
1477
1478 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1479 expect(Ok, stat);
1480 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1481
1482 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1483 expect(Ok, stat);
1484 expect(0, palette->Flags);
1485 expect(16, palette->Count);
1486
1487 check_halftone_palette(palette);
1488
1489 /* test getting/setting pixels */
1490 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1491 expect(Ok, stat);
1492 expect(0xff000000, color);
1493
1494 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
1495 todo_wine ok((stat == Ok) ||
1496 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1497
1498 if (stat == Ok)
1499 {
1500 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1501 expect(Ok, stat);
1502 expect(0xffff00ff, color);
1503 }
1504
1505 GdipDisposeImage((GpImage*)bitmap);
1506
1507 /* test initial palette on 8-bit bitmap */
1508 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1509 expect(Ok, stat);
1510
1511 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1512 expect(Ok, stat);
1513 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1514
1515 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1516 expect(Ok, stat);
1517 expect(PaletteFlagsHalftone, palette->Flags);
1518 expect(256, palette->Count);
1519
1520 check_halftone_palette(palette);
1521
1522 /* test getting/setting pixels */
1523 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1524 expect(Ok, stat);
1525 expect(0xff000000, color);
1526
1527 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
1528 todo_wine ok((stat == Ok) ||
1529 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1530
1531 if (stat == Ok)
1532 {
1533 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1534 expect(Ok, stat);
1535 expect(0xffcccccc, color);
1536 }
1537
1538 /* test setting/getting a different palette */
1539 palette->Entries[1] = 0xffcccccc;
1540
1541 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1542 expect(Ok, stat);
1543
1544 palette->Entries[1] = 0;
1545
1546 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1547 expect(Ok, stat);
1548 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1549
1550 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1551 expect(Ok, stat);
1552 expect(PaletteFlagsHalftone, palette->Flags);
1553 expect(256, palette->Count);
1554 expect(0xffcccccc, palette->Entries[1]);
1555
1556 /* test count < 256 */
1557 palette->Flags = 12345;
1558 palette->Count = 3;
1559
1560 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1561 expect(Ok, stat);
1562
1563 palette->Entries[1] = 0;
1564 palette->Entries[3] = 0xdeadbeef;
1565
1566 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1567 expect(Ok, stat);
1568 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1569
1570 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1571 expect(Ok, stat);
1572 expect(12345, palette->Flags);
1573 expect(3, palette->Count);
1574 expect(0xffcccccc, palette->Entries[1]);
1575 expect(0xdeadbeef, palette->Entries[3]);
1576
1577 /* test count > 256 */
1578 palette->Count = 257;
1579
1580 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1581 ok(stat == InvalidParameter ||
1582 broken(stat == Ok), /* Old gdiplus behavior */
1583 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1584
1585 GdipDisposeImage((GpImage*)bitmap);
1586 }
1587
1588 static void test_colormatrix(void)
1589 {
1590 GpStatus stat;
1591 ColorMatrix colormatrix, graymatrix;
1592 GpImageAttributes *imageattr;
1593 const ColorMatrix identity = {{
1594 {1.0,0.0,0.0,0.0,0.0},
1595 {0.0,1.0,0.0,0.0,0.0},
1596 {0.0,0.0,1.0,0.0,0.0},
1597 {0.0,0.0,0.0,1.0,0.0},
1598 {0.0,0.0,0.0,0.0,1.0}}};
1599 const ColorMatrix double_red = {{
1600 {2.0,0.0,0.0,0.0,0.0},
1601 {0.0,1.0,0.0,0.0,0.0},
1602 {0.0,0.0,1.0,0.0,0.0},
1603 {0.0,0.0,0.0,1.0,0.0},
1604 {0.0,0.0,0.0,0.0,1.0}}};
1605 GpBitmap *bitmap1, *bitmap2;
1606 GpGraphics *graphics;
1607 ARGB color;
1608
1609 colormatrix = identity;
1610 graymatrix = identity;
1611
1612 stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
1613 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1614 expect(InvalidParameter, stat);
1615
1616 stat = GdipCreateImageAttributes(&imageattr);
1617 expect(Ok, stat);
1618
1619 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1620 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1621 expect(Ok, stat);
1622
1623 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1624 TRUE, NULL, NULL, ColorMatrixFlagsDefault);
1625 expect(InvalidParameter, stat);
1626
1627 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1628 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1629 expect(Ok, stat);
1630
1631 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1632 TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
1633 expect(Ok, stat);
1634
1635 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1636 TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
1637 expect(InvalidParameter, stat);
1638
1639 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1640 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
1641 expect(Ok, stat);
1642
1643 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1644 TRUE, &colormatrix, &graymatrix, 3);
1645 expect(InvalidParameter, stat);
1646
1647 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
1648 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1649 expect(InvalidParameter, stat);
1650
1651 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
1652 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1653 expect(InvalidParameter, stat);
1654
1655 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1656 FALSE, NULL, NULL, ColorMatrixFlagsDefault);
1657 expect(Ok, stat);
1658
1659 /* Drawing a bitmap transforms the colors */
1660 colormatrix = double_red;
1661 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1662 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1663 expect(Ok, stat);
1664
1665 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1666 expect(Ok, stat);
1667
1668 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1669 expect(Ok, stat);
1670
1671 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ffff);
1672 expect(Ok, stat);
1673
1674 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1675 expect(Ok, stat);
1676
1677 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1678 UnitPixel, imageattr, NULL, NULL);
1679 expect(Ok, stat);
1680
1681 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1682 expect(Ok, stat);
1683 todo_wine expect(0xff80ffff, color);
1684
1685 GdipDeleteGraphics(graphics);
1686 GdipDisposeImage((GpImage*)bitmap1);
1687 GdipDisposeImage((GpImage*)bitmap2);
1688 GdipDisposeImageAttributes(imageattr);
1689 }
1690
1691 static void test_gamma(void)
1692 {
1693 GpStatus stat;
1694 GpImageAttributes *imageattr;
1695 GpBitmap *bitmap1, *bitmap2;
1696 GpGraphics *graphics;
1697 ARGB color;
1698
1699 stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
1700 expect(InvalidParameter, stat);
1701
1702 stat = GdipCreateImageAttributes(&imageattr);
1703 expect(Ok, stat);
1704
1705 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
1706 expect(Ok, stat);
1707
1708 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
1709 expect(InvalidParameter, stat);
1710
1711 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
1712 expect(InvalidParameter, stat);
1713
1714 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
1715 expect(InvalidParameter, stat);
1716
1717 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
1718 expect(Ok, stat);
1719
1720 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
1721 expect(Ok, stat);
1722
1723 /* Drawing a bitmap transforms the colors */
1724 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
1725 expect(Ok, stat);
1726
1727 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1728 expect(Ok, stat);
1729
1730 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1731 expect(Ok, stat);
1732
1733 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
1734 expect(Ok, stat);
1735
1736 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1737 expect(Ok, stat);
1738
1739 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1740 UnitPixel, imageattr, NULL, NULL);
1741 expect(Ok, stat);
1742
1743 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1744 expect(Ok, stat);
1745 todo_wine ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
1746
1747 GdipDeleteGraphics(graphics);
1748 GdipDisposeImage((GpImage*)bitmap1);
1749 GdipDisposeImage((GpImage*)bitmap2);
1750 GdipDisposeImageAttributes(imageattr);
1751 }
1752
1753 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
1754 static const unsigned char gifanimation[72] = {
1755 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1756 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
1757 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
1758 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
1759 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
1760 };
1761
1762 static void test_multiframegif(void)
1763 {
1764 LPSTREAM stream;
1765 HGLOBAL hglob;
1766 LPBYTE data;
1767 HRESULT hres;
1768 GpStatus stat;
1769 GpBitmap *bmp;
1770 ARGB color;
1771 UINT count;
1772 GUID dimension;
1773
1774 /* Test frame functions with an animated GIF */
1775 hglob = GlobalAlloc (0, sizeof(gifanimation));
1776 data = GlobalLock (hglob);
1777 memcpy(data, gifanimation, sizeof(gifanimation));
1778 GlobalUnlock(hglob);
1779
1780 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1781 ok(hres == S_OK, "Failed to create a stream\n");
1782 if(hres != S_OK) return;
1783
1784 stat = GdipCreateBitmapFromStream(stream, &bmp);
1785 ok(stat == Ok, "Failed to create a Bitmap\n");
1786 if(stat != Ok){
1787 IStream_Release(stream);
1788 return;
1789 }
1790
1791 /* Bitmap starts at frame 0 */
1792 color = 0xdeadbeef;
1793 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1794 expect(Ok, stat);
1795 expect(0xffffffff, color);
1796
1797 /* Check that we get correct metadata */
1798 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1799 expect(Ok, stat);
1800 expect(1, count);
1801
1802 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1803 expect(Ok, stat);
1804 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1805
1806 count = 12345;
1807 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1808 expect(Ok, stat);
1809 todo_wine expect(2, count);
1810
1811 /* SelectActiveFrame overwrites our current data */
1812 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1813 expect(Ok, stat);
1814
1815 color = 0xdeadbeef;
1816 GdipBitmapGetPixel(bmp, 0, 0, &color);
1817 expect(Ok, stat);
1818 todo_wine expect(0xff000000, color);
1819
1820 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1821 expect(Ok, stat);
1822
1823 color = 0xdeadbeef;
1824 GdipBitmapGetPixel(bmp, 0, 0, &color);
1825 expect(Ok, stat);
1826 expect(0xffffffff, color);
1827
1828 /* Write over the image data */
1829 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
1830 expect(Ok, stat);
1831
1832 /* Switching to the same frame does not overwrite our changes */
1833 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1834 expect(Ok, stat);
1835
1836 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1837 expect(Ok, stat);
1838 expect(0xff000000, color);
1839
1840 /* But switching to another frame and back does */
1841 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1842 expect(Ok, stat);
1843
1844 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1845 expect(Ok, stat);
1846
1847 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1848 expect(Ok, stat);
1849 todo_wine expect(0xffffffff, color);
1850
1851 GdipDisposeImage((GpImage*)bmp);
1852 IStream_Release(stream);
1853
1854 /* Test with a non-animated gif */
1855 hglob = GlobalAlloc (0, sizeof(gifimage));
1856 data = GlobalLock (hglob);
1857 memcpy(data, gifimage, sizeof(gifimage));
1858 GlobalUnlock(hglob);
1859
1860 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1861 ok(hres == S_OK, "Failed to create a stream\n");
1862 if(hres != S_OK) return;
1863
1864 stat = GdipCreateBitmapFromStream(stream, &bmp);
1865 ok(stat == Ok, "Failed to create a Bitmap\n");
1866 if(stat != Ok){
1867 IStream_Release(stream);
1868 return;
1869 }
1870
1871 /* Check metadata */
1872 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1873 expect(Ok, stat);
1874 expect(1, count);
1875
1876 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1877 expect(Ok, stat);
1878 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1879
1880 count = 12345;
1881 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1882 expect(Ok, stat);
1883 expect(1, count);
1884
1885 GdipDisposeImage((GpImage*)bmp);
1886 IStream_Release(stream);
1887 }
1888
1889 static void test_rotateflip(void)
1890 {
1891 GpImage *bitmap;
1892 GpStatus stat;
1893 BYTE bits[24];
1894 static const BYTE orig_bits[24] = {
1895 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
1896 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
1897 UINT width, height;
1898 ARGB color;
1899
1900 memcpy(bits, orig_bits, sizeof(bits));
1901 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1902 expect(Ok, stat);
1903
1904 stat = GdipImageRotateFlip(bitmap, Rotate90FlipNone);
1905 expect(Ok, stat);
1906
1907 stat = GdipGetImageWidth(bitmap, &width);
1908 expect(Ok, stat);
1909 stat = GdipGetImageHeight(bitmap, &height);
1910 expect(Ok, stat);
1911 expect(2, width);
1912 expect(3, height);
1913
1914 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1915 expect(Ok, stat);
1916 expect(0xff00ffff, color);
1917
1918 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 0, &color);
1919 expect(Ok, stat);
1920 expect(0xffff0000, color);
1921
1922 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 2, &color);
1923 expect(Ok, stat);
1924 expect(0xffffff00, color);
1925
1926 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 2, &color);
1927 expect(Ok, stat);
1928 expect(0xff0000ff, color);
1929
1930 expect(0, bits[0]);
1931 expect(0, bits[1]);
1932 expect(0xff, bits[2]);
1933
1934 GdipDisposeImage(bitmap);
1935
1936 memcpy(bits, orig_bits, sizeof(bits));
1937 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1938 expect(Ok, stat);
1939
1940 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipX);
1941 expect(Ok, stat);
1942
1943 stat = GdipGetImageWidth(bitmap, &width);
1944 expect(Ok, stat);
1945 stat = GdipGetImageHeight(bitmap, &height);
1946 expect(Ok, stat);
1947 expect(3, width);
1948 expect(2, height);
1949
1950 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1951 expect(Ok, stat);
1952 expect(0xff0000ff, color);
1953
1954 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
1955 expect(Ok, stat);
1956 expect(0xffff0000, color);
1957
1958 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
1959 expect(Ok, stat);
1960 expect(0xffffff00, color);
1961
1962 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
1963 expect(Ok, stat);
1964 expect(0xff00ffff, color);
1965
1966 expect(0, bits[0]);
1967 expect(0, bits[1]);
1968 expect(0xff, bits[2]);
1969
1970 GdipDisposeImage(bitmap);
1971
1972 memcpy(bits, orig_bits, sizeof(bits));
1973 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1974 expect(Ok, stat);
1975
1976 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipY);
1977 expect(Ok, stat);
1978
1979 stat = GdipGetImageWidth(bitmap, &width);
1980 expect(Ok, stat);
1981 stat = GdipGetImageHeight(bitmap, &height);
1982 expect(Ok, stat);
1983 expect(3, width);
1984 expect(2, height);
1985
1986 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1987 expect(Ok, stat);
1988 expect(0xff00ffff, color);
1989
1990 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
1991 expect(Ok, stat);
1992 expect(0xffffff00, color);
1993
1994 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
1995 expect(Ok, stat);
1996 expect(0xffff0000, color);
1997
1998 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
1999 expect(Ok, stat);
2000 expect(0xff0000ff, color);
2001
2002 expect(0, bits[0]);
2003 expect(0, bits[1]);
2004 expect(0xff, bits[2]);
2005
2006 GdipDisposeImage(bitmap);
2007 }
2008
2009 static void test_remaptable(void)
2010 {
2011 GpStatus stat;
2012 GpImageAttributes *imageattr;
2013 GpBitmap *bitmap1, *bitmap2;
2014 GpGraphics *graphics;
2015 ARGB color;
2016 ColorMap *map;
2017
2018 map = GdipAlloc(sizeof(ColorMap));
2019
2020 map->oldColor.Argb = 0xff00ff00;
2021 map->newColor.Argb = 0xffff00ff;
2022
2023 stat = GdipSetImageAttributesRemapTable(NULL, ColorAdjustTypeDefault, TRUE, 1, map);
2024 expect(InvalidParameter, stat);
2025
2026 stat = GdipCreateImageAttributes(&imageattr);
2027 expect(Ok, stat);
2028
2029 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, NULL);
2030 expect(InvalidParameter, stat);
2031
2032 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeCount, TRUE, 1, map);
2033 expect(InvalidParameter, stat);
2034
2035 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeAny, TRUE, 1, map);
2036 expect(InvalidParameter, stat);
2037
2038 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 0, map);
2039 expect(InvalidParameter, stat);
2040
2041 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, FALSE, 0, NULL);
2042 expect(Ok, stat);
2043
2044 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, map);
2045 expect(Ok, stat);
2046
2047 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
2048 expect(Ok, stat);
2049
2050 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
2051 expect(Ok, stat);
2052
2053 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff00ff00);
2054 expect(Ok, stat);
2055
2056 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2057 expect(Ok, stat);
2058
2059 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2060 UnitPixel, imageattr, NULL, NULL);
2061 expect(Ok, stat);
2062
2063 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2064 expect(Ok, stat);
2065 ok(color_match(0xffff00ff, color, 1), "Expected ffff00ff, got %.8x\n", color);
2066
2067 GdipDeleteGraphics(graphics);
2068 GdipDisposeImage((GpImage*)bitmap1);
2069 GdipDisposeImage((GpImage*)bitmap2);
2070 GdipDisposeImageAttributes(imageattr);
2071 GdipFree(map);
2072 }
2073
2074 static void test_colorkey(void)
2075 {
2076 GpStatus stat;
2077 GpImageAttributes *imageattr;
2078 GpBitmap *bitmap1, *bitmap2;
2079 GpGraphics *graphics;
2080 ARGB color;
2081
2082 stat = GdipSetImageAttributesColorKeys(NULL, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2083 expect(InvalidParameter, stat);
2084
2085 stat = GdipCreateImageAttributes(&imageattr);
2086 expect(Ok, stat);
2087
2088 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeCount, TRUE, 0xff405060, 0xff708090);
2089 expect(InvalidParameter, stat);
2090
2091 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeAny, TRUE, 0xff405060, 0xff708090);
2092 expect(InvalidParameter, stat);
2093
2094 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2095 expect(Ok, stat);
2096
2097 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap1);
2098 expect(Ok, stat);
2099
2100 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap2);
2101 expect(Ok, stat);
2102
2103 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0x20405060);
2104 expect(Ok, stat);
2105
2106 stat = GdipBitmapSetPixel(bitmap1, 0, 1, 0x40506070);
2107 expect(Ok, stat);
2108
2109 stat = GdipBitmapSetPixel(bitmap1, 1, 0, 0x60708090);
2110 expect(Ok, stat);
2111
2112 stat = GdipBitmapSetPixel(bitmap1, 1, 1, 0xffffffff);
2113 expect(Ok, stat);
2114
2115 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2116 expect(Ok, stat);
2117
2118 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,2,2, 0,0,2,2,
2119 UnitPixel, imageattr, NULL, NULL);
2120 expect(Ok, stat);
2121
2122 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2123 expect(Ok, stat);
2124 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2125
2126 stat = GdipBitmapGetPixel(bitmap2, 0, 1, &color);
2127 expect(Ok, stat);
2128 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2129
2130 stat = GdipBitmapGetPixel(bitmap2, 1, 0, &color);
2131 expect(Ok, stat);
2132 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2133
2134 stat = GdipBitmapGetPixel(bitmap2, 1, 1, &color);
2135 expect(Ok, stat);
2136 ok(color_match(0xffffffff, color, 1), "Expected ffff00ff, got %.8x\n", color);
2137
2138 GdipDeleteGraphics(graphics);
2139 GdipDisposeImage((GpImage*)bitmap1);
2140 GdipDisposeImage((GpImage*)bitmap2);
2141 GdipDisposeImageAttributes(imageattr);
2142 }
2143
2144 START_TEST(image)
2145 {
2146 struct GdiplusStartupInput gdiplusStartupInput;
2147 ULONG_PTR gdiplusToken;
2148
2149 gdiplusStartupInput.GdiplusVersion = 1;
2150 gdiplusStartupInput.DebugEventCallback = NULL;
2151 gdiplusStartupInput.SuppressBackgroundThread = 0;
2152 gdiplusStartupInput.SuppressExternalCodecs = 0;
2153
2154 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
2155
2156 test_Scan0();
2157 test_FromGdiDib();
2158 test_GetImageDimension();
2159 test_GdipImageGetFrameDimensionsCount();
2160 test_LoadingImages();
2161 test_SavingImages();
2162 test_encoders();
2163 test_LockBits();
2164 test_GdipCreateBitmapFromHBITMAP();
2165 test_GdipGetImageFlags();
2166 test_GdipCloneImage();
2167 test_testcontrol();
2168 test_fromhicon();
2169 test_getrawformat();
2170 test_loadwmf();
2171 test_createfromwmf();
2172 test_resolution();
2173 test_createhbitmap();
2174 test_getthumbnail();
2175 test_getsetpixel();
2176 test_palette();
2177 test_colormatrix();
2178 test_gamma();
2179 test_multiframegif();
2180 test_rotateflip();
2181 test_remaptable();
2182 test_colorkey();
2183
2184 GdiplusShutdown(gdiplusToken);
2185 }