push f10498d6475569c88c33f00dcf9f5eb9a10319d3
[wine/hacks.git] / dlls / gdiplus / image.c
blob8a4dcc2738902b362fd4a0cda147caa3d6e60477
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 GdipCloneBitmapAreaI(INT x, INT y, INT width, INT height,
253 PixelFormat format, GpBitmap* srcBitmap, GpBitmap** dstBitmap)
255 FIXME("(%i,%i,%i,%i,%i,%p,%p)\n", x, y, width, height, format, srcBitmap, dstBitmap);
257 return NotImplemented;
260 GpStatus WINGDIPAPI GdipCloneImage(GpImage *image, GpImage **cloneImage)
262 IStream* stream;
263 HRESULT hr;
264 INT size;
265 LARGE_INTEGER move;
266 GpStatus stat = GenericError;
268 TRACE("%p, %p\n", image, cloneImage);
270 if (!image || !cloneImage)
271 return InvalidParameter;
273 hr = CreateStreamOnHGlobal(0, TRUE, &stream);
274 if (FAILED(hr))
275 return GenericError;
277 hr = IPicture_SaveAsFile(image->picture, stream, FALSE, &size);
278 if(FAILED(hr))
280 WARN("Failed to save image on stream\n");
281 goto out;
284 /* Set seek pointer back to the beginning of the picture */
285 move.QuadPart = 0;
286 hr = IStream_Seek(stream, move, STREAM_SEEK_SET, NULL);
287 if (FAILED(hr))
288 goto out;
290 stat = GdipLoadImageFromStream(stream, cloneImage);
291 if (stat != Ok) WARN("Failed to load image from stream\n");
293 out:
294 IStream_Release(stream);
295 return stat;
298 GpStatus WINGDIPAPI GdipCreateBitmapFromFile(GDIPCONST WCHAR* filename,
299 GpBitmap **bitmap)
301 GpStatus stat;
302 IStream *stream;
304 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
306 if(!filename || !bitmap)
307 return InvalidParameter;
309 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
311 if(stat != Ok)
312 return stat;
314 stat = GdipCreateBitmapFromStream(stream, bitmap);
316 IStream_Release(stream);
318 return stat;
321 GpStatus WINGDIPAPI GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO* info,
322 VOID *bits, GpBitmap **bitmap)
324 DWORD height, stride;
325 PixelFormat format;
327 FIXME("(%p, %p, %p) - partially implemented\n", info, bits, bitmap);
329 height = abs(info->bmiHeader.biHeight);
330 stride = ((info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) >> 3) & ~3;
332 if(info->bmiHeader.biHeight > 0) /* bottom-up */
334 bits = (BYTE*)bits + (height - 1) * stride;
335 stride = -stride;
338 switch(info->bmiHeader.biBitCount) {
339 case 1:
340 format = PixelFormat1bppIndexed;
341 break;
342 case 4:
343 format = PixelFormat4bppIndexed;
344 break;
345 case 8:
346 format = PixelFormat8bppIndexed;
347 break;
348 case 24:
349 format = PixelFormat24bppRGB;
350 break;
351 default:
352 FIXME("don't know how to handle %d bpp\n", info->bmiHeader.biBitCount);
353 *bitmap = NULL;
354 return InvalidParameter;
357 return GdipCreateBitmapFromScan0(info->bmiHeader.biWidth, height, stride, format,
358 bits, bitmap);
362 /* FIXME: no icm */
363 GpStatus WINGDIPAPI GdipCreateBitmapFromFileICM(GDIPCONST WCHAR* filename,
364 GpBitmap **bitmap)
366 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
368 return GdipCreateBitmapFromFile(filename, bitmap);
371 GpStatus WINGDIPAPI GdipCreateBitmapFromResource(HINSTANCE hInstance,
372 GDIPCONST WCHAR* lpBitmapName, GpBitmap** bitmap)
374 HBITMAP hbm;
375 GpStatus stat = InvalidParameter;
377 TRACE("%p (%s) %p\n", hInstance, debugstr_w(lpBitmapName), bitmap);
379 if(!lpBitmapName || !bitmap)
380 return InvalidParameter;
382 /* load DIB */
383 hbm = LoadImageW(hInstance, lpBitmapName, IMAGE_BITMAP, 0, 0,
384 LR_CREATEDIBSECTION);
386 if(hbm){
387 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, bitmap);
388 DeleteObject(hbm);
391 return stat;
394 GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
395 HBITMAP* hbmReturn, ARGB background)
397 FIXME("stub\n");
399 hbmReturn = NULL;
401 return NotImplemented;
404 GpStatus WINGDIPAPI GdipConvertToEmfPlus(const GpGraphics* ref,
405 GpMetafile* metafile, BOOL* succ, EmfType emfType,
406 const WCHAR* description, GpMetafile** out_metafile)
408 static int calls;
410 if(!ref || !metafile || !out_metafile)
411 return InvalidParameter;
413 *succ = FALSE;
414 *out_metafile = NULL;
416 if(!(calls++))
417 FIXME("not implemented\n");
419 return NotImplemented;
422 /* FIXME: this should create a bitmap in the given size with the attributes
423 * (resolution etc.) of the graphics object */
424 GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT width, INT height,
425 GpGraphics* target, GpBitmap** bitmap)
427 static int calls;
428 GpStatus ret;
430 if(!target || !bitmap)
431 return InvalidParameter;
433 if(!(calls++))
434 FIXME("hacked stub\n");
436 ret = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat24bppRGB,
437 NULL, bitmap);
439 return ret;
442 GpStatus WINGDIPAPI GdipCreateBitmapFromHICON(HICON hicon, GpBitmap** bitmap)
444 HICON icon_copy;
445 ICONINFO iinfo;
446 PICTDESC desc;
448 TRACE("%p, %p\n", hicon, bitmap);
450 if(!bitmap || !GetIconInfo(hicon, &iinfo))
451 return InvalidParameter;
453 *bitmap = GdipAlloc(sizeof(GpBitmap));
454 if(!*bitmap) return OutOfMemory;
456 icon_copy = CreateIconIndirect(&iinfo);
458 if(!icon_copy){
459 GdipFree(*bitmap);
460 return InvalidParameter;
463 desc.cbSizeofstruct = sizeof(PICTDESC);
464 desc.picType = PICTYPE_ICON;
465 desc.u.icon.hicon = icon_copy;
467 if(OleCreatePictureIndirect(&desc, &IID_IPicture, TRUE,
468 (LPVOID*) &((*bitmap)->image.picture)) != S_OK){
469 DestroyIcon(icon_copy);
470 GdipFree(*bitmap);
471 return GenericError;
474 (*bitmap)->format = PixelFormat32bppARGB;
475 (*bitmap)->image.type = ImageTypeBitmap;
476 (*bitmap)->image.flags = ImageFlagsNone;
477 (*bitmap)->width = ipicture_pixel_width((*bitmap)->image.picture);
478 (*bitmap)->height = ipicture_pixel_height((*bitmap)->image.picture);
480 DeleteObject(iinfo.hbmColor);
481 DeleteObject(iinfo.hbmMask);
483 return Ok;
486 GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
487 PixelFormat format, BYTE* scan0, GpBitmap** bitmap)
489 BITMAPFILEHEADER *bmfh;
490 BITMAPINFOHEADER *bmih;
491 BYTE *buff;
492 INT datalen, size;
493 IStream *stream;
495 TRACE("%d %d %d %d %p %p\n", width, height, stride, format, scan0, bitmap);
497 if (!bitmap) return InvalidParameter;
499 if(width <= 0 || height <= 0 || (scan0 && (stride % 4))){
500 *bitmap = NULL;
501 return InvalidParameter;
504 if(scan0 && !stride)
505 return InvalidParameter;
507 *bitmap = GdipAlloc(sizeof(GpBitmap));
508 if(!*bitmap) return OutOfMemory;
510 if(stride == 0){
511 stride = width * (PIXELFORMATBPP(format) / 8);
512 stride = (stride + 3) & ~3;
515 datalen = abs(stride * height);
516 size = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + datalen;
517 buff = GdipAlloc(size);
518 if(!buff){
519 GdipFree(*bitmap);
520 return OutOfMemory;
523 bmfh = (BITMAPFILEHEADER*) buff;
524 bmih = (BITMAPINFOHEADER*) (bmfh + 1);
526 bmfh->bfType = (((WORD)'M') << 8) + (WORD)'B';
527 bmfh->bfSize = size;
528 bmfh->bfOffBits = size - datalen;
530 bmih->biSize = sizeof(BITMAPINFOHEADER);
531 bmih->biWidth = width;
532 /* FIXME: use the rest of the data from format */
533 bmih->biBitCount = PIXELFORMATBPP(format);
534 bmih->biCompression = BI_RGB;
535 bmih->biSizeImage = datalen;
537 if (scan0)
539 if (stride > 0)
541 bmih->biHeight = -height;
542 memcpy(bmih + 1, scan0, datalen);
544 else
546 bmih->biHeight = height;
547 memcpy(bmih + 1, scan0 + stride * (height - 1), datalen);
550 else
552 bmih->biHeight = height;
553 memset(bmih + 1, 0, datalen);
556 if(CreateStreamOnHGlobal(buff, TRUE, &stream) != S_OK){
557 ERR("could not make stream\n");
558 GdipFree(*bitmap);
559 GdipFree(buff);
560 *bitmap = NULL;
561 return GenericError;
564 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
565 (LPVOID*) &((*bitmap)->image.picture)) != S_OK){
566 TRACE("Could not load picture\n");
567 IStream_Release(stream);
568 GdipFree(*bitmap);
569 GdipFree(buff);
570 *bitmap = NULL;
571 return GenericError;
574 (*bitmap)->image.type = ImageTypeBitmap;
575 (*bitmap)->image.flags = ImageFlagsNone;
576 (*bitmap)->width = width;
577 (*bitmap)->height = height;
578 (*bitmap)->format = format;
580 return Ok;
583 GpStatus WINGDIPAPI GdipCreateBitmapFromStream(IStream* stream,
584 GpBitmap **bitmap)
586 GpStatus stat;
588 TRACE("%p %p\n", stream, bitmap);
590 stat = GdipLoadImageFromStream(stream, (GpImage**) bitmap);
592 if(stat != Ok)
593 return stat;
595 if((*bitmap)->image.type != ImageTypeBitmap){
596 IPicture_Release((*bitmap)->image.picture);
597 GdipFree(bitmap);
598 return GenericError; /* FIXME: what error to return? */
601 return Ok;
604 /* FIXME: no icm */
605 GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream* stream,
606 GpBitmap **bitmap)
608 TRACE("%p %p\n", stream, bitmap);
610 return GdipCreateBitmapFromStream(stream, bitmap);
613 GpStatus WINGDIPAPI GdipCreateCachedBitmap(GpBitmap *bitmap, GpGraphics *graphics,
614 GpCachedBitmap **cachedbmp)
616 GpStatus stat;
618 TRACE("%p %p %p\n", bitmap, graphics, cachedbmp);
620 if(!bitmap || !graphics || !cachedbmp)
621 return InvalidParameter;
623 *cachedbmp = GdipAlloc(sizeof(GpCachedBitmap));
624 if(!*cachedbmp)
625 return OutOfMemory;
627 stat = GdipCloneImage(&(bitmap->image), &(*cachedbmp)->image);
628 if(stat != Ok){
629 GdipFree(*cachedbmp);
630 return stat;
633 return Ok;
636 GpStatus WINGDIPAPI GdipDeleteCachedBitmap(GpCachedBitmap *cachedbmp)
638 TRACE("%p\n", cachedbmp);
640 if(!cachedbmp)
641 return InvalidParameter;
643 GdipDisposeImage(cachedbmp->image);
644 GdipFree(cachedbmp);
646 return Ok;
649 GpStatus WINGDIPAPI GdipDrawCachedBitmap(GpGraphics *graphics,
650 GpCachedBitmap *cachedbmp, INT x, INT y)
652 TRACE("%p %p %d %d\n", graphics, cachedbmp, x, y);
654 if(!graphics || !cachedbmp)
655 return InvalidParameter;
657 return GdipDrawImage(graphics, cachedbmp->image, (REAL)x, (REAL)y);
660 GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
662 HDC hdc;
664 TRACE("%p\n", image);
666 if(!image)
667 return InvalidParameter;
669 IPicture_get_CurDC(image->picture, &hdc);
670 DeleteDC(hdc);
671 IPicture_Release(image->picture);
672 if (image->type == ImageTypeBitmap)
673 GdipFree(((GpBitmap*)image)->bitmapbits);
674 GdipFree(image);
676 return Ok;
679 GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage *image, ImageItemData* item)
681 if(!image || !item)
682 return InvalidParameter;
684 return NotImplemented;
687 GpStatus WINGDIPAPI GdipGetImageBounds(GpImage *image, GpRectF *srcRect,
688 GpUnit *srcUnit)
690 TRACE("%p %p %p\n", image, srcRect, srcUnit);
692 if(!image || !srcRect || !srcUnit)
693 return InvalidParameter;
694 if(image->type == ImageTypeMetafile){
695 *srcRect = ((GpMetafile*)image)->bounds;
696 *srcUnit = ((GpMetafile*)image)->unit;
698 else if(image->type == ImageTypeBitmap){
699 srcRect->X = srcRect->Y = 0.0;
700 srcRect->Width = (REAL) ((GpBitmap*)image)->width;
701 srcRect->Height = (REAL) ((GpBitmap*)image)->height;
702 *srcUnit = UnitPixel;
704 else{
705 srcRect->X = srcRect->Y = 0.0;
706 srcRect->Width = ipicture_pixel_width(image->picture);
707 srcRect->Height = ipicture_pixel_height(image->picture);
708 *srcUnit = UnitPixel;
711 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect->X, srcRect->Y,
712 srcRect->Width, srcRect->Height, *srcUnit);
714 return Ok;
717 GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
718 REAL *height)
720 TRACE("%p %p %p\n", image, width, height);
722 if(!image || !height || !width)
723 return InvalidParameter;
725 if(image->type == ImageTypeMetafile){
726 HDC hdc = GetDC(0);
728 *height = convert_unit(hdc, ((GpMetafile*)image)->unit) *
729 ((GpMetafile*)image)->bounds.Height;
731 *width = convert_unit(hdc, ((GpMetafile*)image)->unit) *
732 ((GpMetafile*)image)->bounds.Width;
734 ReleaseDC(0, hdc);
737 else if(image->type == ImageTypeBitmap){
738 *height = ((GpBitmap*)image)->height;
739 *width = ((GpBitmap*)image)->width;
741 else{
742 *height = ipicture_pixel_height(image->picture);
743 *width = ipicture_pixel_width(image->picture);
746 TRACE("returning (%f, %f)\n", *height, *width);
747 return Ok;
750 GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image,
751 GpGraphics **graphics)
753 HDC hdc;
755 TRACE("%p %p\n", image, graphics);
757 if(!image || !graphics)
758 return InvalidParameter;
760 if(image->type != ImageTypeBitmap){
761 FIXME("not implemented for image type %d\n", image->type);
762 return NotImplemented;
765 IPicture_get_CurDC(image->picture, &hdc);
767 if(!hdc){
768 hdc = CreateCompatibleDC(0);
769 IPicture_SelectPicture(image->picture, hdc, NULL, NULL);
772 return GdipCreateFromHDC(hdc, graphics);
775 GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
777 TRACE("%p %p\n", image, height);
779 if(!image || !height)
780 return InvalidParameter;
782 if(image->type == ImageTypeMetafile){
783 HDC hdc = GetDC(0);
785 *height = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
786 ((GpMetafile*)image)->bounds.Height);
788 ReleaseDC(0, hdc);
790 else if(image->type == ImageTypeBitmap)
791 *height = ((GpBitmap*)image)->height;
792 else
793 *height = ipicture_pixel_height(image->picture);
795 TRACE("returning %d\n", *height);
797 return Ok;
800 GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res)
802 static int calls;
804 if(!image || !res)
805 return InvalidParameter;
807 if(!(calls++))
808 FIXME("not implemented\n");
810 return NotImplemented;
813 GpStatus WINGDIPAPI GdipGetImagePaletteSize(GpImage *image, INT *size)
815 FIXME("%p %p\n", image, size);
817 if(!image || !size)
818 return InvalidParameter;
820 return NotImplemented;
823 /* FIXME: test this function for non-bitmap types */
824 GpStatus WINGDIPAPI GdipGetImagePixelFormat(GpImage *image, PixelFormat *format)
826 TRACE("%p %p\n", image, format);
828 if(!image || !format)
829 return InvalidParameter;
831 if(image->type != ImageTypeBitmap)
832 *format = PixelFormat24bppRGB;
833 else
834 *format = ((GpBitmap*) image)->format;
836 return Ok;
839 GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage *image, GUID *format)
841 static int calls;
843 if(!image || !format)
844 return InvalidParameter;
846 if(!(calls++))
847 FIXME("stub\n");
849 /* FIXME: should be detected from embedded picture or stored separately */
850 switch (image->type)
852 case ImageTypeBitmap: *format = ImageFormatBMP; break;
853 case ImageTypeMetafile: *format = ImageFormatEMF; break;
854 default:
855 WARN("unknown type %u\n", image->type);
856 *format = ImageFormatUndefined;
858 return Ok;
861 GpStatus WINGDIPAPI GdipGetImageType(GpImage *image, ImageType *type)
863 TRACE("%p %p\n", image, type);
865 if(!image || !type)
866 return InvalidParameter;
868 *type = image->type;
870 return Ok;
873 GpStatus WINGDIPAPI GdipGetImageVerticalResolution(GpImage *image, REAL *res)
875 static int calls;
877 if(!image || !res)
878 return InvalidParameter;
880 if(!(calls++))
881 FIXME("not implemented\n");
883 return NotImplemented;
886 GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
888 TRACE("%p %p\n", image, width);
890 if(!image || !width)
891 return InvalidParameter;
893 if(image->type == ImageTypeMetafile){
894 HDC hdc = GetDC(0);
896 *width = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
897 ((GpMetafile*)image)->bounds.Width);
899 ReleaseDC(0, hdc);
901 else if(image->type == ImageTypeBitmap)
902 *width = ((GpBitmap*)image)->width;
903 else
904 *width = ipicture_pixel_width(image->picture);
906 TRACE("returning %d\n", *width);
908 return Ok;
911 GpStatus WINGDIPAPI GdipGetMetafileHeaderFromMetafile(GpMetafile * metafile,
912 MetafileHeader * header)
914 static int calls;
916 if(!metafile || !header)
917 return InvalidParameter;
919 if(!(calls++))
920 FIXME("not implemented\n");
922 return Ok;
925 GpStatus WINGDIPAPI GdipGetAllPropertyItems(GpImage *image, UINT size,
926 UINT num, PropertyItem* items)
928 static int calls;
930 if(!(calls++))
931 FIXME("not implemented\n");
933 return InvalidParameter;
936 GpStatus WINGDIPAPI GdipGetPropertyCount(GpImage *image, UINT* num)
938 static int calls;
940 if(!(calls++))
941 FIXME("not implemented\n");
943 return InvalidParameter;
946 GpStatus WINGDIPAPI GdipGetPropertyIdList(GpImage *image, UINT num, PROPID* list)
948 static int calls;
950 if(!(calls++))
951 FIXME("not implemented\n");
953 return InvalidParameter;
956 GpStatus WINGDIPAPI GdipGetPropertyItem(GpImage *image, PROPID id, UINT size,
957 PropertyItem* buffer)
959 static int calls;
961 if(!(calls++))
962 FIXME("not implemented\n");
964 return InvalidParameter;
967 GpStatus WINGDIPAPI GdipGetPropertyItemSize(GpImage *image, PROPID pid,
968 UINT* size)
970 static int calls;
972 TRACE("%p %x %p\n", image, pid, size);
974 if(!size || !image)
975 return InvalidParameter;
977 if(!(calls++))
978 FIXME("not implemented\n");
980 return NotImplemented;
983 GpStatus WINGDIPAPI GdipGetPropertySize(GpImage *image, UINT* size, UINT* num)
985 static int calls;
987 if(!(calls++))
988 FIXME("not implemented\n");
990 return InvalidParameter;
993 GpStatus WINGDIPAPI GdipImageGetFrameCount(GpImage *image,
994 GDIPCONST GUID* dimensionID, UINT* count)
996 static int calls;
998 if(!image || !dimensionID || !count)
999 return InvalidParameter;
1001 if(!(calls++))
1002 FIXME("not implemented\n");
1004 return NotImplemented;
1007 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsCount(GpImage *image,
1008 UINT* count)
1010 if(!image || !count)
1011 return InvalidParameter;
1013 *count = 1;
1015 FIXME("stub\n");
1017 return Ok;
1020 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsList(GpImage* image,
1021 GUID* dimensionIDs, UINT count)
1023 static int calls;
1025 if(!image || !dimensionIDs)
1026 return InvalidParameter;
1028 if(!(calls++))
1029 FIXME("not implemented\n");
1031 return Ok;
1034 GpStatus WINGDIPAPI GdipImageSelectActiveFrame(GpImage *image,
1035 GDIPCONST GUID* dimensionID, UINT frameidx)
1037 static int calls;
1039 if(!image || !dimensionID)
1040 return InvalidParameter;
1042 if(!(calls++))
1043 FIXME("not implemented\n");
1045 return Ok;
1048 GpStatus WINGDIPAPI GdipLoadImageFromFile(GDIPCONST WCHAR* filename,
1049 GpImage **image)
1051 GpStatus stat;
1052 IStream *stream;
1054 TRACE("(%s) %p\n", debugstr_w(filename), image);
1056 if (!filename || !image)
1057 return InvalidParameter;
1059 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
1061 if (stat != Ok)
1062 return stat;
1064 stat = GdipLoadImageFromStream(stream, image);
1066 IStream_Release(stream);
1068 return stat;
1071 /* FIXME: no icm handling */
1072 GpStatus WINGDIPAPI GdipLoadImageFromFileICM(GDIPCONST WCHAR* filename,GpImage **image)
1074 TRACE("(%s) %p\n", debugstr_w(filename), image);
1076 return GdipLoadImageFromFile(filename, image);
1079 GpStatus WINGDIPAPI GdipLoadImageFromStream(IStream* stream, GpImage **image)
1081 IPicture *pic;
1082 short type;
1084 TRACE("%p %p\n", stream, image);
1086 if(!stream || !image)
1087 return InvalidParameter;
1089 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
1090 (LPVOID*) &pic) != S_OK){
1091 TRACE("Could not load picture\n");
1092 return GenericError;
1095 IPicture_get_Type(pic, &type);
1097 if(type == PICTYPE_BITMAP){
1098 BITMAPINFO *pbmi;
1099 BITMAPCOREHEADER* bmch;
1100 HBITMAP hbm;
1101 HDC hdc;
1103 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1104 if (!pbmi)
1105 return OutOfMemory;
1106 *image = GdipAlloc(sizeof(GpBitmap));
1107 if(!*image){
1108 GdipFree(pbmi);
1109 return OutOfMemory;
1111 (*image)->type = ImageTypeBitmap;
1113 (*((GpBitmap**) image))->width = ipicture_pixel_width(pic);
1114 (*((GpBitmap**) image))->height = ipicture_pixel_height(pic);
1116 /* get the pixel format */
1117 IPicture_get_Handle(pic, (OLE_HANDLE*)&hbm);
1118 IPicture_get_CurDC(pic, &hdc);
1120 bmch = (BITMAPCOREHEADER*) (&pbmi->bmiHeader);
1121 bmch->bcSize = sizeof(BITMAPCOREHEADER);
1123 if(!hdc){
1124 HBITMAP old;
1125 hdc = CreateCompatibleDC(0);
1126 old = SelectObject(hdc, hbm);
1127 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
1128 SelectObject(hdc, old);
1129 DeleteDC(hdc);
1131 else
1132 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
1134 switch(bmch->bcBitCount)
1136 case 1:
1137 (*((GpBitmap**) image))->format = PixelFormat1bppIndexed;
1138 break;
1139 case 4:
1140 (*((GpBitmap**) image))->format = PixelFormat4bppIndexed;
1141 break;
1142 case 8:
1143 (*((GpBitmap**) image))->format = PixelFormat8bppIndexed;
1144 break;
1145 case 16:
1146 (*((GpBitmap**) image))->format = PixelFormat16bppRGB565;
1147 break;
1148 case 24:
1149 (*((GpBitmap**) image))->format = PixelFormat24bppRGB;
1150 break;
1151 case 32:
1152 (*((GpBitmap**) image))->format = PixelFormat32bppRGB;
1153 break;
1154 case 48:
1155 (*((GpBitmap**) image))->format = PixelFormat48bppRGB;
1156 break;
1157 default:
1158 FIXME("Bit depth %d is not fully supported yet\n", bmch->bcBitCount);
1159 (*((GpBitmap**) image))->format = (bmch->bcBitCount << 8) | PixelFormatGDI;
1160 break;
1163 GdipFree(pbmi);
1165 else if(type == PICTYPE_METAFILE || type == PICTYPE_ENHMETAFILE){
1166 /* FIXME: missing initialization code */
1167 *image = GdipAlloc(sizeof(GpMetafile));
1168 if(!*image) return OutOfMemory;
1169 (*image)->type = ImageTypeMetafile;
1171 else{
1172 *image = GdipAlloc(sizeof(GpImage));
1173 if(!*image) return OutOfMemory;
1174 (*image)->type = ImageTypeUnknown;
1177 (*image)->picture = pic;
1178 (*image)->flags = ImageFlagsNone;
1180 return Ok;
1183 /* FIXME: no ICM */
1184 GpStatus WINGDIPAPI GdipLoadImageFromStreamICM(IStream* stream, GpImage **image)
1186 TRACE("%p %p\n", stream, image);
1188 return GdipLoadImageFromStream(stream, image);
1191 GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
1193 static int calls;
1195 if(!image)
1196 return InvalidParameter;
1198 if(!(calls++))
1199 FIXME("not implemented\n");
1201 return NotImplemented;
1204 GpStatus WINGDIPAPI GdipSetPropertyItem(GpImage *image, GDIPCONST PropertyItem* item)
1206 static int calls;
1208 if(!(calls++))
1209 FIXME("not implemented\n");
1211 return NotImplemented;
1214 GpStatus WINGDIPAPI GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
1215 GDIPCONST CLSID *clsidEncoder,
1216 GDIPCONST EncoderParameters *encoderParams)
1218 GpStatus stat;
1219 IStream *stream;
1221 TRACE("%p (%s) %p %p\n", image, debugstr_w(filename), clsidEncoder, encoderParams);
1223 if (!image || !filename|| !clsidEncoder)
1224 return InvalidParameter;
1226 if (!(image->picture))
1227 return InvalidParameter;
1229 stat = GdipCreateStreamOnFile(filename, GENERIC_WRITE, &stream);
1230 if (stat != Ok)
1231 return GenericError;
1233 stat = GdipSaveImageToStream(image, stream, clsidEncoder, encoderParams);
1235 IStream_Release(stream);
1236 return stat;
1239 /*************************************************************************
1240 * Encoding functions -
1241 * These functions encode an image in different image file formats.
1243 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
1244 #define BITMAP_FORMAT_JPEG 0xd8ff
1245 #define BITMAP_FORMAT_GIF 0x4947
1246 #define BITMAP_FORMAT_PNG 0x5089
1247 #define BITMAP_FORMAT_APM 0xcdd7
1249 static GpStatus encode_image_BMP(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
1250 void **output, unsigned int *output_size)
1252 int num_palette_entries;
1253 BITMAPFILEHEADER *bmp_file_hdr;
1254 BITMAPINFO *bmp_info_hdr;
1256 if (bitmap_info->bmiHeader.biClrUsed) {
1257 num_palette_entries = bitmap_info->bmiHeader.biClrUsed;
1258 if (num_palette_entries > 256) num_palette_entries = 256;
1259 } else {
1260 if (bitmap_info->bmiHeader.biBitCount <= 8)
1261 num_palette_entries = 1 << bitmap_info->bmiHeader.biBitCount;
1262 else
1263 num_palette_entries = 0;
1266 *output_size =
1267 sizeof(BITMAPFILEHEADER) +
1268 sizeof(BITMAPINFOHEADER) +
1269 num_palette_entries * sizeof(RGBQUAD) +
1270 bitmap_info->bmiHeader.biSizeImage;
1272 *output = GdipAlloc(*output_size);
1274 bmp_file_hdr = *output;
1275 bmp_file_hdr->bfType = BITMAP_FORMAT_BMP;
1276 bmp_file_hdr->bfSize = *output_size;
1277 bmp_file_hdr->bfOffBits =
1278 sizeof(BITMAPFILEHEADER) +
1279 sizeof(BITMAPINFOHEADER) +
1280 num_palette_entries * sizeof (RGBQUAD);
1282 bmp_info_hdr = (BITMAPINFO*) ((unsigned char*)(*output) + sizeof(BITMAPFILEHEADER));
1283 memcpy(bmp_info_hdr, bitmap_info, sizeof(BITMAPINFOHEADER) + num_palette_entries * sizeof(RGBQUAD));
1284 memcpy((unsigned char *)(*output) +
1285 sizeof(BITMAPFILEHEADER) +
1286 sizeof(BITMAPINFOHEADER) +
1287 num_palette_entries * sizeof(RGBQUAD),
1288 bitmap_bits, bitmap_info->bmiHeader.biSizeImage);
1290 return Ok;
1293 typedef GpStatus encode_image_func(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
1294 void **output, unsigned int *output_size);
1296 typedef enum {
1297 BMP,
1298 NUM_ENCODERS_SUPPORTED
1299 } ImageFormat;
1301 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED];
1302 static encode_image_func *const encode_image_funcs[NUM_ENCODERS_SUPPORTED] = {
1303 encode_image_BMP,
1306 /*****************************************************************************
1307 * GdipSaveImageToStream [GDIPLUS.@]
1309 GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
1310 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
1312 GpStatus stat;
1313 HRESULT hr;
1314 short type;
1315 HBITMAP hbmp;
1316 HBITMAP old_hbmp;
1317 HDC hdc;
1318 int bm_is_selected;
1319 BITMAPINFO bmp_info;
1320 LPVOID bmp_bits;
1321 encode_image_func* encode_image;
1322 LPVOID output;
1323 unsigned int output_size;
1324 unsigned int dummy;
1325 int i;
1327 old_hbmp = 0;
1328 output = NULL;
1329 output_size = 0;
1331 TRACE("%p %p %p %p\n", image, stream, clsid, params);
1333 if(!image || !stream)
1334 return InvalidParameter;
1336 if (!image->picture)
1337 return GenericError;
1339 hr = IPicture_get_Type(image->picture, &type);
1340 if (FAILED(hr) || type != PICTYPE_BITMAP)
1341 return GenericError;
1343 /* select correct encoder */
1344 encode_image = NULL;
1345 for (i = 0; i < NUM_ENCODERS_SUPPORTED; i++) {
1346 if (IsEqualCLSID(clsid, &codecs[i].Clsid))
1347 encode_image = encode_image_funcs[i];
1349 if (encode_image == NULL)
1350 return UnknownImageFormat;
1352 /* extract underlying hbitmap representation from the IPicture */
1353 hr = IPicture_get_Handle(image->picture, (OLE_HANDLE*)&hbmp);
1354 if (FAILED(hr) || !hbmp)
1355 return GenericError;
1356 hr = IPicture_get_CurDC(image->picture, &hdc);
1357 if (FAILED(hr))
1358 return GenericError;
1359 bm_is_selected = (hdc != 0);
1360 if (!bm_is_selected) {
1361 hdc = CreateCompatibleDC(0);
1362 old_hbmp = SelectObject(hdc, hbmp);
1365 /* get bits from HBITMAP */
1366 bmp_info.bmiHeader.biSize = sizeof(bmp_info.bmiHeader);
1367 bmp_info.bmiHeader.biBitCount = 0;
1368 GetDIBits(hdc, hbmp, 0, 0, NULL, &bmp_info, DIB_RGB_COLORS);
1370 bmp_bits = GdipAlloc(bmp_info.bmiHeader.biSizeImage);
1372 if (bmp_bits)
1373 GetDIBits(hdc, hbmp, 0, abs(bmp_info.bmiHeader.biHeight), bmp_bits, &bmp_info, DIB_RGB_COLORS);
1375 if (!bm_is_selected) {
1376 SelectObject(hdc, old_hbmp);
1377 DeleteDC(hdc);
1380 if (!bmp_bits)
1381 return OutOfMemory;
1383 stat = encode_image(bmp_bits, &bmp_info, &output, &output_size);
1384 if (stat == Ok)
1385 IStream_Write(stream, output, output_size, &dummy);
1387 GdipFree(output);
1388 GdipFree(bmp_bits);
1390 return stat;
1393 /*****************************************************************************
1394 * GdipSetImagePalette [GDIPLUS.@]
1396 GpStatus WINGDIPAPI GdipSetImagePalette(GpImage *image,
1397 GDIPCONST ColorPalette *palette)
1399 static int calls;
1401 if(!image || !palette)
1402 return InvalidParameter;
1404 if(!(calls++))
1405 FIXME("not implemented\n");
1407 return NotImplemented;
1410 /*************************************************************************
1411 * Encoders -
1412 * Structures that represent which formats we support for encoding.
1415 /* ImageCodecInfo creation routines taken from libgdiplus */
1416 static const WCHAR bmp_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
1417 static const WCHAR bmp_extension[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
1418 static const WCHAR bmp_mimetype[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
1419 static const WCHAR bmp_format[] = {'B', 'M', 'P', 0}; /* BMP */
1420 static const BYTE bmp_sig_pattern[] = { 0x42, 0x4D };
1421 static const BYTE bmp_sig_mask[] = { 0xFF, 0xFF };
1423 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED] =
1425 { /* BMP */
1426 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
1427 /* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
1428 /* CodecName */ bmp_codecname,
1429 /* DllName */ NULL,
1430 /* FormatDescription */ bmp_format,
1431 /* FilenameExtension */ bmp_extension,
1432 /* MimeType */ bmp_mimetype,
1433 /* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
1434 /* Version */ 1,
1435 /* SigCount */ 1,
1436 /* SigSize */ 2,
1437 /* SigPattern */ bmp_sig_pattern,
1438 /* SigMask */ bmp_sig_mask,
1442 /*****************************************************************************
1443 * GdipGetImageDecodersSize [GDIPLUS.@]
1445 GpStatus WINGDIPAPI GdipGetImageDecodersSize(UINT *numDecoders, UINT *size)
1447 FIXME("%p %p stub!\n", numDecoders, size);
1449 if (!numDecoders || !size)
1450 return InvalidParameter;
1452 *numDecoders = 0;
1453 *size = 0;
1455 return Ok;
1458 /*****************************************************************************
1459 * GdipGetImageDecoders [GDIPLUS.@]
1461 GpStatus WINGDIPAPI GdipGetImageDecoders(UINT numDecoders, UINT size, ImageCodecInfo *decoders)
1463 FIXME("%u %u %p stub!\n", numDecoders, size, decoders);
1465 if (!decoders)
1466 return GenericError;
1468 return NotImplemented;
1471 /*****************************************************************************
1472 * GdipGetImageEncodersSize [GDIPLUS.@]
1474 GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size)
1476 TRACE("%p %p\n", numEncoders, size);
1478 if (!numEncoders || !size)
1479 return InvalidParameter;
1481 *numEncoders = NUM_ENCODERS_SUPPORTED;
1482 *size = sizeof (codecs);
1484 return Ok;
1487 /*****************************************************************************
1488 * GdipGetImageEncoders [GDIPLUS.@]
1490 GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders)
1492 TRACE("%u %u %p\n", numEncoders, size, encoders);
1494 if (!encoders ||
1495 (numEncoders != NUM_ENCODERS_SUPPORTED) ||
1496 (size != sizeof (codecs)))
1497 return GenericError;
1499 memcpy(encoders, codecs, sizeof (codecs));
1501 return Ok;
1504 /*****************************************************************************
1505 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
1507 GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBitmap** bitmap)
1509 BITMAP bm;
1510 GpStatus retval;
1511 PixelFormat format;
1512 BYTE* bits;
1514 TRACE("%p %p %p\n", hbm, hpal, bitmap);
1516 if(!hbm || !bitmap)
1517 return InvalidParameter;
1519 /* TODO: Support for device-dependent bitmaps */
1520 if(hpal){
1521 FIXME("no support for device-dependent bitmaps\n");
1522 return NotImplemented;
1525 if (GetObjectA(hbm, sizeof(bm), &bm) != sizeof(bm))
1526 return InvalidParameter;
1528 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
1529 switch(bm.bmBitsPixel) {
1530 case 1:
1531 format = PixelFormat1bppIndexed;
1532 break;
1533 case 4:
1534 format = PixelFormat4bppIndexed;
1535 break;
1536 case 8:
1537 format = PixelFormat8bppIndexed;
1538 break;
1539 case 24:
1540 format = PixelFormat24bppRGB;
1541 break;
1542 case 32:
1543 format = PixelFormat32bppRGB;
1544 break;
1545 case 48:
1546 format = PixelFormat48bppRGB;
1547 break;
1548 default:
1549 FIXME("don't know how to handle %d bpp\n", bm.bmBitsPixel);
1550 return InvalidParameter;
1553 if (bm.bmBits)
1554 bits = (BYTE*)bm.bmBits + (bm.bmHeight - 1) * bm.bmWidthBytes;
1555 else
1557 FIXME("can only get image data from DIB sections\n");
1558 bits = NULL;
1561 retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, -bm.bmWidthBytes,
1562 format, bits, bitmap);
1564 return retval;
1567 /*****************************************************************************
1568 * GdipSetEffectParameters [GDIPLUS.@]
1570 GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect *effect,
1571 const VOID *params, const UINT size)
1573 static int calls;
1575 if(!(calls++))
1576 FIXME("not implemented\n");
1578 return NotImplemented;
1581 /*****************************************************************************
1582 * GdipGetImageFlags [GDIPLUS.@]
1584 GpStatus WINGDIPAPI GdipGetImageFlags(GpImage *image, UINT *flags)
1586 TRACE("%p %p\n", image, flags);
1588 if(!image || !flags)
1589 return InvalidParameter;
1591 *flags = image->flags;
1593 return Ok;
1596 GpStatus WINGDIPAPI GdipTestControl(GpTestControlEnum control, void *param)
1598 TRACE("(%d, %p)\n", control, param);
1600 switch(control){
1601 case TestControlForceBilinear:
1602 if(param)
1603 FIXME("TestControlForceBilinear not handled\n");
1604 break;
1605 case TestControlNoICM:
1606 if(param)
1607 FIXME("TestControlNoICM not handled\n");
1608 break;
1609 case TestControlGetBuildNumber:
1610 *((DWORD*)param) = 3102;
1611 break;
1614 return Ok;
1617 GpStatus WINGDIPAPI GdipRecordMetafileFileName(GDIPCONST WCHAR* fileName,
1618 HDC hdc, EmfType type, GDIPCONST GpRectF *pFrameRect,
1619 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc,
1620 GpMetafile **metafile)
1622 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
1623 frameUnit, debugstr_w(desc), metafile);
1625 return NotImplemented;
1628 GpStatus WINGDIPAPI GdipRecordMetafileFileNameI(GDIPCONST WCHAR* fileName, HDC hdc, EmfType type,
1629 GDIPCONST GpRect *pFrameRect, MetafileFrameUnit frameUnit,
1630 GDIPCONST WCHAR *desc, GpMetafile **metafile)
1632 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
1633 frameUnit, debugstr_w(desc), metafile);
1635 return NotImplemented;
1638 GpStatus WINGDIPAPI GdipImageForceValidation(GpImage *image)
1640 FIXME("%p\n", image);
1642 return Ok;