2 * Unit test suite for images
4 * Copyright (C) 2007 Google (Evan Stade)
5 * Copyright (C) 2012 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #define WIN32_NO_STATUS
31 #define COM_NO_WINDOWS_H
33 //#include "windows.h"
34 #include <wine/test.h>
40 #define expect(expected, got) ok((got) == (expected), "Expected %d, got %d\n", (UINT)(expected), (UINT)(got))
41 #define expectf(expected, got) ok(fabs((expected) - (got)) < 0.0001, "Expected %f, got %f\n", (expected), (got))
43 static BOOL
color_match(ARGB c1
, ARGB c2
, BYTE max_diff
)
45 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
47 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
49 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
51 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
55 static void expect_guid(REFGUID expected
, REFGUID got
, int line
, BOOL todo
)
61 StringFromGUID2(got
, bufferW
, sizeof(bufferW
)/sizeof(bufferW
[0]));
62 WideCharToMultiByte(CP_ACP
, 0, bufferW
, sizeof(bufferW
)/sizeof(bufferW
[0]), buffer
, sizeof(buffer
), NULL
, NULL
);
63 StringFromGUID2(expected
, bufferW
, sizeof(bufferW
)/sizeof(bufferW
[0]));
64 WideCharToMultiByte(CP_ACP
, 0, bufferW
, sizeof(bufferW
)/sizeof(bufferW
[0]), buffer2
, sizeof(buffer2
), NULL
, NULL
);
66 todo_wine
ok_(__FILE__
, line
)(IsEqualGUID(expected
, got
), "Expected %s, got %s\n", buffer2
, buffer
);
68 ok_(__FILE__
, line
)(IsEqualGUID(expected
, got
), "Expected %s, got %s\n", buffer2
, buffer
);
71 static void expect_rawformat(REFGUID expected
, GpImage
*img
, int line
, BOOL todo
)
76 stat
= GdipGetImageRawFormat(img
, &raw
);
77 ok_(__FILE__
, line
)(stat
== Ok
, "GdipGetImageRawFormat failed with %d\n", stat
);
78 if(stat
!= Ok
) return;
79 expect_guid(expected
, &raw
, line
, todo
);
82 static void test_bufferrawformat(void* buff
, int size
, REFGUID expected
, int line
, BOOL todo
)
91 hglob
= GlobalAlloc (0, size
);
92 data
= GlobalLock (hglob
);
93 memcpy(data
, buff
, size
);
94 GlobalUnlock(hglob
); data
= NULL
;
96 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
97 ok_(__FILE__
, line
)(hres
== S_OK
, "Failed to create a stream\n");
98 if(hres
!= S_OK
) return;
100 stat
= GdipLoadImageFromStream(stream
, &img
);
101 ok_(__FILE__
, line
)(stat
== Ok
, "Failed to create a Bitmap\n");
103 IStream_Release(stream
);
107 expect_rawformat(expected
, img
, line
, todo
);
109 GdipDisposeImage(img
);
110 IStream_Release(stream
);
113 static void test_Scan0(void)
120 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB
, NULL
, &bm
);
122 ok(NULL
!= bm
, "Expected bitmap to be initialized\n");
124 GdipDisposeImage((GpImage
*)bm
);
126 bm
= (GpBitmap
*)0xdeadbeef;
127 stat
= GdipCreateBitmapFromScan0(10, -10, 10, PixelFormat24bppRGB
, NULL
, &bm
);
128 expect(InvalidParameter
, stat
);
129 ok( !bm
, "expected null bitmap\n" );
131 bm
= (GpBitmap
*)0xdeadbeef;
132 stat
= GdipCreateBitmapFromScan0(-10, 10, 10, PixelFormat24bppRGB
, NULL
, &bm
);
133 expect(InvalidParameter
, stat
);
134 ok( !bm
, "expected null bitmap\n" );
136 bm
= (GpBitmap
*)0xdeadbeef;
137 stat
= GdipCreateBitmapFromScan0(10, 0, 10, PixelFormat24bppRGB
, NULL
, &bm
);
138 expect(InvalidParameter
, stat
);
139 ok( !bm
, "expected null bitmap\n" );
142 stat
= GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB
, buff
, &bm
);
144 ok(NULL
!= bm
, "Expected bitmap to be initialized\n");
146 GdipDisposeImage((GpImage
*)bm
);
148 bm
= (GpBitmap
*) 0xdeadbeef;
149 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB
, buff
, &bm
);
150 expect(InvalidParameter
, stat
);
151 ok( !bm
, "expected null bitmap\n" );
153 bm
= (GpBitmap
*)0xdeadbeef;
154 stat
= GdipCreateBitmapFromScan0(10, 10, 0, PixelFormat24bppRGB
, buff
, &bm
);
155 expect(InvalidParameter
, stat
);
156 ok( bm
== (GpBitmap
*)0xdeadbeef, "expected deadbeef bitmap\n" );
159 stat
= GdipCreateBitmapFromScan0(10, 10, -8, PixelFormat24bppRGB
, buff
, &bm
);
161 ok(NULL
!= bm
, "Expected bitmap to be initialized\n");
163 GdipDisposeImage((GpImage
*)bm
);
165 bm
= (GpBitmap
*)0xdeadbeef;
166 stat
= GdipCreateBitmapFromScan0(10, 10, -10, PixelFormat24bppRGB
, buff
, &bm
);
167 expect(InvalidParameter
, stat
);
168 ok( !bm
, "expected null bitmap\n" );
171 static void test_FromGdiDib(void)
176 BYTE rbmi
[sizeof(BITMAPINFOHEADER
)+256*sizeof(RGBQUAD
)];
177 BITMAPINFO
*bmi
= (BITMAPINFO
*)rbmi
;
182 memset(rbmi
, 0, sizeof(rbmi
));
184 bmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
185 bmi
->bmiHeader
.biWidth
= 10;
186 bmi
->bmiHeader
.biHeight
= 10;
187 bmi
->bmiHeader
.biPlanes
= 1;
188 bmi
->bmiHeader
.biBitCount
= 32;
189 bmi
->bmiHeader
.biCompression
= BI_RGB
;
191 stat
= GdipCreateBitmapFromGdiDib(NULL
, buff
, &bm
);
192 expect(InvalidParameter
, stat
);
194 stat
= GdipCreateBitmapFromGdiDib(bmi
, NULL
, &bm
);
195 expect(InvalidParameter
, stat
);
197 stat
= GdipCreateBitmapFromGdiDib(bmi
, buff
, NULL
);
198 expect(InvalidParameter
, stat
);
200 stat
= GdipCreateBitmapFromGdiDib(bmi
, buff
, &bm
);
202 ok(NULL
!= bm
, "Expected bitmap to be initialized\n");
205 stat
= GdipGetImagePixelFormat((GpImage
*)bm
, &format
);
207 expect(PixelFormat32bppRGB
, format
);
209 GdipDisposeImage((GpImage
*)bm
);
212 bmi
->bmiHeader
.biBitCount
= 24;
213 stat
= GdipCreateBitmapFromGdiDib(bmi
, buff
, &bm
);
215 ok(NULL
!= bm
, "Expected bitmap to be initialized\n");
218 stat
= GdipGetImagePixelFormat((GpImage
*)bm
, &format
);
220 expect(PixelFormat24bppRGB
, format
);
222 GdipDisposeImage((GpImage
*)bm
);
225 bmi
->bmiHeader
.biBitCount
= 16;
226 stat
= GdipCreateBitmapFromGdiDib(bmi
, buff
, &bm
);
228 ok(NULL
!= bm
, "Expected bitmap to be initialized\n");
231 stat
= GdipGetImagePixelFormat((GpImage
*)bm
, &format
);
233 expect(PixelFormat16bppRGB555
, format
);
235 GdipDisposeImage((GpImage
*)bm
);
238 bmi
->bmiHeader
.biBitCount
= 8;
239 stat
= GdipCreateBitmapFromGdiDib(bmi
, buff
, &bm
);
241 ok(NULL
!= bm
, "Expected bitmap to be initialized\n");
244 stat
= GdipGetImagePixelFormat((GpImage
*)bm
, &format
);
246 expect(PixelFormat8bppIndexed
, format
);
248 GdipDisposeImage((GpImage
*)bm
);
251 bmi
->bmiHeader
.biBitCount
= 4;
252 stat
= GdipCreateBitmapFromGdiDib(bmi
, buff
, &bm
);
254 ok(NULL
!= bm
, "Expected bitmap to be initialized\n");
257 stat
= GdipGetImagePixelFormat((GpImage
*)bm
, &format
);
259 expect(PixelFormat4bppIndexed
, format
);
261 GdipDisposeImage((GpImage
*)bm
);
264 bmi
->bmiHeader
.biBitCount
= 1;
265 stat
= GdipCreateBitmapFromGdiDib(bmi
, buff
, &bm
);
267 ok(NULL
!= bm
, "Expected bitmap to be initialized\n");
270 stat
= GdipGetImagePixelFormat((GpImage
*)bm
, &format
);
272 expect(PixelFormat1bppIndexed
, format
);
274 GdipDisposeImage((GpImage
*)bm
);
277 bmi
->bmiHeader
.biBitCount
= 0;
278 stat
= GdipCreateBitmapFromGdiDib(bmi
, buff
, &bm
);
279 expect(InvalidParameter
, stat
);
282 static void test_GetImageDimension(void)
286 const REAL WIDTH
= 10.0, HEIGHT
= 20.0;
289 bm
= (GpBitmap
*)0xdeadbeef;
290 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
,NULL
, &bm
);
292 ok((GpBitmap
*)0xdeadbeef != bm
, "Expected bitmap to not be 0xdeadbeef\n");
293 ok(NULL
!= bm
, "Expected bitmap to not be NULL\n");
295 stat
= GdipGetImageDimension(NULL
,&w
,&h
);
296 expect(InvalidParameter
, stat
);
298 stat
= GdipGetImageDimension((GpImage
*)bm
,NULL
,&h
);
299 expect(InvalidParameter
, stat
);
301 stat
= GdipGetImageDimension((GpImage
*)bm
,&w
,NULL
);
302 expect(InvalidParameter
, stat
);
306 stat
= GdipGetImageDimension((GpImage
*)bm
,&w
,&h
);
310 GdipDisposeImage((GpImage
*)bm
);
313 static void test_GdipImageGetFrameDimensionsCount(void)
317 const REAL WIDTH
= 10.0, HEIGHT
= 20.0;
319 GUID dimension
= {0};
323 bm
= (GpBitmap
*)0xdeadbeef;
324 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
,NULL
, &bm
);
326 ok((GpBitmap
*)0xdeadbeef != bm
, "Expected bitmap to not be 0xdeadbeef\n");
327 ok(NULL
!= bm
, "Expected bitmap to not be NULL\n");
329 stat
= GdipImageGetFrameDimensionsCount(NULL
,&w
);
330 expect(InvalidParameter
, stat
);
332 stat
= GdipImageGetFrameDimensionsCount((GpImage
*)bm
,NULL
);
333 expect(InvalidParameter
, stat
);
336 stat
= GdipImageGetFrameDimensionsCount((GpImage
*)bm
,&w
);
340 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bm
, &dimension
, 1);
342 expect_guid(&FrameDimensionPage
, &dimension
, __LINE__
, FALSE
);
344 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bm
, &dimension
, 2);
345 expect(InvalidParameter
, stat
);
347 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bm
, &dimension
, 0);
348 expect(InvalidParameter
, stat
);
350 stat
= GdipImageGetFrameCount(NULL
, &dimension
, &count
);
351 expect(InvalidParameter
, stat
);
353 /* WinXP crashes on this test */
356 stat
= GdipImageGetFrameCount((GpImage
*)bm
, &dimension
, NULL
);
357 expect(InvalidParameter
, stat
);
360 stat
= GdipImageGetFrameCount((GpImage
*)bm
, NULL
, &count
);
364 stat
= GdipImageGetFrameCount((GpImage
*)bm
, &dimension
, &count
);
368 GdipBitmapSetPixel(bm
, 0, 0, 0xffffffff);
370 stat
= GdipImageSelectActiveFrame((GpImage
*)bm
, &dimension
, 0);
373 /* SelectActiveFrame has no effect on image data of memory bitmaps */
375 GdipBitmapGetPixel(bm
, 0, 0, &color
);
376 expect(0xffffffff, color
);
378 GdipDisposeImage((GpImage
*)bm
);
381 static void test_LoadingImages(void)
385 stat
= GdipCreateBitmapFromFile(0, 0);
386 expect(InvalidParameter
, stat
);
388 stat
= GdipCreateBitmapFromFile(0, (GpBitmap
**)0xdeadbeef);
389 expect(InvalidParameter
, stat
);
391 stat
= GdipLoadImageFromFile(0, 0);
392 expect(InvalidParameter
, stat
);
394 stat
= GdipLoadImageFromFile(0, (GpImage
**)0xdeadbeef);
395 expect(InvalidParameter
, stat
);
397 stat
= GdipLoadImageFromFileICM(0, 0);
398 expect(InvalidParameter
, stat
);
400 stat
= GdipLoadImageFromFileICM(0, (GpImage
**)0xdeadbeef);
401 expect(InvalidParameter
, stat
);
404 static void test_SavingImages(void)
410 const REAL WIDTH
= 10.0, HEIGHT
= 20.0;
412 ImageCodecInfo
*codecs
;
413 static const CHAR filenameA
[] = "a.bmp";
414 static const WCHAR filename
[] = { 'a','.','b','m','p',0 };
418 stat
= GdipSaveImageToFile(0, 0, 0, 0);
419 expect(InvalidParameter
, stat
);
422 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
428 stat
= GdipSaveImageToFile((GpImage
*)bm
, 0, 0, 0);
429 expect(InvalidParameter
, stat
);
431 stat
= GdipSaveImageToFile((GpImage
*)bm
, filename
, 0, 0);
432 expect(InvalidParameter
, stat
);
434 /* encoder tests should succeed -- already tested */
435 stat
= GdipGetImageEncodersSize(&n
, &s
);
436 if (stat
!= Ok
|| n
== 0) goto cleanup
;
438 codecs
= GdipAlloc(s
);
439 if (!codecs
) goto cleanup
;
441 stat
= GdipGetImageEncoders(n
, s
, codecs
);
442 if (stat
!= Ok
) goto cleanup
;
444 stat
= GdipSaveImageToFile((GpImage
*)bm
, filename
, &codecs
[0].Clsid
, 0);
447 GdipDisposeImage((GpImage
*)bm
);
450 /* re-load and check image stats */
451 stat
= GdipLoadImageFromFile(filename
, (GpImage
**)&bm
);
453 if (stat
!= Ok
) goto cleanup
;
455 stat
= GdipGetImageDimension((GpImage
*)bm
, &w
, &h
);
456 if (stat
!= Ok
) goto cleanup
;
464 GdipDisposeImage((GpImage
*)bm
);
465 ok(DeleteFileA(filenameA
), "Delete failed.\n");
468 static void test_encoders(void)
473 ImageCodecInfo
*codecs
;
477 static const CHAR bmp_format
[] = "BMP";
479 stat
= GdipGetImageEncodersSize(&n
, &s
);
482 codecs
= GdipAlloc(s
);
486 stat
= GdipGetImageEncoders(n
, s
, NULL
);
487 expect(GenericError
, stat
);
489 stat
= GdipGetImageEncoders(0, s
, codecs
);
490 expect(GenericError
, stat
);
492 stat
= GdipGetImageEncoders(n
, s
-1, codecs
);
493 expect(GenericError
, stat
);
495 stat
= GdipGetImageEncoders(n
, s
+1, codecs
);
496 expect(GenericError
, stat
);
498 stat
= GdipGetImageEncoders(n
, s
, codecs
);
502 for (i
= 0; i
< n
; i
++)
506 WideCharToMultiByte(CP_ACP
, 0, codecs
[i
].FormatDescription
, -1,
509 if (CompareStringA(LOCALE_SYSTEM_DEFAULT
, 0,
511 bmp_format
, -1) == CSTR_EQUAL
) {
517 ok(FALSE
, "No BMP codec found.\n");
522 static void test_LockBits(void)
528 const INT WIDTH
= 10, HEIGHT
= 20;
533 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
541 stat
= GdipBitmapSetPixel(bm
, 2, 3, 0xffc30000);
544 stat
= GdipBitmapSetPixel(bm
, 2, 8, 0xff480000);
548 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
552 expect(0xc3, ((BYTE
*)bd
.Scan0
)[2]);
553 expect(0x48, ((BYTE
*)bd
.Scan0
)[2 + bd
.Stride
* 5]);
555 ((char*)bd
.Scan0
)[2] = 0xff;
557 stat
= GdipBitmapUnlockBits(bm
, &bd
);
561 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
563 expect(0xffff0000, color
);
565 stat
= GdipBitmapSetPixel(bm
, 2, 3, 0xffc30000);
568 /* read-only, with NULL rect -> whole bitmap lock */
569 stat
= GdipBitmapLockBits(bm
, NULL
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
571 expect(bd
.Width
, WIDTH
);
572 expect(bd
.Height
, HEIGHT
);
575 ((char*)bd
.Scan0
)[2 + 2*3 + 3*bd
.Stride
] = 0xff;
577 stat
= GdipBitmapUnlockBits(bm
, &bd
);
581 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
583 expect(0xffff0000, color
);
585 /* read-only, consecutive */
586 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
590 stat
= GdipBitmapUnlockBits(bm
, &bd
);
594 stat
= GdipDisposeImage((GpImage
*)bm
);
596 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
600 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
602 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
603 expect(WrongState
, stat
);
605 stat
= GdipBitmapUnlockBits(bm
, &bd
);
608 stat
= GdipDisposeImage((GpImage
*)bm
);
610 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
613 stat
= GdipBitmapSetPixel(bm
, 2, 3, 0xffff0000);
616 stat
= GdipBitmapSetPixel(bm
, 2, 8, 0xffc30000);
619 /* write, no conversion */
620 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
, PixelFormat24bppRGB
, &bd
);
624 /* all bits are readable, inside the rect or not */
625 expect(0xff, ((BYTE
*)bd
.Scan0
)[2]);
626 expect(0xc3, ((BYTE
*)bd
.Scan0
)[2 + bd
.Stride
* 5]);
628 stat
= GdipBitmapUnlockBits(bm
, &bd
);
632 /* read, conversion */
633 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat32bppARGB
, &bd
);
637 expect(0xff, ((BYTE
*)bd
.Scan0
)[2]);
639 /* Areas outside the rectangle appear to be uninitialized */
640 ok(0xc3 != ((BYTE
*)bd
.Scan0
)[2 + bd
.Stride
* 5], "original image bits are readable\n");
642 ((BYTE
*)bd
.Scan0
)[2] = 0xc3;
644 stat
= GdipBitmapUnlockBits(bm
, &bd
);
648 /* writes do not work in read mode if there was a conversion */
649 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
651 expect(0xffff0000, color
);
653 /* read/write, conversion */
654 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
|ImageLockModeWrite
, PixelFormat32bppARGB
, &bd
);
658 expect(0xff, ((BYTE
*)bd
.Scan0
)[2]);
659 ((BYTE
*)bd
.Scan0
)[1] = 0x88;
661 /* Areas outside the rectangle appear to be uninitialized */
662 ok(0xc3 != ((BYTE
*)bd
.Scan0
)[2 + bd
.Stride
* 5], "original image bits are readable\n");
664 stat
= GdipBitmapUnlockBits(bm
, &bd
);
668 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
670 expect(0xffff8800, color
);
672 /* write, conversion */
673 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
, PixelFormat32bppARGB
, &bd
);
679 /* This is completely uninitialized. */
680 ok(0xff != ((BYTE
*)bd
.Scan0
)[2], "original image bits are readable\n");
681 ok(0xc3 != ((BYTE
*)bd
.Scan0
)[2 + bd
.Stride
* 5], "original image bits are readable\n");
684 /* Initialize the buffer so the unlock doesn't access undefined memory */
686 memset(((BYTE
*)bd
.Scan0
) + bd
.Stride
* y
, 0, 12);
688 ((BYTE
*)bd
.Scan0
)[0] = 0x12;
689 ((BYTE
*)bd
.Scan0
)[1] = 0x34;
690 ((BYTE
*)bd
.Scan0
)[2] = 0x56;
692 stat
= GdipBitmapUnlockBits(bm
, &bd
);
696 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
698 expect(0xff563412, color
);
700 stat
= GdipBitmapGetPixel(bm
, 2, 8, &color
);
702 expect(0xffc30000, color
);
704 stat
= GdipDisposeImage((GpImage
*)bm
);
706 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
709 /* write, no modification */
710 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
, PixelFormat24bppRGB
, &bd
);
714 stat
= GdipBitmapUnlockBits(bm
, &bd
);
718 /* write, consecutive */
719 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
, PixelFormat24bppRGB
, &bd
);
723 stat
= GdipBitmapUnlockBits(bm
, &bd
);
727 stat
= GdipDisposeImage((GpImage
*)bm
);
729 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
733 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
, PixelFormat24bppRGB
, &bd
);
738 ((char*)bd
.Scan0
)[2] = 0xff;
740 stat
= GdipBitmapUnlockBits(bm
, &bd
);
744 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
746 expect(0xffff0000, color
);
748 stat
= GdipDisposeImage((GpImage
*)bm
);
752 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
754 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
756 stat
= GdipDisposeImage((GpImage
*)bm
);
760 static void test_LockBits_UserBuf(void)
766 const INT WIDTH
= 10, HEIGHT
= 20;
771 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat32bppARGB
, NULL
, &bm
);
774 memset(bits
, 0xaa, sizeof(bits
));
783 bd
.Stride
= WIDTH
* 4;
784 bd
.PixelFormat
= PixelFormat32bppARGB
;
785 bd
.Scan0
= &bits
[2+3*WIDTH
];
786 bd
.Reserved
= 0xaaaaaaaa;
789 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
|ImageLockModeUserInputBuf
, PixelFormat32bppARGB
, &bd
);
792 expect(0xaaaaaaaa, bits
[0]);
793 expect(0, bits
[2+3*WIDTH
]);
795 bits
[2+3*WIDTH
] = 0xdeadbeef;
798 stat
= GdipBitmapUnlockBits(bm
, &bd
);
802 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
807 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
|ImageLockModeUserInputBuf
, PixelFormat32bppARGB
, &bd
);
810 expect(0xdeadbeef, bits
[2+3*WIDTH
]);
811 bits
[2+3*WIDTH
] = 0x12345678;
814 stat
= GdipBitmapUnlockBits(bm
, &bd
);
818 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
820 expect(0x12345678, color
);
825 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
|ImageLockModeWrite
|ImageLockModeUserInputBuf
, PixelFormat32bppARGB
, &bd
);
828 expect(0x12345678, bits
[2+3*WIDTH
]);
829 bits
[2+3*WIDTH
] = 0xdeadbeef;
832 stat
= GdipBitmapUnlockBits(bm
, &bd
);
836 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
838 expect(0xdeadbeef, color
);
840 stat
= GdipDisposeImage((GpImage
*)bm
);
844 struct BITMAPINFOWITHBITFIELDS
846 BITMAPINFOHEADER bmiHeader
;
850 union BITMAPINFOUNION
853 struct BITMAPINFOWITHBITFIELDS bf
;
856 static void test_GdipCreateBitmapFromHBITMAP(void)
858 GpBitmap
* gpbm
= NULL
;
860 HPALETTE hpal
= NULL
;
863 LOGPALETTE
* LogPal
= NULL
;
865 const REAL WIDTH1
= 5;
866 const REAL HEIGHT1
= 15;
867 const REAL WIDTH2
= 10;
868 const REAL HEIGHT2
= 20;
870 union BITMAPINFOUNION bmi
;
874 stat
= GdipCreateBitmapFromHBITMAP(NULL
, NULL
, NULL
);
875 expect(InvalidParameter
, stat
);
877 hbm
= CreateBitmap(WIDTH1
, HEIGHT1
, 1, 1, NULL
);
878 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, NULL
);
879 expect(InvalidParameter
, stat
);
881 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
883 expect(Ok
, GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
));
884 expectf(WIDTH1
, width
);
885 expectf(HEIGHT1
, height
);
887 GdipDisposeImage((GpImage
*)gpbm
);
890 memset(buff
, 0, sizeof(buff
));
891 hbm
= CreateBitmap(WIDTH2
, HEIGHT2
, 1, 1, &buff
);
892 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
895 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)gpbm
, __LINE__
, FALSE
);
897 expect(Ok
, GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
));
898 expectf(WIDTH2
, width
);
899 expectf(HEIGHT2
, height
);
901 GdipDisposeImage((GpImage
*)gpbm
);
904 hdc
= CreateCompatibleDC(0);
905 ok(hdc
!= NULL
, "CreateCompatibleDC failed\n");
906 bmi
.bi
.bmiHeader
.biSize
= sizeof(bmi
.bi
.bmiHeader
);
907 bmi
.bi
.bmiHeader
.biHeight
= HEIGHT1
;
908 bmi
.bi
.bmiHeader
.biWidth
= WIDTH1
;
909 bmi
.bi
.bmiHeader
.biBitCount
= 24;
910 bmi
.bi
.bmiHeader
.biPlanes
= 1;
911 bmi
.bi
.bmiHeader
.biCompression
= BI_RGB
;
912 bmi
.bi
.bmiHeader
.biClrUsed
= 0;
914 hbm
= CreateDIBSection(hdc
, &bmi
.bi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
915 ok(hbm
!= NULL
, "CreateDIBSection failed\n");
919 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
921 expect(Ok
, GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
));
922 expectf(WIDTH1
, width
);
923 expectf(HEIGHT1
, height
);
926 /* test whether writing to the bitmap affects the original */
927 stat
= GdipBitmapSetPixel(gpbm
, 0, 0, 0xffffffff);
932 GdipDisposeImage((GpImage
*)gpbm
);
935 LogPal
= GdipAlloc(sizeof(LOGPALETTE
));
936 ok(LogPal
!= NULL
, "unable to allocate LOGPALETTE\n");
937 LogPal
->palVersion
= 0x300;
938 LogPal
->palNumEntries
= 1;
939 hpal
= CreatePalette(LogPal
);
940 ok(hpal
!= NULL
, "CreatePalette failed\n");
943 stat
= GdipCreateBitmapFromHBITMAP(hbm
, hpal
, &gpbm
);
947 GdipDisposeImage((GpImage
*)gpbm
);
952 /* 16-bit 555 dib, rgb */
953 bmi
.bi
.bmiHeader
.biBitCount
= 16;
954 bmi
.bi
.bmiHeader
.biCompression
= BI_RGB
;
956 hbm
= CreateDIBSection(hdc
, &bmi
.bi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
957 ok(hbm
!= NULL
, "CreateDIBSection failed\n");
961 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
966 stat
= GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
);
968 expectf(WIDTH1
, width
);
969 expectf(HEIGHT1
, height
);
971 stat
= GdipGetImagePixelFormat((GpImage
*) gpbm
, &format
);
973 expect(PixelFormat16bppRGB555
, format
);
975 GdipDisposeImage((GpImage
*)gpbm
);
979 /* 16-bit 555 dib, with bitfields */
980 bmi
.bi
.bmiHeader
.biSize
= sizeof(bmi
);
981 bmi
.bi
.bmiHeader
.biCompression
= BI_BITFIELDS
;
982 bmi
.bf
.masks
[0] = 0x7c00;
983 bmi
.bf
.masks
[1] = 0x3e0;
984 bmi
.bf
.masks
[2] = 0x1f;
986 hbm
= CreateDIBSection(hdc
, &bmi
.bi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
987 ok(hbm
!= NULL
, "CreateDIBSection failed\n");
991 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
996 stat
= GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
);
998 expectf(WIDTH1
, width
);
999 expectf(HEIGHT1
, height
);
1001 stat
= GdipGetImagePixelFormat((GpImage
*) gpbm
, &format
);
1003 expect(PixelFormat16bppRGB555
, format
);
1005 GdipDisposeImage((GpImage
*)gpbm
);
1009 /* 16-bit 565 dib, with bitfields */
1010 bmi
.bf
.masks
[0] = 0xf800;
1011 bmi
.bf
.masks
[1] = 0x7e0;
1012 bmi
.bf
.masks
[2] = 0x1f;
1014 hbm
= CreateDIBSection(hdc
, &bmi
.bi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1015 ok(hbm
!= NULL
, "CreateDIBSection failed\n");
1019 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
1024 stat
= GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
);
1026 expectf(WIDTH1
, width
);
1027 expectf(HEIGHT1
, height
);
1029 stat
= GdipGetImagePixelFormat((GpImage
*) gpbm
, &format
);
1031 expect(PixelFormat16bppRGB565
, format
);
1033 GdipDisposeImage((GpImage
*)gpbm
);
1040 static void test_GdipGetImageFlags(void)
1046 img
= (GpImage
*)0xdeadbeef;
1048 stat
= GdipGetImageFlags(NULL
, NULL
);
1049 expect(InvalidParameter
, stat
);
1051 stat
= GdipGetImageFlags(NULL
, &flags
);
1052 expect(InvalidParameter
, stat
);
1054 stat
= GdipGetImageFlags(img
, NULL
);
1055 expect(InvalidParameter
, stat
);
1057 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed
, NULL
, (GpBitmap
**)&img
);
1059 stat
= GdipGetImageFlags(img
, &flags
);
1061 expect(ImageFlagsHasAlpha
, flags
);
1062 GdipDisposeImage(img
);
1064 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed
, NULL
, (GpBitmap
**)&img
);
1066 stat
= GdipGetImageFlags(img
, &flags
);
1068 expect(ImageFlagsHasAlpha
, flags
);
1069 GdipDisposeImage(img
);
1071 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed
, NULL
, (GpBitmap
**)&img
);
1073 stat
= GdipGetImageFlags(img
, &flags
);
1075 expect(ImageFlagsHasAlpha
, flags
);
1076 GdipDisposeImage(img
);
1078 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale
, NULL
, (GpBitmap
**)&img
);
1080 stat
= GdipGetImageFlags(img
, &flags
);
1082 expect(ImageFlagsNone
, flags
);
1083 GdipDisposeImage(img
);
1085 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555
, NULL
, (GpBitmap
**)&img
);
1087 stat
= GdipGetImageFlags(img
, &flags
);
1089 expect(ImageFlagsNone
, flags
);
1090 GdipDisposeImage(img
);
1092 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565
, NULL
, (GpBitmap
**)&img
);
1094 stat
= GdipGetImageFlags(img
, &flags
);
1096 expect(ImageFlagsNone
, flags
);
1097 GdipDisposeImage(img
);
1099 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppARGB1555
, NULL
, (GpBitmap
**)&img
);
1101 stat
= GdipGetImageFlags(img
, &flags
);
1103 expect(ImageFlagsHasAlpha
, flags
);
1104 GdipDisposeImage(img
);
1106 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB
, NULL
, (GpBitmap
**)&img
);
1108 stat
= GdipGetImageFlags(img
, &flags
);
1110 expect(ImageFlagsNone
, flags
);
1111 GdipDisposeImage(img
);
1113 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB
, NULL
, (GpBitmap
**)&img
);
1115 stat
= GdipGetImageFlags(img
, &flags
);
1117 expect(ImageFlagsNone
, flags
);
1118 GdipDisposeImage(img
);
1120 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB
, NULL
, (GpBitmap
**)&img
);
1122 stat
= GdipGetImageFlags(img
, &flags
);
1124 expect(ImageFlagsHasAlpha
, flags
);
1125 GdipDisposeImage(img
);
1127 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppPARGB
, NULL
, (GpBitmap
**)&img
);
1129 stat
= GdipGetImageFlags(img
, &flags
);
1131 expect(ImageFlagsHasAlpha
, flags
);
1132 GdipDisposeImage(img
);
1134 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB
, NULL
, (GpBitmap
**)&img
);
1138 stat
= GdipGetImageFlags(img
, &flags
);
1140 expect(ImageFlagsNone
, flags
);
1141 GdipDisposeImage(img
);
1144 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB
, NULL
, (GpBitmap
**)&img
);
1149 stat
= GdipGetImageFlags(img
, &flags
);
1151 expect(ImageFlagsHasAlpha
, flags
);
1152 GdipDisposeImage(img
);
1155 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB
, NULL
, (GpBitmap
**)&img
);
1160 stat
= GdipGetImageFlags(img
, &flags
);
1162 expect(ImageFlagsHasAlpha
, flags
);
1163 GdipDisposeImage(img
);
1167 static void test_GdipCloneImage(void)
1173 GpImage
*image_src
, *image_dest
= NULL
;
1174 const INT WIDTH
= 10, HEIGHT
= 20;
1176 /* Create an image, clone it, delete the original, make sure the copy works */
1177 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
1179 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)bm
, __LINE__
, FALSE
);
1181 image_src
= ((GpImage
*)bm
);
1182 stat
= GdipCloneImage(image_src
, &image_dest
);
1184 expect_rawformat(&ImageFormatMemoryBMP
, image_dest
, __LINE__
, FALSE
);
1186 stat
= GdipDisposeImage((GpImage
*)bm
);
1188 stat
= GdipGetImageBounds(image_dest
, &rectF
, &unit
);
1191 /* Treat FP values carefully */
1192 expectf((REAL
)WIDTH
, rectF
.Width
);
1193 expectf((REAL
)HEIGHT
, rectF
.Height
);
1195 stat
= GdipDisposeImage(image_dest
);
1199 static void test_testcontrol(void)
1205 stat
= GdipTestControl(TestControlGetBuildNumber
, ¶m
);
1207 ok(param
!= 0, "Build number expected, got %u\n", param
);
1210 static void test_fromhicon(void)
1212 static const BYTE bmp_bits
[1024];
1213 HBITMAP hbmMask
, hbmColor
;
1217 GpBitmap
*bitmap
= NULL
;
1223 stat
= GdipCreateBitmapFromHICON(NULL
, NULL
);
1224 expect(InvalidParameter
, stat
);
1225 stat
= GdipCreateBitmapFromHICON(NULL
, &bitmap
);
1226 expect(InvalidParameter
, stat
);
1228 /* color icon 1 bit */
1229 hbmMask
= CreateBitmap(16, 16, 1, 1, bmp_bits
);
1230 ok(hbmMask
!= 0, "CreateBitmap failed\n");
1231 hbmColor
= CreateBitmap(16, 16, 1, 1, bmp_bits
);
1232 ok(hbmColor
!= 0, "CreateBitmap failed\n");
1236 info
.hbmMask
= hbmMask
;
1237 info
.hbmColor
= hbmColor
;
1238 hIcon
= CreateIconIndirect(&info
);
1239 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
1240 DeleteObject(hbmMask
);
1241 DeleteObject(hbmColor
);
1243 stat
= GdipCreateBitmapFromHICON(hIcon
, &bitmap
);
1245 broken(stat
== InvalidParameter
), /* Win98 */
1246 "Expected Ok, got %.8x\n", stat
);
1248 /* check attributes */
1249 stat
= GdipGetImageHeight((GpImage
*)bitmap
, &dim
);
1252 stat
= GdipGetImageWidth((GpImage
*)bitmap
, &dim
);
1255 stat
= GdipGetImageType((GpImage
*)bitmap
, &type
);
1257 expect(ImageTypeBitmap
, type
);
1258 stat
= GdipGetImagePixelFormat((GpImage
*)bitmap
, &format
);
1260 expect(PixelFormat32bppARGB
, format
);
1262 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)bitmap
, __LINE__
, FALSE
);
1263 GdipDisposeImage((GpImage
*)bitmap
);
1267 /* color icon 8 bpp */
1268 hbmMask
= CreateBitmap(16, 16, 1, 8, bmp_bits
);
1269 ok(hbmMask
!= 0, "CreateBitmap failed\n");
1270 hbmColor
= CreateBitmap(16, 16, 1, 8, bmp_bits
);
1271 ok(hbmColor
!= 0, "CreateBitmap failed\n");
1275 info
.hbmMask
= hbmMask
;
1276 info
.hbmColor
= hbmColor
;
1277 hIcon
= CreateIconIndirect(&info
);
1278 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
1279 DeleteObject(hbmMask
);
1280 DeleteObject(hbmColor
);
1282 stat
= GdipCreateBitmapFromHICON(hIcon
, &bitmap
);
1285 /* check attributes */
1286 stat
= GdipGetImageHeight((GpImage
*)bitmap
, &dim
);
1289 stat
= GdipGetImageWidth((GpImage
*)bitmap
, &dim
);
1292 stat
= GdipGetImageType((GpImage
*)bitmap
, &type
);
1294 expect(ImageTypeBitmap
, type
);
1295 stat
= GdipGetImagePixelFormat((GpImage
*)bitmap
, &format
);
1297 expect(PixelFormat32bppARGB
, format
);
1299 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)bitmap
, __LINE__
, FALSE
);
1300 GdipDisposeImage((GpImage
*)bitmap
);
1306 static const unsigned char pngimage
[285] = {
1307 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
1308 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
1309 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
1310 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
1311 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
1312 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
1313 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
1316 static const unsigned char gifimage
[35] = {
1317 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
1318 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
1322 static const unsigned char bmpimage
[66] = {
1323 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
1324 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
1325 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
1326 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
1330 static const unsigned char jpgimage
[285] = {
1331 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
1332 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
1333 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
1334 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
1335 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
1336 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
1337 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
1338 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1339 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1340 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
1341 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
1342 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1343 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
1344 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
1345 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1346 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
1347 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
1348 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
1350 /* 1x1 pixel tiff */
1351 static const unsigned char tiffimage
[] = {
1352 0x49,0x49,0x2a,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xfe,0x00,
1353 0x04,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x00,0x01,0x00,
1354 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1355 0x00,0x00,0x02,0x01,0x03,0x00,0x03,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0x03,0x01,
1356 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,0x01,0x03,0x00,0x01,0x00,
1357 0x00,0x00,0x02,0x00,0x00,0x00,0x0d,0x01,0x02,0x00,0x1b,0x00,0x00,0x00,0xd8,0x00,
1358 0x00,0x00,0x11,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x12,0x01,
1359 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x01,0x03,0x00,0x01,0x00,
1360 0x00,0x00,0x03,0x00,0x00,0x00,0x16,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x40,0x00,
1361 0x00,0x00,0x17,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1a,0x01,
1362 0x05,0x00,0x01,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x1b,0x01,0x05,0x00,0x01,0x00,
1363 0x00,0x00,0xfc,0x00,0x00,0x00,0x1c,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1364 0x00,0x00,0x28,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
1365 0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x6d,0x65,
1366 0x68,0x2f,0x44,0x65,0x73,0x6b,0x74,0x6f,0x70,0x2f,0x74,0x65,0x73,0x74,0x2e,0x74,
1367 0x69,0x66,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,
1370 /* 320x320 twip wmf */
1371 static const unsigned char wmfimage
[180] = {
1372 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
1373 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
1374 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
1375 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
1376 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
1377 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
1378 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
1379 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
1380 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
1381 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
1382 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
1385 static void test_getrawformat(void)
1387 test_bufferrawformat((void*)pngimage
, sizeof(pngimage
), &ImageFormatPNG
, __LINE__
, FALSE
);
1388 test_bufferrawformat((void*)gifimage
, sizeof(gifimage
), &ImageFormatGIF
, __LINE__
, FALSE
);
1389 test_bufferrawformat((void*)bmpimage
, sizeof(bmpimage
), &ImageFormatBMP
, __LINE__
, FALSE
);
1390 test_bufferrawformat((void*)jpgimage
, sizeof(jpgimage
), &ImageFormatJPEG
, __LINE__
, FALSE
);
1391 test_bufferrawformat((void*)tiffimage
, sizeof(tiffimage
), &ImageFormatTIFF
, __LINE__
, FALSE
);
1392 test_bufferrawformat((void*)wmfimage
, sizeof(wmfimage
), &ImageFormatWMF
, __LINE__
, FALSE
);
1395 static void test_loadwmf(void)
1406 MetafileHeader header
;
1408 hglob
= GlobalAlloc (0, sizeof(wmfimage
));
1409 data
= GlobalLock (hglob
);
1410 memcpy(data
, wmfimage
, sizeof(wmfimage
));
1411 GlobalUnlock(hglob
); data
= NULL
;
1413 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
1414 ok(hres
== S_OK
, "Failed to create a stream\n");
1415 if(hres
!= S_OK
) return;
1417 stat
= GdipLoadImageFromStream(stream
, &img
);
1418 ok(stat
== Ok
, "Failed to create a Bitmap\n");
1420 IStream_Release(stream
);
1424 IStream_Release(stream
);
1426 stat
= GdipGetImageBounds(img
, &bounds
, &unit
);
1428 todo_wine
expect(UnitPixel
, unit
);
1429 expectf(0.0, bounds
.X
);
1430 expectf(0.0, bounds
.Y
);
1431 todo_wine
expectf(320.0, bounds
.Width
);
1432 todo_wine
expectf(320.0, bounds
.Height
);
1434 stat
= GdipGetImageHorizontalResolution(img
, &res
);
1436 todo_wine
expectf(1440.0, res
);
1438 stat
= GdipGetImageVerticalResolution(img
, &res
);
1440 todo_wine
expectf(1440.0, res
);
1442 memset(&header
, 0, sizeof(header
));
1443 stat
= GdipGetMetafileHeaderFromMetafile((GpMetafile
*)img
, &header
);
1447 todo_wine
expect(MetafileTypeWmfPlaceable
, header
.Type
);
1448 todo_wine
expect(sizeof(wmfimage
)-sizeof(WmfPlaceableFileHeader
), header
.Size
);
1449 todo_wine
expect(0x300, header
.Version
);
1450 expect(0, header
.EmfPlusFlags
);
1451 todo_wine
expectf(1440.0, header
.DpiX
);
1452 todo_wine
expectf(1440.0, header
.DpiY
);
1453 expect(0, header
.X
);
1454 expect(0, header
.Y
);
1455 todo_wine
expect(320, header
.Width
);
1456 todo_wine
expect(320, header
.Height
);
1457 todo_wine
expect(1, U(header
).WmfHeader
.mtType
);
1458 expect(0, header
.EmfPlusHeaderSize
);
1459 expect(0, header
.LogicalDpiX
);
1460 expect(0, header
.LogicalDpiY
);
1463 GdipDisposeImage(img
);
1466 static void test_createfromwmf(void)
1474 MetafileHeader header
;
1476 hwmf
= SetMetaFileBitsEx(sizeof(wmfimage
)-sizeof(WmfPlaceableFileHeader
),
1477 wmfimage
+sizeof(WmfPlaceableFileHeader
));
1478 ok(hwmf
!= 0, "SetMetaFileBitsEx failed\n");
1480 stat
= GdipCreateMetafileFromWmf(hwmf
, TRUE
,
1481 (WmfPlaceableFileHeader
*)wmfimage
, (GpMetafile
**)&img
);
1483 if (stat
!= Ok
) return; // ReactOS
1485 stat
= GdipGetImageBounds(img
, &bounds
, &unit
);
1487 expect(UnitPixel
, unit
);
1488 expectf(0.0, bounds
.X
);
1489 expectf(0.0, bounds
.Y
);
1490 expectf(320.0, bounds
.Width
);
1491 expectf(320.0, bounds
.Height
);
1493 stat
= GdipGetImageHorizontalResolution(img
, &res
);
1495 expectf(1440.0, res
);
1497 stat
= GdipGetImageVerticalResolution(img
, &res
);
1499 expectf(1440.0, res
);
1501 memset(&header
, 0, sizeof(header
));
1502 stat
= GdipGetMetafileHeaderFromMetafile((GpMetafile
*)img
, &header
);
1506 todo_wine
expect(MetafileTypeWmfPlaceable
, header
.Type
);
1507 todo_wine
expect(sizeof(wmfimage
)-sizeof(WmfPlaceableFileHeader
), header
.Size
);
1508 todo_wine
expect(0x300, header
.Version
);
1509 expect(0, header
.EmfPlusFlags
);
1510 todo_wine
expectf(1440.0, header
.DpiX
);
1511 todo_wine
expectf(1440.0, header
.DpiY
);
1512 expect(0, header
.X
);
1513 expect(0, header
.Y
);
1514 todo_wine
expect(320, header
.Width
);
1515 todo_wine
expect(320, header
.Height
);
1516 todo_wine
expect(1, U(header
).WmfHeader
.mtType
);
1517 expect(0, header
.EmfPlusHeaderSize
);
1518 expect(0, header
.LogicalDpiX
);
1519 expect(0, header
.LogicalDpiY
);
1522 GdipDisposeImage(img
);
1525 static void test_resolution(void)
1529 GpGraphics
*graphics
;
1532 int screenxres
, screenyres
;
1535 stat
= GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB
, NULL
, &bitmap
);
1538 /* test invalid values */
1539 stat
= GdipGetImageHorizontalResolution(NULL
, &res
);
1540 expect(InvalidParameter
, stat
);
1542 stat
= GdipGetImageHorizontalResolution((GpImage
*)bitmap
, NULL
);
1543 expect(InvalidParameter
, stat
);
1545 stat
= GdipGetImageVerticalResolution(NULL
, &res
);
1546 expect(InvalidParameter
, stat
);
1548 stat
= GdipGetImageVerticalResolution((GpImage
*)bitmap
, NULL
);
1549 expect(InvalidParameter
, stat
);
1551 stat
= GdipBitmapSetResolution(NULL
, 96.0, 96.0);
1552 expect(InvalidParameter
, stat
);
1554 stat
= GdipBitmapSetResolution(bitmap
, 0.0, 0.0);
1555 expect(InvalidParameter
, stat
);
1557 /* defaults to screen resolution */
1558 screendc
= GetDC(0);
1560 screenxres
= GetDeviceCaps(screendc
, LOGPIXELSX
);
1561 screenyres
= GetDeviceCaps(screendc
, LOGPIXELSY
);
1563 ReleaseDC(0, screendc
);
1565 stat
= GdipGetImageHorizontalResolution((GpImage
*)bitmap
, &res
);
1567 expectf((REAL
)screenxres
, res
);
1569 stat
= GdipGetImageVerticalResolution((GpImage
*)bitmap
, &res
);
1571 expectf((REAL
)screenyres
, res
);
1573 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap
, &graphics
);
1575 stat
= GdipGetDpiX(graphics
, &res
);
1577 expectf((REAL
)screenxres
, res
);
1578 stat
= GdipGetDpiY(graphics
, &res
);
1580 expectf((REAL
)screenyres
, res
);
1582 /* test changing the resolution */
1583 stat
= GdipBitmapSetResolution(bitmap
, screenxres
*2.0, screenyres
*3.0);
1586 stat
= GdipGetImageHorizontalResolution((GpImage
*)bitmap
, &res
);
1588 expectf(screenxres
*2.0, res
);
1590 stat
= GdipGetImageVerticalResolution((GpImage
*)bitmap
, &res
);
1592 expectf(screenyres
*3.0, res
);
1594 stat
= GdipGetDpiX(graphics
, &res
);
1596 expectf((REAL
)screenxres
, res
);
1597 stat
= GdipGetDpiY(graphics
, &res
);
1599 expectf((REAL
)screenyres
, res
);
1601 stat
= GdipDeleteGraphics(graphics
);
1604 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap
, &graphics
);
1606 stat
= GdipGetDpiX(graphics
, &res
);
1608 expectf(screenxres
*2.0, res
);
1609 stat
= GdipGetDpiY(graphics
, &res
);
1611 expectf(screenyres
*3.0, res
);
1612 stat
= GdipDeleteGraphics(graphics
);
1615 stat
= GdipDisposeImage((GpImage
*)bitmap
);
1619 static void test_createhbitmap(void)
1623 HBITMAP hbitmap
, oldhbitmap
;
1630 memset(bits
, 0x68, 640);
1633 stat
= GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB
, bits
, &bitmap
);
1636 /* test NULL values */
1637 stat
= GdipCreateHBITMAPFromBitmap(NULL
, &hbitmap
, 0);
1638 expect(InvalidParameter
, stat
);
1640 stat
= GdipCreateHBITMAPFromBitmap(bitmap
, NULL
, 0);
1641 expect(InvalidParameter
, stat
);
1643 /* create HBITMAP */
1644 stat
= GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
1649 ret
= GetObjectA(hbitmap
, sizeof(BITMAP
), &bm
);
1650 expect(sizeof(BITMAP
), ret
);
1652 expect(0, bm
.bmType
);
1653 expect(10, bm
.bmWidth
);
1654 expect(20, bm
.bmHeight
);
1655 expect(40, bm
.bmWidthBytes
);
1656 expect(1, bm
.bmPlanes
);
1657 expect(32, bm
.bmBitsPixel
);
1658 ok(bm
.bmBits
!= NULL
, "got DDB, expected DIB\n");
1662 DWORD val
= *(DWORD
*)bm
.bmBits
;
1663 ok(val
== 0xff686868, "got %x, expected 0xff686868\n", val
);
1666 hdc
= CreateCompatibleDC(NULL
);
1668 oldhbitmap
= SelectObject(hdc
, hbitmap
);
1669 pixel
= GetPixel(hdc
, 5, 5);
1670 SelectObject(hdc
, oldhbitmap
);
1674 expect(0x686868, pixel
);
1676 DeleteObject(hbitmap
);
1679 stat
= GdipDisposeImage((GpImage
*)bitmap
);
1682 /* create alpha Bitmap */
1683 stat
= GdipCreateBitmapFromScan0(8, 20, 32, PixelFormat32bppARGB
, bits
, &bitmap
);
1686 /* create HBITMAP */
1687 stat
= GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
1692 ret
= GetObjectA(hbitmap
, sizeof(BITMAP
), &bm
);
1693 expect(sizeof(BITMAP
), ret
);
1695 expect(0, bm
.bmType
);
1696 expect(8, bm
.bmWidth
);
1697 expect(20, bm
.bmHeight
);
1698 expect(32, bm
.bmWidthBytes
);
1699 expect(1, bm
.bmPlanes
);
1700 expect(32, bm
.bmBitsPixel
);
1701 ok(bm
.bmBits
!= NULL
, "got DDB, expected DIB\n");
1705 DWORD val
= *(DWORD
*)bm
.bmBits
;
1706 ok(val
== 0x682a2a2a, "got %x, expected 0x682a2a2a\n", val
);
1709 hdc
= CreateCompatibleDC(NULL
);
1711 oldhbitmap
= SelectObject(hdc
, hbitmap
);
1712 pixel
= GetPixel(hdc
, 5, 5);
1713 SelectObject(hdc
, oldhbitmap
);
1717 expect(0x2a2a2a, pixel
);
1719 DeleteObject(hbitmap
);
1722 stat
= GdipDisposeImage((GpImage
*)bitmap
);
1726 static void test_getthumbnail(void)
1729 GpImage
*bitmap1
, *bitmap2
;
1732 stat
= GdipGetImageThumbnail(NULL
, 0, 0, &bitmap2
, NULL
, NULL
);
1733 expect(InvalidParameter
, stat
);
1735 stat
= GdipCreateBitmapFromScan0(128, 128, 0, PixelFormat32bppRGB
, NULL
, (GpBitmap
**)&bitmap1
);
1738 stat
= GdipGetImageThumbnail(bitmap1
, 0, 0, NULL
, NULL
, NULL
);
1739 expect(InvalidParameter
, stat
);
1741 stat
= GdipGetImageThumbnail(bitmap1
, 0, 0, &bitmap2
, NULL
, NULL
);
1746 stat
= GdipGetImageWidth(bitmap2
, &width
);
1750 stat
= GdipGetImageHeight(bitmap2
, &height
);
1752 expect(120, height
);
1754 GdipDisposeImage(bitmap2
);
1757 GdipDisposeImage(bitmap1
);
1760 stat
= GdipCreateBitmapFromScan0(64, 128, 0, PixelFormat32bppRGB
, NULL
, (GpBitmap
**)&bitmap1
);
1763 stat
= GdipGetImageThumbnail(bitmap1
, 32, 32, &bitmap2
, NULL
, NULL
);
1768 stat
= GdipGetImageWidth(bitmap2
, &width
);
1772 stat
= GdipGetImageHeight(bitmap2
, &height
);
1776 GdipDisposeImage(bitmap2
);
1779 stat
= GdipGetImageThumbnail(bitmap1
, 0, 0, &bitmap2
, NULL
, NULL
);
1784 stat
= GdipGetImageWidth(bitmap2
, &width
);
1788 stat
= GdipGetImageHeight(bitmap2
, &height
);
1790 expect(120, height
);
1792 GdipDisposeImage(bitmap2
);
1795 GdipDisposeImage(bitmap1
);
1798 static void test_getsetpixel(void)
1803 BYTE bits
[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1804 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1806 stat
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB
, bits
, &bitmap
);
1809 /* null parameters */
1810 stat
= GdipBitmapGetPixel(NULL
, 1, 1, &color
);
1811 expect(InvalidParameter
, stat
);
1813 stat
= GdipBitmapGetPixel(bitmap
, 1, 1, NULL
);
1814 expect(InvalidParameter
, stat
);
1816 stat
= GdipBitmapSetPixel(NULL
, 1, 1, 0);
1817 expect(InvalidParameter
, stat
);
1820 stat
= GdipBitmapGetPixel(bitmap
, -1, 1, &color
);
1821 expect(InvalidParameter
, stat
);
1823 stat
= GdipBitmapSetPixel(bitmap
, -1, 1, 0);
1824 expect(InvalidParameter
, stat
);
1826 stat
= GdipBitmapGetPixel(bitmap
, 1, -1, &color
);
1827 ok(stat
== InvalidParameter
||
1828 broken(stat
== Ok
), /* Older gdiplus */
1829 "Expected InvalidParameter, got %.8x\n", stat
);
1831 if (0) /* crashes some gdiplus implementations */
1833 stat
= GdipBitmapSetPixel(bitmap
, 1, -1, 0);
1834 ok(stat
== InvalidParameter
||
1835 broken(stat
== Ok
), /* Older gdiplus */
1836 "Expected InvalidParameter, got %.8x\n", stat
);
1839 stat
= GdipBitmapGetPixel(bitmap
, 2, 1, &color
);
1840 expect(InvalidParameter
, stat
);
1842 stat
= GdipBitmapSetPixel(bitmap
, 2, 1, 0);
1843 expect(InvalidParameter
, stat
);
1845 stat
= GdipBitmapGetPixel(bitmap
, 1, 2, &color
);
1846 expect(InvalidParameter
, stat
);
1848 stat
= GdipBitmapSetPixel(bitmap
, 1, 2, 0);
1849 expect(InvalidParameter
, stat
);
1852 stat
= GdipBitmapGetPixel(bitmap
, 1, 1, &color
);
1854 expect(0xffffffff, color
);
1856 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
1858 expect(0xff0000ff, color
);
1860 stat
= GdipBitmapSetPixel(bitmap
, 1, 1, 0xff676869);
1863 stat
= GdipBitmapSetPixel(bitmap
, 0, 0, 0xff474849);
1866 stat
= GdipBitmapGetPixel(bitmap
, 1, 1, &color
);
1868 expect(0xff676869, color
);
1870 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
1872 expect(0xff474849, color
);
1874 stat
= GdipDisposeImage((GpImage
*)bitmap
);
1878 static void check_halftone_palette(ColorPalette
*palette
)
1880 static const BYTE halftone_values
[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1883 for (i
=0; i
<palette
->Count
; i
++)
1885 ARGB expected
=0xff000000;
1888 if (i
&1) expected
|= 0x800000;
1889 if (i
&2) expected
|= 0x8000;
1890 if (i
&4) expected
|= 0x80;
1894 expected
= 0xffc0c0c0;
1898 if (i
&1) expected
|= 0xff0000;
1899 if (i
&2) expected
|= 0xff00;
1900 if (i
&4) expected
|= 0xff;
1904 expected
= 0x00000000;
1908 expected
|= halftone_values
[(i
-40)%6];
1909 expected
|= halftone_values
[((i
-40)/6)%6] << 8;
1910 expected
|= halftone_values
[((i
-40)/36)%6] << 16;
1912 ok(expected
== palette
->Entries
[i
], "Expected %.8x, got %.8x, i=%u/%u\n",
1913 expected
, palette
->Entries
[i
], i
, palette
->Count
);
1917 static void test_palette(void)
1923 ColorPalette
*palette
=(ColorPalette
*)buffer
;
1924 ARGB
*entries
= palette
->Entries
;
1927 /* test initial palette from non-indexed bitmap */
1928 stat
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB
, NULL
, &bitmap
);
1931 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1933 expect(sizeof(UINT
)*2+sizeof(ARGB
), size
);
1935 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1937 expect(0, palette
->Count
);
1939 /* test setting palette on not-indexed bitmap */
1942 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
1945 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1947 expect(sizeof(UINT
)*2+sizeof(ARGB
)*3, size
);
1949 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1951 expect(3, palette
->Count
);
1953 GdipDisposeImage((GpImage
*)bitmap
);
1955 /* test initial palette on 1-bit bitmap */
1956 stat
= GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed
, NULL
, &bitmap
);
1959 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1961 expect(sizeof(UINT
)*2+sizeof(ARGB
)*2, size
);
1963 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1965 expect(PaletteFlagsGrayScale
, palette
->Flags
);
1966 expect(2, palette
->Count
);
1968 expect(0xff000000, entries
[0]);
1969 expect(0xffffffff, entries
[1]);
1971 /* test getting/setting pixels */
1972 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
1974 expect(0xff000000, color
);
1976 stat
= GdipBitmapSetPixel(bitmap
, 0, 1, 0xffffffff);
1978 broken(stat
== InvalidParameter
) /* pre-win7 */, "stat=%.8x\n", stat
);
1982 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
1984 expect(0xffffffff, color
);
1987 GdipDisposeImage((GpImage
*)bitmap
);
1989 /* test initial palette on 4-bit bitmap */
1990 stat
= GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed
, NULL
, &bitmap
);
1993 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1995 expect(sizeof(UINT
)*2+sizeof(ARGB
)*16, size
);
1997 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1999 expect(0, palette
->Flags
);
2000 expect(16, palette
->Count
);
2002 check_halftone_palette(palette
);
2004 /* test getting/setting pixels */
2005 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
2007 expect(0xff000000, color
);
2009 stat
= GdipBitmapSetPixel(bitmap
, 0, 1, 0xffff00ff);
2011 broken(stat
== InvalidParameter
) /* pre-win7 */, "stat=%.8x\n", stat
);
2015 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
2017 expect(0xffff00ff, color
);
2020 GdipDisposeImage((GpImage
*)bitmap
);
2022 /* test initial palette on 8-bit bitmap */
2023 stat
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed
, NULL
, &bitmap
);
2026 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
2028 expect(sizeof(UINT
)*2+sizeof(ARGB
)*256, size
);
2030 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
2032 expect(PaletteFlagsHalftone
, palette
->Flags
);
2033 expect(256, palette
->Count
);
2035 check_halftone_palette(palette
);
2037 /* test getting/setting pixels */
2038 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
2040 expect(0xff000000, color
);
2042 stat
= GdipBitmapSetPixel(bitmap
, 0, 1, 0xffcccccc);
2044 broken(stat
== InvalidParameter
) /* pre-win7 */, "stat=%.8x\n", stat
);
2048 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
2050 expect(0xffcccccc, color
);
2053 /* test setting/getting a different palette */
2054 entries
[1] = 0xffcccccc;
2056 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
2061 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
2063 expect(sizeof(UINT
)*2+sizeof(ARGB
)*256, size
);
2065 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
2067 expect(PaletteFlagsHalftone
, palette
->Flags
);
2068 expect(256, palette
->Count
);
2069 expect(0xffcccccc, entries
[1]);
2071 /* test count < 256 */
2072 palette
->Flags
= 12345;
2075 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
2079 entries
[3] = 0xdeadbeef;
2081 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
2083 expect(sizeof(UINT
)*2+sizeof(ARGB
)*3, size
);
2085 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
2087 expect(12345, palette
->Flags
);
2088 expect(3, palette
->Count
);
2089 expect(0xffcccccc, entries
[1]);
2090 expect(0xdeadbeef, entries
[3]);
2092 /* test count > 256 */
2093 palette
->Count
= 257;
2095 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
2096 ok(stat
== InvalidParameter
||
2097 broken(stat
== Ok
), /* Old gdiplus behavior */
2098 "Expected %.8x, got %.8x\n", InvalidParameter
, stat
);
2100 GdipDisposeImage((GpImage
*)bitmap
);
2103 static void test_colormatrix(void)
2106 ColorMatrix colormatrix
, graymatrix
;
2107 GpImageAttributes
*imageattr
;
2108 const ColorMatrix identity
= {{
2109 {1.0,0.0,0.0,0.0,0.0},
2110 {0.0,1.0,0.0,0.0,0.0},
2111 {0.0,0.0,1.0,0.0,0.0},
2112 {0.0,0.0,0.0,1.0,0.0},
2113 {0.0,0.0,0.0,0.0,1.0}}};
2114 const ColorMatrix double_red
= {{
2115 {2.0,0.0,0.0,0.0,0.0},
2116 {0.0,1.0,0.0,0.0,0.0},
2117 {0.0,0.0,1.0,0.0,0.0},
2118 {0.0,0.0,0.0,1.0,0.0},
2119 {0.0,0.0,0.0,0.0,1.0}}};
2120 const ColorMatrix asymmetric
= {{
2121 {0.0,1.0,0.0,0.0,0.0},
2122 {0.0,0.0,1.0,0.0,0.0},
2123 {0.0,0.0,0.0,1.0,0.0},
2124 {1.0,0.0,0.0,0.0,0.0},
2125 {0.0,0.0,0.0,0.0,1.0}}};
2126 GpBitmap
*bitmap1
, *bitmap2
;
2127 GpGraphics
*graphics
;
2130 colormatrix
= identity
;
2131 graymatrix
= identity
;
2133 stat
= GdipSetImageAttributesColorMatrix(NULL
, ColorAdjustTypeDefault
,
2134 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
2135 expect(InvalidParameter
, stat
);
2137 stat
= GdipCreateImageAttributes(&imageattr
);
2140 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2141 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsDefault
);
2144 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2145 TRUE
, NULL
, NULL
, ColorMatrixFlagsDefault
);
2146 expect(InvalidParameter
, stat
);
2148 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2149 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
2152 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2153 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsSkipGrays
);
2156 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2157 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsAltGray
);
2158 expect(InvalidParameter
, stat
);
2160 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2161 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsAltGray
);
2164 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2165 TRUE
, &colormatrix
, &graymatrix
, 3);
2166 expect(InvalidParameter
, stat
);
2168 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeCount
,
2169 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
2170 expect(InvalidParameter
, stat
);
2172 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeAny
,
2173 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
2174 expect(InvalidParameter
, stat
);
2176 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2177 FALSE
, NULL
, NULL
, ColorMatrixFlagsDefault
);
2180 /* Drawing a bitmap transforms the colors */
2181 colormatrix
= double_red
;
2182 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2183 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsDefault
);
2186 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppARGB
, NULL
, &bitmap1
);
2189 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppARGB
, NULL
, &bitmap2
);
2192 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0xff40ccee);
2195 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
2198 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
2199 UnitPixel
, imageattr
, NULL
, NULL
);
2202 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2204 expect(0xff80ccee, color
);
2206 colormatrix
= asymmetric
;
2207 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2208 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsDefault
);
2211 stat
= GdipBitmapSetPixel(bitmap2
, 0, 0, 0);
2214 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
2215 UnitPixel
, imageattr
, NULL
, NULL
);
2218 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2220 ok(color_match(0xeeff40cc, color
, 3), "expected 0xeeff40cc, got 0x%08x\n", color
);
2222 GdipDeleteGraphics(graphics
);
2223 GdipDisposeImage((GpImage
*)bitmap1
);
2224 GdipDisposeImage((GpImage
*)bitmap2
);
2225 GdipDisposeImageAttributes(imageattr
);
2228 static void test_gamma(void)
2231 GpImageAttributes
*imageattr
;
2232 GpBitmap
*bitmap1
, *bitmap2
;
2233 GpGraphics
*graphics
;
2236 stat
= GdipSetImageAttributesGamma(NULL
, ColorAdjustTypeDefault
, TRUE
, 1.0);
2237 expect(InvalidParameter
, stat
);
2239 stat
= GdipCreateImageAttributes(&imageattr
);
2242 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1.0);
2245 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeAny
, TRUE
, 1.0);
2246 expect(InvalidParameter
, stat
);
2248 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, -1.0);
2249 expect(InvalidParameter
, stat
);
2251 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0.0);
2252 expect(InvalidParameter
, stat
);
2254 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0.5);
2257 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, FALSE
, 0.0);
2260 /* Drawing a bitmap transforms the colors */
2261 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 3.0);
2264 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap1
);
2267 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap2
);
2270 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0xff80ffff);
2273 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
2276 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
2277 UnitPixel
, imageattr
, NULL
, NULL
);
2280 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2282 ok(color_match(0xff20ffff, color
, 1), "Expected ff20ffff, got %.8x\n", color
);
2284 GdipDeleteGraphics(graphics
);
2285 GdipDisposeImage((GpImage
*)bitmap1
);
2286 GdipDisposeImage((GpImage
*)bitmap2
);
2287 GdipDisposeImageAttributes(imageattr
);
2290 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
2291 static const unsigned char gifanimation
[72] = {
2292 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
2293 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
2294 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
2295 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
2296 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
2299 static void test_multiframegif(void)
2311 /* Test frame functions with an animated GIF */
2312 hglob
= GlobalAlloc (0, sizeof(gifanimation
));
2313 data
= GlobalLock (hglob
);
2314 memcpy(data
, gifanimation
, sizeof(gifanimation
));
2315 GlobalUnlock(hglob
);
2317 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
2318 ok(hres
== S_OK
, "Failed to create a stream\n");
2319 if(hres
!= S_OK
) return;
2321 stat
= GdipCreateBitmapFromStream(stream
, &bmp
);
2322 ok(stat
== Ok
, "Failed to create a Bitmap\n");
2324 IStream_Release(stream
);
2328 /* Bitmap starts at frame 0 */
2330 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
2332 expect(0xffffffff, color
);
2334 /* Check that we get correct metadata */
2335 stat
= GdipImageGetFrameDimensionsCount((GpImage
*)bmp
,&count
);
2339 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bmp
, &dimension
, 1);
2341 expect_guid(&FrameDimensionTime
, &dimension
, __LINE__
, FALSE
);
2344 stat
= GdipImageGetFrameCount((GpImage
*)bmp
, &dimension
, &count
);
2348 /* SelectActiveFrame overwrites our current data */
2349 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 1);
2353 GdipBitmapGetPixel(bmp
, 0, 0, &color
);
2355 expect(0xff000000, color
);
2357 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
2361 GdipBitmapGetPixel(bmp
, 0, 0, &color
);
2363 expect(0xffffffff, color
);
2365 /* Write over the image data */
2366 stat
= GdipBitmapSetPixel(bmp
, 0, 0, 0xff000000);
2369 /* Switching to the same frame does not overwrite our changes */
2370 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
2373 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
2375 expect(0xff000000, color
);
2377 /* But switching to another frame and back does */
2378 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 1);
2381 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
2384 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
2386 expect(0xffffffff, color
);
2388 /* rotate/flip discards the information about other frames */
2389 stat
= GdipImageRotateFlip((GpImage
*)bmp
, Rotate90FlipNone
);
2393 stat
= GdipImageGetFrameCount((GpImage
*)bmp
, &dimension
, &count
);
2397 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)bmp
, __LINE__
, FALSE
);
2399 GdipDisposeImage((GpImage
*)bmp
);
2400 IStream_Release(stream
);
2402 /* Test with a non-animated gif */
2403 hglob
= GlobalAlloc (0, sizeof(gifimage
));
2404 data
= GlobalLock (hglob
);
2405 memcpy(data
, gifimage
, sizeof(gifimage
));
2406 GlobalUnlock(hglob
);
2408 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
2409 ok(hres
== S_OK
, "Failed to create a stream\n");
2410 if(hres
!= S_OK
) return;
2412 stat
= GdipCreateBitmapFromStream(stream
, &bmp
);
2413 ok(stat
== Ok
, "Failed to create a Bitmap\n");
2415 IStream_Release(stream
);
2419 /* Check metadata */
2420 stat
= GdipImageGetFrameDimensionsCount((GpImage
*)bmp
,&count
);
2424 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bmp
, &dimension
, 1);
2426 expect_guid(&FrameDimensionTime
, &dimension
, __LINE__
, FALSE
);
2429 stat
= GdipImageGetFrameCount((GpImage
*)bmp
, &dimension
, &count
);
2433 GdipDisposeImage((GpImage
*)bmp
);
2434 IStream_Release(stream
);
2437 static void test_rotateflip(void)
2442 static const BYTE orig_bits
[24] = {
2443 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
2444 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
2448 memcpy(bits
, orig_bits
, sizeof(bits
));
2449 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
2452 stat
= GdipImageRotateFlip(bitmap
, Rotate90FlipNone
);
2455 stat
= GdipGetImageWidth(bitmap
, &width
);
2457 stat
= GdipGetImageHeight(bitmap
, &height
);
2462 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 0, &color
);
2464 expect(0xff00ffff, color
);
2466 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 1, 0, &color
);
2468 expect(0xffff0000, color
);
2470 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 2, &color
);
2472 expect(0xffffff00, color
);
2474 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 1, 2, &color
);
2476 expect(0xff0000ff, color
);
2480 expect(0xff, bits
[2]);
2482 GdipDisposeImage(bitmap
);
2484 memcpy(bits
, orig_bits
, sizeof(bits
));
2485 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
2488 stat
= GdipImageRotateFlip(bitmap
, RotateNoneFlipX
);
2491 stat
= GdipGetImageWidth(bitmap
, &width
);
2493 stat
= GdipGetImageHeight(bitmap
, &height
);
2498 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 0, &color
);
2500 expect(0xff0000ff, color
);
2502 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 0, &color
);
2504 expect(0xffff0000, color
);
2506 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 1, &color
);
2508 expect(0xffffff00, color
);
2510 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 1, &color
);
2512 expect(0xff00ffff, color
);
2516 expect(0xff, bits
[2]);
2518 GdipDisposeImage(bitmap
);
2520 memcpy(bits
, orig_bits
, sizeof(bits
));
2521 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
2524 stat
= GdipImageRotateFlip(bitmap
, RotateNoneFlipY
);
2527 stat
= GdipGetImageWidth(bitmap
, &width
);
2529 stat
= GdipGetImageHeight(bitmap
, &height
);
2534 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 0, &color
);
2536 expect(0xff00ffff, color
);
2538 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 0, &color
);
2540 expect(0xffffff00, color
);
2542 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 1, &color
);
2544 expect(0xffff0000, color
);
2546 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 1, &color
);
2548 expect(0xff0000ff, color
);
2552 expect(0xff, bits
[2]);
2554 GdipDisposeImage(bitmap
);
2557 static void test_remaptable(void)
2560 GpImageAttributes
*imageattr
;
2561 GpBitmap
*bitmap1
, *bitmap2
;
2562 GpGraphics
*graphics
;
2566 map
= GdipAlloc(sizeof(ColorMap
));
2568 map
->oldColor
.Argb
= 0xff00ff00;
2569 map
->newColor
.Argb
= 0xffff00ff;
2571 stat
= GdipSetImageAttributesRemapTable(NULL
, ColorAdjustTypeDefault
, TRUE
, 1, map
);
2572 expect(InvalidParameter
, stat
);
2574 stat
= GdipCreateImageAttributes(&imageattr
);
2577 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1, NULL
);
2578 expect(InvalidParameter
, stat
);
2580 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeCount
, TRUE
, 1, map
);
2581 expect(InvalidParameter
, stat
);
2583 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeAny
, TRUE
, 1, map
);
2584 expect(InvalidParameter
, stat
);
2586 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0, map
);
2587 expect(InvalidParameter
, stat
);
2589 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, FALSE
, 0, NULL
);
2592 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1, map
);
2595 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap1
);
2598 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap2
);
2601 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0xff00ff00);
2604 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
2607 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
2608 UnitPixel
, imageattr
, NULL
, NULL
);
2611 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2613 ok(color_match(0xffff00ff, color
, 1), "Expected ffff00ff, got %.8x\n", color
);
2615 GdipDeleteGraphics(graphics
);
2616 GdipDisposeImage((GpImage
*)bitmap1
);
2617 GdipDisposeImage((GpImage
*)bitmap2
);
2618 GdipDisposeImageAttributes(imageattr
);
2622 static void test_colorkey(void)
2625 GpImageAttributes
*imageattr
;
2626 GpBitmap
*bitmap1
, *bitmap2
;
2627 GpGraphics
*graphics
;
2630 stat
= GdipSetImageAttributesColorKeys(NULL
, ColorAdjustTypeDefault
, TRUE
, 0xff405060, 0xff708090);
2631 expect(InvalidParameter
, stat
);
2633 stat
= GdipCreateImageAttributes(&imageattr
);
2636 stat
= GdipSetImageAttributesColorKeys(imageattr
, ColorAdjustTypeCount
, TRUE
, 0xff405060, 0xff708090);
2637 expect(InvalidParameter
, stat
);
2639 stat
= GdipSetImageAttributesColorKeys(imageattr
, ColorAdjustTypeAny
, TRUE
, 0xff405060, 0xff708090);
2640 expect(InvalidParameter
, stat
);
2642 stat
= GdipSetImageAttributesColorKeys(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0xff405060, 0xff708090);
2645 stat
= GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB
, NULL
, &bitmap1
);
2648 stat
= GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB
, NULL
, &bitmap2
);
2651 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0x20405060);
2654 stat
= GdipBitmapSetPixel(bitmap1
, 0, 1, 0x40506070);
2657 stat
= GdipBitmapSetPixel(bitmap1
, 1, 0, 0x60708090);
2660 stat
= GdipBitmapSetPixel(bitmap1
, 1, 1, 0xffffffff);
2663 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
2666 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,2,2, 0,0,2,2,
2667 UnitPixel
, imageattr
, NULL
, NULL
);
2670 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2672 ok(color_match(0x00000000, color
, 1), "Expected ffff00ff, got %.8x\n", color
);
2674 stat
= GdipBitmapGetPixel(bitmap2
, 0, 1, &color
);
2676 ok(color_match(0x00000000, color
, 1), "Expected ffff00ff, got %.8x\n", color
);
2678 stat
= GdipBitmapGetPixel(bitmap2
, 1, 0, &color
);
2680 ok(color_match(0x00000000, color
, 1), "Expected ffff00ff, got %.8x\n", color
);
2682 stat
= GdipBitmapGetPixel(bitmap2
, 1, 1, &color
);
2684 ok(color_match(0xffffffff, color
, 1), "Expected ffff00ff, got %.8x\n", color
);
2686 GdipDeleteGraphics(graphics
);
2687 GdipDisposeImage((GpImage
*)bitmap1
);
2688 GdipDisposeImage((GpImage
*)bitmap2
);
2689 GdipDisposeImageAttributes(imageattr
);
2692 static void test_dispose(void)
2696 char invalid_image
[256];
2698 stat
= GdipDisposeImage(NULL
);
2699 expect(InvalidParameter
, stat
);
2701 stat
= GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB
, NULL
, (GpBitmap
**)&image
);
2704 stat
= GdipDisposeImage(image
);
2707 stat
= GdipDisposeImage(image
);
2708 expect(ObjectBusy
, stat
);
2710 memset(invalid_image
, 0, 256);
2711 stat
= GdipDisposeImage((GpImage
*)invalid_image
);
2712 expect(ObjectBusy
, stat
);
2715 static LONG
obj_refcount(void *obj
)
2717 IUnknown_AddRef((IUnknown
*)obj
);
2718 return IUnknown_Release((IUnknown
*)obj
);
2721 static GpImage
*load_image(const BYTE
*image_data
, UINT image_size
)
2728 GpImage
*image
= NULL
, *clone
;
2729 ImageType image_type
;
2730 LONG refcount
, old_refcount
;
2732 hmem
= GlobalAlloc(0, image_size
);
2733 data
= GlobalLock(hmem
);
2734 memcpy(data
, image_data
, image_size
);
2737 hr
= CreateStreamOnHGlobal(hmem
, TRUE
, &stream
);
2738 ok(hr
== S_OK
, "CreateStreamOnHGlobal error %#x\n", hr
);
2739 if (hr
!= S_OK
) return NULL
;
2741 refcount
= obj_refcount(stream
);
2742 ok(refcount
== 1, "expected stream refcount 1, got %d\n", refcount
);
2744 status
= GdipLoadImageFromStream(stream
, &image
);
2745 ok(status
== Ok
|| broken(status
== InvalidParameter
), /* XP */
2746 "GdipLoadImageFromStream error %d\n", status
);
2749 IStream_Release(stream
);
2753 status
= GdipGetImageType(image
, &image_type
);
2754 ok(status
== Ok
, "GdipGetImageType error %d\n", status
);
2756 refcount
= obj_refcount(stream
);
2757 if (image_type
== ImageTypeBitmap
)
2758 ok(refcount
> 1, "expected stream refcount > 1, got %d\n", refcount
);
2760 ok(refcount
== 1, "expected stream refcount 1, got %d\n", refcount
);
2761 old_refcount
= refcount
;
2763 status
= GdipCloneImage(image
, &clone
);
2764 ok(status
== Ok
, "GdipCloneImage error %d\n", status
);
2765 refcount
= obj_refcount(stream
);
2766 ok(refcount
== old_refcount
, "expected stream refcount %d, got %d\n", old_refcount
, refcount
);
2767 status
= GdipDisposeImage(clone
);
2768 ok(status
== Ok
, "GdipDisposeImage error %d\n", status
);
2769 refcount
= obj_refcount(stream
);
2770 ok(refcount
== old_refcount
, "expected stream refcount %d, got %d\n", old_refcount
, refcount
);
2772 refcount
= IStream_Release(stream
);
2773 if (image_type
== ImageTypeBitmap
)
2774 ok(refcount
>= 1, "expected stream refcount != 0\n");
2776 ok(refcount
== 0, "expected stream refcount 0, got %d\n", refcount
);
2781 static void test_image_properties(void)
2783 static const struct test_data
2785 const BYTE
*image_data
;
2787 ImageType image_type
;
2789 UINT prop_count2
; /* if win7 behaves differently */
2790 /* 1st property attributes */
2792 UINT prop_size2
; /* if win7 behaves differently */
2794 UINT prop_id2
; /* if win7 behaves differently */
2798 { pngimage
, sizeof(pngimage
), ImageTypeBitmap
, 4, ~0, 1, 20, 0x5110, 0x132 },
2799 { jpgimage
, sizeof(jpgimage
), ImageTypeBitmap
, 2, ~0, 128, 0, 0x5090, 0x5091 },
2800 { tiffimage
, sizeof(tiffimage
), ImageTypeBitmap
, 16, 0, 4, 0, 0xfe, 0 },
2801 { bmpimage
, sizeof(bmpimage
), ImageTypeBitmap
, 0, 0, 0, 0, 0, 0 },
2802 { wmfimage
, sizeof(wmfimage
), ImageTypeMetafile
, 0, 0, 0, 0, 0, 0 }
2806 UINT prop_count
, prop_size
, i
;
2807 PROPID prop_id
[16] = { 0 };
2808 ImageType image_type
;
2815 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
2817 image
= load_image(td
[i
].image_data
, td
[i
].image_size
);
2820 trace("%u: failed to load image data\n", i
);
2824 status
= GdipGetImageType(image
, &image_type
);
2825 ok(status
== Ok
, "%u: GdipGetImageType error %d\n", i
, status
);
2826 ok(td
[i
].image_type
== image_type
, "%u: expected image_type %d, got %d\n",
2827 i
, td
[i
].image_type
, image_type
);
2829 status
= GdipGetPropertyCount(image
, &prop_count
);
2830 ok(status
== Ok
, "%u: GdipGetPropertyCount error %d\n", i
, status
);
2831 if (td
[i
].image_data
== pngimage
|| td
[i
].image_data
== jpgimage
)
2833 ok(td
[i
].prop_count
== prop_count
|| td
[i
].prop_count2
== prop_count
,
2834 " %u: expected property count %u or %u, got %u\n",
2835 i
, td
[i
].prop_count
, td
[i
].prop_count2
, prop_count
);
2837 ok(td
[i
].prop_count
== prop_count
|| td
[i
].prop_count2
== prop_count
,
2838 " %u: expected property count %u or %u, got %u\n",
2839 i
, td
[i
].prop_count
, td
[i
].prop_count2
, prop_count
);
2841 status
= GdipGetPropertyItemSize(NULL
, 0, &prop_size
);
2842 expect(InvalidParameter
, status
);
2843 status
= GdipGetPropertyItemSize(image
, 0, NULL
);
2844 expect(InvalidParameter
, status
);
2845 status
= GdipGetPropertyItemSize(image
, 0, &prop_size
);
2846 if (image_type
== ImageTypeMetafile
)
2847 expect(NotImplemented
, status
);
2849 expect(PropertyNotFound
, status
);
2851 status
= GdipGetPropertyItem(NULL
, 0, 0, &item
.data
);
2852 expect(InvalidParameter
, status
);
2853 status
= GdipGetPropertyItem(image
, 0, 0, NULL
);
2854 expect(InvalidParameter
, status
);
2855 status
= GdipGetPropertyItem(image
, 0, 0, &item
.data
);
2856 if (image_type
== ImageTypeMetafile
)
2857 expect(NotImplemented
, status
);
2859 expect(PropertyNotFound
, status
);
2861 /* FIXME: remove once Wine is fixed */
2862 if (td
[i
].prop_count
!= prop_count
)
2864 GdipDisposeImage(image
);
2868 status
= GdipGetPropertyIdList(NULL
, prop_count
, prop_id
);
2869 expect(InvalidParameter
, status
);
2870 status
= GdipGetPropertyIdList(image
, prop_count
, NULL
);
2871 expect(InvalidParameter
, status
);
2872 status
= GdipGetPropertyIdList(image
, 0, prop_id
);
2873 if (image_type
== ImageTypeMetafile
)
2874 expect(NotImplemented
, status
);
2875 else if (prop_count
== 0)
2878 expect(InvalidParameter
, status
);
2879 status
= GdipGetPropertyIdList(image
, prop_count
- 1, prop_id
);
2880 if (image_type
== ImageTypeMetafile
)
2881 expect(NotImplemented
, status
);
2883 expect(InvalidParameter
, status
);
2884 status
= GdipGetPropertyIdList(image
, prop_count
+ 1, prop_id
);
2885 if (image_type
== ImageTypeMetafile
)
2886 expect(NotImplemented
, status
);
2888 expect(InvalidParameter
, status
);
2889 status
= GdipGetPropertyIdList(image
, prop_count
, prop_id
);
2890 if (image_type
== ImageTypeMetafile
)
2891 expect(NotImplemented
, status
);
2895 if (prop_count
!= 0)
2896 ok(td
[i
].prop_id
== prop_id
[0] || td
[i
].prop_id2
== prop_id
[0],
2897 " %u: expected property id %#x or %#x, got %#x\n",
2898 i
, td
[i
].prop_id
, td
[i
].prop_id2
, prop_id
[0]);
2903 status
= GdipGetPropertyItemSize(image
, prop_id
[0], &prop_size
);
2904 if (prop_count
== 0)
2905 expect(PropertyNotFound
, status
);
2910 assert(sizeof(item
) >= prop_size
);
2911 ok(prop_size
> sizeof(PropertyItem
), "%u: got too small prop_size %u\n",
2913 ok(td
[i
].prop_size
+ sizeof(PropertyItem
) == prop_size
||
2914 td
[i
].prop_size2
+ sizeof(PropertyItem
) == prop_size
,
2915 " %u: expected property size %u or %u, got %u\n",
2916 i
, td
[i
].prop_size
, td
[i
].prop_size2
, prop_size
);
2918 status
= GdipGetPropertyItem(image
, prop_id
[0], 0, &item
.data
);
2919 ok(status
== InvalidParameter
|| status
== GenericError
/* Win7 */,
2920 "%u: expected InvalidParameter, got %d\n", i
, status
);
2921 status
= GdipGetPropertyItem(image
, prop_id
[0], prop_size
- 1, &item
.data
);
2922 ok(status
== InvalidParameter
|| status
== GenericError
/* Win7 */,
2923 "%u: expected InvalidParameter, got %d\n", i
, status
);
2924 status
= GdipGetPropertyItem(image
, prop_id
[0], prop_size
+ 1, &item
.data
);
2925 ok(status
== InvalidParameter
|| status
== GenericError
/* Win7 */,
2926 "%u: expected InvalidParameter, got %d\n", i
, status
);
2927 status
= GdipGetPropertyItem(image
, prop_id
[0], prop_size
, &item
.data
);
2929 ok(prop_id
[0] == item
.data
.id
,
2930 "%u: expected property id %#x, got %#x\n", i
, prop_id
[0], item
.data
.id
);
2934 GdipDisposeImage(image
);
2942 #define IFD_RATIONAL 5
2944 #define IFD_UNDEFINED 7
2945 #define IFD_SSHORT 8
2947 #define IFD_SRATIONAL 10
2948 #define IFD_FLOAT 11
2949 #define IFD_DOUBLE 12
2951 #ifndef PropertyTagTypeSByte
2952 #define PropertyTagTypeSByte 6
2953 #define PropertyTagTypeSShort 8
2954 #define PropertyTagTypeFloat 11
2955 #define PropertyTagTypeDouble 12
2958 static UINT
documented_type(UINT type
)
2962 case PropertyTagTypeSByte
: return PropertyTagTypeByte
;
2963 case PropertyTagTypeSShort
: return PropertyTagTypeShort
;
2964 case PropertyTagTypeFloat
: return PropertyTagTypeUndefined
;
2965 case PropertyTagTypeDouble
: return PropertyTagTypeUndefined
;
2966 default: return type
;
2970 #include "pshpack2.h"
2985 static const struct tiff_data
2990 USHORT number_of_entries
;
2991 struct IFD_entry entry
[40];
2993 struct IFD_rational xres
;
2995 struct IFD_rational srational_val
;
3000 struct IFD_rational rational
[3];
3004 #ifdef WORDS_BIGENDIAN
3010 FIELD_OFFSET(struct tiff_data
, number_of_entries
),
3013 { 0xff, IFD_SHORT
, 1, 0 }, /* SUBFILETYPE */
3014 { 0x100, IFD_LONG
, 1, 1 }, /* IMAGEWIDTH */
3015 { 0x101, IFD_LONG
, 1, 1 }, /* IMAGELENGTH */
3016 { 0x102, IFD_SHORT
, 1, 1 }, /* BITSPERSAMPLE */
3017 { 0x103, IFD_SHORT
, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
3018 { 0x106, IFD_SHORT
, 1, 1 }, /* PHOTOMETRIC */
3019 { 0x111, IFD_LONG
, 1, FIELD_OFFSET(struct tiff_data
, pixel_data
) }, /* STRIPOFFSETS */
3020 { 0x115, IFD_SHORT
, 1, 1 }, /* SAMPLESPERPIXEL */
3021 { 0x116, IFD_LONG
, 1, 1 }, /* ROWSPERSTRIP */
3022 { 0x117, IFD_LONG
, 1, 1 }, /* STRIPBYTECOUNT */
3023 { 0x11a, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_data
, xres
) },
3024 { 0x11b, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_data
, xres
) },
3025 { 0x128, IFD_SHORT
, 1, 2 }, /* RESOLUTIONUNIT */
3026 { 0xf001, IFD_BYTE
, 1, 0x11223344 },
3027 { 0xf002, IFD_BYTE
, 4, 0x11223344 },
3028 { 0xf003, IFD_SBYTE
, 1, 0x11223344 },
3029 { 0xf004, IFD_SSHORT
, 1, 0x11223344 },
3030 { 0xf005, IFD_SSHORT
, 2, 0x11223344 },
3031 { 0xf006, IFD_SLONG
, 1, 0x11223344 },
3032 { 0xf007, IFD_FLOAT
, 1, 0x11223344 },
3033 { 0xf008, IFD_DOUBLE
, 1, FIELD_OFFSET(struct tiff_data
, double_val
) },
3034 { 0xf009, IFD_SRATIONAL
, 1, FIELD_OFFSET(struct tiff_data
, srational_val
) },
3035 { 0xf00a, IFD_BYTE
, 13, FIELD_OFFSET(struct tiff_data
, string
) },
3036 { 0xf00b, IFD_SSHORT
, 4, FIELD_OFFSET(struct tiff_data
, short_val
) },
3037 { 0xf00c, IFD_SLONG
, 2, FIELD_OFFSET(struct tiff_data
, long_val
) },
3038 { 0xf00e, IFD_ASCII
, 13, FIELD_OFFSET(struct tiff_data
, string
) },
3039 { 0xf00f, IFD_ASCII
, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
3040 { 0xf010, IFD_UNDEFINED
, 13, FIELD_OFFSET(struct tiff_data
, string
) },
3041 { 0xf011, IFD_UNDEFINED
, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
3042 /* Some gdiplus versions ignore these fields.
3043 { 0xf012, IFD_BYTE, 0, 0x11223344 },
3044 { 0xf013, IFD_SHORT, 0, 0x11223344 },
3045 { 0xf014, IFD_LONG, 0, 0x11223344 },
3046 { 0xf015, IFD_FLOAT, 0, 0x11223344 },*/
3047 { 0xf016, IFD_SRATIONAL
, 3, FIELD_OFFSET(struct tiff_data
, rational
) },
3048 /* Win7 before SP1 doesn't recognize this field, everybody else does. */
3049 { 0xf017, IFD_FLOAT
, 2, FIELD_OFFSET(struct tiff_data
, float_val
) },
3053 1234567890.0987654321,
3054 { 0x1a2b3c4d, 0x5a6b7c8d },
3056 { 0x0101, 0x0202, 0x0303, 0x0404 },
3057 { 0x11223344, 0x55667788 },
3058 { (FLOAT
)1234.5678, (FLOAT
)8765.4321 },
3059 { { 0x01020304, 0x05060708 }, { 0x10203040, 0x50607080 }, { 0x11223344, 0x55667788 } },
3060 { 0x11, 0x22, 0x33, 0 }
3062 #include "poppack.h"
3064 static void test_tiff_properties(void)
3066 static const struct test_data
3068 ULONG type
, id
, length
;
3069 const BYTE value
[24];
3072 { PropertyTagTypeShort
, 0xff, 2, { 0 } },
3073 { PropertyTagTypeLong
, 0x100, 4, { 1 } },
3074 { PropertyTagTypeLong
, 0x101, 4, { 1 } },
3075 { PropertyTagTypeShort
, 0x102, 2, { 1 } },
3076 { PropertyTagTypeShort
, 0x103, 2, { 1 } },
3077 { PropertyTagTypeShort
, 0x106, 2, { 1 } },
3078 { PropertyTagTypeLong
, 0x111, 4, { 0x44,0x02 } },
3079 { PropertyTagTypeShort
, 0x115, 2, { 1 } },
3080 { PropertyTagTypeLong
, 0x116, 4, { 1 } },
3081 { PropertyTagTypeLong
, 0x117, 4, { 1 } },
3082 { PropertyTagTypeRational
, 0x11a, 8, { 0x84,0x03,0,0,0x03 } },
3083 { PropertyTagTypeRational
, 0x11b, 8, { 0x84,0x03,0,0,0x03 } },
3084 { PropertyTagTypeShort
, 0x128, 2, { 2 } },
3085 { PropertyTagTypeByte
, 0xf001, 1, { 0x44 } },
3086 { PropertyTagTypeByte
, 0xf002, 4, { 0x44,0x33,0x22,0x11 } },
3087 { PropertyTagTypeSByte
, 0xf003, 1, { 0x44 } },
3088 { PropertyTagTypeSShort
, 0xf004, 2, { 0x44,0x33 } },
3089 { PropertyTagTypeSShort
, 0xf005, 4, { 0x44,0x33,0x22,0x11 } },
3090 { PropertyTagTypeSLONG
, 0xf006, 4, { 0x44,0x33,0x22,0x11 } },
3091 { PropertyTagTypeFloat
, 0xf007, 4, { 0x44,0x33,0x22,0x11 } },
3092 { PropertyTagTypeDouble
, 0xf008, 8, { 0x2c,0x52,0x86,0xb4,0x80,0x65,0xd2,0x41 } },
3093 { PropertyTagTypeSRational
, 0xf009, 8, { 0x4d, 0x3c, 0x2b, 0x1a, 0x8d, 0x7c, 0x6b, 0x5a } },
3094 { PropertyTagTypeByte
, 0xf00a, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3095 { PropertyTagTypeSShort
, 0xf00b, 8, { 0x01,0x01,0x02,0x02,0x03,0x03,0x04,0x04 } },
3096 { PropertyTagTypeSLONG
, 0xf00c, 8, { 0x44,0x33,0x22,0x11,0x88,0x77,0x66,0x55 } },
3097 { PropertyTagTypeASCII
, 0xf00e, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3098 { PropertyTagTypeASCII
, 0xf00f, 5, { 'a','b','c','d' } },
3099 { PropertyTagTypeUndefined
, 0xf010, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3100 { PropertyTagTypeUndefined
, 0xf011, 4, { 'a','b','c','d' } },
3101 { PropertyTagTypeSRational
, 0xf016, 24,
3102 { 0x04,0x03,0x02,0x01,0x08,0x07,0x06,0x05,
3103 0x40,0x30,0x20,0x10,0x80,0x70,0x60,0x50,
3104 0x44,0x33,0x22,0x11,0x88,0x77,0x66,0x55 } },
3105 /* Win7 before SP1 doesn't recognize this field, everybody else does. */
3106 { PropertyTagTypeFloat
, 0xf017, 8, { 0x2b,0x52,0x9a,0x44,0xba,0xf5,0x08,0x46 } },
3111 UINT dim_count
, frame_count
, prop_count
, prop_size
, i
;
3113 PropertyItem
*prop_item
;
3115 image
= load_image((const BYTE
*)&TIFF_data
, sizeof(TIFF_data
));
3118 win_skip("Failed to load TIFF image data. Might not be supported. Skipping.\n");
3122 status
= GdipImageGetFrameDimensionsCount(image
, &dim_count
);
3124 expect(1, dim_count
);
3126 status
= GdipImageGetFrameDimensionsList(image
, &guid
, 1);
3128 expect_guid(&FrameDimensionPage
, &guid
, __LINE__
, FALSE
);
3130 frame_count
= 0xdeadbeef;
3131 status
= GdipImageGetFrameCount(image
, &guid
, &frame_count
);
3133 expect(1, frame_count
);
3135 prop_count
= 0xdeadbeef;
3136 status
= GdipGetPropertyCount(image
, &prop_count
);
3138 ok(prop_count
== sizeof(td
)/sizeof(td
[0]) ||
3139 broken(prop_count
== sizeof(td
)/sizeof(td
[0]) - 1) /* Win7 SP0 */,
3140 "expected property count %u, got %u\n", (UINT
)(sizeof(td
)/sizeof(td
[0])), prop_count
);
3142 prop_id
= HeapAlloc(GetProcessHeap(), 0, prop_count
* sizeof(*prop_id
));
3144 status
= GdipGetPropertyIdList(image
, prop_count
, prop_id
);
3147 for (i
= 0; i
< prop_count
; i
++)
3149 status
= GdipGetPropertyItemSize(image
, prop_id
[i
], &prop_size
);
3151 if (status
!= Ok
) break;
3152 ok(prop_size
> sizeof(*prop_item
), "%u: too small item length %u\n", i
, prop_size
);
3154 prop_item
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, prop_size
);
3155 status
= GdipGetPropertyItem(image
, prop_id
[i
], prop_size
, prop_item
);
3157 ok(prop_item
->value
== prop_item
+ 1, "expected item->value %p, got %p\n", prop_item
+ 1, prop_item
->value
);
3158 ok(td
[i
].type
== prop_item
->type
||
3159 /* Win7 stopped using proper but not documented types, and it
3160 looks broken since TypeFloat and TypeDouble now reported as
3161 TypeUndefined, and signed types reported as unsigned. */
3162 broken(prop_item
->type
== documented_type(td
[i
].type
)),
3163 "%u: expected type %u, got %u\n", i
, td
[i
].type
, prop_item
->type
);
3164 ok(td
[i
].id
== prop_item
->id
, "%u: expected id %#x, got %#x\n", i
, td
[i
].id
, prop_item
->id
);
3165 prop_size
-= sizeof(*prop_item
);
3166 ok(prop_item
->length
== prop_size
, "%u: expected length %u, got %u\n", i
, prop_size
, prop_item
->length
);
3167 ok(td
[i
].length
== prop_item
->length
, "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_item
->length
);
3168 ok(td
[i
].length
== prop_size
, "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_size
);
3169 if (td
[i
].length
== prop_item
->length
)
3171 int match
= memcmp(td
[i
].value
, prop_item
->value
, td
[i
].length
) == 0;
3172 ok(match
|| broken(td
[i
].length
<= 4 && !match
), "%u: data mismatch\n", i
);
3176 BYTE
*data
= prop_item
->value
;
3177 printf("id %#x:", prop_item
->id
);
3178 for (j
= 0; j
< prop_item
->length
; j
++)
3179 printf(" %02x", data
[j
]);
3183 HeapFree(GetProcessHeap(), 0, prop_item
);
3186 HeapFree(GetProcessHeap(), 0, prop_id
);
3188 GdipDisposeImage(image
);
3191 static void test_GdipGetAllPropertyItems(void)
3193 static const struct test_data
3195 ULONG type
, id
, length
;
3199 { PropertyTagTypeLong
, 0xfe, 4, { 0 } },
3200 { PropertyTagTypeShort
, 0x100, 2, { 1 } },
3201 { PropertyTagTypeShort
, 0x101, 2, { 1 } },
3202 { PropertyTagTypeShort
, 0x102, 6, { 8,0,8,0,8,0 } },
3203 { PropertyTagTypeShort
, 0x103, 2, { 1 } },
3204 { PropertyTagTypeShort
, 0x106, 2, { 2,0 } },
3205 { PropertyTagTypeASCII
, 0x10d, 27, "/home/meh/Desktop/test.tif" },
3206 { PropertyTagTypeLong
, 0x111, 4, { 8,0,0,0 } },
3207 { PropertyTagTypeShort
, 0x112, 2, { 1 } },
3208 { PropertyTagTypeShort
, 0x115, 2, { 3,0 } },
3209 { PropertyTagTypeShort
, 0x116, 2, { 0x40,0 } },
3210 { PropertyTagTypeLong
, 0x117, 4, { 3,0,0,0 } },
3211 { PropertyTagTypeRational
, 0x11a, 8, { 0,0,0,72,0,0,0,1 } },
3212 { PropertyTagTypeRational
, 0x11b, 8, { 0,0,0,72,0,0,0,1 } },
3213 { PropertyTagTypeShort
, 0x11c, 2, { 1 } },
3214 { PropertyTagTypeShort
, 0x128, 2, { 2 } }
3219 UINT dim_count
, frame_count
, prop_count
, prop_size
, i
;
3220 UINT total_size
, total_count
;
3222 PropertyItem
*prop_item
;
3223 const char *item_data
;
3225 image
= load_image(tiffimage
, sizeof(tiffimage
));
3226 ok(image
!= 0, "Failed to load TIFF image data\n");
3229 dim_count
= 0xdeadbeef;
3230 status
= GdipImageGetFrameDimensionsCount(image
, &dim_count
);
3232 expect(1, dim_count
);
3234 status
= GdipImageGetFrameDimensionsList(image
, &guid
, 1);
3236 expect_guid(&FrameDimensionPage
, &guid
, __LINE__
, FALSE
);
3238 frame_count
= 0xdeadbeef;
3239 status
= GdipImageGetFrameCount(image
, &guid
, &frame_count
);
3241 expect(1, frame_count
);
3243 prop_count
= 0xdeadbeef;
3244 status
= GdipGetPropertyCount(image
, &prop_count
);
3246 ok(prop_count
== sizeof(td
)/sizeof(td
[0]),
3247 "expected property count %u, got %u\n", (UINT
)(sizeof(td
)/sizeof(td
[0])), prop_count
);
3249 prop_id
= HeapAlloc(GetProcessHeap(), 0, prop_count
* sizeof(*prop_id
));
3251 status
= GdipGetPropertyIdList(image
, prop_count
, prop_id
);
3255 for (i
= 0; i
< prop_count
; i
++)
3258 status
= GdipGetPropertyItemSize(image
, prop_id
[i
], &size
);
3260 if (status
!= Ok
) break;
3261 ok(size
> sizeof(*prop_item
), "%u: too small item length %u\n", i
, size
);
3265 prop_item
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
3266 status
= GdipGetPropertyItem(image
, prop_id
[i
], size
, prop_item
);
3268 ok(prop_item
->value
== prop_item
+ 1, "expected item->value %p, got %p\n", prop_item
+ 1, prop_item
->value
);
3269 ok(td
[i
].type
== prop_item
->type
,
3270 "%u: expected type %u, got %u\n", i
, td
[i
].type
, prop_item
->type
);
3271 ok(td
[i
].id
== prop_item
->id
, "%u: expected id %#x, got %#x\n", i
, td
[i
].id
, prop_item
->id
);
3272 size
-= sizeof(*prop_item
);
3273 ok(prop_item
->length
== size
, "%u: expected length %u, got %u\n", i
, size
, prop_item
->length
);
3274 ok(td
[i
].length
== prop_item
->length
, "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_item
->length
);
3275 if (td
[i
].length
== prop_item
->length
)
3277 int match
= memcmp(td
[i
].value
, prop_item
->value
, td
[i
].length
) == 0;
3278 ok(match
, "%u: data mismatch\n", i
);
3282 BYTE
*data
= prop_item
->value
;
3283 printf("id %#x:", prop_item
->id
);
3284 for (j
= 0; j
< prop_item
->length
; j
++)
3285 printf(" %02x", data
[j
]);
3289 HeapFree(GetProcessHeap(), 0, prop_item
);
3292 HeapFree(GetProcessHeap(), 0, prop_id
);
3294 status
= GdipGetPropertySize(NULL
, &total_size
, &total_count
);
3295 expect(InvalidParameter
, status
);
3296 status
= GdipGetPropertySize(image
, &total_size
, NULL
);
3297 expect(InvalidParameter
, status
);
3298 status
= GdipGetPropertySize(image
, NULL
, &total_count
);
3299 expect(InvalidParameter
, status
);
3300 status
= GdipGetPropertySize(image
, NULL
, NULL
);
3301 expect(InvalidParameter
, status
);
3302 total_size
= 0xdeadbeef;
3303 total_count
= 0xdeadbeef;
3304 status
= GdipGetPropertySize(image
, &total_size
, &total_count
);
3306 ok(prop_count
== total_count
,
3307 "expected total property count %u, got %u\n", prop_count
, total_count
);
3308 ok(prop_size
== total_size
,
3309 "expected total property size %u, got %u\n", prop_size
, total_size
);
3311 prop_item
= HeapAlloc(GetProcessHeap(), 0, prop_size
);
3313 status
= GdipGetAllPropertyItems(image
, 0, prop_count
, prop_item
);
3314 expect(InvalidParameter
, status
);
3315 status
= GdipGetAllPropertyItems(image
, prop_size
, 1, prop_item
);
3316 expect(InvalidParameter
, status
);
3317 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, NULL
);
3318 expect(InvalidParameter
, status
);
3319 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, NULL
);
3320 expect(InvalidParameter
, status
);
3321 status
= GdipGetAllPropertyItems(image
, 0, 0, NULL
);
3322 expect(InvalidParameter
, status
);
3323 status
= GdipGetAllPropertyItems(image
, prop_size
+ 1, prop_count
, prop_item
);
3324 expect(InvalidParameter
, status
);
3325 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, prop_item
);
3328 item_data
= (const char *)(prop_item
+ prop_count
);
3329 for (i
= 0; i
< prop_count
; i
++)
3331 ok(prop_item
[i
].value
== item_data
, "%u: expected value %p, got %p\n",
3332 i
, item_data
, prop_item
[i
].value
);
3333 ok(td
[i
].type
== prop_item
[i
].type
,
3334 "%u: expected type %u, got %u\n", i
, td
[i
].type
, prop_item
[i
].type
);
3335 ok(td
[i
].id
== prop_item
[i
].id
, "%u: expected id %#x, got %#x\n", i
, td
[i
].id
, prop_item
[i
].id
);
3336 ok(td
[i
].length
== prop_item
[i
].length
, "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_item
[i
].length
);
3337 if (td
[i
].length
== prop_item
[i
].length
)
3339 int match
= memcmp(td
[i
].value
, prop_item
[i
].value
, td
[i
].length
) == 0;
3340 ok(match
, "%u: data mismatch\n", i
);
3344 BYTE
*data
= prop_item
[i
].value
;
3345 printf("id %#x:", prop_item
[i
].id
);
3346 for (j
= 0; j
< prop_item
[i
].length
; j
++)
3347 printf(" %02x", data
[j
]);
3351 item_data
+= prop_item
[i
].length
;
3354 HeapFree(GetProcessHeap(), 0, prop_item
);
3356 GdipDisposeImage(image
);
3359 static void test_tiff_palette(void)
3370 ARGB
*entries
= palette
.pal
.Entries
;
3372 /* 1bpp TIFF without palette */
3373 image
= load_image((const BYTE
*)&TIFF_data
, sizeof(TIFF_data
));
3376 win_skip("Failed to load TIFF image data. Might not be supported. Skipping.\n");
3380 status
= GdipGetImagePixelFormat(image
, &format
);
3382 ok(format
== PixelFormat1bppIndexed
, "expected PixelFormat1bppIndexed, got %#x\n", format
);
3384 status
= GdipGetImagePaletteSize(image
, &size
);
3385 ok(status
== Ok
|| broken(status
== GenericError
), /* XP */
3386 "GdipGetImagePaletteSize error %d\n", status
);
3387 if (status
== GenericError
)
3389 GdipDisposeImage(image
);
3392 expect(sizeof(ColorPalette
) + sizeof(ARGB
), size
);
3394 status
= GdipGetImagePalette(image
, &palette
.pal
, size
);
3396 expect(0, palette
.pal
.Flags
);
3397 expect(2, palette
.pal
.Count
);
3398 if (palette
.pal
.Count
== 2)
3400 ok(entries
[0] == 0xff000000, "expected 0xff000000, got %#x\n", entries
[0]);
3401 ok(entries
[1] == 0xffffffff, "expected 0xffffffff, got %#x\n", entries
[1]);
3404 GdipDisposeImage(image
);
3407 static void test_bitmapbits(void)
3410 static const BYTE pixels_24
[48] =
3412 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3413 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3414 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3415 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0
3417 static const BYTE pixels_00
[48] =
3419 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3420 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3421 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3422 0,0,0, 0,0,0, 0,0,0, 0,0,0
3424 static const BYTE pixels_24_77
[64] =
3426 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3427 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3428 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3429 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3430 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3431 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3433 static const BYTE pixels_77
[64] =
3435 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3436 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3437 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3438 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3439 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3440 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3441 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3442 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3444 static const BYTE pixels_8
[16] =
3446 0x01,0,0x01,0,0x01,0,0x01,0,
3447 0x01,0,0x01,0,0x01,0,0x01,0
3449 static const BYTE pixels_8_77
[64] =
3451 0x01,0,0x01,0,0x01,0,0x01,0,
3452 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3453 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3454 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3455 0x01,0,0x01,0,0x01,0,0x01,0,
3456 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3457 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3458 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3460 static const BYTE pixels_1_77
[64] =
3462 0xaa,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3463 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3464 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3465 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3466 0xaa,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3467 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3468 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3469 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3471 static const BYTE pixels_1
[8] = {0xaa,0,0,0,0xaa,0,0,0};
3472 static const struct test_data
3479 const BYTE
*pixels_unlocked
;
3483 { PixelFormat24bppRGB
, 24, 0xfff0, 24, 48, pixels_24
, pixels_00
},
3485 { PixelFormat24bppRGB
, 24, 0, 24, 48, pixels_24
, pixels_00
},
3486 { PixelFormat24bppRGB
, 24, ImageLockModeRead
, 24, 48, pixels_24
, pixels_00
},
3487 { PixelFormat24bppRGB
, 24, ImageLockModeWrite
, 24, 48, pixels_24
, pixels_00
},
3488 { PixelFormat24bppRGB
, 24, ImageLockModeRead
|ImageLockModeWrite
, 24, 48, pixels_24
, pixels_00
},
3489 { PixelFormat24bppRGB
, 24, ImageLockModeRead
|ImageLockModeUserInputBuf
, 32, 64, pixels_24_77
, pixels_24
},
3490 { PixelFormat24bppRGB
, 24, ImageLockModeWrite
|ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_00
},
3491 { PixelFormat24bppRGB
, 24, ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_24
},
3493 { PixelFormat8bppIndexed
, 8, 0, 8, 16, pixels_8
, pixels_24
},
3494 { PixelFormat8bppIndexed
, 8, ImageLockModeRead
, 8, 16, pixels_8
, pixels_24
},
3495 { PixelFormat8bppIndexed
, 8, ImageLockModeWrite
, 8, 16, pixels_8
, pixels_00
},
3496 { PixelFormat8bppIndexed
, 8, ImageLockModeRead
|ImageLockModeWrite
, 8, 16, pixels_8
, pixels_00
},
3497 { PixelFormat8bppIndexed
, 8, ImageLockModeRead
|ImageLockModeUserInputBuf
, 32, 64, pixels_8_77
, pixels_24
},
3498 { PixelFormat8bppIndexed
, 8, ImageLockModeWrite
|ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_00
},
3499 { PixelFormat8bppIndexed
, 8, ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_24
},
3501 { PixelFormat1bppIndexed
, 1, 0, 4, 8, pixels_1
, pixels_24
},
3502 { PixelFormat1bppIndexed
, 1, ImageLockModeRead
, 4, 8, pixels_1
, pixels_24
},
3503 { PixelFormat1bppIndexed
, 1, ImageLockModeWrite
, 4, 8, pixels_1
, pixels_00
},
3504 { PixelFormat1bppIndexed
, 1, ImageLockModeRead
|ImageLockModeWrite
, 4, 8, pixels_1
, pixels_00
},
3505 { PixelFormat1bppIndexed
, 1, ImageLockModeRead
|ImageLockModeUserInputBuf
, 32, 64, pixels_1_77
, pixels_24
},
3506 { PixelFormat1bppIndexed
, 1, ImageLockModeWrite
|ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_00
},
3507 { PixelFormat1bppIndexed
, 1, ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_24
},
3519 ARGB
*entries
= palette
.pal
.Entries
;
3521 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
3523 BYTE pixels
[sizeof(pixels_24
)];
3524 memcpy(pixels
, pixels_24
, sizeof(pixels_24
));
3525 status
= GdipCreateBitmapFromScan0(8, 2, 24, PixelFormat24bppRGB
, pixels
, &bitmap
);
3528 /* associate known palette with pixel data */
3529 palette
.pal
.Flags
= PaletteFlagsGrayScale
;
3530 palette
.pal
.Count
= 2;
3531 entries
[0] = 0xff000000;
3532 entries
[1] = 0xffffffff;
3533 status
= GdipSetImagePalette((GpImage
*)bitmap
, &palette
.pal
);
3536 memset(&data
, 0xfe, sizeof(data
));
3537 if (td
[i
].mode
& ImageLockModeUserInputBuf
)
3539 memset(buf
, 0x77, sizeof(buf
));
3543 status
= GdipBitmapLockBits(bitmap
, NULL
, td
[i
].mode
, td
[i
].format
, &data
);
3544 ok(status
== Ok
|| broken(status
== InvalidParameter
) /* XP */, "%u: GdipBitmapLockBits error %d\n", i
, status
);
3547 GdipDisposeImage((GpImage
*)bitmap
);
3550 ok(data
.Width
== 8, "%u: expected 8, got %d\n", i
, data
.Width
);
3551 ok(data
.Height
== 2, "%u: expected 2, got %d\n", i
, data
.Height
);
3552 ok(td
[i
].stride
== data
.Stride
, "%u: expected %d, got %d\n", i
, td
[i
].stride
, data
.Stride
);
3553 ok(td
[i
].format
== data
.PixelFormat
, "%u: expected %d, got %d\n", i
, td
[i
].format
, data
.PixelFormat
);
3554 ok(td
[i
].size
== data
.Height
* data
.Stride
, "%u: expected %d, got %d\n", i
, td
[i
].size
, data
.Height
* data
.Stride
);
3555 if (td
[i
].mode
& ImageLockModeUserInputBuf
)
3556 ok(data
.Scan0
== buf
, "%u: got wrong buffer\n", i
);
3557 if (td
[i
].size
== data
.Height
* data
.Stride
)
3559 UINT j
, match
, width_bytes
= (data
.Width
* td
[i
].bpp
) / 8;
3562 for (j
= 0; j
< data
.Height
; j
++)
3564 if (memcmp((const BYTE
*)data
.Scan0
+ j
* data
.Stride
, td
[i
].pixels
+ j
* data
.Stride
, width_bytes
) != 0)
3570 if ((td
[i
].mode
& (ImageLockModeRead
|ImageLockModeUserInputBuf
)) || td
[i
].format
== PixelFormat24bppRGB
)
3573 "%u: data should match\n", i
);
3576 BYTE
*bits
= data
.Scan0
;
3577 printf("%u: data mismatch for format %#x:", i
, td
[i
].format
);
3578 for (j
= 0; j
< td
[i
].size
; j
++)
3579 printf(" %02x", bits
[j
]);
3584 ok(!match
, "%u: data shouldn't match\n", i
);
3586 memset(data
.Scan0
, 0, td
[i
].size
);
3589 status
= GdipBitmapUnlockBits(bitmap
, &data
);
3590 ok(status
== Ok
, "%u: GdipBitmapUnlockBits error %d\n", i
, status
);
3592 memset(&data
, 0xfe, sizeof(data
));
3593 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat24bppRGB
, &data
);
3594 ok(status
== Ok
, "%u: GdipBitmapLockBits error %d\n", i
, status
);
3595 ok(data
.Width
== 8, "%u: expected 8, got %d\n", i
, data
.Width
);
3596 ok(data
.Height
== 2, "%u: expected 2, got %d\n", i
, data
.Height
);
3597 ok(data
.Stride
== 24, "%u: expected 24, got %d\n", i
, data
.Stride
);
3598 ok(data
.PixelFormat
== PixelFormat24bppRGB
, "%u: got wrong pixel format %d\n", i
, data
.PixelFormat
);
3599 ok(data
.Height
* data
.Stride
== 48, "%u: expected 48, got %d\n", i
, data
.Height
* data
.Stride
);
3600 if (data
.Height
* data
.Stride
== 48)
3602 int match
= memcmp(data
.Scan0
, td
[i
].pixels_unlocked
, 48) == 0;
3603 ok(match
, "%u: data should match\n", i
);
3607 BYTE
*bits
= data
.Scan0
;
3608 printf("%u: data mismatch for format %#x:", i
, td
[i
].format
);
3609 for (j
= 0; j
< 48; j
++)
3610 printf(" %02x", bits
[j
]);
3615 status
= GdipBitmapUnlockBits(bitmap
, &data
);
3616 ok(status
== Ok
, "%u: GdipBitmapUnlockBits error %d\n", i
, status
);
3618 status
= GdipDisposeImage((GpImage
*)bitmap
);
3623 static void test_DrawImage(void)
3625 BYTE black_1x1
[4] = { 0,0,0,0 };
3626 BYTE white_2x2
[16] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
3627 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
3628 BYTE black_2x2
[16] = { 0,0,0,0,0,0,0xff,0xff,
3629 0,0,0,0,0,0,0xff,0xff };
3636 GpGraphics
*graphics
;
3639 status
= GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB
, black_1x1
, &u1
.bitmap
);
3641 status
= GdipBitmapSetResolution(u1
.bitmap
, 100.0, 100.0);
3644 status
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat24bppRGB
, white_2x2
, &u2
.bitmap
);
3646 status
= GdipBitmapSetResolution(u2
.bitmap
, 300.0, 300.0);
3648 status
= GdipGetImageGraphicsContext(u2
.image
, &graphics
);
3650 status
= GdipSetInterpolationMode(graphics
, InterpolationModeNearestNeighbor
);
3653 status
= GdipDrawImageI(graphics
, u1
.image
, 0, 0);
3656 match
= memcmp(white_2x2
, black_2x2
, sizeof(black_2x2
)) == 0;
3657 ok(match
, "data should match\n");
3660 UINT i
, size
= sizeof(white_2x2
);
3661 BYTE
*bits
= white_2x2
;
3662 for (i
= 0; i
< size
; i
++)
3663 printf(" %02x", bits
[i
]);
3667 status
= GdipDeleteGraphics(graphics
);
3669 status
= GdipDisposeImage(u1
.image
);
3671 status
= GdipDisposeImage(u2
.image
);
3675 static void test_GdipDrawImagePointRect(void)
3677 BYTE black_1x1
[4] = { 0,0,0,0 };
3678 BYTE white_2x2
[16] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
3679 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
3680 BYTE black_2x2
[16] = { 0,0,0,0,0,0,0xff,0xff,
3681 0,0,0,0,0,0,0xff,0xff };
3688 GpGraphics
*graphics
;
3691 status
= GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB
, black_1x1
, &u1
.bitmap
);
3693 status
= GdipBitmapSetResolution(u1
.bitmap
, 100.0, 100.0);
3696 status
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat24bppRGB
, white_2x2
, &u2
.bitmap
);
3698 status
= GdipBitmapSetResolution(u2
.bitmap
, 300.0, 300.0);
3700 status
= GdipGetImageGraphicsContext(u2
.image
, &graphics
);
3702 status
= GdipSetInterpolationMode(graphics
, InterpolationModeNearestNeighbor
);
3705 status
= GdipDrawImagePointRectI(graphics
, u1
.image
, 0, 0, 0, 0, 1, 1, UnitPixel
);
3708 match
= memcmp(white_2x2
, black_2x2
, sizeof(black_2x2
)) == 0;
3709 ok(match
, "data should match\n");
3712 UINT i
, size
= sizeof(white_2x2
);
3713 BYTE
*bits
= white_2x2
;
3714 for (i
= 0; i
< size
; i
++)
3715 printf(" %02x", bits
[i
]);
3719 status
= GdipDeleteGraphics(graphics
);
3721 status
= GdipDisposeImage(u1
.image
);
3723 status
= GdipDisposeImage(u2
.image
);
3727 static void test_image_format(void)
3729 static const PixelFormat fmt
[] =
3731 PixelFormat1bppIndexed
, PixelFormat4bppIndexed
, PixelFormat8bppIndexed
,
3732 PixelFormat16bppGrayScale
, PixelFormat16bppRGB555
, PixelFormat16bppRGB565
,
3733 PixelFormat16bppARGB1555
, PixelFormat24bppRGB
, PixelFormat32bppRGB
,
3734 PixelFormat32bppARGB
, PixelFormat32bppPARGB
, PixelFormat48bppRGB
,
3735 PixelFormat64bppARGB
, PixelFormat64bppPARGB
, PixelFormat32bppCMYK
3746 for (i
= 0; i
< sizeof(fmt
)/sizeof(fmt
[0]); i
++)
3748 status
= GdipCreateBitmapFromScan0(1, 1, 0, fmt
[i
], NULL
, &bitmap
);
3749 ok(status
== Ok
|| broken(status
== InvalidParameter
) /* before win7 */,
3750 "GdipCreateBitmapFromScan0 error %d\n", status
);
3751 if (status
!= Ok
) continue;
3753 status
= GdipGetImagePixelFormat((GpImage
*)bitmap
, &format
);
3755 expect(fmt
[i
], format
);
3757 status
= GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3758 if (fmt
[i
] == PixelFormat16bppGrayScale
|| fmt
[i
] == PixelFormat32bppCMYK
)
3759 todo_wine
expect(InvalidParameter
, status
);
3763 ret
= GetObject(hbitmap
, sizeof(bm
), &bm
);
3764 expect(sizeof(bm
), ret
);
3765 expect(0, bm
.bmType
);
3766 expect(1, bm
.bmWidth
);
3767 expect(1, bm
.bmHeight
);
3768 expect(4, bm
.bmWidthBytes
);
3769 expect(1, bm
.bmPlanes
);
3770 expect(32, bm
.bmBitsPixel
);
3771 DeleteObject(hbitmap
);
3774 status
= GdipGetImageThumbnail((GpImage
*)bitmap
, 0, 0, &thumb
, NULL
, NULL
);
3775 if (fmt
[i
] == PixelFormat16bppGrayScale
|| fmt
[i
] == PixelFormat32bppCMYK
)
3777 ok(status
== OutOfMemory
|| broken(status
== InvalidParameter
) /* before win7 */,
3778 "expected OutOfMemory, got %d\n", status
);
3782 status
= GdipGetImagePixelFormat(thumb
, &format
);
3784 ok(format
== PixelFormat32bppPARGB
|| broken(format
!= PixelFormat32bppPARGB
) /* before win7 */,
3785 "expected PixelFormat32bppPARGB, got %#x\n", format
);
3786 status
= GdipDisposeImage(thumb
);
3790 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat32bppPARGB
, &data
);
3791 if (fmt
[i
] == PixelFormat16bppGrayScale
|| fmt
[i
] == PixelFormat32bppCMYK
)
3792 todo_wine
expect(InvalidParameter
, status
);
3796 status
= GdipBitmapUnlockBits(bitmap
, &data
);
3800 status
= GdipDisposeImage((GpImage
*)bitmap
);
3805 static void test_DrawImage_scale(void)
3807 static const BYTE back_8x1
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
3808 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3809 static const BYTE image_080
[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,
3810 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3811 static const BYTE image_100
[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40,
3812 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3813 static const BYTE image_120
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x40,0x40,0x40,
3814 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3815 static const BYTE image_150
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3816 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3817 static const BYTE image_180
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3818 0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3819 static const BYTE image_200
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3820 0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3821 static const BYTE image_250
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,
3822 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40 };
3823 static const BYTE image_120_half
[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
3824 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3825 static const BYTE image_150_half
[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
3826 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3827 static const BYTE image_200_half
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3828 0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40 };
3829 static const BYTE image_250_half
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3830 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40 };
3831 static const struct test_data
3834 PixelOffsetMode pixel_offset_mode
;
3839 { 0.8, PixelOffsetModeNone
, image_080
}, /* 0 */
3840 { 1.0, PixelOffsetModeNone
, image_100
},
3841 { 1.2, PixelOffsetModeNone
, image_120
},
3842 { 1.5, PixelOffsetModeNone
, image_150
},
3843 { 1.8, PixelOffsetModeNone
, image_180
},
3844 { 2.0, PixelOffsetModeNone
, image_200
},
3845 { 2.5, PixelOffsetModeNone
, image_250
},
3847 { 0.8, PixelOffsetModeHighSpeed
, image_080
}, /* 7 */
3848 { 1.0, PixelOffsetModeHighSpeed
, image_100
},
3849 { 1.2, PixelOffsetModeHighSpeed
, image_120
},
3850 { 1.5, PixelOffsetModeHighSpeed
, image_150
},
3851 { 1.8, PixelOffsetModeHighSpeed
, image_180
},
3852 { 2.0, PixelOffsetModeHighSpeed
, image_200
},
3853 { 2.5, PixelOffsetModeHighSpeed
, image_250
},
3855 { 0.8, PixelOffsetModeHalf
, image_080
}, /* 14 */
3856 { 1.0, PixelOffsetModeHalf
, image_100
},
3857 { 1.2, PixelOffsetModeHalf
, image_120_half
, TRUE
},
3858 { 1.5, PixelOffsetModeHalf
, image_150_half
, TRUE
},
3859 { 1.8, PixelOffsetModeHalf
, image_180
},
3860 { 2.0, PixelOffsetModeHalf
, image_200_half
, TRUE
},
3861 { 2.5, PixelOffsetModeHalf
, image_250_half
, TRUE
},
3863 { 0.8, PixelOffsetModeHighQuality
, image_080
}, /* 21 */
3864 { 1.0, PixelOffsetModeHighQuality
, image_100
},
3865 { 1.2, PixelOffsetModeHighQuality
, image_120_half
, TRUE
},
3866 { 1.5, PixelOffsetModeHighQuality
, image_150_half
, TRUE
},
3867 { 1.8, PixelOffsetModeHighQuality
, image_180
},
3868 { 2.0, PixelOffsetModeHighQuality
, image_200_half
, TRUE
},
3869 { 2.5, PixelOffsetModeHighQuality
, image_250_half
, TRUE
},
3871 BYTE src_2x1
[6] = { 0x80,0x80,0x80,0x80,0x80,0x80 };
3879 GpGraphics
*graphics
;
3883 status
= GdipCreateBitmapFromScan0(2, 1, 4, PixelFormat24bppRGB
, src_2x1
, &u1
.bitmap
);
3885 status
= GdipBitmapSetResolution(u1
.bitmap
, 100.0, 100.0);
3888 status
= GdipCreateBitmapFromScan0(8, 1, 24, PixelFormat24bppRGB
, dst_8x1
, &u2
.bitmap
);
3890 status
= GdipBitmapSetResolution(u2
.bitmap
, 100.0, 100.0);
3892 status
= GdipGetImageGraphicsContext(u2
.image
, &graphics
);
3894 status
= GdipSetInterpolationMode(graphics
, InterpolationModeNearestNeighbor
);
3897 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
3899 status
= GdipSetPixelOffsetMode(graphics
, td
[i
].pixel_offset_mode
);
3902 status
= GdipCreateMatrix2(td
[i
].scale_x
, 0.0, 0.0, 1.0, 0.0, 0.0, &matrix
);
3904 status
= GdipSetWorldTransform(graphics
, matrix
);
3906 GdipDeleteMatrix(matrix
);
3908 memcpy(dst_8x1
, back_8x1
, sizeof(dst_8x1
));
3909 status
= GdipDrawImageI(graphics
, u1
.image
, 1, 0);
3912 match
= memcmp(dst_8x1
, td
[i
].image
, sizeof(dst_8x1
)) == 0;
3913 if (!match
&& td
[i
].todo
)
3914 todo_wine
ok(match
, "%d: data should match\n", i
);
3916 ok(match
, "%d: data should match\n", i
);
3919 UINT i
, size
= sizeof(dst_8x1
);
3920 const BYTE
*bits
= dst_8x1
;
3921 for (i
= 0; i
< size
; i
++)
3922 printf(" %02x", bits
[i
]);
3927 status
= GdipDeleteGraphics(graphics
);
3929 status
= GdipDisposeImage(u1
.image
);
3931 status
= GdipDisposeImage(u2
.image
);
3935 static const BYTE animatedgif
[] = {
3936 'G','I','F','8','9','a',0x01,0x00,0x01,0x00,0xA1,0x02,0x00,
3937 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,
3938 /*0x21,0xFF,0x0B,'A','N','I','M','E','X','T','S','1','.','0',*/
3939 0x21,0xFF,0x0B,'N','E','T','S','C','A','P','E','2','.','0',
3940 0x03,0x01,0x05,0x00,0x00,
3941 0x21,0xFE,0x0C,'H','e','l','l','o',' ','W','o','r','l','d','!',0x00,
3942 0x21,0x01,0x0D,'a','n','i','m','a','t','i','o','n','.','g','i','f',0x00,
3943 0x21,0xF9,0x04,0xff,0x0A,0x00,0x08,0x00,
3944 0x2C,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
3945 0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,
3946 0x02,0x02,0x4C,0x01,0x00,
3947 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','1',0x00,
3948 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','1',0x00,
3949 0x21,0xF9,0x04,0x00,0x14,0x00,0x01,0x00,
3950 0x2C,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
3951 0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,
3952 0x02,0x02,0x44,0x01,0x00,
3953 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','2',0x00,
3954 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','2',0x00,0x3B
3957 static void test_gif_properties(void)
3959 static const struct test_data
3961 ULONG type
, id
, length
;
3962 const BYTE value
[13];
3965 { PropertyTagTypeLong
, PropertyTagFrameDelay
, 8, { 10,0,0,0,20,0,0,0 } },
3966 { PropertyTagTypeASCII
, PropertyTagExifUserComment
, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3967 { PropertyTagTypeShort
, PropertyTagLoopCount
, 2, { 5,0 } },
3968 { PropertyTagTypeByte
, PropertyTagGlobalPalette
, 12, { 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c } },
3969 { PropertyTagTypeByte
, PropertyTagIndexBackground
, 1, { 2 } },
3970 { PropertyTagTypeByte
, PropertyTagIndexTransparent
, 1, { 8 } }
3975 UINT dim_count
, frame_count
, prop_count
, prop_size
, i
;
3976 UINT total_size
, total_count
;
3978 PropertyItem
*prop_item
;
3979 const char *item_data
;
3981 image
= load_image(animatedgif
, sizeof(animatedgif
));
3982 if (!image
) /* XP fails to load this GIF image */
3984 trace("Failed to load GIF image data\n");
3988 status
= GdipImageGetFrameDimensionsCount(image
, &dim_count
);
3990 expect(1, dim_count
);
3992 status
= GdipImageGetFrameDimensionsList(image
, &guid
, 1);
3994 expect_guid(&FrameDimensionTime
, &guid
, __LINE__
, FALSE
);
3996 status
= GdipImageGetFrameCount(image
, &guid
, &frame_count
);
3998 expect(2, frame_count
);
4000 status
= GdipImageSelectActiveFrame(image
, &guid
, 1);
4003 status
= GdipGetPropertyCount(image
, &prop_count
);
4005 ok(prop_count
== sizeof(td
)/sizeof(td
[0]) || broken(prop_count
== 1) /* before win7 */,
4006 "expected property count %u, got %u\n", (UINT
)(sizeof(td
)/sizeof(td
[0])), prop_count
);
4008 if (prop_count
!= sizeof(td
)/sizeof(td
[0]))
4010 GdipDisposeImage(image
);
4014 prop_id
= HeapAlloc(GetProcessHeap(), 0, prop_count
* sizeof(*prop_id
));
4016 status
= GdipGetPropertyIdList(image
, prop_count
, prop_id
);
4020 for (i
= 0; i
< prop_count
; i
++)
4023 status
= GdipGetPropertyItemSize(image
, prop_id
[i
], &size
);
4025 if (status
!= Ok
) break;
4026 ok(size
> sizeof(*prop_item
), "%u: too small item length %u\n", i
, size
);
4030 prop_item
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
4031 status
= GdipGetPropertyItem(image
, prop_id
[i
], size
, prop_item
);
4033 ok(prop_item
->value
== prop_item
+ 1, "expected item->value %p, got %p\n", prop_item
+ 1, prop_item
->value
);
4034 ok(td
[i
].type
== prop_item
->type
,
4035 "%u: expected type %u, got %u\n", i
, td
[i
].type
, prop_item
->type
);
4036 ok(td
[i
].id
== prop_item
->id
, "%u: expected id %#x, got %#x\n", i
, td
[i
].id
, prop_item
->id
);
4037 size
-= sizeof(*prop_item
);
4038 ok(prop_item
->length
== size
, "%u: expected length %u, got %u\n", i
, size
, prop_item
->length
);
4039 ok(td
[i
].length
== prop_item
->length
, "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_item
->length
);
4040 if (td
[i
].length
== prop_item
->length
)
4042 int match
= memcmp(td
[i
].value
, prop_item
->value
, td
[i
].length
) == 0;
4043 ok(match
, "%u: data mismatch\n", i
);
4047 BYTE
*data
= prop_item
->value
;
4048 printf("id %#x:", prop_item
->id
);
4049 for (j
= 0; j
< prop_item
->length
; j
++)
4050 printf(" %02x", data
[j
]);
4054 HeapFree(GetProcessHeap(), 0, prop_item
);
4057 HeapFree(GetProcessHeap(), 0, prop_id
);
4059 status
= GdipGetPropertySize(NULL
, &total_size
, &total_count
);
4060 expect(InvalidParameter
, status
);
4061 status
= GdipGetPropertySize(image
, &total_size
, NULL
);
4062 expect(InvalidParameter
, status
);
4063 status
= GdipGetPropertySize(image
, NULL
, &total_count
);
4064 expect(InvalidParameter
, status
);
4065 status
= GdipGetPropertySize(image
, NULL
, NULL
);
4066 expect(InvalidParameter
, status
);
4067 total_size
= 0xdeadbeef;
4068 total_count
= 0xdeadbeef;
4069 status
= GdipGetPropertySize(image
, &total_size
, &total_count
);
4071 ok(prop_count
== total_count
,
4072 "expected total property count %u, got %u\n", prop_count
, total_count
);
4073 ok(prop_size
== total_size
,
4074 "expected total property size %u, got %u\n", prop_size
, total_size
);
4076 prop_item
= HeapAlloc(GetProcessHeap(), 0, prop_size
);
4078 status
= GdipGetAllPropertyItems(image
, 0, prop_count
, prop_item
);
4079 expect(InvalidParameter
, status
);
4080 status
= GdipGetAllPropertyItems(image
, prop_size
, 1, prop_item
);
4081 expect(InvalidParameter
, status
);
4082 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, NULL
);
4083 expect(InvalidParameter
, status
);
4084 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, NULL
);
4085 expect(InvalidParameter
, status
);
4086 status
= GdipGetAllPropertyItems(image
, 0, 0, NULL
);
4087 expect(InvalidParameter
, status
);
4088 status
= GdipGetAllPropertyItems(image
, prop_size
+ 1, prop_count
, prop_item
);
4089 expect(InvalidParameter
, status
);
4090 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, prop_item
);
4093 item_data
= (const char *)(prop_item
+ prop_count
);
4094 for (i
= 0; i
< prop_count
; i
++)
4096 ok(prop_item
[i
].value
== item_data
, "%u: expected value %p, got %p\n",
4097 i
, item_data
, prop_item
[i
].value
);
4098 ok(td
[i
].type
== prop_item
[i
].type
,
4099 "%u: expected type %u, got %u\n", i
, td
[i
].type
, prop_item
[i
].type
);
4100 ok(td
[i
].id
== prop_item
[i
].id
, "%u: expected id %#x, got %#x\n", i
, td
[i
].id
, prop_item
[i
].id
);
4101 ok(td
[i
].length
== prop_item
[i
].length
, "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_item
[i
].length
);
4102 if (td
[i
].length
== prop_item
[i
].length
)
4104 int match
= memcmp(td
[i
].value
, prop_item
[i
].value
, td
[i
].length
) == 0;
4105 ok(match
, "%u: data mismatch\n", i
);
4109 BYTE
*data
= prop_item
[i
].value
;
4110 printf("id %#x:", prop_item
[i
].id
);
4111 for (j
= 0; j
< prop_item
[i
].length
; j
++)
4112 printf(" %02x", data
[j
]);
4116 item_data
+= prop_item
[i
].length
;
4119 HeapFree(GetProcessHeap(), 0, prop_item
);
4121 GdipDisposeImage(image
);
4124 static void test_ARGB_conversion(void)
4126 BYTE argb
[8] = { 0x11,0x22,0x33,0x80, 0xff,0xff,0xff,0 };
4127 BYTE pargb
[8] = { 0x09,0x11,0x1a,0x80, 0,0,0,0 };
4128 BYTE rgb32_xp
[8] = { 0x11,0x22,0x33,0xff, 0xff,0xff,0xff,0xff };
4129 BYTE rgb24
[6] = { 0x11,0x22,0x33, 0xff,0xff,0xff };
4136 status
= GdipCreateBitmapFromScan0(2, 1, 8, PixelFormat32bppARGB
, argb
, &bitmap
);
4139 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat32bppPARGB
, &data
);
4141 ok(data
.Width
== 2, "expected 2, got %d\n", data
.Width
);
4142 ok(data
.Height
== 1, "expected 1, got %d\n", data
.Height
);
4143 ok(data
.Stride
== 8, "expected 8, got %d\n", data
.Stride
);
4144 ok(data
.PixelFormat
== PixelFormat32bppPARGB
, "expected PixelFormat32bppPARGB, got %d\n", data
.PixelFormat
);
4145 match
= !memcmp(data
.Scan0
, pargb
, sizeof(pargb
));
4146 ok(match
, "bits don't match\n");
4150 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat32bppPARGB
,
4151 bits
[0], bits
[1], bits
[2], bits
[3], bits
[4], bits
[5], bits
[6], bits
[7]);
4153 status
= GdipBitmapUnlockBits(bitmap
, &data
);
4156 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat32bppRGB
, &data
);
4158 ok(data
.Width
== 2, "expected 2, got %d\n", data
.Width
);
4159 ok(data
.Height
== 1, "expected 1, got %d\n", data
.Height
);
4160 ok(data
.Stride
== 8, "expected 8, got %d\n", data
.Stride
);
4161 ok(data
.PixelFormat
== PixelFormat32bppRGB
, "expected PixelFormat32bppRGB, got %d\n", data
.PixelFormat
);
4162 match
= !memcmp(data
.Scan0
, argb
, sizeof(argb
)) ||
4163 !memcmp(data
.Scan0
, rgb32_xp
, sizeof(rgb32_xp
));
4164 ok(match
, "bits don't match\n");
4168 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat32bppRGB
,
4169 bits
[0], bits
[1], bits
[2], bits
[3], bits
[4], bits
[5], bits
[6], bits
[7]);
4171 status
= GdipBitmapUnlockBits(bitmap
, &data
);
4174 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat24bppRGB
, &data
);
4176 ok(data
.Width
== 2, "expected 2, got %d\n", data
.Width
);
4177 ok(data
.Height
== 1, "expected 1, got %d\n", data
.Height
);
4178 ok(data
.Stride
== 8, "expected 8, got %d\n", data
.Stride
);
4179 ok(data
.PixelFormat
== PixelFormat24bppRGB
, "expected PixelFormat24bppRGB, got %d\n", data
.PixelFormat
);
4180 match
= !memcmp(data
.Scan0
, rgb24
, sizeof(rgb24
));
4181 ok(match
, "bits don't match\n");
4185 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat24bppRGB
,
4186 bits
[0], bits
[1], bits
[2], bits
[3], bits
[4], bits
[5], bits
[6], bits
[7]);
4188 status
= GdipBitmapUnlockBits(bitmap
, &data
);
4191 GdipDisposeImage((GpImage
*)bitmap
);
4196 struct GdiplusStartupInput gdiplusStartupInput
;
4197 ULONG_PTR gdiplusToken
;
4199 gdiplusStartupInput
.GdiplusVersion
= 1;
4200 gdiplusStartupInput
.DebugEventCallback
= NULL
;
4201 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
4202 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
4204 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
4206 test_ARGB_conversion();
4207 test_DrawImage_scale();
4208 test_image_format();
4210 test_GdipDrawImagePointRect();
4212 test_tiff_palette();
4213 test_GdipGetAllPropertyItems();
4214 test_tiff_properties();
4215 test_gif_properties();
4216 test_image_properties();
4219 test_GetImageDimension();
4220 test_GdipImageGetFrameDimensionsCount();
4221 test_LoadingImages();
4222 test_SavingImages();
4225 test_LockBits_UserBuf();
4226 test_GdipCreateBitmapFromHBITMAP();
4227 test_GdipGetImageFlags();
4228 test_GdipCloneImage();
4231 test_getrawformat();
4233 test_createfromwmf();
4235 test_createhbitmap();
4236 test_getthumbnail();
4241 test_multiframegif();
4247 GdiplusShutdown(gdiplusToken
);