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
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;
37 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
39 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
41 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
45 static void expect_guid(REFGUID expected, REFGUID got, int line, BOOL todo)
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);
56 todo_wine ok_(__FILE__, line)(IsEqualGUID(expected, got), "Expected %s, got %s\n", buffer2, buffer);
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)
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)
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");
93 IStream_Release(stream);
97 expect_rawformat(expected, img, line, todo);
99 GdipDisposeImage(img);
100 IStream_Release(stream);
103 static void test_Scan0(void)
110 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
112 ok(NULL != bm, "Expected bitmap to be initialized\n");
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" );
132 stat = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, buff, &bm);
134 ok(NULL != bm, "Expected bitmap to be initialized\n");
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" );
149 stat = GdipCreateBitmapFromScan0(10, 10, -8, PixelFormat24bppRGB, buff, &bm);
151 ok(NULL != bm, "Expected bitmap to be initialized\n");
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)
166 BYTE rbmi[sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)];
167 BITMAPINFO *bmi = (BITMAPINFO*)rbmi;
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);
192 ok(NULL != bm, "Expected bitmap to be initialized\n");
195 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
197 expect(PixelFormat32bppRGB, format);
199 GdipDisposeImage((GpImage*)bm);
202 bmi->bmiHeader.biBitCount = 24;
203 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
205 ok(NULL != bm, "Expected bitmap to be initialized\n");
208 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
210 expect(PixelFormat24bppRGB, format);
212 GdipDisposeImage((GpImage*)bm);
215 bmi->bmiHeader.biBitCount = 16;
216 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
218 ok(NULL != bm, "Expected bitmap to be initialized\n");
221 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
223 expect(PixelFormat16bppRGB555, format);
225 GdipDisposeImage((GpImage*)bm);
228 bmi->bmiHeader.biBitCount = 8;
229 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
231 ok(NULL != bm, "Expected bitmap to be initialized\n");
234 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
236 expect(PixelFormat8bppIndexed, format);
238 GdipDisposeImage((GpImage*)bm);
241 bmi->bmiHeader.biBitCount = 4;
242 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
244 ok(NULL != bm, "Expected bitmap to be initialized\n");
247 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
249 expect(PixelFormat4bppIndexed, format);
251 GdipDisposeImage((GpImage*)bm);
254 bmi->bmiHeader.biBitCount = 1;
255 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
257 ok(NULL != bm, "Expected bitmap to be initialized\n");
260 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
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)
276 const REAL WIDTH = 10.0, HEIGHT = 20.0;
279 bm = (GpBitmap*)0xdeadbeef;
280 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
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);
296 stat = GdipGetImageDimension((GpImage*)bm,&w,&h);
300 GdipDisposeImage((GpImage*)bm);
303 static void test_GdipImageGetFrameDimensionsCount(void)
307 const REAL WIDTH = 10.0, HEIGHT = 20.0;
309 GUID dimension = {0};
313 bm = (GpBitmap*)0xdeadbeef;
314 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
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);
326 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,&w);
330 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 1);
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 */
346 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, NULL);
347 expect(InvalidParameter, stat);
350 stat = GdipImageGetFrameCount((GpImage*)bm, NULL, &count);
354 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, &count);
358 GdipBitmapSetPixel(bm, 0, 0, 0xffffffff);
360 stat = GdipImageSelectActiveFrame((GpImage*)bm, &dimension, 0);
363 /* SelectActiveFrame has no effect on image data of memory bitmaps */
365 GdipBitmapGetPixel(bm, 0, 0, &color);
366 expect(0xffffffff, color);
368 GdipDisposeImage((GpImage*)bm);
371 static void test_LoadingImages(void)
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)
400 const REAL WIDTH = 10.0, HEIGHT = 20.0;
402 ImageCodecInfo *codecs;
403 static const CHAR filenameA[] = "a.bmp";
404 static const WCHAR filename[] = { 'a','.','b','m','p',0 };
408 stat = GdipSaveImageToFile(0, 0, 0, 0);
409 expect(InvalidParameter, stat);
412 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
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);
437 GdipDisposeImage((GpImage*)bm);
440 /* re-load and check image stats */
441 stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
443 if (stat != Ok) goto cleanup;
445 stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
446 if (stat != Ok) goto cleanup;
454 GdipDisposeImage((GpImage*)bm);
455 ok(DeleteFileA(filenameA), "Delete failed.\n");
458 static void test_encoders(void)
463 ImageCodecInfo *codecs;
467 static const CHAR bmp_format[] = "BMP";
469 stat = GdipGetImageEncodersSize(&n, &s);
472 codecs = GdipAlloc(s);
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);
492 for (i = 0; i < n; i++)
496 WideCharToMultiByte(CP_ACP, 0, codecs[i].FormatDescription, -1,
499 if (CompareStringA(LOCALE_SYSTEM_DEFAULT, 0,
501 bmp_format, -1) == CSTR_EQUAL) {
507 ok(FALSE, "No BMP codec found.\n");
512 static void test_LockBits(void)
518 const INT WIDTH = 10, HEIGHT = 20;
522 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
530 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffc30000);
533 stat = GdipBitmapSetPixel(bm, 2, 8, 0xff480000);
537 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
541 expect(0xc3, ((BYTE*)bd.Scan0)[2]);
542 expect(0x48, ((BYTE*)bd.Scan0)[2 + bd.Stride * 5]);
544 ((char*)bd.Scan0)[2] = 0xff;
546 stat = GdipBitmapUnlockBits(bm, &bd);
550 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
552 expect(0xffff0000, color);
554 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffc30000);
557 /* read-only, with NULL rect -> whole bitmap lock */
558 stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
560 expect(bd.Width, WIDTH);
561 expect(bd.Height, HEIGHT);
564 ((char*)bd.Scan0)[2 + 2*3 + 3*bd.Stride] = 0xff;
566 stat = GdipBitmapUnlockBits(bm, &bd);
570 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
572 expect(0xffff0000, color);
574 /* read-only, consecutive */
575 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
579 stat = GdipBitmapUnlockBits(bm, &bd);
583 stat = GdipDisposeImage((GpImage*)bm);
585 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
589 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
591 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
592 expect(WrongState, stat);
594 stat = GdipBitmapUnlockBits(bm, &bd);
597 stat = GdipDisposeImage((GpImage*)bm);
599 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
602 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffff0000);
605 stat = GdipBitmapSetPixel(bm, 2, 8, 0xffc30000);
608 /* write, no conversion */
609 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
613 /* all bits are readable, inside the rect or not */
614 expect(0xff, ((BYTE*)bd.Scan0)[2]);
615 expect(0xc3, ((BYTE*)bd.Scan0)[2 + bd.Stride * 5]);
617 stat = GdipBitmapUnlockBits(bm, &bd);
621 /* read, conversion */
622 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat32bppARGB, &bd);
626 expect(0xff, ((BYTE*)bd.Scan0)[2]);
628 /* Areas outside the rectangle appear to be uninitialized */
629 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
631 ((BYTE*)bd.Scan0)[2] = 0xc3;
633 stat = GdipBitmapUnlockBits(bm, &bd);
637 /* writes do not work in read mode if there was a conversion */
638 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
640 expect(0xffff0000, color);
642 /* read/write, conversion */
643 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeWrite, PixelFormat32bppARGB, &bd);
647 expect(0xff, ((BYTE*)bd.Scan0)[2]);
649 /* Areas outside the rectangle appear to be uninitialized */
650 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
652 stat = GdipBitmapUnlockBits(bm, &bd);
656 /* write, conversion */
657 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat32bppARGB, &bd);
663 /* This is completely uninitialized. */
664 ok(0xff != ((BYTE*)bd.Scan0)[2], "original image bits are readable\n");
665 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
668 stat = GdipBitmapUnlockBits(bm, &bd);
672 stat = GdipDisposeImage((GpImage*)bm);
674 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
677 /* write, no modification */
678 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
682 stat = GdipBitmapUnlockBits(bm, &bd);
686 /* write, consecutive */
687 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
691 stat = GdipBitmapUnlockBits(bm, &bd);
695 stat = GdipDisposeImage((GpImage*)bm);
697 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
701 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
706 ((char*)bd.Scan0)[2] = 0xff;
708 stat = GdipBitmapUnlockBits(bm, &bd);
712 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
714 expect(0xffff0000, color);
716 stat = GdipDisposeImage((GpImage*)bm);
720 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
722 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
724 stat = GdipDisposeImage((GpImage*)bm);
728 static void test_LockBits_UserBuf(void)
734 const INT WIDTH = 10, HEIGHT = 20;
739 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat32bppARGB, NULL, &bm);
742 memset(bits, 0xaa, sizeof(bits));
751 bd.Stride = WIDTH * 4;
752 bd.PixelFormat = PixelFormat32bppARGB;
753 bd.Scan0 = &bits[2+3*WIDTH];
754 bd.Reserved = 0xaaaaaaaa;
757 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
758 todo_wine expect(Ok, stat);
760 expect(0xaaaaaaaa, bits[0]);
761 todo_wine expect(0, bits[2+3*WIDTH]);
763 bits[2+3*WIDTH] = 0xdeadbeef;
766 stat = GdipBitmapUnlockBits(bm, &bd);
770 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
775 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
776 todo_wine expect(Ok, stat);
778 expect(0xdeadbeef, bits[2+3*WIDTH]);
779 bits[2+3*WIDTH] = 0x12345678;
782 stat = GdipBitmapUnlockBits(bm, &bd);
786 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
788 todo_wine expect(0x12345678, color);
793 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeWrite|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
794 todo_wine expect(Ok, stat);
796 todo_wine expect(0x12345678, bits[2+3*WIDTH]);
797 bits[2+3*WIDTH] = 0xdeadbeef;
800 stat = GdipBitmapUnlockBits(bm, &bd);
804 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
806 todo_wine expect(0xdeadbeef, color);
808 stat = GdipDisposeImage((GpImage*)bm);
812 static void test_GdipCreateBitmapFromHBITMAP(void)
814 GpBitmap* gpbm = NULL;
816 HPALETTE hpal = NULL;
819 LOGPALETTE* LogPal = NULL;
821 const REAL WIDTH1 = 5;
822 const REAL HEIGHT1 = 15;
823 const REAL WIDTH2 = 10;
824 const REAL HEIGHT2 = 20;
829 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
830 expect(InvalidParameter, stat);
832 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
833 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
834 expect(InvalidParameter, stat);
836 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
838 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
839 expectf(WIDTH1, width);
840 expectf(HEIGHT1, height);
842 GdipDisposeImage((GpImage*)gpbm);
845 memset(buff, 0, sizeof(buff));
846 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
847 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
850 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
852 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
853 expectf(WIDTH2, width);
854 expectf(HEIGHT2, height);
856 GdipDisposeImage((GpImage*)gpbm);
859 hdc = CreateCompatibleDC(0);
860 ok(hdc != NULL, "CreateCompatibleDC failed\n");
861 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
862 bmi.bmiHeader.biHeight = HEIGHT1;
863 bmi.bmiHeader.biWidth = WIDTH1;
864 bmi.bmiHeader.biBitCount = 24;
865 bmi.bmiHeader.biPlanes = 1;
866 bmi.bmiHeader.biCompression = BI_RGB;
868 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
869 ok(hbm != NULL, "CreateDIBSection failed\n");
873 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
875 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
876 expectf(WIDTH1, width);
877 expectf(HEIGHT1, height);
880 /* test whether writing to the bitmap affects the original */
881 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
886 GdipDisposeImage((GpImage*)gpbm);
889 LogPal = GdipAlloc(sizeof(LOGPALETTE));
890 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
891 LogPal->palVersion = 0x300;
892 LogPal->palNumEntries = 1;
893 hpal = CreatePalette(LogPal);
894 ok(hpal != NULL, "CreatePalette failed\n");
897 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
903 GdipDisposeImage((GpImage*)gpbm);
909 static void test_GdipGetImageFlags(void)
915 img = (GpImage*)0xdeadbeef;
917 stat = GdipGetImageFlags(NULL, NULL);
918 expect(InvalidParameter, stat);
920 stat = GdipGetImageFlags(NULL, &flags);
921 expect(InvalidParameter, stat);
923 stat = GdipGetImageFlags(img, NULL);
924 expect(InvalidParameter, stat);
926 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, (GpBitmap**)&img);
928 stat = GdipGetImageFlags(img, &flags);
930 expect(ImageFlagsHasAlpha, flags);
931 GdipDisposeImage(img);
933 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, (GpBitmap**)&img);
935 stat = GdipGetImageFlags(img, &flags);
937 expect(ImageFlagsHasAlpha, flags);
938 GdipDisposeImage(img);
940 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, (GpBitmap**)&img);
942 stat = GdipGetImageFlags(img, &flags);
944 expect(ImageFlagsHasAlpha, flags);
945 GdipDisposeImage(img);
947 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, (GpBitmap**)&img);
949 stat = GdipGetImageFlags(img, &flags);
951 expect(ImageFlagsNone, flags);
952 GdipDisposeImage(img);
954 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, (GpBitmap**)&img);
956 stat = GdipGetImageFlags(img, &flags);
958 expect(ImageFlagsNone, flags);
959 GdipDisposeImage(img);
961 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, (GpBitmap**)&img);
963 stat = GdipGetImageFlags(img, &flags);
965 expect(ImageFlagsNone, flags);
966 GdipDisposeImage(img);
968 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppARGB1555, NULL, (GpBitmap**)&img);
970 stat = GdipGetImageFlags(img, &flags);
972 expect(ImageFlagsHasAlpha, flags);
973 GdipDisposeImage(img);
975 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, (GpBitmap**)&img);
977 stat = GdipGetImageFlags(img, &flags);
979 expect(ImageFlagsNone, flags);
980 GdipDisposeImage(img);
982 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, (GpBitmap**)&img);
984 stat = GdipGetImageFlags(img, &flags);
986 expect(ImageFlagsNone, flags);
987 GdipDisposeImage(img);
989 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, (GpBitmap**)&img);
991 stat = GdipGetImageFlags(img, &flags);
993 expect(ImageFlagsHasAlpha, flags);
994 GdipDisposeImage(img);
996 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppPARGB, NULL, (GpBitmap**)&img);
998 stat = GdipGetImageFlags(img, &flags);
1000 expect(ImageFlagsHasAlpha, flags);
1001 GdipDisposeImage(img);
1003 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, (GpBitmap**)&img);
1007 stat = GdipGetImageFlags(img, &flags);
1009 expect(ImageFlagsNone, flags);
1010 GdipDisposeImage(img);
1013 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, (GpBitmap**)&img);
1018 stat = GdipGetImageFlags(img, &flags);
1020 expect(ImageFlagsHasAlpha, flags);
1021 GdipDisposeImage(img);
1024 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, (GpBitmap**)&img);
1029 stat = GdipGetImageFlags(img, &flags);
1031 expect(ImageFlagsHasAlpha, flags);
1032 GdipDisposeImage(img);
1036 static void test_GdipCloneImage(void)
1042 GpImage *image_src, *image_dest = NULL;
1043 const INT WIDTH = 10, HEIGHT = 20;
1045 /* Create an image, clone it, delete the original, make sure the copy works */
1046 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
1048 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
1050 image_src = ((GpImage*)bm);
1051 stat = GdipCloneImage(image_src, &image_dest);
1053 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
1055 stat = GdipDisposeImage((GpImage*)bm);
1057 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
1060 /* Treat FP values carefully */
1061 expectf((REAL)WIDTH, rectF.Width);
1062 expectf((REAL)HEIGHT, rectF.Height);
1064 stat = GdipDisposeImage(image_dest);
1068 static void test_testcontrol(void)
1074 stat = GdipTestControl(TestControlGetBuildNumber, ¶m);
1076 ok(param != 0, "Build number expected, got %u\n", param);
1079 static void test_fromhicon(void)
1081 static const BYTE bmp_bits[1024];
1082 HBITMAP hbmMask, hbmColor;
1086 GpBitmap *bitmap = NULL;
1092 stat = GdipCreateBitmapFromHICON(NULL, NULL);
1093 expect(InvalidParameter, stat);
1094 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
1095 expect(InvalidParameter, stat);
1097 /* color icon 1 bit */
1098 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
1099 ok(hbmMask != 0, "CreateBitmap failed\n");
1100 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
1101 ok(hbmColor != 0, "CreateBitmap failed\n");
1105 info.hbmMask = hbmMask;
1106 info.hbmColor = hbmColor;
1107 hIcon = CreateIconIndirect(&info);
1108 ok(hIcon != 0, "CreateIconIndirect failed\n");
1109 DeleteObject(hbmMask);
1110 DeleteObject(hbmColor);
1112 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
1114 broken(stat == InvalidParameter), /* Win98 */
1115 "Expected Ok, got %.8x\n", stat);
1117 /* check attributes */
1118 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
1121 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
1124 stat = GdipGetImageType((GpImage*)bitmap, &type);
1126 expect(ImageTypeBitmap, type);
1127 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
1129 expect(PixelFormat32bppARGB, format);
1131 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
1132 GdipDisposeImage((GpImage*)bitmap);
1136 /* color icon 8 bpp */
1137 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
1138 ok(hbmMask != 0, "CreateBitmap failed\n");
1139 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
1140 ok(hbmColor != 0, "CreateBitmap failed\n");
1144 info.hbmMask = hbmMask;
1145 info.hbmColor = hbmColor;
1146 hIcon = CreateIconIndirect(&info);
1147 ok(hIcon != 0, "CreateIconIndirect failed\n");
1148 DeleteObject(hbmMask);
1149 DeleteObject(hbmColor);
1151 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
1154 /* check attributes */
1155 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
1158 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
1161 stat = GdipGetImageType((GpImage*)bitmap, &type);
1163 expect(ImageTypeBitmap, type);
1164 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
1166 expect(PixelFormat32bppARGB, format);
1168 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
1169 GdipDisposeImage((GpImage*)bitmap);
1175 static const unsigned char pngimage[285] = {
1176 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
1177 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
1178 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
1179 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
1180 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
1181 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
1182 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
1185 static const unsigned char gifimage[35] = {
1186 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
1187 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
1191 static const unsigned char bmpimage[66] = {
1192 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
1193 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
1194 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
1195 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
1199 static const unsigned char jpgimage[285] = {
1200 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
1201 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
1202 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
1203 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
1204 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
1205 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
1206 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
1207 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1208 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1209 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
1210 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
1211 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1212 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
1213 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
1214 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1215 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
1216 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
1217 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
1219 /* 1x1 pixel tiff */
1220 static const unsigned char tiffimage[] = {
1221 0x49,0x49,0x2a,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xfe,0x00,
1222 0x04,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x00,0x01,0x00,
1223 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1224 0x00,0x00,0x02,0x01,0x03,0x00,0x03,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0x03,0x01,
1225 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,0x01,0x03,0x00,0x01,0x00,
1226 0x00,0x00,0x02,0x00,0x00,0x00,0x0d,0x01,0x02,0x00,0x1b,0x00,0x00,0x00,0xd8,0x00,
1227 0x00,0x00,0x11,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x12,0x01,
1228 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x01,0x03,0x00,0x01,0x00,
1229 0x00,0x00,0x03,0x00,0x00,0x00,0x16,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x40,0x00,
1230 0x00,0x00,0x17,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1a,0x01,
1231 0x05,0x00,0x01,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x1b,0x01,0x05,0x00,0x01,0x00,
1232 0x00,0x00,0xfc,0x00,0x00,0x00,0x1c,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1233 0x00,0x00,0x28,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
1234 0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x6d,0x65,
1235 0x68,0x2f,0x44,0x65,0x73,0x6b,0x74,0x6f,0x70,0x2f,0x74,0x65,0x73,0x74,0x2e,0x74,
1236 0x69,0x66,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,
1239 /* 320x320 twip wmf */
1240 static const unsigned char wmfimage[180] = {
1241 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
1242 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
1243 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
1244 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
1245 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
1246 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
1247 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
1248 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
1249 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
1250 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
1251 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
1254 static void test_getrawformat(void)
1256 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
1257 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
1258 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
1259 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
1260 test_bufferrawformat((void*)tiffimage, sizeof(tiffimage), &ImageFormatTIFF, __LINE__, FALSE);
1261 test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
1264 static void test_loadwmf(void)
1275 MetafileHeader header;
1277 hglob = GlobalAlloc (0, sizeof(wmfimage));
1278 data = GlobalLock (hglob);
1279 memcpy(data, wmfimage, sizeof(wmfimage));
1280 GlobalUnlock(hglob); data = NULL;
1282 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1283 ok(hres == S_OK, "Failed to create a stream\n");
1284 if(hres != S_OK) return;
1286 stat = GdipLoadImageFromStream(stream, &img);
1287 ok(stat == Ok, "Failed to create a Bitmap\n");
1289 IStream_Release(stream);
1293 IStream_Release(stream);
1295 stat = GdipGetImageBounds(img, &bounds, &unit);
1297 todo_wine expect(UnitPixel, unit);
1298 expectf(0.0, bounds.X);
1299 expectf(0.0, bounds.Y);
1300 todo_wine expectf(320.0, bounds.Width);
1301 todo_wine expectf(320.0, bounds.Height);
1303 stat = GdipGetImageHorizontalResolution(img, &res);
1305 todo_wine expectf(1440.0, res);
1307 stat = GdipGetImageVerticalResolution(img, &res);
1309 todo_wine expectf(1440.0, res);
1311 memset(&header, 0, sizeof(header));
1312 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1316 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1317 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1318 todo_wine expect(0x300, header.Version);
1319 expect(0, header.EmfPlusFlags);
1320 todo_wine expectf(1440.0, header.DpiX);
1321 todo_wine expectf(1440.0, header.DpiY);
1322 expect(0, header.X);
1323 expect(0, header.Y);
1324 todo_wine expect(320, header.Width);
1325 todo_wine expect(320, header.Height);
1326 todo_wine expect(1, U(header).WmfHeader.mtType);
1327 expect(0, header.EmfPlusHeaderSize);
1328 expect(0, header.LogicalDpiX);
1329 expect(0, header.LogicalDpiY);
1332 GdipDisposeImage(img);
1335 static void test_createfromwmf(void)
1343 MetafileHeader header;
1345 hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
1346 wmfimage+sizeof(WmfPlaceableFileHeader));
1347 ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
1349 stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
1350 (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
1353 stat = GdipGetImageBounds(img, &bounds, &unit);
1355 expect(UnitPixel, unit);
1356 expectf(0.0, bounds.X);
1357 expectf(0.0, bounds.Y);
1358 expectf(320.0, bounds.Width);
1359 expectf(320.0, bounds.Height);
1361 stat = GdipGetImageHorizontalResolution(img, &res);
1363 expectf(1440.0, res);
1365 stat = GdipGetImageVerticalResolution(img, &res);
1367 expectf(1440.0, res);
1369 memset(&header, 0, sizeof(header));
1370 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1374 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1375 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1376 todo_wine expect(0x300, header.Version);
1377 expect(0, header.EmfPlusFlags);
1378 todo_wine expectf(1440.0, header.DpiX);
1379 todo_wine expectf(1440.0, header.DpiY);
1380 expect(0, header.X);
1381 expect(0, header.Y);
1382 todo_wine expect(320, header.Width);
1383 todo_wine expect(320, header.Height);
1384 todo_wine expect(1, U(header).WmfHeader.mtType);
1385 expect(0, header.EmfPlusHeaderSize);
1386 expect(0, header.LogicalDpiX);
1387 expect(0, header.LogicalDpiY);
1390 GdipDisposeImage(img);
1393 static void test_resolution(void)
1399 int screenxres, screenyres;
1402 stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
1405 /* test invalid values */
1406 stat = GdipGetImageHorizontalResolution(NULL, &res);
1407 expect(InvalidParameter, stat);
1409 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
1410 expect(InvalidParameter, stat);
1412 stat = GdipGetImageVerticalResolution(NULL, &res);
1413 expect(InvalidParameter, stat);
1415 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
1416 expect(InvalidParameter, stat);
1418 stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
1419 expect(InvalidParameter, stat);
1421 stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
1422 expect(InvalidParameter, stat);
1424 /* defaults to screen resolution */
1425 screendc = GetDC(0);
1427 screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
1428 screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
1430 ReleaseDC(0, screendc);
1432 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1434 expectf((REAL)screenxres, res);
1436 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1438 expectf((REAL)screenyres, res);
1440 /* test changing the resolution */
1441 stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
1444 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1446 expectf(screenxres*2.0, res);
1448 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1450 expectf(screenyres*3.0, res);
1452 stat = GdipDisposeImage((GpImage*)bitmap);
1456 static void test_createhbitmap(void)
1460 HBITMAP hbitmap, oldhbitmap;
1467 memset(bits, 0x68, 640);
1470 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
1473 /* test NULL values */
1474 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
1475 expect(InvalidParameter, stat);
1477 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
1478 expect(InvalidParameter, stat);
1480 /* create HBITMAP */
1481 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
1486 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
1487 expect(sizeof(BITMAP), ret);
1489 expect(0, bm.bmType);
1490 expect(10, bm.bmWidth);
1491 expect(20, bm.bmHeight);
1492 expect(40, bm.bmWidthBytes);
1493 expect(1, bm.bmPlanes);
1494 expect(32, bm.bmBitsPixel);
1495 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1497 hdc = CreateCompatibleDC(NULL);
1499 oldhbitmap = SelectObject(hdc, hbitmap);
1500 pixel = GetPixel(hdc, 5, 5);
1501 SelectObject(hdc, oldhbitmap);
1505 expect(0x686868, pixel);
1507 DeleteObject(hbitmap);
1510 stat = GdipDisposeImage((GpImage*)bitmap);
1514 static void test_getthumbnail(void)
1517 GpImage *bitmap1, *bitmap2;
1520 stat = GdipGetImageThumbnail(NULL, 0, 0, &bitmap2, NULL, NULL);
1521 expect(InvalidParameter, stat);
1523 stat = GdipCreateBitmapFromScan0(128, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1526 stat = GdipGetImageThumbnail(bitmap1, 0, 0, NULL, NULL, NULL);
1527 expect(InvalidParameter, stat);
1529 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1534 stat = GdipGetImageWidth(bitmap2, &width);
1538 stat = GdipGetImageHeight(bitmap2, &height);
1540 expect(120, height);
1542 GdipDisposeImage(bitmap2);
1545 GdipDisposeImage(bitmap1);
1548 stat = GdipCreateBitmapFromScan0(64, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1551 stat = GdipGetImageThumbnail(bitmap1, 32, 32, &bitmap2, NULL, NULL);
1556 stat = GdipGetImageWidth(bitmap2, &width);
1560 stat = GdipGetImageHeight(bitmap2, &height);
1564 GdipDisposeImage(bitmap2);
1567 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1572 stat = GdipGetImageWidth(bitmap2, &width);
1576 stat = GdipGetImageHeight(bitmap2, &height);
1578 expect(120, height);
1580 GdipDisposeImage(bitmap2);
1583 GdipDisposeImage(bitmap1);
1586 static void test_getsetpixel(void)
1591 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1592 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1594 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1597 /* null parameters */
1598 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1599 expect(InvalidParameter, stat);
1601 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1602 expect(InvalidParameter, stat);
1604 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1605 expect(InvalidParameter, stat);
1608 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1609 expect(InvalidParameter, stat);
1611 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1612 expect(InvalidParameter, stat);
1614 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1615 ok(stat == InvalidParameter ||
1616 broken(stat == Ok), /* Older gdiplus */
1617 "Expected InvalidParameter, got %.8x\n", stat);
1619 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1620 ok(stat == InvalidParameter ||
1621 broken(stat == Ok), /* Older gdiplus */
1622 "Expected InvalidParameter, got %.8x\n", stat);
1624 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1625 expect(InvalidParameter, stat);
1627 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1628 expect(InvalidParameter, stat);
1630 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1631 expect(InvalidParameter, stat);
1633 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1634 expect(InvalidParameter, stat);
1637 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1639 expect(0xffffffff, color);
1641 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1643 expect(0xff0000ff, color);
1645 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1648 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1651 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1653 expect(0xff676869, color);
1655 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1657 expect(0xff474849, color);
1659 stat = GdipDisposeImage((GpImage*)bitmap);
1663 static void check_halftone_palette(ColorPalette *palette)
1665 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1668 for (i=0; i<palette->Count; i++)
1670 ARGB expected=0xff000000;
1673 if (i&1) expected |= 0x800000;
1674 if (i&2) expected |= 0x8000;
1675 if (i&4) expected |= 0x80;
1679 expected = 0xffc0c0c0;
1683 if (i&1) expected |= 0xff0000;
1684 if (i&2) expected |= 0xff00;
1685 if (i&4) expected |= 0xff;
1689 expected = 0x00000000;
1693 expected |= halftone_values[(i-40)%6];
1694 expected |= halftone_values[((i-40)/6)%6] << 8;
1695 expected |= halftone_values[((i-40)/36)%6] << 16;
1697 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1698 expected, palette->Entries[i], i, palette->Count);
1702 static void test_palette(void)
1708 ColorPalette *palette=(ColorPalette*)buffer;
1711 /* test initial palette from non-indexed bitmap */
1712 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1715 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1717 expect(sizeof(UINT)*2+sizeof(ARGB), size);
1719 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1721 expect(0, palette->Count);
1723 /* test setting palette on not-indexed bitmap */
1726 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1729 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1731 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1733 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1735 expect(3, palette->Count);
1737 GdipDisposeImage((GpImage*)bitmap);
1739 /* test initial palette on 1-bit bitmap */
1740 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1743 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1745 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1747 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1749 expect(PaletteFlagsGrayScale, palette->Flags);
1750 expect(2, palette->Count);
1752 expect(0xff000000, palette->Entries[0]);
1753 expect(0xffffffff, palette->Entries[1]);
1755 /* test getting/setting pixels */
1756 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1758 expect(0xff000000, color);
1760 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1762 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1766 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1768 expect(0xffffffff, color);
1771 GdipDisposeImage((GpImage*)bitmap);
1773 /* test initial palette on 4-bit bitmap */
1774 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1777 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1779 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1781 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1783 expect(0, palette->Flags);
1784 expect(16, palette->Count);
1786 check_halftone_palette(palette);
1788 /* test getting/setting pixels */
1789 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1791 expect(0xff000000, color);
1793 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
1795 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1799 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1801 expect(0xffff00ff, color);
1804 GdipDisposeImage((GpImage*)bitmap);
1806 /* test initial palette on 8-bit bitmap */
1807 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1810 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1812 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1814 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1816 expect(PaletteFlagsHalftone, palette->Flags);
1817 expect(256, palette->Count);
1819 check_halftone_palette(palette);
1821 /* test getting/setting pixels */
1822 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1824 expect(0xff000000, color);
1826 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
1828 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1832 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1834 expect(0xffcccccc, color);
1837 /* test setting/getting a different palette */
1838 palette->Entries[1] = 0xffcccccc;
1840 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1843 palette->Entries[1] = 0;
1845 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1847 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1849 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1851 expect(PaletteFlagsHalftone, palette->Flags);
1852 expect(256, palette->Count);
1853 expect(0xffcccccc, palette->Entries[1]);
1855 /* test count < 256 */
1856 palette->Flags = 12345;
1859 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1862 palette->Entries[1] = 0;
1863 palette->Entries[3] = 0xdeadbeef;
1865 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1867 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1869 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1871 expect(12345, palette->Flags);
1872 expect(3, palette->Count);
1873 expect(0xffcccccc, palette->Entries[1]);
1874 expect(0xdeadbeef, palette->Entries[3]);
1876 /* test count > 256 */
1877 palette->Count = 257;
1879 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1880 ok(stat == InvalidParameter ||
1881 broken(stat == Ok), /* Old gdiplus behavior */
1882 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1884 GdipDisposeImage((GpImage*)bitmap);
1887 static void test_colormatrix(void)
1890 ColorMatrix colormatrix, graymatrix;
1891 GpImageAttributes *imageattr;
1892 const ColorMatrix identity = {{
1893 {1.0,0.0,0.0,0.0,0.0},
1894 {0.0,1.0,0.0,0.0,0.0},
1895 {0.0,0.0,1.0,0.0,0.0},
1896 {0.0,0.0,0.0,1.0,0.0},
1897 {0.0,0.0,0.0,0.0,1.0}}};
1898 const ColorMatrix double_red = {{
1899 {2.0,0.0,0.0,0.0,0.0},
1900 {0.0,1.0,0.0,0.0,0.0},
1901 {0.0,0.0,1.0,0.0,0.0},
1902 {0.0,0.0,0.0,1.0,0.0},
1903 {0.0,0.0,0.0,0.0,1.0}}};
1904 GpBitmap *bitmap1, *bitmap2;
1905 GpGraphics *graphics;
1908 colormatrix = identity;
1909 graymatrix = identity;
1911 stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
1912 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1913 expect(InvalidParameter, stat);
1915 stat = GdipCreateImageAttributes(&imageattr);
1918 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1919 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1922 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1923 TRUE, NULL, NULL, ColorMatrixFlagsDefault);
1924 expect(InvalidParameter, stat);
1926 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1927 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1930 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1931 TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
1934 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1935 TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
1936 expect(InvalidParameter, stat);
1938 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1939 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
1942 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1943 TRUE, &colormatrix, &graymatrix, 3);
1944 expect(InvalidParameter, stat);
1946 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
1947 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1948 expect(InvalidParameter, stat);
1950 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
1951 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1952 expect(InvalidParameter, stat);
1954 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1955 FALSE, NULL, NULL, ColorMatrixFlagsDefault);
1958 /* Drawing a bitmap transforms the colors */
1959 colormatrix = double_red;
1960 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1961 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1964 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1967 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1970 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ffff);
1973 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1976 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1977 UnitPixel, imageattr, NULL, NULL);
1980 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1982 todo_wine expect(0xff80ffff, color);
1984 GdipDeleteGraphics(graphics);
1985 GdipDisposeImage((GpImage*)bitmap1);
1986 GdipDisposeImage((GpImage*)bitmap2);
1987 GdipDisposeImageAttributes(imageattr);
1990 static void test_gamma(void)
1993 GpImageAttributes *imageattr;
1994 GpBitmap *bitmap1, *bitmap2;
1995 GpGraphics *graphics;
1998 stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
1999 expect(InvalidParameter, stat);
2001 stat = GdipCreateImageAttributes(&imageattr);
2004 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
2007 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
2008 expect(InvalidParameter, stat);
2010 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
2011 expect(InvalidParameter, stat);
2013 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
2014 expect(InvalidParameter, stat);
2016 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
2019 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
2022 /* Drawing a bitmap transforms the colors */
2023 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
2026 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
2029 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
2032 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
2035 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2038 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2039 UnitPixel, imageattr, NULL, NULL);
2042 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2044 todo_wine ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
2046 GdipDeleteGraphics(graphics);
2047 GdipDisposeImage((GpImage*)bitmap1);
2048 GdipDisposeImage((GpImage*)bitmap2);
2049 GdipDisposeImageAttributes(imageattr);
2052 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
2053 static const unsigned char gifanimation[72] = {
2054 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
2055 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
2056 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
2057 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
2058 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
2061 static void test_multiframegif(void)
2073 /* Test frame functions with an animated GIF */
2074 hglob = GlobalAlloc (0, sizeof(gifanimation));
2075 data = GlobalLock (hglob);
2076 memcpy(data, gifanimation, sizeof(gifanimation));
2077 GlobalUnlock(hglob);
2079 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
2080 ok(hres == S_OK, "Failed to create a stream\n");
2081 if(hres != S_OK) return;
2083 stat = GdipCreateBitmapFromStream(stream, &bmp);
2084 ok(stat == Ok, "Failed to create a Bitmap\n");
2086 IStream_Release(stream);
2090 /* Bitmap starts at frame 0 */
2092 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2094 expect(0xffffffff, color);
2096 /* Check that we get correct metadata */
2097 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
2101 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
2103 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
2106 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2108 todo_wine expect(2, count);
2110 /* SelectActiveFrame overwrites our current data */
2111 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
2115 GdipBitmapGetPixel(bmp, 0, 0, &color);
2117 todo_wine expect(0xff000000, color);
2119 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2123 GdipBitmapGetPixel(bmp, 0, 0, &color);
2125 expect(0xffffffff, color);
2127 /* Write over the image data */
2128 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
2131 /* Switching to the same frame does not overwrite our changes */
2132 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2135 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2137 expect(0xff000000, color);
2139 /* But switching to another frame and back does */
2140 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
2143 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2146 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2148 todo_wine expect(0xffffffff, color);
2150 GdipDisposeImage((GpImage*)bmp);
2151 IStream_Release(stream);
2153 /* Test with a non-animated gif */
2154 hglob = GlobalAlloc (0, sizeof(gifimage));
2155 data = GlobalLock (hglob);
2156 memcpy(data, gifimage, sizeof(gifimage));
2157 GlobalUnlock(hglob);
2159 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
2160 ok(hres == S_OK, "Failed to create a stream\n");
2161 if(hres != S_OK) return;
2163 stat = GdipCreateBitmapFromStream(stream, &bmp);
2164 ok(stat == Ok, "Failed to create a Bitmap\n");
2166 IStream_Release(stream);
2170 /* Check metadata */
2171 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
2175 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
2177 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
2180 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2184 GdipDisposeImage((GpImage*)bmp);
2185 IStream_Release(stream);
2188 static void test_rotateflip(void)
2193 static const BYTE orig_bits[24] = {
2194 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
2195 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
2199 memcpy(bits, orig_bits, sizeof(bits));
2200 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2203 stat = GdipImageRotateFlip(bitmap, Rotate90FlipNone);
2206 stat = GdipGetImageWidth(bitmap, &width);
2208 stat = GdipGetImageHeight(bitmap, &height);
2213 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2215 expect(0xff00ffff, color);
2217 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 0, &color);
2219 expect(0xffff0000, color);
2221 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 2, &color);
2223 expect(0xffffff00, color);
2225 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 2, &color);
2227 expect(0xff0000ff, color);
2231 expect(0xff, bits[2]);
2233 GdipDisposeImage(bitmap);
2235 memcpy(bits, orig_bits, sizeof(bits));
2236 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2239 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipX);
2242 stat = GdipGetImageWidth(bitmap, &width);
2244 stat = GdipGetImageHeight(bitmap, &height);
2249 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2251 expect(0xff0000ff, color);
2253 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2255 expect(0xffff0000, color);
2257 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2259 expect(0xffffff00, color);
2261 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2263 expect(0xff00ffff, color);
2267 expect(0xff, bits[2]);
2269 GdipDisposeImage(bitmap);
2271 memcpy(bits, orig_bits, sizeof(bits));
2272 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2275 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipY);
2278 stat = GdipGetImageWidth(bitmap, &width);
2280 stat = GdipGetImageHeight(bitmap, &height);
2285 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2287 expect(0xff00ffff, color);
2289 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2291 expect(0xffffff00, color);
2293 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2295 expect(0xffff0000, color);
2297 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2299 expect(0xff0000ff, color);
2303 expect(0xff, bits[2]);
2305 GdipDisposeImage(bitmap);
2308 static void test_remaptable(void)
2311 GpImageAttributes *imageattr;
2312 GpBitmap *bitmap1, *bitmap2;
2313 GpGraphics *graphics;
2317 map = GdipAlloc(sizeof(ColorMap));
2319 map->oldColor.Argb = 0xff00ff00;
2320 map->newColor.Argb = 0xffff00ff;
2322 stat = GdipSetImageAttributesRemapTable(NULL, ColorAdjustTypeDefault, TRUE, 1, map);
2323 expect(InvalidParameter, stat);
2325 stat = GdipCreateImageAttributes(&imageattr);
2328 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, NULL);
2329 expect(InvalidParameter, stat);
2331 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeCount, TRUE, 1, map);
2332 expect(InvalidParameter, stat);
2334 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeAny, TRUE, 1, map);
2335 expect(InvalidParameter, stat);
2337 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 0, map);
2338 expect(InvalidParameter, stat);
2340 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, FALSE, 0, NULL);
2343 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, map);
2346 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
2349 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
2352 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff00ff00);
2355 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2358 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2359 UnitPixel, imageattr, NULL, NULL);
2362 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2364 ok(color_match(0xffff00ff, color, 1), "Expected ffff00ff, got %.8x\n", color);
2366 GdipDeleteGraphics(graphics);
2367 GdipDisposeImage((GpImage*)bitmap1);
2368 GdipDisposeImage((GpImage*)bitmap2);
2369 GdipDisposeImageAttributes(imageattr);
2373 static void test_colorkey(void)
2376 GpImageAttributes *imageattr;
2377 GpBitmap *bitmap1, *bitmap2;
2378 GpGraphics *graphics;
2381 stat = GdipSetImageAttributesColorKeys(NULL, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2382 expect(InvalidParameter, stat);
2384 stat = GdipCreateImageAttributes(&imageattr);
2387 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeCount, TRUE, 0xff405060, 0xff708090);
2388 expect(InvalidParameter, stat);
2390 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeAny, TRUE, 0xff405060, 0xff708090);
2391 expect(InvalidParameter, stat);
2393 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2396 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap1);
2399 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap2);
2402 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0x20405060);
2405 stat = GdipBitmapSetPixel(bitmap1, 0, 1, 0x40506070);
2408 stat = GdipBitmapSetPixel(bitmap1, 1, 0, 0x60708090);
2411 stat = GdipBitmapSetPixel(bitmap1, 1, 1, 0xffffffff);
2414 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2417 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,2,2, 0,0,2,2,
2418 UnitPixel, imageattr, NULL, NULL);
2421 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2423 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2425 stat = GdipBitmapGetPixel(bitmap2, 0, 1, &color);
2427 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2429 stat = GdipBitmapGetPixel(bitmap2, 1, 0, &color);
2431 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2433 stat = GdipBitmapGetPixel(bitmap2, 1, 1, &color);
2435 ok(color_match(0xffffffff, color, 1), "Expected ffff00ff, got %.8x\n", color);
2437 GdipDeleteGraphics(graphics);
2438 GdipDisposeImage((GpImage*)bitmap1);
2439 GdipDisposeImage((GpImage*)bitmap2);
2440 GdipDisposeImageAttributes(imageattr);
2443 static void test_dispose(void)
2447 char invalid_image[256];
2449 stat = GdipDisposeImage(NULL);
2450 expect(InvalidParameter, stat);
2452 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, (GpBitmap**)&image);
2455 stat = GdipDisposeImage(image);
2458 stat = GdipDisposeImage(image);
2459 expect(ObjectBusy, stat);
2461 memset(invalid_image, 0, 256);
2462 stat = GdipDisposeImage((GpImage*)invalid_image);
2463 expect(ObjectBusy, stat);
2468 struct GdiplusStartupInput gdiplusStartupInput;
2469 ULONG_PTR gdiplusToken;
2471 gdiplusStartupInput.GdiplusVersion = 1;
2472 gdiplusStartupInput.DebugEventCallback = NULL;
2473 gdiplusStartupInput.SuppressBackgroundThread = 0;
2474 gdiplusStartupInput.SuppressExternalCodecs = 0;
2476 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
2480 test_GetImageDimension();
2481 test_GdipImageGetFrameDimensionsCount();
2482 test_LoadingImages();
2483 test_SavingImages();
2486 test_LockBits_UserBuf();
2487 test_GdipCreateBitmapFromHBITMAP();
2488 test_GdipGetImageFlags();
2489 test_GdipCloneImage();
2492 test_getrawformat();
2494 test_createfromwmf();
2496 test_createhbitmap();
2497 test_getthumbnail();
2502 test_multiframegif();
2508 GdiplusShutdown(gdiplusToken);