Release 1.6-rc2.
[wine/testsucceed.git] / dlls / gdiplus / tests / image.c
blob18e159b6c719a475ae8933f359a897f9c7e674d2
1 /*
2 * Unit test suite for images
4 * Copyright (C) 2007 Google (Evan Stade)
5 * Copyright (C) 2012 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define COBJMACROS
24 #include <math.h>
25 #include <assert.h>
26 #include <stdio.h>
28 #include "initguid.h"
29 #include "windows.h"
30 #include "gdiplus.h"
31 #include "wine/test.h"
33 #define expect(expected, got) ok((got) == (expected), "Expected %d, got %d\n", (UINT)(expected), (UINT)(got))
34 #define expectf(expected, got) ok(fabs((expected) - (got)) < 0.0001, "Expected %f, got %f\n", (expected), (got))
36 static BOOL color_match(ARGB c1, ARGB c2, BYTE max_diff)
38 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
39 c1 >>= 8; c2 >>= 8;
40 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
41 c1 >>= 8; c2 >>= 8;
42 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
43 c1 >>= 8; c2 >>= 8;
44 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
45 return TRUE;
48 static void expect_guid(REFGUID expected, REFGUID got, int line, BOOL todo)
50 WCHAR bufferW[39];
51 char buffer[39];
52 char buffer2[39];
54 StringFromGUID2(got, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
55 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer, sizeof(buffer), NULL, NULL);
56 StringFromGUID2(expected, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
57 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer2, sizeof(buffer2), NULL, NULL);
58 if(todo)
59 todo_wine ok_(__FILE__, line)(IsEqualGUID(expected, got), "Expected %s, got %s\n", buffer2, buffer);
60 else
61 ok_(__FILE__, line)(IsEqualGUID(expected, got), "Expected %s, got %s\n", buffer2, buffer);
64 static void expect_rawformat(REFGUID expected, GpImage *img, int line, BOOL todo)
66 GUID raw;
67 GpStatus stat;
69 stat = GdipGetImageRawFormat(img, &raw);
70 ok_(__FILE__, line)(stat == Ok, "GdipGetImageRawFormat failed with %d\n", stat);
71 if(stat != Ok) return;
72 expect_guid(expected, &raw, line, todo);
75 static void test_bufferrawformat(void* buff, int size, REFGUID expected, int line, BOOL todo)
77 LPSTREAM stream;
78 HGLOBAL hglob;
79 LPBYTE data;
80 HRESULT hres;
81 GpStatus stat;
82 GpImage *img;
84 hglob = GlobalAlloc (0, size);
85 data = GlobalLock (hglob);
86 memcpy(data, buff, size);
87 GlobalUnlock(hglob); data = NULL;
89 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
90 ok_(__FILE__, line)(hres == S_OK, "Failed to create a stream\n");
91 if(hres != S_OK) return;
93 stat = GdipLoadImageFromStream(stream, &img);
94 ok_(__FILE__, line)(stat == Ok, "Failed to create a Bitmap\n");
95 if(stat != Ok){
96 IStream_Release(stream);
97 return;
100 expect_rawformat(expected, img, line, todo);
102 GdipDisposeImage(img);
103 IStream_Release(stream);
106 static void test_Scan0(void)
108 GpBitmap *bm;
109 GpStatus stat;
110 BYTE buff[360];
112 bm = NULL;
113 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
114 expect(Ok, stat);
115 ok(NULL != bm, "Expected bitmap to be initialized\n");
116 if (stat == Ok)
117 GdipDisposeImage((GpImage*)bm);
119 bm = (GpBitmap*)0xdeadbeef;
120 stat = GdipCreateBitmapFromScan0(10, -10, 10, PixelFormat24bppRGB, NULL, &bm);
121 expect(InvalidParameter, stat);
122 ok( !bm, "expected null bitmap\n" );
124 bm = (GpBitmap*)0xdeadbeef;
125 stat = GdipCreateBitmapFromScan0(-10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
126 expect(InvalidParameter, stat);
127 ok( !bm, "expected null bitmap\n" );
129 bm = (GpBitmap*)0xdeadbeef;
130 stat = GdipCreateBitmapFromScan0(10, 0, 10, PixelFormat24bppRGB, NULL, &bm);
131 expect(InvalidParameter, stat);
132 ok( !bm, "expected null bitmap\n" );
134 bm = NULL;
135 stat = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, buff, &bm);
136 expect(Ok, stat);
137 ok(NULL != bm, "Expected bitmap to be initialized\n");
138 if (stat == Ok)
139 GdipDisposeImage((GpImage*)bm);
141 bm = (GpBitmap*) 0xdeadbeef;
142 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, buff, &bm);
143 expect(InvalidParameter, stat);
144 ok( !bm, "expected null bitmap\n" );
146 bm = (GpBitmap*)0xdeadbeef;
147 stat = GdipCreateBitmapFromScan0(10, 10, 0, PixelFormat24bppRGB, buff, &bm);
148 expect(InvalidParameter, stat);
149 ok( bm == (GpBitmap*)0xdeadbeef, "expected deadbeef bitmap\n" );
151 bm = NULL;
152 stat = GdipCreateBitmapFromScan0(10, 10, -8, PixelFormat24bppRGB, buff, &bm);
153 expect(Ok, stat);
154 ok(NULL != bm, "Expected bitmap to be initialized\n");
155 if (stat == Ok)
156 GdipDisposeImage((GpImage*)bm);
158 bm = (GpBitmap*)0xdeadbeef;
159 stat = GdipCreateBitmapFromScan0(10, 10, -10, PixelFormat24bppRGB, buff, &bm);
160 expect(InvalidParameter, stat);
161 ok( !bm, "expected null bitmap\n" );
164 static void test_FromGdiDib(void)
166 GpBitmap *bm;
167 GpStatus stat;
168 BYTE buff[400];
169 BYTE rbmi[sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)];
170 BITMAPINFO *bmi = (BITMAPINFO*)rbmi;
171 PixelFormat format;
173 bm = NULL;
175 memset(rbmi, 0, sizeof(rbmi));
177 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
178 bmi->bmiHeader.biWidth = 10;
179 bmi->bmiHeader.biHeight = 10;
180 bmi->bmiHeader.biPlanes = 1;
181 bmi->bmiHeader.biBitCount = 32;
182 bmi->bmiHeader.biCompression = BI_RGB;
184 stat = GdipCreateBitmapFromGdiDib(NULL, buff, &bm);
185 expect(InvalidParameter, stat);
187 stat = GdipCreateBitmapFromGdiDib(bmi, NULL, &bm);
188 expect(InvalidParameter, stat);
190 stat = GdipCreateBitmapFromGdiDib(bmi, buff, NULL);
191 expect(InvalidParameter, stat);
193 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
194 expect(Ok, stat);
195 ok(NULL != bm, "Expected bitmap to be initialized\n");
196 if (stat == Ok)
198 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
199 expect(Ok, stat);
200 expect(PixelFormat32bppRGB, format);
202 GdipDisposeImage((GpImage*)bm);
205 bmi->bmiHeader.biBitCount = 24;
206 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
207 expect(Ok, stat);
208 ok(NULL != bm, "Expected bitmap to be initialized\n");
209 if (stat == Ok)
211 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
212 expect(Ok, stat);
213 expect(PixelFormat24bppRGB, format);
215 GdipDisposeImage((GpImage*)bm);
218 bmi->bmiHeader.biBitCount = 16;
219 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
220 expect(Ok, stat);
221 ok(NULL != bm, "Expected bitmap to be initialized\n");
222 if (stat == Ok)
224 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
225 expect(Ok, stat);
226 expect(PixelFormat16bppRGB555, format);
228 GdipDisposeImage((GpImage*)bm);
231 bmi->bmiHeader.biBitCount = 8;
232 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
233 expect(Ok, stat);
234 ok(NULL != bm, "Expected bitmap to be initialized\n");
235 if (stat == Ok)
237 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
238 expect(Ok, stat);
239 expect(PixelFormat8bppIndexed, format);
241 GdipDisposeImage((GpImage*)bm);
244 bmi->bmiHeader.biBitCount = 4;
245 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
246 expect(Ok, stat);
247 ok(NULL != bm, "Expected bitmap to be initialized\n");
248 if (stat == Ok)
250 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
251 expect(Ok, stat);
252 expect(PixelFormat4bppIndexed, format);
254 GdipDisposeImage((GpImage*)bm);
257 bmi->bmiHeader.biBitCount = 1;
258 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
259 expect(Ok, stat);
260 ok(NULL != bm, "Expected bitmap to be initialized\n");
261 if (stat == Ok)
263 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
264 expect(Ok, stat);
265 expect(PixelFormat1bppIndexed, format);
267 GdipDisposeImage((GpImage*)bm);
270 bmi->bmiHeader.biBitCount = 0;
271 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
272 expect(InvalidParameter, stat);
275 static void test_GetImageDimension(void)
277 GpBitmap *bm;
278 GpStatus stat;
279 const REAL WIDTH = 10.0, HEIGHT = 20.0;
280 REAL w,h;
282 bm = (GpBitmap*)0xdeadbeef;
283 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
284 expect(Ok,stat);
285 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
286 ok(NULL != bm, "Expected bitmap to not be NULL\n");
288 stat = GdipGetImageDimension(NULL,&w,&h);
289 expect(InvalidParameter, stat);
291 stat = GdipGetImageDimension((GpImage*)bm,NULL,&h);
292 expect(InvalidParameter, stat);
294 stat = GdipGetImageDimension((GpImage*)bm,&w,NULL);
295 expect(InvalidParameter, stat);
297 w = -1;
298 h = -1;
299 stat = GdipGetImageDimension((GpImage*)bm,&w,&h);
300 expect(Ok, stat);
301 expectf(WIDTH, w);
302 expectf(HEIGHT, h);
303 GdipDisposeImage((GpImage*)bm);
306 static void test_GdipImageGetFrameDimensionsCount(void)
308 GpBitmap *bm;
309 GpStatus stat;
310 const REAL WIDTH = 10.0, HEIGHT = 20.0;
311 UINT w;
312 GUID dimension = {0};
313 UINT count;
314 ARGB color;
316 bm = (GpBitmap*)0xdeadbeef;
317 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
318 expect(Ok,stat);
319 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
320 ok(NULL != bm, "Expected bitmap to not be NULL\n");
322 stat = GdipImageGetFrameDimensionsCount(NULL,&w);
323 expect(InvalidParameter, stat);
325 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,NULL);
326 expect(InvalidParameter, stat);
328 w = -1;
329 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,&w);
330 expect(Ok, stat);
331 expect(1, w);
333 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 1);
334 expect(Ok, stat);
335 expect_guid(&FrameDimensionPage, &dimension, __LINE__, FALSE);
337 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 2);
338 expect(InvalidParameter, stat);
340 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 0);
341 expect(InvalidParameter, stat);
343 stat = GdipImageGetFrameCount(NULL, &dimension, &count);
344 expect(InvalidParameter, stat);
346 /* WinXP crashes on this test */
347 if(0)
349 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, NULL);
350 expect(InvalidParameter, stat);
353 stat = GdipImageGetFrameCount((GpImage*)bm, NULL, &count);
354 expect(Ok, stat);
356 count = 12345;
357 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, &count);
358 expect(Ok, stat);
359 expect(1, count);
361 GdipBitmapSetPixel(bm, 0, 0, 0xffffffff);
363 stat = GdipImageSelectActiveFrame((GpImage*)bm, &dimension, 0);
364 expect(Ok, stat);
366 /* SelectActiveFrame has no effect on image data of memory bitmaps */
367 color = 0xdeadbeef;
368 GdipBitmapGetPixel(bm, 0, 0, &color);
369 expect(0xffffffff, color);
371 GdipDisposeImage((GpImage*)bm);
374 static void test_LoadingImages(void)
376 GpStatus stat;
378 stat = GdipCreateBitmapFromFile(0, 0);
379 expect(InvalidParameter, stat);
381 stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
382 expect(InvalidParameter, stat);
384 stat = GdipLoadImageFromFile(0, 0);
385 expect(InvalidParameter, stat);
387 stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
388 expect(InvalidParameter, stat);
390 stat = GdipLoadImageFromFileICM(0, 0);
391 expect(InvalidParameter, stat);
393 stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
394 expect(InvalidParameter, stat);
397 static void test_SavingImages(void)
399 GpStatus stat;
400 GpBitmap *bm;
401 UINT n;
402 UINT s;
403 const REAL WIDTH = 10.0, HEIGHT = 20.0;
404 REAL w, h;
405 ImageCodecInfo *codecs;
406 static const CHAR filenameA[] = "a.bmp";
407 static const WCHAR filename[] = { 'a','.','b','m','p',0 };
409 codecs = NULL;
411 stat = GdipSaveImageToFile(0, 0, 0, 0);
412 expect(InvalidParameter, stat);
414 bm = NULL;
415 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
416 expect(Ok, stat);
417 if (!bm)
418 return;
420 /* invalid params */
421 stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
422 expect(InvalidParameter, stat);
424 stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
425 expect(InvalidParameter, stat);
427 /* encoder tests should succeed -- already tested */
428 stat = GdipGetImageEncodersSize(&n, &s);
429 if (stat != Ok || n == 0) goto cleanup;
431 codecs = GdipAlloc(s);
432 if (!codecs) goto cleanup;
434 stat = GdipGetImageEncoders(n, s, codecs);
435 if (stat != Ok) goto cleanup;
437 stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
438 expect(Ok, stat);
440 GdipDisposeImage((GpImage*)bm);
441 bm = 0;
443 /* re-load and check image stats */
444 stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
445 expect(Ok, stat);
446 if (stat != Ok) goto cleanup;
448 stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
449 if (stat != Ok) goto cleanup;
451 expectf(WIDTH, w);
452 expectf(HEIGHT, h);
454 cleanup:
455 GdipFree(codecs);
456 if (bm)
457 GdipDisposeImage((GpImage*)bm);
458 ok(DeleteFileA(filenameA), "Delete failed.\n");
461 static void test_encoders(void)
463 GpStatus stat;
464 UINT n;
465 UINT s;
466 ImageCodecInfo *codecs;
467 int i;
468 int bmp_found;
470 static const CHAR bmp_format[] = "BMP";
472 stat = GdipGetImageEncodersSize(&n, &s);
473 expect(stat, Ok);
475 codecs = GdipAlloc(s);
476 if (!codecs)
477 return;
479 stat = GdipGetImageEncoders(n, s, NULL);
480 expect(GenericError, stat);
482 stat = GdipGetImageEncoders(0, s, codecs);
483 expect(GenericError, stat);
485 stat = GdipGetImageEncoders(n, s-1, codecs);
486 expect(GenericError, stat);
488 stat = GdipGetImageEncoders(n, s+1, codecs);
489 expect(GenericError, stat);
491 stat = GdipGetImageEncoders(n, s, codecs);
492 expect(stat, Ok);
494 bmp_found = FALSE;
495 for (i = 0; i < n; i++)
497 CHAR desc[32];
499 WideCharToMultiByte(CP_ACP, 0, codecs[i].FormatDescription, -1,
500 desc, 32, 0, 0);
502 if (CompareStringA(LOCALE_SYSTEM_DEFAULT, 0,
503 desc, -1,
504 bmp_format, -1) == CSTR_EQUAL) {
505 bmp_found = TRUE;
506 break;
509 if (!bmp_found)
510 ok(FALSE, "No BMP codec found.\n");
512 GdipFree(codecs);
515 static void test_LockBits(void)
517 GpStatus stat;
518 GpBitmap *bm;
519 GpRect rect;
520 BitmapData bd;
521 const INT WIDTH = 10, HEIGHT = 20;
522 ARGB color;
523 int y;
525 bm = NULL;
526 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
527 expect(Ok, stat);
529 rect.X = 2;
530 rect.Y = 3;
531 rect.Width = 4;
532 rect.Height = 5;
534 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffc30000);
535 expect(Ok, stat);
537 stat = GdipBitmapSetPixel(bm, 2, 8, 0xff480000);
538 expect(Ok, stat);
540 /* read-only */
541 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
542 expect(Ok, stat);
544 if (stat == Ok) {
545 expect(0xc3, ((BYTE*)bd.Scan0)[2]);
546 expect(0x48, ((BYTE*)bd.Scan0)[2 + bd.Stride * 5]);
548 ((char*)bd.Scan0)[2] = 0xff;
550 stat = GdipBitmapUnlockBits(bm, &bd);
551 expect(Ok, stat);
554 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
555 expect(Ok, stat);
556 expect(0xffff0000, color);
558 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffc30000);
559 expect(Ok, stat);
561 /* read-only, with NULL rect -> whole bitmap lock */
562 stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
563 expect(Ok, stat);
564 expect(bd.Width, WIDTH);
565 expect(bd.Height, HEIGHT);
567 if (stat == Ok) {
568 ((char*)bd.Scan0)[2 + 2*3 + 3*bd.Stride] = 0xff;
570 stat = GdipBitmapUnlockBits(bm, &bd);
571 expect(Ok, stat);
574 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
575 expect(Ok, stat);
576 expect(0xffff0000, color);
578 /* read-only, consecutive */
579 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
580 expect(Ok, stat);
582 if (stat == Ok) {
583 stat = GdipBitmapUnlockBits(bm, &bd);
584 expect(Ok, stat);
587 stat = GdipDisposeImage((GpImage*)bm);
588 expect(Ok, stat);
589 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
590 expect(Ok, stat);
592 /* read x2 */
593 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
594 expect(Ok, stat);
595 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
596 expect(WrongState, stat);
598 stat = GdipBitmapUnlockBits(bm, &bd);
599 expect(Ok, stat);
601 stat = GdipDisposeImage((GpImage*)bm);
602 expect(Ok, stat);
603 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
604 expect(Ok, stat);
606 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffff0000);
607 expect(Ok, stat);
609 stat = GdipBitmapSetPixel(bm, 2, 8, 0xffc30000);
610 expect(Ok, stat);
612 /* write, no conversion */
613 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
614 expect(Ok, stat);
616 if (stat == Ok) {
617 /* all bits are readable, inside the rect or not */
618 expect(0xff, ((BYTE*)bd.Scan0)[2]);
619 expect(0xc3, ((BYTE*)bd.Scan0)[2 + bd.Stride * 5]);
621 stat = GdipBitmapUnlockBits(bm, &bd);
622 expect(Ok, stat);
625 /* read, conversion */
626 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat32bppARGB, &bd);
627 expect(Ok, stat);
629 if (stat == Ok) {
630 expect(0xff, ((BYTE*)bd.Scan0)[2]);
631 if (0)
632 /* Areas outside the rectangle appear to be uninitialized */
633 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
635 ((BYTE*)bd.Scan0)[2] = 0xc3;
637 stat = GdipBitmapUnlockBits(bm, &bd);
638 expect(Ok, stat);
641 /* writes do not work in read mode if there was a conversion */
642 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
643 expect(Ok, stat);
644 expect(0xffff0000, color);
646 /* read/write, conversion */
647 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeWrite, PixelFormat32bppARGB, &bd);
648 expect(Ok, stat);
650 if (stat == Ok) {
651 expect(0xff, ((BYTE*)bd.Scan0)[2]);
652 ((BYTE*)bd.Scan0)[1] = 0x88;
653 if (0)
654 /* Areas outside the rectangle appear to be uninitialized */
655 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
657 stat = GdipBitmapUnlockBits(bm, &bd);
658 expect(Ok, stat);
661 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
662 expect(Ok, stat);
663 expect(0xffff8800, color);
665 /* write, conversion */
666 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat32bppARGB, &bd);
667 expect(Ok, stat);
669 if (stat == Ok) {
670 if (0)
672 /* This is completely uninitialized. */
673 ok(0xff != ((BYTE*)bd.Scan0)[2], "original image bits are readable\n");
674 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
677 /* Initialize the buffer so the unlock doesn't access undefined memory */
678 for (y=0; y<5; y++)
679 memset(((BYTE*)bd.Scan0) + bd.Stride * y, 0, 12);
681 ((BYTE*)bd.Scan0)[0] = 0x12;
682 ((BYTE*)bd.Scan0)[1] = 0x34;
683 ((BYTE*)bd.Scan0)[2] = 0x56;
685 stat = GdipBitmapUnlockBits(bm, &bd);
686 expect(Ok, stat);
689 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
690 expect(Ok, stat);
691 expect(0xff563412, color);
693 stat = GdipBitmapGetPixel(bm, 2, 8, &color);
694 expect(Ok, stat);
695 expect(0xffc30000, color);
697 stat = GdipDisposeImage((GpImage*)bm);
698 expect(Ok, stat);
699 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
700 expect(Ok, stat);
702 /* write, no modification */
703 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
704 expect(Ok, stat);
706 if (stat == Ok) {
707 stat = GdipBitmapUnlockBits(bm, &bd);
708 expect(Ok, stat);
711 /* write, consecutive */
712 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
713 expect(Ok, stat);
715 if (stat == Ok) {
716 stat = GdipBitmapUnlockBits(bm, &bd);
717 expect(Ok, stat);
720 stat = GdipDisposeImage((GpImage*)bm);
721 expect(Ok, stat);
722 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
723 expect(Ok, stat);
725 /* write, modify */
726 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
727 expect(Ok, stat);
729 if (stat == Ok) {
730 if (bd.Scan0)
731 ((char*)bd.Scan0)[2] = 0xff;
733 stat = GdipBitmapUnlockBits(bm, &bd);
734 expect(Ok, stat);
737 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
738 expect(Ok, stat);
739 expect(0xffff0000, color);
741 stat = GdipDisposeImage((GpImage*)bm);
742 expect(Ok, stat);
744 /* dispose locked */
745 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
746 expect(Ok, stat);
747 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
748 expect(Ok, stat);
749 stat = GdipDisposeImage((GpImage*)bm);
750 expect(Ok, stat);
753 static void test_LockBits_UserBuf(void)
755 GpStatus stat;
756 GpBitmap *bm;
757 GpRect rect;
758 BitmapData bd;
759 const INT WIDTH = 10, HEIGHT = 20;
760 DWORD bits[200];
761 ARGB color;
763 bm = NULL;
764 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat32bppARGB, NULL, &bm);
765 expect(Ok, stat);
767 memset(bits, 0xaa, sizeof(bits));
769 rect.X = 2;
770 rect.Y = 3;
771 rect.Width = 4;
772 rect.Height = 5;
774 bd.Width = 4;
775 bd.Height = 6;
776 bd.Stride = WIDTH * 4;
777 bd.PixelFormat = PixelFormat32bppARGB;
778 bd.Scan0 = &bits[2+3*WIDTH];
779 bd.Reserved = 0xaaaaaaaa;
781 /* read-only */
782 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
783 expect(Ok, stat);
785 expect(0xaaaaaaaa, bits[0]);
786 expect(0, bits[2+3*WIDTH]);
788 bits[2+3*WIDTH] = 0xdeadbeef;
790 if (stat == Ok) {
791 stat = GdipBitmapUnlockBits(bm, &bd);
792 expect(Ok, stat);
795 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
796 expect(Ok, stat);
797 expect(0, color);
799 /* write-only */
800 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
801 expect(Ok, stat);
803 expect(0xdeadbeef, bits[2+3*WIDTH]);
804 bits[2+3*WIDTH] = 0x12345678;
806 if (stat == Ok) {
807 stat = GdipBitmapUnlockBits(bm, &bd);
808 expect(Ok, stat);
811 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
812 expect(Ok, stat);
813 expect(0x12345678, color);
815 bits[2+3*WIDTH] = 0;
817 /* read/write */
818 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeWrite|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
819 expect(Ok, stat);
821 expect(0x12345678, bits[2+3*WIDTH]);
822 bits[2+3*WIDTH] = 0xdeadbeef;
824 if (stat == Ok) {
825 stat = GdipBitmapUnlockBits(bm, &bd);
826 expect(Ok, stat);
829 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
830 expect(Ok, stat);
831 expect(0xdeadbeef, color);
833 stat = GdipDisposeImage((GpImage*)bm);
834 expect(Ok, stat);
837 struct BITMAPINFOWITHBITFIELDS
839 BITMAPINFOHEADER bmiHeader;
840 DWORD masks[3];
843 union BITMAPINFOUNION
845 BITMAPINFO bi;
846 struct BITMAPINFOWITHBITFIELDS bf;
849 static void test_GdipCreateBitmapFromHBITMAP(void)
851 GpBitmap* gpbm = NULL;
852 HBITMAP hbm = NULL;
853 HPALETTE hpal = NULL;
854 GpStatus stat;
855 BYTE buff[1000];
856 LOGPALETTE* LogPal = NULL;
857 REAL width, height;
858 const REAL WIDTH1 = 5;
859 const REAL HEIGHT1 = 15;
860 const REAL WIDTH2 = 10;
861 const REAL HEIGHT2 = 20;
862 HDC hdc;
863 union BITMAPINFOUNION bmi;
864 BYTE *bits;
865 PixelFormat format;
867 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
868 expect(InvalidParameter, stat);
870 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
871 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
872 expect(InvalidParameter, stat);
874 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
875 expect(Ok, stat);
876 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
877 expectf(WIDTH1, width);
878 expectf(HEIGHT1, height);
879 if (stat == Ok)
880 GdipDisposeImage((GpImage*)gpbm);
881 DeleteObject(hbm);
883 memset(buff, 0, sizeof(buff));
884 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
885 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
886 expect(Ok, stat);
887 /* raw format */
888 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
890 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
891 expectf(WIDTH2, width);
892 expectf(HEIGHT2, height);
893 if (stat == Ok)
894 GdipDisposeImage((GpImage*)gpbm);
895 DeleteObject(hbm);
897 hdc = CreateCompatibleDC(0);
898 ok(hdc != NULL, "CreateCompatibleDC failed\n");
899 bmi.bi.bmiHeader.biSize = sizeof(bmi.bi.bmiHeader);
900 bmi.bi.bmiHeader.biHeight = HEIGHT1;
901 bmi.bi.bmiHeader.biWidth = WIDTH1;
902 bmi.bi.bmiHeader.biBitCount = 24;
903 bmi.bi.bmiHeader.biPlanes = 1;
904 bmi.bi.bmiHeader.biCompression = BI_RGB;
905 bmi.bi.bmiHeader.biClrUsed = 0;
907 hbm = CreateDIBSection(hdc, &bmi.bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
908 ok(hbm != NULL, "CreateDIBSection failed\n");
910 bits[0] = 0;
912 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
913 expect(Ok, stat);
914 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
915 expectf(WIDTH1, width);
916 expectf(HEIGHT1, height);
917 if (stat == Ok)
919 /* test whether writing to the bitmap affects the original */
920 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
921 expect(Ok, stat);
923 expect(0, bits[0]);
925 GdipDisposeImage((GpImage*)gpbm);
928 LogPal = GdipAlloc(sizeof(LOGPALETTE));
929 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
930 LogPal->palVersion = 0x300;
931 LogPal->palNumEntries = 1;
932 hpal = CreatePalette(LogPal);
933 ok(hpal != NULL, "CreatePalette failed\n");
934 GdipFree(LogPal);
936 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
937 expect(Ok, stat);
939 if (stat == Ok)
940 GdipDisposeImage((GpImage*)gpbm);
942 DeleteObject(hpal);
943 DeleteObject(hbm);
945 /* 16-bit 555 dib, rgb */
946 bmi.bi.bmiHeader.biBitCount = 16;
947 bmi.bi.bmiHeader.biCompression = BI_RGB;
949 hbm = CreateDIBSection(hdc, &bmi.bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
950 ok(hbm != NULL, "CreateDIBSection failed\n");
952 bits[0] = 0;
954 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
955 expect(Ok, stat);
957 if (stat == Ok)
959 stat = GdipGetImageDimension((GpImage*) gpbm, &width, &height);
960 expect(Ok, stat);
961 expectf(WIDTH1, width);
962 expectf(HEIGHT1, height);
964 stat = GdipGetImagePixelFormat((GpImage*) gpbm, &format);
965 expect(Ok, stat);
966 expect(PixelFormat16bppRGB555, format);
968 GdipDisposeImage((GpImage*)gpbm);
970 DeleteObject(hbm);
972 /* 16-bit 555 dib, with bitfields */
973 bmi.bi.bmiHeader.biSize = sizeof(bmi);
974 bmi.bi.bmiHeader.biCompression = BI_BITFIELDS;
975 bmi.bf.masks[0] = 0x7c00;
976 bmi.bf.masks[1] = 0x3e0;
977 bmi.bf.masks[2] = 0x1f;
979 hbm = CreateDIBSection(hdc, &bmi.bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
980 ok(hbm != NULL, "CreateDIBSection failed\n");
982 bits[0] = 0;
984 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
985 expect(Ok, stat);
987 if (stat == Ok)
989 stat = GdipGetImageDimension((GpImage*) gpbm, &width, &height);
990 expect(Ok, stat);
991 expectf(WIDTH1, width);
992 expectf(HEIGHT1, height);
994 stat = GdipGetImagePixelFormat((GpImage*) gpbm, &format);
995 expect(Ok, stat);
996 expect(PixelFormat16bppRGB555, format);
998 GdipDisposeImage((GpImage*)gpbm);
1000 DeleteObject(hbm);
1002 /* 16-bit 565 dib, with bitfields */
1003 bmi.bf.masks[0] = 0xf800;
1004 bmi.bf.masks[1] = 0x7e0;
1005 bmi.bf.masks[2] = 0x1f;
1007 hbm = CreateDIBSection(hdc, &bmi.bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
1008 ok(hbm != NULL, "CreateDIBSection failed\n");
1010 bits[0] = 0;
1012 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
1013 expect(Ok, stat);
1015 if (stat == Ok)
1017 stat = GdipGetImageDimension((GpImage*) gpbm, &width, &height);
1018 expect(Ok, stat);
1019 expectf(WIDTH1, width);
1020 expectf(HEIGHT1, height);
1022 stat = GdipGetImagePixelFormat((GpImage*) gpbm, &format);
1023 expect(Ok, stat);
1024 expect(PixelFormat16bppRGB565, format);
1026 GdipDisposeImage((GpImage*)gpbm);
1028 DeleteObject(hbm);
1030 DeleteDC(hdc);
1033 static void test_GdipGetImageFlags(void)
1035 GpImage *img;
1036 GpStatus stat;
1037 UINT flags;
1039 img = (GpImage*)0xdeadbeef;
1041 stat = GdipGetImageFlags(NULL, NULL);
1042 expect(InvalidParameter, stat);
1044 stat = GdipGetImageFlags(NULL, &flags);
1045 expect(InvalidParameter, stat);
1047 stat = GdipGetImageFlags(img, NULL);
1048 expect(InvalidParameter, stat);
1050 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, (GpBitmap**)&img);
1051 expect(Ok, stat);
1052 stat = GdipGetImageFlags(img, &flags);
1053 expect(Ok, stat);
1054 expect(ImageFlagsHasAlpha, flags);
1055 GdipDisposeImage(img);
1057 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, (GpBitmap**)&img);
1058 expect(Ok, stat);
1059 stat = GdipGetImageFlags(img, &flags);
1060 expect(Ok, stat);
1061 expect(ImageFlagsHasAlpha, flags);
1062 GdipDisposeImage(img);
1064 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, (GpBitmap**)&img);
1065 expect(Ok, stat);
1066 stat = GdipGetImageFlags(img, &flags);
1067 expect(Ok, stat);
1068 expect(ImageFlagsHasAlpha, flags);
1069 GdipDisposeImage(img);
1071 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, (GpBitmap**)&img);
1072 expect(Ok, stat);
1073 stat = GdipGetImageFlags(img, &flags);
1074 expect(Ok, stat);
1075 expect(ImageFlagsNone, flags);
1076 GdipDisposeImage(img);
1078 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, (GpBitmap**)&img);
1079 expect(Ok, stat);
1080 stat = GdipGetImageFlags(img, &flags);
1081 expect(Ok, stat);
1082 expect(ImageFlagsNone, flags);
1083 GdipDisposeImage(img);
1085 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, (GpBitmap**)&img);
1086 expect(Ok, stat);
1087 stat = GdipGetImageFlags(img, &flags);
1088 expect(Ok, stat);
1089 expect(ImageFlagsNone, flags);
1090 GdipDisposeImage(img);
1092 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppARGB1555, NULL, (GpBitmap**)&img);
1093 expect(Ok, stat);
1094 stat = GdipGetImageFlags(img, &flags);
1095 expect(Ok, stat);
1096 expect(ImageFlagsHasAlpha, flags);
1097 GdipDisposeImage(img);
1099 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, (GpBitmap**)&img);
1100 expect(Ok, stat);
1101 stat = GdipGetImageFlags(img, &flags);
1102 expect(Ok, stat);
1103 expect(ImageFlagsNone, flags);
1104 GdipDisposeImage(img);
1106 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, (GpBitmap**)&img);
1107 expect(Ok, stat);
1108 stat = GdipGetImageFlags(img, &flags);
1109 expect(Ok, stat);
1110 expect(ImageFlagsNone, flags);
1111 GdipDisposeImage(img);
1113 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, (GpBitmap**)&img);
1114 expect(Ok, stat);
1115 stat = GdipGetImageFlags(img, &flags);
1116 expect(Ok, stat);
1117 expect(ImageFlagsHasAlpha, flags);
1118 GdipDisposeImage(img);
1120 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppPARGB, NULL, (GpBitmap**)&img);
1121 expect(Ok, stat);
1122 stat = GdipGetImageFlags(img, &flags);
1123 expect(Ok, stat);
1124 expect(ImageFlagsHasAlpha, flags);
1125 GdipDisposeImage(img);
1127 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, (GpBitmap**)&img);
1128 expect(Ok, stat);
1129 if (stat == Ok)
1131 stat = GdipGetImageFlags(img, &flags);
1132 expect(Ok, stat);
1133 expect(ImageFlagsNone, flags);
1134 GdipDisposeImage(img);
1137 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, (GpBitmap**)&img);
1138 expect(Ok, stat);
1139 if (stat == Ok)
1141 expect(Ok, stat);
1142 stat = GdipGetImageFlags(img, &flags);
1143 expect(Ok, stat);
1144 expect(ImageFlagsHasAlpha, flags);
1145 GdipDisposeImage(img);
1148 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, (GpBitmap**)&img);
1149 expect(Ok, stat);
1150 if (stat == Ok)
1152 expect(Ok, stat);
1153 stat = GdipGetImageFlags(img, &flags);
1154 expect(Ok, stat);
1155 expect(ImageFlagsHasAlpha, flags);
1156 GdipDisposeImage(img);
1160 static void test_GdipCloneImage(void)
1162 GpStatus stat;
1163 GpRectF rectF;
1164 GpUnit unit;
1165 GpBitmap *bm;
1166 GpImage *image_src, *image_dest = NULL;
1167 const INT WIDTH = 10, HEIGHT = 20;
1169 /* Create an image, clone it, delete the original, make sure the copy works */
1170 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
1171 expect(Ok, stat);
1172 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
1174 image_src = ((GpImage*)bm);
1175 stat = GdipCloneImage(image_src, &image_dest);
1176 expect(Ok, stat);
1177 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
1179 stat = GdipDisposeImage((GpImage*)bm);
1180 expect(Ok, stat);
1181 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
1182 expect(Ok, stat);
1184 /* Treat FP values carefully */
1185 expectf((REAL)WIDTH, rectF.Width);
1186 expectf((REAL)HEIGHT, rectF.Height);
1188 stat = GdipDisposeImage(image_dest);
1189 expect(Ok, stat);
1192 static void test_testcontrol(void)
1194 GpStatus stat;
1195 DWORD param;
1197 param = 0;
1198 stat = GdipTestControl(TestControlGetBuildNumber, &param);
1199 expect(Ok, stat);
1200 ok(param != 0, "Build number expected, got %u\n", param);
1203 static void test_fromhicon(void)
1205 static const BYTE bmp_bits[1024];
1206 HBITMAP hbmMask, hbmColor;
1207 ICONINFO info;
1208 HICON hIcon;
1209 GpStatus stat;
1210 GpBitmap *bitmap = NULL;
1211 UINT dim;
1212 ImageType type;
1213 PixelFormat format;
1215 /* NULL */
1216 stat = GdipCreateBitmapFromHICON(NULL, NULL);
1217 expect(InvalidParameter, stat);
1218 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
1219 expect(InvalidParameter, stat);
1221 /* color icon 1 bit */
1222 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
1223 ok(hbmMask != 0, "CreateBitmap failed\n");
1224 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
1225 ok(hbmColor != 0, "CreateBitmap failed\n");
1226 info.fIcon = TRUE;
1227 info.xHotspot = 8;
1228 info.yHotspot = 8;
1229 info.hbmMask = hbmMask;
1230 info.hbmColor = hbmColor;
1231 hIcon = CreateIconIndirect(&info);
1232 ok(hIcon != 0, "CreateIconIndirect failed\n");
1233 DeleteObject(hbmMask);
1234 DeleteObject(hbmColor);
1236 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
1237 ok(stat == Ok ||
1238 broken(stat == InvalidParameter), /* Win98 */
1239 "Expected Ok, got %.8x\n", stat);
1240 if(stat == Ok){
1241 /* check attributes */
1242 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
1243 expect(Ok, stat);
1244 expect(16, dim);
1245 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
1246 expect(Ok, stat);
1247 expect(16, dim);
1248 stat = GdipGetImageType((GpImage*)bitmap, &type);
1249 expect(Ok, stat);
1250 expect(ImageTypeBitmap, type);
1251 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
1252 expect(Ok, stat);
1253 expect(PixelFormat32bppARGB, format);
1254 /* raw format */
1255 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
1256 GdipDisposeImage((GpImage*)bitmap);
1258 DestroyIcon(hIcon);
1260 /* color icon 8 bpp */
1261 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
1262 ok(hbmMask != 0, "CreateBitmap failed\n");
1263 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
1264 ok(hbmColor != 0, "CreateBitmap failed\n");
1265 info.fIcon = TRUE;
1266 info.xHotspot = 8;
1267 info.yHotspot = 8;
1268 info.hbmMask = hbmMask;
1269 info.hbmColor = hbmColor;
1270 hIcon = CreateIconIndirect(&info);
1271 ok(hIcon != 0, "CreateIconIndirect failed\n");
1272 DeleteObject(hbmMask);
1273 DeleteObject(hbmColor);
1275 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
1276 expect(Ok, stat);
1277 if(stat == Ok){
1278 /* check attributes */
1279 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
1280 expect(Ok, stat);
1281 expect(16, dim);
1282 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
1283 expect(Ok, stat);
1284 expect(16, dim);
1285 stat = GdipGetImageType((GpImage*)bitmap, &type);
1286 expect(Ok, stat);
1287 expect(ImageTypeBitmap, type);
1288 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
1289 expect(Ok, stat);
1290 expect(PixelFormat32bppARGB, format);
1291 /* raw format */
1292 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
1293 GdipDisposeImage((GpImage*)bitmap);
1295 DestroyIcon(hIcon);
1298 /* 1x1 pixel png */
1299 static const unsigned char pngimage[285] = {
1300 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
1301 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
1302 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
1303 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
1304 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
1305 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
1306 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
1308 /* 1x1 pixel gif */
1309 static const unsigned char gifimage[35] = {
1310 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
1311 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
1312 0x01,0x00,0x3b
1314 /* 1x1 pixel bmp */
1315 static const unsigned char bmpimage[66] = {
1316 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
1317 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
1318 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
1319 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
1320 0x00,0x00
1322 /* 1x1 pixel jpg */
1323 static const unsigned char jpgimage[285] = {
1324 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
1325 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
1326 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
1327 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
1328 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
1329 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
1330 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
1331 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1332 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1333 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
1334 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
1335 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1336 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
1337 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
1338 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1339 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
1340 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
1341 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
1343 /* 1x1 pixel tiff */
1344 static const unsigned char tiffimage[] = {
1345 0x49,0x49,0x2a,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xfe,0x00,
1346 0x04,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x00,0x01,0x00,
1347 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1348 0x00,0x00,0x02,0x01,0x03,0x00,0x03,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0x03,0x01,
1349 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,0x01,0x03,0x00,0x01,0x00,
1350 0x00,0x00,0x02,0x00,0x00,0x00,0x0d,0x01,0x02,0x00,0x1b,0x00,0x00,0x00,0xd8,0x00,
1351 0x00,0x00,0x11,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x12,0x01,
1352 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x01,0x03,0x00,0x01,0x00,
1353 0x00,0x00,0x03,0x00,0x00,0x00,0x16,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x40,0x00,
1354 0x00,0x00,0x17,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1a,0x01,
1355 0x05,0x00,0x01,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x1b,0x01,0x05,0x00,0x01,0x00,
1356 0x00,0x00,0xfc,0x00,0x00,0x00,0x1c,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1357 0x00,0x00,0x28,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
1358 0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x6d,0x65,
1359 0x68,0x2f,0x44,0x65,0x73,0x6b,0x74,0x6f,0x70,0x2f,0x74,0x65,0x73,0x74,0x2e,0x74,
1360 0x69,0x66,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,
1361 0x00,0x00,0x00,0x01
1363 /* 320x320 twip wmf */
1364 static const unsigned char wmfimage[180] = {
1365 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
1366 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
1367 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
1368 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
1369 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
1370 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
1371 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
1372 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
1373 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
1374 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
1375 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
1376 0x00,0x00,0x00,0x00
1378 static void test_getrawformat(void)
1380 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
1381 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
1382 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
1383 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
1384 test_bufferrawformat((void*)tiffimage, sizeof(tiffimage), &ImageFormatTIFF, __LINE__, FALSE);
1385 test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
1388 static void test_loadwmf(void)
1390 LPSTREAM stream;
1391 HGLOBAL hglob;
1392 LPBYTE data;
1393 HRESULT hres;
1394 GpStatus stat;
1395 GpImage *img;
1396 GpRectF bounds;
1397 GpUnit unit;
1398 REAL res = 12345.0;
1399 MetafileHeader header;
1401 hglob = GlobalAlloc (0, sizeof(wmfimage));
1402 data = GlobalLock (hglob);
1403 memcpy(data, wmfimage, sizeof(wmfimage));
1404 GlobalUnlock(hglob); data = NULL;
1406 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1407 ok(hres == S_OK, "Failed to create a stream\n");
1408 if(hres != S_OK) return;
1410 stat = GdipLoadImageFromStream(stream, &img);
1411 ok(stat == Ok, "Failed to create a Bitmap\n");
1412 if(stat != Ok){
1413 IStream_Release(stream);
1414 return;
1417 IStream_Release(stream);
1419 stat = GdipGetImageBounds(img, &bounds, &unit);
1420 expect(Ok, stat);
1421 todo_wine expect(UnitPixel, unit);
1422 expectf(0.0, bounds.X);
1423 expectf(0.0, bounds.Y);
1424 todo_wine expectf(320.0, bounds.Width);
1425 todo_wine expectf(320.0, bounds.Height);
1427 stat = GdipGetImageHorizontalResolution(img, &res);
1428 expect(Ok, stat);
1429 todo_wine expectf(1440.0, res);
1431 stat = GdipGetImageVerticalResolution(img, &res);
1432 expect(Ok, stat);
1433 todo_wine expectf(1440.0, res);
1435 memset(&header, 0, sizeof(header));
1436 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1437 expect(Ok, stat);
1438 if (stat == Ok)
1440 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1441 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1442 todo_wine expect(0x300, header.Version);
1443 expect(0, header.EmfPlusFlags);
1444 todo_wine expectf(1440.0, header.DpiX);
1445 todo_wine expectf(1440.0, header.DpiY);
1446 expect(0, header.X);
1447 expect(0, header.Y);
1448 todo_wine expect(320, header.Width);
1449 todo_wine expect(320, header.Height);
1450 todo_wine expect(1, U(header).WmfHeader.mtType);
1451 expect(0, header.EmfPlusHeaderSize);
1452 expect(0, header.LogicalDpiX);
1453 expect(0, header.LogicalDpiY);
1456 GdipDisposeImage(img);
1459 static void test_createfromwmf(void)
1461 HMETAFILE hwmf;
1462 GpImage *img;
1463 GpStatus stat;
1464 GpRectF bounds;
1465 GpUnit unit;
1466 REAL res = 12345.0;
1467 MetafileHeader header;
1469 hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
1470 wmfimage+sizeof(WmfPlaceableFileHeader));
1471 ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
1473 stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
1474 (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
1475 expect(Ok, stat);
1477 stat = GdipGetImageBounds(img, &bounds, &unit);
1478 expect(Ok, stat);
1479 expect(UnitPixel, unit);
1480 expectf(0.0, bounds.X);
1481 expectf(0.0, bounds.Y);
1482 expectf(320.0, bounds.Width);
1483 expectf(320.0, bounds.Height);
1485 stat = GdipGetImageHorizontalResolution(img, &res);
1486 expect(Ok, stat);
1487 expectf(1440.0, res);
1489 stat = GdipGetImageVerticalResolution(img, &res);
1490 expect(Ok, stat);
1491 expectf(1440.0, res);
1493 memset(&header, 0, sizeof(header));
1494 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1495 expect(Ok, stat);
1496 if (stat == Ok)
1498 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1499 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1500 todo_wine expect(0x300, header.Version);
1501 expect(0, header.EmfPlusFlags);
1502 todo_wine expectf(1440.0, header.DpiX);
1503 todo_wine expectf(1440.0, header.DpiY);
1504 expect(0, header.X);
1505 expect(0, header.Y);
1506 todo_wine expect(320, header.Width);
1507 todo_wine expect(320, header.Height);
1508 todo_wine expect(1, U(header).WmfHeader.mtType);
1509 expect(0, header.EmfPlusHeaderSize);
1510 expect(0, header.LogicalDpiX);
1511 expect(0, header.LogicalDpiY);
1514 GdipDisposeImage(img);
1517 static void test_resolution(void)
1519 GpStatus stat;
1520 GpBitmap *bitmap;
1521 GpGraphics *graphics;
1522 REAL res=-1.0;
1523 HDC screendc;
1524 int screenxres, screenyres;
1526 /* create Bitmap */
1527 stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
1528 expect(Ok, stat);
1530 /* test invalid values */
1531 stat = GdipGetImageHorizontalResolution(NULL, &res);
1532 expect(InvalidParameter, stat);
1534 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
1535 expect(InvalidParameter, stat);
1537 stat = GdipGetImageVerticalResolution(NULL, &res);
1538 expect(InvalidParameter, stat);
1540 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
1541 expect(InvalidParameter, stat);
1543 stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
1544 expect(InvalidParameter, stat);
1546 stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
1547 expect(InvalidParameter, stat);
1549 /* defaults to screen resolution */
1550 screendc = GetDC(0);
1552 screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
1553 screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
1555 ReleaseDC(0, screendc);
1557 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1558 expect(Ok, stat);
1559 expectf((REAL)screenxres, res);
1561 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1562 expect(Ok, stat);
1563 expectf((REAL)screenyres, res);
1565 stat = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
1566 expect(Ok, stat);
1567 stat = GdipGetDpiX(graphics, &res);
1568 expect(Ok, stat);
1569 expectf((REAL)screenxres, res);
1570 stat = GdipGetDpiY(graphics, &res);
1571 expect(Ok, stat);
1572 expectf((REAL)screenyres, res);
1574 /* test changing the resolution */
1575 stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
1576 expect(Ok, stat);
1578 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1579 expect(Ok, stat);
1580 expectf(screenxres*2.0, res);
1582 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1583 expect(Ok, stat);
1584 expectf(screenyres*3.0, res);
1586 stat = GdipGetDpiX(graphics, &res);
1587 expect(Ok, stat);
1588 expectf((REAL)screenxres, res);
1589 stat = GdipGetDpiY(graphics, &res);
1590 expect(Ok, stat);
1591 expectf((REAL)screenyres, res);
1593 stat = GdipDeleteGraphics(graphics);
1594 expect(Ok, stat);
1596 stat = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
1597 expect(Ok, stat);
1598 stat = GdipGetDpiX(graphics, &res);
1599 expect(Ok, stat);
1600 expectf(screenxres*2.0, res);
1601 stat = GdipGetDpiY(graphics, &res);
1602 expect(Ok, stat);
1603 expectf(screenyres*3.0, res);
1604 stat = GdipDeleteGraphics(graphics);
1605 expect(Ok, stat);
1607 stat = GdipDisposeImage((GpImage*)bitmap);
1608 expect(Ok, stat);
1611 static void test_createhbitmap(void)
1613 GpStatus stat;
1614 GpBitmap *bitmap;
1615 HBITMAP hbitmap, oldhbitmap;
1616 BITMAP bm;
1617 int ret;
1618 HDC hdc;
1619 COLORREF pixel;
1620 BYTE bits[640];
1622 memset(bits, 0x68, 640);
1624 /* create Bitmap */
1625 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
1626 expect(Ok, stat);
1628 /* test NULL values */
1629 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
1630 expect(InvalidParameter, stat);
1632 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
1633 expect(InvalidParameter, stat);
1635 /* create HBITMAP */
1636 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
1637 expect(Ok, stat);
1639 if (stat == Ok)
1641 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
1642 expect(sizeof(BITMAP), ret);
1644 expect(0, bm.bmType);
1645 expect(10, bm.bmWidth);
1646 expect(20, bm.bmHeight);
1647 expect(40, bm.bmWidthBytes);
1648 expect(1, bm.bmPlanes);
1649 expect(32, bm.bmBitsPixel);
1650 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1652 if (bm.bmBits)
1654 DWORD val = *(DWORD*)bm.bmBits;
1655 ok(val == 0xff686868, "got %x, expected 0xff686868\n", val);
1658 hdc = CreateCompatibleDC(NULL);
1660 oldhbitmap = SelectObject(hdc, hbitmap);
1661 pixel = GetPixel(hdc, 5, 5);
1662 SelectObject(hdc, oldhbitmap);
1664 DeleteDC(hdc);
1666 expect(0x686868, pixel);
1668 DeleteObject(hbitmap);
1671 stat = GdipDisposeImage((GpImage*)bitmap);
1672 expect(Ok, stat);
1674 /* create alpha Bitmap */
1675 stat = GdipCreateBitmapFromScan0(8, 20, 32, PixelFormat32bppARGB, bits, &bitmap);
1676 expect(Ok, stat);
1678 /* create HBITMAP */
1679 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
1680 expect(Ok, stat);
1682 if (stat == Ok)
1684 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
1685 expect(sizeof(BITMAP), ret);
1687 expect(0, bm.bmType);
1688 expect(8, bm.bmWidth);
1689 expect(20, bm.bmHeight);
1690 expect(32, bm.bmWidthBytes);
1691 expect(1, bm.bmPlanes);
1692 expect(32, bm.bmBitsPixel);
1693 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1695 if (bm.bmBits)
1697 DWORD val = *(DWORD*)bm.bmBits;
1698 ok(val == 0x682a2a2a, "got %x, expected 0x682a2a2a\n", val);
1701 hdc = CreateCompatibleDC(NULL);
1703 oldhbitmap = SelectObject(hdc, hbitmap);
1704 pixel = GetPixel(hdc, 5, 5);
1705 SelectObject(hdc, oldhbitmap);
1707 DeleteDC(hdc);
1709 expect(0x2a2a2a, pixel);
1711 DeleteObject(hbitmap);
1714 stat = GdipDisposeImage((GpImage*)bitmap);
1715 expect(Ok, stat);
1718 static void test_getthumbnail(void)
1720 GpStatus stat;
1721 GpImage *bitmap1, *bitmap2;
1722 UINT width, height;
1724 stat = GdipGetImageThumbnail(NULL, 0, 0, &bitmap2, NULL, NULL);
1725 expect(InvalidParameter, stat);
1727 stat = GdipCreateBitmapFromScan0(128, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1728 expect(Ok, stat);
1730 stat = GdipGetImageThumbnail(bitmap1, 0, 0, NULL, NULL, NULL);
1731 expect(InvalidParameter, stat);
1733 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1734 expect(Ok, stat);
1736 if (stat == Ok)
1738 stat = GdipGetImageWidth(bitmap2, &width);
1739 expect(Ok, stat);
1740 expect(120, width);
1742 stat = GdipGetImageHeight(bitmap2, &height);
1743 expect(Ok, stat);
1744 expect(120, height);
1746 GdipDisposeImage(bitmap2);
1749 GdipDisposeImage(bitmap1);
1752 stat = GdipCreateBitmapFromScan0(64, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1753 expect(Ok, stat);
1755 stat = GdipGetImageThumbnail(bitmap1, 32, 32, &bitmap2, NULL, NULL);
1756 expect(Ok, stat);
1758 if (stat == Ok)
1760 stat = GdipGetImageWidth(bitmap2, &width);
1761 expect(Ok, stat);
1762 expect(32, width);
1764 stat = GdipGetImageHeight(bitmap2, &height);
1765 expect(Ok, stat);
1766 expect(32, height);
1768 GdipDisposeImage(bitmap2);
1771 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1772 expect(Ok, stat);
1774 if (stat == Ok)
1776 stat = GdipGetImageWidth(bitmap2, &width);
1777 expect(Ok, stat);
1778 expect(120, width);
1780 stat = GdipGetImageHeight(bitmap2, &height);
1781 expect(Ok, stat);
1782 expect(120, height);
1784 GdipDisposeImage(bitmap2);
1787 GdipDisposeImage(bitmap1);
1790 static void test_getsetpixel(void)
1792 GpStatus stat;
1793 GpBitmap *bitmap;
1794 ARGB color;
1795 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1796 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1798 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1799 expect(Ok, stat);
1801 /* null parameters */
1802 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1803 expect(InvalidParameter, stat);
1805 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1806 expect(InvalidParameter, stat);
1808 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1809 expect(InvalidParameter, stat);
1811 /* out of bounds */
1812 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1813 expect(InvalidParameter, stat);
1815 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1816 expect(InvalidParameter, stat);
1818 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1819 ok(stat == InvalidParameter ||
1820 broken(stat == Ok), /* Older gdiplus */
1821 "Expected InvalidParameter, got %.8x\n", stat);
1823 if (0) /* crashes some gdiplus implementations */
1825 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1826 ok(stat == InvalidParameter ||
1827 broken(stat == Ok), /* Older gdiplus */
1828 "Expected InvalidParameter, got %.8x\n", stat);
1831 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1832 expect(InvalidParameter, stat);
1834 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1835 expect(InvalidParameter, stat);
1837 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1838 expect(InvalidParameter, stat);
1840 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1841 expect(InvalidParameter, stat);
1843 /* valid use */
1844 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1845 expect(Ok, stat);
1846 expect(0xffffffff, color);
1848 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1849 expect(Ok, stat);
1850 expect(0xff0000ff, color);
1852 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1853 expect(Ok, stat);
1855 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1856 expect(Ok, stat);
1858 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1859 expect(Ok, stat);
1860 expect(0xff676869, color);
1862 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1863 expect(Ok, stat);
1864 expect(0xff474849, color);
1866 stat = GdipDisposeImage((GpImage*)bitmap);
1867 expect(Ok, stat);
1870 static void check_halftone_palette(ColorPalette *palette)
1872 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1873 UINT i;
1875 for (i=0; i<palette->Count; i++)
1877 ARGB expected=0xff000000;
1878 if (i<8)
1880 if (i&1) expected |= 0x800000;
1881 if (i&2) expected |= 0x8000;
1882 if (i&4) expected |= 0x80;
1884 else if (i == 8)
1886 expected = 0xffc0c0c0;
1888 else if (i < 16)
1890 if (i&1) expected |= 0xff0000;
1891 if (i&2) expected |= 0xff00;
1892 if (i&4) expected |= 0xff;
1894 else if (i < 40)
1896 expected = 0x00000000;
1898 else
1900 expected |= halftone_values[(i-40)%6];
1901 expected |= halftone_values[((i-40)/6)%6] << 8;
1902 expected |= halftone_values[((i-40)/36)%6] << 16;
1904 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1905 expected, palette->Entries[i], i, palette->Count);
1909 static void test_palette(void)
1911 GpStatus stat;
1912 GpBitmap *bitmap;
1913 INT size;
1914 BYTE buffer[1040];
1915 ColorPalette *palette=(ColorPalette*)buffer;
1916 ARGB *entries = palette->Entries;
1917 ARGB color=0;
1919 /* test initial palette from non-indexed bitmap */
1920 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1921 expect(Ok, stat);
1923 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1924 expect(Ok, stat);
1925 expect(sizeof(UINT)*2+sizeof(ARGB), size);
1927 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1928 expect(Ok, stat);
1929 expect(0, palette->Count);
1931 /* test setting palette on not-indexed bitmap */
1932 palette->Count = 3;
1934 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1935 expect(Ok, stat);
1937 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1938 expect(Ok, stat);
1939 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1941 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1942 expect(Ok, stat);
1943 expect(3, palette->Count);
1945 GdipDisposeImage((GpImage*)bitmap);
1947 /* test initial palette on 1-bit bitmap */
1948 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1949 expect(Ok, stat);
1951 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1952 expect(Ok, stat);
1953 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1955 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1956 expect(Ok, stat);
1957 expect(PaletteFlagsGrayScale, palette->Flags);
1958 expect(2, palette->Count);
1960 expect(0xff000000, entries[0]);
1961 expect(0xffffffff, entries[1]);
1963 /* test getting/setting pixels */
1964 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1965 expect(Ok, stat);
1966 expect(0xff000000, color);
1968 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1969 ok((stat == Ok) ||
1970 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1972 if (stat == Ok)
1974 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1975 expect(Ok, stat);
1976 expect(0xffffffff, color);
1979 GdipDisposeImage((GpImage*)bitmap);
1981 /* test initial palette on 4-bit bitmap */
1982 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1983 expect(Ok, stat);
1985 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1986 expect(Ok, stat);
1987 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1989 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1990 expect(Ok, stat);
1991 expect(0, palette->Flags);
1992 expect(16, palette->Count);
1994 check_halftone_palette(palette);
1996 /* test getting/setting pixels */
1997 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1998 expect(Ok, stat);
1999 expect(0xff000000, color);
2001 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
2002 ok((stat == Ok) ||
2003 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
2005 if (stat == Ok)
2007 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
2008 expect(Ok, stat);
2009 expect(0xffff00ff, color);
2012 GdipDisposeImage((GpImage*)bitmap);
2014 /* test initial palette on 8-bit bitmap */
2015 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
2016 expect(Ok, stat);
2018 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
2019 expect(Ok, stat);
2020 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
2022 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
2023 expect(Ok, stat);
2024 expect(PaletteFlagsHalftone, palette->Flags);
2025 expect(256, palette->Count);
2027 check_halftone_palette(palette);
2029 /* test getting/setting pixels */
2030 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
2031 expect(Ok, stat);
2032 expect(0xff000000, color);
2034 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
2035 ok((stat == Ok) ||
2036 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
2038 if (stat == Ok)
2040 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
2041 expect(Ok, stat);
2042 expect(0xffcccccc, color);
2045 /* test setting/getting a different palette */
2046 entries[1] = 0xffcccccc;
2048 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
2049 expect(Ok, stat);
2051 entries[1] = 0;
2053 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
2054 expect(Ok, stat);
2055 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
2057 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
2058 expect(Ok, stat);
2059 expect(PaletteFlagsHalftone, palette->Flags);
2060 expect(256, palette->Count);
2061 expect(0xffcccccc, entries[1]);
2063 /* test count < 256 */
2064 palette->Flags = 12345;
2065 palette->Count = 3;
2067 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
2068 expect(Ok, stat);
2070 entries[1] = 0;
2071 entries[3] = 0xdeadbeef;
2073 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
2074 expect(Ok, stat);
2075 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
2077 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
2078 expect(Ok, stat);
2079 expect(12345, palette->Flags);
2080 expect(3, palette->Count);
2081 expect(0xffcccccc, entries[1]);
2082 expect(0xdeadbeef, entries[3]);
2084 /* test count > 256 */
2085 palette->Count = 257;
2087 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
2088 ok(stat == InvalidParameter ||
2089 broken(stat == Ok), /* Old gdiplus behavior */
2090 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
2092 GdipDisposeImage((GpImage*)bitmap);
2095 static void test_colormatrix(void)
2097 GpStatus stat;
2098 ColorMatrix colormatrix, graymatrix;
2099 GpImageAttributes *imageattr;
2100 const ColorMatrix identity = {{
2101 {1.0,0.0,0.0,0.0,0.0},
2102 {0.0,1.0,0.0,0.0,0.0},
2103 {0.0,0.0,1.0,0.0,0.0},
2104 {0.0,0.0,0.0,1.0,0.0},
2105 {0.0,0.0,0.0,0.0,1.0}}};
2106 const ColorMatrix double_red = {{
2107 {2.0,0.0,0.0,0.0,0.0},
2108 {0.0,1.0,0.0,0.0,0.0},
2109 {0.0,0.0,1.0,0.0,0.0},
2110 {0.0,0.0,0.0,1.0,0.0},
2111 {0.0,0.0,0.0,0.0,1.0}}};
2112 const ColorMatrix asymmetric = {{
2113 {0.0,1.0,0.0,0.0,0.0},
2114 {0.0,0.0,1.0,0.0,0.0},
2115 {0.0,0.0,0.0,1.0,0.0},
2116 {1.0,0.0,0.0,0.0,0.0},
2117 {0.0,0.0,0.0,0.0,1.0}}};
2118 GpBitmap *bitmap1, *bitmap2;
2119 GpGraphics *graphics;
2120 ARGB color;
2122 colormatrix = identity;
2123 graymatrix = identity;
2125 stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
2126 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
2127 expect(InvalidParameter, stat);
2129 stat = GdipCreateImageAttributes(&imageattr);
2130 expect(Ok, stat);
2132 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2133 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
2134 expect(Ok, stat);
2136 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2137 TRUE, NULL, NULL, ColorMatrixFlagsDefault);
2138 expect(InvalidParameter, stat);
2140 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2141 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
2142 expect(Ok, stat);
2144 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2145 TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
2146 expect(Ok, stat);
2148 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2149 TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
2150 expect(InvalidParameter, stat);
2152 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2153 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
2154 expect(Ok, stat);
2156 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2157 TRUE, &colormatrix, &graymatrix, 3);
2158 expect(InvalidParameter, stat);
2160 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
2161 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
2162 expect(InvalidParameter, stat);
2164 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
2165 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
2166 expect(InvalidParameter, stat);
2168 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2169 FALSE, NULL, NULL, ColorMatrixFlagsDefault);
2170 expect(Ok, stat);
2172 /* Drawing a bitmap transforms the colors */
2173 colormatrix = double_red;
2174 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2175 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
2176 expect(Ok, stat);
2178 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppARGB, NULL, &bitmap1);
2179 expect(Ok, stat);
2181 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppARGB, NULL, &bitmap2);
2182 expect(Ok, stat);
2184 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ccee);
2185 expect(Ok, stat);
2187 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2188 expect(Ok, stat);
2190 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2191 UnitPixel, imageattr, NULL, NULL);
2192 expect(Ok, stat);
2194 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2195 expect(Ok, stat);
2196 expect(0xff80ccee, color);
2198 colormatrix = asymmetric;
2199 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2200 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
2201 expect(Ok, stat);
2203 stat = GdipBitmapSetPixel(bitmap2, 0, 0, 0);
2204 expect(Ok, stat);
2206 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2207 UnitPixel, imageattr, NULL, NULL);
2208 expect(Ok, stat);
2210 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2211 expect(Ok, stat);
2212 ok(color_match(0xeeff40cc, color, 3), "expected 0xeeff40cc, got 0x%08x\n", color);
2214 stat = GdipResetImageAttributes(imageattr, ColorAdjustTypeDefault);
2215 expect(Ok, stat);
2217 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2218 UnitPixel, imageattr, NULL, NULL);
2219 expect(Ok, stat);
2221 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2222 expect(Ok, stat);
2223 ok(color_match(0xff40ccee, color, 1), "Expected ff40ccee, got %.8x\n", color);
2225 GdipDeleteGraphics(graphics);
2226 GdipDisposeImage((GpImage*)bitmap1);
2227 GdipDisposeImage((GpImage*)bitmap2);
2228 GdipDisposeImageAttributes(imageattr);
2231 static void test_gamma(void)
2233 GpStatus stat;
2234 GpImageAttributes *imageattr;
2235 GpBitmap *bitmap1, *bitmap2;
2236 GpGraphics *graphics;
2237 ARGB color;
2239 stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
2240 expect(InvalidParameter, stat);
2242 stat = GdipCreateImageAttributes(&imageattr);
2243 expect(Ok, stat);
2245 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
2246 expect(Ok, stat);
2248 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
2249 expect(InvalidParameter, stat);
2251 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
2252 expect(InvalidParameter, stat);
2254 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
2255 expect(InvalidParameter, stat);
2257 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
2258 expect(Ok, stat);
2260 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
2261 expect(Ok, stat);
2263 /* Drawing a bitmap transforms the colors */
2264 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
2265 expect(Ok, stat);
2267 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
2268 expect(Ok, stat);
2270 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
2271 expect(Ok, stat);
2273 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
2274 expect(Ok, stat);
2276 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2277 expect(Ok, stat);
2279 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2280 UnitPixel, imageattr, NULL, NULL);
2281 expect(Ok, stat);
2283 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2284 expect(Ok, stat);
2285 ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
2287 stat = GdipResetImageAttributes(imageattr, ColorAdjustTypeDefault);
2288 expect(Ok, stat);
2290 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2291 UnitPixel, imageattr, NULL, NULL);
2292 expect(Ok, stat);
2294 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2295 expect(Ok, stat);
2296 ok(color_match(0xff80ffff, color, 1), "Expected ff80ffff, got %.8x\n", color);
2298 GdipDeleteGraphics(graphics);
2299 GdipDisposeImage((GpImage*)bitmap1);
2300 GdipDisposeImage((GpImage*)bitmap2);
2301 GdipDisposeImageAttributes(imageattr);
2304 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
2305 static const unsigned char gifanimation[72] = {
2306 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
2307 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
2308 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
2309 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
2310 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
2313 static void test_multiframegif(void)
2315 LPSTREAM stream;
2316 HGLOBAL hglob;
2317 LPBYTE data;
2318 HRESULT hres;
2319 GpStatus stat;
2320 GpBitmap *bmp;
2321 ARGB color;
2322 UINT count;
2323 GUID dimension;
2325 /* Test frame functions with an animated GIF */
2326 hglob = GlobalAlloc (0, sizeof(gifanimation));
2327 data = GlobalLock (hglob);
2328 memcpy(data, gifanimation, sizeof(gifanimation));
2329 GlobalUnlock(hglob);
2331 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
2332 ok(hres == S_OK, "Failed to create a stream\n");
2333 if(hres != S_OK) return;
2335 stat = GdipCreateBitmapFromStream(stream, &bmp);
2336 ok(stat == Ok, "Failed to create a Bitmap\n");
2337 if(stat != Ok){
2338 IStream_Release(stream);
2339 return;
2342 /* Bitmap starts at frame 0 */
2343 color = 0xdeadbeef;
2344 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2345 expect(Ok, stat);
2346 expect(0xffffffff, color);
2348 /* Check that we get correct metadata */
2349 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
2350 expect(Ok, stat);
2351 expect(1, count);
2353 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
2354 expect(Ok, stat);
2355 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
2357 count = 12345;
2358 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2359 expect(Ok, stat);
2360 expect(2, count);
2362 /* SelectActiveFrame overwrites our current data */
2363 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
2364 expect(Ok, stat);
2366 color = 0xdeadbeef;
2367 GdipBitmapGetPixel(bmp, 0, 0, &color);
2368 expect(Ok, stat);
2369 expect(0xff000000, color);
2371 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2372 expect(Ok, stat);
2374 color = 0xdeadbeef;
2375 GdipBitmapGetPixel(bmp, 0, 0, &color);
2376 expect(Ok, stat);
2377 expect(0xffffffff, color);
2379 /* Write over the image data */
2380 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
2381 expect(Ok, stat);
2383 /* Switching to the same frame does not overwrite our changes */
2384 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2385 expect(Ok, stat);
2387 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2388 expect(Ok, stat);
2389 expect(0xff000000, color);
2391 /* But switching to another frame and back does */
2392 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
2393 expect(Ok, stat);
2395 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2396 expect(Ok, stat);
2398 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2399 expect(Ok, stat);
2400 expect(0xffffffff, color);
2402 /* rotate/flip discards the information about other frames */
2403 stat = GdipImageRotateFlip((GpImage*)bmp, Rotate90FlipNone);
2404 expect(Ok, stat);
2406 count = 12345;
2407 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2408 expect(Ok, stat);
2409 expect(1, count);
2411 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bmp, __LINE__, FALSE);
2413 GdipDisposeImage((GpImage*)bmp);
2414 IStream_Release(stream);
2416 /* Test with a non-animated gif */
2417 hglob = GlobalAlloc (0, sizeof(gifimage));
2418 data = GlobalLock (hglob);
2419 memcpy(data, gifimage, sizeof(gifimage));
2420 GlobalUnlock(hglob);
2422 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
2423 ok(hres == S_OK, "Failed to create a stream\n");
2424 if(hres != S_OK) return;
2426 stat = GdipCreateBitmapFromStream(stream, &bmp);
2427 ok(stat == Ok, "Failed to create a Bitmap\n");
2428 if(stat != Ok){
2429 IStream_Release(stream);
2430 return;
2433 /* Check metadata */
2434 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
2435 expect(Ok, stat);
2436 expect(1, count);
2438 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
2439 expect(Ok, stat);
2440 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
2442 count = 12345;
2443 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2444 expect(Ok, stat);
2445 expect(1, count);
2447 GdipDisposeImage((GpImage*)bmp);
2448 IStream_Release(stream);
2451 static void test_rotateflip(void)
2453 GpImage *bitmap;
2454 GpStatus stat;
2455 BYTE bits[24];
2456 static const BYTE orig_bits[24] = {
2457 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
2458 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
2459 UINT width, height;
2460 ARGB color;
2462 memcpy(bits, orig_bits, sizeof(bits));
2463 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2464 expect(Ok, stat);
2466 stat = GdipImageRotateFlip(bitmap, Rotate90FlipNone);
2467 expect(Ok, stat);
2469 stat = GdipGetImageWidth(bitmap, &width);
2470 expect(Ok, stat);
2471 stat = GdipGetImageHeight(bitmap, &height);
2472 expect(Ok, stat);
2473 expect(2, width);
2474 expect(3, height);
2476 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2477 expect(Ok, stat);
2478 expect(0xff00ffff, color);
2480 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 0, &color);
2481 expect(Ok, stat);
2482 expect(0xffff0000, color);
2484 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 2, &color);
2485 expect(Ok, stat);
2486 expect(0xffffff00, color);
2488 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 2, &color);
2489 expect(Ok, stat);
2490 expect(0xff0000ff, color);
2492 expect(0, bits[0]);
2493 expect(0, bits[1]);
2494 expect(0xff, bits[2]);
2496 GdipDisposeImage(bitmap);
2498 memcpy(bits, orig_bits, sizeof(bits));
2499 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2500 expect(Ok, stat);
2502 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipX);
2503 expect(Ok, stat);
2505 stat = GdipGetImageWidth(bitmap, &width);
2506 expect(Ok, stat);
2507 stat = GdipGetImageHeight(bitmap, &height);
2508 expect(Ok, stat);
2509 expect(3, width);
2510 expect(2, height);
2512 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2513 expect(Ok, stat);
2514 expect(0xff0000ff, color);
2516 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2517 expect(Ok, stat);
2518 expect(0xffff0000, color);
2520 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2521 expect(Ok, stat);
2522 expect(0xffffff00, color);
2524 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2525 expect(Ok, stat);
2526 expect(0xff00ffff, color);
2528 expect(0, bits[0]);
2529 expect(0, bits[1]);
2530 expect(0xff, bits[2]);
2532 GdipDisposeImage(bitmap);
2534 memcpy(bits, orig_bits, sizeof(bits));
2535 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2536 expect(Ok, stat);
2538 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipY);
2539 expect(Ok, stat);
2541 stat = GdipGetImageWidth(bitmap, &width);
2542 expect(Ok, stat);
2543 stat = GdipGetImageHeight(bitmap, &height);
2544 expect(Ok, stat);
2545 expect(3, width);
2546 expect(2, height);
2548 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2549 expect(Ok, stat);
2550 expect(0xff00ffff, color);
2552 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2553 expect(Ok, stat);
2554 expect(0xffffff00, color);
2556 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2557 expect(Ok, stat);
2558 expect(0xffff0000, color);
2560 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2561 expect(Ok, stat);
2562 expect(0xff0000ff, color);
2564 expect(0, bits[0]);
2565 expect(0, bits[1]);
2566 expect(0xff, bits[2]);
2568 GdipDisposeImage(bitmap);
2571 static void test_remaptable(void)
2573 GpStatus stat;
2574 GpImageAttributes *imageattr;
2575 GpBitmap *bitmap1, *bitmap2;
2576 GpGraphics *graphics;
2577 ARGB color;
2578 ColorMap *map;
2580 map = GdipAlloc(sizeof(ColorMap));
2582 map->oldColor.Argb = 0xff00ff00;
2583 map->newColor.Argb = 0xffff00ff;
2585 stat = GdipSetImageAttributesRemapTable(NULL, ColorAdjustTypeDefault, TRUE, 1, map);
2586 expect(InvalidParameter, stat);
2588 stat = GdipCreateImageAttributes(&imageattr);
2589 expect(Ok, stat);
2591 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, NULL);
2592 expect(InvalidParameter, stat);
2594 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeCount, TRUE, 1, map);
2595 expect(InvalidParameter, stat);
2597 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeAny, TRUE, 1, map);
2598 expect(InvalidParameter, stat);
2600 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 0, map);
2601 expect(InvalidParameter, stat);
2603 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, FALSE, 0, NULL);
2604 expect(Ok, stat);
2606 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, map);
2607 expect(Ok, stat);
2609 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
2610 expect(Ok, stat);
2612 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
2613 expect(Ok, stat);
2615 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff00ff00);
2616 expect(Ok, stat);
2618 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2619 expect(Ok, stat);
2621 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2622 UnitPixel, imageattr, NULL, NULL);
2623 expect(Ok, stat);
2625 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2626 expect(Ok, stat);
2627 ok(color_match(0xffff00ff, color, 1), "Expected ffff00ff, got %.8x\n", color);
2629 stat = GdipResetImageAttributes(imageattr, ColorAdjustTypeDefault);
2630 expect(Ok, stat);
2632 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2633 UnitPixel, imageattr, NULL, NULL);
2634 expect(Ok, stat);
2636 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2637 expect(Ok, stat);
2638 ok(color_match(0xff00ff00, color, 1), "Expected ff00ff00, got %.8x\n", color);
2640 GdipDeleteGraphics(graphics);
2641 GdipDisposeImage((GpImage*)bitmap1);
2642 GdipDisposeImage((GpImage*)bitmap2);
2643 GdipDisposeImageAttributes(imageattr);
2644 GdipFree(map);
2647 static void test_colorkey(void)
2649 GpStatus stat;
2650 GpImageAttributes *imageattr;
2651 GpBitmap *bitmap1, *bitmap2;
2652 GpGraphics *graphics;
2653 ARGB color;
2655 stat = GdipSetImageAttributesColorKeys(NULL, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2656 expect(InvalidParameter, stat);
2658 stat = GdipCreateImageAttributes(&imageattr);
2659 expect(Ok, stat);
2661 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeCount, TRUE, 0xff405060, 0xff708090);
2662 expect(InvalidParameter, stat);
2664 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeAny, TRUE, 0xff405060, 0xff708090);
2665 expect(InvalidParameter, stat);
2667 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2668 expect(Ok, stat);
2670 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap1);
2671 expect(Ok, stat);
2673 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap2);
2674 expect(Ok, stat);
2676 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0x20405060);
2677 expect(Ok, stat);
2679 stat = GdipBitmapSetPixel(bitmap1, 0, 1, 0x40506070);
2680 expect(Ok, stat);
2682 stat = GdipBitmapSetPixel(bitmap1, 1, 0, 0x60708090);
2683 expect(Ok, stat);
2685 stat = GdipBitmapSetPixel(bitmap1, 1, 1, 0xffffffff);
2686 expect(Ok, stat);
2688 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2689 expect(Ok, stat);
2691 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,2,2, 0,0,2,2,
2692 UnitPixel, imageattr, NULL, NULL);
2693 expect(Ok, stat);
2695 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2696 expect(Ok, stat);
2697 ok(color_match(0x00000000, color, 1), "Expected 00000000, got %.8x\n", color);
2699 stat = GdipBitmapGetPixel(bitmap2, 0, 1, &color);
2700 expect(Ok, stat);
2701 ok(color_match(0x00000000, color, 1), "Expected 00000000, got %.8x\n", color);
2703 stat = GdipBitmapGetPixel(bitmap2, 1, 0, &color);
2704 expect(Ok, stat);
2705 ok(color_match(0x00000000, color, 1), "Expected 00000000, got %.8x\n", color);
2707 stat = GdipBitmapGetPixel(bitmap2, 1, 1, &color);
2708 expect(Ok, stat);
2709 ok(color_match(0xffffffff, color, 1), "Expected ffffffff, got %.8x\n", color);
2711 stat = GdipResetImageAttributes(imageattr, ColorAdjustTypeDefault);
2712 expect(Ok, stat);
2714 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,2,2, 0,0,2,2,
2715 UnitPixel, imageattr, NULL, NULL);
2716 expect(Ok, stat);
2718 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2719 expect(Ok, stat);
2720 ok(color_match(0x20405060, color, 1), "Expected 20405060, got %.8x\n", color);
2722 stat = GdipBitmapGetPixel(bitmap2, 0, 1, &color);
2723 expect(Ok, stat);
2724 ok(color_match(0x40506070, color, 1), "Expected 40506070, got %.8x\n", color);
2726 stat = GdipBitmapGetPixel(bitmap2, 1, 0, &color);
2727 expect(Ok, stat);
2728 ok(color_match(0x60708090, color, 1), "Expected 60708090, got %.8x\n", color);
2730 stat = GdipBitmapGetPixel(bitmap2, 1, 1, &color);
2731 expect(Ok, stat);
2732 ok(color_match(0xffffffff, color, 1), "Expected ffffffff, got %.8x\n", color);
2735 GdipDeleteGraphics(graphics);
2736 GdipDisposeImage((GpImage*)bitmap1);
2737 GdipDisposeImage((GpImage*)bitmap2);
2738 GdipDisposeImageAttributes(imageattr);
2741 static void test_dispose(void)
2743 GpStatus stat;
2744 GpImage *image;
2745 char invalid_image[256];
2747 stat = GdipDisposeImage(NULL);
2748 expect(InvalidParameter, stat);
2750 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, (GpBitmap**)&image);
2751 expect(Ok, stat);
2753 stat = GdipDisposeImage(image);
2754 expect(Ok, stat);
2756 stat = GdipDisposeImage(image);
2757 expect(ObjectBusy, stat);
2759 memset(invalid_image, 0, 256);
2760 stat = GdipDisposeImage((GpImage*)invalid_image);
2761 expect(ObjectBusy, stat);
2764 static LONG obj_refcount(void *obj)
2766 IUnknown_AddRef((IUnknown *)obj);
2767 return IUnknown_Release((IUnknown *)obj);
2770 static GpImage *load_image(const BYTE *image_data, UINT image_size)
2772 IStream *stream;
2773 HGLOBAL hmem;
2774 BYTE *data;
2775 HRESULT hr;
2776 GpStatus status;
2777 GpImage *image = NULL, *clone;
2778 ImageType image_type;
2779 LONG refcount, old_refcount;
2781 hmem = GlobalAlloc(0, image_size);
2782 data = GlobalLock(hmem);
2783 memcpy(data, image_data, image_size);
2784 GlobalUnlock(hmem);
2786 hr = CreateStreamOnHGlobal(hmem, TRUE, &stream);
2787 ok(hr == S_OK, "CreateStreamOnHGlobal error %#x\n", hr);
2788 if (hr != S_OK) return NULL;
2790 refcount = obj_refcount(stream);
2791 ok(refcount == 1, "expected stream refcount 1, got %d\n", refcount);
2793 status = GdipLoadImageFromStream(stream, &image);
2794 ok(status == Ok || broken(status == InvalidParameter), /* XP */
2795 "GdipLoadImageFromStream error %d\n", status);
2796 if (status != Ok)
2798 IStream_Release(stream);
2799 return NULL;
2802 status = GdipGetImageType(image, &image_type);
2803 ok(status == Ok, "GdipGetImageType error %d\n", status);
2805 refcount = obj_refcount(stream);
2806 if (image_type == ImageTypeBitmap)
2807 ok(refcount > 1, "expected stream refcount > 1, got %d\n", refcount);
2808 else
2809 ok(refcount == 1, "expected stream refcount 1, got %d\n", refcount);
2810 old_refcount = refcount;
2812 status = GdipCloneImage(image, &clone);
2813 ok(status == Ok, "GdipCloneImage error %d\n", status);
2814 refcount = obj_refcount(stream);
2815 ok(refcount == old_refcount, "expected stream refcount %d, got %d\n", old_refcount, refcount);
2816 status = GdipDisposeImage(clone);
2817 ok(status == Ok, "GdipDisposeImage error %d\n", status);
2818 refcount = obj_refcount(stream);
2819 ok(refcount == old_refcount, "expected stream refcount %d, got %d\n", old_refcount, refcount);
2821 refcount = IStream_Release(stream);
2822 if (image_type == ImageTypeBitmap)
2823 ok(refcount >= 1, "expected stream refcount != 0\n");
2824 else
2825 ok(refcount == 0, "expected stream refcount 0, got %d\n", refcount);
2827 return image;
2830 static void test_image_properties(void)
2832 static const struct test_data
2834 const BYTE *image_data;
2835 UINT image_size;
2836 ImageType image_type;
2837 UINT prop_count;
2838 UINT prop_count2; /* if win7 behaves differently */
2839 /* 1st property attributes */
2840 UINT prop_size;
2841 UINT prop_size2; /* if win7 behaves differently */
2842 UINT prop_id;
2843 UINT prop_id2; /* if win7 behaves differently */
2845 td[] =
2847 { pngimage, sizeof(pngimage), ImageTypeBitmap, 4, ~0, 1, 20, 0x5110, 0x132 },
2848 { jpgimage, sizeof(jpgimage), ImageTypeBitmap, 2, ~0, 128, 0, 0x5090, 0x5091 },
2849 { tiffimage, sizeof(tiffimage), ImageTypeBitmap, 16, 0, 4, 0, 0xfe, 0 },
2850 { bmpimage, sizeof(bmpimage), ImageTypeBitmap, 0, 0, 0, 0, 0, 0 },
2851 { wmfimage, sizeof(wmfimage), ImageTypeMetafile, 0, 0, 0, 0, 0, 0 }
2853 GpStatus status;
2854 GpImage *image;
2855 UINT prop_count, prop_size, i;
2856 PROPID prop_id[16] = { 0 };
2857 ImageType image_type;
2858 union
2860 PropertyItem data;
2861 char buf[256];
2862 } item;
2864 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
2866 image = load_image(td[i].image_data, td[i].image_size);
2867 if (!image)
2869 trace("%u: failed to load image data\n", i);
2870 continue;
2873 status = GdipGetImageType(image, &image_type);
2874 ok(status == Ok, "%u: GdipGetImageType error %d\n", i, status);
2875 ok(td[i].image_type == image_type, "%u: expected image_type %d, got %d\n",
2876 i, td[i].image_type, image_type);
2878 status = GdipGetPropertyCount(image, &prop_count);
2879 ok(status == Ok, "%u: GdipGetPropertyCount error %d\n", i, status);
2880 if (td[i].image_data == pngimage || td[i].image_data == jpgimage)
2881 todo_wine
2882 ok(td[i].prop_count == prop_count || td[i].prop_count2 == prop_count,
2883 " %u: expected property count %u or %u, got %u\n",
2884 i, td[i].prop_count, td[i].prop_count2, prop_count);
2885 else
2886 ok(td[i].prop_count == prop_count || td[i].prop_count2 == prop_count,
2887 " %u: expected property count %u or %u, got %u\n",
2888 i, td[i].prop_count, td[i].prop_count2, prop_count);
2890 status = GdipGetPropertyItemSize(NULL, 0, &prop_size);
2891 expect(InvalidParameter, status);
2892 status = GdipGetPropertyItemSize(image, 0, NULL);
2893 expect(InvalidParameter, status);
2894 status = GdipGetPropertyItemSize(image, 0, &prop_size);
2895 if (image_type == ImageTypeMetafile)
2896 expect(NotImplemented, status);
2897 else
2898 expect(PropertyNotFound, status);
2900 status = GdipGetPropertyItem(NULL, 0, 0, &item.data);
2901 expect(InvalidParameter, status);
2902 status = GdipGetPropertyItem(image, 0, 0, NULL);
2903 expect(InvalidParameter, status);
2904 status = GdipGetPropertyItem(image, 0, 0, &item.data);
2905 if (image_type == ImageTypeMetafile)
2906 expect(NotImplemented, status);
2907 else
2908 expect(PropertyNotFound, status);
2910 /* FIXME: remove once Wine is fixed */
2911 if (td[i].prop_count != prop_count)
2913 GdipDisposeImage(image);
2914 continue;
2917 status = GdipGetPropertyIdList(NULL, prop_count, prop_id);
2918 expect(InvalidParameter, status);
2919 status = GdipGetPropertyIdList(image, prop_count, NULL);
2920 expect(InvalidParameter, status);
2921 status = GdipGetPropertyIdList(image, 0, prop_id);
2922 if (image_type == ImageTypeMetafile)
2923 expect(NotImplemented, status);
2924 else if (prop_count == 0)
2925 expect(Ok, status);
2926 else
2927 expect(InvalidParameter, status);
2928 status = GdipGetPropertyIdList(image, prop_count - 1, prop_id);
2929 if (image_type == ImageTypeMetafile)
2930 expect(NotImplemented, status);
2931 else
2932 expect(InvalidParameter, status);
2933 status = GdipGetPropertyIdList(image, prop_count + 1, prop_id);
2934 if (image_type == ImageTypeMetafile)
2935 expect(NotImplemented, status);
2936 else
2937 expect(InvalidParameter, status);
2938 status = GdipGetPropertyIdList(image, prop_count, prop_id);
2939 if (image_type == ImageTypeMetafile)
2940 expect(NotImplemented, status);
2941 else
2943 expect(Ok, status);
2944 if (prop_count != 0)
2945 ok(td[i].prop_id == prop_id[0] || td[i].prop_id2 == prop_id[0],
2946 " %u: expected property id %#x or %#x, got %#x\n",
2947 i, td[i].prop_id, td[i].prop_id2, prop_id[0]);
2950 if (status == Ok)
2952 status = GdipGetPropertyItemSize(image, prop_id[0], &prop_size);
2953 if (prop_count == 0)
2954 expect(PropertyNotFound, status);
2955 else
2957 expect(Ok, status);
2959 assert(sizeof(item) >= prop_size);
2960 ok(prop_size > sizeof(PropertyItem), "%u: got too small prop_size %u\n",
2961 i, prop_size);
2962 ok(td[i].prop_size + sizeof(PropertyItem) == prop_size ||
2963 td[i].prop_size2 + sizeof(PropertyItem) == prop_size,
2964 " %u: expected property size %u or %u, got %u\n",
2965 i, td[i].prop_size, td[i].prop_size2, prop_size);
2967 status = GdipGetPropertyItem(image, prop_id[0], 0, &item.data);
2968 ok(status == InvalidParameter || status == GenericError /* Win7 */,
2969 "%u: expected InvalidParameter, got %d\n", i, status);
2970 status = GdipGetPropertyItem(image, prop_id[0], prop_size - 1, &item.data);
2971 ok(status == InvalidParameter || status == GenericError /* Win7 */,
2972 "%u: expected InvalidParameter, got %d\n", i, status);
2973 status = GdipGetPropertyItem(image, prop_id[0], prop_size + 1, &item.data);
2974 ok(status == InvalidParameter || status == GenericError /* Win7 */,
2975 "%u: expected InvalidParameter, got %d\n", i, status);
2976 status = GdipGetPropertyItem(image, prop_id[0], prop_size, &item.data);
2977 expect(Ok, status);
2978 ok(prop_id[0] == item.data.id,
2979 "%u: expected property id %#x, got %#x\n", i, prop_id[0], item.data.id);
2983 GdipDisposeImage(image);
2987 #define IFD_BYTE 1
2988 #define IFD_ASCII 2
2989 #define IFD_SHORT 3
2990 #define IFD_LONG 4
2991 #define IFD_RATIONAL 5
2992 #define IFD_SBYTE 6
2993 #define IFD_UNDEFINED 7
2994 #define IFD_SSHORT 8
2995 #define IFD_SLONG 9
2996 #define IFD_SRATIONAL 10
2997 #define IFD_FLOAT 11
2998 #define IFD_DOUBLE 12
3000 #ifndef PropertyTagTypeSByte
3001 #define PropertyTagTypeSByte 6
3002 #define PropertyTagTypeSShort 8
3003 #define PropertyTagTypeFloat 11
3004 #define PropertyTagTypeDouble 12
3005 #endif
3007 static UINT documented_type(UINT type)
3009 switch (type)
3011 case PropertyTagTypeSByte: return PropertyTagTypeByte;
3012 case PropertyTagTypeSShort: return PropertyTagTypeShort;
3013 case PropertyTagTypeFloat: return PropertyTagTypeUndefined;
3014 case PropertyTagTypeDouble: return PropertyTagTypeUndefined;
3015 default: return type;
3019 #include "pshpack2.h"
3020 struct IFD_entry
3022 SHORT id;
3023 SHORT type;
3024 ULONG count;
3025 LONG value;
3028 struct IFD_rational
3030 LONG numerator;
3031 LONG denominator;
3034 static const struct tiff_data
3036 USHORT byte_order;
3037 USHORT version;
3038 ULONG dir_offset;
3039 USHORT number_of_entries;
3040 struct IFD_entry entry[40];
3041 ULONG next_IFD;
3042 struct IFD_rational xres;
3043 DOUBLE double_val;
3044 struct IFD_rational srational_val;
3045 char string[14];
3046 SHORT short_val[4];
3047 LONG long_val[2];
3048 FLOAT float_val[2];
3049 struct IFD_rational rational[3];
3050 BYTE pixel_data[4];
3051 } TIFF_data =
3053 #ifdef WORDS_BIGENDIAN
3054 'M' | 'M' << 8,
3055 #else
3056 'I' | 'I' << 8,
3057 #endif
3059 FIELD_OFFSET(struct tiff_data, number_of_entries),
3062 { 0xff, IFD_SHORT, 1, 0 }, /* SUBFILETYPE */
3063 { 0x100, IFD_LONG, 1, 1 }, /* IMAGEWIDTH */
3064 { 0x101, IFD_LONG, 1, 1 }, /* IMAGELENGTH */
3065 { 0x102, IFD_SHORT, 1, 1 }, /* BITSPERSAMPLE */
3066 { 0x103, IFD_SHORT, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
3067 { 0x106, IFD_SHORT, 1, 1 }, /* PHOTOMETRIC */
3068 { 0x111, IFD_LONG, 1, FIELD_OFFSET(struct tiff_data, pixel_data) }, /* STRIPOFFSETS */
3069 { 0x115, IFD_SHORT, 1, 1 }, /* SAMPLESPERPIXEL */
3070 { 0x116, IFD_LONG, 1, 1 }, /* ROWSPERSTRIP */
3071 { 0x117, IFD_LONG, 1, 1 }, /* STRIPBYTECOUNT */
3072 { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_data, xres) },
3073 { 0x11b, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_data, xres) },
3074 { 0x128, IFD_SHORT, 1, 2 }, /* RESOLUTIONUNIT */
3075 { 0xf001, IFD_BYTE, 1, 0x11223344 },
3076 { 0xf002, IFD_BYTE, 4, 0x11223344 },
3077 { 0xf003, IFD_SBYTE, 1, 0x11223344 },
3078 { 0xf004, IFD_SSHORT, 1, 0x11223344 },
3079 { 0xf005, IFD_SSHORT, 2, 0x11223344 },
3080 { 0xf006, IFD_SLONG, 1, 0x11223344 },
3081 { 0xf007, IFD_FLOAT, 1, 0x11223344 },
3082 { 0xf008, IFD_DOUBLE, 1, FIELD_OFFSET(struct tiff_data, double_val) },
3083 { 0xf009, IFD_SRATIONAL, 1, FIELD_OFFSET(struct tiff_data, srational_val) },
3084 { 0xf00a, IFD_BYTE, 13, FIELD_OFFSET(struct tiff_data, string) },
3085 { 0xf00b, IFD_SSHORT, 4, FIELD_OFFSET(struct tiff_data, short_val) },
3086 { 0xf00c, IFD_SLONG, 2, FIELD_OFFSET(struct tiff_data, long_val) },
3087 { 0xf00e, IFD_ASCII, 13, FIELD_OFFSET(struct tiff_data, string) },
3088 { 0xf00f, IFD_ASCII, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
3089 { 0xf010, IFD_UNDEFINED, 13, FIELD_OFFSET(struct tiff_data, string) },
3090 { 0xf011, IFD_UNDEFINED, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
3091 /* Some gdiplus versions ignore these fields.
3092 { 0xf012, IFD_BYTE, 0, 0x11223344 },
3093 { 0xf013, IFD_SHORT, 0, 0x11223344 },
3094 { 0xf014, IFD_LONG, 0, 0x11223344 },
3095 { 0xf015, IFD_FLOAT, 0, 0x11223344 },*/
3096 { 0xf016, IFD_SRATIONAL, 3, FIELD_OFFSET(struct tiff_data, rational) },
3097 /* Win7 before SP1 doesn't recognize this field, everybody else does. */
3098 { 0xf017, IFD_FLOAT, 2, FIELD_OFFSET(struct tiff_data, float_val) },
3101 { 900, 3 },
3102 1234567890.0987654321,
3103 { 0x1a2b3c4d, 0x5a6b7c8d },
3104 "Hello World!",
3105 { 0x0101, 0x0202, 0x0303, 0x0404 },
3106 { 0x11223344, 0x55667788 },
3107 { (FLOAT)1234.5678, (FLOAT)8765.4321 },
3108 { { 0x01020304, 0x05060708 }, { 0x10203040, 0x50607080 }, { 0x11223344, 0x55667788 } },
3109 { 0x11, 0x22, 0x33, 0 }
3111 #include "poppack.h"
3113 static void test_tiff_properties(void)
3115 static const struct test_data
3117 ULONG type, id, length;
3118 const BYTE value[24];
3119 } td[31] =
3121 { PropertyTagTypeShort, 0xff, 2, { 0 } },
3122 { PropertyTagTypeLong, 0x100, 4, { 1 } },
3123 { PropertyTagTypeLong, 0x101, 4, { 1 } },
3124 { PropertyTagTypeShort, 0x102, 2, { 1 } },
3125 { PropertyTagTypeShort, 0x103, 2, { 1 } },
3126 { PropertyTagTypeShort, 0x106, 2, { 1 } },
3127 { PropertyTagTypeLong, 0x111, 4, { 0x44,0x02 } },
3128 { PropertyTagTypeShort, 0x115, 2, { 1 } },
3129 { PropertyTagTypeLong, 0x116, 4, { 1 } },
3130 { PropertyTagTypeLong, 0x117, 4, { 1 } },
3131 { PropertyTagTypeRational, 0x11a, 8, { 0x84,0x03,0,0,0x03 } },
3132 { PropertyTagTypeRational, 0x11b, 8, { 0x84,0x03,0,0,0x03 } },
3133 { PropertyTagTypeShort, 0x128, 2, { 2 } },
3134 { PropertyTagTypeByte, 0xf001, 1, { 0x44 } },
3135 { PropertyTagTypeByte, 0xf002, 4, { 0x44,0x33,0x22,0x11 } },
3136 { PropertyTagTypeSByte, 0xf003, 1, { 0x44 } },
3137 { PropertyTagTypeSShort, 0xf004, 2, { 0x44,0x33 } },
3138 { PropertyTagTypeSShort, 0xf005, 4, { 0x44,0x33,0x22,0x11 } },
3139 { PropertyTagTypeSLONG, 0xf006, 4, { 0x44,0x33,0x22,0x11 } },
3140 { PropertyTagTypeFloat, 0xf007, 4, { 0x44,0x33,0x22,0x11 } },
3141 { PropertyTagTypeDouble, 0xf008, 8, { 0x2c,0x52,0x86,0xb4,0x80,0x65,0xd2,0x41 } },
3142 { PropertyTagTypeSRational, 0xf009, 8, { 0x4d, 0x3c, 0x2b, 0x1a, 0x8d, 0x7c, 0x6b, 0x5a } },
3143 { PropertyTagTypeByte, 0xf00a, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3144 { PropertyTagTypeSShort, 0xf00b, 8, { 0x01,0x01,0x02,0x02,0x03,0x03,0x04,0x04 } },
3145 { PropertyTagTypeSLONG, 0xf00c, 8, { 0x44,0x33,0x22,0x11,0x88,0x77,0x66,0x55 } },
3146 { PropertyTagTypeASCII, 0xf00e, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3147 { PropertyTagTypeASCII, 0xf00f, 5, { 'a','b','c','d' } },
3148 { PropertyTagTypeUndefined, 0xf010, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3149 { PropertyTagTypeUndefined, 0xf011, 4, { 'a','b','c','d' } },
3150 { PropertyTagTypeSRational, 0xf016, 24,
3151 { 0x04,0x03,0x02,0x01,0x08,0x07,0x06,0x05,
3152 0x40,0x30,0x20,0x10,0x80,0x70,0x60,0x50,
3153 0x44,0x33,0x22,0x11,0x88,0x77,0x66,0x55 } },
3154 /* Win7 before SP1 doesn't recognize this field, everybody else does. */
3155 { PropertyTagTypeFloat, 0xf017, 8, { 0x2b,0x52,0x9a,0x44,0xba,0xf5,0x08,0x46 } },
3157 GpStatus status;
3158 GpImage *image;
3159 GUID guid;
3160 UINT dim_count, frame_count, prop_count, prop_size, i;
3161 PROPID *prop_id;
3162 PropertyItem *prop_item;
3164 image = load_image((const BYTE *)&TIFF_data, sizeof(TIFF_data));
3165 if (!image)
3167 win_skip("Failed to load TIFF image data. Might not be supported. Skipping.\n");
3168 return;
3171 status = GdipImageGetFrameDimensionsCount(image, &dim_count);
3172 expect(Ok, status);
3173 expect(1, dim_count);
3175 status = GdipImageGetFrameDimensionsList(image, &guid, 1);
3176 expect(Ok, status);
3177 expect_guid(&FrameDimensionPage, &guid, __LINE__, FALSE);
3179 frame_count = 0xdeadbeef;
3180 status = GdipImageGetFrameCount(image, &guid, &frame_count);
3181 expect(Ok, status);
3182 expect(1, frame_count);
3184 prop_count = 0xdeadbeef;
3185 status = GdipGetPropertyCount(image, &prop_count);
3186 expect(Ok, status);
3187 ok(prop_count == sizeof(td)/sizeof(td[0]) ||
3188 broken(prop_count == sizeof(td)/sizeof(td[0]) - 1) /* Win7 SP0 */,
3189 "expected property count %u, got %u\n", (UINT)(sizeof(td)/sizeof(td[0])), prop_count);
3191 prop_id = HeapAlloc(GetProcessHeap(), 0, prop_count * sizeof(*prop_id));
3193 status = GdipGetPropertyIdList(image, prop_count, prop_id);
3194 expect(Ok, status);
3196 for (i = 0; i < prop_count; i++)
3198 status = GdipGetPropertyItemSize(image, prop_id[i], &prop_size);
3199 expect(Ok, status);
3200 if (status != Ok) break;
3201 ok(prop_size > sizeof(*prop_item), "%u: too small item length %u\n", i, prop_size);
3203 prop_item = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, prop_size);
3204 status = GdipGetPropertyItem(image, prop_id[i], prop_size, prop_item);
3205 expect(Ok, status);
3206 ok(prop_item->value == prop_item + 1, "expected item->value %p, got %p\n", prop_item + 1, prop_item->value);
3207 ok(td[i].type == prop_item->type ||
3208 /* Win7 stopped using proper but not documented types, and it
3209 looks broken since TypeFloat and TypeDouble now reported as
3210 TypeUndefined, and signed types reported as unsigned. */
3211 broken(prop_item->type == documented_type(td[i].type)),
3212 "%u: expected type %u, got %u\n", i, td[i].type, prop_item->type);
3213 ok(td[i].id == prop_item->id, "%u: expected id %#x, got %#x\n", i, td[i].id, prop_item->id);
3214 prop_size -= sizeof(*prop_item);
3215 ok(prop_item->length == prop_size, "%u: expected length %u, got %u\n", i, prop_size, prop_item->length);
3216 ok(td[i].length == prop_item->length, "%u: expected length %u, got %u\n", i, td[i].length, prop_item->length);
3217 ok(td[i].length == prop_size, "%u: expected length %u, got %u\n", i, td[i].length, prop_size);
3218 if (td[i].length == prop_item->length)
3220 int match = memcmp(td[i].value, prop_item->value, td[i].length) == 0;
3221 ok(match || broken(td[i].length <= 4 && !match), "%u: data mismatch\n", i);
3222 if (!match)
3224 UINT j;
3225 BYTE *data = prop_item->value;
3226 printf("id %#x:", prop_item->id);
3227 for (j = 0; j < prop_item->length; j++)
3228 printf(" %02x", data[j]);
3229 printf("\n");
3232 HeapFree(GetProcessHeap(), 0, prop_item);
3235 HeapFree(GetProcessHeap(), 0, prop_id);
3237 GdipDisposeImage(image);
3240 static void test_GdipGetAllPropertyItems(void)
3242 static const struct test_data
3244 ULONG type, id, length;
3245 BYTE value[32];
3246 } td[16] =
3248 { PropertyTagTypeLong, 0xfe, 4, { 0 } },
3249 { PropertyTagTypeShort, 0x100, 2, { 1 } },
3250 { PropertyTagTypeShort, 0x101, 2, { 1 } },
3251 { PropertyTagTypeShort, 0x102, 6, { 8,0,8,0,8,0 } },
3252 { PropertyTagTypeShort, 0x103, 2, { 1 } },
3253 { PropertyTagTypeShort, 0x106, 2, { 2,0 } },
3254 { PropertyTagTypeASCII, 0x10d, 27, "/home/meh/Desktop/test.tif" },
3255 { PropertyTagTypeLong, 0x111, 4, { 8,0,0,0 } },
3256 { PropertyTagTypeShort, 0x112, 2, { 1 } },
3257 { PropertyTagTypeShort, 0x115, 2, { 3,0 } },
3258 { PropertyTagTypeShort, 0x116, 2, { 0x40,0 } },
3259 { PropertyTagTypeLong, 0x117, 4, { 3,0,0,0 } },
3260 { PropertyTagTypeRational, 0x11a, 8, { 0,0,0,72,0,0,0,1 } },
3261 { PropertyTagTypeRational, 0x11b, 8, { 0,0,0,72,0,0,0,1 } },
3262 { PropertyTagTypeShort, 0x11c, 2, { 1 } },
3263 { PropertyTagTypeShort, 0x128, 2, { 2 } }
3265 GpStatus status;
3266 GpImage *image;
3267 GUID guid;
3268 UINT dim_count, frame_count, prop_count, prop_size, i;
3269 UINT total_size, total_count;
3270 PROPID *prop_id;
3271 PropertyItem *prop_item;
3272 const char *item_data;
3274 image = load_image(tiffimage, sizeof(tiffimage));
3275 ok(image != 0, "Failed to load TIFF image data\n");
3276 if (!image) return;
3278 dim_count = 0xdeadbeef;
3279 status = GdipImageGetFrameDimensionsCount(image, &dim_count);
3280 expect(Ok, status);
3281 expect(1, dim_count);
3283 status = GdipImageGetFrameDimensionsList(image, &guid, 1);
3284 expect(Ok, status);
3285 expect_guid(&FrameDimensionPage, &guid, __LINE__, FALSE);
3287 frame_count = 0xdeadbeef;
3288 status = GdipImageGetFrameCount(image, &guid, &frame_count);
3289 expect(Ok, status);
3290 expect(1, frame_count);
3292 prop_count = 0xdeadbeef;
3293 status = GdipGetPropertyCount(image, &prop_count);
3294 expect(Ok, status);
3295 ok(prop_count == sizeof(td)/sizeof(td[0]),
3296 "expected property count %u, got %u\n", (UINT)(sizeof(td)/sizeof(td[0])), prop_count);
3298 prop_id = HeapAlloc(GetProcessHeap(), 0, prop_count * sizeof(*prop_id));
3300 status = GdipGetPropertyIdList(image, prop_count, prop_id);
3301 expect(Ok, status);
3303 prop_size = 0;
3304 for (i = 0; i < prop_count; i++)
3306 UINT size;
3307 status = GdipGetPropertyItemSize(image, prop_id[i], &size);
3308 expect(Ok, status);
3309 if (status != Ok) break;
3310 ok(size > sizeof(*prop_item), "%u: too small item length %u\n", i, size);
3312 prop_size += size;
3314 prop_item = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
3315 status = GdipGetPropertyItem(image, prop_id[i], size, prop_item);
3316 expect(Ok, status);
3317 ok(prop_item->value == prop_item + 1, "expected item->value %p, got %p\n", prop_item + 1, prop_item->value);
3318 ok(td[i].type == prop_item->type,
3319 "%u: expected type %u, got %u\n", i, td[i].type, prop_item->type);
3320 ok(td[i].id == prop_item->id, "%u: expected id %#x, got %#x\n", i, td[i].id, prop_item->id);
3321 size -= sizeof(*prop_item);
3322 ok(prop_item->length == size, "%u: expected length %u, got %u\n", i, size, prop_item->length);
3323 ok(td[i].length == prop_item->length, "%u: expected length %u, got %u\n", i, td[i].length, prop_item->length);
3324 if (td[i].length == prop_item->length)
3326 int match = memcmp(td[i].value, prop_item->value, td[i].length) == 0;
3327 ok(match, "%u: data mismatch\n", i);
3328 if (!match)
3330 UINT j;
3331 BYTE *data = prop_item->value;
3332 printf("id %#x:", prop_item->id);
3333 for (j = 0; j < prop_item->length; j++)
3334 printf(" %02x", data[j]);
3335 printf("\n");
3338 HeapFree(GetProcessHeap(), 0, prop_item);
3341 HeapFree(GetProcessHeap(), 0, prop_id);
3343 status = GdipGetPropertySize(NULL, &total_size, &total_count);
3344 expect(InvalidParameter, status);
3345 status = GdipGetPropertySize(image, &total_size, NULL);
3346 expect(InvalidParameter, status);
3347 status = GdipGetPropertySize(image, NULL, &total_count);
3348 expect(InvalidParameter, status);
3349 status = GdipGetPropertySize(image, NULL, NULL);
3350 expect(InvalidParameter, status);
3351 total_size = 0xdeadbeef;
3352 total_count = 0xdeadbeef;
3353 status = GdipGetPropertySize(image, &total_size, &total_count);
3354 expect(Ok, status);
3355 ok(prop_count == total_count,
3356 "expected total property count %u, got %u\n", prop_count, total_count);
3357 ok(prop_size == total_size,
3358 "expected total property size %u, got %u\n", prop_size, total_size);
3360 prop_item = HeapAlloc(GetProcessHeap(), 0, prop_size);
3362 status = GdipGetAllPropertyItems(image, 0, prop_count, prop_item);
3363 expect(InvalidParameter, status);
3364 status = GdipGetAllPropertyItems(image, prop_size, 1, prop_item);
3365 expect(InvalidParameter, status);
3366 status = GdipGetAllPropertyItems(image, prop_size, prop_count, NULL);
3367 expect(InvalidParameter, status);
3368 status = GdipGetAllPropertyItems(image, prop_size, prop_count, NULL);
3369 expect(InvalidParameter, status);
3370 status = GdipGetAllPropertyItems(image, 0, 0, NULL);
3371 expect(InvalidParameter, status);
3372 status = GdipGetAllPropertyItems(image, prop_size + 1, prop_count, prop_item);
3373 expect(InvalidParameter, status);
3374 status = GdipGetAllPropertyItems(image, prop_size, prop_count, prop_item);
3375 expect(Ok, status);
3377 item_data = (const char *)(prop_item + prop_count);
3378 for (i = 0; i < prop_count; i++)
3380 ok(prop_item[i].value == item_data, "%u: expected value %p, got %p\n",
3381 i, item_data, prop_item[i].value);
3382 ok(td[i].type == prop_item[i].type,
3383 "%u: expected type %u, got %u\n", i, td[i].type, prop_item[i].type);
3384 ok(td[i].id == prop_item[i].id, "%u: expected id %#x, got %#x\n", i, td[i].id, prop_item[i].id);
3385 ok(td[i].length == prop_item[i].length, "%u: expected length %u, got %u\n", i, td[i].length, prop_item[i].length);
3386 if (td[i].length == prop_item[i].length)
3388 int match = memcmp(td[i].value, prop_item[i].value, td[i].length) == 0;
3389 ok(match, "%u: data mismatch\n", i);
3390 if (!match)
3392 UINT j;
3393 BYTE *data = prop_item[i].value;
3394 printf("id %#x:", prop_item[i].id);
3395 for (j = 0; j < prop_item[i].length; j++)
3396 printf(" %02x", data[j]);
3397 printf("\n");
3400 item_data += prop_item[i].length;
3403 HeapFree(GetProcessHeap(), 0, prop_item);
3405 GdipDisposeImage(image);
3408 static void test_tiff_palette(void)
3410 GpStatus status;
3411 GpImage *image;
3412 PixelFormat format;
3413 INT size;
3414 struct
3416 ColorPalette pal;
3417 ARGB entry[256];
3418 } palette;
3419 ARGB *entries = palette.pal.Entries;
3421 /* 1bpp TIFF without palette */
3422 image = load_image((const BYTE *)&TIFF_data, sizeof(TIFF_data));
3423 if (!image)
3425 win_skip("Failed to load TIFF image data. Might not be supported. Skipping.\n");
3426 return;
3429 status = GdipGetImagePixelFormat(image, &format);
3430 expect(Ok, status);
3431 ok(format == PixelFormat1bppIndexed, "expected PixelFormat1bppIndexed, got %#x\n", format);
3433 status = GdipGetImagePaletteSize(image, &size);
3434 ok(status == Ok || broken(status == GenericError), /* XP */
3435 "GdipGetImagePaletteSize error %d\n", status);
3436 if (status == GenericError)
3438 GdipDisposeImage(image);
3439 return;
3441 expect(sizeof(ColorPalette) + sizeof(ARGB), size);
3443 status = GdipGetImagePalette(image, &palette.pal, size);
3444 expect(Ok, status);
3445 expect(0, palette.pal.Flags);
3446 expect(2, palette.pal.Count);
3447 if (palette.pal.Count == 2)
3449 ok(entries[0] == 0xff000000, "expected 0xff000000, got %#x\n", entries[0]);
3450 ok(entries[1] == 0xffffffff, "expected 0xffffffff, got %#x\n", entries[1]);
3453 GdipDisposeImage(image);
3456 static void test_bitmapbits(void)
3458 /* 8 x 2 bitmap */
3459 static const BYTE pixels_24[48] =
3461 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3462 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3463 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3464 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0
3466 static const BYTE pixels_00[48] =
3468 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3469 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3470 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3471 0,0,0, 0,0,0, 0,0,0, 0,0,0
3473 static const BYTE pixels_24_77[64] =
3475 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3476 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3477 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3478 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3479 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3480 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3482 static const BYTE pixels_77[64] =
3484 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3485 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3486 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3487 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3488 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3489 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3490 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3491 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3493 static const BYTE pixels_8[16] =
3495 0x01,0,0x01,0,0x01,0,0x01,0,
3496 0x01,0,0x01,0,0x01,0,0x01,0
3498 static const BYTE pixels_8_77[64] =
3500 0x01,0,0x01,0,0x01,0,0x01,0,
3501 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3502 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3503 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3504 0x01,0,0x01,0,0x01,0,0x01,0,
3505 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3506 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3507 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3509 static const BYTE pixels_1_77[64] =
3511 0xaa,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3512 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3513 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3514 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3515 0xaa,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3516 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3517 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3518 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3520 static const BYTE pixels_1[8] = {0xaa,0,0,0,0xaa,0,0,0};
3521 static const struct test_data
3523 PixelFormat format;
3524 UINT bpp;
3525 ImageLockMode mode;
3526 UINT stride, size;
3527 const BYTE *pixels;
3528 const BYTE *pixels_unlocked;
3529 } td[] =
3531 /* 0 */
3532 { PixelFormat24bppRGB, 24, 0xfff0, 24, 48, pixels_24, pixels_00 },
3534 { PixelFormat24bppRGB, 24, 0, 24, 48, pixels_24, pixels_00 },
3535 { PixelFormat24bppRGB, 24, ImageLockModeRead, 24, 48, pixels_24, pixels_00 },
3536 { PixelFormat24bppRGB, 24, ImageLockModeWrite, 24, 48, pixels_24, pixels_00 },
3537 { PixelFormat24bppRGB, 24, ImageLockModeRead|ImageLockModeWrite, 24, 48, pixels_24, pixels_00 },
3538 { PixelFormat24bppRGB, 24, ImageLockModeRead|ImageLockModeUserInputBuf, 32, 64, pixels_24_77, pixels_24 },
3539 { PixelFormat24bppRGB, 24, ImageLockModeWrite|ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_00 },
3540 { PixelFormat24bppRGB, 24, ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_24 },
3541 /* 8 */
3542 { PixelFormat8bppIndexed, 8, 0, 8, 16, pixels_8, pixels_24 },
3543 { PixelFormat8bppIndexed, 8, ImageLockModeRead, 8, 16, pixels_8, pixels_24 },
3544 { PixelFormat8bppIndexed, 8, ImageLockModeWrite, 8, 16, pixels_8, pixels_00 },
3545 { PixelFormat8bppIndexed, 8, ImageLockModeRead|ImageLockModeWrite, 8, 16, pixels_8, pixels_00 },
3546 { PixelFormat8bppIndexed, 8, ImageLockModeRead|ImageLockModeUserInputBuf, 32, 64, pixels_8_77, pixels_24 },
3547 { PixelFormat8bppIndexed, 8, ImageLockModeWrite|ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_00 },
3548 { PixelFormat8bppIndexed, 8, ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_24 },
3549 /* 15 */
3550 { PixelFormat1bppIndexed, 1, 0, 4, 8, pixels_1, pixels_24 },
3551 { PixelFormat1bppIndexed, 1, ImageLockModeRead, 4, 8, pixels_1, pixels_24 },
3552 { PixelFormat1bppIndexed, 1, ImageLockModeWrite, 4, 8, pixels_1, pixels_00 },
3553 { PixelFormat1bppIndexed, 1, ImageLockModeRead|ImageLockModeWrite, 4, 8, pixels_1, pixels_00 },
3554 { PixelFormat1bppIndexed, 1, ImageLockModeRead|ImageLockModeUserInputBuf, 32, 64, pixels_1_77, pixels_24 },
3555 { PixelFormat1bppIndexed, 1, ImageLockModeWrite|ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_00 },
3556 { PixelFormat1bppIndexed, 1, ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_24 },
3558 BYTE buf[64];
3559 GpStatus status;
3560 GpBitmap *bitmap;
3561 UINT i;
3562 BitmapData data;
3563 struct
3565 ColorPalette pal;
3566 ARGB entries[1];
3567 } palette;
3568 ARGB *entries = palette.pal.Entries;
3570 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3572 BYTE pixels[sizeof(pixels_24)];
3573 memcpy(pixels, pixels_24, sizeof(pixels_24));
3574 status = GdipCreateBitmapFromScan0(8, 2, 24, PixelFormat24bppRGB, pixels, &bitmap);
3575 expect(Ok, status);
3577 /* associate known palette with pixel data */
3578 palette.pal.Flags = PaletteFlagsGrayScale;
3579 palette.pal.Count = 2;
3580 entries[0] = 0xff000000;
3581 entries[1] = 0xffffffff;
3582 status = GdipSetImagePalette((GpImage *)bitmap, &palette.pal);
3583 expect(Ok, status);
3585 memset(&data, 0xfe, sizeof(data));
3586 if (td[i].mode & ImageLockModeUserInputBuf)
3588 memset(buf, 0x77, sizeof(buf));
3589 data.Scan0 = buf;
3590 data.Stride = 32;
3592 status = GdipBitmapLockBits(bitmap, NULL, td[i].mode, td[i].format, &data);
3593 ok(status == Ok || broken(status == InvalidParameter) /* XP */, "%u: GdipBitmapLockBits error %d\n", i, status);
3594 if (status != Ok)
3596 GdipDisposeImage((GpImage *)bitmap);
3597 continue;
3599 ok(data.Width == 8, "%u: expected 8, got %d\n", i, data.Width);
3600 ok(data.Height == 2, "%u: expected 2, got %d\n", i, data.Height);
3601 ok(td[i].stride == data.Stride, "%u: expected %d, got %d\n", i, td[i].stride, data.Stride);
3602 ok(td[i].format == data.PixelFormat, "%u: expected %d, got %d\n", i, td[i].format, data.PixelFormat);
3603 ok(td[i].size == data.Height * data.Stride, "%u: expected %d, got %d\n", i, td[i].size, data.Height * data.Stride);
3604 if (td[i].mode & ImageLockModeUserInputBuf)
3605 ok(data.Scan0 == buf, "%u: got wrong buffer\n", i);
3606 if (td[i].size == data.Height * data.Stride)
3608 UINT j, match, width_bytes = (data.Width * td[i].bpp) / 8;
3610 match = 1;
3611 for (j = 0; j < data.Height; j++)
3613 if (memcmp((const BYTE *)data.Scan0 + j * data.Stride, td[i].pixels + j * data.Stride, width_bytes) != 0)
3615 match = 0;
3616 break;
3619 if ((td[i].mode & (ImageLockModeRead|ImageLockModeUserInputBuf)) || td[i].format == PixelFormat24bppRGB)
3621 ok(match,
3622 "%u: data should match\n", i);
3623 if (!match)
3625 BYTE *bits = data.Scan0;
3626 printf("%u: data mismatch for format %#x:", i, td[i].format);
3627 for (j = 0; j < td[i].size; j++)
3628 printf(" %02x", bits[j]);
3629 printf("\n");
3632 else
3633 ok(!match, "%u: data shouldn't match\n", i);
3635 memset(data.Scan0, 0, td[i].size);
3638 status = GdipBitmapUnlockBits(bitmap, &data);
3639 ok(status == Ok, "%u: GdipBitmapUnlockBits error %d\n", i, status);
3641 memset(&data, 0xfe, sizeof(data));
3642 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat24bppRGB, &data);
3643 ok(status == Ok, "%u: GdipBitmapLockBits error %d\n", i, status);
3644 ok(data.Width == 8, "%u: expected 8, got %d\n", i, data.Width);
3645 ok(data.Height == 2, "%u: expected 2, got %d\n", i, data.Height);
3646 ok(data.Stride == 24, "%u: expected 24, got %d\n", i, data.Stride);
3647 ok(data.PixelFormat == PixelFormat24bppRGB, "%u: got wrong pixel format %d\n", i, data.PixelFormat);
3648 ok(data.Height * data.Stride == 48, "%u: expected 48, got %d\n", i, data.Height * data.Stride);
3649 if (data.Height * data.Stride == 48)
3651 int match = memcmp(data.Scan0, td[i].pixels_unlocked, 48) == 0;
3652 ok(match, "%u: data should match\n", i);
3653 if (!match)
3655 UINT j;
3656 BYTE *bits = data.Scan0;
3657 printf("%u: data mismatch for format %#x:", i, td[i].format);
3658 for (j = 0; j < 48; j++)
3659 printf(" %02x", bits[j]);
3660 printf("\n");
3664 status = GdipBitmapUnlockBits(bitmap, &data);
3665 ok(status == Ok, "%u: GdipBitmapUnlockBits error %d\n", i, status);
3667 status = GdipDisposeImage((GpImage *)bitmap);
3668 expect(Ok, status);
3672 static void test_DrawImage(void)
3674 BYTE black_1x1[4] = { 0,0,0,0 };
3675 BYTE white_2x2[16] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
3676 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
3677 BYTE black_2x2[16] = { 0,0,0,0,0,0,0xff,0xff,
3678 0,0,0,0,0,0,0xff,0xff };
3679 GpStatus status;
3680 union
3682 GpBitmap *bitmap;
3683 GpImage *image;
3684 } u1, u2;
3685 GpGraphics *graphics;
3686 int match;
3688 status = GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB, black_1x1, &u1.bitmap);
3689 expect(Ok, status);
3690 status = GdipBitmapSetResolution(u1.bitmap, 100.0, 100.0);
3691 expect(Ok, status);
3693 status = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat24bppRGB, white_2x2, &u2.bitmap);
3694 expect(Ok, status);
3695 status = GdipBitmapSetResolution(u2.bitmap, 300.0, 300.0);
3696 expect(Ok, status);
3697 status = GdipGetImageGraphicsContext(u2.image, &graphics);
3698 expect(Ok, status);
3699 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3700 expect(Ok, status);
3702 status = GdipDrawImageI(graphics, u1.image, 0, 0);
3703 expect(Ok, status);
3705 match = memcmp(white_2x2, black_2x2, sizeof(black_2x2)) == 0;
3706 ok(match, "data should match\n");
3707 if (!match)
3709 UINT i, size = sizeof(white_2x2);
3710 BYTE *bits = white_2x2;
3711 for (i = 0; i < size; i++)
3712 printf(" %02x", bits[i]);
3713 printf("\n");
3716 status = GdipDeleteGraphics(graphics);
3717 expect(Ok, status);
3718 status = GdipDisposeImage(u1.image);
3719 expect(Ok, status);
3720 status = GdipDisposeImage(u2.image);
3721 expect(Ok, status);
3724 static void test_GdipDrawImagePointRect(void)
3726 BYTE black_1x1[4] = { 0,0,0,0 };
3727 BYTE white_2x2[16] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
3728 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
3729 BYTE black_2x2[16] = { 0,0,0,0,0,0,0xff,0xff,
3730 0,0,0,0,0,0,0xff,0xff };
3731 GpStatus status;
3732 union
3734 GpBitmap *bitmap;
3735 GpImage *image;
3736 } u1, u2;
3737 GpGraphics *graphics;
3738 int match;
3740 status = GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB, black_1x1, &u1.bitmap);
3741 expect(Ok, status);
3742 status = GdipBitmapSetResolution(u1.bitmap, 100.0, 100.0);
3743 expect(Ok, status);
3745 status = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat24bppRGB, white_2x2, &u2.bitmap);
3746 expect(Ok, status);
3747 status = GdipBitmapSetResolution(u2.bitmap, 300.0, 300.0);
3748 expect(Ok, status);
3749 status = GdipGetImageGraphicsContext(u2.image, &graphics);
3750 expect(Ok, status);
3751 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3752 expect(Ok, status);
3754 status = GdipDrawImagePointRectI(graphics, u1.image, 0, 0, 0, 0, 1, 1, UnitPixel);
3755 expect(Ok, status);
3757 match = memcmp(white_2x2, black_2x2, sizeof(black_2x2)) == 0;
3758 ok(match, "data should match\n");
3759 if (!match)
3761 UINT i, size = sizeof(white_2x2);
3762 BYTE *bits = white_2x2;
3763 for (i = 0; i < size; i++)
3764 printf(" %02x", bits[i]);
3765 printf("\n");
3768 status = GdipDeleteGraphics(graphics);
3769 expect(Ok, status);
3770 status = GdipDisposeImage(u1.image);
3771 expect(Ok, status);
3772 status = GdipDisposeImage(u2.image);
3773 expect(Ok, status);
3776 static void test_image_format(void)
3778 static const PixelFormat fmt[] =
3780 PixelFormat1bppIndexed, PixelFormat4bppIndexed, PixelFormat8bppIndexed,
3781 PixelFormat16bppGrayScale, PixelFormat16bppRGB555, PixelFormat16bppRGB565,
3782 PixelFormat16bppARGB1555, PixelFormat24bppRGB, PixelFormat32bppRGB,
3783 PixelFormat32bppARGB, PixelFormat32bppPARGB, PixelFormat48bppRGB,
3784 PixelFormat64bppARGB, PixelFormat64bppPARGB, PixelFormat32bppCMYK
3786 GpStatus status;
3787 GpBitmap *bitmap;
3788 GpImage *thumb;
3789 HBITMAP hbitmap;
3790 BITMAP bm;
3791 PixelFormat format;
3792 BitmapData data;
3793 UINT i, ret;
3795 for (i = 0; i < sizeof(fmt)/sizeof(fmt[0]); i++)
3797 status = GdipCreateBitmapFromScan0(1, 1, 0, fmt[i], NULL, &bitmap);
3798 ok(status == Ok || broken(status == InvalidParameter) /* before win7 */,
3799 "GdipCreateBitmapFromScan0 error %d\n", status);
3800 if (status != Ok) continue;
3802 status = GdipGetImagePixelFormat((GpImage *)bitmap, &format);
3803 expect(Ok, status);
3804 expect(fmt[i], format);
3806 status = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
3807 if (fmt[i] == PixelFormat16bppGrayScale || fmt[i] == PixelFormat32bppCMYK)
3808 todo_wine expect(InvalidParameter, status);
3809 else
3811 expect(Ok, status);
3812 ret = GetObject(hbitmap, sizeof(bm), &bm);
3813 expect(sizeof(bm), ret);
3814 expect(0, bm.bmType);
3815 expect(1, bm.bmWidth);
3816 expect(1, bm.bmHeight);
3817 expect(4, bm.bmWidthBytes);
3818 expect(1, bm.bmPlanes);
3819 expect(32, bm.bmBitsPixel);
3820 DeleteObject(hbitmap);
3823 status = GdipGetImageThumbnail((GpImage *)bitmap, 0, 0, &thumb, NULL, NULL);
3824 if (fmt[i] == PixelFormat16bppGrayScale || fmt[i] == PixelFormat32bppCMYK)
3825 todo_wine
3826 ok(status == OutOfMemory || broken(status == InvalidParameter) /* before win7 */,
3827 "expected OutOfMemory, got %d\n", status);
3828 else
3830 expect(Ok, status);
3831 status = GdipGetImagePixelFormat(thumb, &format);
3832 expect(Ok, status);
3833 ok(format == PixelFormat32bppPARGB || broken(format != PixelFormat32bppPARGB) /* before win7 */,
3834 "expected PixelFormat32bppPARGB, got %#x\n", format);
3835 status = GdipDisposeImage(thumb);
3836 expect(Ok, status);
3839 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat32bppPARGB, &data);
3840 if (fmt[i] == PixelFormat16bppGrayScale || fmt[i] == PixelFormat32bppCMYK)
3841 todo_wine expect(InvalidParameter, status);
3842 else
3844 expect(Ok, status);
3845 status = GdipBitmapUnlockBits(bitmap, &data);
3846 expect(Ok, status);
3849 status = GdipDisposeImage((GpImage *)bitmap);
3850 expect(Ok, status);
3854 static void test_DrawImage_scale(void)
3856 static const BYTE back_8x1[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
3857 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3858 static const BYTE image_080[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,
3859 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3860 static const BYTE image_100[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40,
3861 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3862 static const BYTE image_120[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x40,0x40,0x40,
3863 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3864 static const BYTE image_150[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3865 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3866 static const BYTE image_180[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3867 0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3868 static const BYTE image_200[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3869 0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3870 static const BYTE image_250[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,
3871 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40 };
3872 static const BYTE image_120_half[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
3873 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3874 static const BYTE image_150_half[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
3875 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3876 static const BYTE image_200_half[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3877 0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40 };
3878 static const BYTE image_250_half[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3879 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40 };
3880 static const struct test_data
3882 REAL scale_x;
3883 PixelOffsetMode pixel_offset_mode;
3884 const BYTE *image;
3885 BOOL todo;
3886 } td[] =
3888 { 0.8, PixelOffsetModeNone, image_080 }, /* 0 */
3889 { 1.0, PixelOffsetModeNone, image_100 },
3890 { 1.2, PixelOffsetModeNone, image_120 },
3891 { 1.5, PixelOffsetModeNone, image_150 },
3892 { 1.8, PixelOffsetModeNone, image_180 },
3893 { 2.0, PixelOffsetModeNone, image_200 },
3894 { 2.5, PixelOffsetModeNone, image_250 },
3896 { 0.8, PixelOffsetModeHighSpeed, image_080 }, /* 7 */
3897 { 1.0, PixelOffsetModeHighSpeed, image_100 },
3898 { 1.2, PixelOffsetModeHighSpeed, image_120 },
3899 { 1.5, PixelOffsetModeHighSpeed, image_150 },
3900 { 1.8, PixelOffsetModeHighSpeed, image_180 },
3901 { 2.0, PixelOffsetModeHighSpeed, image_200 },
3902 { 2.5, PixelOffsetModeHighSpeed, image_250 },
3904 { 0.8, PixelOffsetModeHalf, image_080 }, /* 14 */
3905 { 1.0, PixelOffsetModeHalf, image_100 },
3906 { 1.2, PixelOffsetModeHalf, image_120_half, TRUE },
3907 { 1.5, PixelOffsetModeHalf, image_150_half, TRUE },
3908 { 1.8, PixelOffsetModeHalf, image_180 },
3909 { 2.0, PixelOffsetModeHalf, image_200_half, TRUE },
3910 { 2.5, PixelOffsetModeHalf, image_250_half, TRUE },
3912 { 0.8, PixelOffsetModeHighQuality, image_080 }, /* 21 */
3913 { 1.0, PixelOffsetModeHighQuality, image_100 },
3914 { 1.2, PixelOffsetModeHighQuality, image_120_half, TRUE },
3915 { 1.5, PixelOffsetModeHighQuality, image_150_half, TRUE },
3916 { 1.8, PixelOffsetModeHighQuality, image_180 },
3917 { 2.0, PixelOffsetModeHighQuality, image_200_half, TRUE },
3918 { 2.5, PixelOffsetModeHighQuality, image_250_half, TRUE },
3920 BYTE src_2x1[6] = { 0x80,0x80,0x80,0x80,0x80,0x80 };
3921 BYTE dst_8x1[24];
3922 GpStatus status;
3923 union
3925 GpBitmap *bitmap;
3926 GpImage *image;
3927 } u1, u2;
3928 GpGraphics *graphics;
3929 GpMatrix *matrix;
3930 int i, match;
3932 status = GdipCreateBitmapFromScan0(2, 1, 4, PixelFormat24bppRGB, src_2x1, &u1.bitmap);
3933 expect(Ok, status);
3934 status = GdipBitmapSetResolution(u1.bitmap, 100.0, 100.0);
3935 expect(Ok, status);
3937 status = GdipCreateBitmapFromScan0(8, 1, 24, PixelFormat24bppRGB, dst_8x1, &u2.bitmap);
3938 expect(Ok, status);
3939 status = GdipBitmapSetResolution(u2.bitmap, 100.0, 100.0);
3940 expect(Ok, status);
3941 status = GdipGetImageGraphicsContext(u2.image, &graphics);
3942 expect(Ok, status);
3943 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3944 expect(Ok, status);
3946 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3948 status = GdipSetPixelOffsetMode(graphics, td[i].pixel_offset_mode);
3949 expect(Ok, status);
3951 status = GdipCreateMatrix2(td[i].scale_x, 0.0, 0.0, 1.0, 0.0, 0.0, &matrix);
3952 expect(Ok, status);
3953 status = GdipSetWorldTransform(graphics, matrix);
3954 expect(Ok, status);
3955 GdipDeleteMatrix(matrix);
3957 memcpy(dst_8x1, back_8x1, sizeof(dst_8x1));
3958 status = GdipDrawImageI(graphics, u1.image, 1, 0);
3959 expect(Ok, status);
3961 match = memcmp(dst_8x1, td[i].image, sizeof(dst_8x1)) == 0;
3962 if (!match && td[i].todo)
3963 todo_wine ok(match, "%d: data should match\n", i);
3964 else
3965 ok(match, "%d: data should match\n", i);
3966 if (!match)
3968 UINT i, size = sizeof(dst_8x1);
3969 const BYTE *bits = dst_8x1;
3970 for (i = 0; i < size; i++)
3971 printf(" %02x", bits[i]);
3972 printf("\n");
3976 status = GdipDeleteGraphics(graphics);
3977 expect(Ok, status);
3978 status = GdipDisposeImage(u1.image);
3979 expect(Ok, status);
3980 status = GdipDisposeImage(u2.image);
3981 expect(Ok, status);
3984 static const BYTE animatedgif[] = {
3985 'G','I','F','8','9','a',0x01,0x00,0x01,0x00,0xA1,0x02,0x00,
3986 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,
3987 /*0x21,0xFF,0x0B,'A','N','I','M','E','X','T','S','1','.','0',*/
3988 0x21,0xFF,0x0B,'N','E','T','S','C','A','P','E','2','.','0',
3989 0x03,0x01,0x05,0x00,0x00,
3990 0x21,0xFE,0x0C,'H','e','l','l','o',' ','W','o','r','l','d','!',0x00,
3991 0x21,0x01,0x0D,'a','n','i','m','a','t','i','o','n','.','g','i','f',0x00,
3992 0x21,0xF9,0x04,0xff,0x0A,0x00,0x08,0x00,
3993 0x2C,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
3994 0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,
3995 0x02,0x02,0x4C,0x01,0x00,
3996 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','1',0x00,
3997 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','1',0x00,
3998 0x21,0xF9,0x04,0x00,0x14,0x00,0x01,0x00,
3999 0x2C,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
4000 0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,
4001 0x02,0x02,0x44,0x01,0x00,
4002 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','2',0x00,
4003 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','2',0x00,0x3B
4006 static void test_gif_properties(void)
4008 static const struct test_data
4010 ULONG type, id, length;
4011 const BYTE value[13];
4012 } td[] =
4014 { PropertyTagTypeLong, PropertyTagFrameDelay, 8, { 10,0,0,0,20,0,0,0 } },
4015 { PropertyTagTypeASCII, PropertyTagExifUserComment, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
4016 { PropertyTagTypeShort, PropertyTagLoopCount, 2, { 5,0 } },
4017 { PropertyTagTypeByte, PropertyTagGlobalPalette, 12, { 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c } },
4018 { PropertyTagTypeByte, PropertyTagIndexBackground, 1, { 2 } },
4019 { PropertyTagTypeByte, PropertyTagIndexTransparent, 1, { 8 } }
4021 GpStatus status;
4022 GpImage *image;
4023 GUID guid;
4024 UINT dim_count, frame_count, prop_count, prop_size, i;
4025 UINT total_size, total_count;
4026 PROPID *prop_id;
4027 PropertyItem *prop_item;
4028 const char *item_data;
4030 image = load_image(animatedgif, sizeof(animatedgif));
4031 if (!image) /* XP fails to load this GIF image */
4033 trace("Failed to load GIF image data\n");
4034 return;
4037 status = GdipImageGetFrameDimensionsCount(image, &dim_count);
4038 expect(Ok, status);
4039 expect(1, dim_count);
4041 status = GdipImageGetFrameDimensionsList(image, &guid, 1);
4042 expect(Ok, status);
4043 expect_guid(&FrameDimensionTime, &guid, __LINE__, FALSE);
4045 status = GdipImageGetFrameCount(image, &guid, &frame_count);
4046 expect(Ok, status);
4047 expect(2, frame_count);
4049 status = GdipImageSelectActiveFrame(image, &guid, 1);
4050 expect(Ok, status);
4052 status = GdipGetPropertyCount(image, &prop_count);
4053 expect(Ok, status);
4054 ok(prop_count == sizeof(td)/sizeof(td[0]) || broken(prop_count == 1) /* before win7 */,
4055 "expected property count %u, got %u\n", (UINT)(sizeof(td)/sizeof(td[0])), prop_count);
4057 if (prop_count != sizeof(td)/sizeof(td[0]))
4059 GdipDisposeImage(image);
4060 return;
4063 prop_id = HeapAlloc(GetProcessHeap(), 0, prop_count * sizeof(*prop_id));
4065 status = GdipGetPropertyIdList(image, prop_count, prop_id);
4066 expect(Ok, status);
4068 prop_size = 0;
4069 for (i = 0; i < prop_count; i++)
4071 UINT size;
4072 status = GdipGetPropertyItemSize(image, prop_id[i], &size);
4073 expect(Ok, status);
4074 if (status != Ok) break;
4075 ok(size > sizeof(*prop_item), "%u: too small item length %u\n", i, size);
4077 prop_size += size;
4079 prop_item = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
4080 status = GdipGetPropertyItem(image, prop_id[i], size, prop_item);
4081 expect(Ok, status);
4082 ok(prop_item->value == prop_item + 1, "expected item->value %p, got %p\n", prop_item + 1, prop_item->value);
4083 ok(td[i].type == prop_item->type,
4084 "%u: expected type %u, got %u\n", i, td[i].type, prop_item->type);
4085 ok(td[i].id == prop_item->id, "%u: expected id %#x, got %#x\n", i, td[i].id, prop_item->id);
4086 size -= sizeof(*prop_item);
4087 ok(prop_item->length == size, "%u: expected length %u, got %u\n", i, size, prop_item->length);
4088 ok(td[i].length == prop_item->length, "%u: expected length %u, got %u\n", i, td[i].length, prop_item->length);
4089 if (td[i].length == prop_item->length)
4091 int match = memcmp(td[i].value, prop_item->value, td[i].length) == 0;
4092 ok(match, "%u: data mismatch\n", i);
4093 if (!match)
4095 UINT j;
4096 BYTE *data = prop_item->value;
4097 printf("id %#x:", prop_item->id);
4098 for (j = 0; j < prop_item->length; j++)
4099 printf(" %02x", data[j]);
4100 printf("\n");
4103 HeapFree(GetProcessHeap(), 0, prop_item);
4106 HeapFree(GetProcessHeap(), 0, prop_id);
4108 status = GdipGetPropertySize(NULL, &total_size, &total_count);
4109 expect(InvalidParameter, status);
4110 status = GdipGetPropertySize(image, &total_size, NULL);
4111 expect(InvalidParameter, status);
4112 status = GdipGetPropertySize(image, NULL, &total_count);
4113 expect(InvalidParameter, status);
4114 status = GdipGetPropertySize(image, NULL, NULL);
4115 expect(InvalidParameter, status);
4116 total_size = 0xdeadbeef;
4117 total_count = 0xdeadbeef;
4118 status = GdipGetPropertySize(image, &total_size, &total_count);
4119 expect(Ok, status);
4120 ok(prop_count == total_count,
4121 "expected total property count %u, got %u\n", prop_count, total_count);
4122 ok(prop_size == total_size,
4123 "expected total property size %u, got %u\n", prop_size, total_size);
4125 prop_item = HeapAlloc(GetProcessHeap(), 0, prop_size);
4127 status = GdipGetAllPropertyItems(image, 0, prop_count, prop_item);
4128 expect(InvalidParameter, status);
4129 status = GdipGetAllPropertyItems(image, prop_size, 1, prop_item);
4130 expect(InvalidParameter, status);
4131 status = GdipGetAllPropertyItems(image, prop_size, prop_count, NULL);
4132 expect(InvalidParameter, status);
4133 status = GdipGetAllPropertyItems(image, prop_size, prop_count, NULL);
4134 expect(InvalidParameter, status);
4135 status = GdipGetAllPropertyItems(image, 0, 0, NULL);
4136 expect(InvalidParameter, status);
4137 status = GdipGetAllPropertyItems(image, prop_size + 1, prop_count, prop_item);
4138 expect(InvalidParameter, status);
4139 status = GdipGetAllPropertyItems(image, prop_size, prop_count, prop_item);
4140 expect(Ok, status);
4142 item_data = (const char *)(prop_item + prop_count);
4143 for (i = 0; i < prop_count; i++)
4145 ok(prop_item[i].value == item_data, "%u: expected value %p, got %p\n",
4146 i, item_data, prop_item[i].value);
4147 ok(td[i].type == prop_item[i].type,
4148 "%u: expected type %u, got %u\n", i, td[i].type, prop_item[i].type);
4149 ok(td[i].id == prop_item[i].id, "%u: expected id %#x, got %#x\n", i, td[i].id, prop_item[i].id);
4150 ok(td[i].length == prop_item[i].length, "%u: expected length %u, got %u\n", i, td[i].length, prop_item[i].length);
4151 if (td[i].length == prop_item[i].length)
4153 int match = memcmp(td[i].value, prop_item[i].value, td[i].length) == 0;
4154 ok(match, "%u: data mismatch\n", i);
4155 if (!match)
4157 UINT j;
4158 BYTE *data = prop_item[i].value;
4159 printf("id %#x:", prop_item[i].id);
4160 for (j = 0; j < prop_item[i].length; j++)
4161 printf(" %02x", data[j]);
4162 printf("\n");
4165 item_data += prop_item[i].length;
4168 HeapFree(GetProcessHeap(), 0, prop_item);
4170 GdipDisposeImage(image);
4173 static void test_ARGB_conversion(void)
4175 BYTE argb[8] = { 0x11,0x22,0x33,0x80, 0xff,0xff,0xff,0 };
4176 BYTE pargb[8] = { 0x09,0x11,0x1a,0x80, 0,0,0,0 };
4177 BYTE rgb32_xp[8] = { 0x11,0x22,0x33,0xff, 0xff,0xff,0xff,0xff };
4178 BYTE rgb24[6] = { 0x11,0x22,0x33, 0xff,0xff,0xff };
4179 BYTE *bits;
4180 GpBitmap *bitmap;
4181 BitmapData data;
4182 GpStatus status;
4183 int match;
4185 status = GdipCreateBitmapFromScan0(2, 1, 8, PixelFormat32bppARGB, argb, &bitmap);
4186 expect(Ok, status);
4188 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat32bppPARGB, &data);
4189 expect(Ok, status);
4190 ok(data.Width == 2, "expected 2, got %d\n", data.Width);
4191 ok(data.Height == 1, "expected 1, got %d\n", data.Height);
4192 ok(data.Stride == 8, "expected 8, got %d\n", data.Stride);
4193 ok(data.PixelFormat == PixelFormat32bppPARGB, "expected PixelFormat32bppPARGB, got %d\n", data.PixelFormat);
4194 match = !memcmp(data.Scan0, pargb, sizeof(pargb));
4195 ok(match, "bits don't match\n");
4196 if (!match)
4198 bits = data.Scan0;
4199 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat32bppPARGB,
4200 bits[0], bits[1], bits[2], bits[3], bits[4], bits[5], bits[6], bits[7]);
4202 status = GdipBitmapUnlockBits(bitmap, &data);
4203 expect(Ok, status);
4205 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat32bppRGB, &data);
4206 expect(Ok, status);
4207 ok(data.Width == 2, "expected 2, got %d\n", data.Width);
4208 ok(data.Height == 1, "expected 1, got %d\n", data.Height);
4209 ok(data.Stride == 8, "expected 8, got %d\n", data.Stride);
4210 ok(data.PixelFormat == PixelFormat32bppRGB, "expected PixelFormat32bppRGB, got %d\n", data.PixelFormat);
4211 match = !memcmp(data.Scan0, argb, sizeof(argb)) ||
4212 !memcmp(data.Scan0, rgb32_xp, sizeof(rgb32_xp));
4213 ok(match, "bits don't match\n");
4214 if (!match)
4216 bits = data.Scan0;
4217 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat32bppRGB,
4218 bits[0], bits[1], bits[2], bits[3], bits[4], bits[5], bits[6], bits[7]);
4220 status = GdipBitmapUnlockBits(bitmap, &data);
4221 expect(Ok, status);
4223 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat24bppRGB, &data);
4224 expect(Ok, status);
4225 ok(data.Width == 2, "expected 2, got %d\n", data.Width);
4226 ok(data.Height == 1, "expected 1, got %d\n", data.Height);
4227 ok(data.Stride == 8, "expected 8, got %d\n", data.Stride);
4228 ok(data.PixelFormat == PixelFormat24bppRGB, "expected PixelFormat24bppRGB, got %d\n", data.PixelFormat);
4229 match = !memcmp(data.Scan0, rgb24, sizeof(rgb24));
4230 ok(match, "bits don't match\n");
4231 if (!match)
4233 bits = data.Scan0;
4234 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat24bppRGB,
4235 bits[0], bits[1], bits[2], bits[3], bits[4], bits[5], bits[6], bits[7]);
4237 status = GdipBitmapUnlockBits(bitmap, &data);
4238 expect(Ok, status);
4240 GdipDisposeImage((GpImage *)bitmap);
4243 START_TEST(image)
4245 struct GdiplusStartupInput gdiplusStartupInput;
4246 ULONG_PTR gdiplusToken;
4248 gdiplusStartupInput.GdiplusVersion = 1;
4249 gdiplusStartupInput.DebugEventCallback = NULL;
4250 gdiplusStartupInput.SuppressBackgroundThread = 0;
4251 gdiplusStartupInput.SuppressExternalCodecs = 0;
4253 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
4255 test_ARGB_conversion();
4256 test_DrawImage_scale();
4257 test_image_format();
4258 test_DrawImage();
4259 test_GdipDrawImagePointRect();
4260 test_bitmapbits();
4261 test_tiff_palette();
4262 test_GdipGetAllPropertyItems();
4263 test_tiff_properties();
4264 test_gif_properties();
4265 test_image_properties();
4266 test_Scan0();
4267 test_FromGdiDib();
4268 test_GetImageDimension();
4269 test_GdipImageGetFrameDimensionsCount();
4270 test_LoadingImages();
4271 test_SavingImages();
4272 test_encoders();
4273 test_LockBits();
4274 test_LockBits_UserBuf();
4275 test_GdipCreateBitmapFromHBITMAP();
4276 test_GdipGetImageFlags();
4277 test_GdipCloneImage();
4278 test_testcontrol();
4279 test_fromhicon();
4280 test_getrawformat();
4281 test_loadwmf();
4282 test_createfromwmf();
4283 test_resolution();
4284 test_createhbitmap();
4285 test_getthumbnail();
4286 test_getsetpixel();
4287 test_palette();
4288 test_colormatrix();
4289 test_gamma();
4290 test_multiframegif();
4291 test_rotateflip();
4292 test_remaptable();
4293 test_colorkey();
4294 test_dispose();
4296 GdiplusShutdown(gdiplusToken);