[gdiplus_winetest]
[reactos.git] / rostests / winetests / gdiplus / image.c
1 /*
2 * Unit test suite for images
3 *
4 * Copyright (C) 2007 Google (Evan Stade)
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #define COBJMACROS
22
23 #include <math.h>
24
25 #include "initguid.h"
26 #include "windows.h"
27 #include "gdiplus.h"
28 #include "wine/test.h"
29
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)
32
33 static void expect_guid(REFGUID expected, REFGUID got, int line, BOOL todo)
34 {
35 WCHAR bufferW[39];
36 char buffer[39];
37 char buffer2[39];
38
39 StringFromGUID2(got, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
40 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer, sizeof(buffer), NULL, NULL);
41 StringFromGUID2(expected, bufferW, sizeof(bufferW)/sizeof(bufferW[0]));
42 WideCharToMultiByte(CP_ACP, 0, bufferW, sizeof(bufferW)/sizeof(bufferW[0]), buffer2, sizeof(buffer2), NULL, NULL);
43 if(todo)
44 todo_wine ok_(__FILE__, line)(IsEqualGUID(expected, got), "Expected %s, got %s\n", buffer2, buffer);
45 else
46 ok_(__FILE__, line)(IsEqualGUID(expected, got), "Expected %s, got %s\n", buffer2, buffer);
47 }
48
49 static void expect_rawformat(REFGUID expected, GpImage *img, int line, BOOL todo)
50 {
51 GUID raw;
52 GpStatus stat;
53
54 stat = GdipGetImageRawFormat(img, &raw);
55 ok_(__FILE__, line)(stat == Ok, "GdipGetImageRawFormat failed with %d\n", stat);
56 if(stat != Ok) return;
57 expect_guid(expected, &raw, line, todo);
58 }
59
60 static void test_bufferrawformat(void* buff, int size, REFGUID expected, int line, BOOL todo)
61 {
62 LPSTREAM stream;
63 HGLOBAL hglob;
64 LPBYTE data;
65 HRESULT hres;
66 GpStatus stat;
67 GpBitmap *bmp;
68
69 hglob = GlobalAlloc (0, size);
70 data = GlobalLock (hglob);
71 memcpy(data, buff, size);
72 GlobalUnlock(hglob); data = NULL;
73
74 hres = CreateStreamOnHGlobal(hglob, TRUE, &stream);
75 ok_(__FILE__, line)(hres == S_OK, "Failed to create a stream\n");
76 if(hres != S_OK) return;
77
78 stat = GdipCreateBitmapFromStream(stream, &bmp);
79 ok_(__FILE__, line)(stat == Ok, "Failed to create a Bitmap\n");
80 if(stat != Ok){
81 IStream_Release(stream);
82 return;
83 }
84
85 expect_rawformat(expected, (GpImage*)bmp, line, todo);
86
87 GdipDisposeImage((GpImage*)bmp);
88 IStream_Release(stream);
89 }
90
91 static void test_Scan0(void)
92 {
93 GpBitmap *bm;
94 GpStatus stat;
95 BYTE buff[360];
96
97 bm = NULL;
98 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
99 expect(Ok, stat);
100 ok(NULL != bm, "Expected bitmap to be initialized\n");
101 if (stat == Ok)
102 GdipDisposeImage((GpImage*)bm);
103
104 bm = (GpBitmap*)0xdeadbeef;
105 stat = GdipCreateBitmapFromScan0(10, -10, 10, PixelFormat24bppRGB, NULL, &bm);
106 expect(InvalidParameter, stat);
107 ok( !bm, "expected null bitmap\n" );
108
109 bm = (GpBitmap*)0xdeadbeef;
110 stat = GdipCreateBitmapFromScan0(-10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
111 expect(InvalidParameter, stat);
112 ok( !bm, "expected null bitmap\n" );
113
114 bm = (GpBitmap*)0xdeadbeef;
115 stat = GdipCreateBitmapFromScan0(10, 0, 10, PixelFormat24bppRGB, NULL, &bm);
116 expect(InvalidParameter, stat);
117 ok( !bm, "expected null bitmap\n" );
118
119 bm = NULL;
120 stat = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, buff, &bm);
121 expect(Ok, stat);
122 ok(NULL != bm, "Expected bitmap to be initialized\n");
123 if (stat == Ok)
124 GdipDisposeImage((GpImage*)bm);
125
126 bm = (GpBitmap*) 0xdeadbeef;
127 stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, buff, &bm);
128 expect(InvalidParameter, stat);
129 ok( !bm, "expected null bitmap\n" );
130
131 bm = (GpBitmap*)0xdeadbeef;
132 stat = GdipCreateBitmapFromScan0(10, 10, 0, PixelFormat24bppRGB, buff, &bm);
133 expect(InvalidParameter, stat);
134 ok( bm == (GpBitmap*)0xdeadbeef, "expected deadbeef bitmap\n" );
135
136 bm = NULL;
137 stat = GdipCreateBitmapFromScan0(10, 10, -8, PixelFormat24bppRGB, buff, &bm);
138 expect(Ok, stat);
139 ok(NULL != bm, "Expected bitmap to be initialized\n");
140 if (stat == Ok)
141 GdipDisposeImage((GpImage*)bm);
142
143 bm = (GpBitmap*)0xdeadbeef;
144 stat = GdipCreateBitmapFromScan0(10, 10, -10, PixelFormat24bppRGB, buff, &bm);
145 expect(InvalidParameter, stat);
146 ok( !bm, "expected null bitmap\n" );
147 }
148
149 static void test_GetImageDimension(void)
150 {
151 GpBitmap *bm;
152 GpStatus stat;
153 const REAL WIDTH = 10.0, HEIGHT = 20.0;
154 REAL w,h;
155
156 bm = (GpBitmap*)0xdeadbeef;
157 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
158 expect(Ok,stat);
159 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
160 ok(NULL != bm, "Expected bitmap to not be NULL\n");
161
162 stat = GdipGetImageDimension(NULL,&w,&h);
163 expect(InvalidParameter, stat);
164
165 stat = GdipGetImageDimension((GpImage*)bm,NULL,&h);
166 expect(InvalidParameter, stat);
167
168 stat = GdipGetImageDimension((GpImage*)bm,&w,NULL);
169 expect(InvalidParameter, stat);
170
171 w = -1;
172 h = -1;
173 stat = GdipGetImageDimension((GpImage*)bm,&w,&h);
174 expect(Ok, stat);
175 expectf(WIDTH, w);
176 expectf(HEIGHT, h);
177 GdipDisposeImage((GpImage*)bm);
178 }
179
180 static void test_GdipImageGetFrameDimensionsCount(void)
181 {
182 GpBitmap *bm;
183 GpStatus stat;
184 const REAL WIDTH = 10.0, HEIGHT = 20.0;
185 UINT w;
186 GUID dimension = {0};
187 UINT count;
188 ARGB color;
189
190 bm = (GpBitmap*)0xdeadbeef;
191 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm);
192 expect(Ok,stat);
193 ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n");
194 ok(NULL != bm, "Expected bitmap to not be NULL\n");
195
196 stat = GdipImageGetFrameDimensionsCount(NULL,&w);
197 expect(InvalidParameter, stat);
198
199 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,NULL);
200 expect(InvalidParameter, stat);
201
202 w = -1;
203 stat = GdipImageGetFrameDimensionsCount((GpImage*)bm,&w);
204 expect(Ok, stat);
205 expect(1, w);
206
207 stat = GdipImageGetFrameDimensionsList((GpImage*)bm, &dimension, 1);
208 expect(Ok, stat);
209 expect_guid(&FrameDimensionPage, &dimension, __LINE__, TRUE);
210
211 count = 12345;
212 stat = GdipImageGetFrameCount((GpImage*)bm, &dimension, &count);
213 todo_wine expect(Ok, stat);
214 todo_wine expect(1, count);
215
216 GdipBitmapSetPixel(bm, 0, 0, 0xffffffff);
217
218 stat = GdipImageSelectActiveFrame((GpImage*)bm, &dimension, 0);
219 expect(Ok, stat);
220
221 /* SelectActiveFrame has no effect on image data of memory bitmaps */
222 color = 0xdeadbeef;
223 GdipBitmapGetPixel(bm, 0, 0, &color);
224 expect(0xffffffff, color);
225
226 GdipDisposeImage((GpImage*)bm);
227 }
228
229 static void test_LoadingImages(void)
230 {
231 GpStatus stat;
232
233 stat = GdipCreateBitmapFromFile(0, 0);
234 expect(InvalidParameter, stat);
235
236 stat = GdipCreateBitmapFromFile(0, (GpBitmap**)0xdeadbeef);
237 expect(InvalidParameter, stat);
238
239 stat = GdipLoadImageFromFile(0, 0);
240 expect(InvalidParameter, stat);
241
242 stat = GdipLoadImageFromFile(0, (GpImage**)0xdeadbeef);
243 expect(InvalidParameter, stat);
244
245 stat = GdipLoadImageFromFileICM(0, 0);
246 expect(InvalidParameter, stat);
247
248 stat = GdipLoadImageFromFileICM(0, (GpImage**)0xdeadbeef);
249 expect(InvalidParameter, stat);
250 }
251
252 static void test_SavingImages(void)
253 {
254 GpStatus stat;
255 GpBitmap *bm;
256 UINT n;
257 UINT s;
258 const REAL WIDTH = 10.0, HEIGHT = 20.0;
259 REAL w, h;
260 ImageCodecInfo *codecs;
261 static const CHAR filenameA[] = "a.bmp";
262 static const WCHAR filename[] = { 'a','.','b','m','p',0 };
263
264 codecs = NULL;
265
266 stat = GdipSaveImageToFile(0, 0, 0, 0);
267 expect(InvalidParameter, stat);
268
269 bm = NULL;
270 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
271 expect(Ok, stat);
272 if (!bm)
273 return;
274
275 /* invalid params */
276 stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
277 expect(InvalidParameter, stat);
278
279 stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
280 expect(InvalidParameter, stat);
281
282 /* encoder tests should succeed -- already tested */
283 stat = GdipGetImageEncodersSize(&n, &s);
284 if (stat != Ok || n == 0) goto cleanup;
285
286 codecs = GdipAlloc(s);
287 if (!codecs) goto cleanup;
288
289 stat = GdipGetImageEncoders(n, s, codecs);
290 if (stat != Ok) goto cleanup;
291
292 stat = GdipSaveImageToFile((GpImage*)bm, filename, &codecs[0].Clsid, 0);
293 expect(stat, Ok);
294
295 GdipDisposeImage((GpImage*)bm);
296 bm = 0;
297
298 /* re-load and check image stats */
299 stat = GdipLoadImageFromFile(filename, (GpImage**)&bm);
300 expect(stat, Ok);
301 if (stat != Ok) goto cleanup;
302
303 stat = GdipGetImageDimension((GpImage*)bm, &w, &h);
304 if (stat != Ok) goto cleanup;
305
306 expectf(WIDTH, w);
307 expectf(HEIGHT, h);
308
309 cleanup:
310 GdipFree(codecs);
311 if (bm)
312 GdipDisposeImage((GpImage*)bm);
313 ok(DeleteFileA(filenameA), "Delete failed.\n");
314 }
315
316 static void test_encoders(void)
317 {
318 GpStatus stat;
319 UINT n;
320 UINT s;
321 ImageCodecInfo *codecs;
322 int i;
323 int bmp_found;
324
325 static const CHAR bmp_format[] = "BMP";
326
327 stat = GdipGetImageEncodersSize(&n, &s);
328 expect(stat, Ok);
329
330 codecs = GdipAlloc(s);
331 if (!codecs)
332 return;
333
334 stat = GdipGetImageEncoders(n, s, NULL);
335 expect(GenericError, stat);
336
337 stat = GdipGetImageEncoders(0, s, codecs);
338 expect(GenericError, stat);
339
340 stat = GdipGetImageEncoders(n, s-1, codecs);
341 expect(GenericError, stat);
342
343 stat = GdipGetImageEncoders(n, s+1, codecs);
344 expect(GenericError, stat);
345
346 stat = GdipGetImageEncoders(n, s, codecs);
347 expect(stat, Ok);
348
349 bmp_found = FALSE;
350 for (i = 0; i < n; i++)
351 {
352 CHAR desc[32];
353
354 WideCharToMultiByte(CP_ACP, 0, codecs[i].FormatDescription, -1,
355 desc, 32, 0, 0);
356
357 if (CompareStringA(LOCALE_SYSTEM_DEFAULT, 0,
358 desc, -1,
359 bmp_format, -1) == CSTR_EQUAL) {
360 bmp_found = TRUE;
361 break;
362 }
363 }
364 if (!bmp_found)
365 ok(FALSE, "No BMP codec found.\n");
366
367 GdipFree(codecs);
368 }
369
370 static void test_LockBits(void)
371 {
372 GpStatus stat;
373 GpBitmap *bm;
374 GpRect rect;
375 BitmapData bd;
376 const INT WIDTH = 10, HEIGHT = 20;
377
378 bm = NULL;
379 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
380 expect(Ok, stat);
381
382 rect.X = 2;
383 rect.Y = 3;
384 rect.Width = 4;
385 rect.Height = 5;
386
387 /* read-only */
388 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
389 expect(Ok, stat);
390
391 if (stat == Ok) {
392 stat = GdipBitmapUnlockBits(bm, &bd);
393 expect(Ok, stat);
394 }
395
396 /* read-only, with NULL rect -> whole bitmap lock */
397 stat = GdipBitmapLockBits(bm, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
398 expect(Ok, stat);
399 expect(bd.Width, WIDTH);
400 expect(bd.Height, HEIGHT);
401
402 if (stat == Ok) {
403 stat = GdipBitmapUnlockBits(bm, &bd);
404 expect(Ok, stat);
405 }
406
407 /* read-only, consecutive */
408 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
409 expect(Ok, stat);
410
411 if (stat == Ok) {
412 stat = GdipBitmapUnlockBits(bm, &bd);
413 expect(Ok, stat);
414 }
415
416 stat = GdipDisposeImage((GpImage*)bm);
417 expect(Ok, stat);
418 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
419 expect(Ok, stat);
420
421 /* read x2 */
422 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
423 expect(Ok, stat);
424 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
425 expect(WrongState, stat);
426
427 stat = GdipBitmapUnlockBits(bm, &bd);
428 expect(Ok, stat);
429
430 stat = GdipDisposeImage((GpImage*)bm);
431 expect(Ok, stat);
432 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
433 expect(Ok, stat);
434
435 /* write, no modification */
436 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
437 expect(Ok, stat);
438
439 if (stat == Ok) {
440 stat = GdipBitmapUnlockBits(bm, &bd);
441 expect(Ok, stat);
442 }
443
444 /* write, consecutive */
445 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
446 expect(Ok, stat);
447
448 if (stat == Ok) {
449 stat = GdipBitmapUnlockBits(bm, &bd);
450 expect(Ok, stat);
451 }
452
453 stat = GdipDisposeImage((GpImage*)bm);
454 expect(Ok, stat);
455 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
456 expect(Ok, stat);
457
458 /* write, modify */
459 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeWrite, PixelFormat24bppRGB, &bd);
460 expect(Ok, stat);
461
462 if (stat == Ok) {
463 if (bd.Scan0)
464 ((char*)bd.Scan0)[2] = 0xff;
465
466 stat = GdipBitmapUnlockBits(bm, &bd);
467 expect(Ok, stat);
468 }
469
470 stat = GdipDisposeImage((GpImage*)bm);
471 expect(Ok, stat);
472
473 /* dispose locked */
474 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
475 expect(Ok, stat);
476 stat = GdipBitmapLockBits(bm, &rect, ImageLockModeRead, PixelFormat24bppRGB, &bd);
477 expect(Ok, stat);
478 stat = GdipDisposeImage((GpImage*)bm);
479 expect(Ok, stat);
480 }
481
482 static void test_GdipCreateBitmapFromHBITMAP(void)
483 {
484 GpBitmap* gpbm = NULL;
485 HBITMAP hbm = NULL;
486 HPALETTE hpal = NULL;
487 GpStatus stat;
488 BYTE buff[1000];
489 LOGPALETTE* LogPal = NULL;
490 REAL width, height;
491 const REAL WIDTH1 = 5;
492 const REAL HEIGHT1 = 15;
493 const REAL WIDTH2 = 10;
494 const REAL HEIGHT2 = 20;
495 HDC hdc;
496 BITMAPINFO bmi;
497 BYTE *bits;
498
499 stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
500 expect(InvalidParameter, stat);
501
502 hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
503 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
504 expect(InvalidParameter, stat);
505
506 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
507 expect(Ok, stat);
508 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
509 expectf(WIDTH1, width);
510 expectf(HEIGHT1, height);
511 if (stat == Ok)
512 GdipDisposeImage((GpImage*)gpbm);
513 DeleteObject(hbm);
514
515 hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
516 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
517 expect(Ok, stat);
518 /* raw format */
519 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)gpbm, __LINE__, FALSE);
520
521 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
522 expectf(WIDTH2, width);
523 expectf(HEIGHT2, height);
524 if (stat == Ok)
525 GdipDisposeImage((GpImage*)gpbm);
526 DeleteObject(hbm);
527
528 hdc = CreateCompatibleDC(0);
529 ok(hdc != NULL, "CreateCompatibleDC failed\n");
530 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
531 bmi.bmiHeader.biHeight = HEIGHT1;
532 bmi.bmiHeader.biWidth = WIDTH1;
533 bmi.bmiHeader.biBitCount = 24;
534 bmi.bmiHeader.biPlanes = 1;
535 bmi.bmiHeader.biCompression = BI_RGB;
536
537 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
538 ok(hbm != NULL, "CreateDIBSection failed\n");
539
540 bits[0] = 0;
541
542 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
543 expect(Ok, stat);
544 expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
545 expectf(WIDTH1, width);
546 expectf(HEIGHT1, height);
547 if (stat == Ok)
548 {
549 /* test whether writing to the bitmap affects the original */
550 stat = GdipBitmapSetPixel(gpbm, 0, 0, 0xffffffff);
551 expect(Ok, stat);
552
553 expect(0, bits[0]);
554
555 GdipDisposeImage((GpImage*)gpbm);
556 }
557
558 LogPal = GdipAlloc(sizeof(LOGPALETTE));
559 ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
560 LogPal->palVersion = 0x300;
561 LogPal->palNumEntries = 1;
562 hpal = CreatePalette(LogPal);
563 ok(hpal != NULL, "CreatePalette failed\n");
564 GdipFree(LogPal);
565
566 stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
567 todo_wine
568 {
569 expect(Ok, stat);
570 }
571 if (stat == Ok)
572 GdipDisposeImage((GpImage*)gpbm);
573
574 DeleteObject(hpal);
575 DeleteObject(hbm);
576 }
577
578 static void test_GdipGetImageFlags(void)
579 {
580 GpImage *img;
581 GpStatus stat;
582 UINT flags;
583
584 img = (GpImage*)0xdeadbeef;
585
586 stat = GdipGetImageFlags(NULL, NULL);
587 expect(InvalidParameter, stat);
588
589 stat = GdipGetImageFlags(NULL, &flags);
590 expect(InvalidParameter, stat);
591
592 stat = GdipGetImageFlags(img, NULL);
593 expect(InvalidParameter, stat);
594 }
595
596 static void test_GdipCloneImage(void)
597 {
598 GpStatus stat;
599 GpRectF rectF;
600 GpUnit unit;
601 GpBitmap *bm;
602 GpImage *image_src, *image_dest = NULL;
603 const INT WIDTH = 10, HEIGHT = 20;
604
605 /* Create an image, clone it, delete the original, make sure the copy works */
606 stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB, NULL, &bm);
607 expect(Ok, stat);
608 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bm, __LINE__, FALSE);
609
610 image_src = ((GpImage*)bm);
611 stat = GdipCloneImage(image_src, &image_dest);
612 expect(Ok, stat);
613 expect_rawformat(&ImageFormatMemoryBMP, image_dest, __LINE__, FALSE);
614
615 stat = GdipDisposeImage((GpImage*)bm);
616 expect(Ok, stat);
617 stat = GdipGetImageBounds(image_dest, &rectF, &unit);
618 expect(Ok, stat);
619
620 /* Treat FP values carefully */
621 expectf((REAL)WIDTH, rectF.Width);
622 expectf((REAL)HEIGHT, rectF.Height);
623
624 stat = GdipDisposeImage(image_dest);
625 expect(Ok, stat);
626 }
627
628 static void test_testcontrol(void)
629 {
630 GpStatus stat;
631 DWORD param;
632
633 param = 0;
634 stat = GdipTestControl(TestControlGetBuildNumber, &param);
635 expect(Ok, stat);
636 ok(param != 0, "Build number expected, got %u\n", param);
637 }
638
639 static void test_fromhicon(void)
640 {
641 static const BYTE bmp_bits[1024];
642 HBITMAP hbmMask, hbmColor;
643 ICONINFO info;
644 HICON hIcon;
645 GpStatus stat;
646 GpBitmap *bitmap = NULL;
647 UINT dim;
648 ImageType type;
649 PixelFormat format;
650
651 /* NULL */
652 stat = GdipCreateBitmapFromHICON(NULL, NULL);
653 expect(InvalidParameter, stat);
654 stat = GdipCreateBitmapFromHICON(NULL, &bitmap);
655 expect(InvalidParameter, stat);
656
657 /* color icon 1 bit */
658 hbmMask = CreateBitmap(16, 16, 1, 1, bmp_bits);
659 ok(hbmMask != 0, "CreateBitmap failed\n");
660 hbmColor = CreateBitmap(16, 16, 1, 1, bmp_bits);
661 ok(hbmColor != 0, "CreateBitmap failed\n");
662 info.fIcon = TRUE;
663 info.xHotspot = 8;
664 info.yHotspot = 8;
665 info.hbmMask = hbmMask;
666 info.hbmColor = hbmColor;
667 hIcon = CreateIconIndirect(&info);
668 ok(hIcon != 0, "CreateIconIndirect failed\n");
669 DeleteObject(hbmMask);
670 DeleteObject(hbmColor);
671
672 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
673 ok(stat == Ok ||
674 broken(stat == InvalidParameter), /* Win98 */
675 "Expected Ok, got %.8x\n", stat);
676 if(stat == Ok){
677 /* check attributes */
678 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
679 expect(Ok, stat);
680 expect(16, dim);
681 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
682 expect(Ok, stat);
683 expect(16, dim);
684 stat = GdipGetImageType((GpImage*)bitmap, &type);
685 expect(Ok, stat);
686 expect(ImageTypeBitmap, type);
687 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
688 expect(PixelFormat32bppARGB, format);
689 /* raw format */
690 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
691 GdipDisposeImage((GpImage*)bitmap);
692 }
693 DestroyIcon(hIcon);
694
695 /* color icon 8 bpp */
696 hbmMask = CreateBitmap(16, 16, 1, 8, bmp_bits);
697 ok(hbmMask != 0, "CreateBitmap failed\n");
698 hbmColor = CreateBitmap(16, 16, 1, 8, bmp_bits);
699 ok(hbmColor != 0, "CreateBitmap failed\n");
700 info.fIcon = TRUE;
701 info.xHotspot = 8;
702 info.yHotspot = 8;
703 info.hbmMask = hbmMask;
704 info.hbmColor = hbmColor;
705 hIcon = CreateIconIndirect(&info);
706 ok(hIcon != 0, "CreateIconIndirect failed\n");
707 DeleteObject(hbmMask);
708 DeleteObject(hbmColor);
709
710 stat = GdipCreateBitmapFromHICON(hIcon, &bitmap);
711 expect(Ok, stat);
712 if(stat == Ok){
713 /* check attributes */
714 stat = GdipGetImageHeight((GpImage*)bitmap, &dim);
715 expect(Ok, stat);
716 expect(16, dim);
717 stat = GdipGetImageWidth((GpImage*)bitmap, &dim);
718 expect(Ok, stat);
719 expect(16, dim);
720 stat = GdipGetImageType((GpImage*)bitmap, &type);
721 expect(Ok, stat);
722 expect(ImageTypeBitmap, type);
723 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
724 expect(PixelFormat32bppARGB, format);
725 /* raw format */
726 expect_rawformat(&ImageFormatMemoryBMP, (GpImage*)bitmap, __LINE__, FALSE);
727 GdipDisposeImage((GpImage*)bitmap);
728 }
729 DestroyIcon(hIcon);
730 }
731
732 /* 1x1 pixel png */
733 static const unsigned char pngimage[285] = {
734 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
735 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x08,0x02,0x00,0x00,0x00,0x90,0x77,0x53,
736 0xde,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,0x0b,
737 0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x07,0x74,0x49,0x4d,0x45,0x07,0xd5,
738 0x06,0x03,0x0f,0x07,0x2d,0x12,0x10,0xf0,0xfd,0x00,0x00,0x00,0x0c,0x49,0x44,0x41,
739 0x54,0x08,0xd7,0x63,0xf8,0xff,0xff,0x3f,0x00,0x05,0xfe,0x02,0xfe,0xdc,0xcc,0x59,
740 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
741 };
742 /* 1x1 pixel gif */
743 static const unsigned char gifimage[35] = {
744 0x47,0x49,0x46,0x38,0x37,0x61,0x01,0x00,0x01,0x00,0x80,0x00,0x00,0xff,0xff,0xff,
745 0xff,0xff,0xff,0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x02,0x02,0x44,
746 0x01,0x00,0x3b
747 };
748 /* 1x1 pixel bmp */
749 static const unsigned char bmpimage[66] = {
750 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
751 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
752 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
753 0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x00,
754 0x00,0x00
755 };
756 /* 1x1 pixel jpg */
757 static const unsigned char jpgimage[285] = {
758 0xff,0xd8,0xff,0xe0,0x00,0x10,0x4a,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2c,
759 0x01,0x2c,0x00,0x00,0xff,0xdb,0x00,0x43,0x00,0x05,0x03,0x04,0x04,0x04,0x03,0x05,
760 0x04,0x04,0x04,0x05,0x05,0x05,0x06,0x07,0x0c,0x08,0x07,0x07,0x07,0x07,0x0f,0x0b,
761 0x0b,0x09,0x0c,0x11,0x0f,0x12,0x12,0x11,0x0f,0x11,0x11,0x13,0x16,0x1c,0x17,0x13,
762 0x14,0x1a,0x15,0x11,0x11,0x18,0x21,0x18,0x1a,0x1d,0x1d,0x1f,0x1f,0x1f,0x13,0x17,
763 0x22,0x24,0x22,0x1e,0x24,0x1c,0x1e,0x1f,0x1e,0xff,0xdb,0x00,0x43,0x01,0x05,0x05,
764 0x05,0x07,0x06,0x07,0x0e,0x08,0x08,0x0e,0x1e,0x14,0x11,0x14,0x1e,0x1e,0x1e,0x1e,
765 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
766 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,
767 0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0x1e,0xff,0xc0,
768 0x00,0x11,0x08,0x00,0x01,0x00,0x01,0x03,0x01,0x22,0x00,0x02,0x11,0x01,0x03,0x11,
769 0x01,0xff,0xc4,0x00,0x15,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
770 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xff,0xc4,0x00,0x14,0x10,0x01,0x00,0x00,
771 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xc4,
772 0x00,0x14,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
773 0x00,0x00,0x00,0x00,0xff,0xc4,0x00,0x14,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
774 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xda,0x00,0x0c,0x03,0x01,
775 0x00,0x02,0x11,0x03,0x11,0x00,0x3f,0x00,0xb2,0xc0,0x07,0xff,0xd9
776 };
777 static void test_getrawformat(void)
778 {
779 test_bufferrawformat((void*)pngimage, sizeof(pngimage), &ImageFormatPNG, __LINE__, FALSE);
780 test_bufferrawformat((void*)gifimage, sizeof(gifimage), &ImageFormatGIF, __LINE__, FALSE);
781 test_bufferrawformat((void*)bmpimage, sizeof(bmpimage), &ImageFormatBMP, __LINE__, FALSE);
782 test_bufferrawformat((void*)jpgimage, sizeof(jpgimage), &ImageFormatJPEG, __LINE__, FALSE);
783 }
784
785 static void test_createhbitmap(void)
786 {
787 GpStatus stat;
788 GpBitmap *bitmap;
789 HBITMAP hbitmap, oldhbitmap;
790 BITMAP bm;
791 int ret;
792 HDC hdc;
793 COLORREF pixel;
794 BYTE bits[640];
795
796 memset(bits, 0x68, 640);
797
798 /* create Bitmap */
799 stat = GdipCreateBitmapFromScan0(10, 20, 32, PixelFormat24bppRGB, bits, &bitmap);
800 expect(Ok, stat);
801
802 /* test NULL values */
803 stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
804 expect(InvalidParameter, stat);
805
806 stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
807 expect(InvalidParameter, stat);
808
809 /* create HBITMAP */
810 stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
811 expect(Ok, stat);
812
813 if (stat == Ok)
814 {
815 ret = GetObjectA(hbitmap, sizeof(BITMAP), &bm);
816 expect(sizeof(BITMAP), ret);
817
818 expect(0, bm.bmType);
819 expect(10, bm.bmWidth);
820 expect(20, bm.bmHeight);
821 expect(40, bm.bmWidthBytes);
822 expect(1, bm.bmPlanes);
823 expect(32, bm.bmBitsPixel);
824 ok(bm.bmBits != NULL, "got DDB, expected DIB\n");
825
826 hdc = CreateCompatibleDC(NULL);
827
828 oldhbitmap = SelectObject(hdc, hbitmap);
829 pixel = GetPixel(hdc, 5, 5);
830 SelectObject(hdc, oldhbitmap);
831
832 DeleteDC(hdc);
833
834 expect(0x686868, pixel);
835
836 DeleteObject(hbitmap);
837 }
838
839 stat = GdipDisposeImage((GpImage*)bitmap);
840 expect(Ok, stat);
841 }
842
843 static void test_getsetpixel(void)
844 {
845 GpStatus stat;
846 GpBitmap *bitmap;
847 ARGB color;
848 BYTE bits[16] = {0x00,0x00,0x00,0x00, 0x00,0xff,0xff,0x00,
849 0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00};
850
851 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, bits, &bitmap);
852 expect(Ok, stat);
853
854 /* null parameters */
855 stat = GdipBitmapGetPixel(NULL, 1, 1, &color);
856 expect(InvalidParameter, stat);
857
858 stat = GdipBitmapGetPixel(bitmap, 1, 1, NULL);
859 expect(InvalidParameter, stat);
860
861 stat = GdipBitmapSetPixel(NULL, 1, 1, 0);
862 expect(InvalidParameter, stat);
863
864 /* out of bounds */
865 stat = GdipBitmapGetPixel(bitmap, -1, 1, &color);
866 expect(InvalidParameter, stat);
867
868 stat = GdipBitmapSetPixel(bitmap, -1, 1, 0);
869 expect(InvalidParameter, stat);
870
871 stat = GdipBitmapGetPixel(bitmap, 1, -1, &color);
872 ok(stat == InvalidParameter ||
873 broken(stat == Ok), /* Older gdiplus */
874 "Expected InvalidParameter, got %.8x\n", stat);
875
876 stat = GdipBitmapSetPixel(bitmap, 1, -1, 0);
877 ok(stat == InvalidParameter ||
878 broken(stat == Ok), /* Older gdiplus */
879 "Expected InvalidParameter, got %.8x\n", stat);
880
881 stat = GdipBitmapGetPixel(bitmap, 2, 1, &color);
882 expect(InvalidParameter, stat);
883
884 stat = GdipBitmapSetPixel(bitmap, 2, 1, 0);
885 expect(InvalidParameter, stat);
886
887 stat = GdipBitmapGetPixel(bitmap, 1, 2, &color);
888 expect(InvalidParameter, stat);
889
890 stat = GdipBitmapSetPixel(bitmap, 1, 2, 0);
891 expect(InvalidParameter, stat);
892
893 /* valid use */
894 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
895 expect(Ok, stat);
896 expect(0xffffffff, color);
897
898 stat = GdipBitmapGetPixel(bitmap, 0, 1, &color);
899 expect(Ok, stat);
900 expect(0xff0000ff, color);
901
902 stat = GdipBitmapSetPixel(bitmap, 1, 1, 0xff676869);
903 expect(Ok, stat);
904
905 stat = GdipBitmapSetPixel(bitmap, 0, 0, 0xff474849);
906 expect(Ok, stat);
907
908 stat = GdipBitmapGetPixel(bitmap, 1, 1, &color);
909 expect(Ok, stat);
910 expect(0xff676869, color);
911
912 stat = GdipBitmapGetPixel(bitmap, 0, 0, &color);
913 expect(Ok, stat);
914 expect(0xff474849, color);
915
916 stat = GdipDisposeImage((GpImage*)bitmap);
917 expect(Ok, stat);
918 }
919
920 static void check_halftone_palette(ColorPalette *palette)
921 {
922 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
923 UINT i;
924
925 for (i=0; i<palette->Count; i++)
926 {
927 ARGB expected=0xff000000;
928 if (i<8)
929 {
930 if (i&1) expected |= 0x800000;
931 if (i&2) expected |= 0x8000;
932 if (i&4) expected |= 0x80;
933 }
934 else if (i == 8)
935 {
936 expected = 0xffc0c0c0;
937 }
938 else if (i < 16)
939 {
940 if (i&1) expected |= 0xff0000;
941 if (i&2) expected |= 0xff00;
942 if (i&4) expected |= 0xff;
943 }
944 else if (i < 40)
945 {
946 expected = 0x00000000;
947 }
948 else
949 {
950 expected |= halftone_values[(i-40)%6];
951 expected |= halftone_values[((i-40)/6)%6] << 8;
952 expected |= halftone_values[((i-40)/36)%6] << 16;
953 }
954 ok(expected == palette->Entries[i], "Expected %.8x, got %.8x, i=%u/%u\n",
955 expected, palette->Entries[i], i, palette->Count);
956 }
957 }
958
959 static void test_palette(void)
960 {
961 GpStatus stat;
962 GpBitmap *bitmap;
963 INT size;
964 BYTE buffer[1040];
965 ColorPalette *palette=(ColorPalette*)buffer;
966
967 /* test initial palette from non-indexed bitmap */
968 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat32bppRGB, NULL, &bitmap);
969 expect(Ok, stat);
970
971 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
972 expect(Ok, stat);
973 expect(sizeof(UINT)*2+sizeof(ARGB), size);
974
975 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
976 expect(Ok, stat);
977 expect(0, palette->Count);
978
979 /* test setting palette on not-indexed bitmap */
980 palette->Count = 3;
981
982 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
983 expect(Ok, stat);
984
985 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
986 expect(Ok, stat);
987 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
988
989 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
990 expect(Ok, stat);
991 expect(3, palette->Count);
992
993 GdipDisposeImage((GpImage*)bitmap);
994
995 /* test initial palette on 1-bit bitmap */
996 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat1bppIndexed, NULL, &bitmap);
997 expect(Ok, stat);
998
999 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1000 expect(Ok, stat);
1001 expect(sizeof(UINT)*2+sizeof(ARGB)*2, size);
1002
1003 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1004 expect(Ok, stat);
1005 expect(PaletteFlagsGrayScale, palette->Flags);
1006 expect(2, palette->Count);
1007
1008 expect(0xff000000, palette->Entries[0]);
1009 expect(0xffffffff, palette->Entries[1]);
1010
1011 GdipDisposeImage((GpImage*)bitmap);
1012
1013 /* test initial palette on 4-bit bitmap */
1014 stat = GdipCreateBitmapFromScan0(2, 2, 4, PixelFormat4bppIndexed, NULL, &bitmap);
1015 expect(Ok, stat);
1016
1017 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1018 expect(Ok, stat);
1019 expect(sizeof(UINT)*2+sizeof(ARGB)*16, size);
1020
1021 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1022 expect(Ok, stat);
1023 expect(0, palette->Flags);
1024 expect(16, palette->Count);
1025
1026 check_halftone_palette(palette);
1027
1028 GdipDisposeImage((GpImage*)bitmap);
1029
1030 /* test initial palette on 8-bit bitmap */
1031 stat = GdipCreateBitmapFromScan0(2, 2, 8, PixelFormat8bppIndexed, NULL, &bitmap);
1032 expect(Ok, stat);
1033
1034 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1035 expect(Ok, stat);
1036 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1037
1038 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1039 expect(Ok, stat);
1040 expect(PaletteFlagsHalftone, palette->Flags);
1041 expect(256, palette->Count);
1042
1043 check_halftone_palette(palette);
1044
1045 /* test setting/getting a different palette */
1046 palette->Entries[1] = 0xffcccccc;
1047
1048 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1049 expect(Ok, stat);
1050
1051 palette->Entries[1] = 0;
1052
1053 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1054 expect(Ok, stat);
1055 expect(sizeof(UINT)*2+sizeof(ARGB)*256, size);
1056
1057 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1058 expect(Ok, stat);
1059 expect(PaletteFlagsHalftone, palette->Flags);
1060 expect(256, palette->Count);
1061 expect(0xffcccccc, palette->Entries[1]);
1062
1063 /* test count < 256 */
1064 palette->Flags = 12345;
1065 palette->Count = 3;
1066
1067 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1068 expect(Ok, stat);
1069
1070 palette->Entries[1] = 0;
1071 palette->Entries[3] = 0xdeadbeef;
1072
1073 stat = GdipGetImagePaletteSize((GpImage*)bitmap, &size);
1074 expect(Ok, stat);
1075 expect(sizeof(UINT)*2+sizeof(ARGB)*3, size);
1076
1077 stat = GdipGetImagePalette((GpImage*)bitmap, palette, size);
1078 expect(Ok, stat);
1079 expect(12345, palette->Flags);
1080 expect(3, palette->Count);
1081 expect(0xffcccccc, palette->Entries[1]);
1082 expect(0xdeadbeef, palette->Entries[3]);
1083
1084 /* test count > 256 */
1085 palette->Count = 257;
1086
1087 stat = GdipSetImagePalette((GpImage*)bitmap, palette);
1088 ok(stat == InvalidParameter ||
1089 broken(stat == Ok), /* Old gdiplus behavior */
1090 "Expected %.8x, got %.8x\n", InvalidParameter, stat);
1091
1092 GdipDisposeImage((GpImage*)bitmap);
1093 }
1094
1095 START_TEST(image)
1096 {
1097 struct GdiplusStartupInput gdiplusStartupInput;
1098 ULONG_PTR gdiplusToken;
1099
1100 gdiplusStartupInput.GdiplusVersion = 1;
1101 gdiplusStartupInput.DebugEventCallback = NULL;
1102 gdiplusStartupInput.SuppressBackgroundThread = 0;
1103 gdiplusStartupInput.SuppressExternalCodecs = 0;
1104
1105 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1106
1107 test_Scan0();
1108 test_GetImageDimension();
1109 test_GdipImageGetFrameDimensionsCount();
1110 test_LoadingImages();
1111 test_SavingImages();
1112 test_encoders();
1113 test_LockBits();
1114 test_GdipCreateBitmapFromHBITMAP();
1115 test_GdipGetImageFlags();
1116 test_GdipCloneImage();
1117 test_testcontrol();
1118 test_fromhicon();
1119 test_getrawformat();
1120 test_createhbitmap();
1121 test_getsetpixel();
1122 test_palette();
1123
1124 GdiplusShutdown(gdiplusToken);
1125 }