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_GdipCreateBitmapFromHBITMAP(void)
626 GpBitmap* gpbm = NULL;
628 HPALETTE hpal = NULL;
631 LOGPALETTE* LogPal = NULL;
633 const REAL WIDTH1 = 5;
634 const REAL HEIGHT1 = 15;
635 const REAL WIDTH2 = 10;
636 const REAL HEIGHT2 = 20;
641 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
642 expect(InvalidParameter, stat);
644 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
645 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
646 expect(InvalidParameter, stat);
648 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
650 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
651 expectf(WIDTH1, width);
652 expectf(HEIGHT1, height);
654 GdipDisposeImage((GpImage*)gpbm);
657 memset(buff, 0, sizeof(buff));
658 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
659 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
662 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
664 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
665 expectf(WIDTH2, width);
666 expectf(HEIGHT2, height);
668 GdipDisposeImage((GpImage*)gpbm);
671 hdc = CreateCompatibleDC(0);
672 ok(hdc != NULL, "CreateCompatibleDC failed\n");
673 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
674 bmi.bmiHeader.biHeight = HEIGHT1;
675 bmi.bmiHeader.biWidth = WIDTH1;
676 bmi.bmiHeader.biBitCount = 24;
677 bmi.bmiHeader.biPlanes = 1;
678 bmi.bmiHeader.biCompression = BI_RGB;
680 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
681 ok(hbm != NULL, "CreateDIBSection failed\n");
685 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
687 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
688 expectf(WIDTH1, width);
689 expectf(HEIGHT1, height);
692 /* test whether writing to the bitmap affects the original */
693 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
698 GdipDisposeImage((GpImage*)gpbm);
701 LogPal = GdipAlloc(sizeof(LOGPALETTE));
702 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
703 LogPal->palVersion = 0x300;
704 LogPal->palNumEntries = 1;
705 hpal = CreatePalette(LogPal);
706 ok(hpal != NULL, "CreatePalette failed\n");
709 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
715 GdipDisposeImage((GpImage*)gpbm);
721 static void test_GdipGetImageFlags(void)
727 img = (GpImage*)0xdeadbeef;
729 stat = GdipGetImageFlags(NULL, NULL);
730 expect(InvalidParameter, stat);
732 stat = GdipGetImageFlags(NULL, &flags);
733 expect(InvalidParameter, stat);
735 stat = GdipGetImageFlags(img, NULL);
736 expect(InvalidParameter, stat);
738 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, (GpBitmap**)&img);
740 stat = GdipGetImageFlags(img, &flags);
742 expect(ImageFlagsHasAlpha, flags);
743 GdipDisposeImage(img);
745 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, (GpBitmap**)&img);
747 stat = GdipGetImageFlags(img, &flags);
749 expect(ImageFlagsHasAlpha, flags);
750 GdipDisposeImage(img);
752 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, (GpBitmap**)&img);
754 stat = GdipGetImageFlags(img, &flags);
756 expect(ImageFlagsHasAlpha, flags);
757 GdipDisposeImage(img);
759 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, (GpBitmap**)&img);
761 stat = GdipGetImageFlags(img, &flags);
763 expect(ImageFlagsNone, flags);
764 GdipDisposeImage(img);
766 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, (GpBitmap**)&img);
768 stat = GdipGetImageFlags(img, &flags);
770 expect(ImageFlagsNone, flags);
771 GdipDisposeImage(img);
773 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, (GpBitmap**)&img);
775 stat = GdipGetImageFlags(img, &flags);
777 expect(ImageFlagsNone, flags);
778 GdipDisposeImage(img);
780 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppARGB1555, NULL, (GpBitmap**)&img);
782 stat = GdipGetImageFlags(img, &flags);
784 expect(ImageFlagsHasAlpha, flags);
785 GdipDisposeImage(img);
787 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, (GpBitmap**)&img);
789 stat = GdipGetImageFlags(img, &flags);
791 expect(ImageFlagsNone, flags);
792 GdipDisposeImage(img);
794 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, (GpBitmap**)&img);
796 stat = GdipGetImageFlags(img, &flags);
798 expect(ImageFlagsNone, flags);
799 GdipDisposeImage(img);
801 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, (GpBitmap**)&img);
803 stat = GdipGetImageFlags(img, &flags);
805 expect(ImageFlagsHasAlpha, flags);
806 GdipDisposeImage(img);
808 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppPARGB, NULL, (GpBitmap**)&img);
810 stat = GdipGetImageFlags(img, &flags);
812 expect(ImageFlagsHasAlpha, flags);
813 GdipDisposeImage(img);
815 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, (GpBitmap**)&img);
819 stat = GdipGetImageFlags(img, &flags);
821 expect(ImageFlagsNone, flags);
822 GdipDisposeImage(img);
825 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, (GpBitmap**)&img);
830 stat = GdipGetImageFlags(img, &flags);
832 expect(ImageFlagsHasAlpha, flags);
833 GdipDisposeImage(img);
836 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, (GpBitmap**)&img);
841 stat = GdipGetImageFlags(img, &flags);
843 expect(ImageFlagsHasAlpha, flags);
844 GdipDisposeImage(img);
848 static void test_GdipCloneImage(void)
854 GpImage *image_src, *image_dest = NULL;
855 const INT WIDTH = 10, HEIGHT = 20;
857 /* Create an image, clone it, delete the original, make sure the copy works */
858 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
860 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
862 image_src = ((GpImage*)bm);
863 stat = GdipCloneImage(image_src, &image_dest);
865 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
867 stat = GdipDisposeImage((GpImage*)bm);
869 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
872 /* Treat FP values carefully */
873 expectf((REAL)WIDTH, rectF.Width);
874 expectf((REAL)HEIGHT, rectF.Height);
876 stat = GdipDisposeImage(image_dest);
880 static void test_testcontrol(void)
886 stat = GdipTestControl(TestControlGetBuildNumber, ¶m);
888 ok(param != 0, "Build number expected, got %u\n", param);
891 static void test_fromhicon(void)
893 static const BYTE bmp_bits[1024];
894 HBITMAP hbmMask, hbmColor;
898 GpBitmap *bitmap = NULL;
904 stat = GdipCreateBitmapFromHICON(NULL, NULL);
905 expect(InvalidParameter, stat);
906 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
907 expect(InvalidParameter, stat);
909 /* color icon 1 bit */
910 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
911 ok(hbmMask != 0, "CreateBitmap failed\n");
912 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
913 ok(hbmColor != 0, "CreateBitmap failed\n");
917 info.hbmMask = hbmMask;
918 info.hbmColor = hbmColor;
919 hIcon = CreateIconIndirect(&info);
920 ok(hIcon != 0, "CreateIconIndirect failed\n");
921 DeleteObject(hbmMask);
922 DeleteObject(hbmColor);
924 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
926 broken(stat == InvalidParameter), /* Win98 */
927 "Expected Ok, got %.8x\n", stat);
929 /* check attributes */
930 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
933 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
936 stat = GdipGetImageType((GpImage*)bitmap, &type);
938 expect(ImageTypeBitmap, type);
939 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
940 expect(PixelFormat32bppARGB, format);
942 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
943 GdipDisposeImage((GpImage*)bitmap);
947 /* color icon 8 bpp */
948 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
949 ok(hbmMask != 0, "CreateBitmap failed\n");
950 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
951 ok(hbmColor != 0, "CreateBitmap failed\n");
955 info.hbmMask = hbmMask;
956 info.hbmColor = hbmColor;
957 hIcon = CreateIconIndirect(&info);
958 ok(hIcon != 0, "CreateIconIndirect failed\n");
959 DeleteObject(hbmMask);
960 DeleteObject(hbmColor);
962 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
965 /* check attributes */
966 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
969 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
972 stat = GdipGetImageType((GpImage*)bitmap, &type);
974 expect(ImageTypeBitmap, type);
975 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
976 expect(PixelFormat32bppARGB, format);
978 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
979 GdipDisposeImage((GpImage*)bitmap);
985 static const unsigned char pngimage[285] = {
986 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
987 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
988 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
989 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
990 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
991 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
992 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
995 static const unsigned char gifimage[35] = {
996 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
997 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
1001 static const unsigned char bmpimage[66] = {
1002 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
1003 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
1004 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
1005 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
1009 static const unsigned char jpgimage[285] = {
1010 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
1011 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
1012 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
1013 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
1014 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
1015 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
1016 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
1017 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1018 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1019 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
1020 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
1021 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1022 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
1023 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
1024 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1025 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
1026 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
1027 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
1029 /* 1x1 pixel tiff */
1030 static const unsigned char tiffimage[] = {
1031 0x49,0x49,0x2a,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xfe,0x00,
1032 0x04,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x00,0x01,0x00,
1033 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1034 0x00,0x00,0x02,0x01,0x03,0x00,0x03,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0x03,0x01,
1035 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,0x01,0x03,0x00,0x01,0x00,
1036 0x00,0x00,0x02,0x00,0x00,0x00,0x0d,0x01,0x02,0x00,0x1b,0x00,0x00,0x00,0xd8,0x00,
1037 0x00,0x00,0x11,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x12,0x01,
1038 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x01,0x03,0x00,0x01,0x00,
1039 0x00,0x00,0x03,0x00,0x00,0x00,0x16,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x40,0x00,
1040 0x00,0x00,0x17,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1a,0x01,
1041 0x05,0x00,0x01,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x1b,0x01,0x05,0x00,0x01,0x00,
1042 0x00,0x00,0xfc,0x00,0x00,0x00,0x1c,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1043 0x00,0x00,0x28,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
1044 0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x6d,0x65,
1045 0x68,0x2f,0x44,0x65,0x73,0x6b,0x74,0x6f,0x70,0x2f,0x74,0x65,0x73,0x74,0x2e,0x74,
1046 0x69,0x66,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,
1049 /* 320x320 twip wmf */
1050 static const unsigned char wmfimage[180] = {
1051 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
1052 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
1053 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
1054 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
1055 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
1056 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
1057 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
1058 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
1059 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
1060 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
1061 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
1064 static void test_getrawformat(void)
1066 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
1067 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
1068 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
1069 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
1070 test_bufferrawformat((void*)tiffimage, sizeof(tiffimage), &ImageFormatTIFF, __LINE__, FALSE);
1071 test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
1074 static void test_loadwmf(void)
1085 MetafileHeader header;
1087 hglob = GlobalAlloc (0, sizeof(wmfimage));
1088 data = GlobalLock (hglob);
1089 memcpy(data, wmfimage, sizeof(wmfimage));
1090 GlobalUnlock(hglob); data = NULL;
1092 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1093 ok(hres == S_OK, "Failed to create a stream\n");
1094 if(hres != S_OK) return;
1096 stat = GdipLoadImageFromStream(stream, &img);
1097 ok(stat == Ok, "Failed to create a Bitmap\n");
1099 IStream_Release(stream);
1103 IStream_Release(stream);
1105 stat = GdipGetImageBounds(img, &bounds, &unit);
1107 todo_wine expect(UnitPixel, unit);
1108 expectf(0.0, bounds.X);
1109 expectf(0.0, bounds.Y);
1110 todo_wine expectf(320.0, bounds.Width);
1111 todo_wine expectf(320.0, bounds.Height);
1113 stat = GdipGetImageHorizontalResolution(img, &res);
1115 todo_wine expectf(1440.0, res);
1117 stat = GdipGetImageVerticalResolution(img, &res);
1119 todo_wine expectf(1440.0, res);
1121 memset(&header, 0, sizeof(header));
1122 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1126 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1127 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1128 todo_wine expect(0x300, header.Version);
1129 expect(0, header.EmfPlusFlags);
1130 todo_wine expectf(1440.0, header.DpiX);
1131 todo_wine expectf(1440.0, header.DpiY);
1132 expect(0, header.X);
1133 expect(0, header.Y);
1134 todo_wine expect(320, header.Width);
1135 todo_wine expect(320, header.Height);
1136 todo_wine expect(1, U(header).WmfHeader.mtType);
1137 expect(0, header.EmfPlusHeaderSize);
1138 expect(0, header.LogicalDpiX);
1139 expect(0, header.LogicalDpiY);
1142 GdipDisposeImage(img);
1145 static void test_createfromwmf(void)
1153 MetafileHeader header;
1155 hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
1156 wmfimage+sizeof(WmfPlaceableFileHeader));
1157 ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
1159 stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
1160 (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
1163 stat = GdipGetImageBounds(img, &bounds, &unit);
1165 expect(UnitPixel, unit);
1166 expectf(0.0, bounds.X);
1167 expectf(0.0, bounds.Y);
1168 expectf(320.0, bounds.Width);
1169 expectf(320.0, bounds.Height);
1171 stat = GdipGetImageHorizontalResolution(img, &res);
1173 expectf(1440.0, res);
1175 stat = GdipGetImageVerticalResolution(img, &res);
1177 expectf(1440.0, res);
1179 memset(&header, 0, sizeof(header));
1180 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1184 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1185 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1186 todo_wine expect(0x300, header.Version);
1187 expect(0, header.EmfPlusFlags);
1188 todo_wine expectf(1440.0, header.DpiX);
1189 todo_wine expectf(1440.0, header.DpiY);
1190 expect(0, header.X);
1191 expect(0, header.Y);
1192 todo_wine expect(320, header.Width);
1193 todo_wine expect(320, header.Height);
1194 todo_wine expect(1, U(header).WmfHeader.mtType);
1195 expect(0, header.EmfPlusHeaderSize);
1196 expect(0, header.LogicalDpiX);
1197 expect(0, header.LogicalDpiY);
1200 GdipDisposeImage(img);
1203 static void test_resolution(void)
1209 int screenxres, screenyres;
1212 stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
1215 /* test invalid values */
1216 stat = GdipGetImageHorizontalResolution(NULL, &res);
1217 expect(InvalidParameter, stat);
1219 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
1220 expect(InvalidParameter, stat);
1222 stat = GdipGetImageVerticalResolution(NULL, &res);
1223 expect(InvalidParameter, stat);
1225 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
1226 expect(InvalidParameter, stat);
1228 stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
1229 expect(InvalidParameter, stat);
1231 stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
1232 expect(InvalidParameter, stat);
1234 /* defaults to screen resolution */
1235 screendc = GetDC(0);
1237 screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
1238 screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
1240 ReleaseDC(0, screendc);
1242 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1244 expectf((REAL)screenxres, res);
1246 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1248 expectf((REAL)screenyres, res);
1250 /* test changing the resolution */
1251 stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
1254 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1256 expectf(screenxres*2.0, res);
1258 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1260 expectf(screenyres*3.0, res);
1262 stat = GdipDisposeImage((GpImage*)bitmap);
1266 static void test_createhbitmap(void)
1270 HBITMAP hbitmap, oldhbitmap;
1277 memset(bits, 0x68, 640);
1280 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
1283 /* test NULL values */
1284 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
1285 expect(InvalidParameter, stat);
1287 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
1288 expect(InvalidParameter, stat);
1290 /* create HBITMAP */
1291 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
1296 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
1297 expect(sizeof(BITMAP), ret);
1299 expect(0, bm.bmType);
1300 expect(10, bm.bmWidth);
1301 expect(20, bm.bmHeight);
1302 expect(40, bm.bmWidthBytes);
1303 expect(1, bm.bmPlanes);
1304 expect(32, bm.bmBitsPixel);
1305 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1307 hdc = CreateCompatibleDC(NULL);
1309 oldhbitmap = SelectObject(hdc, hbitmap);
1310 pixel = GetPixel(hdc, 5, 5);
1311 SelectObject(hdc, oldhbitmap);
1315 expect(0x686868, pixel);
1317 DeleteObject(hbitmap);
1320 stat = GdipDisposeImage((GpImage*)bitmap);
1324 static void test_getthumbnail(void)
1327 GpImage *bitmap1, *bitmap2;
1330 stat = GdipGetImageThumbnail(NULL, 0, 0, &bitmap2, NULL, NULL);
1331 expect(InvalidParameter, stat);
1333 stat = GdipCreateBitmapFromScan0(128, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1336 stat = GdipGetImageThumbnail(bitmap1, 0, 0, NULL, NULL, NULL);
1337 expect(InvalidParameter, stat);
1339 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1344 stat = GdipGetImageWidth(bitmap2, &width);
1348 stat = GdipGetImageHeight(bitmap2, &height);
1350 expect(120, height);
1352 GdipDisposeImage(bitmap2);
1355 GdipDisposeImage(bitmap1);
1358 stat = GdipCreateBitmapFromScan0(64, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1361 stat = GdipGetImageThumbnail(bitmap1, 32, 32, &bitmap2, NULL, NULL);
1366 stat = GdipGetImageWidth(bitmap2, &width);
1370 stat = GdipGetImageHeight(bitmap2, &height);
1374 GdipDisposeImage(bitmap2);
1377 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1382 stat = GdipGetImageWidth(bitmap2, &width);
1386 stat = GdipGetImageHeight(bitmap2, &height);
1388 expect(120, height);
1390 GdipDisposeImage(bitmap2);
1393 GdipDisposeImage(bitmap1);
1396 static void test_getsetpixel(void)
1401 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1402 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1404 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1407 /* null parameters */
1408 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1409 expect(InvalidParameter, stat);
1411 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1412 expect(InvalidParameter, stat);
1414 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1415 expect(InvalidParameter, stat);
1418 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1419 expect(InvalidParameter, stat);
1421 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1422 expect(InvalidParameter, stat);
1424 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1425 ok(stat == InvalidParameter ||
1426 broken(stat == Ok), /* Older gdiplus */
1427 "Expected InvalidParameter, got %.8x\n", stat);
1429 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1430 ok(stat == InvalidParameter ||
1431 broken(stat == Ok), /* Older gdiplus */
1432 "Expected InvalidParameter, got %.8x\n", stat);
1434 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1435 expect(InvalidParameter, stat);
1437 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1438 expect(InvalidParameter, stat);
1440 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1441 expect(InvalidParameter, stat);
1443 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1444 expect(InvalidParameter, stat);
1447 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1449 expect(0xffffffff, color);
1451 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1453 expect(0xff0000ff, color);
1455 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1458 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1461 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1463 expect(0xff676869, color);
1465 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1467 expect(0xff474849, color);
1469 stat = GdipDisposeImage((GpImage*)bitmap);
1473 static void check_halftone_palette(ColorPalette *palette)
1475 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1478 for (i=0; i<palette->Count; i++)
1480 ARGB expected=0xff000000;
1483 if (i&1) expected |= 0x800000;
1484 if (i&2) expected |= 0x8000;
1485 if (i&4) expected |= 0x80;
1489 expected = 0xffc0c0c0;
1493 if (i&1) expected |= 0xff0000;
1494 if (i&2) expected |= 0xff00;
1495 if (i&4) expected |= 0xff;
1499 expected = 0x00000000;
1503 expected |= halftone_values[(i-40)%6];
1504 expected |= halftone_values[((i-40)/6)%6] << 8;
1505 expected |= halftone_values[((i-40)/36)%6] << 16;
1507 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1508 expected, palette->Entries[i], i, palette->Count);
1512 static void test_palette(void)
1518 ColorPalette *palette=(ColorPalette*)buffer;
1521 /* test initial palette from non-indexed bitmap */
1522 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1525 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1527 expect(sizeof(UINT)*2+sizeof(ARGB), size);
1529 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1531 expect(0, palette->Count);
1533 /* test setting palette on not-indexed bitmap */
1536 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1539 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1541 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1543 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1545 expect(3, palette->Count);
1547 GdipDisposeImage((GpImage*)bitmap);
1549 /* test initial palette on 1-bit bitmap */
1550 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1553 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1555 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1557 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1559 expect(PaletteFlagsGrayScale, palette->Flags);
1560 expect(2, palette->Count);
1562 expect(0xff000000, palette->Entries[0]);
1563 expect(0xffffffff, palette->Entries[1]);
1565 /* test getting/setting pixels */
1566 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1568 expect(0xff000000, color);
1570 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1572 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1576 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1578 expect(0xffffffff, color);
1581 GdipDisposeImage((GpImage*)bitmap);
1583 /* test initial palette on 4-bit bitmap */
1584 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1587 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1589 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1591 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1593 expect(0, palette->Flags);
1594 expect(16, palette->Count);
1596 check_halftone_palette(palette);
1598 /* test getting/setting pixels */
1599 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1601 expect(0xff000000, color);
1603 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
1605 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1609 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1611 expect(0xffff00ff, color);
1614 GdipDisposeImage((GpImage*)bitmap);
1616 /* test initial palette on 8-bit bitmap */
1617 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1620 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1622 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1624 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1626 expect(PaletteFlagsHalftone, palette->Flags);
1627 expect(256, palette->Count);
1629 check_halftone_palette(palette);
1631 /* test getting/setting pixels */
1632 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1634 expect(0xff000000, color);
1636 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
1638 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1642 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1644 expect(0xffcccccc, color);
1647 /* test setting/getting a different palette */
1648 palette->Entries[1] = 0xffcccccc;
1650 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1653 palette->Entries[1] = 0;
1655 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1657 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1659 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1661 expect(PaletteFlagsHalftone, palette->Flags);
1662 expect(256, palette->Count);
1663 expect(0xffcccccc, palette->Entries[1]);
1665 /* test count < 256 */
1666 palette->Flags = 12345;
1669 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1672 palette->Entries[1] = 0;
1673 palette->Entries[3] = 0xdeadbeef;
1675 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1677 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1679 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1681 expect(12345, palette->Flags);
1682 expect(3, palette->Count);
1683 expect(0xffcccccc, palette->Entries[1]);
1684 expect(0xdeadbeef, palette->Entries[3]);
1686 /* test count > 256 */
1687 palette->Count = 257;
1689 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1690 ok(stat == InvalidParameter ||
1691 broken(stat == Ok), /* Old gdiplus behavior */
1692 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1694 GdipDisposeImage((GpImage*)bitmap);
1697 static void test_colormatrix(void)
1700 ColorMatrix colormatrix, graymatrix;
1701 GpImageAttributes *imageattr;
1702 const ColorMatrix identity = {{
1703 {1.0,0.0,0.0,0.0,0.0},
1704 {0.0,1.0,0.0,0.0,0.0},
1705 {0.0,0.0,1.0,0.0,0.0},
1706 {0.0,0.0,0.0,1.0,0.0},
1707 {0.0,0.0,0.0,0.0,1.0}}};
1708 const ColorMatrix double_red = {{
1709 {2.0,0.0,0.0,0.0,0.0},
1710 {0.0,1.0,0.0,0.0,0.0},
1711 {0.0,0.0,1.0,0.0,0.0},
1712 {0.0,0.0,0.0,1.0,0.0},
1713 {0.0,0.0,0.0,0.0,1.0}}};
1714 GpBitmap *bitmap1, *bitmap2;
1715 GpGraphics *graphics;
1718 colormatrix = identity;
1719 graymatrix = identity;
1721 stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
1722 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1723 expect(InvalidParameter, stat);
1725 stat = GdipCreateImageAttributes(&imageattr);
1728 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1729 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1732 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1733 TRUE, NULL, NULL, ColorMatrixFlagsDefault);
1734 expect(InvalidParameter, stat);
1736 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1737 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1740 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1741 TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
1744 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1745 TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
1746 expect(InvalidParameter, stat);
1748 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1749 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
1752 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1753 TRUE, &colormatrix, &graymatrix, 3);
1754 expect(InvalidParameter, stat);
1756 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
1757 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1758 expect(InvalidParameter, stat);
1760 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
1761 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1762 expect(InvalidParameter, stat);
1764 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1765 FALSE, NULL, NULL, ColorMatrixFlagsDefault);
1768 /* Drawing a bitmap transforms the colors */
1769 colormatrix = double_red;
1770 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1771 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1774 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1777 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1780 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ffff);
1783 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1786 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1787 UnitPixel, imageattr, NULL, NULL);
1790 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1792 todo_wine expect(0xff80ffff, color);
1794 GdipDeleteGraphics(graphics);
1795 GdipDisposeImage((GpImage*)bitmap1);
1796 GdipDisposeImage((GpImage*)bitmap2);
1797 GdipDisposeImageAttributes(imageattr);
1800 static void test_gamma(void)
1803 GpImageAttributes *imageattr;
1804 GpBitmap *bitmap1, *bitmap2;
1805 GpGraphics *graphics;
1808 stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
1809 expect(InvalidParameter, stat);
1811 stat = GdipCreateImageAttributes(&imageattr);
1814 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
1817 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
1818 expect(InvalidParameter, stat);
1820 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
1821 expect(InvalidParameter, stat);
1823 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
1824 expect(InvalidParameter, stat);
1826 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
1829 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
1832 /* Drawing a bitmap transforms the colors */
1833 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
1836 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1839 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1842 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
1845 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1848 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1849 UnitPixel, imageattr, NULL, NULL);
1852 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1854 todo_wine ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
1856 GdipDeleteGraphics(graphics);
1857 GdipDisposeImage((GpImage*)bitmap1);
1858 GdipDisposeImage((GpImage*)bitmap2);
1859 GdipDisposeImageAttributes(imageattr);
1862 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
1863 static const unsigned char gifanimation[72] = {
1864 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1865 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
1866 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
1867 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
1868 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
1871 static void test_multiframegif(void)
1883 /* Test frame functions with an animated GIF */
1884 hglob = GlobalAlloc (0, sizeof(gifanimation));
1885 data = GlobalLock (hglob);
1886 memcpy(data, gifanimation, sizeof(gifanimation));
1887 GlobalUnlock(hglob);
1889 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1890 ok(hres == S_OK, "Failed to create a stream\n");
1891 if(hres != S_OK) return;
1893 stat = GdipCreateBitmapFromStream(stream, &bmp);
1894 ok(stat == Ok, "Failed to create a Bitmap\n");
1896 IStream_Release(stream);
1900 /* Bitmap starts at frame 0 */
1902 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1904 expect(0xffffffff, color);
1906 /* Check that we get correct metadata */
1907 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1911 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1913 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1916 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1918 todo_wine expect(2, count);
1920 /* SelectActiveFrame overwrites our current data */
1921 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1925 GdipBitmapGetPixel(bmp, 0, 0, &color);
1927 todo_wine expect(0xff000000, color);
1929 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1933 GdipBitmapGetPixel(bmp, 0, 0, &color);
1935 expect(0xffffffff, color);
1937 /* Write over the image data */
1938 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
1941 /* Switching to the same frame does not overwrite our changes */
1942 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1945 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1947 expect(0xff000000, color);
1949 /* But switching to another frame and back does */
1950 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1953 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1956 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1958 todo_wine expect(0xffffffff, color);
1960 GdipDisposeImage((GpImage*)bmp);
1961 IStream_Release(stream);
1963 /* Test with a non-animated gif */
1964 hglob = GlobalAlloc (0, sizeof(gifimage));
1965 data = GlobalLock (hglob);
1966 memcpy(data, gifimage, sizeof(gifimage));
1967 GlobalUnlock(hglob);
1969 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1970 ok(hres == S_OK, "Failed to create a stream\n");
1971 if(hres != S_OK) return;
1973 stat = GdipCreateBitmapFromStream(stream, &bmp);
1974 ok(stat == Ok, "Failed to create a Bitmap\n");
1976 IStream_Release(stream);
1980 /* Check metadata */
1981 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1985 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1987 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1990 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1994 GdipDisposeImage((GpImage*)bmp);
1995 IStream_Release(stream);
1998 static void test_rotateflip(void)
2003 static const BYTE orig_bits[24] = {
2004 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
2005 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
2009 memcpy(bits, orig_bits, sizeof(bits));
2010 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2013 stat = GdipImageRotateFlip(bitmap, Rotate90FlipNone);
2016 stat = GdipGetImageWidth(bitmap, &width);
2018 stat = GdipGetImageHeight(bitmap, &height);
2023 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2025 expect(0xff00ffff, color);
2027 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 0, &color);
2029 expect(0xffff0000, color);
2031 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 2, &color);
2033 expect(0xffffff00, color);
2035 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 2, &color);
2037 expect(0xff0000ff, color);
2041 expect(0xff, bits[2]);
2043 GdipDisposeImage(bitmap);
2045 memcpy(bits, orig_bits, sizeof(bits));
2046 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2049 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipX);
2052 stat = GdipGetImageWidth(bitmap, &width);
2054 stat = GdipGetImageHeight(bitmap, &height);
2059 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2061 expect(0xff0000ff, color);
2063 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2065 expect(0xffff0000, color);
2067 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2069 expect(0xffffff00, color);
2071 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2073 expect(0xff00ffff, color);
2077 expect(0xff, bits[2]);
2079 GdipDisposeImage(bitmap);
2081 memcpy(bits, orig_bits, sizeof(bits));
2082 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2085 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipY);
2088 stat = GdipGetImageWidth(bitmap, &width);
2090 stat = GdipGetImageHeight(bitmap, &height);
2095 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2097 expect(0xff00ffff, color);
2099 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2101 expect(0xffffff00, color);
2103 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2105 expect(0xffff0000, color);
2107 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2109 expect(0xff0000ff, color);
2113 expect(0xff, bits[2]);
2115 GdipDisposeImage(bitmap);
2118 static void test_remaptable(void)
2121 GpImageAttributes *imageattr;
2122 GpBitmap *bitmap1, *bitmap2;
2123 GpGraphics *graphics;
2127 map = GdipAlloc(sizeof(ColorMap));
2129 map->oldColor.Argb = 0xff00ff00;
2130 map->newColor.Argb = 0xffff00ff;
2132 stat = GdipSetImageAttributesRemapTable(NULL, ColorAdjustTypeDefault, TRUE, 1, map);
2133 expect(InvalidParameter, stat);
2135 stat = GdipCreateImageAttributes(&imageattr);
2138 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, NULL);
2139 expect(InvalidParameter, stat);
2141 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeCount, TRUE, 1, map);
2142 expect(InvalidParameter, stat);
2144 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeAny, TRUE, 1, map);
2145 expect(InvalidParameter, stat);
2147 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 0, map);
2148 expect(InvalidParameter, stat);
2150 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, FALSE, 0, NULL);
2153 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, map);
2156 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
2159 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
2162 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff00ff00);
2165 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2168 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2169 UnitPixel, imageattr, NULL, NULL);
2172 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2174 ok(color_match(0xffff00ff, color, 1), "Expected ffff00ff, got %.8x\n", color);
2176 GdipDeleteGraphics(graphics);
2177 GdipDisposeImage((GpImage*)bitmap1);
2178 GdipDisposeImage((GpImage*)bitmap2);
2179 GdipDisposeImageAttributes(imageattr);
2183 static void test_colorkey(void)
2186 GpImageAttributes *imageattr;
2187 GpBitmap *bitmap1, *bitmap2;
2188 GpGraphics *graphics;
2191 stat = GdipSetImageAttributesColorKeys(NULL, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2192 expect(InvalidParameter, stat);
2194 stat = GdipCreateImageAttributes(&imageattr);
2197 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeCount, TRUE, 0xff405060, 0xff708090);
2198 expect(InvalidParameter, stat);
2200 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeAny, TRUE, 0xff405060, 0xff708090);
2201 expect(InvalidParameter, stat);
2203 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2206 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap1);
2209 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap2);
2212 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0x20405060);
2215 stat = GdipBitmapSetPixel(bitmap1, 0, 1, 0x40506070);
2218 stat = GdipBitmapSetPixel(bitmap1, 1, 0, 0x60708090);
2221 stat = GdipBitmapSetPixel(bitmap1, 1, 1, 0xffffffff);
2224 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2227 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,2,2, 0,0,2,2,
2228 UnitPixel, imageattr, NULL, NULL);
2231 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2233 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2235 stat = GdipBitmapGetPixel(bitmap2, 0, 1, &color);
2237 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2239 stat = GdipBitmapGetPixel(bitmap2, 1, 0, &color);
2241 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2243 stat = GdipBitmapGetPixel(bitmap2, 1, 1, &color);
2245 ok(color_match(0xffffffff, color, 1), "Expected ffff00ff, got %.8x\n", color);
2247 GdipDeleteGraphics(graphics);
2248 GdipDisposeImage((GpImage*)bitmap1);
2249 GdipDisposeImage((GpImage*)bitmap2);
2250 GdipDisposeImageAttributes(imageattr);
2253 static void test_dispose(void)
2257 char invalid_image[256];
2259 stat = GdipDisposeImage(NULL);
2260 expect(InvalidParameter, stat);
2262 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, (GpBitmap**)&image);
2265 stat = GdipDisposeImage(image);
2268 stat = GdipDisposeImage(image);
2269 expect(ObjectBusy, stat);
2271 memset(invalid_image, 0, 256);
2272 stat = GdipDisposeImage((GpImage*)invalid_image);
2273 expect(ObjectBusy, stat);
2278 struct GdiplusStartupInput gdiplusStartupInput;
2279 ULONG_PTR gdiplusToken;
2281 gdiplusStartupInput.GdiplusVersion = 1;
2282 gdiplusStartupInput.DebugEventCallback = NULL;
2283 gdiplusStartupInput.SuppressBackgroundThread = 0;
2284 gdiplusStartupInput.SuppressExternalCodecs = 0;
2286 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
2290 test_GetImageDimension();
2291 test_GdipImageGetFrameDimensionsCount();
2292 test_LoadingImages();
2293 test_SavingImages();
2296 test_GdipCreateBitmapFromHBITMAP();
2297 test_GdipGetImageFlags();
2298 test_GdipCloneImage();
2301 test_getrawformat();
2303 test_createfromwmf();
2305 test_createhbitmap();
2306 test_getthumbnail();
2311 test_multiframegif();
2317 GdiplusShutdown(gdiplusToken);