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