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)
386 static const WCHAR nonexistentW
[] = {'n','o','n','e','x','i','s','t','e','n','t',0};
388 stat
= GdipCreateBitmapFromFile(0, 0);
389 expect(InvalidParameter
, stat
);
391 bm
= (GpBitmap
*)0xdeadbeef;
392 stat
= GdipCreateBitmapFromFile(0, &bm
);
393 expect(InvalidParameter
, stat
);
394 ok(bm
== (GpBitmap
*)0xdeadbeef, "returned %p\n", bm
);
396 bm
= (GpBitmap
*)0xdeadbeef;
397 stat
= GdipCreateBitmapFromFile(nonexistentW
, &bm
);
398 todo_wine
expect(InvalidParameter
, stat
);
399 ok(!bm
, "returned %p\n", bm
);
401 stat
= GdipLoadImageFromFile(0, 0);
402 expect(InvalidParameter
, stat
);
404 img
= (GpImage
*)0xdeadbeef;
405 stat
= GdipLoadImageFromFile(0, &img
);
406 expect(InvalidParameter
, stat
);
407 ok(img
== (GpImage
*)0xdeadbeef, "returned %p\n", img
);
409 img
= (GpImage
*)0xdeadbeef;
410 stat
= GdipLoadImageFromFile(nonexistentW
, &img
);
411 todo_wine
expect(OutOfMemory
, stat
);
412 ok(!img
, "returned %p\n", img
);
414 stat
= GdipLoadImageFromFileICM(0, 0);
415 expect(InvalidParameter
, stat
);
417 img
= (GpImage
*)0xdeadbeef;
418 stat
= GdipLoadImageFromFileICM(0, &img
);
419 expect(InvalidParameter
, stat
);
420 ok(img
== (GpImage
*)0xdeadbeef, "returned %p\n", img
);
422 img
= (GpImage
*)0xdeadbeef;
423 stat
= GdipLoadImageFromFileICM(nonexistentW
, &img
);
424 todo_wine
expect(OutOfMemory
, stat
);
425 ok(!img
, "returned %p\n", img
);
428 static void test_SavingImages(void)
434 const REAL WIDTH
= 10.0, HEIGHT
= 20.0;
436 ImageCodecInfo
*codecs
;
437 static const CHAR filenameA
[] = "a.bmp";
438 static const WCHAR filename
[] = { 'a','.','b','m','p',0 };
442 stat
= GdipSaveImageToFile(0, 0, 0, 0);
443 expect(InvalidParameter
, stat
);
446 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
452 stat
= GdipSaveImageToFile((GpImage
*)bm
, 0, 0, 0);
453 expect(InvalidParameter
, stat
);
455 stat
= GdipSaveImageToFile((GpImage
*)bm
, filename
, 0, 0);
456 expect(InvalidParameter
, stat
);
458 /* encoder tests should succeed -- already tested */
459 stat
= GdipGetImageEncodersSize(&n
, &s
);
460 if (stat
!= Ok
|| n
== 0) goto cleanup
;
462 codecs
= GdipAlloc(s
);
463 if (!codecs
) goto cleanup
;
465 stat
= GdipGetImageEncoders(n
, s
, codecs
);
466 if (stat
!= Ok
) goto cleanup
;
468 stat
= GdipSaveImageToFile((GpImage
*)bm
, filename
, &codecs
[0].Clsid
, 0);
471 GdipDisposeImage((GpImage
*)bm
);
474 /* re-load and check image stats */
475 stat
= GdipLoadImageFromFile(filename
, (GpImage
**)&bm
);
477 if (stat
!= Ok
) goto cleanup
;
479 stat
= GdipGetImageDimension((GpImage
*)bm
, &w
, &h
);
480 if (stat
!= Ok
) goto cleanup
;
488 GdipDisposeImage((GpImage
*)bm
);
489 ok(DeleteFileA(filenameA
), "Delete failed.\n");
492 static void test_encoders(void)
497 ImageCodecInfo
*codecs
;
501 static const CHAR bmp_format
[] = "BMP";
503 stat
= GdipGetImageEncodersSize(&n
, &s
);
506 codecs
= GdipAlloc(s
);
510 stat
= GdipGetImageEncoders(n
, s
, NULL
);
511 expect(GenericError
, stat
);
513 stat
= GdipGetImageEncoders(0, s
, codecs
);
514 expect(GenericError
, stat
);
516 stat
= GdipGetImageEncoders(n
, s
-1, codecs
);
517 expect(GenericError
, stat
);
519 stat
= GdipGetImageEncoders(n
, s
+1, codecs
);
520 expect(GenericError
, stat
);
522 stat
= GdipGetImageEncoders(n
, s
, codecs
);
526 for (i
= 0; i
< n
; i
++)
530 WideCharToMultiByte(CP_ACP
, 0, codecs
[i
].FormatDescription
, -1,
533 if (CompareStringA(LOCALE_SYSTEM_DEFAULT
, 0,
535 bmp_format
, -1) == CSTR_EQUAL
) {
541 ok(FALSE
, "No BMP codec found.\n");
546 static void test_LockBits(void)
552 const INT WIDTH
= 10, HEIGHT
= 20;
557 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
565 stat
= GdipBitmapSetPixel(bm
, 2, 3, 0xffc30000);
568 stat
= GdipBitmapSetPixel(bm
, 2, 8, 0xff480000);
572 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
576 expect(0xc3, ((BYTE
*)bd
.Scan0
)[2]);
577 expect(0x48, ((BYTE
*)bd
.Scan0
)[2 + bd
.Stride
* 5]);
579 ((char*)bd
.Scan0
)[2] = 0xff;
581 stat
= GdipBitmapUnlockBits(bm
, &bd
);
585 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
587 expect(0xffff0000, color
);
589 stat
= GdipBitmapSetPixel(bm
, 2, 3, 0xffc30000);
592 /* read-only, with NULL rect -> whole bitmap lock */
593 stat
= GdipBitmapLockBits(bm
, NULL
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
595 expect(bd
.Width
, WIDTH
);
596 expect(bd
.Height
, HEIGHT
);
599 ((char*)bd
.Scan0
)[2 + 2*3 + 3*bd
.Stride
] = 0xff;
601 stat
= GdipBitmapUnlockBits(bm
, &bd
);
605 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
607 expect(0xffff0000, color
);
609 /* read-only, consecutive */
610 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
614 stat
= GdipBitmapUnlockBits(bm
, &bd
);
618 stat
= GdipDisposeImage((GpImage
*)bm
);
620 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
624 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
626 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
627 expect(WrongState
, stat
);
629 stat
= GdipBitmapUnlockBits(bm
, &bd
);
632 stat
= GdipDisposeImage((GpImage
*)bm
);
634 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
637 stat
= GdipBitmapSetPixel(bm
, 2, 3, 0xffff0000);
640 stat
= GdipBitmapSetPixel(bm
, 2, 8, 0xffc30000);
643 /* write, no conversion */
644 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
, PixelFormat24bppRGB
, &bd
);
648 /* all bits are readable, inside the rect or not */
649 expect(0xff, ((BYTE
*)bd
.Scan0
)[2]);
650 expect(0xc3, ((BYTE
*)bd
.Scan0
)[2 + bd
.Stride
* 5]);
652 stat
= GdipBitmapUnlockBits(bm
, &bd
);
656 /* read, conversion */
657 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat32bppARGB
, &bd
);
661 expect(0xff, ((BYTE
*)bd
.Scan0
)[2]);
663 /* Areas outside the rectangle appear to be uninitialized */
664 ok(0xc3 != ((BYTE
*)bd
.Scan0
)[2 + bd
.Stride
* 5], "original image bits are readable\n");
666 ((BYTE
*)bd
.Scan0
)[2] = 0xc3;
668 stat
= GdipBitmapUnlockBits(bm
, &bd
);
672 /* writes do not work in read mode if there was a conversion */
673 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
675 expect(0xffff0000, color
);
677 /* read/write, conversion */
678 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
|ImageLockModeWrite
, PixelFormat32bppARGB
, &bd
);
682 expect(0xff, ((BYTE
*)bd
.Scan0
)[2]);
683 ((BYTE
*)bd
.Scan0
)[1] = 0x88;
685 /* Areas outside the rectangle appear to be uninitialized */
686 ok(0xc3 != ((BYTE
*)bd
.Scan0
)[2 + bd
.Stride
* 5], "original image bits are readable\n");
688 stat
= GdipBitmapUnlockBits(bm
, &bd
);
692 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
694 expect(0xffff8800, color
);
696 /* write, conversion */
697 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
, PixelFormat32bppARGB
, &bd
);
703 /* This is completely uninitialized. */
704 ok(0xff != ((BYTE
*)bd
.Scan0
)[2], "original image bits are readable\n");
705 ok(0xc3 != ((BYTE
*)bd
.Scan0
)[2 + bd
.Stride
* 5], "original image bits are readable\n");
708 /* Initialize the buffer so the unlock doesn't access undefined memory */
710 memset(((BYTE
*)bd
.Scan0
) + bd
.Stride
* y
, 0, 12);
712 ((BYTE
*)bd
.Scan0
)[0] = 0x12;
713 ((BYTE
*)bd
.Scan0
)[1] = 0x34;
714 ((BYTE
*)bd
.Scan0
)[2] = 0x56;
716 stat
= GdipBitmapUnlockBits(bm
, &bd
);
720 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
722 expect(0xff563412, color
);
724 stat
= GdipBitmapGetPixel(bm
, 2, 8, &color
);
726 expect(0xffc30000, color
);
728 stat
= GdipDisposeImage((GpImage
*)bm
);
730 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
733 /* write, no modification */
734 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
, PixelFormat24bppRGB
, &bd
);
738 stat
= GdipBitmapUnlockBits(bm
, &bd
);
742 /* write, consecutive */
743 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
, PixelFormat24bppRGB
, &bd
);
747 stat
= GdipBitmapUnlockBits(bm
, &bd
);
751 stat
= GdipDisposeImage((GpImage
*)bm
);
753 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
757 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
, PixelFormat24bppRGB
, &bd
);
762 ((char*)bd
.Scan0
)[2] = 0xff;
764 stat
= GdipBitmapUnlockBits(bm
, &bd
);
768 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
770 expect(0xffff0000, color
);
772 stat
= GdipDisposeImage((GpImage
*)bm
);
776 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
778 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
, PixelFormat24bppRGB
, &bd
);
780 stat
= GdipDisposeImage((GpImage
*)bm
);
784 static void test_LockBits_UserBuf(void)
790 const INT WIDTH
= 10, HEIGHT
= 20;
795 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat32bppARGB
, NULL
, &bm
);
798 memset(bits
, 0xaa, sizeof(bits
));
807 bd
.Stride
= WIDTH
* 4;
808 bd
.PixelFormat
= PixelFormat32bppARGB
;
809 bd
.Scan0
= &bits
[2+3*WIDTH
];
810 bd
.Reserved
= 0xaaaaaaaa;
813 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
|ImageLockModeUserInputBuf
, PixelFormat32bppARGB
, &bd
);
816 expect(0xaaaaaaaa, bits
[0]);
817 expect(0, bits
[2+3*WIDTH
]);
819 bits
[2+3*WIDTH
] = 0xdeadbeef;
822 stat
= GdipBitmapUnlockBits(bm
, &bd
);
826 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
831 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeWrite
|ImageLockModeUserInputBuf
, PixelFormat32bppARGB
, &bd
);
834 expect(0xdeadbeef, bits
[2+3*WIDTH
]);
835 bits
[2+3*WIDTH
] = 0x12345678;
838 stat
= GdipBitmapUnlockBits(bm
, &bd
);
842 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
844 expect(0x12345678, color
);
849 stat
= GdipBitmapLockBits(bm
, &rect
, ImageLockModeRead
|ImageLockModeWrite
|ImageLockModeUserInputBuf
, PixelFormat32bppARGB
, &bd
);
852 expect(0x12345678, bits
[2+3*WIDTH
]);
853 bits
[2+3*WIDTH
] = 0xdeadbeef;
856 stat
= GdipBitmapUnlockBits(bm
, &bd
);
860 stat
= GdipBitmapGetPixel(bm
, 2, 3, &color
);
862 expect(0xdeadbeef, color
);
864 stat
= GdipDisposeImage((GpImage
*)bm
);
868 struct BITMAPINFOWITHBITFIELDS
870 BITMAPINFOHEADER bmiHeader
;
874 union BITMAPINFOUNION
877 struct BITMAPINFOWITHBITFIELDS bf
;
880 static void test_GdipCreateBitmapFromHBITMAP(void)
882 GpBitmap
* gpbm
= NULL
;
884 HPALETTE hpal
= NULL
;
887 LOGPALETTE
* LogPal
= NULL
;
889 const REAL WIDTH1
= 5;
890 const REAL HEIGHT1
= 15;
891 const REAL WIDTH2
= 10;
892 const REAL HEIGHT2
= 20;
894 union BITMAPINFOUNION bmi
;
898 stat
= GdipCreateBitmapFromHBITMAP(NULL
, NULL
, NULL
);
899 expect(InvalidParameter
, stat
);
901 hbm
= CreateBitmap(WIDTH1
, HEIGHT1
, 1, 1, NULL
);
902 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, NULL
);
903 expect(InvalidParameter
, stat
);
905 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
907 expect(Ok
, GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
));
908 expectf(WIDTH1
, width
);
909 expectf(HEIGHT1
, height
);
911 GdipDisposeImage((GpImage
*)gpbm
);
914 memset(buff
, 0, sizeof(buff
));
915 hbm
= CreateBitmap(WIDTH2
, HEIGHT2
, 1, 1, &buff
);
916 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
919 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)gpbm
, __LINE__
, FALSE
);
921 expect(Ok
, GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
));
922 expectf(WIDTH2
, width
);
923 expectf(HEIGHT2
, height
);
925 GdipDisposeImage((GpImage
*)gpbm
);
928 hdc
= CreateCompatibleDC(0);
929 ok(hdc
!= NULL
, "CreateCompatibleDC failed\n");
930 bmi
.bi
.bmiHeader
.biSize
= sizeof(bmi
.bi
.bmiHeader
);
931 bmi
.bi
.bmiHeader
.biHeight
= HEIGHT1
;
932 bmi
.bi
.bmiHeader
.biWidth
= WIDTH1
;
933 bmi
.bi
.bmiHeader
.biBitCount
= 24;
934 bmi
.bi
.bmiHeader
.biPlanes
= 1;
935 bmi
.bi
.bmiHeader
.biCompression
= BI_RGB
;
936 bmi
.bi
.bmiHeader
.biClrUsed
= 0;
938 hbm
= CreateDIBSection(hdc
, &bmi
.bi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
939 ok(hbm
!= NULL
, "CreateDIBSection failed\n");
943 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
945 expect(Ok
, GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
));
946 expectf(WIDTH1
, width
);
947 expectf(HEIGHT1
, height
);
950 /* test whether writing to the bitmap affects the original */
951 stat
= GdipBitmapSetPixel(gpbm
, 0, 0, 0xffffffff);
956 GdipDisposeImage((GpImage
*)gpbm
);
959 LogPal
= GdipAlloc(sizeof(LOGPALETTE
));
960 ok(LogPal
!= NULL
, "unable to allocate LOGPALETTE\n");
961 LogPal
->palVersion
= 0x300;
962 LogPal
->palNumEntries
= 1;
963 hpal
= CreatePalette(LogPal
);
964 ok(hpal
!= NULL
, "CreatePalette failed\n");
967 stat
= GdipCreateBitmapFromHBITMAP(hbm
, hpal
, &gpbm
);
971 GdipDisposeImage((GpImage
*)gpbm
);
976 /* 16-bit 555 dib, rgb */
977 bmi
.bi
.bmiHeader
.biBitCount
= 16;
978 bmi
.bi
.bmiHeader
.biCompression
= BI_RGB
;
980 hbm
= CreateDIBSection(hdc
, &bmi
.bi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
981 ok(hbm
!= NULL
, "CreateDIBSection failed\n");
985 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
990 stat
= GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
);
992 expectf(WIDTH1
, width
);
993 expectf(HEIGHT1
, height
);
995 stat
= GdipGetImagePixelFormat((GpImage
*) gpbm
, &format
);
997 expect(PixelFormat16bppRGB555
, format
);
999 GdipDisposeImage((GpImage
*)gpbm
);
1003 /* 16-bit 555 dib, with bitfields */
1004 bmi
.bi
.bmiHeader
.biSize
= sizeof(bmi
);
1005 bmi
.bi
.bmiHeader
.biCompression
= BI_BITFIELDS
;
1006 bmi
.bf
.masks
[0] = 0x7c00;
1007 bmi
.bf
.masks
[1] = 0x3e0;
1008 bmi
.bf
.masks
[2] = 0x1f;
1010 hbm
= CreateDIBSection(hdc
, &bmi
.bi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1011 ok(hbm
!= NULL
, "CreateDIBSection failed\n");
1015 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
1020 stat
= GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
);
1022 expectf(WIDTH1
, width
);
1023 expectf(HEIGHT1
, height
);
1025 stat
= GdipGetImagePixelFormat((GpImage
*) gpbm
, &format
);
1027 expect(PixelFormat16bppRGB555
, format
);
1029 GdipDisposeImage((GpImage
*)gpbm
);
1033 /* 16-bit 565 dib, with bitfields */
1034 bmi
.bf
.masks
[0] = 0xf800;
1035 bmi
.bf
.masks
[1] = 0x7e0;
1036 bmi
.bf
.masks
[2] = 0x1f;
1038 hbm
= CreateDIBSection(hdc
, &bmi
.bi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1039 ok(hbm
!= NULL
, "CreateDIBSection failed\n");
1043 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, &gpbm
);
1048 stat
= GdipGetImageDimension((GpImage
*) gpbm
, &width
, &height
);
1050 expectf(WIDTH1
, width
);
1051 expectf(HEIGHT1
, height
);
1053 stat
= GdipGetImagePixelFormat((GpImage
*) gpbm
, &format
);
1055 expect(PixelFormat16bppRGB565
, format
);
1057 GdipDisposeImage((GpImage
*)gpbm
);
1064 static void test_GdipGetImageFlags(void)
1070 img
= (GpImage
*)0xdeadbeef;
1072 stat
= GdipGetImageFlags(NULL
, NULL
);
1073 expect(InvalidParameter
, stat
);
1075 stat
= GdipGetImageFlags(NULL
, &flags
);
1076 expect(InvalidParameter
, stat
);
1078 stat
= GdipGetImageFlags(img
, NULL
);
1079 expect(InvalidParameter
, stat
);
1081 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed
, NULL
, (GpBitmap
**)&img
);
1083 stat
= GdipGetImageFlags(img
, &flags
);
1085 expect(ImageFlagsHasAlpha
, flags
);
1086 GdipDisposeImage(img
);
1088 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed
, NULL
, (GpBitmap
**)&img
);
1090 stat
= GdipGetImageFlags(img
, &flags
);
1092 expect(ImageFlagsHasAlpha
, flags
);
1093 GdipDisposeImage(img
);
1095 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed
, NULL
, (GpBitmap
**)&img
);
1097 stat
= GdipGetImageFlags(img
, &flags
);
1099 expect(ImageFlagsHasAlpha
, flags
);
1100 GdipDisposeImage(img
);
1102 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale
, NULL
, (GpBitmap
**)&img
);
1104 stat
= GdipGetImageFlags(img
, &flags
);
1106 expect(ImageFlagsNone
, flags
);
1107 GdipDisposeImage(img
);
1109 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555
, NULL
, (GpBitmap
**)&img
);
1111 stat
= GdipGetImageFlags(img
, &flags
);
1113 expect(ImageFlagsNone
, flags
);
1114 GdipDisposeImage(img
);
1116 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565
, NULL
, (GpBitmap
**)&img
);
1118 stat
= GdipGetImageFlags(img
, &flags
);
1120 expect(ImageFlagsNone
, flags
);
1121 GdipDisposeImage(img
);
1123 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppARGB1555
, NULL
, (GpBitmap
**)&img
);
1125 stat
= GdipGetImageFlags(img
, &flags
);
1127 expect(ImageFlagsHasAlpha
, flags
);
1128 GdipDisposeImage(img
);
1130 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB
, NULL
, (GpBitmap
**)&img
);
1132 stat
= GdipGetImageFlags(img
, &flags
);
1134 expect(ImageFlagsNone
, flags
);
1135 GdipDisposeImage(img
);
1137 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB
, NULL
, (GpBitmap
**)&img
);
1139 stat
= GdipGetImageFlags(img
, &flags
);
1141 expect(ImageFlagsNone
, flags
);
1142 GdipDisposeImage(img
);
1144 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB
, NULL
, (GpBitmap
**)&img
);
1146 stat
= GdipGetImageFlags(img
, &flags
);
1148 expect(ImageFlagsHasAlpha
, flags
);
1149 GdipDisposeImage(img
);
1151 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppPARGB
, NULL
, (GpBitmap
**)&img
);
1153 stat
= GdipGetImageFlags(img
, &flags
);
1155 expect(ImageFlagsHasAlpha
, flags
);
1156 GdipDisposeImage(img
);
1158 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB
, NULL
, (GpBitmap
**)&img
);
1162 stat
= GdipGetImageFlags(img
, &flags
);
1164 expect(ImageFlagsNone
, flags
);
1165 GdipDisposeImage(img
);
1168 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB
, NULL
, (GpBitmap
**)&img
);
1173 stat
= GdipGetImageFlags(img
, &flags
);
1175 expect(ImageFlagsHasAlpha
, flags
);
1176 GdipDisposeImage(img
);
1179 stat
= GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB
, NULL
, (GpBitmap
**)&img
);
1184 stat
= GdipGetImageFlags(img
, &flags
);
1186 expect(ImageFlagsHasAlpha
, flags
);
1187 GdipDisposeImage(img
);
1191 static void test_GdipCloneImage(void)
1197 GpImage
*image_src
, *image_dest
= NULL
;
1198 const INT WIDTH
= 10, HEIGHT
= 20;
1200 /* Create an image, clone it, delete the original, make sure the copy works */
1201 stat
= GdipCreateBitmapFromScan0(WIDTH
, HEIGHT
, 0, PixelFormat24bppRGB
, NULL
, &bm
);
1203 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)bm
, __LINE__
, FALSE
);
1205 image_src
= ((GpImage
*)bm
);
1206 stat
= GdipCloneImage(image_src
, &image_dest
);
1208 expect_rawformat(&ImageFormatMemoryBMP
, image_dest
, __LINE__
, FALSE
);
1210 stat
= GdipDisposeImage((GpImage
*)bm
);
1212 stat
= GdipGetImageBounds(image_dest
, &rectF
, &unit
);
1215 /* Treat FP values carefully */
1216 expectf((REAL
)WIDTH
, rectF
.Width
);
1217 expectf((REAL
)HEIGHT
, rectF
.Height
);
1219 stat
= GdipDisposeImage(image_dest
);
1223 static void test_testcontrol(void)
1229 stat
= GdipTestControl(TestControlGetBuildNumber
, ¶m
);
1231 ok(param
!= 0, "Build number expected, got %u\n", param
);
1234 static void test_fromhicon(void)
1236 static const BYTE bmp_bits
[1024];
1237 HBITMAP hbmMask
, hbmColor
;
1241 GpBitmap
*bitmap
= NULL
;
1247 stat
= GdipCreateBitmapFromHICON(NULL
, NULL
);
1248 expect(InvalidParameter
, stat
);
1249 stat
= GdipCreateBitmapFromHICON(NULL
, &bitmap
);
1250 expect(InvalidParameter
, stat
);
1252 /* color icon 1 bit */
1253 hbmMask
= CreateBitmap(16, 16, 1, 1, bmp_bits
);
1254 ok(hbmMask
!= 0, "CreateBitmap failed\n");
1255 hbmColor
= CreateBitmap(16, 16, 1, 1, bmp_bits
);
1256 ok(hbmColor
!= 0, "CreateBitmap failed\n");
1260 info
.hbmMask
= hbmMask
;
1261 info
.hbmColor
= hbmColor
;
1262 hIcon
= CreateIconIndirect(&info
);
1263 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
1264 DeleteObject(hbmMask
);
1265 DeleteObject(hbmColor
);
1267 stat
= GdipCreateBitmapFromHICON(hIcon
, &bitmap
);
1269 broken(stat
== InvalidParameter
), /* Win98 */
1270 "Expected Ok, got %.8x\n", stat
);
1272 /* check attributes */
1273 stat
= GdipGetImageHeight((GpImage
*)bitmap
, &dim
);
1276 stat
= GdipGetImageWidth((GpImage
*)bitmap
, &dim
);
1279 stat
= GdipGetImageType((GpImage
*)bitmap
, &type
);
1281 expect(ImageTypeBitmap
, type
);
1282 stat
= GdipGetImagePixelFormat((GpImage
*)bitmap
, &format
);
1284 expect(PixelFormat32bppARGB
, format
);
1286 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)bitmap
, __LINE__
, FALSE
);
1287 GdipDisposeImage((GpImage
*)bitmap
);
1291 /* color icon 8 bpp */
1292 hbmMask
= CreateBitmap(16, 16, 1, 8, bmp_bits
);
1293 ok(hbmMask
!= 0, "CreateBitmap failed\n");
1294 hbmColor
= CreateBitmap(16, 16, 1, 8, bmp_bits
);
1295 ok(hbmColor
!= 0, "CreateBitmap failed\n");
1299 info
.hbmMask
= hbmMask
;
1300 info
.hbmColor
= hbmColor
;
1301 hIcon
= CreateIconIndirect(&info
);
1302 ok(hIcon
!= 0, "CreateIconIndirect failed\n");
1303 DeleteObject(hbmMask
);
1304 DeleteObject(hbmColor
);
1306 stat
= GdipCreateBitmapFromHICON(hIcon
, &bitmap
);
1309 /* check attributes */
1310 stat
= GdipGetImageHeight((GpImage
*)bitmap
, &dim
);
1313 stat
= GdipGetImageWidth((GpImage
*)bitmap
, &dim
);
1316 stat
= GdipGetImageType((GpImage
*)bitmap
, &type
);
1318 expect(ImageTypeBitmap
, type
);
1319 stat
= GdipGetImagePixelFormat((GpImage
*)bitmap
, &format
);
1321 expect(PixelFormat32bppARGB
, format
);
1323 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)bitmap
, __LINE__
, FALSE
);
1324 GdipDisposeImage((GpImage
*)bitmap
);
1330 static const unsigned char pngimage
[285] = {
1331 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
1332 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
1333 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
1334 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
1335 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
1336 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
1337 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
1340 static const unsigned char gifimage
[35] = {
1341 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
1342 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
1346 static const unsigned char bmpimage
[66] = {
1347 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
1348 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
1349 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
1350 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
1354 static const unsigned char jpgimage
[285] = {
1355 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
1356 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
1357 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
1358 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
1359 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
1360 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
1361 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
1362 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1363 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1364 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
1365 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
1366 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1367 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
1368 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
1369 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1370 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
1371 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
1372 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
1374 /* 1x1 pixel tiff */
1375 static const unsigned char tiffimage
[] = {
1376 0x49,0x49,0x2a,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xfe,0x00,
1377 0x04,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x00,0x01,0x00,
1378 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1379 0x00,0x00,0x02,0x01,0x03,0x00,0x03,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0x03,0x01,
1380 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,0x01,0x03,0x00,0x01,0x00,
1381 0x00,0x00,0x02,0x00,0x00,0x00,0x0d,0x01,0x02,0x00,0x1b,0x00,0x00,0x00,0xd8,0x00,
1382 0x00,0x00,0x11,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x12,0x01,
1383 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x01,0x03,0x00,0x01,0x00,
1384 0x00,0x00,0x03,0x00,0x00,0x00,0x16,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x40,0x00,
1385 0x00,0x00,0x17,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1a,0x01,
1386 0x05,0x00,0x01,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x1b,0x01,0x05,0x00,0x01,0x00,
1387 0x00,0x00,0xfc,0x00,0x00,0x00,0x1c,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1388 0x00,0x00,0x28,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
1389 0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x6d,0x65,
1390 0x68,0x2f,0x44,0x65,0x73,0x6b,0x74,0x6f,0x70,0x2f,0x74,0x65,0x73,0x74,0x2e,0x74,
1391 0x69,0x66,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,
1394 /* 320x320 twip wmf */
1395 static const unsigned char wmfimage
[180] = {
1396 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
1397 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
1398 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
1399 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
1400 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
1401 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
1402 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
1403 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
1404 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
1405 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
1406 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
1409 static void test_getrawformat(void)
1411 test_bufferrawformat((void*)pngimage
, sizeof(pngimage
), &ImageFormatPNG
, __LINE__
, FALSE
);
1412 test_bufferrawformat((void*)gifimage
, sizeof(gifimage
), &ImageFormatGIF
, __LINE__
, FALSE
);
1413 test_bufferrawformat((void*)bmpimage
, sizeof(bmpimage
), &ImageFormatBMP
, __LINE__
, FALSE
);
1414 test_bufferrawformat((void*)jpgimage
, sizeof(jpgimage
), &ImageFormatJPEG
, __LINE__
, FALSE
);
1415 test_bufferrawformat((void*)tiffimage
, sizeof(tiffimage
), &ImageFormatTIFF
, __LINE__
, FALSE
);
1416 test_bufferrawformat((void*)wmfimage
, sizeof(wmfimage
), &ImageFormatWMF
, __LINE__
, FALSE
);
1419 static void test_loadwmf(void)
1430 MetafileHeader header
;
1432 hglob
= GlobalAlloc (0, sizeof(wmfimage
));
1433 data
= GlobalLock (hglob
);
1434 memcpy(data
, wmfimage
, sizeof(wmfimage
));
1435 GlobalUnlock(hglob
); data
= NULL
;
1437 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
1438 ok(hres
== S_OK
, "Failed to create a stream\n");
1439 if(hres
!= S_OK
) return;
1441 stat
= GdipLoadImageFromStream(stream
, &img
);
1442 ok(stat
== Ok
, "Failed to create a Bitmap\n");
1444 IStream_Release(stream
);
1448 IStream_Release(stream
);
1450 stat
= GdipGetImageBounds(img
, &bounds
, &unit
);
1452 todo_wine
expect(UnitPixel
, unit
);
1453 expectf(0.0, bounds
.X
);
1454 expectf(0.0, bounds
.Y
);
1455 todo_wine
expectf(320.0, bounds
.Width
);
1456 todo_wine
expectf(320.0, bounds
.Height
);
1458 stat
= GdipGetImageHorizontalResolution(img
, &res
);
1460 todo_wine
expectf(1440.0, res
);
1462 stat
= GdipGetImageVerticalResolution(img
, &res
);
1464 todo_wine
expectf(1440.0, res
);
1466 memset(&header
, 0, sizeof(header
));
1467 stat
= GdipGetMetafileHeaderFromMetafile((GpMetafile
*)img
, &header
);
1471 todo_wine
expect(MetafileTypeWmfPlaceable
, header
.Type
);
1472 todo_wine
expect(sizeof(wmfimage
)-sizeof(WmfPlaceableFileHeader
), header
.Size
);
1473 todo_wine
expect(0x300, header
.Version
);
1474 expect(0, header
.EmfPlusFlags
);
1475 todo_wine
expectf(1440.0, header
.DpiX
);
1476 todo_wine
expectf(1440.0, header
.DpiY
);
1477 expect(0, header
.X
);
1478 expect(0, header
.Y
);
1479 todo_wine
expect(320, header
.Width
);
1480 todo_wine
expect(320, header
.Height
);
1481 todo_wine
expect(1, U(header
).WmfHeader
.mtType
);
1482 expect(0, header
.EmfPlusHeaderSize
);
1483 expect(0, header
.LogicalDpiX
);
1484 expect(0, header
.LogicalDpiY
);
1487 GdipDisposeImage(img
);
1490 static void test_createfromwmf(void)
1498 MetafileHeader header
;
1500 hwmf
= SetMetaFileBitsEx(sizeof(wmfimage
)-sizeof(WmfPlaceableFileHeader
),
1501 wmfimage
+sizeof(WmfPlaceableFileHeader
));
1502 ok(hwmf
!= 0, "SetMetaFileBitsEx failed\n");
1504 stat
= GdipCreateMetafileFromWmf(hwmf
, TRUE
,
1505 (WmfPlaceableFileHeader
*)wmfimage
, (GpMetafile
**)&img
);
1507 if (stat
!= Ok
) return; // ReactOS
1509 stat
= GdipGetImageBounds(img
, &bounds
, &unit
);
1511 expect(UnitPixel
, unit
);
1512 expectf(0.0, bounds
.X
);
1513 expectf(0.0, bounds
.Y
);
1514 expectf(320.0, bounds
.Width
);
1515 expectf(320.0, bounds
.Height
);
1517 stat
= GdipGetImageHorizontalResolution(img
, &res
);
1519 expectf(1440.0, res
);
1521 stat
= GdipGetImageVerticalResolution(img
, &res
);
1523 expectf(1440.0, res
);
1525 memset(&header
, 0, sizeof(header
));
1526 stat
= GdipGetMetafileHeaderFromMetafile((GpMetafile
*)img
, &header
);
1530 todo_wine
expect(MetafileTypeWmfPlaceable
, header
.Type
);
1531 todo_wine
expect(sizeof(wmfimage
)-sizeof(WmfPlaceableFileHeader
), header
.Size
);
1532 todo_wine
expect(0x300, header
.Version
);
1533 expect(0, header
.EmfPlusFlags
);
1534 todo_wine
expectf(1440.0, header
.DpiX
);
1535 todo_wine
expectf(1440.0, header
.DpiY
);
1536 expect(0, header
.X
);
1537 expect(0, header
.Y
);
1538 todo_wine
expect(320, header
.Width
);
1539 todo_wine
expect(320, header
.Height
);
1540 todo_wine
expect(1, U(header
).WmfHeader
.mtType
);
1541 expect(0, header
.EmfPlusHeaderSize
);
1542 expect(0, header
.LogicalDpiX
);
1543 expect(0, header
.LogicalDpiY
);
1546 GdipDisposeImage(img
);
1549 static void test_resolution(void)
1553 GpGraphics
*graphics
;
1556 int screenxres
, screenyres
;
1559 stat
= GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB
, NULL
, &bitmap
);
1562 /* test invalid values */
1563 stat
= GdipGetImageHorizontalResolution(NULL
, &res
);
1564 expect(InvalidParameter
, stat
);
1566 stat
= GdipGetImageHorizontalResolution((GpImage
*)bitmap
, NULL
);
1567 expect(InvalidParameter
, stat
);
1569 stat
= GdipGetImageVerticalResolution(NULL
, &res
);
1570 expect(InvalidParameter
, stat
);
1572 stat
= GdipGetImageVerticalResolution((GpImage
*)bitmap
, NULL
);
1573 expect(InvalidParameter
, stat
);
1575 stat
= GdipBitmapSetResolution(NULL
, 96.0, 96.0);
1576 expect(InvalidParameter
, stat
);
1578 stat
= GdipBitmapSetResolution(bitmap
, 0.0, 0.0);
1579 expect(InvalidParameter
, stat
);
1581 /* defaults to screen resolution */
1582 screendc
= GetDC(0);
1584 screenxres
= GetDeviceCaps(screendc
, LOGPIXELSX
);
1585 screenyres
= GetDeviceCaps(screendc
, LOGPIXELSY
);
1587 ReleaseDC(0, screendc
);
1589 stat
= GdipGetImageHorizontalResolution((GpImage
*)bitmap
, &res
);
1591 expectf((REAL
)screenxres
, res
);
1593 stat
= GdipGetImageVerticalResolution((GpImage
*)bitmap
, &res
);
1595 expectf((REAL
)screenyres
, res
);
1597 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap
, &graphics
);
1599 stat
= GdipGetDpiX(graphics
, &res
);
1601 expectf((REAL
)screenxres
, res
);
1602 stat
= GdipGetDpiY(graphics
, &res
);
1604 expectf((REAL
)screenyres
, res
);
1606 /* test changing the resolution */
1607 stat
= GdipBitmapSetResolution(bitmap
, screenxres
*2.0, screenyres
*3.0);
1610 stat
= GdipGetImageHorizontalResolution((GpImage
*)bitmap
, &res
);
1612 expectf(screenxres
*2.0, res
);
1614 stat
= GdipGetImageVerticalResolution((GpImage
*)bitmap
, &res
);
1616 expectf(screenyres
*3.0, res
);
1618 stat
= GdipGetDpiX(graphics
, &res
);
1620 expectf((REAL
)screenxres
, res
);
1621 stat
= GdipGetDpiY(graphics
, &res
);
1623 expectf((REAL
)screenyres
, res
);
1625 stat
= GdipDeleteGraphics(graphics
);
1628 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap
, &graphics
);
1630 stat
= GdipGetDpiX(graphics
, &res
);
1632 expectf(screenxres
*2.0, res
);
1633 stat
= GdipGetDpiY(graphics
, &res
);
1635 expectf(screenyres
*3.0, res
);
1636 stat
= GdipDeleteGraphics(graphics
);
1639 stat
= GdipDisposeImage((GpImage
*)bitmap
);
1643 static void test_createhbitmap(void)
1647 HBITMAP hbitmap
, oldhbitmap
;
1654 memset(bits
, 0x68, 640);
1657 stat
= GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB
, bits
, &bitmap
);
1660 /* test NULL values */
1661 stat
= GdipCreateHBITMAPFromBitmap(NULL
, &hbitmap
, 0);
1662 expect(InvalidParameter
, stat
);
1664 stat
= GdipCreateHBITMAPFromBitmap(bitmap
, NULL
, 0);
1665 expect(InvalidParameter
, stat
);
1667 /* create HBITMAP */
1668 stat
= GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
1673 ret
= GetObjectA(hbitmap
, sizeof(BITMAP
), &bm
);
1674 expect(sizeof(BITMAP
), ret
);
1676 expect(0, bm
.bmType
);
1677 expect(10, bm
.bmWidth
);
1678 expect(20, bm
.bmHeight
);
1679 expect(40, bm
.bmWidthBytes
);
1680 expect(1, bm
.bmPlanes
);
1681 expect(32, bm
.bmBitsPixel
);
1682 ok(bm
.bmBits
!= NULL
, "got DDB, expected DIB\n");
1686 DWORD val
= *(DWORD
*)bm
.bmBits
;
1687 ok(val
== 0xff686868, "got %x, expected 0xff686868\n", val
);
1690 hdc
= CreateCompatibleDC(NULL
);
1692 oldhbitmap
= SelectObject(hdc
, hbitmap
);
1693 pixel
= GetPixel(hdc
, 5, 5);
1694 SelectObject(hdc
, oldhbitmap
);
1698 expect(0x686868, pixel
);
1700 DeleteObject(hbitmap
);
1703 stat
= GdipDisposeImage((GpImage
*)bitmap
);
1706 /* create alpha Bitmap */
1707 stat
= GdipCreateBitmapFromScan0(8, 20, 32, PixelFormat32bppARGB
, bits
, &bitmap
);
1710 /* create HBITMAP */
1711 stat
= GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
1716 ret
= GetObjectA(hbitmap
, sizeof(BITMAP
), &bm
);
1717 expect(sizeof(BITMAP
), ret
);
1719 expect(0, bm
.bmType
);
1720 expect(8, bm
.bmWidth
);
1721 expect(20, bm
.bmHeight
);
1722 expect(32, bm
.bmWidthBytes
);
1723 expect(1, bm
.bmPlanes
);
1724 expect(32, bm
.bmBitsPixel
);
1725 ok(bm
.bmBits
!= NULL
, "got DDB, expected DIB\n");
1729 DWORD val
= *(DWORD
*)bm
.bmBits
;
1730 ok(val
== 0x682a2a2a, "got %x, expected 0x682a2a2a\n", val
);
1733 hdc
= CreateCompatibleDC(NULL
);
1735 oldhbitmap
= SelectObject(hdc
, hbitmap
);
1736 pixel
= GetPixel(hdc
, 5, 5);
1737 SelectObject(hdc
, oldhbitmap
);
1741 expect(0x2a2a2a, pixel
);
1743 DeleteObject(hbitmap
);
1746 stat
= GdipDisposeImage((GpImage
*)bitmap
);
1750 static void test_getthumbnail(void)
1753 GpImage
*bitmap1
, *bitmap2
;
1756 stat
= GdipGetImageThumbnail(NULL
, 0, 0, &bitmap2
, NULL
, NULL
);
1757 expect(InvalidParameter
, stat
);
1759 stat
= GdipCreateBitmapFromScan0(128, 128, 0, PixelFormat32bppRGB
, NULL
, (GpBitmap
**)&bitmap1
);
1762 stat
= GdipGetImageThumbnail(bitmap1
, 0, 0, NULL
, NULL
, NULL
);
1763 expect(InvalidParameter
, stat
);
1765 stat
= GdipGetImageThumbnail(bitmap1
, 0, 0, &bitmap2
, NULL
, NULL
);
1770 stat
= GdipGetImageWidth(bitmap2
, &width
);
1774 stat
= GdipGetImageHeight(bitmap2
, &height
);
1776 expect(120, height
);
1778 GdipDisposeImage(bitmap2
);
1781 GdipDisposeImage(bitmap1
);
1784 stat
= GdipCreateBitmapFromScan0(64, 128, 0, PixelFormat32bppRGB
, NULL
, (GpBitmap
**)&bitmap1
);
1787 stat
= GdipGetImageThumbnail(bitmap1
, 32, 32, &bitmap2
, NULL
, NULL
);
1792 stat
= GdipGetImageWidth(bitmap2
, &width
);
1796 stat
= GdipGetImageHeight(bitmap2
, &height
);
1800 GdipDisposeImage(bitmap2
);
1803 stat
= GdipGetImageThumbnail(bitmap1
, 0, 0, &bitmap2
, NULL
, NULL
);
1808 stat
= GdipGetImageWidth(bitmap2
, &width
);
1812 stat
= GdipGetImageHeight(bitmap2
, &height
);
1814 expect(120, height
);
1816 GdipDisposeImage(bitmap2
);
1819 GdipDisposeImage(bitmap1
);
1822 static void test_getsetpixel(void)
1827 BYTE bits
[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1828 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1830 stat
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB
, bits
, &bitmap
);
1833 /* null parameters */
1834 stat
= GdipBitmapGetPixel(NULL
, 1, 1, &color
);
1835 expect(InvalidParameter
, stat
);
1837 stat
= GdipBitmapGetPixel(bitmap
, 1, 1, NULL
);
1838 expect(InvalidParameter
, stat
);
1840 stat
= GdipBitmapSetPixel(NULL
, 1, 1, 0);
1841 expect(InvalidParameter
, stat
);
1844 stat
= GdipBitmapGetPixel(bitmap
, -1, 1, &color
);
1845 expect(InvalidParameter
, stat
);
1847 stat
= GdipBitmapSetPixel(bitmap
, -1, 1, 0);
1848 expect(InvalidParameter
, stat
);
1850 stat
= GdipBitmapGetPixel(bitmap
, 1, -1, &color
);
1851 ok(stat
== InvalidParameter
||
1852 broken(stat
== Ok
), /* Older gdiplus */
1853 "Expected InvalidParameter, got %.8x\n", stat
);
1855 if (0) /* crashes some gdiplus implementations */
1857 stat
= GdipBitmapSetPixel(bitmap
, 1, -1, 0);
1858 ok(stat
== InvalidParameter
||
1859 broken(stat
== Ok
), /* Older gdiplus */
1860 "Expected InvalidParameter, got %.8x\n", stat
);
1863 stat
= GdipBitmapGetPixel(bitmap
, 2, 1, &color
);
1864 expect(InvalidParameter
, stat
);
1866 stat
= GdipBitmapSetPixel(bitmap
, 2, 1, 0);
1867 expect(InvalidParameter
, stat
);
1869 stat
= GdipBitmapGetPixel(bitmap
, 1, 2, &color
);
1870 expect(InvalidParameter
, stat
);
1872 stat
= GdipBitmapSetPixel(bitmap
, 1, 2, 0);
1873 expect(InvalidParameter
, stat
);
1876 stat
= GdipBitmapGetPixel(bitmap
, 1, 1, &color
);
1878 expect(0xffffffff, color
);
1880 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
1882 expect(0xff0000ff, color
);
1884 stat
= GdipBitmapSetPixel(bitmap
, 1, 1, 0xff676869);
1887 stat
= GdipBitmapSetPixel(bitmap
, 0, 0, 0xff474849);
1890 stat
= GdipBitmapGetPixel(bitmap
, 1, 1, &color
);
1892 expect(0xff676869, color
);
1894 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
1896 expect(0xff474849, color
);
1898 stat
= GdipDisposeImage((GpImage
*)bitmap
);
1902 static void check_halftone_palette(ColorPalette
*palette
)
1904 static const BYTE halftone_values
[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1907 for (i
=0; i
<palette
->Count
; i
++)
1909 ARGB expected
=0xff000000;
1912 if (i
&1) expected
|= 0x800000;
1913 if (i
&2) expected
|= 0x8000;
1914 if (i
&4) expected
|= 0x80;
1918 expected
= 0xffc0c0c0;
1922 if (i
&1) expected
|= 0xff0000;
1923 if (i
&2) expected
|= 0xff00;
1924 if (i
&4) expected
|= 0xff;
1928 expected
= 0x00000000;
1932 expected
|= halftone_values
[(i
-40)%6];
1933 expected
|= halftone_values
[((i
-40)/6)%6] << 8;
1934 expected
|= halftone_values
[((i
-40)/36)%6] << 16;
1936 ok(expected
== palette
->Entries
[i
], "Expected %.8x, got %.8x, i=%u/%u\n",
1937 expected
, palette
->Entries
[i
], i
, palette
->Count
);
1941 static void test_palette(void)
1947 ColorPalette
*palette
=(ColorPalette
*)buffer
;
1948 ARGB
*entries
= palette
->Entries
;
1951 /* test initial palette from non-indexed bitmap */
1952 stat
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB
, NULL
, &bitmap
);
1955 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1957 expect(sizeof(UINT
)*2+sizeof(ARGB
), size
);
1959 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1961 expect(0, palette
->Count
);
1963 /* test setting palette on not-indexed bitmap */
1966 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
1969 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1971 expect(sizeof(UINT
)*2+sizeof(ARGB
)*3, size
);
1973 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1975 expect(3, palette
->Count
);
1977 GdipDisposeImage((GpImage
*)bitmap
);
1979 /* test initial palette on 1-bit bitmap */
1980 stat
= GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed
, NULL
, &bitmap
);
1983 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
1985 expect(sizeof(UINT
)*2+sizeof(ARGB
)*2, size
);
1987 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
1989 expect(PaletteFlagsGrayScale
, palette
->Flags
);
1990 expect(2, palette
->Count
);
1992 expect(0xff000000, entries
[0]);
1993 expect(0xffffffff, entries
[1]);
1995 /* test getting/setting pixels */
1996 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
1998 expect(0xff000000, color
);
2000 stat
= GdipBitmapSetPixel(bitmap
, 0, 1, 0xffffffff);
2002 broken(stat
== InvalidParameter
) /* pre-win7 */, "stat=%.8x\n", stat
);
2006 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
2008 expect(0xffffffff, color
);
2011 GdipDisposeImage((GpImage
*)bitmap
);
2013 /* test initial palette on 4-bit bitmap */
2014 stat
= GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed
, NULL
, &bitmap
);
2017 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
2019 expect(sizeof(UINT
)*2+sizeof(ARGB
)*16, size
);
2021 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
2023 expect(0, palette
->Flags
);
2024 expect(16, palette
->Count
);
2026 check_halftone_palette(palette
);
2028 /* test getting/setting pixels */
2029 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
2031 expect(0xff000000, color
);
2033 stat
= GdipBitmapSetPixel(bitmap
, 0, 1, 0xffff00ff);
2035 broken(stat
== InvalidParameter
) /* pre-win7 */, "stat=%.8x\n", stat
);
2039 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
2041 expect(0xffff00ff, color
);
2044 GdipDisposeImage((GpImage
*)bitmap
);
2046 /* test initial palette on 8-bit bitmap */
2047 stat
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed
, NULL
, &bitmap
);
2050 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
2052 expect(sizeof(UINT
)*2+sizeof(ARGB
)*256, size
);
2054 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
2056 expect(PaletteFlagsHalftone
, palette
->Flags
);
2057 expect(256, palette
->Count
);
2059 check_halftone_palette(palette
);
2061 /* test getting/setting pixels */
2062 stat
= GdipBitmapGetPixel(bitmap
, 0, 0, &color
);
2064 expect(0xff000000, color
);
2066 stat
= GdipBitmapSetPixel(bitmap
, 0, 1, 0xffcccccc);
2068 broken(stat
== InvalidParameter
) /* pre-win7 */, "stat=%.8x\n", stat
);
2072 stat
= GdipBitmapGetPixel(bitmap
, 0, 1, &color
);
2074 expect(0xffcccccc, color
);
2077 /* test setting/getting a different palette */
2078 entries
[1] = 0xffcccccc;
2080 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
2085 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
2087 expect(sizeof(UINT
)*2+sizeof(ARGB
)*256, size
);
2089 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
2091 expect(PaletteFlagsHalftone
, palette
->Flags
);
2092 expect(256, palette
->Count
);
2093 expect(0xffcccccc, entries
[1]);
2095 /* test count < 256 */
2096 palette
->Flags
= 12345;
2099 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
2103 entries
[3] = 0xdeadbeef;
2105 stat
= GdipGetImagePaletteSize((GpImage
*)bitmap
, &size
);
2107 expect(sizeof(UINT
)*2+sizeof(ARGB
)*3, size
);
2109 stat
= GdipGetImagePalette((GpImage
*)bitmap
, palette
, size
);
2111 expect(12345, palette
->Flags
);
2112 expect(3, palette
->Count
);
2113 expect(0xffcccccc, entries
[1]);
2114 expect(0xdeadbeef, entries
[3]);
2116 /* test count > 256 */
2117 palette
->Count
= 257;
2119 stat
= GdipSetImagePalette((GpImage
*)bitmap
, palette
);
2120 ok(stat
== InvalidParameter
||
2121 broken(stat
== Ok
), /* Old gdiplus behavior */
2122 "Expected %.8x, got %.8x\n", InvalidParameter
, stat
);
2124 GdipDisposeImage((GpImage
*)bitmap
);
2127 static void test_colormatrix(void)
2130 ColorMatrix colormatrix
, graymatrix
;
2131 GpImageAttributes
*imageattr
;
2132 const ColorMatrix identity
= {{
2133 {1.0,0.0,0.0,0.0,0.0},
2134 {0.0,1.0,0.0,0.0,0.0},
2135 {0.0,0.0,1.0,0.0,0.0},
2136 {0.0,0.0,0.0,1.0,0.0},
2137 {0.0,0.0,0.0,0.0,1.0}}};
2138 const ColorMatrix double_red
= {{
2139 {2.0,0.0,0.0,0.0,0.0},
2140 {0.0,1.0,0.0,0.0,0.0},
2141 {0.0,0.0,1.0,0.0,0.0},
2142 {0.0,0.0,0.0,1.0,0.0},
2143 {0.0,0.0,0.0,0.0,1.0}}};
2144 const ColorMatrix asymmetric
= {{
2145 {0.0,1.0,0.0,0.0,0.0},
2146 {0.0,0.0,1.0,0.0,0.0},
2147 {0.0,0.0,0.0,1.0,0.0},
2148 {1.0,0.0,0.0,0.0,0.0},
2149 {0.0,0.0,0.0,0.0,1.0}}};
2150 GpBitmap
*bitmap1
, *bitmap2
;
2151 GpGraphics
*graphics
;
2154 colormatrix
= identity
;
2155 graymatrix
= identity
;
2157 stat
= GdipSetImageAttributesColorMatrix(NULL
, ColorAdjustTypeDefault
,
2158 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
2159 expect(InvalidParameter
, stat
);
2161 stat
= GdipCreateImageAttributes(&imageattr
);
2164 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2165 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsDefault
);
2168 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2169 TRUE
, NULL
, NULL
, ColorMatrixFlagsDefault
);
2170 expect(InvalidParameter
, stat
);
2172 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2173 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
2176 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2177 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsSkipGrays
);
2180 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2181 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsAltGray
);
2182 expect(InvalidParameter
, stat
);
2184 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2185 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsAltGray
);
2188 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2189 TRUE
, &colormatrix
, &graymatrix
, 3);
2190 expect(InvalidParameter
, stat
);
2192 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeCount
,
2193 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
2194 expect(InvalidParameter
, stat
);
2196 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeAny
,
2197 TRUE
, &colormatrix
, &graymatrix
, ColorMatrixFlagsDefault
);
2198 expect(InvalidParameter
, stat
);
2200 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2201 FALSE
, NULL
, NULL
, ColorMatrixFlagsDefault
);
2204 /* Drawing a bitmap transforms the colors */
2205 colormatrix
= double_red
;
2206 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2207 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsDefault
);
2210 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppARGB
, NULL
, &bitmap1
);
2213 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppARGB
, NULL
, &bitmap2
);
2216 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0xff40ccee);
2219 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
2222 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
2223 UnitPixel
, imageattr
, NULL
, NULL
);
2226 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2228 expect(0xff80ccee, color
);
2230 colormatrix
= asymmetric
;
2231 stat
= GdipSetImageAttributesColorMatrix(imageattr
, ColorAdjustTypeDefault
,
2232 TRUE
, &colormatrix
, NULL
, ColorMatrixFlagsDefault
);
2235 stat
= GdipBitmapSetPixel(bitmap2
, 0, 0, 0);
2238 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
2239 UnitPixel
, imageattr
, NULL
, NULL
);
2242 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2244 ok(color_match(0xeeff40cc, color
, 3), "expected 0xeeff40cc, got 0x%08x\n", color
);
2246 stat
= GdipResetImageAttributes(imageattr
, ColorAdjustTypeDefault
);
2249 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
2250 UnitPixel
, imageattr
, NULL
, NULL
);
2253 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2255 ok(color_match(0xff40ccee, color
, 1), "Expected ff40ccee, got %.8x\n", color
);
2257 GdipDeleteGraphics(graphics
);
2258 GdipDisposeImage((GpImage
*)bitmap1
);
2259 GdipDisposeImage((GpImage
*)bitmap2
);
2260 GdipDisposeImageAttributes(imageattr
);
2263 static void test_gamma(void)
2266 GpImageAttributes
*imageattr
;
2267 GpBitmap
*bitmap1
, *bitmap2
;
2268 GpGraphics
*graphics
;
2271 stat
= GdipSetImageAttributesGamma(NULL
, ColorAdjustTypeDefault
, TRUE
, 1.0);
2272 expect(InvalidParameter
, stat
);
2274 stat
= GdipCreateImageAttributes(&imageattr
);
2277 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1.0);
2280 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeAny
, TRUE
, 1.0);
2281 expect(InvalidParameter
, stat
);
2283 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, -1.0);
2284 expect(InvalidParameter
, stat
);
2286 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0.0);
2287 expect(InvalidParameter
, stat
);
2289 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0.5);
2292 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, FALSE
, 0.0);
2295 /* Drawing a bitmap transforms the colors */
2296 stat
= GdipSetImageAttributesGamma(imageattr
, ColorAdjustTypeDefault
, TRUE
, 3.0);
2299 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap1
);
2302 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap2
);
2305 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0xff80ffff);
2308 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
2311 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
2312 UnitPixel
, imageattr
, NULL
, NULL
);
2315 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2317 ok(color_match(0xff20ffff, color
, 1), "Expected ff20ffff, got %.8x\n", color
);
2319 stat
= GdipResetImageAttributes(imageattr
, ColorAdjustTypeDefault
);
2322 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
2323 UnitPixel
, imageattr
, NULL
, NULL
);
2326 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2328 ok(color_match(0xff80ffff, color
, 1), "Expected ff80ffff, got %.8x\n", color
);
2330 GdipDeleteGraphics(graphics
);
2331 GdipDisposeImage((GpImage
*)bitmap1
);
2332 GdipDisposeImage((GpImage
*)bitmap2
);
2333 GdipDisposeImageAttributes(imageattr
);
2336 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
2337 static const unsigned char gifanimation
[72] = {
2338 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
2339 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
2340 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
2341 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
2342 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
2345 static void test_multiframegif(void)
2357 /* Test frame functions with an animated GIF */
2358 hglob
= GlobalAlloc (0, sizeof(gifanimation
));
2359 data
= GlobalLock (hglob
);
2360 memcpy(data
, gifanimation
, sizeof(gifanimation
));
2361 GlobalUnlock(hglob
);
2363 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
2364 ok(hres
== S_OK
, "Failed to create a stream\n");
2365 if(hres
!= S_OK
) return;
2367 stat
= GdipCreateBitmapFromStream(stream
, &bmp
);
2368 ok(stat
== Ok
, "Failed to create a Bitmap\n");
2370 IStream_Release(stream
);
2374 /* Bitmap starts at frame 0 */
2376 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
2378 expect(0xffffffff, color
);
2380 /* Check that we get correct metadata */
2381 stat
= GdipImageGetFrameDimensionsCount((GpImage
*)bmp
,&count
);
2385 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bmp
, &dimension
, 1);
2387 expect_guid(&FrameDimensionTime
, &dimension
, __LINE__
, FALSE
);
2390 stat
= GdipImageGetFrameCount((GpImage
*)bmp
, &dimension
, &count
);
2394 /* SelectActiveFrame overwrites our current data */
2395 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 1);
2399 GdipBitmapGetPixel(bmp
, 0, 0, &color
);
2401 expect(0xff000000, color
);
2403 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
2407 GdipBitmapGetPixel(bmp
, 0, 0, &color
);
2409 expect(0xffffffff, color
);
2411 /* Write over the image data */
2412 stat
= GdipBitmapSetPixel(bmp
, 0, 0, 0xff000000);
2415 /* Switching to the same frame does not overwrite our changes */
2416 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
2419 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
2421 expect(0xff000000, color
);
2423 /* But switching to another frame and back does */
2424 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 1);
2427 stat
= GdipImageSelectActiveFrame((GpImage
*)bmp
, &dimension
, 0);
2430 stat
= GdipBitmapGetPixel(bmp
, 0, 0, &color
);
2432 expect(0xffffffff, color
);
2434 /* rotate/flip discards the information about other frames */
2435 stat
= GdipImageRotateFlip((GpImage
*)bmp
, Rotate90FlipNone
);
2439 stat
= GdipImageGetFrameCount((GpImage
*)bmp
, &dimension
, &count
);
2443 expect_rawformat(&ImageFormatMemoryBMP
, (GpImage
*)bmp
, __LINE__
, FALSE
);
2445 GdipDisposeImage((GpImage
*)bmp
);
2446 IStream_Release(stream
);
2448 /* Test with a non-animated gif */
2449 hglob
= GlobalAlloc (0, sizeof(gifimage
));
2450 data
= GlobalLock (hglob
);
2451 memcpy(data
, gifimage
, sizeof(gifimage
));
2452 GlobalUnlock(hglob
);
2454 hres
= CreateStreamOnHGlobal(hglob
, TRUE
, &stream
);
2455 ok(hres
== S_OK
, "Failed to create a stream\n");
2456 if(hres
!= S_OK
) return;
2458 stat
= GdipCreateBitmapFromStream(stream
, &bmp
);
2459 ok(stat
== Ok
, "Failed to create a Bitmap\n");
2461 IStream_Release(stream
);
2465 /* Check metadata */
2466 stat
= GdipImageGetFrameDimensionsCount((GpImage
*)bmp
,&count
);
2470 stat
= GdipImageGetFrameDimensionsList((GpImage
*)bmp
, &dimension
, 1);
2472 expect_guid(&FrameDimensionTime
, &dimension
, __LINE__
, FALSE
);
2475 stat
= GdipImageGetFrameCount((GpImage
*)bmp
, &dimension
, &count
);
2479 GdipDisposeImage((GpImage
*)bmp
);
2480 IStream_Release(stream
);
2483 static void test_rotateflip(void)
2488 static const BYTE orig_bits
[24] = {
2489 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
2490 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
2494 memcpy(bits
, orig_bits
, sizeof(bits
));
2495 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
2498 stat
= GdipImageRotateFlip(bitmap
, Rotate90FlipNone
);
2501 stat
= GdipGetImageWidth(bitmap
, &width
);
2503 stat
= GdipGetImageHeight(bitmap
, &height
);
2508 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 0, &color
);
2510 expect(0xff00ffff, color
);
2512 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 1, 0, &color
);
2514 expect(0xffff0000, color
);
2516 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 2, &color
);
2518 expect(0xffffff00, color
);
2520 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 1, 2, &color
);
2522 expect(0xff0000ff, color
);
2526 expect(0xff, bits
[2]);
2528 GdipDisposeImage(bitmap
);
2530 memcpy(bits
, orig_bits
, sizeof(bits
));
2531 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
2534 stat
= GdipImageRotateFlip(bitmap
, RotateNoneFlipX
);
2537 stat
= GdipGetImageWidth(bitmap
, &width
);
2539 stat
= GdipGetImageHeight(bitmap
, &height
);
2544 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 0, &color
);
2546 expect(0xff0000ff, color
);
2548 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 0, &color
);
2550 expect(0xffff0000, color
);
2552 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 1, &color
);
2554 expect(0xffffff00, color
);
2556 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 1, &color
);
2558 expect(0xff00ffff, color
);
2562 expect(0xff, bits
[2]);
2564 GdipDisposeImage(bitmap
);
2566 memcpy(bits
, orig_bits
, sizeof(bits
));
2567 stat
= GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB
, bits
, (GpBitmap
**)&bitmap
);
2570 stat
= GdipImageRotateFlip(bitmap
, RotateNoneFlipY
);
2573 stat
= GdipGetImageWidth(bitmap
, &width
);
2575 stat
= GdipGetImageHeight(bitmap
, &height
);
2580 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 0, &color
);
2582 expect(0xff00ffff, color
);
2584 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 0, &color
);
2586 expect(0xffffff00, color
);
2588 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 0, 1, &color
);
2590 expect(0xffff0000, color
);
2592 stat
= GdipBitmapGetPixel((GpBitmap
*)bitmap
, 2, 1, &color
);
2594 expect(0xff0000ff, color
);
2598 expect(0xff, bits
[2]);
2600 GdipDisposeImage(bitmap
);
2603 static void test_remaptable(void)
2606 GpImageAttributes
*imageattr
;
2607 GpBitmap
*bitmap1
, *bitmap2
;
2608 GpGraphics
*graphics
;
2612 map
= GdipAlloc(sizeof(ColorMap
));
2614 map
->oldColor
.Argb
= 0xff00ff00;
2615 map
->newColor
.Argb
= 0xffff00ff;
2617 stat
= GdipSetImageAttributesRemapTable(NULL
, ColorAdjustTypeDefault
, TRUE
, 1, map
);
2618 expect(InvalidParameter
, stat
);
2620 stat
= GdipCreateImageAttributes(&imageattr
);
2623 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1, NULL
);
2624 expect(InvalidParameter
, stat
);
2626 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeCount
, TRUE
, 1, map
);
2627 expect(InvalidParameter
, stat
);
2629 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeAny
, TRUE
, 1, map
);
2630 expect(InvalidParameter
, stat
);
2632 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0, map
);
2633 expect(InvalidParameter
, stat
);
2635 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, FALSE
, 0, NULL
);
2638 stat
= GdipSetImageAttributesRemapTable(imageattr
, ColorAdjustTypeDefault
, TRUE
, 1, map
);
2641 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap1
);
2644 stat
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB
, NULL
, &bitmap2
);
2647 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0xff00ff00);
2650 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
2653 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
2654 UnitPixel
, imageattr
, NULL
, NULL
);
2657 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2659 ok(color_match(0xffff00ff, color
, 1), "Expected ffff00ff, got %.8x\n", color
);
2661 stat
= GdipResetImageAttributes(imageattr
, ColorAdjustTypeDefault
);
2664 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,1,1, 0,0,1,1,
2665 UnitPixel
, imageattr
, NULL
, NULL
);
2668 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2670 ok(color_match(0xff00ff00, color
, 1), "Expected ff00ff00, got %.8x\n", color
);
2672 GdipDeleteGraphics(graphics
);
2673 GdipDisposeImage((GpImage
*)bitmap1
);
2674 GdipDisposeImage((GpImage
*)bitmap2
);
2675 GdipDisposeImageAttributes(imageattr
);
2679 static void test_colorkey(void)
2682 GpImageAttributes
*imageattr
;
2683 GpBitmap
*bitmap1
, *bitmap2
;
2684 GpGraphics
*graphics
;
2687 stat
= GdipSetImageAttributesColorKeys(NULL
, ColorAdjustTypeDefault
, TRUE
, 0xff405060, 0xff708090);
2688 expect(InvalidParameter
, stat
);
2690 stat
= GdipCreateImageAttributes(&imageattr
);
2693 stat
= GdipSetImageAttributesColorKeys(imageattr
, ColorAdjustTypeCount
, TRUE
, 0xff405060, 0xff708090);
2694 expect(InvalidParameter
, stat
);
2696 stat
= GdipSetImageAttributesColorKeys(imageattr
, ColorAdjustTypeAny
, TRUE
, 0xff405060, 0xff708090);
2697 expect(InvalidParameter
, stat
);
2699 stat
= GdipSetImageAttributesColorKeys(imageattr
, ColorAdjustTypeDefault
, TRUE
, 0xff405060, 0xff708090);
2702 stat
= GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB
, NULL
, &bitmap1
);
2705 stat
= GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB
, NULL
, &bitmap2
);
2708 stat
= GdipBitmapSetPixel(bitmap1
, 0, 0, 0x20405060);
2711 stat
= GdipBitmapSetPixel(bitmap1
, 0, 1, 0x40506070);
2714 stat
= GdipBitmapSetPixel(bitmap1
, 1, 0, 0x60708090);
2717 stat
= GdipBitmapSetPixel(bitmap1
, 1, 1, 0xffffffff);
2720 stat
= GdipGetImageGraphicsContext((GpImage
*)bitmap2
, &graphics
);
2723 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,2,2, 0,0,2,2,
2724 UnitPixel
, imageattr
, NULL
, NULL
);
2727 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2729 ok(color_match(0x00000000, color
, 1), "Expected 00000000, got %.8x\n", color
);
2731 stat
= GdipBitmapGetPixel(bitmap2
, 0, 1, &color
);
2733 ok(color_match(0x00000000, color
, 1), "Expected 00000000, got %.8x\n", color
);
2735 stat
= GdipBitmapGetPixel(bitmap2
, 1, 0, &color
);
2737 ok(color_match(0x00000000, color
, 1), "Expected 00000000, got %.8x\n", color
);
2739 stat
= GdipBitmapGetPixel(bitmap2
, 1, 1, &color
);
2741 ok(color_match(0xffffffff, color
, 1), "Expected ffffffff, got %.8x\n", color
);
2743 stat
= GdipResetImageAttributes(imageattr
, ColorAdjustTypeDefault
);
2746 stat
= GdipDrawImageRectRectI(graphics
, (GpImage
*)bitmap1
, 0,0,2,2, 0,0,2,2,
2747 UnitPixel
, imageattr
, NULL
, NULL
);
2750 stat
= GdipBitmapGetPixel(bitmap2
, 0, 0, &color
);
2752 ok(color_match(0x20405060, color
, 1), "Expected 20405060, got %.8x\n", color
);
2754 stat
= GdipBitmapGetPixel(bitmap2
, 0, 1, &color
);
2756 ok(color_match(0x40506070, color
, 1), "Expected 40506070, got %.8x\n", color
);
2758 stat
= GdipBitmapGetPixel(bitmap2
, 1, 0, &color
);
2760 ok(color_match(0x60708090, color
, 1), "Expected 60708090, got %.8x\n", color
);
2762 stat
= GdipBitmapGetPixel(bitmap2
, 1, 1, &color
);
2764 ok(color_match(0xffffffff, color
, 1), "Expected ffffffff, got %.8x\n", color
);
2767 GdipDeleteGraphics(graphics
);
2768 GdipDisposeImage((GpImage
*)bitmap1
);
2769 GdipDisposeImage((GpImage
*)bitmap2
);
2770 GdipDisposeImageAttributes(imageattr
);
2773 static void test_dispose(void)
2777 char invalid_image
[256];
2779 stat
= GdipDisposeImage(NULL
);
2780 expect(InvalidParameter
, stat
);
2782 stat
= GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB
, NULL
, (GpBitmap
**)&image
);
2785 stat
= GdipDisposeImage(image
);
2788 stat
= GdipDisposeImage(image
);
2789 expect(ObjectBusy
, stat
);
2791 memset(invalid_image
, 0, 256);
2792 stat
= GdipDisposeImage((GpImage
*)invalid_image
);
2793 expect(ObjectBusy
, stat
);
2796 static LONG
obj_refcount(void *obj
)
2798 IUnknown_AddRef((IUnknown
*)obj
);
2799 return IUnknown_Release((IUnknown
*)obj
);
2802 static GpImage
*load_image(const BYTE
*image_data
, UINT image_size
)
2809 GpImage
*image
= NULL
, *clone
;
2810 ImageType image_type
;
2811 LONG refcount
, old_refcount
;
2813 hmem
= GlobalAlloc(0, image_size
);
2814 data
= GlobalLock(hmem
);
2815 memcpy(data
, image_data
, image_size
);
2818 hr
= CreateStreamOnHGlobal(hmem
, TRUE
, &stream
);
2819 ok(hr
== S_OK
, "CreateStreamOnHGlobal error %#x\n", hr
);
2820 if (hr
!= S_OK
) return NULL
;
2822 refcount
= obj_refcount(stream
);
2823 ok(refcount
== 1, "expected stream refcount 1, got %d\n", refcount
);
2825 status
= GdipLoadImageFromStream(stream
, &image
);
2826 ok(status
== Ok
|| broken(status
== InvalidParameter
), /* XP */
2827 "GdipLoadImageFromStream error %d\n", status
);
2830 IStream_Release(stream
);
2834 status
= GdipGetImageType(image
, &image_type
);
2835 ok(status
== Ok
, "GdipGetImageType error %d\n", status
);
2837 refcount
= obj_refcount(stream
);
2838 if (image_type
== ImageTypeBitmap
)
2839 ok(refcount
> 1, "expected stream refcount > 1, got %d\n", refcount
);
2841 ok(refcount
== 1, "expected stream refcount 1, got %d\n", refcount
);
2842 old_refcount
= refcount
;
2844 status
= GdipCloneImage(image
, &clone
);
2845 ok(status
== Ok
, "GdipCloneImage error %d\n", status
);
2846 refcount
= obj_refcount(stream
);
2847 ok(refcount
== old_refcount
, "expected stream refcount %d, got %d\n", old_refcount
, refcount
);
2848 status
= GdipDisposeImage(clone
);
2849 ok(status
== Ok
, "GdipDisposeImage error %d\n", status
);
2850 refcount
= obj_refcount(stream
);
2851 ok(refcount
== old_refcount
, "expected stream refcount %d, got %d\n", old_refcount
, refcount
);
2853 refcount
= IStream_Release(stream
);
2854 if (image_type
== ImageTypeBitmap
)
2855 ok(refcount
>= 1, "expected stream refcount != 0\n");
2857 ok(refcount
== 0, "expected stream refcount 0, got %d\n", refcount
);
2862 static void test_image_properties(void)
2864 static const struct test_data
2866 const BYTE
*image_data
;
2868 ImageType image_type
;
2870 UINT prop_count2
; /* if win7 behaves differently */
2871 /* 1st property attributes */
2873 UINT prop_size2
; /* if win7 behaves differently */
2875 UINT prop_id2
; /* if win7 behaves differently */
2879 { pngimage
, sizeof(pngimage
), ImageTypeBitmap
, 4, ~0, 1, 20, 0x5110, 0x132 },
2880 { jpgimage
, sizeof(jpgimage
), ImageTypeBitmap
, 2, ~0, 128, 0, 0x5090, 0x5091 },
2881 { tiffimage
, sizeof(tiffimage
), ImageTypeBitmap
, 16, 0, 4, 0, 0xfe, 0 },
2882 { bmpimage
, sizeof(bmpimage
), ImageTypeBitmap
, 0, 0, 0, 0, 0, 0 },
2883 { wmfimage
, sizeof(wmfimage
), ImageTypeMetafile
, 0, 0, 0, 0, 0, 0 }
2887 UINT prop_count
, prop_size
, i
;
2888 PROPID prop_id
[16] = { 0 };
2889 ImageType image_type
;
2896 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
2898 image
= load_image(td
[i
].image_data
, td
[i
].image_size
);
2901 trace("%u: failed to load image data\n", i
);
2905 status
= GdipGetImageType(image
, &image_type
);
2906 ok(status
== Ok
, "%u: GdipGetImageType error %d\n", i
, status
);
2907 ok(td
[i
].image_type
== image_type
, "%u: expected image_type %d, got %d\n",
2908 i
, td
[i
].image_type
, image_type
);
2910 status
= GdipGetPropertyCount(image
, &prop_count
);
2911 ok(status
== Ok
, "%u: GdipGetPropertyCount error %d\n", i
, status
);
2912 if (td
[i
].image_data
== pngimage
|| td
[i
].image_data
== jpgimage
)
2914 ok(td
[i
].prop_count
== prop_count
|| td
[i
].prop_count2
== prop_count
,
2915 " %u: expected property count %u or %u, got %u\n",
2916 i
, td
[i
].prop_count
, td
[i
].prop_count2
, prop_count
);
2918 ok(td
[i
].prop_count
== prop_count
|| td
[i
].prop_count2
== prop_count
,
2919 " %u: expected property count %u or %u, got %u\n",
2920 i
, td
[i
].prop_count
, td
[i
].prop_count2
, prop_count
);
2922 status
= GdipGetPropertyItemSize(NULL
, 0, &prop_size
);
2923 expect(InvalidParameter
, status
);
2924 status
= GdipGetPropertyItemSize(image
, 0, NULL
);
2925 expect(InvalidParameter
, status
);
2926 status
= GdipGetPropertyItemSize(image
, 0, &prop_size
);
2927 if (image_type
== ImageTypeMetafile
)
2928 expect(NotImplemented
, status
);
2930 expect(PropertyNotFound
, status
);
2932 status
= GdipGetPropertyItem(NULL
, 0, 0, &item
.data
);
2933 expect(InvalidParameter
, status
);
2934 status
= GdipGetPropertyItem(image
, 0, 0, NULL
);
2935 expect(InvalidParameter
, status
);
2936 status
= GdipGetPropertyItem(image
, 0, 0, &item
.data
);
2937 if (image_type
== ImageTypeMetafile
)
2938 expect(NotImplemented
, status
);
2940 expect(PropertyNotFound
, status
);
2942 /* FIXME: remove once Wine is fixed */
2943 if (td
[i
].prop_count
!= prop_count
)
2945 GdipDisposeImage(image
);
2949 status
= GdipGetPropertyIdList(NULL
, prop_count
, prop_id
);
2950 expect(InvalidParameter
, status
);
2951 status
= GdipGetPropertyIdList(image
, prop_count
, NULL
);
2952 expect(InvalidParameter
, status
);
2953 status
= GdipGetPropertyIdList(image
, 0, prop_id
);
2954 if (image_type
== ImageTypeMetafile
)
2955 expect(NotImplemented
, status
);
2956 else if (prop_count
== 0)
2959 expect(InvalidParameter
, status
);
2960 status
= GdipGetPropertyIdList(image
, prop_count
- 1, prop_id
);
2961 if (image_type
== ImageTypeMetafile
)
2962 expect(NotImplemented
, status
);
2964 expect(InvalidParameter
, status
);
2965 status
= GdipGetPropertyIdList(image
, prop_count
+ 1, prop_id
);
2966 if (image_type
== ImageTypeMetafile
)
2967 expect(NotImplemented
, status
);
2969 expect(InvalidParameter
, status
);
2970 status
= GdipGetPropertyIdList(image
, prop_count
, prop_id
);
2971 if (image_type
== ImageTypeMetafile
)
2972 expect(NotImplemented
, status
);
2976 if (prop_count
!= 0)
2977 ok(td
[i
].prop_id
== prop_id
[0] || td
[i
].prop_id2
== prop_id
[0],
2978 " %u: expected property id %#x or %#x, got %#x\n",
2979 i
, td
[i
].prop_id
, td
[i
].prop_id2
, prop_id
[0]);
2984 status
= GdipGetPropertyItemSize(image
, prop_id
[0], &prop_size
);
2985 if (prop_count
== 0)
2986 expect(PropertyNotFound
, status
);
2991 assert(sizeof(item
) >= prop_size
);
2992 ok(prop_size
> sizeof(PropertyItem
), "%u: got too small prop_size %u\n",
2994 ok(td
[i
].prop_size
+ sizeof(PropertyItem
) == prop_size
||
2995 td
[i
].prop_size2
+ sizeof(PropertyItem
) == prop_size
,
2996 " %u: expected property size %u or %u, got %u\n",
2997 i
, td
[i
].prop_size
, td
[i
].prop_size2
, prop_size
);
2999 status
= GdipGetPropertyItem(image
, prop_id
[0], 0, &item
.data
);
3000 ok(status
== InvalidParameter
|| status
== GenericError
/* Win7 */,
3001 "%u: expected InvalidParameter, got %d\n", i
, status
);
3002 status
= GdipGetPropertyItem(image
, prop_id
[0], prop_size
- 1, &item
.data
);
3003 ok(status
== InvalidParameter
|| status
== GenericError
/* Win7 */,
3004 "%u: expected InvalidParameter, got %d\n", i
, status
);
3005 status
= GdipGetPropertyItem(image
, prop_id
[0], prop_size
+ 1, &item
.data
);
3006 ok(status
== InvalidParameter
|| status
== GenericError
/* Win7 */,
3007 "%u: expected InvalidParameter, got %d\n", i
, status
);
3008 status
= GdipGetPropertyItem(image
, prop_id
[0], prop_size
, &item
.data
);
3010 ok(prop_id
[0] == item
.data
.id
,
3011 "%u: expected property id %#x, got %#x\n", i
, prop_id
[0], item
.data
.id
);
3015 GdipDisposeImage(image
);
3023 #define IFD_RATIONAL 5
3025 #define IFD_UNDEFINED 7
3026 #define IFD_SSHORT 8
3028 #define IFD_SRATIONAL 10
3029 #define IFD_FLOAT 11
3030 #define IFD_DOUBLE 12
3032 #ifndef PropertyTagTypeSByte
3033 #define PropertyTagTypeSByte 6
3034 #define PropertyTagTypeSShort 8
3035 #define PropertyTagTypeFloat 11
3036 #define PropertyTagTypeDouble 12
3039 static UINT
documented_type(UINT type
)
3043 case PropertyTagTypeSByte
: return PropertyTagTypeByte
;
3044 case PropertyTagTypeSShort
: return PropertyTagTypeShort
;
3045 case PropertyTagTypeFloat
: return PropertyTagTypeUndefined
;
3046 case PropertyTagTypeDouble
: return PropertyTagTypeUndefined
;
3047 default: return type
;
3051 #include "pshpack2.h"
3066 static const struct tiff_data
3071 USHORT number_of_entries
;
3072 struct IFD_entry entry
[40];
3074 struct IFD_rational xres
;
3076 struct IFD_rational srational_val
;
3081 struct IFD_rational rational
[3];
3085 #ifdef WORDS_BIGENDIAN
3091 FIELD_OFFSET(struct tiff_data
, number_of_entries
),
3094 { 0xff, IFD_SHORT
, 1, 0 }, /* SUBFILETYPE */
3095 { 0x100, IFD_LONG
, 1, 1 }, /* IMAGEWIDTH */
3096 { 0x101, IFD_LONG
, 1, 1 }, /* IMAGELENGTH */
3097 { 0x102, IFD_SHORT
, 1, 1 }, /* BITSPERSAMPLE */
3098 { 0x103, IFD_SHORT
, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
3099 { 0x106, IFD_SHORT
, 1, 1 }, /* PHOTOMETRIC */
3100 { 0x111, IFD_LONG
, 1, FIELD_OFFSET(struct tiff_data
, pixel_data
) }, /* STRIPOFFSETS */
3101 { 0x115, IFD_SHORT
, 1, 1 }, /* SAMPLESPERPIXEL */
3102 { 0x116, IFD_LONG
, 1, 1 }, /* ROWSPERSTRIP */
3103 { 0x117, IFD_LONG
, 1, 1 }, /* STRIPBYTECOUNT */
3104 { 0x11a, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_data
, xres
) },
3105 { 0x11b, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_data
, xres
) },
3106 { 0x128, IFD_SHORT
, 1, 2 }, /* RESOLUTIONUNIT */
3107 { 0xf001, IFD_BYTE
, 1, 0x11223344 },
3108 { 0xf002, IFD_BYTE
, 4, 0x11223344 },
3109 { 0xf003, IFD_SBYTE
, 1, 0x11223344 },
3110 { 0xf004, IFD_SSHORT
, 1, 0x11223344 },
3111 { 0xf005, IFD_SSHORT
, 2, 0x11223344 },
3112 { 0xf006, IFD_SLONG
, 1, 0x11223344 },
3113 { 0xf007, IFD_FLOAT
, 1, 0x11223344 },
3114 { 0xf008, IFD_DOUBLE
, 1, FIELD_OFFSET(struct tiff_data
, double_val
) },
3115 { 0xf009, IFD_SRATIONAL
, 1, FIELD_OFFSET(struct tiff_data
, srational_val
) },
3116 { 0xf00a, IFD_BYTE
, 13, FIELD_OFFSET(struct tiff_data
, string
) },
3117 { 0xf00b, IFD_SSHORT
, 4, FIELD_OFFSET(struct tiff_data
, short_val
) },
3118 { 0xf00c, IFD_SLONG
, 2, FIELD_OFFSET(struct tiff_data
, long_val
) },
3119 { 0xf00e, IFD_ASCII
, 13, FIELD_OFFSET(struct tiff_data
, string
) },
3120 { 0xf00f, IFD_ASCII
, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
3121 { 0xf010, IFD_UNDEFINED
, 13, FIELD_OFFSET(struct tiff_data
, string
) },
3122 { 0xf011, IFD_UNDEFINED
, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
3123 /* Some gdiplus versions ignore these fields.
3124 { 0xf012, IFD_BYTE, 0, 0x11223344 },
3125 { 0xf013, IFD_SHORT, 0, 0x11223344 },
3126 { 0xf014, IFD_LONG, 0, 0x11223344 },
3127 { 0xf015, IFD_FLOAT, 0, 0x11223344 },*/
3128 { 0xf016, IFD_SRATIONAL
, 3, FIELD_OFFSET(struct tiff_data
, rational
) },
3129 /* Win7 before SP1 doesn't recognize this field, everybody else does. */
3130 { 0xf017, IFD_FLOAT
, 2, FIELD_OFFSET(struct tiff_data
, float_val
) },
3134 1234567890.0987654321,
3135 { 0x1a2b3c4d, 0x5a6b7c8d },
3137 { 0x0101, 0x0202, 0x0303, 0x0404 },
3138 { 0x11223344, 0x55667788 },
3139 { (FLOAT
)1234.5678, (FLOAT
)8765.4321 },
3140 { { 0x01020304, 0x05060708 }, { 0x10203040, 0x50607080 }, { 0x11223344, 0x55667788 } },
3141 { 0x11, 0x22, 0x33, 0 }
3143 #include "poppack.h"
3145 static void test_tiff_properties(void)
3147 static const struct test_data
3149 ULONG type
, id
, length
;
3150 const BYTE value
[24];
3153 { PropertyTagTypeShort
, 0xff, 2, { 0 } },
3154 { PropertyTagTypeLong
, 0x100, 4, { 1 } },
3155 { PropertyTagTypeLong
, 0x101, 4, { 1 } },
3156 { PropertyTagTypeShort
, 0x102, 2, { 1 } },
3157 { PropertyTagTypeShort
, 0x103, 2, { 1 } },
3158 { PropertyTagTypeShort
, 0x106, 2, { 1 } },
3159 { PropertyTagTypeLong
, 0x111, 4, { 0x44,0x02 } },
3160 { PropertyTagTypeShort
, 0x115, 2, { 1 } },
3161 { PropertyTagTypeLong
, 0x116, 4, { 1 } },
3162 { PropertyTagTypeLong
, 0x117, 4, { 1 } },
3163 { PropertyTagTypeRational
, 0x11a, 8, { 0x84,0x03,0,0,0x03 } },
3164 { PropertyTagTypeRational
, 0x11b, 8, { 0x84,0x03,0,0,0x03 } },
3165 { PropertyTagTypeShort
, 0x128, 2, { 2 } },
3166 { PropertyTagTypeByte
, 0xf001, 1, { 0x44 } },
3167 { PropertyTagTypeByte
, 0xf002, 4, { 0x44,0x33,0x22,0x11 } },
3168 { PropertyTagTypeSByte
, 0xf003, 1, { 0x44 } },
3169 { PropertyTagTypeSShort
, 0xf004, 2, { 0x44,0x33 } },
3170 { PropertyTagTypeSShort
, 0xf005, 4, { 0x44,0x33,0x22,0x11 } },
3171 { PropertyTagTypeSLONG
, 0xf006, 4, { 0x44,0x33,0x22,0x11 } },
3172 { PropertyTagTypeFloat
, 0xf007, 4, { 0x44,0x33,0x22,0x11 } },
3173 { PropertyTagTypeDouble
, 0xf008, 8, { 0x2c,0x52,0x86,0xb4,0x80,0x65,0xd2,0x41 } },
3174 { PropertyTagTypeSRational
, 0xf009, 8, { 0x4d, 0x3c, 0x2b, 0x1a, 0x8d, 0x7c, 0x6b, 0x5a } },
3175 { PropertyTagTypeByte
, 0xf00a, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3176 { PropertyTagTypeSShort
, 0xf00b, 8, { 0x01,0x01,0x02,0x02,0x03,0x03,0x04,0x04 } },
3177 { PropertyTagTypeSLONG
, 0xf00c, 8, { 0x44,0x33,0x22,0x11,0x88,0x77,0x66,0x55 } },
3178 { PropertyTagTypeASCII
, 0xf00e, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3179 { PropertyTagTypeASCII
, 0xf00f, 5, { 'a','b','c','d' } },
3180 { PropertyTagTypeUndefined
, 0xf010, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3181 { PropertyTagTypeUndefined
, 0xf011, 4, { 'a','b','c','d' } },
3182 { PropertyTagTypeSRational
, 0xf016, 24,
3183 { 0x04,0x03,0x02,0x01,0x08,0x07,0x06,0x05,
3184 0x40,0x30,0x20,0x10,0x80,0x70,0x60,0x50,
3185 0x44,0x33,0x22,0x11,0x88,0x77,0x66,0x55 } },
3186 /* Win7 before SP1 doesn't recognize this field, everybody else does. */
3187 { PropertyTagTypeFloat
, 0xf017, 8, { 0x2b,0x52,0x9a,0x44,0xba,0xf5,0x08,0x46 } },
3192 UINT dim_count
, frame_count
, prop_count
, prop_size
, i
;
3194 PropertyItem
*prop_item
;
3196 image
= load_image((const BYTE
*)&TIFF_data
, sizeof(TIFF_data
));
3199 win_skip("Failed to load TIFF image data. Might not be supported. Skipping.\n");
3203 status
= GdipImageGetFrameDimensionsCount(image
, &dim_count
);
3205 expect(1, dim_count
);
3207 status
= GdipImageGetFrameDimensionsList(image
, &guid
, 1);
3209 expect_guid(&FrameDimensionPage
, &guid
, __LINE__
, FALSE
);
3211 frame_count
= 0xdeadbeef;
3212 status
= GdipImageGetFrameCount(image
, &guid
, &frame_count
);
3214 expect(1, frame_count
);
3216 prop_count
= 0xdeadbeef;
3217 status
= GdipGetPropertyCount(image
, &prop_count
);
3219 ok(prop_count
== sizeof(td
)/sizeof(td
[0]) ||
3220 broken(prop_count
== sizeof(td
)/sizeof(td
[0]) - 1) /* Win7 SP0 */,
3221 "expected property count %u, got %u\n", (UINT
)(sizeof(td
)/sizeof(td
[0])), prop_count
);
3223 prop_id
= HeapAlloc(GetProcessHeap(), 0, prop_count
* sizeof(*prop_id
));
3225 status
= GdipGetPropertyIdList(image
, prop_count
, prop_id
);
3228 for (i
= 0; i
< prop_count
; i
++)
3230 status
= GdipGetPropertyItemSize(image
, prop_id
[i
], &prop_size
);
3232 if (status
!= Ok
) break;
3233 ok(prop_size
> sizeof(*prop_item
), "%u: too small item length %u\n", i
, prop_size
);
3235 prop_item
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, prop_size
);
3236 status
= GdipGetPropertyItem(image
, prop_id
[i
], prop_size
, prop_item
);
3238 ok(prop_item
->value
== prop_item
+ 1, "expected item->value %p, got %p\n", prop_item
+ 1, prop_item
->value
);
3239 ok(td
[i
].type
== prop_item
->type
||
3240 /* Win7 stopped using proper but not documented types, and it
3241 looks broken since TypeFloat and TypeDouble now reported as
3242 TypeUndefined, and signed types reported as unsigned. */
3243 broken(prop_item
->type
== documented_type(td
[i
].type
)),
3244 "%u: expected type %u, got %u\n", i
, td
[i
].type
, prop_item
->type
);
3245 ok(td
[i
].id
== prop_item
->id
, "%u: expected id %#x, got %#x\n", i
, td
[i
].id
, prop_item
->id
);
3246 prop_size
-= sizeof(*prop_item
);
3247 ok(prop_item
->length
== prop_size
, "%u: expected length %u, got %u\n", i
, prop_size
, prop_item
->length
);
3248 ok(td
[i
].length
== prop_item
->length
|| broken(td
[i
].id
== 0xf00f && td
[i
].length
== prop_item
->length
+1) /* XP */,
3249 "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_item
->length
);
3250 ok(td
[i
].length
== prop_size
|| broken(td
[i
].id
== 0xf00f && td
[i
].length
== prop_size
+1) /* XP */,
3251 "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_size
);
3252 if (td
[i
].length
== prop_item
->length
)
3254 int match
= memcmp(td
[i
].value
, prop_item
->value
, td
[i
].length
) == 0;
3255 ok(match
|| broken(td
[i
].length
<= 4 && !match
), "%u: data mismatch\n", i
);
3259 BYTE
*data
= prop_item
->value
;
3260 trace("id %#x:", prop_item
->id
);
3261 for (j
= 0; j
< prop_item
->length
; j
++)
3262 trace(" %02x", data
[j
]);
3266 HeapFree(GetProcessHeap(), 0, prop_item
);
3269 HeapFree(GetProcessHeap(), 0, prop_id
);
3271 GdipDisposeImage(image
);
3274 static void test_GdipGetAllPropertyItems(void)
3276 static const struct test_data
3278 ULONG type
, id
, length
;
3282 { PropertyTagTypeLong
, 0xfe, 4, { 0 } },
3283 { PropertyTagTypeShort
, 0x100, 2, { 1 } },
3284 { PropertyTagTypeShort
, 0x101, 2, { 1 } },
3285 { PropertyTagTypeShort
, 0x102, 6, { 8,0,8,0,8,0 } },
3286 { PropertyTagTypeShort
, 0x103, 2, { 1 } },
3287 { PropertyTagTypeShort
, 0x106, 2, { 2,0 } },
3288 { PropertyTagTypeASCII
, 0x10d, 27, "/home/meh/Desktop/test.tif" },
3289 { PropertyTagTypeLong
, 0x111, 4, { 8,0,0,0 } },
3290 { PropertyTagTypeShort
, 0x112, 2, { 1 } },
3291 { PropertyTagTypeShort
, 0x115, 2, { 3,0 } },
3292 { PropertyTagTypeShort
, 0x116, 2, { 0x40,0 } },
3293 { PropertyTagTypeLong
, 0x117, 4, { 3,0,0,0 } },
3294 { PropertyTagTypeRational
, 0x11a, 8, { 0,0,0,72,0,0,0,1 } },
3295 { PropertyTagTypeRational
, 0x11b, 8, { 0,0,0,72,0,0,0,1 } },
3296 { PropertyTagTypeShort
, 0x11c, 2, { 1 } },
3297 { PropertyTagTypeShort
, 0x128, 2, { 2 } }
3302 UINT dim_count
, frame_count
, prop_count
, prop_size
, i
;
3303 UINT total_size
, total_count
;
3305 PropertyItem
*prop_item
;
3306 const char *item_data
;
3308 image
= load_image(tiffimage
, sizeof(tiffimage
));
3309 ok(image
!= 0, "Failed to load TIFF image data\n");
3312 dim_count
= 0xdeadbeef;
3313 status
= GdipImageGetFrameDimensionsCount(image
, &dim_count
);
3315 expect(1, dim_count
);
3317 status
= GdipImageGetFrameDimensionsList(image
, &guid
, 1);
3319 expect_guid(&FrameDimensionPage
, &guid
, __LINE__
, FALSE
);
3321 frame_count
= 0xdeadbeef;
3322 status
= GdipImageGetFrameCount(image
, &guid
, &frame_count
);
3324 expect(1, frame_count
);
3326 prop_count
= 0xdeadbeef;
3327 status
= GdipGetPropertyCount(image
, &prop_count
);
3329 ok(prop_count
== sizeof(td
)/sizeof(td
[0]),
3330 "expected property count %u, got %u\n", (UINT
)(sizeof(td
)/sizeof(td
[0])), prop_count
);
3332 prop_id
= HeapAlloc(GetProcessHeap(), 0, prop_count
* sizeof(*prop_id
));
3334 status
= GdipGetPropertyIdList(image
, prop_count
, prop_id
);
3338 for (i
= 0; i
< prop_count
; i
++)
3341 status
= GdipGetPropertyItemSize(image
, prop_id
[i
], &size
);
3343 if (status
!= Ok
) break;
3344 ok(size
> sizeof(*prop_item
), "%u: too small item length %u\n", i
, size
);
3348 prop_item
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
3349 status
= GdipGetPropertyItem(image
, prop_id
[i
], size
, prop_item
);
3351 ok(prop_item
->value
== prop_item
+ 1, "expected item->value %p, got %p\n", prop_item
+ 1, prop_item
->value
);
3352 ok(td
[i
].type
== prop_item
->type
,
3353 "%u: expected type %u, got %u\n", i
, td
[i
].type
, prop_item
->type
);
3354 ok(td
[i
].id
== prop_item
->id
, "%u: expected id %#x, got %#x\n", i
, td
[i
].id
, prop_item
->id
);
3355 size
-= sizeof(*prop_item
);
3356 ok(prop_item
->length
== size
, "%u: expected length %u, got %u\n", i
, size
, prop_item
->length
);
3357 ok(td
[i
].length
== prop_item
->length
, "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_item
->length
);
3358 if (td
[i
].length
== prop_item
->length
)
3360 int match
= memcmp(td
[i
].value
, prop_item
->value
, td
[i
].length
) == 0;
3361 ok(match
, "%u: data mismatch\n", i
);
3365 BYTE
*data
= prop_item
->value
;
3366 trace("id %#x:", prop_item
->id
);
3367 for (j
= 0; j
< prop_item
->length
; j
++)
3368 trace(" %02x", data
[j
]);
3372 HeapFree(GetProcessHeap(), 0, prop_item
);
3375 HeapFree(GetProcessHeap(), 0, prop_id
);
3377 status
= GdipGetPropertySize(NULL
, &total_size
, &total_count
);
3378 expect(InvalidParameter
, status
);
3379 status
= GdipGetPropertySize(image
, &total_size
, NULL
);
3380 expect(InvalidParameter
, status
);
3381 status
= GdipGetPropertySize(image
, NULL
, &total_count
);
3382 expect(InvalidParameter
, status
);
3383 status
= GdipGetPropertySize(image
, NULL
, NULL
);
3384 expect(InvalidParameter
, status
);
3385 total_size
= 0xdeadbeef;
3386 total_count
= 0xdeadbeef;
3387 status
= GdipGetPropertySize(image
, &total_size
, &total_count
);
3389 ok(prop_count
== total_count
,
3390 "expected total property count %u, got %u\n", prop_count
, total_count
);
3391 ok(prop_size
== total_size
,
3392 "expected total property size %u, got %u\n", prop_size
, total_size
);
3394 prop_item
= HeapAlloc(GetProcessHeap(), 0, prop_size
);
3396 status
= GdipGetAllPropertyItems(image
, 0, prop_count
, prop_item
);
3397 expect(InvalidParameter
, status
);
3398 status
= GdipGetAllPropertyItems(image
, prop_size
, 1, prop_item
);
3399 expect(InvalidParameter
, status
);
3400 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, NULL
);
3401 expect(InvalidParameter
, status
);
3402 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, NULL
);
3403 expect(InvalidParameter
, status
);
3404 status
= GdipGetAllPropertyItems(image
, 0, 0, NULL
);
3405 expect(InvalidParameter
, status
);
3406 status
= GdipGetAllPropertyItems(image
, prop_size
+ 1, prop_count
, prop_item
);
3407 expect(InvalidParameter
, status
);
3408 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, prop_item
);
3411 item_data
= (const char *)(prop_item
+ prop_count
);
3412 for (i
= 0; i
< prop_count
; i
++)
3414 ok(prop_item
[i
].value
== item_data
, "%u: expected value %p, got %p\n",
3415 i
, item_data
, prop_item
[i
].value
);
3416 ok(td
[i
].type
== prop_item
[i
].type
,
3417 "%u: expected type %u, got %u\n", i
, td
[i
].type
, prop_item
[i
].type
);
3418 ok(td
[i
].id
== prop_item
[i
].id
, "%u: expected id %#x, got %#x\n", i
, td
[i
].id
, prop_item
[i
].id
);
3419 ok(td
[i
].length
== prop_item
[i
].length
, "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_item
[i
].length
);
3420 if (td
[i
].length
== prop_item
[i
].length
)
3422 int match
= memcmp(td
[i
].value
, prop_item
[i
].value
, td
[i
].length
) == 0;
3423 ok(match
, "%u: data mismatch\n", i
);
3427 BYTE
*data
= prop_item
[i
].value
;
3428 trace("id %#x:", prop_item
[i
].id
);
3429 for (j
= 0; j
< prop_item
[i
].length
; j
++)
3430 trace(" %02x", data
[j
]);
3434 item_data
+= prop_item
[i
].length
;
3437 HeapFree(GetProcessHeap(), 0, prop_item
);
3439 GdipDisposeImage(image
);
3442 static void test_tiff_palette(void)
3453 ARGB
*entries
= palette
.pal
.Entries
;
3455 /* 1bpp TIFF without palette */
3456 image
= load_image((const BYTE
*)&TIFF_data
, sizeof(TIFF_data
));
3459 win_skip("Failed to load TIFF image data. Might not be supported. Skipping.\n");
3463 status
= GdipGetImagePixelFormat(image
, &format
);
3465 ok(format
== PixelFormat1bppIndexed
, "expected PixelFormat1bppIndexed, got %#x\n", format
);
3467 status
= GdipGetImagePaletteSize(image
, &size
);
3468 ok(status
== Ok
|| broken(status
== GenericError
), /* XP */
3469 "GdipGetImagePaletteSize error %d\n", status
);
3470 if (status
== GenericError
)
3472 GdipDisposeImage(image
);
3475 expect(sizeof(ColorPalette
) + sizeof(ARGB
), size
);
3477 status
= GdipGetImagePalette(image
, &palette
.pal
, size
);
3479 expect(0, palette
.pal
.Flags
);
3480 expect(2, palette
.pal
.Count
);
3481 if (palette
.pal
.Count
== 2)
3483 ok(entries
[0] == 0xff000000, "expected 0xff000000, got %#x\n", entries
[0]);
3484 ok(entries
[1] == 0xffffffff, "expected 0xffffffff, got %#x\n", entries
[1]);
3487 GdipDisposeImage(image
);
3490 static void test_bitmapbits(void)
3493 static const BYTE pixels_24
[48] =
3495 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3496 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3497 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3498 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0
3500 static const BYTE pixels_00
[48] =
3502 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3503 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3504 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3505 0,0,0, 0,0,0, 0,0,0, 0,0,0
3507 static const BYTE pixels_24_77
[64] =
3509 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3510 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3511 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3512 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3513 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3514 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3516 static const BYTE pixels_77
[64] =
3518 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3519 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3520 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3521 0x77,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 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3527 static const BYTE pixels_8
[16] =
3529 0x01,0,0x01,0,0x01,0,0x01,0,
3530 0x01,0,0x01,0,0x01,0,0x01,0
3532 static const BYTE pixels_8_77
[64] =
3534 0x01,0,0x01,0,0x01,0,0x01,0,
3535 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3536 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3537 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3538 0x01,0,0x01,0,0x01,0,0x01,0,
3539 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3540 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3541 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3543 static const BYTE pixels_1_77
[64] =
3545 0xaa,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3546 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3547 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3548 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3549 0xaa,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3550 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3551 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3552 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3554 static const BYTE pixels_1
[8] = {0xaa,0,0,0,0xaa,0,0,0};
3555 static const struct test_data
3562 const BYTE
*pixels_unlocked
;
3566 { PixelFormat24bppRGB
, 24, 0xfff0, 24, 48, pixels_24
, pixels_00
},
3568 { PixelFormat24bppRGB
, 24, 0, 24, 48, pixels_24
, pixels_00
},
3569 { PixelFormat24bppRGB
, 24, ImageLockModeRead
, 24, 48, pixels_24
, pixels_00
},
3570 { PixelFormat24bppRGB
, 24, ImageLockModeWrite
, 24, 48, pixels_24
, pixels_00
},
3571 { PixelFormat24bppRGB
, 24, ImageLockModeRead
|ImageLockModeWrite
, 24, 48, pixels_24
, pixels_00
},
3572 { PixelFormat24bppRGB
, 24, ImageLockModeRead
|ImageLockModeUserInputBuf
, 32, 64, pixels_24_77
, pixels_24
},
3573 { PixelFormat24bppRGB
, 24, ImageLockModeWrite
|ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_00
},
3574 { PixelFormat24bppRGB
, 24, ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_24
},
3576 { PixelFormat8bppIndexed
, 8, 0, 8, 16, pixels_8
, pixels_24
},
3577 { PixelFormat8bppIndexed
, 8, ImageLockModeRead
, 8, 16, pixels_8
, pixels_24
},
3578 { PixelFormat8bppIndexed
, 8, ImageLockModeWrite
, 8, 16, pixels_8
, pixels_00
},
3579 { PixelFormat8bppIndexed
, 8, ImageLockModeRead
|ImageLockModeWrite
, 8, 16, pixels_8
, pixels_00
},
3580 { PixelFormat8bppIndexed
, 8, ImageLockModeRead
|ImageLockModeUserInputBuf
, 32, 64, pixels_8_77
, pixels_24
},
3581 { PixelFormat8bppIndexed
, 8, ImageLockModeWrite
|ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_00
},
3582 { PixelFormat8bppIndexed
, 8, ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_24
},
3584 { PixelFormat1bppIndexed
, 1, 0, 4, 8, pixels_1
, pixels_24
},
3585 { PixelFormat1bppIndexed
, 1, ImageLockModeRead
, 4, 8, pixels_1
, pixels_24
},
3586 { PixelFormat1bppIndexed
, 1, ImageLockModeWrite
, 4, 8, pixels_1
, pixels_00
},
3587 { PixelFormat1bppIndexed
, 1, ImageLockModeRead
|ImageLockModeWrite
, 4, 8, pixels_1
, pixels_00
},
3588 { PixelFormat1bppIndexed
, 1, ImageLockModeRead
|ImageLockModeUserInputBuf
, 32, 64, pixels_1_77
, pixels_24
},
3589 { PixelFormat1bppIndexed
, 1, ImageLockModeWrite
|ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_00
},
3590 { PixelFormat1bppIndexed
, 1, ImageLockModeUserInputBuf
, 32, 64, pixels_77
, pixels_24
},
3602 ARGB
*entries
= palette
.pal
.Entries
;
3604 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
3606 BYTE pixels
[sizeof(pixels_24
)];
3607 memcpy(pixels
, pixels_24
, sizeof(pixels_24
));
3608 status
= GdipCreateBitmapFromScan0(8, 2, 24, PixelFormat24bppRGB
, pixels
, &bitmap
);
3611 /* associate known palette with pixel data */
3612 palette
.pal
.Flags
= PaletteFlagsGrayScale
;
3613 palette
.pal
.Count
= 2;
3614 entries
[0] = 0xff000000;
3615 entries
[1] = 0xffffffff;
3616 status
= GdipSetImagePalette((GpImage
*)bitmap
, &palette
.pal
);
3619 memset(&data
, 0xfe, sizeof(data
));
3620 if (td
[i
].mode
& ImageLockModeUserInputBuf
)
3622 memset(buf
, 0x77, sizeof(buf
));
3626 status
= GdipBitmapLockBits(bitmap
, NULL
, td
[i
].mode
, td
[i
].format
, &data
);
3627 ok(status
== Ok
|| broken(status
== InvalidParameter
) /* XP */, "%u: GdipBitmapLockBits error %d\n", i
, status
);
3630 GdipDisposeImage((GpImage
*)bitmap
);
3633 ok(data
.Width
== 8, "%u: expected 8, got %d\n", i
, data
.Width
);
3634 ok(data
.Height
== 2, "%u: expected 2, got %d\n", i
, data
.Height
);
3635 ok(td
[i
].stride
== data
.Stride
, "%u: expected %d, got %d\n", i
, td
[i
].stride
, data
.Stride
);
3636 ok(td
[i
].format
== data
.PixelFormat
, "%u: expected %d, got %d\n", i
, td
[i
].format
, data
.PixelFormat
);
3637 ok(td
[i
].size
== data
.Height
* data
.Stride
, "%u: expected %d, got %d\n", i
, td
[i
].size
, data
.Height
* data
.Stride
);
3638 if (td
[i
].mode
& ImageLockModeUserInputBuf
)
3639 ok(data
.Scan0
== buf
, "%u: got wrong buffer\n", i
);
3640 if (td
[i
].size
== data
.Height
* data
.Stride
)
3642 UINT j
, match
, width_bytes
= (data
.Width
* td
[i
].bpp
) / 8;
3645 for (j
= 0; j
< data
.Height
; j
++)
3647 if (memcmp((const BYTE
*)data
.Scan0
+ j
* data
.Stride
, td
[i
].pixels
+ j
* data
.Stride
, width_bytes
) != 0)
3653 if ((td
[i
].mode
& (ImageLockModeRead
|ImageLockModeUserInputBuf
)) || td
[i
].format
== PixelFormat24bppRGB
)
3656 "%u: data should match\n", i
);
3659 BYTE
*bits
= data
.Scan0
;
3660 trace("%u: data mismatch for format %#x:", i
, td
[i
].format
);
3661 for (j
= 0; j
< td
[i
].size
; j
++)
3662 trace(" %02x", bits
[j
]);
3667 ok(!match
, "%u: data shouldn't match\n", i
);
3669 memset(data
.Scan0
, 0, td
[i
].size
);
3672 status
= GdipBitmapUnlockBits(bitmap
, &data
);
3673 ok(status
== Ok
, "%u: GdipBitmapUnlockBits error %d\n", i
, status
);
3675 memset(&data
, 0xfe, sizeof(data
));
3676 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat24bppRGB
, &data
);
3677 ok(status
== Ok
, "%u: GdipBitmapLockBits error %d\n", i
, status
);
3678 ok(data
.Width
== 8, "%u: expected 8, got %d\n", i
, data
.Width
);
3679 ok(data
.Height
== 2, "%u: expected 2, got %d\n", i
, data
.Height
);
3680 ok(data
.Stride
== 24, "%u: expected 24, got %d\n", i
, data
.Stride
);
3681 ok(data
.PixelFormat
== PixelFormat24bppRGB
, "%u: got wrong pixel format %d\n", i
, data
.PixelFormat
);
3682 ok(data
.Height
* data
.Stride
== 48, "%u: expected 48, got %d\n", i
, data
.Height
* data
.Stride
);
3683 if (data
.Height
* data
.Stride
== 48)
3685 int match
= memcmp(data
.Scan0
, td
[i
].pixels_unlocked
, 48) == 0;
3686 ok(match
, "%u: data should match\n", i
);
3690 BYTE
*bits
= data
.Scan0
;
3691 trace("%u: data mismatch for format %#x:", i
, td
[i
].format
);
3692 for (j
= 0; j
< 48; j
++)
3693 trace(" %02x", bits
[j
]);
3698 status
= GdipBitmapUnlockBits(bitmap
, &data
);
3699 ok(status
== Ok
, "%u: GdipBitmapUnlockBits error %d\n", i
, status
);
3701 status
= GdipDisposeImage((GpImage
*)bitmap
);
3706 static void test_DrawImage(void)
3708 BYTE black_1x1
[4] = { 0,0,0,0 };
3709 BYTE white_2x2
[16] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
3710 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
3711 BYTE black_2x2
[16] = { 0,0,0,0,0,0,0xff,0xff,
3712 0,0,0,0,0,0,0xff,0xff };
3719 GpGraphics
*graphics
;
3722 status
= GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB
, black_1x1
, &u1
.bitmap
);
3724 status
= GdipBitmapSetResolution(u1
.bitmap
, 100.0, 100.0);
3727 status
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat24bppRGB
, white_2x2
, &u2
.bitmap
);
3729 status
= GdipBitmapSetResolution(u2
.bitmap
, 300.0, 300.0);
3731 status
= GdipGetImageGraphicsContext(u2
.image
, &graphics
);
3733 status
= GdipSetInterpolationMode(graphics
, InterpolationModeNearestNeighbor
);
3736 status
= GdipDrawImageI(graphics
, u1
.image
, 0, 0);
3739 match
= memcmp(white_2x2
, black_2x2
, sizeof(black_2x2
)) == 0;
3740 ok(match
, "data should match\n");
3743 UINT i
, size
= sizeof(white_2x2
);
3744 BYTE
*bits
= white_2x2
;
3745 for (i
= 0; i
< size
; i
++)
3746 trace(" %02x", bits
[i
]);
3750 status
= GdipDeleteGraphics(graphics
);
3752 status
= GdipDisposeImage(u1
.image
);
3754 status
= GdipDisposeImage(u2
.image
);
3758 static void test_GdipDrawImagePointRect(void)
3760 BYTE black_1x1
[4] = { 0,0,0,0 };
3761 BYTE white_2x2
[16] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
3762 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
3763 BYTE black_2x2
[16] = { 0,0,0,0,0,0,0xff,0xff,
3764 0,0,0,0,0,0,0xff,0xff };
3771 GpGraphics
*graphics
;
3774 status
= GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB
, black_1x1
, &u1
.bitmap
);
3776 status
= GdipBitmapSetResolution(u1
.bitmap
, 100.0, 100.0);
3779 status
= GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat24bppRGB
, white_2x2
, &u2
.bitmap
);
3781 status
= GdipBitmapSetResolution(u2
.bitmap
, 300.0, 300.0);
3783 status
= GdipGetImageGraphicsContext(u2
.image
, &graphics
);
3785 status
= GdipSetInterpolationMode(graphics
, InterpolationModeNearestNeighbor
);
3788 status
= GdipDrawImagePointRectI(graphics
, u1
.image
, 0, 0, 0, 0, 1, 1, UnitPixel
);
3791 match
= memcmp(white_2x2
, black_2x2
, sizeof(black_2x2
)) == 0;
3792 ok(match
, "data should match\n");
3795 UINT i
, size
= sizeof(white_2x2
);
3796 BYTE
*bits
= white_2x2
;
3797 for (i
= 0; i
< size
; i
++)
3798 trace(" %02x", bits
[i
]);
3802 status
= GdipDeleteGraphics(graphics
);
3804 status
= GdipDisposeImage(u1
.image
);
3806 status
= GdipDisposeImage(u2
.image
);
3810 static void test_image_format(void)
3812 static const PixelFormat fmt
[] =
3814 PixelFormat1bppIndexed
, PixelFormat4bppIndexed
, PixelFormat8bppIndexed
,
3815 PixelFormat16bppGrayScale
, PixelFormat16bppRGB555
, PixelFormat16bppRGB565
,
3816 PixelFormat16bppARGB1555
, PixelFormat24bppRGB
, PixelFormat32bppRGB
,
3817 PixelFormat32bppARGB
, PixelFormat32bppPARGB
, PixelFormat48bppRGB
,
3818 PixelFormat64bppARGB
, PixelFormat64bppPARGB
, PixelFormat32bppCMYK
3829 for (i
= 0; i
< sizeof(fmt
)/sizeof(fmt
[0]); i
++)
3831 status
= GdipCreateBitmapFromScan0(1, 1, 0, fmt
[i
], NULL
, &bitmap
);
3832 ok(status
== Ok
|| broken(status
== InvalidParameter
) /* before win7 */,
3833 "GdipCreateBitmapFromScan0 error %d\n", status
);
3834 if (status
!= Ok
) continue;
3836 status
= GdipGetImagePixelFormat((GpImage
*)bitmap
, &format
);
3838 expect(fmt
[i
], format
);
3840 status
= GdipCreateHBITMAPFromBitmap(bitmap
, &hbitmap
, 0);
3841 if (fmt
[i
] == PixelFormat16bppGrayScale
|| fmt
[i
] == PixelFormat32bppCMYK
)
3842 todo_wine
expect(InvalidParameter
, status
);
3846 ret
= GetObjectW(hbitmap
, sizeof(bm
), &bm
);
3847 expect(sizeof(bm
), ret
);
3848 expect(0, bm
.bmType
);
3849 expect(1, bm
.bmWidth
);
3850 expect(1, bm
.bmHeight
);
3851 expect(4, bm
.bmWidthBytes
);
3852 expect(1, bm
.bmPlanes
);
3853 expect(32, bm
.bmBitsPixel
);
3854 DeleteObject(hbitmap
);
3857 status
= GdipGetImageThumbnail((GpImage
*)bitmap
, 0, 0, &thumb
, NULL
, NULL
);
3858 if (fmt
[i
] == PixelFormat16bppGrayScale
|| fmt
[i
] == PixelFormat32bppCMYK
)
3860 ok(status
== OutOfMemory
|| broken(status
== InvalidParameter
) /* before win7 */,
3861 "expected OutOfMemory, got %d\n", status
);
3865 status
= GdipGetImagePixelFormat(thumb
, &format
);
3867 ok(format
== PixelFormat32bppPARGB
|| broken(format
!= PixelFormat32bppPARGB
) /* before win7 */,
3868 "expected PixelFormat32bppPARGB, got %#x\n", format
);
3869 status
= GdipDisposeImage(thumb
);
3873 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat32bppPARGB
, &data
);
3874 if (fmt
[i
] == PixelFormat16bppGrayScale
|| fmt
[i
] == PixelFormat32bppCMYK
)
3875 todo_wine
expect(InvalidParameter
, status
);
3879 status
= GdipBitmapUnlockBits(bitmap
, &data
);
3883 status
= GdipDisposeImage((GpImage
*)bitmap
);
3888 static void test_DrawImage_scale(void)
3890 static const BYTE back_8x1
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
3891 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3892 static const BYTE image_080
[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,
3893 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3894 static const BYTE image_100
[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40,
3895 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3896 static const BYTE image_120
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x40,0x40,0x40,
3897 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3898 static const BYTE image_150
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3899 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3900 static const BYTE image_180
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3901 0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3902 static const BYTE image_200
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3903 0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3904 static const BYTE image_250
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,
3905 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40 };
3906 static const BYTE image_120_half
[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
3907 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3908 static const BYTE image_150_half
[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
3909 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3910 static const BYTE image_200_half
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3911 0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40 };
3912 static const BYTE image_250_half
[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3913 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40 };
3914 static const struct test_data
3917 PixelOffsetMode pixel_offset_mode
;
3922 { 0.8, PixelOffsetModeNone
, image_080
}, /* 0 */
3923 { 1.0, PixelOffsetModeNone
, image_100
},
3924 { 1.2, PixelOffsetModeNone
, image_120
},
3925 { 1.5, PixelOffsetModeNone
, image_150
},
3926 { 1.8, PixelOffsetModeNone
, image_180
},
3927 { 2.0, PixelOffsetModeNone
, image_200
},
3928 { 2.5, PixelOffsetModeNone
, image_250
},
3930 { 0.8, PixelOffsetModeHighSpeed
, image_080
}, /* 7 */
3931 { 1.0, PixelOffsetModeHighSpeed
, image_100
},
3932 { 1.2, PixelOffsetModeHighSpeed
, image_120
},
3933 { 1.5, PixelOffsetModeHighSpeed
, image_150
},
3934 { 1.8, PixelOffsetModeHighSpeed
, image_180
},
3935 { 2.0, PixelOffsetModeHighSpeed
, image_200
},
3936 { 2.5, PixelOffsetModeHighSpeed
, image_250
},
3938 { 0.8, PixelOffsetModeHalf
, image_080
}, /* 14 */
3939 { 1.0, PixelOffsetModeHalf
, image_100
},
3940 { 1.2, PixelOffsetModeHalf
, image_120_half
, TRUE
},
3941 { 1.5, PixelOffsetModeHalf
, image_150_half
, TRUE
},
3942 { 1.8, PixelOffsetModeHalf
, image_180
},
3943 { 2.0, PixelOffsetModeHalf
, image_200_half
, TRUE
},
3944 { 2.5, PixelOffsetModeHalf
, image_250_half
, TRUE
},
3946 { 0.8, PixelOffsetModeHighQuality
, image_080
}, /* 21 */
3947 { 1.0, PixelOffsetModeHighQuality
, image_100
},
3948 { 1.2, PixelOffsetModeHighQuality
, image_120_half
, TRUE
},
3949 { 1.5, PixelOffsetModeHighQuality
, image_150_half
, TRUE
},
3950 { 1.8, PixelOffsetModeHighQuality
, image_180
},
3951 { 2.0, PixelOffsetModeHighQuality
, image_200_half
, TRUE
},
3952 { 2.5, PixelOffsetModeHighQuality
, image_250_half
, TRUE
},
3954 BYTE src_2x1
[6] = { 0x80,0x80,0x80,0x80,0x80,0x80 };
3962 GpGraphics
*graphics
;
3966 status
= GdipCreateBitmapFromScan0(2, 1, 4, PixelFormat24bppRGB
, src_2x1
, &u1
.bitmap
);
3968 status
= GdipBitmapSetResolution(u1
.bitmap
, 100.0, 100.0);
3971 status
= GdipCreateBitmapFromScan0(8, 1, 24, PixelFormat24bppRGB
, dst_8x1
, &u2
.bitmap
);
3973 status
= GdipBitmapSetResolution(u2
.bitmap
, 100.0, 100.0);
3975 status
= GdipGetImageGraphicsContext(u2
.image
, &graphics
);
3977 status
= GdipSetInterpolationMode(graphics
, InterpolationModeNearestNeighbor
);
3980 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
3982 status
= GdipSetPixelOffsetMode(graphics
, td
[i
].pixel_offset_mode
);
3985 status
= GdipCreateMatrix2(td
[i
].scale_x
, 0.0, 0.0, 1.0, 0.0, 0.0, &matrix
);
3987 status
= GdipSetWorldTransform(graphics
, matrix
);
3989 GdipDeleteMatrix(matrix
);
3991 memcpy(dst_8x1
, back_8x1
, sizeof(dst_8x1
));
3992 status
= GdipDrawImageI(graphics
, u1
.image
, 1, 0);
3995 match
= memcmp(dst_8x1
, td
[i
].image
, sizeof(dst_8x1
)) == 0;
3996 if (!match
&& td
[i
].todo
)
3997 todo_wine
ok(match
, "%d: data should match\n", i
);
3999 ok(match
, "%d: data should match\n", i
);
4002 UINT i
, size
= sizeof(dst_8x1
);
4003 const BYTE
*bits
= dst_8x1
;
4004 for (i
= 0; i
< size
; i
++)
4005 trace(" %02x", bits
[i
]);
4010 status
= GdipDeleteGraphics(graphics
);
4012 status
= GdipDisposeImage(u1
.image
);
4014 status
= GdipDisposeImage(u2
.image
);
4018 static const BYTE animatedgif
[] = {
4019 'G','I','F','8','9','a',0x01,0x00,0x01,0x00,0xA1,0x02,0x00,
4020 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,
4021 /*0x21,0xFF,0x0B,'A','N','I','M','E','X','T','S','1','.','0',*/
4022 0x21,0xFF,0x0B,'N','E','T','S','C','A','P','E','2','.','0',
4023 0x03,0x01,0x05,0x00,0x00,
4024 0x21,0xFE,0x0C,'H','e','l','l','o',' ','W','o','r','l','d','!',0x00,
4025 0x21,0x01,0x0D,'a','n','i','m','a','t','i','o','n','.','g','i','f',0x00,
4026 0x21,0xF9,0x04,0xff,0x0A,0x00,0x08,0x00,
4027 0x2C,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
4028 0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,
4029 0x02,0x02,0x4C,0x01,0x00,
4030 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','1',0x00,
4031 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','1',0x00,
4032 0x21,0xF9,0x04,0x00,0x14,0x00,0x01,0x00,
4033 0x2C,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
4034 0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,
4035 0x02,0x02,0x44,0x01,0x00,
4036 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','2',0x00,
4037 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','2',0x00,0x3B
4040 static void test_gif_properties(void)
4042 static const struct test_data
4044 ULONG type
, id
, length
;
4045 const BYTE value
[13];
4048 { PropertyTagTypeLong
, PropertyTagFrameDelay
, 8, { 10,0,0,0,20,0,0,0 } },
4049 { PropertyTagTypeASCII
, PropertyTagExifUserComment
, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
4050 { PropertyTagTypeShort
, PropertyTagLoopCount
, 2, { 5,0 } },
4051 { PropertyTagTypeByte
, PropertyTagGlobalPalette
, 12, { 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c } },
4052 { PropertyTagTypeByte
, PropertyTagIndexBackground
, 1, { 2 } },
4053 { PropertyTagTypeByte
, PropertyTagIndexTransparent
, 1, { 8 } }
4058 UINT dim_count
, frame_count
, prop_count
, prop_size
, i
;
4059 UINT total_size
, total_count
;
4061 PropertyItem
*prop_item
;
4062 const char *item_data
;
4064 image
= load_image(animatedgif
, sizeof(animatedgif
));
4065 if (!image
) /* XP fails to load this GIF image */
4067 trace("Failed to load GIF image data\n");
4071 status
= GdipImageGetFrameDimensionsCount(image
, &dim_count
);
4073 expect(1, dim_count
);
4075 status
= GdipImageGetFrameDimensionsList(image
, &guid
, 1);
4077 expect_guid(&FrameDimensionTime
, &guid
, __LINE__
, FALSE
);
4079 status
= GdipImageGetFrameCount(image
, &guid
, &frame_count
);
4081 expect(2, frame_count
);
4083 status
= GdipImageSelectActiveFrame(image
, &guid
, 1);
4086 status
= GdipGetPropertyCount(image
, &prop_count
);
4088 ok(prop_count
== sizeof(td
)/sizeof(td
[0]) || broken(prop_count
== 1) /* before win7 */,
4089 "expected property count %u, got %u\n", (UINT
)(sizeof(td
)/sizeof(td
[0])), prop_count
);
4091 if (prop_count
!= sizeof(td
)/sizeof(td
[0]))
4093 GdipDisposeImage(image
);
4097 prop_id
= HeapAlloc(GetProcessHeap(), 0, prop_count
* sizeof(*prop_id
));
4099 status
= GdipGetPropertyIdList(image
, prop_count
, prop_id
);
4103 for (i
= 0; i
< prop_count
; i
++)
4106 status
= GdipGetPropertyItemSize(image
, prop_id
[i
], &size
);
4108 if (status
!= Ok
) break;
4109 ok(size
> sizeof(*prop_item
), "%u: too small item length %u\n", i
, size
);
4113 prop_item
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
4114 status
= GdipGetPropertyItem(image
, prop_id
[i
], size
, prop_item
);
4116 ok(prop_item
->value
== prop_item
+ 1, "expected item->value %p, got %p\n", prop_item
+ 1, prop_item
->value
);
4117 ok(td
[i
].type
== prop_item
->type
,
4118 "%u: expected type %u, got %u\n", i
, td
[i
].type
, prop_item
->type
);
4119 ok(td
[i
].id
== prop_item
->id
, "%u: expected id %#x, got %#x\n", i
, td
[i
].id
, prop_item
->id
);
4120 size
-= sizeof(*prop_item
);
4121 ok(prop_item
->length
== size
, "%u: expected length %u, got %u\n", i
, size
, prop_item
->length
);
4122 ok(td
[i
].length
== prop_item
->length
, "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_item
->length
);
4123 if (td
[i
].length
== prop_item
->length
)
4125 int match
= memcmp(td
[i
].value
, prop_item
->value
, td
[i
].length
) == 0;
4126 ok(match
, "%u: data mismatch\n", i
);
4130 BYTE
*data
= prop_item
->value
;
4131 trace("id %#x:", prop_item
->id
);
4132 for (j
= 0; j
< prop_item
->length
; j
++)
4133 trace(" %02x", data
[j
]);
4137 HeapFree(GetProcessHeap(), 0, prop_item
);
4140 HeapFree(GetProcessHeap(), 0, prop_id
);
4142 status
= GdipGetPropertySize(NULL
, &total_size
, &total_count
);
4143 expect(InvalidParameter
, status
);
4144 status
= GdipGetPropertySize(image
, &total_size
, NULL
);
4145 expect(InvalidParameter
, status
);
4146 status
= GdipGetPropertySize(image
, NULL
, &total_count
);
4147 expect(InvalidParameter
, status
);
4148 status
= GdipGetPropertySize(image
, NULL
, NULL
);
4149 expect(InvalidParameter
, status
);
4150 total_size
= 0xdeadbeef;
4151 total_count
= 0xdeadbeef;
4152 status
= GdipGetPropertySize(image
, &total_size
, &total_count
);
4154 ok(prop_count
== total_count
,
4155 "expected total property count %u, got %u\n", prop_count
, total_count
);
4156 ok(prop_size
== total_size
,
4157 "expected total property size %u, got %u\n", prop_size
, total_size
);
4159 prop_item
= HeapAlloc(GetProcessHeap(), 0, prop_size
);
4161 status
= GdipGetAllPropertyItems(image
, 0, prop_count
, prop_item
);
4162 expect(InvalidParameter
, status
);
4163 status
= GdipGetAllPropertyItems(image
, prop_size
, 1, prop_item
);
4164 expect(InvalidParameter
, status
);
4165 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, NULL
);
4166 expect(InvalidParameter
, status
);
4167 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, NULL
);
4168 expect(InvalidParameter
, status
);
4169 status
= GdipGetAllPropertyItems(image
, 0, 0, NULL
);
4170 expect(InvalidParameter
, status
);
4171 status
= GdipGetAllPropertyItems(image
, prop_size
+ 1, prop_count
, prop_item
);
4172 expect(InvalidParameter
, status
);
4173 status
= GdipGetAllPropertyItems(image
, prop_size
, prop_count
, prop_item
);
4176 item_data
= (const char *)(prop_item
+ prop_count
);
4177 for (i
= 0; i
< prop_count
; i
++)
4179 ok(prop_item
[i
].value
== item_data
, "%u: expected value %p, got %p\n",
4180 i
, item_data
, prop_item
[i
].value
);
4181 ok(td
[i
].type
== prop_item
[i
].type
,
4182 "%u: expected type %u, got %u\n", i
, td
[i
].type
, prop_item
[i
].type
);
4183 ok(td
[i
].id
== prop_item
[i
].id
, "%u: expected id %#x, got %#x\n", i
, td
[i
].id
, prop_item
[i
].id
);
4184 ok(td
[i
].length
== prop_item
[i
].length
, "%u: expected length %u, got %u\n", i
, td
[i
].length
, prop_item
[i
].length
);
4185 if (td
[i
].length
== prop_item
[i
].length
)
4187 int match
= memcmp(td
[i
].value
, prop_item
[i
].value
, td
[i
].length
) == 0;
4188 ok(match
, "%u: data mismatch\n", i
);
4192 BYTE
*data
= prop_item
[i
].value
;
4193 trace("id %#x:", prop_item
[i
].id
);
4194 for (j
= 0; j
< prop_item
[i
].length
; j
++)
4195 trace(" %02x", data
[j
]);
4199 item_data
+= prop_item
[i
].length
;
4202 HeapFree(GetProcessHeap(), 0, prop_item
);
4204 GdipDisposeImage(image
);
4207 static void test_ARGB_conversion(void)
4209 BYTE argb
[8] = { 0x11,0x22,0x33,0x80, 0xff,0xff,0xff,0 };
4210 BYTE pargb
[8] = { 0x09,0x11,0x1a,0x80, 0,0,0,0 };
4211 BYTE rgb32_xp
[8] = { 0x11,0x22,0x33,0xff, 0xff,0xff,0xff,0xff };
4212 BYTE rgb24
[6] = { 0x11,0x22,0x33, 0xff,0xff,0xff };
4219 status
= GdipCreateBitmapFromScan0(2, 1, 8, PixelFormat32bppARGB
, argb
, &bitmap
);
4222 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat32bppPARGB
, &data
);
4224 ok(data
.Width
== 2, "expected 2, got %d\n", data
.Width
);
4225 ok(data
.Height
== 1, "expected 1, got %d\n", data
.Height
);
4226 ok(data
.Stride
== 8, "expected 8, got %d\n", data
.Stride
);
4227 ok(data
.PixelFormat
== PixelFormat32bppPARGB
, "expected PixelFormat32bppPARGB, got %d\n", data
.PixelFormat
);
4228 match
= !memcmp(data
.Scan0
, pargb
, sizeof(pargb
));
4229 ok(match
, "bits don't match\n");
4233 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat32bppPARGB
,
4234 bits
[0], bits
[1], bits
[2], bits
[3], bits
[4], bits
[5], bits
[6], bits
[7]);
4236 status
= GdipBitmapUnlockBits(bitmap
, &data
);
4239 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat32bppRGB
, &data
);
4241 ok(data
.Width
== 2, "expected 2, got %d\n", data
.Width
);
4242 ok(data
.Height
== 1, "expected 1, got %d\n", data
.Height
);
4243 ok(data
.Stride
== 8, "expected 8, got %d\n", data
.Stride
);
4244 ok(data
.PixelFormat
== PixelFormat32bppRGB
, "expected PixelFormat32bppRGB, got %d\n", data
.PixelFormat
);
4245 match
= !memcmp(data
.Scan0
, argb
, sizeof(argb
)) ||
4246 !memcmp(data
.Scan0
, rgb32_xp
, sizeof(rgb32_xp
));
4247 ok(match
, "bits don't match\n");
4251 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat32bppRGB
,
4252 bits
[0], bits
[1], bits
[2], bits
[3], bits
[4], bits
[5], bits
[6], bits
[7]);
4254 status
= GdipBitmapUnlockBits(bitmap
, &data
);
4257 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat24bppRGB
, &data
);
4259 ok(data
.Width
== 2, "expected 2, got %d\n", data
.Width
);
4260 ok(data
.Height
== 1, "expected 1, got %d\n", data
.Height
);
4261 ok(data
.Stride
== 8, "expected 8, got %d\n", data
.Stride
);
4262 ok(data
.PixelFormat
== PixelFormat24bppRGB
, "expected PixelFormat24bppRGB, got %d\n", data
.PixelFormat
);
4263 match
= !memcmp(data
.Scan0
, rgb24
, sizeof(rgb24
));
4264 ok(match
, "bits don't match\n");
4268 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat24bppRGB
,
4269 bits
[0], bits
[1], bits
[2], bits
[3], bits
[4], bits
[5], bits
[6], bits
[7]);
4271 status
= GdipBitmapUnlockBits(bitmap
, &data
);
4274 GdipDisposeImage((GpImage
*)bitmap
);
4278 static void test_CloneBitmapArea(void)
4281 GpBitmap
*bitmap
, *copy
;
4282 BitmapData data
, data2
;
4284 status
= GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat24bppRGB
, NULL
, &bitmap
);
4287 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
| ImageLockModeWrite
, PixelFormat24bppRGB
, &data
);
4290 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat24bppRGB
, &data2
);
4291 expect(WrongState
, status
);
4293 status
= GdipCloneBitmapAreaI(0, 0, 1, 1, PixelFormat24bppRGB
, bitmap
, ©
);
4296 status
= GdipBitmapUnlockBits(bitmap
, &data
);
4299 GdipDisposeImage((GpImage
*)copy
);
4300 GdipDisposeImage((GpImage
*)bitmap
);
4305 struct GdiplusStartupInput gdiplusStartupInput
;
4306 ULONG_PTR gdiplusToken
;
4308 gdiplusStartupInput
.GdiplusVersion
= 1;
4309 gdiplusStartupInput
.DebugEventCallback
= NULL
;
4310 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
4311 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
4313 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
4315 test_CloneBitmapArea();
4316 test_ARGB_conversion();
4317 test_DrawImage_scale();
4318 test_image_format();
4320 test_GdipDrawImagePointRect();
4322 test_tiff_palette();
4323 test_GdipGetAllPropertyItems();
4324 test_tiff_properties();
4325 test_gif_properties();
4326 test_image_properties();
4329 test_GetImageDimension();
4330 test_GdipImageGetFrameDimensionsCount();
4331 test_LoadingImages();
4332 test_SavingImages();
4335 test_LockBits_UserBuf();
4336 test_GdipCreateBitmapFromHBITMAP();
4337 test_GdipGetImageFlags();
4338 test_GdipCloneImage();
4341 test_getrawformat();
4343 test_createfromwmf();
4345 test_createhbitmap();
4346 test_getthumbnail();
4351 test_multiframegif();
4357 GdiplusShutdown(gdiplusToken
);