push e7552b73e75828caa36d732caa646c0c70d8de9d
[wine/hacks.git] / dlls / gdiplus / image.c
blob55522258891354ea6a0a963ca48d2db621c7257f
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 GdipBitmapSetResolution(GpBitmap* bitmap, REAL xdpi, REAL ydpi)
197 FIXME("(%p, %.2f, %.2f)\n", bitmap, xdpi, ydpi);
199 return NotImplemented;
202 GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap,
203 BitmapData* lockeddata)
205 HDC hdc;
206 HBITMAP hbm, old = NULL;
207 BOOL bm_is_selected;
208 BITMAPINFO *pbmi;
210 if(!bitmap || !lockeddata)
211 return InvalidParameter;
213 if(!bitmap->lockmode)
214 return WrongState;
216 if(lockeddata->Reserved & ImageLockModeUserInputBuf)
217 return NotImplemented;
219 if(lockeddata->Reserved & ImageLockModeRead){
220 if(!(--bitmap->numlocks))
221 bitmap->lockmode = 0;
223 GdipFree(bitmap->bitmapbits);
224 bitmap->bitmapbits = NULL;
225 return Ok;
228 IPicture_get_Handle(bitmap->image.picture, (OLE_HANDLE*)&hbm);
229 IPicture_get_CurDC(bitmap->image.picture, &hdc);
230 bm_is_selected = (hdc != 0);
232 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
233 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
234 pbmi->bmiHeader.biBitCount = 0;
236 if(!bm_is_selected){
237 hdc = CreateCompatibleDC(0);
238 old = SelectObject(hdc, hbm);
241 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
242 pbmi->bmiHeader.biBitCount = PIXELFORMATBPP(lockeddata->PixelFormat);
243 SetDIBits(hdc, hbm, 0, abs(pbmi->bmiHeader.biHeight),
244 bitmap->bitmapbits, pbmi, DIB_RGB_COLORS);
246 if(!bm_is_selected){
247 SelectObject(hdc, old);
248 DeleteDC(hdc);
251 GdipFree(pbmi);
252 GdipFree(bitmap->bitmapbits);
253 bitmap->bitmapbits = NULL;
254 bitmap->lockmode = 0;
256 return Ok;
259 GpStatus WINGDIPAPI GdipCloneBitmapAreaI(INT x, INT y, INT width, INT height,
260 PixelFormat format, GpBitmap* srcBitmap, GpBitmap** dstBitmap)
262 FIXME("(%i,%i,%i,%i,%i,%p,%p)\n", x, y, width, height, format, srcBitmap, dstBitmap);
264 return NotImplemented;
267 GpStatus WINGDIPAPI GdipCloneImage(GpImage *image, GpImage **cloneImage)
269 IStream* stream;
270 HRESULT hr;
271 INT size;
272 LARGE_INTEGER move;
273 GpStatus stat = GenericError;
275 TRACE("%p, %p\n", image, cloneImage);
277 if (!image || !cloneImage)
278 return InvalidParameter;
280 hr = CreateStreamOnHGlobal(0, TRUE, &stream);
281 if (FAILED(hr))
282 return GenericError;
284 hr = IPicture_SaveAsFile(image->picture, stream, FALSE, &size);
285 if(FAILED(hr))
287 WARN("Failed to save image on stream\n");
288 goto out;
291 /* Set seek pointer back to the beginning of the picture */
292 move.QuadPart = 0;
293 hr = IStream_Seek(stream, move, STREAM_SEEK_SET, NULL);
294 if (FAILED(hr))
295 goto out;
297 stat = GdipLoadImageFromStream(stream, cloneImage);
298 if (stat != Ok) WARN("Failed to load image from stream\n");
300 out:
301 IStream_Release(stream);
302 return stat;
305 GpStatus WINGDIPAPI GdipCreateBitmapFromFile(GDIPCONST WCHAR* filename,
306 GpBitmap **bitmap)
308 GpStatus stat;
309 IStream *stream;
311 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
313 if(!filename || !bitmap)
314 return InvalidParameter;
316 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
318 if(stat != Ok)
319 return stat;
321 stat = GdipCreateBitmapFromStream(stream, bitmap);
323 IStream_Release(stream);
325 return stat;
328 GpStatus WINGDIPAPI GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO* info,
329 VOID *bits, GpBitmap **bitmap)
331 DWORD height, stride;
332 PixelFormat format;
334 FIXME("(%p, %p, %p) - partially implemented\n", info, bits, bitmap);
336 height = abs(info->bmiHeader.biHeight);
337 stride = ((info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) >> 3) & ~3;
339 if(info->bmiHeader.biHeight > 0) /* bottom-up */
341 bits = (BYTE*)bits + (height - 1) * stride;
342 stride = -stride;
345 switch(info->bmiHeader.biBitCount) {
346 case 1:
347 format = PixelFormat1bppIndexed;
348 break;
349 case 4:
350 format = PixelFormat4bppIndexed;
351 break;
352 case 8:
353 format = PixelFormat8bppIndexed;
354 break;
355 case 24:
356 format = PixelFormat24bppRGB;
357 break;
358 default:
359 FIXME("don't know how to handle %d bpp\n", info->bmiHeader.biBitCount);
360 *bitmap = NULL;
361 return InvalidParameter;
364 return GdipCreateBitmapFromScan0(info->bmiHeader.biWidth, height, stride, format,
365 bits, bitmap);
369 /* FIXME: no icm */
370 GpStatus WINGDIPAPI GdipCreateBitmapFromFileICM(GDIPCONST WCHAR* filename,
371 GpBitmap **bitmap)
373 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
375 return GdipCreateBitmapFromFile(filename, bitmap);
378 GpStatus WINGDIPAPI GdipCreateBitmapFromResource(HINSTANCE hInstance,
379 GDIPCONST WCHAR* lpBitmapName, GpBitmap** bitmap)
381 HBITMAP hbm;
382 GpStatus stat = InvalidParameter;
384 TRACE("%p (%s) %p\n", hInstance, debugstr_w(lpBitmapName), bitmap);
386 if(!lpBitmapName || !bitmap)
387 return InvalidParameter;
389 /* load DIB */
390 hbm = LoadImageW(hInstance, lpBitmapName, IMAGE_BITMAP, 0, 0,
391 LR_CREATEDIBSECTION);
393 if(hbm){
394 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, bitmap);
395 DeleteObject(hbm);
398 return stat;
401 GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
402 HBITMAP* hbmReturn, ARGB background)
404 FIXME("stub\n");
406 hbmReturn = NULL;
408 return NotImplemented;
411 GpStatus WINGDIPAPI GdipConvertToEmfPlus(const GpGraphics* ref,
412 GpMetafile* metafile, BOOL* succ, EmfType emfType,
413 const WCHAR* description, GpMetafile** out_metafile)
415 static int calls;
417 if(!ref || !metafile || !out_metafile)
418 return InvalidParameter;
420 *succ = FALSE;
421 *out_metafile = NULL;
423 if(!(calls++))
424 FIXME("not implemented\n");
426 return NotImplemented;
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)
434 static int calls;
435 GpStatus ret;
437 if(!target || !bitmap)
438 return InvalidParameter;
440 if(!(calls++))
441 FIXME("hacked stub\n");
443 ret = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat24bppRGB,
444 NULL, bitmap);
446 return ret;
449 GpStatus WINGDIPAPI GdipCreateBitmapFromHICON(HICON hicon, GpBitmap** bitmap)
451 HICON icon_copy;
452 ICONINFO iinfo;
453 PICTDESC desc;
455 TRACE("%p, %p\n", hicon, bitmap);
457 if(!bitmap || !GetIconInfo(hicon, &iinfo))
458 return InvalidParameter;
460 *bitmap = GdipAlloc(sizeof(GpBitmap));
461 if(!*bitmap) return OutOfMemory;
463 icon_copy = CreateIconIndirect(&iinfo);
465 if(!icon_copy){
466 GdipFree(*bitmap);
467 return InvalidParameter;
470 desc.cbSizeofstruct = sizeof(PICTDESC);
471 desc.picType = PICTYPE_ICON;
472 desc.u.icon.hicon = icon_copy;
474 if(OleCreatePictureIndirect(&desc, &IID_IPicture, TRUE,
475 (LPVOID*) &((*bitmap)->image.picture)) != S_OK){
476 DestroyIcon(icon_copy);
477 GdipFree(*bitmap);
478 return GenericError;
481 (*bitmap)->format = PixelFormat32bppARGB;
482 (*bitmap)->image.type = ImageTypeBitmap;
483 (*bitmap)->image.flags = ImageFlagsNone;
484 (*bitmap)->width = ipicture_pixel_width((*bitmap)->image.picture);
485 (*bitmap)->height = ipicture_pixel_height((*bitmap)->image.picture);
487 DeleteObject(iinfo.hbmColor);
488 DeleteObject(iinfo.hbmMask);
490 return Ok;
493 GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
494 PixelFormat format, BYTE* scan0, GpBitmap** bitmap)
496 BITMAPFILEHEADER *bmfh;
497 BITMAPINFOHEADER *bmih;
498 BYTE *buff;
499 INT datalen, size;
500 IStream *stream;
502 TRACE("%d %d %d %d %p %p\n", width, height, stride, format, scan0, bitmap);
504 if (!bitmap) return InvalidParameter;
506 if(width <= 0 || height <= 0 || (scan0 && (stride % 4))){
507 *bitmap = NULL;
508 return InvalidParameter;
511 if(scan0 && !stride)
512 return InvalidParameter;
514 *bitmap = GdipAlloc(sizeof(GpBitmap));
515 if(!*bitmap) return OutOfMemory;
517 if(stride == 0){
518 stride = width * (PIXELFORMATBPP(format) / 8);
519 stride = (stride + 3) & ~3;
522 datalen = abs(stride * height);
523 size = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + datalen;
524 buff = GdipAlloc(size);
525 if(!buff){
526 GdipFree(*bitmap);
527 return OutOfMemory;
530 bmfh = (BITMAPFILEHEADER*) buff;
531 bmih = (BITMAPINFOHEADER*) (bmfh + 1);
533 bmfh->bfType = (((WORD)'M') << 8) + (WORD)'B';
534 bmfh->bfSize = size;
535 bmfh->bfOffBits = size - datalen;
537 bmih->biSize = sizeof(BITMAPINFOHEADER);
538 bmih->biWidth = width;
539 /* FIXME: use the rest of the data from format */
540 bmih->biBitCount = PIXELFORMATBPP(format);
541 bmih->biCompression = BI_RGB;
542 bmih->biSizeImage = datalen;
544 if (scan0)
546 if (stride > 0)
548 bmih->biHeight = -height;
549 memcpy(bmih + 1, scan0, datalen);
551 else
553 bmih->biHeight = height;
554 memcpy(bmih + 1, scan0 + stride * (height - 1), datalen);
557 else
559 bmih->biHeight = height;
560 memset(bmih + 1, 0, datalen);
563 if(CreateStreamOnHGlobal(buff, TRUE, &stream) != S_OK){
564 ERR("could not make stream\n");
565 GdipFree(*bitmap);
566 GdipFree(buff);
567 *bitmap = NULL;
568 return GenericError;
571 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
572 (LPVOID*) &((*bitmap)->image.picture)) != S_OK){
573 TRACE("Could not load picture\n");
574 IStream_Release(stream);
575 GdipFree(*bitmap);
576 GdipFree(buff);
577 *bitmap = NULL;
578 return GenericError;
581 (*bitmap)->image.type = ImageTypeBitmap;
582 (*bitmap)->image.flags = ImageFlagsNone;
583 (*bitmap)->width = width;
584 (*bitmap)->height = height;
585 (*bitmap)->format = format;
587 return Ok;
590 GpStatus WINGDIPAPI GdipCreateBitmapFromStream(IStream* stream,
591 GpBitmap **bitmap)
593 GpStatus stat;
595 TRACE("%p %p\n", stream, bitmap);
597 stat = GdipLoadImageFromStream(stream, (GpImage**) bitmap);
599 if(stat != Ok)
600 return stat;
602 if((*bitmap)->image.type != ImageTypeBitmap){
603 IPicture_Release((*bitmap)->image.picture);
604 GdipFree(bitmap);
605 return GenericError; /* FIXME: what error to return? */
608 return Ok;
611 /* FIXME: no icm */
612 GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream* stream,
613 GpBitmap **bitmap)
615 TRACE("%p %p\n", stream, bitmap);
617 return GdipCreateBitmapFromStream(stream, bitmap);
620 GpStatus WINGDIPAPI GdipCreateCachedBitmap(GpBitmap *bitmap, GpGraphics *graphics,
621 GpCachedBitmap **cachedbmp)
623 GpStatus stat;
625 TRACE("%p %p %p\n", bitmap, graphics, cachedbmp);
627 if(!bitmap || !graphics || !cachedbmp)
628 return InvalidParameter;
630 *cachedbmp = GdipAlloc(sizeof(GpCachedBitmap));
631 if(!*cachedbmp)
632 return OutOfMemory;
634 stat = GdipCloneImage(&(bitmap->image), &(*cachedbmp)->image);
635 if(stat != Ok){
636 GdipFree(*cachedbmp);
637 return stat;
640 return Ok;
643 GpStatus WINGDIPAPI GdipDeleteCachedBitmap(GpCachedBitmap *cachedbmp)
645 TRACE("%p\n", cachedbmp);
647 if(!cachedbmp)
648 return InvalidParameter;
650 GdipDisposeImage(cachedbmp->image);
651 GdipFree(cachedbmp);
653 return Ok;
656 GpStatus WINGDIPAPI GdipDrawCachedBitmap(GpGraphics *graphics,
657 GpCachedBitmap *cachedbmp, INT x, INT y)
659 TRACE("%p %p %d %d\n", graphics, cachedbmp, x, y);
661 if(!graphics || !cachedbmp)
662 return InvalidParameter;
664 return GdipDrawImage(graphics, cachedbmp->image, (REAL)x, (REAL)y);
667 GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
669 HDC hdc;
671 TRACE("%p\n", image);
673 if(!image)
674 return InvalidParameter;
676 IPicture_get_CurDC(image->picture, &hdc);
677 DeleteDC(hdc);
678 IPicture_Release(image->picture);
679 if (image->type == ImageTypeBitmap)
680 GdipFree(((GpBitmap*)image)->bitmapbits);
681 GdipFree(image);
683 return Ok;
686 GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage *image, ImageItemData* item)
688 if(!image || !item)
689 return InvalidParameter;
691 return NotImplemented;
694 GpStatus WINGDIPAPI GdipGetImageBounds(GpImage *image, GpRectF *srcRect,
695 GpUnit *srcUnit)
697 TRACE("%p %p %p\n", image, srcRect, srcUnit);
699 if(!image || !srcRect || !srcUnit)
700 return InvalidParameter;
701 if(image->type == ImageTypeMetafile){
702 *srcRect = ((GpMetafile*)image)->bounds;
703 *srcUnit = ((GpMetafile*)image)->unit;
705 else if(image->type == ImageTypeBitmap){
706 srcRect->X = srcRect->Y = 0.0;
707 srcRect->Width = (REAL) ((GpBitmap*)image)->width;
708 srcRect->Height = (REAL) ((GpBitmap*)image)->height;
709 *srcUnit = UnitPixel;
711 else{
712 srcRect->X = srcRect->Y = 0.0;
713 srcRect->Width = ipicture_pixel_width(image->picture);
714 srcRect->Height = ipicture_pixel_height(image->picture);
715 *srcUnit = UnitPixel;
718 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect->X, srcRect->Y,
719 srcRect->Width, srcRect->Height, *srcUnit);
721 return Ok;
724 GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
725 REAL *height)
727 TRACE("%p %p %p\n", image, width, height);
729 if(!image || !height || !width)
730 return InvalidParameter;
732 if(image->type == ImageTypeMetafile){
733 HDC hdc = GetDC(0);
735 *height = convert_unit(hdc, ((GpMetafile*)image)->unit) *
736 ((GpMetafile*)image)->bounds.Height;
738 *width = convert_unit(hdc, ((GpMetafile*)image)->unit) *
739 ((GpMetafile*)image)->bounds.Width;
741 ReleaseDC(0, hdc);
744 else if(image->type == ImageTypeBitmap){
745 *height = ((GpBitmap*)image)->height;
746 *width = ((GpBitmap*)image)->width;
748 else{
749 *height = ipicture_pixel_height(image->picture);
750 *width = ipicture_pixel_width(image->picture);
753 TRACE("returning (%f, %f)\n", *height, *width);
754 return Ok;
757 GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image,
758 GpGraphics **graphics)
760 HDC hdc;
762 TRACE("%p %p\n", image, graphics);
764 if(!image || !graphics)
765 return InvalidParameter;
767 if(image->type != ImageTypeBitmap){
768 FIXME("not implemented for image type %d\n", image->type);
769 return NotImplemented;
772 IPicture_get_CurDC(image->picture, &hdc);
774 if(!hdc){
775 hdc = CreateCompatibleDC(0);
776 IPicture_SelectPicture(image->picture, hdc, NULL, NULL);
779 return GdipCreateFromHDC(hdc, graphics);
782 GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
784 TRACE("%p %p\n", image, height);
786 if(!image || !height)
787 return InvalidParameter;
789 if(image->type == ImageTypeMetafile){
790 HDC hdc = GetDC(0);
792 *height = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
793 ((GpMetafile*)image)->bounds.Height);
795 ReleaseDC(0, hdc);
797 else if(image->type == ImageTypeBitmap)
798 *height = ((GpBitmap*)image)->height;
799 else
800 *height = ipicture_pixel_height(image->picture);
802 TRACE("returning %d\n", *height);
804 return Ok;
807 GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res)
809 static int calls;
811 if(!image || !res)
812 return InvalidParameter;
814 if(!(calls++))
815 FIXME("not implemented\n");
817 return NotImplemented;
820 GpStatus WINGDIPAPI GdipGetImagePaletteSize(GpImage *image, INT *size)
822 FIXME("%p %p\n", image, size);
824 if(!image || !size)
825 return InvalidParameter;
827 return NotImplemented;
830 /* FIXME: test this function for non-bitmap types */
831 GpStatus WINGDIPAPI GdipGetImagePixelFormat(GpImage *image, PixelFormat *format)
833 TRACE("%p %p\n", image, format);
835 if(!image || !format)
836 return InvalidParameter;
838 if(image->type != ImageTypeBitmap)
839 *format = PixelFormat24bppRGB;
840 else
841 *format = ((GpBitmap*) image)->format;
843 return Ok;
846 GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage *image, GUID *format)
848 static int calls;
850 if(!image || !format)
851 return InvalidParameter;
853 if(!(calls++))
854 FIXME("stub\n");
856 /* FIXME: should be detected from embedded picture or stored separately */
857 switch (image->type)
859 case ImageTypeBitmap: *format = ImageFormatBMP; break;
860 case ImageTypeMetafile: *format = ImageFormatEMF; break;
861 default:
862 WARN("unknown type %u\n", image->type);
863 *format = ImageFormatUndefined;
865 return Ok;
868 GpStatus WINGDIPAPI GdipGetImageType(GpImage *image, ImageType *type)
870 TRACE("%p %p\n", image, type);
872 if(!image || !type)
873 return InvalidParameter;
875 *type = image->type;
877 return Ok;
880 GpStatus WINGDIPAPI GdipGetImageVerticalResolution(GpImage *image, REAL *res)
882 static int calls;
884 if(!image || !res)
885 return InvalidParameter;
887 if(!(calls++))
888 FIXME("not implemented\n");
890 return NotImplemented;
893 GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
895 TRACE("%p %p\n", image, width);
897 if(!image || !width)
898 return InvalidParameter;
900 if(image->type == ImageTypeMetafile){
901 HDC hdc = GetDC(0);
903 *width = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
904 ((GpMetafile*)image)->bounds.Width);
906 ReleaseDC(0, hdc);
908 else if(image->type == ImageTypeBitmap)
909 *width = ((GpBitmap*)image)->width;
910 else
911 *width = ipicture_pixel_width(image->picture);
913 TRACE("returning %d\n", *width);
915 return Ok;
918 GpStatus WINGDIPAPI GdipGetMetafileHeaderFromMetafile(GpMetafile * metafile,
919 MetafileHeader * header)
921 static int calls;
923 if(!metafile || !header)
924 return InvalidParameter;
926 if(!(calls++))
927 FIXME("not implemented\n");
929 return Ok;
932 GpStatus WINGDIPAPI GdipGetAllPropertyItems(GpImage *image, UINT size,
933 UINT num, PropertyItem* items)
935 static int calls;
937 if(!(calls++))
938 FIXME("not implemented\n");
940 return InvalidParameter;
943 GpStatus WINGDIPAPI GdipGetPropertyCount(GpImage *image, UINT* num)
945 static int calls;
947 if(!(calls++))
948 FIXME("not implemented\n");
950 return InvalidParameter;
953 GpStatus WINGDIPAPI GdipGetPropertyIdList(GpImage *image, UINT num, PROPID* list)
955 static int calls;
957 if(!(calls++))
958 FIXME("not implemented\n");
960 return InvalidParameter;
963 GpStatus WINGDIPAPI GdipGetPropertyItem(GpImage *image, PROPID id, UINT size,
964 PropertyItem* buffer)
966 static int calls;
968 if(!(calls++))
969 FIXME("not implemented\n");
971 return InvalidParameter;
974 GpStatus WINGDIPAPI GdipGetPropertyItemSize(GpImage *image, PROPID pid,
975 UINT* size)
977 static int calls;
979 TRACE("%p %x %p\n", image, pid, size);
981 if(!size || !image)
982 return InvalidParameter;
984 if(!(calls++))
985 FIXME("not implemented\n");
987 return NotImplemented;
990 GpStatus WINGDIPAPI GdipGetPropertySize(GpImage *image, UINT* size, UINT* num)
992 static int calls;
994 if(!(calls++))
995 FIXME("not implemented\n");
997 return InvalidParameter;
1000 GpStatus WINGDIPAPI GdipImageGetFrameCount(GpImage *image,
1001 GDIPCONST GUID* dimensionID, UINT* count)
1003 static int calls;
1005 if(!image || !dimensionID || !count)
1006 return InvalidParameter;
1008 if(!(calls++))
1009 FIXME("not implemented\n");
1011 return NotImplemented;
1014 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsCount(GpImage *image,
1015 UINT* count)
1017 if(!image || !count)
1018 return InvalidParameter;
1020 *count = 1;
1022 FIXME("stub\n");
1024 return Ok;
1027 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsList(GpImage* image,
1028 GUID* dimensionIDs, UINT count)
1030 static int calls;
1032 if(!image || !dimensionIDs)
1033 return InvalidParameter;
1035 if(!(calls++))
1036 FIXME("not implemented\n");
1038 return Ok;
1041 GpStatus WINGDIPAPI GdipImageSelectActiveFrame(GpImage *image,
1042 GDIPCONST GUID* dimensionID, UINT frameidx)
1044 static int calls;
1046 if(!image || !dimensionID)
1047 return InvalidParameter;
1049 if(!(calls++))
1050 FIXME("not implemented\n");
1052 return Ok;
1055 GpStatus WINGDIPAPI GdipLoadImageFromFile(GDIPCONST WCHAR* filename,
1056 GpImage **image)
1058 GpStatus stat;
1059 IStream *stream;
1061 TRACE("(%s) %p\n", debugstr_w(filename), image);
1063 if (!filename || !image)
1064 return InvalidParameter;
1066 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
1068 if (stat != Ok)
1069 return stat;
1071 stat = GdipLoadImageFromStream(stream, image);
1073 IStream_Release(stream);
1075 return stat;
1078 /* FIXME: no icm handling */
1079 GpStatus WINGDIPAPI GdipLoadImageFromFileICM(GDIPCONST WCHAR* filename,GpImage **image)
1081 TRACE("(%s) %p\n", debugstr_w(filename), image);
1083 return GdipLoadImageFromFile(filename, image);
1086 GpStatus WINGDIPAPI GdipLoadImageFromStream(IStream* stream, GpImage **image)
1088 IPicture *pic;
1089 short type;
1091 TRACE("%p %p\n", stream, image);
1093 if(!stream || !image)
1094 return InvalidParameter;
1096 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
1097 (LPVOID*) &pic) != S_OK){
1098 TRACE("Could not load picture\n");
1099 return GenericError;
1102 IPicture_get_Type(pic, &type);
1104 if(type == PICTYPE_BITMAP){
1105 BITMAPINFO *pbmi;
1106 BITMAPCOREHEADER* bmch;
1107 HBITMAP hbm;
1108 HDC hdc;
1110 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1111 if (!pbmi)
1112 return OutOfMemory;
1113 *image = GdipAlloc(sizeof(GpBitmap));
1114 if(!*image){
1115 GdipFree(pbmi);
1116 return OutOfMemory;
1118 (*image)->type = ImageTypeBitmap;
1120 (*((GpBitmap**) image))->width = ipicture_pixel_width(pic);
1121 (*((GpBitmap**) image))->height = ipicture_pixel_height(pic);
1123 /* get the pixel format */
1124 IPicture_get_Handle(pic, (OLE_HANDLE*)&hbm);
1125 IPicture_get_CurDC(pic, &hdc);
1127 bmch = (BITMAPCOREHEADER*) (&pbmi->bmiHeader);
1128 bmch->bcSize = sizeof(BITMAPCOREHEADER);
1130 if(!hdc){
1131 HBITMAP old;
1132 hdc = CreateCompatibleDC(0);
1133 old = SelectObject(hdc, hbm);
1134 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
1135 SelectObject(hdc, old);
1136 DeleteDC(hdc);
1138 else
1139 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
1141 switch(bmch->bcBitCount)
1143 case 1:
1144 (*((GpBitmap**) image))->format = PixelFormat1bppIndexed;
1145 break;
1146 case 4:
1147 (*((GpBitmap**) image))->format = PixelFormat4bppIndexed;
1148 break;
1149 case 8:
1150 (*((GpBitmap**) image))->format = PixelFormat8bppIndexed;
1151 break;
1152 case 16:
1153 (*((GpBitmap**) image))->format = PixelFormat16bppRGB565;
1154 break;
1155 case 24:
1156 (*((GpBitmap**) image))->format = PixelFormat24bppRGB;
1157 break;
1158 case 32:
1159 (*((GpBitmap**) image))->format = PixelFormat32bppRGB;
1160 break;
1161 case 48:
1162 (*((GpBitmap**) image))->format = PixelFormat48bppRGB;
1163 break;
1164 default:
1165 FIXME("Bit depth %d is not fully supported yet\n", bmch->bcBitCount);
1166 (*((GpBitmap**) image))->format = (bmch->bcBitCount << 8) | PixelFormatGDI;
1167 break;
1170 GdipFree(pbmi);
1172 else if(type == PICTYPE_METAFILE || type == PICTYPE_ENHMETAFILE){
1173 /* FIXME: missing initialization code */
1174 *image = GdipAlloc(sizeof(GpMetafile));
1175 if(!*image) return OutOfMemory;
1176 (*image)->type = ImageTypeMetafile;
1178 else{
1179 *image = GdipAlloc(sizeof(GpImage));
1180 if(!*image) return OutOfMemory;
1181 (*image)->type = ImageTypeUnknown;
1184 (*image)->picture = pic;
1185 (*image)->flags = ImageFlagsNone;
1187 return Ok;
1190 /* FIXME: no ICM */
1191 GpStatus WINGDIPAPI GdipLoadImageFromStreamICM(IStream* stream, GpImage **image)
1193 TRACE("%p %p\n", stream, image);
1195 return GdipLoadImageFromStream(stream, image);
1198 GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
1200 static int calls;
1202 if(!image)
1203 return InvalidParameter;
1205 if(!(calls++))
1206 FIXME("not implemented\n");
1208 return NotImplemented;
1211 GpStatus WINGDIPAPI GdipSetPropertyItem(GpImage *image, GDIPCONST PropertyItem* item)
1213 static int calls;
1215 if(!(calls++))
1216 FIXME("not implemented\n");
1218 return NotImplemented;
1221 GpStatus WINGDIPAPI GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
1222 GDIPCONST CLSID *clsidEncoder,
1223 GDIPCONST EncoderParameters *encoderParams)
1225 GpStatus stat;
1226 IStream *stream;
1228 TRACE("%p (%s) %p %p\n", image, debugstr_w(filename), clsidEncoder, encoderParams);
1230 if (!image || !filename|| !clsidEncoder)
1231 return InvalidParameter;
1233 if (!(image->picture))
1234 return InvalidParameter;
1236 stat = GdipCreateStreamOnFile(filename, GENERIC_WRITE, &stream);
1237 if (stat != Ok)
1238 return GenericError;
1240 stat = GdipSaveImageToStream(image, stream, clsidEncoder, encoderParams);
1242 IStream_Release(stream);
1243 return stat;
1246 /*************************************************************************
1247 * Encoding functions -
1248 * These functions encode an image in different image file formats.
1250 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
1251 #define BITMAP_FORMAT_JPEG 0xd8ff
1252 #define BITMAP_FORMAT_GIF 0x4947
1253 #define BITMAP_FORMAT_PNG 0x5089
1254 #define BITMAP_FORMAT_APM 0xcdd7
1256 static GpStatus encode_image_BMP(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
1257 void **output, unsigned int *output_size)
1259 int num_palette_entries;
1260 BITMAPFILEHEADER *bmp_file_hdr;
1261 BITMAPINFO *bmp_info_hdr;
1263 if (bitmap_info->bmiHeader.biClrUsed) {
1264 num_palette_entries = bitmap_info->bmiHeader.biClrUsed;
1265 if (num_palette_entries > 256) num_palette_entries = 256;
1266 } else {
1267 if (bitmap_info->bmiHeader.biBitCount <= 8)
1268 num_palette_entries = 1 << bitmap_info->bmiHeader.biBitCount;
1269 else
1270 num_palette_entries = 0;
1273 *output_size =
1274 sizeof(BITMAPFILEHEADER) +
1275 sizeof(BITMAPINFOHEADER) +
1276 num_palette_entries * sizeof(RGBQUAD) +
1277 bitmap_info->bmiHeader.biSizeImage;
1279 *output = GdipAlloc(*output_size);
1281 bmp_file_hdr = *output;
1282 bmp_file_hdr->bfType = BITMAP_FORMAT_BMP;
1283 bmp_file_hdr->bfSize = *output_size;
1284 bmp_file_hdr->bfOffBits =
1285 sizeof(BITMAPFILEHEADER) +
1286 sizeof(BITMAPINFOHEADER) +
1287 num_palette_entries * sizeof (RGBQUAD);
1289 bmp_info_hdr = (BITMAPINFO*) ((unsigned char*)(*output) + sizeof(BITMAPFILEHEADER));
1290 memcpy(bmp_info_hdr, bitmap_info, sizeof(BITMAPINFOHEADER) + num_palette_entries * sizeof(RGBQUAD));
1291 memcpy((unsigned char *)(*output) +
1292 sizeof(BITMAPFILEHEADER) +
1293 sizeof(BITMAPINFOHEADER) +
1294 num_palette_entries * sizeof(RGBQUAD),
1295 bitmap_bits, bitmap_info->bmiHeader.biSizeImage);
1297 return Ok;
1300 typedef GpStatus encode_image_func(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
1301 void **output, unsigned int *output_size);
1303 typedef enum {
1304 BMP,
1305 NUM_ENCODERS_SUPPORTED
1306 } ImageFormat;
1308 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED];
1309 static encode_image_func *const encode_image_funcs[NUM_ENCODERS_SUPPORTED] = {
1310 encode_image_BMP,
1313 /*****************************************************************************
1314 * GdipSaveImageToStream [GDIPLUS.@]
1316 GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
1317 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
1319 GpStatus stat;
1320 HRESULT hr;
1321 short type;
1322 HBITMAP hbmp;
1323 HBITMAP old_hbmp;
1324 HDC hdc;
1325 int bm_is_selected;
1326 BITMAPINFO bmp_info;
1327 LPVOID bmp_bits;
1328 encode_image_func* encode_image;
1329 LPVOID output;
1330 unsigned int output_size;
1331 unsigned int dummy;
1332 int i;
1334 old_hbmp = 0;
1335 output = NULL;
1336 output_size = 0;
1338 TRACE("%p %p %p %p\n", image, stream, clsid, params);
1340 if(!image || !stream)
1341 return InvalidParameter;
1343 if (!image->picture)
1344 return GenericError;
1346 hr = IPicture_get_Type(image->picture, &type);
1347 if (FAILED(hr) || type != PICTYPE_BITMAP)
1348 return GenericError;
1350 /* select correct encoder */
1351 encode_image = NULL;
1352 for (i = 0; i < NUM_ENCODERS_SUPPORTED; i++) {
1353 if (IsEqualCLSID(clsid, &codecs[i].Clsid))
1354 encode_image = encode_image_funcs[i];
1356 if (encode_image == NULL)
1357 return UnknownImageFormat;
1359 /* extract underlying hbitmap representation from the IPicture */
1360 hr = IPicture_get_Handle(image->picture, (OLE_HANDLE*)&hbmp);
1361 if (FAILED(hr) || !hbmp)
1362 return GenericError;
1363 hr = IPicture_get_CurDC(image->picture, &hdc);
1364 if (FAILED(hr))
1365 return GenericError;
1366 bm_is_selected = (hdc != 0);
1367 if (!bm_is_selected) {
1368 hdc = CreateCompatibleDC(0);
1369 old_hbmp = SelectObject(hdc, hbmp);
1372 /* get bits from HBITMAP */
1373 bmp_info.bmiHeader.biSize = sizeof(bmp_info.bmiHeader);
1374 bmp_info.bmiHeader.biBitCount = 0;
1375 GetDIBits(hdc, hbmp, 0, 0, NULL, &bmp_info, DIB_RGB_COLORS);
1377 bmp_bits = GdipAlloc(bmp_info.bmiHeader.biSizeImage);
1379 if (bmp_bits)
1380 GetDIBits(hdc, hbmp, 0, abs(bmp_info.bmiHeader.biHeight), bmp_bits, &bmp_info, DIB_RGB_COLORS);
1382 if (!bm_is_selected) {
1383 SelectObject(hdc, old_hbmp);
1384 DeleteDC(hdc);
1387 if (!bmp_bits)
1388 return OutOfMemory;
1390 stat = encode_image(bmp_bits, &bmp_info, &output, &output_size);
1391 if (stat == Ok)
1392 IStream_Write(stream, output, output_size, &dummy);
1394 GdipFree(output);
1395 GdipFree(bmp_bits);
1397 return stat;
1400 /*****************************************************************************
1401 * GdipSetImagePalette [GDIPLUS.@]
1403 GpStatus WINGDIPAPI GdipSetImagePalette(GpImage *image,
1404 GDIPCONST ColorPalette *palette)
1406 static int calls;
1408 if(!image || !palette)
1409 return InvalidParameter;
1411 if(!(calls++))
1412 FIXME("not implemented\n");
1414 return NotImplemented;
1417 /*************************************************************************
1418 * Encoders -
1419 * Structures that represent which formats we support for encoding.
1422 /* ImageCodecInfo creation routines taken from libgdiplus */
1423 static const WCHAR bmp_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
1424 static const WCHAR bmp_extension[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
1425 static const WCHAR bmp_mimetype[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
1426 static const WCHAR bmp_format[] = {'B', 'M', 'P', 0}; /* BMP */
1427 static const BYTE bmp_sig_pattern[] = { 0x42, 0x4D };
1428 static const BYTE bmp_sig_mask[] = { 0xFF, 0xFF };
1430 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED] =
1432 { /* BMP */
1433 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
1434 /* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
1435 /* CodecName */ bmp_codecname,
1436 /* DllName */ NULL,
1437 /* FormatDescription */ bmp_format,
1438 /* FilenameExtension */ bmp_extension,
1439 /* MimeType */ bmp_mimetype,
1440 /* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
1441 /* Version */ 1,
1442 /* SigCount */ 1,
1443 /* SigSize */ 2,
1444 /* SigPattern */ bmp_sig_pattern,
1445 /* SigMask */ bmp_sig_mask,
1449 /*****************************************************************************
1450 * GdipGetImageDecodersSize [GDIPLUS.@]
1452 GpStatus WINGDIPAPI GdipGetImageDecodersSize(UINT *numDecoders, UINT *size)
1454 FIXME("%p %p stub!\n", numDecoders, size);
1456 if (!numDecoders || !size)
1457 return InvalidParameter;
1459 *numDecoders = 0;
1460 *size = 0;
1462 return Ok;
1465 /*****************************************************************************
1466 * GdipGetImageDecoders [GDIPLUS.@]
1468 GpStatus WINGDIPAPI GdipGetImageDecoders(UINT numDecoders, UINT size, ImageCodecInfo *decoders)
1470 FIXME("%u %u %p stub!\n", numDecoders, size, decoders);
1472 if (!decoders)
1473 return GenericError;
1475 return NotImplemented;
1478 /*****************************************************************************
1479 * GdipGetImageEncodersSize [GDIPLUS.@]
1481 GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size)
1483 TRACE("%p %p\n", numEncoders, size);
1485 if (!numEncoders || !size)
1486 return InvalidParameter;
1488 *numEncoders = NUM_ENCODERS_SUPPORTED;
1489 *size = sizeof (codecs);
1491 return Ok;
1494 /*****************************************************************************
1495 * GdipGetImageEncoders [GDIPLUS.@]
1497 GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders)
1499 TRACE("%u %u %p\n", numEncoders, size, encoders);
1501 if (!encoders ||
1502 (numEncoders != NUM_ENCODERS_SUPPORTED) ||
1503 (size != sizeof (codecs)))
1504 return GenericError;
1506 memcpy(encoders, codecs, sizeof (codecs));
1508 return Ok;
1511 /*****************************************************************************
1512 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
1514 GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBitmap** bitmap)
1516 BITMAP bm;
1517 GpStatus retval;
1518 PixelFormat format;
1519 BYTE* bits;
1521 TRACE("%p %p %p\n", hbm, hpal, bitmap);
1523 if(!hbm || !bitmap)
1524 return InvalidParameter;
1526 /* TODO: Support for device-dependent bitmaps */
1527 if(hpal){
1528 FIXME("no support for device-dependent bitmaps\n");
1529 return NotImplemented;
1532 if (GetObjectA(hbm, sizeof(bm), &bm) != sizeof(bm))
1533 return InvalidParameter;
1535 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
1536 switch(bm.bmBitsPixel) {
1537 case 1:
1538 format = PixelFormat1bppIndexed;
1539 break;
1540 case 4:
1541 format = PixelFormat4bppIndexed;
1542 break;
1543 case 8:
1544 format = PixelFormat8bppIndexed;
1545 break;
1546 case 24:
1547 format = PixelFormat24bppRGB;
1548 break;
1549 case 32:
1550 format = PixelFormat32bppRGB;
1551 break;
1552 case 48:
1553 format = PixelFormat48bppRGB;
1554 break;
1555 default:
1556 FIXME("don't know how to handle %d bpp\n", bm.bmBitsPixel);
1557 return InvalidParameter;
1560 if (bm.bmBits)
1561 bits = (BYTE*)bm.bmBits + (bm.bmHeight - 1) * bm.bmWidthBytes;
1562 else
1564 FIXME("can only get image data from DIB sections\n");
1565 bits = NULL;
1568 retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, -bm.bmWidthBytes,
1569 format, bits, bitmap);
1571 return retval;
1574 /*****************************************************************************
1575 * GdipSetEffectParameters [GDIPLUS.@]
1577 GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect *effect,
1578 const VOID *params, const UINT size)
1580 static int calls;
1582 if(!(calls++))
1583 FIXME("not implemented\n");
1585 return NotImplemented;
1588 /*****************************************************************************
1589 * GdipGetImageFlags [GDIPLUS.@]
1591 GpStatus WINGDIPAPI GdipGetImageFlags(GpImage *image, UINT *flags)
1593 TRACE("%p %p\n", image, flags);
1595 if(!image || !flags)
1596 return InvalidParameter;
1598 *flags = image->flags;
1600 return Ok;
1603 GpStatus WINGDIPAPI GdipTestControl(GpTestControlEnum control, void *param)
1605 TRACE("(%d, %p)\n", control, param);
1607 switch(control){
1608 case TestControlForceBilinear:
1609 if(param)
1610 FIXME("TestControlForceBilinear not handled\n");
1611 break;
1612 case TestControlNoICM:
1613 if(param)
1614 FIXME("TestControlNoICM not handled\n");
1615 break;
1616 case TestControlGetBuildNumber:
1617 *((DWORD*)param) = 3102;
1618 break;
1621 return Ok;
1624 GpStatus WINGDIPAPI GdipRecordMetafileFileName(GDIPCONST WCHAR* fileName,
1625 HDC hdc, EmfType type, GDIPCONST GpRectF *pFrameRect,
1626 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc,
1627 GpMetafile **metafile)
1629 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
1630 frameUnit, debugstr_w(desc), metafile);
1632 return NotImplemented;
1635 GpStatus WINGDIPAPI GdipRecordMetafileFileNameI(GDIPCONST WCHAR* fileName, HDC hdc, EmfType type,
1636 GDIPCONST GpRect *pFrameRect, MetafileFrameUnit frameUnit,
1637 GDIPCONST WCHAR *desc, GpMetafile **metafile)
1639 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
1640 frameUnit, debugstr_w(desc), metafile);
1642 return NotImplemented;
1645 GpStatus WINGDIPAPI GdipImageForceValidation(GpImage *image)
1647 FIXME("%p\n", image);
1649 return Ok;