winmm: Improve MCI's Sysinfo string command.
[wine/multimedia.git] / dlls / gdiplus / tests / image.c
blob0ca22e554bffc17cc40a633ffecb752605be4890
1 /*
2 * Unit test suite for images
4 * Copyright (C) 2007 Google (Evan Stade)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include <math.h>
25 #include "initguid.h"
26 #include "windows.h"
27 #include "gdiplus.h"
28 #include "wine/test.h"
30 #define expect(expected, got) ok((UINT)(got) == (UINT)(expected), "Expected %.8x, got %.8x\n", (UINT)(expected), (UINT)(got))
31 #define expectf(expected, got) ok(fabs(expected - got) < 0.0001, "Expected %.2f, got %.2f\n", expected, got)
33 static BOOL color_match(ARGB c1, ARGB c2, BYTE max_diff)
35 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
36 c1 >>= 8; c2 >>= 8;
37 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
38 c1 >>= 8; c2 >>= 8;
39 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
40 c1 >>= 8; c2 >>= 8;
41 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
42 return TRUE;
45 static void expect_guid(REFGUID expected, REFGUID got, int line, BOOL todo)
47 WCHAR bufferW[39];
48 char buffer[39];
49 char buffer2[39];
51 StringFromGUID2(got, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
52 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer, sizeof(buffer), NULL, NULL);
53 StringFromGUID2(expected, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
54 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer2, sizeof(buffer2), NULL, NULL);
55 if(todo)
56 todo_wine ok_(__FILE__, line)(IsEqualGUID(expected, got), "Expected %s, got %s\n", buffer2, buffer);
57 else
58 ok_(__FILE__, line)(IsEqualGUID(expected, got), "Expected %s, got %s\n", buffer2, buffer);
61 static void expect_rawformat(REFGUID expected, GpImage *img, int line, BOOL todo)
63 GUID raw;
64 GpStatus stat;
66 stat = GdipGetImageRawFormat(img, &raw);
67 ok_(__FILE__, line)(stat == Ok, "GdipGetImageRawFormat failed with %d\n", stat);
68 if(stat != Ok) return;
69 expect_guid(expected, &raw, line, todo);
72 static void test_bufferrawformat(void* buff, int size, REFGUID expected, int line, BOOL todo)
74 LPSTREAM stream;
75 HGLOBAL hglob;
76 LPBYTE data;
77 HRESULT hres;
78 GpStatus stat;
79 GpImage *img;
81 hglob = GlobalAlloc (0, size);
82 data = GlobalLock (hglob);
83 memcpy(data, buff, size);
84 GlobalUnlock(hglob); data = NULL;
86 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
87 ok_(__FILE__, line)(hres == S_OK, "Failed to create a stream\n");
88 if(hres != S_OK) return;
90 stat = GdipLoadImageFromStream(stream, &img);
91 ok_(__FILE__, line)(stat == Ok, "Failed to create a Bitmap\n");
92 if(stat != Ok){
93 IStream_Release(stream);
94 return;
97 expect_rawformat(expected, img, line, todo);
99 GdipDisposeImage(img);
100 IStream_Release(stream);
103 static void test_Scan0(void)
105 GpBitmap *bm;
106 GpStatus stat;
107 BYTE buff[360];
109 bm = NULL;
110 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
111 expect(Ok, stat);
112 ok(NULL != bm, "Expected bitmap to be initialized\n");
113 if (stat == Ok)
114 GdipDisposeImage((GpImage*)bm);
116 bm = (GpBitmap*)0xdeadbeef;
117 stat = GdipCreateBitmapFromScan0(10, -10, 10, PixelFormat24bppRGB, NULL, &bm);
118 expect(InvalidParameter, stat);
119 ok( !bm, "expected null bitmap\n" );
121 bm = (GpBitmap*)0xdeadbeef;
122 stat = GdipCreateBitmapFromScan0(-10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
123 expect(InvalidParameter, stat);
124 ok( !bm, "expected null bitmap\n" );
126 bm = (GpBitmap*)0xdeadbeef;
127 stat = GdipCreateBitmapFromScan0(10, 0, 10, PixelFormat24bppRGB, NULL, &bm);
128 expect(InvalidParameter, stat);
129 ok( !bm, "expected null bitmap\n" );
131 bm = NULL;
132 stat = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, buff, &bm);
133 expect(Ok, stat);
134 ok(NULL != bm, "Expected bitmap to be initialized\n");
135 if (stat == Ok)
136 GdipDisposeImage((GpImage*)bm);
138 bm = (GpBitmap*) 0xdeadbeef;
139 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, buff, &bm);
140 expect(InvalidParameter, stat);
141 ok( !bm, "expected null bitmap\n" );
143 bm = (GpBitmap*)0xdeadbeef;
144 stat = GdipCreateBitmapFromScan0(10, 10, 0, PixelFormat24bppRGB, buff, &bm);
145 expect(InvalidParameter, stat);
146 ok( bm == (GpBitmap*)0xdeadbeef, "expected deadbeef bitmap\n" );
148 bm = NULL;
149 stat = GdipCreateBitmapFromScan0(10, 10, -8, PixelFormat24bppRGB, buff, &bm);
150 expect(Ok, stat);
151 ok(NULL != bm, "Expected bitmap to be initialized\n");
152 if (stat == Ok)
153 GdipDisposeImage((GpImage*)bm);
155 bm = (GpBitmap*)0xdeadbeef;
156 stat = GdipCreateBitmapFromScan0(10, 10, -10, PixelFormat24bppRGB, buff, &bm);
157 expect(InvalidParameter, stat);
158 ok( !bm, "expected null bitmap\n" );
161 static void test_GetImageDimension(void)
163 GpBitmap *bm;
164 GpStatus stat;
165 const REAL WIDTH = 10.0, HEIGHT = 20.0;
166 REAL w,h;
168 bm = (GpBitmap*)0xdeadbeef;
169 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
170 expect(Ok,stat);
171 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
172 ok(NULL != bm, "Expected bitmap to not be NULL\n");
174 stat = GdipGetImageDimension(NULL,&w,&h);
175 expect(InvalidParameter, stat);
177 stat = GdipGetImageDimension((GpImage*)bm,NULL,&h);
178 expect(InvalidParameter, stat);
180 stat = GdipGetImageDimension((GpImage*)bm,&w,NULL);
181 expect(InvalidParameter, stat);
183 w = -1;
184 h = -1;
185 stat = GdipGetImageDimension((GpImage*)bm,&w,&h);
186 expect(Ok, stat);
187 expectf(WIDTH, w);
188 expectf(HEIGHT, h);
189 GdipDisposeImage((GpImage*)bm);
192 static void test_GdipImageGetFrameDimensionsCount(void)
194 GpBitmap *bm;
195 GpStatus stat;
196 const REAL WIDTH = 10.0, HEIGHT = 20.0;
197 UINT w;
198 GUID dimension = {0};
199 UINT count;
200 ARGB color;
202 bm = (GpBitmap*)0xdeadbeef;
203 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
204 expect(Ok,stat);
205 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
206 ok(NULL != bm, "Expected bitmap to not be NULL\n");
208 stat = GdipImageGetFrameDimensionsCount(NULL,&w);
209 expect(InvalidParameter, stat);
211 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,NULL);
212 expect(InvalidParameter, stat);
214 w = -1;
215 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,&w);
216 expect(Ok, stat);
217 expect(1, w);
219 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 1);
220 expect(Ok, stat);
221 expect_guid(&FrameDimensionPage, &dimension, __LINE__, FALSE);
223 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 2);
224 expect(InvalidParameter, stat);
226 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 0);
227 expect(InvalidParameter, stat);
229 stat = GdipImageGetFrameCount(NULL, &dimension, &count);
230 expect(InvalidParameter, stat);
232 /* WinXP crashes on this test */
233 if(0)
235 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, NULL);
236 expect(InvalidParameter, stat);
239 stat = GdipImageGetFrameCount((GpImage*)bm, NULL, &count);
240 expect(Ok, stat);
242 count = 12345;
243 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, &count);
244 expect(Ok, stat);
245 expect(1, count);
247 GdipBitmapSetPixel(bm, 0, 0, 0xffffffff);
249 stat = GdipImageSelectActiveFrame((GpImage*)bm, &dimension, 0);
250 expect(Ok, stat);
252 /* SelectActiveFrame has no effect on image data of memory bitmaps */
253 color = 0xdeadbeef;
254 GdipBitmapGetPixel(bm, 0, 0, &color);
255 expect(0xffffffff, color);
257 GdipDisposeImage((GpImage*)bm);
260 static void test_LoadingImages(void)
262 GpStatus stat;
264 stat = GdipCreateBitmapFromFile(0, 0);
265 expect(InvalidParameter, stat);
267 stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
268 expect(InvalidParameter, stat);
270 stat = GdipLoadImageFromFile(0, 0);
271 expect(InvalidParameter, stat);
273 stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
274 expect(InvalidParameter, stat);
276 stat = GdipLoadImageFromFileICM(0, 0);
277 expect(InvalidParameter, stat);
279 stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
280 expect(InvalidParameter, stat);
283 static void test_SavingImages(void)
285 GpStatus stat;
286 GpBitmap *bm;
287 UINT n;
288 UINT s;
289 const REAL WIDTH = 10.0, HEIGHT = 20.0;
290 REAL w, h;
291 ImageCodecInfo *codecs;
292 static const CHAR filenameA[] = "a.bmp";
293 static const WCHAR filename[] = { 'a','.','b','m','p',0 };
295 codecs = NULL;
297 stat = GdipSaveImageToFile(0, 0, 0, 0);
298 expect(InvalidParameter, stat);
300 bm = NULL;
301 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
302 expect(Ok, stat);
303 if (!bm)
304 return;
306 /* invalid params */
307 stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
308 expect(InvalidParameter, stat);
310 stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
311 expect(InvalidParameter, stat);
313 /* encoder tests should succeed -- already tested */
314 stat = GdipGetImageEncodersSize(&n, &s);
315 if (stat != Ok || n == 0) goto cleanup;
317 codecs = GdipAlloc(s);
318 if (!codecs) goto cleanup;
320 stat = GdipGetImageEncoders(n, s, codecs);
321 if (stat != Ok) goto cleanup;
323 stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
324 expect(stat, Ok);
326 GdipDisposeImage((GpImage*)bm);
327 bm = 0;
329 /* re-load and check image stats */
330 stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
331 expect(stat, Ok);
332 if (stat != Ok) goto cleanup;
334 stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
335 if (stat != Ok) goto cleanup;
337 expectf(WIDTH, w);
338 expectf(HEIGHT, h);
340 cleanup:
341 GdipFree(codecs);
342 if (bm)
343 GdipDisposeImage((GpImage*)bm);
344 ok(DeleteFileA(filenameA), "Delete failed.\n");
347 static void test_encoders(void)
349 GpStatus stat;
350 UINT n;
351 UINT s;
352 ImageCodecInfo *codecs;
353 int i;
354 int bmp_found;
356 static const CHAR bmp_format[] = "BMP";
358 stat = GdipGetImageEncodersSize(&n, &s);
359 expect(stat, Ok);
361 codecs = GdipAlloc(s);
362 if (!codecs)
363 return;
365 stat = GdipGetImageEncoders(n, s, NULL);
366 expect(GenericError, stat);
368 stat = GdipGetImageEncoders(0, s, codecs);
369 expect(GenericError, stat);
371 stat = GdipGetImageEncoders(n, s-1, codecs);
372 expect(GenericError, stat);
374 stat = GdipGetImageEncoders(n, s+1, codecs);
375 expect(GenericError, stat);
377 stat = GdipGetImageEncoders(n, s, codecs);
378 expect(stat, Ok);
380 bmp_found = FALSE;
381 for (i = 0; i < n; i++)
383 CHAR desc[32];
385 WideCharToMultiByte(CP_ACP, 0, codecs[i].FormatDescription, -1,
386 desc, 32, 0, 0);
388 if (CompareStringA(LOCALE_SYSTEM_DEFAULT, 0,
389 desc, -1,
390 bmp_format, -1) == CSTR_EQUAL) {
391 bmp_found = TRUE;
392 break;
395 if (!bmp_found)
396 ok(FALSE, "No BMP codec found.\n");
398 GdipFree(codecs);
401 static void test_LockBits(void)
403 GpStatus stat;
404 GpBitmap *bm;
405 GpRect rect;
406 BitmapData bd;
407 const INT WIDTH = 10, HEIGHT = 20;
409 bm = NULL;
410 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
411 expect(Ok, stat);
413 rect.X = 2;
414 rect.Y = 3;
415 rect.Width = 4;
416 rect.Height = 5;
418 /* read-only */
419 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
420 expect(Ok, stat);
422 if (stat == Ok) {
423 stat = GdipBitmapUnlockBits(bm, &bd);
424 expect(Ok, stat);
427 /* read-only, with NULL rect -> whole bitmap lock */
428 stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
429 expect(Ok, stat);
430 expect(bd.Width, WIDTH);
431 expect(bd.Height, HEIGHT);
433 if (stat == Ok) {
434 stat = GdipBitmapUnlockBits(bm, &bd);
435 expect(Ok, stat);
438 /* read-only, consecutive */
439 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
440 expect(Ok, stat);
442 if (stat == Ok) {
443 stat = GdipBitmapUnlockBits(bm, &bd);
444 expect(Ok, stat);
447 stat = GdipDisposeImage((GpImage*)bm);
448 expect(Ok, stat);
449 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
450 expect(Ok, stat);
452 /* read x2 */
453 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
454 expect(Ok, stat);
455 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
456 expect(WrongState, stat);
458 stat = GdipBitmapUnlockBits(bm, &bd);
459 expect(Ok, stat);
461 stat = GdipDisposeImage((GpImage*)bm);
462 expect(Ok, stat);
463 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
464 expect(Ok, stat);
466 /* write, no modification */
467 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
468 expect(Ok, stat);
470 if (stat == Ok) {
471 stat = GdipBitmapUnlockBits(bm, &bd);
472 expect(Ok, stat);
475 /* write, consecutive */
476 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
477 expect(Ok, stat);
479 if (stat == Ok) {
480 stat = GdipBitmapUnlockBits(bm, &bd);
481 expect(Ok, stat);
484 stat = GdipDisposeImage((GpImage*)bm);
485 expect(Ok, stat);
486 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
487 expect(Ok, stat);
489 /* write, modify */
490 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
491 expect(Ok, stat);
493 if (stat == Ok) {
494 if (bd.Scan0)
495 ((char*)bd.Scan0)[2] = 0xff;
497 stat = GdipBitmapUnlockBits(bm, &bd);
498 expect(Ok, stat);
501 stat = GdipDisposeImage((GpImage*)bm);
502 expect(Ok, stat);
504 /* dispose locked */
505 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
506 expect(Ok, stat);
507 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
508 expect(Ok, stat);
509 stat = GdipDisposeImage((GpImage*)bm);
510 expect(Ok, stat);
513 static void test_GdipCreateBitmapFromHBITMAP(void)
515 GpBitmap* gpbm = NULL;
516 HBITMAP hbm = NULL;
517 HPALETTE hpal = NULL;
518 GpStatus stat;
519 BYTE buff[1000];
520 LOGPALETTE* LogPal = NULL;
521 REAL width, height;
522 const REAL WIDTH1 = 5;
523 const REAL HEIGHT1 = 15;
524 const REAL WIDTH2 = 10;
525 const REAL HEIGHT2 = 20;
526 HDC hdc;
527 BITMAPINFO bmi;
528 BYTE *bits;
530 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
531 expect(InvalidParameter, stat);
533 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
534 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
535 expect(InvalidParameter, stat);
537 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
538 expect(Ok, stat);
539 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
540 expectf(WIDTH1, width);
541 expectf(HEIGHT1, height);
542 if (stat == Ok)
543 GdipDisposeImage((GpImage*)gpbm);
544 DeleteObject(hbm);
546 memset(buff, 0, sizeof(buff));
547 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
548 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
549 expect(Ok, stat);
550 /* raw format */
551 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
553 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
554 expectf(WIDTH2, width);
555 expectf(HEIGHT2, height);
556 if (stat == Ok)
557 GdipDisposeImage((GpImage*)gpbm);
558 DeleteObject(hbm);
560 hdc = CreateCompatibleDC(0);
561 ok(hdc != NULL, "CreateCompatibleDC failed\n");
562 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
563 bmi.bmiHeader.biHeight = HEIGHT1;
564 bmi.bmiHeader.biWidth = WIDTH1;
565 bmi.bmiHeader.biBitCount = 24;
566 bmi.bmiHeader.biPlanes = 1;
567 bmi.bmiHeader.biCompression = BI_RGB;
569 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
570 ok(hbm != NULL, "CreateDIBSection failed\n");
572 bits[0] = 0;
574 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
575 expect(Ok, stat);
576 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
577 expectf(WIDTH1, width);
578 expectf(HEIGHT1, height);
579 if (stat == Ok)
581 /* test whether writing to the bitmap affects the original */
582 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
583 expect(Ok, stat);
585 expect(0, bits[0]);
587 GdipDisposeImage((GpImage*)gpbm);
590 LogPal = GdipAlloc(sizeof(LOGPALETTE));
591 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
592 LogPal->palVersion = 0x300;
593 LogPal->palNumEntries = 1;
594 hpal = CreatePalette(LogPal);
595 ok(hpal != NULL, "CreatePalette failed\n");
596 GdipFree(LogPal);
598 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
599 todo_wine
601 expect(Ok, stat);
603 if (stat == Ok)
604 GdipDisposeImage((GpImage*)gpbm);
606 DeleteObject(hpal);
607 DeleteObject(hbm);
610 static void test_GdipGetImageFlags(void)
612 GpImage *img;
613 GpStatus stat;
614 UINT flags;
616 img = (GpImage*)0xdeadbeef;
618 stat = GdipGetImageFlags(NULL, NULL);
619 expect(InvalidParameter, stat);
621 stat = GdipGetImageFlags(NULL, &flags);
622 expect(InvalidParameter, stat);
624 stat = GdipGetImageFlags(img, NULL);
625 expect(InvalidParameter, stat);
628 static void test_GdipCloneImage(void)
630 GpStatus stat;
631 GpRectF rectF;
632 GpUnit unit;
633 GpBitmap *bm;
634 GpImage *image_src, *image_dest = NULL;
635 const INT WIDTH = 10, HEIGHT = 20;
637 /* Create an image, clone it, delete the original, make sure the copy works */
638 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
639 expect(Ok, stat);
640 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
642 image_src = ((GpImage*)bm);
643 stat = GdipCloneImage(image_src, &image_dest);
644 expect(Ok, stat);
645 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
647 stat = GdipDisposeImage((GpImage*)bm);
648 expect(Ok, stat);
649 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
650 expect(Ok, stat);
652 /* Treat FP values carefully */
653 expectf((REAL)WIDTH, rectF.Width);
654 expectf((REAL)HEIGHT, rectF.Height);
656 stat = GdipDisposeImage(image_dest);
657 expect(Ok, stat);
660 static void test_testcontrol(void)
662 GpStatus stat;
663 DWORD param;
665 param = 0;
666 stat = GdipTestControl(TestControlGetBuildNumber, &param);
667 expect(Ok, stat);
668 ok(param != 0, "Build number expected, got %u\n", param);
671 static void test_fromhicon(void)
673 static const BYTE bmp_bits[1024];
674 HBITMAP hbmMask, hbmColor;
675 ICONINFO info;
676 HICON hIcon;
677 GpStatus stat;
678 GpBitmap *bitmap = NULL;
679 UINT dim;
680 ImageType type;
681 PixelFormat format;
683 /* NULL */
684 stat = GdipCreateBitmapFromHICON(NULL, NULL);
685 expect(InvalidParameter, stat);
686 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
687 expect(InvalidParameter, stat);
689 /* color icon 1 bit */
690 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
691 ok(hbmMask != 0, "CreateBitmap failed\n");
692 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
693 ok(hbmColor != 0, "CreateBitmap failed\n");
694 info.fIcon = TRUE;
695 info.xHotspot = 8;
696 info.yHotspot = 8;
697 info.hbmMask = hbmMask;
698 info.hbmColor = hbmColor;
699 hIcon = CreateIconIndirect(&info);
700 ok(hIcon != 0, "CreateIconIndirect failed\n");
701 DeleteObject(hbmMask);
702 DeleteObject(hbmColor);
704 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
705 ok(stat == Ok ||
706 broken(stat == InvalidParameter), /* Win98 */
707 "Expected Ok, got %.8x\n", stat);
708 if(stat == Ok){
709 /* check attributes */
710 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
711 expect(Ok, stat);
712 expect(16, dim);
713 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
714 expect(Ok, stat);
715 expect(16, dim);
716 stat = GdipGetImageType((GpImage*)bitmap, &type);
717 expect(Ok, stat);
718 expect(ImageTypeBitmap, type);
719 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
720 expect(PixelFormat32bppARGB, format);
721 /* raw format */
722 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
723 GdipDisposeImage((GpImage*)bitmap);
725 DestroyIcon(hIcon);
727 /* color icon 8 bpp */
728 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
729 ok(hbmMask != 0, "CreateBitmap failed\n");
730 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
731 ok(hbmColor != 0, "CreateBitmap failed\n");
732 info.fIcon = TRUE;
733 info.xHotspot = 8;
734 info.yHotspot = 8;
735 info.hbmMask = hbmMask;
736 info.hbmColor = hbmColor;
737 hIcon = CreateIconIndirect(&info);
738 ok(hIcon != 0, "CreateIconIndirect failed\n");
739 DeleteObject(hbmMask);
740 DeleteObject(hbmColor);
742 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
743 expect(Ok, stat);
744 if(stat == Ok){
745 /* check attributes */
746 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
747 expect(Ok, stat);
748 expect(16, dim);
749 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
750 expect(Ok, stat);
751 expect(16, dim);
752 stat = GdipGetImageType((GpImage*)bitmap, &type);
753 expect(Ok, stat);
754 expect(ImageTypeBitmap, type);
755 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
756 expect(PixelFormat32bppARGB, format);
757 /* raw format */
758 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
759 GdipDisposeImage((GpImage*)bitmap);
761 DestroyIcon(hIcon);
764 /* 1x1 pixel png */
765 static const unsigned char pngimage[285] = {
766 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
767 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
768 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
769 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
770 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
771 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
772 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
774 /* 1x1 pixel gif */
775 static const unsigned char gifimage[35] = {
776 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
777 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
778 0x01,0x00,0x3b
780 /* 1x1 pixel bmp */
781 static const unsigned char bmpimage[66] = {
782 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
783 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
784 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
785 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
786 0x00,0x00
788 /* 1x1 pixel jpg */
789 static const unsigned char jpgimage[285] = {
790 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
791 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
792 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
793 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
794 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
795 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
796 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
797 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
798 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
799 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
800 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
801 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
802 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
803 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
804 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
805 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
806 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
807 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
809 /* 1x1 pixel tiff */
810 static const unsigned char tiffimage[] = {
811 0x49,0x49,0x2a,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xfe,0x00,
812 0x04,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x00,0x01,0x00,
813 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
814 0x00,0x00,0x02,0x01,0x03,0x00,0x03,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0x03,0x01,
815 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,0x01,0x03,0x00,0x01,0x00,
816 0x00,0x00,0x02,0x00,0x00,0x00,0x0d,0x01,0x02,0x00,0x1b,0x00,0x00,0x00,0xd8,0x00,
817 0x00,0x00,0x11,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x12,0x01,
818 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x01,0x03,0x00,0x01,0x00,
819 0x00,0x00,0x03,0x00,0x00,0x00,0x16,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x40,0x00,
820 0x00,0x00,0x17,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1a,0x01,
821 0x05,0x00,0x01,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x1b,0x01,0x05,0x00,0x01,0x00,
822 0x00,0x00,0xfc,0x00,0x00,0x00,0x1c,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
823 0x00,0x00,0x28,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
824 0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x6d,0x65,
825 0x68,0x2f,0x44,0x65,0x73,0x6b,0x74,0x6f,0x70,0x2f,0x74,0x65,0x73,0x74,0x2e,0x74,
826 0x69,0x66,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,
827 0x00,0x00,0x00,0x01
829 /* 320x320 twip wmf */
830 static const unsigned char wmfimage[180] = {
831 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
832 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
833 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
834 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
835 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
836 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
837 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
838 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
839 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
840 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
841 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
842 0x00,0x00,0x00,0x00
844 static void test_getrawformat(void)
846 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
847 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
848 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
849 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
850 test_bufferrawformat((void*)tiffimage, sizeof(tiffimage), &ImageFormatTIFF, __LINE__, FALSE);
851 test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
854 static void test_loadwmf(void)
856 LPSTREAM stream;
857 HGLOBAL hglob;
858 LPBYTE data;
859 HRESULT hres;
860 GpStatus stat;
861 GpImage *img;
862 GpRectF bounds;
863 GpUnit unit;
864 REAL res = 12345.0;
865 MetafileHeader header;
867 hglob = GlobalAlloc (0, sizeof(wmfimage));
868 data = GlobalLock (hglob);
869 memcpy(data, wmfimage, sizeof(wmfimage));
870 GlobalUnlock(hglob); data = NULL;
872 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
873 ok(hres == S_OK, "Failed to create a stream\n");
874 if(hres != S_OK) return;
876 stat = GdipLoadImageFromStream(stream, &img);
877 ok(stat == Ok, "Failed to create a Bitmap\n");
878 if(stat != Ok){
879 IStream_Release(stream);
880 return;
883 IStream_Release(stream);
885 stat = GdipGetImageBounds(img, &bounds, &unit);
886 expect(Ok, stat);
887 todo_wine expect(UnitPixel, unit);
888 expectf(0.0, bounds.X);
889 expectf(0.0, bounds.Y);
890 todo_wine expectf(320.0, bounds.Width);
891 todo_wine expectf(320.0, bounds.Height);
893 stat = GdipGetImageHorizontalResolution(img, &res);
894 expect(Ok, stat);
895 todo_wine expectf(1440.0, res);
897 stat = GdipGetImageVerticalResolution(img, &res);
898 expect(Ok, stat);
899 todo_wine expectf(1440.0, res);
901 memset(&header, 0, sizeof(header));
902 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
903 expect(Ok, stat);
904 if (stat == Ok)
906 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
907 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
908 todo_wine expect(0x300, header.Version);
909 expect(0, header.EmfPlusFlags);
910 todo_wine expectf(1440.0, header.DpiX);
911 todo_wine expectf(1440.0, header.DpiY);
912 expect(0, header.X);
913 expect(0, header.Y);
914 todo_wine expect(320, header.Width);
915 todo_wine expect(320, header.Height);
916 todo_wine expect(1, U(header).WmfHeader.mtType);
917 expect(0, header.EmfPlusHeaderSize);
918 expect(0, header.LogicalDpiX);
919 expect(0, header.LogicalDpiY);
922 GdipDisposeImage(img);
925 static void test_createfromwmf(void)
927 HMETAFILE hwmf;
928 GpImage *img;
929 GpStatus stat;
930 GpRectF bounds;
931 GpUnit unit;
932 REAL res = 12345.0;
933 MetafileHeader header;
935 hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
936 wmfimage+sizeof(WmfPlaceableFileHeader));
937 ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
939 stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
940 (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
941 expect(Ok, stat);
943 stat = GdipGetImageBounds(img, &bounds, &unit);
944 expect(Ok, stat);
945 todo_wine expect(UnitPixel, unit);
946 expectf(0.0, bounds.X);
947 expectf(0.0, bounds.Y);
948 todo_wine expectf(320.0, bounds.Width);
949 todo_wine expectf(320.0, bounds.Height);
951 stat = GdipGetImageHorizontalResolution(img, &res);
952 expect(Ok, stat);
953 expectf(1440.0, res);
955 stat = GdipGetImageVerticalResolution(img, &res);
956 expect(Ok, stat);
957 expectf(1440.0, res);
959 memset(&header, 0, sizeof(header));
960 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
961 expect(Ok, stat);
962 if (stat == Ok)
964 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
965 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
966 todo_wine expect(0x300, header.Version);
967 expect(0, header.EmfPlusFlags);
968 todo_wine expectf(1440.0, header.DpiX);
969 todo_wine expectf(1440.0, header.DpiY);
970 expect(0, header.X);
971 expect(0, header.Y);
972 todo_wine expect(320, header.Width);
973 todo_wine expect(320, header.Height);
974 todo_wine expect(1, U(header).WmfHeader.mtType);
975 expect(0, header.EmfPlusHeaderSize);
976 expect(0, header.LogicalDpiX);
977 expect(0, header.LogicalDpiY);
980 GdipDisposeImage(img);
983 static void test_resolution(void)
985 GpStatus stat;
986 GpBitmap *bitmap;
987 REAL res=-1.0;
988 HDC screendc;
989 int screenxres, screenyres;
991 /* create Bitmap */
992 stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
993 expect(Ok, stat);
995 /* test invalid values */
996 stat = GdipGetImageHorizontalResolution(NULL, &res);
997 expect(InvalidParameter, stat);
999 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
1000 expect(InvalidParameter, stat);
1002 stat = GdipGetImageVerticalResolution(NULL, &res);
1003 expect(InvalidParameter, stat);
1005 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
1006 expect(InvalidParameter, stat);
1008 stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
1009 expect(InvalidParameter, stat);
1011 stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
1012 expect(InvalidParameter, stat);
1014 /* defaults to screen resolution */
1015 screendc = GetDC(0);
1017 screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
1018 screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
1020 ReleaseDC(0, screendc);
1022 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1023 expect(Ok, stat);
1024 expectf((REAL)screenxres, res);
1026 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1027 expect(Ok, stat);
1028 expectf((REAL)screenyres, res);
1030 /* test changing the resolution */
1031 stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
1032 expect(Ok, stat);
1034 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1035 expect(Ok, stat);
1036 expectf(screenxres*2.0, res);
1038 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1039 expect(Ok, stat);
1040 expectf(screenyres*3.0, res);
1042 stat = GdipDisposeImage((GpImage*)bitmap);
1043 expect(Ok, stat);
1046 static void test_createhbitmap(void)
1048 GpStatus stat;
1049 GpBitmap *bitmap;
1050 HBITMAP hbitmap, oldhbitmap;
1051 BITMAP bm;
1052 int ret;
1053 HDC hdc;
1054 COLORREF pixel;
1055 BYTE bits[640];
1057 memset(bits, 0x68, 640);
1059 /* create Bitmap */
1060 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
1061 expect(Ok, stat);
1063 /* test NULL values */
1064 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
1065 expect(InvalidParameter, stat);
1067 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
1068 expect(InvalidParameter, stat);
1070 /* create HBITMAP */
1071 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
1072 expect(Ok, stat);
1074 if (stat == Ok)
1076 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
1077 expect(sizeof(BITMAP), ret);
1079 expect(0, bm.bmType);
1080 expect(10, bm.bmWidth);
1081 expect(20, bm.bmHeight);
1082 expect(40, bm.bmWidthBytes);
1083 expect(1, bm.bmPlanes);
1084 expect(32, bm.bmBitsPixel);
1085 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1087 hdc = CreateCompatibleDC(NULL);
1089 oldhbitmap = SelectObject(hdc, hbitmap);
1090 pixel = GetPixel(hdc, 5, 5);
1091 SelectObject(hdc, oldhbitmap);
1093 DeleteDC(hdc);
1095 expect(0x686868, pixel);
1097 DeleteObject(hbitmap);
1100 stat = GdipDisposeImage((GpImage*)bitmap);
1101 expect(Ok, stat);
1104 static void test_getsetpixel(void)
1106 GpStatus stat;
1107 GpBitmap *bitmap;
1108 ARGB color;
1109 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1110 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1112 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1113 expect(Ok, stat);
1115 /* null parameters */
1116 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1117 expect(InvalidParameter, stat);
1119 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1120 expect(InvalidParameter, stat);
1122 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1123 expect(InvalidParameter, stat);
1125 /* out of bounds */
1126 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1127 expect(InvalidParameter, stat);
1129 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1130 expect(InvalidParameter, stat);
1132 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1133 ok(stat == InvalidParameter ||
1134 broken(stat == Ok), /* Older gdiplus */
1135 "Expected InvalidParameter, got %.8x\n", stat);
1137 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1138 ok(stat == InvalidParameter ||
1139 broken(stat == Ok), /* Older gdiplus */
1140 "Expected InvalidParameter, got %.8x\n", stat);
1142 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1143 expect(InvalidParameter, stat);
1145 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1146 expect(InvalidParameter, stat);
1148 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1149 expect(InvalidParameter, stat);
1151 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1152 expect(InvalidParameter, stat);
1154 /* valid use */
1155 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1156 expect(Ok, stat);
1157 expect(0xffffffff, color);
1159 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1160 expect(Ok, stat);
1161 expect(0xff0000ff, color);
1163 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1164 expect(Ok, stat);
1166 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1167 expect(Ok, stat);
1169 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1170 expect(Ok, stat);
1171 expect(0xff676869, color);
1173 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1174 expect(Ok, stat);
1175 expect(0xff474849, color);
1177 stat = GdipDisposeImage((GpImage*)bitmap);
1178 expect(Ok, stat);
1181 static void check_halftone_palette(ColorPalette *palette)
1183 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1184 UINT i;
1186 for (i=0; i<palette->Count; i++)
1188 ARGB expected=0xff000000;
1189 if (i<8)
1191 if (i&1) expected |= 0x800000;
1192 if (i&2) expected |= 0x8000;
1193 if (i&4) expected |= 0x80;
1195 else if (i == 8)
1197 expected = 0xffc0c0c0;
1199 else if (i < 16)
1201 if (i&1) expected |= 0xff0000;
1202 if (i&2) expected |= 0xff00;
1203 if (i&4) expected |= 0xff;
1205 else if (i < 40)
1207 expected = 0x00000000;
1209 else
1211 expected |= halftone_values[(i-40)%6];
1212 expected |= halftone_values[((i-40)/6)%6] << 8;
1213 expected |= halftone_values[((i-40)/36)%6] << 16;
1215 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1216 expected, palette->Entries[i], i, palette->Count);
1220 static void test_palette(void)
1222 GpStatus stat;
1223 GpBitmap *bitmap;
1224 INT size;
1225 BYTE buffer[1040];
1226 ColorPalette *palette=(ColorPalette*)buffer;
1227 ARGB color=0;
1229 /* test initial palette from non-indexed bitmap */
1230 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1231 expect(Ok, stat);
1233 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1234 expect(Ok, stat);
1235 expect(sizeof(UINT)*2+sizeof(ARGB), size);
1237 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1238 expect(Ok, stat);
1239 expect(0, palette->Count);
1241 /* test setting palette on not-indexed bitmap */
1242 palette->Count = 3;
1244 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1245 expect(Ok, stat);
1247 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1248 expect(Ok, stat);
1249 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1251 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1252 expect(Ok, stat);
1253 expect(3, palette->Count);
1255 GdipDisposeImage((GpImage*)bitmap);
1257 /* test initial palette on 1-bit bitmap */
1258 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1259 expect(Ok, stat);
1261 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1262 expect(Ok, stat);
1263 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1265 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1266 expect(Ok, stat);
1267 expect(PaletteFlagsGrayScale, palette->Flags);
1268 expect(2, palette->Count);
1270 expect(0xff000000, palette->Entries[0]);
1271 expect(0xffffffff, palette->Entries[1]);
1273 /* test getting/setting pixels */
1274 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1275 expect(Ok, stat);
1276 expect(0xff000000, color);
1278 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1279 todo_wine ok((stat == Ok) ||
1280 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1282 if (stat == Ok)
1284 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1285 expect(Ok, stat);
1286 expect(0xffffffff, color);
1289 GdipDisposeImage((GpImage*)bitmap);
1291 /* test initial palette on 4-bit bitmap */
1292 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1293 expect(Ok, stat);
1295 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1296 expect(Ok, stat);
1297 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1299 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1300 expect(Ok, stat);
1301 expect(0, palette->Flags);
1302 expect(16, palette->Count);
1304 check_halftone_palette(palette);
1306 /* test getting/setting pixels */
1307 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1308 expect(Ok, stat);
1309 expect(0xff000000, color);
1311 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
1312 todo_wine ok((stat == Ok) ||
1313 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1315 if (stat == Ok)
1317 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1318 expect(Ok, stat);
1319 expect(0xffff00ff, color);
1322 GdipDisposeImage((GpImage*)bitmap);
1324 /* test initial palette on 8-bit bitmap */
1325 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1326 expect(Ok, stat);
1328 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1329 expect(Ok, stat);
1330 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1332 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1333 expect(Ok, stat);
1334 expect(PaletteFlagsHalftone, palette->Flags);
1335 expect(256, palette->Count);
1337 check_halftone_palette(palette);
1339 /* test getting/setting pixels */
1340 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1341 expect(Ok, stat);
1342 expect(0xff000000, color);
1344 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
1345 todo_wine ok((stat == Ok) ||
1346 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1348 if (stat == Ok)
1350 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1351 expect(Ok, stat);
1352 expect(0xffcccccc, color);
1355 /* test setting/getting a different palette */
1356 palette->Entries[1] = 0xffcccccc;
1358 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1359 expect(Ok, stat);
1361 palette->Entries[1] = 0;
1363 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1364 expect(Ok, stat);
1365 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1367 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1368 expect(Ok, stat);
1369 expect(PaletteFlagsHalftone, palette->Flags);
1370 expect(256, palette->Count);
1371 expect(0xffcccccc, palette->Entries[1]);
1373 /* test count < 256 */
1374 palette->Flags = 12345;
1375 palette->Count = 3;
1377 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1378 expect(Ok, stat);
1380 palette->Entries[1] = 0;
1381 palette->Entries[3] = 0xdeadbeef;
1383 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1384 expect(Ok, stat);
1385 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1387 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1388 expect(Ok, stat);
1389 expect(12345, palette->Flags);
1390 expect(3, palette->Count);
1391 expect(0xffcccccc, palette->Entries[1]);
1392 expect(0xdeadbeef, palette->Entries[3]);
1394 /* test count > 256 */
1395 palette->Count = 257;
1397 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1398 ok(stat == InvalidParameter ||
1399 broken(stat == Ok), /* Old gdiplus behavior */
1400 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1402 GdipDisposeImage((GpImage*)bitmap);
1405 static void test_colormatrix(void)
1407 GpStatus stat;
1408 ColorMatrix colormatrix, graymatrix;
1409 GpImageAttributes *imageattr;
1410 const ColorMatrix identity = {{
1411 {1.0,0.0,0.0,0.0,0.0},
1412 {0.0,1.0,0.0,0.0,0.0},
1413 {0.0,0.0,1.0,0.0,0.0},
1414 {0.0,0.0,0.0,1.0,0.0},
1415 {0.0,0.0,0.0,0.0,1.0}}};
1416 const ColorMatrix double_red = {{
1417 {2.0,0.0,0.0,0.0,0.0},
1418 {0.0,1.0,0.0,0.0,0.0},
1419 {0.0,0.0,1.0,0.0,0.0},
1420 {0.0,0.0,0.0,1.0,0.0},
1421 {0.0,0.0,0.0,0.0,1.0}}};
1422 GpBitmap *bitmap1, *bitmap2;
1423 GpGraphics *graphics;
1424 ARGB color;
1426 colormatrix = identity;
1427 graymatrix = identity;
1429 stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
1430 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1431 expect(InvalidParameter, stat);
1433 stat = GdipCreateImageAttributes(&imageattr);
1434 expect(Ok, stat);
1436 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1437 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1438 expect(Ok, stat);
1440 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1441 TRUE, NULL, NULL, ColorMatrixFlagsDefault);
1442 expect(InvalidParameter, stat);
1444 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1445 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1446 expect(Ok, stat);
1448 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1449 TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
1450 expect(Ok, stat);
1452 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1453 TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
1454 expect(InvalidParameter, stat);
1456 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1457 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
1458 expect(Ok, stat);
1460 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1461 TRUE, &colormatrix, &graymatrix, 3);
1462 expect(InvalidParameter, stat);
1464 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
1465 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1466 expect(InvalidParameter, stat);
1468 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
1469 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1470 expect(InvalidParameter, stat);
1472 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1473 FALSE, NULL, NULL, ColorMatrixFlagsDefault);
1474 expect(Ok, stat);
1476 /* Drawing a bitmap transforms the colors */
1477 colormatrix = double_red;
1478 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1479 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1480 expect(Ok, stat);
1482 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1483 expect(Ok, stat);
1485 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1486 expect(Ok, stat);
1488 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ffff);
1489 expect(Ok, stat);
1491 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1492 expect(Ok, stat);
1494 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1495 UnitPixel, imageattr, NULL, NULL);
1496 expect(Ok, stat);
1498 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1499 expect(Ok, stat);
1500 todo_wine expect(0xff80ffff, color);
1502 GdipDeleteGraphics(graphics);
1503 GdipDisposeImage((GpImage*)bitmap1);
1504 GdipDisposeImage((GpImage*)bitmap2);
1505 GdipDisposeImageAttributes(imageattr);
1508 static void test_gamma(void)
1510 GpStatus stat;
1511 GpImageAttributes *imageattr;
1512 GpBitmap *bitmap1, *bitmap2;
1513 GpGraphics *graphics;
1514 ARGB color;
1516 stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
1517 expect(InvalidParameter, stat);
1519 stat = GdipCreateImageAttributes(&imageattr);
1520 expect(Ok, stat);
1522 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
1523 expect(Ok, stat);
1525 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
1526 expect(InvalidParameter, stat);
1528 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
1529 expect(InvalidParameter, stat);
1531 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
1532 expect(InvalidParameter, stat);
1534 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
1535 expect(Ok, stat);
1537 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
1538 expect(Ok, stat);
1540 /* Drawing a bitmap transforms the colors */
1541 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
1542 expect(Ok, stat);
1544 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1545 expect(Ok, stat);
1547 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1548 expect(Ok, stat);
1550 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
1551 expect(Ok, stat);
1553 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1554 expect(Ok, stat);
1556 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1557 UnitPixel, imageattr, NULL, NULL);
1558 expect(Ok, stat);
1560 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1561 expect(Ok, stat);
1562 todo_wine ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
1564 GdipDeleteGraphics(graphics);
1565 GdipDisposeImage((GpImage*)bitmap1);
1566 GdipDisposeImage((GpImage*)bitmap2);
1567 GdipDisposeImageAttributes(imageattr);
1570 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
1571 static const unsigned char gifanimation[72] = {
1572 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1573 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
1574 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
1575 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
1576 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
1579 static void test_multiframegif(void)
1581 LPSTREAM stream;
1582 HGLOBAL hglob;
1583 LPBYTE data;
1584 HRESULT hres;
1585 GpStatus stat;
1586 GpBitmap *bmp;
1587 ARGB color;
1588 UINT count;
1589 GUID dimension;
1591 /* Test frame functions with an animated GIF */
1592 hglob = GlobalAlloc (0, sizeof(gifanimation));
1593 data = GlobalLock (hglob);
1594 memcpy(data, gifanimation, sizeof(gifanimation));
1595 GlobalUnlock(hglob);
1597 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1598 ok(hres == S_OK, "Failed to create a stream\n");
1599 if(hres != S_OK) return;
1601 stat = GdipCreateBitmapFromStream(stream, &bmp);
1602 ok(stat == Ok, "Failed to create a Bitmap\n");
1603 if(stat != Ok){
1604 IStream_Release(stream);
1605 return;
1608 /* Bitmap starts at frame 0 */
1609 color = 0xdeadbeef;
1610 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1611 expect(Ok, stat);
1612 expect(0xffffffff, color);
1614 /* Check that we get correct metadata */
1615 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1616 expect(Ok, stat);
1617 expect(1, count);
1619 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1620 expect(Ok, stat);
1621 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1623 count = 12345;
1624 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1625 expect(Ok, stat);
1626 todo_wine expect(2, count);
1628 /* SelectActiveFrame overwrites our current data */
1629 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1630 expect(Ok, stat);
1632 color = 0xdeadbeef;
1633 GdipBitmapGetPixel(bmp, 0, 0, &color);
1634 expect(Ok, stat);
1635 todo_wine expect(0xff000000, color);
1637 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1638 expect(Ok, stat);
1640 color = 0xdeadbeef;
1641 GdipBitmapGetPixel(bmp, 0, 0, &color);
1642 expect(Ok, stat);
1643 expect(0xffffffff, color);
1645 /* Write over the image data */
1646 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
1647 expect(Ok, stat);
1649 /* Switching to the same frame does not overwrite our changes */
1650 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1651 expect(Ok, stat);
1653 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1654 expect(Ok, stat);
1655 expect(0xff000000, color);
1657 /* But switching to another frame and back does */
1658 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1659 expect(Ok, stat);
1661 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1662 expect(Ok, stat);
1664 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1665 expect(Ok, stat);
1666 todo_wine expect(0xffffffff, color);
1668 GdipDisposeImage((GpImage*)bmp);
1669 IStream_Release(stream);
1671 /* Test with a non-animated gif */
1672 hglob = GlobalAlloc (0, sizeof(gifimage));
1673 data = GlobalLock (hglob);
1674 memcpy(data, gifimage, sizeof(gifimage));
1675 GlobalUnlock(hglob);
1677 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1678 ok(hres == S_OK, "Failed to create a stream\n");
1679 if(hres != S_OK) return;
1681 stat = GdipCreateBitmapFromStream(stream, &bmp);
1682 ok(stat == Ok, "Failed to create a Bitmap\n");
1683 if(stat != Ok){
1684 IStream_Release(stream);
1685 return;
1688 /* Check metadata */
1689 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1690 expect(Ok, stat);
1691 expect(1, count);
1693 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1694 expect(Ok, stat);
1695 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1697 count = 12345;
1698 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1699 expect(Ok, stat);
1700 expect(1, count);
1702 GdipDisposeImage((GpImage*)bmp);
1703 IStream_Release(stream);
1706 static void test_rotateflip(void)
1708 GpImage *bitmap;
1709 GpStatus stat;
1710 BYTE bits[24];
1711 static const BYTE orig_bits[24] = {
1712 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
1713 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
1714 UINT width, height;
1715 ARGB color;
1717 memcpy(bits, orig_bits, sizeof(bits));
1718 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1719 expect(Ok, stat);
1721 stat = GdipImageRotateFlip(bitmap, Rotate90FlipNone);
1722 expect(Ok, stat);
1724 stat = GdipGetImageWidth(bitmap, &width);
1725 expect(Ok, stat);
1726 stat = GdipGetImageHeight(bitmap, &height);
1727 expect(Ok, stat);
1728 expect(2, width);
1729 expect(3, height);
1731 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1732 expect(Ok, stat);
1733 expect(0xff00ffff, color);
1735 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 0, &color);
1736 expect(Ok, stat);
1737 expect(0xffff0000, color);
1739 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 2, &color);
1740 expect(Ok, stat);
1741 expect(0xffffff00, color);
1743 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 2, &color);
1744 expect(Ok, stat);
1745 expect(0xff0000ff, color);
1747 expect(0, bits[0]);
1748 expect(0, bits[1]);
1749 expect(0xff, bits[2]);
1751 GdipDisposeImage(bitmap);
1753 memcpy(bits, orig_bits, sizeof(bits));
1754 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1755 expect(Ok, stat);
1757 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipX);
1758 expect(Ok, stat);
1760 stat = GdipGetImageWidth(bitmap, &width);
1761 expect(Ok, stat);
1762 stat = GdipGetImageHeight(bitmap, &height);
1763 expect(Ok, stat);
1764 expect(3, width);
1765 expect(2, height);
1767 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1768 expect(Ok, stat);
1769 expect(0xff0000ff, color);
1771 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
1772 expect(Ok, stat);
1773 expect(0xffff0000, color);
1775 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
1776 expect(Ok, stat);
1777 expect(0xffffff00, color);
1779 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
1780 expect(Ok, stat);
1781 expect(0xff00ffff, color);
1783 expect(0, bits[0]);
1784 expect(0, bits[1]);
1785 expect(0xff, bits[2]);
1787 GdipDisposeImage(bitmap);
1789 memcpy(bits, orig_bits, sizeof(bits));
1790 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1791 expect(Ok, stat);
1793 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipY);
1794 expect(Ok, stat);
1796 stat = GdipGetImageWidth(bitmap, &width);
1797 expect(Ok, stat);
1798 stat = GdipGetImageHeight(bitmap, &height);
1799 expect(Ok, stat);
1800 expect(3, width);
1801 expect(2, height);
1803 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1804 expect(Ok, stat);
1805 expect(0xff00ffff, color);
1807 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
1808 expect(Ok, stat);
1809 expect(0xffffff00, color);
1811 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
1812 expect(Ok, stat);
1813 expect(0xffff0000, color);
1815 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
1816 expect(Ok, stat);
1817 expect(0xff0000ff, color);
1819 expect(0, bits[0]);
1820 expect(0, bits[1]);
1821 expect(0xff, bits[2]);
1823 GdipDisposeImage(bitmap);
1826 static void test_remaptable(void)
1828 GpStatus stat;
1829 GpImageAttributes *imageattr;
1830 GpBitmap *bitmap1, *bitmap2;
1831 GpGraphics *graphics;
1832 ARGB color;
1833 ColorMap *map;
1835 map = GdipAlloc(sizeof(ColorMap));
1837 map->oldColor.Argb = 0xff00ff00;
1838 map->newColor.Argb = 0xffff00ff;
1840 stat = GdipSetImageAttributesRemapTable(NULL, ColorAdjustTypeDefault, TRUE, 1, map);
1841 expect(InvalidParameter, stat);
1843 stat = GdipCreateImageAttributes(&imageattr);
1844 expect(Ok, stat);
1846 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, NULL);
1847 expect(InvalidParameter, stat);
1849 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeCount, TRUE, 1, map);
1850 expect(InvalidParameter, stat);
1852 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeAny, TRUE, 1, map);
1853 expect(InvalidParameter, stat);
1855 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 0, map);
1856 expect(InvalidParameter, stat);
1858 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, FALSE, 0, NULL);
1859 expect(Ok, stat);
1861 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, map);
1862 expect(Ok, stat);
1864 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1865 expect(Ok, stat);
1867 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1868 expect(Ok, stat);
1870 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff00ff00);
1871 expect(Ok, stat);
1873 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1874 expect(Ok, stat);
1876 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1877 UnitPixel, imageattr, NULL, NULL);
1878 expect(Ok, stat);
1880 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1881 expect(Ok, stat);
1882 todo_wine ok(color_match(0xffff00ff, color, 1), "Expected ffff00ff, got %.8x\n", color);
1884 GdipDeleteGraphics(graphics);
1885 GdipDisposeImage((GpImage*)bitmap1);
1886 GdipDisposeImage((GpImage*)bitmap2);
1887 GdipDisposeImageAttributes(imageattr);
1888 GdipFree(map);
1891 START_TEST(image)
1893 struct GdiplusStartupInput gdiplusStartupInput;
1894 ULONG_PTR gdiplusToken;
1896 gdiplusStartupInput.GdiplusVersion = 1;
1897 gdiplusStartupInput.DebugEventCallback = NULL;
1898 gdiplusStartupInput.SuppressBackgroundThread = 0;
1899 gdiplusStartupInput.SuppressExternalCodecs = 0;
1901 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1903 test_Scan0();
1904 test_GetImageDimension();
1905 test_GdipImageGetFrameDimensionsCount();
1906 test_LoadingImages();
1907 test_SavingImages();
1908 test_encoders();
1909 test_LockBits();
1910 test_GdipCreateBitmapFromHBITMAP();
1911 test_GdipGetImageFlags();
1912 test_GdipCloneImage();
1913 test_testcontrol();
1914 test_fromhicon();
1915 test_getrawformat();
1916 test_loadwmf();
1917 test_createfromwmf();
1918 test_resolution();
1919 test_createhbitmap();
1920 test_getsetpixel();
1921 test_palette();
1922 test_colormatrix();
1923 test_gamma();
1924 test_multiframegif();
1925 test_rotateflip();
1926 test_remaptable();
1928 GdiplusShutdown(gdiplusToken);