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 void expect_guid(REFGUID expected, REFGUID got, int line, BOOL todo)
39 StringFromGUID2(got, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
40 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer, sizeof(buffer), NULL, NULL);
41 StringFromGUID2(expected, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
42 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer2, sizeof(buffer2), NULL, NULL);
44 todo_wine ok_(__FILE__, line)(IsEqualGUID(expected, got), "Expected %s, got %s\n", buffer2, buffer);
46 ok_(__FILE__, line)(IsEqualGUID(expected, got), "Expected %s, got %s\n", buffer2, buffer);
49 static void expect_rawformat(REFGUID expected, GpImage *img, int line, BOOL todo)
54 stat = GdipGetImageRawFormat(img, &raw);
55 ok_(__FILE__, line)(stat == Ok, "GdipGetImageRawFormat failed with %d\n", stat);
56 if(stat != Ok) return;
57 expect_guid(expected, &raw, line, todo);
60 static void test_bufferrawformat(void* buff, int size, REFGUID expected, int line, BOOL todo)
69 hglob = GlobalAlloc (0, size);
70 data = GlobalLock (hglob);
71 memcpy(data, buff, size);
72 GlobalUnlock(hglob); data = NULL;
74 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
75 ok_(__FILE__, line)(hres == S_OK, "Failed to create a stream\n");
76 if(hres != S_OK) return;
78 stat = GdipLoadImageFromStream(stream, &img);
79 ok_(__FILE__, line)(stat == Ok, "Failed to create a Bitmap\n");
81 IStream_Release(stream);
85 expect_rawformat(expected, img, line, todo);
87 GdipDisposeImage(img);
88 IStream_Release(stream);
91 static void test_Scan0(void)
98 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
100 ok(NULL != bm, "Expected bitmap to be initialized\n");
102 GdipDisposeImage((GpImage*)bm);
104 bm = (GpBitmap*)0xdeadbeef;
105 stat = GdipCreateBitmapFromScan0(10, -10, 10, PixelFormat24bppRGB, NULL, &bm);
106 expect(InvalidParameter, stat);
107 ok( !bm, "expected null bitmap\n" );
109 bm = (GpBitmap*)0xdeadbeef;
110 stat = GdipCreateBitmapFromScan0(-10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
111 expect(InvalidParameter, stat);
112 ok( !bm, "expected null bitmap\n" );
114 bm = (GpBitmap*)0xdeadbeef;
115 stat = GdipCreateBitmapFromScan0(10, 0, 10, PixelFormat24bppRGB, NULL, &bm);
116 expect(InvalidParameter, stat);
117 ok( !bm, "expected null bitmap\n" );
120 stat = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, buff, &bm);
122 ok(NULL != bm, "Expected bitmap to be initialized\n");
124 GdipDisposeImage((GpImage*)bm);
126 bm = (GpBitmap*) 0xdeadbeef;
127 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, buff, &bm);
128 expect(InvalidParameter, stat);
129 ok( !bm, "expected null bitmap\n" );
131 bm = (GpBitmap*)0xdeadbeef;
132 stat = GdipCreateBitmapFromScan0(10, 10, 0, PixelFormat24bppRGB, buff, &bm);
133 expect(InvalidParameter, stat);
134 ok( bm == (GpBitmap*)0xdeadbeef, "expected deadbeef bitmap\n" );
137 stat = GdipCreateBitmapFromScan0(10, 10, -8, PixelFormat24bppRGB, buff, &bm);
139 ok(NULL != bm, "Expected bitmap to be initialized\n");
141 GdipDisposeImage((GpImage*)bm);
143 bm = (GpBitmap*)0xdeadbeef;
144 stat = GdipCreateBitmapFromScan0(10, 10, -10, PixelFormat24bppRGB, buff, &bm);
145 expect(InvalidParameter, stat);
146 ok( !bm, "expected null bitmap\n" );
149 static void test_GetImageDimension(void)
153 const REAL WIDTH = 10.0, HEIGHT = 20.0;
156 bm = (GpBitmap*)0xdeadbeef;
157 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
159 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
160 ok(NULL != bm, "Expected bitmap to not be NULL\n");
162 stat = GdipGetImageDimension(NULL,&w,&h);
163 expect(InvalidParameter, stat);
165 stat = GdipGetImageDimension((GpImage*)bm,NULL,&h);
166 expect(InvalidParameter, stat);
168 stat = GdipGetImageDimension((GpImage*)bm,&w,NULL);
169 expect(InvalidParameter, stat);
173 stat = GdipGetImageDimension((GpImage*)bm,&w,&h);
177 GdipDisposeImage((GpImage*)bm);
180 static void test_GdipImageGetFrameDimensionsCount(void)
184 const REAL WIDTH = 10.0, HEIGHT = 20.0;
186 GUID dimension = {0};
190 bm = (GpBitmap*)0xdeadbeef;
191 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
193 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
194 ok(NULL != bm, "Expected bitmap to not be NULL\n");
196 stat = GdipImageGetFrameDimensionsCount(NULL,&w);
197 expect(InvalidParameter, stat);
199 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,NULL);
200 expect(InvalidParameter, stat);
203 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,&w);
207 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 1);
209 expect_guid(&FrameDimensionPage, &dimension, __LINE__, FALSE);
211 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 2);
212 expect(InvalidParameter, stat);
214 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 0);
215 expect(InvalidParameter, stat);
218 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, &count);
219 todo_wine expect(Ok, stat);
220 todo_wine expect(1, count);
222 GdipBitmapSetPixel(bm, 0, 0, 0xffffffff);
224 stat = GdipImageSelectActiveFrame((GpImage*)bm, &dimension, 0);
227 /* SelectActiveFrame has no effect on image data of memory bitmaps */
229 GdipBitmapGetPixel(bm, 0, 0, &color);
230 expect(0xffffffff, color);
232 GdipDisposeImage((GpImage*)bm);
235 static void test_LoadingImages(void)
239 stat = GdipCreateBitmapFromFile(0, 0);
240 expect(InvalidParameter, stat);
242 stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
243 expect(InvalidParameter, stat);
245 stat = GdipLoadImageFromFile(0, 0);
246 expect(InvalidParameter, stat);
248 stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
249 expect(InvalidParameter, stat);
251 stat = GdipLoadImageFromFileICM(0, 0);
252 expect(InvalidParameter, stat);
254 stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
255 expect(InvalidParameter, stat);
258 static void test_SavingImages(void)
264 const REAL WIDTH = 10.0, HEIGHT = 20.0;
266 ImageCodecInfo *codecs;
267 static const CHAR filenameA[] = "a.bmp";
268 static const WCHAR filename[] = { 'a','.','b','m','p',0 };
272 stat = GdipSaveImageToFile(0, 0, 0, 0);
273 expect(InvalidParameter, stat);
276 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
282 stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
283 expect(InvalidParameter, stat);
285 stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
286 expect(InvalidParameter, stat);
288 /* encoder tests should succeed -- already tested */
289 stat = GdipGetImageEncodersSize(&n, &s);
290 if (stat != Ok || n == 0) goto cleanup;
292 codecs = GdipAlloc(s);
293 if (!codecs) goto cleanup;
295 stat = GdipGetImageEncoders(n, s, codecs);
296 if (stat != Ok) goto cleanup;
298 stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
301 GdipDisposeImage((GpImage*)bm);
304 /* re-load and check image stats */
305 stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
307 if (stat != Ok) goto cleanup;
309 stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
310 if (stat != Ok) goto cleanup;
318 GdipDisposeImage((GpImage*)bm);
319 ok(DeleteFileA(filenameA), "Delete failed.\n");
322 static void test_encoders(void)
327 ImageCodecInfo *codecs;
331 static const CHAR bmp_format[] = "BMP";
333 stat = GdipGetImageEncodersSize(&n, &s);
336 codecs = GdipAlloc(s);
340 stat = GdipGetImageEncoders(n, s, NULL);
341 expect(GenericError, stat);
343 stat = GdipGetImageEncoders(0, s, codecs);
344 expect(GenericError, stat);
346 stat = GdipGetImageEncoders(n, s-1, codecs);
347 expect(GenericError, stat);
349 stat = GdipGetImageEncoders(n, s+1, codecs);
350 expect(GenericError, stat);
352 stat = GdipGetImageEncoders(n, s, codecs);
356 for (i = 0; i < n; i++)
360 WideCharToMultiByte(CP_ACP, 0, codecs[i].FormatDescription, -1,
363 if (CompareStringA(LOCALE_SYSTEM_DEFAULT, 0,
365 bmp_format, -1) == CSTR_EQUAL) {
371 ok(FALSE, "No BMP codec found.\n");
376 static void test_LockBits(void)
382 const INT WIDTH = 10, HEIGHT = 20;
385 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
394 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
398 stat = GdipBitmapUnlockBits(bm, &bd);
402 /* read-only, with NULL rect -> whole bitmap lock */
403 stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
405 expect(bd.Width, WIDTH);
406 expect(bd.Height, HEIGHT);
409 stat = GdipBitmapUnlockBits(bm, &bd);
413 /* read-only, consecutive */
414 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
418 stat = GdipBitmapUnlockBits(bm, &bd);
422 stat = GdipDisposeImage((GpImage*)bm);
424 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
428 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
430 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
431 expect(WrongState, stat);
433 stat = GdipBitmapUnlockBits(bm, &bd);
436 stat = GdipDisposeImage((GpImage*)bm);
438 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
441 /* write, no modification */
442 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
446 stat = GdipBitmapUnlockBits(bm, &bd);
450 /* write, consecutive */
451 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
455 stat = GdipBitmapUnlockBits(bm, &bd);
459 stat = GdipDisposeImage((GpImage*)bm);
461 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
465 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
470 ((char*)bd.Scan0)[2] = 0xff;
472 stat = GdipBitmapUnlockBits(bm, &bd);
476 stat = GdipDisposeImage((GpImage*)bm);
480 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
482 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
484 stat = GdipDisposeImage((GpImage*)bm);
488 static void test_GdipCreateBitmapFromHBITMAP(void)
490 GpBitmap* gpbm = NULL;
492 HPALETTE hpal = NULL;
495 LOGPALETTE* LogPal = NULL;
497 const REAL WIDTH1 = 5;
498 const REAL HEIGHT1 = 15;
499 const REAL WIDTH2 = 10;
500 const REAL HEIGHT2 = 20;
505 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
506 expect(InvalidParameter, stat);
508 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
509 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
510 expect(InvalidParameter, stat);
512 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
514 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
515 expectf(WIDTH1, width);
516 expectf(HEIGHT1, height);
518 GdipDisposeImage((GpImage*)gpbm);
521 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
522 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
525 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
527 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
528 expectf(WIDTH2, width);
529 expectf(HEIGHT2, height);
531 GdipDisposeImage((GpImage*)gpbm);
534 hdc = CreateCompatibleDC(0);
535 ok(hdc != NULL, "CreateCompatibleDC failed\n");
536 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
537 bmi.bmiHeader.biHeight = HEIGHT1;
538 bmi.bmiHeader.biWidth = WIDTH1;
539 bmi.bmiHeader.biBitCount = 24;
540 bmi.bmiHeader.biPlanes = 1;
541 bmi.bmiHeader.biCompression = BI_RGB;
543 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
544 ok(hbm != NULL, "CreateDIBSection failed\n");
548 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
550 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
551 expectf(WIDTH1, width);
552 expectf(HEIGHT1, height);
555 /* test whether writing to the bitmap affects the original */
556 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
561 GdipDisposeImage((GpImage*)gpbm);
564 LogPal = GdipAlloc(sizeof(LOGPALETTE));
565 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
566 LogPal->palVersion = 0x300;
567 LogPal->palNumEntries = 1;
568 hpal = CreatePalette(LogPal);
569 ok(hpal != NULL, "CreatePalette failed\n");
572 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
578 GdipDisposeImage((GpImage*)gpbm);
584 static void test_GdipGetImageFlags(void)
590 img = (GpImage*)0xdeadbeef;
592 stat = GdipGetImageFlags(NULL, NULL);
593 expect(InvalidParameter, stat);
595 stat = GdipGetImageFlags(NULL, &flags);
596 expect(InvalidParameter, stat);
598 stat = GdipGetImageFlags(img, NULL);
599 expect(InvalidParameter, stat);
602 static void test_GdipCloneImage(void)
608 GpImage *image_src, *image_dest = NULL;
609 const INT WIDTH = 10, HEIGHT = 20;
611 /* Create an image, clone it, delete the original, make sure the copy works */
612 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
614 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
616 image_src = ((GpImage*)bm);
617 stat = GdipCloneImage(image_src, &image_dest);
619 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
621 stat = GdipDisposeImage((GpImage*)bm);
623 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
626 /* Treat FP values carefully */
627 expectf((REAL)WIDTH, rectF.Width);
628 expectf((REAL)HEIGHT, rectF.Height);
630 stat = GdipDisposeImage(image_dest);
634 static void test_testcontrol(void)
640 stat = GdipTestControl(TestControlGetBuildNumber, ¶m);
642 ok(param != 0, "Build number expected, got %u\n", param);
645 static void test_fromhicon(void)
647 static const BYTE bmp_bits[1024];
648 HBITMAP hbmMask, hbmColor;
652 GpBitmap *bitmap = NULL;
658 stat = GdipCreateBitmapFromHICON(NULL, NULL);
659 expect(InvalidParameter, stat);
660 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
661 expect(InvalidParameter, stat);
663 /* color icon 1 bit */
664 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
665 ok(hbmMask != 0, "CreateBitmap failed\n");
666 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
667 ok(hbmColor != 0, "CreateBitmap failed\n");
671 info.hbmMask = hbmMask;
672 info.hbmColor = hbmColor;
673 hIcon = CreateIconIndirect(&info);
674 ok(hIcon != 0, "CreateIconIndirect failed\n");
675 DeleteObject(hbmMask);
676 DeleteObject(hbmColor);
678 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
680 broken(stat == InvalidParameter), /* Win98 */
681 "Expected Ok, got %.8x\n", stat);
683 /* check attributes */
684 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
687 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
690 stat = GdipGetImageType((GpImage*)bitmap, &type);
692 expect(ImageTypeBitmap, type);
693 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
694 expect(PixelFormat32bppARGB, format);
696 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
697 GdipDisposeImage((GpImage*)bitmap);
701 /* color icon 8 bpp */
702 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
703 ok(hbmMask != 0, "CreateBitmap failed\n");
704 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
705 ok(hbmColor != 0, "CreateBitmap failed\n");
709 info.hbmMask = hbmMask;
710 info.hbmColor = hbmColor;
711 hIcon = CreateIconIndirect(&info);
712 ok(hIcon != 0, "CreateIconIndirect failed\n");
713 DeleteObject(hbmMask);
714 DeleteObject(hbmColor);
716 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
719 /* check attributes */
720 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
723 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
726 stat = GdipGetImageType((GpImage*)bitmap, &type);
728 expect(ImageTypeBitmap, type);
729 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
730 expect(PixelFormat32bppARGB, format);
732 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
733 GdipDisposeImage((GpImage*)bitmap);
739 static const unsigned char pngimage[285] = {
740 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
741 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
742 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
743 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
744 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
745 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
746 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
749 static const unsigned char gifimage[35] = {
750 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
751 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
755 static const unsigned char bmpimage[66] = {
756 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
757 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
758 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
759 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
763 static const unsigned char jpgimage[285] = {
764 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
765 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
766 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
767 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
768 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
769 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
770 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
771 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
772 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
773 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
774 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
775 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
776 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
777 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
778 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
779 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
780 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
781 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
783 /* 320x320 twip wmf */
784 static const unsigned char wmfimage[180] = {
785 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
786 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
787 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
788 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
789 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
790 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
791 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
792 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
793 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
794 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
795 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
798 static void test_getrawformat(void)
800 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
801 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
802 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
803 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
804 test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
807 static void test_loadwmf(void)
819 hglob = GlobalAlloc (0, sizeof(wmfimage));
820 data = GlobalLock (hglob);
821 memcpy(data, wmfimage, sizeof(wmfimage));
822 GlobalUnlock(hglob); data = NULL;
824 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
825 ok(hres == S_OK, "Failed to create a stream\n");
826 if(hres != S_OK) return;
828 stat = GdipLoadImageFromStream(stream, &img);
829 ok(stat == Ok, "Failed to create a Bitmap\n");
831 IStream_Release(stream);
835 IStream_Release(stream);
837 stat = GdipGetImageBounds(img, &bounds, &unit);
839 todo_wine expect(UnitPixel, unit);
840 expectf(0.0, bounds.X);
841 expectf(0.0, bounds.Y);
842 todo_wine expectf(320.0, bounds.Width);
843 todo_wine expectf(320.0, bounds.Height);
845 stat = GdipGetImageHorizontalResolution(img, &res);
847 todo_wine expectf(1440.0, res);
849 stat = GdipGetImageVerticalResolution(img, &res);
851 todo_wine expectf(1440.0, res);
853 GdipDisposeImage(img);
856 static void test_createfromwmf(void)
865 hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
866 wmfimage+sizeof(WmfPlaceableFileHeader));
867 ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
869 stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
870 (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
873 stat = GdipGetImageBounds(img, &bounds, &unit);
875 todo_wine expect(UnitPixel, unit);
876 expectf(0.0, bounds.X);
877 expectf(0.0, bounds.Y);
878 todo_wine expectf(320.0, bounds.Width);
879 todo_wine expectf(320.0, bounds.Height);
881 stat = GdipGetImageHorizontalResolution(img, &res);
883 expectf(1440.0, res);
885 stat = GdipGetImageVerticalResolution(img, &res);
887 expectf(1440.0, res);
889 GdipDisposeImage(img);
892 static void test_resolution(void)
898 int screenxres, screenyres;
901 stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
904 /* test invalid values */
905 stat = GdipGetImageHorizontalResolution(NULL, &res);
906 expect(InvalidParameter, stat);
908 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
909 expect(InvalidParameter, stat);
911 stat = GdipGetImageVerticalResolution(NULL, &res);
912 expect(InvalidParameter, stat);
914 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
915 expect(InvalidParameter, stat);
917 stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
918 todo_wine expect(InvalidParameter, stat);
920 stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
921 todo_wine expect(InvalidParameter, stat);
923 /* defaults to screen resolution */
926 screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
927 screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
929 ReleaseDC(0, screendc);
931 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
933 expectf((REAL)screenxres, res);
935 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
937 expectf((REAL)screenyres, res);
939 /* test changing the resolution */
940 stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
941 todo_wine expect(Ok, stat);
943 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
945 todo_wine expectf(screenxres*2.0, res);
947 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
949 todo_wine expectf(screenyres*3.0, res);
951 stat = GdipDisposeImage((GpImage*)bitmap);
955 static void test_createhbitmap(void)
959 HBITMAP hbitmap, oldhbitmap;
966 memset(bits, 0x68, 640);
969 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
972 /* test NULL values */
973 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
974 expect(InvalidParameter, stat);
976 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
977 expect(InvalidParameter, stat);
980 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
985 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
986 expect(sizeof(BITMAP), ret);
988 expect(0, bm.bmType);
989 expect(10, bm.bmWidth);
990 expect(20, bm.bmHeight);
991 expect(40, bm.bmWidthBytes);
992 expect(1, bm.bmPlanes);
993 expect(32, bm.bmBitsPixel);
994 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
996 hdc = CreateCompatibleDC(NULL);
998 oldhbitmap = SelectObject(hdc, hbitmap);
999 pixel = GetPixel(hdc, 5, 5);
1000 SelectObject(hdc, oldhbitmap);
1004 expect(0x686868, pixel);
1006 DeleteObject(hbitmap);
1009 stat = GdipDisposeImage((GpImage*)bitmap);
1013 static void test_getsetpixel(void)
1018 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1019 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1021 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1024 /* null parameters */
1025 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1026 expect(InvalidParameter, stat);
1028 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1029 expect(InvalidParameter, stat);
1031 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1032 expect(InvalidParameter, stat);
1035 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1036 expect(InvalidParameter, stat);
1038 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1039 expect(InvalidParameter, stat);
1041 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1042 ok(stat == InvalidParameter ||
1043 broken(stat == Ok), /* Older gdiplus */
1044 "Expected InvalidParameter, got %.8x\n", stat);
1046 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1047 ok(stat == InvalidParameter ||
1048 broken(stat == Ok), /* Older gdiplus */
1049 "Expected InvalidParameter, got %.8x\n", stat);
1051 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1052 expect(InvalidParameter, stat);
1054 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1055 expect(InvalidParameter, stat);
1057 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1058 expect(InvalidParameter, stat);
1060 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1061 expect(InvalidParameter, stat);
1064 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1066 expect(0xffffffff, color);
1068 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1070 expect(0xff0000ff, color);
1072 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1075 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1078 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1080 expect(0xff676869, color);
1082 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1084 expect(0xff474849, color);
1086 stat = GdipDisposeImage((GpImage*)bitmap);
1090 static void check_halftone_palette(ColorPalette *palette)
1092 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1095 for (i=0; i<palette->Count; i++)
1097 ARGB expected=0xff000000;
1100 if (i&1) expected |= 0x800000;
1101 if (i&2) expected |= 0x8000;
1102 if (i&4) expected |= 0x80;
1106 expected = 0xffc0c0c0;
1110 if (i&1) expected |= 0xff0000;
1111 if (i&2) expected |= 0xff00;
1112 if (i&4) expected |= 0xff;
1116 expected = 0x00000000;
1120 expected |= halftone_values[(i-40)%6];
1121 expected |= halftone_values[((i-40)/6)%6] << 8;
1122 expected |= halftone_values[((i-40)/36)%6] << 16;
1124 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1125 expected, palette->Entries[i], i, palette->Count);
1129 static void test_palette(void)
1135 ColorPalette *palette=(ColorPalette*)buffer;
1137 /* test initial palette from non-indexed bitmap */
1138 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1141 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1143 expect(sizeof(UINT)*2+sizeof(ARGB), size);
1145 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1147 expect(0, palette->Count);
1149 /* test setting palette on not-indexed bitmap */
1152 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1155 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1157 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1159 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1161 expect(3, palette->Count);
1163 GdipDisposeImage((GpImage*)bitmap);
1165 /* test initial palette on 1-bit bitmap */
1166 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1169 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1171 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1173 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1175 expect(PaletteFlagsGrayScale, palette->Flags);
1176 expect(2, palette->Count);
1178 expect(0xff000000, palette->Entries[0]);
1179 expect(0xffffffff, palette->Entries[1]);
1181 GdipDisposeImage((GpImage*)bitmap);
1183 /* test initial palette on 4-bit bitmap */
1184 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1187 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1189 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1191 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1193 expect(0, palette->Flags);
1194 expect(16, palette->Count);
1196 check_halftone_palette(palette);
1198 GdipDisposeImage((GpImage*)bitmap);
1200 /* test initial palette on 8-bit bitmap */
1201 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1204 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1206 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1208 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1210 expect(PaletteFlagsHalftone, palette->Flags);
1211 expect(256, palette->Count);
1213 check_halftone_palette(palette);
1215 /* test setting/getting a different palette */
1216 palette->Entries[1] = 0xffcccccc;
1218 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1221 palette->Entries[1] = 0;
1223 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1225 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1227 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1229 expect(PaletteFlagsHalftone, palette->Flags);
1230 expect(256, palette->Count);
1231 expect(0xffcccccc, palette->Entries[1]);
1233 /* test count < 256 */
1234 palette->Flags = 12345;
1237 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1240 palette->Entries[1] = 0;
1241 palette->Entries[3] = 0xdeadbeef;
1243 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1245 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1247 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1249 expect(12345, palette->Flags);
1250 expect(3, palette->Count);
1251 expect(0xffcccccc, palette->Entries[1]);
1252 expect(0xdeadbeef, palette->Entries[3]);
1254 /* test count > 256 */
1255 palette->Count = 257;
1257 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1258 ok(stat == InvalidParameter ||
1259 broken(stat == Ok), /* Old gdiplus behavior */
1260 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1262 GdipDisposeImage((GpImage*)bitmap);
1265 static void test_colormatrix(void)
1268 ColorMatrix colormatrix, graymatrix;
1269 GpImageAttributes *imageattr;
1270 const ColorMatrix identity = {{
1271 {1.0,0.0,0.0,0.0,0.0},
1272 {0.0,1.0,0.0,0.0,0.0},
1273 {0.0,0.0,1.0,0.0,0.0},
1274 {0.0,0.0,0.0,1.0,0.0},
1275 {0.0,0.0,0.0,0.0,1.0}}};
1276 const ColorMatrix double_red = {{
1277 {2.0,0.0,0.0,0.0,0.0},
1278 {0.0,1.0,0.0,0.0,0.0},
1279 {0.0,0.0,1.0,0.0,0.0},
1280 {0.0,0.0,0.0,1.0,0.0},
1281 {0.0,0.0,0.0,0.0,1.0}}};
1282 GpBitmap *bitmap1, *bitmap2;
1283 GpGraphics *graphics;
1286 colormatrix = identity;
1287 graymatrix = identity;
1289 stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
1290 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1291 expect(InvalidParameter, stat);
1293 stat = GdipCreateImageAttributes(&imageattr);
1296 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1297 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1300 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1301 TRUE, NULL, NULL, ColorMatrixFlagsDefault);
1302 expect(InvalidParameter, stat);
1304 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1305 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1308 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1309 TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
1312 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1313 TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
1314 expect(InvalidParameter, stat);
1316 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1317 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
1320 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1321 TRUE, &colormatrix, &graymatrix, 3);
1322 expect(InvalidParameter, stat);
1324 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
1325 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1326 expect(InvalidParameter, stat);
1328 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
1329 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1330 expect(InvalidParameter, stat);
1332 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1333 FALSE, NULL, NULL, ColorMatrixFlagsDefault);
1336 /* Drawing a bitmap transforms the colors */
1337 colormatrix = double_red;
1338 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1339 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1342 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1345 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1348 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ffff);
1351 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1354 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1355 UnitPixel, imageattr, NULL, NULL);
1358 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
1360 todo_wine expect(0xff80ffff, color);
1362 GdipDeleteGraphics(graphics);
1363 GdipDisposeImage((GpImage*)bitmap1);
1364 GdipDisposeImage((GpImage*)bitmap2);
1365 GdipDisposeImageAttributes(imageattr);
1368 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
1369 static const unsigned char gifanimation[72] = {
1370 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1371 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
1372 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
1373 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
1374 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
1377 static void test_multiframegif(void)
1389 /* Test frame functions with an animated GIF */
1390 hglob = GlobalAlloc (0, sizeof(gifanimation));
1391 data = GlobalLock (hglob);
1392 memcpy(data, gifanimation, sizeof(gifanimation));
1393 GlobalUnlock(hglob);
1395 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1396 ok(hres == S_OK, "Failed to create a stream\n");
1397 if(hres != S_OK) return;
1399 stat = GdipCreateBitmapFromStream(stream, &bmp);
1400 ok(stat == Ok, "Failed to create a Bitmap\n");
1402 IStream_Release(stream);
1406 /* Bitmap starts at frame 0 */
1408 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1410 expect(0xffffffff, color);
1412 /* Check that we get correct metadata */
1413 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1417 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1419 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1422 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1423 todo_wine expect(Ok, stat);
1424 todo_wine expect(2, count);
1426 /* SelectActiveFrame overwrites our current data */
1427 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1431 GdipBitmapGetPixel(bmp, 0, 0, &color);
1433 todo_wine expect(0xff000000, color);
1435 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1439 GdipBitmapGetPixel(bmp, 0, 0, &color);
1441 expect(0xffffffff, color);
1443 /* Write over the image data */
1444 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
1447 /* Switching to the same frame does not overwrite our changes */
1448 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1451 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1453 expect(0xff000000, color);
1455 /* But switching to another frame and back does */
1456 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
1459 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
1462 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
1464 todo_wine expect(0xffffffff, color);
1466 GdipDisposeImage((GpImage*)bmp);
1467 IStream_Release(stream);
1469 /* Test with a non-animated gif */
1470 hglob = GlobalAlloc (0, sizeof(gifimage));
1471 data = GlobalLock (hglob);
1472 memcpy(data, gifimage, sizeof(gifimage));
1473 GlobalUnlock(hglob);
1475 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1476 ok(hres == S_OK, "Failed to create a stream\n");
1477 if(hres != S_OK) return;
1479 stat = GdipCreateBitmapFromStream(stream, &bmp);
1480 ok(stat == Ok, "Failed to create a Bitmap\n");
1482 IStream_Release(stream);
1486 /* Check metadata */
1487 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
1491 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
1493 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
1496 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
1497 todo_wine expect(Ok, stat);
1498 todo_wine expect(1, count);
1500 GdipDisposeImage((GpImage*)bmp);
1501 IStream_Release(stream);
1506 struct GdiplusStartupInput gdiplusStartupInput;
1507 ULONG_PTR gdiplusToken;
1509 gdiplusStartupInput.GdiplusVersion = 1;
1510 gdiplusStartupInput.DebugEventCallback = NULL;
1511 gdiplusStartupInput.SuppressBackgroundThread = 0;
1512 gdiplusStartupInput.SuppressExternalCodecs = 0;
1514 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1517 test_GetImageDimension();
1518 test_GdipImageGetFrameDimensionsCount();
1519 test_LoadingImages();
1520 test_SavingImages();
1523 test_GdipCreateBitmapFromHBITMAP();
1524 test_GdipGetImageFlags();
1525 test_GdipCloneImage();
1528 test_getrawformat();
1530 test_createfromwmf();
1532 test_createhbitmap();
1536 test_multiframegif();
1538 GdiplusShutdown(gdiplusToken);