shlwapi: Don't cast WCHAR string to BSTR.
[wine/testsucceed.git] / dlls / gdiplus / tests / image.c
blob2810b51711abe083c626aaba512d9da36bfa9004
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;
831 MetafileHeader header;
833 hglob = GlobalAlloc (0, sizeof(wmfimage));
834 data = GlobalLock (hglob);
835 memcpy(data, wmfimage, sizeof(wmfimage));
836 GlobalUnlock(hglob); data = NULL;
838 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
839 ok(hres == S_OK, "Failed to create a stream\n");
840 if(hres != S_OK) return;
842 stat = GdipLoadImageFromStream(stream, &img);
843 ok(stat == Ok, "Failed to create a Bitmap\n");
844 if(stat != Ok){
845 IStream_Release(stream);
846 return;
849 IStream_Release(stream);
851 stat = GdipGetImageBounds(img, &bounds, &unit);
852 expect(Ok, stat);
853 todo_wine expect(UnitPixel, unit);
854 expectf(0.0, bounds.X);
855 expectf(0.0, bounds.Y);
856 todo_wine expectf(320.0, bounds.Width);
857 todo_wine expectf(320.0, bounds.Height);
859 stat = GdipGetImageHorizontalResolution(img, &res);
860 expect(Ok, stat);
861 todo_wine expectf(1440.0, res);
863 stat = GdipGetImageVerticalResolution(img, &res);
864 expect(Ok, stat);
865 todo_wine expectf(1440.0, res);
867 memset(&header, 0, sizeof(header));
868 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
869 expect(Ok, stat);
870 if (stat == Ok)
872 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
873 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
874 todo_wine expect(0x300, header.Version);
875 expect(0, header.EmfPlusFlags);
876 todo_wine expectf(1440.0, header.DpiX);
877 todo_wine expectf(1440.0, header.DpiY);
878 expect(0, header.X);
879 expect(0, header.Y);
880 todo_wine expect(320, header.Width);
881 todo_wine expect(320, header.Height);
882 todo_wine expect(1, header.WmfHeader.mtType);
883 expect(0, header.EmfPlusHeaderSize);
884 expect(0, header.LogicalDpiX);
885 expect(0, header.LogicalDpiY);
888 GdipDisposeImage(img);
891 static void test_createfromwmf(void)
893 HMETAFILE hwmf;
894 GpImage *img;
895 GpStatus stat;
896 GpRectF bounds;
897 GpUnit unit;
898 REAL res = 12345.0;
899 MetafileHeader header;
901 hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
902 wmfimage+sizeof(WmfPlaceableFileHeader));
903 ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
905 stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
906 (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
907 expect(Ok, stat);
909 stat = GdipGetImageBounds(img, &bounds, &unit);
910 expect(Ok, stat);
911 todo_wine expect(UnitPixel, unit);
912 expectf(0.0, bounds.X);
913 expectf(0.0, bounds.Y);
914 todo_wine expectf(320.0, bounds.Width);
915 todo_wine expectf(320.0, bounds.Height);
917 stat = GdipGetImageHorizontalResolution(img, &res);
918 expect(Ok, stat);
919 expectf(1440.0, res);
921 stat = GdipGetImageVerticalResolution(img, &res);
922 expect(Ok, stat);
923 expectf(1440.0, res);
925 memset(&header, 0, sizeof(header));
926 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
927 expect(Ok, stat);
928 if (stat == Ok)
930 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
931 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
932 todo_wine expect(0x300, header.Version);
933 expect(0, header.EmfPlusFlags);
934 todo_wine expectf(1440.0, header.DpiX);
935 todo_wine expectf(1440.0, header.DpiY);
936 expect(0, header.X);
937 expect(0, header.Y);
938 todo_wine expect(320, header.Width);
939 todo_wine expect(320, header.Height);
940 todo_wine expect(1, header.WmfHeader.mtType);
941 expect(0, header.EmfPlusHeaderSize);
942 expect(0, header.LogicalDpiX);
943 expect(0, header.LogicalDpiY);
946 GdipDisposeImage(img);
949 static void test_resolution(void)
951 GpStatus stat;
952 GpBitmap *bitmap;
953 REAL res=-1.0;
954 HDC screendc;
955 int screenxres, screenyres;
957 /* create Bitmap */
958 stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
959 expect(Ok, stat);
961 /* test invalid values */
962 stat = GdipGetImageHorizontalResolution(NULL, &res);
963 expect(InvalidParameter, stat);
965 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
966 expect(InvalidParameter, stat);
968 stat = GdipGetImageVerticalResolution(NULL, &res);
969 expect(InvalidParameter, stat);
971 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
972 expect(InvalidParameter, stat);
974 stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
975 expect(InvalidParameter, stat);
977 stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
978 expect(InvalidParameter, stat);
980 /* defaults to screen resolution */
981 screendc = GetDC(0);
983 screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
984 screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
986 ReleaseDC(0, screendc);
988 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
989 expect(Ok, stat);
990 expectf((REAL)screenxres, res);
992 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
993 expect(Ok, stat);
994 expectf((REAL)screenyres, res);
996 /* test changing the resolution */
997 stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
998 expect(Ok, stat);
1000 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1001 expect(Ok, stat);
1002 expectf(screenxres*2.0, res);
1004 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1005 expect(Ok, stat);
1006 expectf(screenyres*3.0, res);
1008 stat = GdipDisposeImage((GpImage*)bitmap);
1009 expect(Ok, stat);
1012 static void test_createhbitmap(void)
1014 GpStatus stat;
1015 GpBitmap *bitmap;
1016 HBITMAP hbitmap, oldhbitmap;
1017 BITMAP bm;
1018 int ret;
1019 HDC hdc;
1020 COLORREF pixel;
1021 BYTE bits[640];
1023 memset(bits, 0x68, 640);
1025 /* create Bitmap */
1026 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
1027 expect(Ok, stat);
1029 /* test NULL values */
1030 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
1031 expect(InvalidParameter, stat);
1033 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
1034 expect(InvalidParameter, stat);
1036 /* create HBITMAP */
1037 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
1038 expect(Ok, stat);
1040 if (stat == Ok)
1042 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
1043 expect(sizeof(BITMAP), ret);
1045 expect(0, bm.bmType);
1046 expect(10, bm.bmWidth);
1047 expect(20, bm.bmHeight);
1048 expect(40, bm.bmWidthBytes);
1049 expect(1, bm.bmPlanes);
1050 expect(32, bm.bmBitsPixel);
1051 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1053 hdc = CreateCompatibleDC(NULL);
1055 oldhbitmap = SelectObject(hdc, hbitmap);
1056 pixel = GetPixel(hdc, 5, 5);
1057 SelectObject(hdc, oldhbitmap);
1059 DeleteDC(hdc);
1061 expect(0x686868, pixel);
1063 DeleteObject(hbitmap);
1066 stat = GdipDisposeImage((GpImage*)bitmap);
1067 expect(Ok, stat);
1070 static void test_getsetpixel(void)
1072 GpStatus stat;
1073 GpBitmap *bitmap;
1074 ARGB color;
1075 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1076 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1078 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1079 expect(Ok, stat);
1081 /* null parameters */
1082 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1083 expect(InvalidParameter, stat);
1085 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1086 expect(InvalidParameter, stat);
1088 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1089 expect(InvalidParameter, stat);
1091 /* out of bounds */
1092 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1093 expect(InvalidParameter, stat);
1095 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1096 expect(InvalidParameter, stat);
1098 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1099 ok(stat == InvalidParameter ||
1100 broken(stat == Ok), /* Older gdiplus */
1101 "Expected InvalidParameter, got %.8x\n", stat);
1103 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1104 ok(stat == InvalidParameter ||
1105 broken(stat == Ok), /* Older gdiplus */
1106 "Expected InvalidParameter, got %.8x\n", stat);
1108 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1109 expect(InvalidParameter, stat);
1111 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1112 expect(InvalidParameter, stat);
1114 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1115 expect(InvalidParameter, stat);
1117 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1118 expect(InvalidParameter, stat);
1120 /* valid use */
1121 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1122 expect(Ok, stat);
1123 expect(0xffffffff, color);
1125 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1126 expect(Ok, stat);
1127 expect(0xff0000ff, color);
1129 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1130 expect(Ok, stat);
1132 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1133 expect(Ok, stat);
1135 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1136 expect(Ok, stat);
1137 expect(0xff676869, color);
1139 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1140 expect(Ok, stat);
1141 expect(0xff474849, color);
1143 stat = GdipDisposeImage((GpImage*)bitmap);
1144 expect(Ok, stat);
1147 static void check_halftone_palette(ColorPalette *palette)
1149 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1150 UINT i;
1152 for (i=0; i<palette->Count; i++)
1154 ARGB expected=0xff000000;
1155 if (i<8)
1157 if (i&1) expected |= 0x800000;
1158 if (i&2) expected |= 0x8000;
1159 if (i&4) expected |= 0x80;
1161 else if (i == 8)
1163 expected = 0xffc0c0c0;
1165 else if (i < 16)
1167 if (i&1) expected |= 0xff0000;
1168 if (i&2) expected |= 0xff00;
1169 if (i&4) expected |= 0xff;
1171 else if (i < 40)
1173 expected = 0x00000000;
1175 else
1177 expected |= halftone_values[(i-40)%6];
1178 expected |= halftone_values[((i-40)/6)%6] << 8;
1179 expected |= halftone_values[((i-40)/36)%6] << 16;
1181 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1182 expected, palette->Entries[i], i, palette->Count);
1186 static void test_palette(void)
1188 GpStatus stat;
1189 GpBitmap *bitmap;
1190 INT size;
1191 BYTE buffer[1040];
1192 ColorPalette *palette=(ColorPalette*)buffer;
1193 ARGB color=0;
1195 /* test initial palette from non-indexed bitmap */
1196 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1197 expect(Ok, stat);
1199 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1200 expect(Ok, stat);
1201 expect(sizeof(UINT)*2+sizeof(ARGB), size);
1203 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1204 expect(Ok, stat);
1205 expect(0, palette->Count);
1207 /* test setting palette on not-indexed bitmap */
1208 palette->Count = 3;
1210 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1211 expect(Ok, stat);
1213 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1214 expect(Ok, stat);
1215 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1217 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1218 expect(Ok, stat);
1219 expect(3, palette->Count);
1221 GdipDisposeImage((GpImage*)bitmap);
1223 /* test initial palette on 1-bit bitmap */
1224 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1225 expect(Ok, stat);
1227 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1228 expect(Ok, stat);
1229 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1231 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1232 expect(Ok, stat);
1233 expect(PaletteFlagsGrayScale, palette->Flags);
1234 expect(2, palette->Count);
1236 expect(0xff000000, palette->Entries[0]);
1237 expect(0xffffffff, palette->Entries[1]);
1239 /* test getting/setting pixels */
1240 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1241 expect(Ok, stat);
1242 expect(0xff000000, color);
1244 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1245 todo_wine ok((stat == Ok) ||
1246 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1248 if (stat == Ok)
1250 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1251 expect(Ok, stat);
1252 expect(0xffffffff, color);
1255 GdipDisposeImage((GpImage*)bitmap);
1257 /* test initial palette on 4-bit bitmap */
1258 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1259 expect(Ok, stat);
1261 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1262 expect(Ok, stat);
1263 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1265 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1266 expect(Ok, stat);
1267 expect(0, palette->Flags);
1268 expect(16, palette->Count);
1270 check_halftone_palette(palette);
1272 /* test getting/setting pixels */
1273 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1274 expect(Ok, stat);
1275 expect(0xff000000, color);
1277 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
1278 todo_wine ok((stat == Ok) ||
1279 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1281 if (stat == Ok)
1283 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1284 expect(Ok, stat);
1285 expect(0xffff00ff, color);
1288 GdipDisposeImage((GpImage*)bitmap);
1290 /* test initial palette on 8-bit bitmap */
1291 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1292 expect(Ok, stat);
1294 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1295 expect(Ok, stat);
1296 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1298 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1299 expect(Ok, stat);
1300 expect(PaletteFlagsHalftone, palette->Flags);
1301 expect(256, palette->Count);
1303 check_halftone_palette(palette);
1305 /* test getting/setting pixels */
1306 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1307 expect(Ok, stat);
1308 expect(0xff000000, color);
1310 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
1311 todo_wine ok((stat == Ok) ||
1312 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1314 if (stat == Ok)
1316 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1317 expect(Ok, stat);
1318 expect(0xffcccccc, color);
1321 /* test setting/getting a different palette */
1322 palette->Entries[1] = 0xffcccccc;
1324 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1325 expect(Ok, stat);
1327 palette->Entries[1] = 0;
1329 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1330 expect(Ok, stat);
1331 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1333 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1334 expect(Ok, stat);
1335 expect(PaletteFlagsHalftone, palette->Flags);
1336 expect(256, palette->Count);
1337 expect(0xffcccccc, palette->Entries[1]);
1339 /* test count < 256 */
1340 palette->Flags = 12345;
1341 palette->Count = 3;
1343 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1344 expect(Ok, stat);
1346 palette->Entries[1] = 0;
1347 palette->Entries[3] = 0xdeadbeef;
1349 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1350 expect(Ok, stat);
1351 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1353 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1354 expect(Ok, stat);
1355 expect(12345, palette->Flags);
1356 expect(3, palette->Count);
1357 expect(0xffcccccc, palette->Entries[1]);
1358 expect(0xdeadbeef, palette->Entries[3]);
1360 /* test count > 256 */
1361 palette->Count = 257;
1363 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1364 ok(stat == InvalidParameter ||
1365 broken(stat == Ok), /* Old gdiplus behavior */
1366 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1368 GdipDisposeImage((GpImage*)bitmap);
1371 static void test_colormatrix(void)
1373 GpStatus stat;
1374 ColorMatrix colormatrix, graymatrix;
1375 GpImageAttributes *imageattr;
1376 const ColorMatrix identity = {{
1377 {1.0,0.0,0.0,0.0,0.0},
1378 {0.0,1.0,0.0,0.0,0.0},
1379 {0.0,0.0,1.0,0.0,0.0},
1380 {0.0,0.0,0.0,1.0,0.0},
1381 {0.0,0.0,0.0,0.0,1.0}}};
1382 const ColorMatrix double_red = {{
1383 {2.0,0.0,0.0,0.0,0.0},
1384 {0.0,1.0,0.0,0.0,0.0},
1385 {0.0,0.0,1.0,0.0,0.0},
1386 {0.0,0.0,0.0,1.0,0.0},
1387 {0.0,0.0,0.0,0.0,1.0}}};
1388 GpBitmap *bitmap1, *bitmap2;
1389 GpGraphics *graphics;
1390 ARGB color;
1392 colormatrix = identity;
1393 graymatrix = identity;
1395 stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
1396 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1397 expect(InvalidParameter, stat);
1399 stat = GdipCreateImageAttributes(&imageattr);
1400 expect(Ok, stat);
1402 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1403 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1404 expect(Ok, stat);
1406 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1407 TRUE, NULL, NULL, ColorMatrixFlagsDefault);
1408 expect(InvalidParameter, stat);
1410 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1411 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1412 expect(Ok, stat);
1414 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1415 TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
1416 expect(Ok, stat);
1418 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1419 TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
1420 expect(InvalidParameter, stat);
1422 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1423 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
1424 expect(Ok, stat);
1426 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1427 TRUE, &colormatrix, &graymatrix, 3);
1428 expect(InvalidParameter, stat);
1430 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
1431 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1432 expect(InvalidParameter, stat);
1434 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
1435 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1436 expect(InvalidParameter, stat);
1438 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1439 FALSE, NULL, NULL, ColorMatrixFlagsDefault);
1440 expect(Ok, stat);
1442 /* Drawing a bitmap transforms the colors */
1443 colormatrix = double_red;
1444 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1445 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1446 expect(Ok, stat);
1448 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1449 expect(Ok, stat);
1451 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1452 expect(Ok, stat);
1454 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ffff);
1455 expect(Ok, stat);
1457 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1458 expect(Ok, stat);
1460 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1461 UnitPixel, imageattr, NULL, NULL);
1462 expect(Ok, stat);
1464 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1465 expect(Ok, stat);
1466 todo_wine expect(0xff80ffff, color);
1468 GdipDeleteGraphics(graphics);
1469 GdipDisposeImage((GpImage*)bitmap1);
1470 GdipDisposeImage((GpImage*)bitmap2);
1471 GdipDisposeImageAttributes(imageattr);
1474 static void test_gamma(void)
1476 GpStatus stat;
1477 GpImageAttributes *imageattr;
1478 GpBitmap *bitmap1, *bitmap2;
1479 GpGraphics *graphics;
1480 ARGB color;
1482 stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
1483 expect(InvalidParameter, stat);
1485 stat = GdipCreateImageAttributes(&imageattr);
1486 expect(Ok, stat);
1488 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
1489 expect(Ok, stat);
1491 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
1492 expect(InvalidParameter, stat);
1494 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
1495 expect(InvalidParameter, stat);
1497 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
1498 expect(InvalidParameter, stat);
1500 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
1501 expect(Ok, stat);
1503 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
1504 expect(Ok, stat);
1506 /* Drawing a bitmap transforms the colors */
1507 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
1508 expect(Ok, stat);
1510 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1511 expect(Ok, stat);
1513 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1514 expect(Ok, stat);
1516 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
1517 expect(Ok, stat);
1519 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1520 expect(Ok, stat);
1522 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1523 UnitPixel, imageattr, NULL, NULL);
1524 expect(Ok, stat);
1526 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1527 expect(Ok, stat);
1528 todo_wine ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
1530 GdipDeleteGraphics(graphics);
1531 GdipDisposeImage((GpImage*)bitmap1);
1532 GdipDisposeImage((GpImage*)bitmap2);
1533 GdipDisposeImageAttributes(imageattr);
1536 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
1537 static const unsigned char gifanimation[72] = {
1538 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1539 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
1540 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
1541 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
1542 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
1545 static void test_multiframegif(void)
1547 LPSTREAM stream;
1548 HGLOBAL hglob;
1549 LPBYTE data;
1550 HRESULT hres;
1551 GpStatus stat;
1552 GpBitmap *bmp;
1553 ARGB color;
1554 UINT count;
1555 GUID dimension;
1557 /* Test frame functions with an animated GIF */
1558 hglob = GlobalAlloc (0, sizeof(gifanimation));
1559 data = GlobalLock (hglob);
1560 memcpy(data, gifanimation, sizeof(gifanimation));
1561 GlobalUnlock(hglob);
1563 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1564 ok(hres == S_OK, "Failed to create a stream\n");
1565 if(hres != S_OK) return;
1567 stat = GdipCreateBitmapFromStream(stream, &bmp);
1568 ok(stat == Ok, "Failed to create a Bitmap\n");
1569 if(stat != Ok){
1570 IStream_Release(stream);
1571 return;
1574 /* Bitmap starts at frame 0 */
1575 color = 0xdeadbeef;
1576 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1577 expect(Ok, stat);
1578 expect(0xffffffff, color);
1580 /* Check that we get correct metadata */
1581 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1582 expect(Ok, stat);
1583 expect(1, count);
1585 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1586 expect(Ok, stat);
1587 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1589 count = 12345;
1590 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1591 todo_wine expect(Ok, stat);
1592 todo_wine expect(2, count);
1594 /* SelectActiveFrame overwrites our current data */
1595 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1596 expect(Ok, stat);
1598 color = 0xdeadbeef;
1599 GdipBitmapGetPixel(bmp, 0, 0, &color);
1600 expect(Ok, stat);
1601 todo_wine expect(0xff000000, color);
1603 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1604 expect(Ok, stat);
1606 color = 0xdeadbeef;
1607 GdipBitmapGetPixel(bmp, 0, 0, &color);
1608 expect(Ok, stat);
1609 expect(0xffffffff, color);
1611 /* Write over the image data */
1612 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
1613 expect(Ok, stat);
1615 /* Switching to the same frame does not overwrite our changes */
1616 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1617 expect(Ok, stat);
1619 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1620 expect(Ok, stat);
1621 expect(0xff000000, color);
1623 /* But switching to another frame and back does */
1624 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1625 expect(Ok, stat);
1627 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1628 expect(Ok, stat);
1630 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1631 expect(Ok, stat);
1632 todo_wine expect(0xffffffff, color);
1634 GdipDisposeImage((GpImage*)bmp);
1635 IStream_Release(stream);
1637 /* Test with a non-animated gif */
1638 hglob = GlobalAlloc (0, sizeof(gifimage));
1639 data = GlobalLock (hglob);
1640 memcpy(data, gifimage, sizeof(gifimage));
1641 GlobalUnlock(hglob);
1643 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1644 ok(hres == S_OK, "Failed to create a stream\n");
1645 if(hres != S_OK) return;
1647 stat = GdipCreateBitmapFromStream(stream, &bmp);
1648 ok(stat == Ok, "Failed to create a Bitmap\n");
1649 if(stat != Ok){
1650 IStream_Release(stream);
1651 return;
1654 /* Check metadata */
1655 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1656 expect(Ok, stat);
1657 expect(1, count);
1659 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1660 expect(Ok, stat);
1661 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1663 count = 12345;
1664 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1665 todo_wine expect(Ok, stat);
1666 todo_wine expect(1, count);
1668 GdipDisposeImage((GpImage*)bmp);
1669 IStream_Release(stream);
1672 static void test_rotateflip(void)
1674 GpImage *bitmap;
1675 GpStatus stat;
1676 BYTE bits[24];
1677 static const BYTE orig_bits[24] = {
1678 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
1679 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
1680 UINT width, height;
1681 ARGB color;
1683 memcpy(bits, orig_bits, sizeof(bits));
1684 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1685 expect(Ok, stat);
1687 stat = GdipImageRotateFlip(bitmap, Rotate90FlipNone);
1688 todo_wine expect(Ok, stat);
1690 stat = GdipGetImageWidth(bitmap, &width);
1691 expect(Ok, stat);
1692 stat = GdipGetImageHeight(bitmap, &height);
1693 expect(Ok, stat);
1694 todo_wine expect(2, width);
1695 todo_wine expect(3, height);
1697 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1698 expect(Ok, stat);
1699 todo_wine expect(0xff00ffff, color);
1701 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 0, &color);
1702 expect(Ok, stat);
1703 todo_wine expect(0xffff0000, color);
1705 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 2, &color);
1706 todo_wine expect(Ok, stat);
1707 todo_wine expect(0xffffff00, color);
1709 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 2, &color);
1710 todo_wine expect(Ok, stat);
1711 todo_wine expect(0xff0000ff, color);
1713 expect(0, bits[0]);
1714 expect(0, bits[1]);
1715 expect(0xff, bits[2]);
1717 GdipDisposeImage(bitmap);
1719 memcpy(bits, orig_bits, sizeof(bits));
1720 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1721 expect(Ok, stat);
1723 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipX);
1724 todo_wine expect(Ok, stat);
1726 stat = GdipGetImageWidth(bitmap, &width);
1727 expect(Ok, stat);
1728 stat = GdipGetImageHeight(bitmap, &height);
1729 expect(Ok, stat);
1730 expect(3, width);
1731 expect(2, height);
1733 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1734 expect(Ok, stat);
1735 todo_wine expect(0xff0000ff, color);
1737 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
1738 expect(Ok, stat);
1739 todo_wine expect(0xffff0000, color);
1741 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
1742 expect(Ok, stat);
1743 todo_wine expect(0xffffff00, color);
1745 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
1746 expect(Ok, stat);
1747 todo_wine expect(0xff00ffff, color);
1749 expect(0, bits[0]);
1750 expect(0, bits[1]);
1751 expect(0xff, bits[2]);
1753 GdipDisposeImage(bitmap);
1755 memcpy(bits, orig_bits, sizeof(bits));
1756 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1757 expect(Ok, stat);
1759 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipY);
1760 todo_wine expect(Ok, stat);
1762 stat = GdipGetImageWidth(bitmap, &width);
1763 expect(Ok, stat);
1764 stat = GdipGetImageHeight(bitmap, &height);
1765 expect(Ok, stat);
1766 expect(3, width);
1767 expect(2, height);
1769 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1770 expect(Ok, stat);
1771 todo_wine expect(0xff00ffff, color);
1773 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
1774 expect(Ok, stat);
1775 todo_wine expect(0xffffff00, color);
1777 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
1778 expect(Ok, stat);
1779 todo_wine expect(0xffff0000, color);
1781 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
1782 expect(Ok, stat);
1783 todo_wine expect(0xff0000ff, color);
1785 expect(0, bits[0]);
1786 expect(0, bits[1]);
1787 expect(0xff, bits[2]);
1789 GdipDisposeImage(bitmap);
1792 static void test_remaptable(void)
1794 GpStatus stat;
1795 GpImageAttributes *imageattr;
1796 GpBitmap *bitmap1, *bitmap2;
1797 GpGraphics *graphics;
1798 ARGB color;
1799 ColorMap *map;
1801 map = GdipAlloc(sizeof(ColorMap));
1803 map->oldColor.Argb = 0xff00ff00;
1804 map->newColor.Argb = 0xffff00ff;
1806 stat = GdipSetImageAttributesRemapTable(NULL, ColorAdjustTypeDefault, TRUE, 1, map);
1807 expect(InvalidParameter, stat);
1809 stat = GdipCreateImageAttributes(&imageattr);
1810 expect(Ok, stat);
1812 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, NULL);
1813 expect(InvalidParameter, stat);
1815 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeCount, TRUE, 1, map);
1816 expect(InvalidParameter, stat);
1818 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeAny, TRUE, 1, map);
1819 expect(InvalidParameter, stat);
1821 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 0, map);
1822 expect(InvalidParameter, stat);
1824 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, FALSE, 0, NULL);
1825 expect(Ok, stat);
1827 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, map);
1828 expect(Ok, stat);
1830 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1831 expect(Ok, stat);
1833 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1834 expect(Ok, stat);
1836 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff00ff00);
1837 expect(Ok, stat);
1839 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1840 expect(Ok, stat);
1842 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1843 UnitPixel, imageattr, NULL, NULL);
1844 expect(Ok, stat);
1846 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1847 expect(Ok, stat);
1848 todo_wine ok(color_match(0xffff00ff, color, 1), "Expected ffff00ff, got %.8x\n", color);
1850 GdipDeleteGraphics(graphics);
1851 GdipDisposeImage((GpImage*)bitmap1);
1852 GdipDisposeImage((GpImage*)bitmap2);
1853 GdipDisposeImageAttributes(imageattr);
1854 GdipFree(map);
1857 START_TEST(image)
1859 struct GdiplusStartupInput gdiplusStartupInput;
1860 ULONG_PTR gdiplusToken;
1862 gdiplusStartupInput.GdiplusVersion = 1;
1863 gdiplusStartupInput.DebugEventCallback = NULL;
1864 gdiplusStartupInput.SuppressBackgroundThread = 0;
1865 gdiplusStartupInput.SuppressExternalCodecs = 0;
1867 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1869 test_Scan0();
1870 test_GetImageDimension();
1871 test_GdipImageGetFrameDimensionsCount();
1872 test_LoadingImages();
1873 test_SavingImages();
1874 test_encoders();
1875 test_LockBits();
1876 test_GdipCreateBitmapFromHBITMAP();
1877 test_GdipGetImageFlags();
1878 test_GdipCloneImage();
1879 test_testcontrol();
1880 test_fromhicon();
1881 test_getrawformat();
1882 test_loadwmf();
1883 test_createfromwmf();
1884 test_resolution();
1885 test_createhbitmap();
1886 test_getsetpixel();
1887 test_palette();
1888 test_colormatrix();
1889 test_gamma();
1890 test_multiframegif();
1891 test_rotateflip();
1892 test_remaptable();
1894 GdiplusShutdown(gdiplusToken);