[GDIPLUS]
[reactos.git] / rostests / winetests / gdiplus / image.c
1 /*
2 * Unit test suite for images
3 *
4 * Copyright (C) 2007 Google (Evan Stade)
5 * Copyright (C) 2012 Dmitry Timoshkov
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #define COBJMACROS
23
24 #include <math.h>
25 #include <assert.h>
26 #include <stdio.h>
27
28 #include <initguid.h>
29 #define WIN32_NO_STATUS
30 #define _INC_WINDOWS
31 #define COM_NO_WINDOWS_H
32
33 //#include "windows.h"
34 #include <wine/test.h>
35 #include <wingdi.h>
36 #include <winnls.h>
37 #include <ole2.h>
38 #include <gdiplus.h>
39
40 #define expect(expected, got) ok((got) == (expected), "Expected %d, got %d\n", (UINT)(expected), (UINT)(got))
41 #define expectf(expected, got) ok(fabs((expected) - (got)) < 0.0001, "Expected %f, got %f\n", (expected), (got))
42
43 static BOOL color_match(ARGB c1, ARGB c2, BYTE max_diff)
44 {
45 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
46 c1 >>= 8; c2 >>= 8;
47 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
48 c1 >>= 8; c2 >>= 8;
49 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
50 c1 >>= 8; c2 >>= 8;
51 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
52 return TRUE;
53 }
54
55 static void expect_guid(REFGUID expected, REFGUID got, int line, BOOL todo)
56 {
57 WCHAR bufferW[39];
58 char buffer[39];
59 char buffer2[39];
60
61 StringFromGUID2(got, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
62 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer, sizeof(buffer), NULL, NULL);
63 StringFromGUID2(expected, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
64 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer2, sizeof(buffer2), NULL, NULL);
65 if(todo)
66 todo_wine ok_(__FILE__, line)(IsEqualGUID(expected, got), "Expected %s, got %s\n", buffer2, buffer);
67 else
68 ok_(__FILE__, line)(IsEqualGUID(expected, got), "Expected %s, got %s\n", buffer2, buffer);
69 }
70
71 static void expect_rawformat(REFGUID expected, GpImage *img, int line, BOOL todo)
72 {
73 GUID raw;
74 GpStatus stat;
75
76 stat = GdipGetImageRawFormat(img, &raw);
77 ok_(__FILE__, line)(stat == Ok, "GdipGetImageRawFormat failed with %d\n", stat);
78 if(stat != Ok) return;
79 expect_guid(expected, &raw, line, todo);
80 }
81
82 static void test_bufferrawformat(void* buff, int size, REFGUID expected, int line, BOOL todo)
83 {
84 LPSTREAM stream;
85 HGLOBAL hglob;
86 LPBYTE data;
87 HRESULT hres;
88 GpStatus stat;
89 GpImage *img;
90
91 hglob = GlobalAlloc (0, size);
92 data = GlobalLock (hglob);
93 memcpy(data, buff, size);
94 GlobalUnlock(hglob); data = NULL;
95
96 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
97 ok_(__FILE__, line)(hres == S_OK, "Failed to create a stream\n");
98 if(hres != S_OK) return;
99
100 stat = GdipLoadImageFromStream(stream, &img);
101 ok_(__FILE__, line)(stat == Ok, "Failed to create a Bitmap\n");
102 if(stat != Ok){
103 IStream_Release(stream);
104 return;
105 }
106
107 expect_rawformat(expected, img, line, todo);
108
109 GdipDisposeImage(img);
110 IStream_Release(stream);
111 }
112
113 static void test_Scan0(void)
114 {
115 GpBitmap *bm;
116 GpStatus stat;
117 BYTE buff[360];
118
119 bm = NULL;
120 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
121 expect(Ok, stat);
122 ok(NULL != bm, "Expected bitmap to be initialized\n");
123 if (stat == Ok)
124 GdipDisposeImage((GpImage*)bm);
125
126 bm = (GpBitmap*)0xdeadbeef;
127 stat = GdipCreateBitmapFromScan0(10, -10, 10, PixelFormat24bppRGB, NULL, &bm);
128 expect(InvalidParameter, stat);
129 ok( !bm, "expected null bitmap\n" );
130
131 bm = (GpBitmap*)0xdeadbeef;
132 stat = GdipCreateBitmapFromScan0(-10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
133 expect(InvalidParameter, stat);
134 ok( !bm, "expected null bitmap\n" );
135
136 bm = (GpBitmap*)0xdeadbeef;
137 stat = GdipCreateBitmapFromScan0(10, 0, 10, PixelFormat24bppRGB, NULL, &bm);
138 expect(InvalidParameter, stat);
139 ok( !bm, "expected null bitmap\n" );
140
141 bm = NULL;
142 stat = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, buff, &bm);
143 expect(Ok, stat);
144 ok(NULL != bm, "Expected bitmap to be initialized\n");
145 if (stat == Ok)
146 GdipDisposeImage((GpImage*)bm);
147
148 bm = (GpBitmap*) 0xdeadbeef;
149 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, buff, &bm);
150 expect(InvalidParameter, stat);
151 ok( !bm, "expected null bitmap\n" );
152
153 bm = (GpBitmap*)0xdeadbeef;
154 stat = GdipCreateBitmapFromScan0(10, 10, 0, PixelFormat24bppRGB, buff, &bm);
155 expect(InvalidParameter, stat);
156 ok( bm == (GpBitmap*)0xdeadbeef, "expected deadbeef bitmap\n" );
157
158 bm = NULL;
159 stat = GdipCreateBitmapFromScan0(10, 10, -8, PixelFormat24bppRGB, buff, &bm);
160 expect(Ok, stat);
161 ok(NULL != bm, "Expected bitmap to be initialized\n");
162 if (stat == Ok)
163 GdipDisposeImage((GpImage*)bm);
164
165 bm = (GpBitmap*)0xdeadbeef;
166 stat = GdipCreateBitmapFromScan0(10, 10, -10, PixelFormat24bppRGB, buff, &bm);
167 expect(InvalidParameter, stat);
168 ok( !bm, "expected null bitmap\n" );
169 }
170
171 static void test_FromGdiDib(void)
172 {
173 GpBitmap *bm;
174 GpStatus stat;
175 BYTE buff[400];
176 BYTE rbmi[sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)];
177 BITMAPINFO *bmi = (BITMAPINFO*)rbmi;
178 PixelFormat format;
179
180 bm = NULL;
181
182 memset(rbmi, 0, sizeof(rbmi));
183
184 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
185 bmi->bmiHeader.biWidth = 10;
186 bmi->bmiHeader.biHeight = 10;
187 bmi->bmiHeader.biPlanes = 1;
188 bmi->bmiHeader.biBitCount = 32;
189 bmi->bmiHeader.biCompression = BI_RGB;
190
191 stat = GdipCreateBitmapFromGdiDib(NULL, buff, &bm);
192 expect(InvalidParameter, stat);
193
194 stat = GdipCreateBitmapFromGdiDib(bmi, NULL, &bm);
195 expect(InvalidParameter, stat);
196
197 stat = GdipCreateBitmapFromGdiDib(bmi, buff, NULL);
198 expect(InvalidParameter, stat);
199
200 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
201 expect(Ok, stat);
202 ok(NULL != bm, "Expected bitmap to be initialized\n");
203 if (stat == Ok)
204 {
205 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
206 expect(Ok, stat);
207 expect(PixelFormat32bppRGB, format);
208
209 GdipDisposeImage((GpImage*)bm);
210 }
211
212 bmi->bmiHeader.biBitCount = 24;
213 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
214 expect(Ok, stat);
215 ok(NULL != bm, "Expected bitmap to be initialized\n");
216 if (stat == Ok)
217 {
218 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
219 expect(Ok, stat);
220 expect(PixelFormat24bppRGB, format);
221
222 GdipDisposeImage((GpImage*)bm);
223 }
224
225 bmi->bmiHeader.biBitCount = 16;
226 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
227 expect(Ok, stat);
228 ok(NULL != bm, "Expected bitmap to be initialized\n");
229 if (stat == Ok)
230 {
231 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
232 expect(Ok, stat);
233 expect(PixelFormat16bppRGB555, format);
234
235 GdipDisposeImage((GpImage*)bm);
236 }
237
238 bmi->bmiHeader.biBitCount = 8;
239 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
240 expect(Ok, stat);
241 ok(NULL != bm, "Expected bitmap to be initialized\n");
242 if (stat == Ok)
243 {
244 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
245 expect(Ok, stat);
246 expect(PixelFormat8bppIndexed, format);
247
248 GdipDisposeImage((GpImage*)bm);
249 }
250
251 bmi->bmiHeader.biBitCount = 4;
252 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
253 expect(Ok, stat);
254 ok(NULL != bm, "Expected bitmap to be initialized\n");
255 if (stat == Ok)
256 {
257 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
258 expect(Ok, stat);
259 expect(PixelFormat4bppIndexed, format);
260
261 GdipDisposeImage((GpImage*)bm);
262 }
263
264 bmi->bmiHeader.biBitCount = 1;
265 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
266 expect(Ok, stat);
267 ok(NULL != bm, "Expected bitmap to be initialized\n");
268 if (stat == Ok)
269 {
270 stat = GdipGetImagePixelFormat((GpImage*)bm, &format);
271 expect(Ok, stat);
272 expect(PixelFormat1bppIndexed, format);
273
274 GdipDisposeImage((GpImage*)bm);
275 }
276
277 bmi->bmiHeader.biBitCount = 0;
278 stat = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
279 expect(InvalidParameter, stat);
280 }
281
282 static void test_GetImageDimension(void)
283 {
284 GpBitmap *bm;
285 GpStatus stat;
286 const REAL WIDTH = 10.0, HEIGHT = 20.0;
287 REAL w,h;
288
289 bm = (GpBitmap*)0xdeadbeef;
290 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
291 expect(Ok,stat);
292 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
293 ok(NULL != bm, "Expected bitmap to not be NULL\n");
294
295 stat = GdipGetImageDimension(NULL,&w,&h);
296 expect(InvalidParameter, stat);
297
298 stat = GdipGetImageDimension((GpImage*)bm,NULL,&h);
299 expect(InvalidParameter, stat);
300
301 stat = GdipGetImageDimension((GpImage*)bm,&w,NULL);
302 expect(InvalidParameter, stat);
303
304 w = -1;
305 h = -1;
306 stat = GdipGetImageDimension((GpImage*)bm,&w,&h);
307 expect(Ok, stat);
308 expectf(WIDTH, w);
309 expectf(HEIGHT, h);
310 GdipDisposeImage((GpImage*)bm);
311 }
312
313 static void test_GdipImageGetFrameDimensionsCount(void)
314 {
315 GpBitmap *bm;
316 GpStatus stat;
317 const REAL WIDTH = 10.0, HEIGHT = 20.0;
318 UINT w;
319 GUID dimension = {0};
320 UINT count;
321 ARGB color;
322
323 bm = (GpBitmap*)0xdeadbeef;
324 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
325 expect(Ok,stat);
326 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
327 ok(NULL != bm, "Expected bitmap to not be NULL\n");
328
329 stat = GdipImageGetFrameDimensionsCount(NULL,&w);
330 expect(InvalidParameter, stat);
331
332 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,NULL);
333 expect(InvalidParameter, stat);
334
335 w = -1;
336 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,&w);
337 expect(Ok, stat);
338 expect(1, w);
339
340 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 1);
341 expect(Ok, stat);
342 expect_guid(&FrameDimensionPage, &dimension, __LINE__, FALSE);
343
344 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 2);
345 expect(InvalidParameter, stat);
346
347 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 0);
348 expect(InvalidParameter, stat);
349
350 stat = GdipImageGetFrameCount(NULL, &dimension, &count);
351 expect(InvalidParameter, stat);
352
353 /* WinXP crashes on this test */
354 if(0)
355 {
356 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, NULL);
357 expect(InvalidParameter, stat);
358 }
359
360 stat = GdipImageGetFrameCount((GpImage*)bm, NULL, &count);
361 expect(Ok, stat);
362
363 count = 12345;
364 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, &count);
365 expect(Ok, stat);
366 expect(1, count);
367
368 GdipBitmapSetPixel(bm, 0, 0, 0xffffffff);
369
370 stat = GdipImageSelectActiveFrame((GpImage*)bm, &dimension, 0);
371 expect(Ok, stat);
372
373 /* SelectActiveFrame has no effect on image data of memory bitmaps */
374 color = 0xdeadbeef;
375 GdipBitmapGetPixel(bm, 0, 0, &color);
376 expect(0xffffffff, color);
377
378 GdipDisposeImage((GpImage*)bm);
379 }
380
381 static void test_LoadingImages(void)
382 {
383 GpStatus stat;
384
385 stat = GdipCreateBitmapFromFile(0, 0);
386 expect(InvalidParameter, stat);
387
388 stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
389 expect(InvalidParameter, stat);
390
391 stat = GdipLoadImageFromFile(0, 0);
392 expect(InvalidParameter, stat);
393
394 stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
395 expect(InvalidParameter, stat);
396
397 stat = GdipLoadImageFromFileICM(0, 0);
398 expect(InvalidParameter, stat);
399
400 stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
401 expect(InvalidParameter, stat);
402 }
403
404 static void test_SavingImages(void)
405 {
406 GpStatus stat;
407 GpBitmap *bm;
408 UINT n;
409 UINT s;
410 const REAL WIDTH = 10.0, HEIGHT = 20.0;
411 REAL w, h;
412 ImageCodecInfo *codecs;
413 static const CHAR filenameA[] = "a.bmp";
414 static const WCHAR filename[] = { 'a','.','b','m','p',0 };
415
416 codecs = NULL;
417
418 stat = GdipSaveImageToFile(0, 0, 0, 0);
419 expect(InvalidParameter, stat);
420
421 bm = NULL;
422 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
423 expect(Ok, stat);
424 if (!bm)
425 return;
426
427 /* invalid params */
428 stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
429 expect(InvalidParameter, stat);
430
431 stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
432 expect(InvalidParameter, stat);
433
434 /* encoder tests should succeed -- already tested */
435 stat = GdipGetImageEncodersSize(&n, &s);
436 if (stat != Ok || n == 0) goto cleanup;
437
438 codecs = GdipAlloc(s);
439 if (!codecs) goto cleanup;
440
441 stat = GdipGetImageEncoders(n, s, codecs);
442 if (stat != Ok) goto cleanup;
443
444 stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
445 expect(Ok, stat);
446
447 GdipDisposeImage((GpImage*)bm);
448 bm = 0;
449
450 /* re-load and check image stats */
451 stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
452 expect(Ok, stat);
453 if (stat != Ok) goto cleanup;
454
455 stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
456 if (stat != Ok) goto cleanup;
457
458 expectf(WIDTH, w);
459 expectf(HEIGHT, h);
460
461 cleanup:
462 GdipFree(codecs);
463 if (bm)
464 GdipDisposeImage((GpImage*)bm);
465 ok(DeleteFileA(filenameA), "Delete failed.\n");
466 }
467
468 static void test_encoders(void)
469 {
470 GpStatus stat;
471 UINT n;
472 UINT s;
473 ImageCodecInfo *codecs;
474 int i;
475 int bmp_found;
476
477 static const CHAR bmp_format[] = "BMP";
478
479 stat = GdipGetImageEncodersSize(&n, &s);
480 expect(stat, Ok);
481
482 codecs = GdipAlloc(s);
483 if (!codecs)
484 return;
485
486 stat = GdipGetImageEncoders(n, s, NULL);
487 expect(GenericError, stat);
488
489 stat = GdipGetImageEncoders(0, s, codecs);
490 expect(GenericError, stat);
491
492 stat = GdipGetImageEncoders(n, s-1, codecs);
493 expect(GenericError, stat);
494
495 stat = GdipGetImageEncoders(n, s+1, codecs);
496 expect(GenericError, stat);
497
498 stat = GdipGetImageEncoders(n, s, codecs);
499 expect(stat, Ok);
500
501 bmp_found = FALSE;
502 for (i = 0; i < n; i++)
503 {
504 CHAR desc[32];
505
506 WideCharToMultiByte(CP_ACP, 0, codecs[i].FormatDescription, -1,
507 desc, 32, 0, 0);
508
509 if (CompareStringA(LOCALE_SYSTEM_DEFAULT, 0,
510 desc, -1,
511 bmp_format, -1) == CSTR_EQUAL) {
512 bmp_found = TRUE;
513 break;
514 }
515 }
516 if (!bmp_found)
517 ok(FALSE, "No BMP codec found.\n");
518
519 GdipFree(codecs);
520 }
521
522 static void test_LockBits(void)
523 {
524 GpStatus stat;
525 GpBitmap *bm;
526 GpRect rect;
527 BitmapData bd;
528 const INT WIDTH = 10, HEIGHT = 20;
529 ARGB color;
530 int y;
531
532 bm = NULL;
533 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
534 expect(Ok, stat);
535
536 rect.X = 2;
537 rect.Y = 3;
538 rect.Width = 4;
539 rect.Height = 5;
540
541 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffc30000);
542 expect(Ok, stat);
543
544 stat = GdipBitmapSetPixel(bm, 2, 8, 0xff480000);
545 expect(Ok, stat);
546
547 /* read-only */
548 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
549 expect(Ok, stat);
550
551 if (stat == Ok) {
552 expect(0xc3, ((BYTE*)bd.Scan0)[2]);
553 expect(0x48, ((BYTE*)bd.Scan0)[2 + bd.Stride * 5]);
554
555 ((char*)bd.Scan0)[2] = 0xff;
556
557 stat = GdipBitmapUnlockBits(bm, &bd);
558 expect(Ok, stat);
559 }
560
561 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
562 expect(Ok, stat);
563 expect(0xffff0000, color);
564
565 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffc30000);
566 expect(Ok, stat);
567
568 /* read-only, with NULL rect -> whole bitmap lock */
569 stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
570 expect(Ok, stat);
571 expect(bd.Width, WIDTH);
572 expect(bd.Height, HEIGHT);
573
574 if (stat == Ok) {
575 ((char*)bd.Scan0)[2 + 2*3 + 3*bd.Stride] = 0xff;
576
577 stat = GdipBitmapUnlockBits(bm, &bd);
578 expect(Ok, stat);
579 }
580
581 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
582 expect(Ok, stat);
583 expect(0xffff0000, color);
584
585 /* read-only, consecutive */
586 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
587 expect(Ok, stat);
588
589 if (stat == Ok) {
590 stat = GdipBitmapUnlockBits(bm, &bd);
591 expect(Ok, stat);
592 }
593
594 stat = GdipDisposeImage((GpImage*)bm);
595 expect(Ok, stat);
596 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
597 expect(Ok, stat);
598
599 /* read x2 */
600 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
601 expect(Ok, stat);
602 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
603 expect(WrongState, stat);
604
605 stat = GdipBitmapUnlockBits(bm, &bd);
606 expect(Ok, stat);
607
608 stat = GdipDisposeImage((GpImage*)bm);
609 expect(Ok, stat);
610 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
611 expect(Ok, stat);
612
613 stat = GdipBitmapSetPixel(bm, 2, 3, 0xffff0000);
614 expect(Ok, stat);
615
616 stat = GdipBitmapSetPixel(bm, 2, 8, 0xffc30000);
617 expect(Ok, stat);
618
619 /* write, no conversion */
620 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
621 expect(Ok, stat);
622
623 if (stat == Ok) {
624 /* all bits are readable, inside the rect or not */
625 expect(0xff, ((BYTE*)bd.Scan0)[2]);
626 expect(0xc3, ((BYTE*)bd.Scan0)[2 + bd.Stride * 5]);
627
628 stat = GdipBitmapUnlockBits(bm, &bd);
629 expect(Ok, stat);
630 }
631
632 /* read, conversion */
633 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat32bppARGB, &bd);
634 expect(Ok, stat);
635
636 if (stat == Ok) {
637 expect(0xff, ((BYTE*)bd.Scan0)[2]);
638 if (0)
639 /* Areas outside the rectangle appear to be uninitialized */
640 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
641
642 ((BYTE*)bd.Scan0)[2] = 0xc3;
643
644 stat = GdipBitmapUnlockBits(bm, &bd);
645 expect(Ok, stat);
646 }
647
648 /* writes do not work in read mode if there was a conversion */
649 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
650 expect(Ok, stat);
651 expect(0xffff0000, color);
652
653 /* read/write, conversion */
654 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeWrite, PixelFormat32bppARGB, &bd);
655 expect(Ok, stat);
656
657 if (stat == Ok) {
658 expect(0xff, ((BYTE*)bd.Scan0)[2]);
659 ((BYTE*)bd.Scan0)[1] = 0x88;
660 if (0)
661 /* Areas outside the rectangle appear to be uninitialized */
662 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
663
664 stat = GdipBitmapUnlockBits(bm, &bd);
665 expect(Ok, stat);
666 }
667
668 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
669 expect(Ok, stat);
670 expect(0xffff8800, color);
671
672 /* write, conversion */
673 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat32bppARGB, &bd);
674 expect(Ok, stat);
675
676 if (stat == Ok) {
677 if (0)
678 {
679 /* This is completely uninitialized. */
680 ok(0xff != ((BYTE*)bd.Scan0)[2], "original image bits are readable\n");
681 ok(0xc3 != ((BYTE*)bd.Scan0)[2 + bd.Stride * 5], "original image bits are readable\n");
682 }
683
684 /* Initialize the buffer so the unlock doesn't access undefined memory */
685 for (y=0; y<5; y++)
686 memset(((BYTE*)bd.Scan0) + bd.Stride * y, 0, 12);
687
688 ((BYTE*)bd.Scan0)[0] = 0x12;
689 ((BYTE*)bd.Scan0)[1] = 0x34;
690 ((BYTE*)bd.Scan0)[2] = 0x56;
691
692 stat = GdipBitmapUnlockBits(bm, &bd);
693 expect(Ok, stat);
694 }
695
696 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
697 expect(Ok, stat);
698 expect(0xff563412, color);
699
700 stat = GdipBitmapGetPixel(bm, 2, 8, &color);
701 expect(Ok, stat);
702 expect(0xffc30000, color);
703
704 stat = GdipDisposeImage((GpImage*)bm);
705 expect(Ok, stat);
706 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
707 expect(Ok, stat);
708
709 /* write, no modification */
710 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
711 expect(Ok, stat);
712
713 if (stat == Ok) {
714 stat = GdipBitmapUnlockBits(bm, &bd);
715 expect(Ok, stat);
716 }
717
718 /* write, consecutive */
719 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
720 expect(Ok, stat);
721
722 if (stat == Ok) {
723 stat = GdipBitmapUnlockBits(bm, &bd);
724 expect(Ok, stat);
725 }
726
727 stat = GdipDisposeImage((GpImage*)bm);
728 expect(Ok, stat);
729 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
730 expect(Ok, stat);
731
732 /* write, modify */
733 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
734 expect(Ok, stat);
735
736 if (stat == Ok) {
737 if (bd.Scan0)
738 ((char*)bd.Scan0)[2] = 0xff;
739
740 stat = GdipBitmapUnlockBits(bm, &bd);
741 expect(Ok, stat);
742 }
743
744 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
745 expect(Ok, stat);
746 expect(0xffff0000, color);
747
748 stat = GdipDisposeImage((GpImage*)bm);
749 expect(Ok, stat);
750
751 /* dispose locked */
752 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
753 expect(Ok, stat);
754 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
755 expect(Ok, stat);
756 stat = GdipDisposeImage((GpImage*)bm);
757 expect(Ok, stat);
758 }
759
760 static void test_LockBits_UserBuf(void)
761 {
762 GpStatus stat;
763 GpBitmap *bm;
764 GpRect rect;
765 BitmapData bd;
766 const INT WIDTH = 10, HEIGHT = 20;
767 DWORD bits[200];
768 ARGB color;
769
770 bm = NULL;
771 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat32bppARGB, NULL, &bm);
772 expect(Ok, stat);
773
774 memset(bits, 0xaa, sizeof(bits));
775
776 rect.X = 2;
777 rect.Y = 3;
778 rect.Width = 4;
779 rect.Height = 5;
780
781 bd.Width = 4;
782 bd.Height = 6;
783 bd.Stride = WIDTH * 4;
784 bd.PixelFormat = PixelFormat32bppARGB;
785 bd.Scan0 = &bits[2+3*WIDTH];
786 bd.Reserved = 0xaaaaaaaa;
787
788 /* read-only */
789 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
790 expect(Ok, stat);
791
792 expect(0xaaaaaaaa, bits[0]);
793 expect(0, bits[2+3*WIDTH]);
794
795 bits[2+3*WIDTH] = 0xdeadbeef;
796
797 if (stat == Ok) {
798 stat = GdipBitmapUnlockBits(bm, &bd);
799 expect(Ok, stat);
800 }
801
802 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
803 expect(Ok, stat);
804 expect(0, color);
805
806 /* write-only */
807 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
808 expect(Ok, stat);
809
810 expect(0xdeadbeef, bits[2+3*WIDTH]);
811 bits[2+3*WIDTH] = 0x12345678;
812
813 if (stat == Ok) {
814 stat = GdipBitmapUnlockBits(bm, &bd);
815 expect(Ok, stat);
816 }
817
818 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
819 expect(Ok, stat);
820 expect(0x12345678, color);
821
822 bits[2+3*WIDTH] = 0;
823
824 /* read/write */
825 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead|ImageLockModeWrite|ImageLockModeUserInputBuf, PixelFormat32bppARGB, &bd);
826 expect(Ok, stat);
827
828 expect(0x12345678, bits[2+3*WIDTH]);
829 bits[2+3*WIDTH] = 0xdeadbeef;
830
831 if (stat == Ok) {
832 stat = GdipBitmapUnlockBits(bm, &bd);
833 expect(Ok, stat);
834 }
835
836 stat = GdipBitmapGetPixel(bm, 2, 3, &color);
837 expect(Ok, stat);
838 expect(0xdeadbeef, color);
839
840 stat = GdipDisposeImage((GpImage*)bm);
841 expect(Ok, stat);
842 }
843
844 struct BITMAPINFOWITHBITFIELDS
845 {
846 BITMAPINFOHEADER bmiHeader;
847 DWORD masks[3];
848 };
849
850 union BITMAPINFOUNION
851 {
852 BITMAPINFO bi;
853 struct BITMAPINFOWITHBITFIELDS bf;
854 };
855
856 static void test_GdipCreateBitmapFromHBITMAP(void)
857 {
858 GpBitmap* gpbm = NULL;
859 HBITMAP hbm = NULL;
860 HPALETTE hpal = NULL;
861 GpStatus stat;
862 BYTE buff[1000];
863 LOGPALETTE* LogPal = NULL;
864 REAL width, height;
865 const REAL WIDTH1 = 5;
866 const REAL HEIGHT1 = 15;
867 const REAL WIDTH2 = 10;
868 const REAL HEIGHT2 = 20;
869 HDC hdc;
870 union BITMAPINFOUNION bmi;
871 BYTE *bits;
872 PixelFormat format;
873
874 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
875 expect(InvalidParameter, stat);
876
877 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
878 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
879 expect(InvalidParameter, stat);
880
881 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
882 expect(Ok, stat);
883 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
884 expectf(WIDTH1, width);
885 expectf(HEIGHT1, height);
886 if (stat == Ok)
887 GdipDisposeImage((GpImage*)gpbm);
888 DeleteObject(hbm);
889
890 memset(buff, 0, sizeof(buff));
891 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
892 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
893 expect(Ok, stat);
894 /* raw format */
895 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
896
897 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
898 expectf(WIDTH2, width);
899 expectf(HEIGHT2, height);
900 if (stat == Ok)
901 GdipDisposeImage((GpImage*)gpbm);
902 DeleteObject(hbm);
903
904 hdc = CreateCompatibleDC(0);
905 ok(hdc != NULL, "CreateCompatibleDC failed\n");
906 bmi.bi.bmiHeader.biSize = sizeof(bmi.bi.bmiHeader);
907 bmi.bi.bmiHeader.biHeight = HEIGHT1;
908 bmi.bi.bmiHeader.biWidth = WIDTH1;
909 bmi.bi.bmiHeader.biBitCount = 24;
910 bmi.bi.bmiHeader.biPlanes = 1;
911 bmi.bi.bmiHeader.biCompression = BI_RGB;
912 bmi.bi.bmiHeader.biClrUsed = 0;
913
914 hbm = CreateDIBSection(hdc, &bmi.bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
915 ok(hbm != NULL, "CreateDIBSection failed\n");
916
917 bits[0] = 0;
918
919 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
920 expect(Ok, stat);
921 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
922 expectf(WIDTH1, width);
923 expectf(HEIGHT1, height);
924 if (stat == Ok)
925 {
926 /* test whether writing to the bitmap affects the original */
927 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
928 expect(Ok, stat);
929
930 expect(0, bits[0]);
931
932 GdipDisposeImage((GpImage*)gpbm);
933 }
934
935 LogPal = GdipAlloc(sizeof(LOGPALETTE));
936 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
937 LogPal->palVersion = 0x300;
938 LogPal->palNumEntries = 1;
939 hpal = CreatePalette(LogPal);
940 ok(hpal != NULL, "CreatePalette failed\n");
941 GdipFree(LogPal);
942
943 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
944 expect(Ok, stat);
945
946 if (stat == Ok)
947 GdipDisposeImage((GpImage*)gpbm);
948
949 DeleteObject(hpal);
950 DeleteObject(hbm);
951
952 /* 16-bit 555 dib, rgb */
953 bmi.bi.bmiHeader.biBitCount = 16;
954 bmi.bi.bmiHeader.biCompression = BI_RGB;
955
956 hbm = CreateDIBSection(hdc, &bmi.bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
957 ok(hbm != NULL, "CreateDIBSection failed\n");
958
959 bits[0] = 0;
960
961 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
962 expect(Ok, stat);
963
964 if (stat == Ok)
965 {
966 stat = GdipGetImageDimension((GpImage*) gpbm, &width, &height);
967 expect(Ok, stat);
968 expectf(WIDTH1, width);
969 expectf(HEIGHT1, height);
970
971 stat = GdipGetImagePixelFormat((GpImage*) gpbm, &format);
972 expect(Ok, stat);
973 expect(PixelFormat16bppRGB555, format);
974
975 GdipDisposeImage((GpImage*)gpbm);
976 }
977 DeleteObject(hbm);
978
979 /* 16-bit 555 dib, with bitfields */
980 bmi.bi.bmiHeader.biSize = sizeof(bmi);
981 bmi.bi.bmiHeader.biCompression = BI_BITFIELDS;
982 bmi.bf.masks[0] = 0x7c00;
983 bmi.bf.masks[1] = 0x3e0;
984 bmi.bf.masks[2] = 0x1f;
985
986 hbm = CreateDIBSection(hdc, &bmi.bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
987 ok(hbm != NULL, "CreateDIBSection failed\n");
988
989 bits[0] = 0;
990
991 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
992 expect(Ok, stat);
993
994 if (stat == Ok)
995 {
996 stat = GdipGetImageDimension((GpImage*) gpbm, &width, &height);
997 expect(Ok, stat);
998 expectf(WIDTH1, width);
999 expectf(HEIGHT1, height);
1000
1001 stat = GdipGetImagePixelFormat((GpImage*) gpbm, &format);
1002 expect(Ok, stat);
1003 expect(PixelFormat16bppRGB555, format);
1004
1005 GdipDisposeImage((GpImage*)gpbm);
1006 }
1007 DeleteObject(hbm);
1008
1009 /* 16-bit 565 dib, with bitfields */
1010 bmi.bf.masks[0] = 0xf800;
1011 bmi.bf.masks[1] = 0x7e0;
1012 bmi.bf.masks[2] = 0x1f;
1013
1014 hbm = CreateDIBSection(hdc, &bmi.bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
1015 ok(hbm != NULL, "CreateDIBSection failed\n");
1016
1017 bits[0] = 0;
1018
1019 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
1020 expect(Ok, stat);
1021
1022 if (stat == Ok)
1023 {
1024 stat = GdipGetImageDimension((GpImage*) gpbm, &width, &height);
1025 expect(Ok, stat);
1026 expectf(WIDTH1, width);
1027 expectf(HEIGHT1, height);
1028
1029 stat = GdipGetImagePixelFormat((GpImage*) gpbm, &format);
1030 expect(Ok, stat);
1031 expect(PixelFormat16bppRGB565, format);
1032
1033 GdipDisposeImage((GpImage*)gpbm);
1034 }
1035 DeleteObject(hbm);
1036
1037 DeleteDC(hdc);
1038 }
1039
1040 static void test_GdipGetImageFlags(void)
1041 {
1042 GpImage *img;
1043 GpStatus stat;
1044 UINT flags;
1045
1046 img = (GpImage*)0xdeadbeef;
1047
1048 stat = GdipGetImageFlags(NULL, NULL);
1049 expect(InvalidParameter, stat);
1050
1051 stat = GdipGetImageFlags(NULL, &flags);
1052 expect(InvalidParameter, stat);
1053
1054 stat = GdipGetImageFlags(img, NULL);
1055 expect(InvalidParameter, stat);
1056
1057 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, (GpBitmap**)&img);
1058 expect(Ok, stat);
1059 stat = GdipGetImageFlags(img, &flags);
1060 expect(Ok, stat);
1061 expect(ImageFlagsHasAlpha, flags);
1062 GdipDisposeImage(img);
1063
1064 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, (GpBitmap**)&img);
1065 expect(Ok, stat);
1066 stat = GdipGetImageFlags(img, &flags);
1067 expect(Ok, stat);
1068 expect(ImageFlagsHasAlpha, flags);
1069 GdipDisposeImage(img);
1070
1071 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, (GpBitmap**)&img);
1072 expect(Ok, stat);
1073 stat = GdipGetImageFlags(img, &flags);
1074 expect(Ok, stat);
1075 expect(ImageFlagsHasAlpha, flags);
1076 GdipDisposeImage(img);
1077
1078 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, (GpBitmap**)&img);
1079 expect(Ok, stat);
1080 stat = GdipGetImageFlags(img, &flags);
1081 expect(Ok, stat);
1082 expect(ImageFlagsNone, flags);
1083 GdipDisposeImage(img);
1084
1085 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, (GpBitmap**)&img);
1086 expect(Ok, stat);
1087 stat = GdipGetImageFlags(img, &flags);
1088 expect(Ok, stat);
1089 expect(ImageFlagsNone, flags);
1090 GdipDisposeImage(img);
1091
1092 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, (GpBitmap**)&img);
1093 expect(Ok, stat);
1094 stat = GdipGetImageFlags(img, &flags);
1095 expect(Ok, stat);
1096 expect(ImageFlagsNone, flags);
1097 GdipDisposeImage(img);
1098
1099 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppARGB1555, NULL, (GpBitmap**)&img);
1100 expect(Ok, stat);
1101 stat = GdipGetImageFlags(img, &flags);
1102 expect(Ok, stat);
1103 expect(ImageFlagsHasAlpha, flags);
1104 GdipDisposeImage(img);
1105
1106 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, (GpBitmap**)&img);
1107 expect(Ok, stat);
1108 stat = GdipGetImageFlags(img, &flags);
1109 expect(Ok, stat);
1110 expect(ImageFlagsNone, flags);
1111 GdipDisposeImage(img);
1112
1113 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, (GpBitmap**)&img);
1114 expect(Ok, stat);
1115 stat = GdipGetImageFlags(img, &flags);
1116 expect(Ok, stat);
1117 expect(ImageFlagsNone, flags);
1118 GdipDisposeImage(img);
1119
1120 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, (GpBitmap**)&img);
1121 expect(Ok, stat);
1122 stat = GdipGetImageFlags(img, &flags);
1123 expect(Ok, stat);
1124 expect(ImageFlagsHasAlpha, flags);
1125 GdipDisposeImage(img);
1126
1127 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppPARGB, NULL, (GpBitmap**)&img);
1128 expect(Ok, stat);
1129 stat = GdipGetImageFlags(img, &flags);
1130 expect(Ok, stat);
1131 expect(ImageFlagsHasAlpha, flags);
1132 GdipDisposeImage(img);
1133
1134 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, (GpBitmap**)&img);
1135 expect(Ok, stat);
1136 if (stat == Ok)
1137 {
1138 stat = GdipGetImageFlags(img, &flags);
1139 expect(Ok, stat);
1140 expect(ImageFlagsNone, flags);
1141 GdipDisposeImage(img);
1142 }
1143
1144 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, (GpBitmap**)&img);
1145 expect(Ok, stat);
1146 if (stat == Ok)
1147 {
1148 expect(Ok, stat);
1149 stat = GdipGetImageFlags(img, &flags);
1150 expect(Ok, stat);
1151 expect(ImageFlagsHasAlpha, flags);
1152 GdipDisposeImage(img);
1153 }
1154
1155 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, (GpBitmap**)&img);
1156 expect(Ok, stat);
1157 if (stat == Ok)
1158 {
1159 expect(Ok, stat);
1160 stat = GdipGetImageFlags(img, &flags);
1161 expect(Ok, stat);
1162 expect(ImageFlagsHasAlpha, flags);
1163 GdipDisposeImage(img);
1164 }
1165 }
1166
1167 static void test_GdipCloneImage(void)
1168 {
1169 GpStatus stat;
1170 GpRectF rectF;
1171 GpUnit unit;
1172 GpBitmap *bm;
1173 GpImage *image_src, *image_dest = NULL;
1174 const INT WIDTH = 10, HEIGHT = 20;
1175
1176 /* Create an image, clone it, delete the original, make sure the copy works */
1177 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
1178 expect(Ok, stat);
1179 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
1180
1181 image_src = ((GpImage*)bm);
1182 stat = GdipCloneImage(image_src, &image_dest);
1183 expect(Ok, stat);
1184 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
1185
1186 stat = GdipDisposeImage((GpImage*)bm);
1187 expect(Ok, stat);
1188 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
1189 expect(Ok, stat);
1190
1191 /* Treat FP values carefully */
1192 expectf((REAL)WIDTH, rectF.Width);
1193 expectf((REAL)HEIGHT, rectF.Height);
1194
1195 stat = GdipDisposeImage(image_dest);
1196 expect(Ok, stat);
1197 }
1198
1199 static void test_testcontrol(void)
1200 {
1201 GpStatus stat;
1202 DWORD param;
1203
1204 param = 0;
1205 stat = GdipTestControl(TestControlGetBuildNumber, &param);
1206 expect(Ok, stat);
1207 ok(param != 0, "Build number expected, got %u\n", param);
1208 }
1209
1210 static void test_fromhicon(void)
1211 {
1212 static const BYTE bmp_bits[1024];
1213 HBITMAP hbmMask, hbmColor;
1214 ICONINFO info;
1215 HICON hIcon;
1216 GpStatus stat;
1217 GpBitmap *bitmap = NULL;
1218 UINT dim;
1219 ImageType type;
1220 PixelFormat format;
1221
1222 /* NULL */
1223 stat = GdipCreateBitmapFromHICON(NULL, NULL);
1224 expect(InvalidParameter, stat);
1225 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
1226 expect(InvalidParameter, stat);
1227
1228 /* color icon 1 bit */
1229 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
1230 ok(hbmMask != 0, "CreateBitmap failed\n");
1231 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
1232 ok(hbmColor != 0, "CreateBitmap failed\n");
1233 info.fIcon = TRUE;
1234 info.xHotspot = 8;
1235 info.yHotspot = 8;
1236 info.hbmMask = hbmMask;
1237 info.hbmColor = hbmColor;
1238 hIcon = CreateIconIndirect(&info);
1239 ok(hIcon != 0, "CreateIconIndirect failed\n");
1240 DeleteObject(hbmMask);
1241 DeleteObject(hbmColor);
1242
1243 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
1244 ok(stat == Ok ||
1245 broken(stat == InvalidParameter), /* Win98 */
1246 "Expected Ok, got %.8x\n", stat);
1247 if(stat == Ok){
1248 /* check attributes */
1249 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
1250 expect(Ok, stat);
1251 expect(16, dim);
1252 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
1253 expect(Ok, stat);
1254 expect(16, dim);
1255 stat = GdipGetImageType((GpImage*)bitmap, &type);
1256 expect(Ok, stat);
1257 expect(ImageTypeBitmap, type);
1258 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
1259 expect(Ok, stat);
1260 expect(PixelFormat32bppARGB, format);
1261 /* raw format */
1262 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
1263 GdipDisposeImage((GpImage*)bitmap);
1264 }
1265 DestroyIcon(hIcon);
1266
1267 /* color icon 8 bpp */
1268 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
1269 ok(hbmMask != 0, "CreateBitmap failed\n");
1270 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
1271 ok(hbmColor != 0, "CreateBitmap failed\n");
1272 info.fIcon = TRUE;
1273 info.xHotspot = 8;
1274 info.yHotspot = 8;
1275 info.hbmMask = hbmMask;
1276 info.hbmColor = hbmColor;
1277 hIcon = CreateIconIndirect(&info);
1278 ok(hIcon != 0, "CreateIconIndirect failed\n");
1279 DeleteObject(hbmMask);
1280 DeleteObject(hbmColor);
1281
1282 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
1283 expect(Ok, stat);
1284 if(stat == Ok){
1285 /* check attributes */
1286 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
1287 expect(Ok, stat);
1288 expect(16, dim);
1289 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
1290 expect(Ok, stat);
1291 expect(16, dim);
1292 stat = GdipGetImageType((GpImage*)bitmap, &type);
1293 expect(Ok, stat);
1294 expect(ImageTypeBitmap, type);
1295 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
1296 expect(Ok, stat);
1297 expect(PixelFormat32bppARGB, format);
1298 /* raw format */
1299 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
1300 GdipDisposeImage((GpImage*)bitmap);
1301 }
1302 DestroyIcon(hIcon);
1303 }
1304
1305 /* 1x1 pixel png */
1306 static const unsigned char pngimage[285] = {
1307 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
1308 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
1309 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
1310 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
1311 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
1312 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
1313 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
1314 };
1315 /* 1x1 pixel gif */
1316 static const unsigned char gifimage[35] = {
1317 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
1318 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
1319 0x01,0x00,0x3b
1320 };
1321 /* 1x1 pixel bmp */
1322 static const unsigned char bmpimage[66] = {
1323 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
1324 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
1325 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
1326 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
1327 0x00,0x00
1328 };
1329 /* 1x1 pixel jpg */
1330 static const unsigned char jpgimage[285] = {
1331 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
1332 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
1333 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
1334 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
1335 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
1336 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
1337 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
1338 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1339 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
1340 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
1341 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
1342 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1343 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
1344 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
1345 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1346 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
1347 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
1348 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
1349 };
1350 /* 1x1 pixel tiff */
1351 static const unsigned char tiffimage[] = {
1352 0x49,0x49,0x2a,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xfe,0x00,
1353 0x04,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x00,0x01,0x00,
1354 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1355 0x00,0x00,0x02,0x01,0x03,0x00,0x03,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,0x03,0x01,
1356 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,0x01,0x03,0x00,0x01,0x00,
1357 0x00,0x00,0x02,0x00,0x00,0x00,0x0d,0x01,0x02,0x00,0x1b,0x00,0x00,0x00,0xd8,0x00,
1358 0x00,0x00,0x11,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x12,0x01,
1359 0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x01,0x03,0x00,0x01,0x00,
1360 0x00,0x00,0x03,0x00,0x00,0x00,0x16,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x40,0x00,
1361 0x00,0x00,0x17,0x01,0x04,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x1a,0x01,
1362 0x05,0x00,0x01,0x00,0x00,0x00,0xf4,0x00,0x00,0x00,0x1b,0x01,0x05,0x00,0x01,0x00,
1363 0x00,0x00,0xfc,0x00,0x00,0x00,0x1c,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x01,0x00,
1364 0x00,0x00,0x28,0x01,0x03,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
1365 0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x6d,0x65,
1366 0x68,0x2f,0x44,0x65,0x73,0x6b,0x74,0x6f,0x70,0x2f,0x74,0x65,0x73,0x74,0x2e,0x74,
1367 0x69,0x66,0x00,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x48,
1368 0x00,0x00,0x00,0x01
1369 };
1370 /* 320x320 twip wmf */
1371 static const unsigned char wmfimage[180] = {
1372 0xd7,0xcd,0xc6,0x9a,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x40,0x01,0xa0,0x05,
1373 0x00,0x00,0x00,0x00,0xb1,0x52,0x01,0x00,0x09,0x00,0x00,0x03,0x4f,0x00,0x00,0x00,
1374 0x0f,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0b,0x02,0x00,0x00,
1375 0x00,0x00,0x05,0x00,0x00,0x00,0x0c,0x02,0x40,0x01,0x40,0x01,0x04,0x00,0x00,0x00,
1376 0x02,0x01,0x01,0x00,0x04,0x00,0x00,0x00,0x04,0x01,0x0d,0x00,0x08,0x00,0x00,0x00,
1377 0xfa,0x02,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
1378 0x2d,0x01,0x00,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
1379 0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x01,0x00,0x07,0x00,0x00,0x00,0xfc,0x02,
1380 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x2d,0x01,0x02,0x00,
1381 0x07,0x00,0x00,0x00,0x1b,0x04,0x40,0x01,0x40,0x01,0x00,0x00,0x00,0x00,0x04,0x00,
1382 0x00,0x00,0xf0,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0xf0,0x01,0x01,0x00,0x03,0x00,
1383 0x00,0x00,0x00,0x00
1384 };
1385 static void test_getrawformat(void)
1386 {
1387 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
1388 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
1389 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
1390 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
1391 test_bufferrawformat((void*)tiffimage, sizeof(tiffimage), &ImageFormatTIFF, __LINE__, FALSE);
1392 test_bufferrawformat((void*)wmfimage, sizeof(wmfimage), &ImageFormatWMF, __LINE__, FALSE);
1393 }
1394
1395 static void test_loadwmf(void)
1396 {
1397 LPSTREAM stream;
1398 HGLOBAL hglob;
1399 LPBYTE data;
1400 HRESULT hres;
1401 GpStatus stat;
1402 GpImage *img;
1403 GpRectF bounds;
1404 GpUnit unit;
1405 REAL res = 12345.0;
1406 MetafileHeader header;
1407
1408 hglob = GlobalAlloc (0, sizeof(wmfimage));
1409 data = GlobalLock (hglob);
1410 memcpy(data, wmfimage, sizeof(wmfimage));
1411 GlobalUnlock(hglob); data = NULL;
1412
1413 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
1414 ok(hres == S_OK, "Failed to create a stream\n");
1415 if(hres != S_OK) return;
1416
1417 stat = GdipLoadImageFromStream(stream, &img);
1418 ok(stat == Ok, "Failed to create a Bitmap\n");
1419 if(stat != Ok){
1420 IStream_Release(stream);
1421 return;
1422 }
1423
1424 IStream_Release(stream);
1425
1426 stat = GdipGetImageBounds(img, &bounds, &unit);
1427 expect(Ok, stat);
1428 todo_wine expect(UnitPixel, unit);
1429 expectf(0.0, bounds.X);
1430 expectf(0.0, bounds.Y);
1431 todo_wine expectf(320.0, bounds.Width);
1432 todo_wine expectf(320.0, bounds.Height);
1433
1434 stat = GdipGetImageHorizontalResolution(img, &res);
1435 expect(Ok, stat);
1436 todo_wine expectf(1440.0, res);
1437
1438 stat = GdipGetImageVerticalResolution(img, &res);
1439 expect(Ok, stat);
1440 todo_wine expectf(1440.0, res);
1441
1442 memset(&header, 0, sizeof(header));
1443 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1444 expect(Ok, stat);
1445 if (stat == Ok)
1446 {
1447 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1448 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1449 todo_wine expect(0x300, header.Version);
1450 expect(0, header.EmfPlusFlags);
1451 todo_wine expectf(1440.0, header.DpiX);
1452 todo_wine expectf(1440.0, header.DpiY);
1453 expect(0, header.X);
1454 expect(0, header.Y);
1455 todo_wine expect(320, header.Width);
1456 todo_wine expect(320, header.Height);
1457 todo_wine expect(1, U(header).WmfHeader.mtType);
1458 expect(0, header.EmfPlusHeaderSize);
1459 expect(0, header.LogicalDpiX);
1460 expect(0, header.LogicalDpiY);
1461 }
1462
1463 GdipDisposeImage(img);
1464 }
1465
1466 static void test_createfromwmf(void)
1467 {
1468 HMETAFILE hwmf;
1469 GpImage *img;
1470 GpStatus stat;
1471 GpRectF bounds;
1472 GpUnit unit;
1473 REAL res = 12345.0;
1474 MetafileHeader header;
1475
1476 hwmf = SetMetaFileBitsEx(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader),
1477 wmfimage+sizeof(WmfPlaceableFileHeader));
1478 ok(hwmf != 0, "SetMetaFileBitsEx failed\n");
1479
1480 stat = GdipCreateMetafileFromWmf(hwmf, TRUE,
1481 (WmfPlaceableFileHeader*)wmfimage, (GpMetafile**)&img);
1482 expect(Ok, stat);
1483 if (stat != Ok) return; // ReactOS
1484
1485 stat = GdipGetImageBounds(img, &bounds, &unit);
1486 expect(Ok, stat);
1487 expect(UnitPixel, unit);
1488 expectf(0.0, bounds.X);
1489 expectf(0.0, bounds.Y);
1490 expectf(320.0, bounds.Width);
1491 expectf(320.0, bounds.Height);
1492
1493 stat = GdipGetImageHorizontalResolution(img, &res);
1494 expect(Ok, stat);
1495 expectf(1440.0, res);
1496
1497 stat = GdipGetImageVerticalResolution(img, &res);
1498 expect(Ok, stat);
1499 expectf(1440.0, res);
1500
1501 memset(&header, 0, sizeof(header));
1502 stat = GdipGetMetafileHeaderFromMetafile((GpMetafile*)img, &header);
1503 expect(Ok, stat);
1504 if (stat == Ok)
1505 {
1506 todo_wine expect(MetafileTypeWmfPlaceable, header.Type);
1507 todo_wine expect(sizeof(wmfimage)-sizeof(WmfPlaceableFileHeader), header.Size);
1508 todo_wine expect(0x300, header.Version);
1509 expect(0, header.EmfPlusFlags);
1510 todo_wine expectf(1440.0, header.DpiX);
1511 todo_wine expectf(1440.0, header.DpiY);
1512 expect(0, header.X);
1513 expect(0, header.Y);
1514 todo_wine expect(320, header.Width);
1515 todo_wine expect(320, header.Height);
1516 todo_wine expect(1, U(header).WmfHeader.mtType);
1517 expect(0, header.EmfPlusHeaderSize);
1518 expect(0, header.LogicalDpiX);
1519 expect(0, header.LogicalDpiY);
1520 }
1521
1522 GdipDisposeImage(img);
1523 }
1524
1525 static void test_resolution(void)
1526 {
1527 GpStatus stat;
1528 GpBitmap *bitmap;
1529 GpGraphics *graphics;
1530 REAL res=-1.0;
1531 HDC screendc;
1532 int screenxres, screenyres;
1533
1534 /* create Bitmap */
1535 stat = GdipCreateBitmapFromScan0(1, 1, 32, PixelFormat24bppRGB, NULL, &bitmap);
1536 expect(Ok, stat);
1537
1538 /* test invalid values */
1539 stat = GdipGetImageHorizontalResolution(NULL, &res);
1540 expect(InvalidParameter, stat);
1541
1542 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, NULL);
1543 expect(InvalidParameter, stat);
1544
1545 stat = GdipGetImageVerticalResolution(NULL, &res);
1546 expect(InvalidParameter, stat);
1547
1548 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, NULL);
1549 expect(InvalidParameter, stat);
1550
1551 stat = GdipBitmapSetResolution(NULL, 96.0, 96.0);
1552 expect(InvalidParameter, stat);
1553
1554 stat = GdipBitmapSetResolution(bitmap, 0.0, 0.0);
1555 expect(InvalidParameter, stat);
1556
1557 /* defaults to screen resolution */
1558 screendc = GetDC(0);
1559
1560 screenxres = GetDeviceCaps(screendc, LOGPIXELSX);
1561 screenyres = GetDeviceCaps(screendc, LOGPIXELSY);
1562
1563 ReleaseDC(0, screendc);
1564
1565 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1566 expect(Ok, stat);
1567 expectf((REAL)screenxres, res);
1568
1569 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1570 expect(Ok, stat);
1571 expectf((REAL)screenyres, res);
1572
1573 stat = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
1574 expect(Ok, stat);
1575 stat = GdipGetDpiX(graphics, &res);
1576 expect(Ok, stat);
1577 expectf((REAL)screenxres, res);
1578 stat = GdipGetDpiY(graphics, &res);
1579 expect(Ok, stat);
1580 expectf((REAL)screenyres, res);
1581
1582 /* test changing the resolution */
1583 stat = GdipBitmapSetResolution(bitmap, screenxres*2.0, screenyres*3.0);
1584 expect(Ok, stat);
1585
1586 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &res);
1587 expect(Ok, stat);
1588 expectf(screenxres*2.0, res);
1589
1590 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &res);
1591 expect(Ok, stat);
1592 expectf(screenyres*3.0, res);
1593
1594 stat = GdipGetDpiX(graphics, &res);
1595 expect(Ok, stat);
1596 expectf((REAL)screenxres, res);
1597 stat = GdipGetDpiY(graphics, &res);
1598 expect(Ok, stat);
1599 expectf((REAL)screenyres, res);
1600
1601 stat = GdipDeleteGraphics(graphics);
1602 expect(Ok, stat);
1603
1604 stat = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
1605 expect(Ok, stat);
1606 stat = GdipGetDpiX(graphics, &res);
1607 expect(Ok, stat);
1608 expectf(screenxres*2.0, res);
1609 stat = GdipGetDpiY(graphics, &res);
1610 expect(Ok, stat);
1611 expectf(screenyres*3.0, res);
1612 stat = GdipDeleteGraphics(graphics);
1613 expect(Ok, stat);
1614
1615 stat = GdipDisposeImage((GpImage*)bitmap);
1616 expect(Ok, stat);
1617 }
1618
1619 static void test_createhbitmap(void)
1620 {
1621 GpStatus stat;
1622 GpBitmap *bitmap;
1623 HBITMAP hbitmap, oldhbitmap;
1624 BITMAP bm;
1625 int ret;
1626 HDC hdc;
1627 COLORREF pixel;
1628 BYTE bits[640];
1629
1630 memset(bits, 0x68, 640);
1631
1632 /* create Bitmap */
1633 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
1634 expect(Ok, stat);
1635
1636 /* test NULL values */
1637 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
1638 expect(InvalidParameter, stat);
1639
1640 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
1641 expect(InvalidParameter, stat);
1642
1643 /* create HBITMAP */
1644 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
1645 expect(Ok, stat);
1646
1647 if (stat == Ok)
1648 {
1649 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
1650 expect(sizeof(BITMAP), ret);
1651
1652 expect(0, bm.bmType);
1653 expect(10, bm.bmWidth);
1654 expect(20, bm.bmHeight);
1655 expect(40, bm.bmWidthBytes);
1656 expect(1, bm.bmPlanes);
1657 expect(32, bm.bmBitsPixel);
1658 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1659
1660 if (bm.bmBits)
1661 {
1662 DWORD val = *(DWORD*)bm.bmBits;
1663 ok(val == 0xff686868, "got %x, expected 0xff686868\n", val);
1664 }
1665
1666 hdc = CreateCompatibleDC(NULL);
1667
1668 oldhbitmap = SelectObject(hdc, hbitmap);
1669 pixel = GetPixel(hdc, 5, 5);
1670 SelectObject(hdc, oldhbitmap);
1671
1672 DeleteDC(hdc);
1673
1674 expect(0x686868, pixel);
1675
1676 DeleteObject(hbitmap);
1677 }
1678
1679 stat = GdipDisposeImage((GpImage*)bitmap);
1680 expect(Ok, stat);
1681
1682 /* create alpha Bitmap */
1683 stat = GdipCreateBitmapFromScan0(8, 20, 32, PixelFormat32bppARGB, bits, &bitmap);
1684 expect(Ok, stat);
1685
1686 /* create HBITMAP */
1687 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
1688 expect(Ok, stat);
1689
1690 if (stat == Ok)
1691 {
1692 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
1693 expect(sizeof(BITMAP), ret);
1694
1695 expect(0, bm.bmType);
1696 expect(8, bm.bmWidth);
1697 expect(20, bm.bmHeight);
1698 expect(32, bm.bmWidthBytes);
1699 expect(1, bm.bmPlanes);
1700 expect(32, bm.bmBitsPixel);
1701 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
1702
1703 if (bm.bmBits)
1704 {
1705 DWORD val = *(DWORD*)bm.bmBits;
1706 ok(val == 0x682a2a2a, "got %x, expected 0x682a2a2a\n", val);
1707 }
1708
1709 hdc = CreateCompatibleDC(NULL);
1710
1711 oldhbitmap = SelectObject(hdc, hbitmap);
1712 pixel = GetPixel(hdc, 5, 5);
1713 SelectObject(hdc, oldhbitmap);
1714
1715 DeleteDC(hdc);
1716
1717 expect(0x2a2a2a, pixel);
1718
1719 DeleteObject(hbitmap);
1720 }
1721
1722 stat = GdipDisposeImage((GpImage*)bitmap);
1723 expect(Ok, stat);
1724 }
1725
1726 static void test_getthumbnail(void)
1727 {
1728 GpStatus stat;
1729 GpImage *bitmap1, *bitmap2;
1730 UINT width, height;
1731
1732 stat = GdipGetImageThumbnail(NULL, 0, 0, &bitmap2, NULL, NULL);
1733 expect(InvalidParameter, stat);
1734
1735 stat = GdipCreateBitmapFromScan0(128, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1736 expect(Ok, stat);
1737
1738 stat = GdipGetImageThumbnail(bitmap1, 0, 0, NULL, NULL, NULL);
1739 expect(InvalidParameter, stat);
1740
1741 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1742 expect(Ok, stat);
1743
1744 if (stat == Ok)
1745 {
1746 stat = GdipGetImageWidth(bitmap2, &width);
1747 expect(Ok, stat);
1748 expect(120, width);
1749
1750 stat = GdipGetImageHeight(bitmap2, &height);
1751 expect(Ok, stat);
1752 expect(120, height);
1753
1754 GdipDisposeImage(bitmap2);
1755 }
1756
1757 GdipDisposeImage(bitmap1);
1758
1759
1760 stat = GdipCreateBitmapFromScan0(64, 128, 0, PixelFormat32bppRGB, NULL, (GpBitmap**)&bitmap1);
1761 expect(Ok, stat);
1762
1763 stat = GdipGetImageThumbnail(bitmap1, 32, 32, &bitmap2, NULL, NULL);
1764 expect(Ok, stat);
1765
1766 if (stat == Ok)
1767 {
1768 stat = GdipGetImageWidth(bitmap2, &width);
1769 expect(Ok, stat);
1770 expect(32, width);
1771
1772 stat = GdipGetImageHeight(bitmap2, &height);
1773 expect(Ok, stat);
1774 expect(32, height);
1775
1776 GdipDisposeImage(bitmap2);
1777 }
1778
1779 stat = GdipGetImageThumbnail(bitmap1, 0, 0, &bitmap2, NULL, NULL);
1780 expect(Ok, stat);
1781
1782 if (stat == Ok)
1783 {
1784 stat = GdipGetImageWidth(bitmap2, &width);
1785 expect(Ok, stat);
1786 expect(120, width);
1787
1788 stat = GdipGetImageHeight(bitmap2, &height);
1789 expect(Ok, stat);
1790 expect(120, height);
1791
1792 GdipDisposeImage(bitmap2);
1793 }
1794
1795 GdipDisposeImage(bitmap1);
1796 }
1797
1798 static void test_getsetpixel(void)
1799 {
1800 GpStatus stat;
1801 GpBitmap *bitmap;
1802 ARGB color;
1803 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
1804 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
1805
1806 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
1807 expect(Ok, stat);
1808
1809 /* null parameters */
1810 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
1811 expect(InvalidParameter, stat);
1812
1813 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
1814 expect(InvalidParameter, stat);
1815
1816 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
1817 expect(InvalidParameter, stat);
1818
1819 /* out of bounds */
1820 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
1821 expect(InvalidParameter, stat);
1822
1823 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
1824 expect(InvalidParameter, stat);
1825
1826 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
1827 ok(stat == InvalidParameter ||
1828 broken(stat == Ok), /* Older gdiplus */
1829 "Expected InvalidParameter, got %.8x\n", stat);
1830
1831 if (0) /* crashes some gdiplus implementations */
1832 {
1833 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
1834 ok(stat == InvalidParameter ||
1835 broken(stat == Ok), /* Older gdiplus */
1836 "Expected InvalidParameter, got %.8x\n", stat);
1837 }
1838
1839 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
1840 expect(InvalidParameter, stat);
1841
1842 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
1843 expect(InvalidParameter, stat);
1844
1845 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
1846 expect(InvalidParameter, stat);
1847
1848 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
1849 expect(InvalidParameter, stat);
1850
1851 /* valid use */
1852 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1853 expect(Ok, stat);
1854 expect(0xffffffff, color);
1855
1856 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1857 expect(Ok, stat);
1858 expect(0xff0000ff, color);
1859
1860 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
1861 expect(Ok, stat);
1862
1863 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
1864 expect(Ok, stat);
1865
1866 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
1867 expect(Ok, stat);
1868 expect(0xff676869, color);
1869
1870 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1871 expect(Ok, stat);
1872 expect(0xff474849, color);
1873
1874 stat = GdipDisposeImage((GpImage*)bitmap);
1875 expect(Ok, stat);
1876 }
1877
1878 static void check_halftone_palette(ColorPalette *palette)
1879 {
1880 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1881 UINT i;
1882
1883 for (i=0; i<palette->Count; i++)
1884 {
1885 ARGB expected=0xff000000;
1886 if (i<8)
1887 {
1888 if (i&1) expected |= 0x800000;
1889 if (i&2) expected |= 0x8000;
1890 if (i&4) expected |= 0x80;
1891 }
1892 else if (i == 8)
1893 {
1894 expected = 0xffc0c0c0;
1895 }
1896 else if (i < 16)
1897 {
1898 if (i&1) expected |= 0xff0000;
1899 if (i&2) expected |= 0xff00;
1900 if (i&4) expected |= 0xff;
1901 }
1902 else if (i < 40)
1903 {
1904 expected = 0x00000000;
1905 }
1906 else
1907 {
1908 expected |= halftone_values[(i-40)%6];
1909 expected |= halftone_values[((i-40)/6)%6] << 8;
1910 expected |= halftone_values[((i-40)/36)%6] << 16;
1911 }
1912 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
1913 expected, palette->Entries[i], i, palette->Count);
1914 }
1915 }
1916
1917 static void test_palette(void)
1918 {
1919 GpStatus stat;
1920 GpBitmap *bitmap;
1921 INT size;
1922 BYTE buffer[1040];
1923 ColorPalette *palette=(ColorPalette*)buffer;
1924 ARGB *entries = palette->Entries;
1925 ARGB color=0;
1926
1927 /* test initial palette from non-indexed bitmap */
1928 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
1929 expect(Ok, stat);
1930
1931 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1932 expect(Ok, stat);
1933 expect(sizeof(UINT)*2+sizeof(ARGB), size);
1934
1935 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1936 expect(Ok, stat);
1937 expect(0, palette->Count);
1938
1939 /* test setting palette on not-indexed bitmap */
1940 palette->Count = 3;
1941
1942 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1943 expect(Ok, stat);
1944
1945 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1946 expect(Ok, stat);
1947 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1948
1949 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1950 expect(Ok, stat);
1951 expect(3, palette->Count);
1952
1953 GdipDisposeImage((GpImage*)bitmap);
1954
1955 /* test initial palette on 1-bit bitmap */
1956 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
1957 expect(Ok, stat);
1958
1959 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1960 expect(Ok, stat);
1961 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1962
1963 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1964 expect(Ok, stat);
1965 expect(PaletteFlagsGrayScale, palette->Flags);
1966 expect(2, palette->Count);
1967
1968 expect(0xff000000, entries[0]);
1969 expect(0xffffffff, entries[1]);
1970
1971 /* test getting/setting pixels */
1972 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
1973 expect(Ok, stat);
1974 expect(0xff000000, color);
1975
1976 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffffffff);
1977 ok((stat == Ok) ||
1978 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
1979
1980 if (stat == Ok)
1981 {
1982 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
1983 expect(Ok, stat);
1984 expect(0xffffffff, color);
1985 }
1986
1987 GdipDisposeImage((GpImage*)bitmap);
1988
1989 /* test initial palette on 4-bit bitmap */
1990 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1991 expect(Ok, stat);
1992
1993 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1994 expect(Ok, stat);
1995 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1996
1997 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1998 expect(Ok, stat);
1999 expect(0, palette->Flags);
2000 expect(16, palette->Count);
2001
2002 check_halftone_palette(palette);
2003
2004 /* test getting/setting pixels */
2005 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
2006 expect(Ok, stat);
2007 expect(0xff000000, color);
2008
2009 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffff00ff);
2010 ok((stat == Ok) ||
2011 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
2012
2013 if (stat == Ok)
2014 {
2015 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
2016 expect(Ok, stat);
2017 expect(0xffff00ff, color);
2018 }
2019
2020 GdipDisposeImage((GpImage*)bitmap);
2021
2022 /* test initial palette on 8-bit bitmap */
2023 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
2024 expect(Ok, stat);
2025
2026 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
2027 expect(Ok, stat);
2028 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
2029
2030 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
2031 expect(Ok, stat);
2032 expect(PaletteFlagsHalftone, palette->Flags);
2033 expect(256, palette->Count);
2034
2035 check_halftone_palette(palette);
2036
2037 /* test getting/setting pixels */
2038 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
2039 expect(Ok, stat);
2040 expect(0xff000000, color);
2041
2042 stat = GdipBitmapSetPixel(bitmap, 0, 1, 0xffcccccc);
2043 ok((stat == Ok) ||
2044 broken(stat == InvalidParameter) /* pre-win7 */, "stat=%.8x\n", stat);
2045
2046 if (stat == Ok)
2047 {
2048 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
2049 expect(Ok, stat);
2050 expect(0xffcccccc, color);
2051 }
2052
2053 /* test setting/getting a different palette */
2054 entries[1] = 0xffcccccc;
2055
2056 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
2057 expect(Ok, stat);
2058
2059 entries[1] = 0;
2060
2061 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
2062 expect(Ok, stat);
2063 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
2064
2065 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
2066 expect(Ok, stat);
2067 expect(PaletteFlagsHalftone, palette->Flags);
2068 expect(256, palette->Count);
2069 expect(0xffcccccc, entries[1]);
2070
2071 /* test count < 256 */
2072 palette->Flags = 12345;
2073 palette->Count = 3;
2074
2075 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
2076 expect(Ok, stat);
2077
2078 entries[1] = 0;
2079 entries[3] = 0xdeadbeef;
2080
2081 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
2082 expect(Ok, stat);
2083 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
2084
2085 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
2086 expect(Ok, stat);
2087 expect(12345, palette->Flags);
2088 expect(3, palette->Count);
2089 expect(0xffcccccc, entries[1]);
2090 expect(0xdeadbeef, entries[3]);
2091
2092 /* test count > 256 */
2093 palette->Count = 257;
2094
2095 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
2096 ok(stat == InvalidParameter ||
2097 broken(stat == Ok), /* Old gdiplus behavior */
2098 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
2099
2100 GdipDisposeImage((GpImage*)bitmap);
2101 }
2102
2103 static void test_colormatrix(void)
2104 {
2105 GpStatus stat;
2106 ColorMatrix colormatrix, graymatrix;
2107 GpImageAttributes *imageattr;
2108 const ColorMatrix identity = {{
2109 {1.0,0.0,0.0,0.0,0.0},
2110 {0.0,1.0,0.0,0.0,0.0},
2111 {0.0,0.0,1.0,0.0,0.0},
2112 {0.0,0.0,0.0,1.0,0.0},
2113 {0.0,0.0,0.0,0.0,1.0}}};
2114 const ColorMatrix double_red = {{
2115 {2.0,0.0,0.0,0.0,0.0},
2116 {0.0,1.0,0.0,0.0,0.0},
2117 {0.0,0.0,1.0,0.0,0.0},
2118 {0.0,0.0,0.0,1.0,0.0},
2119 {0.0,0.0,0.0,0.0,1.0}}};
2120 const ColorMatrix asymmetric = {{
2121 {0.0,1.0,0.0,0.0,0.0},
2122 {0.0,0.0,1.0,0.0,0.0},
2123 {0.0,0.0,0.0,1.0,0.0},
2124 {1.0,0.0,0.0,0.0,0.0},
2125 {0.0,0.0,0.0,0.0,1.0}}};
2126 GpBitmap *bitmap1, *bitmap2;
2127 GpGraphics *graphics;
2128 ARGB color;
2129
2130 colormatrix = identity;
2131 graymatrix = identity;
2132
2133 stat = GdipSetImageAttributesColorMatrix(NULL, ColorAdjustTypeDefault,
2134 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
2135 expect(InvalidParameter, stat);
2136
2137 stat = GdipCreateImageAttributes(&imageattr);
2138 expect(Ok, stat);
2139
2140 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2141 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
2142 expect(Ok, stat);
2143
2144 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2145 TRUE, NULL, NULL, ColorMatrixFlagsDefault);
2146 expect(InvalidParameter, stat);
2147
2148 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2149 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
2150 expect(Ok, stat);
2151
2152 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2153 TRUE, &colormatrix, NULL, ColorMatrixFlagsSkipGrays);
2154 expect(Ok, stat);
2155
2156 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2157 TRUE, &colormatrix, NULL, ColorMatrixFlagsAltGray);
2158 expect(InvalidParameter, stat);
2159
2160 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2161 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsAltGray);
2162 expect(Ok, stat);
2163
2164 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2165 TRUE, &colormatrix, &graymatrix, 3);
2166 expect(InvalidParameter, stat);
2167
2168 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeCount,
2169 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
2170 expect(InvalidParameter, stat);
2171
2172 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeAny,
2173 TRUE, &colormatrix, &graymatrix, ColorMatrixFlagsDefault);
2174 expect(InvalidParameter, stat);
2175
2176 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2177 FALSE, NULL, NULL, ColorMatrixFlagsDefault);
2178 expect(Ok, stat);
2179
2180 /* Drawing a bitmap transforms the colors */
2181 colormatrix = double_red;
2182 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2183 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
2184 expect(Ok, stat);
2185
2186 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppARGB, NULL, &bitmap1);
2187 expect(Ok, stat);
2188
2189 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppARGB, NULL, &bitmap2);
2190 expect(Ok, stat);
2191
2192 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff40ccee);
2193 expect(Ok, stat);
2194
2195 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2196 expect(Ok, stat);
2197
2198 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2199 UnitPixel, imageattr, NULL, NULL);
2200 expect(Ok, stat);
2201
2202 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2203 expect(Ok, stat);
2204 expect(0xff80ccee, color);
2205
2206 colormatrix = asymmetric;
2207 stat = GdipSetImageAttributesColorMatrix(imageattr, ColorAdjustTypeDefault,
2208 TRUE, &colormatrix, NULL, ColorMatrixFlagsDefault);
2209 expect(Ok, stat);
2210
2211 stat = GdipBitmapSetPixel(bitmap2, 0, 0, 0);
2212 expect(Ok, stat);
2213
2214 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2215 UnitPixel, imageattr, NULL, NULL);
2216 expect(Ok, stat);
2217
2218 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2219 expect(Ok, stat);
2220 ok(color_match(0xeeff40cc, color, 3), "expected 0xeeff40cc, got 0x%08x\n", color);
2221
2222 stat = GdipResetImageAttributes(imageattr, ColorAdjustTypeDefault);
2223 expect(Ok, stat);
2224
2225 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2226 UnitPixel, imageattr, NULL, NULL);
2227 expect(Ok, stat);
2228
2229 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2230 expect(Ok, stat);
2231 ok(color_match(0xff40ccee, color, 1), "Expected ff40ccee, got %.8x\n", color);
2232
2233 GdipDeleteGraphics(graphics);
2234 GdipDisposeImage((GpImage*)bitmap1);
2235 GdipDisposeImage((GpImage*)bitmap2);
2236 GdipDisposeImageAttributes(imageattr);
2237 }
2238
2239 static void test_gamma(void)
2240 {
2241 GpStatus stat;
2242 GpImageAttributes *imageattr;
2243 GpBitmap *bitmap1, *bitmap2;
2244 GpGraphics *graphics;
2245 ARGB color;
2246
2247 stat = GdipSetImageAttributesGamma(NULL, ColorAdjustTypeDefault, TRUE, 1.0);
2248 expect(InvalidParameter, stat);
2249
2250 stat = GdipCreateImageAttributes(&imageattr);
2251 expect(Ok, stat);
2252
2253 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 1.0);
2254 expect(Ok, stat);
2255
2256 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeAny, TRUE, 1.0);
2257 expect(InvalidParameter, stat);
2258
2259 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, -1.0);
2260 expect(InvalidParameter, stat);
2261
2262 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.0);
2263 expect(InvalidParameter, stat);
2264
2265 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 0.5);
2266 expect(Ok, stat);
2267
2268 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, FALSE, 0.0);
2269 expect(Ok, stat);
2270
2271 /* Drawing a bitmap transforms the colors */
2272 stat = GdipSetImageAttributesGamma(imageattr, ColorAdjustTypeDefault, TRUE, 3.0);
2273 expect(Ok, stat);
2274
2275 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
2276 expect(Ok, stat);
2277
2278 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
2279 expect(Ok, stat);
2280
2281 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff80ffff);
2282 expect(Ok, stat);
2283
2284 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2285 expect(Ok, stat);
2286
2287 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2288 UnitPixel, imageattr, NULL, NULL);
2289 expect(Ok, stat);
2290
2291 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2292 expect(Ok, stat);
2293 ok(color_match(0xff20ffff, color, 1), "Expected ff20ffff, got %.8x\n", color);
2294
2295 stat = GdipResetImageAttributes(imageattr, ColorAdjustTypeDefault);
2296 expect(Ok, stat);
2297
2298 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2299 UnitPixel, imageattr, NULL, NULL);
2300 expect(Ok, stat);
2301
2302 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2303 expect(Ok, stat);
2304 ok(color_match(0xff80ffff, color, 1), "Expected ff80ffff, got %.8x\n", color);
2305
2306 GdipDeleteGraphics(graphics);
2307 GdipDisposeImage((GpImage*)bitmap1);
2308 GdipDisposeImage((GpImage*)bitmap2);
2309 GdipDisposeImageAttributes(imageattr);
2310 }
2311
2312 /* 1x1 pixel gif, 2 frames; first frame is white, second is black */
2313 static const unsigned char gifanimation[72] = {
2314 0x47,0x49,0x46,0x38,0x39,0x61,0x01,0x00,0x01,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
2315 0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xf9,0x04,0x00,0x0a,0x00,0xff,
2316 0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x4c,0x01,0x00,
2317 0x21,0xf9,0x04,0x01,0x0a,0x00,0x01,0x00,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
2318 0x00,0x00,0x02,0x02,0x44,0x01,0x00,0x3b
2319 };
2320
2321 static void test_multiframegif(void)
2322 {
2323 LPSTREAM stream;
2324 HGLOBAL hglob;
2325 LPBYTE data;
2326 HRESULT hres;
2327 GpStatus stat;
2328 GpBitmap *bmp;
2329 ARGB color;
2330 UINT count;
2331 GUID dimension;
2332
2333 /* Test frame functions with an animated GIF */
2334 hglob = GlobalAlloc (0, sizeof(gifanimation));
2335 data = GlobalLock (hglob);
2336 memcpy(data, gifanimation, sizeof(gifanimation));
2337 GlobalUnlock(hglob);
2338
2339 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
2340 ok(hres == S_OK, "Failed to create a stream\n");
2341 if(hres != S_OK) return;
2342
2343 stat = GdipCreateBitmapFromStream(stream, &bmp);
2344 ok(stat == Ok, "Failed to create a Bitmap\n");
2345 if(stat != Ok){
2346 IStream_Release(stream);
2347 return;
2348 }
2349
2350 /* Bitmap starts at frame 0 */
2351 color = 0xdeadbeef;
2352 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2353 expect(Ok, stat);
2354 expect(0xffffffff, color);
2355
2356 /* Check that we get correct metadata */
2357 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
2358 expect(Ok, stat);
2359 expect(1, count);
2360
2361 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
2362 expect(Ok, stat);
2363 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
2364
2365 count = 12345;
2366 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2367 expect(Ok, stat);
2368 expect(2, count);
2369
2370 /* SelectActiveFrame overwrites our current data */
2371 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
2372 expect(Ok, stat);
2373
2374 color = 0xdeadbeef;
2375 GdipBitmapGetPixel(bmp, 0, 0, &color);
2376 expect(Ok, stat);
2377 expect(0xff000000, color);
2378
2379 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2380 expect(Ok, stat);
2381
2382 color = 0xdeadbeef;
2383 GdipBitmapGetPixel(bmp, 0, 0, &color);
2384 expect(Ok, stat);
2385 expect(0xffffffff, color);
2386
2387 /* Write over the image data */
2388 stat = GdipBitmapSetPixel(bmp, 0, 0, 0xff000000);
2389 expect(Ok, stat);
2390
2391 /* Switching to the same frame does not overwrite our changes */
2392 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2393 expect(Ok, stat);
2394
2395 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2396 expect(Ok, stat);
2397 expect(0xff000000, color);
2398
2399 /* But switching to another frame and back does */
2400 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 1);
2401 expect(Ok, stat);
2402
2403 stat = GdipImageSelectActiveFrame((GpImage*)bmp, &dimension, 0);
2404 expect(Ok, stat);
2405
2406 stat = GdipBitmapGetPixel(bmp, 0, 0, &color);
2407 expect(Ok, stat);
2408 expect(0xffffffff, color);
2409
2410 /* rotate/flip discards the information about other frames */
2411 stat = GdipImageRotateFlip((GpImage*)bmp, Rotate90FlipNone);
2412 expect(Ok, stat);
2413
2414 count = 12345;
2415 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2416 expect(Ok, stat);
2417 expect(1, count);
2418
2419 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bmp, __LINE__, FALSE);
2420
2421 GdipDisposeImage((GpImage*)bmp);
2422 IStream_Release(stream);
2423
2424 /* Test with a non-animated gif */
2425 hglob = GlobalAlloc (0, sizeof(gifimage));
2426 data = GlobalLock (hglob);
2427 memcpy(data, gifimage, sizeof(gifimage));
2428 GlobalUnlock(hglob);
2429
2430 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
2431 ok(hres == S_OK, "Failed to create a stream\n");
2432 if(hres != S_OK) return;
2433
2434 stat = GdipCreateBitmapFromStream(stream, &bmp);
2435 ok(stat == Ok, "Failed to create a Bitmap\n");
2436 if(stat != Ok){
2437 IStream_Release(stream);
2438 return;
2439 }
2440
2441 /* Check metadata */
2442 stat = GdipImageGetFrameDimensionsCount((GpImage*)bmp,&count);
2443 expect(Ok, stat);
2444 expect(1, count);
2445
2446 stat = GdipImageGetFrameDimensionsList((GpImage*)bmp, &dimension, 1);
2447 expect(Ok, stat);
2448 expect_guid(&FrameDimensionTime, &dimension, __LINE__, FALSE);
2449
2450 count = 12345;
2451 stat = GdipImageGetFrameCount((GpImage*)bmp, &dimension, &count);
2452 expect(Ok, stat);
2453 expect(1, count);
2454
2455 GdipDisposeImage((GpImage*)bmp);
2456 IStream_Release(stream);
2457 }
2458
2459 static void test_rotateflip(void)
2460 {
2461 GpImage *bitmap;
2462 GpStatus stat;
2463 BYTE bits[24];
2464 static const BYTE orig_bits[24] = {
2465 0,0,0xff, 0,0xff,0, 0xff,0,0, 23,23,23,
2466 0xff,0xff,0, 0xff,0,0xff, 0,0xff,0xff, 23,23,23};
2467 UINT width, height;
2468 ARGB color;
2469
2470 memcpy(bits, orig_bits, sizeof(bits));
2471 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2472 expect(Ok, stat);
2473
2474 stat = GdipImageRotateFlip(bitmap, Rotate90FlipNone);
2475 expect(Ok, stat);
2476
2477 stat = GdipGetImageWidth(bitmap, &width);
2478 expect(Ok, stat);
2479 stat = GdipGetImageHeight(bitmap, &height);
2480 expect(Ok, stat);
2481 expect(2, width);
2482 expect(3, height);
2483
2484 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2485 expect(Ok, stat);
2486 expect(0xff00ffff, color);
2487
2488 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 0, &color);
2489 expect(Ok, stat);
2490 expect(0xffff0000, color);
2491
2492 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 2, &color);
2493 expect(Ok, stat);
2494 expect(0xffffff00, color);
2495
2496 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 1, 2, &color);
2497 expect(Ok, stat);
2498 expect(0xff0000ff, color);
2499
2500 expect(0, bits[0]);
2501 expect(0, bits[1]);
2502 expect(0xff, bits[2]);
2503
2504 GdipDisposeImage(bitmap);
2505
2506 memcpy(bits, orig_bits, sizeof(bits));
2507 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2508 expect(Ok, stat);
2509
2510 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipX);
2511 expect(Ok, stat);
2512
2513 stat = GdipGetImageWidth(bitmap, &width);
2514 expect(Ok, stat);
2515 stat = GdipGetImageHeight(bitmap, &height);
2516 expect(Ok, stat);
2517 expect(3, width);
2518 expect(2, height);
2519
2520 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2521 expect(Ok, stat);
2522 expect(0xff0000ff, color);
2523
2524 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2525 expect(Ok, stat);
2526 expect(0xffff0000, color);
2527
2528 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2529 expect(Ok, stat);
2530 expect(0xffffff00, color);
2531
2532 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2533 expect(Ok, stat);
2534 expect(0xff00ffff, color);
2535
2536 expect(0, bits[0]);
2537 expect(0, bits[1]);
2538 expect(0xff, bits[2]);
2539
2540 GdipDisposeImage(bitmap);
2541
2542 memcpy(bits, orig_bits, sizeof(bits));
2543 stat = GdipCreateBitmapFromScan0(3, 2, 12, PixelFormat24bppRGB, bits, (GpBitmap**)&bitmap);
2544 expect(Ok, stat);
2545
2546 stat = GdipImageRotateFlip(bitmap, RotateNoneFlipY);
2547 expect(Ok, stat);
2548
2549 stat = GdipGetImageWidth(bitmap, &width);
2550 expect(Ok, stat);
2551 stat = GdipGetImageHeight(bitmap, &height);
2552 expect(Ok, stat);
2553 expect(3, width);
2554 expect(2, height);
2555
2556 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 0, &color);
2557 expect(Ok, stat);
2558 expect(0xff00ffff, color);
2559
2560 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 0, &color);
2561 expect(Ok, stat);
2562 expect(0xffffff00, color);
2563
2564 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 0, 1, &color);
2565 expect(Ok, stat);
2566 expect(0xffff0000, color);
2567
2568 stat = GdipBitmapGetPixel((GpBitmap*)bitmap, 2, 1, &color);
2569 expect(Ok, stat);
2570 expect(0xff0000ff, color);
2571
2572 expect(0, bits[0]);
2573 expect(0, bits[1]);
2574 expect(0xff, bits[2]);
2575
2576 GdipDisposeImage(bitmap);
2577 }
2578
2579 static void test_remaptable(void)
2580 {
2581 GpStatus stat;
2582 GpImageAttributes *imageattr;
2583 GpBitmap *bitmap1, *bitmap2;
2584 GpGraphics *graphics;
2585 ARGB color;
2586 ColorMap *map;
2587
2588 map = GdipAlloc(sizeof(ColorMap));
2589
2590 map->oldColor.Argb = 0xff00ff00;
2591 map->newColor.Argb = 0xffff00ff;
2592
2593 stat = GdipSetImageAttributesRemapTable(NULL, ColorAdjustTypeDefault, TRUE, 1, map);
2594 expect(InvalidParameter, stat);
2595
2596 stat = GdipCreateImageAttributes(&imageattr);
2597 expect(Ok, stat);
2598
2599 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, NULL);
2600 expect(InvalidParameter, stat);
2601
2602 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeCount, TRUE, 1, map);
2603 expect(InvalidParameter, stat);
2604
2605 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeAny, TRUE, 1, map);
2606 expect(InvalidParameter, stat);
2607
2608 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 0, map);
2609 expect(InvalidParameter, stat);
2610
2611 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, FALSE, 0, NULL);
2612 expect(Ok, stat);
2613
2614 stat = GdipSetImageAttributesRemapTable(imageattr, ColorAdjustTypeDefault, TRUE, 1, map);
2615 expect(Ok, stat);
2616
2617 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap1);
2618 expect(Ok, stat);
2619
2620 stat = GdipCreateBitmapFromScan0(1, 1, 0, PixelFormat32bppRGB, NULL, &bitmap2);
2621 expect(Ok, stat);
2622
2623 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0xff00ff00);
2624 expect(Ok, stat);
2625
2626 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2627 expect(Ok, stat);
2628
2629 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2630 UnitPixel, imageattr, NULL, NULL);
2631 expect(Ok, stat);
2632
2633 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2634 expect(Ok, stat);
2635 ok(color_match(0xffff00ff, color, 1), "Expected ffff00ff, got %.8x\n", color);
2636
2637 stat = GdipResetImageAttributes(imageattr, ColorAdjustTypeDefault);
2638 expect(Ok, stat);
2639
2640 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,1,1, 0,0,1,1,
2641 UnitPixel, imageattr, NULL, NULL);
2642 expect(Ok, stat);
2643
2644 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2645 expect(Ok, stat);
2646 ok(color_match(0xff00ff00, color, 1), "Expected ff00ff00, got %.8x\n", color);
2647
2648 GdipDeleteGraphics(graphics);
2649 GdipDisposeImage((GpImage*)bitmap1);
2650 GdipDisposeImage((GpImage*)bitmap2);
2651 GdipDisposeImageAttributes(imageattr);
2652 GdipFree(map);
2653 }
2654
2655 static void test_colorkey(void)
2656 {
2657 GpStatus stat;
2658 GpImageAttributes *imageattr;
2659 GpBitmap *bitmap1, *bitmap2;
2660 GpGraphics *graphics;
2661 ARGB color;
2662
2663 stat = GdipSetImageAttributesColorKeys(NULL, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2664 expect(InvalidParameter, stat);
2665
2666 stat = GdipCreateImageAttributes(&imageattr);
2667 expect(Ok, stat);
2668
2669 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeCount, TRUE, 0xff405060, 0xff708090);
2670 expect(InvalidParameter, stat);
2671
2672 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeAny, TRUE, 0xff405060, 0xff708090);
2673 expect(InvalidParameter, stat);
2674
2675 stat = GdipSetImageAttributesColorKeys(imageattr, ColorAdjustTypeDefault, TRUE, 0xff405060, 0xff708090);
2676 expect(Ok, stat);
2677
2678 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap1);
2679 expect(Ok, stat);
2680
2681 stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, &bitmap2);
2682 expect(Ok, stat);
2683
2684 stat = GdipBitmapSetPixel(bitmap1, 0, 0, 0x20405060);
2685 expect(Ok, stat);
2686
2687 stat = GdipBitmapSetPixel(bitmap1, 0, 1, 0x40506070);
2688 expect(Ok, stat);
2689
2690 stat = GdipBitmapSetPixel(bitmap1, 1, 0, 0x60708090);
2691 expect(Ok, stat);
2692
2693 stat = GdipBitmapSetPixel(bitmap1, 1, 1, 0xffffffff);
2694 expect(Ok, stat);
2695
2696 stat = GdipGetImageGraphicsContext((GpImage*)bitmap2, &graphics);
2697 expect(Ok, stat);
2698
2699 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,2,2, 0,0,2,2,
2700 UnitPixel, imageattr, NULL, NULL);
2701 expect(Ok, stat);
2702
2703 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2704 expect(Ok, stat);
2705 ok(color_match(0x00000000, color, 1), "Expected 00000000, got %.8x\n", color);
2706
2707 stat = GdipBitmapGetPixel(bitmap2, 0, 1, &color);
2708 expect(Ok, stat);
2709 ok(color_match(0x00000000, color, 1), "Expected 00000000, got %.8x\n", color);
2710
2711 stat = GdipBitmapGetPixel(bitmap2, 1, 0, &color);
2712 expect(Ok, stat);
2713 ok(color_match(0x00000000, color, 1), "Expected 00000000, got %.8x\n", color);
2714
2715 stat = GdipBitmapGetPixel(bitmap2, 1, 1, &color);
2716 expect(Ok, stat);
2717 ok(color_match(0xffffffff, color, 1), "Expected ffffffff, got %.8x\n", color);
2718
2719 stat = GdipResetImageAttributes(imageattr, ColorAdjustTypeDefault);
2720 expect(Ok, stat);
2721
2722 stat = GdipDrawImageRectRectI(graphics, (GpImage*)bitmap1, 0,0,2,2, 0,0,2,2,
2723 UnitPixel, imageattr, NULL, NULL);
2724 expect(Ok, stat);
2725
2726 stat = GdipBitmapGetPixel(bitmap2, 0, 0, &color);
2727 expect(Ok, stat);
2728 ok(color_match(0x20405060, color, 1), "Expected 20405060, got %.8x\n", color);
2729
2730 stat = GdipBitmapGetPixel(bitmap2, 0, 1, &color);
2731 expect(Ok, stat);
2732 ok(color_match(0x40506070, color, 1), "Expected 40506070, got %.8x\n", color);
2733
2734 stat = GdipBitmapGetPixel(bitmap2, 1, 0, &color);
2735 expect(Ok, stat);
2736 ok(color_match(0x60708090, color, 1), "Expected 60708090, got %.8x\n", color);
2737
2738 stat = GdipBitmapGetPixel(bitmap2, 1, 1, &color);
2739 expect(Ok, stat);
2740 ok(color_match(0xffffffff, color, 1), "Expected ffffffff, got %.8x\n", color);
2741
2742
2743 GdipDeleteGraphics(graphics);
2744 GdipDisposeImage((GpImage*)bitmap1);
2745 GdipDisposeImage((GpImage*)bitmap2);
2746 GdipDisposeImageAttributes(imageattr);
2747 }
2748
2749 static void test_dispose(void)
2750 {
2751 GpStatus stat;
2752 GpImage *image;
2753 char invalid_image[256];
2754