gdiplus: Handle more cases in GdipCreateBitmapFromGdiDib.
[wine/hacks.git] / dlls / gdiplus / tests / image.c
blob09ba8f06ead9484bf94b39e41059a67aa0cb04a6
1 /*
2 * Unit test suite for images
4 * Copyright (C) 2007 Google (Evan Stade)
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.
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.
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
21 #define COBJMACROS
23 #include <math.h>
25 #include "initguid.h"
26 #include "windows.h"
27 #include "gdiplus.h"
28 #include "wine/test.h"
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)
33 static BOOL color_match(ARGB c1, ARGB c2, BYTE max_diff)
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;
45 static void expect_guid(REFGUID expected, REFGUID got, int line, BOOL todo)
47 WCHAR bufferW[39];
48 char buffer[39];
49 char buffer2[39];
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);
61 static void expect_rawformat(REFGUID expected, GpImage *img, int line, BOOL todo)
63 GUID raw;
64 GpStatus stat;
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);
72 static void test_bufferrawformat(void* buff, int size, REFGUID expected, int line, BOOL todo)
74 LPSTREAM stream;
75 HGLOBAL hglob;
76 LPBYTE data;
77 HRESULT hres;
78 GpStatus stat;
79 GpImage *img;
81 hglob = GlobalAlloc (0, size);
82 data = GlobalLock (hglob);
83 memcpy(data, buff, size);
84 GlobalUnlock(hglob); data = NULL;
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;
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;
97 expect_rawformat(expected, img, line, todo);
99 GdipDisposeImage(img);
100 IStream_Release(stream);
103 static void test_Scan0(void)
105 GpBitmap *bm;
106 GpStatus stat;
107 BYTE buff[360];
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);
116 bm = (GpBitmap*)0xdeadbeef;
117 stat = GdipCreateBitmapFromScan0(10, -10, 10, PixelFormat24bppRGB, NULL, &bm);
118 expect(InvalidParameter, stat);
119 ok( !bm, "expected null bitmap\n" );
121 bm = (GpBitmap*)0xdeadbeef;
122 stat = GdipCreateBitmapFromScan0(-10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
123 expect(InvalidParameter, stat);
124 ok( !bm, "expected null bitmap\n" );
126 bm = (GpBitmap*)0xdeadbeef;
127 stat = GdipCreateBitmapFromScan0(10, 0, 10, PixelFormat24bppRGB, NULL, &bm);
128 expect(InvalidParameter, stat);
129 ok( !bm, "expected null bitmap\n" );
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);
138 bm = (GpBitmap*) 0xdeadbeef;
139 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, buff, &bm);
140 expect(InvalidParameter, stat);
141 ok( !bm, "expected null bitmap\n" );
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" );
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);
155 bm = (GpBitmap*)0xdeadbeef;
156 stat = GdipCreateBitmapFromScan0(10, 10, -10, PixelFormat24bppRGB, buff, &bm);
157 expect(InvalidParameter, stat);
158 ok( !bm, "expected null bitmap\n" );
161 static void test_FromGdiDib(void)
163 GpBitmap *bm;
164 GpStatus stat;
165 BYTE buff[400];
166 BYTE rbmi[sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)];
167 BITMAPINFO *bmi = (BITMAPINFO*)rbmi;
168 PixelFormat format;
170 bm = NULL;
172 memset(rbmi, 0, sizeof(rbmi));
174 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
175 bmi->bmiHeader.biWidth = 10;
176 bmi->bmiHeader.biHeight = 10;
177 bmi->bmiHeader.biPlanes = 1;
178 bmi->bmiHeader.biBitCount = 32;
179 bmi->bmiHeader.biCompression = BI_RGB;
181 stat = GdipCreateBitmapFromGdiDib(NULL, buff, &bm);
182 expect(InvalidParameter, stat);
184 stat = GdipCreateBitmapFromGdiDib(bmi, NULL, &bm);
185 expect(InvalidParameter, stat);
187 stat = GdipCreateBitmapFromGdiDib(bmi, buff, NULL);
188 expect(InvalidParameter, stat);
190 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
191 expect(Ok, stat);
192 ok(NULL != bm, "Expected bitmap to be initialized\n");
193 if (stat == Ok)
195 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
196 expect(Ok, stat);
197 expect(PixelFormat32bppRGB, format);
199 GdipDisposeImage((GpImage*)bm);
202 bmi->bmiHeader.biBitCount = 24;
203 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
204 expect(Ok, stat);
205 ok(NULL != bm, "Expected bitmap to be initialized\n");
206 if (stat == Ok)
208 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
209 expect(Ok, stat);
210 expect(PixelFormat24bppRGB, format);
212 GdipDisposeImage((GpImage*)bm);
215 bmi->bmiHeader.biBitCount = 16;
216 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
217 expect(Ok, stat);
218 ok(NULL != bm, "Expected bitmap to be initialized\n");
219 if (stat == Ok)
221 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
222 expect(Ok, stat);
223 expect(PixelFormat16bppRGB555, format);
225 GdipDisposeImage((GpImage*)bm);
228 bmi->bmiHeader.biBitCount = 8;
229 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
230 expect(Ok, stat);
231 ok(NULL != bm, "Expected bitmap to be initialized\n");
232 if (stat == Ok)
234 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
235 expect(Ok, stat);
236 expect(PixelFormat8bppIndexed, format);
238 GdipDisposeImage((GpImage*)bm);
241 bmi->bmiHeader.biBitCount = 4;
242 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
243 expect(Ok, stat);
244 ok(NULL != bm, "Expected bitmap to be initialized\n");
245 if (stat == Ok)
247 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
248 expect(Ok, stat);
249 expect(PixelFormat4bppIndexed, format);
251 GdipDisposeImage((GpImage*)bm);
254 bmi->bmiHeader.biBitCount = 1;
255 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
256 expect(Ok, stat);
257 ok(NULL != bm, "Expected bitmap to be initialized\n");
258 if (stat == Ok)
260 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
261 expect(Ok, stat);
262 expect(PixelFormat1bppIndexed, format);
264 GdipDisposeImage((GpImage*)bm);
267 bmi->bmiHeader.biBitCount = 0;
268 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
269 expect(InvalidParameter, stat);
272 static void test_GetImageDimension(void)
274 GpBitmap *bm;
275 GpStatus stat;
276 const REAL WIDTH = 10.0, HEIGHT = 20.0;
277 REAL w,h;
279 bm = (GpBitmap*)0xdeadbeef;
280 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
281 expect(Ok,stat);
282 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
283 ok(NULL != bm, "Expected bitmap to not be NULL\n");
285 stat = GdipGetImageDimension(NULL,&w,&h);
286 expect(InvalidParameter, stat);
288 stat = GdipGetImageDimension((GpImage*)bm,NULL,&h);
289 expect(InvalidParameter, stat);
291 stat = GdipGetImageDimension((GpImage*)bm,&w,NULL);
292 expect(InvalidParameter, stat);
294 w = -1;
295 h = -1;
296 stat = GdipGetImageDimension((GpImage*)bm,&w,&h);
297 expect(Ok, stat);
298 expectf(WIDTH, w);
299 expectf(HEIGHT, h);
300 GdipDisposeImage((GpImage*)bm);
303 static void test_GdipImageGetFrameDimensionsCount(void)
305 GpBitmap *bm;
306 GpStatus stat;
307 const REAL WIDTH = 10.0, HEIGHT = 20.0;
308 UINT w;
309 GUID dimension = {0};
310 UINT count;
311 ARGB color;
313 bm = (GpBitmap*)0xdeadbeef;
314 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
315 expect(Ok,stat);
316 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
317 ok(NULL != bm, "Expected bitmap to not be NULL\n");
319 stat = GdipImageGetFrameDimensionsCount(NULL,&w);
320 expect(InvalidParameter, stat);
322 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,NULL);
323 expect(InvalidParameter, stat);
325 w = -1;
326 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,&w);
327 expect(Ok, stat);
328 expect(1, w);
330 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 1);
331 expect(Ok, stat);
332 expect_guid(&FrameDimensionPage, &dimension, __LINE__, FALSE);
334 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 2);
335 expect(InvalidParameter, stat);
337 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 0);
338 expect(InvalidParameter, stat);
340 stat = GdipImageGetFrameCount(NULL, &dimension, &count);
341 expect(InvalidParameter, stat);
343 /* WinXP crashes on this test */
344 if(0)
346 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, NULL);
347 expect(InvalidParameter, stat);
350 stat = GdipImageGetFrameCount((GpImage*)bm, NULL, &count);
351 expect(Ok, stat);
353 count = 12345;
354 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, &count);
355 expect(Ok, stat);
356 expect(1, count);
358 GdipBitmapSetPixel(bm, 0, 0, 0xffffffff);
360 stat = GdipImageSelectActiveFrame((GpImage*)bm, &dimension, 0);
361 expect(Ok, stat);
363 /* SelectActiveFrame has no effect on image data of memory bitmaps */
364 color = 0xdeadbeef;
365 GdipBitmapGetPixel(bm, 0, 0, &color);
366 expect(0xffffffff, color);
368 GdipDisposeImage((GpImage*)bm);
371 static void test_LoadingImages(void)
373 GpStatus stat;
375 stat = GdipCreateBitmapFromFile(0, 0);
376 expect(InvalidParameter, stat);
378 stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
379 expect(InvalidParameter, stat);
381 stat = GdipLoadImageFromFile(0, 0);
382 expect(InvalidParameter, stat);
384 stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
385 expect(InvalidParameter, stat);
387 stat = GdipLoadImageFromFileICM(0, 0);
388 expect(InvalidParameter, stat);
390 stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
391 expect(InvalidParameter, stat);
394 static void test_SavingImages(void)
396 GpStatus stat;
397 GpBitmap *bm;
398 UINT n;
399 UINT s;
400 const REAL WIDTH = 10.0, HEIGHT = 20.0;
401 REAL w, h;
402 ImageCodecInfo *codecs;
403 static const CHAR filenameA[] = "a.bmp";
404 static const WCHAR filename[] = { 'a','.','b','m','p',0 };
406 codecs = NULL;
408 stat = GdipSaveImageToFile(0, 0, 0, 0);
409 expect(InvalidParameter, stat);
411 bm = NULL;
412 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
413 expect(Ok, stat);
414 if (!bm)
415 return;
417 /* invalid params */
418 stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
419 expect(InvalidParameter, stat);
421 stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
422 expect(InvalidParameter, stat);
424 /* encoder tests should succeed -- already tested */
425 stat = GdipGetImageEncodersSize(&n, &s);
426 if (stat != Ok || n == 0) goto cleanup;
428 codecs = GdipAlloc(s);
429 if (!codecs) goto cleanup;
431 stat = GdipGetImageEncoders(n, s, codecs);
432 if (stat != Ok) goto cleanup;
434 stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
435 expect(stat, Ok);
437 GdipDisposeImage((GpImage*)bm);
438 bm = 0;
440 /* re-load and check image stats */
441 stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
442 expect(stat, Ok);
443 if (stat != Ok) goto cleanup;
445 stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
446 if (stat != Ok) goto cleanup;
448 expectf(WIDTH, w);
449 expectf(HEIGHT, h);
451 cleanup:
452 GdipFree(codecs);
453 if (bm)
454 GdipDisposeImage((GpImage*)bm);
455 ok(DeleteFileA(filenameA), "Delete failed.\n");
458 static void test_encoders(void)
460 GpStatus stat;
461 UINT n;
462 UINT s;
463 ImageCodecInfo *codecs;
464 int i;
465 int bmp_found;
467 static const CHAR bmp_format[] = "BMP";
469 stat = GdipGetImageEncodersSize(&n, &s);
470 expect(stat, Ok);
472 codecs = GdipAlloc(s);
473 if (!codecs)
474 return;
476 stat = GdipGetImageEncoders(n, s, NULL);
477 expect(GenericError, stat);
479 stat = GdipGetImageEncoders(0, s, codecs);
480 expect(GenericError, stat);
482 stat = GdipGetImageEncoders(n, s-1, codecs);
483 expect(GenericError, stat);
485 stat = GdipGetImageEncoders(n, s+1, codecs);
486 expect(GenericError, stat);
488 stat = GdipGetImageEncoders(n, s, codecs);
489 expect(stat, Ok);
491 bmp_found = FALSE;
492 for (i = 0; i < n; i++)
494 CHAR desc[32];
496 WideCharToMultiByte(CP_ACP, 0, codecs[i].FormatDescription, -1,
497 desc, 32, 0, 0);
499 if (CompareStringA(LOCALE_SYSTEM_DEFAULT, 0,
500 desc, -1,
501 bmp_format, -1) == CSTR_EQUAL) {
502 bmp_found = TRUE;
503 break;
506 if (!bmp_found)
507 ok(FALSE, "No BMP codec found.\n");
509 GdipFree(codecs);
512 static void test_LockBits(void)
514 GpStatus stat;
515 GpBitmap *bm;
516 GpRect rect;
517 BitmapData bd;
518 const INT WIDTH = 10, HEIGHT = 20;
520 bm = NULL;
521 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
522 expect(Ok, stat);
524 rect.X = 2;
525 rect.Y = 3;
526 rect.Width = 4;
527 rect.Height = 5;
529 /* read-only */
530 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
531 expect(Ok, stat);
533 if (stat == Ok) {
534 stat = GdipBitmapUnlockBits(bm, &bd);
535 expect(Ok, stat);
538 /* read-only, with NULL rect -> whole bitmap lock */
539 stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
540 expect(Ok, stat);
541 expect(bd.Width, WIDTH);
542 expect(bd.Height, HEIGHT);
544 if (stat == Ok) {
545 stat = GdipBitmapUnlockBits(bm, &bd);
546 expect(Ok, stat);
549 /* read-only, consecutive */
550 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
551 expect(Ok, stat);
553 if (stat == Ok) {
554 stat = GdipBitmapUnlockBits(bm, &bd);
555 expect(Ok, stat);
558 stat = GdipDisposeImage((GpImage*)bm);
559 expect(Ok, stat);
560 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
561 expect(Ok, stat);
563 /* read x2 */
564 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
565 expect(Ok, stat);
566 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
567 expect(WrongState, stat);
569 stat = GdipBitmapUnlockBits(bm, &bd);
570 expect(Ok, stat);
572 stat = GdipDisposeImage((GpImage*)bm);
573 expect(Ok, stat);
574 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
575 expect(Ok, stat);
577 /* write, no modification */
578 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
579 expect(Ok, stat);
581 if (stat == Ok) {
582 stat = GdipBitmapUnlockBits(bm, &bd);
583 expect(Ok, stat);
586 /* write, consecutive */
587 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
588 expect(Ok, stat);
590 if (stat == Ok) {
591 stat = GdipBitmapUnlockBits(bm, &bd);
592 expect(Ok, stat);
595 stat = GdipDisposeImage((GpImage*)bm);
596 expect(Ok, stat);
597 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
598 expect(Ok, stat);
600 /* write, modify */
601 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
602 expect(Ok, stat);
604 if (stat == Ok) {
605 if (bd.Scan0)
606 ((char*)bd.Scan0)[2] = 0xff;
608 stat = GdipBitmapUnlockBits(bm, &bd);
609 expect(Ok, stat);
612 stat = GdipDisposeImage((GpImage*)bm);
613 expect(Ok, stat);
615 /* dispose locked */
616 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
617 expect(Ok, stat);
618 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
619 expect(Ok, stat);
620 stat = GdipDisposeImage((GpImage*)bm);
621 expect(Ok, stat);
624 static void test_GdipCreateBitmapFromHBITMAP(void)
626 GpBitmap* gpbm = NULL;
627 HBITMAP hbm = NULL;
628 HPALETTE hpal = NULL;
629 GpStatus stat;
630 BYTE buff[1000];
631 LOGPALETTE* LogPal = NULL;
632 REAL width, height;
633 const REAL WIDTH1 = 5;
634 const REAL HEIGHT1 = 15;
635 const REAL WIDTH2 = 10;
636 const REAL HEIGHT2 = 20;
637 HDC hdc;
638 BITMAPINFO bmi;
639 BYTE *bits;
641 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
642 expect(InvalidParameter, stat);
644 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
645 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
646 expect(InvalidParameter, stat);
648 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
649 expect(Ok, stat);
650 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
651 expectf(WIDTH1, width);
652 expectf(HEIGHT1, height);
653 if (stat == Ok)
654 GdipDisposeImage((GpImage*)gpbm);
655 DeleteObject(hbm);
657 memset(buff, 0, sizeof(buff));
658 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
659 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
660 expect(Ok, stat);
661 /* raw format */
662 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
664 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
665 expectf(WIDTH2, width);
666 expectf(HEIGHT2, height);
667 if (stat == Ok)
668 GdipDisposeImage((GpImage*)gpbm);
669 DeleteObject(hbm);
671 hdc = CreateCompatibleDC(0);
672 ok(hdc != NULL, "CreateCompatibleDC failed\n");
673 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
674 bmi.bmiHeader.biHeight = HEIGHT1;
675 bmi.bmiHeader.biWidth = WIDTH1;
676 bmi.bmiHeader.biBitCount = 24;
677 bmi.bmiHeader.biPlanes = 1;
678 bmi.bmiHeader.biCompression = BI_RGB;
680 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
681 ok(hbm != NULL, "CreateDIBSection failed\n");
683 bits[0] = 0;
685 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
686 expect(Ok, stat);
687 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
688 expectf(WIDTH1, width);
689 expectf(HEIGHT1, height);
690 if (stat == Ok)
692 /* test whether writing to the bitmap affects the original */
693 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
694 expect(Ok, stat);
696 expect(0, bits[0]);
698 GdipDisposeImage((GpImage*)gpbm);
701 LogPal = GdipAlloc(sizeof(LOGPALETTE));
702 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
703 LogPal->palVersion = 0x300;
704 LogPal->palNumEntries = 1;
705 hpal = CreatePalette(LogPal);
706 ok(hpal != NULL, "CreatePalette failed\n");
707 GdipFree(LogPal);
709 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
710 todo_wine
712 expect(Ok, stat);
714 if (stat == Ok)
715 GdipDisposeImage((GpImage*)gpbm);
717 DeleteObject(hpal);
718 DeleteObject(hbm);
721 static void test_GdipGetImageFlags(void)
723 GpImage *img;
724 GpStatus stat;
725 UINT flags;
727 img = (GpImage*)0xdeadbeef;
729 stat = GdipGetImageFlags(NULL, NULL);
730 expect(InvalidParameter, stat);
732 stat = GdipGetImageFlags(NULL, &flags);
733 expect(InvalidParameter, stat);
735 stat = GdipGetImageFlags(img, NULL);
736 expect(InvalidParameter, stat);
739 static void test_GdipCloneImage(void)
741 GpStatus stat;
742 GpRectF rectF;
743 GpUnit unit;
744 GpBitmap *bm;
745 GpImage *image_src, *image_dest = NULL;
746 const INT WIDTH = 10, HEIGHT = 20;
748 /* Create an image, clone it, delete the original, make sure the copy works */
749 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
750 expect(Ok, stat);
751 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
753 image_src = ((GpImage*)bm);
754 stat = GdipCloneImage(image_src, &image_dest);
755 expect(Ok, stat);
756 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
758 stat = GdipDisposeImage((GpImage*)bm);
759 expect(Ok, stat);
760 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
761 expect(Ok, stat);
763 /* Treat FP values carefully */
764 expectf((REAL)WIDTH, rectF.Width);
765 expectf((REAL)HEIGHT, rectF.Height);
767 stat = GdipDisposeImage(image_dest);
768 expect(Ok, stat);
771 static void test_testcontrol(void)
773 GpStatus stat;
774 DWORD param;
776 param = 0;
777 stat = GdipTestControl(TestControlGetBuildNumber, &param);
778 expect(Ok, stat);
779 ok(param != 0, "Build number expected, got %u\n", param);
782 static void test_fromhicon(void)
784 static const BYTE bmp_bits[1024];
785 HBITMAP hbmMask, hbmColor;
786 ICONINFO info;
787 HICON hIcon;
788 GpStatus stat;
789 GpBitmap *bitmap = NULL;
790 UINT dim;
791 ImageType type;
792 PixelFormat format;
794 /* NULL */
795 stat = GdipCreateBitmapFromHICON(NULL, NULL);
796 expect(InvalidParameter, stat);
797 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
798 expect(InvalidParameter, stat);
800 /* color icon 1 bit */
801 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
802 ok(hbmMask != 0, "CreateBitmap failed\n");
803 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
804 ok(hbmColor != 0, "CreateBitmap failed\n");
805 info.fIcon = TRUE;
806 info.xHotspot = 8;
807 info.yHotspot = 8;
808 info.hbmMask = hbmMask;
809 info.hbmColor = hbmColor;
810 hIcon = CreateIconIndirect(&info);
811 ok(hIcon != 0, "CreateIconIndirect failed\n");
812 DeleteObject(hbmMask);
813 DeleteObject(hbmColor);
815 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
816 ok(stat == Ok ||
817 broken(stat == InvalidParameter), /* Win98 */
818 "Expected Ok, got %.8x\n", stat);
819 if(stat == Ok){
820 /* check attributes */
821 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
822 expect(Ok, stat);
823 expect(16, dim);
824 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
825 expect(Ok, stat);
826 expect(16, dim);
827 stat = GdipGetImageType((GpImage*)bitmap, &type);
828 expect(Ok, stat);
829 expect(ImageTypeBitmap, type);
830 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
831 expect(PixelFormat32bppARGB, format);
832 /* raw format */
833 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
834 GdipDisposeImage((GpImage*)bitmap);
836 DestroyIcon(hIcon);
838 /* color icon 8 bpp */
839 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
840 ok(hbmMask != 0, "CreateBitmap failed\n");
841 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
842 ok(hbmColor != 0, "CreateBitmap failed\n");
843 info.fIcon = TRUE;
844 info.xHotspot = 8;
845 info.yHotspot = 8;
846 info.hbmMask = hbmMask;
847 info.hbmColor = hbmColor;
848 hIcon = CreateIconIndirect(&info);
849 ok(hIcon != 0, "CreateIconIndirect failed\n");
850 DeleteObject(hbmMask);
851 DeleteObject(hbmColor);
853 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
854 expect(Ok, stat);
855 if(stat == Ok){
856 /* check attributes */
857 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
858 expect(Ok, stat);
859 expect(16, dim);
860 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
861 expect(Ok, stat);
862 expect(16, dim);
863 stat = GdipGetImageType((GpImage*)bitmap, &type);
864 expect(Ok, stat);
865 expect(ImageTypeBitmap, type);
866 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
867 expect(PixelFormat32bppARGB, format);
868 /* raw format */
869 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
870 GdipDisposeImage((GpImage*)bitmap);
872 DestroyIcon(hIcon);
875 /* 1x1 pixel png */
876 static const unsigned char pngimage[285] = {
877 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
878 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
879 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
880 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
881 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
882 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
883 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
885 /* 1x1 pixel gif */
886 static const unsigned char gifimage[35] = {
887 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
888 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
889 0x01,0x00,0x3b
891 /* 1x1 pixel bmp */
892 static const unsigned char bmpimage[66] = {
893 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
894 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
895 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
896 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
897 0x00,0x00
899 /* 1x1 pixel jpg */
900 static const unsigned char jpgimage[285] = {
901 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
902 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
903 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
904 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
905 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
906 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
907 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
908 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
909 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
910 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
911 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
912 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
913 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
914 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
915 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
916 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
917 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
918 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
920 /* 1x1 pixel tiff */
921 static const unsigned char tiffimage[] = {
922 0x49,0x49,0x2a,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xfe,0x00,
923 0x04,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x00,0x01,0x00,
924 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
925 0x00,0x00,0x02,0x01,0x03,0x00,0x03,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0x03,0x01,
926 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,0x01,0x03,0x00,0x01,0x00,
927 0x00,0x00,0x02,0x00,0x00,0x00,0x0d,0x01,0x02,0x00,0x1b,0x00,0x00,0x00,0xd8,0x00,
928 0x00,0x00,0x11,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x12,0x01,
929 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x01,0x03,0x00,0x01,0x00,
930 0x00,0x00,0x03,0x00,0x00,0x00,0x16,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x40,0x00,
931 0x00,0x00,0x17,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1a,0x01,
932 0x05,0x00,0x01,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x1b,0x01,0x05,0x00,0x01,0x00,
933 0x00,0x00,0xfc,0x00,0x00,0x00,0x1c,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
934 0x00,0x00,0x28,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
935 0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x6d,0x65,
936 0x68,0x2f,0x44,0x65,0x73,0x6b,0x74,0x6f,0x70,0x2f,0x74,0x65,0x73,0x74,0x2e,0x74,
937 0x69,0x66,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,
938 0x00,0x00,0x00,0x01
940 /* 320x320 twip wmf */
941 static const unsigned char wmfimage[180] = {
942 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
943 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
944 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
945 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
946 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
947 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
948 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
949 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
950 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
951 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
952 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
953 0x00,0x00,0x00,0x00
955 static void test_getrawformat(void)
957 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
958 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
959 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
960 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
961 test_bufferrawformat((void*)tiffimage, sizeof(tiffimage), &ImageFormatTIFF, __LINE__, FALSE);
962 test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
965 static void test_loadwmf(void)
967 LPSTREAM stream;
968 HGLOBAL hglob;
969 LPBYTE data;
970 HRESULT hres;
971 GpStatus stat;
972 GpImage *img;
973 GpRectF bounds;
974 GpUnit unit;
975 REAL res = 12345.0;
976 MetafileHeader header;
978 hglob = GlobalAlloc (0, sizeof(wmfimage));
979 data = GlobalLock (hglob);
980 memcpy(data, wmfimage, sizeof(wmfimage));
981 GlobalUnlock(hglob); data = NULL;
983 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
984 ok(hres == S_OK, "Failed to create a stream\n");
985 if(hres != S_OK) return;
987 stat = GdipLoadImageFromStream(stream, &img);
988 ok(stat == Ok, "Failed to create a Bitmap\n");
989 if(stat != Ok){
990 IStream_Release(stream);
991 return;
994 IStream_Release(stream);
996 stat = GdipGetImageBounds(img, &bounds, &unit);
997 expect(Ok, stat);
998 todo_wine expect(UnitPixel, unit);
999 expectf(0.0, bounds.X);
1000 expectf(0.0, bounds.Y);
1001 todo_wine expectf(320.0, bounds.Width);
1002 todo_wine expectf(320.0, bounds.Height);
1004 stat = GdipGetImageHorizontalResolution(img, &res);
1005 expect(Ok, stat);
1006 todo_wine expectf(1440.0, res);
1008 stat = GdipGetImageVerticalResolution(img, &res);
1009 expect(Ok, stat);
1010 todo_wine expectf(1440.0, res);
1012 memset(&header, 0, sizeof(header));
1013 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1014 expect(Ok, stat);
1015 if (stat == Ok)
1017 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1018 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1019 todo_wine expect(0x300, header.Version);
1020 expect(0, header.EmfPlusFlags);
1021 todo_wine expectf(1440.0, header.DpiX);
1022 todo_wine expectf(1440.0, header.DpiY);
1023 expect(0, header.X);
1024 expect(0, header.Y);
1025 todo_wine expect(320, header.Width);
1026 todo_wine expect(320, header.Height);
1027 todo_wine expect(1, U(header).WmfHeader.mtType);
1028 expect(0, header.EmfPlusHeaderSize);
1029 expect(0, header.LogicalDpiX);
1030 expect(0, header.LogicalDpiY);
1033 GdipDisposeImage(img);
1036 static void test_createfromwmf(void)
1038 HMETAFILE hwmf;
1039 GpImage *img;
1040 GpStatus stat;
1041 GpRectF bounds;
1042 GpUnit unit;
1043 REAL res = 12345.0;
1044 MetafileHeader header;
1046 hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
1047 wmfimage+sizeof(WmfPlaceableFileHeader));
1048 ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
1050 stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
1051 (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
1052 expect(Ok, stat);
1054 stat = GdipGetImageBounds(img, &bounds, &unit);
1055 expect(Ok, stat);
1056 expect(UnitPixel, unit);
1057 expectf(0.0, bounds.X);
1058 expectf(0.0, bounds.Y);
1059 expectf(320.0, bounds.Width);
1060 expectf(320.0, bounds.Height);
1062 stat = GdipGetImageHorizontalResolution(img, &res);
1063 expect(Ok, stat);
1064 expectf(1440.0, res);
1066 stat = GdipGetImageVerticalResolution(img, &res);
1067 expect(Ok, stat);
1068 expectf(1440.0, res);
1070 memset(&header, 0, sizeof(header));
1071 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1072 expect(Ok, stat);
1073 if (stat == Ok)
1075 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1076 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1077 todo_wine expect(0x300, header.Version);
1078 expect(0, header.EmfPlusFlags);
1079 todo_wine expectf(1440.0, header.DpiX);
1080 todo_wine expectf(1440.0, header.DpiY);
1081 expect(0, header.X);
1082 expect(0, header.Y);
1083 todo_wine expect(320, header.Width);
1084 todo_wine expect(320, header.Height);
1085 todo_wine expect(1, U(header).WmfHeader.mtType);
1086 expect(0, header.EmfPlusHeaderSize);
1087 expect(0, header.LogicalDpiX);
1088 expect(0, header.LogicalDpiY);
1091 GdipDisposeImage(img);
1094 static void test_resolution(void)
1096 GpStatus stat;
1097 GpBitmap *bitmap;
1098 REAL res=-1.0;
1099 HDC screendc;
1100 int screenxres, screenyres;
1102 /* create Bitmap */
1103 stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
1104 expect(Ok, stat);
1106 /* test invalid values */
1107 stat = GdipGetImageHorizontalResolution(NULL, &res);
1108 expect(InvalidParameter, stat);
1110 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
1111 expect(InvalidParameter, stat);
1113 stat = GdipGetImageVerticalResolution(NULL, &res);
1114 expect(InvalidParameter, stat);
1116 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
1117 expect(InvalidParameter, stat);
1119 stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
1120 expect(InvalidParameter, stat);
1122 stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
1123 expect(InvalidParameter, stat);
1125 /* defaults to screen resolution */
1126 screendc = GetDC(0);
1128 screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
1129 screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
1131 ReleaseDC(0, screendc);
1133 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1134 expect(Ok, stat);
1135 expectf((REAL)screenxres, res);
1137 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1138 expect(Ok, stat);
1139 expectf((REAL)screenyres, res);
1141 /* test changing the resolution */
1142 stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
1143 expect(Ok, stat);
1145 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1146 expect(Ok, stat);
1147 expectf(screenxres*2.0, res);
1149 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1150 expect(Ok, stat);
1151 expectf(screenyres*3.0, res);
1153 stat = GdipDisposeImage((GpImage*)bitmap);
1154 expect(Ok, stat);
1157 static void test_createhbitmap(void)
1159 GpStatus stat;
1160 GpBitmap *bitmap;
1161 HBITMAP hbitmap, oldhbitmap;
1162 BITMAP bm;
1163 int ret;
1164 HDC hdc;
1165 COLORREF pixel;
1166 BYTE bits[640];
1168 memset(bits, 0x68, 640);
1170 /* create Bitmap */
1171 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
1172 expect(Ok, stat);
1174 /* test NULL values */
1175 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
1176 expect(InvalidParameter, stat);
1178 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
1179 expect(InvalidParameter, stat);
1181 /* create HBITMAP */
1182 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
1183 expect(Ok, stat);
1185 if (stat == Ok)
1187 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
1188 expect(sizeof(BITMAP), ret);
1190 expect(0, bm.bmType);
1191 expect(10, bm.bmWidth);
1192 expect(20, bm.bmHeight);
1193 expect(40, bm.bmWidthBytes);
1194 expect(1, bm.bmPlanes);
1195 expect(32, bm.bmBitsPixel);
1196 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1198 hdc = CreateCompatibleDC(NULL);
1200 oldhbitmap = SelectObject(hdc, hbitmap);
1201 pixel = GetPixel(hdc, 5, 5);
1202 SelectObject(hdc, oldhbitmap);
1204 DeleteDC(hdc);
1206 expect(0x686868, pixel);
1208 DeleteObject(hbitmap);
1211 stat = GdipDisposeImage((GpImage*)bitmap);
1212 expect(Ok, stat);
1215 static void test_getsetpixel(void)
1217 GpStatus stat;
1218 GpBitmap *bitmap;
1219 ARGB color;
1220 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1221 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1223 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1224 expect(Ok, stat);
1226 /* null parameters */
1227 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1228 expect(InvalidParameter, stat);
1230 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1231 expect(InvalidParameter, stat);
1233 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1234 expect(InvalidParameter, stat);
1236 /* out of bounds */
1237 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1238 expect(InvalidParameter, stat);
1240 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1241 expect(InvalidParameter, stat);
1243 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1244 ok(stat == InvalidParameter ||
1245 broken(stat == Ok), /* Older gdiplus */
1246 "Expected InvalidParameter, got %.8x\n", stat);
1248 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1249 ok(stat == InvalidParameter ||
1250 broken(stat == Ok), /* Older gdiplus */
1251 "Expected InvalidParameter, got %.8x\n", stat);
1253 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1254 expect(InvalidParameter, stat);
1256 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1257 expect(InvalidParameter, stat);
1259 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1260 expect(InvalidParameter, stat);
1262 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1263 expect(InvalidParameter, stat);
1265 /* valid use */
1266 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1267 expect(Ok, stat);
1268 expect(0xffffffff, color);
1270 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1271 expect(Ok, stat);
1272 expect(0xff0000ff, color);
1274 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1275 expect(Ok, stat);
1277 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1278 expect(Ok, stat);
1280 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1281 expect(Ok, stat);
1282 expect(0xff676869, color);
1284 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1285 expect(Ok, stat);
1286 expect(0xff474849, color);
1288 stat = GdipDisposeImage((GpImage*)bitmap);
1289 expect(Ok, stat);
1292 static void check_halftone_palette(ColorPalette *palette)
1294 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1295 UINT i;
1297 for (i=0; i<palette->Count; i++)
1299 ARGB expected=0xff000000;
1300 if (i<8)
1302 if (i&1) expected |= 0x800000;
1303 if (i&2) expected |= 0x8000;
1304 if (i&4) expected |= 0x80;
1306 else if (i == 8)
1308 expected = 0xffc0c0c0;
1310 else if (i < 16)
1312 if (i&1) expected |= 0xff0000;
1313 if (i&2) expected |= 0xff00;
1314 if (i&4) expected |= 0xff;
1316 else if (i < 40)
1318 expected = 0x00000000;
1320 else
1322 expected |= halftone_values[(i-40)%6];
1323 expected |= halftone_values[((i-40)/6)%6] << 8;
1324 expected |= halftone_values[((i-40)/36)%6] << 16;
1326 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1327 expected, palette->Entries[i], i, palette->Count);
1331 static void test_palette(void)
1333 GpStatus stat;
1334 GpBitmap *bitmap;
1335 INT size;
1336 BYTE buffer[1040];
1337 ColorPalette *palette=(ColorPalette*)buffer;
1338 ARGB color=0;
1340 /* test initial palette from non-indexed bitmap */
1341 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1342 expect(Ok, stat);
1344 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1345 expect(Ok, stat);
1346 expect(sizeof(UINT)*2+sizeof(ARGB), size);
1348 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1349 expect(Ok, stat);
1350 expect(0, palette->Count);
1352 /* test setting palette on not-indexed bitmap */
1353 palette->Count = 3;
1355 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1356 expect(Ok, stat);
1358 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1359 expect(Ok, stat);
1360 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1362 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1363 expect(Ok, stat);
1364 expect(3, palette->Count);
1366 GdipDisposeImage((GpImage*)bitmap);
1368 /* test initial palette on 1-bit bitmap */
1369 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1370 expect(Ok, stat);
1372 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1373 expect(Ok, stat);
1374 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1376 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1377 expect(Ok, stat);
1378 expect(PaletteFlagsGrayScale, palette->Flags);
1379 expect(2, palette->Count);
1381 expect(0xff000000, palette->Entries[0]);
1382 expect(0xffffffff, palette->Entries[1]);
1384 /* test getting/setting pixels */
1385 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1386 expect(Ok, stat);
1387 expect(0xff000000, color);
1389 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1390 todo_wine ok((stat == Ok) ||
1391 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1393 if (stat == Ok)
1395 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1396 expect(Ok, stat);
1397 expect(0xffffffff, color);
1400 GdipDisposeImage((GpImage*)bitmap);
1402 /* test initial palette on 4-bit bitmap */
1403 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1404 expect(Ok, stat);
1406 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1407 expect(Ok, stat);
1408 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1410 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1411 expect(Ok, stat);
1412 expect(0, palette->Flags);
1413 expect(16, palette->Count);
1415 check_halftone_palette(palette);
1417 /* test getting/setting pixels */
1418 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1419 expect(Ok, stat);
1420 expect(0xff000000, color);
1422 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
1423 todo_wine ok((stat == Ok) ||
1424 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1426 if (stat == Ok)
1428 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1429 expect(Ok, stat);
1430 expect(0xffff00ff, color);
1433 GdipDisposeImage((GpImage*)bitmap);
1435 /* test initial palette on 8-bit bitmap */
1436 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1437 expect(Ok, stat);
1439 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1440 expect(Ok, stat);
1441 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1443 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1444 expect(Ok, stat);
1445 expect(PaletteFlagsHalftone, palette->Flags);
1446 expect(256, palette->Count);
1448 check_halftone_palette(palette);
1450 /* test getting/setting pixels */
1451 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1452 expect(Ok, stat);
1453 expect(0xff000000, color);
1455 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
1456 todo_wine ok((stat == Ok) ||
1457 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1459 if (stat == Ok)
1461 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1462 expect(Ok, stat);
1463 expect(0xffcccccc, color);
1466 /* test setting/getting a different palette */
1467 palette->Entries[1] = 0xffcccccc;
1469 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1470 expect(Ok, stat);
1472 palette->Entries[1] = 0;
1474 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1475 expect(Ok, stat);
1476 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1478 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1479 expect(Ok, stat);
1480 expect(PaletteFlagsHalftone, palette->Flags);
1481 expect(256, palette->Count);
1482 expect(0xffcccccc, palette->Entries[1]);
1484 /* test count < 256 */
1485 palette->Flags = 12345;
1486 palette->Count = 3;
1488 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1489 expect(Ok, stat);
1491 palette->Entries[1] = 0;
1492 palette->Entries[3] = 0xdeadbeef;
1494 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1495 expect(Ok, stat);
1496 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1498 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1499 expect(Ok, stat);
1500 expect(12345, palette->Flags);
1501 expect(3, palette->Count);
1502 expect(0xffcccccc, palette->Entries[1]);
1503 expect(0xdeadbeef, palette->Entries[3]);
1505 /* test count > 256 */
1506 palette->Count = 257;
1508 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1509 ok(stat == InvalidParameter ||
1510 broken(stat == Ok), /* Old gdiplus behavior */
1511 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1513 GdipDisposeImage((GpImage*)bitmap);
1516 static void test_colormatrix(void)
1518 GpStatus stat;
1519 ColorMatrix colormatrix, graymatrix;
1520 GpImageAttributes *imageattr;
1521 const ColorMatrix identity = {{
1522 {1.0,0.0,0.0,0.0,0.0},
1523 {0.0,1.0,0.0,0.0,0.0},
1524 {0.0,0.0,1.0,0.0,0.0},
1525 {0.0,0.0,0.0,1.0,0.0},
1526 {0.0,0.0,0.0,0.0,1.0}}};
1527 const ColorMatrix double_red = {{
1528 {2.0,0.0,0.0,0.0,0.0},
1529 {0.0,1.0,0.0,0.0,0.0},
1530 {0.0,0.0,1.0,0.0,0.0},
1531 {0.0,0.0,0.0,1.0,0.0},
1532 {0.0,0.0,0.0,0.0,1.0}}};
1533 GpBitmap *bitmap1, *bitmap2;
1534 GpGraphics *graphics;
1535 ARGB color;
1537 colormatrix = identity;
1538 graymatrix = identity;
1540 stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
1541 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1542 expect(InvalidParameter, stat);
1544 stat = GdipCreateImageAttributes(&imageattr);
1545 expect(Ok, stat);
1547 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1548 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1549 expect(Ok, stat);
1551 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1552 TRUE, NULL, NULL, ColorMatrixFlagsDefault);
1553 expect(InvalidParameter, stat);
1555 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1556 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1557 expect(Ok, stat);
1559 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1560 TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
1561 expect(Ok, stat);
1563 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1564 TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
1565 expect(InvalidParameter, stat);
1567 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1568 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
1569 expect(Ok, stat);
1571 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1572 TRUE, &colormatrix, &graymatrix, 3);
1573 expect(InvalidParameter, stat);
1575 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
1576 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1577 expect(InvalidParameter, stat);
1579 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
1580 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1581 expect(InvalidParameter, stat);
1583 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1584 FALSE, NULL, NULL, ColorMatrixFlagsDefault);
1585 expect(Ok, stat);
1587 /* Drawing a bitmap transforms the colors */
1588 colormatrix = double_red;
1589 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1590 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1591 expect(Ok, stat);
1593 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1594 expect(Ok, stat);
1596 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1597 expect(Ok, stat);
1599 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ffff);
1600 expect(Ok, stat);
1602 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1603 expect(Ok, stat);
1605 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1606 UnitPixel, imageattr, NULL, NULL);
1607 expect(Ok, stat);
1609 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1610 expect(Ok, stat);
1611 todo_wine expect(0xff80ffff, color);
1613 GdipDeleteGraphics(graphics);
1614 GdipDisposeImage((GpImage*)bitmap1);
1615 GdipDisposeImage((GpImage*)bitmap2);
1616 GdipDisposeImageAttributes(imageattr);
1619 static void test_gamma(void)
1621 GpStatus stat;
1622 GpImageAttributes *imageattr;
1623 GpBitmap *bitmap1, *bitmap2;
1624 GpGraphics *graphics;
1625 ARGB color;
1627 stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
1628 expect(InvalidParameter, stat);
1630 stat = GdipCreateImageAttributes(&imageattr);
1631 expect(Ok, stat);
1633 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
1634 expect(Ok, stat);
1636 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
1637 expect(InvalidParameter, stat);
1639 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
1640 expect(InvalidParameter, stat);
1642 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
1643 expect(InvalidParameter, stat);
1645 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
1646 expect(Ok, stat);
1648 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
1649 expect(Ok, stat);
1651 /* Drawing a bitmap transforms the colors */
1652 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
1653 expect(Ok, stat);
1655 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1656 expect(Ok, stat);
1658 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1659 expect(Ok, stat);
1661 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
1662 expect(Ok, stat);
1664 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1665 expect(Ok, stat);
1667 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1668 UnitPixel, imageattr, NULL, NULL);
1669 expect(Ok, stat);
1671 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1672 expect(Ok, stat);
1673 todo_wine ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
1675 GdipDeleteGraphics(graphics);
1676 GdipDisposeImage((GpImage*)bitmap1);
1677 GdipDisposeImage((GpImage*)bitmap2);
1678 GdipDisposeImageAttributes(imageattr);
1681 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
1682 static const unsigned char gifanimation[72] = {
1683 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1684 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
1685 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
1686 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
1687 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
1690 static void test_multiframegif(void)
1692 LPSTREAM stream;
1693 HGLOBAL hglob;
1694 LPBYTE data;
1695 HRESULT hres;
1696 GpStatus stat;
1697 GpBitmap *bmp;
1698 ARGB color;
1699 UINT count;
1700 GUID dimension;
1702 /* Test frame functions with an animated GIF */
1703 hglob = GlobalAlloc (0, sizeof(gifanimation));
1704 data = GlobalLock (hglob);
1705 memcpy(data, gifanimation, sizeof(gifanimation));
1706 GlobalUnlock(hglob);
1708 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1709 ok(hres == S_OK, "Failed to create a stream\n");
1710 if(hres != S_OK) return;
1712 stat = GdipCreateBitmapFromStream(stream, &bmp);
1713 ok(stat == Ok, "Failed to create a Bitmap\n");
1714 if(stat != Ok){
1715 IStream_Release(stream);
1716 return;
1719 /* Bitmap starts at frame 0 */
1720 color = 0xdeadbeef;
1721 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1722 expect(Ok, stat);
1723 expect(0xffffffff, color);
1725 /* Check that we get correct metadata */
1726 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1727 expect(Ok, stat);
1728 expect(1, count);
1730 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1731 expect(Ok, stat);
1732 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1734 count = 12345;
1735 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1736 expect(Ok, stat);
1737 todo_wine expect(2, count);
1739 /* SelectActiveFrame overwrites our current data */
1740 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1741 expect(Ok, stat);
1743 color = 0xdeadbeef;
1744 GdipBitmapGetPixel(bmp, 0, 0, &color);
1745 expect(Ok, stat);
1746 todo_wine expect(0xff000000, color);
1748 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1749 expect(Ok, stat);
1751 color = 0xdeadbeef;
1752 GdipBitmapGetPixel(bmp, 0, 0, &color);
1753 expect(Ok, stat);
1754 expect(0xffffffff, color);
1756 /* Write over the image data */
1757 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
1758 expect(Ok, stat);
1760 /* Switching to the same frame does not overwrite our changes */
1761 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1762 expect(Ok, stat);
1764 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1765 expect(Ok, stat);
1766 expect(0xff000000, color);
1768 /* But switching to another frame and back does */
1769 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1770 expect(Ok, stat);
1772 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1773 expect(Ok, stat);
1775 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1776 expect(Ok, stat);
1777 todo_wine expect(0xffffffff, color);
1779 GdipDisposeImage((GpImage*)bmp);
1780 IStream_Release(stream);
1782 /* Test with a non-animated gif */
1783 hglob = GlobalAlloc (0, sizeof(gifimage));
1784 data = GlobalLock (hglob);
1785 memcpy(data, gifimage, sizeof(gifimage));
1786 GlobalUnlock(hglob);
1788 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1789 ok(hres == S_OK, "Failed to create a stream\n");
1790 if(hres != S_OK) return;
1792 stat = GdipCreateBitmapFromStream(stream, &bmp);
1793 ok(stat == Ok, "Failed to create a Bitmap\n");
1794 if(stat != Ok){
1795 IStream_Release(stream);
1796 return;
1799 /* Check metadata */
1800 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1801 expect(Ok, stat);
1802 expect(1, count);
1804 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1805 expect(Ok, stat);
1806 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1808 count = 12345;
1809 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1810 expect(Ok, stat);
1811 expect(1, count);
1813 GdipDisposeImage((GpImage*)bmp);
1814 IStream_Release(stream);
1817 static void test_rotateflip(void)
1819 GpImage *bitmap;
1820 GpStatus stat;
1821 BYTE bits[24];
1822 static const BYTE orig_bits[24] = {
1823 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
1824 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
1825 UINT width, height;
1826 ARGB color;
1828 memcpy(bits, orig_bits, sizeof(bits));
1829 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1830 expect(Ok, stat);
1832 stat = GdipImageRotateFlip(bitmap, Rotate90FlipNone);
1833 expect(Ok, stat);
1835 stat = GdipGetImageWidth(bitmap, &width);
1836 expect(Ok, stat);
1837 stat = GdipGetImageHeight(bitmap, &height);
1838 expect(Ok, stat);
1839 expect(2, width);
1840 expect(3, height);
1842 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1843 expect(Ok, stat);
1844 expect(0xff00ffff, color);
1846 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 0, &color);
1847 expect(Ok, stat);
1848 expect(0xffff0000, color);
1850 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 2, &color);
1851 expect(Ok, stat);
1852 expect(0xffffff00, color);
1854 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 2, &color);
1855 expect(Ok, stat);
1856 expect(0xff0000ff, color);
1858 expect(0, bits[0]);
1859 expect(0, bits[1]);
1860 expect(0xff, bits[2]);
1862 GdipDisposeImage(bitmap);
1864 memcpy(bits, orig_bits, sizeof(bits));
1865 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1866 expect(Ok, stat);
1868 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipX);
1869 expect(Ok, stat);
1871 stat = GdipGetImageWidth(bitmap, &width);
1872 expect(Ok, stat);
1873 stat = GdipGetImageHeight(bitmap, &height);
1874 expect(Ok, stat);
1875 expect(3, width);
1876 expect(2, height);
1878 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1879 expect(Ok, stat);
1880 expect(0xff0000ff, color);
1882 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
1883 expect(Ok, stat);
1884 expect(0xffff0000, color);
1886 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
1887 expect(Ok, stat);
1888 expect(0xffffff00, color);
1890 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
1891 expect(Ok, stat);
1892 expect(0xff00ffff, color);
1894 expect(0, bits[0]);
1895 expect(0, bits[1]);
1896 expect(0xff, bits[2]);
1898 GdipDisposeImage(bitmap);
1900 memcpy(bits, orig_bits, sizeof(bits));
1901 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1902 expect(Ok, stat);
1904 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipY);
1905 expect(Ok, stat);
1907 stat = GdipGetImageWidth(bitmap, &width);
1908 expect(Ok, stat);
1909 stat = GdipGetImageHeight(bitmap, &height);
1910 expect(Ok, stat);
1911 expect(3, width);
1912 expect(2, height);
1914 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1915 expect(Ok, stat);
1916 expect(0xff00ffff, color);
1918 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
1919 expect(Ok, stat);
1920 expect(0xffffff00, color);
1922 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
1923 expect(Ok, stat);
1924 expect(0xffff0000, color);
1926 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
1927 expect(Ok, stat);
1928 expect(0xff0000ff, color);
1930 expect(0, bits[0]);
1931 expect(0, bits[1]);
1932 expect(0xff, bits[2]);
1934 GdipDisposeImage(bitmap);
1937 static void test_remaptable(void)
1939 GpStatus stat;
1940 GpImageAttributes *imageattr;
1941 GpBitmap *bitmap1, *bitmap2;
1942 GpGraphics *graphics;
1943 ARGB color;
1944 ColorMap *map;
1946 map = GdipAlloc(sizeof(ColorMap));
1948 map->oldColor.Argb = 0xff00ff00;
1949 map->newColor.Argb = 0xffff00ff;
1951 stat = GdipSetImageAttributesRemapTable(NULL, ColorAdjustTypeDefault, TRUE, 1, map);
1952 expect(InvalidParameter, stat);
1954 stat = GdipCreateImageAttributes(&imageattr);
1955 expect(Ok, stat);
1957 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, NULL);
1958 expect(InvalidParameter, stat);
1960 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeCount, TRUE, 1, map);
1961 expect(InvalidParameter, stat);
1963 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeAny, TRUE, 1, map);
1964 expect(InvalidParameter, stat);
1966 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 0, map);
1967 expect(InvalidParameter, stat);
1969 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, FALSE, 0, NULL);
1970 expect(Ok, stat);
1972 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, map);
1973 expect(Ok, stat);
1975 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1976 expect(Ok, stat);
1978 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1979 expect(Ok, stat);
1981 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff00ff00);
1982 expect(Ok, stat);
1984 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1985 expect(Ok, stat);
1987 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1988 UnitPixel, imageattr, NULL, NULL);
1989 expect(Ok, stat);
1991 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1992 expect(Ok, stat);
1993 ok(color_match(0xffff00ff, color, 1), "Expected ffff00ff, got %.8x\n", color);
1995 GdipDeleteGraphics(graphics);
1996 GdipDisposeImage((GpImage*)bitmap1);
1997 GdipDisposeImage((GpImage*)bitmap2);
1998 GdipDisposeImageAttributes(imageattr);
1999 GdipFree(map);
2002 START_TEST(image)
2004 struct GdiplusStartupInput gdiplusStartupInput;
2005 ULONG_PTR gdiplusToken;
2007 gdiplusStartupInput.GdiplusVersion = 1;
2008 gdiplusStartupInput.DebugEventCallback = NULL;
2009 gdiplusStartupInput.SuppressBackgroundThread = 0;
2010 gdiplusStartupInput.SuppressExternalCodecs = 0;
2012 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
2014 test_Scan0();
2015 test_FromGdiDib();
2016 test_GetImageDimension();
2017 test_GdipImageGetFrameDimensionsCount();
2018 test_LoadingImages();
2019 test_SavingImages();
2020 test_encoders();
2021 test_LockBits();
2022 test_GdipCreateBitmapFromHBITMAP();
2023 test_GdipGetImageFlags();
2024 test_GdipCloneImage();
2025 test_testcontrol();
2026 test_fromhicon();
2027 test_getrawformat();
2028 test_loadwmf();
2029 test_createfromwmf();
2030 test_resolution();
2031 test_createhbitmap();
2032 test_getsetpixel();
2033 test_palette();
2034 test_colormatrix();
2035 test_gamma();
2036 test_multiframegif();
2037 test_rotateflip();
2038 test_remaptable();
2040 GdiplusShutdown(gdiplusToken);