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 memset(buff, 0, sizeof(buff));
534 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
535 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
538 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
540 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
541 expectf(WIDTH2, width);
542 expectf(HEIGHT2, height);
544 GdipDisposeImage((GpImage*)gpbm);
547 hdc = CreateCompatibleDC(0);
548 ok(hdc != NULL, "CreateCompatibleDC failed\n");
549 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
550 bmi.bmiHeader.biHeight = HEIGHT1;
551 bmi.bmiHeader.biWidth = WIDTH1;
552 bmi.bmiHeader.biBitCount = 24;
553 bmi.bmiHeader.biPlanes = 1;
554 bmi.bmiHeader.biCompression = BI_RGB;
556 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
557 ok(hbm != NULL, "CreateDIBSection failed\n");
561 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
563 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
564 expectf(WIDTH1, width);
565 expectf(HEIGHT1, height);
568 /* test whether writing to the bitmap affects the original */
569 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
574 GdipDisposeImage((GpImage*)gpbm);
577 LogPal = GdipAlloc(sizeof(LOGPALETTE));
578 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
579 LogPal->palVersion = 0x300;
580 LogPal->palNumEntries = 1;
581 hpal = CreatePalette(LogPal);
582 ok(hpal != NULL, "CreatePalette failed\n");
585 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
591 GdipDisposeImage((GpImage*)gpbm);
597 static void test_GdipGetImageFlags(void)
603 img = (GpImage*)0xdeadbeef;
605 stat = GdipGetImageFlags(NULL, NULL);
606 expect(InvalidParameter, stat);
608 stat = GdipGetImageFlags(NULL, &flags);
609 expect(InvalidParameter, stat);
611 stat = GdipGetImageFlags(img, NULL);
612 expect(InvalidParameter, stat);
615 static void test_GdipCloneImage(void)
621 GpImage *image_src, *image_dest = NULL;
622 const INT WIDTH = 10, HEIGHT = 20;
624 /* Create an image, clone it, delete the original, make sure the copy works */
625 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
627 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
629 image_src = ((GpImage*)bm);
630 stat = GdipCloneImage(image_src, &image_dest);
632 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
634 stat = GdipDisposeImage((GpImage*)bm);
636 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
639 /* Treat FP values carefully */
640 expectf((REAL)WIDTH, rectF.Width);
641 expectf((REAL)HEIGHT, rectF.Height);
643 stat = GdipDisposeImage(image_dest);
647 static void test_testcontrol(void)
653 stat = GdipTestControl(TestControlGetBuildNumber, ¶m);
655 ok(param != 0, "Build number expected, got %u\n", param);
658 static void test_fromhicon(void)
660 static const BYTE bmp_bits[1024];
661 HBITMAP hbmMask, hbmColor;
665 GpBitmap *bitmap = NULL;
671 stat = GdipCreateBitmapFromHICON(NULL, NULL);
672 expect(InvalidParameter, stat);
673 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
674 expect(InvalidParameter, stat);
676 /* color icon 1 bit */
677 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
678 ok(hbmMask != 0, "CreateBitmap failed\n");
679 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
680 ok(hbmColor != 0, "CreateBitmap failed\n");
684 info.hbmMask = hbmMask;
685 info.hbmColor = hbmColor;
686 hIcon = CreateIconIndirect(&info);
687 ok(hIcon != 0, "CreateIconIndirect failed\n");
688 DeleteObject(hbmMask);
689 DeleteObject(hbmColor);
691 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
693 broken(stat == InvalidParameter), /* Win98 */
694 "Expected Ok, got %.8x\n", stat);
696 /* check attributes */
697 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
700 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
703 stat = GdipGetImageType((GpImage*)bitmap, &type);
705 expect(ImageTypeBitmap, type);
706 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
707 expect(PixelFormat32bppARGB, format);
709 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
710 GdipDisposeImage((GpImage*)bitmap);
714 /* color icon 8 bpp */
715 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
716 ok(hbmMask != 0, "CreateBitmap failed\n");
717 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
718 ok(hbmColor != 0, "CreateBitmap failed\n");
722 info.hbmMask = hbmMask;
723 info.hbmColor = hbmColor;
724 hIcon = CreateIconIndirect(&info);
725 ok(hIcon != 0, "CreateIconIndirect failed\n");
726 DeleteObject(hbmMask);
727 DeleteObject(hbmColor);
729 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
732 /* check attributes */
733 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
736 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
739 stat = GdipGetImageType((GpImage*)bitmap, &type);
741 expect(ImageTypeBitmap, type);
742 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
743 expect(PixelFormat32bppARGB, format);
745 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
746 GdipDisposeImage((GpImage*)bitmap);
752 static const unsigned char pngimage[285] = {
753 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
754 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
755 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
756 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
757 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
758 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
759 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
762 static const unsigned char gifimage[35] = {
763 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
764 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
768 static const unsigned char bmpimage[66] = {
769 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
770 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
771 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
772 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
776 static const unsigned char jpgimage[285] = {
777 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
778 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
779 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
780 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
781 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
782 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
783 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,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,0x1e,0x1e,
786 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
787 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
788 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
789 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
790 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
791 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
792 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
793 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
794 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
796 /* 320x320 twip wmf */
797 static const unsigned char wmfimage[180] = {
798 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
799 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
800 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
801 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
802 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
803 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
804 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
805 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
806 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
807 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
808 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
811 static void test_getrawformat(void)
813 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
814 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
815 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
816 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
817 test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
820 static void test_loadwmf(void)
832 hglob = GlobalAlloc (0, sizeof(wmfimage));
833 data = GlobalLock (hglob);
834 memcpy(data, wmfimage, sizeof(wmfimage));
835 GlobalUnlock(hglob); data = NULL;
837 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
838 ok(hres == S_OK, "Failed to create a stream\n");
839 if(hres != S_OK) return;
841 stat = GdipLoadImageFromStream(stream, &img);
842 ok(stat == Ok, "Failed to create a Bitmap\n");
844 IStream_Release(stream);
848 IStream_Release(stream);
850 stat = GdipGetImageBounds(img, &bounds, &unit);
852 todo_wine expect(UnitPixel, unit);
853 expectf(0.0, bounds.X);
854 expectf(0.0, bounds.Y);
855 todo_wine expectf(320.0, bounds.Width);
856 todo_wine expectf(320.0, bounds.Height);
858 stat = GdipGetImageHorizontalResolution(img, &res);
860 todo_wine expectf(1440.0, res);
862 stat = GdipGetImageVerticalResolution(img, &res);
864 todo_wine expectf(1440.0, res);
866 GdipDisposeImage(img);
869 static void test_createfromwmf(void)
878 hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
879 wmfimage+sizeof(WmfPlaceableFileHeader));
880 ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
882 stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
883 (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
886 stat = GdipGetImageBounds(img, &bounds, &unit);
888 todo_wine expect(UnitPixel, unit);
889 expectf(0.0, bounds.X);
890 expectf(0.0, bounds.Y);
891 todo_wine expectf(320.0, bounds.Width);
892 todo_wine expectf(320.0, bounds.Height);
894 stat = GdipGetImageHorizontalResolution(img, &res);
896 expectf(1440.0, res);
898 stat = GdipGetImageVerticalResolution(img, &res);
900 expectf(1440.0, res);
902 GdipDisposeImage(img);
905 static void test_resolution(void)
911 int screenxres, screenyres;
914 stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
917 /* test invalid values */
918 stat = GdipGetImageHorizontalResolution(NULL, &res);
919 expect(InvalidParameter, stat);
921 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
922 expect(InvalidParameter, stat);
924 stat = GdipGetImageVerticalResolution(NULL, &res);
925 expect(InvalidParameter, stat);
927 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
928 expect(InvalidParameter, stat);
930 stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
931 expect(InvalidParameter, stat);
933 stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
934 expect(InvalidParameter, stat);
936 /* defaults to screen resolution */
939 screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
940 screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
942 ReleaseDC(0, screendc);
944 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
946 expectf((REAL)screenxres, res);
948 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
950 expectf((REAL)screenyres, res);
952 /* test changing the resolution */
953 stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
956 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
958 expectf(screenxres*2.0, res);
960 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
962 expectf(screenyres*3.0, res);
964 stat = GdipDisposeImage((GpImage*)bitmap);
968 static void test_createhbitmap(void)
972 HBITMAP hbitmap, oldhbitmap;
979 memset(bits, 0x68, 640);
982 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
985 /* test NULL values */
986 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
987 expect(InvalidParameter, stat);
989 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
990 expect(InvalidParameter, stat);
993 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
998 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
999 expect(sizeof(BITMAP), ret);
1001 expect(0, bm.bmType);
1002 expect(10, bm.bmWidth);
1003 expect(20, bm.bmHeight);
1004 expect(40, bm.bmWidthBytes);
1005 expect(1, bm.bmPlanes);
1006 expect(32, bm.bmBitsPixel);
1007 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1009 hdc = CreateCompatibleDC(NULL);
1011 oldhbitmap = SelectObject(hdc, hbitmap);
1012 pixel = GetPixel(hdc, 5, 5);
1013 SelectObject(hdc, oldhbitmap);
1017 expect(0x686868, pixel);
1019 DeleteObject(hbitmap);
1022 stat = GdipDisposeImage((GpImage*)bitmap);
1026 static void test_getsetpixel(void)
1031 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1032 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1034 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1037 /* null parameters */
1038 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1039 expect(InvalidParameter, stat);
1041 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1042 expect(InvalidParameter, stat);
1044 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1045 expect(InvalidParameter, stat);
1048 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1049 expect(InvalidParameter, stat);
1051 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1052 expect(InvalidParameter, stat);
1054 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1055 ok(stat == InvalidParameter ||
1056 broken(stat == Ok), /* Older gdiplus */
1057 "Expected InvalidParameter, got %.8x\n", stat);
1059 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1060 ok(stat == InvalidParameter ||
1061 broken(stat == Ok), /* Older gdiplus */
1062 "Expected InvalidParameter, got %.8x\n", stat);
1064 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1065 expect(InvalidParameter, stat);
1067 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1068 expect(InvalidParameter, stat);
1070 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1071 expect(InvalidParameter, stat);
1073 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1074 expect(InvalidParameter, stat);
1077 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1079 expect(0xffffffff, color);
1081 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1083 expect(0xff0000ff, color);
1085 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1088 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1091 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1093 expect(0xff676869, color);
1095 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1097 expect(0xff474849, color);
1099 stat = GdipDisposeImage((GpImage*)bitmap);
1103 static void check_halftone_palette(ColorPalette *palette)
1105 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1108 for (i=0; i<palette->Count; i++)
1110 ARGB expected=0xff000000;
1113 if (i&1) expected |= 0x800000;
1114 if (i&2) expected |= 0x8000;
1115 if (i&4) expected |= 0x80;
1119 expected = 0xffc0c0c0;
1123 if (i&1) expected |= 0xff0000;
1124 if (i&2) expected |= 0xff00;
1125 if (i&4) expected |= 0xff;
1129 expected = 0x00000000;
1133 expected |= halftone_values[(i-40)%6];
1134 expected |= halftone_values[((i-40)/6)%6] << 8;
1135 expected |= halftone_values[((i-40)/36)%6] << 16;
1137 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1138 expected, palette->Entries[i], i, palette->Count);
1142 static void test_palette(void)
1148 ColorPalette *palette=(ColorPalette*)buffer;
1151 /* test initial palette from non-indexed bitmap */
1152 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1155 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1157 expect(sizeof(UINT)*2+sizeof(ARGB), size);
1159 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1161 expect(0, palette->Count);
1163 /* test setting palette on not-indexed bitmap */
1166 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1169 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1171 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1173 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1175 expect(3, palette->Count);
1177 GdipDisposeImage((GpImage*)bitmap);
1179 /* test initial palette on 1-bit bitmap */
1180 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1183 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1185 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1187 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1189 expect(PaletteFlagsGrayScale, palette->Flags);
1190 expect(2, palette->Count);
1192 expect(0xff000000, palette->Entries[0]);
1193 expect(0xffffffff, palette->Entries[1]);
1195 /* test getting/setting pixels */
1196 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1198 expect(0xff000000, color);
1200 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1201 todo_wine ok((stat == Ok) ||
1202 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1206 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1208 expect(0xffffffff, color);
1211 GdipDisposeImage((GpImage*)bitmap);
1213 /* test initial palette on 4-bit bitmap */
1214 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1217 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1219 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1221 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1223 expect(0, palette->Flags);
1224 expect(16, palette->Count);
1226 check_halftone_palette(palette);
1228 /* test getting/setting pixels */
1229 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1231 expect(0xff000000, color);
1233 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
1234 todo_wine ok((stat == Ok) ||
1235 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1239 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1241 expect(0xffff00ff, color);
1244 GdipDisposeImage((GpImage*)bitmap);
1246 /* test initial palette on 8-bit bitmap */
1247 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1250 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1252 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1254 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1256 expect(PaletteFlagsHalftone, palette->Flags);
1257 expect(256, palette->Count);
1259 check_halftone_palette(palette);
1261 /* test getting/setting pixels */
1262 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1264 expect(0xff000000, color);
1266 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
1267 todo_wine ok((stat == Ok) ||
1268 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1272 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1274 expect(0xffcccccc, color);
1277 /* test setting/getting a different palette */
1278 palette->Entries[1] = 0xffcccccc;
1280 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1283 palette->Entries[1] = 0;
1285 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1287 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1289 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1291 expect(PaletteFlagsHalftone, palette->Flags);
1292 expect(256, palette->Count);
1293 expect(0xffcccccc, palette->Entries[1]);
1295 /* test count < 256 */
1296 palette->Flags = 12345;
1299 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1302 palette->Entries[1] = 0;
1303 palette->Entries[3] = 0xdeadbeef;
1305 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1307 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1309 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1311 expect(12345, palette->Flags);
1312 expect(3, palette->Count);
1313 expect(0xffcccccc, palette->Entries[1]);
1314 expect(0xdeadbeef, palette->Entries[3]);
1316 /* test count > 256 */
1317 palette->Count = 257;
1319 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1320 ok(stat == InvalidParameter ||
1321 broken(stat == Ok), /* Old gdiplus behavior */
1322 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1324 GdipDisposeImage((GpImage*)bitmap);
1327 static void test_colormatrix(void)
1330 ColorMatrix colormatrix, graymatrix;
1331 GpImageAttributes *imageattr;
1332 const ColorMatrix identity = {{
1333 {1.0,0.0,0.0,0.0,0.0},
1334 {0.0,1.0,0.0,0.0,0.0},
1335 {0.0,0.0,1.0,0.0,0.0},
1336 {0.0,0.0,0.0,1.0,0.0},
1337 {0.0,0.0,0.0,0.0,1.0}}};
1338 const ColorMatrix double_red = {{
1339 {2.0,0.0,0.0,0.0,0.0},
1340 {0.0,1.0,0.0,0.0,0.0},
1341 {0.0,0.0,1.0,0.0,0.0},
1342 {0.0,0.0,0.0,1.0,0.0},
1343 {0.0,0.0,0.0,0.0,1.0}}};
1344 GpBitmap *bitmap1, *bitmap2;
1345 GpGraphics *graphics;
1348 colormatrix = identity;
1349 graymatrix = identity;
1351 stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
1352 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1353 expect(InvalidParameter, stat);
1355 stat = GdipCreateImageAttributes(&imageattr);
1358 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1359 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1362 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1363 TRUE, NULL, NULL, ColorMatrixFlagsDefault);
1364 expect(InvalidParameter, stat);
1366 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1367 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1370 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1371 TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
1374 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1375 TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
1376 expect(InvalidParameter, stat);
1378 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1379 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
1382 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1383 TRUE, &colormatrix, &graymatrix, 3);
1384 expect(InvalidParameter, stat);
1386 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
1387 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1388 expect(InvalidParameter, stat);
1390 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
1391 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1392 expect(InvalidParameter, stat);
1394 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1395 FALSE, NULL, NULL, ColorMatrixFlagsDefault);
1398 /* Drawing a bitmap transforms the colors */
1399 colormatrix = double_red;
1400 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1401 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1404 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1407 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1410 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ffff);
1413 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1416 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1417 UnitPixel, imageattr, NULL, NULL);
1420 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1422 todo_wine expect(0xff80ffff, color);
1424 GdipDeleteGraphics(graphics);
1425 GdipDisposeImage((GpImage*)bitmap1);
1426 GdipDisposeImage((GpImage*)bitmap2);
1427 GdipDisposeImageAttributes(imageattr);
1430 static void test_gamma(void)
1433 GpImageAttributes *imageattr;
1434 GpBitmap *bitmap1, *bitmap2;
1435 GpGraphics *graphics;
1438 stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
1439 expect(InvalidParameter, stat);
1441 stat = GdipCreateImageAttributes(&imageattr);
1444 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
1447 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
1448 expect(InvalidParameter, stat);
1450 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
1451 expect(InvalidParameter, stat);
1453 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
1454 expect(InvalidParameter, stat);
1456 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
1459 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
1462 /* Drawing a bitmap transforms the colors */
1463 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
1466 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1469 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1472 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
1475 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1478 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1479 UnitPixel, imageattr, NULL, NULL);
1482 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1484 todo_wine ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
1486 GdipDeleteGraphics(graphics);
1487 GdipDisposeImage((GpImage*)bitmap1);
1488 GdipDisposeImage((GpImage*)bitmap2);
1489 GdipDisposeImageAttributes(imageattr);
1492 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
1493 static const unsigned char gifanimation[72] = {
1494 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1495 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
1496 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
1497 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
1498 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
1501 static void test_multiframegif(void)
1513 /* Test frame functions with an animated GIF */
1514 hglob = GlobalAlloc (0, sizeof(gifanimation));
1515 data = GlobalLock (hglob);
1516 memcpy(data, gifanimation, sizeof(gifanimation));
1517 GlobalUnlock(hglob);
1519 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1520 ok(hres == S_OK, "Failed to create a stream\n");
1521 if(hres != S_OK) return;
1523 stat = GdipCreateBitmapFromStream(stream, &bmp);
1524 ok(stat == Ok, "Failed to create a Bitmap\n");
1526 IStream_Release(stream);
1530 /* Bitmap starts at frame 0 */
1532 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1534 expect(0xffffffff, color);
1536 /* Check that we get correct metadata */
1537 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1541 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1543 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1546 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1547 todo_wine expect(Ok, stat);
1548 todo_wine expect(2, count);
1550 /* SelectActiveFrame overwrites our current data */
1551 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1555 GdipBitmapGetPixel(bmp, 0, 0, &color);
1557 todo_wine expect(0xff000000, color);
1559 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1563 GdipBitmapGetPixel(bmp, 0, 0, &color);
1565 expect(0xffffffff, color);
1567 /* Write over the image data */
1568 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
1571 /* Switching to the same frame does not overwrite our changes */
1572 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1575 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1577 expect(0xff000000, color);
1579 /* But switching to another frame and back does */
1580 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1583 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1586 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1588 todo_wine expect(0xffffffff, color);
1590 GdipDisposeImage((GpImage*)bmp);
1591 IStream_Release(stream);
1593 /* Test with a non-animated gif */
1594 hglob = GlobalAlloc (0, sizeof(gifimage));
1595 data = GlobalLock (hglob);
1596 memcpy(data, gifimage, sizeof(gifimage));
1597 GlobalUnlock(hglob);
1599 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1600 ok(hres == S_OK, "Failed to create a stream\n");
1601 if(hres != S_OK) return;
1603 stat = GdipCreateBitmapFromStream(stream, &bmp);
1604 ok(stat == Ok, "Failed to create a Bitmap\n");
1606 IStream_Release(stream);
1610 /* Check metadata */
1611 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1615 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1617 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1620 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1621 todo_wine expect(Ok, stat);
1622 todo_wine expect(1, count);
1624 GdipDisposeImage((GpImage*)bmp);
1625 IStream_Release(stream);
1628 static void test_rotateflip(void)
1633 static const BYTE orig_bits[24] = {
1634 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
1635 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
1639 memcpy(bits, orig_bits, sizeof(bits));
1640 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1643 stat = GdipImageRotateFlip(bitmap, Rotate90FlipNone);
1644 todo_wine expect(Ok, stat);
1646 stat = GdipGetImageWidth(bitmap, &width);
1648 stat = GdipGetImageHeight(bitmap, &height);
1650 todo_wine expect(2, width);
1651 todo_wine expect(3, height);
1653 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1655 todo_wine expect(0xff00ffff, color);
1657 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 0, &color);
1659 todo_wine expect(0xffff0000, color);
1661 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 2, &color);
1662 todo_wine expect(Ok, stat);
1663 todo_wine expect(0xffffff00, color);
1665 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 2, &color);
1666 todo_wine expect(Ok, stat);
1667 todo_wine expect(0xff0000ff, color);
1671 expect(0xff, bits[2]);
1673 GdipDisposeImage(bitmap);
1675 memcpy(bits, orig_bits, sizeof(bits));
1676 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1679 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipX);
1680 todo_wine expect(Ok, stat);
1682 stat = GdipGetImageWidth(bitmap, &width);
1684 stat = GdipGetImageHeight(bitmap, &height);
1689 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1691 todo_wine expect(0xff0000ff, color);
1693 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
1695 todo_wine expect(0xffff0000, color);
1697 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
1699 todo_wine expect(0xffffff00, color);
1701 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
1703 todo_wine expect(0xff00ffff, color);
1707 expect(0xff, bits[2]);
1709 GdipDisposeImage(bitmap);
1711 memcpy(bits, orig_bits, sizeof(bits));
1712 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1715 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipY);
1716 todo_wine expect(Ok, stat);
1718 stat = GdipGetImageWidth(bitmap, &width);
1720 stat = GdipGetImageHeight(bitmap, &height);
1725 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1727 todo_wine expect(0xff00ffff, color);
1729 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
1731 todo_wine expect(0xffffff00, color);
1733 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
1735 todo_wine expect(0xffff0000, color);
1737 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
1739 todo_wine expect(0xff0000ff, color);
1743 expect(0xff, bits[2]);
1745 GdipDisposeImage(bitmap);
1750 struct GdiplusStartupInput gdiplusStartupInput;
1751 ULONG_PTR gdiplusToken;
1753 gdiplusStartupInput.GdiplusVersion = 1;
1754 gdiplusStartupInput.DebugEventCallback = NULL;
1755 gdiplusStartupInput.SuppressBackgroundThread = 0;
1756 gdiplusStartupInput.SuppressExternalCodecs = 0;
1758 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1761 test_GetImageDimension();
1762 test_GdipImageGetFrameDimensionsCount();
1763 test_LoadingImages();
1764 test_SavingImages();
1767 test_GdipCreateBitmapFromHBITMAP();
1768 test_GdipGetImageFlags();
1769 test_GdipCloneImage();
1772 test_getrawformat();
1774 test_createfromwmf();
1776 test_createhbitmap();
1781 test_multiframegif();
1784 GdiplusShutdown(gdiplusToken);