push 6e61d6ca5bcaf95ac09a664b4ba4f88238c927be
[wine/hacks.git] / dlls / gdiplus / tests / image.c
blob9085ef2cf2d8e37a12d17eabc0845b487b7e71c4
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 count = 12345;
230 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, &count);
231 todo_wine expect(Ok, stat);
232 todo_wine expect(1, count);
234 GdipBitmapSetPixel(bm, 0, 0, 0xffffffff);
236 stat = GdipImageSelectActiveFrame((GpImage*)bm, &dimension, 0);
237 expect(Ok, stat);
239 /* SelectActiveFrame has no effect on image data of memory bitmaps */
240 color = 0xdeadbeef;
241 GdipBitmapGetPixel(bm, 0, 0, &color);
242 expect(0xffffffff, color);
244 GdipDisposeImage((GpImage*)bm);
247 static void test_LoadingImages(void)
249 GpStatus stat;
251 stat = GdipCreateBitmapFromFile(0, 0);
252 expect(InvalidParameter, stat);
254 stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
255 expect(InvalidParameter, stat);
257 stat = GdipLoadImageFromFile(0, 0);
258 expect(InvalidParameter, stat);
260 stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
261 expect(InvalidParameter, stat);
263 stat = GdipLoadImageFromFileICM(0, 0);
264 expect(InvalidParameter, stat);
266 stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
267 expect(InvalidParameter, stat);
270 static void test_SavingImages(void)
272 GpStatus stat;
273 GpBitmap *bm;
274 UINT n;
275 UINT s;
276 const REAL WIDTH = 10.0, HEIGHT = 20.0;
277 REAL w, h;
278 ImageCodecInfo *codecs;
279 static const CHAR filenameA[] = "a.bmp";
280 static const WCHAR filename[] = { 'a','.','b','m','p',0 };
282 codecs = NULL;
284 stat = GdipSaveImageToFile(0, 0, 0, 0);
285 expect(InvalidParameter, stat);
287 bm = NULL;
288 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
289 expect(Ok, stat);
290 if (!bm)
291 return;
293 /* invalid params */
294 stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
295 expect(InvalidParameter, stat);
297 stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
298 expect(InvalidParameter, stat);
300 /* encoder tests should succeed -- already tested */
301 stat = GdipGetImageEncodersSize(&n, &s);
302 if (stat != Ok || n == 0) goto cleanup;
304 codecs = GdipAlloc(s);
305 if (!codecs) goto cleanup;
307 stat = GdipGetImageEncoders(n, s, codecs);
308 if (stat != Ok) goto cleanup;
310 stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
311 expect(stat, Ok);
313 GdipDisposeImage((GpImage*)bm);
314 bm = 0;
316 /* re-load and check image stats */
317 stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
318 expect(stat, Ok);
319 if (stat != Ok) goto cleanup;
321 stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
322 if (stat != Ok) goto cleanup;
324 expectf(WIDTH, w);
325 expectf(HEIGHT, h);
327 cleanup:
328 GdipFree(codecs);
329 if (bm)
330 GdipDisposeImage((GpImage*)bm);
331 ok(DeleteFileA(filenameA), "Delete failed.\n");
334 static void test_encoders(void)
336 GpStatus stat;
337 UINT n;
338 UINT s;
339 ImageCodecInfo *codecs;
340 int i;
341 int bmp_found;
343 static const CHAR bmp_format[] = "BMP";
345 stat = GdipGetImageEncodersSize(&n, &s);
346 expect(stat, Ok);
348 codecs = GdipAlloc(s);
349 if (!codecs)
350 return;
352 stat = GdipGetImageEncoders(n, s, NULL);
353 expect(GenericError, stat);
355 stat = GdipGetImageEncoders(0, s, codecs);
356 expect(GenericError, stat);
358 stat = GdipGetImageEncoders(n, s-1, codecs);
359 expect(GenericError, stat);
361 stat = GdipGetImageEncoders(n, s+1, codecs);
362 expect(GenericError, stat);
364 stat = GdipGetImageEncoders(n, s, codecs);
365 expect(stat, Ok);
367 bmp_found = FALSE;
368 for (i = 0; i < n; i++)
370 CHAR desc[32];
372 WideCharToMultiByte(CP_ACP, 0, codecs[i].FormatDescription, -1,
373 desc, 32, 0, 0);
375 if (CompareStringA(LOCALE_SYSTEM_DEFAULT, 0,
376 desc, -1,
377 bmp_format, -1) == CSTR_EQUAL) {
378 bmp_found = TRUE;
379 break;
382 if (!bmp_found)
383 ok(FALSE, "No BMP codec found.\n");
385 GdipFree(codecs);
388 static void test_LockBits(void)
390 GpStatus stat;
391 GpBitmap *bm;
392 GpRect rect;
393 BitmapData bd;
394 const INT WIDTH = 10, HEIGHT = 20;
396 bm = NULL;
397 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
398 expect(Ok, stat);
400 rect.X = 2;
401 rect.Y = 3;
402 rect.Width = 4;
403 rect.Height = 5;
405 /* read-only */
406 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
407 expect(Ok, stat);
409 if (stat == Ok) {
410 stat = GdipBitmapUnlockBits(bm, &bd);
411 expect(Ok, stat);
414 /* read-only, with NULL rect -> whole bitmap lock */
415 stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
416 expect(Ok, stat);
417 expect(bd.Width, WIDTH);
418 expect(bd.Height, HEIGHT);
420 if (stat == Ok) {
421 stat = GdipBitmapUnlockBits(bm, &bd);
422 expect(Ok, stat);
425 /* read-only, consecutive */
426 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
427 expect(Ok, stat);
429 if (stat == Ok) {
430 stat = GdipBitmapUnlockBits(bm, &bd);
431 expect(Ok, stat);
434 stat = GdipDisposeImage((GpImage*)bm);
435 expect(Ok, stat);
436 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
437 expect(Ok, stat);
439 /* read x2 */
440 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
441 expect(Ok, stat);
442 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
443 expect(WrongState, stat);
445 stat = GdipBitmapUnlockBits(bm, &bd);
446 expect(Ok, stat);
448 stat = GdipDisposeImage((GpImage*)bm);
449 expect(Ok, stat);
450 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
451 expect(Ok, stat);
453 /* write, no modification */
454 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
455 expect(Ok, stat);
457 if (stat == Ok) {
458 stat = GdipBitmapUnlockBits(bm, &bd);
459 expect(Ok, stat);
462 /* write, consecutive */
463 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
464 expect(Ok, stat);
466 if (stat == Ok) {
467 stat = GdipBitmapUnlockBits(bm, &bd);
468 expect(Ok, stat);
471 stat = GdipDisposeImage((GpImage*)bm);
472 expect(Ok, stat);
473 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
474 expect(Ok, stat);
476 /* write, modify */
477 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
478 expect(Ok, stat);
480 if (stat == Ok) {
481 if (bd.Scan0)
482 ((char*)bd.Scan0)[2] = 0xff;
484 stat = GdipBitmapUnlockBits(bm, &bd);
485 expect(Ok, stat);
488 stat = GdipDisposeImage((GpImage*)bm);
489 expect(Ok, stat);
491 /* dispose locked */
492 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
493 expect(Ok, stat);
494 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
495 expect(Ok, stat);
496 stat = GdipDisposeImage((GpImage*)bm);
497 expect(Ok, stat);
500 static void test_GdipCreateBitmapFromHBITMAP(void)
502 GpBitmap* gpbm = NULL;
503 HBITMAP hbm = NULL;
504 HPALETTE hpal = NULL;
505 GpStatus stat;
506 BYTE buff[1000];
507 LOGPALETTE* LogPal = NULL;
508 REAL width, height;
509 const REAL WIDTH1 = 5;
510 const REAL HEIGHT1 = 15;
511 const REAL WIDTH2 = 10;
512 const REAL HEIGHT2 = 20;
513 HDC hdc;
514 BITMAPINFO bmi;
515 BYTE *bits;
517 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
518 expect(InvalidParameter, stat);
520 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
521 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
522 expect(InvalidParameter, stat);
524 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
525 expect(Ok, stat);
526 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
527 expectf(WIDTH1, width);
528 expectf(HEIGHT1, height);
529 if (stat == Ok)
530 GdipDisposeImage((GpImage*)gpbm);
531 DeleteObject(hbm);
533 memset(buff, 0, sizeof(buff));
534 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
535 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
536 expect(Ok, stat);
537 /* raw format */
538 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
540 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
541 expectf(WIDTH2, width);
542 expectf(HEIGHT2, height);
543 if (stat == Ok)
544 GdipDisposeImage((GpImage*)gpbm);
545 DeleteObject(hbm);
547 hdc = CreateCompatibleDC(0);
548 ok(hdc != NULL, "CreateCompatibleDC failed\n");
549 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
550 bmi.bmiHeader.biHeight = HEIGHT1;
551 bmi.bmiHeader.biWidth = WIDTH1;
552 bmi.bmiHeader.biBitCount = 24;
553 bmi.bmiHeader.biPlanes = 1;
554 bmi.bmiHeader.biCompression = BI_RGB;
556 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
557 ok(hbm != NULL, "CreateDIBSection failed\n");
559 bits[0] = 0;
561 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
562 expect(Ok, stat);
563 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
564 expectf(WIDTH1, width);
565 expectf(HEIGHT1, height);
566 if (stat == Ok)
568 /* test whether writing to the bitmap affects the original */
569 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
570 expect(Ok, stat);
572 expect(0, bits[0]);
574 GdipDisposeImage((GpImage*)gpbm);
577 LogPal = GdipAlloc(sizeof(LOGPALETTE));
578 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
579 LogPal->palVersion = 0x300;
580 LogPal->palNumEntries = 1;
581 hpal = CreatePalette(LogPal);
582 ok(hpal != NULL, "CreatePalette failed\n");
583 GdipFree(LogPal);
585 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
586 todo_wine
588 expect(Ok, stat);
590 if (stat == Ok)
591 GdipDisposeImage((GpImage*)gpbm);
593 DeleteObject(hpal);
594 DeleteObject(hbm);
597 static void test_GdipGetImageFlags(void)
599 GpImage *img;
600 GpStatus stat;
601 UINT flags;
603 img = (GpImage*)0xdeadbeef;
605 stat = GdipGetImageFlags(NULL, NULL);
606 expect(InvalidParameter, stat);
608 stat = GdipGetImageFlags(NULL, &flags);
609 expect(InvalidParameter, stat);
611 stat = GdipGetImageFlags(img, NULL);
612 expect(InvalidParameter, stat);
615 static void test_GdipCloneImage(void)
617 GpStatus stat;
618 GpRectF rectF;
619 GpUnit unit;
620 GpBitmap *bm;
621 GpImage *image_src, *image_dest = NULL;
622 const INT WIDTH = 10, HEIGHT = 20;
624 /* Create an image, clone it, delete the original, make sure the copy works */
625 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
626 expect(Ok, stat);
627 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
629 image_src = ((GpImage*)bm);
630 stat = GdipCloneImage(image_src, &image_dest);
631 expect(Ok, stat);
632 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
634 stat = GdipDisposeImage((GpImage*)bm);
635 expect(Ok, stat);
636 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
637 expect(Ok, stat);
639 /* Treat FP values carefully */
640 expectf((REAL)WIDTH, rectF.Width);
641 expectf((REAL)HEIGHT, rectF.Height);
643 stat = GdipDisposeImage(image_dest);
644 expect(Ok, stat);
647 static void test_testcontrol(void)
649 GpStatus stat;
650 DWORD param;
652 param = 0;
653 stat = GdipTestControl(TestControlGetBuildNumber, &param);
654 expect(Ok, stat);
655 ok(param != 0, "Build number expected, got %u\n", param);
658 static void test_fromhicon(void)
660 static const BYTE bmp_bits[1024];
661 HBITMAP hbmMask, hbmColor;
662 ICONINFO info;
663 HICON hIcon;
664 GpStatus stat;
665 GpBitmap *bitmap = NULL;
666 UINT dim;
667 ImageType type;
668 PixelFormat format;
670 /* NULL */
671 stat = GdipCreateBitmapFromHICON(NULL, NULL);
672 expect(InvalidParameter, stat);
673 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
674 expect(InvalidParameter, stat);
676 /* color icon 1 bit */
677 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
678 ok(hbmMask != 0, "CreateBitmap failed\n");
679 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
680 ok(hbmColor != 0, "CreateBitmap failed\n");
681 info.fIcon = TRUE;
682 info.xHotspot = 8;
683 info.yHotspot = 8;
684 info.hbmMask = hbmMask;
685 info.hbmColor = hbmColor;
686 hIcon = CreateIconIndirect(&info);
687 ok(hIcon != 0, "CreateIconIndirect failed\n");
688 DeleteObject(hbmMask);
689 DeleteObject(hbmColor);
691 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
692 ok(stat == Ok ||
693 broken(stat == InvalidParameter), /* Win98 */
694 "Expected Ok, got %.8x\n", stat);
695 if(stat == Ok){
696 /* check attributes */
697 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
698 expect(Ok, stat);
699 expect(16, dim);
700 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
701 expect(Ok, stat);
702 expect(16, dim);
703 stat = GdipGetImageType((GpImage*)bitmap, &type);
704 expect(Ok, stat);
705 expect(ImageTypeBitmap, type);
706 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
707 expect(PixelFormat32bppARGB, format);
708 /* raw format */
709 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
710 GdipDisposeImage((GpImage*)bitmap);
712 DestroyIcon(hIcon);
714 /* color icon 8 bpp */
715 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
716 ok(hbmMask != 0, "CreateBitmap failed\n");
717 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
718 ok(hbmColor != 0, "CreateBitmap failed\n");
719 info.fIcon = TRUE;
720 info.xHotspot = 8;
721 info.yHotspot = 8;
722 info.hbmMask = hbmMask;
723 info.hbmColor = hbmColor;
724 hIcon = CreateIconIndirect(&info);
725 ok(hIcon != 0, "CreateIconIndirect failed\n");
726 DeleteObject(hbmMask);
727 DeleteObject(hbmColor);
729 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
730 expect(Ok, stat);
731 if(stat == Ok){
732 /* check attributes */
733 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
734 expect(Ok, stat);
735 expect(16, dim);
736 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
737 expect(Ok, stat);
738 expect(16, dim);
739 stat = GdipGetImageType((GpImage*)bitmap, &type);
740 expect(Ok, stat);
741 expect(ImageTypeBitmap, type);
742 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
743 expect(PixelFormat32bppARGB, format);
744 /* raw format */
745 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
746 GdipDisposeImage((GpImage*)bitmap);
748 DestroyIcon(hIcon);
751 /* 1x1 pixel png */
752 static const unsigned char pngimage[285] = {
753 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
754 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
755 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
756 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
757 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
758 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
759 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
761 /* 1x1 pixel gif */
762 static const unsigned char gifimage[35] = {
763 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
764 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
765 0x01,0x00,0x3b
767 /* 1x1 pixel bmp */
768 static const unsigned char bmpimage[66] = {
769 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
770 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
771 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
772 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
773 0x00,0x00
775 /* 1x1 pixel jpg */
776 static const unsigned char jpgimage[285] = {
777 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
778 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
779 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
780 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
781 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
782 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
783 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
784 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
785 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
786 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
787 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
788 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
789 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
790 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
791 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
792 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
793 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
794 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
796 /* 320x320 twip wmf */
797 static const unsigned char wmfimage[180] = {
798 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
799 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
800 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
801 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
802 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
803 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
804 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
805 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
806 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
807 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
808 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
809 0x00,0x00,0x00,0x00
811 static void test_getrawformat(void)
813 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
814 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
815 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
816 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
817 test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
820 static void test_loadwmf(void)
822 LPSTREAM stream;
823 HGLOBAL hglob;
824 LPBYTE data;
825 HRESULT hres;
826 GpStatus stat;
827 GpImage *img;
828 GpRectF bounds;
829 GpUnit unit;
830 REAL res = 12345.0;
832 hglob = GlobalAlloc (0, sizeof(wmfimage));
833 data = GlobalLock (hglob);
834 memcpy(data, wmfimage, sizeof(wmfimage));
835 GlobalUnlock(hglob); data = NULL;
837 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
838 ok(hres == S_OK, "Failed to create a stream\n");
839 if(hres != S_OK) return;
841 stat = GdipLoadImageFromStream(stream, &img);
842 ok(stat == Ok, "Failed to create a Bitmap\n");
843 if(stat != Ok){
844 IStream_Release(stream);
845 return;
848 IStream_Release(stream);
850 stat = GdipGetImageBounds(img, &bounds, &unit);
851 expect(Ok, stat);
852 todo_wine expect(UnitPixel, unit);
853 expectf(0.0, bounds.X);
854 expectf(0.0, bounds.Y);
855 todo_wine expectf(320.0, bounds.Width);
856 todo_wine expectf(320.0, bounds.Height);
858 stat = GdipGetImageHorizontalResolution(img, &res);
859 expect(Ok, stat);
860 todo_wine expectf(1440.0, res);
862 stat = GdipGetImageVerticalResolution(img, &res);
863 expect(Ok, stat);
864 todo_wine expectf(1440.0, res);
866 GdipDisposeImage(img);
869 static void test_createfromwmf(void)
871 HMETAFILE hwmf;
872 GpImage *img;
873 GpStatus stat;
874 GpRectF bounds;
875 GpUnit unit;
876 REAL res = 12345.0;
878 hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
879 wmfimage+sizeof(WmfPlaceableFileHeader));
880 ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
882 stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
883 (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
884 expect(Ok, stat);
886 stat = GdipGetImageBounds(img, &bounds, &unit);
887 expect(Ok, stat);
888 todo_wine expect(UnitPixel, unit);
889 expectf(0.0, bounds.X);
890 expectf(0.0, bounds.Y);
891 todo_wine expectf(320.0, bounds.Width);
892 todo_wine expectf(320.0, bounds.Height);
894 stat = GdipGetImageHorizontalResolution(img, &res);
895 expect(Ok, stat);
896 expectf(1440.0, res);
898 stat = GdipGetImageVerticalResolution(img, &res);
899 expect(Ok, stat);
900 expectf(1440.0, res);
902 GdipDisposeImage(img);
905 static void test_resolution(void)
907 GpStatus stat;
908 GpBitmap *bitmap;
909 REAL res=-1.0;
910 HDC screendc;
911 int screenxres, screenyres;
913 /* create Bitmap */
914 stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
915 expect(Ok, stat);
917 /* test invalid values */
918 stat = GdipGetImageHorizontalResolution(NULL, &res);
919 expect(InvalidParameter, stat);
921 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
922 expect(InvalidParameter, stat);
924 stat = GdipGetImageVerticalResolution(NULL, &res);
925 expect(InvalidParameter, stat);
927 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
928 expect(InvalidParameter, stat);
930 stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
931 expect(InvalidParameter, stat);
933 stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
934 expect(InvalidParameter, stat);
936 /* defaults to screen resolution */
937 screendc = GetDC(0);
939 screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
940 screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
942 ReleaseDC(0, screendc);
944 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
945 expect(Ok, stat);
946 expectf((REAL)screenxres, res);
948 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
949 expect(Ok, stat);
950 expectf((REAL)screenyres, res);
952 /* test changing the resolution */
953 stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
954 expect(Ok, stat);
956 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
957 expect(Ok, stat);
958 expectf(screenxres*2.0, res);
960 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
961 expect(Ok, stat);
962 expectf(screenyres*3.0, res);
964 stat = GdipDisposeImage((GpImage*)bitmap);
965 expect(Ok, stat);
968 static void test_createhbitmap(void)
970 GpStatus stat;
971 GpBitmap *bitmap;
972 HBITMAP hbitmap, oldhbitmap;
973 BITMAP bm;
974 int ret;
975 HDC hdc;
976 COLORREF pixel;
977 BYTE bits[640];
979 memset(bits, 0x68, 640);
981 /* create Bitmap */
982 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
983 expect(Ok, stat);
985 /* test NULL values */
986 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
987 expect(InvalidParameter, stat);
989 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
990 expect(InvalidParameter, stat);
992 /* create HBITMAP */
993 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
994 expect(Ok, stat);
996 if (stat == Ok)
998 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
999 expect(sizeof(BITMAP), ret);
1001 expect(0, bm.bmType);
1002 expect(10, bm.bmWidth);
1003 expect(20, bm.bmHeight);
1004 expect(40, bm.bmWidthBytes);
1005 expect(1, bm.bmPlanes);
1006 expect(32, bm.bmBitsPixel);
1007 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1009 hdc = CreateCompatibleDC(NULL);
1011 oldhbitmap = SelectObject(hdc, hbitmap);
1012 pixel = GetPixel(hdc, 5, 5);
1013 SelectObject(hdc, oldhbitmap);
1015 DeleteDC(hdc);
1017 expect(0x686868, pixel);
1019 DeleteObject(hbitmap);
1022 stat = GdipDisposeImage((GpImage*)bitmap);
1023 expect(Ok, stat);
1026 static void test_getsetpixel(void)
1028 GpStatus stat;
1029 GpBitmap *bitmap;
1030 ARGB color;
1031 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1032 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1034 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1035 expect(Ok, stat);
1037 /* null parameters */
1038 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1039 expect(InvalidParameter, stat);
1041 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1042 expect(InvalidParameter, stat);
1044 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1045 expect(InvalidParameter, stat);
1047 /* out of bounds */
1048 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1049 expect(InvalidParameter, stat);
1051 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1052 expect(InvalidParameter, stat);
1054 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1055 ok(stat == InvalidParameter ||
1056 broken(stat == Ok), /* Older gdiplus */
1057 "Expected InvalidParameter, got %.8x\n", stat);
1059 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1060 ok(stat == InvalidParameter ||
1061 broken(stat == Ok), /* Older gdiplus */
1062 "Expected InvalidParameter, got %.8x\n", stat);
1064 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1065 expect(InvalidParameter, stat);
1067 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1068 expect(InvalidParameter, stat);
1070 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1071 expect(InvalidParameter, stat);
1073 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1074 expect(InvalidParameter, stat);
1076 /* valid use */
1077 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1078 expect(Ok, stat);
1079 expect(0xffffffff, color);
1081 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1082 expect(Ok, stat);
1083 expect(0xff0000ff, color);
1085 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1086 expect(Ok, stat);
1088 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1089 expect(Ok, stat);
1091 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1092 expect(Ok, stat);
1093 expect(0xff676869, color);
1095 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1096 expect(Ok, stat);
1097 expect(0xff474849, color);
1099 stat = GdipDisposeImage((GpImage*)bitmap);
1100 expect(Ok, stat);
1103 static void check_halftone_palette(ColorPalette *palette)
1105 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1106 UINT i;
1108 for (i=0; i<palette->Count; i++)
1110 ARGB expected=0xff000000;
1111 if (i<8)
1113 if (i&1) expected |= 0x800000;
1114 if (i&2) expected |= 0x8000;
1115 if (i&4) expected |= 0x80;
1117 else if (i == 8)
1119 expected = 0xffc0c0c0;
1121 else if (i < 16)
1123 if (i&1) expected |= 0xff0000;
1124 if (i&2) expected |= 0xff00;
1125 if (i&4) expected |= 0xff;
1127 else if (i < 40)
1129 expected = 0x00000000;
1131 else
1133 expected |= halftone_values[(i-40)%6];
1134 expected |= halftone_values[((i-40)/6)%6] << 8;
1135 expected |= halftone_values[((i-40)/36)%6] << 16;
1137 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1138 expected, palette->Entries[i], i, palette->Count);
1142 static void test_palette(void)
1144 GpStatus stat;
1145 GpBitmap *bitmap;
1146 INT size;
1147 BYTE buffer[1040];
1148 ColorPalette *palette=(ColorPalette*)buffer;
1149 ARGB color=0;
1151 /* test initial palette from non-indexed bitmap */
1152 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1153 expect(Ok, stat);
1155 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1156 expect(Ok, stat);
1157 expect(sizeof(UINT)*2+sizeof(ARGB), size);
1159 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1160 expect(Ok, stat);
1161 expect(0, palette->Count);
1163 /* test setting palette on not-indexed bitmap */
1164 palette->Count = 3;
1166 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1167 expect(Ok, stat);
1169 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1170 expect(Ok, stat);
1171 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1173 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1174 expect(Ok, stat);
1175 expect(3, palette->Count);
1177 GdipDisposeImage((GpImage*)bitmap);
1179 /* test initial palette on 1-bit bitmap */
1180 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1181 expect(Ok, stat);
1183 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1184 expect(Ok, stat);
1185 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1187 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1188 expect(Ok, stat);
1189 expect(PaletteFlagsGrayScale, palette->Flags);
1190 expect(2, palette->Count);
1192 expect(0xff000000, palette->Entries[0]);
1193 expect(0xffffffff, palette->Entries[1]);
1195 /* test getting/setting pixels */
1196 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1197 expect(Ok, stat);
1198 expect(0xff000000, color);
1200 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1201 todo_wine ok((stat == Ok) ||
1202 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1204 if (stat == Ok)
1206 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1207 expect(Ok, stat);
1208 expect(0xffffffff, color);
1211 GdipDisposeImage((GpImage*)bitmap);
1213 /* test initial palette on 4-bit bitmap */
1214 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1215 expect(Ok, stat);
1217 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1218 expect(Ok, stat);
1219 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1221 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1222 expect(Ok, stat);
1223 expect(0, palette->Flags);
1224 expect(16, palette->Count);
1226 check_halftone_palette(palette);
1228 /* test getting/setting pixels */
1229 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1230 expect(Ok, stat);
1231 expect(0xff000000, color);
1233 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
1234 todo_wine ok((stat == Ok) ||
1235 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1237 if (stat == Ok)
1239 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1240 expect(Ok, stat);
1241 expect(0xffff00ff, color);
1244 GdipDisposeImage((GpImage*)bitmap);
1246 /* test initial palette on 8-bit bitmap */
1247 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1248 expect(Ok, stat);
1250 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1251 expect(Ok, stat);
1252 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1254 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1255 expect(Ok, stat);
1256 expect(PaletteFlagsHalftone, palette->Flags);
1257 expect(256, palette->Count);
1259 check_halftone_palette(palette);
1261 /* test getting/setting pixels */
1262 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1263 expect(Ok, stat);
1264 expect(0xff000000, color);
1266 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
1267 todo_wine ok((stat == Ok) ||
1268 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1270 if (stat == Ok)
1272 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1273 expect(Ok, stat);
1274 expect(0xffcccccc, color);
1277 /* test setting/getting a different palette */
1278 palette->Entries[1] = 0xffcccccc;
1280 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1281 expect(Ok, stat);
1283 palette->Entries[1] = 0;
1285 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1286 expect(Ok, stat);
1287 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1289 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1290 expect(Ok, stat);
1291 expect(PaletteFlagsHalftone, palette->Flags);
1292 expect(256, palette->Count);
1293 expect(0xffcccccc, palette->Entries[1]);
1295 /* test count < 256 */
1296 palette->Flags = 12345;
1297 palette->Count = 3;
1299 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1300 expect(Ok, stat);
1302 palette->Entries[1] = 0;
1303 palette->Entries[3] = 0xdeadbeef;
1305 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1306 expect(Ok, stat);
1307 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1309 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1310 expect(Ok, stat);
1311 expect(12345, palette->Flags);
1312 expect(3, palette->Count);
1313 expect(0xffcccccc, palette->Entries[1]);
1314 expect(0xdeadbeef, palette->Entries[3]);
1316 /* test count > 256 */
1317 palette->Count = 257;
1319 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1320 ok(stat == InvalidParameter ||
1321 broken(stat == Ok), /* Old gdiplus behavior */
1322 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1324 GdipDisposeImage((GpImage*)bitmap);
1327 static void test_colormatrix(void)
1329 GpStatus stat;
1330 ColorMatrix colormatrix, graymatrix;
1331 GpImageAttributes *imageattr;
1332 const ColorMatrix identity = {{
1333 {1.0,0.0,0.0,0.0,0.0},
1334 {0.0,1.0,0.0,0.0,0.0},
1335 {0.0,0.0,1.0,0.0,0.0},
1336 {0.0,0.0,0.0,1.0,0.0},
1337 {0.0,0.0,0.0,0.0,1.0}}};
1338 const ColorMatrix double_red = {{
1339 {2.0,0.0,0.0,0.0,0.0},
1340 {0.0,1.0,0.0,0.0,0.0},
1341 {0.0,0.0,1.0,0.0,0.0},
1342 {0.0,0.0,0.0,1.0,0.0},
1343 {0.0,0.0,0.0,0.0,1.0}}};
1344 GpBitmap *bitmap1, *bitmap2;
1345 GpGraphics *graphics;
1346 ARGB color;
1348 colormatrix = identity;
1349 graymatrix = identity;
1351 stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
1352 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1353 expect(InvalidParameter, stat);
1355 stat = GdipCreateImageAttributes(&imageattr);
1356 expect(Ok, stat);
1358 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1359 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1360 expect(Ok, stat);
1362 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1363 TRUE, NULL, NULL, ColorMatrixFlagsDefault);
1364 expect(InvalidParameter, stat);
1366 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1367 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1368 expect(Ok, stat);
1370 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1371 TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
1372 expect(Ok, stat);
1374 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1375 TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
1376 expect(InvalidParameter, stat);
1378 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1379 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
1380 expect(Ok, stat);
1382 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1383 TRUE, &colormatrix, &graymatrix, 3);
1384 expect(InvalidParameter, stat);
1386 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
1387 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1388 expect(InvalidParameter, stat);
1390 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
1391 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1392 expect(InvalidParameter, stat);
1394 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1395 FALSE, NULL, NULL, ColorMatrixFlagsDefault);
1396 expect(Ok, stat);
1398 /* Drawing a bitmap transforms the colors */
1399 colormatrix = double_red;
1400 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1401 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1402 expect(Ok, stat);
1404 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1405 expect(Ok, stat);
1407 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1408 expect(Ok, stat);
1410 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ffff);
1411 expect(Ok, stat);
1413 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1414 expect(Ok, stat);
1416 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1417 UnitPixel, imageattr, NULL, NULL);
1418 expect(Ok, stat);
1420 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1421 expect(Ok, stat);
1422 todo_wine expect(0xff80ffff, color);
1424 GdipDeleteGraphics(graphics);
1425 GdipDisposeImage((GpImage*)bitmap1);
1426 GdipDisposeImage((GpImage*)bitmap2);
1427 GdipDisposeImageAttributes(imageattr);
1430 static void test_gamma(void)
1432 GpStatus stat;
1433 GpImageAttributes *imageattr;
1434 GpBitmap *bitmap1, *bitmap2;
1435 GpGraphics *graphics;
1436 ARGB color;
1438 stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
1439 expect(InvalidParameter, stat);
1441 stat = GdipCreateImageAttributes(&imageattr);
1442 expect(Ok, stat);
1444 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
1445 expect(Ok, stat);
1447 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
1448 expect(InvalidParameter, stat);
1450 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
1451 expect(InvalidParameter, stat);
1453 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
1454 expect(InvalidParameter, stat);
1456 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
1457 expect(Ok, stat);
1459 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
1460 expect(Ok, stat);
1462 /* Drawing a bitmap transforms the colors */
1463 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
1464 expect(Ok, stat);
1466 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1467 expect(Ok, stat);
1469 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1470 expect(Ok, stat);
1472 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
1473 expect(Ok, stat);
1475 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1476 expect(Ok, stat);
1478 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1479 UnitPixel, imageattr, NULL, NULL);
1480 expect(Ok, stat);
1482 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1483 expect(Ok, stat);
1484 todo_wine ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
1486 GdipDeleteGraphics(graphics);
1487 GdipDisposeImage((GpImage*)bitmap1);
1488 GdipDisposeImage((GpImage*)bitmap2);
1489 GdipDisposeImageAttributes(imageattr);
1492 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
1493 static const unsigned char gifanimation[72] = {
1494 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1495 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
1496 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
1497 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
1498 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
1501 static void test_multiframegif(void)
1503 LPSTREAM stream;
1504 HGLOBAL hglob;
1505 LPBYTE data;
1506 HRESULT hres;
1507 GpStatus stat;
1508 GpBitmap *bmp;
1509 ARGB color;
1510 UINT count;
1511 GUID dimension;
1513 /* Test frame functions with an animated GIF */
1514 hglob = GlobalAlloc (0, sizeof(gifanimation));
1515 data = GlobalLock (hglob);
1516 memcpy(data, gifanimation, sizeof(gifanimation));
1517 GlobalUnlock(hglob);
1519 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1520 ok(hres == S_OK, "Failed to create a stream\n");
1521 if(hres != S_OK) return;
1523 stat = GdipCreateBitmapFromStream(stream, &bmp);
1524 ok(stat == Ok, "Failed to create a Bitmap\n");
1525 if(stat != Ok){
1526 IStream_Release(stream);
1527 return;
1530 /* Bitmap starts at frame 0 */
1531 color = 0xdeadbeef;
1532 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1533 expect(Ok, stat);
1534 expect(0xffffffff, color);
1536 /* Check that we get correct metadata */
1537 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1538 expect(Ok, stat);
1539 expect(1, count);
1541 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1542 expect(Ok, stat);
1543 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1545 count = 12345;
1546 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1547 todo_wine expect(Ok, stat);
1548 todo_wine expect(2, count);
1550 /* SelectActiveFrame overwrites our current data */
1551 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1552 expect(Ok, stat);
1554 color = 0xdeadbeef;
1555 GdipBitmapGetPixel(bmp, 0, 0, &color);
1556 expect(Ok, stat);
1557 todo_wine expect(0xff000000, color);
1559 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1560 expect(Ok, stat);
1562 color = 0xdeadbeef;
1563 GdipBitmapGetPixel(bmp, 0, 0, &color);
1564 expect(Ok, stat);
1565 expect(0xffffffff, color);
1567 /* Write over the image data */
1568 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
1569 expect(Ok, stat);
1571 /* Switching to the same frame does not overwrite our changes */
1572 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1573 expect(Ok, stat);
1575 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1576 expect(Ok, stat);
1577 expect(0xff000000, color);
1579 /* But switching to another frame and back does */
1580 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1581 expect(Ok, stat);
1583 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1584 expect(Ok, stat);
1586 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1587 expect(Ok, stat);
1588 todo_wine expect(0xffffffff, color);
1590 GdipDisposeImage((GpImage*)bmp);
1591 IStream_Release(stream);
1593 /* Test with a non-animated gif */
1594 hglob = GlobalAlloc (0, sizeof(gifimage));
1595 data = GlobalLock (hglob);
1596 memcpy(data, gifimage, sizeof(gifimage));
1597 GlobalUnlock(hglob);
1599 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1600 ok(hres == S_OK, "Failed to create a stream\n");
1601 if(hres != S_OK) return;
1603 stat = GdipCreateBitmapFromStream(stream, &bmp);
1604 ok(stat == Ok, "Failed to create a Bitmap\n");
1605 if(stat != Ok){
1606 IStream_Release(stream);
1607 return;
1610 /* Check metadata */
1611 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1612 expect(Ok, stat);
1613 expect(1, count);
1615 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1616 expect(Ok, stat);
1617 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1619 count = 12345;
1620 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1621 todo_wine expect(Ok, stat);
1622 todo_wine expect(1, count);
1624 GdipDisposeImage((GpImage*)bmp);
1625 IStream_Release(stream);
1628 static void test_rotateflip(void)
1630 GpImage *bitmap;
1631 GpStatus stat;
1632 BYTE bits[24];
1633 static const BYTE orig_bits[24] = {
1634 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
1635 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
1636 UINT width, height;
1637 ARGB color;
1639 memcpy(bits, orig_bits, sizeof(bits));
1640 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1641 expect(Ok, stat);
1643 stat = GdipImageRotateFlip(bitmap, Rotate90FlipNone);
1644 todo_wine expect(Ok, stat);
1646 stat = GdipGetImageWidth(bitmap, &width);
1647 expect(Ok, stat);
1648 stat = GdipGetImageHeight(bitmap, &height);
1649 expect(Ok, stat);
1650 todo_wine expect(2, width);
1651 todo_wine expect(3, height);
1653 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1654 expect(Ok, stat);
1655 todo_wine expect(0xff00ffff, color);
1657 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 0, &color);
1658 expect(Ok, stat);
1659 todo_wine expect(0xffff0000, color);
1661 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 2, &color);
1662 todo_wine expect(Ok, stat);
1663 todo_wine expect(0xffffff00, color);
1665 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 2, &color);
1666 todo_wine expect(Ok, stat);
1667 todo_wine expect(0xff0000ff, color);
1669 expect(0, bits[0]);
1670 expect(0, bits[1]);
1671 expect(0xff, bits[2]);
1673 GdipDisposeImage(bitmap);
1675 memcpy(bits, orig_bits, sizeof(bits));
1676 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1677 expect(Ok, stat);
1679 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipX);
1680 todo_wine expect(Ok, stat);
1682 stat = GdipGetImageWidth(bitmap, &width);
1683 expect(Ok, stat);
1684 stat = GdipGetImageHeight(bitmap, &height);
1685 expect(Ok, stat);
1686 expect(3, width);
1687 expect(2, height);
1689 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1690 expect(Ok, stat);
1691 todo_wine expect(0xff0000ff, color);
1693 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
1694 expect(Ok, stat);
1695 todo_wine expect(0xffff0000, color);
1697 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
1698 expect(Ok, stat);
1699 todo_wine expect(0xffffff00, color);
1701 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
1702 expect(Ok, stat);
1703 todo_wine expect(0xff00ffff, color);
1705 expect(0, bits[0]);
1706 expect(0, bits[1]);
1707 expect(0xff, bits[2]);
1709 GdipDisposeImage(bitmap);
1711 memcpy(bits, orig_bits, sizeof(bits));
1712 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1713 expect(Ok, stat);
1715 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipY);
1716 todo_wine expect(Ok, stat);
1718 stat = GdipGetImageWidth(bitmap, &width);
1719 expect(Ok, stat);
1720 stat = GdipGetImageHeight(bitmap, &height);
1721 expect(Ok, stat);
1722 expect(3, width);
1723 expect(2, height);
1725 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1726 expect(Ok, stat);
1727 todo_wine expect(0xff00ffff, color);
1729 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
1730 expect(Ok, stat);
1731 todo_wine expect(0xffffff00, color);
1733 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
1734 expect(Ok, stat);
1735 todo_wine expect(0xffff0000, color);
1737 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
1738 expect(Ok, stat);
1739 todo_wine expect(0xff0000ff, color);
1741 expect(0, bits[0]);
1742 expect(0, bits[1]);
1743 expect(0xff, bits[2]);
1745 GdipDisposeImage(bitmap);
1748 static void test_remaptable(void)
1750 GpStatus stat;
1751 GpImageAttributes *imageattr;
1752 GpBitmap *bitmap1, *bitmap2;
1753 GpGraphics *graphics;
1754 ARGB color;
1755 ColorMap *map;
1757 map = GdipAlloc(sizeof(ColorMap));
1759 map->oldColor.Argb = 0xff00ff00;
1760 map->newColor.Argb = 0xffff00ff;
1762 stat = GdipSetImageAttributesRemapTable(NULL, ColorAdjustTypeDefault, TRUE, 1, map);
1763 expect(InvalidParameter, stat);
1765 stat = GdipCreateImageAttributes(&imageattr);
1766 expect(Ok, stat);
1768 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, NULL);
1769 expect(InvalidParameter, stat);
1771 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeCount, TRUE, 1, map);
1772 expect(InvalidParameter, stat);
1774 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeAny, TRUE, 1, map);
1775 expect(InvalidParameter, stat);
1777 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 0, map);
1778 expect(InvalidParameter, stat);
1780 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, FALSE, 0, NULL);
1781 expect(Ok, stat);
1783 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, map);
1784 expect(Ok, stat);
1786 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1787 expect(Ok, stat);
1789 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1790 expect(Ok, stat);
1792 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff00ff00);
1793 expect(Ok, stat);
1795 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1796 expect(Ok, stat);
1798 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1799 UnitPixel, imageattr, NULL, NULL);
1800 expect(Ok, stat);
1802 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1803 expect(Ok, stat);
1804 todo_wine ok(color_match(0xffff00ff, color, 1), "Expected ffff00ff, got %.8x\n", color);
1806 GdipDeleteGraphics(graphics);
1807 GdipDisposeImage((GpImage*)bitmap1);
1808 GdipDisposeImage((GpImage*)bitmap2);
1809 GdipDisposeImageAttributes(imageattr);
1810 GdipFree(map);
1813 START_TEST(image)
1815 struct GdiplusStartupInput gdiplusStartupInput;
1816 ULONG_PTR gdiplusToken;
1818 gdiplusStartupInput.GdiplusVersion = 1;
1819 gdiplusStartupInput.DebugEventCallback = NULL;
1820 gdiplusStartupInput.SuppressBackgroundThread = 0;
1821 gdiplusStartupInput.SuppressExternalCodecs = 0;
1823 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1825 test_Scan0();
1826 test_GetImageDimension();
1827 test_GdipImageGetFrameDimensionsCount();
1828 test_LoadingImages();
1829 test_SavingImages();
1830 test_encoders();
1831 test_LockBits();
1832 test_GdipCreateBitmapFromHBITMAP();
1833 test_GdipGetImageFlags();
1834 test_GdipCloneImage();
1835 test_testcontrol();
1836 test_fromhicon();
1837 test_getrawformat();
1838 test_loadwmf();
1839 test_createfromwmf();
1840 test_resolution();
1841 test_createhbitmap();
1842 test_getsetpixel();
1843 test_palette();
1844 test_colormatrix();
1845 test_gamma();
1846 test_multiframegif();
1847 test_rotateflip();
1848 test_remaptable();
1850 GdiplusShutdown(gdiplusToken);