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_FromGdiDib(void)
166 BYTE rbmi[sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)];
167 BITMAPINFO *bmi = (BITMAPINFO*)rbmi;
172 memset(rbmi, 0, sizeof(rbmi));
174 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
175 bmi->bmiHeader.biWidth = 10;
176 bmi->bmiHeader.biHeight = 10;
177 bmi->bmiHeader.biPlanes = 1;
178 bmi->bmiHeader.biBitCount = 32;
179 bmi->bmiHeader.biCompression = BI_RGB;
181 stat = GdipCreateBitmapFromGdiDib(NULL, buff, &bm);
182 expect(InvalidParameter, stat);
184 stat = GdipCreateBitmapFromGdiDib(bmi, NULL, &bm);
185 expect(InvalidParameter, stat);
187 stat = GdipCreateBitmapFromGdiDib(bmi, buff, NULL);
188 expect(InvalidParameter, stat);
190 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
192 ok(NULL != bm, "Expected bitmap to be initialized\n");
195 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
197 expect(PixelFormat32bppRGB, format);
199 GdipDisposeImage((GpImage*)bm);
202 bmi->bmiHeader.biBitCount = 24;
203 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
205 ok(NULL != bm, "Expected bitmap to be initialized\n");
208 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
210 expect(PixelFormat24bppRGB, format);
212 GdipDisposeImage((GpImage*)bm);
215 bmi->bmiHeader.biBitCount = 16;
216 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
218 ok(NULL != bm, "Expected bitmap to be initialized\n");
221 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
223 expect(PixelFormat16bppRGB555, format);
225 GdipDisposeImage((GpImage*)bm);
228 bmi->bmiHeader.biBitCount = 8;
229 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
231 ok(NULL != bm, "Expected bitmap to be initialized\n");
234 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
236 expect(PixelFormat8bppIndexed, format);
238 GdipDisposeImage((GpImage*)bm);
241 bmi->bmiHeader.biBitCount = 4;
242 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
244 ok(NULL != bm, "Expected bitmap to be initialized\n");
247 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
249 expect(PixelFormat4bppIndexed, format);
251 GdipDisposeImage((GpImage*)bm);
254 bmi->bmiHeader.biBitCount = 1;
255 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
257 ok(NULL != bm, "Expected bitmap to be initialized\n");
260 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
262 expect(PixelFormat1bppIndexed, format);
264 GdipDisposeImage((GpImage*)bm);
267 bmi->bmiHeader.biBitCount = 0;
268 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
269 expect(InvalidParameter, stat);
272 static void test_GetImageDimension(void)
276 const REAL WIDTH = 10.0, HEIGHT = 20.0;
279 bm = (GpBitmap*)0xdeadbeef;
280 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
282 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
283 ok(NULL != bm, "Expected bitmap to not be NULL\n");
285 stat = GdipGetImageDimension(NULL,&w,&h);
286 expect(InvalidParameter, stat);
288 stat = GdipGetImageDimension((GpImage*)bm,NULL,&h);
289 expect(InvalidParameter, stat);
291 stat = GdipGetImageDimension((GpImage*)bm,&w,NULL);
292 expect(InvalidParameter, stat);
296 stat = GdipGetImageDimension((GpImage*)bm,&w,&h);
300 GdipDisposeImage((GpImage*)bm);
303 static void test_GdipImageGetFrameDimensionsCount(void)
307 const REAL WIDTH = 10.0, HEIGHT = 20.0;
309 GUID dimension = {0};
313 bm = (GpBitmap*)0xdeadbeef;
314 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
316 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
317 ok(NULL != bm, "Expected bitmap to not be NULL\n");
319 stat = GdipImageGetFrameDimensionsCount(NULL,&w);
320 expect(InvalidParameter, stat);
322 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,NULL);
323 expect(InvalidParameter, stat);
326 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,&w);
330 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 1);
332 expect_guid(&FrameDimensionPage, &dimension, __LINE__, FALSE);
334 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 2);
335 expect(InvalidParameter, stat);
337 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 0);
338 expect(InvalidParameter, stat);
340 stat = GdipImageGetFrameCount(NULL, &dimension, &count);
341 expect(InvalidParameter, stat);
343 /* WinXP crashes on this test */
346 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, NULL);
347 expect(InvalidParameter, stat);
350 stat = GdipImageGetFrameCount((GpImage*)bm, NULL, &count);
354 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, &count);
358 GdipBitmapSetPixel(bm, 0, 0, 0xffffffff);
360 stat = GdipImageSelectActiveFrame((GpImage*)bm, &dimension, 0);
363 /* SelectActiveFrame has no effect on image data of memory bitmaps */
365 GdipBitmapGetPixel(bm, 0, 0, &color);
366 expect(0xffffffff, color);
368 GdipDisposeImage((GpImage*)bm);
371 static void test_LoadingImages(void)
375 stat = GdipCreateBitmapFromFile(0, 0);
376 expect(InvalidParameter, stat);
378 stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
379 expect(InvalidParameter, stat);
381 stat = GdipLoadImageFromFile(0, 0);
382 expect(InvalidParameter, stat);
384 stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
385 expect(InvalidParameter, stat);
387 stat = GdipLoadImageFromFileICM(0, 0);
388 expect(InvalidParameter, stat);
390 stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
391 expect(InvalidParameter, stat);
394 static void test_SavingImages(void)
400 const REAL WIDTH = 10.0, HEIGHT = 20.0;
402 ImageCodecInfo *codecs;
403 static const CHAR filenameA[] = "a.bmp";
404 static const WCHAR filename[] = { 'a','.','b','m','p',0 };
408 stat = GdipSaveImageToFile(0, 0, 0, 0);
409 expect(InvalidParameter, stat);
412 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
418 stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
419 expect(InvalidParameter, stat);
421 stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
422 expect(InvalidParameter, stat);
424 /* encoder tests should succeed -- already tested */
425 stat = GdipGetImageEncodersSize(&n, &s);
426 if (stat != Ok || n == 0) goto cleanup;
428 codecs = GdipAlloc(s);
429 if (!codecs) goto cleanup;
431 stat = GdipGetImageEncoders(n, s, codecs);
432 if (stat != Ok) goto cleanup;
434 stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
437 GdipDisposeImage((GpImage*)bm);
440 /* re-load and check image stats */
441 stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
443 if (stat != Ok) goto cleanup;
445 stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
446 if (stat != Ok) goto cleanup;
454 GdipDisposeImage((GpImage*)bm);
455 ok(DeleteFileA(filenameA), "Delete failed.\n");
458 static void test_encoders(void)
463 ImageCodecInfo *codecs;
467 static const CHAR bmp_format[] = "BMP";
469 stat = GdipGetImageEncodersSize(&n, &s);
472 codecs = GdipAlloc(s);
476 stat = GdipGetImageEncoders(n, s, NULL);
477 expect(GenericError, stat);
479 stat = GdipGetImageEncoders(0, s, codecs);
480 expect(GenericError, stat);
482 stat = GdipGetImageEncoders(n, s-1, codecs);
483 expect(GenericError, stat);
485 stat = GdipGetImageEncoders(n, s+1, codecs);
486 expect(GenericError, stat);
488 stat = GdipGetImageEncoders(n, s, codecs);
492 for (i = 0; i < n; i++)
496 WideCharToMultiByte(CP_ACP, 0, codecs[i].FormatDescription, -1,
499 if (CompareStringA(LOCALE_SYSTEM_DEFAULT, 0,
501 bmp_format, -1) == CSTR_EQUAL) {
507 ok(FALSE, "No BMP codec found.\n");
512 static void test_LockBits(void)
518 const INT WIDTH = 10, HEIGHT = 20;
523 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
531 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffc30000);
534 stat = GdipBitmapSetPixel(bm, 2, 8, 0xff480000);
538 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
542 expect(0xc3, ((BYTE*)bd.Scan0)[2]);
543 expect(0x48, ((BYTE*)bd.Scan0)[2 + bd.Stride * 5]);
545 ((char*)bd.Scan0)[2] = 0xff;
547 stat = GdipBitmapUnlockBits(bm, &bd);
551 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
553 expect(0xffff0000, color);
555 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffc30000);
558 /* read-only, with NULL rect -> whole bitmap lock */
559 stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
561 expect(bd.Width, WIDTH);
562 expect(bd.Height, HEIGHT);
565 ((char*)bd.Scan0)[2 + 2*3 + 3*bd.Stride] = 0xff;
567 stat = GdipBitmapUnlockBits(bm, &bd);
571 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
573 expect(0xffff0000, color);
575 /* read-only, consecutive */
576 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
580 stat = GdipBitmapUnlockBits(bm, &bd);
584 stat = GdipDisposeImage((GpImage*)bm);
586 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
590 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
592 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
593 expect(WrongState, stat);
595 stat = GdipBitmapUnlockBits(bm, &bd);
598 stat = GdipDisposeImage((GpImage*)bm);
600 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
603 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffff0000);
606 stat = GdipBitmapSetPixel(bm, 2, 8, 0xffc30000);
609 /* write, no conversion */
610 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
614 /* all bits are readable, inside the rect or not */
615 expect(0xff, ((BYTE*)bd.Scan0)[2]);
616 expect(0xc3, ((BYTE*)bd.Scan0)[2 + bd.Stride * 5]);
618 stat = GdipBitmapUnlockBits(bm, &bd);
622 /* read, conversion */
623 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat32bppARGB, &bd);
627 expect(0xff, ((BYTE*)bd.Scan0)[2]);
629 /* Areas outside the rectangle appear to be uninitialized */
630 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
632 ((BYTE*)bd.Scan0)[2] = 0xc3;
634 stat = GdipBitmapUnlockBits(bm, &bd);
638 /* writes do not work in read mode if there was a conversion */
639 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
641 expect(0xffff0000, color);
643 /* read/write, conversion */
644 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeWrite, PixelFormat32bppARGB, &bd);
648 expect(0xff, ((BYTE*)bd.Scan0)[2]);
649 ((BYTE*)bd.Scan0)[1] = 0x88;
651 /* Areas outside the rectangle appear to be uninitialized */
652 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
654 stat = GdipBitmapUnlockBits(bm, &bd);
658 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
660 expect(0xffff8800, color);
662 /* write, conversion */
663 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat32bppARGB, &bd);
669 /* This is completely uninitialized. */
670 ok(0xff != ((BYTE*)bd.Scan0)[2], "original image bits are readable\n");
671 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
674 /* Initialize the buffer so the unlock doesn't access undefined memory */
676 memset(((BYTE*)bd.Scan0) + bd.Stride * y, 0, 12);
678 ((BYTE*)bd.Scan0)[0] = 0x12;
679 ((BYTE*)bd.Scan0)[1] = 0x34;
680 ((BYTE*)bd.Scan0)[2] = 0x56;
682 stat = GdipBitmapUnlockBits(bm, &bd);
686 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
688 expect(0xff563412, color);
690 stat = GdipBitmapGetPixel(bm, 2, 8, &color);
692 expect(0xffc30000, color);
694 stat = GdipDisposeImage((GpImage*)bm);
696 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
699 /* write, no modification */
700 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
704 stat = GdipBitmapUnlockBits(bm, &bd);
708 /* write, consecutive */
709 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
713 stat = GdipBitmapUnlockBits(bm, &bd);
717 stat = GdipDisposeImage((GpImage*)bm);
719 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
723 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
728 ((char*)bd.Scan0)[2] = 0xff;
730 stat = GdipBitmapUnlockBits(bm, &bd);
734 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
736 expect(0xffff0000, color);
738 stat = GdipDisposeImage((GpImage*)bm);
742 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
744 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
746 stat = GdipDisposeImage((GpImage*)bm);
750 static void test_LockBits_UserBuf(void)
756 const INT WIDTH = 10, HEIGHT = 20;
761 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat32bppARGB, NULL, &bm);
764 memset(bits, 0xaa, sizeof(bits));
773 bd.Stride = WIDTH * 4;
774 bd.PixelFormat = PixelFormat32bppARGB;
775 bd.Scan0 = &bits[2+3*WIDTH];
776 bd.Reserved = 0xaaaaaaaa;
779 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
782 expect(0xaaaaaaaa, bits[0]);
783 expect(0, bits[2+3*WIDTH]);
785 bits[2+3*WIDTH] = 0xdeadbeef;
788 stat = GdipBitmapUnlockBits(bm, &bd);
792 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
797 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
800 expect(0xdeadbeef, bits[2+3*WIDTH]);
801 bits[2+3*WIDTH] = 0x12345678;
804 stat = GdipBitmapUnlockBits(bm, &bd);
808 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
810 expect(0x12345678, color);
815 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeWrite|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
818 expect(0x12345678, bits[2+3*WIDTH]);
819 bits[2+3*WIDTH] = 0xdeadbeef;
822 stat = GdipBitmapUnlockBits(bm, &bd);
826 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
828 expect(0xdeadbeef, color);
830 stat = GdipDisposeImage((GpImage*)bm);
834 static void test_GdipCreateBitmapFromHBITMAP(void)
836 GpBitmap* gpbm = NULL;
838 HPALETTE hpal = NULL;
841 LOGPALETTE* LogPal = NULL;
843 const REAL WIDTH1 = 5;
844 const REAL HEIGHT1 = 15;
845 const REAL WIDTH2 = 10;
846 const REAL HEIGHT2 = 20;
851 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
852 expect(InvalidParameter, stat);
854 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
855 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
856 expect(InvalidParameter, stat);
858 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
860 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
861 expectf(WIDTH1, width);
862 expectf(HEIGHT1, height);
864 GdipDisposeImage((GpImage*)gpbm);
867 memset(buff, 0, sizeof(buff));
868 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
869 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
872 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
874 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
875 expectf(WIDTH2, width);
876 expectf(HEIGHT2, height);
878 GdipDisposeImage((GpImage*)gpbm);
881 hdc = CreateCompatibleDC(0);
882 ok(hdc != NULL, "CreateCompatibleDC failed\n");
883 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
884 bmi.bmiHeader.biHeight = HEIGHT1;
885 bmi.bmiHeader.biWidth = WIDTH1;
886 bmi.bmiHeader.biBitCount = 24;
887 bmi.bmiHeader.biPlanes = 1;
888 bmi.bmiHeader.biCompression = BI_RGB;
890 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
891 ok(hbm != NULL, "CreateDIBSection failed\n");
895 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
897 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
898 expectf(WIDTH1, width);
899 expectf(HEIGHT1, height);
902 /* test whether writing to the bitmap affects the original */
903 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
908 GdipDisposeImage((GpImage*)gpbm);
911 LogPal = GdipAlloc(sizeof(LOGPALETTE));
912 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
913 LogPal->palVersion = 0x300;
914 LogPal->palNumEntries = 1;
915 hpal = CreatePalette(LogPal);
916 ok(hpal != NULL, "CreatePalette failed\n");
919 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
925 GdipDisposeImage((GpImage*)gpbm);
931 static void test_GdipGetImageFlags(void)
937 img = (GpImage*)0xdeadbeef;
939 stat = GdipGetImageFlags(NULL, NULL);
940 expect(InvalidParameter, stat);
942 stat = GdipGetImageFlags(NULL, &flags);
943 expect(InvalidParameter, stat);
945 stat = GdipGetImageFlags(img, NULL);
946 expect(InvalidParameter, stat);
948 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, (GpBitmap**)&img);
950 stat = GdipGetImageFlags(img, &flags);
952 expect(ImageFlagsHasAlpha, flags);
953 GdipDisposeImage(img);
955 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, (GpBitmap**)&img);
957 stat = GdipGetImageFlags(img, &flags);
959 expect(ImageFlagsHasAlpha, flags);
960 GdipDisposeImage(img);
962 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, (GpBitmap**)&img);
964 stat = GdipGetImageFlags(img, &flags);
966 expect(ImageFlagsHasAlpha, flags);
967 GdipDisposeImage(img);
969 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, (GpBitmap**)&img);
971 stat = GdipGetImageFlags(img, &flags);
973 expect(ImageFlagsNone, flags);
974 GdipDisposeImage(img);
976 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, (GpBitmap**)&img);
978 stat = GdipGetImageFlags(img, &flags);
980 expect(ImageFlagsNone, flags);
981 GdipDisposeImage(img);
983 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, (GpBitmap**)&img);
985 stat = GdipGetImageFlags(img, &flags);
987 expect(ImageFlagsNone, flags);
988 GdipDisposeImage(img);
990 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppARGB1555, NULL, (GpBitmap**)&img);
992 stat = GdipGetImageFlags(img, &flags);
994 expect(ImageFlagsHasAlpha, flags);
995 GdipDisposeImage(img);
997 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, (GpBitmap**)&img);
999 stat = GdipGetImageFlags(img, &flags);
1001 expect(ImageFlagsNone, flags);
1002 GdipDisposeImage(img);
1004 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, (GpBitmap**)&img);
1006 stat = GdipGetImageFlags(img, &flags);
1008 expect(ImageFlagsNone, flags);
1009 GdipDisposeImage(img);
1011 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, (GpBitmap**)&img);
1013 stat = GdipGetImageFlags(img, &flags);
1015 expect(ImageFlagsHasAlpha, flags);
1016 GdipDisposeImage(img);
1018 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppPARGB, NULL, (GpBitmap**)&img);
1020 stat = GdipGetImageFlags(img, &flags);
1022 expect(ImageFlagsHasAlpha, flags);
1023 GdipDisposeImage(img);
1025 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, (GpBitmap**)&img);
1029 stat = GdipGetImageFlags(img, &flags);
1031 expect(ImageFlagsNone, flags);
1032 GdipDisposeImage(img);
1035 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, (GpBitmap**)&img);
1040 stat = GdipGetImageFlags(img, &flags);
1042 expect(ImageFlagsHasAlpha, flags);
1043 GdipDisposeImage(img);
1046 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, (GpBitmap**)&img);
1051 stat = GdipGetImageFlags(img, &flags);
1053 expect(ImageFlagsHasAlpha, flags);
1054 GdipDisposeImage(img);
1058 static void test_GdipCloneImage(void)
1064 GpImage *image_src, *image_dest = NULL;
1065 const INT WIDTH = 10, HEIGHT = 20;
1067 /* Create an image, clone it, delete the original, make sure the copy works */
1068 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
1070 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
1072 image_src = ((GpImage*)bm);
1073 stat = GdipCloneImage(image_src, &image_dest);
1075 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
1077 stat = GdipDisposeImage((GpImage*)bm);
1079 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
1082 /* Treat FP values carefully */
1083 expectf((REAL)WIDTH, rectF.Width);
1084 expectf((REAL)HEIGHT, rectF.Height);
1086 stat = GdipDisposeImage(image_dest);
1090 static void test_testcontrol(void)
1096 stat = GdipTestControl(TestControlGetBuildNumber, ¶m);
1098 ok(param != 0, "Build number expected, got %u\n", param);
1101 static void test_fromhicon(void)
1103 static const BYTE bmp_bits[1024];
1104 HBITMAP hbmMask, hbmColor;
1108 GpBitmap *bitmap = NULL;
1114 stat = GdipCreateBitmapFromHICON(NULL, NULL);
1115 expect(InvalidParameter, stat);
1116 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
1117 expect(InvalidParameter, stat);
1119 /* color icon 1 bit */
1120 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
1121 ok(hbmMask != 0, "CreateBitmap failed\n");
1122 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
1123 ok(hbmColor != 0, "CreateBitmap failed\n");
1127 info.hbmMask = hbmMask;
1128 info.hbmColor = hbmColor;
1129 hIcon = CreateIconIndirect(&info);
1130 ok(hIcon != 0, "CreateIconIndirect failed\n");
1131 DeleteObject(hbmMask);
1132 DeleteObject(hbmColor);
1134 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
1136 broken(stat == InvalidParameter), /* Win98 */
1137 "Expected Ok, got %.8x\n", stat);
1139 /* check attributes */
1140 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
1143 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
1146 stat = GdipGetImageType((GpImage*)bitmap, &type);
1148 expect(ImageTypeBitmap, type);
1149 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
1151 expect(PixelFormat32bppARGB, format);
1153 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
1154 GdipDisposeImage((GpImage*)bitmap);
1158 /* color icon 8 bpp */
1159 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
1160 ok(hbmMask != 0, "CreateBitmap failed\n");
1161 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
1162 ok(hbmColor != 0, "CreateBitmap failed\n");
1166 info.hbmMask = hbmMask;
1167 info.hbmColor = hbmColor;
1168 hIcon = CreateIconIndirect(&info);
1169 ok(hIcon != 0, "CreateIconIndirect failed\n");
1170 DeleteObject(hbmMask);
1171 DeleteObject(hbmColor);
1173 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
1176 /* check attributes */
1177 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
1180 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
1183 stat = GdipGetImageType((GpImage*)bitmap, &type);
1185 expect(ImageTypeBitmap, type);
1186 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
1188 expect(PixelFormat32bppARGB, format);
1190 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
1191 GdipDisposeImage((GpImage*)bitmap);
1197 static const unsigned char pngimage[285] = {
1198 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
1199 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
1200 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
1201 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
1202 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
1203 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
1204 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
1207 static const unsigned char gifimage[35] = {
1208 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
1209 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
1213 static const unsigned char bmpimage[66] = {
1214 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
1215 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
1216 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
1217 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
1221 static const unsigned char jpgimage[285] = {
1222 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
1223 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
1224 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
1225 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
1226 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
1227 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
1228 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
1229 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1230 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1231 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
1232 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
1233 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1234 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
1235 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
1236 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1237 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
1238 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
1239 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
1241 /* 1x1 pixel tiff */
1242 static const unsigned char tiffimage[] = {
1243 0x49,0x49,0x2a,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xfe,0x00,
1244 0x04,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x00,0x01,0x00,
1245 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1246 0x00,0x00,0x02,0x01,0x03,0x00,0x03,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0x03,0x01,
1247 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,0x01,0x03,0x00,0x01,0x00,
1248 0x00,0x00,0x02,0x00,0x00,0x00,0x0d,0x01,0x02,0x00,0x1b,0x00,0x00,0x00,0xd8,0x00,
1249 0x00,0x00,0x11,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x12,0x01,
1250 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x01,0x03,0x00,0x01,0x00,
1251 0x00,0x00,0x03,0x00,0x00,0x00,0x16,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x40,0x00,
1252 0x00,0x00,0x17,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1a,0x01,
1253 0x05,0x00,0x01,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x1b,0x01,0x05,0x00,0x01,0x00,
1254 0x00,0x00,0xfc,0x00,0x00,0x00,0x1c,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1255 0x00,0x00,0x28,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
1256 0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x6d,0x65,
1257 0x68,0x2f,0x44,0x65,0x73,0x6b,0x74,0x6f,0x70,0x2f,0x74,0x65,0x73,0x74,0x2e,0x74,
1258 0x69,0x66,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,
1261 /* 320x320 twip wmf */
1262 static const unsigned char wmfimage[180] = {
1263 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
1264 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
1265 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
1266 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
1267 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
1268 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
1269 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
1270 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
1271 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
1272 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
1273 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
1276 static void test_getrawformat(void)
1278 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
1279 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
1280 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
1281 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
1282 test_bufferrawformat((void*)tiffimage, sizeof(tiffimage), &ImageFormatTIFF, __LINE__, FALSE);
1283 test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
1286 static void test_loadwmf(void)
1297 MetafileHeader header;
1299 hglob = GlobalAlloc (0, sizeof(wmfimage));
1300 data = GlobalLock (hglob);
1301 memcpy(data, wmfimage, sizeof(wmfimage));
1302 GlobalUnlock(hglob); data = NULL;
1304 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1305 ok(hres == S_OK, "Failed to create a stream\n");
1306 if(hres != S_OK) return;
1308 stat = GdipLoadImageFromStream(stream, &img);
1309 ok(stat == Ok, "Failed to create a Bitmap\n");
1311 IStream_Release(stream);
1315 IStream_Release(stream);
1317 stat = GdipGetImageBounds(img, &bounds, &unit);
1319 todo_wine expect(UnitPixel, unit);
1320 expectf(0.0, bounds.X);
1321 expectf(0.0, bounds.Y);
1322 todo_wine expectf(320.0, bounds.Width);
1323 todo_wine expectf(320.0, bounds.Height);
1325 stat = GdipGetImageHorizontalResolution(img, &res);
1327 todo_wine expectf(1440.0, res);
1329 stat = GdipGetImageVerticalResolution(img, &res);
1331 todo_wine expectf(1440.0, res);
1333 memset(&header, 0, sizeof(header));
1334 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1338 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1339 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1340 todo_wine expect(0x300, header.Version);
1341 expect(0, header.EmfPlusFlags);
1342 todo_wine expectf(1440.0, header.DpiX);
1343 todo_wine expectf(1440.0, header.DpiY);
1344 expect(0, header.X);
1345 expect(0, header.Y);
1346 todo_wine expect(320, header.Width);
1347 todo_wine expect(320, header.Height);
1348 todo_wine expect(1, U(header).WmfHeader.mtType);
1349 expect(0, header.EmfPlusHeaderSize);
1350 expect(0, header.LogicalDpiX);
1351 expect(0, header.LogicalDpiY);
1354 GdipDisposeImage(img);
1357 static void test_createfromwmf(void)
1365 MetafileHeader header;
1367 hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
1368 wmfimage+sizeof(WmfPlaceableFileHeader));
1369 ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
1371 stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
1372 (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
1375 stat = GdipGetImageBounds(img, &bounds, &unit);
1377 expect(UnitPixel, unit);
1378 expectf(0.0, bounds.X);
1379 expectf(0.0, bounds.Y);
1380 expectf(320.0, bounds.Width);
1381 expectf(320.0, bounds.Height);
1383 stat = GdipGetImageHorizontalResolution(img, &res);
1385 expectf(1440.0, res);
1387 stat = GdipGetImageVerticalResolution(img, &res);
1389 expectf(1440.0, res);
1391 memset(&header, 0, sizeof(header));
1392 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1396 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1397 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1398 todo_wine expect(0x300, header.Version);
1399 expect(0, header.EmfPlusFlags);
1400 todo_wine expectf(1440.0, header.DpiX);
1401 todo_wine expectf(1440.0, header.DpiY);
1402 expect(0, header.X);
1403 expect(0, header.Y);
1404 todo_wine expect(320, header.Width);
1405 todo_wine expect(320, header.Height);
1406 todo_wine expect(1, U(header).WmfHeader.mtType);
1407 expect(0, header.EmfPlusHeaderSize);
1408 expect(0, header.LogicalDpiX);
1409 expect(0, header.LogicalDpiY);
1412 GdipDisposeImage(img);
1415 static void test_resolution(void)
1421 int screenxres, screenyres;
1424 stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
1427 /* test invalid values */
1428 stat = GdipGetImageHorizontalResolution(NULL, &res);
1429 expect(InvalidParameter, stat);
1431 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
1432 expect(InvalidParameter, stat);
1434 stat = GdipGetImageVerticalResolution(NULL, &res);
1435 expect(InvalidParameter, stat);
1437 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
1438 expect(InvalidParameter, stat);
1440 stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
1441 expect(InvalidParameter, stat);
1443 stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
1444 expect(InvalidParameter, stat);
1446 /* defaults to screen resolution */
1447 screendc = GetDC(0);
1449 screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
1450 screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
1452 ReleaseDC(0, screendc);
1454 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1456 expectf((REAL)screenxres, res);
1458 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1460 expectf((REAL)screenyres, res);
1462 /* test changing the resolution */
1463 stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
1466 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1468 expectf(screenxres*2.0, res);
1470 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1472 expectf(screenyres*3.0, res);
1474 stat = GdipDisposeImage((GpImage*)bitmap);
1478 static void test_createhbitmap(void)
1482 HBITMAP hbitmap, oldhbitmap;
1489 memset(bits, 0x68, 640);
1492 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
1495 /* test NULL values */
1496 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
1497 expect(InvalidParameter, stat);
1499 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
1500 expect(InvalidParameter, stat);
1502 /* create HBITMAP */
1503 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
1508 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
1509 expect(sizeof(BITMAP), ret);
1511 expect(0, bm.bmType);
1512 expect(10, bm.bmWidth);
1513 expect(20, bm.bmHeight);
1514 expect(40, bm.bmWidthBytes);
1515 expect(1, bm.bmPlanes);
1516 expect(32, bm.bmBitsPixel);
1517 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1519 hdc = CreateCompatibleDC(NULL);
1521 oldhbitmap = SelectObject(hdc, hbitmap);
1522 pixel = GetPixel(hdc, 5, 5);
1523 SelectObject(hdc, oldhbitmap);
1527 expect(0x686868, pixel);
1529 DeleteObject(hbitmap);
1532 stat = GdipDisposeImage((GpImage*)bitmap);
1536 static void test_getthumbnail(void)
1539 GpImage *bitmap1, *bitmap2;
1542 stat = GdipGetImageThumbnail(NULL, 0, 0, &bitmap2, NULL, NULL);
1543 expect(InvalidParameter, stat);
1545 stat = GdipCreateBitmapFromScan0(128, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1548 stat = GdipGetImageThumbnail(bitmap1, 0, 0, NULL, NULL, NULL);
1549 expect(InvalidParameter, stat);
1551 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1556 stat = GdipGetImageWidth(bitmap2, &width);
1560 stat = GdipGetImageHeight(bitmap2, &height);
1562 expect(120, height);
1564 GdipDisposeImage(bitmap2);
1567 GdipDisposeImage(bitmap1);
1570 stat = GdipCreateBitmapFromScan0(64, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1573 stat = GdipGetImageThumbnail(bitmap1, 32, 32, &bitmap2, NULL, NULL);
1578 stat = GdipGetImageWidth(bitmap2, &width);
1582 stat = GdipGetImageHeight(bitmap2, &height);
1586 GdipDisposeImage(bitmap2);
1589 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1594 stat = GdipGetImageWidth(bitmap2, &width);
1598 stat = GdipGetImageHeight(bitmap2, &height);
1600 expect(120, height);
1602 GdipDisposeImage(bitmap2);
1605 GdipDisposeImage(bitmap1);
1608 static void test_getsetpixel(void)
1613 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1614 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1616 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1619 /* null parameters */
1620 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1621 expect(InvalidParameter, stat);
1623 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1624 expect(InvalidParameter, stat);
1626 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1627 expect(InvalidParameter, stat);
1630 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1631 expect(InvalidParameter, stat);
1633 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1634 expect(InvalidParameter, stat);
1636 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1637 ok(stat == InvalidParameter ||
1638 broken(stat == Ok), /* Older gdiplus */
1639 "Expected InvalidParameter, got %.8x\n", stat);
1641 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1642 ok(stat == InvalidParameter ||
1643 broken(stat == Ok), /* Older gdiplus */
1644 "Expected InvalidParameter, got %.8x\n", stat);
1646 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1647 expect(InvalidParameter, stat);
1649 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1650 expect(InvalidParameter, stat);
1652 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1653 expect(InvalidParameter, stat);
1655 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1656 expect(InvalidParameter, stat);
1659 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1661 expect(0xffffffff, color);
1663 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1665 expect(0xff0000ff, color);
1667 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1670 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1673 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1675 expect(0xff676869, color);
1677 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1679 expect(0xff474849, color);
1681 stat = GdipDisposeImage((GpImage*)bitmap);
1685 static void check_halftone_palette(ColorPalette *palette)
1687 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1690 for (i=0; i<palette->Count; i++)
1692 ARGB expected=0xff000000;
1695 if (i&1) expected |= 0x800000;
1696 if (i&2) expected |= 0x8000;
1697 if (i&4) expected |= 0x80;
1701 expected = 0xffc0c0c0;
1705 if (i&1) expected |= 0xff0000;
1706 if (i&2) expected |= 0xff00;
1707 if (i&4) expected |= 0xff;
1711 expected = 0x00000000;
1715 expected |= halftone_values[(i-40)%6];
1716 expected |= halftone_values[((i-40)/6)%6] << 8;
1717 expected |= halftone_values[((i-40)/36)%6] << 16;
1719 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1720 expected, palette->Entries[i], i, palette->Count);
1724 static void test_palette(void)
1730 ColorPalette *palette=(ColorPalette*)buffer;
1733 /* test initial palette from non-indexed bitmap */
1734 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1737 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1739 expect(sizeof(UINT)*2+sizeof(ARGB), size);
1741 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1743 expect(0, palette->Count);
1745 /* test setting palette on not-indexed bitmap */
1748 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1751 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1753 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1755 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1757 expect(3, palette->Count);
1759 GdipDisposeImage((GpImage*)bitmap);
1761 /* test initial palette on 1-bit bitmap */
1762 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1765 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1767 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1769 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1771 expect(PaletteFlagsGrayScale, palette->Flags);
1772 expect(2, palette->Count);
1774 expect(0xff000000, palette->Entries[0]);
1775 expect(0xffffffff, palette->Entries[1]);
1777 /* test getting/setting pixels */
1778 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1780 expect(0xff000000, color);
1782 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1784 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1788 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1790 expect(0xffffffff, color);
1793 GdipDisposeImage((GpImage*)bitmap);
1795 /* test initial palette on 4-bit bitmap */
1796 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1799 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1801 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1803 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1805 expect(0, palette->Flags);
1806 expect(16, palette->Count);
1808 check_halftone_palette(palette);
1810 /* test getting/setting pixels */
1811 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1813 expect(0xff000000, color);
1815 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
1817 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1821 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1823 expect(0xffff00ff, color);
1826 GdipDisposeImage((GpImage*)bitmap);
1828 /* test initial palette on 8-bit bitmap */
1829 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1832 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1834 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1836 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1838 expect(PaletteFlagsHalftone, palette->Flags);
1839 expect(256, palette->Count);
1841 check_halftone_palette(palette);
1843 /* test getting/setting pixels */
1844 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1846 expect(0xff000000, color);
1848 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
1850 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1854 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1856 expect(0xffcccccc, color);
1859 /* test setting/getting a different palette */
1860 palette->Entries[1] = 0xffcccccc;
1862 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1865 palette->Entries[1] = 0;
1867 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1869 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1871 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1873 expect(PaletteFlagsHalftone, palette->Flags);
1874 expect(256, palette->Count);
1875 expect(0xffcccccc, palette->Entries[1]);
1877 /* test count < 256 */
1878 palette->Flags = 12345;
1881 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1884 palette->Entries[1] = 0;
1885 palette->Entries[3] = 0xdeadbeef;
1887 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1889 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1891 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1893 expect(12345, palette->Flags);
1894 expect(3, palette->Count);
1895 expect(0xffcccccc, palette->Entries[1]);
1896 expect(0xdeadbeef, palette->Entries[3]);
1898 /* test count > 256 */
1899 palette->Count = 257;
1901 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1902 ok(stat == InvalidParameter ||
1903 broken(stat == Ok), /* Old gdiplus behavior */
1904 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1906 GdipDisposeImage((GpImage*)bitmap);
1909 static void test_colormatrix(void)
1912 ColorMatrix colormatrix, graymatrix;
1913 GpImageAttributes *imageattr;
1914 const ColorMatrix identity = {{
1915 {1.0,0.0,0.0,0.0,0.0},
1916 {0.0,1.0,0.0,0.0,0.0},
1917 {0.0,0.0,1.0,0.0,0.0},
1918 {0.0,0.0,0.0,1.0,0.0},
1919 {0.0,0.0,0.0,0.0,1.0}}};
1920 const ColorMatrix double_red = {{
1921 {2.0,0.0,0.0,0.0,0.0},
1922 {0.0,1.0,0.0,0.0,0.0},
1923 {0.0,0.0,1.0,0.0,0.0},
1924 {0.0,0.0,0.0,1.0,0.0},
1925 {0.0,0.0,0.0,0.0,1.0}}};
1926 GpBitmap *bitmap1, *bitmap2;
1927 GpGraphics *graphics;
1930 colormatrix = identity;
1931 graymatrix = identity;
1933 stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
1934 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1935 expect(InvalidParameter, stat);
1937 stat = GdipCreateImageAttributes(&imageattr);
1940 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1941 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1944 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1945 TRUE, NULL, NULL, ColorMatrixFlagsDefault);
1946 expect(InvalidParameter, stat);
1948 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1949 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1952 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1953 TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
1956 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1957 TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
1958 expect(InvalidParameter, stat);
1960 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1961 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
1964 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1965 TRUE, &colormatrix, &graymatrix, 3);
1966 expect(InvalidParameter, stat);
1968 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
1969 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1970 expect(InvalidParameter, stat);
1972 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
1973 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
1974 expect(InvalidParameter, stat);
1976 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1977 FALSE, NULL, NULL, ColorMatrixFlagsDefault);
1980 /* Drawing a bitmap transforms the colors */
1981 colormatrix = double_red;
1982 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
1983 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
1986 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
1989 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
1992 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ffff);
1995 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
1998 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
1999 UnitPixel, imageattr, NULL, NULL);
2002 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2004 todo_wine expect(0xff80ffff, color);
2006 GdipDeleteGraphics(graphics);
2007 GdipDisposeImage((GpImage*)bitmap1);
2008 GdipDisposeImage((GpImage*)bitmap2);
2009 GdipDisposeImageAttributes(imageattr);
2012 static void test_gamma(void)
2015 GpImageAttributes *imageattr;
2016 GpBitmap *bitmap1, *bitmap2;
2017 GpGraphics *graphics;
2020 stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
2021 expect(InvalidParameter, stat);
2023 stat = GdipCreateImageAttributes(&imageattr);
2026 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
2029 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
2030 expect(InvalidParameter, stat);
2032 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
2033 expect(InvalidParameter, stat);
2035 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
2036 expect(InvalidParameter, stat);
2038 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
2041 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
2044 /* Drawing a bitmap transforms the colors */
2045 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
2048 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
2051 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
2054 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
2057 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2060 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2061 UnitPixel, imageattr, NULL, NULL);
2064 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2066 todo_wine ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
2068 GdipDeleteGraphics(graphics);
2069 GdipDisposeImage((GpImage*)bitmap1);
2070 GdipDisposeImage((GpImage*)bitmap2);
2071 GdipDisposeImageAttributes(imageattr);
2074 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
2075 static const unsigned char gifanimation[72] = {
2076 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
2077 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
2078 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
2079 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
2080 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
2083 static void test_multiframegif(void)
2095 /* Test frame functions with an animated GIF */
2096 hglob = GlobalAlloc (0, sizeof(gifanimation));
2097 data = GlobalLock (hglob);
2098 memcpy(data, gifanimation, sizeof(gifanimation));
2099 GlobalUnlock(hglob);
2101 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
2102 ok(hres == S_OK, "Failed to create a stream\n");
2103 if(hres != S_OK) return;
2105 stat = GdipCreateBitmapFromStream(stream, &bmp);
2106 ok(stat == Ok, "Failed to create a Bitmap\n");
2108 IStream_Release(stream);
2112 /* Bitmap starts at frame 0 */
2114 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2116 expect(0xffffffff, color);
2118 /* Check that we get correct metadata */
2119 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
2123 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
2125 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
2128 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2130 todo_wine expect(2, count);
2132 /* SelectActiveFrame overwrites our current data */
2133 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
2137 GdipBitmapGetPixel(bmp, 0, 0, &color);
2139 todo_wine expect(0xff000000, color);
2141 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2145 GdipBitmapGetPixel(bmp, 0, 0, &color);
2147 expect(0xffffffff, color);
2149 /* Write over the image data */
2150 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
2153 /* Switching to the same frame does not overwrite our changes */
2154 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2157 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2159 expect(0xff000000, color);
2161 /* But switching to another frame and back does */
2162 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
2165 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2168 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2170 todo_wine expect(0xffffffff, color);
2172 GdipDisposeImage((GpImage*)bmp);
2173 IStream_Release(stream);
2175 /* Test with a non-animated gif */
2176 hglob = GlobalAlloc (0, sizeof(gifimage));
2177 data = GlobalLock (hglob);
2178 memcpy(data, gifimage, sizeof(gifimage));
2179 GlobalUnlock(hglob);
2181 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
2182 ok(hres == S_OK, "Failed to create a stream\n");
2183 if(hres != S_OK) return;
2185 stat = GdipCreateBitmapFromStream(stream, &bmp);
2186 ok(stat == Ok, "Failed to create a Bitmap\n");
2188 IStream_Release(stream);
2192 /* Check metadata */
2193 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
2197 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
2199 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
2202 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2206 GdipDisposeImage((GpImage*)bmp);
2207 IStream_Release(stream);
2210 static void test_rotateflip(void)
2215 static const BYTE orig_bits[24] = {
2216 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
2217 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
2221 memcpy(bits, orig_bits, sizeof(bits));
2222 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2225 stat = GdipImageRotateFlip(bitmap, Rotate90FlipNone);
2228 stat = GdipGetImageWidth(bitmap, &width);
2230 stat = GdipGetImageHeight(bitmap, &height);
2235 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2237 expect(0xff00ffff, color);
2239 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 0, &color);
2241 expect(0xffff0000, color);
2243 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 2, &color);
2245 expect(0xffffff00, color);
2247 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 2, &color);
2249 expect(0xff0000ff, color);
2253 expect(0xff, bits[2]);
2255 GdipDisposeImage(bitmap);
2257 memcpy(bits, orig_bits, sizeof(bits));
2258 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2261 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipX);
2264 stat = GdipGetImageWidth(bitmap, &width);
2266 stat = GdipGetImageHeight(bitmap, &height);
2271 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2273 expect(0xff0000ff, color);
2275 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2277 expect(0xffff0000, color);
2279 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2281 expect(0xffffff00, color);
2283 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2285 expect(0xff00ffff, color);
2289 expect(0xff, bits[2]);
2291 GdipDisposeImage(bitmap);
2293 memcpy(bits, orig_bits, sizeof(bits));
2294 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2297 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipY);
2300 stat = GdipGetImageWidth(bitmap, &width);
2302 stat = GdipGetImageHeight(bitmap, &height);
2307 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2309 expect(0xff00ffff, color);
2311 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2313 expect(0xffffff00, color);
2315 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2317 expect(0xffff0000, color);
2319 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2321 expect(0xff0000ff, color);
2325 expect(0xff, bits[2]);
2327 GdipDisposeImage(bitmap);
2330 static void test_remaptable(void)
2333 GpImageAttributes *imageattr;
2334 GpBitmap *bitmap1, *bitmap2;
2335 GpGraphics *graphics;
2339 map = GdipAlloc(sizeof(ColorMap));
2341 map->oldColor.Argb = 0xff00ff00;
2342 map->newColor.Argb = 0xffff00ff;
2344 stat = GdipSetImageAttributesRemapTable(NULL, ColorAdjustTypeDefault, TRUE, 1, map);
2345 expect(InvalidParameter, stat);
2347 stat = GdipCreateImageAttributes(&imageattr);
2350 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, NULL);
2351 expect(InvalidParameter, stat);
2353 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeCount, TRUE, 1, map);
2354 expect(InvalidParameter, stat);
2356 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeAny, TRUE, 1, map);
2357 expect(InvalidParameter, stat);
2359 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 0, map);
2360 expect(InvalidParameter, stat);
2362 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, FALSE, 0, NULL);
2365 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, map);
2368 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
2371 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
2374 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff00ff00);
2377 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2380 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2381 UnitPixel, imageattr, NULL, NULL);
2384 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2386 ok(color_match(0xffff00ff, color, 1), "Expected ffff00ff, got %.8x\n", color);
2388 GdipDeleteGraphics(graphics);
2389 GdipDisposeImage((GpImage*)bitmap1);
2390 GdipDisposeImage((GpImage*)bitmap2);
2391 GdipDisposeImageAttributes(imageattr);
2395 static void test_colorkey(void)
2398 GpImageAttributes *imageattr;
2399 GpBitmap *bitmap1, *bitmap2;
2400 GpGraphics *graphics;
2403 stat = GdipSetImageAttributesColorKeys(NULL, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2404 expect(InvalidParameter, stat);
2406 stat = GdipCreateImageAttributes(&imageattr);
2409 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeCount, TRUE, 0xff405060, 0xff708090);
2410 expect(InvalidParameter, stat);
2412 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeAny, TRUE, 0xff405060, 0xff708090);
2413 expect(InvalidParameter, stat);
2415 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2418 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap1);
2421 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap2);
2424 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0x20405060);
2427 stat = GdipBitmapSetPixel(bitmap1, 0, 1, 0x40506070);
2430 stat = GdipBitmapSetPixel(bitmap1, 1, 0, 0x60708090);
2433 stat = GdipBitmapSetPixel(bitmap1, 1, 1, 0xffffffff);
2436 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2439 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,2,2, 0,0,2,2,
2440 UnitPixel, imageattr, NULL, NULL);
2443 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2445 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2447 stat = GdipBitmapGetPixel(bitmap2, 0, 1, &color);
2449 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2451 stat = GdipBitmapGetPixel(bitmap2, 1, 0, &color);
2453 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2455 stat = GdipBitmapGetPixel(bitmap2, 1, 1, &color);
2457 ok(color_match(0xffffffff, color, 1), "Expected ffff00ff, got %.8x\n", color);
2459 GdipDeleteGraphics(graphics);
2460 GdipDisposeImage((GpImage*)bitmap1);
2461 GdipDisposeImage((GpImage*)bitmap2);
2462 GdipDisposeImageAttributes(imageattr);
2465 static void test_dispose(void)
2469 char invalid_image[256];
2471 stat = GdipDisposeImage(NULL);
2472 expect(InvalidParameter, stat);
2474 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, (GpBitmap**)&image);
2477 stat = GdipDisposeImage(image);
2480 stat = GdipDisposeImage(image);
2481 expect(ObjectBusy, stat);
2483 memset(invalid_image, 0, 256);
2484 stat = GdipDisposeImage((GpImage*)invalid_image);
2485 expect(ObjectBusy, stat);
2490 struct GdiplusStartupInput gdiplusStartupInput;
2491 ULONG_PTR gdiplusToken;
2493 gdiplusStartupInput.GdiplusVersion = 1;
2494 gdiplusStartupInput.DebugEventCallback = NULL;
2495 gdiplusStartupInput.SuppressBackgroundThread = 0;
2496 gdiplusStartupInput.SuppressExternalCodecs = 0;
2498 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
2502 test_GetImageDimension();
2503 test_GdipImageGetFrameDimensionsCount();
2504 test_LoadingImages();
2505 test_SavingImages();
2508 test_LockBits_UserBuf();
2509 test_GdipCreateBitmapFromHBITMAP();
2510 test_GdipGetImageFlags();
2511 test_GdipCloneImage();
2514 test_getrawformat();
2516 test_createfromwmf();
2518 test_createhbitmap();
2519 test_getthumbnail();
2524 test_multiframegif();
2530 GdiplusShutdown(gdiplusToken);