[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 GdipDeleteGraphics(graphics);
2223 GdipDisposeImage((GpImage*)bitmap1);
2224 GdipDisposeImage((GpImage*)bitmap2);
2225 GdipDisposeImageAttributes(imageattr);
2226 }
2227
2228 static void test_gamma(void)
2229 {
2230 GpStatus stat;
2231 GpImageAttributes *imageattr;
2232 GpBitmap *bitmap1, *bitmap2;
2233 GpGraphics *graphics;
2234 ARGB color;
2235
2236 stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
2237 expect(InvalidParameter, stat);
2238
2239 stat = GdipCreateImageAttributes(&imageattr);
2240 expect(Ok, stat);
2241
2242 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
2243 expect(Ok, stat);
2244
2245 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
2246 expect(InvalidParameter, stat);
2247
2248 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
2249 expect(InvalidParameter, stat);
2250
2251 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
2252 expect(InvalidParameter, stat);
2253
2254 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
2255 expect(Ok, stat);
2256
2257 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
2258 expect(Ok, stat);
2259
2260 /* Drawing a bitmap transforms the colors */
2261 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
2262 expect(Ok, stat);
2263
2264 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
2265 expect(Ok, stat);
2266
2267 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
2268 expect(Ok, stat);
2269
2270 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
2271 expect(Ok, stat);
2272
2273 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2274 expect(Ok, stat);
2275
2276 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2277 UnitPixel, imageattr, NULL, NULL);
2278 expect(Ok, stat);
2279
2280 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2281 expect(Ok, stat);
2282 ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
2283
2284 GdipDeleteGraphics(graphics);
2285 GdipDisposeImage((GpImage*)bitmap1);
2286 GdipDisposeImage((GpImage*)bitmap2);
2287 GdipDisposeImageAttributes(imageattr);
2288 }
2289
2290 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
2291 static const unsigned char gifanimation[72] = {
2292 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
2293 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
2294 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
2295 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
2296 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
2297 };
2298
2299 static void test_multiframegif(void)
2300 {
2301 LPSTREAM stream;
2302 HGLOBAL hglob;
2303 LPBYTE data;
2304 HRESULT hres;
2305 GpStatus stat;
2306 GpBitmap *bmp;
2307 ARGB color;
2308 UINT count;
2309 GUID dimension;
2310
2311 /* Test frame functions with an animated GIF */
2312 hglob = GlobalAlloc (0, sizeof(gifanimation));
2313 data = GlobalLock (hglob);
2314 memcpy(data, gifanimation, sizeof(gifanimation));
2315 GlobalUnlock(hglob);
2316
2317 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
2318 ok(hres == S_OK, "Failed to create a stream\n");
2319 if(hres != S_OK) return;
2320
2321 stat = GdipCreateBitmapFromStream(stream, &bmp);
2322 ok(stat == Ok, "Failed to create a Bitmap\n");
2323 if(stat != Ok){
2324 IStream_Release(stream);
2325 return;
2326 }
2327
2328 /* Bitmap starts at frame 0 */
2329 color = 0xdeadbeef;
2330 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2331 expect(Ok, stat);
2332 expect(0xffffffff, color);
2333
2334 /* Check that we get correct metadata */
2335 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
2336 expect(Ok, stat);
2337 expect(1, count);
2338
2339 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
2340 expect(Ok, stat);
2341 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
2342
2343 count = 12345;
2344 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2345 expect(Ok, stat);
2346 expect(2, count);
2347
2348 /* SelectActiveFrame overwrites our current data */
2349 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
2350 expect(Ok, stat);
2351
2352 color = 0xdeadbeef;
2353 GdipBitmapGetPixel(bmp, 0, 0, &color);
2354 expect(Ok, stat);
2355 expect(0xff000000, color);
2356
2357 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2358 expect(Ok, stat);
2359
2360 color = 0xdeadbeef;
2361 GdipBitmapGetPixel(bmp, 0, 0, &color);
2362 expect(Ok, stat);
2363 expect(0xffffffff, color);
2364
2365 /* Write over the image data */
2366 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
2367 expect(Ok, stat);
2368
2369 /* Switching to the same frame does not overwrite our changes */
2370 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2371 expect(Ok, stat);
2372
2373 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2374 expect(Ok, stat);
2375 expect(0xff000000, color);
2376
2377 /* But switching to another frame and back does */
2378 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
2379 expect(Ok, stat);
2380
2381 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2382 expect(Ok, stat);
2383
2384 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2385 expect(Ok, stat);
2386 expect(0xffffffff, color);
2387
2388 /* rotate/flip discards the information about other frames */
2389 stat = GdipImageRotateFlip((GpImage*)bmp, Rotate90FlipNone);
2390 expect(Ok, stat);
2391
2392 count = 12345;
2393 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2394 expect(Ok, stat);
2395 expect(1, count);
2396
2397 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bmp, __LINE__, FALSE);
2398
2399 GdipDisposeImage((GpImage*)bmp);
2400 IStream_Release(stream);
2401
2402 /* Test with a non-animated gif */
2403 hglob = GlobalAlloc (0, sizeof(gifimage));
2404 data = GlobalLock (hglob);
2405 memcpy(data, gifimage, sizeof(gifimage));
2406 GlobalUnlock(hglob);
2407
2408 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
2409 ok(hres == S_OK, "Failed to create a stream\n");
2410 if(hres != S_OK) return;
2411
2412 stat = GdipCreateBitmapFromStream(stream, &bmp);
2413 ok(stat == Ok, "Failed to create a Bitmap\n");
2414 if(stat != Ok){
2415 IStream_Release(stream);
2416 return;
2417 }
2418
2419 /* Check metadata */
2420 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
2421 expect(Ok, stat);
2422 expect(1, count);
2423
2424 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
2425 expect(Ok, stat);
2426 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
2427
2428 count = 12345;
2429 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2430 expect(Ok, stat);
2431 expect(1, count);
2432
2433 GdipDisposeImage((GpImage*)bmp);
2434 IStream_Release(stream);
2435 }
2436
2437 static void test_rotateflip(void)
2438 {
2439 GpImage *bitmap;
2440 GpStatus stat;
2441 BYTE bits[24];
2442 static const BYTE orig_bits[24] = {
2443 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
2444 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
2445 UINT width, height;
2446 ARGB color;
2447
2448 memcpy(bits, orig_bits, sizeof(bits));
2449 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2450 expect(Ok, stat);
2451
2452 stat = GdipImageRotateFlip(bitmap, Rotate90FlipNone);
2453 expect(Ok, stat);
2454
2455 stat = GdipGetImageWidth(bitmap, &width);
2456 expect(Ok, stat);
2457 stat = GdipGetImageHeight(bitmap, &height);
2458 expect(Ok, stat);
2459 expect(2, width);
2460 expect(3, height);
2461
2462 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2463 expect(Ok, stat);
2464 expect(0xff00ffff, color);
2465
2466 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 0, &color);
2467 expect(Ok, stat);
2468 expect(0xffff0000, color);
2469
2470 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 2, &color);
2471 expect(Ok, stat);
2472 expect(0xffffff00, color);
2473
2474 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 2, &color);
2475 expect(Ok, stat);
2476 expect(0xff0000ff, color);
2477
2478 expect(0, bits[0]);
2479 expect(0, bits[1]);
2480 expect(0xff, bits[2]);
2481
2482 GdipDisposeImage(bitmap);
2483
2484 memcpy(bits, orig_bits, sizeof(bits));
2485 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2486 expect(Ok, stat);
2487
2488 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipX);
2489 expect(Ok, stat);
2490
2491 stat = GdipGetImageWidth(bitmap, &width);
2492 expect(Ok, stat);
2493 stat = GdipGetImageHeight(bitmap, &height);
2494 expect(Ok, stat);
2495 expect(3, width);
2496 expect(2, height);
2497
2498 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2499 expect(Ok, stat);
2500 expect(0xff0000ff, color);
2501
2502 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2503 expect(Ok, stat);
2504 expect(0xffff0000, color);
2505
2506 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2507 expect(Ok, stat);
2508 expect(0xffffff00, color);
2509
2510 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2511 expect(Ok, stat);
2512 expect(0xff00ffff, color);
2513
2514 expect(0, bits[0]);
2515 expect(0, bits[1]);
2516 expect(0xff, bits[2]);
2517
2518 GdipDisposeImage(bitmap);
2519
2520 memcpy(bits, orig_bits, sizeof(bits));
2521 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2522 expect(Ok, stat);
2523
2524 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipY);
2525 expect(Ok, stat);
2526
2527 stat = GdipGetImageWidth(bitmap, &width);
2528 expect(Ok, stat);
2529 stat = GdipGetImageHeight(bitmap, &height);
2530 expect(Ok, stat);
2531 expect(3, width);
2532 expect(2, height);
2533
2534 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2535 expect(Ok, stat);
2536 expect(0xff00ffff, color);
2537
2538 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2539 expect(Ok, stat);
2540 expect(0xffffff00, color);
2541
2542 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2543 expect(Ok, stat);
2544 expect(0xffff0000, color);
2545
2546 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2547 expect(Ok, stat);
2548 expect(0xff0000ff, color);
2549
2550 expect(0, bits[0]);
2551 expect(0, bits[1]);
2552 expect(0xff, bits[2]);
2553
2554 GdipDisposeImage(bitmap);
2555 }
2556
2557 static void test_remaptable(void)
2558 {
2559 GpStatus stat;
2560 GpImageAttributes *imageattr;
2561 GpBitmap *bitmap1, *bitmap2;
2562 GpGraphics *graphics;
2563 ARGB color;
2564 ColorMap *map;
2565
2566 map = GdipAlloc(sizeof(ColorMap));
2567
2568 map->oldColor.Argb = 0xff00ff00;
2569 map->newColor.Argb = 0xffff00ff;
2570
2571 stat = GdipSetImageAttributesRemapTable(NULL, ColorAdjustTypeDefault, TRUE, 1, map);
2572 expect(InvalidParameter, stat);
2573
2574 stat = GdipCreateImageAttributes(&imageattr);
2575 expect(Ok, stat);
2576
2577 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, NULL);
2578 expect(InvalidParameter, stat);
2579
2580 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeCount, TRUE, 1, map);
2581 expect(InvalidParameter, stat);
2582
2583 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeAny, TRUE, 1, map);
2584 expect(InvalidParameter, stat);
2585
2586 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 0, map);
2587 expect(InvalidParameter, stat);
2588
2589 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, FALSE, 0, NULL);
2590 expect(Ok, stat);
2591
2592 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, map);
2593 expect(Ok, stat);
2594
2595 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
2596 expect(Ok, stat);
2597
2598 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
2599 expect(Ok, stat);
2600
2601 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff00ff00);
2602 expect(Ok, stat);
2603
2604 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2605 expect(Ok, stat);
2606
2607 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2608 UnitPixel, imageattr, NULL, NULL);
2609 expect(Ok, stat);
2610
2611 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2612 expect(Ok, stat);
2613 ok(color_match(0xffff00ff, color, 1), "Expected ffff00ff, got %.8x\n", color);
2614
2615 GdipDeleteGraphics(graphics);
2616 GdipDisposeImage((GpImage*)bitmap1);
2617 GdipDisposeImage((GpImage*)bitmap2);
2618 GdipDisposeImageAttributes(imageattr);
2619 GdipFree(map);
2620 }
2621
2622 static void test_colorkey(void)
2623 {
2624 GpStatus stat;
2625 GpImageAttributes *imageattr;
2626 GpBitmap *bitmap1, *bitmap2;
2627 GpGraphics *graphics;
2628 ARGB color;
2629
2630 stat = GdipSetImageAttributesColorKeys(NULL, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2631 expect(InvalidParameter, stat);
2632
2633 stat = GdipCreateImageAttributes(&imageattr);
2634 expect(Ok, stat);
2635
2636 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeCount, TRUE, 0xff405060, 0xff708090);
2637 expect(InvalidParameter, stat);
2638
2639 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeAny, TRUE, 0xff405060, 0xff708090);
2640 expect(InvalidParameter, stat);
2641
2642 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2643 expect(Ok, stat);
2644
2645 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap1);
2646 expect(Ok, stat);
2647
2648 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap2);
2649 expect(Ok, stat);
2650
2651 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0x20405060);
2652 expect(Ok, stat);
2653
2654 stat = GdipBitmapSetPixel(bitmap1, 0, 1, 0x40506070);
2655 expect(Ok, stat);
2656
2657 stat = GdipBitmapSetPixel(bitmap1, 1, 0, 0x60708090);
2658 expect(Ok, stat);
2659
2660 stat = GdipBitmapSetPixel(bitmap1, 1, 1, 0xffffffff);
2661 expect(Ok, stat);
2662
2663 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2664 expect(Ok, stat);
2665
2666 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,2,2, 0,0,2,2,
2667 UnitPixel, imageattr, NULL, NULL);
2668 expect(Ok, stat);
2669
2670 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2671 expect(Ok, stat);
2672 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2673
2674 stat = GdipBitmapGetPixel(bitmap2, 0, 1, &color);
2675 expect(Ok, stat);
2676 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2677
2678 stat = GdipBitmapGetPixel(bitmap2, 1, 0, &color);
2679 expect(Ok, stat);
2680 ok(color_match(0x00000000, color, 1), "Expected ffff00ff, got %.8x\n", color);
2681
2682 stat = GdipBitmapGetPixel(bitmap2, 1, 1, &color);
2683 expect(Ok, stat);
2684 ok(color_match(0xffffffff, color, 1), "Expected ffff00ff, got %.8x\n", color);
2685
2686 GdipDeleteGraphics(graphics);
2687 GdipDisposeImage((GpImage*)bitmap1);
2688 GdipDisposeImage((GpImage*)bitmap2);
2689 GdipDisposeImageAttributes(imageattr);
2690 }
2691
2692 static void test_dispose(void)
2693 {
2694 GpStatus stat;
2695 GpImage *image;
2696 char invalid_image[256];
2697
2698 stat = GdipDisposeImage(NULL);
2699 expect(InvalidParameter, stat);
2700
2701 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, (GpBitmap**)&image);
2702 expect(Ok, stat);
2703
2704 stat = GdipDisposeImage(image);
2705 expect(Ok, stat);
2706
2707 stat = GdipDisposeImage(image);
2708 expect(ObjectBusy, stat);
2709
2710 memset(invalid_image, 0, 256);
2711 stat = GdipDisposeImage((GpImage*)invalid_image);
2712 expect(ObjectBusy, stat);
2713 }
2714
2715 static LONG obj_refcount(void *obj)
2716 {
2717 IUnknown_AddRef((IUnknown *)obj);
2718 return IUnknown_Release((IUnknown *)obj);
2719 }
2720
2721 static GpImage *load_image(const BYTE *image_data, UINT image_size)
2722 {
2723 IStream *stream;
2724 HGLOBAL hmem;
2725 BYTE *data;
2726 HRESULT hr;
2727 GpStatus status;
2728 GpImage *image = NULL, *clone;
2729 ImageType image_type;
2730 LONG refcount, old_refcount;
2731
2732 hmem = GlobalAlloc(0, image_size);
2733 data = GlobalLock(hmem);
2734 memcpy(data, image_data, image_size);
2735 GlobalUnlock(hmem);
2736
2737 hr = CreateStreamOnHGlobal(hmem, TRUE, &stream);
2738 ok(hr == S_OK, "CreateStreamOnHGlobal error %#x\n", hr);
2739 if (hr != S_OK) return NULL;
2740
2741 refcount = obj_refcount(stream);
2742 ok(refcount == 1, "expected stream refcount 1, got %d\n", refcount);
2743
2744 status = GdipLoadImageFromStream(stream, &image);
2745 ok(status == Ok || broken(status == InvalidParameter), /* XP */
2746 "GdipLoadImageFromStream error %d\n", status);
2747 if (status != Ok)
2748 {
2749 IStream_Release(stream);
2750 return NULL;
2751 }
2752
2753 status = GdipGetImageType(image, &image_type);
2754 ok(status == Ok, "GdipGetImageType error %d\n", status);
2755
2756 refcount = obj_refcount(stream);
2757 if (image_type == ImageTypeBitmap)
2758 ok(refcount > 1, "expected stream refcount > 1, got %d\n", refcount);
2759 else
2760 ok(refcount == 1, "expected stream refcount 1, got %d\n", refcount);
2761 old_refcount = refcount;
2762
2763 status = GdipCloneImage(image, &clone);
2764 ok(status == Ok, "GdipCloneImage error %d\n", status);
2765 refcount = obj_refcount(stream);
2766 ok(refcount == old_refcount, "expected stream refcount %d, got %d\n", old_refcount, refcount);
2767 status = GdipDisposeImage(clone);
2768 ok(status == Ok, "GdipDisposeImage error %d\n", status);
2769 refcount = obj_refcount(stream);
2770 ok(refcount == old_refcount, "expected stream refcount %d, got %d\n", old_refcount, refcount);
2771
2772 refcount = IStream_Release(stream);
2773 if (image_type == ImageTypeBitmap)
2774 ok(refcount >= 1, "expected stream refcount != 0\n");
2775 else
2776 ok(refcount == 0, "expected stream refcount 0, got %d\n", refcount);
2777
2778 return image;
2779 }
2780
2781 static void test_image_properties(void)
2782 {
2783 static const struct test_data
2784 {
2785 const BYTE *image_data;
2786 UINT image_size;
2787 ImageType image_type;
2788 UINT prop_count;
2789 UINT prop_count2; /* if win7 behaves differently */
2790 /* 1st property attributes */
2791 UINT prop_size;
2792 UINT prop_size2; /* if win7 behaves differently */
2793 UINT prop_id;
2794 UINT prop_id2; /* if win7 behaves differently */
2795 }
2796 td[] =
2797 {
2798 { pngimage, sizeof(pngimage), ImageTypeBitmap, 4, ~0, 1, 20, 0x5110, 0x132 },
2799 { jpgimage, sizeof(jpgimage), ImageTypeBitmap, 2, ~0, 128, 0, 0x5090, 0x5091 },
2800 { tiffimage, sizeof(tiffimage), ImageTypeBitmap, 16, 0, 4, 0, 0xfe, 0 },
2801 { bmpimage, sizeof(bmpimage), ImageTypeBitmap, 0, 0, 0, 0, 0, 0 },
2802 { wmfimage, sizeof(wmfimage), ImageTypeMetafile, 0, 0, 0, 0, 0, 0 }
2803 };
2804 GpStatus status;
2805 GpImage *image;
2806 UINT prop_count, prop_size, i;
2807 PROPID prop_id[16] = { 0 };
2808 ImageType image_type;
2809 union
2810 {
2811 PropertyItem data;
2812 char buf[256];
2813 } item;
2814
2815 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
2816 {
2817 image = load_image(td[i].image_data, td[i].image_size);
2818 if (!image)
2819 {
2820 trace("%u: failed to load image data\n", i);
2821 continue;
2822 }
2823
2824 status = GdipGetImageType(image, &image_type);
2825 ok(status == Ok, "%u: GdipGetImageType error %d\n", i, status);
2826 ok(td[i].image_type == image_type, "%u: expected image_type %d, got %d\n",
2827 i, td[i].image_type, image_type);
2828
2829 status = GdipGetPropertyCount(image, &prop_count);
2830 ok(status == Ok, "%u: GdipGetPropertyCount error %d\n", i, status);
2831 if (td[i].image_data == pngimage || td[i].image_data == jpgimage)
2832 todo_wine
2833 ok(td[i].prop_count == prop_count || td[i].prop_count2 == prop_count,
2834 " %u: expected property count %u or %u, got %u\n",
2835 i, td[i].prop_count, td[i].prop_count2, prop_count);
2836 else
2837 ok(td[i].prop_count == prop_count || td[i].prop_count2 == prop_count,
2838 " %u: expected property count %u or %u, got %u\n",
2839 i, td[i].prop_count, td[i].prop_count2, prop_count);
2840
2841 status = GdipGetPropertyItemSize(NULL, 0, &prop_size);
2842 expect(InvalidParameter, status);
2843 status = GdipGetPropertyItemSize(image, 0, NULL);
2844 expect(InvalidParameter, status);
2845 status = GdipGetPropertyItemSize(image, 0, &prop_size);
2846 if (image_type == ImageTypeMetafile)
2847 expect(NotImplemented, status);
2848 else
2849 expect(PropertyNotFound, status);
2850
2851 status = GdipGetPropertyItem(NULL, 0, 0, &item.data);
2852 expect(InvalidParameter, status);
2853 status = GdipGetPropertyItem(image, 0, 0, NULL);
2854 expect(InvalidParameter, status);
2855 status = GdipGetPropertyItem(image, 0, 0, &item.data);
2856 if (image_type == ImageTypeMetafile)
2857 expect(NotImplemented, status);
2858 else
2859 expect(PropertyNotFound, status);
2860
2861 /* FIXME: remove once Wine is fixed */
2862 if (td[i].prop_count != prop_count)
2863 {
2864 GdipDisposeImage(image);
2865 continue;
2866 }
2867
2868 status = GdipGetPropertyIdList(NULL, prop_count, prop_id);
2869 expect(InvalidParameter, status);
2870 status = GdipGetPropertyIdList(image, prop_count, NULL);
2871 expect(InvalidParameter, status);
2872 status = GdipGetPropertyIdList(image, 0, prop_id);
2873 if (image_type == ImageTypeMetafile)
2874 expect(NotImplemented, status);
2875 else if (prop_count == 0)
2876 expect(Ok, status);
2877 else
2878 expect(InvalidParameter, status);
2879 status = GdipGetPropertyIdList(image, prop_count - 1, prop_id);
2880 if (image_type == ImageTypeMetafile)
2881 expect(NotImplemented, status);
2882 else
2883 expect(InvalidParameter, status);
2884 status = GdipGetPropertyIdList(image, prop_count + 1, prop_id);
2885 if (image_type == ImageTypeMetafile)
2886 expect(NotImplemented, status);
2887 else
2888 expect(InvalidParameter, status);
2889 status = GdipGetPropertyIdList(image, prop_count, prop_id);
2890 if (image_type == ImageTypeMetafile)
2891 expect(NotImplemented, status);
2892 else
2893 {
2894 expect(Ok, status);
2895 if (prop_count != 0)
2896 ok(td[i].prop_id == prop_id[0] || td[i].prop_id2 == prop_id[0],
2897 " %u: expected property id %#x or %#x, got %#x\n",
2898 i, td[i].prop_id, td[i].prop_id2, prop_id[0]);
2899 }
2900
2901 if (status == Ok)
2902 {
2903 status = GdipGetPropertyItemSize(image, prop_id[0], &prop_size);
2904 if (prop_count == 0)
2905 expect(PropertyNotFound, status);
2906 else
2907 {
2908 expect(Ok, status);
2909
2910 assert(sizeof(item) >= prop_size);
2911 ok(prop_size > sizeof(PropertyItem), "%u: got too small prop_size %u\n",
2912 i, prop_size);
2913 ok(td[i].prop_size + sizeof(PropertyItem) == prop_size ||
2914 td[i].prop_size2 + sizeof(PropertyItem) == prop_size,
2915 " %u: expected property size %u or %u, got %u\n",
2916 i, td[i].prop_size, td[i].prop_size2, prop_size);
2917
2918 status = GdipGetPropertyItem(image, prop_id[0], 0, &item.data);
2919 ok(status == InvalidParameter || status == GenericError /* Win7 */,
2920 "%u: expected InvalidParameter, got %d\n", i, status);
2921 status = GdipGetPropertyItem(image, prop_id[0], prop_size - 1, &item.data);
2922 ok(status == InvalidParameter || status == GenericError /* Win7 */,
2923 "%u: expected InvalidParameter, got %d\n", i, status);
2924 status = GdipGetPropertyItem(image, prop_id[0], prop_size + 1, &item.data);
2925 ok(status == InvalidParameter || status == GenericError /* Win7 */,
2926 "%u: expected InvalidParameter, got %d\n", i, status);
2927 status = GdipGetPropertyItem(image, prop_id[0], prop_size, &item.data);
2928 expect(Ok, status);
2929 ok(prop_id[0] == item.data.id,
2930 "%u: expected property id %#x, got %#x\n", i, prop_id[0], item.data.id);
2931 }
2932 }
2933
2934 GdipDisposeImage(image);
2935 }
2936 }
2937
2938 #define IFD_BYTE 1
2939 #define IFD_ASCII 2
2940 #define IFD_SHORT 3
2941 #define IFD_LONG 4
2942 #define IFD_RATIONAL 5
2943 #define IFD_SBYTE 6
2944 #define IFD_UNDEFINED 7
2945 #define IFD_SSHORT 8
2946 #define IFD_SLONG 9
2947 #define IFD_SRATIONAL 10
2948 #define IFD_FLOAT 11
2949 #define IFD_DOUBLE 12
2950
2951 #ifndef PropertyTagTypeSByte
2952 #define PropertyTagTypeSByte 6
2953 #define PropertyTagTypeSShort 8
2954 #define PropertyTagTypeFloat 11
2955 #define PropertyTagTypeDouble 12
2956 #endif
2957
2958 static UINT documented_type(UINT type)
2959 {
2960 switch (type)
2961 {
2962 case PropertyTagTypeSByte: return PropertyTagTypeByte;
2963 case PropertyTagTypeSShort: return PropertyTagTypeShort;
2964 case PropertyTagTypeFloat: return PropertyTagTypeUndefined;
2965 case PropertyTagTypeDouble: return PropertyTagTypeUndefined;
2966 default: return type;
2967 }
2968 }
2969
2970 #include "pshpack2.h"
2971 struct IFD_entry
2972 {
2973 SHORT id;
2974 SHORT type;
2975 ULONG count;
2976 LONG value;
2977 };
2978
2979 struct IFD_rational
2980 {
2981 LONG numerator;
2982 LONG denominator;
2983 };
2984
2985 static const struct tiff_data
2986 {
2987 USHORT byte_order;
2988 USHORT version;
2989 ULONG dir_offset;
2990 USHORT number_of_entries;
2991 struct IFD_entry entry[40];
2992 ULONG next_IFD;
2993 struct IFD_rational xres;
2994 DOUBLE double_val;
2995 struct IFD_rational srational_val;
2996 char string[14];
2997 SHORT short_val[4];
2998 LONG long_val[2];
2999 FLOAT float_val[2];
3000 struct IFD_rational rational[3];
3001 BYTE pixel_data[4];
3002 } TIFF_data =
3003 {
3004 #ifdef WORDS_BIGENDIAN
3005 'M' | 'M' << 8,
3006 #else
3007 'I' | 'I' << 8,
3008 #endif
3009 42,
3010 FIELD_OFFSET(struct tiff_data, number_of_entries),
3011 31,
3012 {
3013 { 0xff, IFD_SHORT, 1, 0 }, /* SUBFILETYPE */
3014 { 0x100, IFD_LONG, 1, 1 }, /* IMAGEWIDTH */
3015 { 0x101, IFD_LONG, 1, 1 }, /* IMAGELENGTH */
3016 { 0x102, IFD_SHORT, 1, 1 }, /* BITSPERSAMPLE */
3017 { 0x103, IFD_SHORT, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
3018 { 0x106, IFD_SHORT, 1, 1 }, /* PHOTOMETRIC */
3019 { 0x111, IFD_LONG, 1, FIELD_OFFSET(struct tiff_data, pixel_data) }, /* STRIPOFFSETS */
3020 { 0x115, IFD_SHORT, 1, 1 }, /* SAMPLESPERPIXEL */
3021 { 0x116, IFD_LONG, 1, 1 }, /* ROWSPERSTRIP */
3022 { 0x117, IFD_LONG, 1, 1 }, /* STRIPBYTECOUNT */
3023 { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_data, xres) },
3024 { 0x11b, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_data, xres) },
3025 { 0x128, IFD_SHORT, 1, 2 }, /* RESOLUTIONUNIT */
3026 { 0xf001, IFD_BYTE, 1, 0x11223344 },
3027 { 0xf002, IFD_BYTE, 4, 0x11223344 },
3028 { 0xf003, IFD_SBYTE, 1, 0x11223344 },
3029 { 0xf004, IFD_SSHORT, 1, 0x11223344 },
3030 { 0xf005, IFD_SSHORT, 2, 0x11223344 },
3031 { 0xf006, IFD_SLONG, 1, 0x11223344 },
3032 { 0xf007, IFD_FLOAT, 1, 0x11223344 },
3033 { 0xf008, IFD_DOUBLE, 1, FIELD_OFFSET(struct tiff_data, double_val) },
3034 { 0xf009, IFD_SRATIONAL, 1, FIELD_OFFSET(struct tiff_data, srational_val) },
3035 { 0xf00a, IFD_BYTE, 13, FIELD_OFFSET(struct tiff_data, string) },
3036 { 0xf00b, IFD_SSHORT, 4, FIELD_OFFSET(struct tiff_data, short_val) },
3037 { 0xf00c, IFD_SLONG, 2, FIELD_OFFSET(struct tiff_data, long_val) },
3038 { 0xf00e, IFD_ASCII, 13, FIELD_OFFSET(struct tiff_data, string) },
3039 { 0xf00f, IFD_ASCII, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
3040 { 0xf010, IFD_UNDEFINED, 13, FIELD_OFFSET(struct tiff_data, string) },
3041 { 0xf011, IFD_UNDEFINED, 4, 'a' | 'b' << 8 | 'c' << 16 | 'd' << 24 },
3042 /* Some gdiplus versions ignore these fields.
3043 { 0xf012, IFD_BYTE, 0, 0x11223344 },
3044 { 0xf013, IFD_SHORT, 0, 0x11223344 },
3045 { 0xf014, IFD_LONG, 0, 0x11223344 },
3046 { 0xf015, IFD_FLOAT, 0, 0x11223344 },*/
3047 { 0xf016, IFD_SRATIONAL, 3, FIELD_OFFSET(struct tiff_data, rational) },
3048 /* Win7 before SP1 doesn't recognize this field, everybody else does. */
3049 { 0xf017, IFD_FLOAT, 2, FIELD_OFFSET(struct tiff_data, float_val) },
3050 },
3051 0,
3052 { 900, 3 },
3053 1234567890.0987654321,
3054 { 0x1a2b3c4d, 0x5a6b7c8d },
3055 "Hello World!",
3056 { 0x0101, 0x0202, 0x0303, 0x0404 },
3057 { 0x11223344, 0x55667788 },
3058 { (FLOAT)1234.5678, (FLOAT)8765.4321 },
3059 { { 0x01020304, 0x05060708 }, { 0x10203040, 0x50607080 }, { 0x11223344, 0x55667788 } },
3060 { 0x11, 0x22, 0x33, 0 }
3061 };
3062 #include "poppack.h"
3063
3064 static void test_tiff_properties(void)
3065 {
3066 static const struct test_data
3067 {
3068 ULONG type, id, length;
3069 const BYTE value[24];
3070 } td[31] =
3071 {
3072 { PropertyTagTypeShort, 0xff, 2, { 0 } },
3073 { PropertyTagTypeLong, 0x100, 4, { 1 } },
3074 { PropertyTagTypeLong, 0x101, 4, { 1 } },
3075 { PropertyTagTypeShort, 0x102, 2, { 1 } },
3076 { PropertyTagTypeShort, 0x103, 2, { 1 } },
3077 { PropertyTagTypeShort, 0x106, 2, { 1 } },
3078 { PropertyTagTypeLong, 0x111, 4, { 0x44,0x02 } },
3079 { PropertyTagTypeShort, 0x115, 2, { 1 } },
3080 { PropertyTagTypeLong, 0x116, 4, { 1 } },
3081 { PropertyTagTypeLong, 0x117, 4, { 1 } },
3082 { PropertyTagTypeRational, 0x11a, 8, { 0x84,0x03,0,0,0x03 } },
3083 { PropertyTagTypeRational, 0x11b, 8, { 0x84,0x03,0,0,0x03 } },
3084 { PropertyTagTypeShort, 0x128, 2, { 2 } },
3085 { PropertyTagTypeByte, 0xf001, 1, { 0x44 } },
3086 { PropertyTagTypeByte, 0xf002, 4, { 0x44,0x33,0x22,0x11 } },
3087 { PropertyTagTypeSByte, 0xf003, 1, { 0x44 } },
3088 { PropertyTagTypeSShort, 0xf004, 2, { 0x44,0x33 } },
3089 { PropertyTagTypeSShort, 0xf005, 4, { 0x44,0x33,0x22,0x11 } },
3090 { PropertyTagTypeSLONG, 0xf006, 4, { 0x44,0x33,0x22,0x11 } },
3091 { PropertyTagTypeFloat, 0xf007, 4, { 0x44,0x33,0x22,0x11 } },
3092 { PropertyTagTypeDouble, 0xf008, 8, { 0x2c,0x52,0x86,0xb4,0x80,0x65,0xd2,0x41 } },
3093 { PropertyTagTypeSRational, 0xf009, 8, { 0x4d, 0x3c, 0x2b, 0x1a, 0x8d, 0x7c, 0x6b, 0x5a } },
3094 { PropertyTagTypeByte, 0xf00a, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3095 { PropertyTagTypeSShort, 0xf00b, 8, { 0x01,0x01,0x02,0x02,0x03,0x03,0x04,0x04 } },
3096 { PropertyTagTypeSLONG, 0xf00c, 8, { 0x44,0x33,0x22,0x11,0x88,0x77,0x66,0x55 } },
3097 { PropertyTagTypeASCII, 0xf00e, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3098 { PropertyTagTypeASCII, 0xf00f, 5, { 'a','b','c','d' } },
3099 { PropertyTagTypeUndefined, 0xf010, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3100 { PropertyTagTypeUndefined, 0xf011, 4, { 'a','b','c','d' } },
3101 { PropertyTagTypeSRational, 0xf016, 24,
3102 { 0x04,0x03,0x02,0x01,0x08,0x07,0x06,0x05,
3103 0x40,0x30,0x20,0x10,0x80,0x70,0x60,0x50,
3104 0x44,0x33,0x22,0x11,0x88,0x77,0x66,0x55 } },
3105 /* Win7 before SP1 doesn't recognize this field, everybody else does. */
3106 { PropertyTagTypeFloat, 0xf017, 8, { 0x2b,0x52,0x9a,0x44,0xba,0xf5,0x08,0x46 } },
3107 };
3108 GpStatus status;
3109 GpImage *image;
3110 GUID guid;
3111 UINT dim_count, frame_count, prop_count, prop_size, i;
3112 PROPID *prop_id;
3113 PropertyItem *prop_item;
3114
3115 image = load_image((const BYTE *)&TIFF_data, sizeof(TIFF_data));
3116 if (!image)
3117 {
3118 win_skip("Failed to load TIFF image data. Might not be supported. Skipping.\n");
3119 return;
3120 }
3121
3122 status = GdipImageGetFrameDimensionsCount(image, &dim_count);
3123 expect(Ok, status);
3124 expect(1, dim_count);
3125
3126 status = GdipImageGetFrameDimensionsList(image, &guid, 1);
3127 expect(Ok, status);
3128 expect_guid(&FrameDimensionPage, &guid, __LINE__, FALSE);
3129
3130 frame_count = 0xdeadbeef;
3131 status = GdipImageGetFrameCount(image, &guid, &frame_count);
3132 expect(Ok, status);
3133 expect(1, frame_count);
3134
3135 prop_count = 0xdeadbeef;
3136 status = GdipGetPropertyCount(image, &prop_count);
3137 expect(Ok, status);
3138 ok(prop_count == sizeof(td)/sizeof(td[0]) ||
3139 broken(prop_count == sizeof(td)/sizeof(td[0]) - 1) /* Win7 SP0 */,
3140 "expected property count %u, got %u\n", (UINT)(sizeof(td)/sizeof(td[0])), prop_count);
3141
3142 prop_id = HeapAlloc(GetProcessHeap(), 0, prop_count * sizeof(*prop_id));
3143
3144 status = GdipGetPropertyIdList(image, prop_count, prop_id);
3145 expect(Ok, status);
3146
3147 for (i = 0; i < prop_count; i++)
3148 {
3149 status = GdipGetPropertyItemSize(image, prop_id[i], &prop_size);
3150 expect(Ok, status);
3151 if (status != Ok) break;
3152 ok(prop_size > sizeof(*prop_item), "%u: too small item length %u\n", i, prop_size);
3153
3154 prop_item = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, prop_size);
3155 status = GdipGetPropertyItem(image, prop_id[i], prop_size, prop_item);
3156 expect(Ok, status);
3157 ok(prop_item->value == prop_item + 1, "expected item->value %p, got %p\n", prop_item + 1, prop_item->value);
3158 ok(td[i].type == prop_item->type ||
3159 /* Win7 stopped using proper but not documented types, and it
3160 looks broken since TypeFloat and TypeDouble now reported as
3161 TypeUndefined, and signed types reported as unsigned. */
3162 broken(prop_item->type == documented_type(td[i].type)),
3163 "%u: expected type %u, got %u\n", i, td[i].type, prop_item->type);
3164 ok(td[i].id == prop_item->id, "%u: expected id %#x, got %#x\n", i, td[i].id, prop_item->id);
3165 prop_size -= sizeof(*prop_item);
3166 ok(prop_item->length == prop_size, "%u: expected length %u, got %u\n", i, prop_size, prop_item->length);
3167 ok(td[i].length == prop_item->length, "%u: expected length %u, got %u\n", i, td[i].length, prop_item->length);
3168 ok(td[i].length == prop_size, "%u: expected length %u, got %u\n", i, td[i].length, prop_size);
3169 if (td[i].length == prop_item->length)
3170 {
3171 int match = memcmp(td[i].value, prop_item->value, td[i].length) == 0;
3172 ok(match || broken(td[i].length <= 4 && !match), "%u: data mismatch\n", i);
3173 if (!match)
3174 {
3175 UINT j;
3176 BYTE *data = prop_item->value;
3177 printf("id %#x:", prop_item->id);
3178 for (j = 0; j < prop_item->length; j++)
3179 printf(" %02x", data[j]);
3180 printf("\n");
3181 }
3182 }
3183 HeapFree(GetProcessHeap(), 0, prop_item);
3184 }
3185
3186 HeapFree(GetProcessHeap(), 0, prop_id);
3187
3188 GdipDisposeImage(image);
3189 }
3190
3191 static void test_GdipGetAllPropertyItems(void)
3192 {
3193 static const struct test_data
3194 {
3195 ULONG type, id, length;
3196 BYTE value[32];
3197 } td[16] =
3198 {
3199 { PropertyTagTypeLong, 0xfe, 4, { 0 } },
3200 { PropertyTagTypeShort, 0x100, 2, { 1 } },
3201 { PropertyTagTypeShort, 0x101, 2, { 1 } },
3202 { PropertyTagTypeShort, 0x102, 6, { 8,0,8,0,8,0 } },
3203 { PropertyTagTypeShort, 0x103, 2, { 1 } },
3204 { PropertyTagTypeShort, 0x106, 2, { 2,0 } },
3205 { PropertyTagTypeASCII, 0x10d, 27, "/home/meh/Desktop/test.tif" },
3206 { PropertyTagTypeLong, 0x111, 4, { 8,0,0,0 } },
3207 { PropertyTagTypeShort, 0x112, 2, { 1 } },
3208 { PropertyTagTypeShort, 0x115, 2, { 3,0 } },
3209 { PropertyTagTypeShort, 0x116, 2, { 0x40,0 } },
3210 { PropertyTagTypeLong, 0x117, 4, { 3,0,0,0 } },
3211 { PropertyTagTypeRational, 0x11a, 8, { 0,0,0,72,0,0,0,1 } },
3212 { PropertyTagTypeRational, 0x11b, 8, { 0,0,0,72,0,0,0,1 } },
3213 { PropertyTagTypeShort, 0x11c, 2, { 1 } },
3214 { PropertyTagTypeShort, 0x128, 2, { 2 } }
3215 };
3216 GpStatus status;
3217 GpImage *image;
3218 GUID guid;
3219 UINT dim_count, frame_count, prop_count, prop_size, i;
3220 UINT total_size, total_count;
3221 PROPID *prop_id;
3222 PropertyItem *prop_item;
3223 const char *item_data;
3224
3225 image = load_image(tiffimage, sizeof(tiffimage));
3226 ok(image != 0, "Failed to load TIFF image data\n");
3227 if (!image) return;
3228
3229 dim_count = 0xdeadbeef;
3230 status = GdipImageGetFrameDimensionsCount(image, &dim_count);
3231 expect(Ok, status);
3232 expect(1, dim_count);
3233
3234 status = GdipImageGetFrameDimensionsList(image, &guid, 1);
3235 expect(Ok, status);
3236 expect_guid(&FrameDimensionPage, &guid, __LINE__, FALSE);
3237
3238 frame_count = 0xdeadbeef;
3239 status = GdipImageGetFrameCount(image, &guid, &frame_count);
3240 expect(Ok, status);
3241 expect(1, frame_count);
3242
3243 prop_count = 0xdeadbeef;
3244 status = GdipGetPropertyCount(image, &prop_count);
3245 expect(Ok, status);
3246 ok(prop_count == sizeof(td)/sizeof(td[0]),
3247 "expected property count %u, got %u\n", (UINT)(sizeof(td)/sizeof(td[0])), prop_count);
3248
3249 prop_id = HeapAlloc(GetProcessHeap(), 0, prop_count * sizeof(*prop_id));
3250
3251 status = GdipGetPropertyIdList(image, prop_count, prop_id);
3252 expect(Ok, status);
3253
3254 prop_size = 0;
3255 for (i = 0; i < prop_count; i++)
3256 {
3257 UINT size;
3258 status = GdipGetPropertyItemSize(image, prop_id[i], &size);
3259 expect(Ok, status);
3260 if (status != Ok) break;
3261 ok(size > sizeof(*prop_item), "%u: too small item length %u\n", i, size);
3262
3263 prop_size += size;
3264
3265 prop_item = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
3266 status = GdipGetPropertyItem(image, prop_id[i], size, prop_item);
3267 expect(Ok, status);
3268 ok(prop_item->value == prop_item + 1, "expected item->value %p, got %p\n", prop_item + 1, prop_item->value);
3269 ok(td[i].type == prop_item->type,
3270 "%u: expected type %u, got %u\n", i, td[i].type, prop_item->type);
3271 ok(td[i].id == prop_item->id, "%u: expected id %#x, got %#x\n", i, td[i].id, prop_item->id);
3272 size -= sizeof(*prop_item);
3273 ok(prop_item->length == size, "%u: expected length %u, got %u\n", i, size, prop_item->length);
3274 ok(td[i].length == prop_item->length, "%u: expected length %u, got %u\n", i, td[i].length, prop_item->length);
3275 if (td[i].length == prop_item->length)
3276 {
3277 int match = memcmp(td[i].value, prop_item->value, td[i].length) == 0;
3278 ok(match, "%u: data mismatch\n", i);
3279 if (!match)
3280 {
3281 UINT j;
3282 BYTE *data = prop_item->value;
3283 printf("id %#x:", prop_item->id);
3284 for (j = 0; j < prop_item->length; j++)
3285 printf(" %02x", data[j]);
3286 printf("\n");
3287 }
3288 }
3289 HeapFree(GetProcessHeap(), 0, prop_item);
3290 }
3291
3292 HeapFree(GetProcessHeap(), 0, prop_id);
3293
3294 status = GdipGetPropertySize(NULL, &total_size, &total_count);
3295 expect(InvalidParameter, status);
3296 status = GdipGetPropertySize(image, &total_size, NULL);
3297 expect(InvalidParameter, status);
3298 status = GdipGetPropertySize(image, NULL, &total_count);
3299 expect(InvalidParameter, status);
3300 status = GdipGetPropertySize(image, NULL, NULL);
3301 expect(InvalidParameter, status);
3302 total_size = 0xdeadbeef;
3303 total_count = 0xdeadbeef;
3304 status = GdipGetPropertySize(image, &total_size, &total_count);
3305 expect(Ok, status);
3306 ok(prop_count == total_count,
3307 "expected total property count %u, got %u\n", prop_count, total_count);
3308 ok(prop_size == total_size,
3309 "expected total property size %u, got %u\n", prop_size, total_size);
3310
3311 prop_item = HeapAlloc(GetProcessHeap(), 0, prop_size);
3312
3313 status = GdipGetAllPropertyItems(image, 0, prop_count, prop_item);
3314 expect(InvalidParameter, status);
3315 status = GdipGetAllPropertyItems(image, prop_size, 1, prop_item);
3316 expect(InvalidParameter, status);
3317 status = GdipGetAllPropertyItems(image, prop_size, prop_count, NULL);
3318 expect(InvalidParameter, status);
3319 status = GdipGetAllPropertyItems(image, prop_size, prop_count, NULL);
3320 expect(InvalidParameter, status);
3321 status = GdipGetAllPropertyItems(image, 0, 0, NULL);
3322 expect(InvalidParameter, status);
3323 status = GdipGetAllPropertyItems(image, prop_size + 1, prop_count, prop_item);
3324 expect(InvalidParameter, status);
3325 status = GdipGetAllPropertyItems(image, prop_size, prop_count, prop_item);
3326 expect(Ok, status);
3327
3328 item_data = (const char *)(prop_item + prop_count);
3329 for (i = 0; i < prop_count; i++)
3330 {
3331 ok(prop_item[i].value == item_data, "%u: expected value %p, got %p\n",
3332 i, item_data, prop_item[i].value);
3333 ok(td[i].type == prop_item[i].type,
3334 "%u: expected type %u, got %u\n", i, td[i].type, prop_item[i].type);
3335 ok(td[i].id == prop_item[i].id, "%u: expected id %#x, got %#x\n", i, td[i].id, prop_item[i].id);
3336 ok(td[i].length == prop_item[i].length, "%u: expected length %u, got %u\n", i, td[i].length, prop_item[i].length);
3337 if (td[i].length == prop_item[i].length)
3338 {
3339 int match = memcmp(td[i].value, prop_item[i].value, td[i].length) == 0;
3340 ok(match, "%u: data mismatch\n", i);
3341 if (!match)
3342 {
3343 UINT j;
3344 BYTE *data = prop_item[i].value;
3345 printf("id %#x:", prop_item[i].id);
3346 for (j = 0; j < prop_item[i].length; j++)
3347 printf(" %02x", data[j]);
3348 printf("\n");
3349 }
3350 }
3351 item_data += prop_item[i].length;
3352 }
3353
3354 HeapFree(GetProcessHeap(), 0, prop_item);
3355
3356 GdipDisposeImage(image);
3357 }
3358
3359 static void test_tiff_palette(void)
3360 {
3361 GpStatus status;
3362 GpImage *image;
3363 PixelFormat format;
3364 INT size;
3365 struct
3366 {
3367 ColorPalette pal;
3368 ARGB entry[256];
3369 } palette;
3370 ARGB *entries = palette.pal.Entries;
3371
3372 /* 1bpp TIFF without palette */
3373 image = load_image((const BYTE *)&TIFF_data, sizeof(TIFF_data));
3374 if (!image)
3375 {
3376 win_skip("Failed to load TIFF image data. Might not be supported. Skipping.\n");
3377 return;
3378 }
3379
3380 status = GdipGetImagePixelFormat(image, &format);
3381 expect(Ok, status);
3382 ok(format == PixelFormat1bppIndexed, "expected PixelFormat1bppIndexed, got %#x\n", format);
3383
3384 status = GdipGetImagePaletteSize(image, &size);
3385 ok(status == Ok || broken(status == GenericError), /* XP */
3386 "GdipGetImagePaletteSize error %d\n", status);
3387 if (status == GenericError)
3388 {
3389 GdipDisposeImage(image);
3390 return;
3391 }
3392 expect(sizeof(ColorPalette) + sizeof(ARGB), size);
3393
3394 status = GdipGetImagePalette(image, &palette.pal, size);
3395 expect(Ok, status);
3396 expect(0, palette.pal.Flags);
3397 expect(2, palette.pal.Count);
3398 if (palette.pal.Count == 2)
3399 {
3400 ok(entries[0] == 0xff000000, "expected 0xff000000, got %#x\n", entries[0]);
3401 ok(entries[1] == 0xffffffff, "expected 0xffffffff, got %#x\n", entries[1]);
3402 }
3403
3404 GdipDisposeImage(image);
3405 }
3406
3407 static void test_bitmapbits(void)
3408 {
3409 /* 8 x 2 bitmap */
3410 static const BYTE pixels_24[48] =
3411 {
3412 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3413 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3414 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3415 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0
3416 };
3417 static const BYTE pixels_00[48] =
3418 {
3419 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3420 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3421 0,0,0, 0,0,0, 0,0,0, 0,0,0,
3422 0,0,0, 0,0,0, 0,0,0, 0,0,0
3423 };
3424 static const BYTE pixels_24_77[64] =
3425 {
3426 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3427 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3428 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3429 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3430 0xff,0xff,0xff, 0,0,0, 0xff,0xff,0xff, 0,0,0,
3431 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3432 };
3433 static const BYTE pixels_77[64] =
3434 {
3435 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3436 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3437 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3438 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3439 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3440 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3441 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3442 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3443 };
3444 static const BYTE pixels_8[16] =
3445 {
3446 0x01,0,0x01,0,0x01,0,0x01,0,
3447 0x01,0,0x01,0,0x01,0,0x01,0
3448 };
3449 static const BYTE pixels_8_77[64] =
3450 {
3451 0x01,0,0x01,0,0x01,0,0x01,0,
3452 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3453 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3454 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3455 0x01,0,0x01,0,0x01,0,0x01,0,
3456 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3457 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3458 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3459 };
3460 static const BYTE pixels_1_77[64] =
3461 {
3462 0xaa,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3463 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3464 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3465 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3466 0xaa,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3467 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3468 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
3469 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77
3470 };
3471 static const BYTE pixels_1[8] = {0xaa,0,0,0,0xaa,0,0,0};
3472 static const struct test_data
3473 {
3474 PixelFormat format;
3475 UINT bpp;
3476 ImageLockMode mode;
3477 UINT stride, size;
3478 const BYTE *pixels;
3479 const BYTE *pixels_unlocked;
3480 } td[] =
3481 {
3482 /* 0 */
3483 { PixelFormat24bppRGB, 24, 0xfff0, 24, 48, pixels_24, pixels_00 },
3484
3485 { PixelFormat24bppRGB, 24, 0, 24, 48, pixels_24, pixels_00 },
3486 { PixelFormat24bppRGB, 24, ImageLockModeRead, 24, 48, pixels_24, pixels_00 },
3487 { PixelFormat24bppRGB, 24, ImageLockModeWrite, 24, 48, pixels_24, pixels_00 },
3488 { PixelFormat24bppRGB, 24, ImageLockModeRead|ImageLockModeWrite, 24, 48, pixels_24, pixels_00 },
3489 { PixelFormat24bppRGB, 24, ImageLockModeRead|ImageLockModeUserInputBuf, 32, 64, pixels_24_77, pixels_24 },
3490 { PixelFormat24bppRGB, 24, ImageLockModeWrite|ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_00 },
3491 { PixelFormat24bppRGB, 24, ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_24 },
3492 /* 8 */
3493 { PixelFormat8bppIndexed, 8, 0, 8, 16, pixels_8, pixels_24 },
3494 { PixelFormat8bppIndexed, 8, ImageLockModeRead, 8, 16, pixels_8, pixels_24 },
3495 { PixelFormat8bppIndexed, 8, ImageLockModeWrite, 8, 16, pixels_8, pixels_00 },
3496 { PixelFormat8bppIndexed, 8, ImageLockModeRead|ImageLockModeWrite, 8, 16, pixels_8, pixels_00 },
3497 { PixelFormat8bppIndexed, 8, ImageLockModeRead|ImageLockModeUserInputBuf, 32, 64, pixels_8_77, pixels_24 },
3498 { PixelFormat8bppIndexed, 8, ImageLockModeWrite|ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_00 },
3499 { PixelFormat8bppIndexed, 8, ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_24 },
3500 /* 15 */
3501 { PixelFormat1bppIndexed, 1, 0, 4, 8, pixels_1, pixels_24 },
3502 { PixelFormat1bppIndexed, 1, ImageLockModeRead, 4, 8, pixels_1, pixels_24 },
3503 { PixelFormat1bppIndexed, 1, ImageLockModeWrite, 4, 8, pixels_1, pixels_00 },
3504 { PixelFormat1bppIndexed, 1, ImageLockModeRead|ImageLockModeWrite, 4, 8, pixels_1, pixels_00 },
3505 { PixelFormat1bppIndexed, 1, ImageLockModeRead|ImageLockModeUserInputBuf, 32, 64, pixels_1_77, pixels_24 },
3506 { PixelFormat1bppIndexed, 1, ImageLockModeWrite|ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_00 },
3507 { PixelFormat1bppIndexed, 1, ImageLockModeUserInputBuf, 32, 64, pixels_77, pixels_24 },
3508 };
3509 BYTE buf[64];
3510 GpStatus status;
3511 GpBitmap *bitmap;
3512 UINT i;
3513 BitmapData data;
3514 struct
3515 {
3516 ColorPalette pal;
3517 ARGB entries[1];
3518 } palette;
3519 ARGB *entries = palette.pal.Entries;
3520
3521 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3522 {
3523 BYTE pixels[sizeof(pixels_24)];
3524 memcpy(pixels, pixels_24, sizeof(pixels_24));
3525 status = GdipCreateBitmapFromScan0(8, 2, 24, PixelFormat24bppRGB, pixels, &bitmap);
3526 expect(Ok, status);
3527
3528 /* associate known palette with pixel data */
3529 palette.pal.Flags = PaletteFlagsGrayScale;
3530 palette.pal.Count = 2;
3531 entries[0] = 0xff000000;
3532 entries[1] = 0xffffffff;
3533 status = GdipSetImagePalette((GpImage *)bitmap, &palette.pal);
3534 expect(Ok, status);
3535
3536 memset(&data, 0xfe, sizeof(data));
3537 if (td[i].mode & ImageLockModeUserInputBuf)
3538 {
3539 memset(buf, 0x77, sizeof(buf));
3540 data.Scan0 = buf;
3541 data.Stride = 32;
3542 }
3543 status = GdipBitmapLockBits(bitmap, NULL, td[i].mode, td[i].format, &data);
3544 ok(status == Ok || broken(status == InvalidParameter) /* XP */, "%u: GdipBitmapLockBits error %d\n", i, status);
3545 if (status != Ok)
3546 {
3547 GdipDisposeImage((GpImage *)bitmap);
3548 continue;
3549 }
3550 ok(data.Width == 8, "%u: expected 8, got %d\n", i, data.Width);
3551 ok(data.Height == 2, "%u: expected 2, got %d\n", i, data.Height);
3552 ok(td[i].stride == data.Stride, "%u: expected %d, got %d\n", i, td[i].stride, data.Stride);
3553 ok(td[i].format == data.PixelFormat, "%u: expected %d, got %d\n", i, td[i].format, data.PixelFormat);
3554 ok(td[i].size == data.Height * data.Stride, "%u: expected %d, got %d\n", i, td[i].size, data.Height * data.Stride);
3555 if (td[i].mode & ImageLockModeUserInputBuf)
3556 ok(data.Scan0 == buf, "%u: got wrong buffer\n", i);
3557 if (td[i].size == data.Height * data.Stride)
3558 {
3559 UINT j, match, width_bytes = (data.Width * td[i].bpp) / 8;
3560
3561 match = 1;
3562 for (j = 0; j < data.Height; j++)
3563 {
3564 if (memcmp((const BYTE *)data.Scan0 + j * data.Stride, td[i].pixels + j * data.Stride, width_bytes) != 0)
3565 {
3566 match = 0;
3567 break;
3568 }
3569 }
3570 if ((td[i].mode & (ImageLockModeRead|ImageLockModeUserInputBuf)) || td[i].format == PixelFormat24bppRGB)
3571 {
3572 ok(match,
3573 "%u: data should match\n", i);
3574 if (!match)
3575 {
3576 BYTE *bits = data.Scan0;
3577 printf("%u: data mismatch for format %#x:", i, td[i].format);
3578 for (j = 0; j < td[i].size; j++)
3579 printf(" %02x", bits[j]);
3580 printf("\n");
3581 }
3582 }
3583 else
3584 ok(!match, "%u: data shouldn't match\n", i);
3585
3586 memset(data.Scan0, 0, td[i].size);
3587 }
3588
3589 status = GdipBitmapUnlockBits(bitmap, &data);
3590 ok(status == Ok, "%u: GdipBitmapUnlockBits error %d\n", i, status);
3591
3592 memset(&data, 0xfe, sizeof(data));
3593 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat24bppRGB, &data);
3594 ok(status == Ok, "%u: GdipBitmapLockBits error %d\n", i, status);
3595 ok(data.Width == 8, "%u: expected 8, got %d\n", i, data.Width);
3596 ok(data.Height == 2, "%u: expected 2, got %d\n", i, data.Height);
3597 ok(data.Stride == 24, "%u: expected 24, got %d\n", i, data.Stride);
3598 ok(data.PixelFormat == PixelFormat24bppRGB, "%u: got wrong pixel format %d\n", i, data.PixelFormat);
3599 ok(data.Height * data.Stride == 48, "%u: expected 48, got %d\n", i, data.Height * data.Stride);
3600 if (data.Height * data.Stride == 48)
3601 {
3602 int match = memcmp(data.Scan0, td[i].pixels_unlocked, 48) == 0;
3603 ok(match, "%u: data should match\n", i);
3604 if (!match)
3605 {
3606 UINT j;
3607 BYTE *bits = data.Scan0;
3608 printf("%u: data mismatch for format %#x:", i, td[i].format);
3609 for (j = 0; j < 48; j++)
3610 printf(" %02x", bits[j]);
3611 printf("\n");
3612 }
3613 }
3614
3615 status = GdipBitmapUnlockBits(bitmap, &data);
3616 ok(status == Ok, "%u: GdipBitmapUnlockBits error %d\n", i, status);
3617
3618 status = GdipDisposeImage((GpImage *)bitmap);
3619 expect(Ok, status);
3620 }
3621 }
3622
3623 static void test_DrawImage(void)
3624 {
3625 BYTE black_1x1[4] = { 0,0,0,0 };
3626 BYTE white_2x2[16] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
3627 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
3628 BYTE black_2x2[16] = { 0,0,0,0,0,0,0xff,0xff,
3629 0,0,0,0,0,0,0xff,0xff };
3630 GpStatus status;
3631 union
3632 {
3633 GpBitmap *bitmap;
3634 GpImage *image;
3635 } u1, u2;
3636 GpGraphics *graphics;
3637 int match;
3638
3639 status = GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB, black_1x1, &u1.bitmap);
3640 expect(Ok, status);
3641 status = GdipBitmapSetResolution(u1.bitmap, 100.0, 100.0);
3642 expect(Ok, status);
3643
3644 status = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat24bppRGB, white_2x2, &u2.bitmap);
3645 expect(Ok, status);
3646 status = GdipBitmapSetResolution(u2.bitmap, 300.0, 300.0);
3647 expect(Ok, status);
3648 status = GdipGetImageGraphicsContext(u2.image, &graphics);
3649 expect(Ok, status);
3650 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3651 expect(Ok, status);
3652
3653 status = GdipDrawImageI(graphics, u1.image, 0, 0);
3654 expect(Ok, status);
3655
3656 match = memcmp(white_2x2, black_2x2, sizeof(black_2x2)) == 0;
3657 ok(match, "data should match\n");
3658 if (!match)
3659 {
3660 UINT i, size = sizeof(white_2x2);
3661 BYTE *bits = white_2x2;
3662 for (i = 0; i < size; i++)
3663 printf(" %02x", bits[i]);
3664 printf("\n");
3665 }
3666
3667 status = GdipDeleteGraphics(graphics);
3668 expect(Ok, status);
3669 status = GdipDisposeImage(u1.image);
3670 expect(Ok, status);
3671 status = GdipDisposeImage(u2.image);
3672 expect(Ok, status);
3673 }
3674
3675 static void test_GdipDrawImagePointRect(void)
3676 {
3677 BYTE black_1x1[4] = { 0,0,0,0 };
3678 BYTE white_2x2[16] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
3679 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
3680 BYTE black_2x2[16] = { 0,0,0,0,0,0,0xff,0xff,
3681 0,0,0,0,0,0,0xff,0xff };
3682 GpStatus status;
3683 union
3684 {
3685 GpBitmap *bitmap;
3686 GpImage *image;
3687 } u1, u2;
3688 GpGraphics *graphics;
3689 int match;
3690
3691 status = GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB, black_1x1, &u1.bitmap);
3692 expect(Ok, status);
3693 status = GdipBitmapSetResolution(u1.bitmap, 100.0, 100.0);
3694 expect(Ok, status);
3695
3696 status = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat24bppRGB, white_2x2, &u2.bitmap);
3697 expect(Ok, status);
3698 status = GdipBitmapSetResolution(u2.bitmap, 300.0, 300.0);
3699 expect(Ok, status);
3700 status = GdipGetImageGraphicsContext(u2.image, &graphics);
3701 expect(Ok, status);
3702 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3703 expect(Ok, status);
3704
3705 status = GdipDrawImagePointRectI(graphics, u1.image, 0, 0, 0, 0, 1, 1, UnitPixel);
3706 expect(Ok, status);
3707
3708 match = memcmp(white_2x2, black_2x2, sizeof(black_2x2)) == 0;
3709 ok(match, "data should match\n");
3710 if (!match)
3711 {
3712 UINT i, size = sizeof(white_2x2);
3713 BYTE *bits = white_2x2;
3714 for (i = 0; i < size; i++)
3715 printf(" %02x", bits[i]);
3716 printf("\n");
3717 }
3718
3719 status = GdipDeleteGraphics(graphics);
3720 expect(Ok, status);
3721 status = GdipDisposeImage(u1.image);
3722 expect(Ok, status);
3723 status = GdipDisposeImage(u2.image);
3724 expect(Ok, status);
3725 }
3726
3727 static void test_image_format(void)
3728 {
3729 static const PixelFormat fmt[] =
3730 {
3731 PixelFormat1bppIndexed, PixelFormat4bppIndexed, PixelFormat8bppIndexed,
3732 PixelFormat16bppGrayScale, PixelFormat16bppRGB555, PixelFormat16bppRGB565,
3733 PixelFormat16bppARGB1555, PixelFormat24bppRGB, PixelFormat32bppRGB,
3734 PixelFormat32bppARGB, PixelFormat32bppPARGB, PixelFormat48bppRGB,
3735 PixelFormat64bppARGB, PixelFormat64bppPARGB, PixelFormat32bppCMYK
3736 };
3737 GpStatus status;
3738 GpBitmap *bitmap;
3739 GpImage *thumb;
3740 HBITMAP hbitmap;
3741 BITMAP bm;
3742 PixelFormat format;
3743 BitmapData data;
3744 UINT i, ret;
3745
3746 for (i = 0; i < sizeof(fmt)/sizeof(fmt[0]); i++)
3747 {
3748 status = GdipCreateBitmapFromScan0(1, 1, 0, fmt[i], NULL, &bitmap);
3749 ok(status == Ok || broken(status == InvalidParameter) /* before win7 */,
3750 "GdipCreateBitmapFromScan0 error %d\n", status);
3751 if (status != Ok) continue;
3752
3753 status = GdipGetImagePixelFormat((GpImage *)bitmap, &format);
3754 expect(Ok, status);
3755 expect(fmt[i], format);
3756
3757 status = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
3758 if (fmt[i] == PixelFormat16bppGrayScale || fmt[i] == PixelFormat32bppCMYK)
3759 todo_wine expect(InvalidParameter, status);
3760 else
3761 {
3762 expect(Ok, status);
3763 ret = GetObject(hbitmap, sizeof(bm), &bm);
3764 expect(sizeof(bm), ret);
3765 expect(0, bm.bmType);
3766 expect(1, bm.bmWidth);
3767 expect(1, bm.bmHeight);
3768 expect(4, bm.bmWidthBytes);
3769 expect(1, bm.bmPlanes);
3770 expect(32, bm.bmBitsPixel);
3771 DeleteObject(hbitmap);
3772 }
3773
3774 status = GdipGetImageThumbnail((GpImage *)bitmap, 0, 0, &thumb, NULL, NULL);
3775 if (fmt[i] == PixelFormat16bppGrayScale || fmt[i] == PixelFormat32bppCMYK)
3776 todo_wine
3777 ok(status == OutOfMemory || broken(status == InvalidParameter) /* before win7 */,
3778 "expected OutOfMemory, got %d\n", status);
3779 else
3780 {
3781 expect(Ok, status);
3782 status = GdipGetImagePixelFormat(thumb, &format);
3783 expect(Ok, status);
3784 ok(format == PixelFormat32bppPARGB || broken(format != PixelFormat32bppPARGB) /* before win7 */,
3785 "expected PixelFormat32bppPARGB, got %#x\n", format);
3786 status = GdipDisposeImage(thumb);
3787 expect(Ok, status);
3788 }
3789
3790 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat32bppPARGB, &data);
3791 if (fmt[i] == PixelFormat16bppGrayScale || fmt[i] == PixelFormat32bppCMYK)
3792 todo_wine expect(InvalidParameter, status);
3793 else
3794 {
3795 expect(Ok, status);
3796 status = GdipBitmapUnlockBits(bitmap, &data);
3797 expect(Ok, status);
3798 }
3799
3800 status = GdipDisposeImage((GpImage *)bitmap);
3801 expect(Ok, status);
3802 }
3803 }
3804
3805 static void test_DrawImage_scale(void)
3806 {
3807 static const BYTE back_8x1[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
3808 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3809 static const BYTE image_080[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,
3810 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3811 static const BYTE image_100[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40,
3812 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3813 static const BYTE image_120[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x40,0x40,0x40,
3814 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3815 static const BYTE image_150[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3816 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3817 static const BYTE image_180[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3818 0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3819 static const BYTE image_200[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3820 0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3821 static const BYTE image_250[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,
3822 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40 };
3823 static const BYTE image_120_half[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
3824 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3825 static const BYTE image_150_half[24] = { 0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
3826 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 };
3827 static const BYTE image_200_half[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3828 0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40,0x40,0x40,0x40 };
3829 static const BYTE image_250_half[24] = { 0x40,0x40,0x40,0x40,0x40,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
3830 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x40,0x40,0x40 };
3831 static const struct test_data
3832 {
3833 REAL scale_x;
3834 PixelOffsetMode pixel_offset_mode;
3835 const BYTE *image;
3836 BOOL todo;
3837 } td[] =
3838 {
3839 { 0.8, PixelOffsetModeNone, image_080 }, /* 0 */
3840 { 1.0, PixelOffsetModeNone, image_100 },
3841 { 1.2, PixelOffsetModeNone, image_120 },
3842 { 1.5, PixelOffsetModeNone, image_150 },
3843 { 1.8, PixelOffsetModeNone, image_180 },
3844 { 2.0, PixelOffsetModeNone, image_200 },
3845 { 2.5, PixelOffsetModeNone, image_250 },
3846
3847 { 0.8, PixelOffsetModeHighSpeed, image_080 }, /* 7 */
3848 { 1.0, PixelOffsetModeHighSpeed, image_100 },
3849 { 1.2, PixelOffsetModeHighSpeed, image_120 },
3850 { 1.5, PixelOffsetModeHighSpeed, image_150 },
3851 { 1.8, PixelOffsetModeHighSpeed, image_180 },
3852 { 2.0, PixelOffsetModeHighSpeed, image_200 },
3853 { 2.5, PixelOffsetModeHighSpeed, image_250 },
3854
3855 { 0.8, PixelOffsetModeHalf, image_080 }, /* 14 */
3856 { 1.0, PixelOffsetModeHalf, image_100 },
3857 { 1.2, PixelOffsetModeHalf, image_120_half, TRUE },
3858 { 1.5, PixelOffsetModeHalf, image_150_half, TRUE },
3859 { 1.8, PixelOffsetModeHalf, image_180 },
3860 { 2.0, PixelOffsetModeHalf, image_200_half, TRUE },
3861 { 2.5, PixelOffsetModeHalf, image_250_half, TRUE },
3862
3863 { 0.8, PixelOffsetModeHighQuality, image_080 }, /* 21 */
3864 { 1.0, PixelOffsetModeHighQuality, image_100 },
3865 { 1.2, PixelOffsetModeHighQuality, image_120_half, TRUE },
3866 { 1.5, PixelOffsetModeHighQuality, image_150_half, TRUE },
3867 { 1.8, PixelOffsetModeHighQuality, image_180 },
3868 { 2.0, PixelOffsetModeHighQuality, image_200_half, TRUE },
3869 { 2.5, PixelOffsetModeHighQuality, image_250_half, TRUE },
3870 };
3871 BYTE src_2x1[6] = { 0x80,0x80,0x80,0x80,0x80,0x80 };
3872 BYTE dst_8x1[24];
3873 GpStatus status;
3874 union
3875 {
3876 GpBitmap *bitmap;
3877 GpImage *image;
3878 } u1, u2;
3879 GpGraphics *graphics;
3880 GpMatrix *matrix;
3881 int i, match;
3882
3883 status = GdipCreateBitmapFromScan0(2, 1, 4, PixelFormat24bppRGB, src_2x1, &u1.bitmap);
3884 expect(Ok, status);
3885 status = GdipBitmapSetResolution(u1.bitmap, 100.0, 100.0);
3886 expect(Ok, status);
3887
3888 status = GdipCreateBitmapFromScan0(8, 1, 24, PixelFormat24bppRGB, dst_8x1, &u2.bitmap);
3889 expect(Ok, status);
3890 status = GdipBitmapSetResolution(u2.bitmap, 100.0, 100.0);
3891 expect(Ok, status);
3892 status = GdipGetImageGraphicsContext(u2.image, &graphics);
3893 expect(Ok, status);
3894 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3895 expect(Ok, status);
3896
3897 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3898 {
3899 status = GdipSetPixelOffsetMode(graphics, td[i].pixel_offset_mode);
3900 expect(Ok, status);
3901
3902 status = GdipCreateMatrix2(td[i].scale_x, 0.0, 0.0, 1.0, 0.0, 0.0, &matrix);
3903 expect(Ok, status);
3904 status = GdipSetWorldTransform(graphics, matrix);
3905 expect(Ok, status);
3906 GdipDeleteMatrix(matrix);
3907
3908 memcpy(dst_8x1, back_8x1, sizeof(dst_8x1));
3909 status = GdipDrawImageI(graphics, u1.image, 1, 0);
3910 expect(Ok, status);
3911
3912 match = memcmp(dst_8x1, td[i].image, sizeof(dst_8x1)) == 0;
3913 if (!match && td[i].todo)
3914 todo_wine ok(match, "%d: data should match\n", i);
3915 else
3916 ok(match, "%d: data should match\n", i);
3917 if (!match)
3918 {
3919 UINT i, size = sizeof(dst_8x1);
3920 const BYTE *bits = dst_8x1;
3921 for (i = 0; i < size; i++)
3922 printf(" %02x", bits[i]);
3923 printf("\n");
3924 }
3925 }
3926
3927 status = GdipDeleteGraphics(graphics);
3928 expect(Ok, status);
3929 status = GdipDisposeImage(u1.image);
3930 expect(Ok, status);
3931 status = GdipDisposeImage(u2.image);
3932 expect(Ok, status);
3933 }
3934
3935 static const BYTE animatedgif[] = {
3936 'G','I','F','8','9','a',0x01,0x00,0x01,0x00,0xA1,0x02,0x00,
3937 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,
3938 /*0x21,0xFF,0x0B,'A','N','I','M','E','X','T','S','1','.','0',*/
3939 0x21,0xFF,0x0B,'N','E','T','S','C','A','P','E','2','.','0',
3940 0x03,0x01,0x05,0x00,0x00,
3941 0x21,0xFE,0x0C,'H','e','l','l','o',' ','W','o','r','l','d','!',0x00,
3942 0x21,0x01,0x0D,'a','n','i','m','a','t','i','o','n','.','g','i','f',0x00,
3943 0x21,0xF9,0x04,0xff,0x0A,0x00,0x08,0x00,
3944 0x2C,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
3945 0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,
3946 0x02,0x02,0x4C,0x01,0x00,
3947 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','1',0x00,
3948 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','1',0x00,
3949 0x21,0xF9,0x04,0x00,0x14,0x00,0x01,0x00,
3950 0x2C,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,
3951 0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,
3952 0x02,0x02,0x44,0x01,0x00,
3953 0x21,0xFE,0x08,'i','m','a','g','e',' ','#','2',0x00,
3954 0x21,0x01,0x0C,'p','l','a','i','n','t','e','x','t',' ','#','2',0x00,0x3B
3955 };
3956
3957 static void test_gif_properties(void)
3958 {
3959 static const struct test_data
3960 {
3961 ULONG type, id, length;
3962 const BYTE value[13];
3963 } td[] =
3964 {
3965 { PropertyTagTypeLong, PropertyTagFrameDelay, 8, { 10,0,0,0,20,0,0,0 } },
3966 { PropertyTagTypeASCII, PropertyTagExifUserComment, 13, { 'H','e','l','l','o',' ','W','o','r','l','d','!',0 } },
3967 { PropertyTagTypeShort, PropertyTagLoopCount, 2, { 5,0 } },
3968 { PropertyTagTypeByte, PropertyTagGlobalPalette, 12, { 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c } },
3969 { PropertyTagTypeByte, PropertyTagIndexBackground, 1, { 2 } },
3970 { PropertyTagTypeByte, PropertyTagIndexTransparent, 1, { 8 } }
3971 };
3972 GpStatus status;
3973 GpImage *image;
3974 GUID guid;
3975 UINT dim_count, frame_count, prop_count, prop_size, i;
3976 UINT total_size, total_count;
3977 PROPID *prop_id;
3978 PropertyItem *prop_item;
3979 const char *item_data;
3980
3981 image = load_image(animatedgif, sizeof(animatedgif));
3982 if (!image) /* XP fails to load this GIF image */
3983 {
3984 trace("Failed to load GIF image data\n");
3985 return;
3986 }
3987
3988 status = GdipImageGetFrameDimensionsCount(image, &dim_count);
3989 expect(Ok, status);
3990 expect(1, dim_count);
3991
3992 status = GdipImageGetFrameDimensionsList(image, &guid, 1);
3993 expect(Ok, status);
3994 expect_guid(&FrameDimensionTime, &guid, __LINE__, FALSE);
3995
3996 status = GdipImageGetFrameCount(image, &guid, &frame_count);
3997 expect(Ok, status);
3998 expect(2, frame_count);
3999
4000 status = GdipImageSelectActiveFrame(image, &guid, 1);
4001 expect(Ok, status);
4002
4003 status = GdipGetPropertyCount(image, &prop_count);
4004 expect(Ok, status);
4005 ok(prop_count == sizeof(td)/sizeof(td[0]) || broken(prop_count == 1) /* before win7 */,
4006 "expected property count %u, got %u\n", (UINT)(sizeof(td)/sizeof(td[0])), prop_count);
4007
4008 if (prop_count != sizeof(td)/sizeof(td[0]))
4009 {
4010 GdipDisposeImage(image);
4011 return;
4012 }
4013
4014 prop_id = HeapAlloc(GetProcessHeap(), 0, prop_count * sizeof(*prop_id));
4015
4016 status = GdipGetPropertyIdList(image, prop_count, prop_id);
4017 expect(Ok, status);
4018
4019 prop_size = 0;
4020 for (i = 0; i < prop_count; i++)
4021 {
4022 UINT size;
4023 status = GdipGetPropertyItemSize(image, prop_id[i], &size);
4024 expect(Ok, status);
4025 if (status != Ok) break;
4026 ok(size > sizeof(*prop_item), "%u: too small item length %u\n", i, size);
4027
4028 prop_size += size;
4029
4030 prop_item = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
4031 status = GdipGetPropertyItem(image, prop_id[i], size, prop_item);
4032 expect(Ok, status);
4033 ok(prop_item->value == prop_item + 1, "expected item->value %p, got %p\n", prop_item + 1, prop_item->value);
4034 ok(td[i].type == prop_item->type,
4035 "%u: expected type %u, got %u\n", i, td[i].type, prop_item->type);
4036 ok(td[i].id == prop_item->id, "%u: expected id %#x, got %#x\n", i, td[i].id, prop_item->id);
4037 size -= sizeof(*prop_item);
4038 ok(prop_item->length == size, "%u: expected length %u, got %u\n", i, size, prop_item->length);
4039 ok(td[i].length == prop_item->length, "%u: expected length %u, got %u\n", i, td[i].length, prop_item->length);
4040 if (td[i].length == prop_item->length)
4041 {
4042 int match = memcmp(td[i].value, prop_item->value, td[i].length) == 0;
4043 ok(match, "%u: data mismatch\n", i);
4044 if (!match)
4045 {
4046 UINT j;
4047 BYTE *data = prop_item->value;
4048 printf("id %#x:", prop_item->id);
4049 for (j = 0; j < prop_item->length; j++)
4050 printf(" %02x", data[j]);
4051 printf("\n");
4052 }
4053 }
4054 HeapFree(GetProcessHeap(), 0, prop_item);
4055 }
4056
4057 HeapFree(GetProcessHeap(), 0, prop_id);
4058
4059 status = GdipGetPropertySize(NULL, &total_size, &total_count);
4060 expect(InvalidParameter, status);
4061 status = GdipGetPropertySize(image, &total_size, NULL);
4062 expect(InvalidParameter, status);
4063 status = GdipGetPropertySize(image, NULL, &total_count);
4064 expect(InvalidParameter, status);
4065 status = GdipGetPropertySize(image, NULL, NULL);
4066 expect(InvalidParameter, status);
4067 total_size = 0xdeadbeef;
4068 total_count = 0xdeadbeef;
4069 status = GdipGetPropertySize(image, &total_size, &total_count);
4070 expect(Ok, status);
4071 ok(prop_count == total_count,
4072 "expected total property count %u, got %u\n", prop_count, total_count);
4073 ok(prop_size == total_size,
4074 "expected total property size %u, got %u\n", prop_size, total_size);
4075
4076 prop_item = HeapAlloc(GetProcessHeap(), 0, prop_size);
4077
4078 status = GdipGetAllPropertyItems(image, 0, prop_count, prop_item);
4079 expect(InvalidParameter, status);
4080 status = GdipGetAllPropertyItems(image, prop_size, 1, prop_item);
4081 expect(InvalidParameter, status);
4082 status = GdipGetAllPropertyItems(image, prop_size, prop_count, NULL);
4083 expect(InvalidParameter, status);
4084 status = GdipGetAllPropertyItems(image, prop_size, prop_count, NULL);
4085 expect(InvalidParameter, status);
4086 status = GdipGetAllPropertyItems(image, 0, 0, NULL);
4087 expect(InvalidParameter, status);
4088 status = GdipGetAllPropertyItems(image, prop_size + 1, prop_count, prop_item);
4089 expect(InvalidParameter, status);
4090 status = GdipGetAllPropertyItems(image, prop_size, prop_count, prop_item);
4091 expect(Ok, status);
4092
4093 item_data = (const char *)(prop_item + prop_count);
4094 for (i = 0; i < prop_count; i++)
4095 {
4096 ok(prop_item[i].value == item_data, "%u: expected value %p, got %p\n",
4097 i, item_data, prop_item[i].value);
4098 ok(td[i].type == prop_item[i].type,
4099 "%u: expected type %u, got %u\n", i, td[i].type, prop_item[i].type);
4100 ok(td[i].id == prop_item[i].id, "%u: expected id %#x, got %#x\n", i, td[i].id, prop_item[i].id);
4101 ok(td[i].length == prop_item[i].length, "%u: expected length %u, got %u\n", i, td[i].length, prop_item[i].length);
4102 if (td[i].length == prop_item[i].length)
4103 {
4104 int match = memcmp(td[i].value, prop_item[i].value, td[i].length) == 0;
4105 ok(match, "%u: data mismatch\n", i);
4106 if (!match)
4107 {
4108 UINT j;
4109 BYTE *data = prop_item[i].value;
4110 printf("id %#x:", prop_item[i].id);
4111 for (j = 0; j < prop_item[i].length; j++)
4112 printf(" %02x", data[j]);
4113 printf("\n");
4114 }
4115 }
4116 item_data += prop_item[i].length;
4117 }
4118
4119 HeapFree(GetProcessHeap(), 0, prop_item);
4120
4121 GdipDisposeImage(image);
4122 }
4123
4124 static void test_ARGB_conversion(void)
4125 {
4126 BYTE argb[8] = { 0x11,0x22,0x33,0x80, 0xff,0xff,0xff,0 };
4127 BYTE pargb[8] = { 0x09,0x11,0x1a,0x80, 0,0,0,0 };
4128 BYTE rgb32_xp[8] = { 0x11,0x22,0x33,0xff, 0xff,0xff,0xff,0xff };
4129 BYTE rgb24[6] = { 0x11,0x22,0x33, 0xff,0xff,0xff };
4130 BYTE *bits;
4131 GpBitmap *bitmap;
4132 BitmapData data;
4133 GpStatus status;
4134 int match;
4135
4136 status = GdipCreateBitmapFromScan0(2, 1, 8, PixelFormat32bppARGB, argb, &bitmap);
4137 expect(Ok, status);
4138
4139 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat32bppPARGB, &data);
4140 expect(Ok, status);
4141 ok(data.Width == 2, "expected 2, got %d\n", data.Width);
4142 ok(data.Height == 1, "expected 1, got %d\n", data.Height);
4143 ok(data.Stride == 8, "expected 8, got %d\n", data.Stride);
4144 ok(data.PixelFormat == PixelFormat32bppPARGB, "expected PixelFormat32bppPARGB, got %d\n", data.PixelFormat);
4145 match = !memcmp(data.Scan0, pargb, sizeof(pargb));
4146 ok(match, "bits don't match\n");
4147 if (!match)
4148 {
4149 bits = data.Scan0;
4150 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat32bppPARGB,
4151 bits[0], bits[1], bits[2], bits[3], bits[4], bits[5], bits[6], bits[7]);
4152 }
4153 status = GdipBitmapUnlockBits(bitmap, &data);
4154 expect(Ok, status);
4155
4156 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat32bppRGB, &data);
4157 expect(Ok, status);
4158 ok(data.Width == 2, "expected 2, got %d\n", data.Width);
4159 ok(data.Height == 1, "expected 1, got %d\n", data.Height);
4160 ok(data.Stride == 8, "expected 8, got %d\n", data.Stride);
4161 ok(data.PixelFormat == PixelFormat32bppRGB, "expected PixelFormat32bppRGB, got %d\n", data.PixelFormat);
4162 match = !memcmp(data.Scan0, argb, sizeof(argb)) ||
4163 !memcmp(data.Scan0, rgb32_xp, sizeof(rgb32_xp));
4164 ok(match, "bits don't match\n");
4165 if (!match)
4166 {
4167 bits = data.Scan0;
4168 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat32bppRGB,
4169 bits[0], bits[1], bits[2], bits[3], bits[4], bits[5], bits[6], bits[7]);
4170 }
4171 status = GdipBitmapUnlockBits(bitmap, &data);
4172 expect(Ok, status);
4173
4174 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat24bppRGB, &data);
4175 expect(Ok, status);
4176 ok(data.Width == 2, "expected 2, got %d\n", data.Width);
4177 ok(data.Height == 1, "expected 1, got %d\n", data.Height);
4178 ok(data.Stride == 8, "expected 8, got %d\n", data.Stride);
4179 ok(data.PixelFormat == PixelFormat24bppRGB, "expected PixelFormat24bppRGB, got %d\n", data.PixelFormat);
4180 match = !memcmp(data.Scan0, rgb24, sizeof(rgb24));
4181 ok(match, "bits don't match\n");
4182 if (!match)
4183 {
4184 bits = data.Scan0;
4185 trace("format %#x, bits %02x,%02x,%02x,%02x %02x,%02x,%02x,%02x\n", PixelFormat24bppRGB,
4186 bits[0], bits[1], bits[2], bits[3], bits[4], bits[5], bits[6], bits[7]);
4187 }
4188 status = GdipBitmapUnlockBits(bitmap, &data);
4189 expect(Ok, status);
4190
4191 GdipDisposeImage((GpImage *)bitmap);
4192 }
4193
4194 START_TEST(image)
4195 {
4196 struct GdiplusStartupInput gdiplusStartupInput;
4197 ULONG_PTR gdiplusToken;
4198
4199 gdiplusStartupInput.GdiplusVersion = 1;
4200 gdiplusStartupInput.DebugEventCallback = NULL;
4201 gdiplusStartupInput.SuppressBackgroundThread = 0;
4202 gdiplusStartupInput.SuppressExternalCodecs = 0;
4203
4204 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
4205
4206 test_ARGB_conversion();
4207 test_DrawImage_scale();
4208 test_image_format();
4209 test_DrawImage();
4210 test_GdipDrawImagePointRect();
4211 test_bitmapbits();
4212 test_tiff_palette();
4213 test_GdipGetAllPropertyItems();
4214 test_tiff_properties();
4215 test_gif_properties();
4216 test_image_properties();
4217 test_Scan0();
4218 test_FromGdiDib();
4219 test_GetImageDimension();
4220 test_GdipImageGetFrameDimensionsCount();
4221 test_LoadingImages();
4222 test_SavingImages();
4223 test_encoders();
4224 test_LockBits();
4225 test_LockBits_UserBuf();
4226 test_GdipCreateBitmapFromHBITMAP();
4227 test_GdipGetImageFlags();
4228 test_GdipCloneImage();
4229 test_testcontrol();
4230 test_fromhicon();
4231 test_getrawformat();
4232 test_loadwmf();
4233 test_createfromwmf();
4234 test_resolution();
4235 test_createhbitmap();
4236 test_getthumbnail();
4237 test_getsetpixel();
4238 test_palette();
4239 test_colormatrix();
4240 test_gamma();
4241 test_multiframegif();
4242 test_rotateflip();
4243 test_remaptable();
4244 test_colorkey();
4245 test_dispose();
4246
4247 GdiplusShutdown(gdiplusToken);
4248 }