ole32: Round the extected size in the marshal and moniker tests using the results...
[wine/multimedia.git] / dlls / gdiplus / image.c
blob9944322b3714fbcb1bed375d2745460415f00b4b
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 "gdiplus.h"
35 #include "gdiplus_private.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
40 #define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
42 static INT ipicture_pixel_height(IPicture *pic)
44 HDC hdcref;
45 OLE_YSIZE_HIMETRIC y;
47 IPicture_get_Height(pic, &y);
49 hdcref = GetDC(0);
51 y = MulDiv(y, GetDeviceCaps(hdcref, LOGPIXELSY), INCH_HIMETRIC);
52 ReleaseDC(0, hdcref);
54 return y;
57 static INT ipicture_pixel_width(IPicture *pic)
59 HDC hdcref;
60 OLE_XSIZE_HIMETRIC x;
62 IPicture_get_Width(pic, &x);
64 hdcref = GetDC(0);
66 x = MulDiv(x, GetDeviceCaps(hdcref, LOGPIXELSX), INCH_HIMETRIC);
68 ReleaseDC(0, hdcref);
70 return x;
73 GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y,
74 ARGB *color)
76 static int calls;
77 TRACE("%p %d %d %p\n", bitmap, x, y, color);
79 if(!bitmap || !color)
80 return InvalidParameter;
82 if(!(calls++))
83 FIXME("not implemented\n");
85 *color = 0xdeadbeef;
87 return NotImplemented;
90 /* This function returns a pointer to an array of pixels that represents the
91 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
92 * flags. It is correct behavior that a user who calls this function with write
93 * privileges can write to the whole bitmap (not just the area in rect).
95 * FIXME: only used portion of format is bits per pixel. */
96 GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
97 UINT flags, PixelFormat format, BitmapData* lockeddata)
99 BOOL bm_is_selected;
100 INT stride, bitspp = PIXELFORMATBPP(format);
101 HDC hdc;
102 HBITMAP hbm, old = NULL;
103 BITMAPINFO *pbmi;
104 BYTE *buff = NULL;
105 UINT abs_height;
106 GpRect act_rect; /* actual rect to be used */
108 TRACE("%p %p %d %d %p\n", bitmap, rect, flags, format, lockeddata);
110 if(!lockeddata || !bitmap)
111 return InvalidParameter;
113 if(rect){
114 if(rect->X < 0 || rect->Y < 0 || (rect->X + rect->Width > bitmap->width) ||
115 (rect->Y + rect->Height > bitmap->height) || !flags)
116 return InvalidParameter;
118 act_rect = *rect;
120 else{
121 act_rect.X = act_rect.Y = 0;
122 act_rect.Width = bitmap->width;
123 act_rect.Height = bitmap->height;
126 if(flags & ImageLockModeUserInputBuf)
127 return NotImplemented;
129 if(bitmap->lockmode)
130 return WrongState;
132 IPicture_get_Handle(bitmap->image.picture, (OLE_HANDLE*)&hbm);
133 IPicture_get_CurDC(bitmap->image.picture, &hdc);
134 bm_is_selected = (hdc != 0);
136 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
137 if (!pbmi)
138 return OutOfMemory;
139 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
140 pbmi->bmiHeader.biBitCount = 0;
142 if(!bm_is_selected){
143 hdc = CreateCompatibleDC(0);
144 old = SelectObject(hdc, hbm);
147 /* fill out bmi */
148 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
150 abs_height = abs(pbmi->bmiHeader.biHeight);
151 stride = pbmi->bmiHeader.biWidth * bitspp / 8;
152 stride = (stride + 3) & ~3;
154 buff = GdipAlloc(stride * abs_height);
156 pbmi->bmiHeader.biBitCount = bitspp;
158 if(buff)
159 GetDIBits(hdc, hbm, 0, abs_height, buff, pbmi, DIB_RGB_COLORS);
161 if(!bm_is_selected){
162 SelectObject(hdc, old);
163 DeleteDC(hdc);
166 if(!buff){
167 GdipFree(pbmi);
168 return OutOfMemory;
171 lockeddata->Width = act_rect.Width;
172 lockeddata->Height = act_rect.Height;
173 lockeddata->PixelFormat = format;
174 lockeddata->Reserved = flags;
176 if(pbmi->bmiHeader.biHeight > 0){
177 lockeddata->Stride = -stride;
178 lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X +
179 stride * (abs_height - 1 - act_rect.Y);
181 else{
182 lockeddata->Stride = stride;
183 lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X + stride * act_rect.Y;
186 bitmap->lockmode = flags;
187 bitmap->numlocks++;
189 bitmap->bitmapbits = buff;
191 GdipFree(pbmi);
192 return Ok;
195 GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap,
196 BitmapData* lockeddata)
198 HDC hdc;
199 HBITMAP hbm, old = NULL;
200 BOOL bm_is_selected;
201 BITMAPINFO *pbmi;
203 if(!bitmap || !lockeddata)
204 return InvalidParameter;
206 if(!bitmap->lockmode)
207 return WrongState;
209 if(lockeddata->Reserved & ImageLockModeUserInputBuf)
210 return NotImplemented;
212 if(lockeddata->Reserved & ImageLockModeRead){
213 if(!(--bitmap->numlocks))
214 bitmap->lockmode = 0;
216 GdipFree(bitmap->bitmapbits);
217 bitmap->bitmapbits = NULL;
218 return Ok;
221 IPicture_get_Handle(bitmap->image.picture, (OLE_HANDLE*)&hbm);
222 IPicture_get_CurDC(bitmap->image.picture, &hdc);
223 bm_is_selected = (hdc != 0);
225 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
226 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
227 pbmi->bmiHeader.biBitCount = 0;
229 if(!bm_is_selected){
230 hdc = CreateCompatibleDC(0);
231 old = SelectObject(hdc, hbm);
234 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
235 pbmi->bmiHeader.biBitCount = PIXELFORMATBPP(lockeddata->PixelFormat);
236 SetDIBits(hdc, hbm, 0, abs(pbmi->bmiHeader.biHeight),
237 bitmap->bitmapbits, pbmi, DIB_RGB_COLORS);
239 if(!bm_is_selected){
240 SelectObject(hdc, old);
241 DeleteDC(hdc);
244 GdipFree(pbmi);
245 GdipFree(bitmap->bitmapbits);
246 bitmap->bitmapbits = NULL;
247 bitmap->lockmode = 0;
249 return Ok;
252 GpStatus WINGDIPAPI GdipCloneImage(GpImage *image, GpImage **cloneImage)
254 IStream* stream;
255 HRESULT hr;
256 INT size;
257 LARGE_INTEGER move;
258 GpStatus stat = GenericError;
260 TRACE("%p, %p\n", image, cloneImage);
262 if (!image || !cloneImage)
263 return InvalidParameter;
265 hr = CreateStreamOnHGlobal(0, TRUE, &stream);
266 if (FAILED(hr))
267 return GenericError;
269 hr = IPicture_SaveAsFile(image->picture, stream, FALSE, &size);
270 if(FAILED(hr))
272 WARN("Failed to save image on stream\n");
273 goto out;
276 /* Set seek pointer back to the beginning of the picture */
277 move.QuadPart = 0;
278 hr = IStream_Seek(stream, move, STREAM_SEEK_SET, NULL);
279 if (FAILED(hr))
280 goto out;
282 stat = GdipLoadImageFromStream(stream, cloneImage);
283 if (stat != Ok) WARN("Failed to load image from stream\n");
285 out:
286 IStream_Release(stream);
287 return stat;
290 GpStatus WINGDIPAPI GdipCreateBitmapFromFile(GDIPCONST WCHAR* filename,
291 GpBitmap **bitmap)
293 GpStatus stat;
294 IStream *stream;
296 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
298 if(!filename || !bitmap)
299 return InvalidParameter;
301 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
303 if(stat != Ok)
304 return stat;
306 stat = GdipCreateBitmapFromStream(stream, bitmap);
308 IStream_Release(stream);
310 return stat;
313 GpStatus WINGDIPAPI GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO* info,
314 VOID *bits, GpBitmap **bitmap)
316 DWORD height, stride;
317 PixelFormat format;
319 FIXME("(%p, %p, %p) - partially implemented\n", info, bits, bitmap);
321 height = abs(info->bmiHeader.biHeight);
322 stride = ((info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) >> 3) & ~3;
324 if(info->bmiHeader.biHeight > 0) /* bottom-up */
326 bits = (BYTE*)bits + (height - 1) * stride;
327 stride = -stride;
330 switch(info->bmiHeader.biBitCount) {
331 case 1:
332 format = PixelFormat1bppIndexed;
333 break;
334 case 4:
335 format = PixelFormat4bppIndexed;
336 break;
337 case 8:
338 format = PixelFormat8bppIndexed;
339 break;
340 case 24:
341 format = PixelFormat24bppRGB;
342 break;
343 default:
344 FIXME("don't know how to handle %d bpp\n", info->bmiHeader.biBitCount);
345 *bitmap = NULL;
346 return InvalidParameter;
349 return GdipCreateBitmapFromScan0(info->bmiHeader.biWidth, height, stride, format,
350 bits, bitmap);
354 /* FIXME: no icm */
355 GpStatus WINGDIPAPI GdipCreateBitmapFromFileICM(GDIPCONST WCHAR* filename,
356 GpBitmap **bitmap)
358 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
360 return GdipCreateBitmapFromFile(filename, bitmap);
363 GpStatus WINGDIPAPI GdipCreateBitmapFromResource(HINSTANCE hInstance,
364 GDIPCONST WCHAR* lpBitmapName, GpBitmap** bitmap)
366 HBITMAP hbm;
367 GpStatus stat = InvalidParameter;
369 TRACE("%p (%s) %p\n", hInstance, debugstr_w(lpBitmapName), bitmap);
371 if(!lpBitmapName || !bitmap)
372 return InvalidParameter;
374 /* load DIB */
375 hbm = LoadImageW(hInstance, lpBitmapName, IMAGE_BITMAP, 0, 0,
376 LR_CREATEDIBSECTION);
378 if(hbm){
379 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, bitmap);
380 DeleteObject(hbm);
383 return stat;
386 GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
387 HBITMAP* hbmReturn, ARGB background)
389 FIXME("stub\n");
391 hbmReturn = NULL;
393 return NotImplemented;
396 GpStatus WINGDIPAPI GdipConvertToEmfPlus(const GpGraphics* ref,
397 GpMetafile* metafile, BOOL* succ, EmfType emfType,
398 const WCHAR* description, GpMetafile** out_metafile)
400 static int calls;
402 if(!ref || !metafile || !out_metafile)
403 return InvalidParameter;
405 *succ = FALSE;
406 *out_metafile = NULL;
408 if(!(calls++))
409 FIXME("not implemented\n");
411 return NotImplemented;
414 /* FIXME: this should create a bitmap in the given size with the attributes
415 * (resolution etc.) of the graphics object */
416 GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT width, INT height,
417 GpGraphics* target, GpBitmap** bitmap)
419 static int calls;
420 GpStatus ret;
422 if(!target || !bitmap)
423 return InvalidParameter;
425 if(!(calls++))
426 FIXME("hacked stub\n");
428 ret = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat24bppRGB,
429 NULL, bitmap);
431 return ret;
434 GpStatus WINGDIPAPI GdipCreateBitmapFromHICON(HICON hicon, GpBitmap** bitmap)
436 HICON icon_copy;
437 ICONINFO iinfo;
438 PICTDESC desc;
440 TRACE("%p, %p\n", hicon, bitmap);
442 if(!bitmap || !GetIconInfo(hicon, &iinfo))
443 return InvalidParameter;
445 *bitmap = GdipAlloc(sizeof(GpBitmap));
446 if(!*bitmap) return OutOfMemory;
448 icon_copy = CreateIconIndirect(&iinfo);
450 if(!icon_copy){
451 GdipFree(*bitmap);
452 return InvalidParameter;
455 desc.cbSizeofstruct = sizeof(PICTDESC);
456 desc.picType = PICTYPE_ICON;
457 desc.u.icon.hicon = icon_copy;
459 if(OleCreatePictureIndirect(&desc, &IID_IPicture, TRUE,
460 (LPVOID*) &((*bitmap)->image.picture)) != S_OK){
461 DestroyIcon(icon_copy);
462 GdipFree(*bitmap);
463 return GenericError;
466 (*bitmap)->format = PixelFormat32bppARGB;
467 (*bitmap)->image.type = ImageTypeBitmap;
468 (*bitmap)->image.flags = ImageFlagsNone;
469 (*bitmap)->width = ipicture_pixel_width((*bitmap)->image.picture);
470 (*bitmap)->height = ipicture_pixel_height((*bitmap)->image.picture);
472 DeleteObject(iinfo.hbmColor);
473 DeleteObject(iinfo.hbmMask);
475 return Ok;
478 GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
479 PixelFormat format, BYTE* scan0, GpBitmap** bitmap)
481 BITMAPFILEHEADER *bmfh;
482 BITMAPINFOHEADER *bmih;
483 BYTE *buff;
484 INT datalen, size;
485 IStream *stream;
487 TRACE("%d %d %d %d %p %p\n", width, height, stride, format, scan0, bitmap);
489 if (!bitmap) return InvalidParameter;
491 if(width <= 0 || height <= 0 || (scan0 && (stride % 4))){
492 *bitmap = NULL;
493 return InvalidParameter;
496 if(scan0 && !stride)
497 return InvalidParameter;
499 /* FIXME: windows allows negative stride (reads backwards from scan0) */
500 if(stride < 0){
501 FIXME("negative stride\n");
502 return InvalidParameter;
505 *bitmap = GdipAlloc(sizeof(GpBitmap));
506 if(!*bitmap) return OutOfMemory;
508 if(stride == 0){
509 stride = width * (PIXELFORMATBPP(format) / 8);
510 stride = (stride + 3) & ~3;
513 datalen = abs(stride * height);
514 size = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + datalen;
515 buff = GdipAlloc(size);
516 if(!buff){
517 GdipFree(*bitmap);
518 return OutOfMemory;
521 bmfh = (BITMAPFILEHEADER*) buff;
522 bmih = (BITMAPINFOHEADER*) (bmfh + 1);
524 bmfh->bfType = (((WORD)'M') << 8) + (WORD)'B';
525 bmfh->bfSize = size;
526 bmfh->bfOffBits = size - datalen;
528 bmih->biSize = sizeof(BITMAPINFOHEADER);
529 bmih->biWidth = width;
530 bmih->biHeight = -height;
531 /* FIXME: use the rest of the data from format */
532 bmih->biBitCount = PIXELFORMATBPP(format);
533 bmih->biCompression = BI_RGB;
534 bmih->biSizeImage = datalen;
536 if(scan0)
537 memcpy(bmih + 1, scan0, datalen);
538 else
539 memset(bmih + 1, 0, datalen);
541 if(CreateStreamOnHGlobal(buff, TRUE, &stream) != S_OK){
542 ERR("could not make stream\n");
543 GdipFree(*bitmap);
544 GdipFree(buff);
545 return GenericError;
548 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
549 (LPVOID*) &((*bitmap)->image.picture)) != S_OK){
550 TRACE("Could not load picture\n");
551 IStream_Release(stream);
552 GdipFree(*bitmap);
553 GdipFree(buff);
554 return GenericError;
557 (*bitmap)->image.type = ImageTypeBitmap;
558 (*bitmap)->image.flags = ImageFlagsNone;
559 (*bitmap)->width = width;
560 (*bitmap)->height = height;
561 (*bitmap)->format = format;
563 return Ok;
566 GpStatus WINGDIPAPI GdipCreateBitmapFromStream(IStream* stream,
567 GpBitmap **bitmap)
569 GpStatus stat;
571 TRACE("%p %p\n", stream, bitmap);
573 stat = GdipLoadImageFromStream(stream, (GpImage**) bitmap);
575 if(stat != Ok)
576 return stat;
578 if((*bitmap)->image.type != ImageTypeBitmap){
579 IPicture_Release((*bitmap)->image.picture);
580 GdipFree(bitmap);
581 return GenericError; /* FIXME: what error to return? */
584 return Ok;
587 /* FIXME: no icm */
588 GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream* stream,
589 GpBitmap **bitmap)
591 TRACE("%p %p\n", stream, bitmap);
593 return GdipCreateBitmapFromStream(stream, bitmap);
596 GpStatus WINGDIPAPI GdipCreateCachedBitmap(GpBitmap *bitmap, GpGraphics *graphics,
597 GpCachedBitmap **cachedbmp)
599 GpStatus stat;
601 TRACE("%p %p %p\n", bitmap, graphics, cachedbmp);
603 if(!bitmap || !graphics || !cachedbmp)
604 return InvalidParameter;
606 *cachedbmp = GdipAlloc(sizeof(GpCachedBitmap));
607 if(!*cachedbmp)
608 return OutOfMemory;
610 stat = GdipCloneImage(&(bitmap->image), &(*cachedbmp)->image);
611 if(stat != Ok){
612 GdipFree(*cachedbmp);
613 return stat;
616 return Ok;
619 GpStatus WINGDIPAPI GdipDeleteCachedBitmap(GpCachedBitmap *cachedbmp)
621 TRACE("%p\n", cachedbmp);
623 if(!cachedbmp)
624 return InvalidParameter;
626 GdipDisposeImage(cachedbmp->image);
627 GdipFree(cachedbmp);
629 return Ok;
632 GpStatus WINGDIPAPI GdipDrawCachedBitmap(GpGraphics *graphics,
633 GpCachedBitmap *cachedbmp, INT x, INT y)
635 TRACE("%p %p %d %d\n", graphics, cachedbmp, x, y);
637 if(!graphics || !cachedbmp)
638 return InvalidParameter;
640 return GdipDrawImage(graphics, cachedbmp->image, (REAL)x, (REAL)y);
643 GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
645 HDC hdc;
647 TRACE("%p\n", image);
649 if(!image)
650 return InvalidParameter;
652 IPicture_get_CurDC(image->picture, &hdc);
653 DeleteDC(hdc);
654 IPicture_Release(image->picture);
655 if (image->type == ImageTypeBitmap)
656 GdipFree(((GpBitmap*)image)->bitmapbits);
657 GdipFree(image);
659 return Ok;
662 GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage *image, ImageItemData* item)
664 if(!image || !item)
665 return InvalidParameter;
667 return NotImplemented;
670 GpStatus WINGDIPAPI GdipGetImageBounds(GpImage *image, GpRectF *srcRect,
671 GpUnit *srcUnit)
673 TRACE("%p %p %p\n", image, srcRect, srcUnit);
675 if(!image || !srcRect || !srcUnit)
676 return InvalidParameter;
677 if(image->type == ImageTypeMetafile){
678 *srcRect = ((GpMetafile*)image)->bounds;
679 *srcUnit = ((GpMetafile*)image)->unit;
681 else if(image->type == ImageTypeBitmap){
682 srcRect->X = srcRect->Y = 0.0;
683 srcRect->Width = (REAL) ((GpBitmap*)image)->width;
684 srcRect->Height = (REAL) ((GpBitmap*)image)->height;
685 *srcUnit = UnitPixel;
687 else{
688 srcRect->X = srcRect->Y = 0.0;
689 srcRect->Width = ipicture_pixel_width(image->picture);
690 srcRect->Height = ipicture_pixel_height(image->picture);
691 *srcUnit = UnitPixel;
694 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect->X, srcRect->Y,
695 srcRect->Width, srcRect->Height, *srcUnit);
697 return Ok;
700 GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
701 REAL *height)
703 TRACE("%p %p %p\n", image, width, height);
705 if(!image || !height || !width)
706 return InvalidParameter;
708 if(image->type == ImageTypeMetafile){
709 HDC hdc = GetDC(0);
711 *height = convert_unit(hdc, ((GpMetafile*)image)->unit) *
712 ((GpMetafile*)image)->bounds.Height;
714 *width = convert_unit(hdc, ((GpMetafile*)image)->unit) *
715 ((GpMetafile*)image)->bounds.Width;
717 ReleaseDC(0, hdc);
720 else if(image->type == ImageTypeBitmap){
721 *height = ((GpBitmap*)image)->height;
722 *width = ((GpBitmap*)image)->width;
724 else{
725 *height = ipicture_pixel_height(image->picture);
726 *width = ipicture_pixel_width(image->picture);
729 TRACE("returning (%f, %f)\n", *height, *width);
730 return Ok;
733 GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image,
734 GpGraphics **graphics)
736 HDC hdc;
738 TRACE("%p %p\n", image, graphics);
740 if(!image || !graphics)
741 return InvalidParameter;
743 if(image->type != ImageTypeBitmap){
744 FIXME("not implemented for image type %d\n", image->type);
745 return NotImplemented;
748 IPicture_get_CurDC(image->picture, &hdc);
750 if(!hdc){
751 hdc = CreateCompatibleDC(0);
752 IPicture_SelectPicture(image->picture, hdc, NULL, NULL);
755 return GdipCreateFromHDC(hdc, graphics);
758 GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
760 TRACE("%p %p\n", image, height);
762 if(!image || !height)
763 return InvalidParameter;
765 if(image->type == ImageTypeMetafile){
766 HDC hdc = GetDC(0);
768 *height = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
769 ((GpMetafile*)image)->bounds.Height);
771 ReleaseDC(0, hdc);
773 else if(image->type == ImageTypeBitmap)
774 *height = ((GpBitmap*)image)->height;
775 else
776 *height = ipicture_pixel_height(image->picture);
778 TRACE("returning %d\n", *height);
780 return Ok;
783 GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res)
785 static int calls;
787 if(!image || !res)
788 return InvalidParameter;
790 if(!(calls++))
791 FIXME("not implemented\n");
793 return NotImplemented;
796 GpStatus WINGDIPAPI GdipGetImagePaletteSize(GpImage *image, INT *size)
798 FIXME("%p %p\n", image, size);
800 if(!image || !size)
801 return InvalidParameter;
803 return NotImplemented;
806 /* FIXME: test this function for non-bitmap types */
807 GpStatus WINGDIPAPI GdipGetImagePixelFormat(GpImage *image, PixelFormat *format)
809 TRACE("%p %p\n", image, format);
811 if(!image || !format)
812 return InvalidParameter;
814 if(image->type != ImageTypeBitmap)
815 *format = PixelFormat24bppRGB;
816 else
817 *format = ((GpBitmap*) image)->format;
819 return Ok;
822 GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage *image, GUID *format)
824 static int calls;
826 if(!image || !format)
827 return InvalidParameter;
829 if(!(calls++))
830 FIXME("stub\n");
832 /* FIXME: should be detected from embedded picture or stored separately */
833 switch (image->type)
835 case ImageTypeBitmap: *format = ImageFormatBMP; break;
836 case ImageTypeMetafile: *format = ImageFormatEMF; break;
837 default:
838 WARN("unknown type %u\n", image->type);
839 *format = ImageFormatUndefined;
841 return Ok;
844 GpStatus WINGDIPAPI GdipGetImageType(GpImage *image, ImageType *type)
846 TRACE("%p %p\n", image, type);
848 if(!image || !type)
849 return InvalidParameter;
851 *type = image->type;
853 return Ok;
856 GpStatus WINGDIPAPI GdipGetImageVerticalResolution(GpImage *image, REAL *res)
858 static int calls;
860 if(!image || !res)
861 return InvalidParameter;
863 if(!(calls++))
864 FIXME("not implemented\n");
866 return NotImplemented;
869 GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
871 TRACE("%p %p\n", image, width);
873 if(!image || !width)
874 return InvalidParameter;
876 if(image->type == ImageTypeMetafile){
877 HDC hdc = GetDC(0);
879 *width = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
880 ((GpMetafile*)image)->bounds.Width);
882 ReleaseDC(0, hdc);
884 else if(image->type == ImageTypeBitmap)
885 *width = ((GpBitmap*)image)->width;
886 else
887 *width = ipicture_pixel_width(image->picture);
889 TRACE("returning %d\n", *width);
891 return Ok;
894 GpStatus WINGDIPAPI GdipGetMetafileHeaderFromMetafile(GpMetafile * metafile,
895 MetafileHeader * header)
897 static int calls;
899 if(!metafile || !header)
900 return InvalidParameter;
902 if(!(calls++))
903 FIXME("not implemented\n");
905 return Ok;
908 GpStatus WINGDIPAPI GdipGetAllPropertyItems(GpImage *image, UINT size,
909 UINT num, PropertyItem* items)
911 static int calls;
913 if(!(calls++))
914 FIXME("not implemented\n");
916 return InvalidParameter;
919 GpStatus WINGDIPAPI GdipGetPropertyCount(GpImage *image, UINT* num)
921 static int calls;
923 if(!(calls++))
924 FIXME("not implemented\n");
926 return InvalidParameter;
929 GpStatus WINGDIPAPI GdipGetPropertyIdList(GpImage *image, UINT num, PROPID* list)
931 static int calls;
933 if(!(calls++))
934 FIXME("not implemented\n");
936 return InvalidParameter;
939 GpStatus WINGDIPAPI GdipGetPropertyItem(GpImage *image, PROPID id, UINT size,
940 PropertyItem* buffer)
942 static int calls;
944 if(!(calls++))
945 FIXME("not implemented\n");
947 return InvalidParameter;
950 GpStatus WINGDIPAPI GdipGetPropertyItemSize(GpImage *image, PROPID pid,
951 UINT* size)
953 static int calls;
955 TRACE("%p %x %p\n", image, pid, size);
957 if(!size || !image)
958 return InvalidParameter;
960 if(!(calls++))
961 FIXME("not implemented\n");
963 return NotImplemented;
966 GpStatus WINGDIPAPI GdipGetPropertySize(GpImage *image, UINT* size, UINT* num)
968 static int calls;
970 if(!(calls++))
971 FIXME("not implemented\n");
973 return InvalidParameter;
976 GpStatus WINGDIPAPI GdipImageGetFrameCount(GpImage *image,
977 GDIPCONST GUID* dimensionID, UINT* count)
979 static int calls;
981 if(!image || !dimensionID || !count)
982 return InvalidParameter;
984 if(!(calls++))
985 FIXME("not implemented\n");
987 return NotImplemented;
990 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsCount(GpImage *image,
991 UINT* count)
993 if(!image || !count)
994 return InvalidParameter;
996 *count = 1;
998 FIXME("stub\n");
1000 return Ok;
1003 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsList(GpImage* image,
1004 GUID* dimensionIDs, UINT count)
1006 static int calls;
1008 if(!image || !dimensionIDs)
1009 return InvalidParameter;
1011 if(!(calls++))
1012 FIXME("not implemented\n");
1014 return Ok;
1017 GpStatus WINGDIPAPI GdipImageSelectActiveFrame(GpImage *image,
1018 GDIPCONST GUID* dimensionID, UINT frameidx)
1020 static int calls;
1022 if(!image || !dimensionID)
1023 return InvalidParameter;
1025 if(!(calls++))
1026 FIXME("not implemented\n");
1028 return Ok;
1031 GpStatus WINGDIPAPI GdipLoadImageFromFile(GDIPCONST WCHAR* filename,
1032 GpImage **image)
1034 GpStatus stat;
1035 IStream *stream;
1037 TRACE("(%s) %p\n", debugstr_w(filename), image);
1039 if (!filename || !image)
1040 return InvalidParameter;
1042 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
1044 if (stat != Ok)
1045 return stat;
1047 stat = GdipLoadImageFromStream(stream, image);
1049 IStream_Release(stream);
1051 return stat;
1054 /* FIXME: no icm handling */
1055 GpStatus WINGDIPAPI GdipLoadImageFromFileICM(GDIPCONST WCHAR* filename,GpImage **image)
1057 TRACE("(%s) %p\n", debugstr_w(filename), image);
1059 return GdipLoadImageFromFile(filename, image);
1062 GpStatus WINGDIPAPI GdipLoadImageFromStream(IStream* stream, GpImage **image)
1064 IPicture *pic;
1065 short type;
1067 TRACE("%p %p\n", stream, image);
1069 if(!stream || !image)
1070 return InvalidParameter;
1072 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
1073 (LPVOID*) &pic) != S_OK){
1074 TRACE("Could not load picture\n");
1075 return GenericError;
1078 IPicture_get_Type(pic, &type);
1080 if(type == PICTYPE_BITMAP){
1081 BITMAPINFO *pbmi;
1082 BITMAPCOREHEADER* bmch;
1083 HBITMAP hbm;
1084 HDC hdc;
1086 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1087 if (!pbmi)
1088 return OutOfMemory;
1089 *image = GdipAlloc(sizeof(GpBitmap));
1090 if(!*image){
1091 GdipFree(pbmi);
1092 return OutOfMemory;
1094 (*image)->type = ImageTypeBitmap;
1096 (*((GpBitmap**) image))->width = ipicture_pixel_width(pic);
1097 (*((GpBitmap**) image))->height = ipicture_pixel_height(pic);
1099 /* get the pixel format */
1100 IPicture_get_Handle(pic, (OLE_HANDLE*)&hbm);
1101 IPicture_get_CurDC(pic, &hdc);
1103 bmch = (BITMAPCOREHEADER*) (&pbmi->bmiHeader);
1104 bmch->bcSize = sizeof(BITMAPCOREHEADER);
1106 if(!hdc){
1107 HBITMAP old;
1108 hdc = CreateCompatibleDC(0);
1109 old = SelectObject(hdc, hbm);
1110 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
1111 SelectObject(hdc, old);
1112 DeleteDC(hdc);
1114 else
1115 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
1117 switch(bmch->bcBitCount)
1119 case 1:
1120 (*((GpBitmap**) image))->format = PixelFormat1bppIndexed;
1121 break;
1122 case 4:
1123 (*((GpBitmap**) image))->format = PixelFormat4bppIndexed;
1124 break;
1125 case 8:
1126 (*((GpBitmap**) image))->format = PixelFormat8bppIndexed;
1127 break;
1128 case 16:
1129 (*((GpBitmap**) image))->format = PixelFormat16bppRGB565;
1130 break;
1131 case 24:
1132 (*((GpBitmap**) image))->format = PixelFormat24bppRGB;
1133 break;
1134 case 32:
1135 (*((GpBitmap**) image))->format = PixelFormat32bppRGB;
1136 break;
1137 case 48:
1138 (*((GpBitmap**) image))->format = PixelFormat48bppRGB;
1139 break;
1140 default:
1141 FIXME("Bit depth %d is not fully supported yet\n", bmch->bcBitCount);
1142 (*((GpBitmap**) image))->format = (bmch->bcBitCount << 8) | PixelFormatGDI;
1143 break;
1146 GdipFree(pbmi);
1148 else if(type == PICTYPE_METAFILE || type == PICTYPE_ENHMETAFILE){
1149 /* FIXME: missing initialization code */
1150 *image = GdipAlloc(sizeof(GpMetafile));
1151 if(!*image) return OutOfMemory;
1152 (*image)->type = ImageTypeMetafile;
1154 else{
1155 *image = GdipAlloc(sizeof(GpImage));
1156 if(!*image) return OutOfMemory;
1157 (*image)->type = ImageTypeUnknown;
1160 (*image)->picture = pic;
1161 (*image)->flags = ImageFlagsNone;
1163 return Ok;
1166 /* FIXME: no ICM */
1167 GpStatus WINGDIPAPI GdipLoadImageFromStreamICM(IStream* stream, GpImage **image)
1169 TRACE("%p %p\n", stream, image);
1171 return GdipLoadImageFromStream(stream, image);
1174 GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
1176 static int calls;
1178 if(!image)
1179 return InvalidParameter;
1181 if(!(calls++))
1182 FIXME("not implemented\n");
1184 return NotImplemented;
1187 GpStatus WINGDIPAPI GdipSetPropertyItem(GpImage *image, GDIPCONST PropertyItem* item)
1189 static int calls;
1191 if(!(calls++))
1192 FIXME("not implemented\n");
1194 return NotImplemented;
1197 GpStatus WINGDIPAPI GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
1198 GDIPCONST CLSID *clsidEncoder,
1199 GDIPCONST EncoderParameters *encoderParams)
1201 GpStatus stat;
1202 IStream *stream;
1204 TRACE("%p (%s) %p %p\n", image, debugstr_w(filename), clsidEncoder, encoderParams);
1206 if (!image || !filename|| !clsidEncoder)
1207 return InvalidParameter;
1209 if (!(image->picture))
1210 return InvalidParameter;
1212 stat = GdipCreateStreamOnFile(filename, GENERIC_WRITE, &stream);
1213 if (stat != Ok)
1214 return GenericError;
1216 stat = GdipSaveImageToStream(image, stream, clsidEncoder, encoderParams);
1218 IStream_Release(stream);
1219 return stat;
1222 /*************************************************************************
1223 * Encoding functions -
1224 * These functions encode an image in different image file formats.
1226 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
1227 #define BITMAP_FORMAT_JPEG 0xd8ff
1228 #define BITMAP_FORMAT_GIF 0x4947
1229 #define BITMAP_FORMAT_PNG 0x5089
1230 #define BITMAP_FORMAT_APM 0xcdd7
1232 static GpStatus encode_image_BMP(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
1233 void **output, unsigned int *output_size)
1235 int num_palette_entries;
1236 BITMAPFILEHEADER *bmp_file_hdr;
1237 BITMAPINFO *bmp_info_hdr;
1239 if (bitmap_info->bmiHeader.biClrUsed) {
1240 num_palette_entries = bitmap_info->bmiHeader.biClrUsed;
1241 if (num_palette_entries > 256) num_palette_entries = 256;
1242 } else {
1243 if (bitmap_info->bmiHeader.biBitCount <= 8)
1244 num_palette_entries = 1 << bitmap_info->bmiHeader.biBitCount;
1245 else
1246 num_palette_entries = 0;
1249 *output_size =
1250 sizeof(BITMAPFILEHEADER) +
1251 sizeof(BITMAPINFOHEADER) +
1252 num_palette_entries * sizeof(RGBQUAD) +
1253 bitmap_info->bmiHeader.biSizeImage;
1255 *output = GdipAlloc(*output_size);
1257 bmp_file_hdr = *output;
1258 bmp_file_hdr->bfType = BITMAP_FORMAT_BMP;
1259 bmp_file_hdr->bfSize = *output_size;
1260 bmp_file_hdr->bfOffBits =
1261 sizeof(BITMAPFILEHEADER) +
1262 sizeof(BITMAPINFOHEADER) +
1263 num_palette_entries * sizeof (RGBQUAD);
1265 bmp_info_hdr = (BITMAPINFO*) ((unsigned char*)(*output) + sizeof(BITMAPFILEHEADER));
1266 memcpy(bmp_info_hdr, bitmap_info, sizeof(BITMAPINFOHEADER) + num_palette_entries * sizeof(RGBQUAD));
1267 memcpy((unsigned char *)(*output) +
1268 sizeof(BITMAPFILEHEADER) +
1269 sizeof(BITMAPINFOHEADER) +
1270 num_palette_entries * sizeof(RGBQUAD),
1271 bitmap_bits, bitmap_info->bmiHeader.biSizeImage);
1273 return Ok;
1276 typedef GpStatus encode_image_func(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
1277 void **output, unsigned int *output_size);
1279 typedef enum {
1280 BMP,
1281 NUM_ENCODERS_SUPPORTED
1282 } ImageFormat;
1284 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED];
1285 static encode_image_func *const encode_image_funcs[NUM_ENCODERS_SUPPORTED] = {
1286 encode_image_BMP,
1289 /*****************************************************************************
1290 * GdipSaveImageToStream [GDIPLUS.@]
1292 GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
1293 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
1295 GpStatus stat;
1296 HRESULT hr;
1297 short type;
1298 HBITMAP hbmp;
1299 HBITMAP old_hbmp;
1300 HDC hdc;
1301 int bm_is_selected;
1302 BITMAPINFO bmp_info;
1303 LPVOID bmp_bits;
1304 encode_image_func* encode_image;
1305 LPVOID output;
1306 unsigned int output_size;
1307 unsigned int dummy;
1308 int i;
1310 old_hbmp = 0;
1311 output = NULL;
1312 output_size = 0;
1314 TRACE("%p %p %p %p\n", image, stream, clsid, params);
1316 if(!image || !stream)
1317 return InvalidParameter;
1319 if (!image->picture)
1320 return GenericError;
1322 hr = IPicture_get_Type(image->picture, &type);
1323 if (FAILED(hr) || type != PICTYPE_BITMAP)
1324 return GenericError;
1326 /* select correct encoder */
1327 encode_image = NULL;
1328 for (i = 0; i < NUM_ENCODERS_SUPPORTED; i++) {
1329 if (IsEqualCLSID(clsid, &codecs[i].Clsid))
1330 encode_image = encode_image_funcs[i];
1332 if (encode_image == NULL)
1333 return UnknownImageFormat;
1335 /* extract underlying hbitmap representation from the IPicture */
1336 hr = IPicture_get_Handle(image->picture, (OLE_HANDLE*)&hbmp);
1337 if (FAILED(hr) || !hbmp)
1338 return GenericError;
1339 hr = IPicture_get_CurDC(image->picture, &hdc);
1340 if (FAILED(hr))
1341 return GenericError;
1342 bm_is_selected = (hdc != 0);
1343 if (!bm_is_selected) {
1344 hdc = CreateCompatibleDC(0);
1345 old_hbmp = SelectObject(hdc, hbmp);
1348 /* get bits from HBITMAP */
1349 bmp_info.bmiHeader.biSize = sizeof(bmp_info.bmiHeader);
1350 bmp_info.bmiHeader.biBitCount = 0;
1351 GetDIBits(hdc, hbmp, 0, 0, NULL, &bmp_info, DIB_RGB_COLORS);
1353 bmp_bits = GdipAlloc(bmp_info.bmiHeader.biSizeImage);
1355 if (bmp_bits)
1356 GetDIBits(hdc, hbmp, 0, abs(bmp_info.bmiHeader.biHeight), bmp_bits, &bmp_info, DIB_RGB_COLORS);
1358 if (!bm_is_selected) {
1359 SelectObject(hdc, old_hbmp);
1360 DeleteDC(hdc);
1363 if (!bmp_bits)
1364 return OutOfMemory;
1366 stat = encode_image(bmp_bits, &bmp_info, &output, &output_size);
1367 if (stat == Ok)
1368 IStream_Write(stream, output, output_size, &dummy);
1370 GdipFree(output);
1371 GdipFree(bmp_bits);
1373 return stat;
1376 /*****************************************************************************
1377 * GdipSetImagePalette [GDIPLUS.@]
1379 GpStatus WINGDIPAPI GdipSetImagePalette(GpImage *image,
1380 GDIPCONST ColorPalette *palette)
1382 static int calls;
1384 if(!image || !palette)
1385 return InvalidParameter;
1387 if(!(calls++))
1388 FIXME("not implemented\n");
1390 return NotImplemented;
1393 /*************************************************************************
1394 * Encoders -
1395 * Structures that represent which formats we support for encoding.
1398 /* ImageCodecInfo creation routines taken from libgdiplus */
1399 static const WCHAR bmp_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
1400 static const WCHAR bmp_extension[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
1401 static const WCHAR bmp_mimetype[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
1402 static const WCHAR bmp_format[] = {'B', 'M', 'P', 0}; /* BMP */
1403 static const BYTE bmp_sig_pattern[] = { 0x42, 0x4D };
1404 static const BYTE bmp_sig_mask[] = { 0xFF, 0xFF };
1406 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED] =
1408 { /* BMP */
1409 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
1410 /* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
1411 /* CodecName */ bmp_codecname,
1412 /* DllName */ NULL,
1413 /* FormatDescription */ bmp_format,
1414 /* FilenameExtension */ bmp_extension,
1415 /* MimeType */ bmp_mimetype,
1416 /* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
1417 /* Version */ 1,
1418 /* SigCount */ 1,
1419 /* SigSize */ 2,
1420 /* SigPattern */ bmp_sig_pattern,
1421 /* SigMask */ bmp_sig_mask,
1425 /*****************************************************************************
1426 * GdipGetImageDecodersSize [GDIPLUS.@]
1428 GpStatus WINGDIPAPI GdipGetImageDecodersSize(UINT *numDecoders, UINT *size)
1430 FIXME("%p %p stub!\n", numDecoders, size);
1432 if (!numDecoders || !size)
1433 return InvalidParameter;
1435 *numDecoders = 0;
1436 *size = 0;
1438 return Ok;
1441 /*****************************************************************************
1442 * GdipGetImageDecoders [GDIPLUS.@]
1444 GpStatus WINGDIPAPI GdipGetImageDecoders(UINT numDecoders, UINT size, ImageCodecInfo *decoders)
1446 FIXME("%u %u %p stub!\n", numDecoders, size, decoders);
1448 if (!decoders)
1449 return GenericError;
1451 return NotImplemented;
1454 /*****************************************************************************
1455 * GdipGetImageEncodersSize [GDIPLUS.@]
1457 GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size)
1459 TRACE("%p %p\n", numEncoders, size);
1461 if (!numEncoders || !size)
1462 return InvalidParameter;
1464 *numEncoders = NUM_ENCODERS_SUPPORTED;
1465 *size = sizeof (codecs);
1467 return Ok;
1470 /*****************************************************************************
1471 * GdipGetImageEncoders [GDIPLUS.@]
1473 GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders)
1475 TRACE("%u %u %p\n", numEncoders, size, encoders);
1477 if (!encoders ||
1478 (numEncoders != NUM_ENCODERS_SUPPORTED) ||
1479 (size != sizeof (codecs)))
1480 return GenericError;
1482 memcpy(encoders, codecs, sizeof (codecs));
1484 return Ok;
1487 /*****************************************************************************
1488 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
1490 GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBitmap** bitmap)
1492 BITMAP bm;
1493 GpStatus retval;
1494 PixelFormat format;
1496 TRACE("%p %p %p\n", hbm, hpal, bitmap);
1498 if(!hbm || !bitmap)
1499 return InvalidParameter;
1501 /* TODO: Support for device-dependent bitmaps */
1502 if(hpal){
1503 FIXME("no support for device-dependent bitmaps\n");
1504 return NotImplemented;
1507 if (GetObjectA(hbm, sizeof(bm), &bm) != sizeof(bm))
1508 return InvalidParameter;
1510 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
1511 switch(bm.bmBitsPixel) {
1512 case 1:
1513 format = PixelFormat1bppIndexed;
1514 break;
1515 case 4:
1516 format = PixelFormat4bppIndexed;
1517 break;
1518 case 8:
1519 format = PixelFormat8bppIndexed;
1520 break;
1521 case 24:
1522 format = PixelFormat24bppRGB;
1523 break;
1524 case 32:
1525 format = PixelFormat32bppRGB;
1526 break;
1527 case 48:
1528 format = PixelFormat48bppRGB;
1529 break;
1530 default:
1531 FIXME("don't know how to handle %d bpp\n", bm.bmBitsPixel);
1532 return InvalidParameter;
1535 retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, bm.bmWidthBytes,
1536 format, bm.bmBits, bitmap);
1538 return retval;
1541 /*****************************************************************************
1542 * GdipSetEffectParameters [GDIPLUS.@]
1544 GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect *effect,
1545 const VOID *params, const UINT size)
1547 static int calls;
1549 if(!(calls++))
1550 FIXME("not implemented\n");
1552 return NotImplemented;
1555 /*****************************************************************************
1556 * GdipGetImageFlags [GDIPLUS.@]
1558 GpStatus WINGDIPAPI GdipGetImageFlags(GpImage *image, UINT *flags)
1560 TRACE("%p %p\n", image, flags);
1562 if(!image || !flags)
1563 return InvalidParameter;
1565 *flags = image->flags;
1567 return Ok;
1570 GpStatus WINGDIPAPI GdipTestControl(GpTestControlEnum control, void *param)
1572 TRACE("(%d, %p)\n", control, param);
1574 switch(control){
1575 case TestControlForceBilinear:
1576 if(param)
1577 FIXME("TestControlForceBilinear not handled\n");
1578 break;
1579 case TestControlNoICM:
1580 if(param)
1581 FIXME("TestControlNoICM not handled\n");
1582 break;
1583 case TestControlGetBuildNumber:
1584 *((DWORD*)param) = 3102;
1585 break;
1588 return Ok;
1591 GpStatus WINGDIPAPI GdipRecordMetafileFileName(GDIPCONST WCHAR* fileName,
1592 HDC hdc, EmfType type, GDIPCONST GpRectF *pFrameRect,
1593 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc,
1594 GpMetafile **metafile)
1596 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
1597 frameUnit, debugstr_w(desc), metafile);
1599 return NotImplemented;
1602 GpStatus WINGDIPAPI GdipRecordMetafileFileNameI(GDIPCONST WCHAR* fileName, HDC hdc, EmfType type,
1603 GDIPCONST GpRect *pFrameRect, MetafileFrameUnit frameUnit,
1604 GDIPCONST WCHAR *desc, GpMetafile **metafile)
1606 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
1607 frameUnit, debugstr_w(desc), metafile);
1609 return NotImplemented;
1612 GpStatus WINGDIPAPI GdipImageForceValidation(GpImage *image)
1614 FIXME("%p\n", image);
1616 return Ok;