2 * Unit test suite for images
4 * Copyright (C) 2007 Google (Evan Stade)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/test.h"
30 #define expect(expected, got) ok((UINT)(got) == (UINT)(expected), "Expected %.8x, got %.8x\n", (UINT)(expected), (UINT)(got))
31 #define expectf(expected, got) ok(fabs(expected - got) < 0.0001, "Expected %.2f, got %.2f\n", expected, got)
33 static BOOL
color_match(ARGB c1
, ARGB c2
, BYTE max_diff
)
35 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
37 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
39 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
41 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
45 static void expect_guid(REFGUID expected
, REFGUID got
, int line
, BOOL todo
)
51 StringFromGUID2(got
, bufferW
, sizeof(bufferW
)/sizeof(bufferW
[0]));
52 WideCharToMultiByte(CP_ACP
, 0, bufferW
, sizeof(bufferW
)/sizeof(bufferW
[0]), buffer
, sizeof(buffer
), NULL
, NULL
);
53 StringFromGUID2(expected
, bufferW
, sizeof(bufferW
)/sizeof(bufferW
[0]));
54 WideCharToMultiByte(CP_ACP
, 0, bufferW
, sizeof(bufferW
)/sizeof(bufferW
[0]), buffer2
, sizeof(buffer2
), NULL
, NULL
);
56 todo_wine
ok_(__FILE__
, line
)(IsEqualGUID(expected
, got
), "Expected %s, got %s\n", buffer2
, buffer
);
58 ok_(__FILE__
, line
)(IsEqualGUID(expected
, got
), "Expected %s, got %s\n", buffer2
, buffer
);
61 static void expect_rawformat(REFGUID expected
, GpImage
*img
, int line
, BOOL todo
)
66 stat
= GdipGetImageRawFormat(img
, &raw
);
67 ok_(__FILE__
, line
)(stat
== Ok
, "GdipGetImageRawFormat failed with %d\n", stat
);
68 if(stat
!= Ok
) return;
69 expect_guid(expected
, &raw
, line
, todo
);
72 static void test_bufferrawformat(void* buff
, int size
, REFGUID expected
, int line
, BOOL todo
)
81 hglob
= GlobalAlloc (0, size
);
82 data
= GlobalLock (hglob
);
83 memcpy(data
, buff
, size
);
84 GlobalUnlock(hglob
); data
= NULL
;
86 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
87 ok_(__FILE__
, line
)(hres
== S_OK
, "Failed to create a stream\n");
88 if(hres
!= S_OK
) return;
90 stat
= GdipLoadImageFromStream(stream
, &img
);
91 ok_(__FILE__
, line
)(stat
== Ok
, "Failed to create a Bitmap\n");
93 IStream_Release(stream
);
97 expect_rawformat(expected
, img
, line
, todo
);
99 GdipDisposeImage(img
);
100 IStream_Release(stream
);
103 static void test_Scan0(void)
110 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB
, NULL
, &bm
);
112 ok(NULL
!= bm
, "Expected bitmap to be initialized\n");
114 GdipDisposeImage((GpImage
*)bm
);
116 bm
= (GpBitmap
*)0xdeadbeef;
117 stat
= GdipCreateBitmapFromScan0(10, -10, 10, PixelFormat24bppRGB
, NULL
, &bm
);
118 expect(InvalidParameter
, stat
);
119 ok( !bm
, "expected null bitmap\n" );
121 bm
= (GpBitmap
*)0xdeadbeef;
122 stat
= GdipCreateBitmapFromScan0(-10, 10, 10, PixelFormat24bppRGB
, NULL
, &bm
);
123 expect(InvalidParameter
, stat
);
124 ok( !bm
, "expected null bitmap\n" );
126 bm
= (GpBitmap
*)0xdeadbeef;
127 stat
= GdipCreateBitmapFromScan0(10, 0, 10, PixelFormat24bppRGB
, NULL
, &bm
);
128 expect(InvalidParameter
, stat
);
129 ok( !bm
, "expected null bitmap\n" );
132 stat
= GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB
, buff
, &bm
);
134 ok(NULL
!= bm
, "Expected bitmap to be initialized\n");
136 GdipDisposeImage((GpImage
*)bm
);
138 bm
= (GpBitmap
*) 0xdeadbeef;
139 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB
, buff
, &bm
);
140 expect(InvalidParameter
, stat
);
141 ok( !bm
, "expected null bitmap\n" );
143 bm
= (GpBitmap
*)0xdeadbeef;
144 stat
= GdipCreateBitmapFromScan0(10, 10, 0, PixelFormat24bppRGB
, buff
, &bm
);
145 expect(InvalidParameter
, stat
);
146 ok( bm
== (GpBitmap
*)0xdeadbeef, "expected deadbeef bitmap\n" );
149 stat
= GdipCreateBitmapFromScan0(10, 10, -8, PixelFormat24bppRGB
, buff
, &bm
);
151 ok(NULL
!= bm
, "Expected bitmap to be initialized\n");
153 GdipDisposeImage((GpImage
*)bm
);
155 bm
= (GpBitmap
*)0xdeadbeef;
156 stat
= GdipCreateBitmapFromScan0(10, 10, -10, PixelFormat24bppRGB
, buff
, &bm
);
157 expect(InvalidParameter
, stat
);
158 ok( !bm
, "expected null bitmap\n" );
161 static void test_GetImageDimension(void)
165 const REAL WIDTH
= 10.0, HEIGHT
= 20.0;
168 bm
= (GpBitmap
*)0xdeadbeef;
169 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
,NULL
, &bm
);
171 ok((GpBitmap
*)0xdeadbeef != bm
, "Expected bitmap to not be 0xdeadbeef\n");
172 ok(NULL
!= bm
, "Expected bitmap to not be NULL\n");
174 stat
= GdipGetImageDimension(NULL
,&w
,&h
);
175 expect(InvalidParameter
, stat
);
177 stat
= GdipGetImageDimension((GpImage
*)bm
,NULL
,&h
);
178 expect(InvalidParameter
, stat
);
180 stat
= GdipGetImageDimension((GpImage
*)bm
,&w
,NULL
);
181 expect(InvalidParameter
, stat
);
185 stat
= GdipGetImageDimension((GpImage
*)bm
,&w
,&h
);
189 GdipDisposeImage((GpImage
*)bm
);
192 static void test_GdipImageGetFrameDimensionsCount(void)
196 const REAL WIDTH
= 10.0, HEIGHT
= 20.0;
198 GUID dimension
= {0};
202 bm
= (GpBitmap
*)0xdeadbeef;
203 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
,NULL
, &bm
);
205 ok((GpBitmap
*)0xdeadbeef != bm
, "Expected bitmap to not be 0xdeadbeef\n");
206 ok(NULL
!= bm
, "Expected bitmap to not be NULL\n");
208 stat
= GdipImageGetFrameDimensionsCount(NULL
,&w
);
209 expect(InvalidParameter
, stat
);
211 stat
= GdipImageGetFrameDimensionsCount((GpImage
*)bm
,NULL
);
212 expect(InvalidParameter
, stat
);
215 stat
= GdipImageGetFrameDimensionsCount((GpImage
*)bm
,&w
);
219 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bm
, &dimension
, 1);
221 expect_guid(&FrameDimensionPage
, &dimension
, __LINE__
, FALSE
);
223 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bm
, &dimension
, 2);
224 expect(InvalidParameter
, stat
);
226 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bm
, &dimension
, 0);
227 expect(InvalidParameter
, stat
);
230 stat
= GdipImageGetFrameCount((GpImage
*)bm
, &dimension
, &count
);
231 todo_wine
expect(Ok
, stat
);
232 todo_wine
expect(1, count
);
234 GdipBitmapSetPixel(bm
, 0, 0, 0xffffffff);
236 stat
= GdipImageSelectActiveFrame((GpImage
*)bm
, &dimension
, 0);
239 /* SelectActiveFrame has no effect on image data of memory bitmaps */
241 GdipBitmapGetPixel(bm
, 0, 0, &color
);
242 expect(0xffffffff, color
);
244 GdipDisposeImage((GpImage
*)bm
);
247 static void test_LoadingImages(void)
251 stat
= GdipCreateBitmapFromFile(0, 0);
252 expect(InvalidParameter
, stat
);
254 stat
= GdipCreateBitmapFromFile(0, (GpBitmap
**)0xdeadbeef);
255 expect(InvalidParameter
, stat
);
257 stat
= GdipLoadImageFromFile(0, 0);
258 expect(InvalidParameter
, stat
);
260 stat
= GdipLoadImageFromFile(0, (GpImage
**)0xdeadbeef);
261 expect(InvalidParameter
, stat
);
263 stat
= GdipLoadImageFromFileICM(0, 0);
264 expect(InvalidParameter
, stat
);
266 stat
= GdipLoadImageFromFileICM(0, (GpImage
**)0xdeadbeef);
267 expect(InvalidParameter
, stat
);
270 static void test_SavingImages(void)
276 const REAL WIDTH
= 10.0, HEIGHT
= 20.0;
278 ImageCodecInfo
*codecs
;
279 static const CHAR filenameA
[] = "a.bmp";
280 static const WCHAR filename
[] = { 'a','.','b','m','p',0 };
284 stat
= GdipSaveImageToFile(0, 0, 0, 0);
285 expect(InvalidParameter
, stat
);
288 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
294 stat
= GdipSaveImageToFile((GpImage
*)bm
, 0, 0, 0);
295 expect(InvalidParameter
, stat
);
297 stat
= GdipSaveImageToFile((GpImage
*)bm
, filename
, 0, 0);
298 expect(InvalidParameter
, stat
);
300 /* encoder tests should succeed -- already tested */
301 stat
= GdipGetImageEncodersSize(&n
, &s
);
302 if (stat
!= Ok
|| n
== 0) goto cleanup
;
304 codecs
= GdipAlloc(s
);
305 if (!codecs
) goto cleanup
;
307 stat
= GdipGetImageEncoders(n
, s
, codecs
);
308 if (stat
!= Ok
) goto cleanup
;
310 stat
= GdipSaveImageToFile((GpImage
*)bm
, filename
, &codecs
[0].Clsid
, 0);
313 GdipDisposeImage((GpImage
*)bm
);
316 /* re-load and check image stats */
317 stat
= GdipLoadImageFromFile(filename
, (GpImage
**)&bm
);
319 if (stat
!= Ok
) goto cleanup
;
321 stat
= GdipGetImageDimension((GpImage
*)bm
, &w
, &h
);
322 if (stat
!= Ok
) goto cleanup
;
330 GdipDisposeImage((GpImage
*)bm
);
331 ok(DeleteFileA(filenameA
), "Delete failed.\n");
334 static void test_encoders(void)
339 ImageCodecInfo
*codecs
;
343 static const CHAR bmp_format
[] = "BMP";
345 stat
= GdipGetImageEncodersSize(&n
, &s
);
348 codecs
= GdipAlloc(s
);
352 stat
= GdipGetImageEncoders(n
, s
, NULL
);
353 expect(GenericError
, stat
);
355 stat
= GdipGetImageEncoders(0, s
, codecs
);
356 expect(GenericError
, stat
);
358 stat
= GdipGetImageEncoders(n
, s
-1, codecs
);
359 expect(GenericError
, stat
);
361 stat
= GdipGetImageEncoders(n
, s
+1, codecs
);
362 expect(GenericError
, stat
);
364 stat
= GdipGetImageEncoders(n
, s
, codecs
);
368 for (i
= 0; i
< n
; i
++)
372 WideCharToMultiByte(CP_ACP
, 0, codecs
[i
].FormatDescription
, -1,
375 if (CompareStringA(LOCALE_SYSTEM_DEFAULT
, 0,
377 bmp_format
, -1) == CSTR_EQUAL
) {
383 ok(FALSE
, "No BMP codec found.\n");
388 static void test_LockBits(void)
394 const INT WIDTH
= 10, HEIGHT
= 20;
397 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
406 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
410 stat
= GdipBitmapUnlockBits(bm
, &bd
);
414 /* read-only, with NULL rect -> whole bitmap lock */
415 stat
= GdipBitmapLockBits(bm
, NULL
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
417 expect(bd
.Width
, WIDTH
);
418 expect(bd
.Height
, HEIGHT
);
421 stat
= GdipBitmapUnlockBits(bm
, &bd
);
425 /* read-only, consecutive */
426 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
430 stat
= GdipBitmapUnlockBits(bm
, &bd
);
434 stat
= GdipDisposeImage((GpImage
*)bm
);
436 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
440 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
442 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
443 expect(WrongState
, stat
);
445 stat
= GdipBitmapUnlockBits(bm
, &bd
);
448 stat
= GdipDisposeImage((GpImage
*)bm
);
450 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
453 /* write, no modification */
454 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
, PixelFormat24bppRGB
, &bd
);
458 stat
= GdipBitmapUnlockBits(bm
, &bd
);
462 /* write, consecutive */
463 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
, PixelFormat24bppRGB
, &bd
);
467 stat
= GdipBitmapUnlockBits(bm
, &bd
);
471 stat
= GdipDisposeImage((GpImage
*)bm
);
473 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
477 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
, PixelFormat24bppRGB
, &bd
);
482 ((char*)bd
.Scan0
)[2] = 0xff;
484 stat
= GdipBitmapUnlockBits(bm
, &bd
);
488 stat
= GdipDisposeImage((GpImage
*)bm
);
492 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
494 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
496 stat
= GdipDisposeImage((GpImage
*)bm
);
500 static void test_GdipCreateBitmapFromHBITMAP(void)
502 GpBitmap
* gpbm
= NULL
;
504 HPALETTE hpal
= NULL
;
507 LOGPALETTE
* LogPal
= NULL
;
509 const REAL WIDTH1
= 5;
510 const REAL HEIGHT1
= 15;
511 const REAL WIDTH2
= 10;
512 const REAL HEIGHT2
= 20;
517 stat
= GdipCreateBitmapFromHBITMAP(NULL
, NULL
, NULL
);
518 expect(InvalidParameter
, stat
);
520 hbm
= CreateBitmap(WIDTH1
, HEIGHT1
, 1, 1, NULL
);
521 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, NULL
);
522 expect(InvalidParameter
, stat
);
524 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
526 expect(Ok
, GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
));
527 expectf(WIDTH1
, width
);
528 expectf(HEIGHT1
, height
);
530 GdipDisposeImage((GpImage
*)gpbm
);
533 memset(buff
, 0, sizeof(buff
));
534 hbm
= CreateBitmap(WIDTH2
, HEIGHT2
, 1, 1, &buff
);
535 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
538 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)gpbm
, __LINE__
, FALSE
);
540 expect(Ok
, GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
));
541 expectf(WIDTH2
, width
);
542 expectf(HEIGHT2
, height
);
544 GdipDisposeImage((GpImage
*)gpbm
);
547 hdc
= CreateCompatibleDC(0);
548 ok(hdc
!= NULL
, "CreateCompatibleDC failed\n");
549 bmi
.bmiHeader
.biSize
= sizeof(bmi
.bmiHeader
);
550 bmi
.bmiHeader
.biHeight
= HEIGHT1
;
551 bmi
.bmiHeader
.biWidth
= WIDTH1
;
552 bmi
.bmiHeader
.biBitCount
= 24;
553 bmi
.bmiHeader
.biPlanes
= 1;
554 bmi
.bmiHeader
.biCompression
= BI_RGB
;
556 hbm
= CreateDIBSection(hdc
, &bmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
557 ok(hbm
!= NULL
, "CreateDIBSection failed\n");
561 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
563 expect(Ok
, GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
));
564 expectf(WIDTH1
, width
);
565 expectf(HEIGHT1
, height
);
568 /* test whether writing to the bitmap affects the original */
569 stat
= GdipBitmapSetPixel(gpbm
, 0, 0, 0xffffffff);
574 GdipDisposeImage((GpImage
*)gpbm
);
577 LogPal
= GdipAlloc(sizeof(LOGPALETTE
));
578 ok(LogPal
!= NULL
, "unable to allocate LOGPALETTE\n");
579 LogPal
->palVersion
= 0x300;
580 LogPal
->palNumEntries
= 1;
581 hpal
= CreatePalette(LogPal
);
582 ok(hpal
!= NULL
, "CreatePalette failed\n");
585 stat
= GdipCreateBitmapFromHBITMAP(hbm
, hpal
, &gpbm
);
591 GdipDisposeImage((GpImage
*)gpbm
);
597 static void test_GdipGetImageFlags(void)
603 img
= (GpImage
*)0xdeadbeef;
605 stat
= GdipGetImageFlags(NULL
, NULL
);
606 expect(InvalidParameter
, stat
);
608 stat
= GdipGetImageFlags(NULL
, &flags
);
609 expect(InvalidParameter
, stat
);
611 stat
= GdipGetImageFlags(img
, NULL
);
612 expect(InvalidParameter
, stat
);
615 static void test_GdipCloneImage(void)
621 GpImage
*image_src
, *image_dest
= NULL
;
622 const INT WIDTH
= 10, HEIGHT
= 20;
624 /* Create an image, clone it, delete the original, make sure the copy works */
625 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
627 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)bm
, __LINE__
, FALSE
);
629 image_src
= ((GpImage
*)bm
);
630 stat
= GdipCloneImage(image_src
, &image_dest
);
632 expect_rawformat(&ImageFormatMemoryBMP
, image_dest
, __LINE__
, FALSE
);
634 stat
= GdipDisposeImage((GpImage
*)bm
);
636 stat
= GdipGetImageBounds(image_dest
, &rectF
, &unit
);
639 /* Treat FP values carefully */
640 expectf((REAL
)WIDTH
, rectF
.Width
);
641 expectf((REAL
)HEIGHT
, rectF
.Height
);
643 stat
= GdipDisposeImage(image_dest
);
647 static void test_testcontrol(void)
653 stat
= GdipTestControl(TestControlGetBuildNumber
, ¶m
);
655 ok(param
!= 0, "Build number expected, got %u\n", param
);
658 static void test_fromhicon(void)
660 static const BYTE bmp_bits
[1024];
661 HBITMAP hbmMask
, hbmColor
;
665 GpBitmap
*bitmap
= NULL
;
671 stat
= GdipCreateBitmapFromHICON(NULL
, NULL
);
672 expect(InvalidParameter
, stat
);
673 stat
= GdipCreateBitmapFromHICON(NULL
, &bitmap
);
674 expect(InvalidParameter
, stat
);
676 /* color icon 1 bit */
677 hbmMask
= CreateBitmap(16, 16, 1, 1, bmp_bits
);
678 ok(hbmMask
!= 0, "CreateBitmap failed\n");
679 hbmColor
= CreateBitmap(16, 16, 1, 1, bmp_bits
);
680 ok(hbmColor
!= 0, "CreateBitmap failed\n");
684 info
.hbmMask
= hbmMask
;
685 info
.hbmColor
= hbmColor
;
686 hIcon
= CreateIconIndirect(&info
);
687 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
688 DeleteObject(hbmMask
);
689 DeleteObject(hbmColor
);
691 stat
= GdipCreateBitmapFromHICON(hIcon
, &bitmap
);
693 broken(stat
== InvalidParameter
), /* Win98 */
694 "Expected Ok, got %.8x\n", stat
);
696 /* check attributes */
697 stat
= GdipGetImageHeight((GpImage
*)bitmap
, &dim
);
700 stat
= GdipGetImageWidth((GpImage
*)bitmap
, &dim
);
703 stat
= GdipGetImageType((GpImage
*)bitmap
, &type
);
705 expect(ImageTypeBitmap
, type
);
706 stat
= GdipGetImagePixelFormat((GpImage
*)bitmap
, &format
);
707 expect(PixelFormat32bppARGB
, format
);
709 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)bitmap
, __LINE__
, FALSE
);
710 GdipDisposeImage((GpImage
*)bitmap
);
714 /* color icon 8 bpp */
715 hbmMask
= CreateBitmap(16, 16, 1, 8, bmp_bits
);
716 ok(hbmMask
!= 0, "CreateBitmap failed\n");
717 hbmColor
= CreateBitmap(16, 16, 1, 8, bmp_bits
);
718 ok(hbmColor
!= 0, "CreateBitmap failed\n");
722 info
.hbmMask
= hbmMask
;
723 info
.hbmColor
= hbmColor
;
724 hIcon
= CreateIconIndirect(&info
);
725 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
726 DeleteObject(hbmMask
);
727 DeleteObject(hbmColor
);
729 stat
= GdipCreateBitmapFromHICON(hIcon
, &bitmap
);
732 /* check attributes */
733 stat
= GdipGetImageHeight((GpImage
*)bitmap
, &dim
);
736 stat
= GdipGetImageWidth((GpImage
*)bitmap
, &dim
);
739 stat
= GdipGetImageType((GpImage
*)bitmap
, &type
);
741 expect(ImageTypeBitmap
, type
);
742 stat
= GdipGetImagePixelFormat((GpImage
*)bitmap
, &format
);
743 expect(PixelFormat32bppARGB
, format
);
745 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)bitmap
, __LINE__
, FALSE
);
746 GdipDisposeImage((GpImage
*)bitmap
);
752 static const unsigned char pngimage
[285] = {
753 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
754 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
755 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
756 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
757 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
758 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
759 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
762 static const unsigned char gifimage
[35] = {
763 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
764 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
768 static const unsigned char bmpimage
[66] = {
769 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
770 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
771 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
772 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
776 static const unsigned char jpgimage
[285] = {
777 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
778 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
779 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
780 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
781 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
782 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
783 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
784 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
785 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
786 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
787 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
788 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
789 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
790 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
791 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
792 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
793 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
794 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
796 /* 320x320 twip wmf */
797 static const unsigned char wmfimage
[180] = {
798 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
799 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
800 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
801 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
802 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
803 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
804 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
805 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
806 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
807 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
808 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
811 static void test_getrawformat(void)
813 test_bufferrawformat((void*)pngimage
, sizeof(pngimage
), &ImageFormatPNG
, __LINE__
, FALSE
);
814 test_bufferrawformat((void*)gifimage
, sizeof(gifimage
), &ImageFormatGIF
, __LINE__
, FALSE
);
815 test_bufferrawformat((void*)bmpimage
, sizeof(bmpimage
), &ImageFormatBMP
, __LINE__
, FALSE
);
816 test_bufferrawformat((void*)jpgimage
, sizeof(jpgimage
), &ImageFormatJPEG
, __LINE__
, FALSE
);
817 test_bufferrawformat((void*)wmfimage
, sizeof(wmfimage
), &ImageFormatWMF
, __LINE__
, FALSE
);
820 static void test_loadwmf(void)
831 MetafileHeader header
;
833 hglob
= GlobalAlloc (0, sizeof(wmfimage
));
834 data
= GlobalLock (hglob
);
835 memcpy(data
, wmfimage
, sizeof(wmfimage
));
836 GlobalUnlock(hglob
); data
= NULL
;
838 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
839 ok(hres
== S_OK
, "Failed to create a stream\n");
840 if(hres
!= S_OK
) return;
842 stat
= GdipLoadImageFromStream(stream
, &img
);
843 ok(stat
== Ok
, "Failed to create a Bitmap\n");
845 IStream_Release(stream
);
849 IStream_Release(stream
);
851 stat
= GdipGetImageBounds(img
, &bounds
, &unit
);
853 todo_wine
expect(UnitPixel
, unit
);
854 expectf(0.0, bounds
.X
);
855 expectf(0.0, bounds
.Y
);
856 todo_wine
expectf(320.0, bounds
.Width
);
857 todo_wine
expectf(320.0, bounds
.Height
);
859 stat
= GdipGetImageHorizontalResolution(img
, &res
);
861 todo_wine
expectf(1440.0, res
);
863 stat
= GdipGetImageVerticalResolution(img
, &res
);
865 todo_wine
expectf(1440.0, res
);
867 memset(&header
, 0, sizeof(header
));
868 stat
= GdipGetMetafileHeaderFromMetafile((GpMetafile
*)img
, &header
);
872 todo_wine
expect(MetafileTypeWmfPlaceable
, header
.Type
);
873 todo_wine
expect(sizeof(wmfimage
)-sizeof(WmfPlaceableFileHeader
), header
.Size
);
874 todo_wine
expect(0x300, header
.Version
);
875 expect(0, header
.EmfPlusFlags
);
876 todo_wine
expectf(1440.0, header
.DpiX
);
877 todo_wine
expectf(1440.0, header
.DpiY
);
880 todo_wine
expect(320, header
.Width
);
881 todo_wine
expect(320, header
.Height
);
882 todo_wine
expect(1, header
.WmfHeader
.mtType
);
883 expect(0, header
.EmfPlusHeaderSize
);
884 expect(0, header
.LogicalDpiX
);
885 expect(0, header
.LogicalDpiY
);
888 GdipDisposeImage(img
);
891 static void test_createfromwmf(void)
899 MetafileHeader header
;
901 hwmf
= SetMetaFileBitsEx(sizeof(wmfimage
)-sizeof(WmfPlaceableFileHeader
),
902 wmfimage
+sizeof(WmfPlaceableFileHeader
));
903 ok(hwmf
!= 0, "SetMetaFileBitsEx failed\n");
905 stat
= GdipCreateMetafileFromWmf(hwmf
, TRUE
,
906 (WmfPlaceableFileHeader
*)wmfimage
, (GpMetafile
**)&img
);
909 stat
= GdipGetImageBounds(img
, &bounds
, &unit
);
911 todo_wine
expect(UnitPixel
, unit
);
912 expectf(0.0, bounds
.X
);
913 expectf(0.0, bounds
.Y
);
914 todo_wine
expectf(320.0, bounds
.Width
);
915 todo_wine
expectf(320.0, bounds
.Height
);
917 stat
= GdipGetImageHorizontalResolution(img
, &res
);
919 expectf(1440.0, res
);
921 stat
= GdipGetImageVerticalResolution(img
, &res
);
923 expectf(1440.0, res
);
925 memset(&header
, 0, sizeof(header
));
926 stat
= GdipGetMetafileHeaderFromMetafile((GpMetafile
*)img
, &header
);
930 todo_wine
expect(MetafileTypeWmfPlaceable
, header
.Type
);
931 todo_wine
expect(sizeof(wmfimage
)-sizeof(WmfPlaceableFileHeader
), header
.Size
);
932 todo_wine
expect(0x300, header
.Version
);
933 expect(0, header
.EmfPlusFlags
);
934 todo_wine
expectf(1440.0, header
.DpiX
);
935 todo_wine
expectf(1440.0, header
.DpiY
);
938 todo_wine
expect(320, header
.Width
);
939 todo_wine
expect(320, header
.Height
);
940 todo_wine
expect(1, header
.WmfHeader
.mtType
);
941 expect(0, header
.EmfPlusHeaderSize
);
942 expect(0, header
.LogicalDpiX
);
943 expect(0, header
.LogicalDpiY
);
946 GdipDisposeImage(img
);
949 static void test_resolution(void)
955 int screenxres
, screenyres
;
958 stat
= GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB
, NULL
, &bitmap
);
961 /* test invalid values */
962 stat
= GdipGetImageHorizontalResolution(NULL
, &res
);
963 expect(InvalidParameter
, stat
);
965 stat
= GdipGetImageHorizontalResolution((GpImage
*)bitmap
, NULL
);
966 expect(InvalidParameter
, stat
);
968 stat
= GdipGetImageVerticalResolution(NULL
, &res
);
969 expect(InvalidParameter
, stat
);
971 stat
= GdipGetImageVerticalResolution((GpImage
*)bitmap
, NULL
);
972 expect(InvalidParameter
, stat
);
974 stat
= GdipBitmapSetResolution(NULL
, 96.0, 96.0);
975 expect(InvalidParameter
, stat
);
977 stat
= GdipBitmapSetResolution(bitmap
, 0.0, 0.0);
978 expect(InvalidParameter
, stat
);
980 /* defaults to screen resolution */
983 screenxres
= GetDeviceCaps(screendc
, LOGPIXELSX
);
984 screenyres
= GetDeviceCaps(screendc
, LOGPIXELSY
);
986 ReleaseDC(0, screendc
);
988 stat
= GdipGetImageHorizontalResolution((GpImage
*)bitmap
, &res
);
990 expectf((REAL
)screenxres
, res
);
992 stat
= GdipGetImageVerticalResolution((GpImage
*)bitmap
, &res
);
994 expectf((REAL
)screenyres
, res
);
996 /* test changing the resolution */
997 stat
= GdipBitmapSetResolution(bitmap
, screenxres
*2.0, screenyres
*3.0);
1000 stat
= GdipGetImageHorizontalResolution((GpImage
*)bitmap
, &res
);
1002 expectf(screenxres
*2.0, res
);
1004 stat
= GdipGetImageVerticalResolution((GpImage
*)bitmap
, &res
);
1006 expectf(screenyres
*3.0, res
);
1008 stat
= GdipDisposeImage((GpImage
*)bitmap
);
1012 static void test_createhbitmap(void)
1016 HBITMAP hbitmap
, oldhbitmap
;
1023 memset(bits
, 0x68, 640);
1026 stat
= GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB
, bits
, &bitmap
);
1029 /* test NULL values */
1030 stat
= GdipCreateHBITMAPFromBitmap(NULL
, &hbitmap
, 0);
1031 expect(InvalidParameter
, stat
);
1033 stat
= GdipCreateHBITMAPFromBitmap(bitmap
, NULL
, 0);
1034 expect(InvalidParameter
, stat
);
1036 /* create HBITMAP */
1037 stat
= GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
1042 ret
= GetObjectA(hbitmap
, sizeof(BITMAP
), &bm
);
1043 expect(sizeof(BITMAP
), ret
);
1045 expect(0, bm
.bmType
);
1046 expect(10, bm
.bmWidth
);
1047 expect(20, bm
.bmHeight
);
1048 expect(40, bm
.bmWidthBytes
);
1049 expect(1, bm
.bmPlanes
);
1050 expect(32, bm
.bmBitsPixel
);
1051 ok(bm
.bmBits
!= NULL
, "got DDB, expected DIB\n");
1053 hdc
= CreateCompatibleDC(NULL
);
1055 oldhbitmap
= SelectObject(hdc
, hbitmap
);
1056 pixel
= GetPixel(hdc
, 5, 5);
1057 SelectObject(hdc
, oldhbitmap
);
1061 expect(0x686868, pixel
);
1063 DeleteObject(hbitmap
);
1066 stat
= GdipDisposeImage((GpImage
*)bitmap
);
1070 static void test_getsetpixel(void)
1075 BYTE bits
[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1076 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1078 stat
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB
, bits
, &bitmap
);
1081 /* null parameters */
1082 stat
= GdipBitmapGetPixel(NULL
, 1, 1, &color
);
1083 expect(InvalidParameter
, stat
);
1085 stat
= GdipBitmapGetPixel(bitmap
, 1, 1, NULL
);
1086 expect(InvalidParameter
, stat
);
1088 stat
= GdipBitmapSetPixel(NULL
, 1, 1, 0);
1089 expect(InvalidParameter
, stat
);
1092 stat
= GdipBitmapGetPixel(bitmap
, -1, 1, &color
);
1093 expect(InvalidParameter
, stat
);
1095 stat
= GdipBitmapSetPixel(bitmap
, -1, 1, 0);
1096 expect(InvalidParameter
, stat
);
1098 stat
= GdipBitmapGetPixel(bitmap
, 1, -1, &color
);
1099 ok(stat
== InvalidParameter
||
1100 broken(stat
== Ok
), /* Older gdiplus */
1101 "Expected InvalidParameter, got %.8x\n", stat
);
1103 stat
= GdipBitmapSetPixel(bitmap
, 1, -1, 0);
1104 ok(stat
== InvalidParameter
||
1105 broken(stat
== Ok
), /* Older gdiplus */
1106 "Expected InvalidParameter, got %.8x\n", stat
);
1108 stat
= GdipBitmapGetPixel(bitmap
, 2, 1, &color
);
1109 expect(InvalidParameter
, stat
);
1111 stat
= GdipBitmapSetPixel(bitmap
, 2, 1, 0);
1112 expect(InvalidParameter
, stat
);
1114 stat
= GdipBitmapGetPixel(bitmap
, 1, 2, &color
);
1115 expect(InvalidParameter
, stat
);
1117 stat
= GdipBitmapSetPixel(bitmap
, 1, 2, 0);
1118 expect(InvalidParameter
, stat
);
1121 stat
= GdipBitmapGetPixel(bitmap
, 1, 1, &color
);
1123 expect(0xffffffff, color
);
1125 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
1127 expect(0xff0000ff, color
);
1129 stat
= GdipBitmapSetPixel(bitmap
, 1, 1, 0xff676869);
1132 stat
= GdipBitmapSetPixel(bitmap
, 0, 0, 0xff474849);
1135 stat
= GdipBitmapGetPixel(bitmap
, 1, 1, &color
);
1137 expect(0xff676869, color
);
1139 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
1141 expect(0xff474849, color
);
1143 stat
= GdipDisposeImage((GpImage
*)bitmap
);
1147 static void check_halftone_palette(ColorPalette
*palette
)
1149 static const BYTE halftone_values
[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1152 for (i
=0; i
<palette
->Count
; i
++)
1154 ARGB expected
=0xff000000;
1157 if (i
&1) expected
|= 0x800000;
1158 if (i
&2) expected
|= 0x8000;
1159 if (i
&4) expected
|= 0x80;
1163 expected
= 0xffc0c0c0;
1167 if (i
&1) expected
|= 0xff0000;
1168 if (i
&2) expected
|= 0xff00;
1169 if (i
&4) expected
|= 0xff;
1173 expected
= 0x00000000;
1177 expected
|= halftone_values
[(i
-40)%6];
1178 expected
|= halftone_values
[((i
-40)/6)%6] << 8;
1179 expected
|= halftone_values
[((i
-40)/36)%6] << 16;
1181 ok(expected
== palette
->Entries
[i
], "Expected %.8x, got %.8x, i=%u/%u\n",
1182 expected
, palette
->Entries
[i
], i
, palette
->Count
);
1186 static void test_palette(void)
1192 ColorPalette
*palette
=(ColorPalette
*)buffer
;
1195 /* test initial palette from non-indexed bitmap */
1196 stat
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB
, NULL
, &bitmap
);
1199 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1201 expect(sizeof(UINT
)*2+sizeof(ARGB
), size
);
1203 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1205 expect(0, palette
->Count
);
1207 /* test setting palette on not-indexed bitmap */
1210 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
1213 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1215 expect(sizeof(UINT
)*2+sizeof(ARGB
)*3, size
);
1217 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1219 expect(3, palette
->Count
);
1221 GdipDisposeImage((GpImage
*)bitmap
);
1223 /* test initial palette on 1-bit bitmap */
1224 stat
= GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed
, NULL
, &bitmap
);
1227 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1229 expect(sizeof(UINT
)*2+sizeof(ARGB
)*2, size
);
1231 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1233 expect(PaletteFlagsGrayScale
, palette
->Flags
);
1234 expect(2, palette
->Count
);
1236 expect(0xff000000, palette
->Entries
[0]);
1237 expect(0xffffffff, palette
->Entries
[1]);
1239 /* test getting/setting pixels */
1240 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
1242 expect(0xff000000, color
);
1244 stat
= GdipBitmapSetPixel(bitmap
, 0, 1, 0xffffffff);
1245 todo_wine
ok((stat
== Ok
) ||
1246 broken(stat
== InvalidParameter
) /* pre-win7 */, "stat=%.8x\n", stat
);
1250 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
1252 expect(0xffffffff, color
);
1255 GdipDisposeImage((GpImage
*)bitmap
);
1257 /* test initial palette on 4-bit bitmap */
1258 stat
= GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed
, NULL
, &bitmap
);
1261 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1263 expect(sizeof(UINT
)*2+sizeof(ARGB
)*16, size
);
1265 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1267 expect(0, palette
->Flags
);
1268 expect(16, palette
->Count
);
1270 check_halftone_palette(palette
);
1272 /* test getting/setting pixels */
1273 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
1275 expect(0xff000000, color
);
1277 stat
= GdipBitmapSetPixel(bitmap
, 0, 1, 0xffff00ff);
1278 todo_wine
ok((stat
== Ok
) ||
1279 broken(stat
== InvalidParameter
) /* pre-win7 */, "stat=%.8x\n", stat
);
1283 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
1285 expect(0xffff00ff, color
);
1288 GdipDisposeImage((GpImage
*)bitmap
);
1290 /* test initial palette on 8-bit bitmap */
1291 stat
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed
, NULL
, &bitmap
);
1294 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1296 expect(sizeof(UINT
)*2+sizeof(ARGB
)*256, size
);
1298 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1300 expect(PaletteFlagsHalftone
, palette
->Flags
);
1301 expect(256, palette
->Count
);
1303 check_halftone_palette(palette
);
1305 /* test getting/setting pixels */
1306 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
1308 expect(0xff000000, color
);
1310 stat
= GdipBitmapSetPixel(bitmap
, 0, 1, 0xffcccccc);
1311 todo_wine
ok((stat
== Ok
) ||
1312 broken(stat
== InvalidParameter
) /* pre-win7 */, "stat=%.8x\n", stat
);
1316 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
1318 expect(0xffcccccc, color
);
1321 /* test setting/getting a different palette */
1322 palette
->Entries
[1] = 0xffcccccc;
1324 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
1327 palette
->Entries
[1] = 0;
1329 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1331 expect(sizeof(UINT
)*2+sizeof(ARGB
)*256, size
);
1333 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1335 expect(PaletteFlagsHalftone
, palette
->Flags
);
1336 expect(256, palette
->Count
);
1337 expect(0xffcccccc, palette
->Entries
[1]);
1339 /* test count < 256 */
1340 palette
->Flags
= 12345;
1343 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
1346 palette
->Entries
[1] = 0;
1347 palette
->Entries
[3] = 0xdeadbeef;
1349 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1351 expect(sizeof(UINT
)*2+sizeof(ARGB
)*3, size
);
1353 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1355 expect(12345, palette
->Flags
);
1356 expect(3, palette
->Count
);
1357 expect(0xffcccccc, palette
->Entries
[1]);
1358 expect(0xdeadbeef, palette
->Entries
[3]);
1360 /* test count > 256 */
1361 palette
->Count
= 257;
1363 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
1364 ok(stat
== InvalidParameter
||
1365 broken(stat
== Ok
), /* Old gdiplus behavior */
1366 "Expected %.8x, got %.8x\n", InvalidParameter
, stat
);
1368 GdipDisposeImage((GpImage
*)bitmap
);
1371 static void test_colormatrix(void)
1374 ColorMatrix colormatrix
, graymatrix
;
1375 GpImageAttributes
*imageattr
;
1376 const ColorMatrix identity
= {{
1377 {1.0,0.0,0.0,0.0,0.0},
1378 {0.0,1.0,0.0,0.0,0.0},
1379 {0.0,0.0,1.0,0.0,0.0},
1380 {0.0,0.0,0.0,1.0,0.0},
1381 {0.0,0.0,0.0,0.0,1.0}}};
1382 const ColorMatrix double_red
= {{
1383 {2.0,0.0,0.0,0.0,0.0},
1384 {0.0,1.0,0.0,0.0,0.0},
1385 {0.0,0.0,1.0,0.0,0.0},
1386 {0.0,0.0,0.0,1.0,0.0},
1387 {0.0,0.0,0.0,0.0,1.0}}};
1388 GpBitmap
*bitmap1
, *bitmap2
;
1389 GpGraphics
*graphics
;
1392 colormatrix
= identity
;
1393 graymatrix
= identity
;
1395 stat
= GdipSetImageAttributesColorMatrix(NULL
, ColorAdjustTypeDefault
,
1396 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
1397 expect(InvalidParameter
, stat
);
1399 stat
= GdipCreateImageAttributes(&imageattr
);
1402 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1403 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsDefault
);
1406 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1407 TRUE
, NULL
, NULL
, ColorMatrixFlagsDefault
);
1408 expect(InvalidParameter
, stat
);
1410 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1411 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
1414 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1415 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsSkipGrays
);
1418 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1419 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsAltGray
);
1420 expect(InvalidParameter
, stat
);
1422 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1423 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsAltGray
);
1426 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1427 TRUE
, &colormatrix
, &graymatrix
, 3);
1428 expect(InvalidParameter
, stat
);
1430 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeCount
,
1431 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
1432 expect(InvalidParameter
, stat
);
1434 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeAny
,
1435 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
1436 expect(InvalidParameter
, stat
);
1438 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1439 FALSE
, NULL
, NULL
, ColorMatrixFlagsDefault
);
1442 /* Drawing a bitmap transforms the colors */
1443 colormatrix
= double_red
;
1444 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1445 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsDefault
);
1448 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap1
);
1451 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap2
);
1454 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0xff40ffff);
1457 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
1460 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
1461 UnitPixel
, imageattr
, NULL
, NULL
);
1464 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
1466 todo_wine
expect(0xff80ffff, color
);
1468 GdipDeleteGraphics(graphics
);
1469 GdipDisposeImage((GpImage
*)bitmap1
);
1470 GdipDisposeImage((GpImage
*)bitmap2
);
1471 GdipDisposeImageAttributes(imageattr
);
1474 static void test_gamma(void)
1477 GpImageAttributes
*imageattr
;
1478 GpBitmap
*bitmap1
, *bitmap2
;
1479 GpGraphics
*graphics
;
1482 stat
= GdipSetImageAttributesGamma(NULL
, ColorAdjustTypeDefault
, TRUE
, 1.0);
1483 expect(InvalidParameter
, stat
);
1485 stat
= GdipCreateImageAttributes(&imageattr
);
1488 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1.0);
1491 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeAny
, TRUE
, 1.0);
1492 expect(InvalidParameter
, stat
);
1494 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, -1.0);
1495 expect(InvalidParameter
, stat
);
1497 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0.0);
1498 expect(InvalidParameter
, stat
);
1500 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0.5);
1503 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, FALSE
, 0.0);
1506 /* Drawing a bitmap transforms the colors */
1507 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 3.0);
1510 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap1
);
1513 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap2
);
1516 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0xff80ffff);
1519 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
1522 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
1523 UnitPixel
, imageattr
, NULL
, NULL
);
1526 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
1528 todo_wine
ok(color_match(0xff20ffff, color
, 1), "Expected ff20ffff, got %.8x\n", color
);
1530 GdipDeleteGraphics(graphics
);
1531 GdipDisposeImage((GpImage
*)bitmap1
);
1532 GdipDisposeImage((GpImage
*)bitmap2
);
1533 GdipDisposeImageAttributes(imageattr
);
1536 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
1537 static const unsigned char gifanimation
[72] = {
1538 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1539 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
1540 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
1541 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
1542 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
1545 static void test_multiframegif(void)
1557 /* Test frame functions with an animated GIF */
1558 hglob
= GlobalAlloc (0, sizeof(gifanimation
));
1559 data
= GlobalLock (hglob
);
1560 memcpy(data
, gifanimation
, sizeof(gifanimation
));
1561 GlobalUnlock(hglob
);
1563 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
1564 ok(hres
== S_OK
, "Failed to create a stream\n");
1565 if(hres
!= S_OK
) return;
1567 stat
= GdipCreateBitmapFromStream(stream
, &bmp
);
1568 ok(stat
== Ok
, "Failed to create a Bitmap\n");
1570 IStream_Release(stream
);
1574 /* Bitmap starts at frame 0 */
1576 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
1578 expect(0xffffffff, color
);
1580 /* Check that we get correct metadata */
1581 stat
= GdipImageGetFrameDimensionsCount((GpImage
*)bmp
,&count
);
1585 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bmp
, &dimension
, 1);
1587 expect_guid(&FrameDimensionTime
, &dimension
, __LINE__
, FALSE
);
1590 stat
= GdipImageGetFrameCount((GpImage
*)bmp
, &dimension
, &count
);
1591 todo_wine
expect(Ok
, stat
);
1592 todo_wine
expect(2, count
);
1594 /* SelectActiveFrame overwrites our current data */
1595 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 1);
1599 GdipBitmapGetPixel(bmp
, 0, 0, &color
);
1601 todo_wine
expect(0xff000000, color
);
1603 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
1607 GdipBitmapGetPixel(bmp
, 0, 0, &color
);
1609 expect(0xffffffff, color
);
1611 /* Write over the image data */
1612 stat
= GdipBitmapSetPixel(bmp
, 0, 0, 0xff000000);
1615 /* Switching to the same frame does not overwrite our changes */
1616 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
1619 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
1621 expect(0xff000000, color
);
1623 /* But switching to another frame and back does */
1624 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 1);
1627 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
1630 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
1632 todo_wine
expect(0xffffffff, color
);
1634 GdipDisposeImage((GpImage
*)bmp
);
1635 IStream_Release(stream
);
1637 /* Test with a non-animated gif */
1638 hglob
= GlobalAlloc (0, sizeof(gifimage
));
1639 data
= GlobalLock (hglob
);
1640 memcpy(data
, gifimage
, sizeof(gifimage
));
1641 GlobalUnlock(hglob
);
1643 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
1644 ok(hres
== S_OK
, "Failed to create a stream\n");
1645 if(hres
!= S_OK
) return;
1647 stat
= GdipCreateBitmapFromStream(stream
, &bmp
);
1648 ok(stat
== Ok
, "Failed to create a Bitmap\n");
1650 IStream_Release(stream
);
1654 /* Check metadata */
1655 stat
= GdipImageGetFrameDimensionsCount((GpImage
*)bmp
,&count
);
1659 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bmp
, &dimension
, 1);
1661 expect_guid(&FrameDimensionTime
, &dimension
, __LINE__
, FALSE
);
1664 stat
= GdipImageGetFrameCount((GpImage
*)bmp
, &dimension
, &count
);
1665 todo_wine
expect(Ok
, stat
);
1666 todo_wine
expect(1, count
);
1668 GdipDisposeImage((GpImage
*)bmp
);
1669 IStream_Release(stream
);
1672 static void test_rotateflip(void)
1677 static const BYTE orig_bits
[24] = {
1678 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
1679 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
1683 memcpy(bits
, orig_bits
, sizeof(bits
));
1684 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
1687 stat
= GdipImageRotateFlip(bitmap
, Rotate90FlipNone
);
1688 todo_wine
expect(Ok
, stat
);
1690 stat
= GdipGetImageWidth(bitmap
, &width
);
1692 stat
= GdipGetImageHeight(bitmap
, &height
);
1694 todo_wine
expect(2, width
);
1695 todo_wine
expect(3, height
);
1697 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 0, &color
);
1699 todo_wine
expect(0xff00ffff, color
);
1701 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 1, 0, &color
);
1703 todo_wine
expect(0xffff0000, color
);
1705 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 2, &color
);
1706 todo_wine
expect(Ok
, stat
);
1707 todo_wine
expect(0xffffff00, color
);
1709 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 1, 2, &color
);
1710 todo_wine
expect(Ok
, stat
);
1711 todo_wine
expect(0xff0000ff, color
);
1715 expect(0xff, bits
[2]);
1717 GdipDisposeImage(bitmap
);
1719 memcpy(bits
, orig_bits
, sizeof(bits
));
1720 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
1723 stat
= GdipImageRotateFlip(bitmap
, RotateNoneFlipX
);
1724 todo_wine
expect(Ok
, stat
);
1726 stat
= GdipGetImageWidth(bitmap
, &width
);
1728 stat
= GdipGetImageHeight(bitmap
, &height
);
1733 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 0, &color
);
1735 todo_wine
expect(0xff0000ff, color
);
1737 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 0, &color
);
1739 todo_wine
expect(0xffff0000, color
);
1741 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 1, &color
);
1743 todo_wine
expect(0xffffff00, color
);
1745 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 1, &color
);
1747 todo_wine
expect(0xff00ffff, color
);
1751 expect(0xff, bits
[2]);
1753 GdipDisposeImage(bitmap
);
1755 memcpy(bits
, orig_bits
, sizeof(bits
));
1756 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
1759 stat
= GdipImageRotateFlip(bitmap
, RotateNoneFlipY
);
1760 todo_wine
expect(Ok
, stat
);
1762 stat
= GdipGetImageWidth(bitmap
, &width
);
1764 stat
= GdipGetImageHeight(bitmap
, &height
);
1769 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 0, &color
);
1771 todo_wine
expect(0xff00ffff, color
);
1773 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 0, &color
);
1775 todo_wine
expect(0xffffff00, color
);
1777 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 1, &color
);
1779 todo_wine
expect(0xffff0000, color
);
1781 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 1, &color
);
1783 todo_wine
expect(0xff0000ff, color
);
1787 expect(0xff, bits
[2]);
1789 GdipDisposeImage(bitmap
);
1792 static void test_remaptable(void)
1795 GpImageAttributes
*imageattr
;
1796 GpBitmap
*bitmap1
, *bitmap2
;
1797 GpGraphics
*graphics
;
1801 map
= GdipAlloc(sizeof(ColorMap
));
1803 map
->oldColor
.Argb
= 0xff00ff00;
1804 map
->newColor
.Argb
= 0xffff00ff;
1806 stat
= GdipSetImageAttributesRemapTable(NULL
, ColorAdjustTypeDefault
, TRUE
, 1, map
);
1807 expect(InvalidParameter
, stat
);
1809 stat
= GdipCreateImageAttributes(&imageattr
);
1812 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1, NULL
);
1813 expect(InvalidParameter
, stat
);
1815 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeCount
, TRUE
, 1, map
);
1816 expect(InvalidParameter
, stat
);
1818 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeAny
, TRUE
, 1, map
);
1819 expect(InvalidParameter
, stat
);
1821 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0, map
);
1822 expect(InvalidParameter
, stat
);
1824 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, FALSE
, 0, NULL
);
1827 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1, map
);
1830 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap1
);
1833 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap2
);
1836 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0xff00ff00);
1839 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
1842 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
1843 UnitPixel
, imageattr
, NULL
, NULL
);
1846 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
1848 todo_wine
ok(color_match(0xffff00ff, color
, 1), "Expected ffff00ff, got %.8x\n", color
);
1850 GdipDeleteGraphics(graphics
);
1851 GdipDisposeImage((GpImage
*)bitmap1
);
1852 GdipDisposeImage((GpImage
*)bitmap2
);
1853 GdipDisposeImageAttributes(imageattr
);
1859 struct GdiplusStartupInput gdiplusStartupInput
;
1860 ULONG_PTR gdiplusToken
;
1862 gdiplusStartupInput
.GdiplusVersion
= 1;
1863 gdiplusStartupInput
.DebugEventCallback
= NULL
;
1864 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
1865 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
1867 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
1870 test_GetImageDimension();
1871 test_GdipImageGetFrameDimensionsCount();
1872 test_LoadingImages();
1873 test_SavingImages();
1876 test_GdipCreateBitmapFromHBITMAP();
1877 test_GdipGetImageFlags();
1878 test_GdipCloneImage();
1881 test_getrawformat();
1883 test_createfromwmf();
1885 test_createhbitmap();
1890 test_multiframegif();
1894 GdiplusShutdown(gdiplusToken
);