msdaps: Add server side stubs for IAccessor.
[wine] / dlls / gdiplus / tests / 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_GetImageDimension(void)
162 {
163     GpBitmap *bm;
164     GpStatus stat;
165     const REAL WIDTH = 10.0, HEIGHT = 20.0;
166     REAL w,h;
167
168     bm = (GpBitmap*)0xdeadbeef;
169     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
170     expect(Ok,stat);
171     ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
172     ok(NULL != bm, "Expected bitmap to not be NULL\n");
173
174     stat = GdipGetImageDimension(NULL,&w,&h);
175     expect(InvalidParameter, stat);
176
177     stat = GdipGetImageDimension((GpImage*)bm,NULL,&h);
178     expect(InvalidParameter, stat);
179
180     stat = GdipGetImageDimension((GpImage*)bm,&w,NULL);
181     expect(InvalidParameter, stat);
182
183     w = -1;
184     h = -1;
185     stat = GdipGetImageDimension((GpImage*)bm,&w,&h);
186     expect(Ok, stat);
187     expectf(WIDTH,  w);
188     expectf(HEIGHT, h);
189     GdipDisposeImage((GpImage*)bm);
190 }
191
192 static void test_GdipImageGetFrameDimensionsCount(void)
193 {
194     GpBitmap *bm;
195     GpStatus stat;
196     const REAL WIDTH = 10.0, HEIGHT = 20.0;
197     UINT w;
198     GUID dimension = {0};
199     UINT count;
200     ARGB color;
201
202     bm = (GpBitmap*)0xdeadbeef;
203     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
204     expect(Ok,stat);
205     ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
206     ok(NULL != bm, "Expected bitmap to not be NULL\n");
207
208     stat = GdipImageGetFrameDimensionsCount(NULL,&w);
209     expect(InvalidParameter, stat);
210
211     stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,NULL);
212     expect(InvalidParameter, stat);
213
214     w = -1;
215     stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,&w);
216     expect(Ok, stat);
217     expect(1, w);
218
219     stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 1);
220     expect(Ok, stat);
221     expect_guid(&FrameDimensionPage, &dimension, __LINE__, FALSE);
222
223     stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 2);
224     expect(InvalidParameter, stat);
225
226     stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 0);
227     expect(InvalidParameter, stat);
228
229     count = 12345;
230     stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, &count);
231     todo_wine expect(Ok, stat);
232     todo_wine expect(1, count);
233
234     GdipBitmapSetPixel(bm, 0, 0, 0xffffffff);
235
236     stat = GdipImageSelectActiveFrame((GpImage*)bm, &dimension, 0);
237     expect(Ok, stat);
238
239     /* SelectActiveFrame has no effect on image data of memory bitmaps */
240     color = 0xdeadbeef;
241     GdipBitmapGetPixel(bm, 0, 0, &color);
242     expect(0xffffffff, color);
243
244     GdipDisposeImage((GpImage*)bm);
245 }
246
247 static void test_LoadingImages(void)
248 {
249     GpStatus stat;
250
251     stat = GdipCreateBitmapFromFile(0, 0);
252     expect(InvalidParameter, stat);
253
254     stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
255     expect(InvalidParameter, stat);
256
257     stat = GdipLoadImageFromFile(0, 0);
258     expect(InvalidParameter, stat);
259
260     stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
261     expect(InvalidParameter, stat);
262
263     stat = GdipLoadImageFromFileICM(0, 0);
264     expect(InvalidParameter, stat);
265
266     stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
267     expect(InvalidParameter, stat);
268 }
269
270 static void test_SavingImages(void)
271 {
272     GpStatus stat;
273     GpBitmap *bm;
274     UINT n;
275     UINT s;
276     const REAL WIDTH = 10.0, HEIGHT = 20.0;
277     REAL w, h;
278     ImageCodecInfo *codecs;
279     static const CHAR filenameA[] = "a.bmp";
280     static const WCHAR filename[] = { 'a','.','b','m','p',0 };
281
282     codecs = NULL;
283
284     stat = GdipSaveImageToFile(0, 0, 0, 0);
285     expect(InvalidParameter, stat);
286
287     bm = NULL;
288     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
289     expect(Ok, stat);
290     if (!bm)
291         return;
292
293     /* invalid params */
294     stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
295     expect(InvalidParameter, stat);
296
297     stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
298     expect(InvalidParameter, stat);
299
300     /* encoder tests should succeed -- already tested */
301     stat = GdipGetImageEncodersSize(&n, &s);
302     if (stat != Ok || n == 0) goto cleanup;
303
304     codecs = GdipAlloc(s);
305     if (!codecs) goto cleanup;
306
307     stat = GdipGetImageEncoders(n, s, codecs);
308     if (stat != Ok) goto cleanup;
309
310     stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
311     expect(stat, Ok);
312
313     GdipDisposeImage((GpImage*)bm);
314     bm = 0;
315
316     /* re-load and check image stats */
317     stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
318     expect(stat, Ok);
319     if (stat != Ok) goto cleanup;
320
321     stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
322     if (stat != Ok) goto cleanup;
323
324     expectf(WIDTH, w);
325     expectf(HEIGHT, h);
326
327  cleanup:
328     GdipFree(codecs);
329     if (bm)
330         GdipDisposeImage((GpImage*)bm);
331     ok(DeleteFileA(filenameA), "Delete failed.\n");
332 }
333
334 static void test_encoders(void)
335 {
336     GpStatus stat;
337     UINT n;
338     UINT s;
339     ImageCodecInfo *codecs;
340     int i;
341     int bmp_found;
342
343     static const CHAR bmp_format[] = "BMP";
344
345     stat = GdipGetImageEncodersSize(&n, &s);
346     expect(stat, Ok);
347
348     codecs = GdipAlloc(s);
349     if (!codecs)
350         return;
351
352     stat = GdipGetImageEncoders(n, s, NULL);
353     expect(GenericError, stat);
354
355     stat = GdipGetImageEncoders(0, s, codecs);
356     expect(GenericError, stat);
357
358     stat = GdipGetImageEncoders(n, s-1, codecs);
359     expect(GenericError, stat);
360
361     stat = GdipGetImageEncoders(n, s+1, codecs);
362     expect(GenericError, stat);
363
364     stat = GdipGetImageEncoders(n, s, codecs);
365     expect(stat, Ok);
366
367     bmp_found = FALSE;
368     for (i = 0; i < n; i++)
369         {
370             CHAR desc[32];
371
372             WideCharToMultiByte(CP_ACP, 0, codecs[i].FormatDescription, -1,
373                                 desc, 32, 0, 0);
374
375             if (CompareStringA(LOCALE_SYSTEM_DEFAULT, 0,
376                                desc, -1,
377                                bmp_format, -1) == CSTR_EQUAL) {
378                 bmp_found = TRUE;
379                 break;
380             }
381         }
382     if (!bmp_found)
383         ok(FALSE, "No BMP codec found.\n");
384
385     GdipFree(codecs);
386 }
387
388 static void test_LockBits(void)
389 {
390     GpStatus stat;
391     GpBitmap *bm;
392     GpRect rect;
393     BitmapData bd;
394     const INT WIDTH = 10, HEIGHT = 20;
395
396     bm = NULL;
397     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
398     expect(Ok, stat);
399
400     rect.X = 2;
401     rect.Y = 3;
402     rect.Width = 4;
403     rect.Height = 5;
404
405     /* read-only */
406     stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
407     expect(Ok, stat);
408
409     if (stat == Ok) {
410         stat = GdipBitmapUnlockBits(bm, &bd);
411         expect(Ok, stat);
412     }
413
414     /* read-only, with NULL rect -> whole bitmap lock */
415     stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
416     expect(Ok, stat);
417     expect(bd.Width,  WIDTH);
418     expect(bd.Height, HEIGHT);
419
420     if (stat == Ok) {
421         stat = GdipBitmapUnlockBits(bm, &bd);
422         expect(Ok, stat);
423     }
424
425     /* read-only, consecutive */
426     stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
427     expect(Ok, stat);
428
429     if (stat == Ok) {
430         stat = GdipBitmapUnlockBits(bm, &bd);
431         expect(Ok, stat);
432     }
433
434     stat = GdipDisposeImage((GpImage*)bm);
435     expect(Ok, stat);
436     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
437     expect(Ok, stat);
438
439     /* read x2 */
440     stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
441     expect(Ok, stat);
442     stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
443     expect(WrongState, stat);
444
445     stat = GdipBitmapUnlockBits(bm, &bd);
446     expect(Ok, stat);
447
448     stat = GdipDisposeImage((GpImage*)bm);
449     expect(Ok, stat);
450     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
451     expect(Ok, stat);
452
453     /* write, no modification */
454     stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
455     expect(Ok, stat);
456
457     if (stat == Ok) {
458         stat = GdipBitmapUnlockBits(bm, &bd);
459         expect(Ok, stat);
460     }
461
462     /* write, consecutive */
463     stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
464     expect(Ok, stat);
465
466     if (stat == Ok) {
467         stat = GdipBitmapUnlockBits(bm, &bd);
468         expect(Ok, stat);
469     }
470
471     stat = GdipDisposeImage((GpImage*)bm);
472     expect(Ok, stat);
473     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
474     expect(Ok, stat);
475
476     /* write, modify */
477     stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
478     expect(Ok, stat);
479
480     if (stat == Ok) {
481         if (bd.Scan0)
482             ((char*)bd.Scan0)[2] = 0xff;
483
484         stat = GdipBitmapUnlockBits(bm, &bd);
485         expect(Ok, stat);
486     }
487
488     stat = GdipDisposeImage((GpImage*)bm);
489     expect(Ok, stat);
490
491     /* dispose locked */
492     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
493     expect(Ok, stat);
494     stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
495     expect(Ok, stat);
496     stat = GdipDisposeImage((GpImage*)bm);
497     expect(Ok, stat);
498 }
499
500 static void test_GdipCreateBitmapFromHBITMAP(void)
501 {
502     GpBitmap* gpbm = NULL;
503     HBITMAP hbm = NULL;
504     HPALETTE hpal = NULL;
505     GpStatus stat;
506     BYTE buff[1000];
507     LOGPALETTE* LogPal = NULL;
508     REAL width, height;
509     const REAL WIDTH1 = 5;
510     const REAL HEIGHT1 = 15;
511     const REAL WIDTH2 = 10;
512     const REAL HEIGHT2 = 20;
513     HDC hdc;
514     BITMAPINFO bmi;
515     BYTE *bits;
516
517     stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
518     expect(InvalidParameter, stat);
519
520     hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
521     stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
522     expect(InvalidParameter, stat);
523
524     stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
525     expect(Ok, stat);
526     expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
527     expectf(WIDTH1,  width);
528     expectf(HEIGHT1, height);
529     if (stat == Ok)
530         GdipDisposeImage((GpImage*)gpbm);
531     DeleteObject(hbm);
532
533     hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
534     stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
535     expect(Ok, stat);
536     /* raw format */
537     expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
538
539     expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
540     expectf(WIDTH2,  width);
541     expectf(HEIGHT2, height);
542     if (stat == Ok)
543         GdipDisposeImage((GpImage*)gpbm);
544     DeleteObject(hbm);
545
546     hdc = CreateCompatibleDC(0);
547     ok(hdc != NULL, "CreateCompatibleDC failed\n");
548     bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
549     bmi.bmiHeader.biHeight = HEIGHT1;
550     bmi.bmiHeader.biWidth = WIDTH1;
551     bmi.bmiHeader.biBitCount = 24;
552     bmi.bmiHeader.biPlanes = 1;
553     bmi.bmiHeader.biCompression = BI_RGB;
554
555     hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
556     ok(hbm != NULL, "CreateDIBSection failed\n");
557
558     bits[0] = 0;
559
560     stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
561     expect(Ok, stat);
562     expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
563     expectf(WIDTH1,  width);
564     expectf(HEIGHT1, height);
565     if (stat == Ok)
566     {
567         /* test whether writing to the bitmap affects the original */
568         stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
569         expect(Ok, stat);
570
571         expect(0, bits[0]);
572
573         GdipDisposeImage((GpImage*)gpbm);
574     }
575
576     LogPal = GdipAlloc(sizeof(LOGPALETTE));
577     ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
578     LogPal->palVersion = 0x300;
579     LogPal->palNumEntries = 1;
580     hpal = CreatePalette(LogPal);
581     ok(hpal != NULL, "CreatePalette failed\n");
582     GdipFree(LogPal);
583
584     stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
585     todo_wine
586     {
587         expect(Ok, stat);
588     }
589     if (stat == Ok)
590         GdipDisposeImage((GpImage*)gpbm);
591
592     DeleteObject(hpal);
593     DeleteObject(hbm);
594 }
595
596 static void test_GdipGetImageFlags(void)
597 {
598     GpImage *img;
599     GpStatus stat;
600     UINT flags;
601
602     img = (GpImage*)0xdeadbeef;
603
604     stat = GdipGetImageFlags(NULL, NULL);
605     expect(InvalidParameter, stat);
606
607     stat = GdipGetImageFlags(NULL, &flags);
608     expect(InvalidParameter, stat);
609
610     stat = GdipGetImageFlags(img, NULL);
611     expect(InvalidParameter, stat);
612 }
613
614 static void test_GdipCloneImage(void)
615 {
616     GpStatus stat;
617     GpRectF rectF;
618     GpUnit unit;
619     GpBitmap *bm;
620     GpImage *image_src, *image_dest = NULL;
621     const INT WIDTH = 10, HEIGHT = 20;
622
623     /* Create an image, clone it, delete the original, make sure the copy works */
624     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
625     expect(Ok, stat);
626     expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
627
628     image_src = ((GpImage*)bm);
629     stat = GdipCloneImage(image_src, &image_dest);
630     expect(Ok, stat);
631     expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
632
633     stat = GdipDisposeImage((GpImage*)bm);
634     expect(Ok, stat);
635     stat = GdipGetImageBounds(image_dest, &rectF, &unit);
636     expect(Ok, stat);
637
638     /* Treat FP values carefully */
639     expectf((REAL)WIDTH, rectF.Width);
640     expectf((REAL)HEIGHT, rectF.Height);
641
642     stat = GdipDisposeImage(image_dest);
643     expect(Ok, stat);
644 }
645
646 static void test_testcontrol(void)
647 {
648     GpStatus stat;
649     DWORD param;
650
651     param = 0;
652     stat = GdipTestControl(TestControlGetBuildNumber, &param);
653     expect(Ok, stat);
654     ok(param != 0, "Build number expected, got %u\n", param);
655 }
656
657 static void test_fromhicon(void)
658 {
659     static const BYTE bmp_bits[1024];
660     HBITMAP hbmMask, hbmColor;
661     ICONINFO info;
662     HICON hIcon;
663     GpStatus stat;
664     GpBitmap *bitmap = NULL;
665     UINT dim;
666     ImageType type;
667     PixelFormat format;
668
669     /* NULL */
670     stat = GdipCreateBitmapFromHICON(NULL, NULL);
671     expect(InvalidParameter, stat);
672     stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
673     expect(InvalidParameter, stat);
674
675     /* color icon 1 bit */
676     hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
677     ok(hbmMask != 0, "CreateBitmap failed\n");
678     hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
679     ok(hbmColor != 0, "CreateBitmap failed\n");
680     info.fIcon = TRUE;
681     info.xHotspot = 8;
682     info.yHotspot = 8;
683     info.hbmMask = hbmMask;
684     info.hbmColor = hbmColor;
685     hIcon = CreateIconIndirect(&info);
686     ok(hIcon != 0, "CreateIconIndirect failed\n");
687     DeleteObject(hbmMask);
688     DeleteObject(hbmColor);
689
690     stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
691     ok(stat == Ok ||
692        broken(stat == InvalidParameter), /* Win98 */
693        "Expected Ok, got %.8x\n", stat);
694     if(stat == Ok){
695        /* check attributes */
696        stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
697        expect(Ok, stat);
698        expect(16, dim);
699        stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
700        expect(Ok, stat);
701        expect(16, dim);
702        stat = GdipGetImageType((GpImage*)bitmap, &type);
703        expect(Ok, stat);
704        expect(ImageTypeBitmap, type);
705        stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
706        expect(PixelFormat32bppARGB, format);
707        /* raw format */
708        expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
709        GdipDisposeImage((GpImage*)bitmap);
710     }
711     DestroyIcon(hIcon);
712
713     /* color icon 8 bpp */
714     hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
715     ok(hbmMask != 0, "CreateBitmap failed\n");
716     hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
717     ok(hbmColor != 0, "CreateBitmap failed\n");
718     info.fIcon = TRUE;
719     info.xHotspot = 8;
720     info.yHotspot = 8;
721     info.hbmMask = hbmMask;
722     info.hbmColor = hbmColor;
723     hIcon = CreateIconIndirect(&info);
724     ok(hIcon != 0, "CreateIconIndirect failed\n");
725     DeleteObject(hbmMask);
726     DeleteObject(hbmColor);
727
728     stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
729     expect(Ok, stat);
730     if(stat == Ok){
731         /* check attributes */
732         stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
733         expect(Ok, stat);
734         expect(16, dim);
735         stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
736         expect(Ok, stat);
737         expect(16, dim);
738         stat = GdipGetImageType((GpImage*)bitmap, &type);
739         expect(Ok, stat);
740         expect(ImageTypeBitmap, type);
741         stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
742         expect(PixelFormat32bppARGB, format);
743         /* raw format */
744         expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
745         GdipDisposeImage((GpImage*)bitmap);
746     }
747     DestroyIcon(hIcon);
748 }
749
750 /* 1x1 pixel png */
751 static const unsigned char pngimage[285] = {
752 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
753 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
754 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
755 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
756 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
757 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
758 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
759 };
760 /* 1x1 pixel gif */
761 static const unsigned char gifimage[35] = {
762 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
763 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
764 0x01,0x00,0x3b
765 };
766 /* 1x1 pixel bmp */
767 static const unsigned char bmpimage[66] = {
768 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
769 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
770 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
771 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
772 0x00,0x00
773 };
774 /* 1x1 pixel jpg */
775 static const unsigned char jpgimage[285] = {
776 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
777 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
778 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
779 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
780 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
781 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
782 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
783 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
784 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
785 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
786 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
787 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
788 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
789 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
790 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
791 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
792 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
793 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
794 };
795 /* 320x320 twip wmf */
796 static const unsigned char wmfimage[180] = {
797 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
798 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
799 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
800 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
801 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
802 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
803 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
804 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
805 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
806 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
807 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
808 0x00,0x00,0x00,0x00
809 };
810 static void test_getrawformat(void)
811 {
812     test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG,  __LINE__, FALSE);
813     test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF,  __LINE__, FALSE);
814     test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP,  __LINE__, FALSE);
815     test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
816     test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
817 }
818
819 static void test_loadwmf(void)
820 {
821     LPSTREAM stream;
822     HGLOBAL  hglob;
823     LPBYTE   data;
824     HRESULT  hres;
825     GpStatus stat;
826     GpImage *img;
827     GpRectF bounds;
828     GpUnit unit;
829     REAL res = 12345.0;
830
831     hglob = GlobalAlloc (0, sizeof(wmfimage));
832     data = GlobalLock (hglob);
833     memcpy(data, wmfimage, sizeof(wmfimage));
834     GlobalUnlock(hglob); data = NULL;
835
836     hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
837     ok(hres == S_OK, "Failed to create a stream\n");
838     if(hres != S_OK) return;
839
840     stat = GdipLoadImageFromStream(stream, &img);
841     ok(stat == Ok, "Failed to create a Bitmap\n");
842     if(stat != Ok){
843         IStream_Release(stream);
844         return;
845     }
846
847     IStream_Release(stream);
848
849     stat = GdipGetImageBounds(img, &bounds, &unit);
850     expect(Ok, stat);
851     todo_wine expect(UnitPixel, unit);
852     expectf(0.0, bounds.X);
853     expectf(0.0, bounds.Y);
854     todo_wine expectf(320.0, bounds.Width);
855     todo_wine expectf(320.0, bounds.Height);
856
857     stat = GdipGetImageHorizontalResolution(img, &res);
858     expect(Ok, stat);
859     todo_wine expectf(1440.0, res);
860
861     stat = GdipGetImageVerticalResolution(img, &res);
862     expect(Ok, stat);
863     todo_wine expectf(1440.0, res);
864
865     GdipDisposeImage(img);
866 }
867
868 static void test_createfromwmf(void)
869 {
870     HMETAFILE hwmf;
871     GpImage *img;
872     GpStatus stat;
873     GpRectF bounds;
874     GpUnit unit;
875     REAL res = 12345.0;
876
877     hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
878         wmfimage+sizeof(WmfPlaceableFileHeader));
879     ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
880
881     stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
882         (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
883     expect(Ok, stat);
884
885     stat = GdipGetImageBounds(img, &bounds, &unit);
886     expect(Ok, stat);
887     todo_wine expect(UnitPixel, unit);
888     expectf(0.0, bounds.X);
889     expectf(0.0, bounds.Y);
890     todo_wine expectf(320.0, bounds.Width);
891     todo_wine expectf(320.0, bounds.Height);
892
893     stat = GdipGetImageHorizontalResolution(img, &res);
894     expect(Ok, stat);
895     expectf(1440.0, res);
896
897     stat = GdipGetImageVerticalResolution(img, &res);
898     expect(Ok, stat);
899     expectf(1440.0, res);
900
901     GdipDisposeImage(img);
902 }
903
904 static void test_resolution(void)
905 {
906     GpStatus stat;
907     GpBitmap *bitmap;
908     REAL res=-1.0;
909     HDC screendc;
910     int screenxres, screenyres;
911
912     /* create Bitmap */
913     stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
914     expect(Ok, stat);
915
916     /* test invalid values */
917     stat = GdipGetImageHorizontalResolution(NULL, &res);
918     expect(InvalidParameter, stat);
919
920     stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
921     expect(InvalidParameter, stat);
922
923     stat = GdipGetImageVerticalResolution(NULL, &res);
924     expect(InvalidParameter, stat);
925
926     stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
927     expect(InvalidParameter, stat);
928
929     stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
930     expect(InvalidParameter, stat);
931
932     stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
933     expect(InvalidParameter, stat);
934
935     /* defaults to screen resolution */
936     screendc = GetDC(0);
937
938     screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
939     screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
940
941     ReleaseDC(0, screendc);
942
943     stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
944     expect(Ok, stat);
945     expectf((REAL)screenxres, res);
946
947     stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
948     expect(Ok, stat);
949     expectf((REAL)screenyres, res);
950
951     /* test changing the resolution */
952     stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
953     expect(Ok, stat);
954
955     stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
956     expect(Ok, stat);
957     expectf(screenxres*2.0, res);
958
959     stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
960     expect(Ok, stat);
961     expectf(screenyres*3.0, res);
962
963     stat = GdipDisposeImage((GpImage*)bitmap);
964     expect(Ok, stat);
965 }
966
967 static void test_createhbitmap(void)
968 {
969     GpStatus stat;
970     GpBitmap *bitmap;
971     HBITMAP hbitmap, oldhbitmap;
972     BITMAP bm;
973     int ret;
974     HDC hdc;
975     COLORREF pixel;
976     BYTE bits[640];
977
978     memset(bits, 0x68, 640);
979
980     /* create Bitmap */
981     stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
982     expect(Ok, stat);
983
984     /* test NULL values */
985     stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
986     expect(InvalidParameter, stat);
987
988     stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
989     expect(InvalidParameter, stat);
990
991     /* create HBITMAP */
992     stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
993     expect(Ok, stat);
994
995     if (stat == Ok)
996     {
997         ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
998         expect(sizeof(BITMAP), ret);
999
1000         expect(0, bm.bmType);
1001         expect(10, bm.bmWidth);
1002         expect(20, bm.bmHeight);
1003         expect(40, bm.bmWidthBytes);
1004         expect(1, bm.bmPlanes);
1005         expect(32, bm.bmBitsPixel);
1006         ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1007
1008         hdc = CreateCompatibleDC(NULL);
1009
1010         oldhbitmap = SelectObject(hdc, hbitmap);
1011         pixel = GetPixel(hdc, 5, 5);
1012         SelectObject(hdc, oldhbitmap);
1013
1014         DeleteDC(hdc);
1015
1016         expect(0x686868, pixel);
1017
1018         DeleteObject(hbitmap);
1019     }
1020
1021     stat = GdipDisposeImage((GpImage*)bitmap);
1022     expect(Ok, stat);
1023 }
1024
1025 static void test_getsetpixel(void)
1026 {
1027     GpStatus stat;
1028     GpBitmap *bitmap;
1029     ARGB color;
1030     BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1031                      0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1032
1033     stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1034     expect(Ok, stat);
1035
1036     /* null parameters */
1037     stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1038     expect(InvalidParameter, stat);
1039
1040     stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1041     expect(InvalidParameter, stat);
1042
1043     stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1044     expect(InvalidParameter, stat);
1045
1046     /* out of bounds */
1047     stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1048     expect(InvalidParameter, stat);
1049
1050     stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1051     expect(InvalidParameter, stat);
1052
1053     stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1054     ok(stat == InvalidParameter ||
1055        broken(stat == Ok), /* Older gdiplus */
1056        "Expected InvalidParameter, got %.8x\n", stat);
1057
1058     stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1059     ok(stat == InvalidParameter ||
1060        broken(stat == Ok), /* Older gdiplus */
1061        "Expected InvalidParameter, got %.8x\n", stat);
1062
1063     stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1064     expect(InvalidParameter, stat);
1065
1066     stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1067     expect(InvalidParameter, stat);
1068
1069     stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1070     expect(InvalidParameter, stat);
1071
1072     stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1073     expect(InvalidParameter, stat);
1074
1075     /* valid use */
1076     stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1077     expect(Ok, stat);
1078     expect(0xffffffff, color);
1079
1080     stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1081     expect(Ok, stat);
1082     expect(0xff0000ff, color);
1083
1084     stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1085     expect(Ok, stat);
1086
1087     stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1088     expect(Ok, stat);
1089
1090     stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1091     expect(Ok, stat);
1092     expect(0xff676869, color);
1093
1094     stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1095     expect(Ok, stat);
1096     expect(0xff474849, color);
1097
1098     stat = GdipDisposeImage((GpImage*)bitmap);
1099     expect(Ok, stat);
1100 }
1101
1102 static void check_halftone_palette(ColorPalette *palette)
1103 {
1104     static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1105     UINT i;
1106
1107     for (i=0; i<palette->Count; i++)
1108     {
1109         ARGB expected=0xff000000;
1110         if (i<8)
1111         {
1112             if (i&1) expected |= 0x800000;
1113             if (i&2) expected |= 0x8000;
1114             if (i&4) expected |= 0x80;
1115         }
1116         else if (i == 8)
1117         {
1118             expected = 0xffc0c0c0;
1119         }
1120         else if (i < 16)
1121         {
1122             if (i&1) expected |= 0xff0000;
1123             if (i&2) expected |= 0xff00;
1124             if (i&4) expected |= 0xff;
1125         }
1126         else if (i < 40)
1127         {
1128             expected = 0x00000000;
1129         }
1130         else
1131         {
1132             expected |= halftone_values[(i-40)%6];
1133             expected |= halftone_values[((i-40)/6)%6] << 8;
1134             expected |= halftone_values[((i-40)/36)%6] << 16;
1135         }
1136         ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1137             expected, palette->Entries[i], i, palette->Count);
1138     }
1139 }
1140
1141 static void test_palette(void)
1142 {
1143     GpStatus stat;
1144     GpBitmap *bitmap;
1145     INT size;
1146     BYTE buffer[1040];
1147     ColorPalette *palette=(ColorPalette*)buffer;
1148     ARGB color=0;
1149
1150     /* test initial palette from non-indexed bitmap */
1151     stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1152     expect(Ok, stat);
1153
1154     stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1155     expect(Ok, stat);
1156     expect(sizeof(UINT)*2+sizeof(ARGB), size);
1157
1158     stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1159     expect(Ok, stat);
1160     expect(0, palette->Count);
1161
1162     /* test setting palette on not-indexed bitmap */
1163     palette->Count = 3;
1164
1165     stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1166     expect(Ok, stat);
1167
1168     stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1169     expect(Ok, stat);
1170     expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1171
1172     stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1173     expect(Ok, stat);
1174     expect(3, palette->Count);
1175
1176     GdipDisposeImage((GpImage*)bitmap);
1177
1178     /* test initial palette on 1-bit bitmap */
1179     stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1180     expect(Ok, stat);
1181
1182     stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1183     expect(Ok, stat);
1184     expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1185
1186     stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1187     expect(Ok, stat);
1188     expect(PaletteFlagsGrayScale, palette->Flags);
1189     expect(2, palette->Count);
1190
1191     expect(0xff000000, palette->Entries[0]);
1192     expect(0xffffffff, palette->Entries[1]);
1193
1194     /* test getting/setting pixels */
1195     stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1196     expect(Ok, stat);
1197     expect(0xff000000, color);
1198
1199     stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1200     todo_wine ok((stat == Ok) ||
1201        broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1202
1203     if (stat == Ok)
1204     {
1205         stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1206         expect(Ok, stat);
1207         expect(0xffffffff, color);
1208     }
1209
1210     GdipDisposeImage((GpImage*)bitmap);
1211
1212     /* test initial palette on 4-bit bitmap */
1213     stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1214     expect(Ok, stat);
1215
1216     stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1217     expect(Ok, stat);
1218     expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1219
1220     stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1221     expect(Ok, stat);
1222     expect(0, palette->Flags);
1223     expect(16, palette->Count);
1224
1225     check_halftone_palette(palette);
1226
1227     /* test getting/setting pixels */
1228     stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1229     expect(Ok, stat);
1230     expect(0xff000000, color);
1231
1232     stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
1233     todo_wine ok((stat == Ok) ||
1234        broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1235
1236     if (stat == Ok)
1237     {
1238         stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1239         expect(Ok, stat);
1240         expect(0xffff00ff, color);
1241     }
1242
1243     GdipDisposeImage((GpImage*)bitmap);
1244
1245     /* test initial palette on 8-bit bitmap */
1246     stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1247     expect(Ok, stat);
1248
1249     stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1250     expect(Ok, stat);
1251     expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1252
1253     stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1254     expect(Ok, stat);
1255     expect(PaletteFlagsHalftone, palette->Flags);
1256     expect(256, palette->Count);
1257
1258     check_halftone_palette(palette);
1259
1260     /* test getting/setting pixels */
1261     stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1262     expect(Ok, stat);
1263     expect(0xff000000, color);
1264
1265     stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
1266     todo_wine ok((stat == Ok) ||
1267        broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1268
1269     if (stat == Ok)
1270     {
1271         stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1272         expect(Ok, stat);
1273         expect(0xffcccccc, color);
1274     }
1275
1276     /* test setting/getting a different palette */
1277     palette->Entries[1] = 0xffcccccc;
1278
1279     stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1280     expect(Ok, stat);
1281
1282     palette->Entries[1] = 0;
1283
1284     stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1285     expect(Ok, stat);
1286     expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1287
1288     stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1289     expect(Ok, stat);
1290     expect(PaletteFlagsHalftone, palette->Flags);
1291     expect(256, palette->Count);
1292     expect(0xffcccccc, palette->Entries[1]);
1293
1294     /* test count < 256 */
1295     palette->Flags = 12345;
1296     palette->Count = 3;
1297
1298     stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1299     expect(Ok, stat);
1300
1301     palette->Entries[1] = 0;
1302     palette->Entries[3] = 0xdeadbeef;
1303
1304     stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1305     expect(Ok, stat);
1306     expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1307
1308     stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1309     expect(Ok, stat);
1310     expect(12345, palette->Flags);
1311     expect(3, palette->Count);
1312     expect(0xffcccccc, palette->Entries[1]);
1313     expect(0xdeadbeef, palette->Entries[3]);
1314
1315     /* test count > 256 */
1316     palette->Count = 257;
1317
1318     stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1319     ok(stat == InvalidParameter ||
1320        broken(stat == Ok), /* Old gdiplus behavior */
1321        "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1322
1323     GdipDisposeImage((GpImage*)bitmap);
1324 }
1325
1326 static void test_colormatrix(void)
1327 {
1328     GpStatus stat;
1329     ColorMatrix colormatrix, graymatrix;
1330     GpImageAttributes *imageattr;
1331     const ColorMatrix identity = {{
1332         {1.0,0.0,0.0,0.0,0.0},
1333         {0.0,1.0,0.0,0.0,0.0},
1334         {0.0,0.0,1.0,0.0,0.0},
1335         {0.0,0.0,0.0,1.0,0.0},
1336         {0.0,0.0,0.0,0.0,1.0}}};
1337     const ColorMatrix double_red = {{
1338         {2.0,0.0,0.0,0.0,0.0},
1339         {0.0,1.0,0.0,0.0,0.0},
1340         {0.0,0.0,1.0,0.0,0.0},
1341         {0.0,0.0,0.0,1.0,0.0},
1342         {0.0,0.0,0.0,0.0,1.0}}};
1343     GpBitmap *bitmap1, *bitmap2;
1344     GpGraphics *graphics;
1345     ARGB color;
1346
1347     colormatrix = identity;
1348     graymatrix = identity;
1349
1350     stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
1351         TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1352     expect(InvalidParameter, stat);
1353
1354     stat = GdipCreateImageAttributes(&imageattr);
1355     expect(Ok, stat);
1356
1357     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1358         TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1359     expect(Ok, stat);
1360
1361     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1362         TRUE, NULL, NULL, ColorMatrixFlagsDefault);
1363     expect(InvalidParameter, stat);
1364
1365     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1366         TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1367     expect(Ok, stat);
1368
1369     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1370         TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
1371     expect(Ok, stat);
1372
1373     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1374         TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
1375     expect(InvalidParameter, stat);
1376
1377     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1378         TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
1379     expect(Ok, stat);
1380
1381     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1382         TRUE, &colormatrix, &graymatrix, 3);
1383     expect(InvalidParameter, stat);
1384
1385     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
1386         TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1387     expect(InvalidParameter, stat);
1388
1389     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
1390         TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1391     expect(InvalidParameter, stat);
1392
1393     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1394         FALSE, NULL, NULL, ColorMatrixFlagsDefault);
1395     expect(Ok, stat);
1396
1397     /* Drawing a bitmap transforms the colors */
1398     colormatrix = double_red;
1399     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1400         TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1401     expect(Ok, stat);
1402
1403     stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1404     expect(Ok, stat);
1405
1406     stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1407     expect(Ok, stat);
1408
1409     stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ffff);
1410     expect(Ok, stat);
1411
1412     stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1413     expect(Ok, stat);
1414
1415     stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1416         UnitPixel, imageattr, NULL, NULL);
1417     expect(Ok, stat);
1418
1419     stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1420     expect(Ok, stat);
1421     todo_wine expect(0xff80ffff, color);
1422
1423     GdipDeleteGraphics(graphics);
1424     GdipDisposeImage((GpImage*)bitmap1);
1425     GdipDisposeImage((GpImage*)bitmap2);
1426     GdipDisposeImageAttributes(imageattr);
1427 }
1428
1429 static void test_gamma(void)
1430 {
1431     GpStatus stat;
1432     GpImageAttributes *imageattr;
1433     GpBitmap *bitmap1, *bitmap2;
1434     GpGraphics *graphics;
1435     ARGB color;
1436
1437     stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
1438     expect(InvalidParameter, stat);
1439
1440     stat = GdipCreateImageAttributes(&imageattr);
1441     expect(Ok, stat);
1442
1443     stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
1444     expect(Ok, stat);
1445
1446     stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
1447     expect(InvalidParameter, stat);
1448
1449     stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
1450     expect(InvalidParameter, stat);
1451
1452     stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
1453     expect(InvalidParameter, stat);
1454
1455     stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
1456     expect(Ok, stat);
1457
1458     stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
1459     expect(Ok, stat);
1460
1461     /* Drawing a bitmap transforms the colors */
1462     stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
1463     expect(Ok, stat);
1464
1465     stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1466     expect(Ok, stat);
1467
1468     stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1469     expect(Ok, stat);
1470
1471     stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
1472     expect(Ok, stat);
1473
1474     stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1475     expect(Ok, stat);
1476
1477     stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1478         UnitPixel, imageattr, NULL, NULL);
1479     expect(Ok, stat);
1480
1481     stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1482     expect(Ok, stat);
1483     todo_wine ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
1484
1485     GdipDeleteGraphics(graphics);
1486     GdipDisposeImage((GpImage*)bitmap1);
1487     GdipDisposeImage((GpImage*)bitmap2);
1488     GdipDisposeImageAttributes(imageattr);
1489 }
1490
1491 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
1492 static const unsigned char gifanimation[72] = {
1493 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1494 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
1495 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
1496 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
1497 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
1498 };
1499
1500 static void test_multiframegif(void)
1501 {
1502     LPSTREAM stream;
1503     HGLOBAL hglob;
1504     LPBYTE data;
1505     HRESULT hres;
1506     GpStatus stat;
1507     GpBitmap *bmp;
1508     ARGB color;
1509     UINT count;
1510     GUID dimension;
1511
1512     /* Test frame functions with an animated GIF */
1513     hglob = GlobalAlloc (0, sizeof(gifanimation));
1514     data = GlobalLock (hglob);
1515     memcpy(data, gifanimation, sizeof(gifanimation));
1516     GlobalUnlock(hglob);
1517
1518     hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1519     ok(hres == S_OK, "Failed to create a stream\n");
1520     if(hres != S_OK) return;
1521
1522     stat = GdipCreateBitmapFromStream(stream, &bmp);
1523     ok(stat == Ok, "Failed to create a Bitmap\n");
1524     if(stat != Ok){
1525         IStream_Release(stream);
1526         return;
1527     }
1528
1529     /* Bitmap starts at frame 0 */
1530     color = 0xdeadbeef;
1531     stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1532     expect(Ok, stat);
1533     expect(0xffffffff, color);
1534
1535     /* Check that we get correct metadata */
1536     stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1537     expect(Ok, stat);
1538     expect(1, count);
1539
1540     stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1541     expect(Ok, stat);
1542     expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1543
1544     count = 12345;
1545     stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1546     todo_wine expect(Ok, stat);
1547     todo_wine expect(2, count);
1548
1549     /* SelectActiveFrame overwrites our current data */
1550     stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1551     expect(Ok, stat);
1552
1553     color = 0xdeadbeef;
1554     GdipBitmapGetPixel(bmp, 0, 0, &color);
1555     expect(Ok, stat);
1556     todo_wine expect(0xff000000, color);
1557
1558     stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1559     expect(Ok, stat);
1560
1561     color = 0xdeadbeef;
1562     GdipBitmapGetPixel(bmp, 0, 0, &color);
1563     expect(Ok, stat);
1564     expect(0xffffffff, color);
1565
1566     /* Write over the image data */
1567     stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
1568     expect(Ok, stat);
1569
1570     /* Switching to the same frame does not overwrite our changes */
1571     stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1572     expect(Ok, stat);
1573
1574     stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1575     expect(Ok, stat);
1576     expect(0xff000000, color);
1577
1578     /* But switching to another frame and back does */
1579     stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1580     expect(Ok, stat);
1581
1582     stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1583     expect(Ok, stat);
1584
1585     stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1586     expect(Ok, stat);
1587     todo_wine expect(0xffffffff, color);
1588
1589     GdipDisposeImage((GpImage*)bmp);
1590     IStream_Release(stream);
1591
1592     /* Test with a non-animated gif */
1593     hglob = GlobalAlloc (0, sizeof(gifimage));
1594     data = GlobalLock (hglob);
1595     memcpy(data, gifimage, sizeof(gifimage));
1596     GlobalUnlock(hglob);
1597
1598     hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1599     ok(hres == S_OK, "Failed to create a stream\n");
1600     if(hres != S_OK) return;
1601
1602     stat = GdipCreateBitmapFromStream(stream, &bmp);
1603     ok(stat == Ok, "Failed to create a Bitmap\n");
1604     if(stat != Ok){
1605         IStream_Release(stream);
1606         return;
1607     }
1608
1609     /* Check metadata */
1610     stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1611     expect(Ok, stat);
1612     expect(1, count);
1613
1614     stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1615     expect(Ok, stat);
1616     expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1617
1618     count = 12345;
1619     stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1620     todo_wine expect(Ok, stat);
1621     todo_wine expect(1, count);
1622
1623     GdipDisposeImage((GpImage*)bmp);
1624     IStream_Release(stream);
1625 }
1626
1627 START_TEST(image)
1628 {
1629     struct GdiplusStartupInput gdiplusStartupInput;
1630     ULONG_PTR gdiplusToken;
1631
1632     gdiplusStartupInput.GdiplusVersion              = 1;
1633     gdiplusStartupInput.DebugEventCallback          = NULL;
1634     gdiplusStartupInput.SuppressBackgroundThread    = 0;
1635     gdiplusStartupInput.SuppressExternalCodecs      = 0;
1636
1637     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1638
1639     test_Scan0();
1640     test_GetImageDimension();
1641     test_GdipImageGetFrameDimensionsCount();
1642     test_LoadingImages();
1643     test_SavingImages();
1644     test_encoders();
1645     test_LockBits();
1646     test_GdipCreateBitmapFromHBITMAP();
1647     test_GdipGetImageFlags();
1648     test_GdipCloneImage();
1649     test_testcontrol();
1650     test_fromhicon();
1651     test_getrawformat();
1652     test_loadwmf();
1653     test_createfromwmf();
1654     test_resolution();
1655     test_createhbitmap();
1656     test_getsetpixel();
1657     test_palette();
1658     test_colormatrix();
1659     test_gamma();
1660     test_multiframegif();
1661
1662     GdiplusShutdown(gdiplusToken);
1663 }