push 38a8c0aff9170390b5a3ded41e7cf5b02f3a73d8
[wine/hacks.git] / dlls / gdiplus / tests / image.c
blobcd761bdf5cc88948aedcb02556fec83bbe71f871
1 /*
2 * Unit test suite for images
4 * Copyright (C) 2007 Google (Evan Stade)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include <math.h>
25 #include "initguid.h"
26 #include "windows.h"
27 #include "gdiplus.h"
28 #include "wine/test.h"
30 #define expect(expected, got) ok(((UINT)got) == ((UINT)expected), "Expected %.8x, got %.8x\n", (UINT)expected, (UINT)got)
31 #define expectf(expected, got) ok(fabs(expected - got) < 0.0001, "Expected %.2f, got %.2f\n", expected, got)
33 static void expect_rawformat(REFGUID expected, GpImage *img, int line, BOOL todo)
35 GUID raw;
36 WCHAR bufferW[39];
37 char buffer[39];
38 char buffer2[39];
39 GpStatus stat;
41 stat = GdipGetImageRawFormat(img, &raw);
42 ok_(__FILE__, line)(stat == Ok, "GdipGetImageRawFormat failed with %d\n", stat);
43 if(stat != Ok) return;
44 StringFromGUID2(&raw, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
45 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer, sizeof(buffer), NULL, NULL);
46 StringFromGUID2(expected, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
47 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer2, sizeof(buffer2), NULL, NULL);
48 if(todo)
49 todo_wine ok_(__FILE__, line)(IsEqualGUID(&raw, expected), "Expected format %s, got %s\n", buffer2, buffer);
50 else
51 ok_(__FILE__, line)(IsEqualGUID(&raw, expected), "Expected format %s, got %s\n", buffer2, buffer);
54 static void test_bufferrawformat(void* buff, int size, REFGUID expected, int line, BOOL todo)
56 LPSTREAM stream;
57 HGLOBAL hglob;
58 LPBYTE data;
59 HRESULT hres;
60 GpStatus stat;
61 GpBitmap *bmp;
63 hglob = GlobalAlloc (0, size);
64 data = GlobalLock (hglob);
65 memcpy(data, buff, size);
66 GlobalUnlock(hglob); data = NULL;
68 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
69 ok_(__FILE__, line)(hres == S_OK, "Failed to create a stream\n");
70 if(hres != S_OK) return;
72 stat = GdipCreateBitmapFromStream(stream, &bmp);
73 ok_(__FILE__, line)(stat == Ok, "Failed to create a Bitmap\n");
74 if(stat != Ok){
75 IStream_Release(stream);
76 return;
79 expect_rawformat(expected, (GpImage*)bmp, line, todo);
81 GdipDisposeImage((GpImage*)bmp);
82 IStream_Release(stream);
85 static void test_Scan0(void)
87 GpBitmap *bm;
88 GpStatus stat;
89 BYTE buff[360];
91 bm = NULL;
92 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
93 expect(Ok, stat);
94 ok(NULL != bm, "Expected bitmap to be initialized\n");
95 if (stat == Ok)
96 GdipDisposeImage((GpImage*)bm);
98 bm = (GpBitmap*)0xdeadbeef;
99 stat = GdipCreateBitmapFromScan0(10, -10, 10, PixelFormat24bppRGB, NULL, &bm);
100 expect(InvalidParameter, stat);
101 ok( !bm, "expected null bitmap\n" );
103 bm = (GpBitmap*)0xdeadbeef;
104 stat = GdipCreateBitmapFromScan0(-10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
105 expect(InvalidParameter, stat);
106 ok( !bm, "expected null bitmap\n" );
108 bm = (GpBitmap*)0xdeadbeef;
109 stat = GdipCreateBitmapFromScan0(10, 0, 10, PixelFormat24bppRGB, NULL, &bm);
110 expect(InvalidParameter, stat);
111 ok( !bm, "expected null bitmap\n" );
113 bm = NULL;
114 stat = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, buff, &bm);
115 expect(Ok, stat);
116 ok(NULL != bm, "Expected bitmap to be initialized\n");
117 if (stat == Ok)
118 GdipDisposeImage((GpImage*)bm);
120 bm = (GpBitmap*) 0xdeadbeef;
121 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, buff, &bm);
122 expect(InvalidParameter, stat);
123 ok( !bm, "expected null bitmap\n" );
125 bm = (GpBitmap*)0xdeadbeef;
126 stat = GdipCreateBitmapFromScan0(10, 10, 0, PixelFormat24bppRGB, buff, &bm);
127 expect(InvalidParameter, stat);
128 ok( bm == (GpBitmap*)0xdeadbeef, "expected deadbeef bitmap\n" );
130 bm = NULL;
131 stat = GdipCreateBitmapFromScan0(10, 10, -8, PixelFormat24bppRGB, buff, &bm);
132 expect(Ok, stat);
133 ok(NULL != bm, "Expected bitmap to be initialized\n");
134 if (stat == Ok)
135 GdipDisposeImage((GpImage*)bm);
137 bm = (GpBitmap*)0xdeadbeef;
138 stat = GdipCreateBitmapFromScan0(10, 10, -10, PixelFormat24bppRGB, buff, &bm);
139 expect(InvalidParameter, stat);
140 ok( !bm, "expected null bitmap\n" );
143 static void test_GetImageDimension(void)
145 GpBitmap *bm;
146 GpStatus stat;
147 const REAL WIDTH = 10.0, HEIGHT = 20.0;
148 REAL w,h;
150 bm = (GpBitmap*)0xdeadbeef;
151 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
152 expect(Ok,stat);
153 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
154 ok(NULL != bm, "Expected bitmap to not be NULL\n");
156 stat = GdipGetImageDimension(NULL,&w,&h);
157 expect(InvalidParameter, stat);
159 stat = GdipGetImageDimension((GpImage*)bm,NULL,&h);
160 expect(InvalidParameter, stat);
162 stat = GdipGetImageDimension((GpImage*)bm,&w,NULL);
163 expect(InvalidParameter, stat);
165 w = -1;
166 h = -1;
167 stat = GdipGetImageDimension((GpImage*)bm,&w,&h);
168 expect(Ok, stat);
169 expectf(WIDTH, w);
170 expectf(HEIGHT, h);
171 GdipDisposeImage((GpImage*)bm);
174 static void test_GdipImageGetFrameDimensionsCount(void)
176 GpBitmap *bm;
177 GpStatus stat;
178 const REAL WIDTH = 10.0, HEIGHT = 20.0;
179 UINT w;
181 bm = (GpBitmap*)0xdeadbeef;
182 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
183 expect(Ok,stat);
184 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
185 ok(NULL != bm, "Expected bitmap to not be NULL\n");
187 stat = GdipImageGetFrameDimensionsCount(NULL,&w);
188 expect(InvalidParameter, stat);
190 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,NULL);
191 expect(InvalidParameter, stat);
193 w = -1;
194 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,&w);
195 expect(Ok, stat);
196 expect(1, w);
197 GdipDisposeImage((GpImage*)bm);
200 static void test_LoadingImages(void)
202 GpStatus stat;
204 stat = GdipCreateBitmapFromFile(0, 0);
205 expect(InvalidParameter, stat);
207 stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
208 expect(InvalidParameter, stat);
210 stat = GdipLoadImageFromFile(0, 0);
211 expect(InvalidParameter, stat);
213 stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
214 expect(InvalidParameter, stat);
216 stat = GdipLoadImageFromFileICM(0, 0);
217 expect(InvalidParameter, stat);
219 stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
220 expect(InvalidParameter, stat);
223 static void test_SavingImages(void)
225 GpStatus stat;
226 GpBitmap *bm;
227 UINT n;
228 UINT s;
229 const REAL WIDTH = 10.0, HEIGHT = 20.0;
230 REAL w, h;
231 ImageCodecInfo *codecs;
232 static const CHAR filenameA[] = "a.bmp";
233 static const WCHAR filename[] = { 'a','.','b','m','p',0 };
235 codecs = NULL;
237 stat = GdipSaveImageToFile(0, 0, 0, 0);
238 expect(InvalidParameter, stat);
240 bm = NULL;
241 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
242 expect(Ok, stat);
243 if (!bm)
244 return;
246 /* invalid params */
247 stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
248 expect(InvalidParameter, stat);
250 stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
251 expect(InvalidParameter, stat);
253 /* encoder tests should succeed -- already tested */
254 stat = GdipGetImageEncodersSize(&n, &s);
255 if (stat != Ok || n == 0) goto cleanup;
257 codecs = GdipAlloc(s);
258 if (!codecs) goto cleanup;
260 stat = GdipGetImageEncoders(n, s, codecs);
261 if (stat != Ok) goto cleanup;
263 stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
264 expect(stat, Ok);
266 GdipDisposeImage((GpImage*)bm);
267 bm = 0;
269 /* re-load and check image stats */
270 stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
271 expect(stat, Ok);
272 if (stat != Ok) goto cleanup;
274 stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
275 if (stat != Ok) goto cleanup;
277 expectf(WIDTH, w);
278 expectf(HEIGHT, h);
280 cleanup:
281 GdipFree(codecs);
282 if (bm)
283 GdipDisposeImage((GpImage*)bm);
284 ok(DeleteFileA(filenameA), "Delete failed.\n");
287 static void test_encoders(void)
289 GpStatus stat;
290 UINT n;
291 UINT s;
292 ImageCodecInfo *codecs;
293 int i;
294 int bmp_found;
296 static const CHAR bmp_format[] = "BMP";
298 stat = GdipGetImageEncodersSize(&n, &s);
299 expect(stat, Ok);
301 codecs = GdipAlloc(s);
302 if (!codecs)
303 return;
305 stat = GdipGetImageEncoders(n, s, NULL);
306 expect(GenericError, stat);
308 stat = GdipGetImageEncoders(0, s, codecs);
309 expect(GenericError, stat);
311 stat = GdipGetImageEncoders(n, s-1, codecs);
312 expect(GenericError, stat);
314 stat = GdipGetImageEncoders(n, s+1, codecs);
315 expect(GenericError, stat);
317 stat = GdipGetImageEncoders(n, s, codecs);
318 expect(stat, Ok);
320 bmp_found = FALSE;
321 for (i = 0; i < n; i++)
323 CHAR desc[32];
325 WideCharToMultiByte(CP_ACP, 0, codecs[i].FormatDescription, -1,
326 desc, 32, 0, 0);
328 if (CompareStringA(LOCALE_SYSTEM_DEFAULT, 0,
329 desc, -1,
330 bmp_format, -1) == CSTR_EQUAL) {
331 bmp_found = TRUE;
332 break;
335 if (!bmp_found)
336 ok(FALSE, "No BMP codec found.\n");
338 GdipFree(codecs);
341 static void test_LockBits(void)
343 GpStatus stat;
344 GpBitmap *bm;
345 GpRect rect;
346 BitmapData bd;
347 const INT WIDTH = 10, HEIGHT = 20;
349 bm = NULL;
350 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
351 expect(Ok, stat);
353 rect.X = 2;
354 rect.Y = 3;
355 rect.Width = 4;
356 rect.Height = 5;
358 /* read-only */
359 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
360 expect(Ok, stat);
362 if (stat == Ok) {
363 stat = GdipBitmapUnlockBits(bm, &bd);
364 expect(Ok, stat);
367 /* read-only, with NULL rect -> whole bitmap lock */
368 stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
369 expect(Ok, stat);
370 expect(bd.Width, WIDTH);
371 expect(bd.Height, HEIGHT);
373 if (stat == Ok) {
374 stat = GdipBitmapUnlockBits(bm, &bd);
375 expect(Ok, stat);
378 /* read-only, consecutive */
379 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
380 expect(Ok, stat);
382 if (stat == Ok) {
383 stat = GdipBitmapUnlockBits(bm, &bd);
384 expect(Ok, stat);
387 stat = GdipDisposeImage((GpImage*)bm);
388 expect(Ok, stat);
389 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
390 expect(Ok, stat);
392 /* read x2 */
393 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
394 expect(Ok, stat);
395 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
396 expect(WrongState, stat);
398 stat = GdipBitmapUnlockBits(bm, &bd);
399 expect(Ok, stat);
401 stat = GdipDisposeImage((GpImage*)bm);
402 expect(Ok, stat);
403 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
404 expect(Ok, stat);
406 /* write, no modification */
407 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
408 expect(Ok, stat);
410 if (stat == Ok) {
411 stat = GdipBitmapUnlockBits(bm, &bd);
412 expect(Ok, stat);
415 /* write, consecutive */
416 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
417 expect(Ok, stat);
419 if (stat == Ok) {
420 stat = GdipBitmapUnlockBits(bm, &bd);
421 expect(Ok, stat);
424 stat = GdipDisposeImage((GpImage*)bm);
425 expect(Ok, stat);
426 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
427 expect(Ok, stat);
429 /* write, modify */
430 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
431 expect(Ok, stat);
433 if (stat == Ok) {
434 if (bd.Scan0)
435 ((char*)bd.Scan0)[2] = 0xff;
437 stat = GdipBitmapUnlockBits(bm, &bd);
438 expect(Ok, stat);
441 stat = GdipDisposeImage((GpImage*)bm);
442 expect(Ok, stat);
444 /* dispose locked */
445 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
446 expect(Ok, stat);
447 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
448 expect(Ok, stat);
449 stat = GdipDisposeImage((GpImage*)bm);
450 expect(Ok, stat);
453 static void test_GdipCreateBitmapFromHBITMAP(void)
455 GpBitmap* gpbm = NULL;
456 HBITMAP hbm = NULL;
457 HPALETTE hpal = NULL;
458 GpStatus stat;
459 BYTE buff[1000];
460 LOGPALETTE* LogPal = NULL;
461 REAL width, height;
462 const REAL WIDTH1 = 5;
463 const REAL HEIGHT1 = 15;
464 const REAL WIDTH2 = 10;
465 const REAL HEIGHT2 = 20;
466 HDC hdc;
467 BITMAPINFO bmi;
469 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
470 expect(InvalidParameter, stat);
472 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
473 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
474 expect(InvalidParameter, stat);
476 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
477 expect(Ok, stat);
478 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
479 expectf(WIDTH1, width);
480 expectf(HEIGHT1, height);
481 if (stat == Ok)
482 GdipDisposeImage((GpImage*)gpbm);
483 DeleteObject(hbm);
485 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
486 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
487 expect(Ok, stat);
488 /* raw format */
489 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
491 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
492 expectf(WIDTH2, width);
493 expectf(HEIGHT2, height);
494 if (stat == Ok)
495 GdipDisposeImage((GpImage*)gpbm);
496 DeleteObject(hbm);
498 hdc = CreateCompatibleDC(0);
499 ok(hdc != NULL, "CreateCompatibleDC failed\n");
500 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
501 bmi.bmiHeader.biHeight = HEIGHT1;
502 bmi.bmiHeader.biWidth = WIDTH1;
503 bmi.bmiHeader.biBitCount = 24;
504 bmi.bmiHeader.biPlanes = 1;
505 bmi.bmiHeader.biCompression = BI_RGB;
507 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
508 ok(hbm != NULL, "CreateDIBSection failed\n");
510 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
511 expect(Ok, stat);
512 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
513 expectf(WIDTH1, width);
514 expectf(HEIGHT1, height);
515 if (stat == Ok)
516 GdipDisposeImage((GpImage*)gpbm);
518 LogPal = GdipAlloc(sizeof(LOGPALETTE));
519 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
520 LogPal->palVersion = 0x300;
521 hpal = CreatePalette(LogPal);
522 ok(hpal != NULL, "CreatePalette failed\n");
523 GdipFree(LogPal);
525 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
526 todo_wine
528 expect(Ok, stat);
530 if (stat == Ok)
531 GdipDisposeImage((GpImage*)gpbm);
533 DeleteObject(hpal);
534 DeleteObject(hbm);
537 static void test_GdipGetImageFlags(void)
539 GpImage *img;
540 GpStatus stat;
541 UINT flags;
543 img = (GpImage*)0xdeadbeef;
545 stat = GdipGetImageFlags(NULL, NULL);
546 expect(InvalidParameter, stat);
548 stat = GdipGetImageFlags(NULL, &flags);
549 expect(InvalidParameter, stat);
551 stat = GdipGetImageFlags(img, NULL);
552 expect(InvalidParameter, stat);
555 static void test_GdipCloneImage(void)
557 GpStatus stat;
558 GpRectF rectF;
559 GpUnit unit;
560 GpBitmap *bm;
561 GpImage *image_src, *image_dest = NULL;
562 const INT WIDTH = 10, HEIGHT = 20;
564 /* Create an image, clone it, delete the original, make sure the copy works */
565 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
566 expect(Ok, stat);
567 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
569 image_src = ((GpImage*)bm);
570 stat = GdipCloneImage(image_src, &image_dest);
571 expect(Ok, stat);
572 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
574 stat = GdipDisposeImage((GpImage*)bm);
575 expect(Ok, stat);
576 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
577 expect(Ok, stat);
579 /* Treat FP values carefully */
580 expectf((REAL)WIDTH, rectF.Width);
581 expectf((REAL)HEIGHT, rectF.Height);
583 stat = GdipDisposeImage(image_dest);
584 expect(Ok, stat);
587 static void test_testcontrol(void)
589 GpStatus stat;
590 DWORD param;
592 param = 0;
593 stat = GdipTestControl(TestControlGetBuildNumber, &param);
594 expect(Ok, stat);
595 ok(param != 0, "Build number expected, got %u\n", param);
598 static void test_fromhicon(void)
600 static const BYTE bmp_bits[1024];
601 HBITMAP hbmMask, hbmColor;
602 ICONINFO info;
603 HICON hIcon;
604 GpStatus stat;
605 GpBitmap *bitmap = NULL;
606 UINT dim;
607 ImageType type;
608 PixelFormat format;
610 /* NULL */
611 stat = GdipCreateBitmapFromHICON(NULL, NULL);
612 expect(InvalidParameter, stat);
613 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
614 expect(InvalidParameter, stat);
616 /* color icon 1 bit */
617 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
618 ok(hbmMask != 0, "CreateBitmap failed\n");
619 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
620 ok(hbmColor != 0, "CreateBitmap failed\n");
621 info.fIcon = TRUE;
622 info.xHotspot = 8;
623 info.yHotspot = 8;
624 info.hbmMask = hbmMask;
625 info.hbmColor = hbmColor;
626 hIcon = CreateIconIndirect(&info);
627 ok(hIcon != 0, "CreateIconIndirect failed\n");
628 DeleteObject(hbmMask);
629 DeleteObject(hbmColor);
631 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
632 ok(stat == Ok ||
633 broken(stat == InvalidParameter), /* Win98 */
634 "Expected Ok, got %.8x\n", stat);
635 if(stat == Ok){
636 /* check attributes */
637 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
638 expect(Ok, stat);
639 expect(16, dim);
640 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
641 expect(Ok, stat);
642 expect(16, dim);
643 stat = GdipGetImageType((GpImage*)bitmap, &type);
644 expect(Ok, stat);
645 expect(ImageTypeBitmap, type);
646 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
647 expect(PixelFormat32bppARGB, format);
648 /* raw format */
649 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
650 GdipDisposeImage((GpImage*)bitmap);
652 DestroyIcon(hIcon);
654 /* color icon 8 bpp */
655 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
656 ok(hbmMask != 0, "CreateBitmap failed\n");
657 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
658 ok(hbmColor != 0, "CreateBitmap failed\n");
659 info.fIcon = TRUE;
660 info.xHotspot = 8;
661 info.yHotspot = 8;
662 info.hbmMask = hbmMask;
663 info.hbmColor = hbmColor;
664 hIcon = CreateIconIndirect(&info);
665 ok(hIcon != 0, "CreateIconIndirect failed\n");
666 DeleteObject(hbmMask);
667 DeleteObject(hbmColor);
669 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
670 expect(Ok, stat);
671 if(stat == Ok){
672 /* check attributes */
673 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
674 expect(Ok, stat);
675 expect(16, dim);
676 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
677 expect(Ok, stat);
678 expect(16, dim);
679 stat = GdipGetImageType((GpImage*)bitmap, &type);
680 expect(Ok, stat);
681 expect(ImageTypeBitmap, type);
682 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
683 expect(PixelFormat32bppARGB, format);
684 /* raw format */
685 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
686 GdipDisposeImage((GpImage*)bitmap);
688 DestroyIcon(hIcon);
691 /* 1x1 pixel png */
692 static const unsigned char pngimage[285] = {
693 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
694 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
695 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
696 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
697 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
698 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
699 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
701 /* 1x1 pixel gif */
702 static const unsigned char gifimage[35] = {
703 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
704 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
705 0x01,0x00,0x3b
707 /* 1x1 pixel bmp */
708 static const unsigned char bmpimage[66] = {
709 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
710 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
711 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
712 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
713 0x00,0x00
715 /* 1x1 pixel jpg */
716 static const unsigned char jpgimage[285] = {
717 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
718 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
719 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
720 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
721 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
722 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
723 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
724 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
725 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
726 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
727 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
728 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
729 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
730 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
731 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
732 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
733 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
734 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
736 static void test_getrawformat(void)
738 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
739 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
740 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
741 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
744 static void test_createhbitmap(void)
746 GpStatus stat;
747 GpBitmap *bitmap;
748 HBITMAP hbitmap, oldhbitmap;
749 BITMAP bm;
750 int ret;
751 HDC hdc;
752 COLORREF pixel;
753 BYTE bits[640];
755 memset(bits, 0x68, 640);
757 /* create Bitmap */
758 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
759 expect(Ok, stat);
761 /* test NULL values */
762 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
763 expect(InvalidParameter, stat);
765 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
766 expect(InvalidParameter, stat);
768 /* create HBITMAP */
769 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
770 expect(Ok, stat);
772 if (stat == Ok)
774 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
775 expect(sizeof(BITMAP), ret);
777 expect(0, bm.bmType);
778 expect(10, bm.bmWidth);
779 expect(20, bm.bmHeight);
780 expect(40, bm.bmWidthBytes);
781 expect(1, bm.bmPlanes);
782 expect(32, bm.bmBitsPixel);
783 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
785 hdc = CreateCompatibleDC(NULL);
787 oldhbitmap = SelectObject(hdc, hbitmap);
788 pixel = GetPixel(hdc, 5, 5);
789 SelectObject(hdc, oldhbitmap);
791 DeleteDC(hdc);
793 expect(0x686868, pixel);
795 DeleteObject(hbitmap);
798 stat = GdipDisposeImage((GpImage*)bitmap);
799 expect(Ok, stat);
802 static void test_getsetpixel(void)
804 GpStatus stat;
805 GpBitmap *bitmap;
806 ARGB color;
807 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
808 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
810 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
811 expect(Ok, stat);
813 /* null parameters */
814 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
815 expect(InvalidParameter, stat);
817 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
818 expect(InvalidParameter, stat);
820 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
821 expect(InvalidParameter, stat);
823 /* out of bounds */
824 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
825 expect(InvalidParameter, stat);
827 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
828 expect(InvalidParameter, stat);
830 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
831 ok(stat == InvalidParameter ||
832 broken(stat == Ok), /* Older gdiplus */
833 "Expected InvalidParameter, got %.8x\n", stat);
835 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
836 ok(stat == InvalidParameter ||
837 broken(stat == Ok), /* Older gdiplus */
838 "Expected InvalidParameter, got %.8x\n", stat);
840 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
841 expect(InvalidParameter, stat);
843 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
844 expect(InvalidParameter, stat);
846 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
847 expect(InvalidParameter, stat);
849 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
850 expect(InvalidParameter, stat);
852 /* valid use */
853 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
854 expect(Ok, stat);
855 expect(0xffffffff, color);
857 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
858 expect(Ok, stat);
859 expect(0xff0000ff, color);
861 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
862 expect(Ok, stat);
864 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
865 expect(Ok, stat);
867 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
868 expect(Ok, stat);
869 expect(0xff676869, color);
871 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
872 expect(Ok, stat);
873 expect(0xff474849, color);
875 stat = GdipDisposeImage((GpImage*)bitmap);
876 expect(Ok, stat);
879 START_TEST(image)
881 struct GdiplusStartupInput gdiplusStartupInput;
882 ULONG_PTR gdiplusToken;
884 gdiplusStartupInput.GdiplusVersion = 1;
885 gdiplusStartupInput.DebugEventCallback = NULL;
886 gdiplusStartupInput.SuppressBackgroundThread = 0;
887 gdiplusStartupInput.SuppressExternalCodecs = 0;
889 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
891 test_Scan0();
892 test_GetImageDimension();
893 test_GdipImageGetFrameDimensionsCount();
894 test_LoadingImages();
895 test_SavingImages();
896 test_encoders();
897 test_LockBits();
898 test_GdipCreateBitmapFromHBITMAP();
899 test_GdipGetImageFlags();
900 test_GdipCloneImage();
901 test_testcontrol();
902 test_fromhicon();
903 test_getrawformat();
904 test_createhbitmap();
905 test_getsetpixel();
907 GdiplusShutdown(gdiplusToken);