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;
521 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
530 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
534 stat
= GdipBitmapUnlockBits(bm
, &bd
);
538 /* read-only, with NULL rect -> whole bitmap lock */
539 stat
= GdipBitmapLockBits(bm
, NULL
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
541 expect(bd
.Width
, WIDTH
);
542 expect(bd
.Height
, HEIGHT
);
545 stat
= GdipBitmapUnlockBits(bm
, &bd
);
549 /* read-only, consecutive */
550 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
554 stat
= GdipBitmapUnlockBits(bm
, &bd
);
558 stat
= GdipDisposeImage((GpImage
*)bm
);
560 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
564 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
566 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
567 expect(WrongState
, stat
);
569 stat
= GdipBitmapUnlockBits(bm
, &bd
);
572 stat
= GdipDisposeImage((GpImage
*)bm
);
574 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
577 /* write, no modification */
578 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
, PixelFormat24bppRGB
, &bd
);
582 stat
= GdipBitmapUnlockBits(bm
, &bd
);
586 /* write, consecutive */
587 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
, PixelFormat24bppRGB
, &bd
);
591 stat
= GdipBitmapUnlockBits(bm
, &bd
);
595 stat
= GdipDisposeImage((GpImage
*)bm
);
597 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
601 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
, PixelFormat24bppRGB
, &bd
);
606 ((char*)bd
.Scan0
)[2] = 0xff;
608 stat
= GdipBitmapUnlockBits(bm
, &bd
);
612 stat
= GdipDisposeImage((GpImage
*)bm
);
616 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
618 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
620 stat
= GdipDisposeImage((GpImage
*)bm
);
624 static void test_GdipCreateBitmapFromHBITMAP(void)
626 GpBitmap
* gpbm
= NULL
;
628 HPALETTE hpal
= NULL
;
631 LOGPALETTE
* LogPal
= NULL
;
633 const REAL WIDTH1
= 5;
634 const REAL HEIGHT1
= 15;
635 const REAL WIDTH2
= 10;
636 const REAL HEIGHT2
= 20;
641 stat
= GdipCreateBitmapFromHBITMAP(NULL
, NULL
, NULL
);
642 expect(InvalidParameter
, stat
);
644 hbm
= CreateBitmap(WIDTH1
, HEIGHT1
, 1, 1, NULL
);
645 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, NULL
);
646 expect(InvalidParameter
, stat
);
648 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
650 expect(Ok
, GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
));
651 expectf(WIDTH1
, width
);
652 expectf(HEIGHT1
, height
);
654 GdipDisposeImage((GpImage
*)gpbm
);
657 memset(buff
, 0, sizeof(buff
));
658 hbm
= CreateBitmap(WIDTH2
, HEIGHT2
, 1, 1, &buff
);
659 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
662 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)gpbm
, __LINE__
, FALSE
);
664 expect(Ok
, GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
));
665 expectf(WIDTH2
, width
);
666 expectf(HEIGHT2
, height
);
668 GdipDisposeImage((GpImage
*)gpbm
);
671 hdc
= CreateCompatibleDC(0);
672 ok(hdc
!= NULL
, "CreateCompatibleDC failed\n");
673 bmi
.bmiHeader
.biSize
= sizeof(bmi
.bmiHeader
);
674 bmi
.bmiHeader
.biHeight
= HEIGHT1
;
675 bmi
.bmiHeader
.biWidth
= WIDTH1
;
676 bmi
.bmiHeader
.biBitCount
= 24;
677 bmi
.bmiHeader
.biPlanes
= 1;
678 bmi
.bmiHeader
.biCompression
= BI_RGB
;
680 hbm
= CreateDIBSection(hdc
, &bmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
681 ok(hbm
!= NULL
, "CreateDIBSection failed\n");
685 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
687 expect(Ok
, GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
));
688 expectf(WIDTH1
, width
);
689 expectf(HEIGHT1
, height
);
692 /* test whether writing to the bitmap affects the original */
693 stat
= GdipBitmapSetPixel(gpbm
, 0, 0, 0xffffffff);
698 GdipDisposeImage((GpImage
*)gpbm
);
701 LogPal
= GdipAlloc(sizeof(LOGPALETTE
));
702 ok(LogPal
!= NULL
, "unable to allocate LOGPALETTE\n");
703 LogPal
->palVersion
= 0x300;
704 LogPal
->palNumEntries
= 1;
705 hpal
= CreatePalette(LogPal
);
706 ok(hpal
!= NULL
, "CreatePalette failed\n");
709 stat
= GdipCreateBitmapFromHBITMAP(hbm
, hpal
, &gpbm
);
715 GdipDisposeImage((GpImage
*)gpbm
);
721 static void test_GdipGetImageFlags(void)
727 img
= (GpImage
*)0xdeadbeef;
729 stat
= GdipGetImageFlags(NULL
, NULL
);
730 expect(InvalidParameter
, stat
);
732 stat
= GdipGetImageFlags(NULL
, &flags
);
733 expect(InvalidParameter
, stat
);
735 stat
= GdipGetImageFlags(img
, NULL
);
736 expect(InvalidParameter
, stat
);
739 static void test_GdipCloneImage(void)
745 GpImage
*image_src
, *image_dest
= NULL
;
746 const INT WIDTH
= 10, HEIGHT
= 20;
748 /* Create an image, clone it, delete the original, make sure the copy works */
749 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
751 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)bm
, __LINE__
, FALSE
);
753 image_src
= ((GpImage
*)bm
);
754 stat
= GdipCloneImage(image_src
, &image_dest
);
756 expect_rawformat(&ImageFormatMemoryBMP
, image_dest
, __LINE__
, FALSE
);
758 stat
= GdipDisposeImage((GpImage
*)bm
);
760 stat
= GdipGetImageBounds(image_dest
, &rectF
, &unit
);
763 /* Treat FP values carefully */
764 expectf((REAL
)WIDTH
, rectF
.Width
);
765 expectf((REAL
)HEIGHT
, rectF
.Height
);
767 stat
= GdipDisposeImage(image_dest
);
771 static void test_testcontrol(void)
777 stat
= GdipTestControl(TestControlGetBuildNumber
, ¶m
);
779 ok(param
!= 0, "Build number expected, got %u\n", param
);
782 static void test_fromhicon(void)
784 static const BYTE bmp_bits
[1024];
785 HBITMAP hbmMask
, hbmColor
;
789 GpBitmap
*bitmap
= NULL
;
795 stat
= GdipCreateBitmapFromHICON(NULL
, NULL
);
796 expect(InvalidParameter
, stat
);
797 stat
= GdipCreateBitmapFromHICON(NULL
, &bitmap
);
798 expect(InvalidParameter
, stat
);
800 /* color icon 1 bit */
801 hbmMask
= CreateBitmap(16, 16, 1, 1, bmp_bits
);
802 ok(hbmMask
!= 0, "CreateBitmap failed\n");
803 hbmColor
= CreateBitmap(16, 16, 1, 1, bmp_bits
);
804 ok(hbmColor
!= 0, "CreateBitmap failed\n");
808 info
.hbmMask
= hbmMask
;
809 info
.hbmColor
= hbmColor
;
810 hIcon
= CreateIconIndirect(&info
);
811 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
812 DeleteObject(hbmMask
);
813 DeleteObject(hbmColor
);
815 stat
= GdipCreateBitmapFromHICON(hIcon
, &bitmap
);
817 broken(stat
== InvalidParameter
), /* Win98 */
818 "Expected Ok, got %.8x\n", stat
);
820 /* check attributes */
821 stat
= GdipGetImageHeight((GpImage
*)bitmap
, &dim
);
824 stat
= GdipGetImageWidth((GpImage
*)bitmap
, &dim
);
827 stat
= GdipGetImageType((GpImage
*)bitmap
, &type
);
829 expect(ImageTypeBitmap
, type
);
830 stat
= GdipGetImagePixelFormat((GpImage
*)bitmap
, &format
);
831 expect(PixelFormat32bppARGB
, format
);
833 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)bitmap
, __LINE__
, FALSE
);
834 GdipDisposeImage((GpImage
*)bitmap
);
838 /* color icon 8 bpp */
839 hbmMask
= CreateBitmap(16, 16, 1, 8, bmp_bits
);
840 ok(hbmMask
!= 0, "CreateBitmap failed\n");
841 hbmColor
= CreateBitmap(16, 16, 1, 8, bmp_bits
);
842 ok(hbmColor
!= 0, "CreateBitmap failed\n");
846 info
.hbmMask
= hbmMask
;
847 info
.hbmColor
= hbmColor
;
848 hIcon
= CreateIconIndirect(&info
);
849 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
850 DeleteObject(hbmMask
);
851 DeleteObject(hbmColor
);
853 stat
= GdipCreateBitmapFromHICON(hIcon
, &bitmap
);
856 /* check attributes */
857 stat
= GdipGetImageHeight((GpImage
*)bitmap
, &dim
);
860 stat
= GdipGetImageWidth((GpImage
*)bitmap
, &dim
);
863 stat
= GdipGetImageType((GpImage
*)bitmap
, &type
);
865 expect(ImageTypeBitmap
, type
);
866 stat
= GdipGetImagePixelFormat((GpImage
*)bitmap
, &format
);
867 expect(PixelFormat32bppARGB
, format
);
869 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)bitmap
, __LINE__
, FALSE
);
870 GdipDisposeImage((GpImage
*)bitmap
);
876 static const unsigned char pngimage
[285] = {
877 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
878 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
879 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
880 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
881 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
882 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
883 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
886 static const unsigned char gifimage
[35] = {
887 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
888 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
892 static const unsigned char bmpimage
[66] = {
893 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
894 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
895 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
896 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
900 static const unsigned char jpgimage
[285] = {
901 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
902 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
903 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
904 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
905 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
906 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
907 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
908 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
909 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
910 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
911 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
912 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
913 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
914 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
915 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
916 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
917 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
918 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
921 static const unsigned char tiffimage
[] = {
922 0x49,0x49,0x2a,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xfe,0x00,
923 0x04,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x00,0x01,0x00,
924 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
925 0x00,0x00,0x02,0x01,0x03,0x00,0x03,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0x03,0x01,
926 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,0x01,0x03,0x00,0x01,0x00,
927 0x00,0x00,0x02,0x00,0x00,0x00,0x0d,0x01,0x02,0x00,0x1b,0x00,0x00,0x00,0xd8,0x00,
928 0x00,0x00,0x11,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x12,0x01,
929 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x01,0x03,0x00,0x01,0x00,
930 0x00,0x00,0x03,0x00,0x00,0x00,0x16,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x40,0x00,
931 0x00,0x00,0x17,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1a,0x01,
932 0x05,0x00,0x01,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x1b,0x01,0x05,0x00,0x01,0x00,
933 0x00,0x00,0xfc,0x00,0x00,0x00,0x1c,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
934 0x00,0x00,0x28,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
935 0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x6d,0x65,
936 0x68,0x2f,0x44,0x65,0x73,0x6b,0x74,0x6f,0x70,0x2f,0x74,0x65,0x73,0x74,0x2e,0x74,
937 0x69,0x66,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,
940 /* 320x320 twip wmf */
941 static const unsigned char wmfimage
[180] = {
942 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
943 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
944 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
945 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
946 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
947 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
948 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
949 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
950 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
951 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
952 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
955 static void test_getrawformat(void)
957 test_bufferrawformat((void*)pngimage
, sizeof(pngimage
), &ImageFormatPNG
, __LINE__
, FALSE
);
958 test_bufferrawformat((void*)gifimage
, sizeof(gifimage
), &ImageFormatGIF
, __LINE__
, FALSE
);
959 test_bufferrawformat((void*)bmpimage
, sizeof(bmpimage
), &ImageFormatBMP
, __LINE__
, FALSE
);
960 test_bufferrawformat((void*)jpgimage
, sizeof(jpgimage
), &ImageFormatJPEG
, __LINE__
, FALSE
);
961 test_bufferrawformat((void*)tiffimage
, sizeof(tiffimage
), &ImageFormatTIFF
, __LINE__
, FALSE
);
962 test_bufferrawformat((void*)wmfimage
, sizeof(wmfimage
), &ImageFormatWMF
, __LINE__
, FALSE
);
965 static void test_loadwmf(void)
976 MetafileHeader header
;
978 hglob
= GlobalAlloc (0, sizeof(wmfimage
));
979 data
= GlobalLock (hglob
);
980 memcpy(data
, wmfimage
, sizeof(wmfimage
));
981 GlobalUnlock(hglob
); data
= NULL
;
983 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
984 ok(hres
== S_OK
, "Failed to create a stream\n");
985 if(hres
!= S_OK
) return;
987 stat
= GdipLoadImageFromStream(stream
, &img
);
988 ok(stat
== Ok
, "Failed to create a Bitmap\n");
990 IStream_Release(stream
);
994 IStream_Release(stream
);
996 stat
= GdipGetImageBounds(img
, &bounds
, &unit
);
998 todo_wine
expect(UnitPixel
, unit
);
999 expectf(0.0, bounds
.X
);
1000 expectf(0.0, bounds
.Y
);
1001 todo_wine
expectf(320.0, bounds
.Width
);
1002 todo_wine
expectf(320.0, bounds
.Height
);
1004 stat
= GdipGetImageHorizontalResolution(img
, &res
);
1006 todo_wine
expectf(1440.0, res
);
1008 stat
= GdipGetImageVerticalResolution(img
, &res
);
1010 todo_wine
expectf(1440.0, res
);
1012 memset(&header
, 0, sizeof(header
));
1013 stat
= GdipGetMetafileHeaderFromMetafile((GpMetafile
*)img
, &header
);
1017 todo_wine
expect(MetafileTypeWmfPlaceable
, header
.Type
);
1018 todo_wine
expect(sizeof(wmfimage
)-sizeof(WmfPlaceableFileHeader
), header
.Size
);
1019 todo_wine
expect(0x300, header
.Version
);
1020 expect(0, header
.EmfPlusFlags
);
1021 todo_wine
expectf(1440.0, header
.DpiX
);
1022 todo_wine
expectf(1440.0, header
.DpiY
);
1023 expect(0, header
.X
);
1024 expect(0, header
.Y
);
1025 todo_wine
expect(320, header
.Width
);
1026 todo_wine
expect(320, header
.Height
);
1027 todo_wine
expect(1, U(header
).WmfHeader
.mtType
);
1028 expect(0, header
.EmfPlusHeaderSize
);
1029 expect(0, header
.LogicalDpiX
);
1030 expect(0, header
.LogicalDpiY
);
1033 GdipDisposeImage(img
);
1036 static void test_createfromwmf(void)
1044 MetafileHeader header
;
1046 hwmf
= SetMetaFileBitsEx(sizeof(wmfimage
)-sizeof(WmfPlaceableFileHeader
),
1047 wmfimage
+sizeof(WmfPlaceableFileHeader
));
1048 ok(hwmf
!= 0, "SetMetaFileBitsEx failed\n");
1050 stat
= GdipCreateMetafileFromWmf(hwmf
, TRUE
,
1051 (WmfPlaceableFileHeader
*)wmfimage
, (GpMetafile
**)&img
);
1054 stat
= GdipGetImageBounds(img
, &bounds
, &unit
);
1056 expect(UnitPixel
, unit
);
1057 expectf(0.0, bounds
.X
);
1058 expectf(0.0, bounds
.Y
);
1059 expectf(320.0, bounds
.Width
);
1060 expectf(320.0, bounds
.Height
);
1062 stat
= GdipGetImageHorizontalResolution(img
, &res
);
1064 expectf(1440.0, res
);
1066 stat
= GdipGetImageVerticalResolution(img
, &res
);
1068 expectf(1440.0, res
);
1070 memset(&header
, 0, sizeof(header
));
1071 stat
= GdipGetMetafileHeaderFromMetafile((GpMetafile
*)img
, &header
);
1075 todo_wine
expect(MetafileTypeWmfPlaceable
, header
.Type
);
1076 todo_wine
expect(sizeof(wmfimage
)-sizeof(WmfPlaceableFileHeader
), header
.Size
);
1077 todo_wine
expect(0x300, header
.Version
);
1078 expect(0, header
.EmfPlusFlags
);
1079 todo_wine
expectf(1440.0, header
.DpiX
);
1080 todo_wine
expectf(1440.0, header
.DpiY
);
1081 expect(0, header
.X
);
1082 expect(0, header
.Y
);
1083 todo_wine
expect(320, header
.Width
);
1084 todo_wine
expect(320, header
.Height
);
1085 todo_wine
expect(1, U(header
).WmfHeader
.mtType
);
1086 expect(0, header
.EmfPlusHeaderSize
);
1087 expect(0, header
.LogicalDpiX
);
1088 expect(0, header
.LogicalDpiY
);
1091 GdipDisposeImage(img
);
1094 static void test_resolution(void)
1100 int screenxres
, screenyres
;
1103 stat
= GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB
, NULL
, &bitmap
);
1106 /* test invalid values */
1107 stat
= GdipGetImageHorizontalResolution(NULL
, &res
);
1108 expect(InvalidParameter
, stat
);
1110 stat
= GdipGetImageHorizontalResolution((GpImage
*)bitmap
, NULL
);
1111 expect(InvalidParameter
, stat
);
1113 stat
= GdipGetImageVerticalResolution(NULL
, &res
);
1114 expect(InvalidParameter
, stat
);
1116 stat
= GdipGetImageVerticalResolution((GpImage
*)bitmap
, NULL
);
1117 expect(InvalidParameter
, stat
);
1119 stat
= GdipBitmapSetResolution(NULL
, 96.0, 96.0);
1120 expect(InvalidParameter
, stat
);
1122 stat
= GdipBitmapSetResolution(bitmap
, 0.0, 0.0);
1123 expect(InvalidParameter
, stat
);
1125 /* defaults to screen resolution */
1126 screendc
= GetDC(0);
1128 screenxres
= GetDeviceCaps(screendc
, LOGPIXELSX
);
1129 screenyres
= GetDeviceCaps(screendc
, LOGPIXELSY
);
1131 ReleaseDC(0, screendc
);
1133 stat
= GdipGetImageHorizontalResolution((GpImage
*)bitmap
, &res
);
1135 expectf((REAL
)screenxres
, res
);
1137 stat
= GdipGetImageVerticalResolution((GpImage
*)bitmap
, &res
);
1139 expectf((REAL
)screenyres
, res
);
1141 /* test changing the resolution */
1142 stat
= GdipBitmapSetResolution(bitmap
, screenxres
*2.0, screenyres
*3.0);
1145 stat
= GdipGetImageHorizontalResolution((GpImage
*)bitmap
, &res
);
1147 expectf(screenxres
*2.0, res
);
1149 stat
= GdipGetImageVerticalResolution((GpImage
*)bitmap
, &res
);
1151 expectf(screenyres
*3.0, res
);
1153 stat
= GdipDisposeImage((GpImage
*)bitmap
);
1157 static void test_createhbitmap(void)
1161 HBITMAP hbitmap
, oldhbitmap
;
1168 memset(bits
, 0x68, 640);
1171 stat
= GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB
, bits
, &bitmap
);
1174 /* test NULL values */
1175 stat
= GdipCreateHBITMAPFromBitmap(NULL
, &hbitmap
, 0);
1176 expect(InvalidParameter
, stat
);
1178 stat
= GdipCreateHBITMAPFromBitmap(bitmap
, NULL
, 0);
1179 expect(InvalidParameter
, stat
);
1181 /* create HBITMAP */
1182 stat
= GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
1187 ret
= GetObjectA(hbitmap
, sizeof(BITMAP
), &bm
);
1188 expect(sizeof(BITMAP
), ret
);
1190 expect(0, bm
.bmType
);
1191 expect(10, bm
.bmWidth
);
1192 expect(20, bm
.bmHeight
);
1193 expect(40, bm
.bmWidthBytes
);
1194 expect(1, bm
.bmPlanes
);
1195 expect(32, bm
.bmBitsPixel
);
1196 ok(bm
.bmBits
!= NULL
, "got DDB, expected DIB\n");
1198 hdc
= CreateCompatibleDC(NULL
);
1200 oldhbitmap
= SelectObject(hdc
, hbitmap
);
1201 pixel
= GetPixel(hdc
, 5, 5);
1202 SelectObject(hdc
, oldhbitmap
);
1206 expect(0x686868, pixel
);
1208 DeleteObject(hbitmap
);
1211 stat
= GdipDisposeImage((GpImage
*)bitmap
);
1215 static void test_getthumbnail(void)
1218 GpImage
*bitmap1
, *bitmap2
;
1221 stat
= GdipGetImageThumbnail(NULL
, 0, 0, &bitmap2
, NULL
, NULL
);
1222 expect(InvalidParameter
, stat
);
1224 stat
= GdipCreateBitmapFromScan0(128, 128, 0, PixelFormat32bppRGB
, NULL
, (GpBitmap
**)&bitmap1
);
1227 stat
= GdipGetImageThumbnail(bitmap1
, 0, 0, NULL
, NULL
, NULL
);
1228 expect(InvalidParameter
, stat
);
1230 stat
= GdipGetImageThumbnail(bitmap1
, 0, 0, &bitmap2
, NULL
, NULL
);
1235 stat
= GdipGetImageWidth(bitmap2
, &width
);
1239 stat
= GdipGetImageHeight(bitmap2
, &height
);
1241 expect(120, height
);
1243 GdipDisposeImage(bitmap2
);
1246 GdipDisposeImage(bitmap1
);
1249 stat
= GdipCreateBitmapFromScan0(64, 128, 0, PixelFormat32bppRGB
, NULL
, (GpBitmap
**)&bitmap1
);
1252 stat
= GdipGetImageThumbnail(bitmap1
, 32, 32, &bitmap2
, NULL
, NULL
);
1257 stat
= GdipGetImageWidth(bitmap2
, &width
);
1261 stat
= GdipGetImageHeight(bitmap2
, &height
);
1265 GdipDisposeImage(bitmap2
);
1268 stat
= GdipGetImageThumbnail(bitmap1
, 0, 0, &bitmap2
, NULL
, NULL
);
1273 stat
= GdipGetImageWidth(bitmap2
, &width
);
1277 stat
= GdipGetImageHeight(bitmap2
, &height
);
1279 expect(120, height
);
1281 GdipDisposeImage(bitmap2
);
1284 GdipDisposeImage(bitmap1
);
1287 static void test_getsetpixel(void)
1292 BYTE bits
[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1293 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1295 stat
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB
, bits
, &bitmap
);
1298 /* null parameters */
1299 stat
= GdipBitmapGetPixel(NULL
, 1, 1, &color
);
1300 expect(InvalidParameter
, stat
);
1302 stat
= GdipBitmapGetPixel(bitmap
, 1, 1, NULL
);
1303 expect(InvalidParameter
, stat
);
1305 stat
= GdipBitmapSetPixel(NULL
, 1, 1, 0);
1306 expect(InvalidParameter
, stat
);
1309 stat
= GdipBitmapGetPixel(bitmap
, -1, 1, &color
);
1310 expect(InvalidParameter
, stat
);
1312 stat
= GdipBitmapSetPixel(bitmap
, -1, 1, 0);
1313 expect(InvalidParameter
, stat
);
1315 stat
= GdipBitmapGetPixel(bitmap
, 1, -1, &color
);
1316 ok(stat
== InvalidParameter
||
1317 broken(stat
== Ok
), /* Older gdiplus */
1318 "Expected InvalidParameter, got %.8x\n", stat
);
1320 stat
= GdipBitmapSetPixel(bitmap
, 1, -1, 0);
1321 ok(stat
== InvalidParameter
||
1322 broken(stat
== Ok
), /* Older gdiplus */
1323 "Expected InvalidParameter, got %.8x\n", stat
);
1325 stat
= GdipBitmapGetPixel(bitmap
, 2, 1, &color
);
1326 expect(InvalidParameter
, stat
);
1328 stat
= GdipBitmapSetPixel(bitmap
, 2, 1, 0);
1329 expect(InvalidParameter
, stat
);
1331 stat
= GdipBitmapGetPixel(bitmap
, 1, 2, &color
);
1332 expect(InvalidParameter
, stat
);
1334 stat
= GdipBitmapSetPixel(bitmap
, 1, 2, 0);
1335 expect(InvalidParameter
, stat
);
1338 stat
= GdipBitmapGetPixel(bitmap
, 1, 1, &color
);
1340 expect(0xffffffff, color
);
1342 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
1344 expect(0xff0000ff, color
);
1346 stat
= GdipBitmapSetPixel(bitmap
, 1, 1, 0xff676869);
1349 stat
= GdipBitmapSetPixel(bitmap
, 0, 0, 0xff474849);
1352 stat
= GdipBitmapGetPixel(bitmap
, 1, 1, &color
);
1354 expect(0xff676869, color
);
1356 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
1358 expect(0xff474849, color
);
1360 stat
= GdipDisposeImage((GpImage
*)bitmap
);
1364 static void check_halftone_palette(ColorPalette
*palette
)
1366 static const BYTE halftone_values
[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1369 for (i
=0; i
<palette
->Count
; i
++)
1371 ARGB expected
=0xff000000;
1374 if (i
&1) expected
|= 0x800000;
1375 if (i
&2) expected
|= 0x8000;
1376 if (i
&4) expected
|= 0x80;
1380 expected
= 0xffc0c0c0;
1384 if (i
&1) expected
|= 0xff0000;
1385 if (i
&2) expected
|= 0xff00;
1386 if (i
&4) expected
|= 0xff;
1390 expected
= 0x00000000;
1394 expected
|= halftone_values
[(i
-40)%6];
1395 expected
|= halftone_values
[((i
-40)/6)%6] << 8;
1396 expected
|= halftone_values
[((i
-40)/36)%6] << 16;
1398 ok(expected
== palette
->Entries
[i
], "Expected %.8x, got %.8x, i=%u/%u\n",
1399 expected
, palette
->Entries
[i
], i
, palette
->Count
);
1403 static void test_palette(void)
1409 ColorPalette
*palette
=(ColorPalette
*)buffer
;
1412 /* test initial palette from non-indexed bitmap */
1413 stat
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB
, NULL
, &bitmap
);
1416 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1418 expect(sizeof(UINT
)*2+sizeof(ARGB
), size
);
1420 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1422 expect(0, palette
->Count
);
1424 /* test setting palette on not-indexed bitmap */
1427 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
1430 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1432 expect(sizeof(UINT
)*2+sizeof(ARGB
)*3, size
);
1434 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1436 expect(3, palette
->Count
);
1438 GdipDisposeImage((GpImage
*)bitmap
);
1440 /* test initial palette on 1-bit bitmap */
1441 stat
= GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed
, NULL
, &bitmap
);
1444 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1446 expect(sizeof(UINT
)*2+sizeof(ARGB
)*2, size
);
1448 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1450 expect(PaletteFlagsGrayScale
, palette
->Flags
);
1451 expect(2, palette
->Count
);
1453 expect(0xff000000, palette
->Entries
[0]);
1454 expect(0xffffffff, palette
->Entries
[1]);
1456 /* test getting/setting pixels */
1457 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
1459 expect(0xff000000, color
);
1461 stat
= GdipBitmapSetPixel(bitmap
, 0, 1, 0xffffffff);
1462 todo_wine
ok((stat
== Ok
) ||
1463 broken(stat
== InvalidParameter
) /* pre-win7 */, "stat=%.8x\n", stat
);
1467 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
1469 expect(0xffffffff, color
);
1472 GdipDisposeImage((GpImage
*)bitmap
);
1474 /* test initial palette on 4-bit bitmap */
1475 stat
= GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed
, NULL
, &bitmap
);
1478 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1480 expect(sizeof(UINT
)*2+sizeof(ARGB
)*16, size
);
1482 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1484 expect(0, palette
->Flags
);
1485 expect(16, palette
->Count
);
1487 check_halftone_palette(palette
);
1489 /* test getting/setting pixels */
1490 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
1492 expect(0xff000000, color
);
1494 stat
= GdipBitmapSetPixel(bitmap
, 0, 1, 0xffff00ff);
1495 todo_wine
ok((stat
== Ok
) ||
1496 broken(stat
== InvalidParameter
) /* pre-win7 */, "stat=%.8x\n", stat
);
1500 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
1502 expect(0xffff00ff, color
);
1505 GdipDisposeImage((GpImage
*)bitmap
);
1507 /* test initial palette on 8-bit bitmap */
1508 stat
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed
, NULL
, &bitmap
);
1511 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1513 expect(sizeof(UINT
)*2+sizeof(ARGB
)*256, size
);
1515 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1517 expect(PaletteFlagsHalftone
, palette
->Flags
);
1518 expect(256, palette
->Count
);
1520 check_halftone_palette(palette
);
1522 /* test getting/setting pixels */
1523 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
1525 expect(0xff000000, color
);
1527 stat
= GdipBitmapSetPixel(bitmap
, 0, 1, 0xffcccccc);
1528 todo_wine
ok((stat
== Ok
) ||
1529 broken(stat
== InvalidParameter
) /* pre-win7 */, "stat=%.8x\n", stat
);
1533 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
1535 expect(0xffcccccc, color
);
1538 /* test setting/getting a different palette */
1539 palette
->Entries
[1] = 0xffcccccc;
1541 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
1544 palette
->Entries
[1] = 0;
1546 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1548 expect(sizeof(UINT
)*2+sizeof(ARGB
)*256, size
);
1550 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1552 expect(PaletteFlagsHalftone
, palette
->Flags
);
1553 expect(256, palette
->Count
);
1554 expect(0xffcccccc, palette
->Entries
[1]);
1556 /* test count < 256 */
1557 palette
->Flags
= 12345;
1560 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
1563 palette
->Entries
[1] = 0;
1564 palette
->Entries
[3] = 0xdeadbeef;
1566 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1568 expect(sizeof(UINT
)*2+sizeof(ARGB
)*3, size
);
1570 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1572 expect(12345, palette
->Flags
);
1573 expect(3, palette
->Count
);
1574 expect(0xffcccccc, palette
->Entries
[1]);
1575 expect(0xdeadbeef, palette
->Entries
[3]);
1577 /* test count > 256 */
1578 palette
->Count
= 257;
1580 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
1581 ok(stat
== InvalidParameter
||
1582 broken(stat
== Ok
), /* Old gdiplus behavior */
1583 "Expected %.8x, got %.8x\n", InvalidParameter
, stat
);
1585 GdipDisposeImage((GpImage
*)bitmap
);
1588 static void test_colormatrix(void)
1591 ColorMatrix colormatrix
, graymatrix
;
1592 GpImageAttributes
*imageattr
;
1593 const ColorMatrix identity
= {{
1594 {1.0,0.0,0.0,0.0,0.0},
1595 {0.0,1.0,0.0,0.0,0.0},
1596 {0.0,0.0,1.0,0.0,0.0},
1597 {0.0,0.0,0.0,1.0,0.0},
1598 {0.0,0.0,0.0,0.0,1.0}}};
1599 const ColorMatrix double_red
= {{
1600 {2.0,0.0,0.0,0.0,0.0},
1601 {0.0,1.0,0.0,0.0,0.0},
1602 {0.0,0.0,1.0,0.0,0.0},
1603 {0.0,0.0,0.0,1.0,0.0},
1604 {0.0,0.0,0.0,0.0,1.0}}};
1605 GpBitmap
*bitmap1
, *bitmap2
;
1606 GpGraphics
*graphics
;
1609 colormatrix
= identity
;
1610 graymatrix
= identity
;
1612 stat
= GdipSetImageAttributesColorMatrix(NULL
, ColorAdjustTypeDefault
,
1613 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
1614 expect(InvalidParameter
, stat
);
1616 stat
= GdipCreateImageAttributes(&imageattr
);
1619 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1620 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsDefault
);
1623 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1624 TRUE
, NULL
, NULL
, ColorMatrixFlagsDefault
);
1625 expect(InvalidParameter
, stat
);
1627 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1628 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
1631 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1632 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsSkipGrays
);
1635 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1636 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsAltGray
);
1637 expect(InvalidParameter
, stat
);
1639 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1640 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsAltGray
);
1643 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1644 TRUE
, &colormatrix
, &graymatrix
, 3);
1645 expect(InvalidParameter
, stat
);
1647 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeCount
,
1648 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
1649 expect(InvalidParameter
, stat
);
1651 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeAny
,
1652 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
1653 expect(InvalidParameter
, stat
);
1655 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1656 FALSE
, NULL
, NULL
, ColorMatrixFlagsDefault
);
1659 /* Drawing a bitmap transforms the colors */
1660 colormatrix
= double_red
;
1661 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1662 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsDefault
);
1665 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap1
);
1668 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap2
);
1671 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0xff40ffff);
1674 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
1677 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
1678 UnitPixel
, imageattr
, NULL
, NULL
);
1681 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
1683 todo_wine
expect(0xff80ffff, color
);
1685 GdipDeleteGraphics(graphics
);
1686 GdipDisposeImage((GpImage
*)bitmap1
);
1687 GdipDisposeImage((GpImage
*)bitmap2
);
1688 GdipDisposeImageAttributes(imageattr
);
1691 static void test_gamma(void)
1694 GpImageAttributes
*imageattr
;
1695 GpBitmap
*bitmap1
, *bitmap2
;
1696 GpGraphics
*graphics
;
1699 stat
= GdipSetImageAttributesGamma(NULL
, ColorAdjustTypeDefault
, TRUE
, 1.0);
1700 expect(InvalidParameter
, stat
);
1702 stat
= GdipCreateImageAttributes(&imageattr
);
1705 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1.0);
1708 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeAny
, TRUE
, 1.0);
1709 expect(InvalidParameter
, stat
);
1711 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, -1.0);
1712 expect(InvalidParameter
, stat
);
1714 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0.0);
1715 expect(InvalidParameter
, stat
);
1717 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0.5);
1720 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, FALSE
, 0.0);
1723 /* Drawing a bitmap transforms the colors */
1724 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 3.0);
1727 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap1
);
1730 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap2
);
1733 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0xff80ffff);
1736 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
1739 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
1740 UnitPixel
, imageattr
, NULL
, NULL
);
1743 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
1745 todo_wine
ok(color_match(0xff20ffff, color
, 1), "Expected ff20ffff, got %.8x\n", color
);
1747 GdipDeleteGraphics(graphics
);
1748 GdipDisposeImage((GpImage
*)bitmap1
);
1749 GdipDisposeImage((GpImage
*)bitmap2
);
1750 GdipDisposeImageAttributes(imageattr
);
1753 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
1754 static const unsigned char gifanimation
[72] = {
1755 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1756 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
1757 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
1758 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
1759 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
1762 static void test_multiframegif(void)
1774 /* Test frame functions with an animated GIF */
1775 hglob
= GlobalAlloc (0, sizeof(gifanimation
));
1776 data
= GlobalLock (hglob
);
1777 memcpy(data
, gifanimation
, sizeof(gifanimation
));
1778 GlobalUnlock(hglob
);
1780 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
1781 ok(hres
== S_OK
, "Failed to create a stream\n");
1782 if(hres
!= S_OK
) return;
1784 stat
= GdipCreateBitmapFromStream(stream
, &bmp
);
1785 ok(stat
== Ok
, "Failed to create a Bitmap\n");
1787 IStream_Release(stream
);
1791 /* Bitmap starts at frame 0 */
1793 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
1795 expect(0xffffffff, color
);
1797 /* Check that we get correct metadata */
1798 stat
= GdipImageGetFrameDimensionsCount((GpImage
*)bmp
,&count
);
1802 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bmp
, &dimension
, 1);
1804 expect_guid(&FrameDimensionTime
, &dimension
, __LINE__
, FALSE
);
1807 stat
= GdipImageGetFrameCount((GpImage
*)bmp
, &dimension
, &count
);
1809 todo_wine
expect(2, count
);
1811 /* SelectActiveFrame overwrites our current data */
1812 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 1);
1816 GdipBitmapGetPixel(bmp
, 0, 0, &color
);
1818 todo_wine
expect(0xff000000, color
);
1820 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
1824 GdipBitmapGetPixel(bmp
, 0, 0, &color
);
1826 expect(0xffffffff, color
);
1828 /* Write over the image data */
1829 stat
= GdipBitmapSetPixel(bmp
, 0, 0, 0xff000000);
1832 /* Switching to the same frame does not overwrite our changes */
1833 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
1836 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
1838 expect(0xff000000, color
);
1840 /* But switching to another frame and back does */
1841 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 1);
1844 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
1847 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
1849 todo_wine
expect(0xffffffff, color
);
1851 GdipDisposeImage((GpImage
*)bmp
);
1852 IStream_Release(stream
);
1854 /* Test with a non-animated gif */
1855 hglob
= GlobalAlloc (0, sizeof(gifimage
));
1856 data
= GlobalLock (hglob
);
1857 memcpy(data
, gifimage
, sizeof(gifimage
));
1858 GlobalUnlock(hglob
);
1860 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
1861 ok(hres
== S_OK
, "Failed to create a stream\n");
1862 if(hres
!= S_OK
) return;
1864 stat
= GdipCreateBitmapFromStream(stream
, &bmp
);
1865 ok(stat
== Ok
, "Failed to create a Bitmap\n");
1867 IStream_Release(stream
);
1871 /* Check metadata */
1872 stat
= GdipImageGetFrameDimensionsCount((GpImage
*)bmp
,&count
);
1876 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bmp
, &dimension
, 1);
1878 expect_guid(&FrameDimensionTime
, &dimension
, __LINE__
, FALSE
);
1881 stat
= GdipImageGetFrameCount((GpImage
*)bmp
, &dimension
, &count
);
1885 GdipDisposeImage((GpImage
*)bmp
);
1886 IStream_Release(stream
);
1889 static void test_rotateflip(void)
1894 static const BYTE orig_bits
[24] = {
1895 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
1896 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
1900 memcpy(bits
, orig_bits
, sizeof(bits
));
1901 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
1904 stat
= GdipImageRotateFlip(bitmap
, Rotate90FlipNone
);
1907 stat
= GdipGetImageWidth(bitmap
, &width
);
1909 stat
= GdipGetImageHeight(bitmap
, &height
);
1914 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 0, &color
);
1916 expect(0xff00ffff, color
);
1918 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 1, 0, &color
);
1920 expect(0xffff0000, color
);
1922 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 2, &color
);
1924 expect(0xffffff00, color
);
1926 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 1, 2, &color
);
1928 expect(0xff0000ff, color
);
1932 expect(0xff, bits
[2]);
1934 GdipDisposeImage(bitmap
);
1936 memcpy(bits
, orig_bits
, sizeof(bits
));
1937 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
1940 stat
= GdipImageRotateFlip(bitmap
, RotateNoneFlipX
);
1943 stat
= GdipGetImageWidth(bitmap
, &width
);
1945 stat
= GdipGetImageHeight(bitmap
, &height
);
1950 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 0, &color
);
1952 expect(0xff0000ff, color
);
1954 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 0, &color
);
1956 expect(0xffff0000, color
);
1958 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 1, &color
);
1960 expect(0xffffff00, color
);
1962 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 1, &color
);
1964 expect(0xff00ffff, color
);
1968 expect(0xff, bits
[2]);
1970 GdipDisposeImage(bitmap
);
1972 memcpy(bits
, orig_bits
, sizeof(bits
));
1973 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
1976 stat
= GdipImageRotateFlip(bitmap
, RotateNoneFlipY
);
1979 stat
= GdipGetImageWidth(bitmap
, &width
);
1981 stat
= GdipGetImageHeight(bitmap
, &height
);
1986 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 0, &color
);
1988 expect(0xff00ffff, color
);
1990 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 0, &color
);
1992 expect(0xffffff00, color
);
1994 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 1, &color
);
1996 expect(0xffff0000, color
);
1998 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 1, &color
);
2000 expect(0xff0000ff, color
);
2004 expect(0xff, bits
[2]);
2006 GdipDisposeImage(bitmap
);
2009 static void test_remaptable(void)
2012 GpImageAttributes
*imageattr
;
2013 GpBitmap
*bitmap1
, *bitmap2
;
2014 GpGraphics
*graphics
;
2018 map
= GdipAlloc(sizeof(ColorMap
));
2020 map
->oldColor
.Argb
= 0xff00ff00;
2021 map
->newColor
.Argb
= 0xffff00ff;
2023 stat
= GdipSetImageAttributesRemapTable(NULL
, ColorAdjustTypeDefault
, TRUE
, 1, map
);
2024 expect(InvalidParameter
, stat
);
2026 stat
= GdipCreateImageAttributes(&imageattr
);
2029 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1, NULL
);
2030 expect(InvalidParameter
, stat
);
2032 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeCount
, TRUE
, 1, map
);
2033 expect(InvalidParameter
, stat
);
2035 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeAny
, TRUE
, 1, map
);
2036 expect(InvalidParameter
, stat
);
2038 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0, map
);
2039 expect(InvalidParameter
, stat
);
2041 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, FALSE
, 0, NULL
);
2044 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1, map
);
2047 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap1
);
2050 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap2
);
2053 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0xff00ff00);
2056 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
2059 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
2060 UnitPixel
, imageattr
, NULL
, NULL
);
2063 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2065 ok(color_match(0xffff00ff, color
, 1), "Expected ffff00ff, got %.8x\n", color
);
2067 GdipDeleteGraphics(graphics
);
2068 GdipDisposeImage((GpImage
*)bitmap1
);
2069 GdipDisposeImage((GpImage
*)bitmap2
);
2070 GdipDisposeImageAttributes(imageattr
);
2074 static void test_colorkey(void)
2077 GpImageAttributes
*imageattr
;
2078 GpBitmap
*bitmap1
, *bitmap2
;
2079 GpGraphics
*graphics
;
2082 stat
= GdipSetImageAttributesColorKeys(NULL
, ColorAdjustTypeDefault
, TRUE
, 0xff405060, 0xff708090);
2083 expect(InvalidParameter
, stat
);
2085 stat
= GdipCreateImageAttributes(&imageattr
);
2088 stat
= GdipSetImageAttributesColorKeys(imageattr
, ColorAdjustTypeCount
, TRUE
, 0xff405060, 0xff708090);
2089 expect(InvalidParameter
, stat
);
2091 stat
= GdipSetImageAttributesColorKeys(imageattr
, ColorAdjustTypeAny
, TRUE
, 0xff405060, 0xff708090);
2092 expect(InvalidParameter
, stat
);
2094 stat
= GdipSetImageAttributesColorKeys(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0xff405060, 0xff708090);
2097 stat
= GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB
, NULL
, &bitmap1
);
2100 stat
= GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB
, NULL
, &bitmap2
);
2103 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0x20405060);
2106 stat
= GdipBitmapSetPixel(bitmap1
, 0, 1, 0x40506070);
2109 stat
= GdipBitmapSetPixel(bitmap1
, 1, 0, 0x60708090);
2112 stat
= GdipBitmapSetPixel(bitmap1
, 1, 1, 0xffffffff);
2115 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
2118 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,2,2, 0,0,2,2,
2119 UnitPixel
, imageattr
, NULL
, NULL
);
2122 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2124 ok(color_match(0x00000000, color
, 1), "Expected ffff00ff, got %.8x\n", color
);
2126 stat
= GdipBitmapGetPixel(bitmap2
, 0, 1, &color
);
2128 ok(color_match(0x00000000, color
, 1), "Expected ffff00ff, got %.8x\n", color
);
2130 stat
= GdipBitmapGetPixel(bitmap2
, 1, 0, &color
);
2132 ok(color_match(0x00000000, color
, 1), "Expected ffff00ff, got %.8x\n", color
);
2134 stat
= GdipBitmapGetPixel(bitmap2
, 1, 1, &color
);
2136 ok(color_match(0xffffffff, color
, 1), "Expected ffff00ff, got %.8x\n", color
);
2138 GdipDeleteGraphics(graphics
);
2139 GdipDisposeImage((GpImage
*)bitmap1
);
2140 GdipDisposeImage((GpImage
*)bitmap2
);
2141 GdipDisposeImageAttributes(imageattr
);
2146 struct GdiplusStartupInput gdiplusStartupInput
;
2147 ULONG_PTR gdiplusToken
;
2149 gdiplusStartupInput
.GdiplusVersion
= 1;
2150 gdiplusStartupInput
.DebugEventCallback
= NULL
;
2151 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
2152 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
2154 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
2158 test_GetImageDimension();
2159 test_GdipImageGetFrameDimensionsCount();
2160 test_LoadingImages();
2161 test_SavingImages();
2164 test_GdipCreateBitmapFromHBITMAP();
2165 test_GdipGetImageFlags();
2166 test_GdipCloneImage();
2169 test_getrawformat();
2171 test_createfromwmf();
2173 test_createhbitmap();
2174 test_getthumbnail();
2179 test_multiframegif();
2184 GdiplusShutdown(gdiplusToken
);