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);
229 stat = GdipImageGetFrameCount(NULL, &dimension, &count);
230 expect(InvalidParameter, stat);
232 /* WinXP crashes on this test */
235 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, NULL);
236 expect(InvalidParameter, stat);
239 stat = GdipImageGetFrameCount((GpImage*)bm, NULL, &count);
243 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, &count);
247 GdipBitmapSetPixel(bm, 0, 0, 0xffffffff);
249 stat = GdipImageSelectActiveFrame((GpImage*)bm, &dimension, 0);
252 /* SelectActiveFrame has no effect on image data of memory bitmaps */
254 GdipBitmapGetPixel(bm, 0, 0, &color);
255 expect(0xffffffff, color);
257 GdipDisposeImage((GpImage*)bm);
260 static void test_LoadingImages(void)
264 stat = GdipCreateBitmapFromFile(0, 0);
265 expect(InvalidParameter, stat);
267 stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
268 expect(InvalidParameter, stat);
270 stat = GdipLoadImageFromFile(0, 0);
271 expect(InvalidParameter, stat);
273 stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
274 expect(InvalidParameter, stat);
276 stat = GdipLoadImageFromFileICM(0, 0);
277 expect(InvalidParameter, stat);
279 stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
280 expect(InvalidParameter, stat);
283 static void test_SavingImages(void)
289 const REAL WIDTH = 10.0, HEIGHT = 20.0;
291 ImageCodecInfo *codecs;
292 static const CHAR filenameA[] = "a.bmp";
293 static const WCHAR filename[] = { 'a','.','b','m','p',0 };
297 stat = GdipSaveImageToFile(0, 0, 0, 0);
298 expect(InvalidParameter, stat);
301 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
307 stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
308 expect(InvalidParameter, stat);
310 stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
311 expect(InvalidParameter, stat);
313 /* encoder tests should succeed -- already tested */
314 stat = GdipGetImageEncodersSize(&n, &s);
315 if (stat != Ok || n == 0) goto cleanup;
317 codecs = GdipAlloc(s);
318 if (!codecs) goto cleanup;
320 stat = GdipGetImageEncoders(n, s, codecs);
321 if (stat != Ok) goto cleanup;
323 stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
326 GdipDisposeImage((GpImage*)bm);
329 /* re-load and check image stats */
330 stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
332 if (stat != Ok) goto cleanup;
334 stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
335 if (stat != Ok) goto cleanup;
343 GdipDisposeImage((GpImage*)bm);
344 ok(DeleteFileA(filenameA), "Delete failed.\n");
347 static void test_encoders(void)
352 ImageCodecInfo *codecs;
356 static const CHAR bmp_format[] = "BMP";
358 stat = GdipGetImageEncodersSize(&n, &s);
361 codecs = GdipAlloc(s);
365 stat = GdipGetImageEncoders(n, s, NULL);
366 expect(GenericError, stat);
368 stat = GdipGetImageEncoders(0, s, codecs);
369 expect(GenericError, stat);
371 stat = GdipGetImageEncoders(n, s-1, codecs);
372 expect(GenericError, stat);
374 stat = GdipGetImageEncoders(n, s+1, codecs);
375 expect(GenericError, stat);
377 stat = GdipGetImageEncoders(n, s, codecs);
381 for (i = 0; i < n; i++)
385 WideCharToMultiByte(CP_ACP, 0, codecs[i].FormatDescription, -1,
388 if (CompareStringA(LOCALE_SYSTEM_DEFAULT, 0,
390 bmp_format, -1) == CSTR_EQUAL) {
396 ok(FALSE, "No BMP codec found.\n");
401 static void test_LockBits(void)
407 const INT WIDTH = 10, HEIGHT = 20;
410 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
419 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
423 stat = GdipBitmapUnlockBits(bm, &bd);
427 /* read-only, with NULL rect -> whole bitmap lock */
428 stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
430 expect(bd.Width, WIDTH);
431 expect(bd.Height, HEIGHT);
434 stat = GdipBitmapUnlockBits(bm, &bd);
438 /* read-only, consecutive */
439 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
443 stat = GdipBitmapUnlockBits(bm, &bd);
447 stat = GdipDisposeImage((GpImage*)bm);
449 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
453 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
455 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
456 expect(WrongState, stat);
458 stat = GdipBitmapUnlockBits(bm, &bd);
461 stat = GdipDisposeImage((GpImage*)bm);
463 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
466 /* write, no modification */
467 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
471 stat = GdipBitmapUnlockBits(bm, &bd);
475 /* write, consecutive */
476 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
480 stat = GdipBitmapUnlockBits(bm, &bd);
484 stat = GdipDisposeImage((GpImage*)bm);
486 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
490 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
495 ((char*)bd.Scan0)[2] = 0xff;
497 stat = GdipBitmapUnlockBits(bm, &bd);
501 stat = GdipDisposeImage((GpImage*)bm);
505 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
507 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
509 stat = GdipDisposeImage((GpImage*)bm);
513 static void test_GdipCreateBitmapFromHBITMAP(void)
515 GpBitmap* gpbm = NULL;
517 HPALETTE hpal = NULL;
520 LOGPALETTE* LogPal = NULL;
522 const REAL WIDTH1 = 5;
523 const REAL HEIGHT1 = 15;
524 const REAL WIDTH2 = 10;
525 const REAL HEIGHT2 = 20;
530 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
531 expect(InvalidParameter, stat);
533 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
534 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
535 expect(InvalidParameter, stat);
537 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
539 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
540 expectf(WIDTH1, width);
541 expectf(HEIGHT1, height);
543 GdipDisposeImage((GpImage*)gpbm);
546 memset(buff, 0, sizeof(buff));
547 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
548 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
551 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
553 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
554 expectf(WIDTH2, width);
555 expectf(HEIGHT2, height);
557 GdipDisposeImage((GpImage*)gpbm);
560 hdc = CreateCompatibleDC(0);
561 ok(hdc != NULL, "CreateCompatibleDC failed\n");
562 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
563 bmi.bmiHeader.biHeight = HEIGHT1;
564 bmi.bmiHeader.biWidth = WIDTH1;
565 bmi.bmiHeader.biBitCount = 24;
566 bmi.bmiHeader.biPlanes = 1;
567 bmi.bmiHeader.biCompression = BI_RGB;
569 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
570 ok(hbm != NULL, "CreateDIBSection failed\n");
574 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
576 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
577 expectf(WIDTH1, width);
578 expectf(HEIGHT1, height);
581 /* test whether writing to the bitmap affects the original */
582 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
587 GdipDisposeImage((GpImage*)gpbm);
590 LogPal = GdipAlloc(sizeof(LOGPALETTE));
591 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
592 LogPal->palVersion = 0x300;
593 LogPal->palNumEntries = 1;
594 hpal = CreatePalette(LogPal);
595 ok(hpal != NULL, "CreatePalette failed\n");
598 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
604 GdipDisposeImage((GpImage*)gpbm);
610 static void test_GdipGetImageFlags(void)
616 img = (GpImage*)0xdeadbeef;
618 stat = GdipGetImageFlags(NULL, NULL);
619 expect(InvalidParameter, stat);
621 stat = GdipGetImageFlags(NULL, &flags);
622 expect(InvalidParameter, stat);
624 stat = GdipGetImageFlags(img, NULL);
625 expect(InvalidParameter, stat);
628 static void test_GdipCloneImage(void)
634 GpImage *image_src, *image_dest = NULL;
635 const INT WIDTH = 10, HEIGHT = 20;
637 /* Create an image, clone it, delete the original, make sure the copy works */
638 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
640 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
642 image_src = ((GpImage*)bm);
643 stat = GdipCloneImage(image_src, &image_dest);
645 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
647 stat = GdipDisposeImage((GpImage*)bm);
649 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
652 /* Treat FP values carefully */
653 expectf((REAL)WIDTH, rectF.Width);
654 expectf((REAL)HEIGHT, rectF.Height);
656 stat = GdipDisposeImage(image_dest);
660 static void test_testcontrol(void)
666 stat = GdipTestControl(TestControlGetBuildNumber, ¶m);
668 ok(param != 0, "Build number expected, got %u\n", param);
671 static void test_fromhicon(void)
673 static const BYTE bmp_bits[1024];
674 HBITMAP hbmMask, hbmColor;
678 GpBitmap *bitmap = NULL;
684 stat = GdipCreateBitmapFromHICON(NULL, NULL);
685 expect(InvalidParameter, stat);
686 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
687 expect(InvalidParameter, stat);
689 /* color icon 1 bit */
690 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
691 ok(hbmMask != 0, "CreateBitmap failed\n");
692 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
693 ok(hbmColor != 0, "CreateBitmap failed\n");
697 info.hbmMask = hbmMask;
698 info.hbmColor = hbmColor;
699 hIcon = CreateIconIndirect(&info);
700 ok(hIcon != 0, "CreateIconIndirect failed\n");
701 DeleteObject(hbmMask);
702 DeleteObject(hbmColor);
704 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
706 broken(stat == InvalidParameter), /* Win98 */
707 "Expected Ok, got %.8x\n", stat);
709 /* check attributes */
710 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
713 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
716 stat = GdipGetImageType((GpImage*)bitmap, &type);
718 expect(ImageTypeBitmap, type);
719 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
720 expect(PixelFormat32bppARGB, format);
722 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
723 GdipDisposeImage((GpImage*)bitmap);
727 /* color icon 8 bpp */
728 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
729 ok(hbmMask != 0, "CreateBitmap failed\n");
730 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
731 ok(hbmColor != 0, "CreateBitmap failed\n");
735 info.hbmMask = hbmMask;
736 info.hbmColor = hbmColor;
737 hIcon = CreateIconIndirect(&info);
738 ok(hIcon != 0, "CreateIconIndirect failed\n");
739 DeleteObject(hbmMask);
740 DeleteObject(hbmColor);
742 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
745 /* check attributes */
746 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
749 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
752 stat = GdipGetImageType((GpImage*)bitmap, &type);
754 expect(ImageTypeBitmap, type);
755 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
756 expect(PixelFormat32bppARGB, format);
758 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
759 GdipDisposeImage((GpImage*)bitmap);
765 static const unsigned char pngimage[285] = {
766 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
767 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
768 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
769 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
770 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
771 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
772 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
775 static const unsigned char gifimage[35] = {
776 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
777 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
781 static const unsigned char bmpimage[66] = {
782 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
783 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
784 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
785 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
789 static const unsigned char jpgimage[285] = {
790 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
791 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
792 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
793 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
794 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
795 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
796 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
797 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
798 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
799 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
800 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
801 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
802 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
803 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
804 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
805 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
806 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
807 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
810 static const unsigned char tiffimage[] = {
811 0x49,0x49,0x2a,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xfe,0x00,
812 0x04,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x00,0x01,0x00,
813 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
814 0x00,0x00,0x02,0x01,0x03,0x00,0x03,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0x03,0x01,
815 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,0x01,0x03,0x00,0x01,0x00,
816 0x00,0x00,0x02,0x00,0x00,0x00,0x0d,0x01,0x02,0x00,0x1b,0x00,0x00,0x00,0xd8,0x00,
817 0x00,0x00,0x11,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x12,0x01,
818 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x01,0x03,0x00,0x01,0x00,
819 0x00,0x00,0x03,0x00,0x00,0x00,0x16,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x40,0x00,
820 0x00,0x00,0x17,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1a,0x01,
821 0x05,0x00,0x01,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x1b,0x01,0x05,0x00,0x01,0x00,
822 0x00,0x00,0xfc,0x00,0x00,0x00,0x1c,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
823 0x00,0x00,0x28,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
824 0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x6d,0x65,
825 0x68,0x2f,0x44,0x65,0x73,0x6b,0x74,0x6f,0x70,0x2f,0x74,0x65,0x73,0x74,0x2e,0x74,
826 0x69,0x66,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,
829 /* 320x320 twip wmf */
830 static const unsigned char wmfimage[180] = {
831 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
832 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
833 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
834 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
835 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
836 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
837 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
838 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
839 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
840 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
841 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
844 static void test_getrawformat(void)
846 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
847 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
848 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
849 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
850 test_bufferrawformat((void*)tiffimage, sizeof(tiffimage), &ImageFormatTIFF, __LINE__, FALSE);
851 test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
854 static void test_loadwmf(void)
865 MetafileHeader header;
867 hglob = GlobalAlloc (0, sizeof(wmfimage));
868 data = GlobalLock (hglob);
869 memcpy(data, wmfimage, sizeof(wmfimage));
870 GlobalUnlock(hglob); data = NULL;
872 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
873 ok(hres == S_OK, "Failed to create a stream\n");
874 if(hres != S_OK) return;
876 stat = GdipLoadImageFromStream(stream, &img);
877 ok(stat == Ok, "Failed to create a Bitmap\n");
879 IStream_Release(stream);
883 IStream_Release(stream);
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 todo_wine expectf(1440.0, res);
897 stat = GdipGetImageVerticalResolution(img, &res);
899 todo_wine expectf(1440.0, res);
901 memset(&header, 0, sizeof(header));
902 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
906 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
907 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
908 todo_wine expect(0x300, header.Version);
909 expect(0, header.EmfPlusFlags);
910 todo_wine expectf(1440.0, header.DpiX);
911 todo_wine expectf(1440.0, header.DpiY);
914 todo_wine expect(320, header.Width);
915 todo_wine expect(320, header.Height);
916 todo_wine expect(1, U(header).WmfHeader.mtType);
917 expect(0, header.EmfPlusHeaderSize);
918 expect(0, header.LogicalDpiX);
919 expect(0, header.LogicalDpiY);
922 GdipDisposeImage(img);
925 static void test_createfromwmf(void)
933 MetafileHeader header;
935 hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
936 wmfimage+sizeof(WmfPlaceableFileHeader));
937 ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
939 stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
940 (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
943 stat = GdipGetImageBounds(img, &bounds, &unit);
945 todo_wine expect(UnitPixel, unit);
946 expectf(0.0, bounds.X);
947 expectf(0.0, bounds.Y);
948 todo_wine expectf(320.0, bounds.Width);
949 todo_wine expectf(320.0, bounds.Height);
951 stat = GdipGetImageHorizontalResolution(img, &res);
953 expectf(1440.0, res);
955 stat = GdipGetImageVerticalResolution(img, &res);
957 expectf(1440.0, res);
959 memset(&header, 0, sizeof(header));
960 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
964 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
965 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
966 todo_wine expect(0x300, header.Version);
967 expect(0, header.EmfPlusFlags);
968 todo_wine expectf(1440.0, header.DpiX);
969 todo_wine expectf(1440.0, header.DpiY);
972 todo_wine expect(320, header.Width);
973 todo_wine expect(320, header.Height);
974 todo_wine expect(1, U(header).WmfHeader.mtType);
975 expect(0, header.EmfPlusHeaderSize);
976 expect(0, header.LogicalDpiX);
977 expect(0, header.LogicalDpiY);
980 GdipDisposeImage(img);
983 static void test_resolution(void)
989 int screenxres, screenyres;
992 stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
995 /* test invalid values */
996 stat = GdipGetImageHorizontalResolution(NULL, &res);
997 expect(InvalidParameter, stat);
999 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
1000 expect(InvalidParameter, stat);
1002 stat = GdipGetImageVerticalResolution(NULL, &res);
1003 expect(InvalidParameter, stat);
1005 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
1006 expect(InvalidParameter, stat);
1008 stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
1009 expect(InvalidParameter, stat);
1011 stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
1012 expect(InvalidParameter, stat);
1014 /* defaults to screen resolution */
1015 screendc = GetDC(0);
1017 screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
1018 screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
1020 ReleaseDC(0, screendc);
1022 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1024 expectf((REAL)screenxres, res);
1026 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1028 expectf((REAL)screenyres, res);
1030 /* test changing the resolution */
1031 stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
1034 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1036 expectf(screenxres*2.0, res);
1038 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1040 expectf(screenyres*3.0, res);
1042 stat = GdipDisposeImage((GpImage*)bitmap);
1046 static void test_createhbitmap(void)
1050 HBITMAP hbitmap, oldhbitmap;
1057 memset(bits, 0x68, 640);
1060 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
1063 /* test NULL values */
1064 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
1065 expect(InvalidParameter, stat);
1067 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
1068 expect(InvalidParameter, stat);
1070 /* create HBITMAP */
1071 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
1076 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
1077 expect(sizeof(BITMAP), ret);
1079 expect(0, bm.bmType);
1080 expect(10, bm.bmWidth);
1081 expect(20, bm.bmHeight);
1082 expect(40, bm.bmWidthBytes);
1083 expect(1, bm.bmPlanes);
1084 expect(32, bm.bmBitsPixel);
1085 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1087 hdc = CreateCompatibleDC(NULL);
1089 oldhbitmap = SelectObject(hdc, hbitmap);
1090 pixel = GetPixel(hdc, 5, 5);
1091 SelectObject(hdc, oldhbitmap);
1095 expect(0x686868, pixel);
1097 DeleteObject(hbitmap);
1100 stat = GdipDisposeImage((GpImage*)bitmap);
1104 static void test_getsetpixel(void)
1109 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1110 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1112 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1115 /* null parameters */
1116 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1117 expect(InvalidParameter, stat);
1119 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1120 expect(InvalidParameter, stat);
1122 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1123 expect(InvalidParameter, stat);
1126 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1127 expect(InvalidParameter, stat);
1129 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1130 expect(InvalidParameter, stat);
1132 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1133 ok(stat == InvalidParameter ||
1134 broken(stat == Ok), /* Older gdiplus */
1135 "Expected InvalidParameter, got %.8x\n", stat);
1137 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1138 ok(stat == InvalidParameter ||
1139 broken(stat == Ok), /* Older gdiplus */
1140 "Expected InvalidParameter, got %.8x\n", stat);
1142 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1143 expect(InvalidParameter, stat);
1145 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1146 expect(InvalidParameter, stat);
1148 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1149 expect(InvalidParameter, stat);
1151 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1152 expect(InvalidParameter, stat);
1155 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1157 expect(0xffffffff, color);
1159 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1161 expect(0xff0000ff, color);
1163 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1166 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1169 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1171 expect(0xff676869, color);
1173 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1175 expect(0xff474849, color);
1177 stat = GdipDisposeImage((GpImage*)bitmap);
1181 static void check_halftone_palette(ColorPalette *palette)
1183 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1186 for (i=0; i<palette->Count; i++)
1188 ARGB expected=0xff000000;
1191 if (i&1) expected |= 0x800000;
1192 if (i&2) expected |= 0x8000;
1193 if (i&4) expected |= 0x80;
1197 expected = 0xffc0c0c0;
1201 if (i&1) expected |= 0xff0000;
1202 if (i&2) expected |= 0xff00;
1203 if (i&4) expected |= 0xff;
1207 expected = 0x00000000;
1211 expected |= halftone_values[(i-40)%6];
1212 expected |= halftone_values[((i-40)/6)%6] << 8;
1213 expected |= halftone_values[((i-40)/36)%6] << 16;
1215 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1216 expected, palette->Entries[i], i, palette->Count);
1220 static void test_palette(void)
1226 ColorPalette *palette=(ColorPalette*)buffer;
1229 /* test initial palette from non-indexed bitmap */
1230 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1233 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1235 expect(sizeof(UINT)*2+sizeof(ARGB), size);
1237 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1239 expect(0, palette->Count);
1241 /* test setting palette on not-indexed bitmap */
1244 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1247 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1249 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1251 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1253 expect(3, palette->Count);
1255 GdipDisposeImage((GpImage*)bitmap);
1257 /* test initial palette on 1-bit bitmap */
1258 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1261 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1263 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1265 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1267 expect(PaletteFlagsGrayScale, palette->Flags);
1268 expect(2, palette->Count);
1270 expect(0xff000000, palette->Entries[0]);
1271 expect(0xffffffff, palette->Entries[1]);
1273 /* test getting/setting pixels */
1274 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1276 expect(0xff000000, color);
1278 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1279 todo_wine ok((stat == Ok) ||
1280 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1284 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1286 expect(0xffffffff, color);
1289 GdipDisposeImage((GpImage*)bitmap);
1291 /* test initial palette on 4-bit bitmap */
1292 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1295 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1297 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1299 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1301 expect(0, palette->Flags);
1302 expect(16, palette->Count);
1304 check_halftone_palette(palette);
1306 /* test getting/setting pixels */
1307 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1309 expect(0xff000000, color);
1311 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
1312 todo_wine ok((stat == Ok) ||
1313 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1317 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1319 expect(0xffff00ff, color);
1322 GdipDisposeImage((GpImage*)bitmap);
1324 /* test initial palette on 8-bit bitmap */
1325 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1328 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1330 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1332 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1334 expect(PaletteFlagsHalftone, palette->Flags);
1335 expect(256, palette->Count);
1337 check_halftone_palette(palette);
1339 /* test getting/setting pixels */
1340 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1342 expect(0xff000000, color);
1344 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
1345 todo_wine ok((stat == Ok) ||
1346 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1350 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1352 expect(0xffcccccc, color);
1355 /* test setting/getting a different palette */
1356 palette->Entries[1] = 0xffcccccc;
1358 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1361 palette->Entries[1] = 0;
1363 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1365 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1367 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1369 expect(PaletteFlagsHalftone, palette->Flags);
1370 expect(256, palette->Count);
1371 expect(0xffcccccc, palette->Entries[1]);
1373 /* test count < 256 */
1374 palette->Flags = 12345;
1377 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1380 palette->Entries[1] = 0;
1381 palette->Entries[3] = 0xdeadbeef;
1383 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1385 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1387 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1389 expect(12345, palette->Flags);
1390 expect(3, palette->Count);
1391 expect(0xffcccccc, palette->Entries[1]);
1392 expect(0xdeadbeef, palette->Entries[3]);
1394 /* test count > 256 */
1395 palette->Count = 257;
1397 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1398 ok(stat == InvalidParameter ||
1399 broken(stat == Ok), /* Old gdiplus behavior */
1400 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1402 GdipDisposeImage((GpImage*)bitmap);
1405 static void test_colormatrix(void)
1408 ColorMatrix colormatrix, graymatrix;
1409 GpImageAttributes *imageattr;
1410 const ColorMatrix identity = {{
1411 {1.0,0.0,0.0,0.0,0.0},
1412 {0.0,1.0,0.0,0.0,0.0},
1413 {0.0,0.0,1.0,0.0,0.0},
1414 {0.0,0.0,0.0,1.0,0.0},
1415 {0.0,0.0,0.0,0.0,1.0}}};
1416 const ColorMatrix double_red = {{
1417 {2.0,0.0,0.0,0.0,0.0},
1418 {0.0,1.0,0.0,0.0,0.0},
1419 {0.0,0.0,1.0,0.0,0.0},
1420 {0.0,0.0,0.0,1.0,0.0},
1421 {0.0,0.0,0.0,0.0,1.0}}};
1422 GpBitmap *bitmap1, *bitmap2;
1423 GpGraphics *graphics;
1426 colormatrix = identity;
1427 graymatrix = identity;
1429 stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
1430 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1431 expect(InvalidParameter, stat);
1433 stat = GdipCreateImageAttributes(&imageattr);
1436 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1437 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1440 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1441 TRUE, NULL, NULL, ColorMatrixFlagsDefault);
1442 expect(InvalidParameter, stat);
1444 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1445 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1448 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1449 TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
1452 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1453 TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
1454 expect(InvalidParameter, stat);
1456 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1457 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
1460 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1461 TRUE, &colormatrix, &graymatrix, 3);
1462 expect(InvalidParameter, stat);
1464 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
1465 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1466 expect(InvalidParameter, stat);
1468 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
1469 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1470 expect(InvalidParameter, stat);
1472 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1473 FALSE, NULL, NULL, ColorMatrixFlagsDefault);
1476 /* Drawing a bitmap transforms the colors */
1477 colormatrix = double_red;
1478 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1479 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1482 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1485 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1488 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ffff);
1491 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1494 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1495 UnitPixel, imageattr, NULL, NULL);
1498 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1500 todo_wine expect(0xff80ffff, color);
1502 GdipDeleteGraphics(graphics);
1503 GdipDisposeImage((GpImage*)bitmap1);
1504 GdipDisposeImage((GpImage*)bitmap2);
1505 GdipDisposeImageAttributes(imageattr);
1508 static void test_gamma(void)
1511 GpImageAttributes *imageattr;
1512 GpBitmap *bitmap1, *bitmap2;
1513 GpGraphics *graphics;
1516 stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
1517 expect(InvalidParameter, stat);
1519 stat = GdipCreateImageAttributes(&imageattr);
1522 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
1525 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
1526 expect(InvalidParameter, stat);
1528 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
1529 expect(InvalidParameter, stat);
1531 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
1532 expect(InvalidParameter, stat);
1534 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
1537 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
1540 /* Drawing a bitmap transforms the colors */
1541 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
1544 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1547 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1550 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
1553 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1556 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1557 UnitPixel, imageattr, NULL, NULL);
1560 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1562 todo_wine ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
1564 GdipDeleteGraphics(graphics);
1565 GdipDisposeImage((GpImage*)bitmap1);
1566 GdipDisposeImage((GpImage*)bitmap2);
1567 GdipDisposeImageAttributes(imageattr);
1570 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
1571 static const unsigned char gifanimation[72] = {
1572 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1573 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
1574 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
1575 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
1576 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
1579 static void test_multiframegif(void)
1591 /* Test frame functions with an animated GIF */
1592 hglob = GlobalAlloc (0, sizeof(gifanimation));
1593 data = GlobalLock (hglob);
1594 memcpy(data, gifanimation, sizeof(gifanimation));
1595 GlobalUnlock(hglob);
1597 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1598 ok(hres == S_OK, "Failed to create a stream\n");
1599 if(hres != S_OK) return;
1601 stat = GdipCreateBitmapFromStream(stream, &bmp);
1602 ok(stat == Ok, "Failed to create a Bitmap\n");
1604 IStream_Release(stream);
1608 /* Bitmap starts at frame 0 */
1610 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1612 expect(0xffffffff, color);
1614 /* Check that we get correct metadata */
1615 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1619 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1621 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1624 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1626 todo_wine expect(2, count);
1628 /* SelectActiveFrame overwrites our current data */
1629 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1633 GdipBitmapGetPixel(bmp, 0, 0, &color);
1635 todo_wine expect(0xff000000, color);
1637 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1641 GdipBitmapGetPixel(bmp, 0, 0, &color);
1643 expect(0xffffffff, color);
1645 /* Write over the image data */
1646 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
1649 /* Switching to the same frame does not overwrite our changes */
1650 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1653 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1655 expect(0xff000000, color);
1657 /* But switching to another frame and back does */
1658 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1661 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1664 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1666 todo_wine expect(0xffffffff, color);
1668 GdipDisposeImage((GpImage*)bmp);
1669 IStream_Release(stream);
1671 /* Test with a non-animated gif */
1672 hglob = GlobalAlloc (0, sizeof(gifimage));
1673 data = GlobalLock (hglob);
1674 memcpy(data, gifimage, sizeof(gifimage));
1675 GlobalUnlock(hglob);
1677 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1678 ok(hres == S_OK, "Failed to create a stream\n");
1679 if(hres != S_OK) return;
1681 stat = GdipCreateBitmapFromStream(stream, &bmp);
1682 ok(stat == Ok, "Failed to create a Bitmap\n");
1684 IStream_Release(stream);
1688 /* Check metadata */
1689 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1693 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1695 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1698 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1702 GdipDisposeImage((GpImage*)bmp);
1703 IStream_Release(stream);
1706 static void test_rotateflip(void)
1711 static const BYTE orig_bits[24] = {
1712 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
1713 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
1717 memcpy(bits, orig_bits, sizeof(bits));
1718 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1721 stat = GdipImageRotateFlip(bitmap, Rotate90FlipNone);
1722 todo_wine expect(Ok, stat);
1724 stat = GdipGetImageWidth(bitmap, &width);
1726 stat = GdipGetImageHeight(bitmap, &height);
1728 todo_wine expect(2, width);
1729 todo_wine expect(3, height);
1731 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1733 todo_wine expect(0xff00ffff, color);
1735 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 0, &color);
1737 todo_wine expect(0xffff0000, color);
1739 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 2, &color);
1740 todo_wine expect(Ok, stat);
1741 todo_wine expect(0xffffff00, color);
1743 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 2, &color);
1744 todo_wine expect(Ok, stat);
1745 todo_wine expect(0xff0000ff, color);
1749 expect(0xff, bits[2]);
1751 GdipDisposeImage(bitmap);
1753 memcpy(bits, orig_bits, sizeof(bits));
1754 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1757 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipX);
1758 todo_wine expect(Ok, stat);
1760 stat = GdipGetImageWidth(bitmap, &width);
1762 stat = GdipGetImageHeight(bitmap, &height);
1767 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1769 todo_wine expect(0xff0000ff, color);
1771 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
1773 todo_wine expect(0xffff0000, color);
1775 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
1777 todo_wine expect(0xffffff00, color);
1779 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
1781 todo_wine expect(0xff00ffff, color);
1785 expect(0xff, bits[2]);
1787 GdipDisposeImage(bitmap);
1789 memcpy(bits, orig_bits, sizeof(bits));
1790 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
1793 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipY);
1794 todo_wine expect(Ok, stat);
1796 stat = GdipGetImageWidth(bitmap, &width);
1798 stat = GdipGetImageHeight(bitmap, &height);
1803 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
1805 todo_wine expect(0xff00ffff, color);
1807 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
1809 todo_wine expect(0xffffff00, color);
1811 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
1813 todo_wine expect(0xffff0000, color);
1815 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
1817 todo_wine expect(0xff0000ff, color);
1821 expect(0xff, bits[2]);
1823 GdipDisposeImage(bitmap);
1826 static void test_remaptable(void)
1829 GpImageAttributes *imageattr;
1830 GpBitmap *bitmap1, *bitmap2;
1831 GpGraphics *graphics;
1835 map = GdipAlloc(sizeof(ColorMap));
1837 map->oldColor.Argb = 0xff00ff00;
1838 map->newColor.Argb = 0xffff00ff;
1840 stat = GdipSetImageAttributesRemapTable(NULL, ColorAdjustTypeDefault, TRUE, 1, map);
1841 expect(InvalidParameter, stat);
1843 stat = GdipCreateImageAttributes(&imageattr);
1846 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, NULL);
1847 expect(InvalidParameter, stat);
1849 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeCount, TRUE, 1, map);
1850 expect(InvalidParameter, stat);
1852 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeAny, TRUE, 1, map);
1853 expect(InvalidParameter, stat);
1855 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 0, map);
1856 expect(InvalidParameter, stat);
1858 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, FALSE, 0, NULL);
1861 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, map);
1864 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1867 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1870 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff00ff00);
1873 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1876 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1877 UnitPixel, imageattr, NULL, NULL);
1880 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1882 todo_wine ok(color_match(0xffff00ff, color, 1), "Expected ffff00ff, got %.8x\n", color);
1884 GdipDeleteGraphics(graphics);
1885 GdipDisposeImage((GpImage*)bitmap1);
1886 GdipDisposeImage((GpImage*)bitmap2);
1887 GdipDisposeImageAttributes(imageattr);
1893 struct GdiplusStartupInput gdiplusStartupInput;
1894 ULONG_PTR gdiplusToken;
1896 gdiplusStartupInput.GdiplusVersion = 1;
1897 gdiplusStartupInput.DebugEventCallback = NULL;
1898 gdiplusStartupInput.SuppressBackgroundThread = 0;
1899 gdiplusStartupInput.SuppressExternalCodecs = 0;
1901 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1904 test_GetImageDimension();
1905 test_GdipImageGetFrameDimensionsCount();
1906 test_LoadingImages();
1907 test_SavingImages();
1910 test_GdipCreateBitmapFromHBITMAP();
1911 test_GdipGetImageFlags();
1912 test_GdipCloneImage();
1915 test_getrawformat();
1917 test_createfromwmf();
1919 test_createhbitmap();
1924 test_multiframegif();
1928 GdiplusShutdown(gdiplusToken);