push 45342d27cd031b08b6cfabdf8789426cb53c1c53
[wine/hacks.git] / dlls / gdiplus / image.c
blobfde6ab3ceae595f42ac09e2a6d283494a8835473
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 GpStatus WINGDIPAPI GdipBitmapSetPixel(GpBitmap* bitmap, INT x, INT y,
91 ARGB color)
93 static int calls;
94 TRACE("bitmap:%p, x:%d, y:%d, color:%08x\n", bitmap, x, y, color);
96 if(!bitmap)
97 return InvalidParameter;
99 if(!(calls++))
100 FIXME("not implemented\n");
102 return NotImplemented;
105 /* This function returns a pointer to an array of pixels that represents the
106 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
107 * flags. It is correct behavior that a user who calls this function with write
108 * privileges can write to the whole bitmap (not just the area in rect).
110 * FIXME: only used portion of format is bits per pixel. */
111 GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
112 UINT flags, PixelFormat format, BitmapData* lockeddata)
114 BOOL bm_is_selected;
115 INT stride, bitspp = PIXELFORMATBPP(format);
116 HDC hdc;
117 HBITMAP hbm, old = NULL;
118 BITMAPINFO *pbmi;
119 BYTE *buff = NULL;
120 UINT abs_height;
121 GpRect act_rect; /* actual rect to be used */
123 TRACE("%p %p %d %d %p\n", bitmap, rect, flags, format, lockeddata);
125 if(!lockeddata || !bitmap)
126 return InvalidParameter;
128 if(rect){
129 if(rect->X < 0 || rect->Y < 0 || (rect->X + rect->Width > bitmap->width) ||
130 (rect->Y + rect->Height > bitmap->height) || !flags)
131 return InvalidParameter;
133 act_rect = *rect;
135 else{
136 act_rect.X = act_rect.Y = 0;
137 act_rect.Width = bitmap->width;
138 act_rect.Height = bitmap->height;
141 if(flags & ImageLockModeUserInputBuf)
142 return NotImplemented;
144 if(bitmap->lockmode)
145 return WrongState;
147 IPicture_get_Handle(bitmap->image.picture, (OLE_HANDLE*)&hbm);
148 IPicture_get_CurDC(bitmap->image.picture, &hdc);
149 bm_is_selected = (hdc != 0);
151 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
152 if (!pbmi)
153 return OutOfMemory;
154 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
155 pbmi->bmiHeader.biBitCount = 0;
157 if(!bm_is_selected){
158 hdc = CreateCompatibleDC(0);
159 old = SelectObject(hdc, hbm);
162 /* fill out bmi */
163 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
165 abs_height = abs(pbmi->bmiHeader.biHeight);
166 stride = pbmi->bmiHeader.biWidth * bitspp / 8;
167 stride = (stride + 3) & ~3;
169 buff = GdipAlloc(stride * abs_height);
171 pbmi->bmiHeader.biBitCount = bitspp;
173 if(buff)
174 GetDIBits(hdc, hbm, 0, abs_height, buff, pbmi, DIB_RGB_COLORS);
176 if(!bm_is_selected){
177 SelectObject(hdc, old);
178 DeleteDC(hdc);
181 if(!buff){
182 GdipFree(pbmi);
183 return OutOfMemory;
186 lockeddata->Width = act_rect.Width;
187 lockeddata->Height = act_rect.Height;
188 lockeddata->PixelFormat = format;
189 lockeddata->Reserved = flags;
191 if(pbmi->bmiHeader.biHeight > 0){
192 lockeddata->Stride = -stride;
193 lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X +
194 stride * (abs_height - 1 - act_rect.Y);
196 else{
197 lockeddata->Stride = stride;
198 lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X + stride * act_rect.Y;
201 bitmap->lockmode = flags;
202 bitmap->numlocks++;
204 bitmap->bitmapbits = buff;
206 GdipFree(pbmi);
207 return Ok;
210 GpStatus WINGDIPAPI GdipBitmapSetResolution(GpBitmap* bitmap, REAL xdpi, REAL ydpi)
212 FIXME("(%p, %.2f, %.2f)\n", bitmap, xdpi, ydpi);
214 return NotImplemented;
217 GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap,
218 BitmapData* lockeddata)
220 HDC hdc;
221 HBITMAP hbm, old = NULL;
222 BOOL bm_is_selected;
223 BITMAPINFO *pbmi;
225 if(!bitmap || !lockeddata)
226 return InvalidParameter;
228 if(!bitmap->lockmode)
229 return WrongState;
231 if(lockeddata->Reserved & ImageLockModeUserInputBuf)
232 return NotImplemented;
234 if(lockeddata->Reserved & ImageLockModeRead){
235 if(!(--bitmap->numlocks))
236 bitmap->lockmode = 0;
238 GdipFree(bitmap->bitmapbits);
239 bitmap->bitmapbits = NULL;
240 return Ok;
243 IPicture_get_Handle(bitmap->image.picture, (OLE_HANDLE*)&hbm);
244 IPicture_get_CurDC(bitmap->image.picture, &hdc);
245 bm_is_selected = (hdc != 0);
247 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
248 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
249 pbmi->bmiHeader.biBitCount = 0;
251 if(!bm_is_selected){
252 hdc = CreateCompatibleDC(0);
253 old = SelectObject(hdc, hbm);
256 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
257 pbmi->bmiHeader.biBitCount = PIXELFORMATBPP(lockeddata->PixelFormat);
258 SetDIBits(hdc, hbm, 0, abs(pbmi->bmiHeader.biHeight),
259 bitmap->bitmapbits, pbmi, DIB_RGB_COLORS);
261 if(!bm_is_selected){
262 SelectObject(hdc, old);
263 DeleteDC(hdc);
266 GdipFree(pbmi);
267 GdipFree(bitmap->bitmapbits);
268 bitmap->bitmapbits = NULL;
269 bitmap->lockmode = 0;
271 return Ok;
274 GpStatus WINGDIPAPI GdipCloneBitmapAreaI(INT x, INT y, INT width, INT height,
275 PixelFormat format, GpBitmap* srcBitmap, GpBitmap** dstBitmap)
277 FIXME("(%i,%i,%i,%i,%i,%p,%p)\n", x, y, width, height, format, srcBitmap, dstBitmap);
279 return NotImplemented;
282 GpStatus WINGDIPAPI GdipCloneImage(GpImage *image, GpImage **cloneImage)
284 IStream* stream;
285 HRESULT hr;
286 INT size;
287 LARGE_INTEGER move;
288 GpStatus stat = GenericError;
290 TRACE("%p, %p\n", image, cloneImage);
292 if (!image || !cloneImage)
293 return InvalidParameter;
295 hr = CreateStreamOnHGlobal(0, TRUE, &stream);
296 if (FAILED(hr))
297 return GenericError;
299 hr = IPicture_SaveAsFile(image->picture, stream, FALSE, &size);
300 if(FAILED(hr))
302 WARN("Failed to save image on stream\n");
303 goto out;
306 /* Set seek pointer back to the beginning of the picture */
307 move.QuadPart = 0;
308 hr = IStream_Seek(stream, move, STREAM_SEEK_SET, NULL);
309 if (FAILED(hr))
310 goto out;
312 stat = GdipLoadImageFromStream(stream, cloneImage);
313 if (stat != Ok) WARN("Failed to load image from stream\n");
315 out:
316 IStream_Release(stream);
317 return stat;
320 GpStatus WINGDIPAPI GdipCreateBitmapFromFile(GDIPCONST WCHAR* filename,
321 GpBitmap **bitmap)
323 GpStatus stat;
324 IStream *stream;
326 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
328 if(!filename || !bitmap)
329 return InvalidParameter;
331 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
333 if(stat != Ok)
334 return stat;
336 stat = GdipCreateBitmapFromStream(stream, bitmap);
338 IStream_Release(stream);
340 return stat;
343 GpStatus WINGDIPAPI GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO* info,
344 VOID *bits, GpBitmap **bitmap)
346 DWORD height, stride;
347 PixelFormat format;
349 FIXME("(%p, %p, %p) - partially implemented\n", info, bits, bitmap);
351 height = abs(info->bmiHeader.biHeight);
352 stride = ((info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) >> 3) & ~3;
354 if(info->bmiHeader.biHeight > 0) /* bottom-up */
356 bits = (BYTE*)bits + (height - 1) * stride;
357 stride = -stride;
360 switch(info->bmiHeader.biBitCount) {
361 case 1:
362 format = PixelFormat1bppIndexed;
363 break;
364 case 4:
365 format = PixelFormat4bppIndexed;
366 break;
367 case 8:
368 format = PixelFormat8bppIndexed;
369 break;
370 case 24:
371 format = PixelFormat24bppRGB;
372 break;
373 default:
374 FIXME("don't know how to handle %d bpp\n", info->bmiHeader.biBitCount);
375 *bitmap = NULL;
376 return InvalidParameter;
379 return GdipCreateBitmapFromScan0(info->bmiHeader.biWidth, height, stride, format,
380 bits, bitmap);
384 /* FIXME: no icm */
385 GpStatus WINGDIPAPI GdipCreateBitmapFromFileICM(GDIPCONST WCHAR* filename,
386 GpBitmap **bitmap)
388 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
390 return GdipCreateBitmapFromFile(filename, bitmap);
393 GpStatus WINGDIPAPI GdipCreateBitmapFromResource(HINSTANCE hInstance,
394 GDIPCONST WCHAR* lpBitmapName, GpBitmap** bitmap)
396 HBITMAP hbm;
397 GpStatus stat = InvalidParameter;
399 TRACE("%p (%s) %p\n", hInstance, debugstr_w(lpBitmapName), bitmap);
401 if(!lpBitmapName || !bitmap)
402 return InvalidParameter;
404 /* load DIB */
405 hbm = LoadImageW(hInstance, lpBitmapName, IMAGE_BITMAP, 0, 0,
406 LR_CREATEDIBSECTION);
408 if(hbm){
409 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, bitmap);
410 DeleteObject(hbm);
413 return stat;
416 GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
417 HBITMAP* hbmReturn, ARGB background)
419 FIXME("stub\n");
421 hbmReturn = NULL;
423 return NotImplemented;
426 GpStatus WINGDIPAPI GdipConvertToEmfPlus(const GpGraphics* ref,
427 GpMetafile* metafile, BOOL* succ, EmfType emfType,
428 const WCHAR* description, GpMetafile** out_metafile)
430 static int calls;
432 if(!ref || !metafile || !out_metafile)
433 return InvalidParameter;
435 *succ = FALSE;
436 *out_metafile = NULL;
438 if(!(calls++))
439 FIXME("not implemented\n");
441 return NotImplemented;
444 /* FIXME: this should create a bitmap in the given size with the attributes
445 * (resolution etc.) of the graphics object */
446 GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT width, INT height,
447 GpGraphics* target, GpBitmap** bitmap)
449 static int calls;
450 GpStatus ret;
452 if(!target || !bitmap)
453 return InvalidParameter;
455 if(!(calls++))
456 FIXME("hacked stub\n");
458 ret = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat24bppRGB,
459 NULL, bitmap);
461 return ret;
464 GpStatus WINGDIPAPI GdipCreateBitmapFromHICON(HICON hicon, GpBitmap** bitmap)
466 HICON icon_copy;
467 ICONINFO iinfo;
468 PICTDESC desc;
470 TRACE("%p, %p\n", hicon, bitmap);
472 if(!bitmap || !GetIconInfo(hicon, &iinfo))
473 return InvalidParameter;
475 *bitmap = GdipAlloc(sizeof(GpBitmap));
476 if(!*bitmap) return OutOfMemory;
478 icon_copy = CreateIconIndirect(&iinfo);
480 if(!icon_copy){
481 GdipFree(*bitmap);
482 return InvalidParameter;
485 desc.cbSizeofstruct = sizeof(PICTDESC);
486 desc.picType = PICTYPE_ICON;
487 desc.u.icon.hicon = icon_copy;
489 if(OleCreatePictureIndirect(&desc, &IID_IPicture, TRUE,
490 (LPVOID*) &((*bitmap)->image.picture)) != S_OK){
491 DestroyIcon(icon_copy);
492 GdipFree(*bitmap);
493 return GenericError;
496 (*bitmap)->format = PixelFormat32bppARGB;
497 (*bitmap)->image.type = ImageTypeBitmap;
498 (*bitmap)->image.flags = ImageFlagsNone;
499 (*bitmap)->width = ipicture_pixel_width((*bitmap)->image.picture);
500 (*bitmap)->height = ipicture_pixel_height((*bitmap)->image.picture);
502 DeleteObject(iinfo.hbmColor);
503 DeleteObject(iinfo.hbmMask);
505 return Ok;
508 GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
509 PixelFormat format, BYTE* scan0, GpBitmap** bitmap)
511 BITMAPFILEHEADER *bmfh;
512 BITMAPINFOHEADER *bmih;
513 BYTE *buff;
514 INT datalen, size;
515 IStream *stream;
517 TRACE("%d %d %d %d %p %p\n", width, height, stride, format, scan0, bitmap);
519 if (!bitmap) return InvalidParameter;
521 if(width <= 0 || height <= 0 || (scan0 && (stride % 4))){
522 *bitmap = NULL;
523 return InvalidParameter;
526 if(scan0 && !stride)
527 return InvalidParameter;
529 *bitmap = GdipAlloc(sizeof(GpBitmap));
530 if(!*bitmap) return OutOfMemory;
532 if(stride == 0){
533 stride = width * (PIXELFORMATBPP(format) / 8);
534 stride = (stride + 3) & ~3;
537 datalen = abs(stride * height);
538 size = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + datalen;
539 buff = GdipAlloc(size);
540 if(!buff){
541 GdipFree(*bitmap);
542 return OutOfMemory;
545 bmfh = (BITMAPFILEHEADER*) buff;
546 bmih = (BITMAPINFOHEADER*) (bmfh + 1);
548 bmfh->bfType = (((WORD)'M') << 8) + (WORD)'B';
549 bmfh->bfSize = size;
550 bmfh->bfOffBits = size - datalen;
552 bmih->biSize = sizeof(BITMAPINFOHEADER);
553 bmih->biWidth = width;
554 /* FIXME: use the rest of the data from format */
555 bmih->biBitCount = PIXELFORMATBPP(format);
556 bmih->biCompression = BI_RGB;
557 bmih->biSizeImage = datalen;
559 if (scan0)
561 if (stride > 0)
563 bmih->biHeight = -height;
564 memcpy(bmih + 1, scan0, datalen);
566 else
568 bmih->biHeight = height;
569 memcpy(bmih + 1, scan0 + stride * (height - 1), datalen);
572 else
574 bmih->biHeight = height;
575 memset(bmih + 1, 0, datalen);
578 if(CreateStreamOnHGlobal(buff, TRUE, &stream) != S_OK){
579 ERR("could not make stream\n");
580 GdipFree(*bitmap);
581 GdipFree(buff);
582 *bitmap = NULL;
583 return GenericError;
586 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
587 (LPVOID*) &((*bitmap)->image.picture)) != S_OK){
588 TRACE("Could not load picture\n");
589 IStream_Release(stream);
590 GdipFree(*bitmap);
591 GdipFree(buff);
592 *bitmap = NULL;
593 return GenericError;
596 (*bitmap)->image.type = ImageTypeBitmap;
597 (*bitmap)->image.flags = ImageFlagsNone;
598 (*bitmap)->width = width;
599 (*bitmap)->height = height;
600 (*bitmap)->format = format;
602 return Ok;
605 GpStatus WINGDIPAPI GdipCreateBitmapFromStream(IStream* stream,
606 GpBitmap **bitmap)
608 GpStatus stat;
610 TRACE("%p %p\n", stream, bitmap);
612 stat = GdipLoadImageFromStream(stream, (GpImage**) bitmap);
614 if(stat != Ok)
615 return stat;
617 if((*bitmap)->image.type != ImageTypeBitmap){
618 IPicture_Release((*bitmap)->image.picture);
619 GdipFree(bitmap);
620 return GenericError; /* FIXME: what error to return? */
623 return Ok;
626 /* FIXME: no icm */
627 GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream* stream,
628 GpBitmap **bitmap)
630 TRACE("%p %p\n", stream, bitmap);
632 return GdipCreateBitmapFromStream(stream, bitmap);
635 GpStatus WINGDIPAPI GdipCreateCachedBitmap(GpBitmap *bitmap, GpGraphics *graphics,
636 GpCachedBitmap **cachedbmp)
638 GpStatus stat;
640 TRACE("%p %p %p\n", bitmap, graphics, cachedbmp);
642 if(!bitmap || !graphics || !cachedbmp)
643 return InvalidParameter;
645 *cachedbmp = GdipAlloc(sizeof(GpCachedBitmap));
646 if(!*cachedbmp)
647 return OutOfMemory;
649 stat = GdipCloneImage(&(bitmap->image), &(*cachedbmp)->image);
650 if(stat != Ok){
651 GdipFree(*cachedbmp);
652 return stat;
655 return Ok;
658 GpStatus WINGDIPAPI GdipDeleteCachedBitmap(GpCachedBitmap *cachedbmp)
660 TRACE("%p\n", cachedbmp);
662 if(!cachedbmp)
663 return InvalidParameter;
665 GdipDisposeImage(cachedbmp->image);
666 GdipFree(cachedbmp);
668 return Ok;
671 GpStatus WINGDIPAPI GdipDrawCachedBitmap(GpGraphics *graphics,
672 GpCachedBitmap *cachedbmp, INT x, INT y)
674 TRACE("%p %p %d %d\n", graphics, cachedbmp, x, y);
676 if(!graphics || !cachedbmp)
677 return InvalidParameter;
679 return GdipDrawImage(graphics, cachedbmp->image, (REAL)x, (REAL)y);
682 GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
684 HDC hdc;
686 TRACE("%p\n", image);
688 if(!image)
689 return InvalidParameter;
691 IPicture_get_CurDC(image->picture, &hdc);
692 DeleteDC(hdc);
693 IPicture_Release(image->picture);
694 if (image->type == ImageTypeBitmap)
695 GdipFree(((GpBitmap*)image)->bitmapbits);
696 GdipFree(image);
698 return Ok;
701 GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage *image, ImageItemData* item)
703 if(!image || !item)
704 return InvalidParameter;
706 return NotImplemented;
709 GpStatus WINGDIPAPI GdipGetImageBounds(GpImage *image, GpRectF *srcRect,
710 GpUnit *srcUnit)
712 TRACE("%p %p %p\n", image, srcRect, srcUnit);
714 if(!image || !srcRect || !srcUnit)
715 return InvalidParameter;
716 if(image->type == ImageTypeMetafile){
717 *srcRect = ((GpMetafile*)image)->bounds;
718 *srcUnit = ((GpMetafile*)image)->unit;
720 else if(image->type == ImageTypeBitmap){
721 srcRect->X = srcRect->Y = 0.0;
722 srcRect->Width = (REAL) ((GpBitmap*)image)->width;
723 srcRect->Height = (REAL) ((GpBitmap*)image)->height;
724 *srcUnit = UnitPixel;
726 else{
727 srcRect->X = srcRect->Y = 0.0;
728 srcRect->Width = ipicture_pixel_width(image->picture);
729 srcRect->Height = ipicture_pixel_height(image->picture);
730 *srcUnit = UnitPixel;
733 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect->X, srcRect->Y,
734 srcRect->Width, srcRect->Height, *srcUnit);
736 return Ok;
739 GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
740 REAL *height)
742 TRACE("%p %p %p\n", image, width, height);
744 if(!image || !height || !width)
745 return InvalidParameter;
747 if(image->type == ImageTypeMetafile){
748 HDC hdc = GetDC(0);
750 *height = convert_unit(hdc, ((GpMetafile*)image)->unit) *
751 ((GpMetafile*)image)->bounds.Height;
753 *width = convert_unit(hdc, ((GpMetafile*)image)->unit) *
754 ((GpMetafile*)image)->bounds.Width;
756 ReleaseDC(0, hdc);
759 else if(image->type == ImageTypeBitmap){
760 *height = ((GpBitmap*)image)->height;
761 *width = ((GpBitmap*)image)->width;
763 else{
764 *height = ipicture_pixel_height(image->picture);
765 *width = ipicture_pixel_width(image->picture);
768 TRACE("returning (%f, %f)\n", *height, *width);
769 return Ok;
772 GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image,
773 GpGraphics **graphics)
775 HDC hdc;
777 TRACE("%p %p\n", image, graphics);
779 if(!image || !graphics)
780 return InvalidParameter;
782 if(image->type != ImageTypeBitmap){
783 FIXME("not implemented for image type %d\n", image->type);
784 return NotImplemented;
787 IPicture_get_CurDC(image->picture, &hdc);
789 if(!hdc){
790 hdc = CreateCompatibleDC(0);
791 IPicture_SelectPicture(image->picture, hdc, NULL, NULL);
794 return GdipCreateFromHDC(hdc, graphics);
797 GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
799 TRACE("%p %p\n", image, height);
801 if(!image || !height)
802 return InvalidParameter;
804 if(image->type == ImageTypeMetafile){
805 HDC hdc = GetDC(0);
807 *height = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
808 ((GpMetafile*)image)->bounds.Height);
810 ReleaseDC(0, hdc);
812 else if(image->type == ImageTypeBitmap)
813 *height = ((GpBitmap*)image)->height;
814 else
815 *height = ipicture_pixel_height(image->picture);
817 TRACE("returning %d\n", *height);
819 return Ok;
822 GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res)
824 static int calls;
826 if(!image || !res)
827 return InvalidParameter;
829 if(!(calls++))
830 FIXME("not implemented\n");
832 return NotImplemented;
835 GpStatus WINGDIPAPI GdipGetImagePaletteSize(GpImage *image, INT *size)
837 FIXME("%p %p\n", image, size);
839 if(!image || !size)
840 return InvalidParameter;
842 return NotImplemented;
845 /* FIXME: test this function for non-bitmap types */
846 GpStatus WINGDIPAPI GdipGetImagePixelFormat(GpImage *image, PixelFormat *format)
848 TRACE("%p %p\n", image, format);
850 if(!image || !format)
851 return InvalidParameter;
853 if(image->type != ImageTypeBitmap)
854 *format = PixelFormat24bppRGB;
855 else
856 *format = ((GpBitmap*) image)->format;
858 return Ok;
861 GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage *image, GUID *format)
863 static int calls;
865 if(!image || !format)
866 return InvalidParameter;
868 if(!(calls++))
869 FIXME("stub\n");
871 /* FIXME: should be detected from embedded picture or stored separately */
872 switch (image->type)
874 case ImageTypeBitmap: *format = ImageFormatBMP; break;
875 case ImageTypeMetafile: *format = ImageFormatEMF; break;
876 default:
877 WARN("unknown type %u\n", image->type);
878 *format = ImageFormatUndefined;
880 return Ok;
883 GpStatus WINGDIPAPI GdipGetImageType(GpImage *image, ImageType *type)
885 TRACE("%p %p\n", image, type);
887 if(!image || !type)
888 return InvalidParameter;
890 *type = image->type;
892 return Ok;
895 GpStatus WINGDIPAPI GdipGetImageVerticalResolution(GpImage *image, REAL *res)
897 static int calls;
899 if(!image || !res)
900 return InvalidParameter;
902 if(!(calls++))
903 FIXME("not implemented\n");
905 return NotImplemented;
908 GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
910 TRACE("%p %p\n", image, width);
912 if(!image || !width)
913 return InvalidParameter;
915 if(image->type == ImageTypeMetafile){
916 HDC hdc = GetDC(0);
918 *width = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
919 ((GpMetafile*)image)->bounds.Width);
921 ReleaseDC(0, hdc);
923 else if(image->type == ImageTypeBitmap)
924 *width = ((GpBitmap*)image)->width;
925 else
926 *width = ipicture_pixel_width(image->picture);
928 TRACE("returning %d\n", *width);
930 return Ok;
933 GpStatus WINGDIPAPI GdipGetMetafileHeaderFromMetafile(GpMetafile * metafile,
934 MetafileHeader * header)
936 static int calls;
938 if(!metafile || !header)
939 return InvalidParameter;
941 if(!(calls++))
942 FIXME("not implemented\n");
944 return Ok;
947 GpStatus WINGDIPAPI GdipGetAllPropertyItems(GpImage *image, UINT size,
948 UINT num, PropertyItem* items)
950 static int calls;
952 if(!(calls++))
953 FIXME("not implemented\n");
955 return InvalidParameter;
958 GpStatus WINGDIPAPI GdipGetPropertyCount(GpImage *image, UINT* num)
960 static int calls;
962 if(!(calls++))
963 FIXME("not implemented\n");
965 return InvalidParameter;
968 GpStatus WINGDIPAPI GdipGetPropertyIdList(GpImage *image, UINT num, PROPID* list)
970 static int calls;
972 if(!(calls++))
973 FIXME("not implemented\n");
975 return InvalidParameter;
978 GpStatus WINGDIPAPI GdipGetPropertyItem(GpImage *image, PROPID id, UINT size,
979 PropertyItem* buffer)
981 static int calls;
983 if(!(calls++))
984 FIXME("not implemented\n");
986 return InvalidParameter;
989 GpStatus WINGDIPAPI GdipGetPropertyItemSize(GpImage *image, PROPID pid,
990 UINT* size)
992 static int calls;
994 TRACE("%p %x %p\n", image, pid, size);
996 if(!size || !image)
997 return InvalidParameter;
999 if(!(calls++))
1000 FIXME("not implemented\n");
1002 return NotImplemented;
1005 GpStatus WINGDIPAPI GdipGetPropertySize(GpImage *image, UINT* size, UINT* num)
1007 static int calls;
1009 if(!(calls++))
1010 FIXME("not implemented\n");
1012 return InvalidParameter;
1015 GpStatus WINGDIPAPI GdipImageGetFrameCount(GpImage *image,
1016 GDIPCONST GUID* dimensionID, UINT* count)
1018 static int calls;
1020 if(!image || !dimensionID || !count)
1021 return InvalidParameter;
1023 if(!(calls++))
1024 FIXME("not implemented\n");
1026 return NotImplemented;
1029 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsCount(GpImage *image,
1030 UINT* count)
1032 if(!image || !count)
1033 return InvalidParameter;
1035 *count = 1;
1037 FIXME("stub\n");
1039 return Ok;
1042 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsList(GpImage* image,
1043 GUID* dimensionIDs, UINT count)
1045 static int calls;
1047 if(!image || !dimensionIDs)
1048 return InvalidParameter;
1050 if(!(calls++))
1051 FIXME("not implemented\n");
1053 return Ok;
1056 GpStatus WINGDIPAPI GdipImageSelectActiveFrame(GpImage *image,
1057 GDIPCONST GUID* dimensionID, UINT frameidx)
1059 static int calls;
1061 if(!image || !dimensionID)
1062 return InvalidParameter;
1064 if(!(calls++))
1065 FIXME("not implemented\n");
1067 return Ok;
1070 GpStatus WINGDIPAPI GdipLoadImageFromFile(GDIPCONST WCHAR* filename,
1071 GpImage **image)
1073 GpStatus stat;
1074 IStream *stream;
1076 TRACE("(%s) %p\n", debugstr_w(filename), image);
1078 if (!filename || !image)
1079 return InvalidParameter;
1081 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
1083 if (stat != Ok)
1084 return stat;
1086 stat = GdipLoadImageFromStream(stream, image);
1088 IStream_Release(stream);
1090 return stat;
1093 /* FIXME: no icm handling */
1094 GpStatus WINGDIPAPI GdipLoadImageFromFileICM(GDIPCONST WCHAR* filename,GpImage **image)
1096 TRACE("(%s) %p\n", debugstr_w(filename), image);
1098 return GdipLoadImageFromFile(filename, image);
1101 GpStatus WINGDIPAPI GdipLoadImageFromStream(IStream* stream, GpImage **image)
1103 IPicture *pic;
1104 short type;
1106 TRACE("%p %p\n", stream, image);
1108 if(!stream || !image)
1109 return InvalidParameter;
1111 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
1112 (LPVOID*) &pic) != S_OK){
1113 TRACE("Could not load picture\n");
1114 return GenericError;
1117 IPicture_get_Type(pic, &type);
1119 if(type == PICTYPE_BITMAP){
1120 BITMAPINFO *pbmi;
1121 BITMAPCOREHEADER* bmch;
1122 HBITMAP hbm;
1123 HDC hdc;
1125 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1126 if (!pbmi)
1127 return OutOfMemory;
1128 *image = GdipAlloc(sizeof(GpBitmap));
1129 if(!*image){
1130 GdipFree(pbmi);
1131 return OutOfMemory;
1133 (*image)->type = ImageTypeBitmap;
1135 (*((GpBitmap**) image))->width = ipicture_pixel_width(pic);
1136 (*((GpBitmap**) image))->height = ipicture_pixel_height(pic);
1138 /* get the pixel format */
1139 IPicture_get_Handle(pic, (OLE_HANDLE*)&hbm);
1140 IPicture_get_CurDC(pic, &hdc);
1142 bmch = (BITMAPCOREHEADER*) (&pbmi->bmiHeader);
1143 bmch->bcSize = sizeof(BITMAPCOREHEADER);
1145 if(!hdc){
1146 HBITMAP old;
1147 hdc = CreateCompatibleDC(0);
1148 old = SelectObject(hdc, hbm);
1149 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
1150 SelectObject(hdc, old);
1151 DeleteDC(hdc);
1153 else
1154 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
1156 switch(bmch->bcBitCount)
1158 case 1:
1159 (*((GpBitmap**) image))->format = PixelFormat1bppIndexed;
1160 break;
1161 case 4:
1162 (*((GpBitmap**) image))->format = PixelFormat4bppIndexed;
1163 break;
1164 case 8:
1165 (*((GpBitmap**) image))->format = PixelFormat8bppIndexed;
1166 break;
1167 case 16:
1168 (*((GpBitmap**) image))->format = PixelFormat16bppRGB565;
1169 break;
1170 case 24:
1171 (*((GpBitmap**) image))->format = PixelFormat24bppRGB;
1172 break;
1173 case 32:
1174 (*((GpBitmap**) image))->format = PixelFormat32bppRGB;
1175 break;
1176 case 48:
1177 (*((GpBitmap**) image))->format = PixelFormat48bppRGB;
1178 break;
1179 default:
1180 FIXME("Bit depth %d is not fully supported yet\n", bmch->bcBitCount);
1181 (*((GpBitmap**) image))->format = (bmch->bcBitCount << 8) | PixelFormatGDI;
1182 break;
1185 GdipFree(pbmi);
1187 else if(type == PICTYPE_METAFILE || type == PICTYPE_ENHMETAFILE){
1188 /* FIXME: missing initialization code */
1189 *image = GdipAlloc(sizeof(GpMetafile));
1190 if(!*image) return OutOfMemory;
1191 (*image)->type = ImageTypeMetafile;
1193 else{
1194 *image = GdipAlloc(sizeof(GpImage));
1195 if(!*image) return OutOfMemory;
1196 (*image)->type = ImageTypeUnknown;
1199 (*image)->picture = pic;
1200 (*image)->flags = ImageFlagsNone;
1202 return Ok;
1205 /* FIXME: no ICM */
1206 GpStatus WINGDIPAPI GdipLoadImageFromStreamICM(IStream* stream, GpImage **image)
1208 TRACE("%p %p\n", stream, image);
1210 return GdipLoadImageFromStream(stream, image);
1213 GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
1215 static int calls;
1217 if(!image)
1218 return InvalidParameter;
1220 if(!(calls++))
1221 FIXME("not implemented\n");
1223 return NotImplemented;
1226 GpStatus WINGDIPAPI GdipSetPropertyItem(GpImage *image, GDIPCONST PropertyItem* item)
1228 static int calls;
1230 if(!(calls++))
1231 FIXME("not implemented\n");
1233 return NotImplemented;
1236 GpStatus WINGDIPAPI GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
1237 GDIPCONST CLSID *clsidEncoder,
1238 GDIPCONST EncoderParameters *encoderParams)
1240 GpStatus stat;
1241 IStream *stream;
1243 TRACE("%p (%s) %p %p\n", image, debugstr_w(filename), clsidEncoder, encoderParams);
1245 if (!image || !filename|| !clsidEncoder)
1246 return InvalidParameter;
1248 if (!(image->picture))
1249 return InvalidParameter;
1251 stat = GdipCreateStreamOnFile(filename, GENERIC_WRITE, &stream);
1252 if (stat != Ok)
1253 return GenericError;
1255 stat = GdipSaveImageToStream(image, stream, clsidEncoder, encoderParams);
1257 IStream_Release(stream);
1258 return stat;
1261 /*************************************************************************
1262 * Encoding functions -
1263 * These functions encode an image in different image file formats.
1265 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
1266 #define BITMAP_FORMAT_JPEG 0xd8ff
1267 #define BITMAP_FORMAT_GIF 0x4947
1268 #define BITMAP_FORMAT_PNG 0x5089
1269 #define BITMAP_FORMAT_APM 0xcdd7
1271 static GpStatus encode_image_BMP(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
1272 void **output, unsigned int *output_size)
1274 int num_palette_entries;
1275 BITMAPFILEHEADER *bmp_file_hdr;
1276 BITMAPINFO *bmp_info_hdr;
1278 if (bitmap_info->bmiHeader.biClrUsed) {
1279 num_palette_entries = bitmap_info->bmiHeader.biClrUsed;
1280 if (num_palette_entries > 256) num_palette_entries = 256;
1281 } else {
1282 if (bitmap_info->bmiHeader.biBitCount <= 8)
1283 num_palette_entries = 1 << bitmap_info->bmiHeader.biBitCount;
1284 else
1285 num_palette_entries = 0;
1288 *output_size =
1289 sizeof(BITMAPFILEHEADER) +
1290 sizeof(BITMAPINFOHEADER) +
1291 num_palette_entries * sizeof(RGBQUAD) +
1292 bitmap_info->bmiHeader.biSizeImage;
1294 *output = GdipAlloc(*output_size);
1296 bmp_file_hdr = *output;
1297 bmp_file_hdr->bfType = BITMAP_FORMAT_BMP;
1298 bmp_file_hdr->bfSize = *output_size;
1299 bmp_file_hdr->bfOffBits =
1300 sizeof(BITMAPFILEHEADER) +
1301 sizeof(BITMAPINFOHEADER) +
1302 num_palette_entries * sizeof (RGBQUAD);
1304 bmp_info_hdr = (BITMAPINFO*) ((unsigned char*)(*output) + sizeof(BITMAPFILEHEADER));
1305 memcpy(bmp_info_hdr, bitmap_info, sizeof(BITMAPINFOHEADER) + num_palette_entries * sizeof(RGBQUAD));
1306 memcpy((unsigned char *)(*output) +
1307 sizeof(BITMAPFILEHEADER) +
1308 sizeof(BITMAPINFOHEADER) +
1309 num_palette_entries * sizeof(RGBQUAD),
1310 bitmap_bits, bitmap_info->bmiHeader.biSizeImage);
1312 return Ok;
1315 typedef GpStatus encode_image_func(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
1316 void **output, unsigned int *output_size);
1318 typedef enum {
1319 BMP,
1320 NUM_ENCODERS_SUPPORTED
1321 } ImageFormat;
1323 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED];
1324 static encode_image_func *const encode_image_funcs[NUM_ENCODERS_SUPPORTED] = {
1325 encode_image_BMP,
1328 /*****************************************************************************
1329 * GdipSaveImageToStream [GDIPLUS.@]
1331 GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
1332 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
1334 GpStatus stat;
1335 HRESULT hr;
1336 short type;
1337 HBITMAP hbmp;
1338 HBITMAP old_hbmp;
1339 HDC hdc;
1340 int bm_is_selected;
1341 BITMAPINFO bmp_info;
1342 LPVOID bmp_bits;
1343 encode_image_func* encode_image;
1344 LPVOID output;
1345 unsigned int output_size;
1346 unsigned int dummy;
1347 int i;
1349 old_hbmp = 0;
1350 output = NULL;
1351 output_size = 0;
1353 TRACE("%p %p %p %p\n", image, stream, clsid, params);
1355 if(!image || !stream)
1356 return InvalidParameter;
1358 if (!image->picture)
1359 return GenericError;
1361 hr = IPicture_get_Type(image->picture, &type);
1362 if (FAILED(hr) || type != PICTYPE_BITMAP)
1363 return GenericError;
1365 /* select correct encoder */
1366 encode_image = NULL;
1367 for (i = 0; i < NUM_ENCODERS_SUPPORTED; i++) {
1368 if (IsEqualCLSID(clsid, &codecs[i].Clsid))
1369 encode_image = encode_image_funcs[i];
1371 if (encode_image == NULL)
1372 return UnknownImageFormat;
1374 /* extract underlying hbitmap representation from the IPicture */
1375 hr = IPicture_get_Handle(image->picture, (OLE_HANDLE*)&hbmp);
1376 if (FAILED(hr) || !hbmp)
1377 return GenericError;
1378 hr = IPicture_get_CurDC(image->picture, &hdc);
1379 if (FAILED(hr))
1380 return GenericError;
1381 bm_is_selected = (hdc != 0);
1382 if (!bm_is_selected) {
1383 hdc = CreateCompatibleDC(0);
1384 old_hbmp = SelectObject(hdc, hbmp);
1387 /* get bits from HBITMAP */
1388 bmp_info.bmiHeader.biSize = sizeof(bmp_info.bmiHeader);
1389 bmp_info.bmiHeader.biBitCount = 0;
1390 GetDIBits(hdc, hbmp, 0, 0, NULL, &bmp_info, DIB_RGB_COLORS);
1392 bmp_bits = GdipAlloc(bmp_info.bmiHeader.biSizeImage);
1394 if (bmp_bits)
1395 GetDIBits(hdc, hbmp, 0, abs(bmp_info.bmiHeader.biHeight), bmp_bits, &bmp_info, DIB_RGB_COLORS);
1397 if (!bm_is_selected) {
1398 SelectObject(hdc, old_hbmp);
1399 DeleteDC(hdc);
1402 if (!bmp_bits)
1403 return OutOfMemory;
1405 stat = encode_image(bmp_bits, &bmp_info, &output, &output_size);
1406 if (stat == Ok)
1407 IStream_Write(stream, output, output_size, &dummy);
1409 GdipFree(output);
1410 GdipFree(bmp_bits);
1412 return stat;
1415 /*****************************************************************************
1416 * GdipSetImagePalette [GDIPLUS.@]
1418 GpStatus WINGDIPAPI GdipSetImagePalette(GpImage *image,
1419 GDIPCONST ColorPalette *palette)
1421 static int calls;
1423 if(!image || !palette)
1424 return InvalidParameter;
1426 if(!(calls++))
1427 FIXME("not implemented\n");
1429 return NotImplemented;
1432 /*************************************************************************
1433 * Encoders -
1434 * Structures that represent which formats we support for encoding.
1437 /* ImageCodecInfo creation routines taken from libgdiplus */
1438 static const WCHAR bmp_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
1439 static const WCHAR bmp_extension[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
1440 static const WCHAR bmp_mimetype[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
1441 static const WCHAR bmp_format[] = {'B', 'M', 'P', 0}; /* BMP */
1442 static const BYTE bmp_sig_pattern[] = { 0x42, 0x4D };
1443 static const BYTE bmp_sig_mask[] = { 0xFF, 0xFF };
1445 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED] =
1447 { /* BMP */
1448 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
1449 /* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
1450 /* CodecName */ bmp_codecname,
1451 /* DllName */ NULL,
1452 /* FormatDescription */ bmp_format,
1453 /* FilenameExtension */ bmp_extension,
1454 /* MimeType */ bmp_mimetype,
1455 /* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
1456 /* Version */ 1,
1457 /* SigCount */ 1,
1458 /* SigSize */ 2,
1459 /* SigPattern */ bmp_sig_pattern,
1460 /* SigMask */ bmp_sig_mask,
1464 /*****************************************************************************
1465 * GdipGetImageDecodersSize [GDIPLUS.@]
1467 GpStatus WINGDIPAPI GdipGetImageDecodersSize(UINT *numDecoders, UINT *size)
1469 FIXME("%p %p stub!\n", numDecoders, size);
1471 if (!numDecoders || !size)
1472 return InvalidParameter;
1474 *numDecoders = 0;
1475 *size = 0;
1477 return Ok;
1480 /*****************************************************************************
1481 * GdipGetImageDecoders [GDIPLUS.@]
1483 GpStatus WINGDIPAPI GdipGetImageDecoders(UINT numDecoders, UINT size, ImageCodecInfo *decoders)
1485 FIXME("%u %u %p stub!\n", numDecoders, size, decoders);
1487 if (!decoders)
1488 return GenericError;
1490 return NotImplemented;
1493 /*****************************************************************************
1494 * GdipGetImageEncodersSize [GDIPLUS.@]
1496 GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size)
1498 TRACE("%p %p\n", numEncoders, size);
1500 if (!numEncoders || !size)
1501 return InvalidParameter;
1503 *numEncoders = NUM_ENCODERS_SUPPORTED;
1504 *size = sizeof (codecs);
1506 return Ok;
1509 /*****************************************************************************
1510 * GdipGetImageEncoders [GDIPLUS.@]
1512 GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders)
1514 TRACE("%u %u %p\n", numEncoders, size, encoders);
1516 if (!encoders ||
1517 (numEncoders != NUM_ENCODERS_SUPPORTED) ||
1518 (size != sizeof (codecs)))
1519 return GenericError;
1521 memcpy(encoders, codecs, sizeof (codecs));
1523 return Ok;
1526 /*****************************************************************************
1527 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
1529 GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBitmap** bitmap)
1531 BITMAP bm;
1532 GpStatus retval;
1533 PixelFormat format;
1534 BYTE* bits;
1536 TRACE("%p %p %p\n", hbm, hpal, bitmap);
1538 if(!hbm || !bitmap)
1539 return InvalidParameter;
1541 /* TODO: Support for device-dependent bitmaps */
1542 if(hpal){
1543 FIXME("no support for device-dependent bitmaps\n");
1544 return NotImplemented;
1547 if (GetObjectA(hbm, sizeof(bm), &bm) != sizeof(bm))
1548 return InvalidParameter;
1550 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
1551 switch(bm.bmBitsPixel) {
1552 case 1:
1553 format = PixelFormat1bppIndexed;
1554 break;
1555 case 4:
1556 format = PixelFormat4bppIndexed;
1557 break;
1558 case 8:
1559 format = PixelFormat8bppIndexed;
1560 break;
1561 case 24:
1562 format = PixelFormat24bppRGB;
1563 break;
1564 case 32:
1565 format = PixelFormat32bppRGB;
1566 break;
1567 case 48:
1568 format = PixelFormat48bppRGB;
1569 break;
1570 default:
1571 FIXME("don't know how to handle %d bpp\n", bm.bmBitsPixel);
1572 return InvalidParameter;
1575 if (bm.bmBits)
1576 bits = (BYTE*)bm.bmBits + (bm.bmHeight - 1) * bm.bmWidthBytes;
1577 else
1579 FIXME("can only get image data from DIB sections\n");
1580 bits = NULL;
1583 retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, -bm.bmWidthBytes,
1584 format, bits, bitmap);
1586 return retval;
1589 /*****************************************************************************
1590 * GdipSetEffectParameters [GDIPLUS.@]
1592 GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect *effect,
1593 const VOID *params, const UINT size)
1595 static int calls;
1597 if(!(calls++))
1598 FIXME("not implemented\n");
1600 return NotImplemented;
1603 /*****************************************************************************
1604 * GdipGetImageFlags [GDIPLUS.@]
1606 GpStatus WINGDIPAPI GdipGetImageFlags(GpImage *image, UINT *flags)
1608 TRACE("%p %p\n", image, flags);
1610 if(!image || !flags)
1611 return InvalidParameter;
1613 *flags = image->flags;
1615 return Ok;
1618 GpStatus WINGDIPAPI GdipTestControl(GpTestControlEnum control, void *param)
1620 TRACE("(%d, %p)\n", control, param);
1622 switch(control){
1623 case TestControlForceBilinear:
1624 if(param)
1625 FIXME("TestControlForceBilinear not handled\n");
1626 break;
1627 case TestControlNoICM:
1628 if(param)
1629 FIXME("TestControlNoICM not handled\n");
1630 break;
1631 case TestControlGetBuildNumber:
1632 *((DWORD*)param) = 3102;
1633 break;
1636 return Ok;
1639 GpStatus WINGDIPAPI GdipRecordMetafileFileName(GDIPCONST WCHAR* fileName,
1640 HDC hdc, EmfType type, GDIPCONST GpRectF *pFrameRect,
1641 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc,
1642 GpMetafile **metafile)
1644 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
1645 frameUnit, debugstr_w(desc), metafile);
1647 return NotImplemented;
1650 GpStatus WINGDIPAPI GdipRecordMetafileFileNameI(GDIPCONST WCHAR* fileName, HDC hdc, EmfType type,
1651 GDIPCONST GpRect *pFrameRect, MetafileFrameUnit frameUnit,
1652 GDIPCONST WCHAR *desc, GpMetafile **metafile)
1654 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
1655 frameUnit, debugstr_w(desc), metafile);
1657 return NotImplemented;
1660 GpStatus WINGDIPAPI GdipImageForceValidation(GpImage *image)
1662 FIXME("%p\n", image);
1664 return Ok;