push 0a0aa53cd365a71ca6121b6df157ca635450378f
[wine/hacks.git] / dlls / gdiplus / image.c
blob29eb00026b8b057778dc0d11280b05664b345135
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 GdipCreateHICONFromBitmap(GpBitmap *bitmap, HICON *hicon)
660 FIXME("(%p, %p)\n", bitmap, hicon);
662 return NotImplemented;
665 GpStatus WINGDIPAPI GdipDeleteCachedBitmap(GpCachedBitmap *cachedbmp)
667 TRACE("%p\n", cachedbmp);
669 if(!cachedbmp)
670 return InvalidParameter;
672 GdipDisposeImage(cachedbmp->image);
673 GdipFree(cachedbmp);
675 return Ok;
678 GpStatus WINGDIPAPI GdipDrawCachedBitmap(GpGraphics *graphics,
679 GpCachedBitmap *cachedbmp, INT x, INT y)
681 TRACE("%p %p %d %d\n", graphics, cachedbmp, x, y);
683 if(!graphics || !cachedbmp)
684 return InvalidParameter;
686 return GdipDrawImage(graphics, cachedbmp->image, (REAL)x, (REAL)y);
689 GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
691 HDC hdc;
693 TRACE("%p\n", image);
695 if(!image)
696 return InvalidParameter;
698 IPicture_get_CurDC(image->picture, &hdc);
699 DeleteDC(hdc);
700 IPicture_Release(image->picture);
701 if (image->type == ImageTypeBitmap)
702 GdipFree(((GpBitmap*)image)->bitmapbits);
703 GdipFree(image);
705 return Ok;
708 GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage *image, ImageItemData* item)
710 if(!image || !item)
711 return InvalidParameter;
713 return NotImplemented;
716 GpStatus WINGDIPAPI GdipGetImageBounds(GpImage *image, GpRectF *srcRect,
717 GpUnit *srcUnit)
719 TRACE("%p %p %p\n", image, srcRect, srcUnit);
721 if(!image || !srcRect || !srcUnit)
722 return InvalidParameter;
723 if(image->type == ImageTypeMetafile){
724 *srcRect = ((GpMetafile*)image)->bounds;
725 *srcUnit = ((GpMetafile*)image)->unit;
727 else if(image->type == ImageTypeBitmap){
728 srcRect->X = srcRect->Y = 0.0;
729 srcRect->Width = (REAL) ((GpBitmap*)image)->width;
730 srcRect->Height = (REAL) ((GpBitmap*)image)->height;
731 *srcUnit = UnitPixel;
733 else{
734 srcRect->X = srcRect->Y = 0.0;
735 srcRect->Width = ipicture_pixel_width(image->picture);
736 srcRect->Height = ipicture_pixel_height(image->picture);
737 *srcUnit = UnitPixel;
740 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect->X, srcRect->Y,
741 srcRect->Width, srcRect->Height, *srcUnit);
743 return Ok;
746 GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
747 REAL *height)
749 TRACE("%p %p %p\n", image, width, height);
751 if(!image || !height || !width)
752 return InvalidParameter;
754 if(image->type == ImageTypeMetafile){
755 HDC hdc = GetDC(0);
757 *height = convert_unit(hdc, ((GpMetafile*)image)->unit) *
758 ((GpMetafile*)image)->bounds.Height;
760 *width = convert_unit(hdc, ((GpMetafile*)image)->unit) *
761 ((GpMetafile*)image)->bounds.Width;
763 ReleaseDC(0, hdc);
766 else if(image->type == ImageTypeBitmap){
767 *height = ((GpBitmap*)image)->height;
768 *width = ((GpBitmap*)image)->width;
770 else{
771 *height = ipicture_pixel_height(image->picture);
772 *width = ipicture_pixel_width(image->picture);
775 TRACE("returning (%f, %f)\n", *height, *width);
776 return Ok;
779 GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image,
780 GpGraphics **graphics)
782 HDC hdc;
784 TRACE("%p %p\n", image, graphics);
786 if(!image || !graphics)
787 return InvalidParameter;
789 if(image->type != ImageTypeBitmap){
790 FIXME("not implemented for image type %d\n", image->type);
791 return NotImplemented;
794 IPicture_get_CurDC(image->picture, &hdc);
796 if(!hdc){
797 hdc = CreateCompatibleDC(0);
798 IPicture_SelectPicture(image->picture, hdc, NULL, NULL);
801 return GdipCreateFromHDC(hdc, graphics);
804 GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
806 TRACE("%p %p\n", image, height);
808 if(!image || !height)
809 return InvalidParameter;
811 if(image->type == ImageTypeMetafile){
812 HDC hdc = GetDC(0);
814 *height = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
815 ((GpMetafile*)image)->bounds.Height);
817 ReleaseDC(0, hdc);
819 else if(image->type == ImageTypeBitmap)
820 *height = ((GpBitmap*)image)->height;
821 else
822 *height = ipicture_pixel_height(image->picture);
824 TRACE("returning %d\n", *height);
826 return Ok;
829 GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res)
831 static int calls;
833 if(!image || !res)
834 return InvalidParameter;
836 if(!(calls++))
837 FIXME("not implemented\n");
839 return NotImplemented;
842 GpStatus WINGDIPAPI GdipGetImagePaletteSize(GpImage *image, INT *size)
844 FIXME("%p %p\n", image, size);
846 if(!image || !size)
847 return InvalidParameter;
849 return NotImplemented;
852 /* FIXME: test this function for non-bitmap types */
853 GpStatus WINGDIPAPI GdipGetImagePixelFormat(GpImage *image, PixelFormat *format)
855 TRACE("%p %p\n", image, format);
857 if(!image || !format)
858 return InvalidParameter;
860 if(image->type != ImageTypeBitmap)
861 *format = PixelFormat24bppRGB;
862 else
863 *format = ((GpBitmap*) image)->format;
865 return Ok;
868 GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage *image, GUID *format)
870 static int calls;
872 if(!image || !format)
873 return InvalidParameter;
875 if(!(calls++))
876 FIXME("stub\n");
878 /* FIXME: should be detected from embedded picture or stored separately */
879 switch (image->type)
881 case ImageTypeBitmap: *format = ImageFormatBMP; break;
882 case ImageTypeMetafile: *format = ImageFormatEMF; break;
883 default:
884 WARN("unknown type %u\n", image->type);
885 *format = ImageFormatUndefined;
887 return Ok;
890 GpStatus WINGDIPAPI GdipGetImageType(GpImage *image, ImageType *type)
892 TRACE("%p %p\n", image, type);
894 if(!image || !type)
895 return InvalidParameter;
897 *type = image->type;
899 return Ok;
902 GpStatus WINGDIPAPI GdipGetImageVerticalResolution(GpImage *image, REAL *res)
904 static int calls;
906 if(!image || !res)
907 return InvalidParameter;
909 if(!(calls++))
910 FIXME("not implemented\n");
912 return NotImplemented;
915 GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
917 TRACE("%p %p\n", image, width);
919 if(!image || !width)
920 return InvalidParameter;
922 if(image->type == ImageTypeMetafile){
923 HDC hdc = GetDC(0);
925 *width = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
926 ((GpMetafile*)image)->bounds.Width);
928 ReleaseDC(0, hdc);
930 else if(image->type == ImageTypeBitmap)
931 *width = ((GpBitmap*)image)->width;
932 else
933 *width = ipicture_pixel_width(image->picture);
935 TRACE("returning %d\n", *width);
937 return Ok;
940 GpStatus WINGDIPAPI GdipGetMetafileHeaderFromMetafile(GpMetafile * metafile,
941 MetafileHeader * header)
943 static int calls;
945 if(!metafile || !header)
946 return InvalidParameter;
948 if(!(calls++))
949 FIXME("not implemented\n");
951 return Ok;
954 GpStatus WINGDIPAPI GdipGetAllPropertyItems(GpImage *image, UINT size,
955 UINT num, PropertyItem* items)
957 static int calls;
959 if(!(calls++))
960 FIXME("not implemented\n");
962 return InvalidParameter;
965 GpStatus WINGDIPAPI GdipGetPropertyCount(GpImage *image, UINT* num)
967 static int calls;
969 if(!(calls++))
970 FIXME("not implemented\n");
972 return InvalidParameter;
975 GpStatus WINGDIPAPI GdipGetPropertyIdList(GpImage *image, UINT num, PROPID* list)
977 static int calls;
979 if(!(calls++))
980 FIXME("not implemented\n");
982 return InvalidParameter;
985 GpStatus WINGDIPAPI GdipGetPropertyItem(GpImage *image, PROPID id, UINT size,
986 PropertyItem* buffer)
988 static int calls;
990 if(!(calls++))
991 FIXME("not implemented\n");
993 return InvalidParameter;
996 GpStatus WINGDIPAPI GdipGetPropertyItemSize(GpImage *image, PROPID pid,
997 UINT* size)
999 static int calls;
1001 TRACE("%p %x %p\n", image, pid, size);
1003 if(!size || !image)
1004 return InvalidParameter;
1006 if(!(calls++))
1007 FIXME("not implemented\n");
1009 return NotImplemented;
1012 GpStatus WINGDIPAPI GdipGetPropertySize(GpImage *image, UINT* size, UINT* num)
1014 static int calls;
1016 if(!(calls++))
1017 FIXME("not implemented\n");
1019 return InvalidParameter;
1022 GpStatus WINGDIPAPI GdipImageGetFrameCount(GpImage *image,
1023 GDIPCONST GUID* dimensionID, UINT* count)
1025 static int calls;
1027 if(!image || !dimensionID || !count)
1028 return InvalidParameter;
1030 if(!(calls++))
1031 FIXME("not implemented\n");
1033 return NotImplemented;
1036 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsCount(GpImage *image,
1037 UINT* count)
1039 if(!image || !count)
1040 return InvalidParameter;
1042 *count = 1;
1044 FIXME("stub\n");
1046 return Ok;
1049 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsList(GpImage* image,
1050 GUID* dimensionIDs, UINT count)
1052 static int calls;
1054 if(!image || !dimensionIDs)
1055 return InvalidParameter;
1057 if(!(calls++))
1058 FIXME("not implemented\n");
1060 return Ok;
1063 GpStatus WINGDIPAPI GdipImageSelectActiveFrame(GpImage *image,
1064 GDIPCONST GUID* dimensionID, UINT frameidx)
1066 static int calls;
1068 if(!image || !dimensionID)
1069 return InvalidParameter;
1071 if(!(calls++))
1072 FIXME("not implemented\n");
1074 return Ok;
1077 GpStatus WINGDIPAPI GdipLoadImageFromFile(GDIPCONST WCHAR* filename,
1078 GpImage **image)
1080 GpStatus stat;
1081 IStream *stream;
1083 TRACE("(%s) %p\n", debugstr_w(filename), image);
1085 if (!filename || !image)
1086 return InvalidParameter;
1088 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
1090 if (stat != Ok)
1091 return stat;
1093 stat = GdipLoadImageFromStream(stream, image);
1095 IStream_Release(stream);
1097 return stat;
1100 /* FIXME: no icm handling */
1101 GpStatus WINGDIPAPI GdipLoadImageFromFileICM(GDIPCONST WCHAR* filename,GpImage **image)
1103 TRACE("(%s) %p\n", debugstr_w(filename), image);
1105 return GdipLoadImageFromFile(filename, image);
1108 GpStatus WINGDIPAPI GdipLoadImageFromStream(IStream* stream, GpImage **image)
1110 IPicture *pic;
1111 short type;
1113 TRACE("%p %p\n", stream, image);
1115 if(!stream || !image)
1116 return InvalidParameter;
1118 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
1119 (LPVOID*) &pic) != S_OK){
1120 TRACE("Could not load picture\n");
1121 return GenericError;
1124 IPicture_get_Type(pic, &type);
1126 if(type == PICTYPE_BITMAP){
1127 BITMAPINFO *pbmi;
1128 BITMAPCOREHEADER* bmch;
1129 HBITMAP hbm;
1130 HDC hdc;
1132 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1133 if (!pbmi)
1134 return OutOfMemory;
1135 *image = GdipAlloc(sizeof(GpBitmap));
1136 if(!*image){
1137 GdipFree(pbmi);
1138 return OutOfMemory;
1140 (*image)->type = ImageTypeBitmap;
1142 (*((GpBitmap**) image))->width = ipicture_pixel_width(pic);
1143 (*((GpBitmap**) image))->height = ipicture_pixel_height(pic);
1145 /* get the pixel format */
1146 IPicture_get_Handle(pic, (OLE_HANDLE*)&hbm);
1147 IPicture_get_CurDC(pic, &hdc);
1149 bmch = (BITMAPCOREHEADER*) (&pbmi->bmiHeader);
1150 bmch->bcSize = sizeof(BITMAPCOREHEADER);
1152 if(!hdc){
1153 HBITMAP old;
1154 hdc = CreateCompatibleDC(0);
1155 old = SelectObject(hdc, hbm);
1156 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
1157 SelectObject(hdc, old);
1158 DeleteDC(hdc);
1160 else
1161 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
1163 switch(bmch->bcBitCount)
1165 case 1:
1166 (*((GpBitmap**) image))->format = PixelFormat1bppIndexed;
1167 break;
1168 case 4:
1169 (*((GpBitmap**) image))->format = PixelFormat4bppIndexed;
1170 break;
1171 case 8:
1172 (*((GpBitmap**) image))->format = PixelFormat8bppIndexed;
1173 break;
1174 case 16:
1175 (*((GpBitmap**) image))->format = PixelFormat16bppRGB565;
1176 break;
1177 case 24:
1178 (*((GpBitmap**) image))->format = PixelFormat24bppRGB;
1179 break;
1180 case 32:
1181 (*((GpBitmap**) image))->format = PixelFormat32bppRGB;
1182 break;
1183 case 48:
1184 (*((GpBitmap**) image))->format = PixelFormat48bppRGB;
1185 break;
1186 default:
1187 FIXME("Bit depth %d is not fully supported yet\n", bmch->bcBitCount);
1188 (*((GpBitmap**) image))->format = (bmch->bcBitCount << 8) | PixelFormatGDI;
1189 break;
1192 GdipFree(pbmi);
1194 else if(type == PICTYPE_METAFILE || type == PICTYPE_ENHMETAFILE){
1195 /* FIXME: missing initialization code */
1196 *image = GdipAlloc(sizeof(GpMetafile));
1197 if(!*image) return OutOfMemory;
1198 (*image)->type = ImageTypeMetafile;
1200 else{
1201 *image = GdipAlloc(sizeof(GpImage));
1202 if(!*image) return OutOfMemory;
1203 (*image)->type = ImageTypeUnknown;
1206 (*image)->picture = pic;
1207 (*image)->flags = ImageFlagsNone;
1209 return Ok;
1212 /* FIXME: no ICM */
1213 GpStatus WINGDIPAPI GdipLoadImageFromStreamICM(IStream* stream, GpImage **image)
1215 TRACE("%p %p\n", stream, image);
1217 return GdipLoadImageFromStream(stream, image);
1220 GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
1222 static int calls;
1224 if(!image)
1225 return InvalidParameter;
1227 if(!(calls++))
1228 FIXME("not implemented\n");
1230 return NotImplemented;
1233 GpStatus WINGDIPAPI GdipSetPropertyItem(GpImage *image, GDIPCONST PropertyItem* item)
1235 static int calls;
1237 if(!(calls++))
1238 FIXME("not implemented\n");
1240 return NotImplemented;
1243 GpStatus WINGDIPAPI GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
1244 GDIPCONST CLSID *clsidEncoder,
1245 GDIPCONST EncoderParameters *encoderParams)
1247 GpStatus stat;
1248 IStream *stream;
1250 TRACE("%p (%s) %p %p\n", image, debugstr_w(filename), clsidEncoder, encoderParams);
1252 if (!image || !filename|| !clsidEncoder)
1253 return InvalidParameter;
1255 if (!(image->picture))
1256 return InvalidParameter;
1258 stat = GdipCreateStreamOnFile(filename, GENERIC_WRITE, &stream);
1259 if (stat != Ok)
1260 return GenericError;
1262 stat = GdipSaveImageToStream(image, stream, clsidEncoder, encoderParams);
1264 IStream_Release(stream);
1265 return stat;
1268 /*************************************************************************
1269 * Encoding functions -
1270 * These functions encode an image in different image file formats.
1272 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
1273 #define BITMAP_FORMAT_JPEG 0xd8ff
1274 #define BITMAP_FORMAT_GIF 0x4947
1275 #define BITMAP_FORMAT_PNG 0x5089
1276 #define BITMAP_FORMAT_APM 0xcdd7
1278 static GpStatus encode_image_BMP(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
1279 void **output, unsigned int *output_size)
1281 int num_palette_entries;
1282 BITMAPFILEHEADER *bmp_file_hdr;
1283 BITMAPINFO *bmp_info_hdr;
1285 if (bitmap_info->bmiHeader.biClrUsed) {
1286 num_palette_entries = bitmap_info->bmiHeader.biClrUsed;
1287 if (num_palette_entries > 256) num_palette_entries = 256;
1288 } else {
1289 if (bitmap_info->bmiHeader.biBitCount <= 8)
1290 num_palette_entries = 1 << bitmap_info->bmiHeader.biBitCount;
1291 else
1292 num_palette_entries = 0;
1295 *output_size =
1296 sizeof(BITMAPFILEHEADER) +
1297 sizeof(BITMAPINFOHEADER) +
1298 num_palette_entries * sizeof(RGBQUAD) +
1299 bitmap_info->bmiHeader.biSizeImage;
1301 *output = GdipAlloc(*output_size);
1303 bmp_file_hdr = *output;
1304 bmp_file_hdr->bfType = BITMAP_FORMAT_BMP;
1305 bmp_file_hdr->bfSize = *output_size;
1306 bmp_file_hdr->bfOffBits =
1307 sizeof(BITMAPFILEHEADER) +
1308 sizeof(BITMAPINFOHEADER) +
1309 num_palette_entries * sizeof (RGBQUAD);
1311 bmp_info_hdr = (BITMAPINFO*) ((unsigned char*)(*output) + sizeof(BITMAPFILEHEADER));
1312 memcpy(bmp_info_hdr, bitmap_info, sizeof(BITMAPINFOHEADER) + num_palette_entries * sizeof(RGBQUAD));
1313 memcpy((unsigned char *)(*output) +
1314 sizeof(BITMAPFILEHEADER) +
1315 sizeof(BITMAPINFOHEADER) +
1316 num_palette_entries * sizeof(RGBQUAD),
1317 bitmap_bits, bitmap_info->bmiHeader.biSizeImage);
1319 return Ok;
1322 typedef GpStatus encode_image_func(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
1323 void **output, unsigned int *output_size);
1325 typedef enum {
1326 BMP,
1327 NUM_ENCODERS_SUPPORTED
1328 } ImageFormat;
1330 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED];
1331 static encode_image_func *const encode_image_funcs[NUM_ENCODERS_SUPPORTED] = {
1332 encode_image_BMP,
1335 /*****************************************************************************
1336 * GdipSaveImageToStream [GDIPLUS.@]
1338 GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
1339 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
1341 GpStatus stat;
1342 HRESULT hr;
1343 short type;
1344 HBITMAP hbmp;
1345 HBITMAP old_hbmp;
1346 HDC hdc;
1347 int bm_is_selected;
1348 BITMAPINFO bmp_info;
1349 LPVOID bmp_bits;
1350 encode_image_func* encode_image;
1351 LPVOID output;
1352 unsigned int output_size;
1353 unsigned int dummy;
1354 int i;
1356 old_hbmp = 0;
1357 output = NULL;
1358 output_size = 0;
1360 TRACE("%p %p %p %p\n", image, stream, clsid, params);
1362 if(!image || !stream)
1363 return InvalidParameter;
1365 if (!image->picture)
1366 return GenericError;
1368 hr = IPicture_get_Type(image->picture, &type);
1369 if (FAILED(hr) || type != PICTYPE_BITMAP)
1370 return GenericError;
1372 /* select correct encoder */
1373 encode_image = NULL;
1374 for (i = 0; i < NUM_ENCODERS_SUPPORTED; i++) {
1375 if (IsEqualCLSID(clsid, &codecs[i].Clsid))
1376 encode_image = encode_image_funcs[i];
1378 if (encode_image == NULL)
1379 return UnknownImageFormat;
1381 /* extract underlying hbitmap representation from the IPicture */
1382 hr = IPicture_get_Handle(image->picture, (OLE_HANDLE*)&hbmp);
1383 if (FAILED(hr) || !hbmp)
1384 return GenericError;
1385 hr = IPicture_get_CurDC(image->picture, &hdc);
1386 if (FAILED(hr))
1387 return GenericError;
1388 bm_is_selected = (hdc != 0);
1389 if (!bm_is_selected) {
1390 hdc = CreateCompatibleDC(0);
1391 old_hbmp = SelectObject(hdc, hbmp);
1394 /* get bits from HBITMAP */
1395 bmp_info.bmiHeader.biSize = sizeof(bmp_info.bmiHeader);
1396 bmp_info.bmiHeader.biBitCount = 0;
1397 GetDIBits(hdc, hbmp, 0, 0, NULL, &bmp_info, DIB_RGB_COLORS);
1399 bmp_bits = GdipAlloc(bmp_info.bmiHeader.biSizeImage);
1401 if (bmp_bits)
1402 GetDIBits(hdc, hbmp, 0, abs(bmp_info.bmiHeader.biHeight), bmp_bits, &bmp_info, DIB_RGB_COLORS);
1404 if (!bm_is_selected) {
1405 SelectObject(hdc, old_hbmp);
1406 DeleteDC(hdc);
1409 if (!bmp_bits)
1410 return OutOfMemory;
1412 stat = encode_image(bmp_bits, &bmp_info, &output, &output_size);
1413 if (stat == Ok)
1414 IStream_Write(stream, output, output_size, &dummy);
1416 GdipFree(output);
1417 GdipFree(bmp_bits);
1419 return stat;
1422 /*****************************************************************************
1423 * GdipSetImagePalette [GDIPLUS.@]
1425 GpStatus WINGDIPAPI GdipSetImagePalette(GpImage *image,
1426 GDIPCONST ColorPalette *palette)
1428 static int calls;
1430 if(!image || !palette)
1431 return InvalidParameter;
1433 if(!(calls++))
1434 FIXME("not implemented\n");
1436 return NotImplemented;
1439 /*************************************************************************
1440 * Encoders -
1441 * Structures that represent which formats we support for encoding.
1444 /* ImageCodecInfo creation routines taken from libgdiplus */
1445 static const WCHAR bmp_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
1446 static const WCHAR bmp_extension[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
1447 static const WCHAR bmp_mimetype[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
1448 static const WCHAR bmp_format[] = {'B', 'M', 'P', 0}; /* BMP */
1449 static const BYTE bmp_sig_pattern[] = { 0x42, 0x4D };
1450 static const BYTE bmp_sig_mask[] = { 0xFF, 0xFF };
1452 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED] =
1454 { /* BMP */
1455 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
1456 /* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
1457 /* CodecName */ bmp_codecname,
1458 /* DllName */ NULL,
1459 /* FormatDescription */ bmp_format,
1460 /* FilenameExtension */ bmp_extension,
1461 /* MimeType */ bmp_mimetype,
1462 /* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
1463 /* Version */ 1,
1464 /* SigCount */ 1,
1465 /* SigSize */ 2,
1466 /* SigPattern */ bmp_sig_pattern,
1467 /* SigMask */ bmp_sig_mask,
1471 /*****************************************************************************
1472 * GdipGetImageDecodersSize [GDIPLUS.@]
1474 GpStatus WINGDIPAPI GdipGetImageDecodersSize(UINT *numDecoders, UINT *size)
1476 FIXME("%p %p stub!\n", numDecoders, size);
1478 if (!numDecoders || !size)
1479 return InvalidParameter;
1481 *numDecoders = 0;
1482 *size = 0;
1484 return Ok;
1487 /*****************************************************************************
1488 * GdipGetImageDecoders [GDIPLUS.@]
1490 GpStatus WINGDIPAPI GdipGetImageDecoders(UINT numDecoders, UINT size, ImageCodecInfo *decoders)
1492 FIXME("%u %u %p stub!\n", numDecoders, size, decoders);
1494 if (!decoders)
1495 return GenericError;
1497 return NotImplemented;
1500 /*****************************************************************************
1501 * GdipGetImageEncodersSize [GDIPLUS.@]
1503 GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size)
1505 TRACE("%p %p\n", numEncoders, size);
1507 if (!numEncoders || !size)
1508 return InvalidParameter;
1510 *numEncoders = NUM_ENCODERS_SUPPORTED;
1511 *size = sizeof (codecs);
1513 return Ok;
1516 /*****************************************************************************
1517 * GdipGetImageEncoders [GDIPLUS.@]
1519 GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders)
1521 TRACE("%u %u %p\n", numEncoders, size, encoders);
1523 if (!encoders ||
1524 (numEncoders != NUM_ENCODERS_SUPPORTED) ||
1525 (size != sizeof (codecs)))
1526 return GenericError;
1528 memcpy(encoders, codecs, sizeof (codecs));
1530 return Ok;
1533 /*****************************************************************************
1534 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
1536 GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBitmap** bitmap)
1538 BITMAP bm;
1539 GpStatus retval;
1540 PixelFormat format;
1541 BYTE* bits;
1543 TRACE("%p %p %p\n", hbm, hpal, bitmap);
1545 if(!hbm || !bitmap)
1546 return InvalidParameter;
1548 /* TODO: Support for device-dependent bitmaps */
1549 if(hpal){
1550 FIXME("no support for device-dependent bitmaps\n");
1551 return NotImplemented;
1554 if (GetObjectA(hbm, sizeof(bm), &bm) != sizeof(bm))
1555 return InvalidParameter;
1557 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
1558 switch(bm.bmBitsPixel) {
1559 case 1:
1560 format = PixelFormat1bppIndexed;
1561 break;
1562 case 4:
1563 format = PixelFormat4bppIndexed;
1564 break;
1565 case 8:
1566 format = PixelFormat8bppIndexed;
1567 break;
1568 case 24:
1569 format = PixelFormat24bppRGB;
1570 break;
1571 case 32:
1572 format = PixelFormat32bppRGB;
1573 break;
1574 case 48:
1575 format = PixelFormat48bppRGB;
1576 break;
1577 default:
1578 FIXME("don't know how to handle %d bpp\n", bm.bmBitsPixel);
1579 return InvalidParameter;
1582 if (bm.bmBits)
1583 bits = (BYTE*)bm.bmBits + (bm.bmHeight - 1) * bm.bmWidthBytes;
1584 else
1586 FIXME("can only get image data from DIB sections\n");
1587 bits = NULL;
1590 retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, -bm.bmWidthBytes,
1591 format, bits, bitmap);
1593 return retval;
1596 /*****************************************************************************
1597 * GdipSetEffectParameters [GDIPLUS.@]
1599 GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect *effect,
1600 const VOID *params, const UINT size)
1602 static int calls;
1604 if(!(calls++))
1605 FIXME("not implemented\n");
1607 return NotImplemented;
1610 /*****************************************************************************
1611 * GdipGetImageFlags [GDIPLUS.@]
1613 GpStatus WINGDIPAPI GdipGetImageFlags(GpImage *image, UINT *flags)
1615 TRACE("%p %p\n", image, flags);
1617 if(!image || !flags)
1618 return InvalidParameter;
1620 *flags = image->flags;
1622 return Ok;
1625 GpStatus WINGDIPAPI GdipTestControl(GpTestControlEnum control, void *param)
1627 TRACE("(%d, %p)\n", control, param);
1629 switch(control){
1630 case TestControlForceBilinear:
1631 if(param)
1632 FIXME("TestControlForceBilinear not handled\n");
1633 break;
1634 case TestControlNoICM:
1635 if(param)
1636 FIXME("TestControlNoICM not handled\n");
1637 break;
1638 case TestControlGetBuildNumber:
1639 *((DWORD*)param) = 3102;
1640 break;
1643 return Ok;
1646 GpStatus WINGDIPAPI GdipRecordMetafileFileName(GDIPCONST WCHAR* fileName,
1647 HDC hdc, EmfType type, GDIPCONST GpRectF *pFrameRect,
1648 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc,
1649 GpMetafile **metafile)
1651 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
1652 frameUnit, debugstr_w(desc), metafile);
1654 return NotImplemented;
1657 GpStatus WINGDIPAPI GdipRecordMetafileFileNameI(GDIPCONST WCHAR* fileName, HDC hdc, EmfType type,
1658 GDIPCONST GpRect *pFrameRect, MetafileFrameUnit frameUnit,
1659 GDIPCONST WCHAR *desc, GpMetafile **metafile)
1661 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
1662 frameUnit, debugstr_w(desc), metafile);
1664 return NotImplemented;
1667 GpStatus WINGDIPAPI GdipImageForceValidation(GpImage *image)
1669 FIXME("%p\n", image);
1671 return Ok;
1674 /*****************************************************************************
1675 * GdipGetImageThumbnail [GDIPLUS.@]
1677 GpStatus WINGDIPAPI GdipGetImageThumbnail(GpImage *image, UINT width, UINT height,
1678 GpImage **ret_image, GetThumbnailImageAbort cb,
1679 VOID * cb_data)
1681 FIXME("(%p %u %u %p %p %p) stub\n",
1682 image, width, height, ret_image, cb, cb_data);
1683 return NotImplemented;
1686 /*****************************************************************************
1687 * GdipImageRotateFlip [GDIPLUS.@]
1689 GpStatus WINGDIPAPI GdipImageRotateFlip(GpImage *image, RotateFlipType type)
1691 FIXME("(%p %u) stub\n", image, type);
1692 return NotImplemented;