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;
521 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
530 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
534 stat = GdipBitmapUnlockBits(bm, &bd);
538 /* read-only, with NULL rect -> whole bitmap lock */
539 stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
541 expect(bd.Width, WIDTH);
542 expect(bd.Height, HEIGHT);
545 stat = GdipBitmapUnlockBits(bm, &bd);
549 /* read-only, consecutive */
550 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
554 stat = GdipBitmapUnlockBits(bm, &bd);
558 stat = GdipDisposeImage((GpImage*)bm);
560 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
564 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
566 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
567 expect(WrongState, stat);
569 stat = GdipBitmapUnlockBits(bm, &bd);
572 stat = GdipDisposeImage((GpImage*)bm);
574 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
577 /* write, no modification */
578 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
582 stat = GdipBitmapUnlockBits(bm, &bd);
586 /* write, consecutive */
587 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
591 stat = GdipBitmapUnlockBits(bm, &bd);
595 stat = GdipDisposeImage((GpImage*)bm);
597 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
601 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
606 ((char*)bd.Scan0)[2] = 0xff;
608 stat = GdipBitmapUnlockBits(bm, &bd);
612 stat = GdipDisposeImage((GpImage*)bm);
616 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
618 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
620 stat = GdipDisposeImage((GpImage*)bm);
624 static void test_LockBits_UserBuf(void)
630 const INT WIDTH = 10, HEIGHT = 20;
635 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat32bppARGB, NULL, &bm);
638 memset(bits, 0xaa, sizeof(bits));
647 bd.Stride = WIDTH * 4;
648 bd.PixelFormat = PixelFormat32bppARGB;
649 bd.Scan0 = &bits[2+3*WIDTH];
650 bd.Reserved = 0xaaaaaaaa;
653 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
654 todo_wine expect(Ok, stat);
656 expect(0xaaaaaaaa, bits[0]);
657 todo_wine expect(0, bits[2+3*WIDTH]);
659 bits[2+3*WIDTH] = 0xdeadbeef;
662 stat = GdipBitmapUnlockBits(bm, &bd);
666 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
671 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
672 todo_wine expect(Ok, stat);
674 expect(0xdeadbeef, bits[2+3*WIDTH]);
675 bits[2+3*WIDTH] = 0x12345678;
678 stat = GdipBitmapUnlockBits(bm, &bd);
682 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
684 todo_wine expect(0x12345678, color);
689 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeWrite|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
690 todo_wine expect(Ok, stat);
692 todo_wine expect(0x12345678, bits[2+3*WIDTH]);
693 bits[2+3*WIDTH] = 0xdeadbeef;
696 stat = GdipBitmapUnlockBits(bm, &bd);
700 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
702 todo_wine expect(0xdeadbeef, color);
704 stat = GdipDisposeImage((GpImage*)bm);
708 static void test_GdipCreateBitmapFromHBITMAP(void)
710 GpBitmap* gpbm = NULL;
712 HPALETTE hpal = NULL;
715 LOGPALETTE* LogPal = NULL;
717 const REAL WIDTH1 = 5;
718 const REAL HEIGHT1 = 15;
719 const REAL WIDTH2 = 10;
720 const REAL HEIGHT2 = 20;
725 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
726 expect(InvalidParameter, stat);
728 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
729 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
730 expect(InvalidParameter, stat);
732 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
734 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
735 expectf(WIDTH1, width);
736 expectf(HEIGHT1, height);
738 GdipDisposeImage((GpImage*)gpbm);
741 memset(buff, 0, sizeof(buff));
742 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
743 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
746 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
748 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
749 expectf(WIDTH2, width);
750 expectf(HEIGHT2, height);
752 GdipDisposeImage((GpImage*)gpbm);
755 hdc = CreateCompatibleDC(0);
756 ok(hdc != NULL, "CreateCompatibleDC failed\n");
757 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
758 bmi.bmiHeader.biHeight = HEIGHT1;
759 bmi.bmiHeader.biWidth = WIDTH1;
760 bmi.bmiHeader.biBitCount = 24;
761 bmi.bmiHeader.biPlanes = 1;
762 bmi.bmiHeader.biCompression = BI_RGB;
764 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
765 ok(hbm != NULL, "CreateDIBSection failed\n");
769 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
771 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
772 expectf(WIDTH1, width);
773 expectf(HEIGHT1, height);
776 /* test whether writing to the bitmap affects the original */
777 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
782 GdipDisposeImage((GpImage*)gpbm);
785 LogPal = GdipAlloc(sizeof(LOGPALETTE));
786 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
787 LogPal->palVersion = 0x300;
788 LogPal->palNumEntries = 1;
789 hpal = CreatePalette(LogPal);
790 ok(hpal != NULL, "CreatePalette failed\n");
793 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
799 GdipDisposeImage((GpImage*)gpbm);
805 static void test_GdipGetImageFlags(void)
811 img = (GpImage*)0xdeadbeef;
813 stat = GdipGetImageFlags(NULL, NULL);
814 expect(InvalidParameter, stat);
816 stat = GdipGetImageFlags(NULL, &flags);
817 expect(InvalidParameter, stat);
819 stat = GdipGetImageFlags(img, NULL);
820 expect(InvalidParameter, stat);
822 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, (GpBitmap**)&img);
824 stat = GdipGetImageFlags(img, &flags);
826 expect(ImageFlagsHasAlpha, flags);
827 GdipDisposeImage(img);
829 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, (GpBitmap**)&img);
831 stat = GdipGetImageFlags(img, &flags);
833 expect(ImageFlagsHasAlpha, flags);
834 GdipDisposeImage(img);
836 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, (GpBitmap**)&img);
838 stat = GdipGetImageFlags(img, &flags);
840 expect(ImageFlagsHasAlpha, flags);
841 GdipDisposeImage(img);
843 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, (GpBitmap**)&img);
845 stat = GdipGetImageFlags(img, &flags);
847 expect(ImageFlagsNone, flags);
848 GdipDisposeImage(img);
850 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, (GpBitmap**)&img);
852 stat = GdipGetImageFlags(img, &flags);
854 expect(ImageFlagsNone, flags);
855 GdipDisposeImage(img);
857 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, (GpBitmap**)&img);
859 stat = GdipGetImageFlags(img, &flags);
861 expect(ImageFlagsNone, flags);
862 GdipDisposeImage(img);
864 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppARGB1555, NULL, (GpBitmap**)&img);
866 stat = GdipGetImageFlags(img, &flags);
868 expect(ImageFlagsHasAlpha, flags);
869 GdipDisposeImage(img);
871 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, (GpBitmap**)&img);
873 stat = GdipGetImageFlags(img, &flags);
875 expect(ImageFlagsNone, flags);
876 GdipDisposeImage(img);
878 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, (GpBitmap**)&img);
880 stat = GdipGetImageFlags(img, &flags);
882 expect(ImageFlagsNone, flags);
883 GdipDisposeImage(img);
885 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, (GpBitmap**)&img);
887 stat = GdipGetImageFlags(img, &flags);
889 expect(ImageFlagsHasAlpha, flags);
890 GdipDisposeImage(img);
892 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppPARGB, NULL, (GpBitmap**)&img);
894 stat = GdipGetImageFlags(img, &flags);
896 expect(ImageFlagsHasAlpha, flags);
897 GdipDisposeImage(img);
899 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, (GpBitmap**)&img);
903 stat = GdipGetImageFlags(img, &flags);
905 expect(ImageFlagsNone, flags);
906 GdipDisposeImage(img);
909 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, (GpBitmap**)&img);
914 stat = GdipGetImageFlags(img, &flags);
916 expect(ImageFlagsHasAlpha, flags);
917 GdipDisposeImage(img);
920 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, (GpBitmap**)&img);
925 stat = GdipGetImageFlags(img, &flags);
927 expect(ImageFlagsHasAlpha, flags);
928 GdipDisposeImage(img);
932 static void test_GdipCloneImage(void)
938 GpImage *image_src, *image_dest = NULL;
939 const INT WIDTH = 10, HEIGHT = 20;
941 /* Create an image, clone it, delete the original, make sure the copy works */
942 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
944 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
946 image_src = ((GpImage*)bm);
947 stat = GdipCloneImage(image_src, &image_dest);
949 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
951 stat = GdipDisposeImage((GpImage*)bm);
953 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
956 /* Treat FP values carefully */
957 expectf((REAL)WIDTH, rectF.Width);
958 expectf((REAL)HEIGHT, rectF.Height);
960 stat = GdipDisposeImage(image_dest);
964 static void test_testcontrol(void)
970 stat = GdipTestControl(TestControlGetBuildNumber, ¶m);
972 ok(param != 0, "Build number expected, got %u\n", param);
975 static void test_fromhicon(void)
977 static const BYTE bmp_bits[1024];
978 HBITMAP hbmMask, hbmColor;
982 GpBitmap *bitmap = NULL;
988 stat = GdipCreateBitmapFromHICON(NULL, NULL);
989 expect(InvalidParameter, stat);
990 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
991 expect(InvalidParameter, stat);
993 /* color icon 1 bit */
994 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
995 ok(hbmMask != 0, "CreateBitmap failed\n");
996 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
997 ok(hbmColor != 0, "CreateBitmap failed\n");
1001 info.hbmMask = hbmMask;
1002 info.hbmColor = hbmColor;
1003 hIcon = CreateIconIndirect(&info);
1004 ok(hIcon != 0, "CreateIconIndirect failed\n");
1005 DeleteObject(hbmMask);
1006 DeleteObject(hbmColor);
1008 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
1010 broken(stat == InvalidParameter), /* Win98 */
1011 "Expected Ok, got %.8x\n", stat);
1013 /* check attributes */
1014 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
1017 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
1020 stat = GdipGetImageType((GpImage*)bitmap, &type);
1022 expect(ImageTypeBitmap, type);
1023 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
1025 expect(PixelFormat32bppARGB, format);
1027 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
1028 GdipDisposeImage((GpImage*)bitmap);
1032 /* color icon 8 bpp */
1033 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
1034 ok(hbmMask != 0, "CreateBitmap failed\n");
1035 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
1036 ok(hbmColor != 0, "CreateBitmap failed\n");
1040 info.hbmMask = hbmMask;
1041 info.hbmColor = hbmColor;
1042 hIcon = CreateIconIndirect(&info);
1043 ok(hIcon != 0, "CreateIconIndirect failed\n");
1044 DeleteObject(hbmMask);
1045 DeleteObject(hbmColor);
1047 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
1050 /* check attributes */
1051 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
1054 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
1057 stat = GdipGetImageType((GpImage*)bitmap, &type);
1059 expect(ImageTypeBitmap, type);
1060 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
1062 expect(PixelFormat32bppARGB, format);
1064 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
1065 GdipDisposeImage((GpImage*)bitmap);
1071 static const unsigned char pngimage[285] = {
1072 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
1073 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
1074 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
1075 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
1076 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
1077 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
1078 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
1081 static const unsigned char gifimage[35] = {
1082 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
1083 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
1087 static const unsigned char bmpimage[66] = {
1088 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
1089 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
1090 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
1091 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
1095 static const unsigned char jpgimage[285] = {
1096 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
1097 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
1098 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
1099 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
1100 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
1101 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
1102 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
1103 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1104 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1105 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
1106 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
1107 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1108 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
1109 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
1110 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1111 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
1112 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
1113 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
1115 /* 1x1 pixel tiff */
1116 static const unsigned char tiffimage[] = {
1117 0x49,0x49,0x2a,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xfe,0x00,
1118 0x04,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x00,0x01,0x00,
1119 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1120 0x00,0x00,0x02,0x01,0x03,0x00,0x03,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0x03,0x01,
1121 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,0x01,0x03,0x00,0x01,0x00,
1122 0x00,0x00,0x02,0x00,0x00,0x00,0x0d,0x01,0x02,0x00,0x1b,0x00,0x00,0x00,0xd8,0x00,
1123 0x00,0x00,0x11,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x12,0x01,
1124 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x01,0x03,0x00,0x01,0x00,
1125 0x00,0x00,0x03,0x00,0x00,0x00,0x16,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x40,0x00,
1126 0x00,0x00,0x17,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1a,0x01,
1127 0x05,0x00,0x01,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x1b,0x01,0x05,0x00,0x01,0x00,
1128 0x00,0x00,0xfc,0x00,0x00,0x00,0x1c,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1129 0x00,0x00,0x28,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
1130 0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x6d,0x65,
1131 0x68,0x2f,0x44,0x65,0x73,0x6b,0x74,0x6f,0x70,0x2f,0x74,0x65,0x73,0x74,0x2e,0x74,
1132 0x69,0x66,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,
1135 /* 320x320 twip wmf */
1136 static const unsigned char wmfimage[180] = {
1137 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
1138 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
1139 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
1140 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
1141 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
1142 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
1143 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
1144 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
1145 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
1146 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
1147 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
1150 static void test_getrawformat(void)
1152 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
1153 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
1154 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
1155 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
1156 test_bufferrawformat((void*)tiffimage, sizeof(tiffimage), &ImageFormatTIFF, __LINE__, FALSE);
1157 test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
1160 static void test_loadwmf(void)
1171 MetafileHeader header;
1173 hglob = GlobalAlloc (0, sizeof(wmfimage));
1174 data = GlobalLock (hglob);
1175 memcpy(data, wmfimage, sizeof(wmfimage));
1176 GlobalUnlock(hglob); data = NULL;
1178 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1179 ok(hres == S_OK, "Failed to create a stream\n");
1180 if(hres != S_OK) return;
1182 stat = GdipLoadImageFromStream(stream, &img);
1183 ok(stat == Ok, "Failed to create a Bitmap\n");
1185 IStream_Release(stream);
1189 IStream_Release(stream);
1191 stat = GdipGetImageBounds(img, &bounds, &unit);
1193 todo_wine expect(UnitPixel, unit);
1194 expectf(0.0, bounds.X);
1195 expectf(0.0, bounds.Y);
1196 todo_wine expectf(320.0, bounds.Width);
1197 todo_wine expectf(320.0, bounds.Height);
1199 stat = GdipGetImageHorizontalResolution(img, &res);
1201 todo_wine expectf(1440.0, res);
1203 stat = GdipGetImageVerticalResolution(img, &res);
1205 todo_wine expectf(1440.0, res);
1207 memset(&header, 0, sizeof(header));
1208 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1212 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1213 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1214 todo_wine expect(0x300, header.Version);
1215 expect(0, header.EmfPlusFlags);
1216 todo_wine expectf(1440.0, header.DpiX);
1217 todo_wine expectf(1440.0, header.DpiY);
1218 expect(0, header.X);
1219 expect(0, header.Y);
1220 todo_wine expect(320, header.Width);
1221 todo_wine expect(320, header.Height);
1222 todo_wine expect(1, U(header).WmfHeader.mtType);
1223 expect(0, header.EmfPlusHeaderSize);
1224 expect(0, header.LogicalDpiX);
1225 expect(0, header.LogicalDpiY);
1228 GdipDisposeImage(img);
1231 static void test_createfromwmf(void)
1239 MetafileHeader header;
1241 hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
1242 wmfimage+sizeof(WmfPlaceableFileHeader));
1243 ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
1245 stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
1246 (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
1249 stat = GdipGetImageBounds(img, &bounds, &unit);
1251 expect(UnitPixel, unit);
1252 expectf(0.0, bounds.X);
1253 expectf(0.0, bounds.Y);
1254 expectf(320.0, bounds.Width);
1255 expectf(320.0, bounds.Height);
1257 stat = GdipGetImageHorizontalResolution(img, &res);
1259 expectf(1440.0, res);
1261 stat = GdipGetImageVerticalResolution(img, &res);
1263 expectf(1440.0, res);
1265 memset(&header, 0, sizeof(header));
1266 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1270 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1271 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1272 todo_wine expect(0x300, header.Version);
1273 expect(0, header.EmfPlusFlags);
1274 todo_wine expectf(1440.0, header.DpiX);
1275 todo_wine expectf(1440.0, header.DpiY);
1276 expect(0, header.X);
1277 expect(0, header.Y);
1278 todo_wine expect(320, header.Width);
1279 todo_wine expect(320, header.Height);
1280 todo_wine expect(1, U(header).WmfHeader.mtType);
1281 expect(0, header.EmfPlusHeaderSize);
1282 expect(0, header.LogicalDpiX);
1283 expect(0, header.LogicalDpiY);
1286 GdipDisposeImage(img);
1289 static void test_resolution(void)
1295 int screenxres, screenyres;
1298 stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
1301 /* test invalid values */
1302 stat = GdipGetImageHorizontalResolution(NULL, &res);
1303 expect(InvalidParameter, stat);
1305 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
1306 expect(InvalidParameter, stat);
1308 stat = GdipGetImageVerticalResolution(NULL, &res);
1309 expect(InvalidParameter, stat);
1311 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
1312 expect(InvalidParameter, stat);
1314 stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
1315 expect(InvalidParameter, stat);
1317 stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
1318 expect(InvalidParameter, stat);
1320 /* defaults to screen resolution */
1321 screendc = GetDC(0);
1323 screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
1324 screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
1326 ReleaseDC(0, screendc);
1328 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1330 expectf((REAL)screenxres, res);
1332 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1334 expectf((REAL)screenyres, res);
1336 /* test changing the resolution */
1337 stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
1340 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1342 expectf(screenxres*2.0, res);
1344 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1346 expectf(screenyres*3.0, res);
1348 stat = GdipDisposeImage((GpImage*)bitmap);
1352 static void test_createhbitmap(void)
1356 HBITMAP hbitmap, oldhbitmap;
1363 memset(bits, 0x68, 640);
1366 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
1369 /* test NULL values */
1370 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
1371 expect(InvalidParameter, stat);
1373 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
1374 expect(InvalidParameter, stat);
1376 /* create HBITMAP */
1377 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
1382 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
1383 expect(sizeof(BITMAP), ret);
1385 expect(0, bm.bmType);
1386 expect(10, bm.bmWidth);
1387 expect(20, bm.bmHeight);
1388 expect(40, bm.bmWidthBytes);
1389 expect(1, bm.bmPlanes);
1390 expect(32, bm.bmBitsPixel);
1391 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1393 hdc = CreateCompatibleDC(NULL);
1395 oldhbitmap = SelectObject(hdc, hbitmap);
1396 pixel = GetPixel(hdc, 5, 5);
1397 SelectObject(hdc, oldhbitmap);
1401 expect(0x686868, pixel);
1403 DeleteObject(hbitmap);
1406 stat = GdipDisposeImage((GpImage*)bitmap);
1410 static void test_getthumbnail(void)
1413 GpImage *bitmap1, *bitmap2;
1416 stat = GdipGetImageThumbnail(NULL, 0, 0, &bitmap2, NULL, NULL);
1417 expect(InvalidParameter, stat);
1419 stat = GdipCreateBitmapFromScan0(128, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1422 stat = GdipGetImageThumbnail(bitmap1, 0, 0, NULL, NULL, NULL);
1423 expect(InvalidParameter, stat);
1425 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1430 stat = GdipGetImageWidth(bitmap2, &width);
1434 stat = GdipGetImageHeight(bitmap2, &height);
1436 expect(120, height);
1438 GdipDisposeImage(bitmap2);
1441 GdipDisposeImage(bitmap1);
1444 stat = GdipCreateBitmapFromScan0(64, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1447 stat = GdipGetImageThumbnail(bitmap1, 32, 32, &bitmap2, NULL, NULL);
1452 stat = GdipGetImageWidth(bitmap2, &width);
1456 stat = GdipGetImageHeight(bitmap2, &height);
1460 GdipDisposeImage(bitmap2);
1463 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1468 stat = GdipGetImageWidth(bitmap2, &width);
1472 stat = GdipGetImageHeight(bitmap2, &height);
1474 expect(120, height);
1476 GdipDisposeImage(bitmap2);
1479 GdipDisposeImage(bitmap1);
1482 static void test_getsetpixel(void)
1487 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1488 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1490 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1493 /* null parameters */
1494 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1495 expect(InvalidParameter, stat);
1497 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1498 expect(InvalidParameter, stat);
1500 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1501 expect(InvalidParameter, stat);
1504 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1505 expect(InvalidParameter, stat);
1507 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1508 expect(InvalidParameter, stat);
1510 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1511 ok(stat == InvalidParameter ||
1512 broken(stat == Ok), /* Older gdiplus */
1513 "Expected InvalidParameter, got %.8x\n", stat);
1515 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1516 ok(stat == InvalidParameter ||
1517 broken(stat == Ok), /* Older gdiplus */
1518 "Expected InvalidParameter, got %.8x\n", stat);
1520 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1521 expect(InvalidParameter, stat);
1523 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1524 expect(InvalidParameter, stat);
1526 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1527 expect(InvalidParameter, stat);
1529 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1530 expect(InvalidParameter, stat);
1533 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1535 expect(0xffffffff, color);
1537 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1539 expect(0xff0000ff, color);
1541 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1544 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1547 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1549 expect(0xff676869, color);
1551 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1553 expect(0xff474849, color);
1555 stat = GdipDisposeImage((GpImage*)bitmap);
1559 static void check_halftone_palette(ColorPalette *palette)
1561 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1564 for (i=0; i<palette->Count; i++)
1566 ARGB expected=0xff000000;
1569 if (i&1) expected |= 0x800000;
1570 if (i&2) expected |= 0x8000;
1571 if (i&4) expected |= 0x80;
1575 expected = 0xffc0c0c0;
1579 if (i&1) expected |= 0xff0000;
1580 if (i&2) expected |= 0xff00;
1581 if (i&4) expected |= 0xff;
1585 expected = 0x00000000;
1589 expected |= halftone_values[(i-40)%6];
1590 expected |= halftone_values[((i-40)/6)%6] << 8;
1591 expected |= halftone_values[((i-40)/36)%6] << 16;
1593 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1594 expected, palette->Entries[i], i, palette->Count);
1598 static void test_palette(void)
1604 ColorPalette *palette=(ColorPalette*)buffer;
1607 /* test initial palette from non-indexed bitmap */
1608 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1611 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1613 expect(sizeof(UINT)*2+sizeof(ARGB), size);
1615 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1617 expect(0, palette->Count);
1619 /* test setting palette on not-indexed bitmap */
1622 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1625 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1627 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1629 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1631 expect(3, palette->Count);
1633 GdipDisposeImage((GpImage*)bitmap);
1635 /* test initial palette on 1-bit bitmap */
1636 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1639 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1641 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1643 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1645 expect(PaletteFlagsGrayScale, palette->Flags);
1646 expect(2, palette->Count);
1648 expect(0xff000000, palette->Entries[0]);
1649 expect(0xffffffff, palette->Entries[1]);
1651 /* test getting/setting pixels */
1652 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1654 expect(0xff000000, color);
1656 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1658 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1662 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1664 expect(0xffffffff, color);
1667 GdipDisposeImage((GpImage*)bitmap);
1669 /* test initial palette on 4-bit bitmap */
1670 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1673 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1675 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1677 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1679 expect(0, palette->Flags);
1680 expect(16, palette->Count);
1682 check_halftone_palette(palette);
1684 /* test getting/setting pixels */
1685 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1687 expect(0xff000000, color);
1689 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
1691 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1695 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1697 expect(0xffff00ff, color);
1700 GdipDisposeImage((GpImage*)bitmap);
1702 /* test initial palette on 8-bit bitmap */
1703 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1706 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1708 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1710 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1712 expect(PaletteFlagsHalftone, palette->Flags);
1713 expect(256, palette->Count);
1715 check_halftone_palette(palette);
1717 /* test getting/setting pixels */
1718 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1720 expect(0xff000000, color);
1722 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
1724 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1728 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1730 expect(0xffcccccc, color);
1733 /* test setting/getting a different palette */
1734 palette->Entries[1] = 0xffcccccc;
1736 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1739 palette->Entries[1] = 0;
1741 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1743 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1745 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1747 expect(PaletteFlagsHalftone, palette->Flags);
1748 expect(256, palette->Count);
1749 expect(0xffcccccc, palette->Entries[1]);
1751 /* test count < 256 */
1752 palette->Flags = 12345;
1755 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1758 palette->Entries[1] = 0;
1759 palette->Entries[3] = 0xdeadbeef;
1761 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1763 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1765 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1767 expect(12345, palette->Flags);
1768 expect(3, palette->Count);
1769 expect(0xffcccccc, palette->Entries[1]);
1770 expect(0xdeadbeef, palette->Entries[3]);
1772 /* test count > 256 */
1773 palette->Count = 257;
1775 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1776 ok(stat == InvalidParameter ||
1777 broken(stat == Ok), /* Old gdiplus behavior */
1778 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1780 GdipDisposeImage((GpImage*)bitmap);
1783 static void test_colormatrix(void)
1786 ColorMatrix colormatrix, graymatrix;
1787 GpImageAttributes *imageattr;
1788 const ColorMatrix identity = {{
1789 {1.0,0.0,0.0,0.0,0.0},
1790 {0.0,1.0,0.0,0.0,0.0},
1791 {0.0,0.0,1.0,0.0,0.0},
1792 {0.0,0.0,0.0,1.0,0.0},
1793 {0.0,0.0,0.0,0.0,1.0}}};
1794 const ColorMatrix double_red = {{
1795 {2.0,0.0,0.0,0.0,0.0},
1796 {0.0,1.0,0.0,0.0,0.0},
1797 {0.0,0.0,1.0,0.0,0.0},
1798 {0.0,0.0,0.0,1.0,0.0},
1799 {0.0,0.0,0.0,0.0,1.0}}};
1800 GpBitmap *bitmap1, *bitmap2;
1801 GpGraphics *graphics;
1804 colormatrix = identity;
1805 graymatrix = identity;
1807 stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
1808 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1809 expect(InvalidParameter, stat);
1811 stat = GdipCreateImageAttributes(&imageattr);
1814 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1815 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1818 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1819 TRUE, NULL, NULL, ColorMatrixFlagsDefault);
1820 expect(InvalidParameter, stat);
1822 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1823 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1826 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1827 TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
1830 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1831 TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
1832 expect(InvalidParameter, stat);
1834 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1835 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
1838 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1839 TRUE, &colormatrix, &graymatrix, 3);
1840 expect(InvalidParameter, stat);
1842 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
1843 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1844 expect(InvalidParameter, stat);
1846 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
1847 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1848 expect(InvalidParameter, stat);
1850 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1851 FALSE, NULL, NULL, ColorMatrixFlagsDefault);
1854 /* Drawing a bitmap transforms the colors */
1855 colormatrix = double_red;
1856 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1857 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1860 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1863 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1866 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ffff);
1869 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1872 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1873 UnitPixel, imageattr, NULL, NULL);
1876 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1878 todo_wine expect(0xff80ffff, color);
1880 GdipDeleteGraphics(graphics);
1881 GdipDisposeImage((GpImage*)bitmap1);
1882 GdipDisposeImage((GpImage*)bitmap2);
1883 GdipDisposeImageAttributes(imageattr);
1886 static void test_gamma(void)
1889 GpImageAttributes *imageattr;
1890 GpBitmap *bitmap1, *bitmap2;
1891 GpGraphics *graphics;
1894 stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
1895 expect(InvalidParameter, stat);
1897 stat = GdipCreateImageAttributes(&imageattr);
1900 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
1903 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
1904 expect(InvalidParameter, stat);
1906 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
1907 expect(InvalidParameter, stat);
1909 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
1910 expect(InvalidParameter, stat);
1912 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
1915 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
1918 /* Drawing a bitmap transforms the colors */
1919 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
1922 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1925 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1928 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
1931 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1934 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1935 UnitPixel, imageattr, NULL, NULL);
1938 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1940 todo_wine ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
1942 GdipDeleteGraphics(graphics);
1943 GdipDisposeImage((GpImage*)bitmap1);
1944 GdipDisposeImage((GpImage*)bitmap2);
1945 GdipDisposeImageAttributes(imageattr);
1948 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
1949 static const unsigned char gifanimation[72] = {
1950 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1951 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
1952 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
1953 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
1954 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
1957 static void test_multiframegif(void)
1969 /* Test frame functions with an animated GIF */
1970 hglob = GlobalAlloc (0, sizeof(gifanimation));
1971 data = GlobalLock (hglob);
1972 memcpy(data, gifanimation, sizeof(gifanimation));
1973 GlobalUnlock(hglob);
1975 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1976 ok(hres == S_OK, "Failed to create a stream\n");
1977 if(hres != S_OK) return;
1979 stat = GdipCreateBitmapFromStream(stream, &bmp);
1980 ok(stat == Ok, "Failed to create a Bitmap\n");
1982 IStream_Release(stream);
1986 /* Bitmap starts at frame 0 */
1988 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1990 expect(0xffffffff, color);
1992 /* Check that we get correct metadata */
1993 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1997 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1999 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
2002 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2004 todo_wine expect(2, count);
2006 /* SelectActiveFrame overwrites our current data */
2007 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
2011 GdipBitmapGetPixel(bmp, 0, 0, &color);
2013 todo_wine expect(0xff000000, color);
2015 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2019 GdipBitmapGetPixel(bmp, 0, 0, &color);
2021 expect(0xffffffff, color);
2023 /* Write over the image data */
2024 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
2027 /* Switching to the same frame does not overwrite our changes */
2028 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2031 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2033 expect(0xff000000, color);
2035 /* But switching to another frame and back does */
2036 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
2039 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2042 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2044 todo_wine expect(0xffffffff, color);
2046 GdipDisposeImage((GpImage*)bmp);
2047 IStream_Release(stream);
2049 /* Test with a non-animated gif */
2050 hglob = GlobalAlloc (0, sizeof(gifimage));
2051 data = GlobalLock (hglob);
2052 memcpy(data, gifimage, sizeof(gifimage));
2053 GlobalUnlock(hglob);
2055 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
2056 ok(hres == S_OK, "Failed to create a stream\n");
2057 if(hres != S_OK) return;
2059 stat = GdipCreateBitmapFromStream(stream, &bmp);
2060 ok(stat == Ok, "Failed to create a Bitmap\n");
2062 IStream_Release(stream);
2066 /* Check metadata */
2067 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
2071 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
2073 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
2076 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2080 GdipDisposeImage((GpImage*)bmp);
2081 IStream_Release(stream);
2084 static void test_rotateflip(void)
2089 static const BYTE orig_bits[24] = {
2090 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
2091 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
2095 memcpy(bits, orig_bits, sizeof(bits));
2096 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2099 stat = GdipImageRotateFlip(bitmap, Rotate90FlipNone);
2102 stat = GdipGetImageWidth(bitmap, &width);
2104 stat = GdipGetImageHeight(bitmap, &height);
2109 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2111 expect(0xff00ffff, color);
2113 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 0, &color);
2115 expect(0xffff0000, color);
2117 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 2, &color);
2119 expect(0xffffff00, color);
2121 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 2, &color);
2123 expect(0xff0000ff, color);
2127 expect(0xff, bits[2]);
2129 GdipDisposeImage(bitmap);
2131 memcpy(bits, orig_bits, sizeof(bits));
2132 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2135 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipX);
2138 stat = GdipGetImageWidth(bitmap, &width);
2140 stat = GdipGetImageHeight(bitmap, &height);
2145 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2147 expect(0xff0000ff, color);
2149 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2151 expect(0xffff0000, color);
2153 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2155 expect(0xffffff00, color);
2157 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2159 expect(0xff00ffff, color);
2163 expect(0xff, bits[2]);
2165 GdipDisposeImage(bitmap);
2167 memcpy(bits, orig_bits, sizeof(bits));
2168 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2171 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipY);
2174 stat = GdipGetImageWidth(bitmap, &width);
2176 stat = GdipGetImageHeight(bitmap, &height);
2181 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2183 expect(0xff00ffff, color);
2185 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2187 expect(0xffffff00, color);
2189 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2191 expect(0xffff0000, color);
2193 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2195 expect(0xff0000ff, color);
2199 expect(0xff, bits[2]);
2201 GdipDisposeImage(bitmap);
2204 static void test_remaptable(void)
2207 GpImageAttributes *imageattr;
2208 GpBitmap *bitmap1, *bitmap2;
2209 GpGraphics *graphics;
2213 map = GdipAlloc(sizeof(ColorMap));
2215 map->oldColor.Argb = 0xff00ff00;
2216 map->newColor.Argb = 0xffff00ff;
2218 stat = GdipSetImageAttributesRemapTable(NULL, ColorAdjustTypeDefault, TRUE, 1, map);
2219 expect(InvalidParameter, stat);
2221 stat = GdipCreateImageAttributes(&imageattr);
2224 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, NULL);
2225 expect(InvalidParameter, stat);
2227 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeCount, TRUE, 1, map);
2228 expect(InvalidParameter, stat);
2230 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeAny, TRUE, 1, map);
2231 expect(InvalidParameter, stat);
2233 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 0, map);
2234 expect(InvalidParameter, stat);
2236 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, FALSE, 0, NULL);
2239 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, map);
2242 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
2245 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
2248 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff00ff00);
2251 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2254 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2255 UnitPixel, imageattr, NULL, NULL);
2258 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2260 ok(color_match(0xffff00ff, color, 1), "Expected ffff00ff, got %.8x\n", color);
2262 GdipDeleteGraphics(graphics);
2263 GdipDisposeImage((GpImage*)bitmap1);
2264 GdipDisposeImage((GpImage*)bitmap2);
2265 GdipDisposeImageAttributes(imageattr);
2269 static void test_colorkey(void)
2272 GpImageAttributes *imageattr;
2273 GpBitmap *bitmap1, *bitmap2;
2274 GpGraphics *graphics;
2277 stat = GdipSetImageAttributesColorKeys(NULL, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2278 expect(InvalidParameter, stat);
2280 stat = GdipCreateImageAttributes(&imageattr);
2283 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeCount, TRUE, 0xff405060, 0xff708090);
2284 expect(InvalidParameter, stat);
2286 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeAny, TRUE, 0xff405060, 0xff708090);
2287 expect(InvalidParameter, stat);
2289 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2292 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap1);
2295 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap2);
2298 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0x20405060);
2301 stat = GdipBitmapSetPixel(bitmap1, 0, 1, 0x40506070);
2304 stat = GdipBitmapSetPixel(bitmap1, 1, 0, 0x60708090);
2307 stat = GdipBitmapSetPixel(bitmap1, 1, 1, 0xffffffff);
2310 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2313 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,2,2, 0,0,2,2,
2314 UnitPixel, imageattr, NULL, NULL);
2317 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2319 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2321 stat = GdipBitmapGetPixel(bitmap2, 0, 1, &color);
2323 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2325 stat = GdipBitmapGetPixel(bitmap2, 1, 0, &color);
2327 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2329 stat = GdipBitmapGetPixel(bitmap2, 1, 1, &color);
2331 ok(color_match(0xffffffff, color, 1), "Expected ffff00ff, got %.8x\n", color);
2333 GdipDeleteGraphics(graphics);
2334 GdipDisposeImage((GpImage*)bitmap1);
2335 GdipDisposeImage((GpImage*)bitmap2);
2336 GdipDisposeImageAttributes(imageattr);
2339 static void test_dispose(void)
2343 char invalid_image[256];
2345 stat = GdipDisposeImage(NULL);
2346 expect(InvalidParameter, stat);
2348 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, (GpBitmap**)&image);
2351 stat = GdipDisposeImage(image);
2354 stat = GdipDisposeImage(image);
2355 expect(ObjectBusy, stat);
2357 memset(invalid_image, 0, 256);
2358 stat = GdipDisposeImage((GpImage*)invalid_image);
2359 expect(ObjectBusy, stat);
2364 struct GdiplusStartupInput gdiplusStartupInput;
2365 ULONG_PTR gdiplusToken;
2367 gdiplusStartupInput.GdiplusVersion = 1;
2368 gdiplusStartupInput.DebugEventCallback = NULL;
2369 gdiplusStartupInput.SuppressBackgroundThread = 0;
2370 gdiplusStartupInput.SuppressExternalCodecs = 0;
2372 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
2376 test_GetImageDimension();
2377 test_GdipImageGetFrameDimensionsCount();
2378 test_LoadingImages();
2379 test_SavingImages();
2382 test_LockBits_UserBuf();
2383 test_GdipCreateBitmapFromHBITMAP();
2384 test_GdipGetImageFlags();
2385 test_GdipCloneImage();
2388 test_getrawformat();
2390 test_createfromwmf();
2392 test_createhbitmap();
2393 test_getthumbnail();
2398 test_multiframegif();
2404 GdiplusShutdown(gdiplusToken);