winejoystick.drv: Use CP_UNIXCP instead of CP_ACP when converting a string that comes...
[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 void expect_rawformat(REFGUID expected, GpImage *img, int line, BOOL todo)
34 {
35     GUID raw;
36     WCHAR bufferW[39];
37     char buffer[39];
38     char buffer2[39];
39     GpStatus stat;
40
41     stat = GdipGetImageRawFormat(img, &raw);
42     ok_(__FILE__, line)(stat == Ok, "GdipGetImageRawFormat failed with %d\n", stat);
43     if(stat != Ok) return;
44     StringFromGUID2(&raw, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
45     WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer, sizeof(buffer), NULL, NULL);
46     StringFromGUID2(expected, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
47     WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer2, sizeof(buffer2), NULL, NULL);
48     if(todo)
49         todo_wine ok_(__FILE__, line)(IsEqualGUID(&raw, expected), "Expected format %s, got %s\n", buffer2, buffer);
50     else
51         ok_(__FILE__, line)(IsEqualGUID(&raw, expected), "Expected format %s, got %s\n", buffer2, buffer);
52 }
53
54 static void test_bufferrawformat(void* buff, int size, REFGUID expected, int line, BOOL todo)
55 {
56     LPSTREAM stream;
57     HGLOBAL  hglob;
58     LPBYTE   data;
59     HRESULT  hres;
60     GpStatus stat;
61     GpBitmap *bmp;
62
63     hglob = GlobalAlloc (0, size);
64     data = GlobalLock (hglob);
65     memcpy(data, buff, size);
66     GlobalUnlock(hglob); data = NULL;
67
68     hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
69     ok_(__FILE__, line)(hres == S_OK, "Failed to create a stream\n");
70     if(hres != S_OK) return;
71
72     stat = GdipCreateBitmapFromStream(stream, &bmp);
73     ok_(__FILE__, line)(stat == Ok, "Failed to create a Bitmap\n");
74     if(stat != Ok){
75         IStream_Release(stream);
76         return;
77     }
78
79     expect_rawformat(expected, (GpImage*)bmp, line, todo);
80
81     GdipDisposeImage((GpImage*)bmp);
82     IStream_Release(stream);
83 }
84
85 static void test_Scan0(void)
86 {
87     GpBitmap *bm;
88     GpStatus stat;
89     BYTE buff[360];
90
91     bm = NULL;
92     stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
93     expect(Ok, stat);
94     ok(NULL != bm, "Expected bitmap to be initialized\n");
95     if (stat == Ok)
96         GdipDisposeImage((GpImage*)bm);
97
98     bm = (GpBitmap*)0xdeadbeef;
99     stat = GdipCreateBitmapFromScan0(10, -10, 10, PixelFormat24bppRGB, NULL, &bm);
100     expect(InvalidParameter, stat);
101     ok( !bm, "expected null bitmap\n" );
102
103     bm = (GpBitmap*)0xdeadbeef;
104     stat = GdipCreateBitmapFromScan0(-10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
105     expect(InvalidParameter, stat);
106     ok( !bm, "expected null bitmap\n" );
107
108     bm = (GpBitmap*)0xdeadbeef;
109     stat = GdipCreateBitmapFromScan0(10, 0, 10, PixelFormat24bppRGB, NULL, &bm);
110     expect(InvalidParameter, stat);
111     ok( !bm, "expected null bitmap\n" );
112
113     bm = NULL;
114     stat = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, buff, &bm);
115     expect(Ok, stat);
116     ok(NULL != bm, "Expected bitmap to be initialized\n");
117     if (stat == Ok)
118         GdipDisposeImage((GpImage*)bm);
119
120     bm = (GpBitmap*) 0xdeadbeef;
121     stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, buff, &bm);
122     expect(InvalidParameter, stat);
123     ok( !bm, "expected null bitmap\n" );
124
125     bm = (GpBitmap*)0xdeadbeef;
126     stat = GdipCreateBitmapFromScan0(10, 10, 0, PixelFormat24bppRGB, buff, &bm);
127     expect(InvalidParameter, stat);
128     ok( bm == (GpBitmap*)0xdeadbeef, "expected deadbeef bitmap\n" );
129
130     bm = NULL;
131     stat = GdipCreateBitmapFromScan0(10, 10, -8, PixelFormat24bppRGB, buff, &bm);
132     expect(Ok, stat);
133     ok(NULL != bm, "Expected bitmap to be initialized\n");
134     if (stat == Ok)
135         GdipDisposeImage((GpImage*)bm);
136
137     bm = (GpBitmap*)0xdeadbeef;
138     stat = GdipCreateBitmapFromScan0(10, 10, -10, PixelFormat24bppRGB, buff, &bm);
139     expect(InvalidParameter, stat);
140     ok( !bm, "expected null bitmap\n" );
141 }
142
143 static void test_GetImageDimension(void)
144 {
145     GpBitmap *bm;
146     GpStatus stat;
147     const REAL WIDTH = 10.0, HEIGHT = 20.0;
148     REAL w,h;
149
150     bm = (GpBitmap*)0xdeadbeef;
151     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
152     expect(Ok,stat);
153     ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
154     ok(NULL != bm, "Expected bitmap to not be NULL\n");
155
156     stat = GdipGetImageDimension(NULL,&w,&h);
157     expect(InvalidParameter, stat);
158
159     stat = GdipGetImageDimension((GpImage*)bm,NULL,&h);
160     expect(InvalidParameter, stat);
161
162     stat = GdipGetImageDimension((GpImage*)bm,&w,NULL);
163     expect(InvalidParameter, stat);
164
165     w = -1;
166     h = -1;
167     stat = GdipGetImageDimension((GpImage*)bm,&w,&h);
168     expect(Ok, stat);
169     expectf(WIDTH,  w);
170     expectf(HEIGHT, h);
171     GdipDisposeImage((GpImage*)bm);
172 }
173
174 static void test_GdipImageGetFrameDimensionsCount(void)
175 {
176     GpBitmap *bm;
177     GpStatus stat;
178     const REAL WIDTH = 10.0, HEIGHT = 20.0;
179     UINT w;
180
181     bm = (GpBitmap*)0xdeadbeef;
182     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
183     expect(Ok,stat);
184     ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
185     ok(NULL != bm, "Expected bitmap to not be NULL\n");
186
187     stat = GdipImageGetFrameDimensionsCount(NULL,&w);
188     expect(InvalidParameter, stat);
189
190     stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,NULL);
191     expect(InvalidParameter, stat);
192
193     w = -1;
194     stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,&w);
195     expect(Ok, stat);
196     expect(1, w);
197     GdipDisposeImage((GpImage*)bm);
198 }
199
200 static void test_LoadingImages(void)
201 {
202     GpStatus stat;
203
204     stat = GdipCreateBitmapFromFile(0, 0);
205     expect(InvalidParameter, stat);
206
207     stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
208     expect(InvalidParameter, stat);
209
210     stat = GdipLoadImageFromFile(0, 0);
211     expect(InvalidParameter, stat);
212
213     stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
214     expect(InvalidParameter, stat);
215
216     stat = GdipLoadImageFromFileICM(0, 0);
217     expect(InvalidParameter, stat);
218
219     stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
220     expect(InvalidParameter, stat);
221 }
222
223 static void test_SavingImages(void)
224 {
225     GpStatus stat;
226     GpBitmap *bm;
227     UINT n;
228     UINT s;
229     const REAL WIDTH = 10.0, HEIGHT = 20.0;
230     REAL w, h;
231     ImageCodecInfo *codecs;
232     static const WCHAR filename[] = { 'a','.','b','m','p',0 };
233
234     codecs = NULL;
235
236     stat = GdipSaveImageToFile(0, 0, 0, 0);
237     expect(InvalidParameter, stat);
238
239     bm = NULL;
240     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
241     expect(Ok, stat);
242     if (!bm)
243         return;
244
245     /* invalid params */
246     stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
247     expect(InvalidParameter, stat);
248
249     stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
250     expect(InvalidParameter, stat);
251
252     /* encoder tests should succeed -- already tested */
253     stat = GdipGetImageEncodersSize(&n, &s);
254     if (stat != Ok || n == 0) goto cleanup;
255
256     codecs = GdipAlloc(s);
257     if (!codecs) goto cleanup;
258
259     stat = GdipGetImageEncoders(n, s, codecs);
260     if (stat != Ok) goto cleanup;
261
262     stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
263     expect(stat, Ok);
264
265     GdipDisposeImage((GpImage*)bm);
266     bm = 0;
267
268     /* re-load and check image stats */
269     stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
270     expect(stat, Ok);
271     if (stat != Ok) goto cleanup;
272
273     stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
274     if (stat != Ok) goto cleanup;
275
276     expectf(WIDTH, w);
277     expectf(HEIGHT, h);
278
279  cleanup:
280     GdipFree(codecs);
281     if (bm)
282         GdipDisposeImage((GpImage*)bm);
283     ok(DeleteFileW(filename), "Delete failed.\n");
284 }
285
286 static void test_encoders(void)
287 {
288     GpStatus stat;
289     UINT n;
290     UINT s;
291     ImageCodecInfo *codecs;
292     int i;
293     int bmp_found;
294
295     static const WCHAR bmp_format[] = {'B', 'M', 'P', 0};
296
297     stat = GdipGetImageEncodersSize(&n, &s);
298     expect(stat, Ok);
299
300     codecs = GdipAlloc(s);
301     if (!codecs)
302         return;
303
304     stat = GdipGetImageEncoders(n, s, NULL);
305     expect(GenericError, stat);
306
307     stat = GdipGetImageEncoders(0, s, codecs);
308     expect(GenericError, stat);
309
310     stat = GdipGetImageEncoders(n, s-1, codecs);
311     expect(GenericError, stat);
312
313     stat = GdipGetImageEncoders(n, s+1, codecs);
314     expect(GenericError, stat);
315
316     stat = GdipGetImageEncoders(n, s, codecs);
317     expect(stat, Ok);
318
319     bmp_found = FALSE;
320     for (i = 0; i < n; i++)
321         {
322             if (CompareStringW(LOCALE_SYSTEM_DEFAULT, 0,
323                                codecs[i].FormatDescription, -1,
324                                bmp_format, -1) == CSTR_EQUAL) {
325                 bmp_found = TRUE;
326                 break;
327             }
328         }
329     if (!bmp_found)
330         ok(FALSE, "No BMP codec found.\n");
331
332     GdipFree(codecs);
333 }
334
335 static void test_LockBits(void)
336 {
337     GpStatus stat;
338     GpBitmap *bm;
339     GpRect rect;
340     BitmapData bd;
341     const INT WIDTH = 10, HEIGHT = 20;
342
343     bm = NULL;
344     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
345     expect(Ok, stat);
346
347     rect.X = 2;
348     rect.Y = 3;
349     rect.Width = 4;
350     rect.Height = 5;
351
352     /* read-only */
353     stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
354     expect(Ok, stat);
355
356     if (stat == Ok) {
357         stat = GdipBitmapUnlockBits(bm, &bd);
358         expect(Ok, stat);
359     }
360
361     /* read-only, with NULL rect -> whole bitmap lock */
362     stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
363     expect(Ok, stat);
364     expect(bd.Width,  WIDTH);
365     expect(bd.Height, HEIGHT);
366
367     if (stat == Ok) {
368         stat = GdipBitmapUnlockBits(bm, &bd);
369         expect(Ok, stat);
370     }
371
372     /* read-only, consecutive */
373     stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
374     expect(Ok, stat);
375
376     if (stat == Ok) {
377         stat = GdipBitmapUnlockBits(bm, &bd);
378         expect(Ok, stat);
379     }
380
381     stat = GdipDisposeImage((GpImage*)bm);
382     expect(Ok, stat);
383     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
384     expect(Ok, stat);
385
386     /* read x2 */
387     stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
388     expect(Ok, stat);
389     stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
390     expect(WrongState, stat);
391
392     stat = GdipBitmapUnlockBits(bm, &bd);
393     expect(Ok, stat);
394
395     stat = GdipDisposeImage((GpImage*)bm);
396     expect(Ok, stat);
397     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
398     expect(Ok, stat);
399
400     /* write, no modification */
401     stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
402     expect(Ok, stat);
403
404     if (stat == Ok) {
405         stat = GdipBitmapUnlockBits(bm, &bd);
406         expect(Ok, stat);
407     }
408
409     /* write, consecutive */
410     stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
411     expect(Ok, stat);
412
413     if (stat == Ok) {
414         stat = GdipBitmapUnlockBits(bm, &bd);
415         expect(Ok, stat);
416     }
417
418     stat = GdipDisposeImage((GpImage*)bm);
419     expect(Ok, stat);
420     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
421     expect(Ok, stat);
422
423     /* write, modify */
424     stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
425     expect(Ok, stat);
426
427     if (stat == Ok) {
428         if (bd.Scan0)
429             ((char*)bd.Scan0)[2] = 0xff;
430
431         stat = GdipBitmapUnlockBits(bm, &bd);
432         expect(Ok, stat);
433     }
434
435     stat = GdipDisposeImage((GpImage*)bm);
436     expect(Ok, stat);
437
438     /* dispose locked */
439     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
440     expect(Ok, stat);
441     stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
442     expect(Ok, stat);
443     stat = GdipDisposeImage((GpImage*)bm);
444     expect(Ok, stat);
445 }
446
447 static void test_GdipCreateBitmapFromHBITMAP(void)
448 {
449     GpBitmap* gpbm = NULL;
450     HBITMAP hbm = NULL;
451     HPALETTE hpal = NULL;
452     GpStatus stat;
453     BYTE buff[1000];
454     LOGPALETTE* LogPal = NULL;
455     REAL width, height;
456     const REAL WIDTH1 = 5;
457     const REAL HEIGHT1 = 15;
458     const REAL WIDTH2 = 10;
459     const REAL HEIGHT2 = 20;
460     HDC hdc;
461     BITMAPINFO bmi;
462
463     stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
464     expect(InvalidParameter, stat);
465
466     hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
467     stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
468     expect(InvalidParameter, stat);
469
470     stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
471     expect(Ok, stat);
472     expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
473     expectf(WIDTH1,  width);
474     expectf(HEIGHT1, height);
475     if (stat == Ok)
476         GdipDisposeImage((GpImage*)gpbm);
477     GlobalFree(hbm);
478
479     hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
480     stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
481     expect(Ok, stat);
482     /* raw format */
483     expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, TRUE);
484
485     expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
486     expectf(WIDTH2,  width);
487     expectf(HEIGHT2, height);
488     if (stat == Ok)
489         GdipDisposeImage((GpImage*)gpbm);
490     GlobalFree(hbm);
491
492     hdc = CreateCompatibleDC(0);
493     ok(hdc != NULL, "CreateCompatibleDC failed\n");
494     bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
495     bmi.bmiHeader.biHeight = HEIGHT1;
496     bmi.bmiHeader.biWidth = WIDTH1;
497     bmi.bmiHeader.biBitCount = 24;
498     bmi.bmiHeader.biPlanes = 1;
499     bmi.bmiHeader.biCompression = BI_RGB;
500
501     hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
502     ok(hbm != NULL, "CreateDIBSection failed\n");
503
504     stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
505     expect(Ok, stat);
506     expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
507     expectf(WIDTH1,  width);
508     expectf(HEIGHT1, height);
509     if (stat == Ok)
510         GdipDisposeImage((GpImage*)gpbm);
511
512     LogPal = GdipAlloc(sizeof(LOGPALETTE));
513     ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
514     LogPal->palVersion = 0x300;
515     hpal = CreatePalette(LogPal);
516     ok(hpal != NULL, "CreatePalette failed\n");
517     GdipFree(LogPal);
518
519     stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
520     todo_wine
521     {
522         expect(Ok, stat);
523     }
524     if (stat == Ok)
525         GdipDisposeImage((GpImage*)gpbm);
526
527     GlobalFree(hpal);
528     GlobalFree(hbm);
529 }
530
531 static void test_GdipGetImageFlags(void)
532 {
533     GpImage *img;
534     GpStatus stat;
535     UINT flags;
536
537     img = (GpImage*)0xdeadbeef;
538
539     stat = GdipGetImageFlags(NULL, NULL);
540     expect(InvalidParameter, stat);
541
542     stat = GdipGetImageFlags(NULL, &flags);
543     expect(InvalidParameter, stat);
544
545     stat = GdipGetImageFlags(img, NULL);
546     expect(InvalidParameter, stat);
547 }
548
549 static void test_GdipCloneImage(void)
550 {
551     GpStatus stat;
552     GpRectF rectF;
553     GpUnit unit;
554     GpBitmap *bm;
555     GpImage *image_src, *image_dest = NULL;
556     const INT WIDTH = 10, HEIGHT = 20;
557
558     /* Create an image, clone it, delete the original, make sure the copy works */
559     stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
560     expect(Ok, stat);
561     expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, TRUE);
562
563     image_src = ((GpImage*)bm);
564     stat = GdipCloneImage(image_src, &image_dest);
565     expect(Ok, stat);
566     expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, TRUE);
567
568     stat = GdipDisposeImage((GpImage*)bm);
569     expect(Ok, stat);
570     stat = GdipGetImageBounds(image_dest, &rectF, &unit);
571     expect(Ok, stat);
572
573     /* Treat FP values carefully */
574     expectf((REAL)WIDTH, rectF.Width);
575     expectf((REAL)HEIGHT, rectF.Height);
576
577     stat = GdipDisposeImage(image_dest);
578     expect(Ok, stat);
579 }
580
581 static void test_testcontrol(void)
582 {
583     GpStatus stat;
584     DWORD param;
585
586     param = 0;
587     stat = GdipTestControl(TestControlGetBuildNumber, &param);
588     expect(Ok, stat);
589     ok(param != 0, "Build number expected, got %u\n", param);
590 }
591
592 static void test_fromhicon(void)
593 {
594     static const BYTE bmp_bits[1024];
595     HBITMAP hbmMask, hbmColor;
596     ICONINFO info;
597     HICON hIcon;
598     GpStatus stat;
599     GpBitmap *bitmap = NULL;
600     UINT dim;
601     ImageType type;
602     PixelFormat format;
603
604     /* NULL */
605     stat = GdipCreateBitmapFromHICON(NULL, NULL);
606     expect(InvalidParameter, stat);
607     stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
608     expect(InvalidParameter, stat);
609
610     /* color icon 1 bit */
611     hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
612     ok(hbmMask != 0, "CreateBitmap failed\n");
613     hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
614     ok(hbmColor != 0, "CreateBitmap failed\n");
615     info.fIcon = TRUE;
616     info.xHotspot = 8;
617     info.yHotspot = 8;
618     info.hbmMask = hbmMask;
619     info.hbmColor = hbmColor;
620     hIcon = CreateIconIndirect(&info);
621     ok(hIcon != 0, "CreateIconIndirect failed\n");
622     DeleteObject(hbmMask);
623     DeleteObject(hbmColor);
624
625     stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
626     expect(Ok, stat);
627     if(stat == Ok){
628        /* check attributes */
629        stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
630        expect(Ok, stat);
631        expect(16, dim);
632        stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
633        expect(Ok, stat);
634        expect(16, dim);
635        stat = GdipGetImageType((GpImage*)bitmap, &type);
636        expect(Ok, stat);
637        expect(ImageTypeBitmap, type);
638        stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
639        expect(PixelFormat32bppARGB, format);
640        /* raw format */
641        expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, TRUE);
642        GdipDisposeImage((GpImage*)bitmap);
643     }
644     DestroyIcon(hIcon);
645
646     /* color icon 8 bpp */
647     hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
648     ok(hbmMask != 0, "CreateBitmap failed\n");
649     hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
650     ok(hbmColor != 0, "CreateBitmap failed\n");
651     info.fIcon = TRUE;
652     info.xHotspot = 8;
653     info.yHotspot = 8;
654     info.hbmMask = hbmMask;
655     info.hbmColor = hbmColor;
656     hIcon = CreateIconIndirect(&info);
657     ok(hIcon != 0, "CreateIconIndirect failed\n");
658     DeleteObject(hbmMask);
659     DeleteObject(hbmColor);
660
661     stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
662     expect(Ok, stat);
663     if(stat == Ok){
664         /* check attributes */
665         stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
666         expect(Ok, stat);
667         expect(16, dim);
668         stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
669         expect(Ok, stat);
670         expect(16, dim);
671         stat = GdipGetImageType((GpImage*)bitmap, &type);
672         expect(Ok, stat);
673         expect(ImageTypeBitmap, type);
674         stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
675         expect(PixelFormat32bppARGB, format);
676         /* raw format */
677         expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, TRUE);
678         GdipDisposeImage((GpImage*)bitmap);
679     }
680     DestroyIcon(hIcon);
681 }
682
683 /* 1x1 pixel png */
684 static const unsigned char pngimage[285] = {
685 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
686 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
687 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
688 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
689 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
690 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
691 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
692 };
693 /* 1x1 pixel gif */
694 static const unsigned char gifimage[35] = {
695 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
696 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
697 0x01,0x00,0x3b
698 };
699 /* 1x1 pixel bmp */
700 static const unsigned char bmpimage[66] = {
701 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
702 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
703 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
704 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
705 0x00,0x00
706 };
707 /* 1x1 pixel jpg */
708 static const unsigned char jpgimage[285] = {
709 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
710 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
711 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
712 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
713 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
714 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
715 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
716 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
717 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
718 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
719 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
720 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
721 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
722 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
723 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
724 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
725 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
726 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
727 };
728 static void test_getrawformat(void)
729 {
730     test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG,  __LINE__, TRUE);
731     test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF,  __LINE__, TRUE);
732     test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP,  __LINE__, FALSE);
733     test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, TRUE);
734 }
735
736 START_TEST(image)
737 {
738     struct GdiplusStartupInput gdiplusStartupInput;
739     ULONG_PTR gdiplusToken;
740
741     gdiplusStartupInput.GdiplusVersion              = 1;
742     gdiplusStartupInput.DebugEventCallback          = NULL;
743     gdiplusStartupInput.SuppressBackgroundThread    = 0;
744     gdiplusStartupInput.SuppressExternalCodecs      = 0;
745
746     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
747
748     test_Scan0();
749     test_GetImageDimension();
750     test_GdipImageGetFrameDimensionsCount();
751     test_LoadingImages();
752     test_SavingImages();
753     test_encoders();
754     test_LockBits();
755     test_GdipCreateBitmapFromHBITMAP();
756     test_GdipGetImageFlags();
757     test_GdipCloneImage();
758     test_testcontrol();
759     test_fromhicon();
760     test_getrawformat();
761
762     GdiplusShutdown(gdiplusToken);
763 }