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_GetImageDimension(void)
165 const REAL WIDTH = 10.0, HEIGHT = 20.0;
168 bm = (GpBitmap*)0xdeadbeef;
169 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
171 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
172 ok(NULL != bm, "Expected bitmap to not be NULL\n");
174 stat = GdipGetImageDimension(NULL,&w,&h);
175 expect(InvalidParameter, stat);
177 stat = GdipGetImageDimension((GpImage*)bm,NULL,&h);
178 expect(InvalidParameter, stat);
180 stat = GdipGetImageDimension((GpImage*)bm,&w,NULL);
181 expect(InvalidParameter, stat);
185 stat = GdipGetImageDimension((GpImage*)bm,&w,&h);
189 GdipDisposeImage((GpImage*)bm);
192 static void test_GdipImageGetFrameDimensionsCount(void)
196 const REAL WIDTH = 10.0, HEIGHT = 20.0;
198 GUID dimension = {0};
202 bm = (GpBitmap*)0xdeadbeef;
203 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
205 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
206 ok(NULL != bm, "Expected bitmap to not be NULL\n");
208 stat = GdipImageGetFrameDimensionsCount(NULL,&w);
209 expect(InvalidParameter, stat);
211 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,NULL);
212 expect(InvalidParameter, stat);
215 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,&w);
219 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 1);
221 expect_guid(&FrameDimensionPage, &dimension, __LINE__, FALSE);
223 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 2);
224 expect(InvalidParameter, stat);
226 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 0);
227 expect(InvalidParameter, stat);
230 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, &count);
231 todo_wine expect(Ok, stat);
232 todo_wine expect(1, count);
234 GdipBitmapSetPixel(bm, 0, 0, 0xffffffff);
236 stat = GdipImageSelectActiveFrame((GpImage*)bm, &dimension, 0);
239 /* SelectActiveFrame has no effect on image data of memory bitmaps */
241 GdipBitmapGetPixel(bm, 0, 0, &color);
242 expect(0xffffffff, color);
244 GdipDisposeImage((GpImage*)bm);
247 static void test_LoadingImages(void)
251 stat = GdipCreateBitmapFromFile(0, 0);
252 expect(InvalidParameter, stat);
254 stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
255 expect(InvalidParameter, stat);
257 stat = GdipLoadImageFromFile(0, 0);
258 expect(InvalidParameter, stat);
260 stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
261 expect(InvalidParameter, stat);
263 stat = GdipLoadImageFromFileICM(0, 0);
264 expect(InvalidParameter, stat);
266 stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
267 expect(InvalidParameter, stat);
270 static void test_SavingImages(void)
276 const REAL WIDTH = 10.0, HEIGHT = 20.0;
278 ImageCodecInfo *codecs;
279 static const CHAR filenameA[] = "a.bmp";
280 static const WCHAR filename[] = { 'a','.','b','m','p',0 };
284 stat = GdipSaveImageToFile(0, 0, 0, 0);
285 expect(InvalidParameter, stat);
288 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
294 stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
295 expect(InvalidParameter, stat);
297 stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
298 expect(InvalidParameter, stat);
300 /* encoder tests should succeed -- already tested */
301 stat = GdipGetImageEncodersSize(&n, &s);
302 if (stat != Ok || n == 0) goto cleanup;
304 codecs = GdipAlloc(s);
305 if (!codecs) goto cleanup;
307 stat = GdipGetImageEncoders(n, s, codecs);
308 if (stat != Ok) goto cleanup;
310 stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
313 GdipDisposeImage((GpImage*)bm);
316 /* re-load and check image stats */
317 stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
319 if (stat != Ok) goto cleanup;
321 stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
322 if (stat != Ok) goto cleanup;
330 GdipDisposeImage((GpImage*)bm);
331 ok(DeleteFileA(filenameA), "Delete failed.\n");
334 static void test_encoders(void)
339 ImageCodecInfo *codecs;
343 static const CHAR bmp_format[] = "BMP";
345 stat = GdipGetImageEncodersSize(&n, &s);
348 codecs = GdipAlloc(s);
352 stat = GdipGetImageEncoders(n, s, NULL);
353 expect(GenericError, stat);
355 stat = GdipGetImageEncoders(0, s, codecs);
356 expect(GenericError, stat);
358 stat = GdipGetImageEncoders(n, s-1, codecs);
359 expect(GenericError, stat);
361 stat = GdipGetImageEncoders(n, s+1, codecs);
362 expect(GenericError, stat);
364 stat = GdipGetImageEncoders(n, s, codecs);
368 for (i = 0; i < n; i++)
372 WideCharToMultiByte(CP_ACP, 0, codecs[i].FormatDescription, -1,
375 if (CompareStringA(LOCALE_SYSTEM_DEFAULT, 0,
377 bmp_format, -1) == CSTR_EQUAL) {
383 ok(FALSE, "No BMP codec found.\n");
388 static void test_LockBits(void)
394 const INT WIDTH = 10, HEIGHT = 20;
397 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
406 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
410 stat = GdipBitmapUnlockBits(bm, &bd);
414 /* read-only, with NULL rect -> whole bitmap lock */
415 stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
417 expect(bd.Width, WIDTH);
418 expect(bd.Height, HEIGHT);
421 stat = GdipBitmapUnlockBits(bm, &bd);
425 /* read-only, consecutive */
426 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
430 stat = GdipBitmapUnlockBits(bm, &bd);
434 stat = GdipDisposeImage((GpImage*)bm);
436 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
440 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
442 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
443 expect(WrongState, stat);
445 stat = GdipBitmapUnlockBits(bm, &bd);
448 stat = GdipDisposeImage((GpImage*)bm);
450 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
453 /* write, no modification */
454 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
458 stat = GdipBitmapUnlockBits(bm, &bd);
462 /* write, consecutive */
463 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
467 stat = GdipBitmapUnlockBits(bm, &bd);
471 stat = GdipDisposeImage((GpImage*)bm);
473 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
477 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
482 ((char*)bd.Scan0)[2] = 0xff;
484 stat = GdipBitmapUnlockBits(bm, &bd);
488 stat = GdipDisposeImage((GpImage*)bm);
492 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
494 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
496 stat = GdipDisposeImage((GpImage*)bm);
500 static void test_GdipCreateBitmapFromHBITMAP(void)
502 GpBitmap* gpbm = NULL;
504 HPALETTE hpal = NULL;
507 LOGPALETTE* LogPal = NULL;
509 const REAL WIDTH1 = 5;
510 const REAL HEIGHT1 = 15;
511 const REAL WIDTH2 = 10;
512 const REAL HEIGHT2 = 20;
517 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
518 expect(InvalidParameter, stat);
520 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
521 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
522 expect(InvalidParameter, stat);
524 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
526 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
527 expectf(WIDTH1, width);
528 expectf(HEIGHT1, height);
530 GdipDisposeImage((GpImage*)gpbm);
533 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
534 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
537 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
539 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
540 expectf(WIDTH2, width);
541 expectf(HEIGHT2, height);
543 GdipDisposeImage((GpImage*)gpbm);
546 hdc = CreateCompatibleDC(0);
547 ok(hdc != NULL, "CreateCompatibleDC failed\n");
548 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
549 bmi.bmiHeader.biHeight = HEIGHT1;
550 bmi.bmiHeader.biWidth = WIDTH1;
551 bmi.bmiHeader.biBitCount = 24;
552 bmi.bmiHeader.biPlanes = 1;
553 bmi.bmiHeader.biCompression = BI_RGB;
555 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
556 ok(hbm != NULL, "CreateDIBSection failed\n");
560 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
562 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
563 expectf(WIDTH1, width);
564 expectf(HEIGHT1, height);
567 /* test whether writing to the bitmap affects the original */
568 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
573 GdipDisposeImage((GpImage*)gpbm);
576 LogPal = GdipAlloc(sizeof(LOGPALETTE));
577 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
578 LogPal->palVersion = 0x300;
579 LogPal->palNumEntries = 1;
580 hpal = CreatePalette(LogPal);
581 ok(hpal != NULL, "CreatePalette failed\n");
584 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
590 GdipDisposeImage((GpImage*)gpbm);
596 static void test_GdipGetImageFlags(void)
602 img = (GpImage*)0xdeadbeef;
604 stat = GdipGetImageFlags(NULL, NULL);
605 expect(InvalidParameter, stat);
607 stat = GdipGetImageFlags(NULL, &flags);
608 expect(InvalidParameter, stat);
610 stat = GdipGetImageFlags(img, NULL);
611 expect(InvalidParameter, stat);
614 static void test_GdipCloneImage(void)
620 GpImage *image_src, *image_dest = NULL;
621 const INT WIDTH = 10, HEIGHT = 20;
623 /* Create an image, clone it, delete the original, make sure the copy works */
624 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
626 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
628 image_src = ((GpImage*)bm);
629 stat = GdipCloneImage(image_src, &image_dest);
631 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
633 stat = GdipDisposeImage((GpImage*)bm);
635 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
638 /* Treat FP values carefully */
639 expectf((REAL)WIDTH, rectF.Width);
640 expectf((REAL)HEIGHT, rectF.Height);
642 stat = GdipDisposeImage(image_dest);
646 static void test_testcontrol(void)
652 stat = GdipTestControl(TestControlGetBuildNumber, ¶m);
654 ok(param != 0, "Build number expected, got %u\n", param);
657 static void test_fromhicon(void)
659 static const BYTE bmp_bits[1024];
660 HBITMAP hbmMask, hbmColor;
664 GpBitmap *bitmap = NULL;
670 stat = GdipCreateBitmapFromHICON(NULL, NULL);
671 expect(InvalidParameter, stat);
672 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
673 expect(InvalidParameter, stat);
675 /* color icon 1 bit */
676 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
677 ok(hbmMask != 0, "CreateBitmap failed\n");
678 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
679 ok(hbmColor != 0, "CreateBitmap failed\n");
683 info.hbmMask = hbmMask;
684 info.hbmColor = hbmColor;
685 hIcon = CreateIconIndirect(&info);
686 ok(hIcon != 0, "CreateIconIndirect failed\n");
687 DeleteObject(hbmMask);
688 DeleteObject(hbmColor);
690 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
692 broken(stat == InvalidParameter), /* Win98 */
693 "Expected Ok, got %.8x\n", stat);
695 /* check attributes */
696 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
699 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
702 stat = GdipGetImageType((GpImage*)bitmap, &type);
704 expect(ImageTypeBitmap, type);
705 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
706 expect(PixelFormat32bppARGB, format);
708 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
709 GdipDisposeImage((GpImage*)bitmap);
713 /* color icon 8 bpp */
714 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
715 ok(hbmMask != 0, "CreateBitmap failed\n");
716 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
717 ok(hbmColor != 0, "CreateBitmap failed\n");
721 info.hbmMask = hbmMask;
722 info.hbmColor = hbmColor;
723 hIcon = CreateIconIndirect(&info);
724 ok(hIcon != 0, "CreateIconIndirect failed\n");
725 DeleteObject(hbmMask);
726 DeleteObject(hbmColor);
728 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
731 /* check attributes */
732 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
735 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
738 stat = GdipGetImageType((GpImage*)bitmap, &type);
740 expect(ImageTypeBitmap, type);
741 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
742 expect(PixelFormat32bppARGB, format);
744 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
745 GdipDisposeImage((GpImage*)bitmap);
751 static const unsigned char pngimage[285] = {
752 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
753 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
754 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
755 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
756 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
757 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
758 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
761 static const unsigned char gifimage[35] = {
762 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
763 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
767 static const unsigned char bmpimage[66] = {
768 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
769 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
770 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
771 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
775 static const unsigned char jpgimage[285] = {
776 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
777 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
778 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
779 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
780 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
781 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
782 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
783 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
784 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
785 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
786 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
787 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
788 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
789 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
790 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
791 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
792 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
793 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
795 /* 320x320 twip wmf */
796 static const unsigned char wmfimage[180] = {
797 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
798 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
799 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
800 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
801 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
802 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
803 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
804 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
805 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
806 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
807 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
810 static void test_getrawformat(void)
812 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
813 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
814 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
815 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
816 test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
819 static void test_loadwmf(void)
831 hglob = GlobalAlloc (0, sizeof(wmfimage));
832 data = GlobalLock (hglob);
833 memcpy(data, wmfimage, sizeof(wmfimage));
834 GlobalUnlock(hglob); data = NULL;
836 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
837 ok(hres == S_OK, "Failed to create a stream\n");
838 if(hres != S_OK) return;
840 stat = GdipLoadImageFromStream(stream, &img);
841 ok(stat == Ok, "Failed to create a Bitmap\n");
843 IStream_Release(stream);
847 IStream_Release(stream);
849 stat = GdipGetImageBounds(img, &bounds, &unit);
851 todo_wine expect(UnitPixel, unit);
852 expectf(0.0, bounds.X);
853 expectf(0.0, bounds.Y);
854 todo_wine expectf(320.0, bounds.Width);
855 todo_wine expectf(320.0, bounds.Height);
857 stat = GdipGetImageHorizontalResolution(img, &res);
859 todo_wine expectf(1440.0, res);
861 stat = GdipGetImageVerticalResolution(img, &res);
863 todo_wine expectf(1440.0, res);
865 GdipDisposeImage(img);
868 static void test_createfromwmf(void)
877 hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
878 wmfimage+sizeof(WmfPlaceableFileHeader));
879 ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
881 stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
882 (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
885 stat = GdipGetImageBounds(img, &bounds, &unit);
887 todo_wine expect(UnitPixel, unit);
888 expectf(0.0, bounds.X);
889 expectf(0.0, bounds.Y);
890 todo_wine expectf(320.0, bounds.Width);
891 todo_wine expectf(320.0, bounds.Height);
893 stat = GdipGetImageHorizontalResolution(img, &res);
895 expectf(1440.0, res);
897 stat = GdipGetImageVerticalResolution(img, &res);
899 expectf(1440.0, res);
901 GdipDisposeImage(img);
904 static void test_resolution(void)
910 int screenxres, screenyres;
913 stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
916 /* test invalid values */
917 stat = GdipGetImageHorizontalResolution(NULL, &res);
918 expect(InvalidParameter, stat);
920 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
921 expect(InvalidParameter, stat);
923 stat = GdipGetImageVerticalResolution(NULL, &res);
924 expect(InvalidParameter, stat);
926 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
927 expect(InvalidParameter, stat);
929 stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
930 expect(InvalidParameter, stat);
932 stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
933 expect(InvalidParameter, stat);
935 /* defaults to screen resolution */
938 screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
939 screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
941 ReleaseDC(0, screendc);
943 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
945 expectf((REAL)screenxres, res);
947 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
949 expectf((REAL)screenyres, res);
951 /* test changing the resolution */
952 stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
955 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
957 expectf(screenxres*2.0, res);
959 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
961 expectf(screenyres*3.0, res);
963 stat = GdipDisposeImage((GpImage*)bitmap);
967 static void test_createhbitmap(void)
971 HBITMAP hbitmap, oldhbitmap;
978 memset(bits, 0x68, 640);
981 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
984 /* test NULL values */
985 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
986 expect(InvalidParameter, stat);
988 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
989 expect(InvalidParameter, stat);
992 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
997 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
998 expect(sizeof(BITMAP), ret);
1000 expect(0, bm.bmType);
1001 expect(10, bm.bmWidth);
1002 expect(20, bm.bmHeight);
1003 expect(40, bm.bmWidthBytes);
1004 expect(1, bm.bmPlanes);
1005 expect(32, bm.bmBitsPixel);
1006 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1008 hdc = CreateCompatibleDC(NULL);
1010 oldhbitmap = SelectObject(hdc, hbitmap);
1011 pixel = GetPixel(hdc, 5, 5);
1012 SelectObject(hdc, oldhbitmap);
1016 expect(0x686868, pixel);
1018 DeleteObject(hbitmap);
1021 stat = GdipDisposeImage((GpImage*)bitmap);
1025 static void test_getsetpixel(void)
1030 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1031 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1033 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1036 /* null parameters */
1037 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1038 expect(InvalidParameter, stat);
1040 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1041 expect(InvalidParameter, stat);
1043 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1044 expect(InvalidParameter, stat);
1047 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1048 expect(InvalidParameter, stat);
1050 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1051 expect(InvalidParameter, stat);
1053 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1054 ok(stat == InvalidParameter ||
1055 broken(stat == Ok), /* Older gdiplus */
1056 "Expected InvalidParameter, got %.8x\n", stat);
1058 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1059 ok(stat == InvalidParameter ||
1060 broken(stat == Ok), /* Older gdiplus */
1061 "Expected InvalidParameter, got %.8x\n", stat);
1063 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1064 expect(InvalidParameter, stat);
1066 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1067 expect(InvalidParameter, stat);
1069 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1070 expect(InvalidParameter, stat);
1072 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1073 expect(InvalidParameter, stat);
1076 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1078 expect(0xffffffff, color);
1080 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1082 expect(0xff0000ff, color);
1084 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1087 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1090 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1092 expect(0xff676869, color);
1094 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1096 expect(0xff474849, color);
1098 stat = GdipDisposeImage((GpImage*)bitmap);
1102 static void check_halftone_palette(ColorPalette *palette)
1104 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1107 for (i=0; i<palette->Count; i++)
1109 ARGB expected=0xff000000;
1112 if (i&1) expected |= 0x800000;
1113 if (i&2) expected |= 0x8000;
1114 if (i&4) expected |= 0x80;
1118 expected = 0xffc0c0c0;
1122 if (i&1) expected |= 0xff0000;
1123 if (i&2) expected |= 0xff00;
1124 if (i&4) expected |= 0xff;
1128 expected = 0x00000000;
1132 expected |= halftone_values[(i-40)%6];
1133 expected |= halftone_values[((i-40)/6)%6] << 8;
1134 expected |= halftone_values[((i-40)/36)%6] << 16;
1136 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1137 expected, palette->Entries[i], i, palette->Count);
1141 static void test_palette(void)
1147 ColorPalette *palette=(ColorPalette*)buffer;
1150 /* test initial palette from non-indexed bitmap */
1151 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1154 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1156 expect(sizeof(UINT)*2+sizeof(ARGB), size);
1158 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1160 expect(0, palette->Count);
1162 /* test setting palette on not-indexed bitmap */
1165 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1168 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1170 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1172 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1174 expect(3, palette->Count);
1176 GdipDisposeImage((GpImage*)bitmap);
1178 /* test initial palette on 1-bit bitmap */
1179 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1182 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1184 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1186 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1188 expect(PaletteFlagsGrayScale, palette->Flags);
1189 expect(2, palette->Count);
1191 expect(0xff000000, palette->Entries[0]);
1192 expect(0xffffffff, palette->Entries[1]);
1194 /* test getting/setting pixels */
1195 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1197 expect(0xff000000, color);
1199 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1200 todo_wine ok((stat == Ok) ||
1201 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1205 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1207 expect(0xffffffff, color);
1210 GdipDisposeImage((GpImage*)bitmap);
1212 /* test initial palette on 4-bit bitmap */
1213 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1216 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1218 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1220 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1222 expect(0, palette->Flags);
1223 expect(16, palette->Count);
1225 check_halftone_palette(palette);
1227 /* test getting/setting pixels */
1228 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1230 expect(0xff000000, color);
1232 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
1233 todo_wine ok((stat == Ok) ||
1234 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1238 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1240 expect(0xffff00ff, color);
1243 GdipDisposeImage((GpImage*)bitmap);
1245 /* test initial palette on 8-bit bitmap */
1246 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1249 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1251 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1253 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1255 expect(PaletteFlagsHalftone, palette->Flags);
1256 expect(256, palette->Count);
1258 check_halftone_palette(palette);
1260 /* test getting/setting pixels */
1261 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1263 expect(0xff000000, color);
1265 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
1266 todo_wine ok((stat == Ok) ||
1267 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1271 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1273 expect(0xffcccccc, color);
1276 /* test setting/getting a different palette */
1277 palette->Entries[1] = 0xffcccccc;
1279 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1282 palette->Entries[1] = 0;
1284 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1286 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1288 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1290 expect(PaletteFlagsHalftone, palette->Flags);
1291 expect(256, palette->Count);
1292 expect(0xffcccccc, palette->Entries[1]);
1294 /* test count < 256 */
1295 palette->Flags = 12345;
1298 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1301 palette->Entries[1] = 0;
1302 palette->Entries[3] = 0xdeadbeef;
1304 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1306 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1308 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1310 expect(12345, palette->Flags);
1311 expect(3, palette->Count);
1312 expect(0xffcccccc, palette->Entries[1]);
1313 expect(0xdeadbeef, palette->Entries[3]);
1315 /* test count > 256 */
1316 palette->Count = 257;
1318 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1319 ok(stat == InvalidParameter ||
1320 broken(stat == Ok), /* Old gdiplus behavior */
1321 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1323 GdipDisposeImage((GpImage*)bitmap);
1326 static void test_colormatrix(void)
1329 ColorMatrix colormatrix, graymatrix;
1330 GpImageAttributes *imageattr;
1331 const ColorMatrix identity = {{
1332 {1.0,0.0,0.0,0.0,0.0},
1333 {0.0,1.0,0.0,0.0,0.0},
1334 {0.0,0.0,1.0,0.0,0.0},
1335 {0.0,0.0,0.0,1.0,0.0},
1336 {0.0,0.0,0.0,0.0,1.0}}};
1337 const ColorMatrix double_red = {{
1338 {2.0,0.0,0.0,0.0,0.0},
1339 {0.0,1.0,0.0,0.0,0.0},
1340 {0.0,0.0,1.0,0.0,0.0},
1341 {0.0,0.0,0.0,1.0,0.0},
1342 {0.0,0.0,0.0,0.0,1.0}}};
1343 GpBitmap *bitmap1, *bitmap2;
1344 GpGraphics *graphics;
1347 colormatrix = identity;
1348 graymatrix = identity;
1350 stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
1351 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1352 expect(InvalidParameter, stat);
1354 stat = GdipCreateImageAttributes(&imageattr);
1357 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1358 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1361 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1362 TRUE, NULL, NULL, ColorMatrixFlagsDefault);
1363 expect(InvalidParameter, stat);
1365 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1366 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1369 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1370 TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
1373 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1374 TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
1375 expect(InvalidParameter, stat);
1377 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1378 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
1381 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1382 TRUE, &colormatrix, &graymatrix, 3);
1383 expect(InvalidParameter, stat);
1385 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
1386 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1387 expect(InvalidParameter, stat);
1389 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
1390 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1391 expect(InvalidParameter, stat);
1393 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1394 FALSE, NULL, NULL, ColorMatrixFlagsDefault);
1397 /* Drawing a bitmap transforms the colors */
1398 colormatrix = double_red;
1399 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1400 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1403 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1406 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1409 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ffff);
1412 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1415 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1416 UnitPixel, imageattr, NULL, NULL);
1419 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1421 todo_wine expect(0xff80ffff, color);
1423 GdipDeleteGraphics(graphics);
1424 GdipDisposeImage((GpImage*)bitmap1);
1425 GdipDisposeImage((GpImage*)bitmap2);
1426 GdipDisposeImageAttributes(imageattr);
1429 static void test_gamma(void)
1432 GpImageAttributes *imageattr;
1433 GpBitmap *bitmap1, *bitmap2;
1434 GpGraphics *graphics;
1437 stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
1438 expect(InvalidParameter, stat);
1440 stat = GdipCreateImageAttributes(&imageattr);
1443 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
1446 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
1447 expect(InvalidParameter, stat);
1449 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
1450 expect(InvalidParameter, stat);
1452 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
1453 expect(InvalidParameter, stat);
1455 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
1458 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
1461 /* Drawing a bitmap transforms the colors */
1462 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
1465 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1468 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1471 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
1474 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1477 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1478 UnitPixel, imageattr, NULL, NULL);
1481 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1483 todo_wine ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
1485 GdipDeleteGraphics(graphics);
1486 GdipDisposeImage((GpImage*)bitmap1);
1487 GdipDisposeImage((GpImage*)bitmap2);
1488 GdipDisposeImageAttributes(imageattr);
1491 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
1492 static const unsigned char gifanimation[72] = {
1493 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1494 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
1495 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
1496 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
1497 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
1500 static void test_multiframegif(void)
1512 /* Test frame functions with an animated GIF */
1513 hglob = GlobalAlloc (0, sizeof(gifanimation));
1514 data = GlobalLock (hglob);
1515 memcpy(data, gifanimation, sizeof(gifanimation));
1516 GlobalUnlock(hglob);
1518 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1519 ok(hres == S_OK, "Failed to create a stream\n");
1520 if(hres != S_OK) return;
1522 stat = GdipCreateBitmapFromStream(stream, &bmp);
1523 ok(stat == Ok, "Failed to create a Bitmap\n");
1525 IStream_Release(stream);
1529 /* Bitmap starts at frame 0 */
1531 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1533 expect(0xffffffff, color);
1535 /* Check that we get correct metadata */
1536 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1540 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1542 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1545 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1546 todo_wine expect(Ok, stat);
1547 todo_wine expect(2, count);
1549 /* SelectActiveFrame overwrites our current data */
1550 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1554 GdipBitmapGetPixel(bmp, 0, 0, &color);
1556 todo_wine expect(0xff000000, color);
1558 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1562 GdipBitmapGetPixel(bmp, 0, 0, &color);
1564 expect(0xffffffff, color);
1566 /* Write over the image data */
1567 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
1570 /* Switching to the same frame does not overwrite our changes */
1571 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1574 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1576 expect(0xff000000, color);
1578 /* But switching to another frame and back does */
1579 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1582 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1585 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1587 todo_wine expect(0xffffffff, color);
1589 GdipDisposeImage((GpImage*)bmp);
1590 IStream_Release(stream);
1592 /* Test with a non-animated gif */
1593 hglob = GlobalAlloc (0, sizeof(gifimage));
1594 data = GlobalLock (hglob);
1595 memcpy(data, gifimage, sizeof(gifimage));
1596 GlobalUnlock(hglob);
1598 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1599 ok(hres == S_OK, "Failed to create a stream\n");
1600 if(hres != S_OK) return;
1602 stat = GdipCreateBitmapFromStream(stream, &bmp);
1603 ok(stat == Ok, "Failed to create a Bitmap\n");
1605 IStream_Release(stream);
1609 /* Check metadata */
1610 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1614 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1616 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1619 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1620 todo_wine expect(Ok, stat);
1621 todo_wine expect(1, count);
1623 GdipDisposeImage((GpImage*)bmp);
1624 IStream_Release(stream);
1629 struct GdiplusStartupInput gdiplusStartupInput;
1630 ULONG_PTR gdiplusToken;
1632 gdiplusStartupInput.GdiplusVersion = 1;
1633 gdiplusStartupInput.DebugEventCallback = NULL;
1634 gdiplusStartupInput.SuppressBackgroundThread = 0;
1635 gdiplusStartupInput.SuppressExternalCodecs = 0;
1637 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1640 test_GetImageDimension();
1641 test_GdipImageGetFrameDimensionsCount();
1642 test_LoadingImages();
1643 test_SavingImages();
1646 test_GdipCreateBitmapFromHBITMAP();
1647 test_GdipGetImageFlags();
1648 test_GdipCloneImage();
1651 test_getrawformat();
1653 test_createfromwmf();
1655 test_createhbitmap();
1660 test_multiframegif();
1662 GdiplusShutdown(gdiplusToken);