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_getsetpixel(void)
1220 BYTE bits
[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1221 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1223 stat
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB
, bits
, &bitmap
);
1226 /* null parameters */
1227 stat
= GdipBitmapGetPixel(NULL
, 1, 1, &color
);
1228 expect(InvalidParameter
, stat
);
1230 stat
= GdipBitmapGetPixel(bitmap
, 1, 1, NULL
);
1231 expect(InvalidParameter
, stat
);
1233 stat
= GdipBitmapSetPixel(NULL
, 1, 1, 0);
1234 expect(InvalidParameter
, stat
);
1237 stat
= GdipBitmapGetPixel(bitmap
, -1, 1, &color
);
1238 expect(InvalidParameter
, stat
);
1240 stat
= GdipBitmapSetPixel(bitmap
, -1, 1, 0);
1241 expect(InvalidParameter
, stat
);
1243 stat
= GdipBitmapGetPixel(bitmap
, 1, -1, &color
);
1244 ok(stat
== InvalidParameter
||
1245 broken(stat
== Ok
), /* Older gdiplus */
1246 "Expected InvalidParameter, got %.8x\n", stat
);
1248 stat
= GdipBitmapSetPixel(bitmap
, 1, -1, 0);
1249 ok(stat
== InvalidParameter
||
1250 broken(stat
== Ok
), /* Older gdiplus */
1251 "Expected InvalidParameter, got %.8x\n", stat
);
1253 stat
= GdipBitmapGetPixel(bitmap
, 2, 1, &color
);
1254 expect(InvalidParameter
, stat
);
1256 stat
= GdipBitmapSetPixel(bitmap
, 2, 1, 0);
1257 expect(InvalidParameter
, stat
);
1259 stat
= GdipBitmapGetPixel(bitmap
, 1, 2, &color
);
1260 expect(InvalidParameter
, stat
);
1262 stat
= GdipBitmapSetPixel(bitmap
, 1, 2, 0);
1263 expect(InvalidParameter
, stat
);
1266 stat
= GdipBitmapGetPixel(bitmap
, 1, 1, &color
);
1268 expect(0xffffffff, color
);
1270 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
1272 expect(0xff0000ff, color
);
1274 stat
= GdipBitmapSetPixel(bitmap
, 1, 1, 0xff676869);
1277 stat
= GdipBitmapSetPixel(bitmap
, 0, 0, 0xff474849);
1280 stat
= GdipBitmapGetPixel(bitmap
, 1, 1, &color
);
1282 expect(0xff676869, color
);
1284 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
1286 expect(0xff474849, color
);
1288 stat
= GdipDisposeImage((GpImage
*)bitmap
);
1292 static void check_halftone_palette(ColorPalette
*palette
)
1294 static const BYTE halftone_values
[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1297 for (i
=0; i
<palette
->Count
; i
++)
1299 ARGB expected
=0xff000000;
1302 if (i
&1) expected
|= 0x800000;
1303 if (i
&2) expected
|= 0x8000;
1304 if (i
&4) expected
|= 0x80;
1308 expected
= 0xffc0c0c0;
1312 if (i
&1) expected
|= 0xff0000;
1313 if (i
&2) expected
|= 0xff00;
1314 if (i
&4) expected
|= 0xff;
1318 expected
= 0x00000000;
1322 expected
|= halftone_values
[(i
-40)%6];
1323 expected
|= halftone_values
[((i
-40)/6)%6] << 8;
1324 expected
|= halftone_values
[((i
-40)/36)%6] << 16;
1326 ok(expected
== palette
->Entries
[i
], "Expected %.8x, got %.8x, i=%u/%u\n",
1327 expected
, palette
->Entries
[i
], i
, palette
->Count
);
1331 static void test_palette(void)
1337 ColorPalette
*palette
=(ColorPalette
*)buffer
;
1340 /* test initial palette from non-indexed bitmap */
1341 stat
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB
, NULL
, &bitmap
);
1344 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1346 expect(sizeof(UINT
)*2+sizeof(ARGB
), size
);
1348 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1350 expect(0, palette
->Count
);
1352 /* test setting palette on not-indexed bitmap */
1355 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
1358 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1360 expect(sizeof(UINT
)*2+sizeof(ARGB
)*3, size
);
1362 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1364 expect(3, palette
->Count
);
1366 GdipDisposeImage((GpImage
*)bitmap
);
1368 /* test initial palette on 1-bit bitmap */
1369 stat
= GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed
, NULL
, &bitmap
);
1372 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1374 expect(sizeof(UINT
)*2+sizeof(ARGB
)*2, size
);
1376 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1378 expect(PaletteFlagsGrayScale
, palette
->Flags
);
1379 expect(2, palette
->Count
);
1381 expect(0xff000000, palette
->Entries
[0]);
1382 expect(0xffffffff, palette
->Entries
[1]);
1384 /* test getting/setting pixels */
1385 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
1387 expect(0xff000000, color
);
1389 stat
= GdipBitmapSetPixel(bitmap
, 0, 1, 0xffffffff);
1390 todo_wine
ok((stat
== Ok
) ||
1391 broken(stat
== InvalidParameter
) /* pre-win7 */, "stat=%.8x\n", stat
);
1395 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
1397 expect(0xffffffff, color
);
1400 GdipDisposeImage((GpImage
*)bitmap
);
1402 /* test initial palette on 4-bit bitmap */
1403 stat
= GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed
, NULL
, &bitmap
);
1406 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1408 expect(sizeof(UINT
)*2+sizeof(ARGB
)*16, size
);
1410 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1412 expect(0, palette
->Flags
);
1413 expect(16, palette
->Count
);
1415 check_halftone_palette(palette
);
1417 /* test getting/setting pixels */
1418 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
1420 expect(0xff000000, color
);
1422 stat
= GdipBitmapSetPixel(bitmap
, 0, 1, 0xffff00ff);
1423 todo_wine
ok((stat
== Ok
) ||
1424 broken(stat
== InvalidParameter
) /* pre-win7 */, "stat=%.8x\n", stat
);
1428 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
1430 expect(0xffff00ff, color
);
1433 GdipDisposeImage((GpImage
*)bitmap
);
1435 /* test initial palette on 8-bit bitmap */
1436 stat
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed
, NULL
, &bitmap
);
1439 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1441 expect(sizeof(UINT
)*2+sizeof(ARGB
)*256, size
);
1443 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1445 expect(PaletteFlagsHalftone
, palette
->Flags
);
1446 expect(256, palette
->Count
);
1448 check_halftone_palette(palette
);
1450 /* test getting/setting pixels */
1451 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
1453 expect(0xff000000, color
);
1455 stat
= GdipBitmapSetPixel(bitmap
, 0, 1, 0xffcccccc);
1456 todo_wine
ok((stat
== Ok
) ||
1457 broken(stat
== InvalidParameter
) /* pre-win7 */, "stat=%.8x\n", stat
);
1461 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
1463 expect(0xffcccccc, color
);
1466 /* test setting/getting a different palette */
1467 palette
->Entries
[1] = 0xffcccccc;
1469 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
1472 palette
->Entries
[1] = 0;
1474 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1476 expect(sizeof(UINT
)*2+sizeof(ARGB
)*256, size
);
1478 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1480 expect(PaletteFlagsHalftone
, palette
->Flags
);
1481 expect(256, palette
->Count
);
1482 expect(0xffcccccc, palette
->Entries
[1]);
1484 /* test count < 256 */
1485 palette
->Flags
= 12345;
1488 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
1491 palette
->Entries
[1] = 0;
1492 palette
->Entries
[3] = 0xdeadbeef;
1494 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1496 expect(sizeof(UINT
)*2+sizeof(ARGB
)*3, size
);
1498 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1500 expect(12345, palette
->Flags
);
1501 expect(3, palette
->Count
);
1502 expect(0xffcccccc, palette
->Entries
[1]);
1503 expect(0xdeadbeef, palette
->Entries
[3]);
1505 /* test count > 256 */
1506 palette
->Count
= 257;
1508 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
1509 ok(stat
== InvalidParameter
||
1510 broken(stat
== Ok
), /* Old gdiplus behavior */
1511 "Expected %.8x, got %.8x\n", InvalidParameter
, stat
);
1513 GdipDisposeImage((GpImage
*)bitmap
);
1516 static void test_colormatrix(void)
1519 ColorMatrix colormatrix
, graymatrix
;
1520 GpImageAttributes
*imageattr
;
1521 const ColorMatrix identity
= {{
1522 {1.0,0.0,0.0,0.0,0.0},
1523 {0.0,1.0,0.0,0.0,0.0},
1524 {0.0,0.0,1.0,0.0,0.0},
1525 {0.0,0.0,0.0,1.0,0.0},
1526 {0.0,0.0,0.0,0.0,1.0}}};
1527 const ColorMatrix double_red
= {{
1528 {2.0,0.0,0.0,0.0,0.0},
1529 {0.0,1.0,0.0,0.0,0.0},
1530 {0.0,0.0,1.0,0.0,0.0},
1531 {0.0,0.0,0.0,1.0,0.0},
1532 {0.0,0.0,0.0,0.0,1.0}}};
1533 GpBitmap
*bitmap1
, *bitmap2
;
1534 GpGraphics
*graphics
;
1537 colormatrix
= identity
;
1538 graymatrix
= identity
;
1540 stat
= GdipSetImageAttributesColorMatrix(NULL
, ColorAdjustTypeDefault
,
1541 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
1542 expect(InvalidParameter
, stat
);
1544 stat
= GdipCreateImageAttributes(&imageattr
);
1547 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1548 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsDefault
);
1551 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1552 TRUE
, NULL
, NULL
, ColorMatrixFlagsDefault
);
1553 expect(InvalidParameter
, stat
);
1555 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1556 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
1559 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1560 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsSkipGrays
);
1563 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1564 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsAltGray
);
1565 expect(InvalidParameter
, stat
);
1567 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1568 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsAltGray
);
1571 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1572 TRUE
, &colormatrix
, &graymatrix
, 3);
1573 expect(InvalidParameter
, stat
);
1575 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeCount
,
1576 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
1577 expect(InvalidParameter
, stat
);
1579 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeAny
,
1580 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
1581 expect(InvalidParameter
, stat
);
1583 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1584 FALSE
, NULL
, NULL
, ColorMatrixFlagsDefault
);
1587 /* Drawing a bitmap transforms the colors */
1588 colormatrix
= double_red
;
1589 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
1590 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsDefault
);
1593 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap1
);
1596 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap2
);
1599 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0xff40ffff);
1602 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
1605 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
1606 UnitPixel
, imageattr
, NULL
, NULL
);
1609 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
1611 todo_wine
expect(0xff80ffff, color
);
1613 GdipDeleteGraphics(graphics
);
1614 GdipDisposeImage((GpImage
*)bitmap1
);
1615 GdipDisposeImage((GpImage
*)bitmap2
);
1616 GdipDisposeImageAttributes(imageattr
);
1619 static void test_gamma(void)
1622 GpImageAttributes
*imageattr
;
1623 GpBitmap
*bitmap1
, *bitmap2
;
1624 GpGraphics
*graphics
;
1627 stat
= GdipSetImageAttributesGamma(NULL
, ColorAdjustTypeDefault
, TRUE
, 1.0);
1628 expect(InvalidParameter
, stat
);
1630 stat
= GdipCreateImageAttributes(&imageattr
);
1633 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1.0);
1636 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeAny
, TRUE
, 1.0);
1637 expect(InvalidParameter
, stat
);
1639 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, -1.0);
1640 expect(InvalidParameter
, stat
);
1642 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0.0);
1643 expect(InvalidParameter
, stat
);
1645 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0.5);
1648 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, FALSE
, 0.0);
1651 /* Drawing a bitmap transforms the colors */
1652 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 3.0);
1655 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap1
);
1658 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap2
);
1661 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0xff80ffff);
1664 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
1667 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
1668 UnitPixel
, imageattr
, NULL
, NULL
);
1671 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
1673 todo_wine
ok(color_match(0xff20ffff, color
, 1), "Expected ff20ffff, got %.8x\n", color
);
1675 GdipDeleteGraphics(graphics
);
1676 GdipDisposeImage((GpImage
*)bitmap1
);
1677 GdipDisposeImage((GpImage
*)bitmap2
);
1678 GdipDisposeImageAttributes(imageattr
);
1681 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
1682 static const unsigned char gifanimation
[72] = {
1683 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
1684 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
1685 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
1686 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
1687 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
1690 static void test_multiframegif(void)
1702 /* Test frame functions with an animated GIF */
1703 hglob
= GlobalAlloc (0, sizeof(gifanimation
));
1704 data
= GlobalLock (hglob
);
1705 memcpy(data
, gifanimation
, sizeof(gifanimation
));
1706 GlobalUnlock(hglob
);
1708 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
1709 ok(hres
== S_OK
, "Failed to create a stream\n");
1710 if(hres
!= S_OK
) return;
1712 stat
= GdipCreateBitmapFromStream(stream
, &bmp
);
1713 ok(stat
== Ok
, "Failed to create a Bitmap\n");
1715 IStream_Release(stream
);
1719 /* Bitmap starts at frame 0 */
1721 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
1723 expect(0xffffffff, color
);
1725 /* Check that we get correct metadata */
1726 stat
= GdipImageGetFrameDimensionsCount((GpImage
*)bmp
,&count
);
1730 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bmp
, &dimension
, 1);
1732 expect_guid(&FrameDimensionTime
, &dimension
, __LINE__
, FALSE
);
1735 stat
= GdipImageGetFrameCount((GpImage
*)bmp
, &dimension
, &count
);
1737 todo_wine
expect(2, count
);
1739 /* SelectActiveFrame overwrites our current data */
1740 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 1);
1744 GdipBitmapGetPixel(bmp
, 0, 0, &color
);
1746 todo_wine
expect(0xff000000, color
);
1748 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
1752 GdipBitmapGetPixel(bmp
, 0, 0, &color
);
1754 expect(0xffffffff, color
);
1756 /* Write over the image data */
1757 stat
= GdipBitmapSetPixel(bmp
, 0, 0, 0xff000000);
1760 /* Switching to the same frame does not overwrite our changes */
1761 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
1764 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
1766 expect(0xff000000, color
);
1768 /* But switching to another frame and back does */
1769 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 1);
1772 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
1775 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
1777 todo_wine
expect(0xffffffff, color
);
1779 GdipDisposeImage((GpImage
*)bmp
);
1780 IStream_Release(stream
);
1782 /* Test with a non-animated gif */
1783 hglob
= GlobalAlloc (0, sizeof(gifimage
));
1784 data
= GlobalLock (hglob
);
1785 memcpy(data
, gifimage
, sizeof(gifimage
));
1786 GlobalUnlock(hglob
);
1788 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
1789 ok(hres
== S_OK
, "Failed to create a stream\n");
1790 if(hres
!= S_OK
) return;
1792 stat
= GdipCreateBitmapFromStream(stream
, &bmp
);
1793 ok(stat
== Ok
, "Failed to create a Bitmap\n");
1795 IStream_Release(stream
);
1799 /* Check metadata */
1800 stat
= GdipImageGetFrameDimensionsCount((GpImage
*)bmp
,&count
);
1804 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bmp
, &dimension
, 1);
1806 expect_guid(&FrameDimensionTime
, &dimension
, __LINE__
, FALSE
);
1809 stat
= GdipImageGetFrameCount((GpImage
*)bmp
, &dimension
, &count
);
1813 GdipDisposeImage((GpImage
*)bmp
);
1814 IStream_Release(stream
);
1817 static void test_rotateflip(void)
1822 static const BYTE orig_bits
[24] = {
1823 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
1824 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
1828 memcpy(bits
, orig_bits
, sizeof(bits
));
1829 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
1832 stat
= GdipImageRotateFlip(bitmap
, Rotate90FlipNone
);
1835 stat
= GdipGetImageWidth(bitmap
, &width
);
1837 stat
= GdipGetImageHeight(bitmap
, &height
);
1842 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 0, &color
);
1844 expect(0xff00ffff, color
);
1846 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 1, 0, &color
);
1848 expect(0xffff0000, color
);
1850 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 2, &color
);
1852 expect(0xffffff00, color
);
1854 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 1, 2, &color
);
1856 expect(0xff0000ff, color
);
1860 expect(0xff, bits
[2]);
1862 GdipDisposeImage(bitmap
);
1864 memcpy(bits
, orig_bits
, sizeof(bits
));
1865 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
1868 stat
= GdipImageRotateFlip(bitmap
, RotateNoneFlipX
);
1871 stat
= GdipGetImageWidth(bitmap
, &width
);
1873 stat
= GdipGetImageHeight(bitmap
, &height
);
1878 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 0, &color
);
1880 expect(0xff0000ff, color
);
1882 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 0, &color
);
1884 expect(0xffff0000, color
);
1886 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 1, &color
);
1888 expect(0xffffff00, color
);
1890 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 1, &color
);
1892 expect(0xff00ffff, color
);
1896 expect(0xff, bits
[2]);
1898 GdipDisposeImage(bitmap
);
1900 memcpy(bits
, orig_bits
, sizeof(bits
));
1901 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
1904 stat
= GdipImageRotateFlip(bitmap
, RotateNoneFlipY
);
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
, 2, 0, &color
);
1920 expect(0xffffff00, color
);
1922 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 1, &color
);
1924 expect(0xffff0000, color
);
1926 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 1, &color
);
1928 expect(0xff0000ff, color
);
1932 expect(0xff, bits
[2]);
1934 GdipDisposeImage(bitmap
);
1937 static void test_remaptable(void)
1940 GpImageAttributes
*imageattr
;
1941 GpBitmap
*bitmap1
, *bitmap2
;
1942 GpGraphics
*graphics
;
1946 map
= GdipAlloc(sizeof(ColorMap
));
1948 map
->oldColor
.Argb
= 0xff00ff00;
1949 map
->newColor
.Argb
= 0xffff00ff;
1951 stat
= GdipSetImageAttributesRemapTable(NULL
, ColorAdjustTypeDefault
, TRUE
, 1, map
);
1952 expect(InvalidParameter
, stat
);
1954 stat
= GdipCreateImageAttributes(&imageattr
);
1957 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1, NULL
);
1958 expect(InvalidParameter
, stat
);
1960 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeCount
, TRUE
, 1, map
);
1961 expect(InvalidParameter
, stat
);
1963 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeAny
, TRUE
, 1, map
);
1964 expect(InvalidParameter
, stat
);
1966 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0, map
);
1967 expect(InvalidParameter
, stat
);
1969 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, FALSE
, 0, NULL
);
1972 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1, map
);
1975 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap1
);
1978 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap2
);
1981 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0xff00ff00);
1984 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
1987 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
1988 UnitPixel
, imageattr
, NULL
, NULL
);
1991 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
1993 ok(color_match(0xffff00ff, color
, 1), "Expected ffff00ff, got %.8x\n", color
);
1995 GdipDeleteGraphics(graphics
);
1996 GdipDisposeImage((GpImage
*)bitmap1
);
1997 GdipDisposeImage((GpImage
*)bitmap2
);
1998 GdipDisposeImageAttributes(imageattr
);
2004 struct GdiplusStartupInput gdiplusStartupInput
;
2005 ULONG_PTR gdiplusToken
;
2007 gdiplusStartupInput
.GdiplusVersion
= 1;
2008 gdiplusStartupInput
.DebugEventCallback
= NULL
;
2009 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
2010 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
2012 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
2016 test_GetImageDimension();
2017 test_GdipImageGetFrameDimensionsCount();
2018 test_LoadingImages();
2019 test_SavingImages();
2022 test_GdipCreateBitmapFromHBITMAP();
2023 test_GdipGetImageFlags();
2024 test_GdipCloneImage();
2027 test_getrawformat();
2029 test_createfromwmf();
2031 test_createhbitmap();
2036 test_multiframegif();
2040 GdiplusShutdown(gdiplusToken
);