[GDIPLUS_WINETEST]
[reactos.git] / rostests / winetests / gdiplus / image.c
1 /*
2 * Unit test suite for images
3 *
4 * Copyright (C) 2007 Google (Evan Stade)
5 * Copyright (C) 2012 Dmitry Timoshkov
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #define COBJMACROS
23
24 #include <math.h>
25 #include <assert.h>
26 #include <stdio.h>
27
28 #include <initguid.h>
29 #define WIN32_NO_STATUS
30 #define _INC_WINDOWS
31 #define COM_NO_WINDOWS_H
32
33 //#include "windows.h"
34 #include <wine/test.h>
35 #include <wingdi.h>
36 #include <winnls.h>
37 #include <ole2.h>
38 #include <gdiplus.h>
39
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))
42
43 static BOOL color_match(ARGB c1, ARGB c2, BYTE max_diff)
44 {
45 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
46 c1 >>= 8; c2 >>= 8;
47 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
48 c1 >>= 8; c2 >>= 8;
49 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
50 c1 >>= 8; c2 >>= 8;
51 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
52 return TRUE;
53 }
54
55 static void expect_guid(REFGUID expected, REFGUID got, int line, BOOL todo)
56 {
57 WCHAR bufferW[39];
58 char buffer[39];
59 char buffer2[39];
60
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);
65 if(todo)
66 todo_wine ok_(__FILE__, line)(IsEqualGUID(expected, got), "Expected %s, got %s\n", buffer2, buffer);
67 else
68 ok_(__FILE__, line)(IsEqualGUID(expected, got), "Expected %s, got %s\n", buffer2, buffer);
69 }
70
71 static void expect_rawformat(REFGUID expected, GpImage *img, int line, BOOL todo)
72 {
73 GUID raw;
74 GpStatus stat;
75
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);
80 }
81
82 static void test_bufferrawformat(void* buff, int size, REFGUID expected, int line, BOOL todo)
83 {
84 LPSTREAM stream;
85 HGLOBAL hglob;
86 LPBYTE data;
87 HRESULT hres;
88 GpStatus stat;
89 GpImage *img;
90
91 hglob = GlobalAlloc (0, size);
92 data = GlobalLock (hglob);
93 memcpy(data, buff, size);
94 GlobalUnlock(hglob); data = NULL;
95
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;
99
100 stat = GdipLoadImageFromStream(stream, &img);
101 ok_(__FILE__, line)(stat == Ok, "Failed to create a Bitmap\n");
102 if(stat != Ok){
103 IStream_Release(stream);
104 return;
105 }
106
107 expect_rawformat(expected, img, line, todo);
108
109 GdipDisposeImage(img);
110 IStream_Release(stream);
111 }
112
113 static void test_Scan0(void)
114 {
115 GpBitmap *bm;
116 GpStatus stat;
117 BYTE buff[360];
118
119 bm = NULL;
120 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
121 expect(Ok, stat);
122 ok(NULL != bm, "Expected bitmap to be initialized\n");
123 if (stat == Ok)
124 GdipDisposeImage((GpImage*)bm);
125
126 bm = (GpBitmap*)0xdeadbeef;
127 stat = GdipCreateBitmapFromScan0(10, -10, 10, PixelFormat24bppRGB, NULL, &bm);
128 expect(InvalidParameter, stat);
129 ok( !bm, "expected null bitmap\n" );
130
131 bm = (GpBitmap*)0xdeadbeef;
132 stat = GdipCreateBitmapFromScan0(-10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
133 expect(InvalidParameter, stat);
134 ok( !bm, "expected null bitmap\n" );
135
136 bm = (GpBitmap*)0xdeadbeef;
137 stat = GdipCreateBitmapFromScan0(10, 0, 10, PixelFormat24bppRGB, NULL, &bm);
138 expect(InvalidParameter, stat);
139 ok( !bm, "expected null bitmap\n" );
140
141 bm = NULL;
142 stat = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, buff, &bm);
143 expect(Ok, stat);
144 ok(NULL != bm, "Expected bitmap to be initialized\n");
145 if (stat == Ok)
146 GdipDisposeImage((GpImage*)bm);
147
148 bm = (GpBitmap*) 0xdeadbeef;
149 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, buff, &bm);
150 expect(InvalidParameter, stat);
151 ok( !bm, "expected null bitmap\n" );
152
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" );
157
158 bm = NULL;
159 stat = GdipCreateBitmapFromScan0(10, 10, -8, PixelFormat24bppRGB, buff, &bm);
160 expect(Ok, stat);
161 ok(NULL != bm, "Expected bitmap to be initialized\n");
162 if (stat == Ok)
163 GdipDisposeImage((GpImage*)bm);
164
165 bm = (GpBitmap*)0xdeadbeef;
166 stat = GdipCreateBitmapFromScan0(10, 10, -10, PixelFormat24bppRGB, buff, &bm);
167 expect(InvalidParameter, stat);
168 ok( !bm, "expected null bitmap\n" );
169 }
170
171 static void test_FromGdiDib(void)
172 {
173 GpBitmap *bm;
174 GpStatus stat;
175 BYTE buff[400];
176 BYTE rbmi[sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)];
177 BITMAPINFO *bmi = (BITMAPINFO*)rbmi;
178 PixelFormat format;
179
180 bm = NULL;
181
182 memset(rbmi, 0, sizeof(rbmi));
183
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;
190
191 stat = GdipCreateBitmapFromGdiDib(NULL, buff, &bm);
192 expect(InvalidParameter, stat);
193
194 stat = GdipCreateBitmapFromGdiDib(bmi, NULL, &bm);
195 expect(InvalidParameter, stat);
196
197 stat = GdipCreateBitmapFromGdiDib(bmi, buff, NULL);
198 expect(InvalidParameter, stat);
199
200 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
201 expect(Ok, stat);
202 ok(NULL != bm, "Expected bitmap to be initialized\n");
203 if (stat == Ok)
204 {
205 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
206 expect(Ok, stat);
207 expect(PixelFormat32bppRGB, format);
208
209 GdipDisposeImage((GpImage*)bm);
210 }
211
212 bmi->bmiHeader.biBitCount = 24;
213 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
214 expect(Ok, stat);
215 ok(NULL != bm, "Expected bitmap to be initialized\n");
216 if (stat == Ok)
217 {
218 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
219 expect(Ok, stat);
220 expect(PixelFormat24bppRGB, format);
221
222 GdipDisposeImage((GpImage*)bm);
223 }
224
225 bmi->bmiHeader.biBitCount = 16;
226 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
227 expect(Ok, stat);
228 ok(NULL != bm, "Expected bitmap to be initialized\n");
229 if (stat == Ok)
230 {
231 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
232 expect(Ok, stat);
233 expect(PixelFormat16bppRGB555, format);
234
235 GdipDisposeImage((GpImage*)bm);
236 }
237
238 bmi->bmiHeader.biBitCount = 8;
239 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
240 expect(Ok, stat);
241 ok(NULL != bm, "Expected bitmap to be initialized\n");
242 if (stat == Ok)
243 {
244 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
245 expect(Ok, stat);
246 expect(PixelFormat8bppIndexed, format);
247
248 GdipDisposeImage((GpImage*)bm);
249 }
250
251 bmi->bmiHeader.biBitCount = 4;
252 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
253 expect(Ok, stat);
254 ok(NULL != bm, "Expected bitmap to be initialized\n");
255 if (stat == Ok)
256 {
257 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
258 expect(Ok, stat);
259 expect(PixelFormat4bppIndexed, format);
260
261 GdipDisposeImage((GpImage*)bm);
262 }
263
264 bmi->bmiHeader.biBitCount = 1;
265 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
266 expect(Ok, stat);
267 ok(NULL != bm, "Expected bitmap to be initialized\n");
268 if (stat == Ok)
269 {
270 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
271 expect(Ok, stat);
272 expect(PixelFormat1bppIndexed, format);
273
274 GdipDisposeImage((GpImage*)bm);
275 }
276
277 bmi->bmiHeader.biBitCount = 0;
278 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
279 expect(InvalidParameter, stat);
280 }
281
282 static void test_GetImageDimension(void)
283 {
284 GpBitmap *bm;
285 GpStatus stat;
286 const REAL WIDTH = 10.0, HEIGHT = 20.0;
287 REAL w,h;
288
289 bm = (GpBitmap*)0xdeadbeef;
290 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
291 expect(Ok,stat);
292 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
293 ok(NULL != bm, "Expected bitmap to not be NULL\n");
294
295 stat = GdipGetImageDimension(NULL,&w,&h);
296 expect(InvalidParameter, stat);
297
298 stat = GdipGetImageDimension((GpImage*)bm,NULL,&h);
299 expect(InvalidParameter, stat);
300
301 stat = GdipGetImageDimension((GpImage*)bm,&w,NULL);
302 expect(InvalidParameter, stat);
303
304 w = -1;
305 h = -1;
306 stat = GdipGetImageDimension((GpImage*)bm,&w,&h);
307 expect(Ok, stat);
308 expectf(WIDTH, w);
309 expectf(HEIGHT, h);
310 GdipDisposeImage((GpImage*)bm);
311 }
312
313 static void test_GdipImageGetFrameDimensionsCount(void)
314 {
315 GpBitmap *bm;
316 GpStatus stat;
317 const REAL WIDTH = 10.0, HEIGHT = 20.0;
318 UINT w;
319 GUID dimension = {0};
320 UINT count;
321 ARGB color;
322
323 bm = (GpBitmap*)0xdeadbeef;
324 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
325 expect(Ok,stat);
326 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
327 ok(NULL != bm, "Expected bitmap to not be NULL\n");
328
329 stat = GdipImageGetFrameDimensionsCount(NULL,&w);
330 expect(InvalidParameter, stat);
331
332 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,NULL);
333 expect(InvalidParameter, stat);
334
335 w = -1;
336 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,&w);
337 expect(Ok, stat);
338 expect(1, w);
339
340 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 1);
341 expect(Ok, stat);
342 expect_guid(&FrameDimensionPage, &dimension, __LINE__, FALSE);
343
344 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 2);
345 expect(InvalidParameter, stat);
346
347 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 0);
348 expect(InvalidParameter, stat);
349
350 stat = GdipImageGetFrameCount(NULL, &dimension, &count);
351 expect(InvalidParameter, stat);
352
353 /* WinXP crashes on this test */
354 if(0)
355 {
356 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, NULL);
357 expect(InvalidParameter, stat);
358 }
359
360 stat = GdipImageGetFrameCount((GpImage*)bm, NULL, &count);
361 expect(Ok, stat);
362
363 count = 12345;
364 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, &count);
365 expect(Ok, stat);
366 expect(1, count);
367
368 GdipBitmapSetPixel(bm, 0, 0, 0xffffffff);
369
370 stat = GdipImageSelectActiveFrame((GpImage*)bm, &dimension, 0);
371 expect(Ok, stat);
372
373 /* SelectActiveFrame has no effect on image data of memory bitmaps */
374 color = 0xdeadbeef;
375 GdipBitmapGetPixel(bm, 0, 0, &color);
376 expect(0xffffffff, color);
377
378 GdipDisposeImage((GpImage*)bm);
379 }
380
381 static void test_LoadingImages(void)
382 {
383 GpStatus stat;
384
385 stat = GdipCreateBitmapFromFile(0, 0);
386 expect(InvalidParameter, stat);
387
388 stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
389 expect(InvalidParameter, stat);
390
391 stat = GdipLoadImageFromFile(0, 0);
392 expect(InvalidParameter, stat);
393
394 stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
395 expect(InvalidParameter, stat);
396
397 stat = GdipLoadImageFromFileICM(0, 0);
398 expect(InvalidParameter, stat);
399
400 stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
401 expect(InvalidParameter, stat);
402 }
403
404 static void test_SavingImages(void)
405 {
406 GpStatus stat;
407 GpBitmap *bm;
408 UINT n;
409 UINT s;
410 const REAL WIDTH = 10.0, HEIGHT = 20.0;
411 REAL w, h;
412 ImageCodecInfo *codecs;
413 static const CHAR filenameA[] = "a.bmp";
414 static const WCHAR filename[] = { 'a','.','b','m','p',0 };
415
416 codecs = NULL;
417
418 stat = GdipSaveImageToFile(0, 0, 0, 0);
419 expect(InvalidParameter, stat);
420
421 bm = NULL;
422 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
423 expect(Ok, stat);
424 if (!bm)
425 return;
426
427 /* invalid params */
428 stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
429 expect(InvalidParameter, stat);
430
431 stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
432 expect(InvalidParameter, stat);
433
434 /* encoder tests should succeed -- already tested */
435 stat = GdipGetImageEncodersSize(&n, &s);
436 if (stat != Ok || n == 0) goto cleanup;
437
438 codecs = GdipAlloc(s);
439 if (!codecs) goto cleanup;
440
441 stat = GdipGetImageEncoders(n, s, codecs);
442 if (stat != Ok) goto cleanup;
443
444 stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
445 expect(Ok, stat);
446
447 GdipDisposeImage((GpImage*)bm);
448 bm = 0;
449
450 /* re-load and check image stats */
451 stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
452 expect(Ok, stat);
453 if (stat != Ok) goto cleanup;
454
455 stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
456 if (stat != Ok) goto cleanup;
457
458 expectf(WIDTH, w);
459 expectf(HEIGHT, h);
460
461 cleanup:
462 GdipFree(codecs);
463 if (bm)
464 GdipDisposeImage((GpImage*)bm);
465 ok(DeleteFileA(filenameA), "Delete failed.\n");
466 }
467
468 static void test_encoders(void)
469 {
470 GpStatus stat;
471 UINT n;
472 UINT s;
473 ImageCodecInfo *codecs;
474 int i;
475 int bmp_found;
476
477 static const CHAR bmp_format[] = "BMP";
478
479 stat = GdipGetImageEncodersSize(&n, &s);
480 expect(stat, Ok);
481
482 codecs = GdipAlloc(s);
483 if (!codecs)
484 return;
485
486 stat = GdipGetImageEncoders(n, s, NULL);
487 expect(GenericError, stat);
488
489 stat = GdipGetImageEncoders(0, s, codecs);
490 expect(GenericError, stat);
491
492 stat = GdipGetImageEncoders(n, s-1, codecs);
493 expect(GenericError, stat);
494
495 stat = GdipGetImageEncoders(n, s+1, codecs);
496 expect(GenericError, stat);
497
498 stat = GdipGetImageEncoders(n, s, codecs);
499 expect(stat, Ok);
500
501 bmp_found = FALSE;
502 for (i = 0; i < n; i++)
503 {
504 CHAR desc[32];
505
506 WideCharToMultiByte(CP_ACP, 0, codecs[i].FormatDescription, -1,
507 desc, 32, 0, 0);
508
509 if (CompareStringA(LOCALE_SYSTEM_DEFAULT, 0,
510 desc, -1,
511 bmp_format, -1) == CSTR_EQUAL) {
512 bmp_found = TRUE;
513 break;
514 }
515 }
516 if (!bmp_found)
517 ok(FALSE, "No BMP codec found.\n");
518
519 GdipFree(codecs);
520 }
521
522 static void test_LockBits(void)
523 {
524 GpStatus stat;
525 GpBitmap *bm;
526 GpRect rect;
527 BitmapData bd;
528 const INT WIDTH = 10, HEIGHT = 20;
529 ARGB color;
530 int y;
531
532 bm = NULL;
533 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
534 expect(Ok, stat);
535
536 rect.X = 2;
537 rect.Y = 3;
538 rect.Width = 4;
539 rect.Height = 5;
540
541 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffc30000);
542 expect(Ok, stat);
543
544 stat = GdipBitmapSetPixel(bm, 2, 8, 0xff480000);
545 expect(Ok, stat);
546
547 /* read-only */
548 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
549 expect(Ok, stat);
550
551 if (stat == Ok) {
552 expect(0xc3, ((BYTE*)bd.Scan0)[2]);
553 expect(0x48, ((BYTE*)bd.Scan0)[2 + bd.Stride * 5]);
554
555 ((char*)bd.Scan0)[2] = 0xff;
556
557 stat = GdipBitmapUnlockBits(bm, &bd);
558 expect(Ok, stat);
559 }
560
561 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
562 expect(Ok, stat);
563 expect(0xffff0000, color);
564
565 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffc30000);
566 expect(Ok, stat);
567
568 /* read-only, with NULL rect -> whole bitmap lock */
569 stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
570 expect(Ok, stat);
571 expect(bd.Width, WIDTH);
572 expect(bd.Height, HEIGHT);
573
574 if (stat == Ok) {
575 ((char*)bd.Scan0)[2 + 2*3 + 3*bd.Stride] = 0xff;
576
577 stat = GdipBitmapUnlockBits(bm, &bd);
578 expect(Ok, stat);
579 }
580
581 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
582 expect(Ok, stat);
583 expect(0xffff0000, color);
584
585 /* read-only, consecutive */
586 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
587 expect(Ok, stat);
588
589 if (stat == Ok) {
590 stat = GdipBitmapUnlockBits(bm, &bd);
591 expect(Ok, stat);
592 }
593
594 stat = GdipDisposeImage((GpImage*)bm);
595 expect(Ok, stat);
596 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
597 expect(Ok, stat);
598
599 /* read x2 */
600 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
601 expect(Ok, stat);
602 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
603 expect(WrongState, stat);
604
605 stat = GdipBitmapUnlockBits(bm, &bd);
606 expect(Ok, stat);
607
608 stat = GdipDisposeImage((GpImage*)bm);
609 expect(Ok, stat);
610 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
611 expect(Ok, stat);
612
613 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffff0000);
614 expect(Ok, stat);
615
616 stat = GdipBitmapSetPixel(bm, 2, 8, 0xffc30000);
617 expect(Ok, stat);
618
619 /* write, no conversion */
620 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
621 expect(Ok, stat);
622
623 if (stat == Ok) {
624 /* all bits are readable, inside the rect or not */
625 expect(0xff, ((BYTE*)bd.Scan0)[2]);
626 expect(0xc3, ((BYTE*)bd.Scan0)[2 + bd.Stride * 5]);
627
628 stat = GdipBitmapUnlockBits(bm, &bd);
629 expect(Ok, stat);
630 }
631
632 /* read, conversion */
633 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat32bppARGB, &bd);
634 expect(Ok, stat);
635
636 if (stat == Ok) {
637 expect(0xff, ((BYTE*)bd.Scan0)[2]);
638 if (0)
639 /* Areas outside the rectangle appear to be uninitialized */
640 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
641
642 ((BYTE*)bd.Scan0)[2] = 0xc3;
643
644 stat = GdipBitmapUnlockBits(bm, &bd);
645 expect(Ok, stat);
646 }
647
648 /* writes do not work in read mode if there was a conversion */
649 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
650 expect(Ok, stat);
651 expect(0xffff0000, color);
652
653 /* read/write, conversion */
654 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeWrite, PixelFormat32bppARGB, &bd);
655 expect(Ok, stat);
656
657 if (stat == Ok) {
658 expect(0xff, ((BYTE*)bd.Scan0)[2]);
659 ((BYTE*)bd.Scan0)[1] = 0x88;
660 if (0)
661 /* Areas outside the rectangle appear to be uninitialized */
662 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
663
664 stat = GdipBitmapUnlockBits(bm, &bd);
665 expect(Ok, stat);
666 }
667
668 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
669 expect(Ok, stat);
670 expect(0xffff8800, color);
671
672 /* write, conversion */
673 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat32bppARGB, &bd);
674 expect(Ok, stat);
675
676 if (stat == Ok) {
677 if (0)
678 {
679 /* This is completely uninitialized. */
680 ok(0xff != ((BYTE*)bd.Scan0)[2], "original image bits are readable\n");
681 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
682 }
683
684 /* Initialize the buffer so the unlock doesn't access undefined memory */
685 for (y=0; y<5; y++)
686 memset(((BYTE*)bd.Scan0) + bd.Stride * y, 0, 12);
687
688 ((BYTE*)bd.Scan0)[0] = 0x12;
689 ((BYTE*)bd.Scan0)[1] = 0x34;
690 ((BYTE*)bd.Scan0)[2] = 0x56;
691
692 stat = GdipBitmapUnlockBits(bm, &bd);
693 expect(Ok, stat);
694 }
695
696 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
697 expect(Ok, stat);
698 expect(0xff563412, color);
699
700 stat = GdipBitmapGetPixel(bm, 2, 8, &color);
701 expect(Ok, stat);
702 expect(0xffc30000, color);
703
704 stat = GdipDisposeImage((GpImage*)bm);
705 expect(Ok, stat);
706 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
707 expect(Ok, stat);
708
709 /* write, no modification */
710 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
711 expect(Ok, stat);
712
713 if (stat == Ok) {
714 stat = GdipBitmapUnlockBits(bm, &bd);
715 expect(Ok, stat);
716 }
717
718 /* write, consecutive */
719 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
720 expect(Ok, stat);
721
722 if (stat == Ok) {
723 stat = GdipBitmapUnlockBits(bm, &bd);
724 expect(Ok, stat);
725 }
726
727 stat = GdipDisposeImage((GpImage*)bm);
728 expect(Ok, stat);
729 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
730 expect(Ok, stat);
731
732 /* write, modify */
733 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
734 expect(Ok, stat);
735
736 if (stat == Ok) {
737 if (bd.Scan0)
738 ((char*)bd.Scan0)[2] = 0xff;
739
740 stat = GdipBitmapUnlockBits(bm, &bd);
741 expect(Ok, stat);
742 }
743
744 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
745 expect(Ok, stat);
746 expect(0xffff0000, color);
747
748 stat = GdipDisposeImage((GpImage*)bm);
749 expect(Ok, stat);
750
751 /* dispose locked */
752 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
753 expect(Ok, stat);
754 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
755 expect(Ok, stat);
756 stat = GdipDisposeImage((GpImage*)bm);
757 expect(Ok, stat);
758 }
759
760 static void test_LockBits_UserBuf(void)
761 {
762 GpStatus stat;
763 GpBitmap *bm;
764 GpRect rect;
765 BitmapData bd;
766 const INT WIDTH = 10, HEIGHT = 20;
767 DWORD bits[200];
768 ARGB color;
769
770 bm = NULL;
771 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat32bppARGB, NULL, &bm);
772 expect(Ok, stat);
773
774 memset(bits, 0xaa, sizeof(bits));
775
776 rect.X = 2;
777 rect.Y = 3;
778 rect.Width = 4;
779 rect.Height = 5;
780
781 bd.Width = 4;
782 bd.Height = 6;
783 bd.Stride = WIDTH * 4;
784 bd.PixelFormat = PixelFormat32bppARGB;
785 bd.Scan0 = &bits[2+3*WIDTH];
786 bd.Reserved = 0xaaaaaaaa;
787
788 /* read-only */
789 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
790 expect(Ok, stat);
791
792 expect(0xaaaaaaaa, bits[0]);
793 expect(0, bits[2+3*WIDTH]);
794
795 bits[2+3*WIDTH] = 0xdeadbeef;
796
797 if (stat == Ok) {
798 stat = GdipBitmapUnlockBits(bm, &bd);
799 expect(Ok, stat);
800 }
801
802 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
803 expect(Ok, stat);
804 expect(0, color);
805
806 /* write-only */
807 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
808 expect(Ok, stat);
809
810 expect(0xdeadbeef, bits[2+3*WIDTH]);
811 bits[2+3*WIDTH] = 0x12345678;
812
813 if (stat == Ok) {
814 stat = GdipBitmapUnlockBits(bm, &bd);
815 expect(Ok, stat);
816 }
817
818 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
819 expect(Ok, stat);
820 expect(0x12345678, color);
821
822 bits[2+3*WIDTH] = 0;
823
824 /* read/write */
825 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeWrite|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
826 expect(Ok, stat);
827
828 expect(0x12345678, bits[2+3*WIDTH]);
829 bits[2+3*WIDTH] = 0xdeadbeef;
830
831 if (stat == Ok) {
832 stat = GdipBitmapUnlockBits(bm, &bd);
833 expect(Ok, stat);
834 }
835
836 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
837 expect(Ok, stat);
838 expect(0xdeadbeef, color);
839
840 stat = GdipDisposeImage((GpImage*)bm);
841 expect(Ok, stat);
842 }
843
844 struct BITMAPINFOWITHBITFIELDS
845 {
846 BITMAPINFOHEADER bmiHeader;
847 DWORD masks[3];
848 };
849
850 union BITMAPINFOUNION
851 {
852 BITMAPINFO bi;
853 struct BITMAPINFOWITHBITFIELDS bf;
854 };
855
856 static void test_GdipCreateBitmapFromHBITMAP(void)
857 {
858 GpBitmap* gpbm = NULL;
859 HBITMAP hbm = NULL;
860 HPALETTE hpal = NULL;
861 GpStatus stat;
862 BYTE buff[1000];
863 LOGPALETTE* LogPal = NULL;
864 REAL width, height;
865 const REAL WIDTH1 = 5;
866 const REAL HEIGHT1 = 15;
867 const REAL WIDTH2 = 10;
868 const REAL HEIGHT2 = 20;
869 HDC hdc;
870 union BITMAPINFOUNION bmi;
871 BYTE *bits;
872 PixelFormat format;
873
874 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
875 expect(InvalidParameter, stat);
876
877 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
878 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
879 expect(InvalidParameter, stat);
880
881 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
882 expect(Ok, stat);
883 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
884 expectf(WIDTH1, width);
885 expectf(HEIGHT1, height);
886 if (stat == Ok)
887 GdipDisposeImage((GpImage*)gpbm);
888 DeleteObject(hbm);
889
890 memset(buff, 0, sizeof(buff));
891 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
892 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
893 expect(Ok, stat);
894 /* raw format */
895 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
896
897 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
898 expectf(WIDTH2, width);
899 expectf(HEIGHT2, height);
900 if (stat == Ok)
901 GdipDisposeImage((GpImage*)gpbm);
902 DeleteObject(hbm);
903
904 hdc = CreateCompatibleDC(0);
905 ok(hdc != NULL, "CreateCompatibleDC failed\n");
906 bmi.bi.bmiHeader.biSize = sizeof(bmi.bi.bmiHeader);
907 bmi.bi.bmiHeader.biHeight = HEIGHT1;
908 bmi.bi.bmiHeader.biWidth = WIDTH1;
909 bmi.bi.bmiHeader.biBitCount = 24;
910 bmi.bi.bmiHeader.biPlanes = 1;
911 bmi.bi.bmiHeader.biCompression = BI_RGB;
912 bmi.bi.bmiHeader.biClrUsed = 0;
913
914 hbm = CreateDIBSection(hdc, &bmi.bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
915 ok(hbm != NULL, "CreateDIBSection failed\n");
916
917 bits[0] = 0;
918
919 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
920 expect(Ok, stat);
921 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
922 expectf(WIDTH1, width);
923 expectf(HEIGHT1, height);
924 if (stat == Ok)
925 {
926 /* test whether writing to the bitmap affects the original */
927 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
928 expect(Ok, stat);
929
930 expect(0, bits[0]);
931
932 GdipDisposeImage((GpImage*)gpbm);
933 }
934
935 LogPal = GdipAlloc(sizeof(LOGPALETTE));
936 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
937 LogPal->palVersion = 0x300;
938 LogPal->palNumEntries = 1;
939 hpal = CreatePalette(LogPal);
940 ok(hpal != NULL, "CreatePalette failed\n");
941 GdipFree(LogPal);
942
943 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
944 expect(Ok, stat);
945
946 if (stat == Ok)
947 GdipDisposeImage((GpImage*)gpbm);
948
949 DeleteObject(hpal);
950 DeleteObject(hbm);
951
952 /* 16-bit 555 dib, rgb */
953 bmi.bi.bmiHeader.biBitCount = 16;
954 bmi.bi.bmiHeader.biCompression = BI_RGB;
955
956 hbm = CreateDIBSection(hdc, &bmi.bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
957 ok(hbm != NULL, "CreateDIBSection failed\n");
958
959 bits[0] = 0;
960
961 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
962 expect(Ok, stat);
963
964 if (stat == Ok)
965 {
966 stat = GdipGetImageDimension((GpImage*) gpbm, &width, &height);
967 expect(Ok, stat);
968 expectf(WIDTH1, width);
969 expectf(HEIGHT1, height);
970
971 stat = GdipGetImagePixelFormat((GpImage*) gpbm, &format);
972 expect(Ok, stat);
973 expect(PixelFormat16bppRGB555, format);
974
975 GdipDisposeImage((GpImage*)gpbm);
976 }
977 DeleteObject(hbm);
978
979 /* 16-bit 555 dib, with bitfields */
980 bmi.bi.bmiHeader.biSize = sizeof(bmi);
981 bmi.bi.bmiHeader.biCompression = BI_BITFIELDS;
982 bmi.bf.masks[0] = 0x7c00;
983 bmi.bf.masks[1] = 0x3e0;
984 bmi.bf.masks[2] = 0x1f;
985
986 hbm = CreateDIBSection(hdc, &bmi.bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
987 ok(hbm != NULL, "CreateDIBSection failed\n");
988
989 bits[0] = 0;
990
991 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
992 expect(Ok, stat);
993
994 if (stat == Ok)
995 {
996 stat = GdipGetImageDimension((GpImage*) gpbm, &width, &height);
997 expect(Ok, stat);
998 expectf(WIDTH1, width);
999 expectf(HEIGHT1, height);
1000
1001 stat = GdipGetImagePixelFormat((GpImage*) gpbm, &format);
1002 expect(Ok, stat);
1003 expect(PixelFormat16bppRGB555, format);
1004
1005 GdipDisposeImage((GpImage*)gpbm);
1006 }
1007 DeleteObject(hbm);
1008
1009 /* 16-bit 565 dib, with bitfields */
1010 bmi.bf.masks[0] = 0xf800;
1011 bmi.bf.masks[1] = 0x7e0;
1012 bmi.bf.masks[2] = 0x1f;
1013
1014 hbm = CreateDIBSection(hdc, &bmi.bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
1015 ok(hbm != NULL, "CreateDIBSection failed\n");
1016
1017 bits[0] = 0;
1018
1019 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
1020 expect(Ok, stat);
1021
1022 if (stat == Ok)
1023 {
1024 stat = GdipGetImageDimension((GpImage*) gpbm, &width, &height);
1025 expect(Ok, stat);
1026 expectf(WIDTH1, width);
1027 expectf(HEIGHT1, height);
1028
1029 stat = GdipGetImagePixelFormat((GpImage*) gpbm, &format);
1030 expect(Ok, stat);
1031 expect(PixelFormat16bppRGB565, format);
1032
1033 GdipDisposeImage((GpImage*)gpbm);
1034 }
1035 DeleteObject(hbm);
1036
1037 DeleteDC(hdc);
1038 }
1039
1040 static void test_GdipGetImageFlags(void)
1041 {
1042 GpImage *img;
1043 GpStatus stat;
1044 UINT flags;
1045
1046 img = (GpImage*)0xdeadbeef;
1047
1048 stat = GdipGetImageFlags(NULL, NULL);
1049 expect(InvalidParameter, stat);
1050
1051 stat = GdipGetImageFlags(NULL, &flags);
1052 expect(InvalidParameter, stat);
1053
1054 stat = GdipGetImageFlags(img, NULL);
1055 expect(InvalidParameter, stat);
1056
1057 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, (GpBitmap**)&img);
1058 expect(Ok, stat);
1059 stat = GdipGetImageFlags(img, &flags);
1060 expect(Ok, stat);
1061 expect(ImageFlagsHasAlpha, flags);
1062 GdipDisposeImage(img);
1063
1064 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, (GpBitmap**)&img);
1065 expect(Ok, stat);
1066 stat = GdipGetImageFlags(img, &flags);
1067 expect(Ok, stat);
1068 expect(ImageFlagsHasAlpha, flags);
1069 GdipDisposeImage(img);
1070
1071 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, (GpBitmap**)&img);
1072 expect(Ok, stat);
1073 stat = GdipGetImageFlags(img, &flags);
1074 expect(Ok, stat);
1075 expect(ImageFlagsHasAlpha, flags);
1076 GdipDisposeImage(img);
1077
1078 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, (GpBitmap**)&img);
1079 expect(Ok, stat);
1080 stat = GdipGetImageFlags(img, &flags);
1081 expect(Ok, stat);
1082 expect(ImageFlagsNone, flags);
1083 GdipDisposeImage(img);
1084
1085 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, (GpBitmap**)&img);
1086 expect(Ok, stat);
1087 stat = GdipGetImageFlags(img, &flags);
1088 expect(Ok, stat);
1089 expect(ImageFlagsNone, flags);
1090 GdipDisposeImage(img);
1091
1092 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, (GpBitmap**)&img);
1093 expect(Ok, stat);
1094 stat = GdipGetImageFlags(img, &flags);
1095 expect(Ok, stat);
1096 expect(ImageFlagsNone, flags);
1097 GdipDisposeImage(img);
1098
1099 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppARGB1555, NULL, (GpBitmap**)&img);
1100 expect(Ok, stat);
1101 stat = GdipGetImageFlags(img, &flags);
1102 expect(Ok, stat);
1103 expect(ImageFlagsHasAlpha, flags);
1104 GdipDisposeImage(img);
1105
1106 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, (GpBitmap**)&img);
1107 expect(Ok, stat);
1108 stat = GdipGetImageFlags(img, &flags);
1109 expect(Ok, stat);
1110 expect(ImageFlagsNone, flags);
1111 GdipDisposeImage(img);
1112
1113 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, (GpBitmap**)&img);
1114 expect(Ok, stat);
1115 stat = GdipGetImageFlags(img, &flags);
1116 expect(Ok, stat);
1117 expect(ImageFlagsNone, flags);
1118 GdipDisposeImage(img);
1119
1120 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, (GpBitmap**)&img);
1121 expect(Ok, stat);
1122 stat = GdipGetImageFlags(img, &flags);
1123 expect(Ok, stat);
1124 expect(ImageFlagsHasAlpha, flags);
1125 GdipDisposeImage(img);
1126
1127 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppPARGB, NULL, (GpBitmap**)&img);
1128 expect(Ok, stat);
1129 stat = GdipGetImageFlags(img, &flags);
1130 expect(Ok, stat);
1131 expect(ImageFlagsHasAlpha, flags);
1132 GdipDisposeImage(img);
1133
1134 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, (GpBitmap**)&img);
1135 expect(Ok, stat);
1136 if (stat == Ok)
1137 {
1138 stat = GdipGetImageFlags(img, &flags);
1139 expect(Ok, stat);
1140 expect(ImageFlagsNone, flags);
1141 GdipDisposeImage(img);
1142 }
1143
1144 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, (GpBitmap**)&img);
1145 expect(Ok, stat);
1146 if (stat == Ok)
1147 {
1148 expect(Ok, stat);
1149 stat = GdipGetImageFlags(img, &flags);
1150 expect(Ok, stat);
1151 expect(ImageFlagsHasAlpha, flags);
1152 GdipDisposeImage(img);
1153 }
1154
1155 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, (GpBitmap**)&img);
1156 expect(Ok, stat);
1157 if (stat == Ok)
1158 {
1159 expect(Ok, stat);
1160 stat = GdipGetImageFlags(img, &flags);
1161 expect(Ok, stat);
1162 expect(ImageFlagsHasAlpha, flags);
1163 GdipDisposeImage(img);
1164 }
1165 }
1166
1167 static void test_GdipCloneImage(void)
1168 {
1169 GpStatus stat;
1170 GpRectF rectF;
1171 GpUnit unit;
1172 GpBitmap *bm;
1173 GpImage *image_src, *image_dest = NULL;
1174 const INT WIDTH = 10, HEIGHT = 20;
1175
1176 /* Create an image, clone it, delete the original, make sure the copy works */
1177 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
1178 expect(Ok, stat);
1179 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
1180
1181 image_src = ((GpImage*)bm);
1182 stat = GdipCloneImage(image_src, &image_dest);
1183 expect(Ok, stat);
1184 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
1185
1186 stat = GdipDisposeImage((GpImage*)bm);
1187 expect(Ok, stat);
1188 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
1189 expect(Ok, stat);
1190
1191 /* Treat FP values carefully */
1192 expectf((REAL)WIDTH, rectF.Width);
1193 expectf((REAL)HEIGHT, rectF.Height);
1194
1195 stat = GdipDisposeImage(image_dest);
1196 expect(Ok, stat);
1197 }
1198
1199 static void test_testcontrol(void)
1200 {
1201 GpStatus stat;
1202 DWORD param;
1203
1204 param = 0;
1205 stat = GdipTestControl(TestControlGetBuildNumber, &param);
1206 expect(Ok, stat);
1207 ok(param != 0, "Build number expected, got %u\n", param);
1208 }
1209
1210 static void test_fromhicon(void)
1211 {
1212 static const BYTE bmp_bits[1024];
1213 HBITMAP hbmMask, hbmColor;
1214 ICONINFO info;
1215 HICON hIcon;
1216 GpStatus stat;
1217 GpBitmap *bitmap = NULL;
1218 UINT dim;
1219 ImageType type;
1220 PixelFormat format;
1221
1222 /* NULL */
1223 stat = GdipCreateBitmapFromHICON(NULL, NULL);
1224 expect(InvalidParameter, stat);
1225 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
1226 expect(InvalidParameter, stat);
1227
1228 /* color icon 1 bit */
1229 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
1230 ok(hbmMask != 0, "CreateBitmap failed\n");
1231 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
1232 ok(hbmColor != 0, "CreateBitmap failed\n");
1233 info.fIcon = TRUE;
1234 info.xHotspot = 8;
1235 info.yHotspot = 8;
1236 info.hbmMask = hbmMask;
1237 info.hbmColor = hbmColor;
1238 hIcon = CreateIconIndirect(&info);
1239 ok(hIcon != 0, "CreateIconIndirect failed\n");
1240 DeleteObject(hbmMask);
1241 DeleteObject(hbmColor);
1242
1243 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
1244 ok(stat == Ok ||
1245 broken(stat == InvalidParameter), /* Win98 */
1246 "Expected Ok, got %.8x\n", stat);
1247 if(stat == Ok){
1248 /* check attributes */
1249 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
1250 expect(Ok, stat);
1251 expect(16, dim);
1252 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
1253 expect(Ok, stat);
1254 expect(16, dim);
1255 stat = GdipGetImageType((GpImage*)bitmap, &type);
1256 expect(Ok, stat);
1257 expect(ImageTypeBitmap, type);
1258 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
1259 expect(Ok, stat);
1260 expect(PixelFormat32bppARGB, format);
1261 /* raw format */
1262 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
1263 GdipDisposeImage((GpImage*)bitmap);
1264 }
1265 DestroyIcon(hIcon);
1266
1267 /* color icon 8 bpp */
1268 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
1269 ok(hbmMask != 0, "CreateBitmap failed\n");
1270 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
1271 ok(hbmColor != 0, "CreateBitmap failed\n");
1272 info.fIcon = TRUE;
1273 info.xHotspot = 8;
1274 info.yHotspot = 8;
1275 info.hbmMask = hbmMask;
1276 info.hbmColor = hbmColor;
1277 hIcon = CreateIconIndirect(&info);
1278 ok(hIcon != 0, "CreateIconIndirect failed\n");
1279 DeleteObject(hbmMask);
1280 DeleteObject(hbmColor);
1281
1282 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
1283 expect(Ok, stat);
1284 if(stat == Ok){
1285 /* check attributes */
1286 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
1287 expect(Ok, stat);
1288 expect(16, dim);
1289 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
1290 expect(Ok, stat);
1291 expect(16, dim);
1292 stat = GdipGetImageType((GpImage*)bitmap, &type);
1293 expect(Ok, stat);
1294 expect(ImageTypeBitmap, type);
1295 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
1296 expect(Ok, stat);
1297 expect(PixelFormat32bppARGB, format);
1298 /* raw format */
1299 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
1300 GdipDisposeImage((GpImage*)bitmap);
1301 }
1302 DestroyIcon(hIcon);
1303 }
1304
1305 /* 1x1 pixel png */
1306 static const unsigned char pngimage[285] = {
1307 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
1308 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
1309 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
1310 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
1311 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
1312 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
1313 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
1314 };
1315 /* 1x1 pixel gif */
1316 static const unsigned char gifimage[35] = {
1317 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
1318 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
1319 0x01,0x00,0x3b
1320 };
1321 /* 1x1 pixel bmp */
1322 static const unsigned char bmpimage[66] = {
1323 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
1324 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
1325 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
1326 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
1327 0x00,0x00
1328 };
1329 /* 1x1 pixel jpg */
1330 static const unsigned char jpgimage[285] = {
1331 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
1332 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
1333 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
1334 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
1335 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
1336 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
1337 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
1338 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1339 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1340 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
1341 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
1342 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1343 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
1344 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
1345 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1346 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
1347 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
1348 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
1349 };
1350 /* 1x1 pixel tiff */
1351 static const unsigned char tiffimage[] = {
1352 0x49,0x49,0x2a,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xfe,0x00,
1353 0x04,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x00,0x01,0x00,
1354 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1355 0x00,0x00,0x02,0x01,0x03,0x00,0x03,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0x03,0x01,
1356 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,0x01,0x03,0x00,0x01,0x00,
1357 0x00,0x00,0x02,0x00,0x00,0x00,0x0d,0x01,0x02,0x00,0x1b,0x00,0x00,0x00,0xd8,0x00,
1358 0x00,0x00,0x11,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x12,0x01,
1359 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x01,0x03,0x00,0x01,0x00,
1360 0x00,0x00,0x03,0x00,0x00,0x00,0x16,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x40,0x00,
1361 0x00,0x00,0x17,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1a,0x01,
1362 0x05,0x00,0x01,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x1b,0x01,0x05,0x00,0x01,0x00,
1363 0x00,0x00,0xfc,0x00,0x00,0x00,0x1c,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1364 0x00,0x00,0x28,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
1365 0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x6d,0x65,
1366 0x68,0x2f,0x44,0x65,0x73,0x6b,0x74,0x6f,0x70,0x2f,0x74,0x65,0x73,0x74,0x2e,0x74,
1367 0x69,0x66,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,
1368 0x00,0x00,0x00,0x01
1369 };
1370 /* 320x320 twip wmf */
1371 static const unsigned char wmfimage[180] = {
1372 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
1373 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
1374 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
1375 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
1376 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
1377 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
1378 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
1379 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
1380 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
1381 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
1382 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
1383 0x00,0x00,0x00,0x00
1384 };
1385 static void test_getrawformat(void)
1386 {
1387 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
1388 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
1389 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
1390 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
1391 test_bufferrawformat((void*)tiffimage, sizeof(tiffimage), &ImageFormatTIFF, __LINE__, FALSE);
1392 test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
1393 }
1394
1395 static void test_loadwmf(void)
1396 {
1397 LPSTREAM stream;
1398 HGLOBAL hglob;
1399 LPBYTE data;
1400 HRESULT hres;
1401 GpStatus stat;
1402 GpImage *img;
1403 GpRectF bounds;
1404 GpUnit unit;
1405 REAL res = 12345.0;
1406 MetafileHeader header;
1407
1408 hglob = GlobalAlloc (0, sizeof(wmfimage));
1409 data = GlobalLock (hglob);
1410 memcpy(data, wmfimage, sizeof(wmfimage));
1411 GlobalUnlock(hglob); data = NULL;
1412
1413 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1414 ok(hres == S_OK, "Failed to create a stream\n");
1415 if(hres != S_OK) return;
1416
1417 stat = GdipLoadImageFromStream(stream, &img);
1418 ok(stat == Ok, "Failed to create a Bitmap\n");
1419 if(stat != Ok){
1420 IStream_Release(stream);
1421 return;
1422 }
1423
1424 IStream_Release(stream);
1425
1426 stat = GdipGetImageBounds(img, &bounds, &unit);
1427 expect(Ok, stat);
1428 todo_wine expect(UnitPixel, unit);
1429 expectf(0.0, bounds.X);
1430 expectf(0.0, bounds.Y);
1431 todo_wine expectf(320.0, bounds.Width);
1432 todo_wine expectf(320.0, bounds.Height);
1433
1434 stat = GdipGetImageHorizontalResolution(img, &res);
1435 expect(Ok, stat);
1436 todo_wine expectf(1440.0, res);
1437
1438 stat = GdipGetImageVerticalResolution(img, &res);
1439 expect(Ok, stat);
1440 todo_wine expectf(1440.0, res);
1441
1442 memset(&header, 0, sizeof(header));
1443 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1444 expect(Ok, stat);
1445 if (stat == Ok)
1446 {
1447 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1448 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1449 todo_wine expect(0x300, header.Version);
1450 expect(0, header.EmfPlusFlags);
1451 todo_wine expectf(1440.0, header.DpiX);
1452 todo_wine expectf(1440.0, header.DpiY);
1453 expect(0, header.X);
1454 expect(0, header.Y);
1455 todo_wine expect(320, header.Width);
1456 todo_wine expect(320, header.Height);
1457 todo_wine expect(1, U(header).WmfHeader.mtType);
1458 expect(0, header.EmfPlusHeaderSize);
1459 expect(0, header.LogicalDpiX);
1460 expect(0, header.LogicalDpiY);
1461 }
1462
1463 GdipDisposeImage(img);
1464 }
1465
1466 static void test_createfromwmf(void)
1467 {
1468 HMETAFILE hwmf;
1469 GpImage *img;
1470 GpStatus stat;
1471 GpRectF bounds;
1472 GpUnit unit;
1473 REAL res = 12345.0;
1474 MetafileHeader header;
1475
1476 hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
1477 wmfimage+sizeof(WmfPlaceableFileHeader));
1478 ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
1479
1480 stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
1481 (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
1482 expect(Ok, stat);
1483 if (stat != Ok) return; // ReactOS
1484
1485 stat = GdipGetImageBounds(img, &bounds, &unit);
1486 expect(Ok, stat);
1487 expect(UnitPixel, unit);
1488 expectf(0.0, bounds.X);
1489 expectf(0.0, bounds.Y);
1490 expectf(320.0, bounds.Width);
1491 expectf(320.0, bounds.Height);
1492
1493 stat = GdipGetImageHorizontalResolution(img, &res);
1494 expect(Ok, stat);
1495 expectf(1440.0, res);
1496
1497 stat = GdipGetImageVerticalResolution(img, &res);
1498 expect(Ok, stat);
1499 expectf(1440.0, res);
1500
1501 memset(&header, 0, sizeof(header));
1502 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1503 expect(Ok, stat);
1504 if (stat == Ok)
1505 {
1506 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1507 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1508 todo_wine expect(0x300, header.Version);
1509 expect(0, header.EmfPlusFlags);
1510 todo_wine expectf(1440.0, header.DpiX);
1511 todo_wine expectf(1440.0, header.DpiY);
1512 expect(0, header.X);
1513 expect(0, header.Y);
1514 todo_wine expect(320, header.Width);
1515 todo_wine expect(320, header.Height);
1516 todo_wine expect(1, U(header).WmfHeader.mtType);
1517 expect(0, header.EmfPlusHeaderSize);
1518 expect(0, header.LogicalDpiX);
1519 expect(0, header.LogicalDpiY);
1520 }
1521
1522 GdipDisposeImage(img);
1523 }
1524
1525 static void test_resolution(void)
1526 {
1527 GpStatus stat;
1528 GpBitmap *bitmap;
1529 GpGraphics *graphics;
1530 REAL res=-1.0;
1531 HDC screendc;
1532 int screenxres, screenyres;
1533
1534 /* create Bitmap */
1535 stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
1536 expect(Ok, stat);
1537
1538 /* test invalid values */
1539 stat = GdipGetImageHorizontalResolution(NULL, &res);
1540 expect(InvalidParameter, stat);
1541
1542 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
1543 expect(InvalidParameter, stat);
1544
1545 stat = GdipGetImageVerticalResolution(NULL, &res);
1546 expect(InvalidParameter, stat);
1547
1548 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
1549 expect(InvalidParameter, stat);
1550
1551 stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
1552 expect(InvalidParameter, stat);
1553
1554 stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
1555 expect(InvalidParameter, stat);
1556
1557 /* defaults to screen resolution */
1558 screendc = GetDC(0);
1559
1560 screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
1561 screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
1562
1563 ReleaseDC(0, screendc);
1564
1565 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1566 expect(Ok, stat);
1567 expectf((REAL)screenxres, res);
1568
1569 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1570 expect(Ok, stat);
1571 expectf((REAL)screenyres, res);
1572
1573 stat = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
1574 expect(Ok, stat);
1575 stat = GdipGetDpiX(graphics, &res);
1576 expect(Ok, stat);
1577 expectf((REAL)screenxres, res);
1578 stat = GdipGetDpiY(graphics, &res);
1579 expect(Ok, stat);
1580 expectf((REAL)screenyres, res);
1581
1582 /* test changing the resolution */
1583 stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
1584 expect(Ok, stat);
1585
1586 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1587 expect(Ok, stat);
1588 expectf(screenxres*2.0, res);
1589
1590 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1591 expect(Ok, stat);
1592 expectf(screenyres*3.0, res);
1593
1594 stat = GdipGetDpiX(graphics, &res);
1595 expect(Ok, stat);
1596 expectf((REAL)screenxres, res);
1597 stat = GdipGetDpiY(graphics, &res);
1598 expect(Ok, stat);
1599 expectf((REAL)screenyres, res);
1600
1601 stat = GdipDeleteGraphics(graphics);
1602 expect(Ok, stat);
1603
1604 stat = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
1605 expect(Ok, stat);
1606 stat = GdipGetDpiX(graphics, &res);
1607 expect(Ok, stat);
1608 expectf(screenxres*2.0, res);
1609 stat = GdipGetDpiY(graphics, &res);
1610 expect(Ok, stat);
1611 expectf(screenyres*3.0, res);
1612 stat = GdipDeleteGraphics(graphics);
1613 expect(Ok, stat);
1614
1615 stat = GdipDisposeImage((GpImage*)bitmap);
1616 expect(Ok, stat);
1617 }
1618
1619 static void test_createhbitmap(void)
1620 {
1621 GpStatus stat;
1622 GpBitmap *bitmap;
1623 HBITMAP hbitmap, oldhbitmap;
1624 BITMAP bm;
1625 int ret;
1626 HDC hdc;
1627 COLORREF pixel;
1628 BYTE bits[640];
1629
1630 memset(bits, 0x68, 640);
1631
1632 /* create Bitmap */
1633 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
1634 expect(Ok, stat);
1635
1636 /* test NULL values */
1637 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
1638 expect(InvalidParameter, stat);
1639
1640 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
1641 expect(InvalidParameter, stat);
1642
1643 /* create HBITMAP */
1644 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
1645 expect(Ok, stat);
1646
1647 if (stat == Ok)
1648 {
1649 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
1650 expect(sizeof(BITMAP), ret);
1651
1652 expect(0, bm.bmType);
1653 expect(10, bm.bmWidth);
1654 expect(20, bm.bmHeight);
1655 expect(40, bm.bmWidthBytes);
1656 expect(1, bm.bmPlanes);
1657 expect(32, bm.bmBitsPixel);
1658 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1659
1660 if (bm.bmBits)
1661 {
1662 DWORD val = *(DWORD*)bm.bmBits;
1663 ok(val == 0xff686868, "got %x, expected 0xff686868\n", val);
1664 }
1665
1666 hdc = CreateCompatibleDC(NULL);
1667
1668 oldhbitmap = SelectObject(hdc, hbitmap);
1669 pixel = GetPixel(hdc, 5, 5);
1670 SelectObject(hdc, oldhbitmap);
1671
1672 DeleteDC(hdc);
1673
1674 expect(0x686868, pixel);
1675
1676 DeleteObject(hbitmap);
1677 }
1678
1679 stat = GdipDisposeImage((GpImage*)bitmap);
1680 expect(Ok, stat);
1681
1682 /* create alpha Bitmap */
1683 stat = GdipCreateBitmapFromScan0(8, 20, 32, PixelFormat32bppARGB, bits, &bitmap);
1684 expect(Ok, stat);
1685
1686 /* create HBITMAP */
1687 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
1688 expect(Ok, stat);
1689
1690 if (stat == Ok)
1691 {
1692 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
1693 expect(sizeof(BITMAP), ret);
1694
1695 expect(0, bm.bmType);
1696 expect(8, bm.bmWidth);
1697 expect(20, bm.bmHeight);
1698 expect(32, bm.bmWidthBytes);
1699 expect(1, bm.bmPlanes);
1700 expect(32, bm.bmBitsPixel);
1701 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1702
1703 if (bm.bmBits)
1704 {
1705 DWORD val = *(DWORD*)bm.bmBits;
1706 ok(val == 0x682a2a2a, "got %x, expected 0x682a2a2a\n", val);
1707 }
1708
1709 hdc = CreateCompatibleDC(NULL);
1710
1711 oldhbitmap = SelectObject(hdc, hbitmap);
1712 pixel = GetPixel(hdc, 5, 5);
1713 SelectObject(hdc, oldhbitmap);
1714
1715 DeleteDC(hdc);
1716
1717 expect(0x2a2a2a, pixel);
1718
1719 DeleteObject(hbitmap);
1720 }
1721
1722 stat = GdipDisposeImage((GpImage*)bitmap);
1723 expect(Ok, stat);
1724 }
1725
1726 static void test_getthumbnail(void)
1727 {
1728 GpStatus stat;
1729 GpImage *bitmap1, *bitmap2;
1730 UINT width, height;
1731
1732 stat = GdipGetImageThumbnail(NULL, 0, 0, &bitmap2, NULL, NULL);
1733 expect(InvalidParameter, stat);
1734
1735 stat = GdipCreateBitmapFromScan0(128, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1736 expect(Ok, stat);
1737
1738 stat = GdipGetImageThumbnail(bitmap1, 0, 0, NULL, NULL, NULL);
1739 expect(InvalidParameter, stat);
1740
1741 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1742 expect(Ok, stat);
1743
1744 if (stat == Ok)
1745 {
1746 stat = GdipGetImageWidth(bitmap2, &width);
1747 expect(Ok, stat);
1748 expect(120, width);
1749
1750 stat = GdipGetImageHeight(bitmap2, &height);
1751 expect(Ok, stat);
1752 expect(120, height);
1753
1754 GdipDisposeImage(bitmap2);
1755 }
1756
1757 GdipDisposeImage(bitmap1);
1758
1759
1760 stat = GdipCreateBitmapFromScan0(64, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1761 expect(Ok, stat);
1762
1763 stat = GdipGetImageThumbnail(bitmap1, 32, 32, &bitmap2, NULL, NULL);
1764 expect(Ok, stat);
1765
1766 if (stat == Ok)
1767 {
1768 stat = GdipGetImageWidth(bitmap2, &width);
1769 expect(Ok, stat);
1770 expect(32, width);
1771
1772 stat = GdipGetImageHeight(bitmap2, &height);
1773 expect(Ok, stat);
1774 expect(32, height);
1775
1776 GdipDisposeImage(bitmap2);
1777 }
1778
1779 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1780 expect(Ok, stat);
1781
1782 if (stat == Ok)
1783 {
1784 stat = GdipGetImageWidth(bitmap2, &width);
1785 expect(Ok, stat);
1786 expect(120, width);
1787
1788 stat = GdipGetImageHeight(bitmap2, &height);
1789 expect(Ok, stat);
1790 expect(120, height);
1791
1792 GdipDisposeImage(bitmap2);
1793 }
1794
1795 GdipDisposeImage(bitmap1);
1796 }
1797
1798 static void test_getsetpixel(void)
1799 {
1800 GpStatus stat;
1801 GpBitmap *bitmap;
1802 ARGB color;
1803 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1804 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1805
1806 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1807 expect(Ok, stat);
1808
1809 /* null parameters */
1810 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1811 expect(InvalidParameter, stat);
1812
1813 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1814 expect(InvalidParameter, stat);
1815
1816 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1817 expect(InvalidParameter, stat);
1818
1819 /* out of bounds */
1820 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1821 expect(InvalidParameter, stat);
1822
1823 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1824 expect(InvalidParameter, stat);
1825
1826 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1827 ok(stat == InvalidParameter ||
1828 broken(stat == Ok), /* Older gdiplus */
1829 "Expected InvalidParameter, got %.8x\n", stat);
1830
1831 if (0) /* crashes some gdiplus implementations */
1832 {
1833 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1834 ok(stat == InvalidParameter ||
1835 broken(stat == Ok), /* Older gdiplus */
1836 "Expected InvalidParameter, got %.8x\n", stat);
1837 }
1838
1839 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1840 expect(InvalidParameter, stat);
1841
1842 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1843 expect(InvalidParameter, stat);
1844
1845 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1846 expect(InvalidParameter, stat);
1847
1848 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1849 expect(InvalidParameter, stat);
1850
1851 /* valid use */
1852 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1853 expect(Ok, stat);
1854 expect(0xffffffff, color);
1855
1856 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1857 expect(Ok, stat);
1858 expect(0xff0000ff, color);
1859
1860 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1861 expect(Ok, stat);
1862
1863 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1864 expect(Ok, stat);
1865
1866 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1867 expect(Ok, stat);
1868 expect(0xff676869, color);
1869
1870 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1871 expect(Ok, stat);
1872 expect(0xff474849, color);
1873
1874 stat = GdipDisposeImage((GpImage*)bitmap);
1875 expect(Ok, stat);
1876 }
1877
1878 static void check_halftone_palette(ColorPalette *palette)
1879 {
1880 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1881 UINT i;
1882
1883 for (i=0; i<palette->Count; i++)
1884 {
1885 ARGB expected=0xff000000;
1886 if (i<8)
1887 {
1888 if (i&1) expected |= 0x800000;
1889 if (i&2) expected |= 0x8000;
1890 if (i&4) expected |= 0x80;
1891 }
1892 else if (i == 8)
1893 {
1894 expected = 0xffc0c0c0;
1895 }
1896 else if (i < 16)
1897 {
1898 if (i&1) expected |= 0xff0000;
1899 if (i&2) expected |= 0xff00;
1900 if (i&4) expected |= 0xff;
1901 }
1902 else if (i < 40)
1903 {
1904 expected = 0x00000000;
1905 }
1906 else
1907 {
1908 expected |= halftone_values[(i-40)%6];
1909 expected |= halftone_values[((i-40)/6)%6] << 8;
1910 expected |= halftone_values[((i-40)/36)%6] << 16;
1911 }
1912 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1913 expected, palette->Entries[i], i, palette->Count);
1914 }
1915 }
1916
1917 static void test_palette(void)
1918 {
1919 GpStatus stat;
1920 GpBitmap *bitmap;
1921 INT size;
1922 BYTE buffer[1040];
1923 ColorPalette *palette=(ColorPalette*)buffer;
1924 ARGB *entries = palette->Entries;
1925 ARGB color=0;
1926
1927 /* test initial palette from non-indexed bitmap */
1928 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1929 expect(Ok, stat);
1930
1931 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1932 expect(Ok, stat);
1933 expect(sizeof(UINT)*2+sizeof(ARGB), size);
1934
1935 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1936 expect(Ok, stat);
1937 expect(0, palette->Count);
1938
1939 /* test setting palette on not-indexed bitmap */
1940 palette->Count = 3;
1941
1942 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1943 expect(Ok, stat);
1944
1945 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1946 expect(Ok, stat);
1947 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1948
1949 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1950 expect(Ok, stat);
1951 expect(3, palette->Count);
1952
1953 GdipDisposeImage((GpImage*)bitmap);
1954
1955 /* test initial palette on 1-bit bitmap */
1956 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1957 expect(Ok, stat);
1958
1959 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1960 expect(Ok, stat);
1961 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1962
1963 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1964 expect(Ok, stat);
1965 expect(PaletteFlagsGrayScale, palette->Flags);
1966 expect(2, palette->Count);
1967
1968 expect(0xff000000, entries[0]);
1969 expect(0xffffffff, entries[1]);
1970
1971 /* test getting/setting pixels */
1972 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1973 expect(Ok, stat);
1974 expect(0xff000000, color);
1975
1976 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1977 ok((stat == Ok) ||
1978 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1979
1980 if (stat == Ok)
1981 {
1982 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1983 expect(Ok, stat);
1984 expect(0xffffffff, color);
1985 }
1986
1987 GdipDisposeImage((GpImage*)bitmap);
1988
1989 /* test initial palette on 4-bit bitmap */
1990 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1991 expect(Ok, stat);
1992
1993 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1994 expect(Ok, stat);
1995 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1996
1997 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1998 expect(Ok, stat);
1999 expect(0, palette->Flags);
2000 expect(16, palette->Count);
2001
2002 check_halftone_palette(palette);
2003
2004 /* test getting/setting pixels */
2005 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
2006 expect(Ok, stat);
2007 expect(0xff000000, color);
2008
2009 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
2010 ok((stat == Ok) ||
2011 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
2012
2013 if (stat == Ok)
2014 {
2015 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
2016 expect(Ok, stat);
2017 expect(0xffff00ff, color);
2018 }
2019
2020 GdipDisposeImage((GpImage*)bitmap);
2021
2022 /* test initial palette on 8-bit bitmap */
2023 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
2024 expect(Ok, stat);
2025
2026 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
2027 expect(Ok, stat);
2028 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
2029
2030 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
2031 expect(Ok, stat);
2032 expect(PaletteFlagsHalftone, palette->Flags);
2033 expect(256, palette->Count);
2034
2035 check_halftone_palette(palette);
2036
2037 /* test getting/setting pixels */
2038 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
2039 expect(Ok, stat);
2040 expect(0xff000000, color);
2041
2042 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
2043 ok((stat == Ok) ||
2044 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
2045
2046 if (stat == Ok)
2047 {
2048 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
2049 expect(Ok, stat);
2050 expect(0xffcccccc, color);
2051 }
2052
2053 /* test setting/getting a different palette */
2054 entries[1] = 0xffcccccc;
2055
2056 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
2057 expect(Ok, stat);
2058
2059 entries[1] = 0;
2060
2061 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
2062 expect(Ok, stat);
2063 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
2064
2065 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
2066 expect(Ok, stat);
2067 expect(PaletteFlagsHalftone, palette->Flags);
2068 expect(256, palette->Count);
2069 expect(0xffcccccc, entries[1]);
2070
2071 /* test count < 256 */
2072 palette->Flags = 12345;
2073 palette->Count = 3;
2074
2075 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
2076 expect(Ok, stat);
2077
2078 entries[1] = 0;
2079 entries[3] = 0xdeadbeef;
2080
2081 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
2082 expect(Ok, stat);
2083 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
2084
2085 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
2086 expect(Ok, stat);
2087 expect(12345, palette->Flags);
2088 expect(3, palette->Count);
2089 expect(0xffcccccc, entries[1]);
2090 expect(0xdeadbeef, entries[3]);
2091
2092 /* test count > 256 */
2093 palette->Count = 257;
2094
2095 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
2096 ok(stat == InvalidParameter ||
2097 broken(stat == Ok), /* Old gdiplus behavior */
2098 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
2099
2100 GdipDisposeImage((GpImage*)bitmap);
2101 }
2102
2103 static void test_colormatrix(void)
2104 {
2105 GpStatus stat;
2106 ColorMatrix colormatrix, graymatrix;
2107 GpImageAttributes *imageattr;
2108 const ColorMatrix identity = {{
2109 {1.0,0.0,0.0,0.0,0.0},
2110 {0.0,1.0,0.0,0.0,0.0},
2111 {0.0,0.0,1.0,0.0,0.0},
2112 {0.0,0.0,0.0,1.0,0.0},
2113 {0.0,0.0,0.0,0.0,1.0}}};
2114 const ColorMatrix double_red = {{
2115 {2.0,0.0,0.0,0.0,0.0},
2116 {0.0,1.0,0.0,0.0,0.0},
2117 {0.0,0.0,1.0,0.0,0.0},
2118 {0.0,0.0,0.0,1.0,0.0},
2119 {0.0,0.0,0.0,0.0,1.0}}};
2120 const ColorMatrix asymmetric = {{
2121 {0.0,1.0,0.0,0.0,0.0},
2122 {0.0,0.0,1.0,0.0,0.0},
2123 {0.0,0.0,0.0,1.0,0.0},
2124 {1.0,0.0,0.0,0.0,0.0},
2125 {0.0,0.0,0.0,0.0,1.0}}};
2126 GpBitmap *bitmap1, *bitmap2;
2127 GpGraphics *graphics;
2128 ARGB color;
2129
2130 colormatrix = identity;
2131 graymatrix = identity;
2132
2133 stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
2134 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
2135 expect(InvalidParameter, stat);
2136
2137 stat = GdipCreateImageAttributes(&imageattr);
2138 expect(Ok, stat);
2139
2140 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2141 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
2142 expect(Ok, stat);
2143
2144 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2145 TRUE, NULL, NULL, ColorMatrixFlagsDefault);
2146 expect(InvalidParameter, stat);
2147
2148 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2149 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
2150 expect(Ok, stat);
2151
2152 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2153 TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
2154 expect(Ok, stat);
2155
2156 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2157 TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
2158 expect(InvalidParameter, stat);
2159
2160 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2161 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
2162 expect(Ok, stat);
2163
2164 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2165 TRUE, &colormatrix, &graymatrix, 3);
2166 expect(InvalidParameter, stat);
2167
2168 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
2169 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
2170 expect(InvalidParameter, stat);
2171
2172 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
2173 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
2174 expect(InvalidParameter, stat);
2175
2176 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2177 FALSE, NULL, NULL, ColorMatrixFlagsDefault);
2178 expect(Ok, stat);
2179
2180 /* Drawing a bitmap transforms the colors */
2181 colormatrix = double_red;
2182 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2183 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
2184 expect(Ok, stat);
2185
2186 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppARGB, NULL, &bitmap1);
2187 expect(Ok, stat);
2188
2189 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppARGB, NULL, &bitmap2);
2190 expect(Ok, stat);
2191
2192 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ccee);
2193 expect(Ok, stat);
2194
2195 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2196 expect(Ok, stat);
2197
2198 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2199 UnitPixel, imageattr, NULL, NULL);
2200 expect(Ok, stat);
2201
2202 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2203 expect(Ok, stat);
2204 expect(0xff80ccee, color);
2205
2206 colormatrix = asymmetric;
2207 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2208 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
2209 expect(Ok, stat);
2210
2211 stat = GdipBitmapSetPixel(bitmap2, 0, 0, 0);
2212 expect(Ok, stat);
2213
2214 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2215 UnitPixel, imageattr, NULL, NULL);
2216 expect(Ok, stat);
2217
2218 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2219 expect(Ok, stat);
2220 ok(color_match(0xeeff40cc, color, 3), "expected 0xeeff40cc, got 0x%08x\n", color);
2221
2222 stat = GdipResetImageAttributes(imageattr, ColorAdjustTypeDefault);
2223 expect(Ok, stat);
2224
2225 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2226 UnitPixel, imageattr, NULL, NULL);
2227 expect(Ok, stat);
2228
2229 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2230 expect(Ok, stat);
2231 ok(color_match(0xff40ccee, color, 1), "Expected ff40ccee, got %.8x\n", color);
2232
2233 GdipDeleteGraphics(graphics);
2234 GdipDisposeImage((GpImage*)bitmap1);
2235 GdipDisposeImage((GpImage*)bitmap2);
2236 GdipDisposeImageAttributes(imageattr);
2237 }
2238
2239 static void test_gamma(void)
2240 {
2241 GpStatus stat;
2242 GpImageAttributes *imageattr;
2243 GpBitmap *bitmap1, *bitmap2;
2244 GpGraphics *graphics;
2245 ARGB color;
2246
2247 stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
2248 expect(InvalidParameter, stat);
2249
2250 stat = GdipCreateImageAttributes(&imageattr);
2251 expect(Ok, stat);
2252
2253 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
2254 expect(Ok, stat);
2255
2256 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
2257 expect(InvalidParameter, stat);
2258
2259 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
2260 expect(InvalidParameter, stat);
2261
2262 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
2263 expect(InvalidParameter, stat);
2264
2265 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
2266 expect(Ok, stat);
2267
2268 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
2269 expect(Ok, stat);
2270
2271 /* Drawing a bitmap transforms the colors */
2272 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
2273 expect(Ok, stat);
2274
2275 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
2276 expect(Ok, stat);
2277
2278 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
2279 expect(Ok, stat);
2280
2281 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
2282 expect(Ok, stat);
2283
2284 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2285 expect(Ok, stat);
2286
2287 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2288 UnitPixel, imageattr, NULL, NULL);
2289 expect(Ok, stat);
2290
2291 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2292 expect(Ok, stat);
2293 ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
2294
2295 stat = GdipResetImageAttributes(imageattr, ColorAdjustTypeDefault);
2296 expect(Ok, stat);
2297
2298 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2299 UnitPixel, imageattr, NULL, NULL);
2300 expect(Ok, stat);
2301
2302 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2303 expect(Ok, stat);
2304 ok(color_match(0xff80ffff, color, 1), "Expected ff80ffff, got %.8x\n", color);
2305
2306 GdipDeleteGraphics(graphics);
2307 GdipDisposeImage((GpImage*)bitmap1);
2308 GdipDisposeImage((GpImage*)bitmap2);
2309 GdipDisposeImageAttributes(imageattr);
2310 }
2311
2312 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
2313 static const unsigned char gifanimation[72] = {
2314 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
2315 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
2316 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
2317 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
2318 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
2319 };
2320
2321 static void test_multiframegif(void)
2322 {
2323 LPSTREAM stream;
2324 HGLOBAL hglob;
2325 LPBYTE data;
2326 HRESULT hres;
2327 GpStatus stat;
2328 GpBitmap *bmp;
2329 ARGB color;
2330 UINT count;
2331 GUID dimension;
2332
2333 /* Test frame functions with an animated GIF */
2334 hglob = GlobalAlloc (0, sizeof(gifanimation));
2335 data = GlobalLock (hglob);
2336 memcpy(data, gifanimation, sizeof(gifanimation));
2337 GlobalUnlock(hglob);
2338
2339 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
2340 ok(hres == S_OK, "Failed to create a stream\n");
2341 if(hres != S_OK) return;
2342
2343 stat = GdipCreateBitmapFromStream(stream, &bmp);
2344 ok(stat == Ok, "Failed to create a Bitmap\n");
2345 if(stat != Ok){
2346 IStream_Release(stream);
2347 return;
2348 }
2349
2350 /* Bitmap starts at frame 0 */
2351 color = 0xdeadbeef;
2352 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2353 expect(Ok, stat);
2354 expect(0xffffffff, color);
2355
2356 /* Check that we get correct metadata */
2357 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
2358 expect(Ok, stat);
2359 expect(1, count);
2360
2361 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
2362 expect(Ok, stat);
2363 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
2364
2365 count = 12345;
2366 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2367 expect(Ok, stat);
2368 expect(2, count);
2369
2370 /* SelectActiveFrame overwrites our current data */
2371 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
2372 expect(Ok, stat);
2373
2374 color = 0xdeadbeef;
2375 GdipBitmapGetPixel(bmp, 0, 0, &color);
2376 expect(Ok, stat);
2377 expect(0xff000000, color);
2378
2379 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2380 expect(Ok, stat);
2381
2382 color = 0xdeadbeef;
2383 GdipBitmapGetPixel(bmp, 0, 0, &color);
2384 expect(Ok, stat);
2385 expect(0xffffffff, color);
2386
2387 /* Write over the image data */
2388 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
2389 expect(Ok, stat);
2390
2391 /* Switching to the same frame does not overwrite our changes */
2392 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2393 expect(Ok, stat);
2394
2395 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2396 expect(Ok, stat);
2397 expect(0xff000000, color);
2398
2399 /* But switching to another frame and back does */
2400 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
2401 expect(Ok, stat);
2402
2403 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2404 expect(Ok, stat);
2405
2406 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2407 expect(Ok, stat);
2408 expect(0xffffffff, color);
2409
2410 /* rotate/flip discards the information about other frames */
2411 stat = GdipImageRotateFlip((GpImage*)bmp, Rotate90FlipNone);
2412 expect(Ok, stat);
2413
2414 count = 12345;
2415 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2416 expect(Ok, stat);
2417 expect(1, count);
2418
2419 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bmp, __LINE__, FALSE);
2420
2421 GdipDisposeImage((GpImage*)bmp);
2422 IStream_Release(stream);
2423
2424 /* Test with a non-animated gif */
2425 hglob = GlobalAlloc (0, sizeof(gifimage));
2426 data = GlobalLock (hglob);
2427 memcpy(data, gifimage, sizeof(gifimage));
2428 GlobalUnlock(hglob);
2429
2430 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
2431 ok(hres == S_OK, "Failed to create a stream\n");
2432 if(hres != S_OK) return;
2433
2434 stat = GdipCreateBitmapFromStream(stream, &bmp);
2435 ok(stat == Ok, "Failed to create a Bitmap\n");
2436 if(stat != Ok){
2437 IStream_Release(stream);
2438 return;
2439 }
2440
2441 /* Check metadata */
2442 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
2443 expect(Ok, stat);
2444 expect(1, count);
2445
2446 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
2447 expect(Ok, stat);
2448 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
2449
2450 count = 12345;
2451 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2452 expect(Ok, stat);
2453 expect(1, count);
2454
2455 GdipDisposeImage((GpImage*)bmp);
2456 IStream_Release(stream);
2457 }
2458
2459 static void test_rotateflip(void)
2460 {
2461 GpImage *bitmap;
2462 GpStatus stat;
2463 BYTE bits[24];
2464 static const BYTE orig_bits[24] = {
2465 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
2466 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
2467 UINT width, height;
2468 ARGB color;
2469
2470 memcpy(bits, orig_bits, sizeof(bits));
2471 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2472 expect(Ok, stat);
2473
2474 stat = GdipImageRotateFlip(bitmap, Rotate90FlipNone);
2475 expect(Ok, stat);
2476
2477 stat = GdipGetImageWidth(bitmap, &width);
2478 expect(Ok, stat);
2479 stat = GdipGetImageHeight(bitmap, &height);
2480 expect(Ok, stat);
2481 expect(2, width);
2482 expect(3, height);
2483
2484 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2485 expect(Ok, stat);
2486 expect(0xff00ffff, color);
2487
2488 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 0, &color);
2489 expect(Ok, stat);
2490 expect(0xffff0000, color);
2491
2492 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 2, &color);
2493 expect(Ok, stat);
2494 expect(0xffffff00, color);
2495
2496 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 2, &color);
2497 expect(Ok, stat);
2498 expect(0xff0000ff, color);
2499
2500 expect(0, bits[0]);
2501 expect(0, bits[1]);
2502 expect(0xff, bits[2]);
2503
2504 GdipDisposeImage(bitmap);
2505
2506 memcpy(bits, orig_bits, sizeof(bits));
2507 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2508 expect(Ok, stat);
2509
2510 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipX);
2511 expect(Ok, stat);
2512
2513 stat = GdipGetImageWidth(bitmap, &width);
2514 expect(Ok, stat);
2515 stat = GdipGetImageHeight(bitmap, &height);
2516 expect(Ok, stat);
2517 expect(3, width);
2518 expect(2, height);
2519
2520 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2521 expect(Ok, stat);
2522 expect(0xff0000ff, color);
2523
2524 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2525 expect(Ok, stat);
2526 expect(0xffff0000, color);
2527
2528 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2529 expect(Ok, stat);
2530 expect(0xffffff00, color);
2531
2532 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2533 expect(Ok, stat);
2534 expect(0xff00ffff, color);
2535
2536 expect(0, bits[0]);
2537 expect(0, bits[1]);
2538 expect(0xff, bits[2]);
2539
2540 GdipDisposeImage(bitmap);
2541
2542 memcpy(bits, orig_bits, sizeof(bits));
2543 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2544 expect(Ok, stat);
2545
2546 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipY);
2547 expect(Ok, stat);
2548
2549 stat = GdipGetImageWidth(bitmap, &width);
2550 expect(Ok, stat);
2551 stat = GdipGetImageHeight(bitmap, &height);
2552 expect(Ok, stat);
2553 expect(3, width);
2554 expect(2, height);
2555
2556 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2557 expect(Ok, stat);
2558 expect(0xff00ffff, color);
2559
2560 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2561 expect(Ok, stat);
2562 expect(0xffffff00, color);
2563
2564 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2565 expect(Ok, stat);
2566 expect(0xffff0000, color);
2567
2568 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2569 expect(Ok, stat);
2570 expect(0xff0000ff, color);
2571
2572 expect(0, bits[0]);
2573 expect(0, bits[1]);
2574 expect(0xff, bits[2]);
2575
2576 GdipDisposeImage(bitmap);
2577 }
2578
2579 static void test_remaptable(void)
2580 {
2581 GpStatus stat;
2582 GpImageAttributes *imageattr;
2583 GpBitmap *bitmap1, *bitmap2;
2584 GpGraphics *graphics;
2585 ARGB color;
2586 ColorMap *map;
2587
2588 map = GdipAlloc(sizeof(ColorMap));
2589
2590 map->oldColor.Argb = 0xff00ff00;
2591 map->newColor.Argb = 0xffff00ff;
2592
2593 stat = GdipSetImageAttributesRemapTable(NULL, ColorAdjustTypeDefault, TRUE, 1, map);
2594 expect(InvalidParameter, stat);
2595
2596 stat = GdipCreateImageAttributes(&imageattr);
2597 expect(Ok, stat);
2598
2599 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, NULL);
2600 expect(InvalidParameter, stat);
2601
2602 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeCount, TRUE, 1, map);
2603 expect(InvalidParameter, stat);
2604
2605 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeAny, TRUE, 1, map);
2606 expect(InvalidParameter, stat);
2607
2608 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 0, map);
2609 expect(InvalidParameter, stat);
2610
2611 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, FALSE, 0, NULL);
2612 expect(Ok, stat);
2613
2614 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, map);
2615 expect(Ok, stat);
2616
2617 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
2618 expect(Ok, stat);
2619
2620 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
2621 expect(Ok, stat);
2622
2623 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff00ff00);
2624 expect(Ok, stat);
2625
2626 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2627 expect(Ok, stat);
2628
2629 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2630 UnitPixel, imageattr, NULL, NULL);
2631 expect(Ok, stat);
2632
2633 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2634 expect(Ok, stat);
2635 ok(color_match(0xffff00ff, color, 1), "Expected ffff00ff, got %.8x\n", color);
2636
2637 stat = GdipResetImageAttributes(imageattr, ColorAdjustTypeDefault);
2638 expect(Ok, stat);
2639
2640 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2641 UnitPixel, imageattr, NULL, NULL);
2642 expect(Ok, stat);
2643
2644 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2645 expect(Ok, stat);
2646 ok(color_match(0xff00ff00, color, 1), "Expected ff00ff00, got %.8x\n", color);
2647
2648 GdipDeleteGraphics(graphics);
2649 GdipDisposeImage((GpImage*)bitmap1);
2650 GdipDisposeImage((GpImage*)bitmap2);
2651 GdipDisposeImageAttributes(imageattr);
2652 GdipFree(map);
2653 }
2654
2655 static void test_colorkey(void)
2656 {
2657 GpStatus stat;
2658 GpImageAttributes *imageattr;
2659 GpBitmap *bitmap1, *bitmap2;
2660 GpGraphics *graphics;
2661 ARGB color;
2662
2663 stat = GdipSetImageAttributesColorKeys(NULL, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2664 expect(InvalidParameter, stat);
2665
2666 stat = GdipCreateImageAttributes(&imageattr);
2667 expect(Ok, stat);
2668
2669 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeCount, TRUE, 0xff405060, 0xff708090);
2670 expect(InvalidParameter, stat);
2671
2672 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeAny, TRUE, 0xff405060, 0xff708090);
2673 expect(InvalidParameter, stat);
2674
2675 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2676 expect(Ok, stat);
2677
2678 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap1);
2679 expect(Ok, stat);
2680
2681 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap2);
2682 expect(Ok, stat);
2683
2684 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0x20405060);
2685 expect(Ok, stat);
2686
2687 stat = GdipBitmapSetPixel(bitmap1, 0, 1, 0x40506070);
2688 expect(Ok, stat);
2689
2690 stat = GdipBitmapSetPixel(bitmap1, 1, 0, 0x60708090);
2691 expect(Ok, stat);
2692
2693 stat = GdipBitmapSetPixel(bitmap1, 1, 1, 0xffffffff);
2694 expect(Ok, stat);
2695
2696 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2697 expect(Ok, stat);
2698
2699 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,2,2, 0,0,2,2,
2700 UnitPixel, imageattr, NULL, NULL);
2701 expect(Ok, stat);
2702
2703 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2704 expect(Ok, stat);
2705 ok(color_match(0x00000000, color, 1), "Expected 00000000, got %.8x\n", color);
2706
2707 stat = GdipBitmapGetPixel(bitmap2, 0, 1, &color);
2708 expect(Ok, stat);
2709 ok(color_match(0x00000000, color, 1), "Expected 00000000, got %.8x\n", color);
2710
2711 stat = GdipBitmapGetPixel(bitmap2, 1, 0, &color);
2712 expect(Ok, stat);
2713 ok(color_match(0x00000000, color, 1), "Expected 00000000, got %.8x\n", color);
2714
2715 stat = GdipBitmapGetPixel(bitmap2, 1, 1, &color);
2716 expect(Ok, stat);
2717 ok(color_match(0xffffffff, color, 1), "Expected ffffffff, got %.8x\n", color);
2718
2719 stat = GdipResetImageAttributes(imageattr, ColorAdjustTypeDefault);
2720 expect(Ok, stat);
2721
2722 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,2,2, 0,0,2,2,
2723 UnitPixel, imageattr, NULL, NULL);
2724 expect(Ok, stat);
2725
2726 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2727 expect(Ok, stat);
2728 ok(color_match(0x20405060, color, 1), "Expected 20405060, got %.8x\n", color);
2729
2730 stat = GdipBitmapGetPixel(bitmap2, 0, 1, &color);
2731 expect(Ok, stat);
2732 ok(color_match(0x40506070, color, 1), "Expected 40506070, got %.8x\n", color);
2733
2734 stat = GdipBitmapGetPixel(bitmap2, 1, 0, &color);
2735 expect(Ok, stat);
2736 ok(color_match(0x60708090, color, 1), "Expected 60708090, got %.8x\n", color);
2737
2738 stat = GdipBitmapGetPixel(bitmap2, 1, 1, &color);
2739 expect(Ok, stat);
2740 ok(color_match(0xffffffff, color, 1), "Expected ffffffff, got %.8x\n", color);
2741
2742
2743 GdipDeleteGraphics(graphics);
2744 GdipDisposeImage((GpImage*)bitmap1);
2745 GdipDisposeImage((GpImage*)bitmap2);
2746 GdipDisposeImageAttributes(imageattr);
2747 }
2748
2749 static void test_dispose(void)
2750 {
2751 GpStatus stat;
2752 GpImage *image;
2753 char invalid_image[256];
2754
2755 stat = GdipDisposeImage(NULL);
2756 expect(InvalidParameter, stat);
2757
2758 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, (GpBitmap**)&image);
2759 expect(Ok, stat);
2760
2761 stat = GdipDisposeImage(image);
2762 expect(Ok, stat);
2763
2764 stat = GdipDisposeImage(image);
2765 expect(ObjectBusy, stat);
2766
2767 memset(invalid_image, 0, 256);
2768 stat = GdipDisposeImage((GpImage*)invalid_image);
2769 expect(ObjectBusy, stat);
2770 }
2771
2772 static LONG obj_refcount(void *obj)
2773 {
2774 IUnknown_AddRef((IUnknown *)obj);
2775 return IUnknown_Release((IUnknown *)obj);
2776 }
2777
2778 static GpImage *load_image(const BYTE *image_data, UINT image_size)
2779 {
2780 IStream *stream;
2781 HGLOBAL hmem;
2782 BYTE *data;
2783 HRESULT hr;
2784 GpStatus status;
2785 GpImage *image = NULL, *clone;
2786 ImageType image_type;
2787 LONG refcount, old_refcount;
2788
2789 hmem = GlobalAlloc(0, image_size);
2790 data = GlobalLock(hmem);
2791 memcpy(data, image_data, image_size);
2792 GlobalUnlock(hmem);
2793
2794 hr = CreateStreamOnHGlobal(hmem, TRUE, &stream);
2795 ok(hr == S_OK, "CreateStreamOnHGlobal error %#x\n", hr);
2796 if (hr != S_OK) return NULL;
2797
2798 refcount = obj_refcount(stream);
2799 ok(refcount == 1, "expected stream refcount 1, got %d\n", refcount);
2800
2801 status = GdipLoadImageFromStream(stream, &image);
2802 ok(status == Ok || broken(status == InvalidParameter), /* XP */
2803 "GdipLoadImageFromStream error %d\n", status);
2804 if (status != Ok)
2805 {
2806 IStream_Release(stream);
2807 return NULL;
2808 }
2809
2810 status = GdipGetImageType(image, &image_type);
2811 ok(status == Ok, "GdipGetImageType error %d\n", status);
2812
2813 refcount = obj_refcount(stream);
2814 if (image_type == ImageTypeBitmap)
2815 ok(refcount > 1, "expected stream refcount > 1, got %d\n", refcount);
2816 else
2817 ok(refcount == 1, "expected stream refcount 1, got %d\n", refcount);
2818 old_refcount = refcount;
2819
2820 status = GdipCloneImage(image, &clone);
2821 ok(status == Ok, "GdipCloneImage error %d\n", status);
2822 refcount = obj_refcount(stream);
2823 ok(refcount == old_refcount, "expected stream refcount %d, got %d\n", old_refcount, refcount);
2824 status = GdipDisposeImage(clone);
2825 ok(status == Ok, "GdipDisposeImage error %d\n", status);
2826 refcount = obj_refcount(stream);
2827 ok(refcount == old_refcount, "expected stream refcount %d, got %d\n", old_refcount, refcount);
2828
2829 refcount = IStream_Release(stream);
2830 if (image_type == ImageTypeBitmap)
2831 ok(refcount >= 1, "expected stream refcount != 0\n");
2832 else
2833 ok(refcount == 0, "expected stream refcount 0, got %d\n", refcount);
2834
2835 return image;
2836 }
2837
2838 static void test_image_properties(void)
2839 {
2840 static const struct test_data
2841 {
2842 const BYTE *image_data;
2843 UINT image_size;
2844 ImageType image_type;
2845 UINT prop_count;
2846 UINT prop_count2; /* if win7 behaves differently */
2847 /* 1st property attributes */
2848 UINT prop_size;
2849 UINT prop_size2; /* if win7 behaves differently */
2850 UINT prop_id;
2851 UINT prop_id2; /* if win7 behaves differently */
2852 }
2853 td[] =
2854 {
2855 { pngimage, sizeof(pngimage), ImageTypeBitmap, 4, ~0, 1, 20, 0x5110, 0x132 },
2856 { jpgimage, sizeof(jpgimage), ImageTypeBitmap, 2, ~0, 128, 0, 0x5090, 0x5091 },
2857 { tiffimage, sizeof(tiffimage), ImageTypeBitmap, 16, 0, 4, 0, 0xfe, 0 },
2858 { bmpimage, sizeof(bmpimage), ImageTypeBitmap, 0, 0, 0, 0, 0, 0 },
2859 { wmfimage, sizeof(wmfimage), ImageTypeMetafile, 0, 0, 0, 0, 0, 0 }
2860 };
2861 GpStatus status;
2862 GpImage *image;
2863 UINT prop_count, prop_size, i;
2864 PROPID prop_id[16] = { 0 };
2865 ImageType image_type;
2866 union
2867 {
2868 PropertyItem data;
2869 char buf[256];
2870 } item;
2871
2872 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
2873 {
2874 image = load_image(td[i].image_data, td[i].image_size);
2875 if (!image)
2876 {
2877 trace("%u: failed to load image data\n", i);
2878 continue;
2879 }
2880
2881 status = GdipGetImageType(image, &image_type);
2882 ok(status == Ok, "%u: GdipGetImageType error %d\n", i, status);
2883 ok(td[i].image_type == image_type, "%u: expected image_type %d, got %d\n",
2884 i, td[i].image_type, image_type);
2885
2886 status = GdipGetPropertyCount(image, &prop_count);
2887 ok(status == Ok, "%u: GdipGetPropertyCount error %d\n", i, status);
2888 if (td[i].image_data == pngimage || td[i].image_data == jpgimage)
2889 todo_wine
2890 ok(td[i].prop_count == prop_count || td[i].prop_count2 == prop_count,
2891 " %u: expected property count %u or %u, got %u\n",
2892 i, td[i].prop_count, td[i].prop_count2, prop_count);
2893 else
2894 ok(td[i].prop_count == prop_count || td[i].prop_count2 == prop_count,
2895 " %u: expected property count %u or %u, got %u\n",
2896 i, td[i].prop_count, td[i].prop_count2, prop_count);
2897
2898 status = GdipGetPropertyItemSize(NULL, 0, &prop_size);
2899 expect(InvalidParameter, status);
2900 status = GdipGetPropertyItemSize(image, 0, NULL);
2901 expect(InvalidParameter, status);
2902 status = GdipGetPropertyItemSize(image, 0, &prop_size);
2903 if (image_type == ImageTypeMetafile)
2904 expect(NotImplemented, status);
2905 else
2906 expect(PropertyNotFound, status);
2907
2908 status = GdipGetPropertyItem(NULL, 0, 0, &item.data);
2909 expect(InvalidParameter, status);
2910 status = GdipGetPropertyItem(image, 0, 0, NULL);
2911 expect(InvalidParameter, status);
2912 status = GdipGetPropertyItem(image, 0, 0, &item.data);
2913 if (image_type == ImageTypeMetafile)
2914 expect(NotImplemented, status);
2915 else
2916 expect(PropertyNotFound, status);
2917
2918 /* FIXME: remove once Wine is fixed */
2919 if (td[i].prop_count != prop_count)
2920 {
2921 GdipDisposeImage(image);
2922 continue;
2923 }
2924
2925 status = GdipGetPropertyIdList(NULL, prop_count, prop_id);
2926 expect(InvalidParameter, status);
2927 status = GdipGetPropertyIdList(image, prop_count, NULL);
2928 expect(InvalidParameter, status);
2929 status = GdipGetPropertyIdList(image, 0, prop_id);
2930 if (image_type == ImageTypeMetafile)
2931 expect(NotImplemented, status);
2932 else if (prop_count == 0)
2933 expect(Ok, status);
2934 else
2935 expect(InvalidParameter, status);
2936 status = GdipGetPropertyIdList(image, prop_count - 1, prop_id);
2937 if (image_type == ImageTypeMetafile)
2938 expect(NotImplemented, status);
2939 else
2940 expect(InvalidParameter, status);
2941 status = GdipGetPropertyIdList(image, prop_count + 1, prop_id);
2942 if (image_type == ImageTypeMetafile)
2943 expect(NotImplemented, status);
2944 else
2945 expect(InvalidParameter, status);
2946 status = GdipGetPropertyIdList(image, prop_count, prop_id);
2947 if (image_type == ImageTypeMetafile)
2948 expect(NotImplemented, status);
2949 else
2950 {
2951 expect(Ok, status);
2952 if (prop_count != 0)
2953 ok(td[i].prop_id == prop_id[0] || td[i].prop_id2 == prop_id[0],
2954 " %u: expected property id %#x or %#x, got %#x\n",
2955 i, td[i].prop_id, td[i].prop_id2, prop_id[0]);
2956 }
2957
2958 if (status == Ok)
2959 {
2960 status = GdipGetPropertyItemSize(image, prop_id[0], &prop_size);
2961 if (prop_count == 0)
2962 expect(PropertyNotFound, status);
2963 else
2964 {
2965 expect(Ok, status);
2966
2967 assert(sizeof(item) >= prop_size);
2968 ok(prop_size > sizeof(PropertyItem), "%u: got too small prop_size %u\n",
2969 i, prop_size);
2970 ok(td[i].prop_size + sizeof(PropertyItem) == prop_size ||
2971 td[i].prop_size2 + sizeof(PropertyItem) == prop_size,
2972 " %u: expected property size %u or %u, got %u\n",
2973 i, td[i].prop_size, td[i].prop_size2, prop_size);
2974
2975 status = GdipGetPropertyItem(image, prop_id[0], 0, &item.data);
2976 ok(status == InvalidParameter || status == GenericError /* Win7 */,
2977 "%u: expected InvalidParameter, got %d\n", i, status);
2978 status = GdipGetPropertyItem(image, prop_id[0], prop_size - 1, &item.data);
2979 ok(status == InvalidParameter || status == GenericError /* Win7 */,
2980 "%u: expected InvalidParameter, got %d\n", i, status);
2981 status = GdipGetPropertyItem(image, prop_id[0], prop_size + 1, &item.data);
2982 ok(status == InvalidParameter || status == GenericError /* Win7 */,
2983 "%u: expected InvalidParameter, got %d\n", i, status);
2984 status = GdipGetPropertyItem(image, prop_id[0], prop_size, &item.data);
2985 expect(Ok, status);
2986 ok(prop_id[0] == item.data.id,
2987 "%u: expected property id %#x, got %#x\n", i, prop_id[0], item.data.id);
2988 }
2989 }
2990
2991 GdipDisposeImage(image);
2992 }
2993 }
2994
2995 #define IFD_BYTE 1
2996 #define IFD_ASCII 2
2997 #define IFD_SHORT 3
2998 #define IFD_LONG 4
2999 #define IFD_RATIONAL 5
3000 #define IFD_SBYTE 6
3001 #define IFD_UNDEFINED 7
3002 #define IFD_SSHORT 8
3003 #define IFD_SLONG 9
3004 #define IFD_SRATIONAL 10
3005 #define IFD_FLOAT 11
3006 #define IFD_DOUBLE 12
3007
3008 #ifndef PropertyTagTypeSByte
3009 #define PropertyTagTypeSByte 6
3010 #define PropertyTagTypeSShort 8
3011 #define PropertyTagTypeFloat 11
3012 #define PropertyTagTypeDouble 12
3013 #endif
3014
3015 static UINT documented_type(UINT type)
3016 {
3017 switch (type)
3018 {
3019 case PropertyTagTypeSByte: return PropertyTagTypeByte;
3020 case PropertyTagTypeSShort: return PropertyTagTypeShort;
3021 case PropertyTagTypeFloat: return PropertyTagTypeUndefined;
3022 case PropertyTagTypeDouble: return PropertyTagTypeUndefined;
3023 default: return type;
3024 }
3025 }
3026
3027 #include "pshpack2.h"
3028 struct IFD_entry
3029 {
3030 SHORT id;
3031 SHORT type;
3032 ULONG count;
3033 LONG value;
3034 };
3035
3036 struct IFD_rational
3037 {
3038 LONG numerator;
3039 LONG denominator;
3040 };
3041
3042 static const struct tiff_data
3043 {
3044 USHORT byte_order;
3045 USHORT version;
3046 ULONG dir_offset;
3047 USHORT number_of_entries;
3048 struct IFD_entry entry[40];
3049 ULONG next_IFD;
3050 struct IFD_rational xres;
3051 DOUBLE double_val;
3052 struct IFD_rational srational_val;
3053 char string[14];
3054 SHORT short_val[4];
3055 LONG long_val[2];
3056 FLOAT float_val[2];
3057 struct IFD_rational rational[3];
3058 BYTE pixel_data[4];
3059 } TIFF_data =
3060 {
3061 #ifdef WORDS_BIGENDIAN
3062 'M' | 'M' << 8,
3063 #else
3064 'I' | 'I' << 8,
3065 #endif
3066 42,
3067 FIELD_OFFSET(struct tiff_data, number_of_entries),
3068 31,
3069 {
3070 { 0xff, IFD_SHORT, 1, 0 }, /* SUBFILETYPE */
3071 { 0x100, IFD_LONG, 1, 1 }, /* IMAGEWIDTH */
3072 { 0x101, IFD_LONG, 1, 1 }, /* IMAGELENGTH */
3073 { 0x102, IFD_SHORT, 1, 1 }, /* BITSPERSAMPLE */
3074 { 0x103, IFD_SHORT, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
3075 { 0x106, IFD_SHORT, 1, 1 }, /* PHOTOMETRIC */
3076 { 0x111, IFD_LONG, 1, FIELD_OFFSET(struct tiff_data, pixel_data) }, /* STRIPOFFSETS */
3077 { 0x115, IFD_SHORT, 1, 1 }, /* SAMPLESPERPIXEL */
3078 { 0x116, IFD_LONG, 1, 1 }, /* ROWSPERSTRIP */
3079 { 0x117, IFD_LONG, 1, 1 }, /* STRIPBYTECOUNT */
3080 { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_data, xres) },
3081 { 0x11b, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_data, xres) },
3082 { 0x128, IFD_SHORT, 1, 2 }, /* RESOLUTIONUNIT */
3083 { 0xf001, IFD_BYTE, 1, 0x11223344 },
3084 { 0xf002, IFD_BYTE, 4, 0x11223344 },
3085 { 0xf003, IFD_SBYTE, 1, 0x11223344 },
3086 { 0xf004, IFD_SSHORT, 1, 0x11223344 },
3087 { 0xf005, IFD_SSHORT, 2, 0x11223344 },
3088 { 0xf006, IFD_SLONG, 1, 0x11223344 },
3089 { 0xf007, IFD_FLOAT, 1, 0x11223344 },
3090 { 0xf008, IFD_DOUBLE, 1, FIELD_OFFSET(struct tiff_data, double_val) },
3091 { 0xf009, IFD_SRATIONAL, 1, FIELD_OFFSET(struct tiff_data, srational_val) },
3092 { 0xf00a, IFD_BYTE, 13, FIELD_OFFSET(struct tiff_data, string) },
3093 { 0xf00b, IFD_SSHORT, 4, FIELD_OFFSET(struct tiff_data, short_val) },
3094 { 0xf00c, IFD_SLONG, 2, FIELD_OFFSET(struct tiff_data, long_val) },
3095 { 0xf00e, IFD_ASCII, 13, FIELD_OFFSET(struct tiff_data, string) },
3096 { 0xf00f, IFD_ASCII, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
3097 { 0xf010, IFD_UNDEFINED, 13, FIELD_OFFSET(struct tiff_data, string) },
3098 { 0xf011, IFD_UNDEFINED, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
3099 /* Some gdiplus versions ignore these fields.
3100 { 0xf012, IFD_BYTE, 0, 0x11223344 },
3101 { 0xf013, IFD_SHORT, 0, 0x11223344 },
3102 { 0xf014, IFD_LONG, 0, 0x11223344 },
3103 { 0xf015, IFD_FLOAT, 0, 0x11223344 },*/
3104 { 0xf016, IFD_SRATIONAL, 3, FIELD_OFFSET(struct tiff_data, rational) },
3105 /* Win7 before SP1 doesn't recognize this field, everybody else does. */
3106 { 0xf017, IFD_FLOAT, 2, FIELD_OFFSET(struct tiff_data, float_val) },
3107 },
3108 0,
3109 { 900, 3 },
3110 1234567890.0987654321,
3111 { 0x1a2b3c4d, 0x5a6b7c8d },
3112 "Hello World!",
3113 { 0x0101, 0x0202, 0x0303, 0x0404 },
3114 { 0x11223344, 0x55667788 },
3115 { (FLOAT)1234.5678, (FLOAT)8765.4321 },
3116 { { 0x01020304, 0x05060708 }, { 0x10203040, 0x50607080 }, { 0x11223344, 0x55667788 } },
3117 { 0x11, 0x22, 0x33, 0 }
3118 };
3119 #include "poppack.h"
3120
3121 static void test_tiff_properties(void)
3122 {
3123 static const struct test_data
3124 {
3125 ULONG type, id, length;
3126 const BYTE value[24];
3127 } td[31] =
3128 {
3129 { PropertyTagTypeShort, 0xff, 2, { 0 } },
3130 { PropertyTagTypeLong, 0x100, 4, { 1 } },
3131 { PropertyTagTypeLong, 0x101, 4, { 1 } },
3132 { PropertyTagTypeShort, 0x102, 2, { 1 } },
3133 { PropertyTagTypeShort, 0x103, 2, { 1 } },
3134 { PropertyTagTypeShort, 0x106, 2, { 1 } },
3135 { PropertyTagTypeLong, 0x111, 4, { 0x44,0x02 } },
3136 { PropertyTagTypeShort, 0x115, 2, { 1 } },
3137 { PropertyTagTypeLong, 0x116, 4, { 1 } },
3138 { PropertyTagTypeLong, 0x117, 4, { 1 } },
3139 { PropertyTagTypeRational, 0x11a, 8, { 0x84,0x03,0,0,0x03 } },
3140 { PropertyTagTypeRational, 0x11b, 8, { 0x84,0x03,0,0,0x03 } },
3141 { PropertyTagTypeShort, 0x128, 2, { 2 } },
3142 { PropertyTagTypeByte, 0xf001, 1, { 0x44 } },
3143 { PropertyTagTypeByte, 0xf002, 4, { 0x44,0x33,0x22,0x11 } },
3144 { PropertyTagTypeSByte, 0xf003, 1, { 0x44 } },
3145 { PropertyTagTypeSShort, 0xf004, 2, { 0x44,0x33 } },
3146 { PropertyTagTypeSShort, 0xf005, 4, { 0x44,0x33,0x22,0x11 } },
3147 { PropertyTagTypeSLONG, 0xf006, 4, { 0x44,0x33,0x22,0x11 } },
3148 { PropertyTagTypeFloat, 0xf007, 4, { 0x44,0x33,0x22,0x11 } },
3149 { PropertyTagTypeDouble, 0xf008, 8, { 0x2c,0x52,0x86,0xb4,0x80,0x65,0xd2,0x41 } },
3150 { PropertyTagTypeSRational, 0xf009, 8, { 0x4d, 0x3c, 0x2b, 0x1a, 0x8d, 0x7c, 0x6b, 0x5a } },
3151 { PropertyTagTypeByte, 0xf00a, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3152 { PropertyTagTypeSShort, 0xf00b, 8, { 0x01,0x01,0x02,0x02,0x03,0x03,0x04,0x04 } },
3153 { PropertyTagTypeSLONG, 0xf00c, 8, { 0x44,0x33,0x22,0x11,0x88,0x77,0x66,0x55 } },
3154 { PropertyTagTypeASCII, 0xf00e, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3155 { PropertyTagTypeASCII, 0xf00f, 5, { 'a','b','c','d' } },
3156 { PropertyTagTypeUndefined, 0xf010, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3157 { PropertyTagTypeUndefined, 0xf011, 4, { 'a','b','c','d' } },
3158 { PropertyTagTypeSRational, 0xf016, 24,
3159 { 0x04,0x03,0x02,0x01,0x08,0x07,0x06,0x05,
3160 0x40,0x30,0x20,0x10,0x80,0x70,0x60,0x50,
3161 0x44,0x33,0x22,0x11,0x88,0x77,0x66,0x55 } },
3162 /* Win7 before SP1 doesn't recognize this field, everybody else does. */
3163 { PropertyTagTypeFloat, 0xf017, 8, { 0x2b,0x52,0x9a,0x44,0xba,0xf5,0x08,0x46 } },
3164 };
3165 GpStatus status;
3166 GpImage *image;
3167 GUID guid;
3168 UINT dim_count, frame_count, prop_count, prop_size, i;
3169 PROPID *prop_id;
3170 PropertyItem *prop_item;
3171
3172 image = load_image((const BYTE *)&TIFF_data, sizeof(TIFF_data));
3173 if (!image)
3174 {
3175 win_skip("Failed to load TIFF image data. Might not be supported. Skipping.\n");
3176 return;
3177 }
3178
3179 status = GdipImageGetFrameDimensionsCount(image, &dim_count);
3180 expect(Ok, status);
3181 expect(1, dim_count);
3182
3183 status = GdipImageGetFrameDimensionsList(image, &guid, 1);
3184 expect(Ok, status);
3185 expect_guid(&FrameDimensionPage, &guid, __LINE__, FALSE);
3186
3187 frame_count = 0xdeadbeef;
3188 status = GdipImageGetFrameCount(image, &guid, &frame_count);
3189 expect(Ok, status);
3190 expect(1, frame_count);
3191
3192 prop_count = 0xdeadbeef;
3193 status = GdipGetPropertyCount(image, &prop_count);
3194 expect(Ok, status);
3195 ok(prop_count == sizeof(td)/sizeof(td[0]) ||
3196 broken(prop_count == sizeof(td)/sizeof(td[0]) - 1) /* Win7 SP0 */,
3197 "expected property count %u, got %u\n", (UINT)(sizeof(td)/sizeof(td[0])), prop_count);
3198
3199 prop_id = HeapAlloc(GetProcessHeap(), 0, prop_count * sizeof(*prop_id));
3200
3201 status = GdipGetPropertyIdList(image, prop_count, prop_id);
3202 expect(Ok, status);
3203
3204 for (i = 0; i < prop_count; i++)
3205 {
3206 status = GdipGetPropertyItemSize(image, prop_id[i], &prop_size);
3207 expect(Ok, status);
3208 if (status != Ok) break;
3209 ok(prop_size > sizeof(*prop_item), "%u: too small item length %u\n", i, prop_size);
3210
3211 prop_item = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, prop_size);
3212 status = GdipGetPropertyItem(image, prop_id[i], prop_size, prop_item);
3213 expect(Ok, status);
3214 ok(prop_item->value == prop_item + 1, "expected item->value %p, got %p\n", prop_item + 1, prop_item->value);
3215 ok(td[i].type == prop_item->type ||
3216 /* Win7 stopped using proper but not documented types, and it
3217 looks broken since TypeFloat and TypeDouble now reported as
3218 TypeUndefined, and signed types reported as unsigned. */
3219 broken(prop_item->type == documented_type(td[i].type)),
3220 "%u: expected type %u, got %u\n", i, td[i].type, prop_item->type);
3221 ok(td[i].id == prop_item->id, "%u: expected id %#x, got %#x\n", i, td[i].id, prop_item->id);
3222 prop_size -= sizeof(*prop_item);
3223 ok(prop_item->length == prop_size, "%u: expected length %u, got %u\n", i, prop_size, prop_item->length);
3224 ok(td[i].length == prop_item->length, "%u: expected length %u, got %u\n", i, td[i].length, prop_item->length);
3225 ok(td[i].length == prop_size, "%u: expected length %u, got %u\n", i, td[i].length, prop_size);
3226 if (td[i].length == prop_item->length)
3227 {
3228 int match = memcmp(td[i].value, prop_item->value, td[i].length) == 0;
3229 ok(match || broken(td[i].length <= 4 && !match), "%u: data mismatch\n", i);
3230 if (!match)
3231 {
3232 UINT j;
3233 BYTE *data = prop_item->value;
3234 printf("id %#x:", prop_item->id);
3235 for (j = 0; j < prop_item->length; j++)
3236 printf(" %02x", data[j]);
3237 printf("\n");
3238 }
3239 }
3240 HeapFree(GetProcessHeap(), 0, prop_item);
3241 }
3242
3243 HeapFree(GetProcessHeap(), 0, prop_id);
3244
3245 GdipDisposeImage(image);
3246 }
3247
3248 static void test_GdipGetAllPropertyItems(void)
3249 {
3250 static const struct test_data
3251 {
3252 ULONG type, id, length;
3253 BYTE value[32];
3254 } td[16] =
3255 {
3256 { PropertyTagTypeLong, 0xfe, 4, { 0 } },
3257 { PropertyTagTypeShort, 0x100, 2, { 1 } },
3258 { PropertyTagTypeShort, 0x101, 2, { 1 } },
3259 { PropertyTagTypeShort, 0x102, 6, { 8,0,8,0,8,0 } },
3260 { PropertyTagTypeShort, 0x103, 2, { 1 } },
3261 { PropertyTagTypeShort, 0x106, 2, { 2,0 } },
3262 { PropertyTagTypeASCII, 0x10d, 27, "/home/meh/Desktop/test.tif" },
3263 { PropertyTagTypeLong, 0x111, 4, { 8,0,0,0 } },
3264 { PropertyTagTypeShort, 0x112, 2, { 1 } },
3265 { PropertyTagTypeShort, 0x115, 2, { 3,0 } },
3266 { PropertyTagTypeShort, 0x116, 2, { 0x40,0 } },
3267 { PropertyTagTypeLong, 0x117, 4, { 3,0,0,0 } },
3268 { PropertyTagTypeRational, 0x11a, 8, { 0,0,0,72,0,0,0,1 } },
3269 { PropertyTagTypeRational, 0x11b, 8, { 0,0,0,72,0,0,0,1 } },
3270 { PropertyTagTypeShort, 0x11c, 2, { 1 } },
3271 { PropertyTagTypeShort, 0x128, 2, { 2 } }
3272 };
3273 GpStatus status;
3274 GpImage *image;
3275 GUID guid;
3276 UINT dim_count, frame_count, prop_count, prop_size, i;
3277 UINT total_size, total_count;
3278 PROPID *prop_id;
3279 PropertyItem *prop_item;
3280 const char *item_data;
3281
3282 image = load_image(tiffimage, sizeof(tiffimage));
3283 ok(image != 0, "Failed to load TIFF image data\n");
3284 if (!image) return;
3285
3286 dim_count = 0xdeadbeef;
3287 status = GdipImageGetFrameDimensionsCount(image, &dim_count);
3288 expect(Ok, status);
3289 expect(1, dim_count);
3290
3291 status = GdipImageGetFrameDimensionsList(image, &guid, 1);
3292 expect(Ok, status);
3293 expect_guid(&FrameDimensionPage, &guid, __LINE__, FALSE);
3294
3295 frame_count = 0xdeadbeef;
3296 status = GdipImageGetFrameCount(image, &guid, &frame_count);
3297 expect(Ok, status);
3298 expect(1, frame_count);
3299
3300 prop_count = 0xdeadbeef;
3301 status = GdipGetPropertyCount(image, &prop_count);
3302 expect(Ok, status);
3303 ok(prop_count == sizeof(td)/sizeof(td[0]),
3304 "expected property count %u, got %u\n", (UINT)(sizeof(td)/sizeof(td[0])), prop_count);
3305
3306 prop_id = HeapAlloc(GetProcessHeap(), 0, prop_count * sizeof(*prop_id));
3307
3308 status = GdipGetPropertyIdList(image, prop_count, prop_id);
3309 expect(Ok, status);
3310
3311 prop_size = 0;
3312 for (i = 0; i < prop_count; i++)
3313 {
3314 UINT size;
3315 status = GdipGetPropertyItemSize(image, prop_id[i], &size);
3316 expect(Ok, status);
3317 if (status != Ok) break;
3318 ok(size > sizeof(*prop_item), "%u: too small item length %u\n", i, size);
3319
3320 prop_size += size;
3321
3322 prop_item = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
3323 status = GdipGetPropertyItem(image, prop_id[i], size, prop_item);
3324 expect(Ok, status);
3325 ok(prop_item->value == prop_item + 1, "expected item->value %p, got %p\n", prop_item + 1, prop_item->value);
3326 ok(td[i].type == prop_item->type,
3327 "%u: expected type %u, got %u\n", i, td[i].type, prop_item->type);
3328 ok(td[i].id == prop_item->id, "%u: expected id %#x, got %#x\n", i, td[i].id, prop_item->id);
3329 size -= sizeof(*prop_item);
3330 ok(prop_item->length == size, "%u: expected length %u, got %u\n", i, size, prop_item->length);
3331 ok(td[i].length == prop_item->length, "%u: expected length %u, got %u\n", i, td[i].length, prop_item->length);
3332 if (td[i].length == prop_item->length)
3333 {
3334 int match = memcmp(td[i].value, prop_item->value, td[i].length) == 0;
3335 ok(match, "%u: data mismatch\n", i);
3336 if (!match)
3337 {
3338 UINT j;
3339 BYTE *data = prop_item->value;
3340 printf("id %#x:", prop_item->id);
3341 for (j = 0; j < prop_item->length; j++)
3342 printf(" %02x", data[j]);
3343 printf("\n");
3344 }
3345 }
3346 HeapFree(GetProcessHeap(), 0, prop_item);
3347 }
3348
3349 HeapFree(GetProcessHeap(), 0, prop_id);
3350
3351 status = GdipGetPropertySize(NULL, &total_size, &total_count);
3352 expect(InvalidParameter, status);
3353 status = GdipGetPropertySize(image, &total_size, NULL);
3354 expect(InvalidParameter, status);
3355 status = GdipGetPropertySize(image, NULL, &total_count);
3356 expect(InvalidParameter, status);
3357 status = GdipGetPropertySize(image, NULL, NULL);
3358 expect(InvalidParameter, status);
3359 total_size = 0xdeadbeef;
3360 total_count = 0xdeadbeef;
3361 status = GdipGetPropertySize(image, &total_size, &total_count);
3362 expect(Ok, status);
3363 ok(prop_count == total_count,
3364 "expected total property count %u, got %u\n", prop_count, total_count);
3365 ok(prop_size == total_size,
3366 "expected total property size %u, got %u\n", prop_size, total_size);
3367
3368 prop_item = HeapAlloc(GetProcessHeap(), 0, prop_size);
3369
3370 status = GdipGetAllPropertyItems(image, 0, prop_count, prop_item);
3371 expect(InvalidParameter, status);
3372 status = GdipGetAllPropertyItems(image, prop_size, 1, prop_item);
3373 expect(InvalidParameter, status);
3374 status = GdipGetAllPropertyItems(image, prop_size, prop_count, NULL);
3375 expect(InvalidParameter, status);
3376 status = GdipGetAllPropertyItems(image, prop_size, prop_count, NULL);
3377 expect(InvalidParameter, status);
3378 status = GdipGetAllPropertyItems(image, 0, 0, NULL);
3379 expect(InvalidParameter, status);
3380 status = GdipGetAllPropertyItems(image, prop_size + 1, prop_count, prop_item);
3381 expect(InvalidParameter, status);
3382 status = GdipGetAllPropertyItems(image, prop_size, prop_count, prop_item);
3383 expect(Ok, status);
3384
3385 item_data = (const char *)(prop_item + prop_count);
3386 for (i = 0; i < prop_count; i++)
3387 {
3388 ok(prop_item[i].value == item_data, "%u: expected value %p, got %p\n",
3389 i, item_data, prop_item[i].value);
3390 ok(td[i].type == prop_item[i].type,
3391 "%u: expected type %u, got %u\n", i, td[i].type, prop_item[i].type);
3392 ok(td[i].id == prop_item[i].id, "%u: expected id %#x, got %#x\n", i, td[i].id, prop_item[i].id);
3393 ok(td[i].length == prop_item[i].length, "%u: expected length %u, got %u\n", i, td[i].length, prop_item[i].length);
3394 if (td[i].length == prop_item[i].length)
3395 {
3396 int match = memcmp(td[i].value, prop_item[i].value, td[i].length) == 0;
3397 ok(match, "%u: data mismatch\n", i);
3398 if (!match)
3399 {
3400 UINT j;
3401 BYTE *data = prop_item[i].value;
3402 printf("id %#x:", prop_item[i].id);
3403 for (j = 0; j < prop_item[i].length; j++)
3404 printf(" %02x", data[j]);
3405 printf("\n");
3406 }
3407 }
3408 item_data += prop_item[i].length;
3409 }
3410
3411 HeapFree(GetProcessHeap(), 0, prop_item);
3412
3413 GdipDisposeImage(image);
3414 }
3415
3416 static void test_tiff_palette(void)
3417 {
3418 GpStatus status;
3419 GpImage *image;
3420 PixelFormat format;
3421 INT size;
3422 struct
3423 {
3424 ColorPalette pal;
3425 ARGB entry[256];
3426 } palette;
3427 ARGB *entries = palette.pal.Entries;
3428
3429 /* 1bpp TIFF without palette */
3430 image = load_image((const BYTE *)&TIFF_data, sizeof(TIFF_data));
3431 if (!image)
3432 {
3433 win_skip("Failed to load TIFF image data. Might not be supported. Skipping.\n");
3434 return;
3435 }
3436
3437 status = GdipGetImagePixelFormat(image, &format);
3438 expect(Ok, status);
3439 ok(format == PixelFormat1bppIndexed, "expected PixelFormat1bppIndexed, got %#x\n", format);
3440
3441 status = GdipGetImagePaletteSize(image, &size);
3442 ok(status == Ok || broken(status == GenericError), /* XP */
3443 "GdipGetImagePaletteSize error %d\n", status);
3444 if (status == GenericError)
3445 {
3446 GdipDisposeImage(image);
3447 return;
3448 }
3449 expect(sizeof(ColorPalette) + sizeof(ARGB), size);
3450
3451 status = GdipGetImagePalette(image, &palette.pal, size);
3452 expect(Ok, status);
3453 expect(0, palette.pal.Flags);
3454 expect(2, palette.pal.Count);
3455 if (palette.pal.Count == 2)
3456 {
3457 ok(entries[0] == 0xff000000, "expected 0xff000000, got %#x\n", entries[0]);
3458 ok(entries[1] == 0xffffffff, "expected 0xffffffff, got %#x\n", entries[1]);
3459 }
3460
3461 GdipDisposeImage(image);
3462 }
3463
3464 static void test_bitmapbits(void)
3465 {
3466 /* 8 x 2 bitmap */
3467 static const BYTE pixels_24[48] =
3468 {
3469 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3470 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3471 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3472 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0
3473 };
3474 static const BYTE pixels_00[48] =
3475 {
3476 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3477 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3478 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3479 0,0,0, 0,0,0, 0,0,0, 0,0,0
3480 };
3481 static const BYTE pixels_24_77[64] =
3482 {
3483 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3484 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3485 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3486 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3487 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3488 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3489 };
3490 static const BYTE pixels_77[64] =
3491 {
3492 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3493 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3494 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3495 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3496 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3497 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3498 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3499 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3500 };
3501 static const BYTE pixels_8[16] =
3502 {
3503 0x01,0,0x01,0,0x01,0,0x01,0,
3504 0x01,0,0x01,0,0x01,0,0x01,0
3505 };
3506 static const BYTE pixels_8_77[64] =
3507 {
3508 0x01,0,0x01,0,0x01,0,0x01,0,
3509 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3510 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3511 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3512 0x01,0,0x01,0,0x01,0,0x01,0,
3513 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3514 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3515 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3516 };
3517 static const BYTE pixels_1_77[64] =
3518 {
3519 0xaa,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 0xaa,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,
3526 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3527 };
3528 static const BYTE pixels_1[8] = {0xaa,0,0,0,0xaa,0,0,0};
3529 static const struct test_data
3530 {
3531 PixelFormat format;
3532 UINT bpp;
3533 ImageLockMode mode;
3534 UINT stride, size;
3535 const BYTE *pixels;
3536 const BYTE *pixels_unlocked;
3537 } td[] =
3538 {
3539 /* 0 */
3540 { PixelFormat24bppRGB, 24, 0xfff0, 24, 48, pixels_24, pixels_00 },
3541
3542 { PixelFormat24bppRGB, 24, 0, 24, 48, pixels_24, pixels_00 },
3543 { PixelFormat24bppRGB, 24, ImageLockModeRead, 24, 48, pixels_24, pixels_00 },
3544 { PixelFormat24bppRGB, 24, ImageLockModeWrite, 24, 48, pixels_24, pixels_00 },
3545 { PixelFormat24bppRGB, 24, ImageLockModeRead|ImageLockModeWrite, 24, 48, pixels_24, pixels_00 },
3546 { PixelFormat24bppRGB, 24, ImageLockModeRead|ImageLockModeUserInputBuf, 32, 64, pixels_24_77, pixels_24 },
3547 { PixelFormat24bppRGB, 24, ImageLockModeWrite|ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_00 },
3548 { PixelFormat24bppRGB, 24, ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_24 },
3549 /* 8 */
3550 { PixelFormat8bppIndexed, 8, 0, 8, 16, pixels_8, pixels_24 },
3551 { PixelFormat8bppIndexed, 8, ImageLockModeRead, 8, 16, pixels_8, pixels_24 },
3552 { PixelFormat8bppIndexed, 8, ImageLockModeWrite, 8, 16, pixels_8, pixels_00 },
3553 { PixelFormat8bppIndexed, 8, ImageLockModeRead|ImageLockModeWrite, 8, 16, pixels_8, pixels_00 },
3554 { PixelFormat8bppIndexed, 8, ImageLockModeRead|ImageLockModeUserInputBuf, 32, 64, pixels_8_77, pixels_24 },
3555 { PixelFormat8bppIndexed, 8, ImageLockModeWrite|ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_00 },
3556 { PixelFormat8bppIndexed, 8, ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_24 },
3557 /* 15 */
3558 { PixelFormat1bppIndexed, 1, 0, 4, 8, pixels_1, pixels_24 },
3559 { PixelFormat1bppIndexed, 1, ImageLockModeRead, 4, 8, pixels_1, pixels_24 },
3560 { PixelFormat1bppIndexed, 1, ImageLockModeWrite, 4, 8, pixels_1, pixels_00 },
3561 { PixelFormat1bppIndexed, 1, ImageLockModeRead|ImageLockModeWrite, 4, 8, pixels_1, pixels_00 },
3562 { PixelFormat1bppIndexed, 1, ImageLockModeRead|ImageLockModeUserInputBuf, 32, 64, pixels_1_77, pixels_24 },
3563 { PixelFormat1bppIndexed, 1, ImageLockModeWrite|ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_00 },
3564 { PixelFormat1bppIndexed, 1, ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_24 },
3565 };
3566 BYTE buf[64];
3567 GpStatus status;
3568 GpBitmap *bitmap;
3569 UINT i;
3570 BitmapData data;
3571 struct
3572 {
3573 ColorPalette pal;
3574 ARGB entries[1];
3575 } palette;
3576 ARGB *entries = palette.pal.Entries;
3577
3578 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3579 {
3580 BYTE pixels[sizeof(pixels_24)];
3581 memcpy(pixels, pixels_24, sizeof(pixels_24));
3582 status = GdipCreateBitmapFromScan0(8, 2, 24, PixelFormat24bppRGB, pixels, &bitmap);
3583 expect(Ok, status);
3584
3585 /* associate known palette with pixel data */
3586 palette.pal.Flags = PaletteFlagsGrayScale;
3587 palette.pal.Count = 2;
3588 entries[0] = 0xff000000;
3589 entries[1] = 0xffffffff;
3590 status = GdipSetImagePalette((GpImage *)bitmap, &palette.pal);
3591 expect(Ok, status);
3592
3593 memset(&data, 0xfe, sizeof(data));
3594 if (td[i].mode & ImageLockModeUserInputBuf)
3595 {
3596 memset(buf, 0x77, sizeof(buf));
3597 data.Scan0 = buf;
3598 data.Stride = 32;
3599 }
3600 status = GdipBitmapLockBits(bitmap, NULL, td[i].mode, td[i].format, &data);
3601 ok(status == Ok || broken(status == InvalidParameter) /* XP */, "%u: GdipBitmapLockBits error %d\n", i, status);
3602 if (status != Ok)
3603 {
3604 GdipDisposeImage((GpImage *)bitmap);
3605 continue;
3606 }
3607 ok(data.Width == 8, "%u: expected 8, got %d\n", i, data.Width);
3608 ok(data.Height == 2, "%u: expected 2, got %d\n", i, data.Height);
3609 ok(td[i].stride == data.Stride, "%u: expected %d, got %d\n", i, td[i].stride, data.Stride);
3610 ok(td[i].format == data.PixelFormat, "%u: expected %d, got %d\n", i, td[i].format, data.PixelFormat);
3611 ok(td[i].size == data.Height * data.Stride, "%u: expected %d, got %d\n", i, td[i].size, data.Height * data.Stride);
3612 if (td[i].mode & ImageLockModeUserInputBuf)
3613 ok(data.Scan0 == buf, "%u: got wrong buffer\n", i);
3614 if (td[i].size == data.Height * data.Stride)
3615 {
3616 UINT j, match, width_bytes = (data.Width * td[i].bpp) / 8;
3617
3618 match = 1;
3619 for (j = 0; j < data.Height; j++)
3620 {
3621 if (memcmp((const BYTE *)data.Scan0 + j * data.Stride, td[i].pixels + j * data.Stride, width_bytes) != 0)
3622 {
3623 match = 0;
3624 break;
3625 }
3626 }
3627 if ((td[i].mode & (ImageLockModeRead|ImageLockModeUserInputBuf)) || td[i].format == PixelFormat24bppRGB)
3628 {
3629 ok(match,
3630 "%u: data should match\n", i);
3631 if (!match)
3632 {
3633 BYTE *bits = data.Scan0;
3634 printf("%u: data mismatch for format %#x:", i, td[i].format);
3635 for (j = 0; j < td[i].size; j++)
3636 printf(" %02x", bits[j]);
3637 printf("\n");
3638 }
3639 }
3640 else
3641 ok(!match, "%u: data shouldn't match\n", i);
3642
3643 memset(data.Scan0, 0, td[i].size);
3644 }
3645
3646 status = GdipBitmapUnlockBits(bitmap, &data);
3647 ok(status == Ok, "%u: GdipBitmapUnlockBits error %d\n", i, status);
3648
3649 memset(&data, 0xfe, sizeof(data));
3650 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat24bppRGB, &data);
3651 ok(status == Ok, "%u: GdipBitmapLockBits error %d\n", i, status);
3652 ok(data.Width == 8, "%u: expected 8, got %d\n", i, data.Width);
3653 ok(data.Height == 2, "%u: expected 2, got %d\n", i, data.Height);
3654 ok(data.Stride == 24, "%u: expected 24, got %d\n", i, data.Stride);
3655 ok(data.PixelFormat == PixelFormat24bppRGB, "%u: got wrong pixel format %d\n", i, data.PixelFormat);
3656 ok(data.Height * data.Stride == 48, "%u: expected 48, got %d\n", i, data.Height * data.Stride);
3657 if (data.Height * data.Stride == 48)
3658 {
3659 int match = memcmp(data.Scan0, td[i].pixels_unlocked, 48) == 0;
3660 ok(match, "%u: data should match\n", i);
3661 if (!match)
3662 {
3663 UINT j;
3664 BYTE *bits = data.Scan0;
3665 printf("%u: data mismatch for format %#x:", i, td[i].format);
3666 for (j = 0; j < 48; j++)
3667 printf(" %02x", bits[j]);
3668 printf("\n");
3669 }
3670 }
3671
3672 status = GdipBitmapUnlockBits(bitmap, &data);
3673 ok(status == Ok, "%u: GdipBitmapUnlockBits error %d\n", i, status);
3674
3675 status = GdipDisposeImage((GpImage *)bitmap);
3676 expect(Ok, status);
3677 }
3678 }
3679
3680 static void test_DrawImage(void)
3681 {
3682 BYTE black_1x1[4] = { 0,0,0,0 };
3683 BYTE white_2x2[16] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
3684 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
3685 BYTE black_2x2[16] = { 0,0,0,0,0,0,0xff,0xff,
3686 0,0,0,0,0,0,0xff,0xff };
3687 GpStatus status;
3688 union
3689 {
3690 GpBitmap *bitmap;
3691 GpImage *image;
3692 } u1, u2;
3693 GpGraphics *graphics;
3694 int match;
3695
3696 status = GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB, black_1x1, &u1.bitmap);
3697 expect(Ok, status);
3698 status = GdipBitmapSetResolution(u1.bitmap, 100.0, 100.0);
3699 expect(Ok, status);
3700
3701 status = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat24bppRGB, white_2x2, &u2.bitmap);
3702 expect(Ok, status);
3703 status = GdipBitmapSetResolution(u2.bitmap, 300.0, 300.0);
3704 expect(Ok, status);
3705 status = GdipGetImageGraphicsContext(u2.image, &graphics);
3706 expect(Ok, status);
3707 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3708 expect(Ok, status);
3709
3710 status = GdipDrawImageI(graphics, u1.image, 0, 0);
3711 expect(Ok, status);
3712
3713 match = memcmp(white_2x2, black_2x2, sizeof(black_2x2)) == 0;
3714 ok(match, "data should match\n");
3715 if (!match)
3716 {
3717 UINT i, size = sizeof(white_2x2);
3718 BYTE *bits = white_2x2;
3719 for (i = 0; i < size; i++)
3720 printf(" %02x", bits[i]);
3721 printf("\n");
3722 }
3723
3724 status = GdipDeleteGraphics(graphics);
3725 expect(Ok, status);
3726 status = GdipDisposeImage(u1.image);
3727 expect(Ok, status);
3728 status = GdipDisposeImage(u2.image);
3729 expect(Ok, status);
3730 }
3731
3732 static void test_GdipDrawImagePointRect(void)
3733 {
3734 BYTE black_1x1[4] = { 0,0,0,0 };
3735 BYTE white_2x2[16] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
3736 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
3737 BYTE black_2x2[16] = { 0,0,0,0,0,0,0xff,0xff,
3738 0,0,0,0,0,0,0xff,0xff };
3739 GpStatus status;
3740 union
3741 {
3742 GpBitmap *bitmap;
3743 GpImage *image;
3744 } u1, u2;
3745 GpGraphics *graphics;
3746 int match;
3747
3748 status = GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB, black_1x1, &u1.bitmap);
3749 expect(Ok, status);
3750 status = GdipBitmapSetResolution(u1.bitmap, 100.0, 100.0);
3751 expect(Ok, status);
3752
3753 status = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat24bppRGB, white_2x2, &u2.bitmap);
3754 expect(Ok, status);
3755 status = GdipBitmapSetResolution(u2.bitmap, 300.0, 300.0);
3756 expect(Ok, status);
3757 status = GdipGetImageGraphicsContext(u2.image, &graphics);
3758 expect(Ok, status);
3759 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3760 expect(Ok, status);
3761
3762 status = GdipDrawImagePointRectI(graphics, u1.image, 0, 0, 0, 0, 1, 1, UnitPixel);
3763 expect(Ok, status);
3764
3765 match = memcmp(white_2x2, black_2x2, sizeof(black_2x2)) == 0;
3766 ok(match, "data should match\n");
3767 if (!match)
3768 {
3769 UINT i, size = sizeof(white_2x2);
3770 BYTE *bits = white_2x2;
3771 for (i = 0; i < size; i++)
3772 printf(" %02x", bits[i]);
3773 printf("\n");
3774 }
3775
3776 status = GdipDeleteGraphics(graphics);
3777 expect(Ok, status);
3778 status = GdipDisposeImage(u1.image);
3779 expect(Ok, status);
3780 status = GdipDisposeImage(u2.image);
3781 expect(Ok, status);
3782 }
3783
3784 static void test_image_format(void)
3785 {
3786 static const PixelFormat fmt[] =
3787 {
3788 PixelFormat1bppIndexed, PixelFormat4bppIndexed, PixelFormat8bppIndexed,
3789 PixelFormat16bppGrayScale, PixelFormat16bppRGB555, PixelFormat16bppRGB565,
3790 PixelFormat16bppARGB1555, PixelFormat24bppRGB, PixelFormat32bppRGB,
3791 PixelFormat32bppARGB, PixelFormat32bppPARGB, PixelFormat48bppRGB,
3792 PixelFormat64bppARGB, PixelFormat64bppPARGB, PixelFormat32bppCMYK
3793 };
3794 GpStatus status;
3795 GpBitmap *bitmap;
3796 GpImage *thumb;
3797 HBITMAP hbitmap;
3798 BITMAP bm;
3799 PixelFormat format;
3800 BitmapData data;
3801 UINT i, ret;
3802
3803 for (i = 0; i < sizeof(fmt)/sizeof(fmt[0]); i++)
3804 {
3805 status = GdipCreateBitmapFromScan0(1, 1, 0, fmt[i], NULL, &bitmap);
3806 ok(status == Ok || broken(status == InvalidParameter) /* before win7 */,
3807 "GdipCreateBitmapFromScan0 error %d\n", status);
3808 if (status != Ok) continue;
3809
3810 status = GdipGetImagePixelFormat((GpImage *)bitmap, &format);
3811 expect(Ok, status);
3812 expect(fmt[i], format);
3813
3814 status = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
3815 if (fmt[i] == PixelFormat16bppGrayScale || fmt[i] == PixelFormat32bppCMYK)
3816 todo_wine expect(InvalidParameter, status);
3817 else
3818 {
3819 expect(Ok, status);
3820 ret = GetObject(hbitmap, sizeof(bm), &bm);
3821 expect(sizeof(bm), ret);
3822 expect(0, bm.bmType);
3823 expect(1, bm.bmWidth);
3824 expect(1, bm.bmHeight);
3825 expect(4, bm.bmWidthBytes);
3826 expect(1, bm.bmPlanes);
3827 expect(32, bm.bmBitsPixel);
3828 DeleteObject(hbitmap);
3829 }
3830
3831 status = GdipGetImageThumbnail((GpImage *)bitmap, 0, 0, &thumb, NULL, NULL);
3832 if (fmt[i] == PixelFormat16bppGrayScale || fmt[i] == PixelFormat32bppCMYK)
3833 todo_wine
3834 ok(status == OutOfMemory || broken(status == InvalidParameter) /* before win7 */,
3835 "expected OutOfMemory, got %d\n", status);
3836 else
3837 {
3838 expect(Ok, status);
3839 status = GdipGetImagePixelFormat(thumb, &format);
3840 expect(Ok, status);
3841 ok(format == PixelFormat32bppPARGB || broken(format != PixelFormat32bppPARGB) /* before win7 */,
3842 "expected PixelFormat32bppPARGB, got %#x\n", format);
3843 status = GdipDisposeImage(thumb);
3844 expect(Ok, status);
3845 }
3846
3847 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat32bppPARGB, &data);
3848 if (fmt[i] == PixelFormat16bppGrayScale || fmt[i] == PixelFormat32bppCMYK)
3849 todo_wine expect(InvalidParameter, status);
3850 else
3851 {
3852 expect(Ok, status);
3853 status = GdipBitmapUnlockBits(bitmap, &data);
3854 expect(Ok, status);
3855 }
3856
3857 status = GdipDisposeImage((GpImage *)bitmap);
3858 expect(Ok, status);
3859 }
3860 }
3861
3862 static void test_DrawImage_scale(void)
3863 {
3864 static const BYTE back_8x1[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
3865 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3866 static const BYTE image_080[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,
3867 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3868 static const BYTE image_100[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40,
3869 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3870 static const BYTE image_120[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x40,0x40,0x40,
3871 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3872 static const BYTE image_150[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3873 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3874 static const BYTE image_180[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3875 0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3876 static const BYTE image_200[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3877 0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3878 static const BYTE image_250[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,
3879 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40 };
3880 static const BYTE image_120_half[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
3881 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3882 static const BYTE image_150_half[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
3883 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3884 static const BYTE image_200_half[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3885 0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40 };
3886 static const BYTE image_250_half[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3887 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40 };
3888 static const struct test_data
3889 {
3890 REAL scale_x;
3891 PixelOffsetMode pixel_offset_mode;
3892 const BYTE *image;
3893 BOOL todo;
3894 } td[] =
3895 {
3896 { 0.8, PixelOffsetModeNone, image_080 }, /* 0 */
3897 { 1.0, PixelOffsetModeNone, image_100 },
3898 { 1.2, PixelOffsetModeNone, image_120 },
3899 { 1.5, PixelOffsetModeNone, image_150 },
3900 { 1.8, PixelOffsetModeNone, image_180 },
3901 { 2.0, PixelOffsetModeNone, image_200 },
3902 { 2.5, PixelOffsetModeNone, image_250 },
3903
3904 { 0.8, PixelOffsetModeHighSpeed, image_080 }, /* 7 */
3905 { 1.0, PixelOffsetModeHighSpeed, image_100 },
3906 { 1.2, PixelOffsetModeHighSpeed, image_120 },
3907 { 1.5, PixelOffsetModeHighSpeed, image_150 },
3908 { 1.8, PixelOffsetModeHighSpeed, image_180 },
3909 { 2.0, PixelOffsetModeHighSpeed, image_200 },
3910 { 2.5, PixelOffsetModeHighSpeed, image_250 },
3911
3912 { 0.8, PixelOffsetModeHalf, image_080 }, /* 14 */
3913 { 1.0, PixelOffsetModeHalf, image_100 },
3914 { 1.2, PixelOffsetModeHalf, image_120_half, TRUE },
3915 { 1.5, PixelOffsetModeHalf, image_150_half, TRUE },
3916 { 1.8, PixelOffsetModeHalf, image_180 },
3917 { 2.0, PixelOffsetModeHalf, image_200_half, TRUE },
3918 { 2.5, PixelOffsetModeHalf, image_250_half, TRUE },
3919
3920 { 0.8, PixelOffsetModeHighQuality, image_080 }, /* 21 */
3921 { 1.0, PixelOffsetModeHighQuality, image_100 },
3922 { 1.2, PixelOffsetModeHighQuality, image_120_half, TRUE },
3923 { 1.5, PixelOffsetModeHighQuality, image_150_half, TRUE },
3924 { 1.8, PixelOffsetModeHighQuality, image_180 },
3925 { 2.0, PixelOffsetModeHighQuality, image_200_half, TRUE },
3926 { 2.5, PixelOffsetModeHighQuality, image_250_half, TRUE },
3927 };
3928 BYTE src_2x1[6] = { 0x80,0x80,0x80,0x80,0x80,0x80 };
3929 BYTE dst_8x1[24];
3930 GpStatus status;
3931 union
3932 {
3933 GpBitmap *bitmap;
3934 GpImage *image;
3935 } u1, u2;
3936 GpGraphics *graphics;
3937 GpMatrix *matrix;
3938 int i, match;
3939
3940 status = GdipCreateBitmapFromScan0(2, 1, 4, PixelFormat24bppRGB, src_2x1, &u1.bitmap);
3941 expect(Ok, status);
3942 status = GdipBitmapSetResolution(u1.bitmap, 100.0, 100.0);
3943 expect(Ok, status);
3944
3945 status = GdipCreateBitmapFromScan0(8, 1, 24, PixelFormat24bppRGB, dst_8x1, &u2.bitmap);
3946 expect(Ok, status);
3947 status = GdipBitmapSetResolution(u2.bitmap, 100.0, 100.0);
3948 expect(Ok, status);
3949 status = GdipGetImageGraphicsContext(u2.image, &graphics);
3950 expect(Ok, status);
3951 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3952 expect(Ok, status);
3953
3954 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3955 {
3956 status = GdipSetPixelOffsetMode(graphics, td[i].pixel_offset_mode);
3957 expect(Ok, status);
3958
3959 status = GdipCreateMatrix2(td[i].scale_x, 0.0, 0.0, 1.0, 0.0, 0.0, &matrix);
3960 expect(Ok, status);
3961 status = GdipSetWorldTransform(graphics, matrix);
3962 expect(Ok, status);
3963 GdipDeleteMatrix(matrix);
3964
3965 memcpy(dst_8x1, back_8x1, sizeof(dst_8x1));
3966 status = GdipDrawImageI(graphics, u1.image, 1, 0);
3967 expect(Ok, status);
3968
3969 match = memcmp(dst_8x1, td[i].image, sizeof(dst_8x1)) == 0;
3970 if (!match && td[i].todo)
3971 todo_wine ok(match, "%d: data should match\n", i);
3972 else
3973 ok(match, "%d: data should match\n", i);
3974 if (!match)
3975 {
3976 UINT i, size = sizeof(dst_8x1);
3977 const BYTE *bits = dst_8x1;
3978 for (i = 0; i < size; i++)
3979 printf(" %02x", bits[i]);
3980 printf("\n");
3981 }
3982 }
3983
3984 status = GdipDeleteGraphics(graphics);
3985 expect(Ok, status);
3986 status = GdipDisposeImage(u1.image);
3987 expect(Ok, status);
3988 status = GdipDisposeImage(u2.image);
3989 expect(Ok, status);
3990 }
3991
3992 static const BYTE animatedgif[] = {
3993 'G','I','F','8','9','a',0x01,0x00,0x01,0x00,0xA1,0x02,0x00,
3994 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,
3995 /*0x21,0xFF,0x0B,'A','N','I','M','E','X','T','S','1','.','0',*/
3996 0x21,0xFF,0x0B,'N','E','T','S','C','A','P','E','2','.','0',
3997 0x03,0x01,0x05,0x00,0x00,
3998 0x21,0xFE,0x0C,'H','e','l','l','o',' ','W','o','r','l','d','!',0x00,
3999 0x21,0x01,0x0D,'a','n','i','m','a','t','i','o','n','.','g','i','f',0x00,
4000 0x21,0xF9,0x04,0xff,0x0A,0x00,0x08,0x00,
4001 0x2C,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
4002 0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,
4003 0x02,0x02,0x4C,0x01,0x00,
4004 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','1',0x00,
4005 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','1',0x00,
4006 0x21,0xF9,0x04,0x00,0x14,0x00,0x01,0x00,
4007 0x2C,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
4008 0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,
4009 0x02,0x02,0x44,0x01,0x00,
4010 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','2',0x00,
4011 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','2',0x00,0x3B
4012 };
4013
4014 static void test_gif_properties(void)
4015 {
4016 static const struct test_data
4017 {
4018 ULONG type, id, length;
4019 const BYTE value[13];
4020 } td[] =
4021 {
4022 { PropertyTagTypeLong, PropertyTagFrameDelay, 8, { 10,0,0,0,20,0,0,0 } },
4023 { PropertyTagTypeASCII, PropertyTagExifUserComment, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
4024 { PropertyTagTypeShort, PropertyTagLoopCount, 2, { 5,0 } },
4025 { PropertyTagTypeByte, PropertyTagGlobalPalette, 12, { 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c } },
4026 { PropertyTagTypeByte, PropertyTagIndexBackground, 1, { 2 } },
4027 { PropertyTagTypeByte, PropertyTagIndexTransparent, 1, { 8 } }
4028 };
4029 GpStatus status;
4030 GpImage *image;
4031 GUID guid;
4032 UINT dim_count, frame_count, prop_count, prop_size, i;
4033 UINT total_size, total_count;
4034 PROPID *prop_id;
4035 PropertyItem *prop_item;
4036 const char *item_data;
4037
4038 image = load_image(animatedgif, sizeof(animatedgif));
4039 if (!image) /* XP fails to load this GIF image */
4040 {
4041 trace("Failed to load GIF image data\n");
4042 return;
4043 }
4044
4045 status = GdipImageGetFrameDimensionsCount(image, &dim_count);
4046 expect(Ok, status);
4047 expect(1, dim_count);
4048
4049 status = GdipImageGetFrameDimensionsList(image, &guid, 1);
4050 expect(Ok, status);
4051 expect_guid(&FrameDimensionTime, &guid, __LINE__, FALSE);
4052
4053 status = GdipImageGetFrameCount(image, &guid, &frame_count);
4054 expect(Ok, status);
4055 expect(2, frame_count);
4056
4057 status = GdipImageSelectActiveFrame(image, &guid, 1);
4058 expect(Ok, status);
4059
4060 status = GdipGetPropertyCount(image, &prop_count);
4061 expect(Ok, status);
4062 ok(prop_count == sizeof(td)/sizeof(td[0]) || broken(prop_count == 1) /* before win7 */,
4063 "expected property count %u, got %u\n", (UINT)(sizeof(td)/sizeof(td[0])), prop_count);
4064
4065 if (prop_count != sizeof(td)/sizeof(td[0]))
4066 {
4067 GdipDisposeImage(image);
4068 return;
4069 }
4070
4071 prop_id = HeapAlloc(GetProcessHeap(), 0, prop_count * sizeof(*prop_id));
4072
4073 status = GdipGetPropertyIdList(image, prop_count, prop_id);
4074 expect(Ok, status);
4075
4076 prop_size = 0;
4077 for (i = 0; i < prop_count; i++)
4078 {
4079 UINT size;
4080 status = GdipGetPropertyItemSize(image, prop_id[i], &size);
4081 expect(Ok, status);
4082 if (status != Ok) break;
4083 ok(size > sizeof(*prop_item), "%u: too small item length %u\n", i, size);
4084
4085 prop_size += size;
4086
4087 prop_item = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
4088 status = GdipGetPropertyItem(image, prop_id[i], size, prop_item);
4089 expect(Ok, status);
4090 ok(prop_item->value == prop_item + 1, "expected item->value %p, got %p\n", prop_item + 1, prop_item->value);
4091 ok(td[i].type == prop_item->type,
4092 "%u: expected type %u, got %u\n", i, td[i].type, prop_item->type);
4093 ok(td[i].id == prop_item->id, "%u: expected id %#x, got %#x\n", i, td[i].id, prop_item->id);
4094 size -= sizeof(*prop_item);
4095 ok(prop_item->length == size, "%u: expected length %u, got %u\n", i, size, prop_item->length);
4096 ok(td[i].length == prop_item->length, "%u: expected length %u, got %u\n", i, td[i].length, prop_item->length);
4097 if (td[i].length == prop_item->length)
4098 {
4099 int match = memcmp(td[i].value, prop_item->value, td[i].length) == 0;
4100 ok(match, "%u: data mismatch\n", i);
4101 if (!match)
4102 {
4103 UINT j;
4104 BYTE *data = prop_item->value;
4105 printf("id %#x:", prop_item->id);
4106 for (j = 0; j < prop_item->length; j++)
4107 printf(" %02x", data[j]);
4108 printf("\n");
4109 }
4110 }
4111 HeapFree(GetProcessHeap(), 0, prop_item);
4112 }
4113
4114 HeapFree(GetProcessHeap(), 0, prop_id);
4115
4116 status = GdipGetPropertySize(NULL, &total_size, &total_count);
4117 expect(InvalidParameter, status);
4118 status = GdipGetPropertySize(image, &total_size, NULL);
4119 expect(InvalidParameter, status);
4120 status = GdipGetPropertySize(image, NULL, &total_count);
4121 expect(InvalidParameter, status);
4122 status = GdipGetPropertySize(image, NULL, NULL);
4123 expect(InvalidParameter, status);
4124 total_size = 0xdeadbeef;
4125 total_count = 0xdeadbeef;
4126 status = GdipGetPropertySize(image, &total_size, &total_count);
4127 expect(Ok, status);
4128 ok(prop_count == total_count,
4129 "expected total property count %u, got %u\n", prop_count, total_count);
4130 ok(prop_size == total_size,
4131 "expected total property size %u, got %u\n", prop_size, total_size);
4132
4133 prop_item = HeapAlloc(GetProcessHeap(), 0, prop_size);
4134
4135 status = GdipGetAllPropertyItems(image, 0, prop_count, prop_item);
4136 expect(InvalidParameter, status);
4137 status = GdipGetAllPropertyItems(image, prop_size, 1, prop_item);
4138 expect(InvalidParameter, status);
4139 status = GdipGetAllPropertyItems(image, prop_size, prop_count, NULL);
4140 expect(InvalidParameter, status);
4141 status = GdipGetAllPropertyItems(image, prop_size, prop_count, NULL);
4142 expect(InvalidParameter, status);
4143 status = GdipGetAllPropertyItems(image, 0, 0, NULL);
4144 expect(InvalidParameter, status);
4145 status = GdipGetAllPropertyItems(image, prop_size + 1, prop_count, prop_item);
4146 expect(InvalidParameter, status);
4147 status = GdipGetAllPropertyItems(image, prop_size, prop_count, prop_item);
4148 expect(Ok, status);
4149
4150 item_data = (const char *)(prop_item + prop_count);
4151 for (i = 0; i < prop_count; i++)
4152 {
4153 ok(prop_item[i].value == item_data, "%u: expected value %p, got %p\n",
4154 i, item_data, prop_item[i].value);
4155 ok(td[i].type == prop_item[i].type,
4156 "%u: expected type %u, got %u\n", i, td[i].type, prop_item[i].type);
4157 ok(td[i].id == prop_item[i].id, "%u: expected id %#x, got %#x\n", i, td[i].id, prop_item[i].id);
4158 ok(td[i].length == prop_item[i].length, "%u: expected length %u, got %u\n", i, td[i].length, prop_item[i].length);
4159 if (td[i].length == prop_item[i].length)
4160 {
4161 int match = memcmp(td[i].value, prop_item[i].value, td[i].length) == 0;
4162 ok(match, "%u: data mismatch\n", i);
4163 if (!match)
4164 {
4165 UINT j;
4166 BYTE *data = prop_item[i].value;
4167 printf("id %#x:", prop_item[i].id);
4168 for (j = 0; j < prop_item[i].length; j++)
4169 printf(" %02x", data[j]);
4170 printf("\n");
4171 }
4172 }
4173 item_data += prop_item[i].length;
4174 }
4175
4176 HeapFree(GetProcessHeap(), 0, prop_item);
4177
4178 GdipDisposeImage(image);
4179 }
4180
4181 static void test_ARGB_conversion(void)
4182 {
4183 BYTE argb[8] = { 0x11,0x22,0x33,0x80, 0xff,0xff,0xff,0 };
4184 BYTE pargb[8] = { 0x09,0x11,0x1a,0x80, 0,0,0,0 };
4185 BYTE rgb32_xp[8] = { 0x11,0x22,0x33,0xff, 0xff,0xff,0xff,0xff };
4186 BYTE rgb24[6] = { 0x11,0x22,0x33, 0xff,0xff,0xff };
4187 BYTE *bits;
4188 GpBitmap *bitmap;
4189 BitmapData data;
4190 GpStatus status;
4191 int match;
4192
4193 status = GdipCreateBitmapFromScan0(2, 1, 8, PixelFormat32bppARGB, argb, &bitmap);
4194 expect(Ok, status);
4195
4196 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat32bppPARGB, &data);
4197 expect(Ok, status);
4198 ok(data.Width == 2, "expected 2, got %d\n", data.Width);
4199 ok(data.Height == 1, "expected 1, got %d\n", data.Height);
4200 ok(data.Stride == 8, "expected 8, got %d\n", data.Stride);
4201 ok(data.PixelFormat == PixelFormat32bppPARGB, "expected PixelFormat32bppPARGB, got %d\n", data.PixelFormat);
4202 match = !memcmp(data.Scan0, pargb, sizeof(pargb));
4203 ok(match, "bits don't match\n");
4204 if (!match)
4205 {
4206 bits = data.Scan0;
4207 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat32bppPARGB,
4208 bits[0], bits[1], bits[2], bits[3], bits[4], bits[5], bits[6], bits[7]);
4209 }
4210 status = GdipBitmapUnlockBits(bitmap, &data);
4211 expect(Ok, status);
4212
4213 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat32bppRGB, &data);
4214 expect(Ok, status);
4215 ok(data.Width == 2, "expected 2, got %d\n", data.Width);
4216 ok(data.Height == 1, "expected 1, got %d\n", data.Height);
4217 ok(data.Stride == 8, "expected 8, got %d\n", data.Stride);
4218 ok(data.PixelFormat == PixelFormat32bppRGB, "expected PixelFormat32bppRGB, got %d\n", data.PixelFormat);
4219 match = !memcmp(data.Scan0, argb, sizeof(argb)) ||
4220 !memcmp(data.Scan0, rgb32_xp, sizeof(rgb32_xp));
4221 ok(match, "bits don't match\n");
4222 if (!match)
4223 {
4224 bits = data.Scan0;
4225 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat32bppRGB,
4226 bits[0], bits[1], bits[2], bits[3], bits[4], bits[5], bits[6], bits[7]);
4227 }
4228 status = GdipBitmapUnlockBits(bitmap, &data);
4229 expect(Ok, status);
4230
4231 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat24bppRGB, &data);
4232 expect(Ok, status);
4233 ok(data.Width == 2, "expected 2, got %d\n", data.Width);
4234 ok(data.Height == 1, "expected 1, got %d\n", data.Height);
4235 ok(data.Stride == 8, "expected 8, got %d\n", data.Stride);
4236 ok(data.PixelFormat == PixelFormat24bppRGB, "expected PixelFormat24bppRGB, got %d\n", data.PixelFormat);
4237 match = !memcmp(data.Scan0, rgb24, sizeof(rgb24));
4238 ok(match, "bits don't match\n");
4239 if (!match)
4240 {
4241 bits = data.Scan0;
4242 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat24bppRGB,
4243 bits[0], bits[1], bits[2], bits[3], bits[4], bits[5], bits[6], bits[7]);
4244 }
4245 status = GdipBitmapUnlockBits(bitmap, &data);
4246 expect(Ok, status);
4247
4248 GdipDisposeImage((GpImage *)bitmap);
4249 }
4250
4251 START_TEST(image)
4252 {
4253 struct GdiplusStartupInput gdiplusStartupInput;
4254 ULONG_PTR gdiplusToken;
4255
4256 gdiplusStartupInput.GdiplusVersion = 1;
4257 gdiplusStartupInput.DebugEventCallback = NULL;
4258 gdiplusStartupInput.SuppressBackgroundThread = 0;
4259 gdiplusStartupInput.SuppressExternalCodecs = 0;
4260
4261 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
4262
4263 test_ARGB_conversion();
4264 test_DrawImage_scale();
4265 test_image_format();
4266 test_DrawImage();
4267 test_GdipDrawImagePointRect();
4268 test_bitmapbits();
4269 test_tiff_palette();
4270 test_GdipGetAllPropertyItems();
4271 test_tiff_properties();
4272 test_gif_properties();
4273 test_image_properties();
4274 test_Scan0();
4275 test_FromGdiDib();
4276 test_GetImageDimension();
4277 test_GdipImageGetFrameDimensionsCount();
4278 test_LoadingImages();
4279 test_SavingImages();
4280 test_encoders();
4281 test_LockBits();
4282 test_LockBits_UserBuf();
4283 test_GdipCreateBitmapFromHBITMAP();
4284 test_GdipGetImageFlags();
4285 test_GdipCloneImage();
4286 test_testcontrol();
4287 test_fromhicon();
4288 test_getrawformat();
4289 test_loadwmf();
4290 test_createfromwmf();
4291 test_resolution();
4292 test_createhbitmap();
4293 test_getthumbnail();
4294 test_getsetpixel();
4295 test_palette();
4296 test_colormatrix();
4297 test_gamma();
4298 test_multiframegif();
4299 test_rotateflip();
4300 test_remaptable();
4301 test_colorkey();
4302 test_dispose();
4303
4304 GdiplusShutdown(gdiplusToken);
4305 }