winmm: Fix a failing mixer test on 98 and ME.
[wine] / dlls / 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 #include "windef.h"
22 #include "winbase.h"
23 #include "winuser.h"
24 #include "wingdi.h"
25
26 #define COBJMACROS
27 #include "objbase.h"
28 #include "olectl.h"
29 #include "ole2.h"
30
31 #include "gdiplus.h"
32 #include "gdiplus_private.h"
33 #include "wine/debug.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
36
37 #define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
38
39 static INT ipicture_pixel_height(IPicture *pic)
40 {
41     HDC hdcref;
42     OLE_YSIZE_HIMETRIC y;
43
44     IPicture_get_Height(pic, &y);
45
46     hdcref = GetDC(0);
47
48     y = MulDiv(y, GetDeviceCaps(hdcref, LOGPIXELSY), INCH_HIMETRIC);
49     ReleaseDC(0, hdcref);
50
51     return y;
52 }
53
54 static INT ipicture_pixel_width(IPicture *pic)
55 {
56     HDC hdcref;
57     OLE_XSIZE_HIMETRIC x;
58
59     IPicture_get_Width(pic, &x);
60
61     hdcref = GetDC(0);
62
63     x = MulDiv(x, GetDeviceCaps(hdcref, LOGPIXELSX), INCH_HIMETRIC);
64
65     ReleaseDC(0, hdcref);
66
67     return x;
68 }
69
70 GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y,
71     ARGB *color)
72 {
73     static int calls;
74     TRACE("%p %d %d %p\n", bitmap, x, y, color);
75
76     if(!bitmap || !color)
77         return InvalidParameter;
78
79     if(!(calls++))
80         FIXME("not implemented\n");
81
82     *color = 0xdeadbeef;
83
84     return NotImplemented;
85 }
86
87 /* This function returns a pointer to an array of pixels that represents the
88  * bitmap. The *entire* bitmap is locked according to the lock mode specified by
89  * flags.  It is correct behavior that a user who calls this function with write
90  * privileges can write to the whole bitmap (not just the area in rect).
91  *
92  * FIXME: only used portion of format is bits per pixel. */
93 GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
94     UINT flags, PixelFormat format, BitmapData* lockeddata)
95 {
96     BOOL bm_is_selected;
97     INT stride, bitspp = PIXELFORMATBPP(format);
98     OLE_HANDLE hbm;
99     HDC hdc;
100     HBITMAP old = NULL;
101     BITMAPINFO *pbmi;
102     BYTE *buff = NULL;
103     UINT abs_height;
104     GpRect act_rect; /* actual rect to be used */
105
106     TRACE("%p %p %d %d %p\n", bitmap, rect, flags, format, lockeddata);
107
108     if(!lockeddata || !bitmap)
109         return InvalidParameter;
110
111     if(rect){
112         if(rect->X < 0 || rect->Y < 0 || (rect->X + rect->Width > bitmap->width) ||
113           (rect->Y + rect->Height > bitmap->height) || !flags)
114             return InvalidParameter;
115
116         act_rect = *rect;
117     }
118     else{
119         act_rect.X = act_rect.Y = 0;
120         act_rect.Width  = bitmap->width;
121         act_rect.Height = bitmap->height;
122     }
123
124     if(flags & ImageLockModeUserInputBuf)
125         return NotImplemented;
126
127     if(bitmap->lockmode)
128         return WrongState;
129
130     IPicture_get_Handle(bitmap->image.picture, &hbm);
131     IPicture_get_CurDC(bitmap->image.picture, &hdc);
132     bm_is_selected = (hdc != 0);
133
134     pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
135     if (!pbmi)
136         return OutOfMemory;
137     pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
138     pbmi->bmiHeader.biBitCount = 0;
139
140     if(!bm_is_selected){
141         hdc = CreateCompatibleDC(0);
142         old = SelectObject(hdc, (HBITMAP)hbm);
143     }
144
145     /* fill out bmi */
146     GetDIBits(hdc, (HBITMAP)hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
147
148     abs_height = abs(pbmi->bmiHeader.biHeight);
149     stride = pbmi->bmiHeader.biWidth * bitspp / 8;
150     stride = (stride + 3) & ~3;
151
152     buff = GdipAlloc(stride * abs_height);
153
154     pbmi->bmiHeader.biBitCount = bitspp;
155
156     if(buff)
157         GetDIBits(hdc, (HBITMAP)hbm, 0, abs_height, buff, pbmi, DIB_RGB_COLORS);
158
159     if(!bm_is_selected){
160         SelectObject(hdc, old);
161         DeleteDC(hdc);
162     }
163
164     if(!buff){
165         GdipFree(pbmi);
166         return OutOfMemory;
167     }
168
169     lockeddata->Width  = act_rect.Width;
170     lockeddata->Height = act_rect.Height;
171     lockeddata->PixelFormat = format;
172     lockeddata->Reserved = flags;
173
174     if(pbmi->bmiHeader.biHeight > 0){
175         lockeddata->Stride = -stride;
176         lockeddata->Scan0  = buff + (bitspp / 8) * act_rect.X +
177                              stride * (abs_height - 1 - act_rect.Y);
178     }
179     else{
180         lockeddata->Stride = stride;
181         lockeddata->Scan0  = buff + (bitspp / 8) * act_rect.X + stride * act_rect.Y;
182     }
183
184     bitmap->lockmode = flags;
185     bitmap->numlocks++;
186
187     bitmap->bitmapbits = buff;
188
189     GdipFree(pbmi);
190     return Ok;
191 }
192
193 GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap,
194     BitmapData* lockeddata)
195 {
196     OLE_HANDLE hbm;
197     HDC hdc;
198     HBITMAP old = NULL;
199     BOOL bm_is_selected;
200     BITMAPINFO *pbmi;
201
202     if(!bitmap || !lockeddata)
203         return InvalidParameter;
204
205     if(!bitmap->lockmode)
206         return WrongState;
207
208     if(lockeddata->Reserved & ImageLockModeUserInputBuf)
209         return NotImplemented;
210
211     if(lockeddata->Reserved & ImageLockModeRead){
212         if(!(--bitmap->numlocks))
213             bitmap->lockmode = 0;
214
215         GdipFree(bitmap->bitmapbits);
216         bitmap->bitmapbits = NULL;
217         return Ok;
218     }
219
220     IPicture_get_Handle(bitmap->image.picture, &hbm);
221     IPicture_get_CurDC(bitmap->image.picture, &hdc);
222     bm_is_selected = (hdc != 0);
223
224     pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
225     pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
226     pbmi->bmiHeader.biBitCount = 0;
227
228     if(!bm_is_selected){
229         hdc = CreateCompatibleDC(0);
230         old = SelectObject(hdc, (HBITMAP)hbm);
231     }
232
233     GetDIBits(hdc, (HBITMAP)hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
234     pbmi->bmiHeader.biBitCount = PIXELFORMATBPP(lockeddata->PixelFormat);
235     SetDIBits(hdc, (HBITMAP)hbm, 0, abs(pbmi->bmiHeader.biHeight),
236               bitmap->bitmapbits, pbmi, DIB_RGB_COLORS);
237
238     if(!bm_is_selected){
239         SelectObject(hdc, old);
240         DeleteDC(hdc);
241     }
242
243     GdipFree(pbmi);
244     GdipFree(bitmap->bitmapbits);
245     bitmap->bitmapbits = NULL;
246     bitmap->lockmode = 0;
247
248     return Ok;
249 }
250
251 GpStatus WINGDIPAPI GdipCloneImage(GpImage *image, GpImage **cloneImage)
252 {
253     IStream* stream;
254     HRESULT hr;
255     INT size;
256     LARGE_INTEGER move;
257
258     TRACE("%p, %p\n", image, cloneImage);
259
260     if (!image || !cloneImage)
261         return InvalidParameter;
262
263     hr = CreateStreamOnHGlobal(0, TRUE, &stream);
264     if (FAILED(hr))
265         return GenericError;
266
267     *cloneImage = GdipAlloc(sizeof(GpImage));
268     if (!*cloneImage)
269     {
270         IStream_Release(stream);
271         return OutOfMemory;
272     }
273     (*cloneImage)->type = image->type;
274     (*cloneImage)->flags = image->flags;
275
276     hr = IPicture_SaveAsFile(image->picture, stream, FALSE, &size);
277     if(FAILED(hr))
278     {
279         WARN("Failed to save image on stream\n");
280         goto out;
281     }
282
283     /* Set seek pointer back to the beginning of the picture */
284     move.QuadPart = 0;
285     hr = IStream_Seek(stream, move, STREAM_SEEK_SET, NULL);
286     if (FAILED(hr))
287         goto out;
288
289     hr = OleLoadPicture(stream, size, FALSE, &IID_IPicture,
290             (LPVOID*) &(*cloneImage)->picture);
291     if (FAILED(hr))
292     {
293         WARN("Failed to load image from stream\n");
294         goto out;
295     }
296
297     IStream_Release(stream);
298     return Ok;
299 out:
300     IStream_Release(stream);
301     GdipFree(*cloneImage);
302     *cloneImage = NULL;
303     return GenericError;
304 }
305
306 GpStatus WINGDIPAPI GdipCreateBitmapFromFile(GDIPCONST WCHAR* filename,
307     GpBitmap **bitmap)
308 {
309     GpStatus stat;
310     IStream *stream;
311
312     TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
313
314     if(!filename || !bitmap)
315         return InvalidParameter;
316
317     stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
318
319     if(stat != Ok)
320         return stat;
321
322     stat = GdipCreateBitmapFromStream(stream, bitmap);
323
324     IStream_Release(stream);
325
326     return stat;
327 }
328
329 GpStatus WINGDIPAPI GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO* info,
330                                                VOID *bits, GpBitmap **bitmap)
331 {
332     DWORD height, stride;
333     PixelFormat format;
334
335     FIXME("(%p, %p, %p) - partially implemented\n", info, bits, bitmap);
336
337     height = abs(info->bmiHeader.biHeight);
338     stride = ((info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) >> 3) & ~3;
339
340     if(info->bmiHeader.biHeight > 0) /* bottom-up */
341     {
342         bits = (BYTE*)bits + (height - 1) * stride;
343         stride = -stride;
344     }
345
346     switch(info->bmiHeader.biBitCount) {
347     case 1:
348         format = PixelFormat1bppIndexed;
349         break;
350     case 4:
351         format = PixelFormat4bppIndexed;
352         break;
353     case 8:
354         format = PixelFormat8bppIndexed;
355         break;
356     case 24:
357         format = PixelFormat24bppRGB;
358         break;
359     default:
360         FIXME("don't know how to handle %d bpp\n", info->bmiHeader.biBitCount);
361         *bitmap = NULL;
362         return InvalidParameter;
363     }
364
365     return GdipCreateBitmapFromScan0(info->bmiHeader.biWidth, height, stride, format,
366                                      bits, bitmap);
367
368 }
369
370 /* FIXME: no icm */
371 GpStatus WINGDIPAPI GdipCreateBitmapFromFileICM(GDIPCONST WCHAR* filename,
372     GpBitmap **bitmap)
373 {
374     TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
375
376     return GdipCreateBitmapFromFile(filename, bitmap);
377 }
378
379 GpStatus WINGDIPAPI GdipCreateBitmapFromResource(HINSTANCE hInstance,
380     GDIPCONST WCHAR* lpBitmapName, GpBitmap** bitmap)
381 {
382     HBITMAP hbm;
383     GpStatus stat = InvalidParameter;
384
385     TRACE("%p (%s) %p\n", hInstance, debugstr_w(lpBitmapName), bitmap);
386
387     if(!lpBitmapName || !bitmap)
388         return InvalidParameter;
389
390     /* load DIB */
391     hbm = (HBITMAP)LoadImageW(hInstance,lpBitmapName,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);
392
393     if(hbm){
394         stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, bitmap);
395         DeleteObject(hbm);
396     }
397
398     return stat;
399 }
400
401 GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
402     HBITMAP* hbmReturn, ARGB background)
403 {
404     FIXME("stub\n");
405
406     hbmReturn = NULL;
407
408     return NotImplemented;
409 }
410
411 GpStatus WINGDIPAPI GdipConvertToEmfPlus(const GpGraphics* ref,
412     GpMetafile* metafile, BOOL* succ, EmfType emfType,
413     const WCHAR* description, GpMetafile** out_metafile)
414 {
415     static int calls;
416
417     if(!ref || !metafile || !out_metafile)
418         return InvalidParameter;
419
420     *succ = FALSE;
421     *out_metafile = NULL;
422
423     if(!(calls++))
424         FIXME("not implemented\n");
425
426     return NotImplemented;
427 }
428
429 /* FIXME: this should create a bitmap in the given size with the attributes
430  * (resolution etc.) of the graphics object */
431 GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT width, INT height,
432     GpGraphics* target, GpBitmap** bitmap)
433 {
434     static int calls;
435     GpStatus ret;
436
437     if(!target || !bitmap)
438         return InvalidParameter;
439
440     if(!(calls++))
441         FIXME("hacked stub\n");
442
443     ret = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat24bppRGB,
444                                     NULL, bitmap);
445
446     return ret;
447 }
448
449 GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
450     PixelFormat format, BYTE* scan0, GpBitmap** bitmap)
451 {
452     BITMAPFILEHEADER *bmfh;
453     BITMAPINFOHEADER *bmih;
454     BYTE *buff;
455     INT datalen, size;
456     IStream *stream;
457
458     TRACE("%d %d %d %d %p %p\n", width, height, stride, format, scan0, bitmap);
459
460     if (!bitmap) return InvalidParameter;
461
462     if(width <= 0 || height <= 0 || (scan0 && (stride % 4))){
463         *bitmap = NULL;
464         return InvalidParameter;
465     }
466
467     if(scan0 && !stride)
468         return InvalidParameter;
469
470     /* FIXME: windows allows negative stride (reads backwards from scan0) */
471     if(stride < 0){
472         FIXME("negative stride\n");
473         return InvalidParameter;
474     }
475
476     *bitmap = GdipAlloc(sizeof(GpBitmap));
477     if(!*bitmap)    return OutOfMemory;
478
479     if(stride == 0){
480         stride = width * (PIXELFORMATBPP(format) / 8);
481         stride = (stride + 3) & ~3;
482     }
483
484     datalen = abs(stride * height);
485     size = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + datalen;
486     buff = GdipAlloc(size);
487     if(!buff){
488         GdipFree(*bitmap);
489         return OutOfMemory;
490     }
491
492     bmfh = (BITMAPFILEHEADER*) buff;
493     bmih = (BITMAPINFOHEADER*) (bmfh + 1);
494
495     bmfh->bfType    = (((WORD)'M') << 8) + (WORD)'B';
496     bmfh->bfSize    = size;
497     bmfh->bfOffBits = size - datalen;
498
499     bmih->biSize            = sizeof(BITMAPINFOHEADER);
500     bmih->biWidth           = width;
501     bmih->biHeight          = -height;
502     /* FIXME: use the rest of the data from format */
503     bmih->biBitCount        = PIXELFORMATBPP(format);
504     bmih->biCompression     = BI_RGB;
505     bmih->biSizeImage       = datalen;
506
507     if(scan0)
508         memcpy(bmih + 1, scan0, datalen);
509     else
510         memset(bmih + 1, 0, datalen);
511
512     if(CreateStreamOnHGlobal(buff, TRUE, &stream) != S_OK){
513         ERR("could not make stream\n");
514         GdipFree(*bitmap);
515         GdipFree(buff);
516         return GenericError;
517     }
518
519     if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
520         (LPVOID*) &((*bitmap)->image.picture)) != S_OK){
521         TRACE("Could not load picture\n");
522         IStream_Release(stream);
523         GdipFree(*bitmap);
524         GdipFree(buff);
525         return GenericError;
526     }
527
528     (*bitmap)->image.type = ImageTypeBitmap;
529     (*bitmap)->image.flags = ImageFlagsNone;
530     (*bitmap)->width = width;
531     (*bitmap)->height = height;
532     (*bitmap)->format = format;
533
534     return Ok;
535 }
536
537 GpStatus WINGDIPAPI GdipCreateBitmapFromStream(IStream* stream,
538     GpBitmap **bitmap)
539 {
540     GpStatus stat;
541
542     TRACE("%p %p\n", stream, bitmap);
543
544     stat = GdipLoadImageFromStream(stream, (GpImage**) bitmap);
545
546     if(stat != Ok)
547         return stat;
548
549     if((*bitmap)->image.type != ImageTypeBitmap){
550         IPicture_Release((*bitmap)->image.picture);
551         GdipFree(bitmap);
552         return GenericError; /* FIXME: what error to return? */
553     }
554
555     return Ok;
556 }
557
558 /* FIXME: no icm */
559 GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream* stream,
560     GpBitmap **bitmap)
561 {
562     TRACE("%p %p\n", stream, bitmap);
563
564     return GdipCreateBitmapFromStream(stream, bitmap);
565 }
566
567 GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
568 {
569     HDC hdc;
570
571     TRACE("%p\n", image);
572
573     if(!image)
574         return InvalidParameter;
575
576     IPicture_get_CurDC(image->picture, &hdc);
577     DeleteDC(hdc);
578     IPicture_Release(image->picture);
579     if (image->type == ImageTypeBitmap)
580         GdipFree(((GpBitmap*)image)->bitmapbits);
581     GdipFree(image);
582
583     return Ok;
584 }
585
586 GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage *image, ImageItemData* item)
587 {
588     if(!image || !item)
589         return InvalidParameter;
590
591     return NotImplemented;
592 }
593
594 GpStatus WINGDIPAPI GdipGetImageBounds(GpImage *image, GpRectF *srcRect,
595     GpUnit *srcUnit)
596 {
597     TRACE("%p %p %p\n", image, srcRect, srcUnit);
598
599     if(!image || !srcRect || !srcUnit)
600         return InvalidParameter;
601     if(image->type == ImageTypeMetafile){
602         *srcRect = ((GpMetafile*)image)->bounds;
603         *srcUnit = ((GpMetafile*)image)->unit;
604     }
605     else if(image->type == ImageTypeBitmap){
606         srcRect->X = srcRect->Y = 0.0;
607         srcRect->Width = (REAL) ((GpBitmap*)image)->width;
608         srcRect->Height = (REAL) ((GpBitmap*)image)->height;
609         *srcUnit = UnitPixel;
610     }
611     else{
612         srcRect->X = srcRect->Y = 0.0;
613         srcRect->Width = ipicture_pixel_width(image->picture);
614         srcRect->Height = ipicture_pixel_height(image->picture);
615         *srcUnit = UnitPixel;
616     }
617
618     TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect->X, srcRect->Y,
619           srcRect->Width, srcRect->Height, *srcUnit);
620
621     return Ok;
622 }
623
624 GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
625     REAL *height)
626 {
627     TRACE("%p %p %p\n", image, width, height);
628
629     if(!image || !height || !width)
630         return InvalidParameter;
631
632     if(image->type == ImageTypeMetafile){
633         HDC hdc = GetDC(0);
634
635         *height = convert_unit(hdc, ((GpMetafile*)image)->unit) *
636                         ((GpMetafile*)image)->bounds.Height;
637
638         *width = convert_unit(hdc, ((GpMetafile*)image)->unit) *
639                         ((GpMetafile*)image)->bounds.Width;
640
641         ReleaseDC(0, hdc);
642     }
643
644     else if(image->type == ImageTypeBitmap){
645         *height = ((GpBitmap*)image)->height;
646         *width = ((GpBitmap*)image)->width;
647     }
648     else{
649         *height = ipicture_pixel_height(image->picture);
650         *width = ipicture_pixel_width(image->picture);
651     }
652
653     TRACE("returning (%f, %f)\n", *height, *width);
654     return Ok;
655 }
656
657 GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image,
658     GpGraphics **graphics)
659 {
660     HDC hdc;
661
662     TRACE("%p %p\n", image, graphics);
663
664     if(!image || !graphics)
665         return InvalidParameter;
666
667     if(image->type != ImageTypeBitmap){
668         FIXME("not implemented for image type %d\n", image->type);
669         return NotImplemented;
670     }
671
672     IPicture_get_CurDC(image->picture, &hdc);
673
674     if(!hdc){
675         hdc = CreateCompatibleDC(0);
676         IPicture_SelectPicture(image->picture, hdc, NULL, NULL);
677     }
678
679     return GdipCreateFromHDC(hdc, graphics);
680 }
681
682 GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
683 {
684     TRACE("%p %p\n", image, height);
685
686     if(!image || !height)
687         return InvalidParameter;
688
689     if(image->type == ImageTypeMetafile){
690         HDC hdc = GetDC(0);
691
692         *height = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
693                         ((GpMetafile*)image)->bounds.Height);
694
695         ReleaseDC(0, hdc);
696     }
697     else if(image->type == ImageTypeBitmap)
698         *height = ((GpBitmap*)image)->height;
699     else
700         *height = ipicture_pixel_height(image->picture);
701
702     TRACE("returning %d\n", *height);
703
704     return Ok;
705 }
706
707 GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res)
708 {
709     static int calls;
710
711     if(!image || !res)
712         return InvalidParameter;
713
714     if(!(calls++))
715         FIXME("not implemented\n");
716
717     return NotImplemented;
718 }
719
720 /* FIXME: test this function for non-bitmap types */
721 GpStatus WINGDIPAPI GdipGetImagePixelFormat(GpImage *image, PixelFormat *format)
722 {
723     TRACE("%p %p\n", image, format);
724
725     if(!image || !format)
726         return InvalidParameter;
727
728     if(image->type != ImageTypeBitmap)
729         *format = PixelFormat24bppRGB;
730     else
731         *format = ((GpBitmap*) image)->format;
732
733     return Ok;
734 }
735
736 GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage *image, GUID *format)
737 {
738     static int calls;
739
740     if(!image || !format)
741         return InvalidParameter;
742
743     if(!(calls++))
744         FIXME("not implemented\n");
745
746     return NotImplemented;
747 }
748
749 GpStatus WINGDIPAPI GdipGetImageType(GpImage *image, ImageType *type)
750 {
751     TRACE("%p %p\n", image, type);
752
753     if(!image || !type)
754         return InvalidParameter;
755
756     *type = image->type;
757
758     return Ok;
759 }
760
761 GpStatus WINGDIPAPI GdipGetImageVerticalResolution(GpImage *image, REAL *res)
762 {
763     static int calls;
764
765     if(!image || !res)
766         return InvalidParameter;
767
768     if(!(calls++))
769         FIXME("not implemented\n");
770
771     return NotImplemented;
772 }
773
774 GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
775 {
776     TRACE("%p %p\n", image, width);
777
778     if(!image || !width)
779         return InvalidParameter;
780
781     if(image->type == ImageTypeMetafile){
782         HDC hdc = GetDC(0);
783
784         *width = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
785                         ((GpMetafile*)image)->bounds.Width);
786
787         ReleaseDC(0, hdc);
788     }
789     else if(image->type == ImageTypeBitmap)
790         *width = ((GpBitmap*)image)->width;
791     else
792         *width = ipicture_pixel_width(image->picture);
793
794     TRACE("returning %d\n", *width);
795
796     return Ok;
797 }
798
799 GpStatus WINGDIPAPI GdipGetMetafileHeaderFromMetafile(GpMetafile * metafile,
800     MetafileHeader * header)
801 {
802     static int calls;
803
804     if(!metafile || !header)
805         return InvalidParameter;
806
807     if(!(calls++))
808         FIXME("not implemented\n");
809
810     return Ok;
811 }
812
813 GpStatus WINGDIPAPI GdipGetAllPropertyItems(GpImage *image, UINT size,
814     UINT num, PropertyItem* items)
815 {
816     static int calls;
817
818     if(!(calls++))
819         FIXME("not implemented\n");
820
821     return InvalidParameter;
822 }
823
824 GpStatus WINGDIPAPI GdipGetPropertyCount(GpImage *image, UINT* num)
825 {
826     static int calls;
827
828     if(!(calls++))
829         FIXME("not implemented\n");
830
831     return InvalidParameter;
832 }
833
834 GpStatus WINGDIPAPI GdipGetPropertyIdList(GpImage *image, UINT num, PROPID* list)
835 {
836     static int calls;
837
838     if(!(calls++))
839         FIXME("not implemented\n");
840
841     return InvalidParameter;
842 }
843
844 GpStatus WINGDIPAPI GdipGetPropertyItem(GpImage *image, PROPID id, UINT size,
845     PropertyItem* buffer)
846 {
847     static int calls;
848
849     if(!(calls++))
850         FIXME("not implemented\n");
851
852     return InvalidParameter;
853 }
854
855 GpStatus WINGDIPAPI GdipGetPropertyItemSize(GpImage *image, PROPID pid,
856     UINT* size)
857 {
858     static int calls;
859
860     TRACE("%p %x %p\n", image, pid, size);
861
862     if(!size || !image)
863         return InvalidParameter;
864
865     if(!(calls++))
866         FIXME("not implemented\n");
867
868     return NotImplemented;
869 }
870
871 GpStatus WINGDIPAPI GdipGetPropertySize(GpImage *image, UINT* size, UINT* num)
872 {
873     static int calls;
874
875     if(!(calls++))
876         FIXME("not implemented\n");
877
878     return InvalidParameter;
879 }
880
881 GpStatus WINGDIPAPI GdipImageGetFrameCount(GpImage *image,
882     GDIPCONST GUID* dimensionID, UINT* count)
883 {
884     static int calls;
885
886     if(!image || !dimensionID || !count)
887         return InvalidParameter;
888
889     if(!(calls++))
890         FIXME("not implemented\n");
891
892     return NotImplemented;
893 }
894
895 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsCount(GpImage *image,
896     UINT* count)
897 {
898     if(!image || !count)
899         return InvalidParameter;
900
901     *count = 1;
902
903     FIXME("stub\n");
904
905     return Ok;
906 }
907
908 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsList(GpImage* image,
909     GUID* dimensionIDs, UINT count)
910 {
911     static int calls;
912
913     if(!image || !dimensionIDs)
914         return InvalidParameter;
915
916     if(!(calls++))
917         FIXME("not implemented\n");
918
919     return Ok;
920 }
921
922 GpStatus WINGDIPAPI GdipImageSelectActiveFrame(GpImage *image,
923     GDIPCONST GUID* dimensionID, UINT frameidx)
924 {
925     static int calls;
926
927     if(!image || !dimensionID)
928         return InvalidParameter;
929
930     if(!(calls++))
931         FIXME("not implemented\n");
932
933     return Ok;
934 }
935
936 GpStatus WINGDIPAPI GdipLoadImageFromFile(GDIPCONST WCHAR* filename,
937                                           GpImage **image)
938 {
939     GpStatus stat;
940     IStream *stream;
941
942     TRACE("(%s) %p\n", debugstr_w(filename), image);
943
944     if (!filename || !image)
945         return InvalidParameter;
946
947     stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
948
949     if (stat != Ok)
950         return stat;
951
952     stat = GdipLoadImageFromStream(stream, image);
953
954     IStream_Release(stream);
955
956     return stat;
957 }
958
959 /* FIXME: no icm handling */
960 GpStatus WINGDIPAPI GdipLoadImageFromFileICM(GDIPCONST WCHAR* filename,GpImage **image)
961 {
962     TRACE("(%s) %p\n", debugstr_w(filename), image);
963
964     return GdipLoadImageFromFile(filename, image);
965 }
966
967 GpStatus WINGDIPAPI GdipLoadImageFromStream(IStream* stream, GpImage **image)
968 {
969     IPicture *pic;
970     short type;
971
972     TRACE("%p %p\n", stream, image);
973
974     if(!stream || !image)
975         return InvalidParameter;
976
977     if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
978         (LPVOID*) &pic) != S_OK){
979         TRACE("Could not load picture\n");
980         return GenericError;
981     }
982
983     IPicture_get_Type(pic, &type);
984
985     if(type == PICTYPE_BITMAP){
986         BITMAPINFO *pbmi;
987         BITMAPCOREHEADER* bmch;
988         OLE_HANDLE hbm;
989         HDC hdc;
990
991         pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
992         if (!pbmi)
993             return OutOfMemory;
994         *image = GdipAlloc(sizeof(GpBitmap));
995         if(!*image){
996             GdipFree(pbmi);
997             return OutOfMemory;
998         }
999         (*image)->type = ImageTypeBitmap;
1000
1001         (*((GpBitmap**) image))->width = ipicture_pixel_width(pic);
1002         (*((GpBitmap**) image))->height = ipicture_pixel_height(pic);
1003
1004         /* get the pixel format */
1005         IPicture_get_Handle(pic, &hbm);
1006         IPicture_get_CurDC(pic, &hdc);
1007
1008         bmch = (BITMAPCOREHEADER*) (&pbmi->bmiHeader);
1009         bmch->bcSize = sizeof(BITMAPCOREHEADER);
1010
1011         if(!hdc){
1012             HBITMAP old;
1013             hdc = CreateCompatibleDC(0);
1014             old = SelectObject(hdc, (HBITMAP)hbm);
1015             GetDIBits(hdc, (HBITMAP)hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
1016             SelectObject(hdc, old);
1017             DeleteDC(hdc);
1018         }
1019         else
1020             GetDIBits(hdc, (HBITMAP)hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
1021
1022         (*((GpBitmap**) image))->format = (bmch->bcBitCount << 8) | PixelFormatGDI;
1023         GdipFree(pbmi);
1024     }
1025     else if(type == PICTYPE_METAFILE || type == PICTYPE_ENHMETAFILE){
1026         /* FIXME: missing initialization code */
1027         *image = GdipAlloc(sizeof(GpMetafile));
1028         if(!*image) return OutOfMemory;
1029         (*image)->type = ImageTypeMetafile;
1030     }
1031     else{
1032         *image = GdipAlloc(sizeof(GpImage));
1033         if(!*image) return OutOfMemory;
1034         (*image)->type = ImageTypeUnknown;
1035     }
1036
1037     (*image)->picture = pic;
1038     (*image)->flags   = ImageFlagsNone;
1039
1040     return Ok;
1041 }
1042
1043 /* FIXME: no ICM */
1044 GpStatus WINGDIPAPI GdipLoadImageFromStreamICM(IStream* stream, GpImage **image)
1045 {
1046     TRACE("%p %p\n", stream, image);
1047
1048     return GdipLoadImageFromStream(stream, image);
1049 }
1050
1051 GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
1052 {
1053     static int calls;
1054
1055     if(!image)
1056         return InvalidParameter;
1057
1058     if(!(calls++))
1059         FIXME("not implemented\n");
1060
1061     return NotImplemented;
1062 }
1063
1064 GpStatus WINGDIPAPI GdipSetPropertyItem(GpImage *image, GDIPCONST PropertyItem* item)
1065 {
1066     static int calls;
1067
1068     if(!(calls++))
1069         FIXME("not implemented\n");
1070
1071     return NotImplemented;
1072 }
1073
1074 GpStatus WINGDIPAPI GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
1075                                         GDIPCONST CLSID *clsidEncoder,
1076                                         GDIPCONST EncoderParameters *encoderParams)
1077 {
1078     GpStatus stat;
1079     IStream *stream;
1080
1081     TRACE("%p (%s) %p %p\n", image, debugstr_w(filename), clsidEncoder, encoderParams);
1082
1083     if (!image || !filename|| !clsidEncoder)
1084         return InvalidParameter;
1085
1086     if (!(image->picture))
1087         return InvalidParameter;
1088
1089     stat = GdipCreateStreamOnFile(filename, GENERIC_WRITE, &stream);
1090     if (stat != Ok)
1091         return GenericError;
1092
1093     stat = GdipSaveImageToStream(image, stream, clsidEncoder, encoderParams);
1094
1095     IStream_Release(stream);
1096     return stat;
1097 }
1098
1099 /*************************************************************************
1100  * Encoding functions -
1101  *   These functions encode an image in different image file formats.
1102  */
1103 #define BITMAP_FORMAT_BMP   0x4d42 /* "BM" */
1104 #define BITMAP_FORMAT_JPEG  0xd8ff
1105 #define BITMAP_FORMAT_GIF   0x4947
1106 #define BITMAP_FORMAT_PNG   0x5089
1107 #define BITMAP_FORMAT_APM   0xcdd7
1108
1109 static GpStatus encode_image_BMP(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
1110                                  void **output, unsigned int *output_size)
1111 {
1112     int num_palette_entries;
1113     BITMAPFILEHEADER *bmp_file_hdr;
1114     BITMAPINFO *bmp_info_hdr;
1115
1116     if (bitmap_info->bmiHeader.biClrUsed) {
1117         num_palette_entries = bitmap_info->bmiHeader.biClrUsed;
1118         if (num_palette_entries > 256) num_palette_entries = 256;
1119     } else {
1120         if (bitmap_info->bmiHeader.biBitCount <= 8)
1121             num_palette_entries = 1 << bitmap_info->bmiHeader.biBitCount;
1122         else
1123             num_palette_entries = 0;
1124     }
1125
1126     *output_size =
1127         sizeof(BITMAPFILEHEADER) +
1128         sizeof(BITMAPINFOHEADER) +
1129         num_palette_entries * sizeof(RGBQUAD) +
1130         bitmap_info->bmiHeader.biSizeImage;
1131
1132     *output = GdipAlloc(*output_size);
1133
1134     bmp_file_hdr = (BITMAPFILEHEADER*) *output;
1135     bmp_file_hdr->bfType = BITMAP_FORMAT_BMP;
1136     bmp_file_hdr->bfSize = *output_size;
1137     bmp_file_hdr->bfOffBits =
1138         sizeof(BITMAPFILEHEADER) +
1139         sizeof(BITMAPINFOHEADER) +
1140         num_palette_entries * sizeof (RGBQUAD);
1141
1142     bmp_info_hdr = (BITMAPINFO*) ((unsigned char*)(*output) + sizeof(BITMAPFILEHEADER));
1143     memcpy(bmp_info_hdr, bitmap_info, sizeof(BITMAPINFOHEADER) + num_palette_entries * sizeof(RGBQUAD));
1144     memcpy((unsigned char *)(*output) +
1145            sizeof(BITMAPFILEHEADER) +
1146            sizeof(BITMAPINFOHEADER) +
1147            num_palette_entries * sizeof(RGBQUAD),
1148            bitmap_bits, bitmap_info->bmiHeader.biSizeImage);
1149
1150     return Ok;
1151 }
1152
1153 typedef GpStatus encode_image_func(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
1154                                    void **output, unsigned int *output_size);
1155
1156 typedef enum {
1157     BMP,
1158     NUM_ENCODERS_SUPPORTED
1159 } ImageFormat;
1160
1161 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED];
1162 static encode_image_func *const encode_image_funcs[NUM_ENCODERS_SUPPORTED] = {
1163     encode_image_BMP,
1164 };
1165
1166 /*****************************************************************************
1167  * GdipSaveImageToStream [GDIPLUS.@]
1168  */
1169 GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
1170     GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
1171 {
1172     GpStatus stat;
1173     HRESULT hr;
1174     short type;
1175     HBITMAP hbmp;
1176     HBITMAP old_hbmp;
1177     HDC hdc;
1178     int bm_is_selected;
1179     BITMAPINFO bmp_info;
1180     LPVOID bmp_bits;
1181     encode_image_func* encode_image;
1182     LPVOID output;
1183     unsigned int output_size;
1184     unsigned int dummy;
1185     int i;
1186
1187     old_hbmp = 0;
1188     output = NULL;
1189     output_size = 0;
1190
1191     TRACE("%p %p %p %p\n", image, stream, clsid, params);
1192
1193     if(!image || !stream)
1194         return InvalidParameter;
1195
1196     if (!image->picture)
1197         return GenericError;
1198
1199     hr = IPicture_get_Type(image->picture, &type);
1200     if (FAILED(hr) || type != PICTYPE_BITMAP)
1201         return GenericError;
1202
1203     /* select correct encoder */
1204     encode_image = NULL;
1205     for (i = 0; i < NUM_ENCODERS_SUPPORTED; i++) {
1206         if (IsEqualCLSID(clsid, &codecs[i].Clsid))
1207             encode_image = encode_image_funcs[i];
1208     }
1209     if (encode_image == NULL)
1210         return UnknownImageFormat;
1211
1212     /* extract underlying hbitmap representation from the IPicture */
1213     hr = IPicture_get_Handle(image->picture, (OLE_HANDLE*)&hbmp);
1214     if (FAILED(hr) || !hbmp)
1215         return GenericError;
1216     hr = IPicture_get_CurDC(image->picture, &hdc);
1217     if (FAILED(hr))
1218         return GenericError;
1219     bm_is_selected = (hdc != 0);
1220     if (!bm_is_selected) {
1221         hdc = CreateCompatibleDC(0);
1222         old_hbmp = SelectObject(hdc, hbmp);
1223     }
1224
1225     /* get bits from HBITMAP */
1226     bmp_info.bmiHeader.biSize = sizeof(bmp_info.bmiHeader);
1227     bmp_info.bmiHeader.biBitCount = 0;
1228     GetDIBits(hdc, hbmp, 0, 0, NULL, &bmp_info, DIB_RGB_COLORS);
1229
1230     bmp_bits = GdipAlloc(bmp_info.bmiHeader.biSizeImage);
1231
1232     if (bmp_bits)
1233         GetDIBits(hdc, hbmp, 0, abs(bmp_info.bmiHeader.biHeight), bmp_bits, &bmp_info, DIB_RGB_COLORS);
1234
1235     if (!bm_is_selected) {
1236         SelectObject(hdc, old_hbmp);
1237         DeleteDC(hdc);
1238     }
1239
1240     if (!bmp_bits)
1241         return OutOfMemory;
1242
1243     stat = encode_image(bmp_bits, &bmp_info, &output, &output_size);
1244     if (stat == Ok)
1245         IStream_Write(stream, output, output_size, &dummy);
1246
1247     GdipFree(output);
1248     GdipFree(bmp_bits);
1249
1250     return stat;
1251 }
1252
1253 /*****************************************************************************
1254  * GdipSetImagePalette [GDIPLUS.@]
1255  */
1256 GpStatus WINGDIPAPI GdipSetImagePalette(GpImage *image,
1257     GDIPCONST ColorPalette *palette)
1258 {
1259     static int calls;
1260
1261     if(!image || !palette)
1262         return InvalidParameter;
1263
1264     if(!(calls++))
1265         FIXME("not implemented\n");
1266
1267     return NotImplemented;
1268 }
1269
1270 /*************************************************************************
1271  * Encoders -
1272  *   Structures that represent which formats we support for encoding.
1273  */
1274
1275 /* ImageCodecInfo creation routines taken from libgdiplus */
1276 static const WCHAR bmp_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
1277 static const WCHAR bmp_extension[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
1278 static const WCHAR bmp_mimetype[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
1279 static const WCHAR bmp_format[] = {'B', 'M', 'P', 0}; /* BMP */
1280 static const BYTE bmp_sig_pattern[] = { 0x42, 0x4D };
1281 static const BYTE bmp_sig_mask[] = { 0xFF, 0xFF };
1282
1283 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED] =
1284     {
1285         { /* BMP */
1286             /* Clsid */              { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
1287             /* FormatID */           { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
1288             /* CodecName */          bmp_codecname,
1289             /* DllName */            NULL,
1290             /* FormatDescription */  bmp_format,
1291             /* FilenameExtension */  bmp_extension,
1292             /* MimeType */           bmp_mimetype,
1293             /* Flags */              ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
1294             /* Version */            1,
1295             /* SigCount */           1,
1296             /* SigSize */            2,
1297             /* SigPattern */         bmp_sig_pattern,
1298             /* SigMask */            bmp_sig_mask,
1299         },
1300     };
1301
1302 /*****************************************************************************
1303  * GdipGetImageDecodersSize [GDIPLUS.@]
1304  */
1305 GpStatus WINGDIPAPI GdipGetImageDecodersSize(UINT *numDecoders, UINT *size)
1306 {
1307     FIXME("%p %p stub!\n", numDecoders, size);
1308
1309     if (!numDecoders || !size)
1310         return InvalidParameter;
1311
1312     *numDecoders = 0;
1313     *size = 0;
1314
1315     return Ok;
1316 }
1317
1318 /*****************************************************************************
1319  * GdipGetImageDecoders [GDIPLUS.@]
1320  */
1321 GpStatus WINGDIPAPI GdipGetImageDecoders(UINT numDecoders, UINT size, ImageCodecInfo *decoders)
1322 {
1323     FIXME("%u %u %p stub!\n", numDecoders, size, decoders);
1324
1325     if (!decoders)
1326         return GenericError;
1327
1328     return NotImplemented;
1329 }
1330
1331 /*****************************************************************************
1332  * GdipGetImageEncodersSize [GDIPLUS.@]
1333  */
1334 GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size)
1335 {
1336     TRACE("%p %p\n", numEncoders, size);
1337
1338     if (!numEncoders || !size)
1339         return InvalidParameter;
1340
1341     *numEncoders = NUM_ENCODERS_SUPPORTED;
1342     *size = sizeof (codecs);
1343
1344     return Ok;
1345 }
1346
1347 /*****************************************************************************
1348  * GdipGetImageEncoders [GDIPLUS.@]
1349  */
1350 GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders)
1351 {
1352     TRACE("%u %u %p\n", numEncoders, size, encoders);
1353
1354     if (!encoders ||
1355         (numEncoders != NUM_ENCODERS_SUPPORTED) ||
1356         (size != sizeof (codecs)))
1357         return GenericError;
1358
1359     memcpy(encoders, codecs, sizeof (codecs));
1360
1361     return Ok;
1362 }
1363
1364 /*****************************************************************************
1365  * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
1366  */
1367 GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBitmap** bitmap)
1368 {
1369     BITMAP bm;
1370     GpStatus retval;
1371     PixelFormat format;
1372
1373     TRACE("%p %p %p\n", hbm, hpal, bitmap);
1374
1375     if(!hbm || !bitmap)
1376         return InvalidParameter;
1377
1378     /* TODO: Support for device-dependent bitmaps */
1379     if(hpal){
1380         FIXME("no support for device-dependent bitmaps\n");
1381         return NotImplemented;
1382     }
1383
1384     if (GetObjectA(hbm, sizeof(bm), &bm) != sizeof(bm))
1385             return InvalidParameter;
1386
1387     /* TODO: Figure out the correct format for 16, 32, 64 bpp */
1388     switch(bm.bmBitsPixel) {
1389         case 1:
1390             format = PixelFormat1bppIndexed;
1391             break;
1392         case 4:
1393             format = PixelFormat4bppIndexed;
1394             break;
1395         case 8:
1396             format = PixelFormat8bppIndexed;
1397             break;
1398         case 24:
1399             format = PixelFormat24bppRGB;
1400             break;
1401         case 32:
1402             format = PixelFormat32bppRGB;
1403             break;
1404         case 48:
1405             format = PixelFormat48bppRGB;
1406             break;
1407         default:
1408             FIXME("don't know how to handle %d bpp\n", bm.bmBitsPixel);
1409             return InvalidParameter;
1410     }
1411
1412     retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, bm.bmWidthBytes,
1413         format, bm.bmBits, bitmap);
1414
1415     return retval;
1416 }
1417
1418 /*****************************************************************************
1419  * GdipSetEffectParameters [GDIPLUS.@]
1420  */
1421 GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect *effect,
1422     const VOID *params, const UINT size)
1423 {
1424     static int calls;
1425
1426     if(!(calls++))
1427         FIXME("not implemented\n");
1428
1429     return NotImplemented;
1430 }
1431
1432 /*****************************************************************************
1433  * GdipGetImageFlags [GDIPLUS.@]
1434  */
1435 GpStatus WINGDIPAPI GdipGetImageFlags(GpImage *image, UINT *flags)
1436 {
1437     TRACE("%p %p\n", image, flags);
1438
1439     if(!image || !flags)
1440         return InvalidParameter;
1441
1442     *flags = image->flags;
1443
1444     return Ok;
1445 }
1446
1447 GpStatus WINGDIPAPI GdipTestControl(GpTestControlEnum control, void *param)
1448 {
1449     TRACE("(%d, %p)\n", control, param);
1450
1451     switch(control){
1452         case TestControlForceBilinear:
1453             if(param)
1454                 FIXME("TestControlForceBilinear not handled\n");
1455             break;
1456         case TestControlNoICM:
1457             if(param)
1458                 FIXME("TestControlNoICM not handled\n");
1459             break;
1460         case TestControlGetBuildNumber:
1461             *((DWORD*)param) = 3102;
1462             break;
1463     }
1464
1465     return Ok;
1466 }
1467
1468 GpStatus WINGDIPAPI GdipRecordMetafileFileName(GDIPCONST WCHAR* fileName,
1469                             HDC hdc, EmfType type, GDIPCONST GpRectF *pFrameRect,
1470                             MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc,
1471                             GpMetafile **metafile)
1472 {
1473     FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
1474                                  frameUnit, debugstr_w(desc), metafile);
1475
1476     return NotImplemented;
1477 }
1478
1479 GpStatus WINGDIPAPI GdipRecordMetafileFileNameI(GDIPCONST WCHAR* fileName, HDC hdc, EmfType type,
1480                             GDIPCONST GpRect *pFrameRect, MetafileFrameUnit frameUnit,
1481                             GDIPCONST WCHAR *desc, GpMetafile **metafile)
1482 {
1483     FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
1484                                  frameUnit, debugstr_w(desc), metafile);
1485
1486     return NotImplemented;
1487 }