quartz: Do not assert() the existence of a media format of an input pin.
[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     memset(buff, 0, sizeof(buff));
534     hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
535     stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
536     expect(Ok, stat);
537     /* raw format */
538     expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
539
540     expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
541     expectf(WIDTH2,  width);
542     expectf(HEIGHT2, height);
543     if (stat == Ok)
544         GdipDisposeImage((GpImage*)gpbm);
545     DeleteObject(hbm);
546
547     hdc = CreateCompatibleDC(0);
548     ok(hdc != NULL, "CreateCompatibleDC failed\n");
549     bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
550     bmi.bmiHeader.biHeight = HEIGHT1;
551     bmi.bmiHeader.biWidth = WIDTH1;
552     bmi.bmiHeader.biBitCount = 24;
553     bmi.bmiHeader.biPlanes = 1;
554     bmi.bmiHeader.biCompression = BI_RGB;
555
556     hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
557     ok(hbm != NULL, "CreateDIBSection failed\n");
558
559     bits[0] = 0;
560
561     stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
562     expect(Ok, stat);
563     expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
564     expectf(WIDTH1,  width);
565     expectf(HEIGHT1, height);
566     if (stat == Ok)
567     {
568         /* test whether writing to the bitmap affects the original */
569         stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
570         expect(Ok, stat);
571
572         expect(0, bits[0]);
573
574         GdipDisposeImage((GpImage*)gpbm);
575     }
576
577     LogPal = GdipAlloc(sizeof(LOGPALETTE));
578     ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
579     LogPal->palVersion = 0x300;
580     LogPal->palNumEntries = 1;
581     hpal = CreatePalette(LogPal);
582     ok(hpal != NULL, "CreatePalette failed\n");
583     GdipFree(LogPal);
584
585     stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
586     todo_wine
587     {
588         expect(Ok, stat);
589     }
590     if (stat == Ok)
591         GdipDisposeImage((GpImage*)gpbm);
592
593     DeleteObject(hpal);
594     DeleteObject(hbm);
595 }
596
597 static void test_GdipGetImageFlags(void)
598 {
599     GpImage *img;
600     GpStatus stat;
601     UINT flags;
602
603     img = (GpImage*)0xdeadbeef;
604
605     stat = GdipGetImageFlags(NULL, NULL);
606     expect(InvalidParameter, stat);
607
608     stat = GdipGetImageFlags(NULL, &flags);
609     expect(InvalidParameter, stat);
610
611     stat = GdipGetImageFlags(img, NULL);
612     expect(InvalidParameter, stat);
613 }
614
615 static void test_GdipCloneImage(void)
616 {
617     GpStatus stat;
618     GpRectF rectF;
619     GpUnit unit;
620     GpBitmap *bm;
621     GpImage *image_src, *image_dest = NULL;
622     const INT WIDTH = 10, HEIGHT = 20;
623
624     /* Create an image, clone it, delete the original, make sure the copy works */
625     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
626     expect(Ok, stat);
627     expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
628
629     image_src = ((GpImage*)bm);
630     stat = GdipCloneImage(image_src, &image_dest);
631     expect(Ok, stat);
632     expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
633
634     stat = GdipDisposeImage((GpImage*)bm);
635     expect(Ok, stat);
636     stat = GdipGetImageBounds(image_dest, &rectF, &unit);
637     expect(Ok, stat);
638
639     /* Treat FP values carefully */
640     expectf((REAL)WIDTH, rectF.Width);
641     expectf((REAL)HEIGHT, rectF.Height);
642
643     stat = GdipDisposeImage(image_dest);
644     expect(Ok, stat);
645 }
646
647 static void test_testcontrol(void)
648 {
649     GpStatus stat;
650     DWORD param;
651
652     param = 0;
653     stat = GdipTestControl(TestControlGetBuildNumber, &param);
654     expect(Ok, stat);
655     ok(param != 0, "Build number expected, got %u\n", param);
656 }
657
658 static void test_fromhicon(void)
659 {
660     static const BYTE bmp_bits[1024];
661     HBITMAP hbmMask, hbmColor;
662     ICONINFO info;
663     HICON hIcon;
664     GpStatus stat;
665     GpBitmap *bitmap = NULL;
666     UINT dim;
667     ImageType type;
668     PixelFormat format;
669
670     /* NULL */
671     stat = GdipCreateBitmapFromHICON(NULL, NULL);
672     expect(InvalidParameter, stat);
673     stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
674     expect(InvalidParameter, stat);
675
676     /* color icon 1 bit */
677     hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
678     ok(hbmMask != 0, "CreateBitmap failed\n");
679     hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
680     ok(hbmColor != 0, "CreateBitmap failed\n");
681     info.fIcon = TRUE;
682     info.xHotspot = 8;
683     info.yHotspot = 8;
684     info.hbmMask = hbmMask;
685     info.hbmColor = hbmColor;
686     hIcon = CreateIconIndirect(&info);
687     ok(hIcon != 0, "CreateIconIndirect failed\n");
688     DeleteObject(hbmMask);
689     DeleteObject(hbmColor);
690
691     stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
692     ok(stat == Ok ||
693        broken(stat == InvalidParameter), /* Win98 */
694        "Expected Ok, got %.8x\n", stat);
695     if(stat == Ok){
696        /* check attributes */
697        stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
698        expect(Ok, stat);
699        expect(16, dim);
700        stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
701        expect(Ok, stat);
702        expect(16, dim);
703        stat = GdipGetImageType((GpImage*)bitmap, &type);
704        expect(Ok, stat);
705        expect(ImageTypeBitmap, type);
706        stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
707        expect(PixelFormat32bppARGB, format);
708        /* raw format */
709        expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
710        GdipDisposeImage((GpImage*)bitmap);
711     }
712     DestroyIcon(hIcon);
713
714     /* color icon 8 bpp */
715     hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
716     ok(hbmMask != 0, "CreateBitmap failed\n");
717     hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
718     ok(hbmColor != 0, "CreateBitmap failed\n");
719     info.fIcon = TRUE;
720     info.xHotspot = 8;
721     info.yHotspot = 8;
722     info.hbmMask = hbmMask;
723     info.hbmColor = hbmColor;
724     hIcon = CreateIconIndirect(&info);
725     ok(hIcon != 0, "CreateIconIndirect failed\n");
726     DeleteObject(hbmMask);
727     DeleteObject(hbmColor);
728
729     stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
730     expect(Ok, stat);
731     if(stat == Ok){
732         /* check attributes */
733         stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
734         expect(Ok, stat);
735         expect(16, dim);
736         stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
737         expect(Ok, stat);
738         expect(16, dim);
739         stat = GdipGetImageType((GpImage*)bitmap, &type);
740         expect(Ok, stat);
741         expect(ImageTypeBitmap, type);
742         stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
743         expect(PixelFormat32bppARGB, format);
744         /* raw format */
745         expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
746         GdipDisposeImage((GpImage*)bitmap);
747     }
748     DestroyIcon(hIcon);
749 }
750
751 /* 1x1 pixel png */
752 static const unsigned char pngimage[285] = {
753 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
754 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
755 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
756 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
757 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
758 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
759 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
760 };
761 /* 1x1 pixel gif */
762 static const unsigned char gifimage[35] = {
763 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
764 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
765 0x01,0x00,0x3b
766 };
767 /* 1x1 pixel bmp */
768 static const unsigned char bmpimage[66] = {
769 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
770 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
771 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
772 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
773 0x00,0x00
774 };
775 /* 1x1 pixel jpg */
776 static const unsigned char jpgimage[285] = {
777 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
778 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
779 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
780 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
781 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
782 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
783 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,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,0x1e,0x1e,
786 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
787 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
788 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
789 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
790 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
791 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
792 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
793 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
794 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
795 };
796 /* 320x320 twip wmf */
797 static const unsigned char wmfimage[180] = {
798 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
799 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
800 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
801 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
802 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
803 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
804 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
805 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
806 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
807 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
808 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
809 0x00,0x00,0x00,0x00
810 };
811 static void test_getrawformat(void)
812 {
813     test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG,  __LINE__, FALSE);
814     test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF,  __LINE__, FALSE);
815     test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP,  __LINE__, FALSE);
816     test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
817     test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
818 }
819
820 static void test_loadwmf(void)
821 {
822     LPSTREAM stream;
823     HGLOBAL  hglob;
824     LPBYTE   data;
825     HRESULT  hres;
826     GpStatus stat;
827     GpImage *img;
828     GpRectF bounds;
829     GpUnit unit;
830     REAL res = 12345.0;
831
832     hglob = GlobalAlloc (0, sizeof(wmfimage));
833     data = GlobalLock (hglob);
834     memcpy(data, wmfimage, sizeof(wmfimage));
835     GlobalUnlock(hglob); data = NULL;
836
837     hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
838     ok(hres == S_OK, "Failed to create a stream\n");
839     if(hres != S_OK) return;
840
841     stat = GdipLoadImageFromStream(stream, &img);
842     ok(stat == Ok, "Failed to create a Bitmap\n");
843     if(stat != Ok){
844         IStream_Release(stream);
845         return;
846     }
847
848     IStream_Release(stream);
849
850     stat = GdipGetImageBounds(img, &bounds, &unit);
851     expect(Ok, stat);
852     todo_wine expect(UnitPixel, unit);
853     expectf(0.0, bounds.X);
854     expectf(0.0, bounds.Y);
855     todo_wine expectf(320.0, bounds.Width);
856     todo_wine expectf(320.0, bounds.Height);
857
858     stat = GdipGetImageHorizontalResolution(img, &res);
859     expect(Ok, stat);
860     todo_wine expectf(1440.0, res);
861
862     stat = GdipGetImageVerticalResolution(img, &res);
863     expect(Ok, stat);
864     todo_wine expectf(1440.0, res);
865
866     GdipDisposeImage(img);
867 }
868
869 static void test_createfromwmf(void)
870 {
871     HMETAFILE hwmf;
872     GpImage *img;
873     GpStatus stat;
874     GpRectF bounds;
875     GpUnit unit;
876     REAL res = 12345.0;
877
878     hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
879         wmfimage+sizeof(WmfPlaceableFileHeader));
880     ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
881
882     stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
883         (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
884     expect(Ok, stat);
885
886     stat = GdipGetImageBounds(img, &bounds, &unit);
887     expect(Ok, stat);
888     todo_wine expect(UnitPixel, unit);
889     expectf(0.0, bounds.X);
890     expectf(0.0, bounds.Y);
891     todo_wine expectf(320.0, bounds.Width);
892     todo_wine expectf(320.0, bounds.Height);
893
894     stat = GdipGetImageHorizontalResolution(img, &res);
895     expect(Ok, stat);
896     expectf(1440.0, res);
897
898     stat = GdipGetImageVerticalResolution(img, &res);
899     expect(Ok, stat);
900     expectf(1440.0, res);
901
902     GdipDisposeImage(img);
903 }
904
905 static void test_resolution(void)
906 {
907     GpStatus stat;
908     GpBitmap *bitmap;
909     REAL res=-1.0;
910     HDC screendc;
911     int screenxres, screenyres;
912
913     /* create Bitmap */
914     stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
915     expect(Ok, stat);
916
917     /* test invalid values */
918     stat = GdipGetImageHorizontalResolution(NULL, &res);
919     expect(InvalidParameter, stat);
920
921     stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
922     expect(InvalidParameter, stat);
923
924     stat = GdipGetImageVerticalResolution(NULL, &res);
925     expect(InvalidParameter, stat);
926
927     stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
928     expect(InvalidParameter, stat);
929
930     stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
931     expect(InvalidParameter, stat);
932
933     stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
934     expect(InvalidParameter, stat);
935
936     /* defaults to screen resolution */
937     screendc = GetDC(0);
938
939     screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
940     screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
941
942     ReleaseDC(0, screendc);
943
944     stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
945     expect(Ok, stat);
946     expectf((REAL)screenxres, res);
947
948     stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
949     expect(Ok, stat);
950     expectf((REAL)screenyres, res);
951
952     /* test changing the resolution */
953     stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
954     expect(Ok, stat);
955
956     stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
957     expect(Ok, stat);
958     expectf(screenxres*2.0, res);
959
960     stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
961     expect(Ok, stat);
962     expectf(screenyres*3.0, res);
963
964     stat = GdipDisposeImage((GpImage*)bitmap);
965     expect(Ok, stat);
966 }
967
968 static void test_createhbitmap(void)
969 {
970     GpStatus stat;
971     GpBitmap *bitmap;
972     HBITMAP hbitmap, oldhbitmap;
973     BITMAP bm;
974     int ret;
975     HDC hdc;
976     COLORREF pixel;
977     BYTE bits[640];
978
979     memset(bits, 0x68, 640);
980
981     /* create Bitmap */
982     stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
983     expect(Ok, stat);
984
985     /* test NULL values */
986     stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
987     expect(InvalidParameter, stat);
988
989     stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
990     expect(InvalidParameter, stat);
991
992     /* create HBITMAP */
993     stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
994     expect(Ok, stat);
995
996     if (stat == Ok)
997     {
998         ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
999         expect(sizeof(BITMAP), ret);
1000
1001         expect(0, bm.bmType);
1002         expect(10, bm.bmWidth);
1003         expect(20, bm.bmHeight);
1004         expect(40, bm.bmWidthBytes);
1005         expect(1, bm.bmPlanes);
1006         expect(32, bm.bmBitsPixel);
1007         ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1008
1009         hdc = CreateCompatibleDC(NULL);
1010
1011         oldhbitmap = SelectObject(hdc, hbitmap);
1012         pixel = GetPixel(hdc, 5, 5);
1013         SelectObject(hdc, oldhbitmap);
1014
1015         DeleteDC(hdc);
1016
1017         expect(0x686868, pixel);
1018
1019         DeleteObject(hbitmap);
1020     }
1021
1022     stat = GdipDisposeImage((GpImage*)bitmap);
1023     expect(Ok, stat);
1024 }
1025
1026 static void test_getsetpixel(void)
1027 {
1028     GpStatus stat;
1029     GpBitmap *bitmap;
1030     ARGB color;
1031     BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1032                      0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1033
1034     stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1035     expect(Ok, stat);
1036
1037     /* null parameters */
1038     stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1039     expect(InvalidParameter, stat);
1040
1041     stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1042     expect(InvalidParameter, stat);
1043
1044     stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1045     expect(InvalidParameter, stat);
1046
1047     /* out of bounds */
1048     stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1049     expect(InvalidParameter, stat);
1050
1051     stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1052     expect(InvalidParameter, stat);
1053
1054     stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1055     ok(stat == InvalidParameter ||
1056        broken(stat == Ok), /* Older gdiplus */
1057        "Expected InvalidParameter, got %.8x\n", stat);
1058
1059     stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1060     ok(stat == InvalidParameter ||
1061        broken(stat == Ok), /* Older gdiplus */
1062        "Expected InvalidParameter, got %.8x\n", stat);
1063
1064     stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1065     expect(InvalidParameter, stat);
1066
1067     stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1068     expect(InvalidParameter, stat);
1069
1070     stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1071     expect(InvalidParameter, stat);
1072
1073     stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1074     expect(InvalidParameter, stat);
1075
1076     /* valid use */
1077     stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1078     expect(Ok, stat);
1079     expect(0xffffffff, color);
1080
1081     stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1082     expect(Ok, stat);
1083     expect(0xff0000ff, color);
1084
1085     stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1086     expect(Ok, stat);
1087
1088     stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1089     expect(Ok, stat);
1090
1091     stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1092     expect(Ok, stat);
1093     expect(0xff676869, color);
1094
1095     stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1096     expect(Ok, stat);
1097     expect(0xff474849, color);
1098
1099     stat = GdipDisposeImage((GpImage*)bitmap);
1100     expect(Ok, stat);
1101 }
1102
1103 static void check_halftone_palette(ColorPalette *palette)
1104 {
1105     static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1106     UINT i;
1107
1108     for (i=0; i<palette->Count; i++)
1109     {
1110         ARGB expected=0xff000000;
1111         if (i<8)
1112         {
1113             if (i&1) expected |= 0x800000;
1114             if (i&2) expected |= 0x8000;
1115             if (i&4) expected |= 0x80;
1116         }
1117         else if (i == 8)
1118         {
1119             expected = 0xffc0c0c0;
1120         }
1121         else if (i < 16)
1122         {
1123             if (i&1) expected |= 0xff0000;
1124             if (i&2) expected |= 0xff00;
1125             if (i&4) expected |= 0xff;
1126         }
1127         else if (i < 40)
1128         {
1129             expected = 0x00000000;
1130         }
1131         else
1132         {
1133             expected |= halftone_values[(i-40)%6];
1134             expected |= halftone_values[((i-40)/6)%6] << 8;
1135             expected |= halftone_values[((i-40)/36)%6] << 16;
1136         }
1137         ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1138             expected, palette->Entries[i], i, palette->Count);
1139     }
1140 }
1141
1142 static void test_palette(void)
1143 {
1144     GpStatus stat;
1145     GpBitmap *bitmap;
1146     INT size;
1147     BYTE buffer[1040];
1148     ColorPalette *palette=(ColorPalette*)buffer;
1149     ARGB color=0;
1150
1151     /* test initial palette from non-indexed bitmap */
1152     stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1153     expect(Ok, stat);
1154
1155     stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1156     expect(Ok, stat);
1157     expect(sizeof(UINT)*2+sizeof(ARGB), size);
1158
1159     stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1160     expect(Ok, stat);
1161     expect(0, palette->Count);
1162
1163     /* test setting palette on not-indexed bitmap */
1164     palette->Count = 3;
1165
1166     stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1167     expect(Ok, stat);
1168
1169     stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1170     expect(Ok, stat);
1171     expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1172
1173     stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1174     expect(Ok, stat);
1175     expect(3, palette->Count);
1176
1177     GdipDisposeImage((GpImage*)bitmap);
1178
1179     /* test initial palette on 1-bit bitmap */
1180     stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1181     expect(Ok, stat);
1182
1183     stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1184     expect(Ok, stat);
1185     expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1186
1187     stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1188     expect(Ok, stat);
1189     expect(PaletteFlagsGrayScale, palette->Flags);
1190     expect(2, palette->Count);
1191
1192     expect(0xff000000, palette->Entries[0]);
1193     expect(0xffffffff, palette->Entries[1]);
1194
1195     /* test getting/setting pixels */
1196     stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1197     expect(Ok, stat);
1198     expect(0xff000000, color);
1199
1200     stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1201     todo_wine ok((stat == Ok) ||
1202        broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1203
1204     if (stat == Ok)
1205     {
1206         stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1207         expect(Ok, stat);
1208         expect(0xffffffff, color);
1209     }
1210
1211     GdipDisposeImage((GpImage*)bitmap);
1212
1213     /* test initial palette on 4-bit bitmap */
1214     stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1215     expect(Ok, stat);
1216
1217     stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1218     expect(Ok, stat);
1219     expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1220
1221     stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1222     expect(Ok, stat);
1223     expect(0, palette->Flags);
1224     expect(16, palette->Count);
1225
1226     check_halftone_palette(palette);
1227
1228     /* test getting/setting pixels */
1229     stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1230     expect(Ok, stat);
1231     expect(0xff000000, color);
1232
1233     stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
1234     todo_wine ok((stat == Ok) ||
1235        broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1236
1237     if (stat == Ok)
1238     {
1239         stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1240         expect(Ok, stat);
1241         expect(0xffff00ff, color);
1242     }
1243
1244     GdipDisposeImage((GpImage*)bitmap);
1245
1246     /* test initial palette on 8-bit bitmap */
1247     stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1248     expect(Ok, stat);
1249
1250     stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1251     expect(Ok, stat);
1252     expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1253
1254     stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1255     expect(Ok, stat);
1256     expect(PaletteFlagsHalftone, palette->Flags);
1257     expect(256, palette->Count);
1258
1259     check_halftone_palette(palette);
1260
1261     /* test getting/setting pixels */
1262     stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1263     expect(Ok, stat);
1264     expect(0xff000000, color);
1265
1266     stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
1267     todo_wine ok((stat == Ok) ||
1268        broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1269
1270     if (stat == Ok)
1271     {
1272         stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1273         expect(Ok, stat);
1274         expect(0xffcccccc, color);
1275     }
1276
1277     /* test setting/getting a different palette */
1278     palette->Entries[1] = 0xffcccccc;
1279
1280     stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1281     expect(Ok, stat);
1282
1283     palette->Entries[1] = 0;
1284
1285     stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1286     expect(Ok, stat);
1287     expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1288
1289     stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1290     expect(Ok, stat);
1291     expect(PaletteFlagsHalftone, palette->Flags);
1292     expect(256, palette->Count);
1293     expect(0xffcccccc, palette->Entries[1]);
1294
1295     /* test count < 256 */
1296     palette->Flags = 12345;
1297     palette->Count = 3;
1298
1299     stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1300     expect(Ok, stat);
1301
1302     palette->Entries[1] = 0;
1303     palette->Entries[3] = 0xdeadbeef;
1304
1305     stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1306     expect(Ok, stat);
1307     expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1308
1309     stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1310     expect(Ok, stat);
1311     expect(12345, palette->Flags);
1312     expect(3, palette->Count);
1313     expect(0xffcccccc, palette->Entries[1]);
1314     expect(0xdeadbeef, palette->Entries[3]);
1315
1316     /* test count > 256 */
1317     palette->Count = 257;
1318
1319     stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1320     ok(stat == InvalidParameter ||
1321        broken(stat == Ok), /* Old gdiplus behavior */
1322        "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1323
1324     GdipDisposeImage((GpImage*)bitmap);
1325 }
1326
1327 static void test_colormatrix(void)
1328 {
1329     GpStatus stat;
1330     ColorMatrix colormatrix, graymatrix;
1331     GpImageAttributes *imageattr;
1332     const ColorMatrix identity = {{
1333         {1.0,0.0,0.0,0.0,0.0},
1334         {0.0,1.0,0.0,0.0,0.0},
1335         {0.0,0.0,1.0,0.0,0.0},
1336         {0.0,0.0,0.0,1.0,0.0},
1337         {0.0,0.0,0.0,0.0,1.0}}};
1338     const ColorMatrix double_red = {{
1339         {2.0,0.0,0.0,0.0,0.0},
1340         {0.0,1.0,0.0,0.0,0.0},
1341         {0.0,0.0,1.0,0.0,0.0},
1342         {0.0,0.0,0.0,1.0,0.0},
1343         {0.0,0.0,0.0,0.0,1.0}}};
1344     GpBitmap *bitmap1, *bitmap2;
1345     GpGraphics *graphics;
1346     ARGB color;
1347
1348     colormatrix = identity;
1349     graymatrix = identity;
1350
1351     stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
1352         TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1353     expect(InvalidParameter, stat);
1354
1355     stat = GdipCreateImageAttributes(&imageattr);
1356     expect(Ok, stat);
1357
1358     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1359         TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1360     expect(Ok, stat);
1361
1362     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1363         TRUE, NULL, NULL, ColorMatrixFlagsDefault);
1364     expect(InvalidParameter, stat);
1365
1366     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1367         TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1368     expect(Ok, stat);
1369
1370     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1371         TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
1372     expect(Ok, stat);
1373
1374     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1375         TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
1376     expect(InvalidParameter, stat);
1377
1378     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1379         TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
1380     expect(Ok, stat);
1381
1382     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1383         TRUE, &colormatrix, &graymatrix, 3);
1384     expect(InvalidParameter, stat);
1385
1386     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
1387         TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1388     expect(InvalidParameter, stat);
1389
1390     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
1391         TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1392     expect(InvalidParameter, stat);
1393
1394     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1395         FALSE, NULL, NULL, ColorMatrixFlagsDefault);
1396     expect(Ok, stat);
1397
1398     /* Drawing a bitmap transforms the colors */
1399     colormatrix = double_red;
1400     stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1401         TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1402     expect(Ok, stat);
1403
1404     stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1405     expect(Ok, stat);
1406
1407     stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1408     expect(Ok, stat);
1409
1410     stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ffff);
1411     expect(Ok, stat);
1412
1413     stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1414     expect(Ok, stat);
1415
1416     stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1417         UnitPixel, imageattr, NULL, NULL);
1418     expect(Ok, stat);
1419
1420     stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1421     expect(Ok, stat);
1422     todo_wine expect(0xff80ffff, color);
1423
1424     GdipDeleteGraphics(graphics);
1425     GdipDisposeImage((GpImage*)bitmap1);
1426     GdipDisposeImage((GpImage*)bitmap2);
1427     GdipDisposeImageAttributes(imageattr);
1428 }
1429
1430 static void test_gamma(void)
1431 {
1432     GpStatus stat;
1433     GpImageAttributes *imageattr;
1434     GpBitmap *bitmap1, *bitmap2;
1435     GpGraphics *graphics;
1436     ARGB color;
1437
1438     stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
1439     expect(InvalidParameter, stat);
1440
1441     stat = GdipCreateImageAttributes(&imageattr);
1442     expect(Ok, stat);
1443
1444     stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
1445     expect(Ok, stat);
1446
1447     stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
1448     expect(InvalidParameter, stat);
1449
1450     stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
1451     expect(InvalidParameter, stat);
1452
1453     stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
1454     expect(InvalidParameter, stat);
1455
1456     stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
1457     expect(Ok, stat);
1458
1459     stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
1460     expect(Ok, stat);
1461
1462     /* Drawing a bitmap transforms the colors */
1463     stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
1464     expect(Ok, stat);
1465
1466     stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1467     expect(Ok, stat);
1468
1469     stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1470     expect(Ok, stat);
1471
1472     stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
1473     expect(Ok, stat);
1474
1475     stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1476     expect(Ok, stat);
1477
1478     stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1479         UnitPixel, imageattr, NULL, NULL);
1480     expect(Ok, stat);
1481
1482     stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1483     expect(Ok, stat);
1484     todo_wine ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
1485
1486     GdipDeleteGraphics(graphics);
1487     GdipDisposeImage((GpImage*)bitmap1);
1488     GdipDisposeImage((GpImage*)bitmap2);
1489     GdipDisposeImageAttributes(imageattr);
1490 }
1491
1492 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
1493 static const unsigned char gifanimation[72] = {
1494 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1495 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
1496 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
1497 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
1498 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
1499 };
1500
1501 static void test_multiframegif(void)
1502 {
1503     LPSTREAM stream;
1504     HGLOBAL hglob;
1505     LPBYTE data;
1506     HRESULT hres;
1507     GpStatus stat;
1508     GpBitmap *bmp;
1509     ARGB color;
1510     UINT count;
1511     GUID dimension;
1512
1513     /* Test frame functions with an animated GIF */
1514     hglob = GlobalAlloc (0, sizeof(gifanimation));
1515     data = GlobalLock (hglob);
1516     memcpy(data, gifanimation, sizeof(gifanimation));
1517     GlobalUnlock(hglob);
1518
1519     hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1520     ok(hres == S_OK, "Failed to create a stream\n");
1521     if(hres != S_OK) return;
1522
1523     stat = GdipCreateBitmapFromStream(stream, &bmp);
1524     ok(stat == Ok, "Failed to create a Bitmap\n");
1525     if(stat != Ok){
1526         IStream_Release(stream);
1527         return;
1528     }
1529
1530     /* Bitmap starts at frame 0 */
1531     color = 0xdeadbeef;
1532     stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1533     expect(Ok, stat);
1534     expect(0xffffffff, color);
1535
1536     /* Check that we get correct metadata */
1537     stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1538     expect(Ok, stat);
1539     expect(1, count);
1540
1541     stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1542     expect(Ok, stat);
1543     expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1544
1545     count = 12345;
1546     stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1547     todo_wine expect(Ok, stat);
1548     todo_wine expect(2, count);
1549
1550     /* SelectActiveFrame overwrites our current data */
1551     stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1552     expect(Ok, stat);
1553
1554     color = 0xdeadbeef;
1555     GdipBitmapGetPixel(bmp, 0, 0, &color);
1556     expect(Ok, stat);
1557     todo_wine expect(0xff000000, color);
1558
1559     stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1560     expect(Ok, stat);
1561
1562     color = 0xdeadbeef;
1563     GdipBitmapGetPixel(bmp, 0, 0, &color);
1564     expect(Ok, stat);
1565     expect(0xffffffff, color);
1566
1567     /* Write over the image data */
1568     stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
1569     expect(Ok, stat);
1570
1571     /* Switching to the same frame does not overwrite our changes */
1572     stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1573     expect(Ok, stat);
1574
1575     stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1576     expect(Ok, stat);
1577     expect(0xff000000, color);
1578
1579     /* But switching to another frame and back does */
1580     stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1581     expect(Ok, stat);
1582
1583     stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1584     expect(Ok, stat);
1585
1586     stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1587     expect(Ok, stat);
1588     todo_wine expect(0xffffffff, color);
1589
1590     GdipDisposeImage((GpImage*)bmp);
1591     IStream_Release(stream);
1592
1593     /* Test with a non-animated gif */
1594     hglob = GlobalAlloc (0, sizeof(gifimage));
1595     data = GlobalLock (hglob);
1596     memcpy(data, gifimage, sizeof(gifimage));
1597     GlobalUnlock(hglob);
1598
1599     hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1600     ok(hres == S_OK, "Failed to create a stream\n");
1601     if(hres != S_OK) return;
1602
1603     stat = GdipCreateBitmapFromStream(stream, &bmp);
1604     ok(stat == Ok, "Failed to create a Bitmap\n");
1605     if(stat != Ok){
1606         IStream_Release(stream);
1607         return;
1608     }
1609
1610     /* Check metadata */
1611     stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1612     expect(Ok, stat);
1613     expect(1, count);
1614
1615     stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1616     expect(Ok, stat);
1617     expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1618
1619     count = 12345;
1620     stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1621     todo_wine expect(Ok, stat);
1622     todo_wine expect(1, count);
1623
1624     GdipDisposeImage((GpImage*)bmp);
1625     IStream_Release(stream);
1626 }
1627
1628 static void test_rotateflip(void)
1629 {
1630     GpImage *bitmap;
1631     GpStatus stat;
1632     BYTE bits[24];
1633     static const BYTE orig_bits[24] = {
1634         0,0,0xff,    0,0xff,0,    0xff,0,0,    23,23,23,
1635         0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
1636     UINT width, height;
1637     ARGB color;
1638
1639     memcpy(bits, orig_bits, sizeof(bits));
1640     stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1641     expect(Ok, stat);
1642
1643     stat = GdipImageRotateFlip(bitmap, Rotate90FlipNone);
1644     todo_wine expect(Ok, stat);
1645
1646     stat = GdipGetImageWidth(bitmap, &width);
1647     expect(Ok, stat);
1648     stat = GdipGetImageHeight(bitmap, &height);
1649     expect(Ok, stat);
1650     todo_wine expect(2, width);
1651     todo_wine expect(3, height);
1652
1653     stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1654     expect(Ok, stat);
1655     todo_wine expect(0xff00ffff, color);
1656
1657     stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 0, &color);
1658     expect(Ok, stat);
1659     todo_wine expect(0xffff0000, color);
1660
1661     stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 2, &color);
1662     todo_wine expect(Ok, stat);
1663     todo_wine expect(0xffffff00, color);
1664
1665     stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 2, &color);
1666     todo_wine expect(Ok, stat);
1667     todo_wine expect(0xff0000ff, color);
1668
1669     expect(0, bits[0]);
1670     expect(0, bits[1]);
1671     expect(0xff, bits[2]);
1672
1673     GdipDisposeImage(bitmap);
1674
1675     memcpy(bits, orig_bits, sizeof(bits));
1676     stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1677     expect(Ok, stat);
1678
1679     stat = GdipImageRotateFlip(bitmap, RotateNoneFlipX);
1680     todo_wine expect(Ok, stat);
1681
1682     stat = GdipGetImageWidth(bitmap, &width);
1683     expect(Ok, stat);
1684     stat = GdipGetImageHeight(bitmap, &height);
1685     expect(Ok, stat);
1686     expect(3, width);
1687     expect(2, height);
1688
1689     stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1690     expect(Ok, stat);
1691     todo_wine expect(0xff0000ff, color);
1692
1693     stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
1694     expect(Ok, stat);
1695     todo_wine expect(0xffff0000, color);
1696
1697     stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
1698     expect(Ok, stat);
1699     todo_wine expect(0xffffff00, color);
1700
1701     stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
1702     expect(Ok, stat);
1703     todo_wine expect(0xff00ffff, color);
1704
1705     expect(0, bits[0]);
1706     expect(0, bits[1]);
1707     expect(0xff, bits[2]);
1708
1709     GdipDisposeImage(bitmap);
1710
1711     memcpy(bits, orig_bits, sizeof(bits));
1712     stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1713     expect(Ok, stat);
1714
1715     stat = GdipImageRotateFlip(bitmap, RotateNoneFlipY);
1716     todo_wine expect(Ok, stat);
1717
1718     stat = GdipGetImageWidth(bitmap, &width);
1719     expect(Ok, stat);
1720     stat = GdipGetImageHeight(bitmap, &height);
1721     expect(Ok, stat);
1722     expect(3, width);
1723     expect(2, height);
1724
1725     stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1726     expect(Ok, stat);
1727     todo_wine expect(0xff00ffff, color);
1728
1729     stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
1730     expect(Ok, stat);
1731     todo_wine expect(0xffffff00, color);
1732
1733     stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
1734     expect(Ok, stat);
1735     todo_wine expect(0xffff0000, color);
1736
1737     stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
1738     expect(Ok, stat);
1739     todo_wine expect(0xff0000ff, color);
1740
1741     expect(0, bits[0]);
1742     expect(0, bits[1]);
1743     expect(0xff, bits[2]);
1744
1745     GdipDisposeImage(bitmap);
1746 }
1747
1748 START_TEST(image)
1749 {
1750     struct GdiplusStartupInput gdiplusStartupInput;
1751     ULONG_PTR gdiplusToken;
1752
1753     gdiplusStartupInput.GdiplusVersion              = 1;
1754     gdiplusStartupInput.DebugEventCallback          = NULL;
1755     gdiplusStartupInput.SuppressBackgroundThread    = 0;
1756     gdiplusStartupInput.SuppressExternalCodecs      = 0;
1757
1758     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1759
1760     test_Scan0();
1761     test_GetImageDimension();
1762     test_GdipImageGetFrameDimensionsCount();
1763     test_LoadingImages();
1764     test_SavingImages();
1765     test_encoders();
1766     test_LockBits();
1767     test_GdipCreateBitmapFromHBITMAP();
1768     test_GdipGetImageFlags();
1769     test_GdipCloneImage();
1770     test_testcontrol();
1771     test_fromhicon();
1772     test_getrawformat();
1773     test_loadwmf();
1774     test_createfromwmf();
1775     test_resolution();
1776     test_createhbitmap();
1777     test_getsetpixel();
1778     test_palette();
1779     test_colormatrix();
1780     test_gamma();
1781     test_multiframegif();
1782     test_rotateflip();
1783
1784     GdiplusShutdown(gdiplusToken);
1785 }