Merge from amd64 branch:
[reactos.git] / reactos / dll / win32 / gdiplus / image.c
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #include <stdarg.h>
20
21 #define NONAMELESSUNION
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wingdi.h"
27
28 #define COBJMACROS
29 #include "objbase.h"
30 #include "olectl.h"
31 #include "ole2.h"
32
33 #include "initguid.h"
34 #include "wincodec.h"
35 #include "gdiplus.h"
36 #include "gdiplus_private.h"
37 #include "wine/debug.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
40
41 #define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
42
43 static INT ipicture_pixel_height(IPicture *pic)
44 {
45 HDC hdcref;
46 OLE_YSIZE_HIMETRIC y;
47
48 IPicture_get_Height(pic, &y);
49
50 hdcref = GetDC(0);
51
52 y = MulDiv(y, GetDeviceCaps(hdcref, LOGPIXELSY), INCH_HIMETRIC);
53 ReleaseDC(0, hdcref);
54
55 return y;
56 }
57
58 static INT ipicture_pixel_width(IPicture *pic)
59 {
60 HDC hdcref;
61 OLE_XSIZE_HIMETRIC x;
62
63 IPicture_get_Width(pic, &x);
64
65 hdcref = GetDC(0);
66
67 x = MulDiv(x, GetDeviceCaps(hdcref, LOGPIXELSX), INCH_HIMETRIC);
68
69 ReleaseDC(0, hdcref);
70
71 return x;
72 }
73
74 GpStatus WINGDIPAPI GdipBitmapApplyEffect(GpBitmap* bitmap, CGpEffect* effect,
75 RECT* roi, BOOL useAuxData, VOID** auxData, INT* auxDataSize)
76 {
77 FIXME("(%p %p %p %d %p %p): stub\n", bitmap, effect, roi, useAuxData, auxData, auxDataSize);
78 /*
79 * Note: According to Jose Roca's GDI+ docs, this function is not
80 * implemented in Windows's GDI+.
81 */
82 return NotImplemented;
83 }
84
85 GpStatus WINGDIPAPI GdipBitmapCreateApplyEffect(GpBitmap** inputBitmaps,
86 INT numInputs, CGpEffect* effect, RECT* roi, RECT* outputRect,
87 GpBitmap** outputBitmap, BOOL useAuxData, VOID** auxData, INT* auxDataSize)
88 {
89 FIXME("(%p %d %p %p %p %p %d %p %p): stub\n", inputBitmaps, numInputs, effect, roi, outputRect, outputBitmap, useAuxData, auxData, auxDataSize);
90 /*
91 * Note: According to Jose Roca's GDI+ docs, this function is not
92 * implemented in Windows's GDI+.
93 */
94 return NotImplemented;
95 }
96
97 static inline void getpixel_16bppGrayScale(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
98 const BYTE *row, UINT x)
99 {
100 *r = *g = *b = row[x*2+1];
101 *a = 255;
102 }
103
104 static inline void getpixel_16bppRGB555(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
105 const BYTE *row, UINT x)
106 {
107 WORD pixel = *((WORD*)(row)+x);
108 *r = (pixel>>7&0xf8)|(pixel>>12&0x7);
109 *g = (pixel>>2&0xf8)|(pixel>>6&0x7);
110 *b = (pixel<<3&0xf8)|(pixel>>2&0x7);
111 *a = 255;
112 }
113
114 static inline void getpixel_16bppRGB565(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
115 const BYTE *row, UINT x)
116 {
117 WORD pixel = *((WORD*)(row)+x);
118 *r = (pixel>>8&0xf8)|(pixel>>13&0x7);
119 *g = (pixel>>3&0xfc)|(pixel>>9&0x3);
120 *b = (pixel<<3&0xf8)|(pixel>>2&0x7);
121 *a = 255;
122 }
123
124 static inline void getpixel_16bppARGB1555(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
125 const BYTE *row, UINT x)
126 {
127 WORD pixel = *((WORD*)(row)+x);
128 *r = (pixel>>7&0xf8)|(pixel>>12&0x7);
129 *g = (pixel>>2&0xf8)|(pixel>>6&0x7);
130 *b = (pixel<<3&0xf8)|(pixel>>2&0x7);
131 if ((pixel&0x8000) == 0x8000)
132 *a = 255;
133 else
134 *a = 0;
135 }
136
137 static inline void getpixel_24bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
138 const BYTE *row, UINT x)
139 {
140 *r = row[x*3+2];
141 *g = row[x*3+1];
142 *b = row[x*3];
143 *a = 255;
144 }
145
146 static inline void getpixel_32bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
147 const BYTE *row, UINT x)
148 {
149 *r = row[x*4+2];
150 *g = row[x*4+1];
151 *b = row[x*4];
152 *a = 255;
153 }
154
155 static inline void getpixel_32bppARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
156 const BYTE *row, UINT x)
157 {
158 *r = row[x*4+2];
159 *g = row[x*4+1];
160 *b = row[x*4];
161 *a = row[x*4+3];
162 }
163
164 static inline void getpixel_32bppPARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
165 const BYTE *row, UINT x)
166 {
167 *a = row[x*4+3];
168 if (*a == 0)
169 *r = *g = *b = 0;
170 else
171 {
172 *r = row[x*4+2] * 255 / *a;
173 *g = row[x*4+1] * 255 / *a;
174 *b = row[x*4] * 255 / *a;
175 }
176 }
177
178 static inline void getpixel_48bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
179 const BYTE *row, UINT x)
180 {
181 *r = row[x*6+5];
182 *g = row[x*6+3];
183 *b = row[x*6+1];
184 *a = 255;
185 }
186
187 static inline void getpixel_64bppARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
188 const BYTE *row, UINT x)
189 {
190 *r = row[x*8+5];
191 *g = row[x*8+3];
192 *b = row[x*8+1];
193 *a = row[x*8+7];
194 }
195
196 static inline void getpixel_64bppPARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
197 const BYTE *row, UINT x)
198 {
199 *a = row[x*8+7];
200 if (*a == 0)
201 *r = *g = *b = 0;
202 else
203 {
204 *r = row[x*8+5] * 255 / *a;
205 *g = row[x*8+3] * 255 / *a;
206 *b = row[x*8+1] * 255 / *a;
207 }
208 }
209
210 GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y,
211 ARGB *color)
212 {
213 BYTE r, g, b, a;
214 BYTE *row;
215 TRACE("%p %d %d %p\n", bitmap, x, y, color);
216
217 if(!bitmap || !color ||
218 x < 0 || y < 0 || x >= bitmap->width || y >= bitmap->height)
219 return InvalidParameter;
220
221 row = bitmap->bits+bitmap->stride*y;
222
223 switch (bitmap->format)
224 {
225 case PixelFormat16bppGrayScale:
226 getpixel_16bppGrayScale(&r,&g,&b,&a,row,x);
227 break;
228 case PixelFormat16bppRGB555:
229 getpixel_16bppRGB555(&r,&g,&b,&a,row,x);
230 break;
231 case PixelFormat16bppRGB565:
232 getpixel_16bppRGB565(&r,&g,&b,&a,row,x);
233 break;
234 case PixelFormat16bppARGB1555:
235 getpixel_16bppARGB1555(&r,&g,&b,&a,row,x);
236 break;
237 case PixelFormat24bppRGB:
238 getpixel_24bppRGB(&r,&g,&b,&a,row,x);
239 break;
240 case PixelFormat32bppRGB:
241 getpixel_32bppRGB(&r,&g,&b,&a,row,x);
242 break;
243 case PixelFormat32bppARGB:
244 getpixel_32bppARGB(&r,&g,&b,&a,row,x);
245 break;
246 case PixelFormat32bppPARGB:
247 getpixel_32bppPARGB(&r,&g,&b,&a,row,x);
248 break;
249 case PixelFormat48bppRGB:
250 getpixel_48bppRGB(&r,&g,&b,&a,row,x);
251 break;
252 case PixelFormat64bppARGB:
253 getpixel_64bppARGB(&r,&g,&b,&a,row,x);
254 break;
255 case PixelFormat64bppPARGB:
256 getpixel_64bppPARGB(&r,&g,&b,&a,row,x);
257 break;
258 default:
259 FIXME("not implemented for format 0x%x\n", bitmap->format);
260 return NotImplemented;
261 }
262
263 *color = a<<24|r<<16|g<<8|b;
264
265 return Ok;
266 }
267
268 static inline void setpixel_16bppGrayScale(BYTE r, BYTE g, BYTE b, BYTE a,
269 BYTE *row, UINT x)
270 {
271 *((WORD*)(row)+x) = (r+g+b)*85;
272 }
273
274 static inline void setpixel_16bppRGB555(BYTE r, BYTE g, BYTE b, BYTE a,
275 BYTE *row, UINT x)
276 {
277 *((WORD*)(row)+x) = (r<<7&0x7c00)|
278 (g<<2&0x03e0)|
279 (b>>3&0x001f);
280 }
281
282 static inline void setpixel_16bppRGB565(BYTE r, BYTE g, BYTE b, BYTE a,
283 BYTE *row, UINT x)
284 {
285 *((WORD*)(row)+x) = (r<<8&0xf800)|
286 (g<<3&0x07e0)|
287 (b>>3&0x001f);
288 }
289
290 static inline void setpixel_16bppARGB1555(BYTE r, BYTE g, BYTE b, BYTE a,
291 BYTE *row, UINT x)
292 {
293 *((WORD*)(row)+x) = (a<<8&0x8000)|
294 (r<<7&0x7c00)|
295 (g<<2&0x03e0)|
296 (b>>3&0x001f);
297 }
298
299 static inline void setpixel_24bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
300 BYTE *row, UINT x)
301 {
302 row[x*3+2] = r;
303 row[x*3+1] = g;
304 row[x*3] = b;
305 }
306
307 static inline void setpixel_32bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
308 BYTE *row, UINT x)
309 {
310 *((DWORD*)(row)+x) = (r<<16)|(g<<8)|b;
311 }
312
313 static inline void setpixel_32bppARGB(BYTE r, BYTE g, BYTE b, BYTE a,
314 BYTE *row, UINT x)
315 {
316 *((DWORD*)(row)+x) = (a<<24)|(r<<16)|(g<<8)|b;
317 }
318
319 static inline void setpixel_32bppPARGB(BYTE r, BYTE g, BYTE b, BYTE a,
320 BYTE *row, UINT x)
321 {
322 r = r * a / 255;
323 g = g * a / 255;
324 b = b * a / 255;
325 *((DWORD*)(row)+x) = (a<<24)|(r<<16)|(g<<8)|b;
326 }
327
328 static inline void setpixel_48bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
329 BYTE *row, UINT x)
330 {
331 row[x*6+5] = row[x*6+4] = r;
332 row[x*6+3] = row[x*6+2] = g;
333 row[x*6+1] = row[x*6] = b;
334 }
335
336 static inline void setpixel_64bppARGB(BYTE r, BYTE g, BYTE b, BYTE a,
337 BYTE *row, UINT x)
338 {
339 UINT64 a64=a, r64=r, g64=g, b64=b;
340 *((UINT64*)(row)+x) = (a64<<56)|(a64<<48)|(r64<<40)|(r64<<32)|(g64<<24)|(g64<<16)|(b64<<8)|b64;
341 }
342
343 static inline void setpixel_64bppPARGB(BYTE r, BYTE g, BYTE b, BYTE a,
344 BYTE *row, UINT x)
345 {
346 UINT64 a64, r64, g64, b64;
347 a64 = a * 257;
348 r64 = r * a / 255;
349 g64 = g * a / 255;
350 b64 = b * a / 255;
351 *((UINT64*)(row)+x) = (a64<<48)|(r64<<32)|(g64<<16)|b64;
352 }
353
354 GpStatus WINGDIPAPI GdipBitmapSetPixel(GpBitmap* bitmap, INT x, INT y,
355 ARGB color)
356 {
357 BYTE a, r, g, b;
358 BYTE *row;
359 TRACE("bitmap:%p, x:%d, y:%d, color:%08x\n", bitmap, x, y, color);
360
361 if(!bitmap || x < 0 || y < 0 || x >= bitmap->width || y >= bitmap->height)
362 return InvalidParameter;
363
364 a = color>>24;
365 r = color>>16;
366 g = color>>8;
367 b = color;
368
369 row = bitmap->bits + bitmap->stride * y;
370
371 switch (bitmap->format)
372 {
373 case PixelFormat16bppGrayScale:
374 setpixel_16bppGrayScale(r,g,b,a,row,x);
375 break;
376 case PixelFormat16bppRGB555:
377 setpixel_16bppRGB555(r,g,b,a,row,x);
378 break;
379 case PixelFormat16bppRGB565:
380 setpixel_16bppRGB565(r,g,b,a,row,x);
381 break;
382 case PixelFormat16bppARGB1555:
383 setpixel_16bppARGB1555(r,g,b,a,row,x);
384 break;
385 case PixelFormat24bppRGB:
386 setpixel_24bppRGB(r,g,b,a,row,x);
387 break;
388 case PixelFormat32bppRGB:
389 setpixel_32bppRGB(r,g,b,a,row,x);
390 break;
391 case PixelFormat32bppARGB:
392 setpixel_32bppARGB(r,g,b,a,row,x);
393 break;
394 case PixelFormat32bppPARGB:
395 setpixel_32bppPARGB(r,g,b,a,row,x);
396 break;
397 case PixelFormat48bppRGB:
398 setpixel_48bppRGB(r,g,b,a,row,x);
399 break;
400 case PixelFormat64bppARGB:
401 setpixel_64bppARGB(r,g,b,a,row,x);
402 break;
403 case PixelFormat64bppPARGB:
404 setpixel_64bppPARGB(r,g,b,a,row,x);
405 break;
406 default:
407 FIXME("not implemented for format 0x%x\n", bitmap->format);
408 return NotImplemented;
409 }
410
411 return Ok;
412 }
413
414 /* This function returns a pointer to an array of pixels that represents the
415 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
416 * flags. It is correct behavior that a user who calls this function with write
417 * privileges can write to the whole bitmap (not just the area in rect).
418 *
419 * FIXME: only used portion of format is bits per pixel. */
420 GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
421 UINT flags, PixelFormat format, BitmapData* lockeddata)
422 {
423 BOOL bm_is_selected;
424 INT stride, bitspp = PIXELFORMATBPP(format);
425 HDC hdc;
426 HBITMAP hbm, old = NULL;
427 BITMAPINFO *pbmi;
428 BYTE *buff = NULL;
429 UINT abs_height;
430 GpRect act_rect; /* actual rect to be used */
431
432 TRACE("%p %p %d %d %p\n", bitmap, rect, flags, format, lockeddata);
433
434 if(!lockeddata || !bitmap)
435 return InvalidParameter;
436
437 if(rect){
438 if(rect->X < 0 || rect->Y < 0 || (rect->X + rect->Width > bitmap->width) ||
439 (rect->Y + rect->Height > bitmap->height) || !flags)
440 return InvalidParameter;
441
442 act_rect = *rect;
443 }
444 else{
445 act_rect.X = act_rect.Y = 0;
446 act_rect.Width = bitmap->width;
447 act_rect.Height = bitmap->height;
448 }
449
450 if(flags & ImageLockModeUserInputBuf)
451 return NotImplemented;
452
453 if(bitmap->lockmode)
454 return WrongState;
455
456 if (bitmap->bits && bitmap->format == format)
457 {
458 /* no conversion is necessary; just use the bits directly */
459 lockeddata->Width = act_rect.Width;
460 lockeddata->Height = act_rect.Height;
461 lockeddata->PixelFormat = format;
462 lockeddata->Reserved = flags;
463 lockeddata->Stride = bitmap->stride;
464 lockeddata->Scan0 = bitmap->bits + (bitspp / 8) * act_rect.X +
465 bitmap->stride * act_rect.Y;
466
467 bitmap->lockmode = flags;
468 bitmap->numlocks++;
469
470 return Ok;
471 }
472
473 hbm = bitmap->hbitmap;
474 hdc = bitmap->hdc;
475 bm_is_selected = (hdc != 0);
476
477 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
478 if (!pbmi)
479 return OutOfMemory;
480 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
481 pbmi->bmiHeader.biBitCount = 0;
482
483 if(!bm_is_selected){
484 hdc = CreateCompatibleDC(0);
485 old = SelectObject(hdc, hbm);
486 }
487
488 /* fill out bmi */
489 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
490
491 abs_height = abs(pbmi->bmiHeader.biHeight);
492 stride = pbmi->bmiHeader.biWidth * bitspp / 8;
493 stride = (stride + 3) & ~3;
494
495 buff = GdipAlloc(stride * abs_height);
496
497 pbmi->bmiHeader.biBitCount = bitspp;
498
499 if(buff)
500 GetDIBits(hdc, hbm, 0, abs_height, buff, pbmi, DIB_RGB_COLORS);
501
502 if(!bm_is_selected){
503 SelectObject(hdc, old);
504 DeleteDC(hdc);
505 }
506
507 if(!buff){
508 GdipFree(pbmi);
509 return OutOfMemory;
510 }
511
512 lockeddata->Width = act_rect.Width;
513 lockeddata->Height = act_rect.Height;
514 lockeddata->PixelFormat = format;
515 lockeddata->Reserved = flags;
516
517 if(pbmi->bmiHeader.biHeight > 0){
518 lockeddata->Stride = -stride;
519 lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X +
520 stride * (abs_height - 1 - act_rect.Y);
521 }
522 else{
523 lockeddata->Stride = stride;
524 lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X + stride * act_rect.Y;
525 }
526
527 bitmap->lockmode = flags;
528 bitmap->numlocks++;
529
530 bitmap->bitmapbits = buff;
531
532 GdipFree(pbmi);
533 return Ok;
534 }
535
536 GpStatus WINGDIPAPI GdipBitmapSetResolution(GpBitmap* bitmap, REAL xdpi, REAL ydpi)
537 {
538 FIXME("(%p, %.2f, %.2f)\n", bitmap, xdpi, ydpi);
539
540 return NotImplemented;
541 }
542
543 GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap,
544 BitmapData* lockeddata)
545 {
546 HDC hdc;
547 HBITMAP hbm, old = NULL;
548 BOOL bm_is_selected;
549 BITMAPINFO *pbmi;
550
551 if(!bitmap || !lockeddata)
552 return InvalidParameter;
553
554 if(!bitmap->lockmode)
555 return WrongState;
556
557 if(lockeddata->Reserved & ImageLockModeUserInputBuf)
558 return NotImplemented;
559
560 if(lockeddata->Reserved & ImageLockModeRead){
561 if(!(--bitmap->numlocks))
562 bitmap->lockmode = 0;
563
564 GdipFree(bitmap->bitmapbits);
565 bitmap->bitmapbits = NULL;
566 return Ok;
567 }
568
569 if (!bitmap->bitmapbits)
570 {
571 /* we passed a direct reference; no need to do anything */
572 bitmap->lockmode = 0;
573 return Ok;
574 }
575
576 hbm = bitmap->hbitmap;
577 hdc = bitmap->hdc;
578 bm_is_selected = (hdc != 0);
579
580 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
581 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
582 pbmi->bmiHeader.biBitCount = 0;
583
584 if(!bm_is_selected){
585 hdc = CreateCompatibleDC(0);
586 old = SelectObject(hdc, hbm);
587 }
588
589 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
590 pbmi->bmiHeader.biBitCount = PIXELFORMATBPP(lockeddata->PixelFormat);
591 SetDIBits(hdc, hbm, 0, abs(pbmi->bmiHeader.biHeight),
592 bitmap->bitmapbits, pbmi, DIB_RGB_COLORS);
593
594 if(!bm_is_selected){
595 SelectObject(hdc, old);
596 DeleteDC(hdc);
597 }
598
599 GdipFree(pbmi);
600 GdipFree(bitmap->bitmapbits);
601 bitmap->bitmapbits = NULL;
602 bitmap->lockmode = 0;
603
604 return Ok;
605 }
606
607 GpStatus WINGDIPAPI GdipCloneBitmapArea(REAL x, REAL y, REAL width, REAL height,
608 PixelFormat format, GpBitmap* srcBitmap, GpBitmap** dstBitmap)
609 {
610 FIXME("(%f,%f,%f,%f,%i,%p,%p): stub\n", x, y, width, height, format, srcBitmap, dstBitmap);
611
612 return NotImplemented;
613 }
614
615 GpStatus WINGDIPAPI GdipCloneBitmapAreaI(INT x, INT y, INT width, INT height,
616 PixelFormat format, GpBitmap* srcBitmap, GpBitmap** dstBitmap)
617 {
618 FIXME("(%i,%i,%i,%i,%i,%p,%p): stub\n", x, y, width, height, format, srcBitmap, dstBitmap);
619
620 return NotImplemented;
621 }
622
623 GpStatus WINGDIPAPI GdipCloneImage(GpImage *image, GpImage **cloneImage)
624 {
625 GpStatus stat = GenericError;
626
627 TRACE("%p, %p\n", image, cloneImage);
628
629 if (!image || !cloneImage)
630 return InvalidParameter;
631
632 if (image->picture)
633 {
634 IStream* stream;
635 HRESULT hr;
636 INT size;
637 LARGE_INTEGER move;
638
639 hr = CreateStreamOnHGlobal(0, TRUE, &stream);
640 if (FAILED(hr))
641 return GenericError;
642
643 hr = IPicture_SaveAsFile(image->picture, stream, FALSE, &size);
644 if(FAILED(hr))
645 {
646 WARN("Failed to save image on stream\n");
647 goto out;
648 }
649
650 /* Set seek pointer back to the beginning of the picture */
651 move.QuadPart = 0;
652 hr = IStream_Seek(stream, move, STREAM_SEEK_SET, NULL);
653 if (FAILED(hr))
654 goto out;
655
656 stat = GdipLoadImageFromStream(stream, cloneImage);
657 if (stat != Ok) WARN("Failed to load image from stream\n");
658
659 out:
660 IStream_Release(stream);
661 return stat;
662 }
663 else if (image->type == ImageTypeBitmap)
664 {
665 GpBitmap *bitmap = (GpBitmap*)image;
666 BitmapData lockeddata_src, lockeddata_dst;
667 int i;
668 UINT row_size;
669
670 stat = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, bitmap->format,
671 &lockeddata_src);
672 if (stat != Ok) return stat;
673
674 stat = GdipCreateBitmapFromScan0(lockeddata_src.Width, lockeddata_src.Height,
675 0, lockeddata_src.PixelFormat, NULL, (GpBitmap**)cloneImage);
676 if (stat == Ok)
677 {
678 stat = GdipBitmapLockBits((GpBitmap*)*cloneImage, NULL, ImageLockModeWrite,
679 lockeddata_src.PixelFormat, &lockeddata_dst);
680
681 if (stat == Ok)
682 {
683 /* copy the image data */
684 row_size = (lockeddata_src.Width * PIXELFORMATBPP(lockeddata_src.PixelFormat) +7)/8;
685 for (i=0; i<lockeddata_src.Height; i++)
686 memcpy((BYTE*)lockeddata_dst.Scan0+lockeddata_dst.Stride*i,
687 (BYTE*)lockeddata_src.Scan0+lockeddata_src.Stride*i,
688 row_size);
689
690 GdipBitmapUnlockBits((GpBitmap*)*cloneImage, &lockeddata_dst);
691 }
692
693 GdipBitmapUnlockBits(bitmap, &lockeddata_src);
694 }
695
696 if (stat != Ok)
697 {
698 GdipDisposeImage(*cloneImage);
699 *cloneImage = NULL;
700 }
701 else memcpy(&(*cloneImage)->format, &image->format, sizeof(GUID));
702
703 return stat;
704 }
705 else
706 {
707 ERR("GpImage with no IPicture or bitmap?!\n");
708 return NotImplemented;
709 }
710 }
711
712 GpStatus WINGDIPAPI GdipCreateBitmapFromFile(GDIPCONST WCHAR* filename,
713 GpBitmap **bitmap)
714 {
715 GpStatus stat;
716 IStream *stream;
717
718 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
719
720 if(!filename || !bitmap)
721 return InvalidParameter;
722
723 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
724
725 if(stat != Ok)
726 return stat;
727
728 stat = GdipCreateBitmapFromStream(stream, bitmap);
729
730 IStream_Release(stream);
731
732 return stat;
733 }
734
735 GpStatus WINGDIPAPI GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO* info,
736 VOID *bits, GpBitmap **bitmap)
737 {
738 DWORD height, stride;
739 PixelFormat format;
740
741 FIXME("(%p, %p, %p) - partially implemented\n", info, bits, bitmap);
742
743 height = abs(info->bmiHeader.biHeight);
744 stride = ((info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) >> 3) & ~3;
745
746 if(info->bmiHeader.biHeight > 0) /* bottom-up */
747 {
748 bits = (BYTE*)bits + (height - 1) * stride;
749 stride = -stride;
750 }
751
752 switch(info->bmiHeader.biBitCount) {
753 case 1:
754 format = PixelFormat1bppIndexed;
755 break;
756 case 4:
757 format = PixelFormat4bppIndexed;
758 break;
759 case 8:
760 format = PixelFormat8bppIndexed;
761 break;
762 case 24:
763 format = PixelFormat24bppRGB;
764 break;
765 default:
766 FIXME("don't know how to handle %d bpp\n", info->bmiHeader.biBitCount);
767 *bitmap = NULL;
768 return InvalidParameter;
769 }
770
771 return GdipCreateBitmapFromScan0(info->bmiHeader.biWidth, height, stride, format,
772 bits, bitmap);
773
774 }
775
776 /* FIXME: no icm */
777 GpStatus WINGDIPAPI GdipCreateBitmapFromFileICM(GDIPCONST WCHAR* filename,
778 GpBitmap **bitmap)
779 {
780 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
781
782 return GdipCreateBitmapFromFile(filename, bitmap);
783 }
784
785 GpStatus WINGDIPAPI GdipCreateBitmapFromResource(HINSTANCE hInstance,
786 GDIPCONST WCHAR* lpBitmapName, GpBitmap** bitmap)
787 {
788 HBITMAP hbm;
789 GpStatus stat = InvalidParameter;
790
791 TRACE("%p (%s) %p\n", hInstance, debugstr_w(lpBitmapName), bitmap);
792
793 if(!lpBitmapName || !bitmap)
794 return InvalidParameter;
795
796 /* load DIB */
797 hbm = LoadImageW(hInstance, lpBitmapName, IMAGE_BITMAP, 0, 0,
798 LR_CREATEDIBSECTION);
799
800 if(hbm){
801 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, bitmap);
802 DeleteObject(hbm);
803 }
804
805 return stat;
806 }
807
808 GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
809 HBITMAP* hbmReturn, ARGB background)
810 {
811 GpStatus stat;
812 HBITMAP result, oldbitmap;
813 UINT width, height;
814 HDC hdc;
815 GpGraphics *graphics;
816 BITMAPINFOHEADER bih;
817 void *bits;
818 TRACE("(%p,%p,%x)\n", bitmap, hbmReturn, background);
819
820 if (!bitmap || !hbmReturn) return InvalidParameter;
821
822 GdipGetImageWidth((GpImage*)bitmap, &width);
823 GdipGetImageHeight((GpImage*)bitmap, &height);
824
825 bih.biSize = sizeof(bih);
826 bih.biWidth = width;
827 bih.biHeight = height;
828 bih.biPlanes = 1;
829 bih.biBitCount = 32;
830 bih.biCompression = BI_RGB;
831 bih.biSizeImage = 0;
832 bih.biXPelsPerMeter = 0;
833 bih.biYPelsPerMeter = 0;
834 bih.biClrUsed = 0;
835 bih.biClrImportant = 0;
836
837 hdc = CreateCompatibleDC(NULL);
838 if (!hdc) return GenericError;
839
840 result = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS, &bits,
841 NULL, 0);
842
843 if (result)
844 {
845 oldbitmap = SelectObject(hdc, result);
846
847 stat = GdipCreateFromHDC(hdc, &graphics);
848 if (stat == Ok)
849 {
850 stat = GdipGraphicsClear(graphics, background);
851
852 if (stat == Ok)
853 stat = GdipDrawImage(graphics, (GpImage*)bitmap, 0, 0);
854
855 GdipDeleteGraphics(graphics);
856 }
857
858 SelectObject(hdc, oldbitmap);
859 }
860 else
861 stat = GenericError;
862
863 DeleteDC(hdc);
864
865 if (stat != Ok && result)
866 {
867 DeleteObject(result);
868 result = NULL;
869 }
870
871 *hbmReturn = result;
872
873 return stat;
874 }
875
876 GpStatus WINGDIPAPI GdipConvertToEmfPlus(const GpGraphics* ref,
877 GpMetafile* metafile, BOOL* succ, EmfType emfType,
878 const WCHAR* description, GpMetafile** out_metafile)
879 {
880 static int calls;
881
882 if(!ref || !metafile || !out_metafile)
883 return InvalidParameter;
884
885 *succ = FALSE;
886 *out_metafile = NULL;
887
888 if(!(calls++))
889 FIXME("not implemented\n");
890
891 return NotImplemented;
892 }
893
894 /* FIXME: this should create a bitmap in the given size with the attributes
895 * (resolution etc.) of the graphics object */
896 GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT width, INT height,
897 GpGraphics* target, GpBitmap** bitmap)
898 {
899 static int calls;
900 GpStatus ret;
901
902 if(!target || !bitmap)
903 return InvalidParameter;
904
905 if(!(calls++))
906 FIXME("hacked stub\n");
907
908 ret = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat24bppRGB,
909 NULL, bitmap);
910
911 return ret;
912 }
913
914 GpStatus WINGDIPAPI GdipCreateBitmapFromHICON(HICON hicon, GpBitmap** bitmap)
915 {
916 GpStatus stat;
917 ICONINFO iinfo;
918 BITMAP bm;
919 int ret;
920 UINT width, height;
921 GpRect rect;
922 BitmapData lockeddata;
923 HDC screendc;
924 BOOL has_alpha;
925 int x, y;
926 BYTE *bits;
927 BITMAPINFOHEADER bih;
928 DWORD *src;
929 BYTE *dst_row;
930 DWORD *dst;
931
932 TRACE("%p, %p\n", hicon, bitmap);
933
934 if(!bitmap || !GetIconInfo(hicon, &iinfo))
935 return InvalidParameter;
936
937 /* get the size of the icon */
938 ret = GetObjectA(iinfo.hbmColor ? iinfo.hbmColor : iinfo.hbmMask, sizeof(bm), &bm);
939 if (ret == 0) {
940 DeleteObject(iinfo.hbmColor);
941 DeleteObject(iinfo.hbmMask);
942 return GenericError;
943 }
944
945 width = bm.bmWidth;
946
947 if (iinfo.hbmColor)
948 height = abs(bm.bmHeight);
949 else /* combined bitmap + mask */
950 height = abs(bm.bmHeight) / 2;
951
952 bits = HeapAlloc(GetProcessHeap(), 0, 4*width*height);
953 if (!bits) {
954 DeleteObject(iinfo.hbmColor);
955 DeleteObject(iinfo.hbmMask);
956 return OutOfMemory;
957 }
958
959 stat = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat32bppARGB, NULL, bitmap);
960 if (stat != Ok) {
961 DeleteObject(iinfo.hbmColor);
962 DeleteObject(iinfo.hbmMask);
963 HeapFree(GetProcessHeap(), 0, bits);
964 return stat;
965 }
966
967 rect.X = 0;
968 rect.Y = 0;
969 rect.Width = width;
970 rect.Height = height;
971
972 stat = GdipBitmapLockBits(*bitmap, &rect, ImageLockModeWrite, PixelFormat32bppARGB, &lockeddata);
973 if (stat != Ok) {
974 DeleteObject(iinfo.hbmColor);
975 DeleteObject(iinfo.hbmMask);
976 HeapFree(GetProcessHeap(), 0, bits);
977 GdipDisposeImage((GpImage*)*bitmap);
978 return stat;
979 }
980
981 bih.biSize = sizeof(bih);
982 bih.biWidth = width;
983 bih.biHeight = -height;
984 bih.biPlanes = 1;
985 bih.biBitCount = 32;
986 bih.biCompression = BI_RGB;
987 bih.biSizeImage = 0;
988 bih.biXPelsPerMeter = 0;
989 bih.biYPelsPerMeter = 0;
990 bih.biClrUsed = 0;
991 bih.biClrImportant = 0;
992
993 screendc = GetDC(0);
994 if (iinfo.hbmColor)
995 {
996 GetDIBits(screendc, iinfo.hbmColor, 0, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
997
998 if (bm.bmBitsPixel == 32)
999 {
1000 has_alpha = FALSE;
1001
1002 /* If any pixel has a non-zero alpha, ignore hbmMask */
1003 src = (DWORD*)bits;
1004 for (x=0; x<width && !has_alpha; x++)
1005 for (y=0; y<height && !has_alpha; y++)
1006 if ((*src++ & 0xff000000) != 0)
1007 has_alpha = TRUE;
1008 }
1009 else has_alpha = FALSE;
1010 }
1011 else
1012 {
1013 GetDIBits(screendc, iinfo.hbmMask, 0, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
1014 has_alpha = FALSE;
1015 }
1016
1017 /* copy the image data to the Bitmap */
1018 src = (DWORD*)bits;
1019 dst_row = lockeddata.Scan0;
1020 for (y=0; y<height; y++)
1021 {
1022 memcpy(dst_row, src, width*4);
1023 src += width;
1024 dst_row += lockeddata.Stride;
1025 }
1026
1027 if (!has_alpha)
1028 {
1029 if (iinfo.hbmMask)
1030 {
1031 /* read alpha data from the mask */
1032 if (iinfo.hbmColor)
1033 GetDIBits(screendc, iinfo.hbmMask, 0, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
1034 else
1035 GetDIBits(screendc, iinfo.hbmMask, height, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
1036
1037 src = (DWORD*)bits;
1038 dst_row = lockeddata.Scan0;
1039 for (y=0; y<height; y++)
1040 {
1041 dst = (DWORD*)dst_row;
1042 for (x=0; x<height; x++)
1043 {
1044 DWORD src_value = *src++;
1045 if (src_value)
1046 *dst++ = 0;
1047 else
1048 *dst++ |= 0xff000000;
1049 }
1050 dst_row += lockeddata.Stride;
1051 }
1052 }
1053 else
1054 {
1055 /* set constant alpha of 255 */
1056 dst_row = bits;
1057 for (y=0; y<height; y++)
1058 {
1059 dst = (DWORD*)dst_row;
1060 for (x=0; x<height; x++)
1061 *dst++ |= 0xff000000;
1062 dst_row += lockeddata.Stride;
1063 }
1064 }
1065 }
1066
1067 ReleaseDC(0, screendc);
1068
1069 DeleteObject(iinfo.hbmColor);
1070 DeleteObject(iinfo.hbmMask);
1071
1072 GdipBitmapUnlockBits(*bitmap, &lockeddata);
1073
1074 HeapFree(GetProcessHeap(), 0, bits);
1075
1076 return Ok;
1077 }
1078
1079 GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
1080 PixelFormat format, BYTE* scan0, GpBitmap** bitmap)
1081 {
1082 BITMAPINFOHEADER bmih;
1083 HBITMAP hbitmap;
1084 INT row_size, dib_stride;
1085 HDC hdc;
1086 BYTE *bits;
1087 int i;
1088
1089 TRACE("%d %d %d %d %p %p\n", width, height, stride, format, scan0, bitmap);
1090
1091 if (!bitmap) return InvalidParameter;
1092
1093 if(width <= 0 || height <= 0 || (scan0 && (stride % 4))){
1094 *bitmap = NULL;
1095 return InvalidParameter;
1096 }
1097
1098 if(scan0 && !stride)
1099 return InvalidParameter;
1100
1101 row_size = (width * PIXELFORMATBPP(format)+7) / 8;
1102 dib_stride = (row_size + 3) & ~3;
1103
1104 if(stride == 0)
1105 stride = dib_stride;
1106
1107 bmih.biSize = sizeof(BITMAPINFOHEADER);
1108 bmih.biWidth = width;
1109 bmih.biHeight = -height;
1110 bmih.biPlanes = 1;
1111 /* FIXME: use the rest of the data from format */
1112 bmih.biBitCount = PIXELFORMATBPP(format);
1113 bmih.biCompression = BI_RGB;
1114 bmih.biSizeImage = 0;
1115 bmih.biXPelsPerMeter = 0;
1116 bmih.biYPelsPerMeter = 0;
1117 bmih.biClrUsed = 0;
1118 bmih.biClrImportant = 0;
1119
1120 hdc = CreateCompatibleDC(NULL);
1121 if (!hdc) return GenericError;
1122
1123 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, (void**)&bits,
1124 NULL, 0);
1125
1126 DeleteDC(hdc);
1127
1128 if (!hbitmap) return GenericError;
1129
1130 /* copy bits to the dib if necessary */
1131 /* FIXME: should reference the bits instead of copying them */
1132 if (scan0)
1133 for (i=0; i<height; i++)
1134 memcpy(bits+i*dib_stride, scan0+i*stride, row_size);
1135
1136 *bitmap = GdipAlloc(sizeof(GpBitmap));
1137 if(!*bitmap)
1138 {
1139 DeleteObject(hbitmap);
1140 return OutOfMemory;
1141 }
1142
1143 (*bitmap)->image.type = ImageTypeBitmap;
1144 memcpy(&(*bitmap)->image.format, &ImageFormatMemoryBMP, sizeof(GUID));
1145 (*bitmap)->image.flags = ImageFlagsNone;
1146 (*bitmap)->width = width;
1147 (*bitmap)->height = height;
1148 (*bitmap)->format = format;
1149 (*bitmap)->image.picture = NULL;
1150 (*bitmap)->hbitmap = hbitmap;
1151 (*bitmap)->hdc = NULL;
1152 (*bitmap)->bits = bits;
1153 (*bitmap)->stride = dib_stride;
1154
1155 return Ok;
1156 }
1157
1158 GpStatus WINGDIPAPI GdipCreateBitmapFromStream(IStream* stream,
1159 GpBitmap **bitmap)
1160 {
1161 GpStatus stat;
1162
1163 TRACE("%p %p\n", stream, bitmap);
1164
1165 stat = GdipLoadImageFromStream(stream, (GpImage**) bitmap);
1166
1167 if(stat != Ok)
1168 return stat;
1169
1170 if((*bitmap)->image.type != ImageTypeBitmap){
1171 GdipDisposeImage(&(*bitmap)->image);
1172 *bitmap = NULL;
1173 return GenericError; /* FIXME: what error to return? */
1174 }
1175
1176 return Ok;
1177 }
1178
1179 /* FIXME: no icm */
1180 GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream* stream,
1181 GpBitmap **bitmap)
1182 {
1183 TRACE("%p %p\n", stream, bitmap);
1184
1185 return GdipCreateBitmapFromStream(stream, bitmap);
1186 }
1187
1188 GpStatus WINGDIPAPI GdipCreateCachedBitmap(GpBitmap *bitmap, GpGraphics *graphics,
1189 GpCachedBitmap **cachedbmp)
1190 {
1191 GpStatus stat;
1192
1193 TRACE("%p %p %p\n", bitmap, graphics, cachedbmp);
1194
1195 if(!bitmap || !graphics || !cachedbmp)
1196 return InvalidParameter;
1197
1198 *cachedbmp = GdipAlloc(sizeof(GpCachedBitmap));
1199 if(!*cachedbmp)
1200 return OutOfMemory;
1201
1202 stat = GdipCloneImage(&(bitmap->image), &(*cachedbmp)->image);
1203 if(stat != Ok){
1204 GdipFree(*cachedbmp);
1205 return stat;
1206 }
1207
1208 return Ok;
1209 }
1210
1211 GpStatus WINGDIPAPI GdipCreateHICONFromBitmap(GpBitmap *bitmap, HICON *hicon)
1212 {
1213 FIXME("(%p, %p)\n", bitmap, hicon);
1214
1215 return NotImplemented;
1216 }
1217
1218 GpStatus WINGDIPAPI GdipDeleteCachedBitmap(GpCachedBitmap *cachedbmp)
1219 {
1220 TRACE("%p\n", cachedbmp);
1221
1222 if(!cachedbmp)
1223 return InvalidParameter;
1224
1225 GdipDisposeImage(cachedbmp->image);
1226 GdipFree(cachedbmp);
1227
1228 return Ok;
1229 }
1230
1231 GpStatus WINGDIPAPI GdipDrawCachedBitmap(GpGraphics *graphics,
1232 GpCachedBitmap *cachedbmp, INT x, INT y)
1233 {
1234 TRACE("%p %p %d %d\n", graphics, cachedbmp, x, y);
1235
1236 if(!graphics || !cachedbmp)
1237 return InvalidParameter;
1238
1239 return GdipDrawImage(graphics, cachedbmp->image, (REAL)x, (REAL)y);
1240 }
1241
1242 GpStatus WINGDIPAPI GdipEmfToWmfBits(HENHMETAFILE hemf, UINT cbData16,
1243 LPBYTE pData16, INT iMapMode, INT eFlags)
1244 {
1245 FIXME("(%p, %d, %p, %d, %d): stub\n", hemf, cbData16, pData16, iMapMode, eFlags);
1246 return NotImplemented;
1247 }
1248
1249 GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
1250 {
1251 TRACE("%p\n", image);
1252
1253 if(!image)
1254 return InvalidParameter;
1255
1256 if (image->picture)
1257 IPicture_Release(image->picture);
1258 if (image->type == ImageTypeBitmap)
1259 {
1260 GdipFree(((GpBitmap*)image)->bitmapbits);
1261 DeleteDC(((GpBitmap*)image)->hdc);
1262 }
1263 GdipFree(image);
1264
1265 return Ok;
1266 }
1267
1268 GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage *image, ImageItemData* item)
1269 {
1270 if(!image || !item)
1271 return InvalidParameter;
1272
1273 return NotImplemented;
1274 }
1275
1276 GpStatus WINGDIPAPI GdipGetImageBounds(GpImage *image, GpRectF *srcRect,
1277 GpUnit *srcUnit)
1278 {
1279 TRACE("%p %p %p\n", image, srcRect, srcUnit);
1280
1281 if(!image || !srcRect || !srcUnit)
1282 return InvalidParameter;
1283 if(image->type == ImageTypeMetafile){
1284 *srcRect = ((GpMetafile*)image)->bounds;
1285 *srcUnit = ((GpMetafile*)image)->unit;
1286 }
1287 else if(image->type == ImageTypeBitmap){
1288 srcRect->X = srcRect->Y = 0.0;
1289 srcRect->Width = (REAL) ((GpBitmap*)image)->width;
1290 srcRect->Height = (REAL) ((GpBitmap*)image)->height;
1291 *srcUnit = UnitPixel;
1292 }
1293 else{
1294 srcRect->X = srcRect->Y = 0.0;
1295 srcRect->Width = ipicture_pixel_width(image->picture);
1296 srcRect->Height = ipicture_pixel_height(image->picture);
1297 *srcUnit = UnitPixel;
1298 }
1299
1300 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect->X, srcRect->Y,
1301 srcRect->Width, srcRect->Height, *srcUnit);
1302
1303 return Ok;
1304 }
1305
1306 GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
1307 REAL *height)
1308 {
1309 TRACE("%p %p %p\n", image, width, height);
1310
1311 if(!image || !height || !width)
1312 return InvalidParameter;
1313
1314 if(image->type == ImageTypeMetafile){
1315 HDC hdc = GetDC(0);
1316
1317 *height = convert_unit(hdc, ((GpMetafile*)image)->unit) *
1318 ((GpMetafile*)image)->bounds.Height;
1319
1320 *width = convert_unit(hdc, ((GpMetafile*)image)->unit) *
1321 ((GpMetafile*)image)->bounds.Width;
1322
1323 ReleaseDC(0, hdc);
1324 }
1325
1326 else if(image->type == ImageTypeBitmap){
1327 *height = ((GpBitmap*)image)->height;
1328 *width = ((GpBitmap*)image)->width;
1329 }
1330 else{
1331 *height = ipicture_pixel_height(image->picture);
1332 *width = ipicture_pixel_width(image->picture);
1333 }
1334
1335 TRACE("returning (%f, %f)\n", *height, *width);
1336 return Ok;
1337 }
1338
1339 GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image,
1340 GpGraphics **graphics)
1341 {
1342 HDC hdc;
1343
1344 TRACE("%p %p\n", image, graphics);
1345
1346 if(!image || !graphics)
1347 return InvalidParameter;
1348
1349 if(image->type != ImageTypeBitmap){
1350 FIXME("not implemented for image type %d\n", image->type);
1351 return NotImplemented;
1352 }
1353
1354 hdc = ((GpBitmap*)image)->hdc;
1355
1356 if(!hdc){
1357 hdc = CreateCompatibleDC(0);
1358 SelectObject(hdc, ((GpBitmap*)image)->hbitmap);
1359 ((GpBitmap*)image)->hdc = hdc;
1360 }
1361
1362 return GdipCreateFromHDC(hdc, graphics);
1363 }
1364
1365 GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
1366 {
1367 TRACE("%p %p\n", image, height);
1368
1369 if(!image || !height)
1370 return InvalidParameter;
1371
1372 if(image->type == ImageTypeMetafile){
1373 HDC hdc = GetDC(0);
1374
1375 *height = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
1376 ((GpMetafile*)image)->bounds.Height);
1377
1378 ReleaseDC(0, hdc);
1379 }
1380 else if(image->type == ImageTypeBitmap)
1381 *height = ((GpBitmap*)image)->height;
1382 else
1383 *height = ipicture_pixel_height(image->picture);
1384
1385 TRACE("returning %d\n", *height);
1386
1387 return Ok;
1388 }
1389
1390 GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res)
1391 {
1392 static int calls;
1393
1394 if(!image || !res)
1395 return InvalidParameter;
1396
1397 if(!(calls++))
1398 FIXME("not implemented\n");
1399
1400 return NotImplemented;
1401 }
1402
1403 GpStatus WINGDIPAPI GdipGetImagePaletteSize(GpImage *image, INT *size)
1404 {
1405 FIXME("%p %p\n", image, size);
1406
1407 if(!image || !size)
1408 return InvalidParameter;
1409
1410 return NotImplemented;
1411 }
1412
1413 /* FIXME: test this function for non-bitmap types */
1414 GpStatus WINGDIPAPI GdipGetImagePixelFormat(GpImage *image, PixelFormat *format)
1415 {
1416 TRACE("%p %p\n", image, format);
1417
1418 if(!image || !format)
1419 return InvalidParameter;
1420
1421 if(image->type != ImageTypeBitmap)
1422 *format = PixelFormat24bppRGB;
1423 else
1424 *format = ((GpBitmap*) image)->format;
1425
1426 return Ok;
1427 }
1428
1429 GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage *image, GUID *format)
1430 {
1431 if(!image || !format)
1432 return InvalidParameter;
1433
1434 memcpy(format, &image->format, sizeof(GUID));
1435
1436 return Ok;
1437 }
1438
1439 GpStatus WINGDIPAPI GdipGetImageType(GpImage *image, ImageType *type)
1440 {
1441 TRACE("%p %p\n", image, type);
1442
1443 if(!image || !type)
1444 return InvalidParameter;
1445
1446 *type = image->type;
1447
1448 return Ok;
1449 }
1450
1451 GpStatus WINGDIPAPI GdipGetImageVerticalResolution(GpImage *image, REAL *res)
1452 {
1453 static int calls;
1454
1455 if(!image || !res)
1456 return InvalidParameter;
1457
1458 if(!(calls++))
1459 FIXME("not implemented\n");
1460
1461 return NotImplemented;
1462 }
1463
1464 GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
1465 {
1466 TRACE("%p %p\n", image, width);
1467
1468 if(!image || !width)
1469 return InvalidParameter;
1470
1471 if(image->type == ImageTypeMetafile){
1472 HDC hdc = GetDC(0);
1473
1474 *width = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
1475 ((GpMetafile*)image)->bounds.Width);
1476
1477 ReleaseDC(0, hdc);
1478 }
1479 else if(image->type == ImageTypeBitmap)
1480 *width = ((GpBitmap*)image)->width;
1481 else
1482 *width = ipicture_pixel_width(image->picture);
1483
1484 TRACE("returning %d\n", *width);
1485
1486 return Ok;
1487 }
1488
1489 GpStatus WINGDIPAPI GdipGetMetafileHeaderFromMetafile(GpMetafile * metafile,
1490 MetafileHeader * header)
1491 {
1492 static int calls;
1493
1494 if(!metafile || !header)
1495 return InvalidParameter;
1496
1497 if(!(calls++))
1498 FIXME("not implemented\n");
1499
1500 return Ok;
1501 }
1502
1503 GpStatus WINGDIPAPI GdipGetAllPropertyItems(GpImage *image, UINT size,
1504 UINT num, PropertyItem* items)
1505 {
1506 static int calls;
1507
1508 if(!(calls++))
1509 FIXME("not implemented\n");
1510
1511 return InvalidParameter;
1512 }
1513
1514 GpStatus WINGDIPAPI GdipGetPropertyCount(GpImage *image, UINT* num)
1515 {
1516 static int calls;
1517
1518 if(!(calls++))
1519 FIXME("not implemented\n");
1520
1521 return InvalidParameter;
1522 }
1523
1524 GpStatus WINGDIPAPI GdipGetPropertyIdList(GpImage *image, UINT num, PROPID* list)
1525 {
1526 static int calls;
1527
1528 if(!(calls++))
1529 FIXME("not implemented\n");
1530
1531 return InvalidParameter;
1532 }
1533
1534 GpStatus WINGDIPAPI GdipGetPropertyItem(GpImage *image, PROPID id, UINT size,
1535 PropertyItem* buffer)
1536 {
1537 static int calls;
1538
1539 if(!(calls++))
1540 FIXME("not implemented\n");
1541
1542 return InvalidParameter;
1543 }
1544
1545 GpStatus WINGDIPAPI GdipGetPropertyItemSize(GpImage *image, PROPID pid,
1546 UINT* size)
1547 {
1548 static int calls;
1549
1550 TRACE("%p %x %p\n", image, pid, size);
1551
1552 if(!size || !image)
1553 return InvalidParameter;
1554
1555 if(!(calls++))
1556 FIXME("not implemented\n");
1557
1558 return NotImplemented;
1559 }
1560
1561 GpStatus WINGDIPAPI GdipGetPropertySize(GpImage *image, UINT* size, UINT* num)
1562 {
1563 static int calls;
1564
1565 if(!(calls++))
1566 FIXME("not implemented\n");
1567
1568 return InvalidParameter;
1569 }
1570
1571 GpStatus WINGDIPAPI GdipImageGetFrameCount(GpImage *image,
1572 GDIPCONST GUID* dimensionID, UINT* count)
1573 {
1574 static int calls;
1575
1576 if(!image || !dimensionID || !count)
1577 return InvalidParameter;
1578
1579 if(!(calls++))
1580 FIXME("not implemented\n");
1581
1582 return NotImplemented;
1583 }
1584
1585 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsCount(GpImage *image,
1586 UINT* count)
1587 {
1588 if(!image || !count)
1589 return InvalidParameter;
1590
1591 *count = 1;
1592
1593 FIXME("stub\n");
1594
1595 return Ok;
1596 }
1597
1598 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsList(GpImage* image,
1599 GUID* dimensionIDs, UINT count)
1600 {
1601 static int calls;
1602
1603 if(!image || !dimensionIDs)
1604 return InvalidParameter;
1605
1606 if(!(calls++))
1607 FIXME("not implemented\n");
1608
1609 return Ok;
1610 }
1611
1612 GpStatus WINGDIPAPI GdipImageSelectActiveFrame(GpImage *image,
1613 GDIPCONST GUID* dimensionID, UINT frameidx)
1614 {
1615 static int calls;
1616
1617 if(!image || !dimensionID)
1618 return InvalidParameter;
1619
1620 if(!(calls++))
1621 FIXME("not implemented\n");
1622
1623 return Ok;
1624 }
1625
1626 GpStatus WINGDIPAPI GdipLoadImageFromFile(GDIPCONST WCHAR* filename,
1627 GpImage **image)
1628 {
1629 GpStatus stat;
1630 IStream *stream;
1631
1632 TRACE("(%s) %p\n", debugstr_w(filename), image);
1633
1634 if (!filename || !image)
1635 return InvalidParameter;
1636
1637 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
1638
1639 if (stat != Ok)
1640 return stat;
1641
1642 stat = GdipLoadImageFromStream(stream, image);
1643
1644 IStream_Release(stream);
1645
1646 return stat;
1647 }
1648
1649 /* FIXME: no icm handling */
1650 GpStatus WINGDIPAPI GdipLoadImageFromFileICM(GDIPCONST WCHAR* filename,GpImage **image)
1651 {
1652 TRACE("(%s) %p\n", debugstr_w(filename), image);
1653
1654 return GdipLoadImageFromFile(filename, image);
1655 }
1656
1657 static const WICPixelFormatGUID *wic_pixel_formats[] = {
1658 &GUID_WICPixelFormat16bppBGR555,
1659 &GUID_WICPixelFormat24bppBGR,
1660 &GUID_WICPixelFormat32bppBGR,
1661 &GUID_WICPixelFormat32bppBGRA,
1662 &GUID_WICPixelFormat32bppPBGRA,
1663 NULL
1664 };
1665
1666 static const PixelFormat wic_gdip_formats[] = {
1667 PixelFormat16bppRGB555,
1668 PixelFormat24bppRGB,
1669 PixelFormat32bppRGB,
1670 PixelFormat32bppARGB,
1671 PixelFormat32bppPARGB,
1672 };
1673
1674 static GpStatus decode_image_wic(IStream* stream, REFCLSID clsid, GpImage **image)
1675 {
1676 GpStatus status=Ok;
1677 GpBitmap *bitmap;
1678 HRESULT hr;
1679 IWICBitmapDecoder *decoder;
1680 IWICBitmapFrameDecode *frame;
1681 IWICBitmapSource *source=NULL;
1682 WICPixelFormatGUID wic_format;
1683 PixelFormat gdip_format=0;
1684 int i;
1685 UINT width, height;
1686 BitmapData lockeddata;
1687 WICRect wrc;
1688 HRESULT initresult;
1689
1690 initresult = CoInitialize(NULL);
1691
1692 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER,
1693 &IID_IWICBitmapDecoder, (void**)&decoder);
1694 if (FAILED(hr)) goto end;
1695
1696 hr = IWICBitmapDecoder_Initialize(decoder, (IStream*)stream, WICDecodeMetadataCacheOnLoad);
1697 if (SUCCEEDED(hr))
1698 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
1699
1700 if (SUCCEEDED(hr)) /* got frame */
1701 {
1702 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &wic_format);
1703
1704 if (SUCCEEDED(hr))
1705 {
1706 for (i=0; wic_pixel_formats[i]; i++)
1707 {
1708 if (IsEqualGUID(&wic_format, wic_pixel_formats[i]))
1709 {
1710 source = (IWICBitmapSource*)frame;
1711 IWICBitmapSource_AddRef(source);
1712 gdip_format = wic_gdip_formats[i];
1713 break;
1714 }
1715 }
1716 if (!source)
1717 {
1718 /* unknown format; fall back on 32bppARGB */
1719 hr = WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA, (IWICBitmapSource*)frame, &source);
1720 gdip_format = PixelFormat32bppARGB;
1721 }
1722 }
1723
1724 if (SUCCEEDED(hr)) /* got source */
1725 {
1726 hr = IWICBitmapSource_GetSize(source, &width, &height);
1727
1728 if (SUCCEEDED(hr))
1729 status = GdipCreateBitmapFromScan0(width, height, 0, gdip_format,
1730 NULL, &bitmap);
1731
1732 if (SUCCEEDED(hr) && status == Ok) /* created bitmap */
1733 {
1734 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeWrite,
1735 gdip_format, &lockeddata);
1736 if (status == Ok) /* locked bitmap */
1737 {
1738 wrc.X = 0;
1739 wrc.Width = width;
1740 wrc.Height = 1;
1741 for (i=0; i<height; i++)
1742 {
1743 wrc.Y = i;
1744 hr = IWICBitmapSource_CopyPixels(source, &wrc, abs(lockeddata.Stride),
1745 abs(lockeddata.Stride), (BYTE*)lockeddata.Scan0+lockeddata.Stride*i);
1746 if (FAILED(hr)) break;
1747 }
1748
1749 GdipBitmapUnlockBits(bitmap, &lockeddata);
1750 }
1751
1752 if (SUCCEEDED(hr) && status == Ok)
1753 *image = (GpImage*)bitmap;
1754 else
1755 {
1756 *image = NULL;
1757 GdipDisposeImage((GpImage*)bitmap);
1758 }
1759 }
1760
1761 IWICBitmapSource_Release(source);
1762 }
1763
1764 IWICBitmapFrameDecode_Release(frame);
1765 }
1766
1767 IWICBitmapDecoder_Release(decoder);
1768
1769 end:
1770 if (SUCCEEDED(initresult)) CoUninitialize();
1771
1772 if (FAILED(hr) && status == Ok) status = hresult_to_status(hr);
1773
1774 return status;
1775 }
1776
1777 static GpStatus decode_image_icon(IStream* stream, REFCLSID clsid, GpImage **image)
1778 {
1779 return decode_image_wic(stream, &CLSID_WICIcoDecoder, image);
1780 }
1781
1782 static GpStatus decode_image_bmp(IStream* stream, REFCLSID clsid, GpImage **image)
1783 {
1784 GpStatus status;
1785 GpBitmap* bitmap;
1786
1787 status = decode_image_wic(stream, &CLSID_WICBmpDecoder, image);
1788
1789 bitmap = (GpBitmap*)*image;
1790
1791 if (status == Ok && bitmap->format == PixelFormat32bppARGB)
1792 {
1793 /* WIC supports bmp files with alpha, but gdiplus does not */
1794 bitmap->format = PixelFormat32bppRGB;
1795 }
1796
1797 return status;
1798 }
1799
1800 static GpStatus decode_image_jpeg(IStream* stream, REFCLSID clsid, GpImage **image)
1801 {
1802 return decode_image_wic(stream, &CLSID_WICJpegDecoder, image);
1803 }
1804
1805 static GpStatus decode_image_png(IStream* stream, REFCLSID clsid, GpImage **image)
1806 {
1807 return decode_image_wic(stream, &CLSID_WICPngDecoder, image);
1808 }
1809
1810 static GpStatus decode_image_gif(IStream* stream, REFCLSID clsid, GpImage **image)
1811 {
1812 return decode_image_wic(stream, &CLSID_WICGifDecoder, image);
1813 }
1814
1815 static GpStatus decode_image_olepicture_metafile(IStream* stream, REFCLSID clsid, GpImage **image)
1816 {
1817 IPicture *pic;
1818
1819 TRACE("%p %p\n", stream, image);
1820
1821 if(!stream || !image)
1822 return InvalidParameter;
1823
1824 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
1825 (LPVOID*) &pic) != S_OK){
1826 TRACE("Could not load picture\n");
1827 return GenericError;
1828 }
1829
1830 /* FIXME: missing initialization code */
1831 *image = GdipAlloc(sizeof(GpMetafile));
1832 if(!*image) return OutOfMemory;
1833 (*image)->type = ImageTypeMetafile;
1834 (*image)->picture = pic;
1835 (*image)->flags = ImageFlagsNone;
1836
1837 return Ok;
1838 }
1839
1840 typedef GpStatus (*encode_image_func)(GpImage *image, IStream* stream,
1841 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params);
1842
1843 typedef GpStatus (*decode_image_func)(IStream *stream, REFCLSID clsid, GpImage** image);
1844
1845 typedef struct image_codec {
1846 ImageCodecInfo info;
1847 encode_image_func encode_func;
1848 decode_image_func decode_func;
1849 } image_codec;
1850
1851 typedef enum {
1852 BMP,
1853 JPEG,
1854 GIF,
1855 EMF,
1856 WMF,
1857 PNG,
1858 ICO,
1859 NUM_CODECS
1860 } ImageFormat;
1861
1862 static const struct image_codec codecs[NUM_CODECS];
1863
1864 static GpStatus get_decoder_info(IStream* stream, const struct image_codec **result)
1865 {
1866 BYTE signature[8];
1867 LARGE_INTEGER seek;
1868 HRESULT hr;
1869 UINT bytesread;
1870 int i, j;
1871
1872 /* seek to the start of the stream */
1873 seek.QuadPart = 0;
1874 hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL);
1875 if (FAILED(hr)) return hresult_to_status(hr);
1876
1877 /* read the first 8 bytes */
1878 /* FIXME: This assumes all codecs have one signature <= 8 bytes in length */
1879 hr = IStream_Read(stream, signature, 8, &bytesread);
1880 if (FAILED(hr)) return hresult_to_status(hr);
1881 if (hr == S_FALSE || bytesread == 0) return GenericError;
1882
1883 for (i = 0; i < NUM_CODECS; i++) {
1884 if ((codecs[i].info.Flags & ImageCodecFlagsDecoder) &&
1885 bytesread >= codecs[i].info.SigSize)
1886 {
1887 for (j=0; j<codecs[i].info.SigSize; j++)
1888 if ((signature[j] & codecs[i].info.SigMask[j]) != codecs[i].info.SigPattern[j])
1889 break;
1890 if (j == codecs[i].info.SigSize)
1891 {
1892 *result = &codecs[i];
1893 return Ok;
1894 }
1895 }
1896 }
1897
1898 TRACE("no match for %i byte signature %x %x %x %x %x %x %x %x\n", bytesread,
1899 signature[0],signature[1],signature[2],signature[3],
1900 signature[4],signature[5],signature[6],signature[7]);
1901
1902 return GenericError;
1903 }
1904
1905 GpStatus WINGDIPAPI GdipLoadImageFromStream(IStream* stream, GpImage **image)
1906 {
1907 GpStatus stat;
1908 LARGE_INTEGER seek;
1909 HRESULT hr;
1910 const struct image_codec *codec=NULL;
1911
1912 /* choose an appropriate image decoder */
1913 stat = get_decoder_info(stream, &codec);
1914 if (stat != Ok) return stat;
1915
1916 /* seek to the start of the stream */
1917 seek.QuadPart = 0;
1918 hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL);
1919 if (FAILED(hr)) return hresult_to_status(hr);
1920
1921 /* call on the image decoder to do the real work */
1922 stat = codec->decode_func(stream, &codec->info.Clsid, image);
1923
1924 /* take note of the original data format */
1925 if (stat == Ok)
1926 {
1927 memcpy(&(*image)->format, &codec->info.FormatID, sizeof(GUID));
1928 }
1929
1930 return stat;
1931 }
1932
1933 /* FIXME: no ICM */
1934 GpStatus WINGDIPAPI GdipLoadImageFromStreamICM(IStream* stream, GpImage **image)
1935 {
1936 TRACE("%p %p\n", stream, image);
1937
1938 return GdipLoadImageFromStream(stream, image);
1939 }
1940
1941 GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
1942 {
1943 static int calls;
1944
1945 if(!image)
1946 return InvalidParameter;
1947
1948 if(!(calls++))
1949 FIXME("not implemented\n");
1950
1951 return NotImplemented;
1952 }
1953
1954 GpStatus WINGDIPAPI GdipSetPropertyItem(GpImage *image, GDIPCONST PropertyItem* item)
1955 {
1956 static int calls;
1957
1958 if(!(calls++))
1959 FIXME("not implemented\n");
1960
1961 return NotImplemented;
1962 }
1963
1964 GpStatus WINGDIPAPI GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
1965 GDIPCONST CLSID *clsidEncoder,
1966 GDIPCONST EncoderParameters *encoderParams)
1967 {
1968 GpStatus stat;
1969 IStream *stream;
1970
1971 TRACE("%p (%s) %p %p\n", image, debugstr_w(filename), clsidEncoder, encoderParams);
1972
1973 if (!image || !filename|| !clsidEncoder)
1974 return InvalidParameter;
1975
1976 stat = GdipCreateStreamOnFile(filename, GENERIC_WRITE, &stream);
1977 if (stat != Ok)
1978 return GenericError;
1979
1980 stat = GdipSaveImageToStream(image, stream, clsidEncoder, encoderParams);
1981
1982 IStream_Release(stream);
1983 return stat;
1984 }
1985
1986 /*************************************************************************
1987 * Encoding functions -
1988 * These functions encode an image in different image file formats.
1989 */
1990 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
1991 #define BITMAP_FORMAT_JPEG 0xd8ff
1992 #define BITMAP_FORMAT_GIF 0x4947
1993 #define BITMAP_FORMAT_PNG 0x5089
1994 #define BITMAP_FORMAT_APM 0xcdd7
1995
1996 static GpStatus encode_image_WIC(GpImage *image, IStream* stream,
1997 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
1998 {
1999 GpStatus stat;
2000 GpBitmap *bitmap;
2001 IWICBitmapEncoder *encoder;
2002 IWICBitmapFrameEncode *frameencode;
2003 IPropertyBag2 *encoderoptions;
2004 HRESULT hr;
2005 UINT width, height;
2006 PixelFormat gdipformat=0;
2007 WICPixelFormatGUID wicformat;
2008 GpRect rc;
2009 BitmapData lockeddata;
2010 HRESULT initresult;
2011 UINT i;
2012
2013 if (image->type != ImageTypeBitmap)
2014 return GenericError;
2015
2016 bitmap = (GpBitmap*)image;
2017
2018 GdipGetImageWidth(image, &width);
2019 GdipGetImageHeight(image, &height);
2020
2021 rc.X = 0;
2022 rc.Y = 0;
2023 rc.Width = width;
2024 rc.Height = height;
2025
2026 initresult = CoInitialize(NULL);
2027
2028 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER,
2029 &IID_IWICBitmapEncoder, (void**)&encoder);
2030 if (FAILED(hr))
2031 {
2032 if (SUCCEEDED(initresult)) CoUninitialize();
2033 return hresult_to_status(hr);
2034 }
2035
2036 hr = IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache);
2037
2038 if (SUCCEEDED(hr))
2039 {
2040 hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frameencode, &encoderoptions);
2041 }
2042
2043 if (SUCCEEDED(hr)) /* created frame */
2044 {
2045 hr = IWICBitmapFrameEncode_Initialize(frameencode, encoderoptions);
2046
2047 if (SUCCEEDED(hr))
2048 hr = IWICBitmapFrameEncode_SetSize(frameencode, width, height);
2049
2050 if (SUCCEEDED(hr))
2051 /* FIXME: use the resolution from the image */
2052 hr = IWICBitmapFrameEncode_SetResolution(frameencode, 96.0, 96.0);
2053
2054 if (SUCCEEDED(hr))
2055 {
2056 for (i=0; wic_pixel_formats[i]; i++)
2057 {
2058 if (wic_gdip_formats[i] == bitmap->format)
2059 break;
2060 }
2061 if (wic_pixel_formats[i])
2062 memcpy(&wicformat, wic_pixel_formats[i], sizeof(GUID));
2063 else
2064 memcpy(&wicformat, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID));
2065
2066 hr = IWICBitmapFrameEncode_SetPixelFormat(frameencode, &wicformat);
2067
2068 for (i=0; wic_pixel_formats[i]; i++)
2069 {
2070 if (IsEqualGUID(&wicformat, wic_pixel_formats[i]))
2071 break;
2072 }
2073 if (wic_pixel_formats[i])
2074 gdipformat = wic_gdip_formats[i];
2075 else
2076 {
2077 ERR("cannot provide pixel format %s\n", debugstr_guid(&wicformat));
2078 hr = E_FAIL;
2079 }
2080 }
2081
2082 if (SUCCEEDED(hr))
2083 {
2084 stat = GdipBitmapLockBits(bitmap, &rc, ImageLockModeRead, gdipformat,
2085 &lockeddata);
2086
2087 if (stat == Ok)
2088 {
2089 UINT row_size = (lockeddata.Width * PIXELFORMATBPP(gdipformat) + 7)/8;
2090 BYTE *row;
2091
2092 /* write one row at a time in case stride is negative */
2093 row = lockeddata.Scan0;
2094 for (i=0; i<lockeddata.Height; i++)
2095 {
2096 hr = IWICBitmapFrameEncode_WritePixels(frameencode, 1, row_size, row_size, row);
2097 if (FAILED(hr)) break;
2098 row += lockeddata.Stride;
2099 }
2100
2101 GdipBitmapUnlockBits(bitmap, &lockeddata);
2102 }
2103 else
2104 hr = E_FAIL;
2105 }
2106
2107 if (SUCCEEDED(hr))
2108 hr = IWICBitmapFrameEncode_Commit(frameencode);
2109
2110 IWICBitmapFrameEncode_Release(frameencode);
2111 IPropertyBag2_Release(encoderoptions);
2112 }
2113
2114 if (SUCCEEDED(hr))
2115 hr = IWICBitmapEncoder_Commit(encoder);
2116
2117 IWICBitmapEncoder_Release(encoder);
2118
2119 if (SUCCEEDED(initresult)) CoUninitialize();
2120
2121 return hresult_to_status(hr);
2122 }
2123
2124 static GpStatus encode_image_BMP(GpImage *image, IStream* stream,
2125 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
2126 {
2127 return encode_image_WIC(image, stream, &CLSID_WICBmpEncoder, params);
2128 }
2129
2130 static GpStatus encode_image_png(GpImage *image, IStream* stream,
2131 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
2132 {
2133 return encode_image_WIC(image, stream, &CLSID_WICPngEncoder, params);
2134 }
2135
2136 /*****************************************************************************
2137 * GdipSaveImageToStream [GDIPLUS.@]
2138 */
2139 GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
2140 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
2141 {
2142 GpStatus stat;
2143 encode_image_func encode_image;
2144 int i;
2145
2146 TRACE("%p %p %p %p\n", image, stream, clsid, params);
2147
2148 if(!image || !stream)
2149 return InvalidParameter;
2150
2151 /* select correct encoder */
2152 encode_image = NULL;
2153 for (i = 0; i < NUM_CODECS; i++) {
2154 if ((codecs[i].info.Flags & ImageCodecFlagsEncoder) &&
2155 IsEqualCLSID(clsid, &codecs[i].info.Clsid))
2156 encode_image = codecs[i].encode_func;
2157 }
2158 if (encode_image == NULL)
2159 return UnknownImageFormat;
2160
2161 stat = encode_image(image, stream, clsid, params);
2162
2163 return stat;
2164 }
2165
2166 /*****************************************************************************
2167 * GdipGetImagePalette [GDIPLUS.@]
2168 */
2169 GpStatus WINGDIPAPI GdipGetImagePalette(GpImage *image, ColorPalette *palette, INT size)
2170 {
2171 static int calls = 0;
2172
2173 if(!image)
2174 return InvalidParameter;
2175
2176 if(!(calls++))
2177 FIXME("not implemented\n");
2178
2179 return NotImplemented;
2180 }
2181
2182 /*****************************************************************************
2183 * GdipSetImagePalette [GDIPLUS.@]
2184 */
2185 GpStatus WINGDIPAPI GdipSetImagePalette(GpImage *image,
2186 GDIPCONST ColorPalette *palette)
2187 {
2188 static int calls;
2189
2190 if(!image || !palette)
2191 return InvalidParameter;
2192
2193 if(!(calls++))
2194 FIXME("not implemented\n");
2195
2196 return NotImplemented;
2197 }
2198
2199 /*************************************************************************
2200 * Encoders -
2201 * Structures that represent which formats we support for encoding.
2202 */
2203
2204 /* ImageCodecInfo creation routines taken from libgdiplus */
2205 static const WCHAR bmp_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
2206 static const WCHAR bmp_extension[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
2207 static const WCHAR bmp_mimetype[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
2208 static const WCHAR bmp_format[] = {'B', 'M', 'P', 0}; /* BMP */
2209 static const BYTE bmp_sig_pattern[] = { 0x42, 0x4D };
2210 static const BYTE bmp_sig_mask[] = { 0xFF, 0xFF };
2211
2212 static const WCHAR jpeg_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'J','P','E','G', 0};
2213 static const WCHAR jpeg_extension[] = {'*','.','J','P','G',';', '*','.','J','P','E','G',';', '*','.','J','P','E',';', '*','.','J','F','I','F',0};
2214 static const WCHAR jpeg_mimetype[] = {'i','m','a','g','e','/','j','p','e','g', 0};
2215 static const WCHAR jpeg_format[] = {'J','P','E','G',0};
2216 static const BYTE jpeg_sig_pattern[] = { 0xFF, 0xD8 };
2217 static const BYTE jpeg_sig_mask[] = { 0xFF, 0xFF };
2218
2219 static const WCHAR gif_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'G','I','F', 0};
2220 static const WCHAR gif_extension[] = {'*','.','G','I','F',0};
2221 static const WCHAR gif_mimetype[] = {'i','m','a','g','e','/','g','i','f', 0};
2222 static const WCHAR gif_format[] = {'G','I','F',0};
2223 static const BYTE gif_sig_pattern[4] = "GIF8";
2224 static const BYTE gif_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF };
2225
2226 static const WCHAR emf_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'E','M','F', 0};
2227 static const WCHAR emf_extension[] = {'*','.','E','M','F',0};
2228 static const WCHAR emf_mimetype[] = {'i','m','a','g','e','/','x','-','e','m','f', 0};
2229 static const WCHAR emf_format[] = {'E','M','F',0};
2230 static const BYTE emf_sig_pattern[] = { 0x01, 0x00, 0x00, 0x00 };
2231 static const BYTE emf_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF };
2232
2233 static const WCHAR wmf_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'W','M','F', 0};
2234 static const WCHAR wmf_extension[] = {'*','.','W','M','F',0};
2235 static const WCHAR wmf_mimetype[] = {'i','m','a','g','e','/','x','-','w','m','f', 0};
2236 static const WCHAR wmf_format[] = {'W','M','F',0};
2237 static const BYTE wmf_sig_pattern[] = { 0xd7, 0xcd };
2238 static const BYTE wmf_sig_mask[] = { 0xFF, 0xFF };
2239
2240 static const WCHAR png_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'P','N','G', 0};
2241 static const WCHAR png_extension[] = {'*','.','P','N','G',0};
2242 static const WCHAR png_mimetype[] = {'i','m','a','g','e','/','p','n','g', 0};
2243 static const WCHAR png_format[] = {'P','N','G',0};
2244 static const BYTE png_sig_pattern[] = { 137, 80, 78, 71, 13, 10, 26, 10, };
2245 static const BYTE png_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
2246
2247 static const WCHAR ico_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'I','C','O', 0};
2248 static const WCHAR ico_extension[] = {'*','.','I','C','O',0};
2249 static const WCHAR ico_mimetype[] = {'i','m','a','g','e','/','x','-','i','c','o','n', 0};
2250 static const WCHAR ico_format[] = {'I','C','O',0};
2251 static const BYTE ico_sig_pattern[] = { 0x00, 0x00, 0x01, 0x00 };
2252 static const BYTE ico_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF };
2253
2254 static const struct image_codec codecs[NUM_CODECS] = {
2255 {
2256 { /* BMP */
2257 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2258 /* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2259 /* CodecName */ bmp_codecname,
2260 /* DllName */ NULL,
2261 /* FormatDescription */ bmp_format,
2262 /* FilenameExtension */ bmp_extension,
2263 /* MimeType */ bmp_mimetype,
2264 /* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2265 /* Version */ 1,
2266 /* SigCount */ 1,
2267 /* SigSize */ 2,
2268 /* SigPattern */ bmp_sig_pattern,
2269 /* SigMask */ bmp_sig_mask,
2270 },
2271 encode_image_BMP,
2272 decode_image_bmp
2273 },
2274 {
2275 { /* JPEG */
2276 /* Clsid */ { 0x557cf401, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2277 /* FormatID */ { 0xb96b3caeU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2278 /* CodecName */ jpeg_codecname,
2279 /* DllName */ NULL,
2280 /* FormatDescription */ jpeg_format,
2281 /* FilenameExtension */ jpeg_extension,
2282 /* MimeType */ jpeg_mimetype,
2283 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2284 /* Version */ 1,
2285 /* SigCount */ 1,
2286 /* SigSize */ 2,
2287 /* SigPattern */ jpeg_sig_pattern,
2288 /* SigMask */ jpeg_sig_mask,
2289 },
2290 NULL,
2291 decode_image_jpeg
2292 },
2293 {
2294 { /* GIF */
2295 /* Clsid */ { 0x557cf402, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2296 /* FormatID */ { 0xb96b3cb0U, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2297 /* CodecName */ gif_codecname,
2298 /* DllName */ NULL,
2299 /* FormatDescription */ gif_format,
2300 /* FilenameExtension */ gif_extension,
2301 /* MimeType */ gif_mimetype,
2302 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2303 /* Version */ 1,
2304 /* SigCount */ 1,
2305 /* SigSize */ 4,
2306 /* SigPattern */ gif_sig_pattern,
2307 /* SigMask */ gif_sig_mask,
2308 },
2309 NULL,
2310 decode_image_gif
2311 },
2312 {
2313 { /* EMF */
2314 /* Clsid */ { 0x557cf403, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2315 /* FormatID */ { 0xb96b3cacU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2316 /* CodecName */ emf_codecname,
2317 /* DllName */ NULL,
2318 /* FormatDescription */ emf_format,
2319 /* FilenameExtension */ emf_extension,
2320 /* MimeType */ emf_mimetype,
2321 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportVector | ImageCodecFlagsBuiltin,
2322 /* Version */ 1,
2323 /* SigCount */ 1,
2324 /* SigSize */ 4,
2325 /* SigPattern */ emf_sig_pattern,
2326 /* SigMask */ emf_sig_mask,
2327 },
2328 NULL,
2329 decode_image_olepicture_metafile
2330 },
2331 {
2332 { /* WMF */
2333 /* Clsid */ { 0x557cf404, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2334 /* FormatID */ { 0xb96b3cadU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2335 /* CodecName */ wmf_codecname,
2336 /* DllName */ NULL,
2337 /* FormatDescription */ wmf_format,
2338 /* FilenameExtension */ wmf_extension,
2339 /* MimeType */ wmf_mimetype,
2340 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportVector | ImageCodecFlagsBuiltin,
2341 /* Version */ 1,
2342 /* SigCount */ 1,
2343 /* SigSize */ 2,
2344 /* SigPattern */ wmf_sig_pattern,
2345 /* SigMask */ wmf_sig_mask,
2346 },
2347 NULL,
2348 decode_image_olepicture_metafile
2349 },
2350 {
2351 { /* PNG */
2352 /* Clsid */ { 0x557cf406, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2353 /* FormatID */ { 0xb96b3cafU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2354 /* CodecName */ png_codecname,
2355 /* DllName */ NULL,
2356 /* FormatDescription */ png_format,
2357 /* FilenameExtension */ png_extension,
2358 /* MimeType */ png_mimetype,
2359 /* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2360 /* Version */ 1,
2361 /* SigCount */ 1,
2362 /* SigSize */ 8,
2363 /* SigPattern */ png_sig_pattern,
2364 /* SigMask */ png_sig_mask,
2365 },
2366 encode_image_png,
2367 decode_image_png
2368 },
2369 {
2370 { /* ICO */
2371 /* Clsid */ { 0x557cf407, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2372 /* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2373 /* CodecName */ ico_codecname,
2374 /* DllName */ NULL,
2375 /* FormatDescription */ ico_format,
2376 /* FilenameExtension */ ico_extension,
2377 /* MimeType */ ico_mimetype,
2378 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2379 /* Version */ 1,
2380 /* SigCount */ 1,
2381 /* SigSize */ 4,
2382 /* SigPattern */ ico_sig_pattern,
2383 /* SigMask */ ico_sig_mask,
2384 },
2385 NULL,
2386 decode_image_icon
2387 },
2388 };
2389
2390 /*****************************************************************************
2391 * GdipGetImageDecodersSize [GDIPLUS.@]
2392 */
2393 GpStatus WINGDIPAPI GdipGetImageDecodersSize(UINT *numDecoders, UINT *size)
2394 {
2395 int decoder_count=0;
2396 int i;
2397 TRACE("%p %p\n", numDecoders, size);
2398
2399 if (!numDecoders || !size)
2400 return InvalidParameter;
2401
2402 for (i=0; i<NUM_CODECS; i++)
2403 {
2404 if (codecs[i].info.Flags & ImageCodecFlagsDecoder)
2405 decoder_count++;
2406 }
2407
2408 *numDecoders = decoder_count;
2409 *size = decoder_count * sizeof(ImageCodecInfo);
2410
2411 return Ok;
2412 }
2413
2414 /*****************************************************************************
2415 * GdipGetImageDecoders [GDIPLUS.@]
2416 */
2417 GpStatus WINGDIPAPI GdipGetImageDecoders(UINT numDecoders, UINT size, ImageCodecInfo *decoders)
2418 {
2419 int i, decoder_count=0;
2420 TRACE("%u %u %p\n", numDecoders, size, decoders);
2421
2422 if (!decoders ||
2423 size != numDecoders * sizeof(ImageCodecInfo))
2424 return GenericError;
2425
2426 for (i=0; i<NUM_CODECS; i++)
2427 {
2428 if (codecs[i].info.Flags & ImageCodecFlagsDecoder)
2429 {
2430 if (decoder_count == numDecoders) return GenericError;
2431 memcpy(&decoders[decoder_count], &codecs[i].info, sizeof(ImageCodecInfo));
2432 decoder_count++;
2433 }
2434 }
2435
2436 if (decoder_count < numDecoders) return GenericError;
2437
2438 return Ok;
2439 }
2440
2441 /*****************************************************************************
2442 * GdipGetImageEncodersSize [GDIPLUS.@]
2443 */
2444 GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size)
2445 {
2446 int encoder_count=0;
2447 int i;
2448 TRACE("%p %p\n", numEncoders, size);
2449
2450 if (!numEncoders || !size)
2451 return InvalidParameter;
2452
2453 for (i=0; i<NUM_CODECS; i++)
2454 {
2455 if (codecs[i].info.Flags & ImageCodecFlagsEncoder)
2456 encoder_count++;
2457 }
2458
2459 *numEncoders = encoder_count;
2460 *size = encoder_count * sizeof(ImageCodecInfo);
2461
2462 return Ok;
2463 }
2464
2465 /*****************************************************************************
2466 * GdipGetImageEncoders [GDIPLUS.@]
2467 */
2468 GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders)
2469 {
2470 int i, encoder_count=0;
2471 TRACE("%u %u %p\n", numEncoders, size, encoders);
2472
2473 if (!encoders ||
2474 size != numEncoders * sizeof(ImageCodecInfo))
2475 return GenericError;
2476
2477 for (i=0; i<NUM_CODECS; i++)
2478 {
2479 if (codecs[i].info.Flags & ImageCodecFlagsEncoder)
2480 {
2481 if (encoder_count == numEncoders) return GenericError;
2482 memcpy(&encoders[encoder_count], &codecs[i].info, sizeof(ImageCodecInfo));
2483 encoder_count++;
2484 }
2485 }
2486
2487 if (encoder_count < numEncoders) return GenericError;
2488
2489 return Ok;
2490 }
2491
2492 /*****************************************************************************
2493 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
2494 */
2495 GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBitmap** bitmap)
2496 {
2497 BITMAP bm;
2498 GpStatus retval;
2499 PixelFormat format;
2500 BYTE* bits;
2501
2502 TRACE("%p %p %p\n", hbm, hpal, bitmap);
2503
2504 if(!hbm || !bitmap)
2505 return InvalidParameter;
2506
2507 /* TODO: Support for device-dependent bitmaps */
2508 if(hpal){
2509 FIXME("no support for device-dependent bitmaps\n");
2510 return NotImplemented;
2511 }
2512
2513 if (GetObjectA(hbm, sizeof(bm), &bm) != sizeof(bm))
2514 return InvalidParameter;
2515
2516 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
2517 switch(bm.bmBitsPixel) {
2518 case 1:
2519 format = PixelFormat1bppIndexed;
2520 break;
2521 case 4:
2522 format = PixelFormat4bppIndexed;
2523 break;
2524 case 8:
2525 format = PixelFormat8bppIndexed;
2526 break;
2527 case 24:
2528 format = PixelFormat24bppRGB;
2529 break;
2530 case 32:
2531 format = PixelFormat32bppRGB;
2532 break;
2533 case 48:
2534 format = PixelFormat48bppRGB;
2535 break;
2536 default:
2537 FIXME("don't know how to handle %d bpp\n", bm.bmBitsPixel);
2538 return InvalidParameter;
2539 }
2540
2541 if (bm.bmBits)
2542 bits = (BYTE*)bm.bmBits + (bm.bmHeight - 1) * bm.bmWidthBytes;
2543 else
2544 {
2545 FIXME("can only get image data from DIB sections\n");
2546 bits = NULL;
2547 }
2548
2549 retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, -bm.bmWidthBytes,
2550 format, bits, bitmap);
2551
2552 return retval;
2553 }
2554
2555 GpStatus WINGDIPAPI GdipDeleteEffect(CGpEffect *effect)
2556 {
2557 FIXME("(%p): stub\n", effect);
2558 /* note: According to Jose Roca's GDI+ Docs, this is not implemented
2559 * in Windows's gdiplus */
2560 return NotImplemented;
2561 }
2562
2563 /*****************************************************************************
2564 * GdipSetEffectParameters [GDIPLUS.@]
2565 */
2566 GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect *effect,
2567 const VOID *params, const UINT size)
2568 {
2569 static int calls;
2570
2571 if(!(calls++))
2572 FIXME("not implemented\n");
2573
2574 return NotImplemented;
2575 }
2576
2577 /*****************************************************************************
2578 * GdipGetImageFlags [GDIPLUS.@]
2579 */
2580 GpStatus WINGDIPAPI GdipGetImageFlags(GpImage *image, UINT *flags)
2581 {
2582 TRACE("%p %p\n", image, flags);
2583
2584 if(!image || !flags)
2585 return InvalidParameter;
2586
2587 *flags = image->flags;
2588
2589 return Ok;
2590 }
2591
2592 GpStatus WINGDIPAPI GdipTestControl(GpTestControlEnum control, void *param)
2593 {
2594 TRACE("(%d, %p)\n", control, param);
2595
2596 switch(control){
2597 case TestControlForceBilinear:
2598 if(param)
2599 FIXME("TestControlForceBilinear not handled\n");
2600 break;
2601 case TestControlNoICM:
2602 if(param)
2603 FIXME("TestControlNoICM not handled\n");
2604 break;
2605 case TestControlGetBuildNumber:
2606 *((DWORD*)param) = 3102;
2607 break;
2608 }
2609
2610 return Ok;
2611 }
2612
2613 GpStatus WINGDIPAPI GdipRecordMetafileFileName(GDIPCONST WCHAR* fileName,
2614 HDC hdc, EmfType type, GDIPCONST GpRectF *pFrameRect,
2615 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc,
2616 GpMetafile **metafile)
2617 {
2618 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
2619 frameUnit, debugstr_w(desc), metafile);
2620
2621 return NotImplemented;
2622 }
2623
2624 GpStatus WINGDIPAPI GdipRecordMetafileFileNameI(GDIPCONST WCHAR* fileName, HDC hdc, EmfType type,
2625 GDIPCONST GpRect *pFrameRect, MetafileFrameUnit frameUnit,
2626 GDIPCONST WCHAR *desc, GpMetafile **metafile)
2627 {
2628 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
2629 frameUnit, debugstr_w(desc), metafile);
2630
2631 return NotImplemented;
2632 }
2633
2634 GpStatus WINGDIPAPI GdipImageForceValidation(GpImage *image)
2635 {
2636 FIXME("%p\n", image);
2637
2638 return Ok;
2639 }
2640
2641 /*****************************************************************************
2642 * GdipGetImageThumbnail [GDIPLUS.@]
2643 */
2644 GpStatus WINGDIPAPI GdipGetImageThumbnail(GpImage *image, UINT width, UINT height,
2645 GpImage **ret_image, GetThumbnailImageAbort cb,
2646 VOID * cb_data)
2647 {
2648 FIXME("(%p %u %u %p %p %p) stub\n",
2649 image, width, height, ret_image, cb, cb_data);
2650 return NotImplemented;
2651 }
2652
2653 /*****************************************************************************
2654 * GdipImageRotateFlip [GDIPLUS.@]
2655 */
2656 GpStatus WINGDIPAPI GdipImageRotateFlip(GpImage *image, RotateFlipType type)
2657 {
2658 FIXME("(%p %u) stub\n", image, type);
2659 return NotImplemented;
2660 }