gdiplus: Explicitly copy the bits from dib sections to new bitmaps.
[wine/hacks.git] / dlls / gdiplus / image.c
blobaa03712b9f0db9448cc5709f00cfad86b3f59810
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
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.
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.
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
19 #include <stdarg.h>
21 #define NONAMELESSUNION
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wingdi.h"
28 #define COBJMACROS
29 #include "objbase.h"
30 #include "olectl.h"
31 #include "ole2.h"
33 #include "initguid.h"
34 #include "wincodec.h"
35 #include "gdiplus.h"
36 #include "gdiplus_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
41 #define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
43 static INT ipicture_pixel_height(IPicture *pic)
45 HDC hdcref;
46 OLE_YSIZE_HIMETRIC y;
48 IPicture_get_Height(pic, &y);
50 hdcref = GetDC(0);
52 y = MulDiv(y, GetDeviceCaps(hdcref, LOGPIXELSY), INCH_HIMETRIC);
53 ReleaseDC(0, hdcref);
55 return y;
58 static INT ipicture_pixel_width(IPicture *pic)
60 HDC hdcref;
61 OLE_XSIZE_HIMETRIC x;
63 IPicture_get_Width(pic, &x);
65 hdcref = GetDC(0);
67 x = MulDiv(x, GetDeviceCaps(hdcref, LOGPIXELSX), INCH_HIMETRIC);
69 ReleaseDC(0, hdcref);
71 return x;
74 GpStatus WINGDIPAPI GdipBitmapApplyEffect(GpBitmap* bitmap, CGpEffect* effect,
75 RECT* roi, BOOL useAuxData, VOID** auxData, INT* auxDataSize)
77 FIXME("(%p %p %p %d %p %p): stub\n", bitmap, effect, roi, useAuxData, auxData, auxDataSize);
79 * Note: According to Jose Roca's GDI+ docs, this function is not
80 * implemented in Windows's GDI+.
82 return NotImplemented;
85 GpStatus WINGDIPAPI GdipBitmapCreateApplyEffect(GpBitmap** inputBitmaps,
86 INT numInputs, CGpEffect* effect, RECT* roi, RECT* outputRect,
87 GpBitmap** outputBitmap, BOOL useAuxData, VOID** auxData, INT* auxDataSize)
89 FIXME("(%p %d %p %p %p %p %d %p %p): stub\n", inputBitmaps, numInputs, effect, roi, outputRect, outputBitmap, useAuxData, auxData, auxDataSize);
91 * Note: According to Jose Roca's GDI+ docs, this function is not
92 * implemented in Windows's GDI+.
94 return NotImplemented;
97 static inline void getpixel_16bppGrayScale(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
98 const BYTE *row, UINT x)
100 *r = *g = *b = row[x*2+1];
101 *a = 255;
104 static inline void getpixel_16bppRGB555(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
105 const BYTE *row, UINT x)
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;
114 static inline void getpixel_16bppRGB565(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
115 const BYTE *row, UINT x)
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;
124 static inline void getpixel_16bppARGB1555(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
125 const BYTE *row, UINT x)
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;
137 static inline void getpixel_24bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
138 const BYTE *row, UINT x)
140 *r = row[x*3+2];
141 *g = row[x*3+1];
142 *b = row[x*3];
143 *a = 255;
146 static inline void getpixel_32bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
147 const BYTE *row, UINT x)
149 *r = row[x*4+2];
150 *g = row[x*4+1];
151 *b = row[x*4];
152 *a = 255;
155 static inline void getpixel_32bppARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
156 const BYTE *row, UINT x)
158 *r = row[x*4+2];
159 *g = row[x*4+1];
160 *b = row[x*4];
161 *a = row[x*4+3];
164 static inline void getpixel_32bppPARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
165 const BYTE *row, UINT x)
167 *a = row[x*4+3];
168 if (*a == 0)
169 *r = *g = *b = 0;
170 else
172 *r = row[x*4+2] * 255 / *a;
173 *g = row[x*4+1] * 255 / *a;
174 *b = row[x*4] * 255 / *a;
178 static inline void getpixel_48bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
179 const BYTE *row, UINT x)
181 *r = row[x*6+5];
182 *g = row[x*6+3];
183 *b = row[x*6+1];
184 *a = 255;
187 static inline void getpixel_64bppARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
188 const BYTE *row, UINT x)
190 *r = row[x*8+5];
191 *g = row[x*8+3];
192 *b = row[x*8+1];
193 *a = row[x*8+7];
196 static inline void getpixel_64bppPARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
197 const BYTE *row, UINT x)
199 *a = row[x*8+7];
200 if (*a == 0)
201 *r = *g = *b = 0;
202 else
204 *r = row[x*8+5] * 255 / *a;
205 *g = row[x*8+3] * 255 / *a;
206 *b = row[x*8+1] * 255 / *a;
210 GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y,
211 ARGB *color)
213 BYTE r, g, b, a;
214 BYTE *row;
215 TRACE("%p %d %d %p\n", bitmap, x, y, color);
217 if(!bitmap || !color ||
218 x < 0 || y < 0 || x >= bitmap->width || y >= bitmap->height)
219 return InvalidParameter;
221 row = bitmap->bits+bitmap->stride*y;
223 switch (bitmap->format)
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;
263 *color = a<<24|r<<16|g<<8|b;
265 return Ok;
268 static inline void setpixel_16bppGrayScale(BYTE r, BYTE g, BYTE b, BYTE a,
269 BYTE *row, UINT x)
271 *((WORD*)(row)+x) = (r+g+b)*85;
274 static inline void setpixel_16bppRGB555(BYTE r, BYTE g, BYTE b, BYTE a,
275 BYTE *row, UINT x)
277 *((WORD*)(row)+x) = (r<<7&0x7c00)|
278 (g<<2&0x03e0)|
279 (b>>3&0x001f);
282 static inline void setpixel_16bppRGB565(BYTE r, BYTE g, BYTE b, BYTE a,
283 BYTE *row, UINT x)
285 *((WORD*)(row)+x) = (r<<8&0xf800)|
286 (g<<3&0x07e0)|
287 (b>>3&0x001f);
290 static inline void setpixel_16bppARGB1555(BYTE r, BYTE g, BYTE b, BYTE a,
291 BYTE *row, UINT x)
293 *((WORD*)(row)+x) = (a<<8&0x8000)|
294 (r<<7&0x7c00)|
295 (g<<2&0x03e0)|
296 (b>>3&0x001f);
299 static inline void setpixel_24bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
300 BYTE *row, UINT x)
302 row[x*3+2] = r;
303 row[x*3+1] = g;
304 row[x*3] = b;
307 static inline void setpixel_32bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
308 BYTE *row, UINT x)
310 *((DWORD*)(row)+x) = (r<<16)|(g<<8)|b;
313 static inline void setpixel_32bppARGB(BYTE r, BYTE g, BYTE b, BYTE a,
314 BYTE *row, UINT x)
316 *((DWORD*)(row)+x) = (a<<24)|(r<<16)|(g<<8)|b;
319 static inline void setpixel_32bppPARGB(BYTE r, BYTE g, BYTE b, BYTE a,
320 BYTE *row, UINT x)
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;
328 static inline void setpixel_48bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
329 BYTE *row, UINT x)
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;
336 static inline void setpixel_64bppARGB(BYTE r, BYTE g, BYTE b, BYTE a,
337 BYTE *row, UINT x)
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;
343 static inline void setpixel_64bppPARGB(BYTE r, BYTE g, BYTE b, BYTE a,
344 BYTE *row, UINT x)
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;
354 GpStatus WINGDIPAPI GdipBitmapSetPixel(GpBitmap* bitmap, INT x, INT y,
355 ARGB color)
357 BYTE a, r, g, b;
358 BYTE *row;
359 TRACE("bitmap:%p, x:%d, y:%d, color:%08x\n", bitmap, x, y, color);
361 if(!bitmap || x < 0 || y < 0 || x >= bitmap->width || y >= bitmap->height)
362 return InvalidParameter;
364 a = color>>24;
365 r = color>>16;
366 g = color>>8;
367 b = color;
369 row = bitmap->bits + bitmap->stride * y;
371 switch (bitmap->format)
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;
411 return Ok;
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).
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)
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 */
432 TRACE("%p %p %d %d %p\n", bitmap, rect, flags, format, lockeddata);
434 if(!lockeddata || !bitmap)
435 return InvalidParameter;
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;
442 act_rect = *rect;
444 else{
445 act_rect.X = act_rect.Y = 0;
446 act_rect.Width = bitmap->width;
447 act_rect.Height = bitmap->height;
450 if(flags & ImageLockModeUserInputBuf)
451 return NotImplemented;
453 if(bitmap->lockmode)
454 return WrongState;
456 if (bitmap->bits && bitmap->format == format)
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;
467 bitmap->lockmode = flags;
468 bitmap->numlocks++;
470 return Ok;
473 hbm = bitmap->hbitmap;
474 hdc = bitmap->hdc;
475 bm_is_selected = (hdc != 0);
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;
483 if(!bm_is_selected){
484 hdc = CreateCompatibleDC(0);
485 old = SelectObject(hdc, hbm);
488 /* fill out bmi */
489 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
491 abs_height = abs(pbmi->bmiHeader.biHeight);
492 stride = pbmi->bmiHeader.biWidth * bitspp / 8;
493 stride = (stride + 3) & ~3;
495 buff = GdipAlloc(stride * abs_height);
497 pbmi->bmiHeader.biBitCount = bitspp;
499 if(buff)
500 GetDIBits(hdc, hbm, 0, abs_height, buff, pbmi, DIB_RGB_COLORS);
502 if(!bm_is_selected){
503 SelectObject(hdc, old);
504 DeleteDC(hdc);
507 if(!buff){
508 GdipFree(pbmi);
509 return OutOfMemory;
512 lockeddata->Width = act_rect.Width;
513 lockeddata->Height = act_rect.Height;
514 lockeddata->PixelFormat = format;
515 lockeddata->Reserved = flags;
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);
522 else{
523 lockeddata->Stride = stride;
524 lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X + stride * act_rect.Y;
527 bitmap->lockmode = flags;
528 bitmap->numlocks++;
530 bitmap->bitmapbits = buff;
532 GdipFree(pbmi);
533 return Ok;
536 GpStatus WINGDIPAPI GdipBitmapSetResolution(GpBitmap* bitmap, REAL xdpi, REAL ydpi)
538 FIXME("(%p, %.2f, %.2f)\n", bitmap, xdpi, ydpi);
540 return NotImplemented;
543 GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap,
544 BitmapData* lockeddata)
546 HDC hdc;
547 HBITMAP hbm, old = NULL;
548 BOOL bm_is_selected;
549 BITMAPINFO *pbmi;
551 if(!bitmap || !lockeddata)
552 return InvalidParameter;
554 if(!bitmap->lockmode)
555 return WrongState;
557 if(lockeddata->Reserved & ImageLockModeUserInputBuf)
558 return NotImplemented;
560 if(lockeddata->Reserved & ImageLockModeRead){
561 if(!(--bitmap->numlocks))
562 bitmap->lockmode = 0;
564 GdipFree(bitmap->bitmapbits);
565 bitmap->bitmapbits = NULL;
566 return Ok;
569 if (!bitmap->bitmapbits)
571 /* we passed a direct reference; no need to do anything */
572 bitmap->lockmode = 0;
573 return Ok;
576 hbm = bitmap->hbitmap;
577 hdc = bitmap->hdc;
578 bm_is_selected = (hdc != 0);
580 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
581 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
582 pbmi->bmiHeader.biBitCount = 0;
584 if(!bm_is_selected){
585 hdc = CreateCompatibleDC(0);
586 old = SelectObject(hdc, hbm);
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);
594 if(!bm_is_selected){
595 SelectObject(hdc, old);
596 DeleteDC(hdc);
599 GdipFree(pbmi);
600 GdipFree(bitmap->bitmapbits);
601 bitmap->bitmapbits = NULL;
602 bitmap->lockmode = 0;
604 return Ok;
607 GpStatus WINGDIPAPI GdipCloneBitmapArea(REAL x, REAL y, REAL width, REAL height,
608 PixelFormat format, GpBitmap* srcBitmap, GpBitmap** dstBitmap)
610 BitmapData lockeddata_src, lockeddata_dst;
611 int i;
612 UINT row_size;
613 Rect area;
614 GpStatus stat;
616 TRACE("(%f,%f,%f,%f,%i,%p,%p)\n", x, y, width, height, format, srcBitmap, dstBitmap);
618 if (!srcBitmap || !dstBitmap || srcBitmap->image.type != ImageTypeBitmap ||
619 x < 0 || y < 0 ||
620 x + width > srcBitmap->width || y + height > srcBitmap->height)
622 TRACE("<-- InvalidParameter\n");
623 return InvalidParameter;
626 if (format == PixelFormatDontCare)
627 format = srcBitmap->format;
629 area.X = roundr(x);
630 area.Y = roundr(y);
631 area.Width = roundr(width);
632 area.Height = roundr(height);
634 stat = GdipBitmapLockBits(srcBitmap, &area, ImageLockModeRead, format,
635 &lockeddata_src);
636 if (stat != Ok) return stat;
638 stat = GdipCreateBitmapFromScan0(lockeddata_src.Width, lockeddata_src.Height,
639 0, lockeddata_src.PixelFormat, NULL, dstBitmap);
640 if (stat == Ok)
642 stat = GdipBitmapLockBits(*dstBitmap, NULL, ImageLockModeWrite,
643 lockeddata_src.PixelFormat, &lockeddata_dst);
645 if (stat == Ok)
647 /* copy the image data */
648 row_size = (lockeddata_src.Width * PIXELFORMATBPP(lockeddata_src.PixelFormat) +7)/8;
649 for (i=0; i<lockeddata_src.Height; i++)
650 memcpy((BYTE*)lockeddata_dst.Scan0+lockeddata_dst.Stride*i,
651 (BYTE*)lockeddata_src.Scan0+lockeddata_src.Stride*i,
652 row_size);
654 GdipBitmapUnlockBits(*dstBitmap, &lockeddata_dst);
657 if (stat != Ok)
658 GdipDisposeImage((GpImage*)*dstBitmap);
661 GdipBitmapUnlockBits(srcBitmap, &lockeddata_src);
663 if (stat != Ok)
665 *dstBitmap = NULL;
668 return stat;
671 GpStatus WINGDIPAPI GdipCloneBitmapAreaI(INT x, INT y, INT width, INT height,
672 PixelFormat format, GpBitmap* srcBitmap, GpBitmap** dstBitmap)
674 TRACE("(%i,%i,%i,%i,%i,%p,%p)\n", x, y, width, height, format, srcBitmap, dstBitmap);
676 return GdipCloneBitmapArea(x, y, width, height, format, srcBitmap, dstBitmap);
679 GpStatus WINGDIPAPI GdipCloneImage(GpImage *image, GpImage **cloneImage)
681 GpStatus stat = GenericError;
683 TRACE("%p, %p\n", image, cloneImage);
685 if (!image || !cloneImage)
686 return InvalidParameter;
688 if (image->picture)
690 IStream* stream;
691 HRESULT hr;
692 INT size;
693 LARGE_INTEGER move;
695 hr = CreateStreamOnHGlobal(0, TRUE, &stream);
696 if (FAILED(hr))
697 return GenericError;
699 hr = IPicture_SaveAsFile(image->picture, stream, FALSE, &size);
700 if(FAILED(hr))
702 WARN("Failed to save image on stream\n");
703 goto out;
706 /* Set seek pointer back to the beginning of the picture */
707 move.QuadPart = 0;
708 hr = IStream_Seek(stream, move, STREAM_SEEK_SET, NULL);
709 if (FAILED(hr))
710 goto out;
712 stat = GdipLoadImageFromStream(stream, cloneImage);
713 if (stat != Ok) WARN("Failed to load image from stream\n");
715 out:
716 IStream_Release(stream);
717 return stat;
719 else if (image->type == ImageTypeBitmap)
721 GpBitmap *bitmap = (GpBitmap*)image;
722 BitmapData lockeddata_src, lockeddata_dst;
723 int i;
724 UINT row_size;
726 stat = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, bitmap->format,
727 &lockeddata_src);
728 if (stat != Ok) return stat;
730 stat = GdipCreateBitmapFromScan0(lockeddata_src.Width, lockeddata_src.Height,
731 0, lockeddata_src.PixelFormat, NULL, (GpBitmap**)cloneImage);
732 if (stat == Ok)
734 stat = GdipBitmapLockBits((GpBitmap*)*cloneImage, NULL, ImageLockModeWrite,
735 lockeddata_src.PixelFormat, &lockeddata_dst);
737 if (stat == Ok)
739 /* copy the image data */
740 row_size = (lockeddata_src.Width * PIXELFORMATBPP(lockeddata_src.PixelFormat) +7)/8;
741 for (i=0; i<lockeddata_src.Height; i++)
742 memcpy((BYTE*)lockeddata_dst.Scan0+lockeddata_dst.Stride*i,
743 (BYTE*)lockeddata_src.Scan0+lockeddata_src.Stride*i,
744 row_size);
746 GdipBitmapUnlockBits((GpBitmap*)*cloneImage, &lockeddata_dst);
749 if (stat != Ok)
750 GdipDisposeImage(*cloneImage);
753 GdipBitmapUnlockBits(bitmap, &lockeddata_src);
755 if (stat != Ok)
757 *cloneImage = NULL;
759 else memcpy(&(*cloneImage)->format, &image->format, sizeof(GUID));
761 return stat;
763 else
765 ERR("GpImage with no IPicture or bitmap?!\n");
766 return NotImplemented;
770 GpStatus WINGDIPAPI GdipCreateBitmapFromFile(GDIPCONST WCHAR* filename,
771 GpBitmap **bitmap)
773 GpStatus stat;
774 IStream *stream;
776 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
778 if(!filename || !bitmap)
779 return InvalidParameter;
781 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
783 if(stat != Ok)
784 return stat;
786 stat = GdipCreateBitmapFromStream(stream, bitmap);
788 IStream_Release(stream);
790 return stat;
793 GpStatus WINGDIPAPI GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO* info,
794 VOID *bits, GpBitmap **bitmap)
796 DWORD height, stride;
797 PixelFormat format;
799 FIXME("(%p, %p, %p) - partially implemented\n", info, bits, bitmap);
801 height = abs(info->bmiHeader.biHeight);
802 stride = ((info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) >> 3) & ~3;
804 if(info->bmiHeader.biHeight > 0) /* bottom-up */
806 bits = (BYTE*)bits + (height - 1) * stride;
807 stride = -stride;
810 switch(info->bmiHeader.biBitCount) {
811 case 1:
812 format = PixelFormat1bppIndexed;
813 break;
814 case 4:
815 format = PixelFormat4bppIndexed;
816 break;
817 case 8:
818 format = PixelFormat8bppIndexed;
819 break;
820 case 24:
821 format = PixelFormat24bppRGB;
822 break;
823 default:
824 FIXME("don't know how to handle %d bpp\n", info->bmiHeader.biBitCount);
825 *bitmap = NULL;
826 return InvalidParameter;
829 return GdipCreateBitmapFromScan0(info->bmiHeader.biWidth, height, stride, format,
830 bits, bitmap);
834 /* FIXME: no icm */
835 GpStatus WINGDIPAPI GdipCreateBitmapFromFileICM(GDIPCONST WCHAR* filename,
836 GpBitmap **bitmap)
838 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
840 return GdipCreateBitmapFromFile(filename, bitmap);
843 GpStatus WINGDIPAPI GdipCreateBitmapFromResource(HINSTANCE hInstance,
844 GDIPCONST WCHAR* lpBitmapName, GpBitmap** bitmap)
846 HBITMAP hbm;
847 GpStatus stat = InvalidParameter;
849 TRACE("%p (%s) %p\n", hInstance, debugstr_w(lpBitmapName), bitmap);
851 if(!lpBitmapName || !bitmap)
852 return InvalidParameter;
854 /* load DIB */
855 hbm = LoadImageW(hInstance, lpBitmapName, IMAGE_BITMAP, 0, 0,
856 LR_CREATEDIBSECTION);
858 if(hbm){
859 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, bitmap);
860 DeleteObject(hbm);
863 return stat;
866 GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
867 HBITMAP* hbmReturn, ARGB background)
869 GpStatus stat;
870 HBITMAP result, oldbitmap;
871 UINT width, height;
872 HDC hdc;
873 GpGraphics *graphics;
874 BITMAPINFOHEADER bih;
875 void *bits;
876 TRACE("(%p,%p,%x)\n", bitmap, hbmReturn, background);
878 if (!bitmap || !hbmReturn) return InvalidParameter;
880 GdipGetImageWidth((GpImage*)bitmap, &width);
881 GdipGetImageHeight((GpImage*)bitmap, &height);
883 bih.biSize = sizeof(bih);
884 bih.biWidth = width;
885 bih.biHeight = height;
886 bih.biPlanes = 1;
887 bih.biBitCount = 32;
888 bih.biCompression = BI_RGB;
889 bih.biSizeImage = 0;
890 bih.biXPelsPerMeter = 0;
891 bih.biYPelsPerMeter = 0;
892 bih.biClrUsed = 0;
893 bih.biClrImportant = 0;
895 hdc = CreateCompatibleDC(NULL);
896 if (!hdc) return GenericError;
898 result = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS, &bits,
899 NULL, 0);
901 if (result)
903 oldbitmap = SelectObject(hdc, result);
905 stat = GdipCreateFromHDC(hdc, &graphics);
906 if (stat == Ok)
908 stat = GdipGraphicsClear(graphics, background);
910 if (stat == Ok)
911 stat = GdipDrawImage(graphics, (GpImage*)bitmap, 0, 0);
913 GdipDeleteGraphics(graphics);
916 SelectObject(hdc, oldbitmap);
918 else
919 stat = GenericError;
921 DeleteDC(hdc);
923 if (stat != Ok && result)
925 DeleteObject(result);
926 result = NULL;
929 *hbmReturn = result;
931 return stat;
934 GpStatus WINGDIPAPI GdipConvertToEmfPlus(const GpGraphics* ref,
935 GpMetafile* metafile, BOOL* succ, EmfType emfType,
936 const WCHAR* description, GpMetafile** out_metafile)
938 static int calls;
940 if(!ref || !metafile || !out_metafile)
941 return InvalidParameter;
943 *succ = FALSE;
944 *out_metafile = NULL;
946 if(!(calls++))
947 FIXME("not implemented\n");
949 return NotImplemented;
952 /* FIXME: this should create a bitmap in the given size with the attributes
953 * (resolution etc.) of the graphics object */
954 GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT width, INT height,
955 GpGraphics* target, GpBitmap** bitmap)
957 static int calls;
958 GpStatus ret;
960 if(!target || !bitmap)
961 return InvalidParameter;
963 if(!(calls++))
964 FIXME("hacked stub\n");
966 ret = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat24bppRGB,
967 NULL, bitmap);
969 return ret;
972 GpStatus WINGDIPAPI GdipCreateBitmapFromHICON(HICON hicon, GpBitmap** bitmap)
974 GpStatus stat;
975 ICONINFO iinfo;
976 BITMAP bm;
977 int ret;
978 UINT width, height;
979 GpRect rect;
980 BitmapData lockeddata;
981 HDC screendc;
982 BOOL has_alpha;
983 int x, y;
984 BYTE *bits;
985 BITMAPINFOHEADER bih;
986 DWORD *src;
987 BYTE *dst_row;
988 DWORD *dst;
990 TRACE("%p, %p\n", hicon, bitmap);
992 if(!bitmap || !GetIconInfo(hicon, &iinfo))
993 return InvalidParameter;
995 /* get the size of the icon */
996 ret = GetObjectA(iinfo.hbmColor ? iinfo.hbmColor : iinfo.hbmMask, sizeof(bm), &bm);
997 if (ret == 0) {
998 DeleteObject(iinfo.hbmColor);
999 DeleteObject(iinfo.hbmMask);
1000 return GenericError;
1003 width = bm.bmWidth;
1005 if (iinfo.hbmColor)
1006 height = abs(bm.bmHeight);
1007 else /* combined bitmap + mask */
1008 height = abs(bm.bmHeight) / 2;
1010 bits = HeapAlloc(GetProcessHeap(), 0, 4*width*height);
1011 if (!bits) {
1012 DeleteObject(iinfo.hbmColor);
1013 DeleteObject(iinfo.hbmMask);
1014 return OutOfMemory;
1017 stat = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat32bppARGB, NULL, bitmap);
1018 if (stat != Ok) {
1019 DeleteObject(iinfo.hbmColor);
1020 DeleteObject(iinfo.hbmMask);
1021 HeapFree(GetProcessHeap(), 0, bits);
1022 return stat;
1025 rect.X = 0;
1026 rect.Y = 0;
1027 rect.Width = width;
1028 rect.Height = height;
1030 stat = GdipBitmapLockBits(*bitmap, &rect, ImageLockModeWrite, PixelFormat32bppARGB, &lockeddata);
1031 if (stat != Ok) {
1032 DeleteObject(iinfo.hbmColor);
1033 DeleteObject(iinfo.hbmMask);
1034 HeapFree(GetProcessHeap(), 0, bits);
1035 GdipDisposeImage((GpImage*)*bitmap);
1036 return stat;
1039 bih.biSize = sizeof(bih);
1040 bih.biWidth = width;
1041 bih.biHeight = -height;
1042 bih.biPlanes = 1;
1043 bih.biBitCount = 32;
1044 bih.biCompression = BI_RGB;
1045 bih.biSizeImage = 0;
1046 bih.biXPelsPerMeter = 0;
1047 bih.biYPelsPerMeter = 0;
1048 bih.biClrUsed = 0;
1049 bih.biClrImportant = 0;
1051 screendc = GetDC(0);
1052 if (iinfo.hbmColor)
1054 GetDIBits(screendc, iinfo.hbmColor, 0, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
1056 if (bm.bmBitsPixel == 32)
1058 has_alpha = FALSE;
1060 /* If any pixel has a non-zero alpha, ignore hbmMask */
1061 src = (DWORD*)bits;
1062 for (x=0; x<width && !has_alpha; x++)
1063 for (y=0; y<height && !has_alpha; y++)
1064 if ((*src++ & 0xff000000) != 0)
1065 has_alpha = TRUE;
1067 else has_alpha = FALSE;
1069 else
1071 GetDIBits(screendc, iinfo.hbmMask, 0, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
1072 has_alpha = FALSE;
1075 /* copy the image data to the Bitmap */
1076 src = (DWORD*)bits;
1077 dst_row = lockeddata.Scan0;
1078 for (y=0; y<height; y++)
1080 memcpy(dst_row, src, width*4);
1081 src += width;
1082 dst_row += lockeddata.Stride;
1085 if (!has_alpha)
1087 if (iinfo.hbmMask)
1089 /* read alpha data from the mask */
1090 if (iinfo.hbmColor)
1091 GetDIBits(screendc, iinfo.hbmMask, 0, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
1092 else
1093 GetDIBits(screendc, iinfo.hbmMask, height, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
1095 src = (DWORD*)bits;
1096 dst_row = lockeddata.Scan0;
1097 for (y=0; y<height; y++)
1099 dst = (DWORD*)dst_row;
1100 for (x=0; x<height; x++)
1102 DWORD src_value = *src++;
1103 if (src_value)
1104 *dst++ = 0;
1105 else
1106 *dst++ |= 0xff000000;
1108 dst_row += lockeddata.Stride;
1111 else
1113 /* set constant alpha of 255 */
1114 dst_row = bits;
1115 for (y=0; y<height; y++)
1117 dst = (DWORD*)dst_row;
1118 for (x=0; x<height; x++)
1119 *dst++ |= 0xff000000;
1120 dst_row += lockeddata.Stride;
1125 ReleaseDC(0, screendc);
1127 DeleteObject(iinfo.hbmColor);
1128 DeleteObject(iinfo.hbmMask);
1130 GdipBitmapUnlockBits(*bitmap, &lockeddata);
1132 HeapFree(GetProcessHeap(), 0, bits);
1134 return Ok;
1137 static void generate_halftone_palette(ARGB *entries, UINT count)
1139 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1140 UINT i;
1142 for (i=0; i<8 && i<count; i++)
1144 entries[i] = 0xff000000;
1145 if (i&1) entries[i] |= 0x800000;
1146 if (i&2) entries[i] |= 0x8000;
1147 if (i&4) entries[i] |= 0x80;
1150 if (8 < count)
1151 entries[i] = 0xffc0c0c0;
1153 for (i=9; i<16 && i<count; i++)
1155 entries[i] = 0xff000000;
1156 if (i&1) entries[i] |= 0xff0000;
1157 if (i&2) entries[i] |= 0xff00;
1158 if (i&4) entries[i] |= 0xff;
1161 for (i=16; i<40 && i<count; i++)
1163 entries[i] = 0;
1166 for (i=40; i<256 && i<count; i++)
1168 entries[i] = 0xff000000;
1169 entries[i] |= halftone_values[(i-40)%6];
1170 entries[i] |= halftone_values[((i-40)/6)%6] << 8;
1171 entries[i] |= halftone_values[((i-40)/36)%6] << 16;
1175 GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
1176 PixelFormat format, BYTE* scan0, GpBitmap** bitmap)
1178 BITMAPINFOHEADER bmih;
1179 HBITMAP hbitmap;
1180 INT row_size, dib_stride;
1181 HDC hdc;
1182 BYTE *bits;
1183 int i;
1185 TRACE("%d %d %d %d %p %p\n", width, height, stride, format, scan0, bitmap);
1187 if (!bitmap) return InvalidParameter;
1189 if(width <= 0 || height <= 0 || (scan0 && (stride % 4))){
1190 *bitmap = NULL;
1191 return InvalidParameter;
1194 if(scan0 && !stride)
1195 return InvalidParameter;
1197 row_size = (width * PIXELFORMATBPP(format)+7) / 8;
1198 dib_stride = (row_size + 3) & ~3;
1200 if(stride == 0)
1201 stride = dib_stride;
1203 bmih.biSize = sizeof(BITMAPINFOHEADER);
1204 bmih.biWidth = width;
1205 bmih.biHeight = -height;
1206 bmih.biPlanes = 1;
1207 /* FIXME: use the rest of the data from format */
1208 bmih.biBitCount = PIXELFORMATBPP(format);
1209 bmih.biCompression = BI_RGB;
1210 bmih.biSizeImage = 0;
1211 bmih.biXPelsPerMeter = 0;
1212 bmih.biYPelsPerMeter = 0;
1213 bmih.biClrUsed = 0;
1214 bmih.biClrImportant = 0;
1216 hdc = CreateCompatibleDC(NULL);
1217 if (!hdc) return GenericError;
1219 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, (void**)&bits,
1220 NULL, 0);
1222 DeleteDC(hdc);
1224 if (!hbitmap) return GenericError;
1226 /* copy bits to the dib if necessary */
1227 /* FIXME: should reference the bits instead of copying them */
1228 if (scan0)
1229 for (i=0; i<height; i++)
1230 memcpy(bits+i*dib_stride, scan0+i*stride, row_size);
1232 *bitmap = GdipAlloc(sizeof(GpBitmap));
1233 if(!*bitmap)
1235 DeleteObject(hbitmap);
1236 return OutOfMemory;
1239 (*bitmap)->image.type = ImageTypeBitmap;
1240 memcpy(&(*bitmap)->image.format, &ImageFormatMemoryBMP, sizeof(GUID));
1241 (*bitmap)->image.flags = ImageFlagsNone;
1242 (*bitmap)->image.palette_flags = 0;
1243 (*bitmap)->image.palette_count = 0;
1244 (*bitmap)->image.palette_size = 0;
1245 (*bitmap)->image.palette_entries = NULL;
1246 (*bitmap)->width = width;
1247 (*bitmap)->height = height;
1248 (*bitmap)->format = format;
1249 (*bitmap)->image.picture = NULL;
1250 (*bitmap)->hbitmap = hbitmap;
1251 (*bitmap)->hdc = NULL;
1252 (*bitmap)->bits = bits;
1253 (*bitmap)->stride = dib_stride;
1255 if (format == PixelFormat1bppIndexed ||
1256 format == PixelFormat4bppIndexed ||
1257 format == PixelFormat8bppIndexed)
1259 (*bitmap)->image.palette_size = (*bitmap)->image.palette_count = 1 << PIXELFORMATBPP(format);
1260 (*bitmap)->image.palette_entries = GdipAlloc(sizeof(ARGB) * ((*bitmap)->image.palette_size));
1262 if (!(*bitmap)->image.palette_entries)
1264 GdipDisposeImage(&(*bitmap)->image);
1265 *bitmap = NULL;
1266 return OutOfMemory;
1269 if (format == PixelFormat1bppIndexed)
1271 (*bitmap)->image.palette_flags = PaletteFlagsGrayScale;
1272 (*bitmap)->image.palette_entries[0] = 0xff000000;
1273 (*bitmap)->image.palette_entries[1] = 0xffffffff;
1275 else
1277 if (format == PixelFormat8bppIndexed)
1278 (*bitmap)->image.palette_flags = PaletteFlagsHalftone;
1280 generate_halftone_palette((*bitmap)->image.palette_entries,
1281 (*bitmap)->image.palette_count);
1285 return Ok;
1288 GpStatus WINGDIPAPI GdipCreateBitmapFromStream(IStream* stream,
1289 GpBitmap **bitmap)
1291 GpStatus stat;
1293 TRACE("%p %p\n", stream, bitmap);
1295 stat = GdipLoadImageFromStream(stream, (GpImage**) bitmap);
1297 if(stat != Ok)
1298 return stat;
1300 if((*bitmap)->image.type != ImageTypeBitmap){
1301 GdipDisposeImage(&(*bitmap)->image);
1302 *bitmap = NULL;
1303 return GenericError; /* FIXME: what error to return? */
1306 return Ok;
1309 /* FIXME: no icm */
1310 GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream* stream,
1311 GpBitmap **bitmap)
1313 TRACE("%p %p\n", stream, bitmap);
1315 return GdipCreateBitmapFromStream(stream, bitmap);
1318 GpStatus WINGDIPAPI GdipCreateCachedBitmap(GpBitmap *bitmap, GpGraphics *graphics,
1319 GpCachedBitmap **cachedbmp)
1321 GpStatus stat;
1323 TRACE("%p %p %p\n", bitmap, graphics, cachedbmp);
1325 if(!bitmap || !graphics || !cachedbmp)
1326 return InvalidParameter;
1328 *cachedbmp = GdipAlloc(sizeof(GpCachedBitmap));
1329 if(!*cachedbmp)
1330 return OutOfMemory;
1332 stat = GdipCloneImage(&(bitmap->image), &(*cachedbmp)->image);
1333 if(stat != Ok){
1334 GdipFree(*cachedbmp);
1335 return stat;
1338 return Ok;
1341 GpStatus WINGDIPAPI GdipCreateHICONFromBitmap(GpBitmap *bitmap, HICON *hicon)
1343 FIXME("(%p, %p)\n", bitmap, hicon);
1345 return NotImplemented;
1348 GpStatus WINGDIPAPI GdipDeleteCachedBitmap(GpCachedBitmap *cachedbmp)
1350 TRACE("%p\n", cachedbmp);
1352 if(!cachedbmp)
1353 return InvalidParameter;
1355 GdipDisposeImage(cachedbmp->image);
1356 GdipFree(cachedbmp);
1358 return Ok;
1361 GpStatus WINGDIPAPI GdipDrawCachedBitmap(GpGraphics *graphics,
1362 GpCachedBitmap *cachedbmp, INT x, INT y)
1364 TRACE("%p %p %d %d\n", graphics, cachedbmp, x, y);
1366 if(!graphics || !cachedbmp)
1367 return InvalidParameter;
1369 return GdipDrawImage(graphics, cachedbmp->image, (REAL)x, (REAL)y);
1372 GpStatus WINGDIPAPI GdipEmfToWmfBits(HENHMETAFILE hemf, UINT cbData16,
1373 LPBYTE pData16, INT iMapMode, INT eFlags)
1375 FIXME("(%p, %d, %p, %d, %d): stub\n", hemf, cbData16, pData16, iMapMode, eFlags);
1376 return NotImplemented;
1379 GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
1381 TRACE("%p\n", image);
1383 if(!image)
1384 return InvalidParameter;
1386 if (image->picture)
1387 IPicture_Release(image->picture);
1388 if (image->type == ImageTypeBitmap)
1390 GdipFree(((GpBitmap*)image)->bitmapbits);
1391 DeleteDC(((GpBitmap*)image)->hdc);
1393 GdipFree(image->palette_entries);
1394 GdipFree(image);
1396 return Ok;
1399 GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage *image, ImageItemData* item)
1401 if(!image || !item)
1402 return InvalidParameter;
1404 return NotImplemented;
1407 GpStatus WINGDIPAPI GdipGetImageBounds(GpImage *image, GpRectF *srcRect,
1408 GpUnit *srcUnit)
1410 TRACE("%p %p %p\n", image, srcRect, srcUnit);
1412 if(!image || !srcRect || !srcUnit)
1413 return InvalidParameter;
1414 if(image->type == ImageTypeMetafile){
1415 *srcRect = ((GpMetafile*)image)->bounds;
1416 *srcUnit = ((GpMetafile*)image)->unit;
1418 else if(image->type == ImageTypeBitmap){
1419 srcRect->X = srcRect->Y = 0.0;
1420 srcRect->Width = (REAL) ((GpBitmap*)image)->width;
1421 srcRect->Height = (REAL) ((GpBitmap*)image)->height;
1422 *srcUnit = UnitPixel;
1424 else{
1425 srcRect->X = srcRect->Y = 0.0;
1426 srcRect->Width = ipicture_pixel_width(image->picture);
1427 srcRect->Height = ipicture_pixel_height(image->picture);
1428 *srcUnit = UnitPixel;
1431 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect->X, srcRect->Y,
1432 srcRect->Width, srcRect->Height, *srcUnit);
1434 return Ok;
1437 GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
1438 REAL *height)
1440 TRACE("%p %p %p\n", image, width, height);
1442 if(!image || !height || !width)
1443 return InvalidParameter;
1445 if(image->type == ImageTypeMetafile){
1446 HDC hdc = GetDC(0);
1448 *height = convert_unit(hdc, ((GpMetafile*)image)->unit) *
1449 ((GpMetafile*)image)->bounds.Height;
1451 *width = convert_unit(hdc, ((GpMetafile*)image)->unit) *
1452 ((GpMetafile*)image)->bounds.Width;
1454 ReleaseDC(0, hdc);
1457 else if(image->type == ImageTypeBitmap){
1458 *height = ((GpBitmap*)image)->height;
1459 *width = ((GpBitmap*)image)->width;
1461 else{
1462 *height = ipicture_pixel_height(image->picture);
1463 *width = ipicture_pixel_width(image->picture);
1466 TRACE("returning (%f, %f)\n", *height, *width);
1467 return Ok;
1470 GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image,
1471 GpGraphics **graphics)
1473 HDC hdc;
1475 TRACE("%p %p\n", image, graphics);
1477 if(!image || !graphics)
1478 return InvalidParameter;
1480 if(image->type != ImageTypeBitmap){
1481 FIXME("not implemented for image type %d\n", image->type);
1482 return NotImplemented;
1485 hdc = ((GpBitmap*)image)->hdc;
1487 if(!hdc){
1488 hdc = CreateCompatibleDC(0);
1489 SelectObject(hdc, ((GpBitmap*)image)->hbitmap);
1490 ((GpBitmap*)image)->hdc = hdc;
1493 return GdipCreateFromHDC(hdc, graphics);
1496 GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
1498 TRACE("%p %p\n", image, height);
1500 if(!image || !height)
1501 return InvalidParameter;
1503 if(image->type == ImageTypeMetafile){
1504 HDC hdc = GetDC(0);
1506 *height = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
1507 ((GpMetafile*)image)->bounds.Height);
1509 ReleaseDC(0, hdc);
1511 else if(image->type == ImageTypeBitmap)
1512 *height = ((GpBitmap*)image)->height;
1513 else
1514 *height = ipicture_pixel_height(image->picture);
1516 TRACE("returning %d\n", *height);
1518 return Ok;
1521 GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res)
1523 static int calls;
1525 if(!image || !res)
1526 return InvalidParameter;
1528 if(!(calls++))
1529 FIXME("not implemented\n");
1531 return NotImplemented;
1534 GpStatus WINGDIPAPI GdipGetImagePaletteSize(GpImage *image, INT *size)
1536 TRACE("%p %p\n", image, size);
1538 if(!image || !size)
1539 return InvalidParameter;
1541 if (image->palette_count == 0)
1542 *size = sizeof(ColorPalette);
1543 else
1544 *size = sizeof(UINT)*2 + sizeof(ARGB)*image->palette_count;
1546 TRACE("<-- %u\n", *size);
1548 return Ok;
1551 /* FIXME: test this function for non-bitmap types */
1552 GpStatus WINGDIPAPI GdipGetImagePixelFormat(GpImage *image, PixelFormat *format)
1554 TRACE("%p %p\n", image, format);
1556 if(!image || !format)
1557 return InvalidParameter;
1559 if(image->type != ImageTypeBitmap)
1560 *format = PixelFormat24bppRGB;
1561 else
1562 *format = ((GpBitmap*) image)->format;
1564 return Ok;
1567 GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage *image, GUID *format)
1569 if(!image || !format)
1570 return InvalidParameter;
1572 memcpy(format, &image->format, sizeof(GUID));
1574 return Ok;
1577 GpStatus WINGDIPAPI GdipGetImageType(GpImage *image, ImageType *type)
1579 TRACE("%p %p\n", image, type);
1581 if(!image || !type)
1582 return InvalidParameter;
1584 *type = image->type;
1586 return Ok;
1589 GpStatus WINGDIPAPI GdipGetImageVerticalResolution(GpImage *image, REAL *res)
1591 static int calls;
1593 if(!image || !res)
1594 return InvalidParameter;
1596 if(!(calls++))
1597 FIXME("not implemented\n");
1599 return NotImplemented;
1602 GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
1604 TRACE("%p %p\n", image, width);
1606 if(!image || !width)
1607 return InvalidParameter;
1609 if(image->type == ImageTypeMetafile){
1610 HDC hdc = GetDC(0);
1612 *width = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
1613 ((GpMetafile*)image)->bounds.Width);
1615 ReleaseDC(0, hdc);
1617 else if(image->type == ImageTypeBitmap)
1618 *width = ((GpBitmap*)image)->width;
1619 else
1620 *width = ipicture_pixel_width(image->picture);
1622 TRACE("returning %d\n", *width);
1624 return Ok;
1627 GpStatus WINGDIPAPI GdipGetMetafileHeaderFromMetafile(GpMetafile * metafile,
1628 MetafileHeader * header)
1630 static int calls;
1632 if(!metafile || !header)
1633 return InvalidParameter;
1635 if(!(calls++))
1636 FIXME("not implemented\n");
1638 return Ok;
1641 GpStatus WINGDIPAPI GdipGetAllPropertyItems(GpImage *image, UINT size,
1642 UINT num, PropertyItem* items)
1644 static int calls;
1646 if(!(calls++))
1647 FIXME("not implemented\n");
1649 return InvalidParameter;
1652 GpStatus WINGDIPAPI GdipGetPropertyCount(GpImage *image, UINT* num)
1654 static int calls;
1656 if(!(calls++))
1657 FIXME("not implemented\n");
1659 return InvalidParameter;
1662 GpStatus WINGDIPAPI GdipGetPropertyIdList(GpImage *image, UINT num, PROPID* list)
1664 static int calls;
1666 if(!(calls++))
1667 FIXME("not implemented\n");
1669 return InvalidParameter;
1672 GpStatus WINGDIPAPI GdipGetPropertyItem(GpImage *image, PROPID id, UINT size,
1673 PropertyItem* buffer)
1675 static int calls;
1677 if(!(calls++))
1678 FIXME("not implemented\n");
1680 return InvalidParameter;
1683 GpStatus WINGDIPAPI GdipGetPropertyItemSize(GpImage *image, PROPID pid,
1684 UINT* size)
1686 static int calls;
1688 TRACE("%p %x %p\n", image, pid, size);
1690 if(!size || !image)
1691 return InvalidParameter;
1693 if(!(calls++))
1694 FIXME("not implemented\n");
1696 return NotImplemented;
1699 GpStatus WINGDIPAPI GdipGetPropertySize(GpImage *image, UINT* size, UINT* num)
1701 static int calls;
1703 if(!(calls++))
1704 FIXME("not implemented\n");
1706 return InvalidParameter;
1709 GpStatus WINGDIPAPI GdipImageGetFrameCount(GpImage *image,
1710 GDIPCONST GUID* dimensionID, UINT* count)
1712 static int calls;
1714 if(!image || !dimensionID || !count)
1715 return InvalidParameter;
1717 if(!(calls++))
1718 FIXME("not implemented\n");
1720 return NotImplemented;
1723 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsCount(GpImage *image,
1724 UINT* count)
1726 if(!image || !count)
1727 return InvalidParameter;
1729 *count = 1;
1731 FIXME("stub\n");
1733 return Ok;
1736 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsList(GpImage* image,
1737 GUID* dimensionIDs, UINT count)
1739 static int calls;
1741 if(!image || !dimensionIDs)
1742 return InvalidParameter;
1744 if(!(calls++))
1745 FIXME("not implemented\n");
1747 return Ok;
1750 GpStatus WINGDIPAPI GdipImageSelectActiveFrame(GpImage *image,
1751 GDIPCONST GUID* dimensionID, UINT frameidx)
1753 static int calls;
1755 if(!image || !dimensionID)
1756 return InvalidParameter;
1758 if(!(calls++))
1759 FIXME("not implemented\n");
1761 return Ok;
1764 GpStatus WINGDIPAPI GdipLoadImageFromFile(GDIPCONST WCHAR* filename,
1765 GpImage **image)
1767 GpStatus stat;
1768 IStream *stream;
1770 TRACE("(%s) %p\n", debugstr_w(filename), image);
1772 if (!filename || !image)
1773 return InvalidParameter;
1775 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
1777 if (stat != Ok)
1778 return stat;
1780 stat = GdipLoadImageFromStream(stream, image);
1782 IStream_Release(stream);
1784 return stat;
1787 /* FIXME: no icm handling */
1788 GpStatus WINGDIPAPI GdipLoadImageFromFileICM(GDIPCONST WCHAR* filename,GpImage **image)
1790 TRACE("(%s) %p\n", debugstr_w(filename), image);
1792 return GdipLoadImageFromFile(filename, image);
1795 static const WICPixelFormatGUID *wic_pixel_formats[] = {
1796 &GUID_WICPixelFormat16bppBGR555,
1797 &GUID_WICPixelFormat24bppBGR,
1798 &GUID_WICPixelFormat32bppBGR,
1799 &GUID_WICPixelFormat32bppBGRA,
1800 &GUID_WICPixelFormat32bppPBGRA,
1801 NULL
1804 static const PixelFormat wic_gdip_formats[] = {
1805 PixelFormat16bppRGB555,
1806 PixelFormat24bppRGB,
1807 PixelFormat32bppRGB,
1808 PixelFormat32bppARGB,
1809 PixelFormat32bppPARGB,
1812 static GpStatus decode_image_wic(IStream* stream, REFCLSID clsid, GpImage **image)
1814 GpStatus status=Ok;
1815 GpBitmap *bitmap;
1816 HRESULT hr;
1817 IWICBitmapDecoder *decoder;
1818 IWICBitmapFrameDecode *frame;
1819 IWICBitmapSource *source=NULL;
1820 WICPixelFormatGUID wic_format;
1821 PixelFormat gdip_format=0;
1822 int i;
1823 UINT width, height;
1824 BitmapData lockeddata;
1825 WICRect wrc;
1826 HRESULT initresult;
1828 initresult = CoInitialize(NULL);
1830 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER,
1831 &IID_IWICBitmapDecoder, (void**)&decoder);
1832 if (FAILED(hr)) goto end;
1834 hr = IWICBitmapDecoder_Initialize(decoder, (IStream*)stream, WICDecodeMetadataCacheOnLoad);
1835 if (SUCCEEDED(hr))
1836 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
1838 if (SUCCEEDED(hr)) /* got frame */
1840 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &wic_format);
1842 if (SUCCEEDED(hr))
1844 for (i=0; wic_pixel_formats[i]; i++)
1846 if (IsEqualGUID(&wic_format, wic_pixel_formats[i]))
1848 source = (IWICBitmapSource*)frame;
1849 IWICBitmapSource_AddRef(source);
1850 gdip_format = wic_gdip_formats[i];
1851 break;
1854 if (!source)
1856 /* unknown format; fall back on 32bppARGB */
1857 hr = WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA, (IWICBitmapSource*)frame, &source);
1858 gdip_format = PixelFormat32bppARGB;
1862 if (SUCCEEDED(hr)) /* got source */
1864 hr = IWICBitmapSource_GetSize(source, &width, &height);
1866 if (SUCCEEDED(hr))
1867 status = GdipCreateBitmapFromScan0(width, height, 0, gdip_format,
1868 NULL, &bitmap);
1870 if (SUCCEEDED(hr) && status == Ok) /* created bitmap */
1872 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeWrite,
1873 gdip_format, &lockeddata);
1874 if (status == Ok) /* locked bitmap */
1876 wrc.X = 0;
1877 wrc.Width = width;
1878 wrc.Height = 1;
1879 for (i=0; i<height; i++)
1881 wrc.Y = i;
1882 hr = IWICBitmapSource_CopyPixels(source, &wrc, abs(lockeddata.Stride),
1883 abs(lockeddata.Stride), (BYTE*)lockeddata.Scan0+lockeddata.Stride*i);
1884 if (FAILED(hr)) break;
1887 GdipBitmapUnlockBits(bitmap, &lockeddata);
1890 if (SUCCEEDED(hr) && status == Ok)
1891 *image = (GpImage*)bitmap;
1892 else
1894 *image = NULL;
1895 GdipDisposeImage((GpImage*)bitmap);
1899 IWICBitmapSource_Release(source);
1902 IWICBitmapFrameDecode_Release(frame);
1905 IWICBitmapDecoder_Release(decoder);
1907 end:
1908 if (SUCCEEDED(initresult)) CoUninitialize();
1910 if (FAILED(hr) && status == Ok) status = hresult_to_status(hr);
1912 return status;
1915 static GpStatus decode_image_icon(IStream* stream, REFCLSID clsid, GpImage **image)
1917 return decode_image_wic(stream, &CLSID_WICIcoDecoder, image);
1920 static GpStatus decode_image_bmp(IStream* stream, REFCLSID clsid, GpImage **image)
1922 GpStatus status;
1923 GpBitmap* bitmap;
1925 status = decode_image_wic(stream, &CLSID_WICBmpDecoder, image);
1927 bitmap = (GpBitmap*)*image;
1929 if (status == Ok && bitmap->format == PixelFormat32bppARGB)
1931 /* WIC supports bmp files with alpha, but gdiplus does not */
1932 bitmap->format = PixelFormat32bppRGB;
1935 return status;
1938 static GpStatus decode_image_jpeg(IStream* stream, REFCLSID clsid, GpImage **image)
1940 return decode_image_wic(stream, &CLSID_WICJpegDecoder, image);
1943 static GpStatus decode_image_png(IStream* stream, REFCLSID clsid, GpImage **image)
1945 return decode_image_wic(stream, &CLSID_WICPngDecoder, image);
1948 static GpStatus decode_image_gif(IStream* stream, REFCLSID clsid, GpImage **image)
1950 return decode_image_wic(stream, &CLSID_WICGifDecoder, image);
1953 static GpStatus decode_image_olepicture_metafile(IStream* stream, REFCLSID clsid, GpImage **image)
1955 IPicture *pic;
1957 TRACE("%p %p\n", stream, image);
1959 if(!stream || !image)
1960 return InvalidParameter;
1962 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
1963 (LPVOID*) &pic) != S_OK){
1964 TRACE("Could not load picture\n");
1965 return GenericError;
1968 /* FIXME: missing initialization code */
1969 *image = GdipAlloc(sizeof(GpMetafile));
1970 if(!*image) return OutOfMemory;
1971 (*image)->type = ImageTypeMetafile;
1972 (*image)->picture = pic;
1973 (*image)->flags = ImageFlagsNone;
1974 (*image)->palette_flags = 0;
1975 (*image)->palette_count = 0;
1976 (*image)->palette_size = 0;
1977 (*image)->palette_entries = NULL;
1979 return Ok;
1982 typedef GpStatus (*encode_image_func)(GpImage *image, IStream* stream,
1983 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params);
1985 typedef GpStatus (*decode_image_func)(IStream *stream, REFCLSID clsid, GpImage** image);
1987 typedef struct image_codec {
1988 ImageCodecInfo info;
1989 encode_image_func encode_func;
1990 decode_image_func decode_func;
1991 } image_codec;
1993 typedef enum {
1994 BMP,
1995 JPEG,
1996 GIF,
1997 EMF,
1998 WMF,
1999 PNG,
2000 ICO,
2001 NUM_CODECS
2002 } ImageFormat;
2004 static const struct image_codec codecs[NUM_CODECS];
2006 static GpStatus get_decoder_info(IStream* stream, const struct image_codec **result)
2008 BYTE signature[8];
2009 LARGE_INTEGER seek;
2010 HRESULT hr;
2011 UINT bytesread;
2012 int i, j;
2014 /* seek to the start of the stream */
2015 seek.QuadPart = 0;
2016 hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL);
2017 if (FAILED(hr)) return hresult_to_status(hr);
2019 /* read the first 8 bytes */
2020 /* FIXME: This assumes all codecs have one signature <= 8 bytes in length */
2021 hr = IStream_Read(stream, signature, 8, &bytesread);
2022 if (FAILED(hr)) return hresult_to_status(hr);
2023 if (hr == S_FALSE || bytesread == 0) return GenericError;
2025 for (i = 0; i < NUM_CODECS; i++) {
2026 if ((codecs[i].info.Flags & ImageCodecFlagsDecoder) &&
2027 bytesread >= codecs[i].info.SigSize)
2029 for (j=0; j<codecs[i].info.SigSize; j++)
2030 if ((signature[j] & codecs[i].info.SigMask[j]) != codecs[i].info.SigPattern[j])
2031 break;
2032 if (j == codecs[i].info.SigSize)
2034 *result = &codecs[i];
2035 return Ok;
2040 TRACE("no match for %i byte signature %x %x %x %x %x %x %x %x\n", bytesread,
2041 signature[0],signature[1],signature[2],signature[3],
2042 signature[4],signature[5],signature[6],signature[7]);
2044 return GenericError;
2047 GpStatus WINGDIPAPI GdipLoadImageFromStream(IStream* stream, GpImage **image)
2049 GpStatus stat;
2050 LARGE_INTEGER seek;
2051 HRESULT hr;
2052 const struct image_codec *codec=NULL;
2054 /* choose an appropriate image decoder */
2055 stat = get_decoder_info(stream, &codec);
2056 if (stat != Ok) return stat;
2058 /* seek to the start of the stream */
2059 seek.QuadPart = 0;
2060 hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL);
2061 if (FAILED(hr)) return hresult_to_status(hr);
2063 /* call on the image decoder to do the real work */
2064 stat = codec->decode_func(stream, &codec->info.Clsid, image);
2066 /* take note of the original data format */
2067 if (stat == Ok)
2069 memcpy(&(*image)->format, &codec->info.FormatID, sizeof(GUID));
2072 return stat;
2075 /* FIXME: no ICM */
2076 GpStatus WINGDIPAPI GdipLoadImageFromStreamICM(IStream* stream, GpImage **image)
2078 TRACE("%p %p\n", stream, image);
2080 return GdipLoadImageFromStream(stream, image);
2083 GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
2085 static int calls;
2087 if(!image)
2088 return InvalidParameter;
2090 if(!(calls++))
2091 FIXME("not implemented\n");
2093 return NotImplemented;
2096 GpStatus WINGDIPAPI GdipSetPropertyItem(GpImage *image, GDIPCONST PropertyItem* item)
2098 static int calls;
2100 if(!(calls++))
2101 FIXME("not implemented\n");
2103 return NotImplemented;
2106 GpStatus WINGDIPAPI GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
2107 GDIPCONST CLSID *clsidEncoder,
2108 GDIPCONST EncoderParameters *encoderParams)
2110 GpStatus stat;
2111 IStream *stream;
2113 TRACE("%p (%s) %p %p\n", image, debugstr_w(filename), clsidEncoder, encoderParams);
2115 if (!image || !filename|| !clsidEncoder)
2116 return InvalidParameter;
2118 stat = GdipCreateStreamOnFile(filename, GENERIC_WRITE, &stream);
2119 if (stat != Ok)
2120 return GenericError;
2122 stat = GdipSaveImageToStream(image, stream, clsidEncoder, encoderParams);
2124 IStream_Release(stream);
2125 return stat;
2128 /*************************************************************************
2129 * Encoding functions -
2130 * These functions encode an image in different image file formats.
2132 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
2133 #define BITMAP_FORMAT_JPEG 0xd8ff
2134 #define BITMAP_FORMAT_GIF 0x4947
2135 #define BITMAP_FORMAT_PNG 0x5089
2136 #define BITMAP_FORMAT_APM 0xcdd7
2138 static GpStatus encode_image_WIC(GpImage *image, IStream* stream,
2139 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
2141 GpStatus stat;
2142 GpBitmap *bitmap;
2143 IWICBitmapEncoder *encoder;
2144 IWICBitmapFrameEncode *frameencode;
2145 IPropertyBag2 *encoderoptions;
2146 HRESULT hr;
2147 UINT width, height;
2148 PixelFormat gdipformat=0;
2149 WICPixelFormatGUID wicformat;
2150 GpRect rc;
2151 BitmapData lockeddata;
2152 HRESULT initresult;
2153 UINT i;
2155 if (image->type != ImageTypeBitmap)
2156 return GenericError;
2158 bitmap = (GpBitmap*)image;
2160 GdipGetImageWidth(image, &width);
2161 GdipGetImageHeight(image, &height);
2163 rc.X = 0;
2164 rc.Y = 0;
2165 rc.Width = width;
2166 rc.Height = height;
2168 initresult = CoInitialize(NULL);
2170 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER,
2171 &IID_IWICBitmapEncoder, (void**)&encoder);
2172 if (FAILED(hr))
2174 if (SUCCEEDED(initresult)) CoUninitialize();
2175 return hresult_to_status(hr);
2178 hr = IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache);
2180 if (SUCCEEDED(hr))
2182 hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frameencode, &encoderoptions);
2185 if (SUCCEEDED(hr)) /* created frame */
2187 hr = IWICBitmapFrameEncode_Initialize(frameencode, encoderoptions);
2189 if (SUCCEEDED(hr))
2190 hr = IWICBitmapFrameEncode_SetSize(frameencode, width, height);
2192 if (SUCCEEDED(hr))
2193 /* FIXME: use the resolution from the image */
2194 hr = IWICBitmapFrameEncode_SetResolution(frameencode, 96.0, 96.0);
2196 if (SUCCEEDED(hr))
2198 for (i=0; wic_pixel_formats[i]; i++)
2200 if (wic_gdip_formats[i] == bitmap->format)
2201 break;
2203 if (wic_pixel_formats[i])
2204 memcpy(&wicformat, wic_pixel_formats[i], sizeof(GUID));
2205 else
2206 memcpy(&wicformat, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID));
2208 hr = IWICBitmapFrameEncode_SetPixelFormat(frameencode, &wicformat);
2210 for (i=0; wic_pixel_formats[i]; i++)
2212 if (IsEqualGUID(&wicformat, wic_pixel_formats[i]))
2213 break;
2215 if (wic_pixel_formats[i])
2216 gdipformat = wic_gdip_formats[i];
2217 else
2219 ERR("cannot provide pixel format %s\n", debugstr_guid(&wicformat));
2220 hr = E_FAIL;
2224 if (SUCCEEDED(hr))
2226 stat = GdipBitmapLockBits(bitmap, &rc, ImageLockModeRead, gdipformat,
2227 &lockeddata);
2229 if (stat == Ok)
2231 UINT row_size = (lockeddata.Width * PIXELFORMATBPP(gdipformat) + 7)/8;
2232 BYTE *row;
2234 /* write one row at a time in case stride is negative */
2235 row = lockeddata.Scan0;
2236 for (i=0; i<lockeddata.Height; i++)
2238 hr = IWICBitmapFrameEncode_WritePixels(frameencode, 1, row_size, row_size, row);
2239 if (FAILED(hr)) break;
2240 row += lockeddata.Stride;
2243 GdipBitmapUnlockBits(bitmap, &lockeddata);
2245 else
2246 hr = E_FAIL;
2249 if (SUCCEEDED(hr))
2250 hr = IWICBitmapFrameEncode_Commit(frameencode);
2252 IWICBitmapFrameEncode_Release(frameencode);
2253 IPropertyBag2_Release(encoderoptions);
2256 if (SUCCEEDED(hr))
2257 hr = IWICBitmapEncoder_Commit(encoder);
2259 IWICBitmapEncoder_Release(encoder);
2261 if (SUCCEEDED(initresult)) CoUninitialize();
2263 return hresult_to_status(hr);
2266 static GpStatus encode_image_BMP(GpImage *image, IStream* stream,
2267 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
2269 return encode_image_WIC(image, stream, &CLSID_WICBmpEncoder, params);
2272 static GpStatus encode_image_png(GpImage *image, IStream* stream,
2273 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
2275 return encode_image_WIC(image, stream, &CLSID_WICPngEncoder, params);
2278 /*****************************************************************************
2279 * GdipSaveImageToStream [GDIPLUS.@]
2281 GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
2282 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
2284 GpStatus stat;
2285 encode_image_func encode_image;
2286 int i;
2288 TRACE("%p %p %p %p\n", image, stream, clsid, params);
2290 if(!image || !stream)
2291 return InvalidParameter;
2293 /* select correct encoder */
2294 encode_image = NULL;
2295 for (i = 0; i < NUM_CODECS; i++) {
2296 if ((codecs[i].info.Flags & ImageCodecFlagsEncoder) &&
2297 IsEqualCLSID(clsid, &codecs[i].info.Clsid))
2298 encode_image = codecs[i].encode_func;
2300 if (encode_image == NULL)
2301 return UnknownImageFormat;
2303 stat = encode_image(image, stream, clsid, params);
2305 return stat;
2308 /*****************************************************************************
2309 * GdipGetImagePalette [GDIPLUS.@]
2311 GpStatus WINGDIPAPI GdipGetImagePalette(GpImage *image, ColorPalette *palette, INT size)
2313 TRACE("(%p,%p,%i)\n", image, palette, size);
2315 if (!image || !palette)
2316 return InvalidParameter;
2318 if (size < (sizeof(UINT)*2+sizeof(ARGB)*image->palette_count))
2320 TRACE("<-- InsufficientBuffer\n");
2321 return InsufficientBuffer;
2324 palette->Flags = image->palette_flags;
2325 palette->Count = image->palette_count;
2326 memcpy(palette->Entries, image->palette_entries, sizeof(ARGB)*image->palette_count);
2328 return Ok;
2331 /*****************************************************************************
2332 * GdipSetImagePalette [GDIPLUS.@]
2334 GpStatus WINGDIPAPI GdipSetImagePalette(GpImage *image,
2335 GDIPCONST ColorPalette *palette)
2337 TRACE("(%p,%p)\n", image, palette);
2339 if(!image || !palette || palette->Count > 256)
2340 return InvalidParameter;
2342 if (palette->Count > image->palette_size)
2344 ARGB *new_palette;
2346 new_palette = GdipAlloc(sizeof(ARGB) * palette->Count);
2347 if (!new_palette) return OutOfMemory;
2349 GdipFree(image->palette_entries);
2350 image->palette_entries = new_palette;
2351 image->palette_size = palette->Count;
2354 image->palette_flags = palette->Flags;
2355 image->palette_count = palette->Count;
2356 memcpy(image->palette_entries, palette->Entries, sizeof(ARGB)*palette->Count);
2358 return Ok;
2361 /*************************************************************************
2362 * Encoders -
2363 * Structures that represent which formats we support for encoding.
2366 /* ImageCodecInfo creation routines taken from libgdiplus */
2367 static const WCHAR bmp_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
2368 static const WCHAR bmp_extension[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
2369 static const WCHAR bmp_mimetype[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
2370 static const WCHAR bmp_format[] = {'B', 'M', 'P', 0}; /* BMP */
2371 static const BYTE bmp_sig_pattern[] = { 0x42, 0x4D };
2372 static const BYTE bmp_sig_mask[] = { 0xFF, 0xFF };
2374 static const WCHAR jpeg_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'J','P','E','G', 0};
2375 static const WCHAR jpeg_extension[] = {'*','.','J','P','G',';', '*','.','J','P','E','G',';', '*','.','J','P','E',';', '*','.','J','F','I','F',0};
2376 static const WCHAR jpeg_mimetype[] = {'i','m','a','g','e','/','j','p','e','g', 0};
2377 static const WCHAR jpeg_format[] = {'J','P','E','G',0};
2378 static const BYTE jpeg_sig_pattern[] = { 0xFF, 0xD8 };
2379 static const BYTE jpeg_sig_mask[] = { 0xFF, 0xFF };
2381 static const WCHAR gif_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'G','I','F', 0};
2382 static const WCHAR gif_extension[] = {'*','.','G','I','F',0};
2383 static const WCHAR gif_mimetype[] = {'i','m','a','g','e','/','g','i','f', 0};
2384 static const WCHAR gif_format[] = {'G','I','F',0};
2385 static const BYTE gif_sig_pattern[4] = "GIF8";
2386 static const BYTE gif_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF };
2388 static const WCHAR emf_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'E','M','F', 0};
2389 static const WCHAR emf_extension[] = {'*','.','E','M','F',0};
2390 static const WCHAR emf_mimetype[] = {'i','m','a','g','e','/','x','-','e','m','f', 0};
2391 static const WCHAR emf_format[] = {'E','M','F',0};
2392 static const BYTE emf_sig_pattern[] = { 0x01, 0x00, 0x00, 0x00 };
2393 static const BYTE emf_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF };
2395 static const WCHAR wmf_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'W','M','F', 0};
2396 static const WCHAR wmf_extension[] = {'*','.','W','M','F',0};
2397 static const WCHAR wmf_mimetype[] = {'i','m','a','g','e','/','x','-','w','m','f', 0};
2398 static const WCHAR wmf_format[] = {'W','M','F',0};
2399 static const BYTE wmf_sig_pattern[] = { 0xd7, 0xcd };
2400 static const BYTE wmf_sig_mask[] = { 0xFF, 0xFF };
2402 static const WCHAR png_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'P','N','G', 0};
2403 static const WCHAR png_extension[] = {'*','.','P','N','G',0};
2404 static const WCHAR png_mimetype[] = {'i','m','a','g','e','/','p','n','g', 0};
2405 static const WCHAR png_format[] = {'P','N','G',0};
2406 static const BYTE png_sig_pattern[] = { 137, 80, 78, 71, 13, 10, 26, 10, };
2407 static const BYTE png_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
2409 static const WCHAR ico_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'I','C','O', 0};
2410 static const WCHAR ico_extension[] = {'*','.','I','C','O',0};
2411 static const WCHAR ico_mimetype[] = {'i','m','a','g','e','/','x','-','i','c','o','n', 0};
2412 static const WCHAR ico_format[] = {'I','C','O',0};
2413 static const BYTE ico_sig_pattern[] = { 0x00, 0x00, 0x01, 0x00 };
2414 static const BYTE ico_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF };
2416 static const struct image_codec codecs[NUM_CODECS] = {
2418 { /* BMP */
2419 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2420 /* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2421 /* CodecName */ bmp_codecname,
2422 /* DllName */ NULL,
2423 /* FormatDescription */ bmp_format,
2424 /* FilenameExtension */ bmp_extension,
2425 /* MimeType */ bmp_mimetype,
2426 /* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2427 /* Version */ 1,
2428 /* SigCount */ 1,
2429 /* SigSize */ 2,
2430 /* SigPattern */ bmp_sig_pattern,
2431 /* SigMask */ bmp_sig_mask,
2433 encode_image_BMP,
2434 decode_image_bmp
2437 { /* JPEG */
2438 /* Clsid */ { 0x557cf401, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2439 /* FormatID */ { 0xb96b3caeU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2440 /* CodecName */ jpeg_codecname,
2441 /* DllName */ NULL,
2442 /* FormatDescription */ jpeg_format,
2443 /* FilenameExtension */ jpeg_extension,
2444 /* MimeType */ jpeg_mimetype,
2445 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2446 /* Version */ 1,
2447 /* SigCount */ 1,
2448 /* SigSize */ 2,
2449 /* SigPattern */ jpeg_sig_pattern,
2450 /* SigMask */ jpeg_sig_mask,
2452 NULL,
2453 decode_image_jpeg
2456 { /* GIF */
2457 /* Clsid */ { 0x557cf402, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2458 /* FormatID */ { 0xb96b3cb0U, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2459 /* CodecName */ gif_codecname,
2460 /* DllName */ NULL,
2461 /* FormatDescription */ gif_format,
2462 /* FilenameExtension */ gif_extension,
2463 /* MimeType */ gif_mimetype,
2464 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2465 /* Version */ 1,
2466 /* SigCount */ 1,
2467 /* SigSize */ 4,
2468 /* SigPattern */ gif_sig_pattern,
2469 /* SigMask */ gif_sig_mask,
2471 NULL,
2472 decode_image_gif
2475 { /* EMF */
2476 /* Clsid */ { 0x557cf403, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2477 /* FormatID */ { 0xb96b3cacU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2478 /* CodecName */ emf_codecname,
2479 /* DllName */ NULL,
2480 /* FormatDescription */ emf_format,
2481 /* FilenameExtension */ emf_extension,
2482 /* MimeType */ emf_mimetype,
2483 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportVector | ImageCodecFlagsBuiltin,
2484 /* Version */ 1,
2485 /* SigCount */ 1,
2486 /* SigSize */ 4,
2487 /* SigPattern */ emf_sig_pattern,
2488 /* SigMask */ emf_sig_mask,
2490 NULL,
2491 decode_image_olepicture_metafile
2494 { /* WMF */
2495 /* Clsid */ { 0x557cf404, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2496 /* FormatID */ { 0xb96b3cadU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2497 /* CodecName */ wmf_codecname,
2498 /* DllName */ NULL,
2499 /* FormatDescription */ wmf_format,
2500 /* FilenameExtension */ wmf_extension,
2501 /* MimeType */ wmf_mimetype,
2502 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportVector | ImageCodecFlagsBuiltin,
2503 /* Version */ 1,
2504 /* SigCount */ 1,
2505 /* SigSize */ 2,
2506 /* SigPattern */ wmf_sig_pattern,
2507 /* SigMask */ wmf_sig_mask,
2509 NULL,
2510 decode_image_olepicture_metafile
2513 { /* PNG */
2514 /* Clsid */ { 0x557cf406, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2515 /* FormatID */ { 0xb96b3cafU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2516 /* CodecName */ png_codecname,
2517 /* DllName */ NULL,
2518 /* FormatDescription */ png_format,
2519 /* FilenameExtension */ png_extension,
2520 /* MimeType */ png_mimetype,
2521 /* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2522 /* Version */ 1,
2523 /* SigCount */ 1,
2524 /* SigSize */ 8,
2525 /* SigPattern */ png_sig_pattern,
2526 /* SigMask */ png_sig_mask,
2528 encode_image_png,
2529 decode_image_png
2532 { /* ICO */
2533 /* Clsid */ { 0x557cf407, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2534 /* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2535 /* CodecName */ ico_codecname,
2536 /* DllName */ NULL,
2537 /* FormatDescription */ ico_format,
2538 /* FilenameExtension */ ico_extension,
2539 /* MimeType */ ico_mimetype,
2540 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2541 /* Version */ 1,
2542 /* SigCount */ 1,
2543 /* SigSize */ 4,
2544 /* SigPattern */ ico_sig_pattern,
2545 /* SigMask */ ico_sig_mask,
2547 NULL,
2548 decode_image_icon
2552 /*****************************************************************************
2553 * GdipGetImageDecodersSize [GDIPLUS.@]
2555 GpStatus WINGDIPAPI GdipGetImageDecodersSize(UINT *numDecoders, UINT *size)
2557 int decoder_count=0;
2558 int i;
2559 TRACE("%p %p\n", numDecoders, size);
2561 if (!numDecoders || !size)
2562 return InvalidParameter;
2564 for (i=0; i<NUM_CODECS; i++)
2566 if (codecs[i].info.Flags & ImageCodecFlagsDecoder)
2567 decoder_count++;
2570 *numDecoders = decoder_count;
2571 *size = decoder_count * sizeof(ImageCodecInfo);
2573 return Ok;
2576 /*****************************************************************************
2577 * GdipGetImageDecoders [GDIPLUS.@]
2579 GpStatus WINGDIPAPI GdipGetImageDecoders(UINT numDecoders, UINT size, ImageCodecInfo *decoders)
2581 int i, decoder_count=0;
2582 TRACE("%u %u %p\n", numDecoders, size, decoders);
2584 if (!decoders ||
2585 size != numDecoders * sizeof(ImageCodecInfo))
2586 return GenericError;
2588 for (i=0; i<NUM_CODECS; i++)
2590 if (codecs[i].info.Flags & ImageCodecFlagsDecoder)
2592 if (decoder_count == numDecoders) return GenericError;
2593 memcpy(&decoders[decoder_count], &codecs[i].info, sizeof(ImageCodecInfo));
2594 decoder_count++;
2598 if (decoder_count < numDecoders) return GenericError;
2600 return Ok;
2603 /*****************************************************************************
2604 * GdipGetImageEncodersSize [GDIPLUS.@]
2606 GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size)
2608 int encoder_count=0;
2609 int i;
2610 TRACE("%p %p\n", numEncoders, size);
2612 if (!numEncoders || !size)
2613 return InvalidParameter;
2615 for (i=0; i<NUM_CODECS; i++)
2617 if (codecs[i].info.Flags & ImageCodecFlagsEncoder)
2618 encoder_count++;
2621 *numEncoders = encoder_count;
2622 *size = encoder_count * sizeof(ImageCodecInfo);
2624 return Ok;
2627 /*****************************************************************************
2628 * GdipGetImageEncoders [GDIPLUS.@]
2630 GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders)
2632 int i, encoder_count=0;
2633 TRACE("%u %u %p\n", numEncoders, size, encoders);
2635 if (!encoders ||
2636 size != numEncoders * sizeof(ImageCodecInfo))
2637 return GenericError;
2639 for (i=0; i<NUM_CODECS; i++)
2641 if (codecs[i].info.Flags & ImageCodecFlagsEncoder)
2643 if (encoder_count == numEncoders) return GenericError;
2644 memcpy(&encoders[encoder_count], &codecs[i].info, sizeof(ImageCodecInfo));
2645 encoder_count++;
2649 if (encoder_count < numEncoders) return GenericError;
2651 return Ok;
2654 /*****************************************************************************
2655 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
2657 GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBitmap** bitmap)
2659 BITMAP bm;
2660 GpStatus retval;
2661 PixelFormat format;
2662 BitmapData lockeddata;
2663 INT y;
2665 TRACE("%p %p %p\n", hbm, hpal, bitmap);
2667 if(!hbm || !bitmap)
2668 return InvalidParameter;
2670 /* TODO: Support for device-dependent bitmaps */
2671 if(hpal){
2672 FIXME("no support for device-dependent bitmaps\n");
2673 return NotImplemented;
2676 if (GetObjectA(hbm, sizeof(bm), &bm) != sizeof(bm))
2677 return InvalidParameter;
2679 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
2680 switch(bm.bmBitsPixel) {
2681 case 1:
2682 format = PixelFormat1bppIndexed;
2683 break;
2684 case 4:
2685 format = PixelFormat4bppIndexed;
2686 break;
2687 case 8:
2688 format = PixelFormat8bppIndexed;
2689 break;
2690 case 24:
2691 format = PixelFormat24bppRGB;
2692 break;
2693 case 32:
2694 format = PixelFormat32bppRGB;
2695 break;
2696 case 48:
2697 format = PixelFormat48bppRGB;
2698 break;
2699 default:
2700 FIXME("don't know how to handle %d bpp\n", bm.bmBitsPixel);
2701 return InvalidParameter;
2704 retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, 0,
2705 format, NULL, bitmap);
2707 if (retval == Ok)
2709 retval = GdipBitmapLockBits(*bitmap, NULL, ImageLockModeWrite,
2710 format, &lockeddata);
2711 if (retval == Ok)
2713 if (bm.bmBits)
2715 for (y=0; y<bm.bmHeight; y++)
2717 memcpy((BYTE*)lockeddata.Scan0+lockeddata.Stride*y,
2718 (BYTE*)bm.bmBits+bm.bmWidthBytes*(bm.bmHeight-1-y),
2719 bm.bmWidthBytes);
2722 else
2724 FIXME("can only get image data from DIB sections\n");
2727 GdipBitmapUnlockBits(*bitmap, &lockeddata);
2731 return retval;
2734 GpStatus WINGDIPAPI GdipDeleteEffect(CGpEffect *effect)
2736 FIXME("(%p): stub\n", effect);
2737 /* note: According to Jose Roca's GDI+ Docs, this is not implemented
2738 * in Windows's gdiplus */
2739 return NotImplemented;
2742 /*****************************************************************************
2743 * GdipSetEffectParameters [GDIPLUS.@]
2745 GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect *effect,
2746 const VOID *params, const UINT size)
2748 static int calls;
2750 if(!(calls++))
2751 FIXME("not implemented\n");
2753 return NotImplemented;
2756 /*****************************************************************************
2757 * GdipGetImageFlags [GDIPLUS.@]
2759 GpStatus WINGDIPAPI GdipGetImageFlags(GpImage *image, UINT *flags)
2761 TRACE("%p %p\n", image, flags);
2763 if(!image || !flags)
2764 return InvalidParameter;
2766 *flags = image->flags;
2768 return Ok;
2771 GpStatus WINGDIPAPI GdipTestControl(GpTestControlEnum control, void *param)
2773 TRACE("(%d, %p)\n", control, param);
2775 switch(control){
2776 case TestControlForceBilinear:
2777 if(param)
2778 FIXME("TestControlForceBilinear not handled\n");
2779 break;
2780 case TestControlNoICM:
2781 if(param)
2782 FIXME("TestControlNoICM not handled\n");
2783 break;
2784 case TestControlGetBuildNumber:
2785 *((DWORD*)param) = 3102;
2786 break;
2789 return Ok;
2792 GpStatus WINGDIPAPI GdipRecordMetafileFileName(GDIPCONST WCHAR* fileName,
2793 HDC hdc, EmfType type, GDIPCONST GpRectF *pFrameRect,
2794 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc,
2795 GpMetafile **metafile)
2797 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
2798 frameUnit, debugstr_w(desc), metafile);
2800 return NotImplemented;
2803 GpStatus WINGDIPAPI GdipRecordMetafileFileNameI(GDIPCONST WCHAR* fileName, HDC hdc, EmfType type,
2804 GDIPCONST GpRect *pFrameRect, MetafileFrameUnit frameUnit,
2805 GDIPCONST WCHAR *desc, GpMetafile **metafile)
2807 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
2808 frameUnit, debugstr_w(desc), metafile);
2810 return NotImplemented;
2813 GpStatus WINGDIPAPI GdipImageForceValidation(GpImage *image)
2815 FIXME("%p\n", image);
2817 return Ok;
2820 /*****************************************************************************
2821 * GdipGetImageThumbnail [GDIPLUS.@]
2823 GpStatus WINGDIPAPI GdipGetImageThumbnail(GpImage *image, UINT width, UINT height,
2824 GpImage **ret_image, GetThumbnailImageAbort cb,
2825 VOID * cb_data)
2827 FIXME("(%p %u %u %p %p %p) stub\n",
2828 image, width, height, ret_image, cb, cb_data);
2829 return NotImplemented;
2832 /*****************************************************************************
2833 * GdipImageRotateFlip [GDIPLUS.@]
2835 GpStatus WINGDIPAPI GdipImageRotateFlip(GpImage *image, RotateFlipType type)
2837 FIXME("(%p %u) stub\n", image, type);
2838 return NotImplemented;