gdiplus: Include an alpha channel in HBITMAPs created from Bitmaps.
[wine/multimedia.git] / dlls / gdiplus / tests / image.c
blob44554a593dcb9f21b6c436f09dab0523cbab2b57
1 /*
2 * Unit test suite for images
4 * Copyright (C) 2007 Google (Evan Stade)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include <math.h>
25 #include "initguid.h"
26 #include "windows.h"
27 #include "gdiplus.h"
28 #include "wine/test.h"
30 #define expect(expected, got) ok((UINT)(got) == (UINT)(expected), "Expected %.8x, got %.8x\n", (UINT)(expected), (UINT)(got))
31 #define expectf(expected, got) ok(fabs(expected - got) < 0.0001, "Expected %.2f, got %.2f\n", expected, got)
33 static BOOL color_match(ARGB c1, ARGB c2, BYTE max_diff)
35 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
36 c1 >>= 8; c2 >>= 8;
37 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
38 c1 >>= 8; c2 >>= 8;
39 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
40 c1 >>= 8; c2 >>= 8;
41 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
42 return TRUE;
45 static void expect_guid(REFGUID expected, REFGUID got, int line, BOOL todo)
47 WCHAR bufferW[39];
48 char buffer[39];
49 char buffer2[39];
51 StringFromGUID2(got, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
52 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer, sizeof(buffer), NULL, NULL);
53 StringFromGUID2(expected, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
54 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer2, sizeof(buffer2), NULL, NULL);
55 if(todo)
56 todo_wine ok_(__FILE__, line)(IsEqualGUID(expected, got), "Expected %s, got %s\n", buffer2, buffer);
57 else
58 ok_(__FILE__, line)(IsEqualGUID(expected, got), "Expected %s, got %s\n", buffer2, buffer);
61 static void expect_rawformat(REFGUID expected, GpImage *img, int line, BOOL todo)
63 GUID raw;
64 GpStatus stat;
66 stat = GdipGetImageRawFormat(img, &raw);
67 ok_(__FILE__, line)(stat == Ok, "GdipGetImageRawFormat failed with %d\n", stat);
68 if(stat != Ok) return;
69 expect_guid(expected, &raw, line, todo);
72 static void test_bufferrawformat(void* buff, int size, REFGUID expected, int line, BOOL todo)
74 LPSTREAM stream;
75 HGLOBAL hglob;
76 LPBYTE data;
77 HRESULT hres;
78 GpStatus stat;
79 GpImage *img;
81 hglob = GlobalAlloc (0, size);
82 data = GlobalLock (hglob);
83 memcpy(data, buff, size);
84 GlobalUnlock(hglob); data = NULL;
86 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
87 ok_(__FILE__, line)(hres == S_OK, "Failed to create a stream\n");
88 if(hres != S_OK) return;
90 stat = GdipLoadImageFromStream(stream, &img);
91 ok_(__FILE__, line)(stat == Ok, "Failed to create a Bitmap\n");
92 if(stat != Ok){
93 IStream_Release(stream);
94 return;
97 expect_rawformat(expected, img, line, todo);
99 GdipDisposeImage(img);
100 IStream_Release(stream);
103 static void test_Scan0(void)
105 GpBitmap *bm;
106 GpStatus stat;
107 BYTE buff[360];
109 bm = NULL;
110 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
111 expect(Ok, stat);
112 ok(NULL != bm, "Expected bitmap to be initialized\n");
113 if (stat == Ok)
114 GdipDisposeImage((GpImage*)bm);
116 bm = (GpBitmap*)0xdeadbeef;
117 stat = GdipCreateBitmapFromScan0(10, -10, 10, PixelFormat24bppRGB, NULL, &bm);
118 expect(InvalidParameter, stat);
119 ok( !bm, "expected null bitmap\n" );
121 bm = (GpBitmap*)0xdeadbeef;
122 stat = GdipCreateBitmapFromScan0(-10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
123 expect(InvalidParameter, stat);
124 ok( !bm, "expected null bitmap\n" );
126 bm = (GpBitmap*)0xdeadbeef;
127 stat = GdipCreateBitmapFromScan0(10, 0, 10, PixelFormat24bppRGB, NULL, &bm);
128 expect(InvalidParameter, stat);
129 ok( !bm, "expected null bitmap\n" );
131 bm = NULL;
132 stat = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, buff, &bm);
133 expect(Ok, stat);
134 ok(NULL != bm, "Expected bitmap to be initialized\n");
135 if (stat == Ok)
136 GdipDisposeImage((GpImage*)bm);
138 bm = (GpBitmap*) 0xdeadbeef;
139 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, buff, &bm);
140 expect(InvalidParameter, stat);
141 ok( !bm, "expected null bitmap\n" );
143 bm = (GpBitmap*)0xdeadbeef;
144 stat = GdipCreateBitmapFromScan0(10, 10, 0, PixelFormat24bppRGB, buff, &bm);
145 expect(InvalidParameter, stat);
146 ok( bm == (GpBitmap*)0xdeadbeef, "expected deadbeef bitmap\n" );
148 bm = NULL;
149 stat = GdipCreateBitmapFromScan0(10, 10, -8, PixelFormat24bppRGB, buff, &bm);
150 expect(Ok, stat);
151 ok(NULL != bm, "Expected bitmap to be initialized\n");
152 if (stat == Ok)
153 GdipDisposeImage((GpImage*)bm);
155 bm = (GpBitmap*)0xdeadbeef;
156 stat = GdipCreateBitmapFromScan0(10, 10, -10, PixelFormat24bppRGB, buff, &bm);
157 expect(InvalidParameter, stat);
158 ok( !bm, "expected null bitmap\n" );
161 static void test_FromGdiDib(void)
163 GpBitmap *bm;
164 GpStatus stat;
165 BYTE buff[400];
166 BYTE rbmi[sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)];
167 BITMAPINFO *bmi = (BITMAPINFO*)rbmi;
168 PixelFormat format;
170 bm = NULL;
172 memset(rbmi, 0, sizeof(rbmi));
174 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
175 bmi->bmiHeader.biWidth = 10;
176 bmi->bmiHeader.biHeight = 10;
177 bmi->bmiHeader.biPlanes = 1;
178 bmi->bmiHeader.biBitCount = 32;
179 bmi->bmiHeader.biCompression = BI_RGB;
181 stat = GdipCreateBitmapFromGdiDib(NULL, buff, &bm);
182 expect(InvalidParameter, stat);
184 stat = GdipCreateBitmapFromGdiDib(bmi, NULL, &bm);
185 expect(InvalidParameter, stat);
187 stat = GdipCreateBitmapFromGdiDib(bmi, buff, NULL);
188 expect(InvalidParameter, stat);
190 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
191 expect(Ok, stat);
192 ok(NULL != bm, "Expected bitmap to be initialized\n");
193 if (stat == Ok)
195 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
196 expect(Ok, stat);
197 expect(PixelFormat32bppRGB, format);
199 GdipDisposeImage((GpImage*)bm);
202 bmi->bmiHeader.biBitCount = 24;
203 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
204 expect(Ok, stat);
205 ok(NULL != bm, "Expected bitmap to be initialized\n");
206 if (stat == Ok)
208 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
209 expect(Ok, stat);
210 expect(PixelFormat24bppRGB, format);
212 GdipDisposeImage((GpImage*)bm);
215 bmi->bmiHeader.biBitCount = 16;
216 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
217 expect(Ok, stat);
218 ok(NULL != bm, "Expected bitmap to be initialized\n");
219 if (stat == Ok)
221 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
222 expect(Ok, stat);
223 expect(PixelFormat16bppRGB555, format);
225 GdipDisposeImage((GpImage*)bm);
228 bmi->bmiHeader.biBitCount = 8;
229 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
230 expect(Ok, stat);
231 ok(NULL != bm, "Expected bitmap to be initialized\n");
232 if (stat == Ok)
234 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
235 expect(Ok, stat);
236 expect(PixelFormat8bppIndexed, format);
238 GdipDisposeImage((GpImage*)bm);
241 bmi->bmiHeader.biBitCount = 4;
242 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
243 expect(Ok, stat);
244 ok(NULL != bm, "Expected bitmap to be initialized\n");
245 if (stat == Ok)
247 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
248 expect(Ok, stat);
249 expect(PixelFormat4bppIndexed, format);
251 GdipDisposeImage((GpImage*)bm);
254 bmi->bmiHeader.biBitCount = 1;
255 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
256 expect(Ok, stat);
257 ok(NULL != bm, "Expected bitmap to be initialized\n");
258 if (stat == Ok)
260 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
261 expect(Ok, stat);
262 expect(PixelFormat1bppIndexed, format);
264 GdipDisposeImage((GpImage*)bm);
267 bmi->bmiHeader.biBitCount = 0;
268 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
269 expect(InvalidParameter, stat);
272 static void test_GetImageDimension(void)
274 GpBitmap *bm;
275 GpStatus stat;
276 const REAL WIDTH = 10.0, HEIGHT = 20.0;
277 REAL w,h;
279 bm = (GpBitmap*)0xdeadbeef;
280 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
281 expect(Ok,stat);
282 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
283 ok(NULL != bm, "Expected bitmap to not be NULL\n");
285 stat = GdipGetImageDimension(NULL,&w,&h);
286 expect(InvalidParameter, stat);
288 stat = GdipGetImageDimension((GpImage*)bm,NULL,&h);
289 expect(InvalidParameter, stat);
291 stat = GdipGetImageDimension((GpImage*)bm,&w,NULL);
292 expect(InvalidParameter, stat);
294 w = -1;
295 h = -1;
296 stat = GdipGetImageDimension((GpImage*)bm,&w,&h);
297 expect(Ok, stat);
298 expectf(WIDTH, w);
299 expectf(HEIGHT, h);
300 GdipDisposeImage((GpImage*)bm);
303 static void test_GdipImageGetFrameDimensionsCount(void)
305 GpBitmap *bm;
306 GpStatus stat;
307 const REAL WIDTH = 10.0, HEIGHT = 20.0;
308 UINT w;
309 GUID dimension = {0};
310 UINT count;
311 ARGB color;
313 bm = (GpBitmap*)0xdeadbeef;
314 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
315 expect(Ok,stat);
316 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
317 ok(NULL != bm, "Expected bitmap to not be NULL\n");
319 stat = GdipImageGetFrameDimensionsCount(NULL,&w);
320 expect(InvalidParameter, stat);
322 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,NULL);
323 expect(InvalidParameter, stat);
325 w = -1;
326 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,&w);
327 expect(Ok, stat);
328 expect(1, w);
330 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 1);
331 expect(Ok, stat);
332 expect_guid(&FrameDimensionPage, &dimension, __LINE__, FALSE);
334 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 2);
335 expect(InvalidParameter, stat);
337 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 0);
338 expect(InvalidParameter, stat);
340 stat = GdipImageGetFrameCount(NULL, &dimension, &count);
341 expect(InvalidParameter, stat);
343 /* WinXP crashes on this test */
344 if(0)
346 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, NULL);
347 expect(InvalidParameter, stat);
350 stat = GdipImageGetFrameCount((GpImage*)bm, NULL, &count);
351 expect(Ok, stat);
353 count = 12345;
354 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, &count);
355 expect(Ok, stat);
356 expect(1, count);
358 GdipBitmapSetPixel(bm, 0, 0, 0xffffffff);
360 stat = GdipImageSelectActiveFrame((GpImage*)bm, &dimension, 0);
361 expect(Ok, stat);
363 /* SelectActiveFrame has no effect on image data of memory bitmaps */
364 color = 0xdeadbeef;
365 GdipBitmapGetPixel(bm, 0, 0, &color);
366 expect(0xffffffff, color);
368 GdipDisposeImage((GpImage*)bm);
371 static void test_LoadingImages(void)
373 GpStatus stat;
375 stat = GdipCreateBitmapFromFile(0, 0);
376 expect(InvalidParameter, stat);
378 stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
379 expect(InvalidParameter, stat);
381 stat = GdipLoadImageFromFile(0, 0);
382 expect(InvalidParameter, stat);
384 stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
385 expect(InvalidParameter, stat);
387 stat = GdipLoadImageFromFileICM(0, 0);
388 expect(InvalidParameter, stat);
390 stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
391 expect(InvalidParameter, stat);
394 static void test_SavingImages(void)
396 GpStatus stat;
397 GpBitmap *bm;
398 UINT n;
399 UINT s;
400 const REAL WIDTH = 10.0, HEIGHT = 20.0;
401 REAL w, h;
402 ImageCodecInfo *codecs;
403 static const CHAR filenameA[] = "a.bmp";
404 static const WCHAR filename[] = { 'a','.','b','m','p',0 };
406 codecs = NULL;
408 stat = GdipSaveImageToFile(0, 0, 0, 0);
409 expect(InvalidParameter, stat);
411 bm = NULL;
412 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
413 expect(Ok, stat);
414 if (!bm)
415 return;
417 /* invalid params */
418 stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
419 expect(InvalidParameter, stat);
421 stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
422 expect(InvalidParameter, stat);
424 /* encoder tests should succeed -- already tested */
425 stat = GdipGetImageEncodersSize(&n, &s);
426 if (stat != Ok || n == 0) goto cleanup;
428 codecs = GdipAlloc(s);
429 if (!codecs) goto cleanup;
431 stat = GdipGetImageEncoders(n, s, codecs);
432 if (stat != Ok) goto cleanup;
434 stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
435 expect(stat, Ok);
437 GdipDisposeImage((GpImage*)bm);
438 bm = 0;
440 /* re-load and check image stats */
441 stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
442 expect(stat, Ok);
443 if (stat != Ok) goto cleanup;
445 stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
446 if (stat != Ok) goto cleanup;
448 expectf(WIDTH, w);
449 expectf(HEIGHT, h);
451 cleanup:
452 GdipFree(codecs);
453 if (bm)
454 GdipDisposeImage((GpImage*)bm);
455 ok(DeleteFileA(filenameA), "Delete failed.\n");
458 static void test_encoders(void)
460 GpStatus stat;
461 UINT n;
462 UINT s;
463 ImageCodecInfo *codecs;
464 int i;
465 int bmp_found;
467 static const CHAR bmp_format[] = "BMP";
469 stat = GdipGetImageEncodersSize(&n, &s);
470 expect(stat, Ok);
472 codecs = GdipAlloc(s);
473 if (!codecs)
474 return;
476 stat = GdipGetImageEncoders(n, s, NULL);
477 expect(GenericError, stat);
479 stat = GdipGetImageEncoders(0, s, codecs);
480 expect(GenericError, stat);
482 stat = GdipGetImageEncoders(n, s-1, codecs);
483 expect(GenericError, stat);
485 stat = GdipGetImageEncoders(n, s+1, codecs);
486 expect(GenericError, stat);
488 stat = GdipGetImageEncoders(n, s, codecs);
489 expect(stat, Ok);
491 bmp_found = FALSE;
492 for (i = 0; i < n; i++)
494 CHAR desc[32];
496 WideCharToMultiByte(CP_ACP, 0, codecs[i].FormatDescription, -1,
497 desc, 32, 0, 0);
499 if (CompareStringA(LOCALE_SYSTEM_DEFAULT, 0,
500 desc, -1,
501 bmp_format, -1) == CSTR_EQUAL) {
502 bmp_found = TRUE;
503 break;
506 if (!bmp_found)
507 ok(FALSE, "No BMP codec found.\n");
509 GdipFree(codecs);
512 static void test_LockBits(void)
514 GpStatus stat;
515 GpBitmap *bm;
516 GpRect rect;
517 BitmapData bd;
518 const INT WIDTH = 10, HEIGHT = 20;
519 ARGB color;
520 int y;
522 bm = NULL;
523 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
524 expect(Ok, stat);
526 rect.X = 2;
527 rect.Y = 3;
528 rect.Width = 4;
529 rect.Height = 5;
531 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffc30000);
532 expect(Ok, stat);
534 stat = GdipBitmapSetPixel(bm, 2, 8, 0xff480000);
535 expect(Ok, stat);
537 /* read-only */
538 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
539 expect(Ok, stat);
541 if (stat == Ok) {
542 expect(0xc3, ((BYTE*)bd.Scan0)[2]);
543 expect(0x48, ((BYTE*)bd.Scan0)[2 + bd.Stride * 5]);
545 ((char*)bd.Scan0)[2] = 0xff;
547 stat = GdipBitmapUnlockBits(bm, &bd);
548 expect(Ok, stat);
551 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
552 expect(Ok, stat);
553 expect(0xffff0000, color);
555 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffc30000);
556 expect(Ok, stat);
558 /* read-only, with NULL rect -> whole bitmap lock */
559 stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
560 expect(Ok, stat);
561 expect(bd.Width, WIDTH);
562 expect(bd.Height, HEIGHT);
564 if (stat == Ok) {
565 ((char*)bd.Scan0)[2 + 2*3 + 3*bd.Stride] = 0xff;
567 stat = GdipBitmapUnlockBits(bm, &bd);
568 expect(Ok, stat);
571 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
572 expect(Ok, stat);
573 expect(0xffff0000, color);
575 /* read-only, consecutive */
576 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
577 expect(Ok, stat);
579 if (stat == Ok) {
580 stat = GdipBitmapUnlockBits(bm, &bd);
581 expect(Ok, stat);
584 stat = GdipDisposeImage((GpImage*)bm);
585 expect(Ok, stat);
586 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
587 expect(Ok, stat);
589 /* read x2 */
590 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
591 expect(Ok, stat);
592 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
593 expect(WrongState, stat);
595 stat = GdipBitmapUnlockBits(bm, &bd);
596 expect(Ok, stat);
598 stat = GdipDisposeImage((GpImage*)bm);
599 expect(Ok, stat);
600 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
601 expect(Ok, stat);
603 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffff0000);
604 expect(Ok, stat);
606 stat = GdipBitmapSetPixel(bm, 2, 8, 0xffc30000);
607 expect(Ok, stat);
609 /* write, no conversion */
610 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
611 expect(Ok, stat);
613 if (stat == Ok) {
614 /* all bits are readable, inside the rect or not */
615 expect(0xff, ((BYTE*)bd.Scan0)[2]);
616 expect(0xc3, ((BYTE*)bd.Scan0)[2 + bd.Stride * 5]);
618 stat = GdipBitmapUnlockBits(bm, &bd);
619 expect(Ok, stat);
622 /* read, conversion */
623 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat32bppARGB, &bd);
624 expect(Ok, stat);
626 if (stat == Ok) {
627 expect(0xff, ((BYTE*)bd.Scan0)[2]);
628 if (0)
629 /* Areas outside the rectangle appear to be uninitialized */
630 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
632 ((BYTE*)bd.Scan0)[2] = 0xc3;
634 stat = GdipBitmapUnlockBits(bm, &bd);
635 expect(Ok, stat);
638 /* writes do not work in read mode if there was a conversion */
639 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
640 expect(Ok, stat);
641 expect(0xffff0000, color);
643 /* read/write, conversion */
644 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeWrite, PixelFormat32bppARGB, &bd);
645 expect(Ok, stat);
647 if (stat == Ok) {
648 expect(0xff, ((BYTE*)bd.Scan0)[2]);
649 ((BYTE*)bd.Scan0)[1] = 0x88;
650 if (0)
651 /* Areas outside the rectangle appear to be uninitialized */
652 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
654 stat = GdipBitmapUnlockBits(bm, &bd);
655 expect(Ok, stat);
658 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
659 expect(Ok, stat);
660 expect(0xffff8800, color);
662 /* write, conversion */
663 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat32bppARGB, &bd);
664 expect(Ok, stat);
666 if (stat == Ok) {
667 if (0)
669 /* This is completely uninitialized. */
670 ok(0xff != ((BYTE*)bd.Scan0)[2], "original image bits are readable\n");
671 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
674 /* Initialize the buffer so the unlock doesn't access undefined memory */
675 for (y=0; y<5; y++)
676 memset(((BYTE*)bd.Scan0) + bd.Stride * y, 0, 12);
678 ((BYTE*)bd.Scan0)[0] = 0x12;
679 ((BYTE*)bd.Scan0)[1] = 0x34;
680 ((BYTE*)bd.Scan0)[2] = 0x56;
682 stat = GdipBitmapUnlockBits(bm, &bd);
683 expect(Ok, stat);
686 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
687 expect(Ok, stat);
688 expect(0xff563412, color);
690 stat = GdipBitmapGetPixel(bm, 2, 8, &color);
691 expect(Ok, stat);
692 expect(0xffc30000, color);
694 stat = GdipDisposeImage((GpImage*)bm);
695 expect(Ok, stat);
696 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
697 expect(Ok, stat);
699 /* write, no modification */
700 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
701 expect(Ok, stat);
703 if (stat == Ok) {
704 stat = GdipBitmapUnlockBits(bm, &bd);
705 expect(Ok, stat);
708 /* write, consecutive */
709 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
710 expect(Ok, stat);
712 if (stat == Ok) {
713 stat = GdipBitmapUnlockBits(bm, &bd);
714 expect(Ok, stat);
717 stat = GdipDisposeImage((GpImage*)bm);
718 expect(Ok, stat);
719 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
720 expect(Ok, stat);
722 /* write, modify */
723 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
724 expect(Ok, stat);
726 if (stat == Ok) {
727 if (bd.Scan0)
728 ((char*)bd.Scan0)[2] = 0xff;
730 stat = GdipBitmapUnlockBits(bm, &bd);
731 expect(Ok, stat);
734 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
735 expect(Ok, stat);
736 expect(0xffff0000, color);
738 stat = GdipDisposeImage((GpImage*)bm);
739 expect(Ok, stat);
741 /* dispose locked */
742 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
743 expect(Ok, stat);
744 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
745 expect(Ok, stat);
746 stat = GdipDisposeImage((GpImage*)bm);
747 expect(Ok, stat);
750 static void test_LockBits_UserBuf(void)
752 GpStatus stat;
753 GpBitmap *bm;
754 GpRect rect;
755 BitmapData bd;
756 const INT WIDTH = 10, HEIGHT = 20;
757 DWORD bits[200];
758 ARGB color;
760 bm = NULL;
761 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat32bppARGB, NULL, &bm);
762 expect(Ok, stat);
764 memset(bits, 0xaa, sizeof(bits));
766 rect.X = 2;
767 rect.Y = 3;
768 rect.Width = 4;
769 rect.Height = 5;
771 bd.Width = 4;
772 bd.Height = 6;
773 bd.Stride = WIDTH * 4;
774 bd.PixelFormat = PixelFormat32bppARGB;
775 bd.Scan0 = &bits[2+3*WIDTH];
776 bd.Reserved = 0xaaaaaaaa;
778 /* read-only */
779 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
780 expect(Ok, stat);
782 expect(0xaaaaaaaa, bits[0]);
783 expect(0, bits[2+3*WIDTH]);
785 bits[2+3*WIDTH] = 0xdeadbeef;
787 if (stat == Ok) {
788 stat = GdipBitmapUnlockBits(bm, &bd);
789 expect(Ok, stat);
792 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
793 expect(Ok, stat);
794 expect(0, color);
796 /* write-only */
797 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
798 expect(Ok, stat);
800 expect(0xdeadbeef, bits[2+3*WIDTH]);
801 bits[2+3*WIDTH] = 0x12345678;
803 if (stat == Ok) {
804 stat = GdipBitmapUnlockBits(bm, &bd);
805 expect(Ok, stat);
808 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
809 expect(Ok, stat);
810 expect(0x12345678, color);
812 bits[2+3*WIDTH] = 0;
814 /* read/write */
815 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeWrite|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
816 expect(Ok, stat);
818 expect(0x12345678, bits[2+3*WIDTH]);
819 bits[2+3*WIDTH] = 0xdeadbeef;
821 if (stat == Ok) {
822 stat = GdipBitmapUnlockBits(bm, &bd);
823 expect(Ok, stat);
826 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
827 expect(Ok, stat);
828 expect(0xdeadbeef, color);
830 stat = GdipDisposeImage((GpImage*)bm);
831 expect(Ok, stat);
834 static void test_GdipCreateBitmapFromHBITMAP(void)
836 GpBitmap* gpbm = NULL;
837 HBITMAP hbm = NULL;
838 HPALETTE hpal = NULL;
839 GpStatus stat;
840 BYTE buff[1000];
841 LOGPALETTE* LogPal = NULL;
842 REAL width, height;
843 const REAL WIDTH1 = 5;
844 const REAL HEIGHT1 = 15;
845 const REAL WIDTH2 = 10;
846 const REAL HEIGHT2 = 20;
847 HDC hdc;
848 BITMAPINFO bmi;
849 BYTE *bits;
851 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
852 expect(InvalidParameter, stat);
854 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
855 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
856 expect(InvalidParameter, stat);
858 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
859 expect(Ok, stat);
860 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
861 expectf(WIDTH1, width);
862 expectf(HEIGHT1, height);
863 if (stat == Ok)
864 GdipDisposeImage((GpImage*)gpbm);
865 DeleteObject(hbm);
867 memset(buff, 0, sizeof(buff));
868 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
869 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
870 expect(Ok, stat);
871 /* raw format */
872 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
874 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
875 expectf(WIDTH2, width);
876 expectf(HEIGHT2, height);
877 if (stat == Ok)
878 GdipDisposeImage((GpImage*)gpbm);
879 DeleteObject(hbm);
881 hdc = CreateCompatibleDC(0);
882 ok(hdc != NULL, "CreateCompatibleDC failed\n");
883 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
884 bmi.bmiHeader.biHeight = HEIGHT1;
885 bmi.bmiHeader.biWidth = WIDTH1;
886 bmi.bmiHeader.biBitCount = 24;
887 bmi.bmiHeader.biPlanes = 1;
888 bmi.bmiHeader.biCompression = BI_RGB;
890 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
891 ok(hbm != NULL, "CreateDIBSection failed\n");
893 bits[0] = 0;
895 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
896 expect(Ok, stat);
897 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
898 expectf(WIDTH1, width);
899 expectf(HEIGHT1, height);
900 if (stat == Ok)
902 /* test whether writing to the bitmap affects the original */
903 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
904 expect(Ok, stat);
906 expect(0, bits[0]);
908 GdipDisposeImage((GpImage*)gpbm);
911 LogPal = GdipAlloc(sizeof(LOGPALETTE));
912 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
913 LogPal->palVersion = 0x300;
914 LogPal->palNumEntries = 1;
915 hpal = CreatePalette(LogPal);
916 ok(hpal != NULL, "CreatePalette failed\n");
917 GdipFree(LogPal);
919 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
920 expect(Ok, stat);
922 if (stat == Ok)
923 GdipDisposeImage((GpImage*)gpbm);
925 DeleteObject(hpal);
926 DeleteObject(hbm);
929 static void test_GdipGetImageFlags(void)
931 GpImage *img;
932 GpStatus stat;
933 UINT flags;
935 img = (GpImage*)0xdeadbeef;
937 stat = GdipGetImageFlags(NULL, NULL);
938 expect(InvalidParameter, stat);
940 stat = GdipGetImageFlags(NULL, &flags);
941 expect(InvalidParameter, stat);
943 stat = GdipGetImageFlags(img, NULL);
944 expect(InvalidParameter, stat);
946 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, (GpBitmap**)&img);
947 expect(Ok, stat);
948 stat = GdipGetImageFlags(img, &flags);
949 expect(Ok, stat);
950 expect(ImageFlagsHasAlpha, flags);
951 GdipDisposeImage(img);
953 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, (GpBitmap**)&img);
954 expect(Ok, stat);
955 stat = GdipGetImageFlags(img, &flags);
956 expect(Ok, stat);
957 expect(ImageFlagsHasAlpha, flags);
958 GdipDisposeImage(img);
960 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, (GpBitmap**)&img);
961 expect(Ok, stat);
962 stat = GdipGetImageFlags(img, &flags);
963 expect(Ok, stat);
964 expect(ImageFlagsHasAlpha, flags);
965 GdipDisposeImage(img);
967 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, (GpBitmap**)&img);
968 expect(Ok, stat);
969 stat = GdipGetImageFlags(img, &flags);
970 expect(Ok, stat);
971 expect(ImageFlagsNone, flags);
972 GdipDisposeImage(img);
974 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, (GpBitmap**)&img);
975 expect(Ok, stat);
976 stat = GdipGetImageFlags(img, &flags);
977 expect(Ok, stat);
978 expect(ImageFlagsNone, flags);
979 GdipDisposeImage(img);
981 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, (GpBitmap**)&img);
982 expect(Ok, stat);
983 stat = GdipGetImageFlags(img, &flags);
984 expect(Ok, stat);
985 expect(ImageFlagsNone, flags);
986 GdipDisposeImage(img);
988 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppARGB1555, NULL, (GpBitmap**)&img);
989 expect(Ok, stat);
990 stat = GdipGetImageFlags(img, &flags);
991 expect(Ok, stat);
992 expect(ImageFlagsHasAlpha, flags);
993 GdipDisposeImage(img);
995 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, (GpBitmap**)&img);
996 expect(Ok, stat);
997 stat = GdipGetImageFlags(img, &flags);
998 expect(Ok, stat);
999 expect(ImageFlagsNone, flags);
1000 GdipDisposeImage(img);
1002 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, (GpBitmap**)&img);
1003 expect(Ok, stat);
1004 stat = GdipGetImageFlags(img, &flags);
1005 expect(Ok, stat);
1006 expect(ImageFlagsNone, flags);
1007 GdipDisposeImage(img);
1009 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, (GpBitmap**)&img);
1010 expect(Ok, stat);
1011 stat = GdipGetImageFlags(img, &flags);
1012 expect(Ok, stat);
1013 expect(ImageFlagsHasAlpha, flags);
1014 GdipDisposeImage(img);
1016 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppPARGB, NULL, (GpBitmap**)&img);
1017 expect(Ok, stat);
1018 stat = GdipGetImageFlags(img, &flags);
1019 expect(Ok, stat);
1020 expect(ImageFlagsHasAlpha, flags);
1021 GdipDisposeImage(img);
1023 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, (GpBitmap**)&img);
1024 expect(Ok, stat);
1025 if (stat == Ok)
1027 stat = GdipGetImageFlags(img, &flags);
1028 expect(Ok, stat);
1029 expect(ImageFlagsNone, flags);
1030 GdipDisposeImage(img);
1033 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, (GpBitmap**)&img);
1034 expect(Ok, stat);
1035 if (stat == Ok)
1037 expect(Ok, stat);
1038 stat = GdipGetImageFlags(img, &flags);
1039 expect(Ok, stat);
1040 expect(ImageFlagsHasAlpha, flags);
1041 GdipDisposeImage(img);
1044 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, (GpBitmap**)&img);
1045 expect(Ok, stat);
1046 if (stat == Ok)
1048 expect(Ok, stat);
1049 stat = GdipGetImageFlags(img, &flags);
1050 expect(Ok, stat);
1051 expect(ImageFlagsHasAlpha, flags);
1052 GdipDisposeImage(img);
1056 static void test_GdipCloneImage(void)
1058 GpStatus stat;
1059 GpRectF rectF;
1060 GpUnit unit;
1061 GpBitmap *bm;
1062 GpImage *image_src, *image_dest = NULL;
1063 const INT WIDTH = 10, HEIGHT = 20;
1065 /* Create an image, clone it, delete the original, make sure the copy works */
1066 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
1067 expect(Ok, stat);
1068 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
1070 image_src = ((GpImage*)bm);
1071 stat = GdipCloneImage(image_src, &image_dest);
1072 expect(Ok, stat);
1073 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
1075 stat = GdipDisposeImage((GpImage*)bm);
1076 expect(Ok, stat);
1077 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
1078 expect(Ok, stat);
1080 /* Treat FP values carefully */
1081 expectf((REAL)WIDTH, rectF.Width);
1082 expectf((REAL)HEIGHT, rectF.Height);
1084 stat = GdipDisposeImage(image_dest);
1085 expect(Ok, stat);
1088 static void test_testcontrol(void)
1090 GpStatus stat;
1091 DWORD param;
1093 param = 0;
1094 stat = GdipTestControl(TestControlGetBuildNumber, &param);
1095 expect(Ok, stat);
1096 ok(param != 0, "Build number expected, got %u\n", param);
1099 static void test_fromhicon(void)
1101 static const BYTE bmp_bits[1024];
1102 HBITMAP hbmMask, hbmColor;
1103 ICONINFO info;
1104 HICON hIcon;
1105 GpStatus stat;
1106 GpBitmap *bitmap = NULL;
1107 UINT dim;
1108 ImageType type;
1109 PixelFormat format;
1111 /* NULL */
1112 stat = GdipCreateBitmapFromHICON(NULL, NULL);
1113 expect(InvalidParameter, stat);
1114 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
1115 expect(InvalidParameter, stat);
1117 /* color icon 1 bit */
1118 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
1119 ok(hbmMask != 0, "CreateBitmap failed\n");
1120 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
1121 ok(hbmColor != 0, "CreateBitmap failed\n");
1122 info.fIcon = TRUE;
1123 info.xHotspot = 8;
1124 info.yHotspot = 8;
1125 info.hbmMask = hbmMask;
1126 info.hbmColor = hbmColor;
1127 hIcon = CreateIconIndirect(&info);
1128 ok(hIcon != 0, "CreateIconIndirect failed\n");
1129 DeleteObject(hbmMask);
1130 DeleteObject(hbmColor);
1132 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
1133 ok(stat == Ok ||
1134 broken(stat == InvalidParameter), /* Win98 */
1135 "Expected Ok, got %.8x\n", stat);
1136 if(stat == Ok){
1137 /* check attributes */
1138 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
1139 expect(Ok, stat);
1140 expect(16, dim);
1141 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
1142 expect(Ok, stat);
1143 expect(16, dim);
1144 stat = GdipGetImageType((GpImage*)bitmap, &type);
1145 expect(Ok, stat);
1146 expect(ImageTypeBitmap, type);
1147 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
1148 expect(Ok, stat);
1149 expect(PixelFormat32bppARGB, format);
1150 /* raw format */
1151 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
1152 GdipDisposeImage((GpImage*)bitmap);
1154 DestroyIcon(hIcon);
1156 /* color icon 8 bpp */
1157 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
1158 ok(hbmMask != 0, "CreateBitmap failed\n");
1159 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
1160 ok(hbmColor != 0, "CreateBitmap failed\n");
1161 info.fIcon = TRUE;
1162 info.xHotspot = 8;
1163 info.yHotspot = 8;
1164 info.hbmMask = hbmMask;
1165 info.hbmColor = hbmColor;
1166 hIcon = CreateIconIndirect(&info);
1167 ok(hIcon != 0, "CreateIconIndirect failed\n");
1168 DeleteObject(hbmMask);
1169 DeleteObject(hbmColor);
1171 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
1172 expect(Ok, stat);
1173 if(stat == Ok){
1174 /* check attributes */
1175 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
1176 expect(Ok, stat);
1177 expect(16, dim);
1178 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
1179 expect(Ok, stat);
1180 expect(16, dim);
1181 stat = GdipGetImageType((GpImage*)bitmap, &type);
1182 expect(Ok, stat);
1183 expect(ImageTypeBitmap, type);
1184 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
1185 expect(Ok, stat);
1186 expect(PixelFormat32bppARGB, format);
1187 /* raw format */
1188 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
1189 GdipDisposeImage((GpImage*)bitmap);
1191 DestroyIcon(hIcon);
1194 /* 1x1 pixel png */
1195 static const unsigned char pngimage[285] = {
1196 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
1197 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
1198 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
1199 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
1200 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
1201 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
1202 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
1204 /* 1x1 pixel gif */
1205 static const unsigned char gifimage[35] = {
1206 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
1207 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
1208 0x01,0x00,0x3b
1210 /* 1x1 pixel bmp */
1211 static const unsigned char bmpimage[66] = {
1212 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
1213 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
1214 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
1215 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
1216 0x00,0x00
1218 /* 1x1 pixel jpg */
1219 static const unsigned char jpgimage[285] = {
1220 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
1221 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
1222 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
1223 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
1224 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
1225 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
1226 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
1227 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1228 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1229 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
1230 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
1231 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1232 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
1233 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
1234 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1235 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
1236 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
1237 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
1239 /* 1x1 pixel tiff */
1240 static const unsigned char tiffimage[] = {
1241 0x49,0x49,0x2a,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xfe,0x00,
1242 0x04,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x00,0x01,0x00,
1243 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1244 0x00,0x00,0x02,0x01,0x03,0x00,0x03,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0x03,0x01,
1245 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,0x01,0x03,0x00,0x01,0x00,
1246 0x00,0x00,0x02,0x00,0x00,0x00,0x0d,0x01,0x02,0x00,0x1b,0x00,0x00,0x00,0xd8,0x00,
1247 0x00,0x00,0x11,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x12,0x01,
1248 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x01,0x03,0x00,0x01,0x00,
1249 0x00,0x00,0x03,0x00,0x00,0x00,0x16,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x40,0x00,
1250 0x00,0x00,0x17,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1a,0x01,
1251 0x05,0x00,0x01,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x1b,0x01,0x05,0x00,0x01,0x00,
1252 0x00,0x00,0xfc,0x00,0x00,0x00,0x1c,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1253 0x00,0x00,0x28,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
1254 0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x6d,0x65,
1255 0x68,0x2f,0x44,0x65,0x73,0x6b,0x74,0x6f,0x70,0x2f,0x74,0x65,0x73,0x74,0x2e,0x74,
1256 0x69,0x66,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,
1257 0x00,0x00,0x00,0x01
1259 /* 320x320 twip wmf */
1260 static const unsigned char wmfimage[180] = {
1261 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
1262 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
1263 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
1264 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
1265 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
1266 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
1267 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
1268 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
1269 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
1270 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
1271 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
1272 0x00,0x00,0x00,0x00
1274 static void test_getrawformat(void)
1276 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
1277 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
1278 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
1279 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
1280 test_bufferrawformat((void*)tiffimage, sizeof(tiffimage), &ImageFormatTIFF, __LINE__, FALSE);
1281 test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
1284 static void test_loadwmf(void)
1286 LPSTREAM stream;
1287 HGLOBAL hglob;
1288 LPBYTE data;
1289 HRESULT hres;
1290 GpStatus stat;
1291 GpImage *img;
1292 GpRectF bounds;
1293 GpUnit unit;
1294 REAL res = 12345.0;
1295 MetafileHeader header;
1297 hglob = GlobalAlloc (0, sizeof(wmfimage));
1298 data = GlobalLock (hglob);
1299 memcpy(data, wmfimage, sizeof(wmfimage));
1300 GlobalUnlock(hglob); data = NULL;
1302 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1303 ok(hres == S_OK, "Failed to create a stream\n");
1304 if(hres != S_OK) return;
1306 stat = GdipLoadImageFromStream(stream, &img);
1307 ok(stat == Ok, "Failed to create a Bitmap\n");
1308 if(stat != Ok){
1309 IStream_Release(stream);
1310 return;
1313 IStream_Release(stream);
1315 stat = GdipGetImageBounds(img, &bounds, &unit);
1316 expect(Ok, stat);
1317 todo_wine expect(UnitPixel, unit);
1318 expectf(0.0, bounds.X);
1319 expectf(0.0, bounds.Y);
1320 todo_wine expectf(320.0, bounds.Width);
1321 todo_wine expectf(320.0, bounds.Height);
1323 stat = GdipGetImageHorizontalResolution(img, &res);
1324 expect(Ok, stat);
1325 todo_wine expectf(1440.0, res);
1327 stat = GdipGetImageVerticalResolution(img, &res);
1328 expect(Ok, stat);
1329 todo_wine expectf(1440.0, res);
1331 memset(&header, 0, sizeof(header));
1332 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1333 expect(Ok, stat);
1334 if (stat == Ok)
1336 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1337 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1338 todo_wine expect(0x300, header.Version);
1339 expect(0, header.EmfPlusFlags);
1340 todo_wine expectf(1440.0, header.DpiX);
1341 todo_wine expectf(1440.0, header.DpiY);
1342 expect(0, header.X);
1343 expect(0, header.Y);
1344 todo_wine expect(320, header.Width);
1345 todo_wine expect(320, header.Height);
1346 todo_wine expect(1, U(header).WmfHeader.mtType);
1347 expect(0, header.EmfPlusHeaderSize);
1348 expect(0, header.LogicalDpiX);
1349 expect(0, header.LogicalDpiY);
1352 GdipDisposeImage(img);
1355 static void test_createfromwmf(void)
1357 HMETAFILE hwmf;
1358 GpImage *img;
1359 GpStatus stat;
1360 GpRectF bounds;
1361 GpUnit unit;
1362 REAL res = 12345.0;
1363 MetafileHeader header;
1365 hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
1366 wmfimage+sizeof(WmfPlaceableFileHeader));
1367 ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
1369 stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
1370 (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
1371 expect(Ok, stat);
1373 stat = GdipGetImageBounds(img, &bounds, &unit);
1374 expect(Ok, stat);
1375 expect(UnitPixel, unit);
1376 expectf(0.0, bounds.X);
1377 expectf(0.0, bounds.Y);
1378 expectf(320.0, bounds.Width);
1379 expectf(320.0, bounds.Height);
1381 stat = GdipGetImageHorizontalResolution(img, &res);
1382 expect(Ok, stat);
1383 expectf(1440.0, res);
1385 stat = GdipGetImageVerticalResolution(img, &res);
1386 expect(Ok, stat);
1387 expectf(1440.0, res);
1389 memset(&header, 0, sizeof(header));
1390 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1391 expect(Ok, stat);
1392 if (stat == Ok)
1394 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1395 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1396 todo_wine expect(0x300, header.Version);
1397 expect(0, header.EmfPlusFlags);
1398 todo_wine expectf(1440.0, header.DpiX);
1399 todo_wine expectf(1440.0, header.DpiY);
1400 expect(0, header.X);
1401 expect(0, header.Y);
1402 todo_wine expect(320, header.Width);
1403 todo_wine expect(320, header.Height);
1404 todo_wine expect(1, U(header).WmfHeader.mtType);
1405 expect(0, header.EmfPlusHeaderSize);
1406 expect(0, header.LogicalDpiX);
1407 expect(0, header.LogicalDpiY);
1410 GdipDisposeImage(img);
1413 static void test_resolution(void)
1415 GpStatus stat;
1416 GpBitmap *bitmap;
1417 REAL res=-1.0;
1418 HDC screendc;
1419 int screenxres, screenyres;
1421 /* create Bitmap */
1422 stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
1423 expect(Ok, stat);
1425 /* test invalid values */
1426 stat = GdipGetImageHorizontalResolution(NULL, &res);
1427 expect(InvalidParameter, stat);
1429 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
1430 expect(InvalidParameter, stat);
1432 stat = GdipGetImageVerticalResolution(NULL, &res);
1433 expect(InvalidParameter, stat);
1435 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
1436 expect(InvalidParameter, stat);
1438 stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
1439 expect(InvalidParameter, stat);
1441 stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
1442 expect(InvalidParameter, stat);
1444 /* defaults to screen resolution */
1445 screendc = GetDC(0);
1447 screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
1448 screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
1450 ReleaseDC(0, screendc);
1452 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1453 expect(Ok, stat);
1454 expectf((REAL)screenxres, res);
1456 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1457 expect(Ok, stat);
1458 expectf((REAL)screenyres, res);
1460 /* test changing the resolution */
1461 stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
1462 expect(Ok, stat);
1464 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1465 expect(Ok, stat);
1466 expectf(screenxres*2.0, res);
1468 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1469 expect(Ok, stat);
1470 expectf(screenyres*3.0, res);
1472 stat = GdipDisposeImage((GpImage*)bitmap);
1473 expect(Ok, stat);
1476 static void test_createhbitmap(void)
1478 GpStatus stat;
1479 GpBitmap *bitmap;
1480 HBITMAP hbitmap, oldhbitmap;
1481 BITMAP bm;
1482 int ret;
1483 HDC hdc;
1484 COLORREF pixel;
1485 BYTE bits[640];
1487 memset(bits, 0x68, 640);
1489 /* create Bitmap */
1490 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
1491 expect(Ok, stat);
1493 /* test NULL values */
1494 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
1495 expect(InvalidParameter, stat);
1497 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
1498 expect(InvalidParameter, stat);
1500 /* create HBITMAP */
1501 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
1502 expect(Ok, stat);
1504 if (stat == Ok)
1506 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
1507 expect(sizeof(BITMAP), ret);
1509 expect(0, bm.bmType);
1510 expect(10, bm.bmWidth);
1511 expect(20, bm.bmHeight);
1512 expect(40, bm.bmWidthBytes);
1513 expect(1, bm.bmPlanes);
1514 expect(32, bm.bmBitsPixel);
1515 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1517 if (bm.bmBits)
1519 DWORD val = *(DWORD*)bm.bmBits;
1520 ok(val == 0xff686868, "got %x, expected 0xff686868\n", val);
1523 hdc = CreateCompatibleDC(NULL);
1525 oldhbitmap = SelectObject(hdc, hbitmap);
1526 pixel = GetPixel(hdc, 5, 5);
1527 SelectObject(hdc, oldhbitmap);
1529 DeleteDC(hdc);
1531 expect(0x686868, pixel);
1533 DeleteObject(hbitmap);
1536 stat = GdipDisposeImage((GpImage*)bitmap);
1537 expect(Ok, stat);
1539 /* create alpha Bitmap */
1540 stat = GdipCreateBitmapFromScan0(8, 20, 32, PixelFormat32bppARGB, bits, &bitmap);
1541 expect(Ok, stat);
1543 /* create HBITMAP */
1544 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
1545 expect(Ok, stat);
1547 if (stat == Ok)
1549 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
1550 expect(sizeof(BITMAP), ret);
1552 expect(0, bm.bmType);
1553 expect(8, bm.bmWidth);
1554 expect(20, bm.bmHeight);
1555 expect(32, bm.bmWidthBytes);
1556 expect(1, bm.bmPlanes);
1557 expect(32, bm.bmBitsPixel);
1558 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1560 if (bm.bmBits)
1562 DWORD val = *(DWORD*)bm.bmBits;
1563 ok(val == 0x682a2a2a, "got %x, expected 0x682a2a2a\n", val);
1566 hdc = CreateCompatibleDC(NULL);
1568 oldhbitmap = SelectObject(hdc, hbitmap);
1569 pixel = GetPixel(hdc, 5, 5);
1570 SelectObject(hdc, oldhbitmap);
1572 DeleteDC(hdc);
1574 expect(0x2a2a2a, pixel);
1576 DeleteObject(hbitmap);
1579 stat = GdipDisposeImage((GpImage*)bitmap);
1580 expect(Ok, stat);
1583 static void test_getthumbnail(void)
1585 GpStatus stat;
1586 GpImage *bitmap1, *bitmap2;
1587 UINT width, height;
1589 stat = GdipGetImageThumbnail(NULL, 0, 0, &bitmap2, NULL, NULL);
1590 expect(InvalidParameter, stat);
1592 stat = GdipCreateBitmapFromScan0(128, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1593 expect(Ok, stat);
1595 stat = GdipGetImageThumbnail(bitmap1, 0, 0, NULL, NULL, NULL);
1596 expect(InvalidParameter, stat);
1598 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1599 expect(Ok, stat);
1601 if (stat == Ok)
1603 stat = GdipGetImageWidth(bitmap2, &width);
1604 expect(Ok, stat);
1605 expect(120, width);
1607 stat = GdipGetImageHeight(bitmap2, &height);
1608 expect(Ok, stat);
1609 expect(120, height);
1611 GdipDisposeImage(bitmap2);
1614 GdipDisposeImage(bitmap1);
1617 stat = GdipCreateBitmapFromScan0(64, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1618 expect(Ok, stat);
1620 stat = GdipGetImageThumbnail(bitmap1, 32, 32, &bitmap2, NULL, NULL);
1621 expect(Ok, stat);
1623 if (stat == Ok)
1625 stat = GdipGetImageWidth(bitmap2, &width);
1626 expect(Ok, stat);
1627 expect(32, width);
1629 stat = GdipGetImageHeight(bitmap2, &height);
1630 expect(Ok, stat);
1631 expect(32, height);
1633 GdipDisposeImage(bitmap2);
1636 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1637 expect(Ok, stat);
1639 if (stat == Ok)
1641 stat = GdipGetImageWidth(bitmap2, &width);
1642 expect(Ok, stat);
1643 expect(120, width);
1645 stat = GdipGetImageHeight(bitmap2, &height);
1646 expect(Ok, stat);
1647 expect(120, height);
1649 GdipDisposeImage(bitmap2);
1652 GdipDisposeImage(bitmap1);
1655 static void test_getsetpixel(void)
1657 GpStatus stat;
1658 GpBitmap *bitmap;
1659 ARGB color;
1660 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1661 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1663 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1664 expect(Ok, stat);
1666 /* null parameters */
1667 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1668 expect(InvalidParameter, stat);
1670 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1671 expect(InvalidParameter, stat);
1673 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1674 expect(InvalidParameter, stat);
1676 /* out of bounds */
1677 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1678 expect(InvalidParameter, stat);
1680 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1681 expect(InvalidParameter, stat);
1683 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1684 ok(stat == InvalidParameter ||
1685 broken(stat == Ok), /* Older gdiplus */
1686 "Expected InvalidParameter, got %.8x\n", stat);
1688 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1689 ok(stat == InvalidParameter ||
1690 broken(stat == Ok), /* Older gdiplus */
1691 "Expected InvalidParameter, got %.8x\n", stat);
1693 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1694 expect(InvalidParameter, stat);
1696 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1697 expect(InvalidParameter, stat);
1699 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1700 expect(InvalidParameter, stat);
1702 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1703 expect(InvalidParameter, stat);
1705 /* valid use */
1706 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1707 expect(Ok, stat);
1708 expect(0xffffffff, color);
1710 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1711 expect(Ok, stat);
1712 expect(0xff0000ff, color);
1714 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1715 expect(Ok, stat);
1717 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1718 expect(Ok, stat);
1720 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1721 expect(Ok, stat);
1722 expect(0xff676869, color);
1724 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1725 expect(Ok, stat);
1726 expect(0xff474849, color);
1728 stat = GdipDisposeImage((GpImage*)bitmap);
1729 expect(Ok, stat);
1732 static void check_halftone_palette(ColorPalette *palette)
1734 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1735 UINT i;
1737 for (i=0; i<palette->Count; i++)
1739 ARGB expected=0xff000000;
1740 if (i<8)
1742 if (i&1) expected |= 0x800000;
1743 if (i&2) expected |= 0x8000;
1744 if (i&4) expected |= 0x80;
1746 else if (i == 8)
1748 expected = 0xffc0c0c0;
1750 else if (i < 16)
1752 if (i&1) expected |= 0xff0000;
1753 if (i&2) expected |= 0xff00;
1754 if (i&4) expected |= 0xff;
1756 else if (i < 40)
1758 expected = 0x00000000;
1760 else
1762 expected |= halftone_values[(i-40)%6];
1763 expected |= halftone_values[((i-40)/6)%6] << 8;
1764 expected |= halftone_values[((i-40)/36)%6] << 16;
1766 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1767 expected, palette->Entries[i], i, palette->Count);
1771 static void test_palette(void)
1773 GpStatus stat;
1774 GpBitmap *bitmap;
1775 INT size;
1776 BYTE buffer[1040];
1777 ColorPalette *palette=(ColorPalette*)buffer;
1778 ARGB color=0;
1780 /* test initial palette from non-indexed bitmap */
1781 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1782 expect(Ok, stat);
1784 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1785 expect(Ok, stat);
1786 expect(sizeof(UINT)*2+sizeof(ARGB), size);
1788 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1789 expect(Ok, stat);
1790 expect(0, palette->Count);
1792 /* test setting palette on not-indexed bitmap */
1793 palette->Count = 3;
1795 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1796 expect(Ok, stat);
1798 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1799 expect(Ok, stat);
1800 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1802 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1803 expect(Ok, stat);
1804 expect(3, palette->Count);
1806 GdipDisposeImage((GpImage*)bitmap);
1808 /* test initial palette on 1-bit bitmap */
1809 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1810 expect(Ok, stat);
1812 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1813 expect(Ok, stat);
1814 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1816 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1817 expect(Ok, stat);
1818 expect(PaletteFlagsGrayScale, palette->Flags);
1819 expect(2, palette->Count);
1821 expect(0xff000000, palette->Entries[0]);
1822 expect(0xffffffff, palette->Entries[1]);
1824 /* test getting/setting pixels */
1825 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1826 expect(Ok, stat);
1827 expect(0xff000000, color);
1829 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1830 ok((stat == Ok) ||
1831 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1833 if (stat == Ok)
1835 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1836 expect(Ok, stat);
1837 expect(0xffffffff, color);
1840 GdipDisposeImage((GpImage*)bitmap);
1842 /* test initial palette on 4-bit bitmap */
1843 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1844 expect(Ok, stat);
1846 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1847 expect(Ok, stat);
1848 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1850 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1851 expect(Ok, stat);
1852 expect(0, palette->Flags);
1853 expect(16, palette->Count);
1855 check_halftone_palette(palette);
1857 /* test getting/setting pixels */
1858 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1859 expect(Ok, stat);
1860 expect(0xff000000, color);
1862 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
1863 ok((stat == Ok) ||
1864 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1866 if (stat == Ok)
1868 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1869 expect(Ok, stat);
1870 expect(0xffff00ff, color);
1873 GdipDisposeImage((GpImage*)bitmap);
1875 /* test initial palette on 8-bit bitmap */
1876 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1877 expect(Ok, stat);
1879 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1880 expect(Ok, stat);
1881 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1883 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1884 expect(Ok, stat);
1885 expect(PaletteFlagsHalftone, palette->Flags);
1886 expect(256, palette->Count);
1888 check_halftone_palette(palette);
1890 /* test getting/setting pixels */
1891 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1892 expect(Ok, stat);
1893 expect(0xff000000, color);
1895 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
1896 ok((stat == Ok) ||
1897 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1899 if (stat == Ok)
1901 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1902 expect(Ok, stat);
1903 expect(0xffcccccc, color);
1906 /* test setting/getting a different palette */
1907 palette->Entries[1] = 0xffcccccc;
1909 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1910 expect(Ok, stat);
1912 palette->Entries[1] = 0;
1914 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1915 expect(Ok, stat);
1916 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1918 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1919 expect(Ok, stat);
1920 expect(PaletteFlagsHalftone, palette->Flags);
1921 expect(256, palette->Count);
1922 expect(0xffcccccc, palette->Entries[1]);
1924 /* test count < 256 */
1925 palette->Flags = 12345;
1926 palette->Count = 3;
1928 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1929 expect(Ok, stat);
1931 palette->Entries[1] = 0;
1932 palette->Entries[3] = 0xdeadbeef;
1934 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1935 expect(Ok, stat);
1936 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1938 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1939 expect(Ok, stat);
1940 expect(12345, palette->Flags);
1941 expect(3, palette->Count);
1942 expect(0xffcccccc, palette->Entries[1]);
1943 expect(0xdeadbeef, palette->Entries[3]);
1945 /* test count > 256 */
1946 palette->Count = 257;
1948 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1949 ok(stat == InvalidParameter ||
1950 broken(stat == Ok), /* Old gdiplus behavior */
1951 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1953 GdipDisposeImage((GpImage*)bitmap);
1956 static void test_colormatrix(void)
1958 GpStatus stat;
1959 ColorMatrix colormatrix, graymatrix;
1960 GpImageAttributes *imageattr;
1961 const ColorMatrix identity = {{
1962 {1.0,0.0,0.0,0.0,0.0},
1963 {0.0,1.0,0.0,0.0,0.0},
1964 {0.0,0.0,1.0,0.0,0.0},
1965 {0.0,0.0,0.0,1.0,0.0},
1966 {0.0,0.0,0.0,0.0,1.0}}};
1967 const ColorMatrix double_red = {{
1968 {2.0,0.0,0.0,0.0,0.0},
1969 {0.0,1.0,0.0,0.0,0.0},
1970 {0.0,0.0,1.0,0.0,0.0},
1971 {0.0,0.0,0.0,1.0,0.0},
1972 {0.0,0.0,0.0,0.0,1.0}}};
1973 const ColorMatrix asymmetric = {{
1974 {0.0,1.0,0.0,0.0,0.0},
1975 {0.0,0.0,1.0,0.0,0.0},
1976 {0.0,0.0,0.0,1.0,0.0},
1977 {1.0,0.0,0.0,0.0,0.0},
1978 {0.0,0.0,0.0,0.0,1.0}}};
1979 GpBitmap *bitmap1, *bitmap2;
1980 GpGraphics *graphics;
1981 ARGB color;
1983 colormatrix = identity;
1984 graymatrix = identity;
1986 stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
1987 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1988 expect(InvalidParameter, stat);
1990 stat = GdipCreateImageAttributes(&imageattr);
1991 expect(Ok, stat);
1993 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1994 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1995 expect(Ok, stat);
1997 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1998 TRUE, NULL, NULL, ColorMatrixFlagsDefault);
1999 expect(InvalidParameter, stat);
2001 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2002 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
2003 expect(Ok, stat);
2005 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2006 TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
2007 expect(Ok, stat);
2009 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2010 TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
2011 expect(InvalidParameter, stat);
2013 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2014 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
2015 expect(Ok, stat);
2017 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2018 TRUE, &colormatrix, &graymatrix, 3);
2019 expect(InvalidParameter, stat);
2021 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
2022 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
2023 expect(InvalidParameter, stat);
2025 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
2026 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
2027 expect(InvalidParameter, stat);
2029 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2030 FALSE, NULL, NULL, ColorMatrixFlagsDefault);
2031 expect(Ok, stat);
2033 /* Drawing a bitmap transforms the colors */
2034 colormatrix = double_red;
2035 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2036 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
2037 expect(Ok, stat);
2039 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppARGB, NULL, &bitmap1);
2040 expect(Ok, stat);
2042 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppARGB, NULL, &bitmap2);
2043 expect(Ok, stat);
2045 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ccee);
2046 expect(Ok, stat);
2048 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2049 expect(Ok, stat);
2051 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2052 UnitPixel, imageattr, NULL, NULL);
2053 expect(Ok, stat);
2055 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2056 expect(Ok, stat);
2057 expect(0xff80ccee, color);
2059 colormatrix = asymmetric;
2060 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2061 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
2062 expect(Ok, stat);
2064 stat = GdipBitmapSetPixel(bitmap2, 0, 0, 0);
2065 expect(Ok, stat);
2067 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2068 UnitPixel, imageattr, NULL, NULL);
2069 expect(Ok, stat);
2071 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2072 expect(Ok, stat);
2073 ok(color_match(0xeeff40cc, color, 3), "expected 0xeeff40cc, got 0x%08x\n", color);
2075 GdipDeleteGraphics(graphics);
2076 GdipDisposeImage((GpImage*)bitmap1);
2077 GdipDisposeImage((GpImage*)bitmap2);
2078 GdipDisposeImageAttributes(imageattr);
2081 static void test_gamma(void)
2083 GpStatus stat;
2084 GpImageAttributes *imageattr;
2085 GpBitmap *bitmap1, *bitmap2;
2086 GpGraphics *graphics;
2087 ARGB color;
2089 stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
2090 expect(InvalidParameter, stat);
2092 stat = GdipCreateImageAttributes(&imageattr);
2093 expect(Ok, stat);
2095 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
2096 expect(Ok, stat);
2098 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
2099 expect(InvalidParameter, stat);
2101 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
2102 expect(InvalidParameter, stat);
2104 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
2105 expect(InvalidParameter, stat);
2107 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
2108 expect(Ok, stat);
2110 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
2111 expect(Ok, stat);
2113 /* Drawing a bitmap transforms the colors */
2114 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
2115 expect(Ok, stat);
2117 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
2118 expect(Ok, stat);
2120 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
2121 expect(Ok, stat);
2123 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
2124 expect(Ok, stat);
2126 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2127 expect(Ok, stat);
2129 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2130 UnitPixel, imageattr, NULL, NULL);
2131 expect(Ok, stat);
2133 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2134 expect(Ok, stat);
2135 ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
2137 GdipDeleteGraphics(graphics);
2138 GdipDisposeImage((GpImage*)bitmap1);
2139 GdipDisposeImage((GpImage*)bitmap2);
2140 GdipDisposeImageAttributes(imageattr);
2143 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
2144 static const unsigned char gifanimation[72] = {
2145 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
2146 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
2147 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
2148 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
2149 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
2152 static void test_multiframegif(void)
2154 LPSTREAM stream;
2155 HGLOBAL hglob;
2156 LPBYTE data;
2157 HRESULT hres;
2158 GpStatus stat;
2159 GpBitmap *bmp;
2160 ARGB color;
2161 UINT count;
2162 GUID dimension;
2164 /* Test frame functions with an animated GIF */
2165 hglob = GlobalAlloc (0, sizeof(gifanimation));
2166 data = GlobalLock (hglob);
2167 memcpy(data, gifanimation, sizeof(gifanimation));
2168 GlobalUnlock(hglob);
2170 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
2171 ok(hres == S_OK, "Failed to create a stream\n");
2172 if(hres != S_OK) return;
2174 stat = GdipCreateBitmapFromStream(stream, &bmp);
2175 ok(stat == Ok, "Failed to create a Bitmap\n");
2176 if(stat != Ok){
2177 IStream_Release(stream);
2178 return;
2181 /* Bitmap starts at frame 0 */
2182 color = 0xdeadbeef;
2183 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2184 expect(Ok, stat);
2185 expect(0xffffffff, color);
2187 /* Check that we get correct metadata */
2188 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
2189 expect(Ok, stat);
2190 expect(1, count);
2192 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
2193 expect(Ok, stat);
2194 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
2196 count = 12345;
2197 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2198 expect(Ok, stat);
2199 todo_wine expect(2, count);
2201 /* SelectActiveFrame overwrites our current data */
2202 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
2203 expect(Ok, stat);
2205 color = 0xdeadbeef;
2206 GdipBitmapGetPixel(bmp, 0, 0, &color);
2207 expect(Ok, stat);
2208 todo_wine expect(0xff000000, color);
2210 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2211 expect(Ok, stat);
2213 color = 0xdeadbeef;
2214 GdipBitmapGetPixel(bmp, 0, 0, &color);
2215 expect(Ok, stat);
2216 expect(0xffffffff, color);
2218 /* Write over the image data */
2219 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
2220 expect(Ok, stat);
2222 /* Switching to the same frame does not overwrite our changes */
2223 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2224 expect(Ok, stat);
2226 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2227 expect(Ok, stat);
2228 expect(0xff000000, color);
2230 /* But switching to another frame and back does */
2231 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
2232 expect(Ok, stat);
2234 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2235 expect(Ok, stat);
2237 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2238 expect(Ok, stat);
2239 todo_wine expect(0xffffffff, color);
2241 GdipDisposeImage((GpImage*)bmp);
2242 IStream_Release(stream);
2244 /* Test with a non-animated gif */
2245 hglob = GlobalAlloc (0, sizeof(gifimage));
2246 data = GlobalLock (hglob);
2247 memcpy(data, gifimage, sizeof(gifimage));
2248 GlobalUnlock(hglob);
2250 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
2251 ok(hres == S_OK, "Failed to create a stream\n");
2252 if(hres != S_OK) return;
2254 stat = GdipCreateBitmapFromStream(stream, &bmp);
2255 ok(stat == Ok, "Failed to create a Bitmap\n");
2256 if(stat != Ok){
2257 IStream_Release(stream);
2258 return;
2261 /* Check metadata */
2262 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
2263 expect(Ok, stat);
2264 expect(1, count);
2266 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
2267 expect(Ok, stat);
2268 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
2270 count = 12345;
2271 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2272 expect(Ok, stat);
2273 expect(1, count);
2275 GdipDisposeImage((GpImage*)bmp);
2276 IStream_Release(stream);
2279 static void test_rotateflip(void)
2281 GpImage *bitmap;
2282 GpStatus stat;
2283 BYTE bits[24];
2284 static const BYTE orig_bits[24] = {
2285 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
2286 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
2287 UINT width, height;
2288 ARGB color;
2290 memcpy(bits, orig_bits, sizeof(bits));
2291 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2292 expect(Ok, stat);
2294 stat = GdipImageRotateFlip(bitmap, Rotate90FlipNone);
2295 expect(Ok, stat);
2297 stat = GdipGetImageWidth(bitmap, &width);
2298 expect(Ok, stat);
2299 stat = GdipGetImageHeight(bitmap, &height);
2300 expect(Ok, stat);
2301 expect(2, width);
2302 expect(3, height);
2304 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2305 expect(Ok, stat);
2306 expect(0xff00ffff, color);
2308 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 0, &color);
2309 expect(Ok, stat);
2310 expect(0xffff0000, color);
2312 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 2, &color);
2313 expect(Ok, stat);
2314 expect(0xffffff00, color);
2316 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 2, &color);
2317 expect(Ok, stat);
2318 expect(0xff0000ff, color);
2320 expect(0, bits[0]);
2321 expect(0, bits[1]);
2322 expect(0xff, bits[2]);
2324 GdipDisposeImage(bitmap);
2326 memcpy(bits, orig_bits, sizeof(bits));
2327 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2328 expect(Ok, stat);
2330 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipX);
2331 expect(Ok, stat);
2333 stat = GdipGetImageWidth(bitmap, &width);
2334 expect(Ok, stat);
2335 stat = GdipGetImageHeight(bitmap, &height);
2336 expect(Ok, stat);
2337 expect(3, width);
2338 expect(2, height);
2340 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2341 expect(Ok, stat);
2342 expect(0xff0000ff, color);
2344 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2345 expect(Ok, stat);
2346 expect(0xffff0000, color);
2348 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2349 expect(Ok, stat);
2350 expect(0xffffff00, color);
2352 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2353 expect(Ok, stat);
2354 expect(0xff00ffff, color);
2356 expect(0, bits[0]);
2357 expect(0, bits[1]);
2358 expect(0xff, bits[2]);
2360 GdipDisposeImage(bitmap);
2362 memcpy(bits, orig_bits, sizeof(bits));
2363 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2364 expect(Ok, stat);
2366 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipY);
2367 expect(Ok, stat);
2369 stat = GdipGetImageWidth(bitmap, &width);
2370 expect(Ok, stat);
2371 stat = GdipGetImageHeight(bitmap, &height);
2372 expect(Ok, stat);
2373 expect(3, width);
2374 expect(2, height);
2376 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2377 expect(Ok, stat);
2378 expect(0xff00ffff, color);
2380 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2381 expect(Ok, stat);
2382 expect(0xffffff00, color);
2384 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2385 expect(Ok, stat);
2386 expect(0xffff0000, color);
2388 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2389 expect(Ok, stat);
2390 expect(0xff0000ff, color);
2392 expect(0, bits[0]);
2393 expect(0, bits[1]);
2394 expect(0xff, bits[2]);
2396 GdipDisposeImage(bitmap);
2399 static void test_remaptable(void)
2401 GpStatus stat;
2402 GpImageAttributes *imageattr;
2403 GpBitmap *bitmap1, *bitmap2;
2404 GpGraphics *graphics;
2405 ARGB color;
2406 ColorMap *map;
2408 map = GdipAlloc(sizeof(ColorMap));
2410 map->oldColor.Argb = 0xff00ff00;
2411 map->newColor.Argb = 0xffff00ff;
2413 stat = GdipSetImageAttributesRemapTable(NULL, ColorAdjustTypeDefault, TRUE, 1, map);
2414 expect(InvalidParameter, stat);
2416 stat = GdipCreateImageAttributes(&imageattr);
2417 expect(Ok, stat);
2419 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, NULL);
2420 expect(InvalidParameter, stat);
2422 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeCount, TRUE, 1, map);
2423 expect(InvalidParameter, stat);
2425 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeAny, TRUE, 1, map);
2426 expect(InvalidParameter, stat);
2428 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 0, map);
2429 expect(InvalidParameter, stat);
2431 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, FALSE, 0, NULL);
2432 expect(Ok, stat);
2434 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, map);
2435 expect(Ok, stat);
2437 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
2438 expect(Ok, stat);
2440 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
2441 expect(Ok, stat);
2443 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff00ff00);
2444 expect(Ok, stat);
2446 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2447 expect(Ok, stat);
2449 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2450 UnitPixel, imageattr, NULL, NULL);
2451 expect(Ok, stat);
2453 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2454 expect(Ok, stat);
2455 ok(color_match(0xffff00ff, color, 1), "Expected ffff00ff, got %.8x\n", color);
2457 GdipDeleteGraphics(graphics);
2458 GdipDisposeImage((GpImage*)bitmap1);
2459 GdipDisposeImage((GpImage*)bitmap2);
2460 GdipDisposeImageAttributes(imageattr);
2461 GdipFree(map);
2464 static void test_colorkey(void)
2466 GpStatus stat;
2467 GpImageAttributes *imageattr;
2468 GpBitmap *bitmap1, *bitmap2;
2469 GpGraphics *graphics;
2470 ARGB color;
2472 stat = GdipSetImageAttributesColorKeys(NULL, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2473 expect(InvalidParameter, stat);
2475 stat = GdipCreateImageAttributes(&imageattr);
2476 expect(Ok, stat);
2478 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeCount, TRUE, 0xff405060, 0xff708090);
2479 expect(InvalidParameter, stat);
2481 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeAny, TRUE, 0xff405060, 0xff708090);
2482 expect(InvalidParameter, stat);
2484 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2485 expect(Ok, stat);
2487 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap1);
2488 expect(Ok, stat);
2490 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap2);
2491 expect(Ok, stat);
2493 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0x20405060);
2494 expect(Ok, stat);
2496 stat = GdipBitmapSetPixel(bitmap1, 0, 1, 0x40506070);
2497 expect(Ok, stat);
2499 stat = GdipBitmapSetPixel(bitmap1, 1, 0, 0x60708090);
2500 expect(Ok, stat);
2502 stat = GdipBitmapSetPixel(bitmap1, 1, 1, 0xffffffff);
2503 expect(Ok, stat);
2505 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2506 expect(Ok, stat);
2508 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,2,2, 0,0,2,2,
2509 UnitPixel, imageattr, NULL, NULL);
2510 expect(Ok, stat);
2512 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2513 expect(Ok, stat);
2514 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2516 stat = GdipBitmapGetPixel(bitmap2, 0, 1, &color);
2517 expect(Ok, stat);
2518 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2520 stat = GdipBitmapGetPixel(bitmap2, 1, 0, &color);
2521 expect(Ok, stat);
2522 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2524 stat = GdipBitmapGetPixel(bitmap2, 1, 1, &color);
2525 expect(Ok, stat);
2526 ok(color_match(0xffffffff, color, 1), "Expected ffff00ff, got %.8x\n", color);
2528 GdipDeleteGraphics(graphics);
2529 GdipDisposeImage((GpImage*)bitmap1);
2530 GdipDisposeImage((GpImage*)bitmap2);
2531 GdipDisposeImageAttributes(imageattr);
2534 static void test_dispose(void)
2536 GpStatus stat;
2537 GpImage *image;
2538 char invalid_image[256];
2540 stat = GdipDisposeImage(NULL);
2541 expect(InvalidParameter, stat);
2543 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, (GpBitmap**)&image);
2544 expect(Ok, stat);
2546 stat = GdipDisposeImage(image);
2547 expect(Ok, stat);
2549 stat = GdipDisposeImage(image);
2550 expect(ObjectBusy, stat);
2552 memset(invalid_image, 0, 256);
2553 stat = GdipDisposeImage((GpImage*)invalid_image);
2554 expect(ObjectBusy, stat);
2557 START_TEST(image)
2559 struct GdiplusStartupInput gdiplusStartupInput;
2560 ULONG_PTR gdiplusToken;
2562 gdiplusStartupInput.GdiplusVersion = 1;
2563 gdiplusStartupInput.DebugEventCallback = NULL;
2564 gdiplusStartupInput.SuppressBackgroundThread = 0;
2565 gdiplusStartupInput.SuppressExternalCodecs = 0;
2567 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
2569 test_Scan0();
2570 test_FromGdiDib();
2571 test_GetImageDimension();
2572 test_GdipImageGetFrameDimensionsCount();
2573 test_LoadingImages();
2574 test_SavingImages();
2575 test_encoders();
2576 test_LockBits();
2577 test_LockBits_UserBuf();
2578 test_GdipCreateBitmapFromHBITMAP();
2579 test_GdipGetImageFlags();
2580 test_GdipCloneImage();
2581 test_testcontrol();
2582 test_fromhicon();
2583 test_getrawformat();
2584 test_loadwmf();
2585 test_createfromwmf();
2586 test_resolution();
2587 test_createhbitmap();
2588 test_getthumbnail();
2589 test_getsetpixel();
2590 test_palette();
2591 test_colormatrix();
2592 test_gamma();
2593 test_multiframegif();
2594 test_rotateflip();
2595 test_remaptable();
2596 test_colorkey();
2597 test_dispose();
2599 GdiplusShutdown(gdiplusToken);