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 stat
= GdipResetImageAttributes(imageattr
, ColorAdjustTypeDefault
);
2225 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
2226 UnitPixel
, imageattr
, NULL
, NULL
);
2229 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2231 ok(color_match(0xff40ccee, color
, 1), "Expected ff40ccee, got %.8x\n", color
);
2233 GdipDeleteGraphics(graphics
);
2234 GdipDisposeImage((GpImage
*)bitmap1
);
2235 GdipDisposeImage((GpImage
*)bitmap2
);
2236 GdipDisposeImageAttributes(imageattr
);
2239 static void test_gamma(void)
2242 GpImageAttributes
*imageattr
;
2243 GpBitmap
*bitmap1
, *bitmap2
;
2244 GpGraphics
*graphics
;
2247 stat
= GdipSetImageAttributesGamma(NULL
, ColorAdjustTypeDefault
, TRUE
, 1.0);
2248 expect(InvalidParameter
, stat
);
2250 stat
= GdipCreateImageAttributes(&imageattr
);
2253 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1.0);
2256 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeAny
, TRUE
, 1.0);
2257 expect(InvalidParameter
, stat
);
2259 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, -1.0);
2260 expect(InvalidParameter
, stat
);
2262 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0.0);
2263 expect(InvalidParameter
, stat
);
2265 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0.5);
2268 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, FALSE
, 0.0);
2271 /* Drawing a bitmap transforms the colors */
2272 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 3.0);
2275 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap1
);
2278 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap2
);
2281 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0xff80ffff);
2284 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
2287 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
2288 UnitPixel
, imageattr
, NULL
, NULL
);
2291 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2293 ok(color_match(0xff20ffff, color
, 1), "Expected ff20ffff, got %.8x\n", color
);
2295 stat
= GdipResetImageAttributes(imageattr
, ColorAdjustTypeDefault
);
2298 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
2299 UnitPixel
, imageattr
, NULL
, NULL
);
2302 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2304 ok(color_match(0xff80ffff, color
, 1), "Expected ff80ffff, got %.8x\n", color
);
2306 GdipDeleteGraphics(graphics
);
2307 GdipDisposeImage((GpImage
*)bitmap1
);
2308 GdipDisposeImage((GpImage
*)bitmap2
);
2309 GdipDisposeImageAttributes(imageattr
);
2312 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
2313 static const unsigned char gifanimation
[72] = {
2314 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
2315 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
2316 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
2317 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
2318 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
2321 static void test_multiframegif(void)
2333 /* Test frame functions with an animated GIF */
2334 hglob
= GlobalAlloc (0, sizeof(gifanimation
));
2335 data
= GlobalLock (hglob
);
2336 memcpy(data
, gifanimation
, sizeof(gifanimation
));
2337 GlobalUnlock(hglob
);
2339 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
2340 ok(hres
== S_OK
, "Failed to create a stream\n");
2341 if(hres
!= S_OK
) return;
2343 stat
= GdipCreateBitmapFromStream(stream
, &bmp
);
2344 ok(stat
== Ok
, "Failed to create a Bitmap\n");
2346 IStream_Release(stream
);
2350 /* Bitmap starts at frame 0 */
2352 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
2354 expect(0xffffffff, color
);
2356 /* Check that we get correct metadata */
2357 stat
= GdipImageGetFrameDimensionsCount((GpImage
*)bmp
,&count
);
2361 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bmp
, &dimension
, 1);
2363 expect_guid(&FrameDimensionTime
, &dimension
, __LINE__
, FALSE
);
2366 stat
= GdipImageGetFrameCount((GpImage
*)bmp
, &dimension
, &count
);
2370 /* SelectActiveFrame overwrites our current data */
2371 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 1);
2375 GdipBitmapGetPixel(bmp
, 0, 0, &color
);
2377 expect(0xff000000, color
);
2379 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
2383 GdipBitmapGetPixel(bmp
, 0, 0, &color
);
2385 expect(0xffffffff, color
);
2387 /* Write over the image data */
2388 stat
= GdipBitmapSetPixel(bmp
, 0, 0, 0xff000000);
2391 /* Switching to the same frame does not overwrite our changes */
2392 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
2395 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
2397 expect(0xff000000, color
);
2399 /* But switching to another frame and back does */
2400 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 1);
2403 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
2406 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
2408 expect(0xffffffff, color
);
2410 /* rotate/flip discards the information about other frames */
2411 stat
= GdipImageRotateFlip((GpImage
*)bmp
, Rotate90FlipNone
);
2415 stat
= GdipImageGetFrameCount((GpImage
*)bmp
, &dimension
, &count
);
2419 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)bmp
, __LINE__
, FALSE
);
2421 GdipDisposeImage((GpImage
*)bmp
);
2422 IStream_Release(stream
);
2424 /* Test with a non-animated gif */
2425 hglob
= GlobalAlloc (0, sizeof(gifimage
));
2426 data
= GlobalLock (hglob
);
2427 memcpy(data
, gifimage
, sizeof(gifimage
));
2428 GlobalUnlock(hglob
);
2430 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
2431 ok(hres
== S_OK
, "Failed to create a stream\n");
2432 if(hres
!= S_OK
) return;
2434 stat
= GdipCreateBitmapFromStream(stream
, &bmp
);
2435 ok(stat
== Ok
, "Failed to create a Bitmap\n");
2437 IStream_Release(stream
);
2441 /* Check metadata */
2442 stat
= GdipImageGetFrameDimensionsCount((GpImage
*)bmp
,&count
);
2446 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bmp
, &dimension
, 1);
2448 expect_guid(&FrameDimensionTime
, &dimension
, __LINE__
, FALSE
);
2451 stat
= GdipImageGetFrameCount((GpImage
*)bmp
, &dimension
, &count
);
2455 GdipDisposeImage((GpImage
*)bmp
);
2456 IStream_Release(stream
);
2459 static void test_rotateflip(void)
2464 static const BYTE orig_bits
[24] = {
2465 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
2466 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
2470 memcpy(bits
, orig_bits
, sizeof(bits
));
2471 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
2474 stat
= GdipImageRotateFlip(bitmap
, Rotate90FlipNone
);
2477 stat
= GdipGetImageWidth(bitmap
, &width
);
2479 stat
= GdipGetImageHeight(bitmap
, &height
);
2484 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 0, &color
);
2486 expect(0xff00ffff, color
);
2488 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 1, 0, &color
);
2490 expect(0xffff0000, color
);
2492 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 2, &color
);
2494 expect(0xffffff00, color
);
2496 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 1, 2, &color
);
2498 expect(0xff0000ff, color
);
2502 expect(0xff, bits
[2]);
2504 GdipDisposeImage(bitmap
);
2506 memcpy(bits
, orig_bits
, sizeof(bits
));
2507 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
2510 stat
= GdipImageRotateFlip(bitmap
, RotateNoneFlipX
);
2513 stat
= GdipGetImageWidth(bitmap
, &width
);
2515 stat
= GdipGetImageHeight(bitmap
, &height
);
2520 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 0, &color
);
2522 expect(0xff0000ff, color
);
2524 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 0, &color
);
2526 expect(0xffff0000, color
);
2528 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 1, &color
);
2530 expect(0xffffff00, color
);
2532 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 1, &color
);
2534 expect(0xff00ffff, color
);
2538 expect(0xff, bits
[2]);
2540 GdipDisposeImage(bitmap
);
2542 memcpy(bits
, orig_bits
, sizeof(bits
));
2543 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
2546 stat
= GdipImageRotateFlip(bitmap
, RotateNoneFlipY
);
2549 stat
= GdipGetImageWidth(bitmap
, &width
);
2551 stat
= GdipGetImageHeight(bitmap
, &height
);
2556 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 0, &color
);
2558 expect(0xff00ffff, color
);
2560 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 0, &color
);
2562 expect(0xffffff00, color
);
2564 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 1, &color
);
2566 expect(0xffff0000, color
);
2568 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 1, &color
);
2570 expect(0xff0000ff, color
);
2574 expect(0xff, bits
[2]);
2576 GdipDisposeImage(bitmap
);
2579 static void test_remaptable(void)
2582 GpImageAttributes
*imageattr
;
2583 GpBitmap
*bitmap1
, *bitmap2
;
2584 GpGraphics
*graphics
;
2588 map
= GdipAlloc(sizeof(ColorMap
));
2590 map
->oldColor
.Argb
= 0xff00ff00;
2591 map
->newColor
.Argb
= 0xffff00ff;
2593 stat
= GdipSetImageAttributesRemapTable(NULL
, ColorAdjustTypeDefault
, TRUE
, 1, map
);
2594 expect(InvalidParameter
, stat
);
2596 stat
= GdipCreateImageAttributes(&imageattr
);
2599 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1, NULL
);
2600 expect(InvalidParameter
, stat
);
2602 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeCount
, TRUE
, 1, map
);
2603 expect(InvalidParameter
, stat
);
2605 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeAny
, TRUE
, 1, map
);
2606 expect(InvalidParameter
, stat
);
2608 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0, map
);
2609 expect(InvalidParameter
, stat
);
2611 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, FALSE
, 0, NULL
);
2614 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1, map
);
2617 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap1
);
2620 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap2
);
2623 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0xff00ff00);
2626 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
2629 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
2630 UnitPixel
, imageattr
, NULL
, NULL
);
2633 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2635 ok(color_match(0xffff00ff, color
, 1), "Expected ffff00ff, got %.8x\n", color
);
2637 stat
= GdipResetImageAttributes(imageattr
, ColorAdjustTypeDefault
);
2640 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
2641 UnitPixel
, imageattr
, NULL
, NULL
);
2644 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2646 ok(color_match(0xff00ff00, color
, 1), "Expected ff00ff00, got %.8x\n", color
);
2648 GdipDeleteGraphics(graphics
);
2649 GdipDisposeImage((GpImage
*)bitmap1
);
2650 GdipDisposeImage((GpImage
*)bitmap2
);
2651 GdipDisposeImageAttributes(imageattr
);
2655 static void test_colorkey(void)
2658 GpImageAttributes
*imageattr
;
2659 GpBitmap
*bitmap1
, *bitmap2
;
2660 GpGraphics
*graphics
;
2663 stat
= GdipSetImageAttributesColorKeys(NULL
, ColorAdjustTypeDefault
, TRUE
, 0xff405060, 0xff708090);
2664 expect(InvalidParameter
, stat
);
2666 stat
= GdipCreateImageAttributes(&imageattr
);
2669 stat
= GdipSetImageAttributesColorKeys(imageattr
, ColorAdjustTypeCount
, TRUE
, 0xff405060, 0xff708090);
2670 expect(InvalidParameter
, stat
);
2672 stat
= GdipSetImageAttributesColorKeys(imageattr
, ColorAdjustTypeAny
, TRUE
, 0xff405060, 0xff708090);
2673 expect(InvalidParameter
, stat
);
2675 stat
= GdipSetImageAttributesColorKeys(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0xff405060, 0xff708090);
2678 stat
= GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB
, NULL
, &bitmap1
);
2681 stat
= GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB
, NULL
, &bitmap2
);
2684 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0x20405060);
2687 stat
= GdipBitmapSetPixel(bitmap1
, 0, 1, 0x40506070);
2690 stat
= GdipBitmapSetPixel(bitmap1
, 1, 0, 0x60708090);
2693 stat
= GdipBitmapSetPixel(bitmap1
, 1, 1, 0xffffffff);
2696 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
2699 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,2,2, 0,0,2,2,
2700 UnitPixel
, imageattr
, NULL
, NULL
);
2703 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2705 ok(color_match(0x00000000, color
, 1), "Expected 00000000, got %.8x\n", color
);
2707 stat
= GdipBitmapGetPixel(bitmap2
, 0, 1, &color
);
2709 ok(color_match(0x00000000, color
, 1), "Expected 00000000, got %.8x\n", color
);
2711 stat
= GdipBitmapGetPixel(bitmap2
, 1, 0, &color
);
2713 ok(color_match(0x00000000, color
, 1), "Expected 00000000, got %.8x\n", color
);
2715 stat
= GdipBitmapGetPixel(bitmap2
, 1, 1, &color
);
2717 ok(color_match(0xffffffff, color
, 1), "Expected ffffffff, got %.8x\n", color
);
2719 stat
= GdipResetImageAttributes(imageattr
, ColorAdjustTypeDefault
);
2722 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,2,2, 0,0,2,2,
2723 UnitPixel
, imageattr
, NULL
, NULL
);
2726 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2728 ok(color_match(0x20405060, color
, 1), "Expected 20405060, got %.8x\n", color
);
2730 stat
= GdipBitmapGetPixel(bitmap2
, 0, 1, &color
);
2732 ok(color_match(0x40506070, color
, 1), "Expected 40506070, got %.8x\n", color
);
2734 stat
= GdipBitmapGetPixel(bitmap2
, 1, 0, &color
);
2736 ok(color_match(0x60708090, color
, 1), "Expected 60708090, got %.8x\n", color
);
2738 stat
= GdipBitmapGetPixel(bitmap2
, 1, 1, &color
);
2740 ok(color_match(0xffffffff, color
, 1), "Expected ffffffff, got %.8x\n", color
);
2743 GdipDeleteGraphics(graphics
);
2744 GdipDisposeImage((GpImage
*)bitmap1
);
2745 GdipDisposeImage((GpImage
*)bitmap2
);
2746 GdipDisposeImageAttributes(imageattr
);
2749 static void test_dispose(void)
2753 char invalid_image
[256];
2755 stat
= GdipDisposeImage(NULL
);
2756 expect(InvalidParameter
, stat
);
2758 stat
= GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB
, NULL
, (GpBitmap
**)&image
);
2761 stat
= GdipDisposeImage(image
);
2764 stat
= GdipDisposeImage(image
);
2765 expect(ObjectBusy
, stat
);
2767 memset(invalid_image
, 0, 256);
2768 stat
= GdipDisposeImage((GpImage
*)invalid_image
);
2769 expect(ObjectBusy
, stat
);
2772 static LONG
obj_refcount(void *obj
)
2774 IUnknown_AddRef((IUnknown
*)obj
);
2775 return IUnknown_Release((IUnknown
*)obj
);
2778 static GpImage
*load_image(const BYTE
*image_data
, UINT image_size
)
2785 GpImage
*image
= NULL
, *clone
;
2786 ImageType image_type
;
2787 LONG refcount
, old_refcount
;
2789 hmem
= GlobalAlloc(0, image_size
);
2790 data
= GlobalLock(hmem
);
2791 memcpy(data
, image_data
, image_size
);
2794 hr
= CreateStreamOnHGlobal(hmem
, TRUE
, &stream
);
2795 ok(hr
== S_OK
, "CreateStreamOnHGlobal error %#x\n", hr
);
2796 if (hr
!= S_OK
) return NULL
;
2798 refcount
= obj_refcount(stream
);
2799 ok(refcount
== 1, "expected stream refcount 1, got %d\n", refcount
);
2801 status
= GdipLoadImageFromStream(stream
, &image
);
2802 ok(status
== Ok
|| broken(status
== InvalidParameter
), /* XP */
2803 "GdipLoadImageFromStream error %d\n", status
);
2806 IStream_Release(stream
);
2810 status
= GdipGetImageType(image
, &image_type
);
2811 ok(status
== Ok
, "GdipGetImageType error %d\n", status
);
2813 refcount
= obj_refcount(stream
);
2814 if (image_type
== ImageTypeBitmap
)
2815 ok(refcount
> 1, "expected stream refcount > 1, got %d\n", refcount
);
2817 ok(refcount
== 1, "expected stream refcount 1, got %d\n", refcount
);
2818 old_refcount
= refcount
;
2820 status
= GdipCloneImage(image
, &clone
);
2821 ok(status
== Ok
, "GdipCloneImage error %d\n", status
);
2822 refcount
= obj_refcount(stream
);
2823 ok(refcount
== old_refcount
, "expected stream refcount %d, got %d\n", old_refcount
, refcount
);
2824 status
= GdipDisposeImage(clone
);
2825 ok(status
== Ok
, "GdipDisposeImage error %d\n", status
);
2826 refcount
= obj_refcount(stream
);
2827 ok(refcount
== old_refcount
, "expected stream refcount %d, got %d\n", old_refcount
, refcount
);
2829 refcount
= IStream_Release(stream
);
2830 if (image_type
== ImageTypeBitmap
)
2831 ok(refcount
>= 1, "expected stream refcount != 0\n");
2833 ok(refcount
== 0, "expected stream refcount 0, got %d\n", refcount
);
2838 static void test_image_properties(void)
2840 static const struct test_data
2842 const BYTE
*image_data
;
2844 ImageType image_type
;
2846 UINT prop_count2
; /* if win7 behaves differently */
2847 /* 1st property attributes */
2849 UINT prop_size2
; /* if win7 behaves differently */
2851 UINT prop_id2
; /* if win7 behaves differently */
2855 { pngimage
, sizeof(pngimage
), ImageTypeBitmap
, 4, ~0, 1, 20, 0x5110, 0x132 },
2856 { jpgimage
, sizeof(jpgimage
), ImageTypeBitmap
, 2, ~0, 128, 0, 0x5090, 0x5091 },
2857 { tiffimage
, sizeof(tiffimage
), ImageTypeBitmap
, 16, 0, 4, 0, 0xfe, 0 },
2858 { bmpimage
, sizeof(bmpimage
), ImageTypeBitmap
, 0, 0, 0, 0, 0, 0 },
2859 { wmfimage
, sizeof(wmfimage
), ImageTypeMetafile
, 0, 0, 0, 0, 0, 0 }
2863 UINT prop_count
, prop_size
, i
;
2864 PROPID prop_id
[16] = { 0 };
2865 ImageType image_type
;
2872 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
2874 image
= load_image(td
[i
].image_data
, td
[i
].image_size
);
2877 trace("%u: failed to load image data\n", i
);
2881 status
= GdipGetImageType(image
, &image_type
);
2882 ok(status
== Ok
, "%u: GdipGetImageType error %d\n", i
, status
);
2883 ok(td
[i
].image_type
== image_type
, "%u: expected image_type %d, got %d\n",
2884 i
, td
[i
].image_type
, image_type
);
2886 status
= GdipGetPropertyCount(image
, &prop_count
);
2887 ok(status
== Ok
, "%u: GdipGetPropertyCount error %d\n", i
, status
);
2888 if (td
[i
].image_data
== pngimage
|| td
[i
].image_data
== jpgimage
)
2890 ok(td
[i
].prop_count
== prop_count
|| td
[i
].prop_count2
== prop_count
,
2891 " %u: expected property count %u or %u, got %u\n",
2892 i
, td
[i
].prop_count
, td
[i
].prop_count2
, prop_count
);
2894 ok(td
[i
].prop_count
== prop_count
|| td
[i
].prop_count2
== prop_count
,
2895 " %u: expected property count %u or %u, got %u\n",
2896 i
, td
[i
].prop_count
, td
[i
].prop_count2
, prop_count
);
2898 status
= GdipGetPropertyItemSize(NULL
, 0, &prop_size
);
2899 expect(InvalidParameter
, status
);
2900 status
= GdipGetPropertyItemSize(image
, 0, NULL
);
2901 expect(InvalidParameter
, status
);
2902 status
= GdipGetPropertyItemSize(image
, 0, &prop_size
);
2903 if (image_type
== ImageTypeMetafile
)
2904 expect(NotImplemented
, status
);
2906 expect(PropertyNotFound
, status
);
2908 status
= GdipGetPropertyItem(NULL
, 0, 0, &item
.data
);
2909 expect(InvalidParameter
, status
);
2910 status
= GdipGetPropertyItem(image
, 0, 0, NULL
);
2911 expect(InvalidParameter
, status
);
2912 status
= GdipGetPropertyItem(image
, 0, 0, &item
.data
);
2913 if (image_type
== ImageTypeMetafile
)
2914 expect(NotImplemented
, status
);
2916 expect(PropertyNotFound
, status
);
2918 /* FIXME: remove once Wine is fixed */
2919 if (td
[i
].prop_count
!= prop_count
)
2921 GdipDisposeImage(image
);
2925 status
= GdipGetPropertyIdList(NULL
, prop_count
, prop_id
);
2926 expect(InvalidParameter
, status
);
2927 status
= GdipGetPropertyIdList(image
, prop_count
, NULL
);
2928 expect(InvalidParameter
, status
);
2929 status
= GdipGetPropertyIdList(image
, 0, prop_id
);
2930 if (image_type
== ImageTypeMetafile
)
2931 expect(NotImplemented
, status
);
2932 else if (prop_count
== 0)
2935 expect(InvalidParameter
, status
);
2936 status
= GdipGetPropertyIdList(image
, prop_count
- 1, prop_id
);
2937 if (image_type
== ImageTypeMetafile
)
2938 expect(NotImplemented
, status
);
2940 expect(InvalidParameter
, status
);
2941 status
= GdipGetPropertyIdList(image
, prop_count
+ 1, prop_id
);
2942 if (image_type
== ImageTypeMetafile
)
2943 expect(NotImplemented
, status
);
2945 expect(InvalidParameter
, status
);
2946 status
= GdipGetPropertyIdList(image
, prop_count
, prop_id
);
2947 if (image_type
== ImageTypeMetafile
)
2948 expect(NotImplemented
, status
);
2952 if (prop_count
!= 0)
2953 ok(td
[i
].prop_id
== prop_id
[0] || td
[i
].prop_id2
== prop_id
[0],
2954 " %u: expected property id %#x or %#x, got %#x\n",
2955 i
, td
[i
].prop_id
, td
[i
].prop_id2
, prop_id
[0]);
2960 status
= GdipGetPropertyItemSize(image
, prop_id
[0], &prop_size
);
2961 if (prop_count
== 0)
2962 expect(PropertyNotFound
, status
);
2967 assert(sizeof(item
) >= prop_size
);
2968 ok(prop_size
> sizeof(PropertyItem
), "%u: got too small prop_size %u\n",
2970 ok(td
[i
].prop_size
+ sizeof(PropertyItem
) == prop_size
||
2971 td
[i
].prop_size2
+ sizeof(PropertyItem
) == prop_size
,
2972 " %u: expected property size %u or %u, got %u\n",
2973 i
, td
[i
].prop_size
, td
[i
].prop_size2
, prop_size
);
2975 status
= GdipGetPropertyItem(image
, prop_id
[0], 0, &item
.data
);
2976 ok(status
== InvalidParameter
|| status
== GenericError
/* Win7 */,
2977 "%u: expected InvalidParameter, got %d\n", i
, status
);
2978 status
= GdipGetPropertyItem(image
, prop_id
[0], prop_size
- 1, &item
.data
);
2979 ok(status
== InvalidParameter
|| status
== GenericError
/* Win7 */,
2980 "%u: expected InvalidParameter, got %d\n", i
, status
);
2981 status
= GdipGetPropertyItem(image
, prop_id
[0], prop_size
+ 1, &item
.data
);
2982 ok(status
== InvalidParameter
|| status
== GenericError
/* Win7 */,
2983 "%u: expected InvalidParameter, got %d\n", i
, status
);
2984 status
= GdipGetPropertyItem(image
, prop_id
[0], prop_size
, &item
.data
);
2986 ok(prop_id
[0] == item
.data
.id
,
2987 "%u: expected property id %#x, got %#x\n", i
, prop_id
[0], item
.data
.id
);
2991 GdipDisposeImage(image
);
2999 #define IFD_RATIONAL 5
3001 #define IFD_UNDEFINED 7
3002 #define IFD_SSHORT 8
3004 #define IFD_SRATIONAL 10
3005 #define IFD_FLOAT 11
3006 #define IFD_DOUBLE 12
3008 #ifndef PropertyTagTypeSByte
3009 #define PropertyTagTypeSByte 6
3010 #define PropertyTagTypeSShort 8
3011 #define PropertyTagTypeFloat 11
3012 #define PropertyTagTypeDouble 12
3015 static UINT
documented_type(UINT type
)
3019 case PropertyTagTypeSByte
: return PropertyTagTypeByte
;
3020 case PropertyTagTypeSShort
: return PropertyTagTypeShort
;
3021 case PropertyTagTypeFloat
: return PropertyTagTypeUndefined
;
3022 case PropertyTagTypeDouble
: return PropertyTagTypeUndefined
;
3023 default: return type
;
3027 #include "pshpack2.h"
3042 static const struct tiff_data
3047 USHORT number_of_entries
;
3048 struct IFD_entry entry
[40];
3050 struct IFD_rational xres
;
3052 struct IFD_rational srational_val
;
3057 struct IFD_rational rational
[3];
3061 #ifdef WORDS_BIGENDIAN
3067 FIELD_OFFSET(struct tiff_data
, number_of_entries
),
3070 { 0xff, IFD_SHORT
, 1, 0 }, /* SUBFILETYPE */
3071 { 0x100, IFD_LONG
, 1, 1 }, /* IMAGEWIDTH */
3072 { 0x101, IFD_LONG
, 1, 1 }, /* IMAGELENGTH */
3073 { 0x102, IFD_SHORT
, 1, 1 }, /* BITSPERSAMPLE */
3074 { 0x103, IFD_SHORT
, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
3075 { 0x106, IFD_SHORT
, 1, 1 }, /* PHOTOMETRIC */
3076 { 0x111, IFD_LONG
, 1, FIELD_OFFSET(struct tiff_data
, pixel_data
) }, /* STRIPOFFSETS */
3077 { 0x115, IFD_SHORT
, 1, 1 }, /* SAMPLESPERPIXEL */
3078 { 0x116, IFD_LONG
, 1, 1 }, /* ROWSPERSTRIP */
3079 { 0x117, IFD_LONG
, 1, 1 }, /* STRIPBYTECOUNT */
3080 { 0x11a, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_data
, xres
) },
3081 { 0x11b, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_data
, xres
) },
3082 { 0x128, IFD_SHORT
, 1, 2 }, /* RESOLUTIONUNIT */
3083 { 0xf001, IFD_BYTE
, 1, 0x11223344 },
3084 { 0xf002, IFD_BYTE
, 4, 0x11223344 },
3085 { 0xf003, IFD_SBYTE
, 1, 0x11223344 },
3086 { 0xf004, IFD_SSHORT
, 1, 0x11223344 },
3087 { 0xf005, IFD_SSHORT
, 2, 0x11223344 },
3088 { 0xf006, IFD_SLONG
, 1, 0x11223344 },
3089 { 0xf007, IFD_FLOAT
, 1, 0x11223344 },
3090 { 0xf008, IFD_DOUBLE
, 1, FIELD_OFFSET(struct tiff_data
, double_val
) },
3091 { 0xf009, IFD_SRATIONAL
, 1, FIELD_OFFSET(struct tiff_data
, srational_val
) },
3092 { 0xf00a, IFD_BYTE
, 13, FIELD_OFFSET(struct tiff_data
, string
) },
3093 { 0xf00b, IFD_SSHORT
, 4, FIELD_OFFSET(struct tiff_data
, short_val
) },
3094 { 0xf00c, IFD_SLONG
, 2, FIELD_OFFSET(struct tiff_data
, long_val
) },
3095 { 0xf00e, IFD_ASCII
, 13, FIELD_OFFSET(struct tiff_data
, string
) },
3096 { 0xf00f, IFD_ASCII
, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
3097 { 0xf010, IFD_UNDEFINED
, 13, FIELD_OFFSET(struct tiff_data
, string
) },
3098 { 0xf011, IFD_UNDEFINED
, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
3099 /* Some gdiplus versions ignore these fields.
3100 { 0xf012, IFD_BYTE, 0, 0x11223344 },
3101 { 0xf013, IFD_SHORT, 0, 0x11223344 },
3102 { 0xf014, IFD_LONG, 0, 0x11223344 },
3103 { 0xf015, IFD_FLOAT, 0, 0x11223344 },*/
3104 { 0xf016, IFD_SRATIONAL
, 3, FIELD_OFFSET(struct tiff_data
, rational
) },
3105 /* Win7 before SP1 doesn't recognize this field, everybody else does. */
3106 { 0xf017, IFD_FLOAT
, 2, FIELD_OFFSET(struct tiff_data
, float_val
) },
3110 1234567890.0987654321,
3111 { 0x1a2b3c4d, 0x5a6b7c8d },
3113 { 0x0101, 0x0202, 0x0303, 0x0404 },
3114 { 0x11223344, 0x55667788 },
3115 { (FLOAT
)1234.5678, (FLOAT
)8765.4321 },
3116 { { 0x01020304, 0x05060708 }, { 0x10203040, 0x50607080 }, { 0x11223344, 0x55667788 } },
3117 { 0x11, 0x22, 0x33, 0 }
3119 #include "poppack.h"
3121 static void test_tiff_properties(void)
3123 static const struct test_data
3125 ULONG type
, id
, length
;
3126 const BYTE value
[24];
3129 { PropertyTagTypeShort
, 0xff, 2, { 0 } },
3130 { PropertyTagTypeLong
, 0x100, 4, { 1 } },
3131 { PropertyTagTypeLong
, 0x101, 4, { 1 } },
3132 { PropertyTagTypeShort
, 0x102, 2, { 1 } },
3133 { PropertyTagTypeShort
, 0x103, 2, { 1 } },
3134 { PropertyTagTypeShort
, 0x106, 2, { 1 } },
3135 { PropertyTagTypeLong
, 0x111, 4, { 0x44,0x02 } },
3136 { PropertyTagTypeShort
, 0x115, 2, { 1 } },
3137 { PropertyTagTypeLong
, 0x116, 4, { 1 } },
3138 { PropertyTagTypeLong
, 0x117, 4, { 1 } },
3139 { PropertyTagTypeRational
, 0x11a, 8, { 0x84,0x03,0,0,0x03 } },
3140 { PropertyTagTypeRational
, 0x11b, 8, { 0x84,0x03,0,0,0x03 } },
3141 { PropertyTagTypeShort
, 0x128, 2, { 2 } },
3142 { PropertyTagTypeByte
, 0xf001, 1, { 0x44 } },
3143 { PropertyTagTypeByte
, 0xf002, 4, { 0x44,0x33,0x22,0x11 } },
3144 { PropertyTagTypeSByte
, 0xf003, 1, { 0x44 } },
3145 { PropertyTagTypeSShort
, 0xf004, 2, { 0x44,0x33 } },
3146 { PropertyTagTypeSShort
, 0xf005, 4, { 0x44,0x33,0x22,0x11 } },
3147 { PropertyTagTypeSLONG
, 0xf006, 4, { 0x44,0x33,0x22,0x11 } },
3148 { PropertyTagTypeFloat
, 0xf007, 4, { 0x44,0x33,0x22,0x11 } },
3149 { PropertyTagTypeDouble
, 0xf008, 8, { 0x2c,0x52,0x86,0xb4,0x80,0x65,0xd2,0x41 } },
3150 { PropertyTagTypeSRational
, 0xf009, 8, { 0x4d, 0x3c, 0x2b, 0x1a, 0x8d, 0x7c, 0x6b, 0x5a } },
3151 { PropertyTagTypeByte
, 0xf00a, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3152 { PropertyTagTypeSShort
, 0xf00b, 8, { 0x01,0x01,0x02,0x02,0x03,0x03,0x04,0x04 } },
3153 { PropertyTagTypeSLONG
, 0xf00c, 8, { 0x44,0x33,0x22,0x11,0x88,0x77,0x66,0x55 } },
3154 { PropertyTagTypeASCII
, 0xf00e, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3155 { PropertyTagTypeASCII
, 0xf00f, 5, { 'a','b','c','d' } },
3156 { PropertyTagTypeUndefined
, 0xf010, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3157 { PropertyTagTypeUndefined
, 0xf011, 4, { 'a','b','c','d' } },
3158 { PropertyTagTypeSRational
, 0xf016, 24,
3159 { 0x04,0x03,0x02,0x01,0x08,0x07,0x06,0x05,
3160 0x40,0x30,0x20,0x10,0x80,0x70,0x60,0x50,
3161 0x44,0x33,0x22,0x11,0x88,0x77,0x66,0x55 } },
3162 /* Win7 before SP1 doesn't recognize this field, everybody else does. */
3163 { PropertyTagTypeFloat
, 0xf017, 8, { 0x2b,0x52,0x9a,0x44,0xba,0xf5,0x08,0x46 } },
3168 UINT dim_count
, frame_count
, prop_count
, prop_size
, i
;
3170 PropertyItem
*prop_item
;
3172 image
= load_image((const BYTE
*)&TIFF_data
, sizeof(TIFF_data
));
3175 win_skip("Failed to load TIFF image data. Might not be supported. Skipping.\n");
3179 status
= GdipImageGetFrameDimensionsCount(image
, &dim_count
);
3181 expect(1, dim_count
);
3183 status
= GdipImageGetFrameDimensionsList(image
, &guid
, 1);
3185 expect_guid(&FrameDimensionPage
, &guid
, __LINE__
, FALSE
);
3187 frame_count
= 0xdeadbeef;
3188 status
= GdipImageGetFrameCount(image
, &guid
, &frame_count
);
3190 expect(1, frame_count
);
3192 prop_count
= 0xdeadbeef;
3193 status
= GdipGetPropertyCount(image
, &prop_count
);
3195 ok(prop_count
== sizeof(td
)/sizeof(td
[0]) ||
3196 broken(prop_count
== sizeof(td
)/sizeof(td
[0]) - 1) /* Win7 SP0 */,
3197 "expected property count %u, got %u\n", (UINT
)(sizeof(td
)/sizeof(td
[0])), prop_count
);
3199 prop_id
= HeapAlloc(GetProcessHeap(), 0, prop_count
* sizeof(*prop_id
));
3201 status
= GdipGetPropertyIdList(image
, prop_count
, prop_id
);
3204 for (i
= 0; i
< prop_count
; i
++)
3206 status
= GdipGetPropertyItemSize(image
, prop_id
[i
], &prop_size
);
3208 if (status
!= Ok
) break;
3209 ok(prop_size
> sizeof(*prop_item
), "%u: too small item length %u\n", i
, prop_size
);
3211 prop_item
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, prop_size
);
3212 status
= GdipGetPropertyItem(image
, prop_id
[i
], prop_size
, prop_item
);
3214 ok(prop_item
->value
== prop_item
+ 1, "expected item->value %p, got %p\n", prop_item
+ 1, prop_item
->value
);
3215 ok(td
[i
].type
== prop_item
->type
||
3216 /* Win7 stopped using proper but not documented types, and it
3217 looks broken since TypeFloat and TypeDouble now reported as
3218 TypeUndefined, and signed types reported as unsigned. */
3219 broken(prop_item
->type
== documented_type(td
[i
].type
)),
3220 "%u: expected type %u, got %u\n", i
, td
[i
].type
, prop_item
->type
);
3221 ok(td
[i
].id
== prop_item
->id
, "%u: expected id %#x, got %#x\n", i
, td
[i
].id
, prop_item
->id
);
3222 prop_size
-= sizeof(*prop_item
);
3223 ok(prop_item
->length
== prop_size
, "%u: expected length %u, got %u\n", i
, prop_size
, prop_item
->length
);
3224 ok(td
[i
].length
== prop_item
->length
|| broken(td
[i
].id
== 0xf00f && td
[i
].length
== prop_item
->length
+1) /* XP */,
3225 "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_item
->length
);
3226 ok(td
[i
].length
== prop_size
|| broken(td
[i
].id
== 0xf00f && td
[i
].length
== prop_size
+1) /* XP */,
3227 "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_size
);
3228 if (td
[i
].length
== prop_item
->length
)
3230 int match
= memcmp(td
[i
].value
, prop_item
->value
, td
[i
].length
) == 0;
3231 ok(match
|| broken(td
[i
].length
<= 4 && !match
), "%u: data mismatch\n", i
);
3235 BYTE
*data
= prop_item
->value
;
3236 trace("id %#x:", prop_item
->id
);
3237 for (j
= 0; j
< prop_item
->length
; j
++)
3238 trace(" %02x", data
[j
]);
3242 HeapFree(GetProcessHeap(), 0, prop_item
);
3245 HeapFree(GetProcessHeap(), 0, prop_id
);
3247 GdipDisposeImage(image
);
3250 static void test_GdipGetAllPropertyItems(void)
3252 static const struct test_data
3254 ULONG type
, id
, length
;
3258 { PropertyTagTypeLong
, 0xfe, 4, { 0 } },
3259 { PropertyTagTypeShort
, 0x100, 2, { 1 } },
3260 { PropertyTagTypeShort
, 0x101, 2, { 1 } },
3261 { PropertyTagTypeShort
, 0x102, 6, { 8,0,8,0,8,0 } },
3262 { PropertyTagTypeShort
, 0x103, 2, { 1 } },
3263 { PropertyTagTypeShort
, 0x106, 2, { 2,0 } },
3264 { PropertyTagTypeASCII
, 0x10d, 27, "/home/meh/Desktop/test.tif" },
3265 { PropertyTagTypeLong
, 0x111, 4, { 8,0,0,0 } },
3266 { PropertyTagTypeShort
, 0x112, 2, { 1 } },
3267 { PropertyTagTypeShort
, 0x115, 2, { 3,0 } },
3268 { PropertyTagTypeShort
, 0x116, 2, { 0x40,0 } },
3269 { PropertyTagTypeLong
, 0x117, 4, { 3,0,0,0 } },
3270 { PropertyTagTypeRational
, 0x11a, 8, { 0,0,0,72,0,0,0,1 } },
3271 { PropertyTagTypeRational
, 0x11b, 8, { 0,0,0,72,0,0,0,1 } },
3272 { PropertyTagTypeShort
, 0x11c, 2, { 1 } },
3273 { PropertyTagTypeShort
, 0x128, 2, { 2 } }
3278 UINT dim_count
, frame_count
, prop_count
, prop_size
, i
;
3279 UINT total_size
, total_count
;
3281 PropertyItem
*prop_item
;
3282 const char *item_data
;
3284 image
= load_image(tiffimage
, sizeof(tiffimage
));
3285 ok(image
!= 0, "Failed to load TIFF image data\n");
3288 dim_count
= 0xdeadbeef;
3289 status
= GdipImageGetFrameDimensionsCount(image
, &dim_count
);
3291 expect(1, dim_count
);
3293 status
= GdipImageGetFrameDimensionsList(image
, &guid
, 1);
3295 expect_guid(&FrameDimensionPage
, &guid
, __LINE__
, FALSE
);
3297 frame_count
= 0xdeadbeef;
3298 status
= GdipImageGetFrameCount(image
, &guid
, &frame_count
);
3300 expect(1, frame_count
);
3302 prop_count
= 0xdeadbeef;
3303 status
= GdipGetPropertyCount(image
, &prop_count
);
3305 ok(prop_count
== sizeof(td
)/sizeof(td
[0]),
3306 "expected property count %u, got %u\n", (UINT
)(sizeof(td
)/sizeof(td
[0])), prop_count
);
3308 prop_id
= HeapAlloc(GetProcessHeap(), 0, prop_count
* sizeof(*prop_id
));
3310 status
= GdipGetPropertyIdList(image
, prop_count
, prop_id
);
3314 for (i
= 0; i
< prop_count
; i
++)
3317 status
= GdipGetPropertyItemSize(image
, prop_id
[i
], &size
);
3319 if (status
!= Ok
) break;
3320 ok(size
> sizeof(*prop_item
), "%u: too small item length %u\n", i
, size
);
3324 prop_item
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
3325 status
= GdipGetPropertyItem(image
, prop_id
[i
], size
, prop_item
);
3327 ok(prop_item
->value
== prop_item
+ 1, "expected item->value %p, got %p\n", prop_item
+ 1, prop_item
->value
);
3328 ok(td
[i
].type
== prop_item
->type
,
3329 "%u: expected type %u, got %u\n", i
, td
[i
].type
, prop_item
->type
);
3330 ok(td
[i
].id
== prop_item
->id
, "%u: expected id %#x, got %#x\n", i
, td
[i
].id
, prop_item
->id
);
3331 size
-= sizeof(*prop_item
);
3332 ok(prop_item
->length
== size
, "%u: expected length %u, got %u\n", i
, size
, prop_item
->length
);
3333 ok(td
[i
].length
== prop_item
->length
, "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_item
->length
);
3334 if (td
[i
].length
== prop_item
->length
)
3336 int match
= memcmp(td
[i
].value
, prop_item
->value
, td
[i
].length
) == 0;
3337 ok(match
, "%u: data mismatch\n", i
);
3341 BYTE
*data
= prop_item
->value
;
3342 trace("id %#x:", prop_item
->id
);
3343 for (j
= 0; j
< prop_item
->length
; j
++)
3344 trace(" %02x", data
[j
]);
3348 HeapFree(GetProcessHeap(), 0, prop_item
);
3351 HeapFree(GetProcessHeap(), 0, prop_id
);
3353 status
= GdipGetPropertySize(NULL
, &total_size
, &total_count
);
3354 expect(InvalidParameter
, status
);
3355 status
= GdipGetPropertySize(image
, &total_size
, NULL
);
3356 expect(InvalidParameter
, status
);
3357 status
= GdipGetPropertySize(image
, NULL
, &total_count
);
3358 expect(InvalidParameter
, status
);
3359 status
= GdipGetPropertySize(image
, NULL
, NULL
);
3360 expect(InvalidParameter
, status
);
3361 total_size
= 0xdeadbeef;
3362 total_count
= 0xdeadbeef;
3363 status
= GdipGetPropertySize(image
, &total_size
, &total_count
);
3365 ok(prop_count
== total_count
,
3366 "expected total property count %u, got %u\n", prop_count
, total_count
);
3367 ok(prop_size
== total_size
,
3368 "expected total property size %u, got %u\n", prop_size
, total_size
);
3370 prop_item
= HeapAlloc(GetProcessHeap(), 0, prop_size
);
3372 status
= GdipGetAllPropertyItems(image
, 0, prop_count
, prop_item
);
3373 expect(InvalidParameter
, status
);
3374 status
= GdipGetAllPropertyItems(image
, prop_size
, 1, prop_item
);
3375 expect(InvalidParameter
, status
);
3376 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, NULL
);
3377 expect(InvalidParameter
, status
);
3378 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, NULL
);
3379 expect(InvalidParameter
, status
);
3380 status
= GdipGetAllPropertyItems(image
, 0, 0, NULL
);
3381 expect(InvalidParameter
, status
);
3382 status
= GdipGetAllPropertyItems(image
, prop_size
+ 1, prop_count
, prop_item
);
3383 expect(InvalidParameter
, status
);
3384 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, prop_item
);
3387 item_data
= (const char *)(prop_item
+ prop_count
);
3388 for (i
= 0; i
< prop_count
; i
++)
3390 ok(prop_item
[i
].value
== item_data
, "%u: expected value %p, got %p\n",
3391 i
, item_data
, prop_item
[i
].value
);
3392 ok(td
[i
].type
== prop_item
[i
].type
,
3393 "%u: expected type %u, got %u\n", i
, td
[i
].type
, prop_item
[i
].type
);
3394 ok(td
[i
].id
== prop_item
[i
].id
, "%u: expected id %#x, got %#x\n", i
, td
[i
].id
, prop_item
[i
].id
);
3395 ok(td
[i
].length
== prop_item
[i
].length
, "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_item
[i
].length
);
3396 if (td
[i
].length
== prop_item
[i
].length
)
3398 int match
= memcmp(td
[i
].value
, prop_item
[i
].value
, td
[i
].length
) == 0;
3399 ok(match
, "%u: data mismatch\n", i
);
3403 BYTE
*data
= prop_item
[i
].value
;
3404 trace("id %#x:", prop_item
[i
].id
);
3405 for (j
= 0; j
< prop_item
[i
].length
; j
++)
3406 trace(" %02x", data
[j
]);
3410 item_data
+= prop_item
[i
].length
;
3413 HeapFree(GetProcessHeap(), 0, prop_item
);
3415 GdipDisposeImage(image
);
3418 static void test_tiff_palette(void)
3429 ARGB
*entries
= palette
.pal
.Entries
;
3431 /* 1bpp TIFF without palette */
3432 image
= load_image((const BYTE
*)&TIFF_data
, sizeof(TIFF_data
));
3435 win_skip("Failed to load TIFF image data. Might not be supported. Skipping.\n");
3439 status
= GdipGetImagePixelFormat(image
, &format
);
3441 ok(format
== PixelFormat1bppIndexed
, "expected PixelFormat1bppIndexed, got %#x\n", format
);
3443 status
= GdipGetImagePaletteSize(image
, &size
);
3444 ok(status
== Ok
|| broken(status
== GenericError
), /* XP */
3445 "GdipGetImagePaletteSize error %d\n", status
);
3446 if (status
== GenericError
)
3448 GdipDisposeImage(image
);
3451 expect(sizeof(ColorPalette
) + sizeof(ARGB
), size
);
3453 status
= GdipGetImagePalette(image
, &palette
.pal
, size
);
3455 expect(0, palette
.pal
.Flags
);
3456 expect(2, palette
.pal
.Count
);
3457 if (palette
.pal
.Count
== 2)
3459 ok(entries
[0] == 0xff000000, "expected 0xff000000, got %#x\n", entries
[0]);
3460 ok(entries
[1] == 0xffffffff, "expected 0xffffffff, got %#x\n", entries
[1]);
3463 GdipDisposeImage(image
);
3466 static void test_bitmapbits(void)
3469 static const BYTE pixels_24
[48] =
3471 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3472 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3473 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3474 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0
3476 static const BYTE pixels_00
[48] =
3478 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3479 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3480 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3481 0,0,0, 0,0,0, 0,0,0, 0,0,0
3483 static const BYTE pixels_24_77
[64] =
3485 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3486 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3487 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3488 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3489 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3490 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3492 static const BYTE pixels_77
[64] =
3494 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3495 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3496 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3497 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3498 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3499 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3500 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3501 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3503 static const BYTE pixels_8
[16] =
3505 0x01,0,0x01,0,0x01,0,0x01,0,
3506 0x01,0,0x01,0,0x01,0,0x01,0
3508 static const BYTE pixels_8_77
[64] =
3510 0x01,0,0x01,0,0x01,0,0x01,0,
3511 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3512 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3513 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3514 0x01,0,0x01,0,0x01,0,0x01,0,
3515 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3516 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3517 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3519 static const BYTE pixels_1_77
[64] =
3521 0xaa,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3522 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3523 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3524 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3525 0xaa,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3526 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3527 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3528 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3530 static const BYTE pixels_1
[8] = {0xaa,0,0,0,0xaa,0,0,0};
3531 static const struct test_data
3538 const BYTE
*pixels_unlocked
;
3542 { PixelFormat24bppRGB
, 24, 0xfff0, 24, 48, pixels_24
, pixels_00
},
3544 { PixelFormat24bppRGB
, 24, 0, 24, 48, pixels_24
, pixels_00
},
3545 { PixelFormat24bppRGB
, 24, ImageLockModeRead
, 24, 48, pixels_24
, pixels_00
},
3546 { PixelFormat24bppRGB
, 24, ImageLockModeWrite
, 24, 48, pixels_24
, pixels_00
},
3547 { PixelFormat24bppRGB
, 24, ImageLockModeRead
|ImageLockModeWrite
, 24, 48, pixels_24
, pixels_00
},
3548 { PixelFormat24bppRGB
, 24, ImageLockModeRead
|ImageLockModeUserInputBuf
, 32, 64, pixels_24_77
, pixels_24
},
3549 { PixelFormat24bppRGB
, 24, ImageLockModeWrite
|ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_00
},
3550 { PixelFormat24bppRGB
, 24, ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_24
},
3552 { PixelFormat8bppIndexed
, 8, 0, 8, 16, pixels_8
, pixels_24
},
3553 { PixelFormat8bppIndexed
, 8, ImageLockModeRead
, 8, 16, pixels_8
, pixels_24
},
3554 { PixelFormat8bppIndexed
, 8, ImageLockModeWrite
, 8, 16, pixels_8
, pixels_00
},
3555 { PixelFormat8bppIndexed
, 8, ImageLockModeRead
|ImageLockModeWrite
, 8, 16, pixels_8
, pixels_00
},
3556 { PixelFormat8bppIndexed
, 8, ImageLockModeRead
|ImageLockModeUserInputBuf
, 32, 64, pixels_8_77
, pixels_24
},
3557 { PixelFormat8bppIndexed
, 8, ImageLockModeWrite
|ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_00
},
3558 { PixelFormat8bppIndexed
, 8, ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_24
},
3560 { PixelFormat1bppIndexed
, 1, 0, 4, 8, pixels_1
, pixels_24
},
3561 { PixelFormat1bppIndexed
, 1, ImageLockModeRead
, 4, 8, pixels_1
, pixels_24
},
3562 { PixelFormat1bppIndexed
, 1, ImageLockModeWrite
, 4, 8, pixels_1
, pixels_00
},
3563 { PixelFormat1bppIndexed
, 1, ImageLockModeRead
|ImageLockModeWrite
, 4, 8, pixels_1
, pixels_00
},
3564 { PixelFormat1bppIndexed
, 1, ImageLockModeRead
|ImageLockModeUserInputBuf
, 32, 64, pixels_1_77
, pixels_24
},
3565 { PixelFormat1bppIndexed
, 1, ImageLockModeWrite
|ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_00
},
3566 { PixelFormat1bppIndexed
, 1, ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_24
},
3578 ARGB
*entries
= palette
.pal
.Entries
;
3580 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
3582 BYTE pixels
[sizeof(pixels_24
)];
3583 memcpy(pixels
, pixels_24
, sizeof(pixels_24
));
3584 status
= GdipCreateBitmapFromScan0(8, 2, 24, PixelFormat24bppRGB
, pixels
, &bitmap
);
3587 /* associate known palette with pixel data */
3588 palette
.pal
.Flags
= PaletteFlagsGrayScale
;
3589 palette
.pal
.Count
= 2;
3590 entries
[0] = 0xff000000;
3591 entries
[1] = 0xffffffff;
3592 status
= GdipSetImagePalette((GpImage
*)bitmap
, &palette
.pal
);
3595 memset(&data
, 0xfe, sizeof(data
));
3596 if (td
[i
].mode
& ImageLockModeUserInputBuf
)
3598 memset(buf
, 0x77, sizeof(buf
));
3602 status
= GdipBitmapLockBits(bitmap
, NULL
, td
[i
].mode
, td
[i
].format
, &data
);
3603 ok(status
== Ok
|| broken(status
== InvalidParameter
) /* XP */, "%u: GdipBitmapLockBits error %d\n", i
, status
);
3606 GdipDisposeImage((GpImage
*)bitmap
);
3609 ok(data
.Width
== 8, "%u: expected 8, got %d\n", i
, data
.Width
);
3610 ok(data
.Height
== 2, "%u: expected 2, got %d\n", i
, data
.Height
);
3611 ok(td
[i
].stride
== data
.Stride
, "%u: expected %d, got %d\n", i
, td
[i
].stride
, data
.Stride
);
3612 ok(td
[i
].format
== data
.PixelFormat
, "%u: expected %d, got %d\n", i
, td
[i
].format
, data
.PixelFormat
);
3613 ok(td
[i
].size
== data
.Height
* data
.Stride
, "%u: expected %d, got %d\n", i
, td
[i
].size
, data
.Height
* data
.Stride
);
3614 if (td
[i
].mode
& ImageLockModeUserInputBuf
)
3615 ok(data
.Scan0
== buf
, "%u: got wrong buffer\n", i
);
3616 if (td
[i
].size
== data
.Height
* data
.Stride
)
3618 UINT j
, match
, width_bytes
= (data
.Width
* td
[i
].bpp
) / 8;
3621 for (j
= 0; j
< data
.Height
; j
++)
3623 if (memcmp((const BYTE
*)data
.Scan0
+ j
* data
.Stride
, td
[i
].pixels
+ j
* data
.Stride
, width_bytes
) != 0)
3629 if ((td
[i
].mode
& (ImageLockModeRead
|ImageLockModeUserInputBuf
)) || td
[i
].format
== PixelFormat24bppRGB
)
3632 "%u: data should match\n", i
);
3635 BYTE
*bits
= data
.Scan0
;
3636 trace("%u: data mismatch for format %#x:", i
, td
[i
].format
);
3637 for (j
= 0; j
< td
[i
].size
; j
++)
3638 trace(" %02x", bits
[j
]);
3643 ok(!match
, "%u: data shouldn't match\n", i
);
3645 memset(data
.Scan0
, 0, td
[i
].size
);
3648 status
= GdipBitmapUnlockBits(bitmap
, &data
);
3649 ok(status
== Ok
, "%u: GdipBitmapUnlockBits error %d\n", i
, status
);
3651 memset(&data
, 0xfe, sizeof(data
));
3652 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat24bppRGB
, &data
);
3653 ok(status
== Ok
, "%u: GdipBitmapLockBits error %d\n", i
, status
);
3654 ok(data
.Width
== 8, "%u: expected 8, got %d\n", i
, data
.Width
);
3655 ok(data
.Height
== 2, "%u: expected 2, got %d\n", i
, data
.Height
);
3656 ok(data
.Stride
== 24, "%u: expected 24, got %d\n", i
, data
.Stride
);
3657 ok(data
.PixelFormat
== PixelFormat24bppRGB
, "%u: got wrong pixel format %d\n", i
, data
.PixelFormat
);
3658 ok(data
.Height
* data
.Stride
== 48, "%u: expected 48, got %d\n", i
, data
.Height
* data
.Stride
);
3659 if (data
.Height
* data
.Stride
== 48)
3661 int match
= memcmp(data
.Scan0
, td
[i
].pixels_unlocked
, 48) == 0;
3662 ok(match
, "%u: data should match\n", i
);
3666 BYTE
*bits
= data
.Scan0
;
3667 trace("%u: data mismatch for format %#x:", i
, td
[i
].format
);
3668 for (j
= 0; j
< 48; j
++)
3669 trace(" %02x", bits
[j
]);
3674 status
= GdipBitmapUnlockBits(bitmap
, &data
);
3675 ok(status
== Ok
, "%u: GdipBitmapUnlockBits error %d\n", i
, status
);
3677 status
= GdipDisposeImage((GpImage
*)bitmap
);
3682 static void test_DrawImage(void)
3684 BYTE black_1x1
[4] = { 0,0,0,0 };
3685 BYTE white_2x2
[16] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
3686 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
3687 BYTE black_2x2
[16] = { 0,0,0,0,0,0,0xff,0xff,
3688 0,0,0,0,0,0,0xff,0xff };
3695 GpGraphics
*graphics
;
3698 status
= GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB
, black_1x1
, &u1
.bitmap
);
3700 status
= GdipBitmapSetResolution(u1
.bitmap
, 100.0, 100.0);
3703 status
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat24bppRGB
, white_2x2
, &u2
.bitmap
);
3705 status
= GdipBitmapSetResolution(u2
.bitmap
, 300.0, 300.0);
3707 status
= GdipGetImageGraphicsContext(u2
.image
, &graphics
);
3709 status
= GdipSetInterpolationMode(graphics
, InterpolationModeNearestNeighbor
);
3712 status
= GdipDrawImageI(graphics
, u1
.image
, 0, 0);
3715 match
= memcmp(white_2x2
, black_2x2
, sizeof(black_2x2
)) == 0;
3716 ok(match
, "data should match\n");
3719 UINT i
, size
= sizeof(white_2x2
);
3720 BYTE
*bits
= white_2x2
;
3721 for (i
= 0; i
< size
; i
++)
3722 trace(" %02x", bits
[i
]);
3726 status
= GdipDeleteGraphics(graphics
);
3728 status
= GdipDisposeImage(u1
.image
);
3730 status
= GdipDisposeImage(u2
.image
);
3734 static void test_GdipDrawImagePointRect(void)
3736 BYTE black_1x1
[4] = { 0,0,0,0 };
3737 BYTE white_2x2
[16] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
3738 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
3739 BYTE black_2x2
[16] = { 0,0,0,0,0,0,0xff,0xff,
3740 0,0,0,0,0,0,0xff,0xff };
3747 GpGraphics
*graphics
;
3750 status
= GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB
, black_1x1
, &u1
.bitmap
);
3752 status
= GdipBitmapSetResolution(u1
.bitmap
, 100.0, 100.0);
3755 status
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat24bppRGB
, white_2x2
, &u2
.bitmap
);
3757 status
= GdipBitmapSetResolution(u2
.bitmap
, 300.0, 300.0);
3759 status
= GdipGetImageGraphicsContext(u2
.image
, &graphics
);
3761 status
= GdipSetInterpolationMode(graphics
, InterpolationModeNearestNeighbor
);
3764 status
= GdipDrawImagePointRectI(graphics
, u1
.image
, 0, 0, 0, 0, 1, 1, UnitPixel
);
3767 match
= memcmp(white_2x2
, black_2x2
, sizeof(black_2x2
)) == 0;
3768 ok(match
, "data should match\n");
3771 UINT i
, size
= sizeof(white_2x2
);
3772 BYTE
*bits
= white_2x2
;
3773 for (i
= 0; i
< size
; i
++)
3774 trace(" %02x", bits
[i
]);
3778 status
= GdipDeleteGraphics(graphics
);
3780 status
= GdipDisposeImage(u1
.image
);
3782 status
= GdipDisposeImage(u2
.image
);
3786 static void test_image_format(void)
3788 static const PixelFormat fmt
[] =
3790 PixelFormat1bppIndexed
, PixelFormat4bppIndexed
, PixelFormat8bppIndexed
,
3791 PixelFormat16bppGrayScale
, PixelFormat16bppRGB555
, PixelFormat16bppRGB565
,
3792 PixelFormat16bppARGB1555
, PixelFormat24bppRGB
, PixelFormat32bppRGB
,
3793 PixelFormat32bppARGB
, PixelFormat32bppPARGB
, PixelFormat48bppRGB
,
3794 PixelFormat64bppARGB
, PixelFormat64bppPARGB
, PixelFormat32bppCMYK
3805 for (i
= 0; i
< sizeof(fmt
)/sizeof(fmt
[0]); i
++)
3807 status
= GdipCreateBitmapFromScan0(1, 1, 0, fmt
[i
], NULL
, &bitmap
);
3808 ok(status
== Ok
|| broken(status
== InvalidParameter
) /* before win7 */,
3809 "GdipCreateBitmapFromScan0 error %d\n", status
);
3810 if (status
!= Ok
) continue;
3812 status
= GdipGetImagePixelFormat((GpImage
*)bitmap
, &format
);
3814 expect(fmt
[i
], format
);
3816 status
= GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3817 if (fmt
[i
] == PixelFormat16bppGrayScale
|| fmt
[i
] == PixelFormat32bppCMYK
)
3818 todo_wine
expect(InvalidParameter
, status
);
3822 ret
= GetObjectW(hbitmap
, sizeof(bm
), &bm
);
3823 expect(sizeof(bm
), ret
);
3824 expect(0, bm
.bmType
);
3825 expect(1, bm
.bmWidth
);
3826 expect(1, bm
.bmHeight
);
3827 expect(4, bm
.bmWidthBytes
);
3828 expect(1, bm
.bmPlanes
);
3829 expect(32, bm
.bmBitsPixel
);
3830 DeleteObject(hbitmap
);
3833 status
= GdipGetImageThumbnail((GpImage
*)bitmap
, 0, 0, &thumb
, NULL
, NULL
);
3834 if (fmt
[i
] == PixelFormat16bppGrayScale
|| fmt
[i
] == PixelFormat32bppCMYK
)
3836 ok(status
== OutOfMemory
|| broken(status
== InvalidParameter
) /* before win7 */,
3837 "expected OutOfMemory, got %d\n", status
);
3841 status
= GdipGetImagePixelFormat(thumb
, &format
);
3843 ok(format
== PixelFormat32bppPARGB
|| broken(format
!= PixelFormat32bppPARGB
) /* before win7 */,
3844 "expected PixelFormat32bppPARGB, got %#x\n", format
);
3845 status
= GdipDisposeImage(thumb
);
3849 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat32bppPARGB
, &data
);
3850 if (fmt
[i
] == PixelFormat16bppGrayScale
|| fmt
[i
] == PixelFormat32bppCMYK
)
3851 todo_wine
expect(InvalidParameter
, status
);
3855 status
= GdipBitmapUnlockBits(bitmap
, &data
);
3859 status
= GdipDisposeImage((GpImage
*)bitmap
);
3864 static void test_DrawImage_scale(void)
3866 static const BYTE back_8x1
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
3867 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3868 static const BYTE image_080
[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,
3869 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3870 static const BYTE image_100
[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40,
3871 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3872 static const BYTE image_120
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x40,0x40,0x40,
3873 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3874 static const BYTE image_150
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3875 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3876 static const BYTE image_180
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3877 0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3878 static const BYTE image_200
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3879 0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3880 static const BYTE image_250
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,
3881 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40 };
3882 static const BYTE image_120_half
[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
3883 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3884 static const BYTE image_150_half
[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
3885 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3886 static const BYTE image_200_half
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3887 0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40 };
3888 static const BYTE image_250_half
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3889 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40 };
3890 static const struct test_data
3893 PixelOffsetMode pixel_offset_mode
;
3898 { 0.8, PixelOffsetModeNone
, image_080
}, /* 0 */
3899 { 1.0, PixelOffsetModeNone
, image_100
},
3900 { 1.2, PixelOffsetModeNone
, image_120
},
3901 { 1.5, PixelOffsetModeNone
, image_150
},
3902 { 1.8, PixelOffsetModeNone
, image_180
},
3903 { 2.0, PixelOffsetModeNone
, image_200
},
3904 { 2.5, PixelOffsetModeNone
, image_250
},
3906 { 0.8, PixelOffsetModeHighSpeed
, image_080
}, /* 7 */
3907 { 1.0, PixelOffsetModeHighSpeed
, image_100
},
3908 { 1.2, PixelOffsetModeHighSpeed
, image_120
},
3909 { 1.5, PixelOffsetModeHighSpeed
, image_150
},
3910 { 1.8, PixelOffsetModeHighSpeed
, image_180
},
3911 { 2.0, PixelOffsetModeHighSpeed
, image_200
},
3912 { 2.5, PixelOffsetModeHighSpeed
, image_250
},
3914 { 0.8, PixelOffsetModeHalf
, image_080
}, /* 14 */
3915 { 1.0, PixelOffsetModeHalf
, image_100
},
3916 { 1.2, PixelOffsetModeHalf
, image_120_half
, TRUE
},
3917 { 1.5, PixelOffsetModeHalf
, image_150_half
, TRUE
},
3918 { 1.8, PixelOffsetModeHalf
, image_180
},
3919 { 2.0, PixelOffsetModeHalf
, image_200_half
, TRUE
},
3920 { 2.5, PixelOffsetModeHalf
, image_250_half
, TRUE
},
3922 { 0.8, PixelOffsetModeHighQuality
, image_080
}, /* 21 */
3923 { 1.0, PixelOffsetModeHighQuality
, image_100
},
3924 { 1.2, PixelOffsetModeHighQuality
, image_120_half
, TRUE
},
3925 { 1.5, PixelOffsetModeHighQuality
, image_150_half
, TRUE
},
3926 { 1.8, PixelOffsetModeHighQuality
, image_180
},
3927 { 2.0, PixelOffsetModeHighQuality
, image_200_half
, TRUE
},
3928 { 2.5, PixelOffsetModeHighQuality
, image_250_half
, TRUE
},
3930 BYTE src_2x1
[6] = { 0x80,0x80,0x80,0x80,0x80,0x80 };
3938 GpGraphics
*graphics
;
3942 status
= GdipCreateBitmapFromScan0(2, 1, 4, PixelFormat24bppRGB
, src_2x1
, &u1
.bitmap
);
3944 status
= GdipBitmapSetResolution(u1
.bitmap
, 100.0, 100.0);
3947 status
= GdipCreateBitmapFromScan0(8, 1, 24, PixelFormat24bppRGB
, dst_8x1
, &u2
.bitmap
);
3949 status
= GdipBitmapSetResolution(u2
.bitmap
, 100.0, 100.0);
3951 status
= GdipGetImageGraphicsContext(u2
.image
, &graphics
);
3953 status
= GdipSetInterpolationMode(graphics
, InterpolationModeNearestNeighbor
);
3956 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
3958 status
= GdipSetPixelOffsetMode(graphics
, td
[i
].pixel_offset_mode
);
3961 status
= GdipCreateMatrix2(td
[i
].scale_x
, 0.0, 0.0, 1.0, 0.0, 0.0, &matrix
);
3963 status
= GdipSetWorldTransform(graphics
, matrix
);
3965 GdipDeleteMatrix(matrix
);
3967 memcpy(dst_8x1
, back_8x1
, sizeof(dst_8x1
));
3968 status
= GdipDrawImageI(graphics
, u1
.image
, 1, 0);
3971 match
= memcmp(dst_8x1
, td
[i
].image
, sizeof(dst_8x1
)) == 0;
3972 if (!match
&& td
[i
].todo
)
3973 todo_wine
ok(match
, "%d: data should match\n", i
);
3975 ok(match
, "%d: data should match\n", i
);
3978 UINT i
, size
= sizeof(dst_8x1
);
3979 const BYTE
*bits
= dst_8x1
;
3980 for (i
= 0; i
< size
; i
++)
3981 trace(" %02x", bits
[i
]);
3986 status
= GdipDeleteGraphics(graphics
);
3988 status
= GdipDisposeImage(u1
.image
);
3990 status
= GdipDisposeImage(u2
.image
);
3994 static const BYTE animatedgif
[] = {
3995 'G','I','F','8','9','a',0x01,0x00,0x01,0x00,0xA1,0x02,0x00,
3996 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,
3997 /*0x21,0xFF,0x0B,'A','N','I','M','E','X','T','S','1','.','0',*/
3998 0x21,0xFF,0x0B,'N','E','T','S','C','A','P','E','2','.','0',
3999 0x03,0x01,0x05,0x00,0x00,
4000 0x21,0xFE,0x0C,'H','e','l','l','o',' ','W','o','r','l','d','!',0x00,
4001 0x21,0x01,0x0D,'a','n','i','m','a','t','i','o','n','.','g','i','f',0x00,
4002 0x21,0xF9,0x04,0xff,0x0A,0x00,0x08,0x00,
4003 0x2C,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
4004 0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,
4005 0x02,0x02,0x4C,0x01,0x00,
4006 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','1',0x00,
4007 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','1',0x00,
4008 0x21,0xF9,0x04,0x00,0x14,0x00,0x01,0x00,
4009 0x2C,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
4010 0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,
4011 0x02,0x02,0x44,0x01,0x00,
4012 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','2',0x00,
4013 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','2',0x00,0x3B
4016 static void test_gif_properties(void)
4018 static const struct test_data
4020 ULONG type
, id
, length
;
4021 const BYTE value
[13];
4024 { PropertyTagTypeLong
, PropertyTagFrameDelay
, 8, { 10,0,0,0,20,0,0,0 } },
4025 { PropertyTagTypeASCII
, PropertyTagExifUserComment
, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
4026 { PropertyTagTypeShort
, PropertyTagLoopCount
, 2, { 5,0 } },
4027 { PropertyTagTypeByte
, PropertyTagGlobalPalette
, 12, { 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c } },
4028 { PropertyTagTypeByte
, PropertyTagIndexBackground
, 1, { 2 } },
4029 { PropertyTagTypeByte
, PropertyTagIndexTransparent
, 1, { 8 } }
4034 UINT dim_count
, frame_count
, prop_count
, prop_size
, i
;
4035 UINT total_size
, total_count
;
4037 PropertyItem
*prop_item
;
4038 const char *item_data
;
4040 image
= load_image(animatedgif
, sizeof(animatedgif
));
4041 if (!image
) /* XP fails to load this GIF image */
4043 trace("Failed to load GIF image data\n");
4047 status
= GdipImageGetFrameDimensionsCount(image
, &dim_count
);
4049 expect(1, dim_count
);
4051 status
= GdipImageGetFrameDimensionsList(image
, &guid
, 1);
4053 expect_guid(&FrameDimensionTime
, &guid
, __LINE__
, FALSE
);
4055 status
= GdipImageGetFrameCount(image
, &guid
, &frame_count
);
4057 expect(2, frame_count
);
4059 status
= GdipImageSelectActiveFrame(image
, &guid
, 1);
4062 status
= GdipGetPropertyCount(image
, &prop_count
);
4064 ok(prop_count
== sizeof(td
)/sizeof(td
[0]) || broken(prop_count
== 1) /* before win7 */,
4065 "expected property count %u, got %u\n", (UINT
)(sizeof(td
)/sizeof(td
[0])), prop_count
);
4067 if (prop_count
!= sizeof(td
)/sizeof(td
[0]))
4069 GdipDisposeImage(image
);
4073 prop_id
= HeapAlloc(GetProcessHeap(), 0, prop_count
* sizeof(*prop_id
));
4075 status
= GdipGetPropertyIdList(image
, prop_count
, prop_id
);
4079 for (i
= 0; i
< prop_count
; i
++)
4082 status
= GdipGetPropertyItemSize(image
, prop_id
[i
], &size
);
4084 if (status
!= Ok
) break;
4085 ok(size
> sizeof(*prop_item
), "%u: too small item length %u\n", i
, size
);
4089 prop_item
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
4090 status
= GdipGetPropertyItem(image
, prop_id
[i
], size
, prop_item
);
4092 ok(prop_item
->value
== prop_item
+ 1, "expected item->value %p, got %p\n", prop_item
+ 1, prop_item
->value
);
4093 ok(td
[i
].type
== prop_item
->type
,
4094 "%u: expected type %u, got %u\n", i
, td
[i
].type
, prop_item
->type
);
4095 ok(td
[i
].id
== prop_item
->id
, "%u: expected id %#x, got %#x\n", i
, td
[i
].id
, prop_item
->id
);
4096 size
-= sizeof(*prop_item
);
4097 ok(prop_item
->length
== size
, "%u: expected length %u, got %u\n", i
, size
, prop_item
->length
);
4098 ok(td
[i
].length
== prop_item
->length
, "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_item
->length
);
4099 if (td
[i
].length
== prop_item
->length
)
4101 int match
= memcmp(td
[i
].value
, prop_item
->value
, td
[i
].length
) == 0;
4102 ok(match
, "%u: data mismatch\n", i
);
4106 BYTE
*data
= prop_item
->value
;
4107 trace("id %#x:", prop_item
->id
);
4108 for (j
= 0; j
< prop_item
->length
; j
++)
4109 trace(" %02x", data
[j
]);
4113 HeapFree(GetProcessHeap(), 0, prop_item
);
4116 HeapFree(GetProcessHeap(), 0, prop_id
);
4118 status
= GdipGetPropertySize(NULL
, &total_size
, &total_count
);
4119 expect(InvalidParameter
, status
);
4120 status
= GdipGetPropertySize(image
, &total_size
, NULL
);
4121 expect(InvalidParameter
, status
);
4122 status
= GdipGetPropertySize(image
, NULL
, &total_count
);
4123 expect(InvalidParameter
, status
);
4124 status
= GdipGetPropertySize(image
, NULL
, NULL
);
4125 expect(InvalidParameter
, status
);
4126 total_size
= 0xdeadbeef;
4127 total_count
= 0xdeadbeef;
4128 status
= GdipGetPropertySize(image
, &total_size
, &total_count
);
4130 ok(prop_count
== total_count
,
4131 "expected total property count %u, got %u\n", prop_count
, total_count
);
4132 ok(prop_size
== total_size
,
4133 "expected total property size %u, got %u\n", prop_size
, total_size
);
4135 prop_item
= HeapAlloc(GetProcessHeap(), 0, prop_size
);
4137 status
= GdipGetAllPropertyItems(image
, 0, prop_count
, prop_item
);
4138 expect(InvalidParameter
, status
);
4139 status
= GdipGetAllPropertyItems(image
, prop_size
, 1, prop_item
);
4140 expect(InvalidParameter
, status
);
4141 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, NULL
);
4142 expect(InvalidParameter
, status
);
4143 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, NULL
);
4144 expect(InvalidParameter
, status
);
4145 status
= GdipGetAllPropertyItems(image
, 0, 0, NULL
);
4146 expect(InvalidParameter
, status
);
4147 status
= GdipGetAllPropertyItems(image
, prop_size
+ 1, prop_count
, prop_item
);
4148 expect(InvalidParameter
, status
);
4149 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, prop_item
);
4152 item_data
= (const char *)(prop_item
+ prop_count
);
4153 for (i
= 0; i
< prop_count
; i
++)
4155 ok(prop_item
[i
].value
== item_data
, "%u: expected value %p, got %p\n",
4156 i
, item_data
, prop_item
[i
].value
);
4157 ok(td
[i
].type
== prop_item
[i
].type
,
4158 "%u: expected type %u, got %u\n", i
, td
[i
].type
, prop_item
[i
].type
);
4159 ok(td
[i
].id
== prop_item
[i
].id
, "%u: expected id %#x, got %#x\n", i
, td
[i
].id
, prop_item
[i
].id
);
4160 ok(td
[i
].length
== prop_item
[i
].length
, "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_item
[i
].length
);
4161 if (td
[i
].length
== prop_item
[i
].length
)
4163 int match
= memcmp(td
[i
].value
, prop_item
[i
].value
, td
[i
].length
) == 0;
4164 ok(match
, "%u: data mismatch\n", i
);
4168 BYTE
*data
= prop_item
[i
].value
;
4169 trace("id %#x:", prop_item
[i
].id
);
4170 for (j
= 0; j
< prop_item
[i
].length
; j
++)
4171 trace(" %02x", data
[j
]);
4175 item_data
+= prop_item
[i
].length
;
4178 HeapFree(GetProcessHeap(), 0, prop_item
);
4180 GdipDisposeImage(image
);
4183 static void test_ARGB_conversion(void)
4185 BYTE argb
[8] = { 0x11,0x22,0x33,0x80, 0xff,0xff,0xff,0 };
4186 BYTE pargb
[8] = { 0x09,0x11,0x1a,0x80, 0,0,0,0 };
4187 BYTE rgb32_xp
[8] = { 0x11,0x22,0x33,0xff, 0xff,0xff,0xff,0xff };
4188 BYTE rgb24
[6] = { 0x11,0x22,0x33, 0xff,0xff,0xff };
4195 status
= GdipCreateBitmapFromScan0(2, 1, 8, PixelFormat32bppARGB
, argb
, &bitmap
);
4198 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat32bppPARGB
, &data
);
4200 ok(data
.Width
== 2, "expected 2, got %d\n", data
.Width
);
4201 ok(data
.Height
== 1, "expected 1, got %d\n", data
.Height
);
4202 ok(data
.Stride
== 8, "expected 8, got %d\n", data
.Stride
);
4203 ok(data
.PixelFormat
== PixelFormat32bppPARGB
, "expected PixelFormat32bppPARGB, got %d\n", data
.PixelFormat
);
4204 match
= !memcmp(data
.Scan0
, pargb
, sizeof(pargb
));
4205 ok(match
, "bits don't match\n");
4209 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat32bppPARGB
,
4210 bits
[0], bits
[1], bits
[2], bits
[3], bits
[4], bits
[5], bits
[6], bits
[7]);
4212 status
= GdipBitmapUnlockBits(bitmap
, &data
);
4215 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat32bppRGB
, &data
);
4217 ok(data
.Width
== 2, "expected 2, got %d\n", data
.Width
);
4218 ok(data
.Height
== 1, "expected 1, got %d\n", data
.Height
);
4219 ok(data
.Stride
== 8, "expected 8, got %d\n", data
.Stride
);
4220 ok(data
.PixelFormat
== PixelFormat32bppRGB
, "expected PixelFormat32bppRGB, got %d\n", data
.PixelFormat
);
4221 match
= !memcmp(data
.Scan0
, argb
, sizeof(argb
)) ||
4222 !memcmp(data
.Scan0
, rgb32_xp
, sizeof(rgb32_xp
));
4223 ok(match
, "bits don't match\n");
4227 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat32bppRGB
,
4228 bits
[0], bits
[1], bits
[2], bits
[3], bits
[4], bits
[5], bits
[6], bits
[7]);
4230 status
= GdipBitmapUnlockBits(bitmap
, &data
);
4233 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat24bppRGB
, &data
);
4235 ok(data
.Width
== 2, "expected 2, got %d\n", data
.Width
);
4236 ok(data
.Height
== 1, "expected 1, got %d\n", data
.Height
);
4237 ok(data
.Stride
== 8, "expected 8, got %d\n", data
.Stride
);
4238 ok(data
.PixelFormat
== PixelFormat24bppRGB
, "expected PixelFormat24bppRGB, got %d\n", data
.PixelFormat
);
4239 match
= !memcmp(data
.Scan0
, rgb24
, sizeof(rgb24
));
4240 ok(match
, "bits don't match\n");
4244 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat24bppRGB
,
4245 bits
[0], bits
[1], bits
[2], bits
[3], bits
[4], bits
[5], bits
[6], bits
[7]);
4247 status
= GdipBitmapUnlockBits(bitmap
, &data
);
4250 GdipDisposeImage((GpImage
*)bitmap
);
4254 static void test_CloneBitmapArea(void)
4257 GpBitmap
*bitmap
, *copy
;
4258 BitmapData data
, data2
;
4260 status
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat24bppRGB
, NULL
, &bitmap
);
4263 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
| ImageLockModeWrite
, PixelFormat24bppRGB
, &data
);
4266 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat24bppRGB
, &data2
);
4267 expect(WrongState
, status
);
4269 status
= GdipCloneBitmapAreaI(0, 0, 1, 1, PixelFormat24bppRGB
, bitmap
, ©
);
4272 status
= GdipBitmapUnlockBits(bitmap
, &data
);
4275 GdipDisposeImage((GpImage
*)copy
);
4276 GdipDisposeImage((GpImage
*)bitmap
);
4281 struct GdiplusStartupInput gdiplusStartupInput
;
4282 ULONG_PTR gdiplusToken
;
4284 gdiplusStartupInput
.GdiplusVersion
= 1;
4285 gdiplusStartupInput
.DebugEventCallback
= NULL
;
4286 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
4287 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
4289 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
4291 test_CloneBitmapArea();
4292 test_ARGB_conversion();
4293 test_DrawImage_scale();
4294 test_image_format();
4296 test_GdipDrawImagePointRect();
4298 test_tiff_palette();
4299 test_GdipGetAllPropertyItems();
4300 test_tiff_properties();
4301 test_gif_properties();
4302 test_image_properties();
4305 test_GetImageDimension();
4306 test_GdipImageGetFrameDimensionsCount();
4307 test_LoadingImages();
4308 test_SavingImages();
4311 test_LockBits_UserBuf();
4312 test_GdipCreateBitmapFromHBITMAP();
4313 test_GdipGetImageFlags();
4314 test_GdipCloneImage();
4317 test_getrawformat();
4319 test_createfromwmf();
4321 test_createhbitmap();
4322 test_getthumbnail();
4327 test_multiframegif();
4333 GdiplusShutdown(gdiplusToken
);