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_rawformat(REFGUID expected, GpImage *img, int line, BOOL todo)
41 stat = GdipGetImageRawFormat(img, &raw);
42 ok_(__FILE__, line)(stat == Ok, "GdipGetImageRawFormat failed with %d\n", stat);
43 if(stat != Ok) return;
44 StringFromGUID2(&raw, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
45 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer, sizeof(buffer), NULL, NULL);
46 StringFromGUID2(expected, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
47 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer2, sizeof(buffer2), NULL, NULL);
49 todo_wine ok_(__FILE__, line)(IsEqualGUID(&raw, expected), "Expected format %s, got %s\n", buffer2, buffer);
51 ok_(__FILE__, line)(IsEqualGUID(&raw, expected), "Expected format %s, got %s\n", buffer2, buffer);
54 static void test_bufferrawformat(void* buff, int size, REFGUID expected, int line, BOOL todo)
63 hglob = GlobalAlloc (0, size);
64 data = GlobalLock (hglob);
65 memcpy(data, buff, size);
66 GlobalUnlock(hglob); data = NULL;
68 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
69 ok_(__FILE__, line)(hres == S_OK, "Failed to create a stream\n");
70 if(hres != S_OK) return;
72 stat = GdipCreateBitmapFromStream(stream, &bmp);
73 ok_(__FILE__, line)(stat == Ok, "Failed to create a Bitmap\n");
75 IStream_Release(stream);
79 expect_rawformat(expected, (GpImage*)bmp, line, todo);
81 GdipDisposeImage((GpImage*)bmp);
82 IStream_Release(stream);
85 static void test_Scan0(void)
92 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
94 ok(NULL != bm, "Expected bitmap to be initialized\n");
96 GdipDisposeImage((GpImage*)bm);
98 bm = (GpBitmap*)0xdeadbeef;
99 stat = GdipCreateBitmapFromScan0(10, -10, 10, PixelFormat24bppRGB, NULL, &bm);
100 expect(InvalidParameter, stat);
101 ok( !bm, "expected null bitmap\n" );
103 bm = (GpBitmap*)0xdeadbeef;
104 stat = GdipCreateBitmapFromScan0(-10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
105 expect(InvalidParameter, stat);
106 ok( !bm, "expected null bitmap\n" );
108 bm = (GpBitmap*)0xdeadbeef;
109 stat = GdipCreateBitmapFromScan0(10, 0, 10, PixelFormat24bppRGB, NULL, &bm);
110 expect(InvalidParameter, stat);
111 ok( !bm, "expected null bitmap\n" );
114 stat = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, buff, &bm);
116 ok(NULL != bm, "Expected bitmap to be initialized\n");
118 GdipDisposeImage((GpImage*)bm);
120 bm = (GpBitmap*) 0xdeadbeef;
121 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, buff, &bm);
122 expect(InvalidParameter, stat);
123 ok( !bm, "expected null bitmap\n" );
125 bm = (GpBitmap*)0xdeadbeef;
126 stat = GdipCreateBitmapFromScan0(10, 10, 0, PixelFormat24bppRGB, buff, &bm);
127 expect(InvalidParameter, stat);
128 ok( bm == (GpBitmap*)0xdeadbeef, "expected deadbeef bitmap\n" );
131 stat = GdipCreateBitmapFromScan0(10, 10, -8, PixelFormat24bppRGB, buff, &bm);
133 ok(NULL != bm, "Expected bitmap to be initialized\n");
135 GdipDisposeImage((GpImage*)bm);
137 bm = (GpBitmap*)0xdeadbeef;
138 stat = GdipCreateBitmapFromScan0(10, 10, -10, PixelFormat24bppRGB, buff, &bm);
139 expect(InvalidParameter, stat);
140 ok( !bm, "expected null bitmap\n" );
143 static void test_GetImageDimension(void)
147 const REAL WIDTH = 10.0, HEIGHT = 20.0;
150 bm = (GpBitmap*)0xdeadbeef;
151 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
153 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
154 ok(NULL != bm, "Expected bitmap to not be NULL\n");
156 stat = GdipGetImageDimension(NULL,&w,&h);
157 expect(InvalidParameter, stat);
159 stat = GdipGetImageDimension((GpImage*)bm,NULL,&h);
160 expect(InvalidParameter, stat);
162 stat = GdipGetImageDimension((GpImage*)bm,&w,NULL);
163 expect(InvalidParameter, stat);
167 stat = GdipGetImageDimension((GpImage*)bm,&w,&h);
171 GdipDisposeImage((GpImage*)bm);
174 static void test_GdipImageGetFrameDimensionsCount(void)
178 const REAL WIDTH = 10.0, HEIGHT = 20.0;
181 bm = (GpBitmap*)0xdeadbeef;
182 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
184 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
185 ok(NULL != bm, "Expected bitmap to not be NULL\n");
187 stat = GdipImageGetFrameDimensionsCount(NULL,&w);
188 expect(InvalidParameter, stat);
190 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,NULL);
191 expect(InvalidParameter, stat);
194 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,&w);
197 GdipDisposeImage((GpImage*)bm);
200 static void test_LoadingImages(void)
204 stat = GdipCreateBitmapFromFile(0, 0);
205 expect(InvalidParameter, stat);
207 stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
208 expect(InvalidParameter, stat);
210 stat = GdipLoadImageFromFile(0, 0);
211 expect(InvalidParameter, stat);
213 stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
214 expect(InvalidParameter, stat);
216 stat = GdipLoadImageFromFileICM(0, 0);
217 expect(InvalidParameter, stat);
219 stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
220 expect(InvalidParameter, stat);
223 static void test_SavingImages(void)
229 const REAL WIDTH = 10.0, HEIGHT = 20.0;
231 ImageCodecInfo *codecs;
232 static const CHAR filenameA[] = "a.bmp";
233 static const WCHAR filename[] = { 'a','.','b','m','p',0 };
237 stat = GdipSaveImageToFile(0, 0, 0, 0);
238 expect(InvalidParameter, stat);
241 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
247 stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
248 expect(InvalidParameter, stat);
250 stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
251 expect(InvalidParameter, stat);
253 /* encoder tests should succeed -- already tested */
254 stat = GdipGetImageEncodersSize(&n, &s);
255 if (stat != Ok || n == 0) goto cleanup;
257 codecs = GdipAlloc(s);
258 if (!codecs) goto cleanup;
260 stat = GdipGetImageEncoders(n, s, codecs);
261 if (stat != Ok) goto cleanup;
263 stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
266 GdipDisposeImage((GpImage*)bm);
269 /* re-load and check image stats */
270 stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
272 if (stat != Ok) goto cleanup;
274 stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
275 if (stat != Ok) goto cleanup;
283 GdipDisposeImage((GpImage*)bm);
284 ok(DeleteFileA(filenameA), "Delete failed.\n");
287 static void test_encoders(void)
292 ImageCodecInfo *codecs;
296 static const CHAR bmp_format[] = "BMP";
298 stat = GdipGetImageEncodersSize(&n, &s);
301 codecs = GdipAlloc(s);
305 stat = GdipGetImageEncoders(n, s, NULL);
306 expect(GenericError, stat);
308 stat = GdipGetImageEncoders(0, s, codecs);
309 expect(GenericError, stat);
311 stat = GdipGetImageEncoders(n, s-1, codecs);
312 expect(GenericError, stat);
314 stat = GdipGetImageEncoders(n, s+1, codecs);
315 expect(GenericError, stat);
317 stat = GdipGetImageEncoders(n, s, codecs);
321 for (i = 0; i < n; i++)
325 WideCharToMultiByte(CP_ACP, 0, codecs[i].FormatDescription, -1,
328 if (CompareStringA(LOCALE_SYSTEM_DEFAULT, 0,
330 bmp_format, -1) == CSTR_EQUAL) {
336 ok(FALSE, "No BMP codec found.\n");
341 static void test_LockBits(void)
347 const INT WIDTH = 10, HEIGHT = 20;
350 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
359 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
363 stat = GdipBitmapUnlockBits(bm, &bd);
367 /* read-only, with NULL rect -> whole bitmap lock */
368 stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
370 expect(bd.Width, WIDTH);
371 expect(bd.Height, HEIGHT);
374 stat = GdipBitmapUnlockBits(bm, &bd);
378 /* read-only, consecutive */
379 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
383 stat = GdipBitmapUnlockBits(bm, &bd);
387 stat = GdipDisposeImage((GpImage*)bm);
389 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
393 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
395 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
396 expect(WrongState, stat);
398 stat = GdipBitmapUnlockBits(bm, &bd);
401 stat = GdipDisposeImage((GpImage*)bm);
403 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
406 /* write, no modification */
407 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
411 stat = GdipBitmapUnlockBits(bm, &bd);
415 /* write, consecutive */
416 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
420 stat = GdipBitmapUnlockBits(bm, &bd);
424 stat = GdipDisposeImage((GpImage*)bm);
426 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
430 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
435 ((char*)bd.Scan0)[2] = 0xff;
437 stat = GdipBitmapUnlockBits(bm, &bd);
441 stat = GdipDisposeImage((GpImage*)bm);
445 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
447 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
449 stat = GdipDisposeImage((GpImage*)bm);
453 static void test_GdipCreateBitmapFromHBITMAP(void)
455 GpBitmap* gpbm = NULL;
457 HPALETTE hpal = NULL;
460 LOGPALETTE* LogPal = NULL;
462 const REAL WIDTH1 = 5;
463 const REAL HEIGHT1 = 15;
464 const REAL WIDTH2 = 10;
465 const REAL HEIGHT2 = 20;
470 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
471 expect(InvalidParameter, stat);
473 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
474 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
475 expect(InvalidParameter, stat);
477 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
479 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
480 expectf(WIDTH1, width);
481 expectf(HEIGHT1, height);
483 GdipDisposeImage((GpImage*)gpbm);
486 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
487 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
490 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
492 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
493 expectf(WIDTH2, width);
494 expectf(HEIGHT2, height);
496 GdipDisposeImage((GpImage*)gpbm);
499 hdc = CreateCompatibleDC(0);
500 ok(hdc != NULL, "CreateCompatibleDC failed\n");
501 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
502 bmi.bmiHeader.biHeight = HEIGHT1;
503 bmi.bmiHeader.biWidth = WIDTH1;
504 bmi.bmiHeader.biBitCount = 24;
505 bmi.bmiHeader.biPlanes = 1;
506 bmi.bmiHeader.biCompression = BI_RGB;
508 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
509 ok(hbm != NULL, "CreateDIBSection failed\n");
513 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
515 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
516 expectf(WIDTH1, width);
517 expectf(HEIGHT1, height);
520 /* test whether writing to the bitmap affects the original */
521 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
526 GdipDisposeImage((GpImage*)gpbm);
529 LogPal = GdipAlloc(sizeof(LOGPALETTE));
530 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
531 LogPal->palVersion = 0x300;
532 hpal = CreatePalette(LogPal);
533 ok(hpal != NULL, "CreatePalette failed\n");
536 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
542 GdipDisposeImage((GpImage*)gpbm);
548 static void test_GdipGetImageFlags(void)
554 img = (GpImage*)0xdeadbeef;
556 stat = GdipGetImageFlags(NULL, NULL);
557 expect(InvalidParameter, stat);
559 stat = GdipGetImageFlags(NULL, &flags);
560 expect(InvalidParameter, stat);
562 stat = GdipGetImageFlags(img, NULL);
563 expect(InvalidParameter, stat);
566 static void test_GdipCloneImage(void)
572 GpImage *image_src, *image_dest = NULL;
573 const INT WIDTH = 10, HEIGHT = 20;
575 /* Create an image, clone it, delete the original, make sure the copy works */
576 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
578 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
580 image_src = ((GpImage*)bm);
581 stat = GdipCloneImage(image_src, &image_dest);
583 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
585 stat = GdipDisposeImage((GpImage*)bm);
587 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
590 /* Treat FP values carefully */
591 expectf((REAL)WIDTH, rectF.Width);
592 expectf((REAL)HEIGHT, rectF.Height);
594 stat = GdipDisposeImage(image_dest);
598 static void test_testcontrol(void)
604 stat = GdipTestControl(TestControlGetBuildNumber, ¶m);
606 ok(param != 0, "Build number expected, got %u\n", param);
609 static void test_fromhicon(void)
611 static const BYTE bmp_bits[1024];
612 HBITMAP hbmMask, hbmColor;
616 GpBitmap *bitmap = NULL;
622 stat = GdipCreateBitmapFromHICON(NULL, NULL);
623 expect(InvalidParameter, stat);
624 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
625 expect(InvalidParameter, stat);
627 /* color icon 1 bit */
628 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
629 ok(hbmMask != 0, "CreateBitmap failed\n");
630 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
631 ok(hbmColor != 0, "CreateBitmap failed\n");
635 info.hbmMask = hbmMask;
636 info.hbmColor = hbmColor;
637 hIcon = CreateIconIndirect(&info);
638 ok(hIcon != 0, "CreateIconIndirect failed\n");
639 DeleteObject(hbmMask);
640 DeleteObject(hbmColor);
642 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
644 broken(stat == InvalidParameter), /* Win98 */
645 "Expected Ok, got %.8x\n", stat);
647 /* check attributes */
648 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
651 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
654 stat = GdipGetImageType((GpImage*)bitmap, &type);
656 expect(ImageTypeBitmap, type);
657 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
658 expect(PixelFormat32bppARGB, format);
660 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
661 GdipDisposeImage((GpImage*)bitmap);
665 /* color icon 8 bpp */
666 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
667 ok(hbmMask != 0, "CreateBitmap failed\n");
668 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
669 ok(hbmColor != 0, "CreateBitmap failed\n");
673 info.hbmMask = hbmMask;
674 info.hbmColor = hbmColor;
675 hIcon = CreateIconIndirect(&info);
676 ok(hIcon != 0, "CreateIconIndirect failed\n");
677 DeleteObject(hbmMask);
678 DeleteObject(hbmColor);
680 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
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);
703 static const unsigned char pngimage[285] = {
704 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
705 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
706 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
707 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
708 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
709 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
710 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
713 static const unsigned char gifimage[35] = {
714 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
715 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
719 static const unsigned char bmpimage[66] = {
720 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
721 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
722 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
723 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
727 static const unsigned char jpgimage[285] = {
728 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
729 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
730 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
731 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
732 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
733 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
734 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
735 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
736 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
737 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
738 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
739 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
740 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
741 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
742 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
743 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
744 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
745 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
747 static void test_getrawformat(void)
749 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
750 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
751 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
752 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
755 static void test_createhbitmap(void)
759 HBITMAP hbitmap, oldhbitmap;
766 memset(bits, 0x68, 640);
769 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
772 /* test NULL values */
773 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
774 expect(InvalidParameter, stat);
776 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
777 expect(InvalidParameter, stat);
780 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
785 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
786 expect(sizeof(BITMAP), ret);
788 expect(0, bm.bmType);
789 expect(10, bm.bmWidth);
790 expect(20, bm.bmHeight);
791 expect(40, bm.bmWidthBytes);
792 expect(1, bm.bmPlanes);
793 expect(32, bm.bmBitsPixel);
794 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
796 hdc = CreateCompatibleDC(NULL);
798 oldhbitmap = SelectObject(hdc, hbitmap);
799 pixel = GetPixel(hdc, 5, 5);
800 SelectObject(hdc, oldhbitmap);
804 expect(0x686868, pixel);
806 DeleteObject(hbitmap);
809 stat = GdipDisposeImage((GpImage*)bitmap);
813 static void test_getsetpixel(void)
818 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
819 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
821 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
824 /* null parameters */
825 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
826 expect(InvalidParameter, stat);
828 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
829 expect(InvalidParameter, stat);
831 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
832 expect(InvalidParameter, stat);
835 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
836 expect(InvalidParameter, stat);
838 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
839 expect(InvalidParameter, stat);
841 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
842 ok(stat == InvalidParameter ||
843 broken(stat == Ok), /* Older gdiplus */
844 "Expected InvalidParameter, got %.8x\n", stat);
846 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
847 ok(stat == InvalidParameter ||
848 broken(stat == Ok), /* Older gdiplus */
849 "Expected InvalidParameter, got %.8x\n", stat);
851 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
852 expect(InvalidParameter, stat);
854 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
855 expect(InvalidParameter, stat);
857 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
858 expect(InvalidParameter, stat);
860 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
861 expect(InvalidParameter, stat);
864 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
866 expect(0xffffffff, color);
868 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
870 expect(0xff0000ff, color);
872 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
875 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
878 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
880 expect(0xff676869, color);
882 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
884 expect(0xff474849, color);
886 stat = GdipDisposeImage((GpImage*)bitmap);
890 static void check_halftone_palette(ColorPalette *palette)
892 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
895 for (i=0; i<palette->Count; i++)
897 ARGB expected=0xff000000;
900 if (i&1) expected |= 0x800000;
901 if (i&2) expected |= 0x8000;
902 if (i&4) expected |= 0x80;
906 expected = 0xffc0c0c0;
910 if (i&1) expected |= 0xff0000;
911 if (i&2) expected |= 0xff00;
912 if (i&4) expected |= 0xff;
916 expected = 0x00000000;
920 expected |= halftone_values[(i-40)%6];
921 expected |= halftone_values[((i-40)/6)%6] << 8;
922 expected |= halftone_values[((i-40)/36)%6] << 16;
924 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
925 expected, palette->Entries[i], i, palette->Count);
929 static void test_palette(void)
935 ColorPalette *palette=(ColorPalette*)buffer;
937 /* test initial palette from non-indexed bitmap */
938 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
941 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
943 expect(sizeof(UINT)*2+sizeof(ARGB), size);
945 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
947 expect(0, palette->Count);
949 /* test setting palette on not-indexed bitmap */
952 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
955 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
957 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
959 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
961 expect(3, palette->Count);
963 GdipDisposeImage((GpImage*)bitmap);
965 /* test initial palette on 1-bit bitmap */
966 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
969 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
971 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
973 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
975 expect(PaletteFlagsGrayScale, palette->Flags);
976 expect(2, palette->Count);
978 expect(0xff000000, palette->Entries[0]);
979 expect(0xffffffff, palette->Entries[1]);
981 GdipDisposeImage((GpImage*)bitmap);
983 /* test initial palette on 4-bit bitmap */
984 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
987 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
989 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
991 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
993 expect(0, palette->Flags);
994 expect(16, palette->Count);
996 check_halftone_palette(palette);
998 GdipDisposeImage((GpImage*)bitmap);
1000 /* test initial palette on 8-bit bitmap */
1001 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1004 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1006 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1008 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1010 expect(PaletteFlagsHalftone, palette->Flags);
1011 expect(256, palette->Count);
1013 check_halftone_palette(palette);
1015 /* test setting/getting a different palette */
1016 palette->Entries[1] = 0xffcccccc;
1018 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1021 palette->Entries[1] = 0;
1023 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1025 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1027 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1029 expect(PaletteFlagsHalftone, palette->Flags);
1030 expect(256, palette->Count);
1031 expect(0xffcccccc, palette->Entries[1]);
1033 /* test count < 256 */
1034 palette->Flags = 12345;
1037 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1040 palette->Entries[1] = 0;
1041 palette->Entries[3] = 0xdeadbeef;
1043 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1045 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1047 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1049 expect(12345, palette->Flags);
1050 expect(3, palette->Count);
1051 expect(0xffcccccc, palette->Entries[1]);
1052 expect(0xdeadbeef, palette->Entries[3]);
1054 /* test count > 256 */
1055 palette->Count = 257;
1057 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1058 ok(stat == InvalidParameter ||
1059 broken(stat == Ok), /* Old gdiplus behavior */
1060 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1062 GdipDisposeImage((GpImage*)bitmap);
1067 struct GdiplusStartupInput gdiplusStartupInput;
1068 ULONG_PTR gdiplusToken;
1070 gdiplusStartupInput.GdiplusVersion = 1;
1071 gdiplusStartupInput.DebugEventCallback = NULL;
1072 gdiplusStartupInput.SuppressBackgroundThread = 0;
1073 gdiplusStartupInput.SuppressExternalCodecs = 0;
1075 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1078 test_GetImageDimension();
1079 test_GdipImageGetFrameDimensionsCount();
1080 test_LoadingImages();
1081 test_SavingImages();
1084 test_GdipCreateBitmapFromHBITMAP();
1085 test_GdipGetImageFlags();
1086 test_GdipCloneImage();
1089 test_getrawformat();
1090 test_createhbitmap();
1094 GdiplusShutdown(gdiplusToken);