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