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
21 #define NONAMELESSUNION
36 #include "gdiplus_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
41 #define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
43 static INT
ipicture_pixel_height(IPicture
*pic
)
48 IPicture_get_Height(pic
, &y
);
52 y
= MulDiv(y
, GetDeviceCaps(hdcref
, LOGPIXELSY
), INCH_HIMETRIC
);
58 static INT
ipicture_pixel_width(IPicture
*pic
)
63 IPicture_get_Width(pic
, &x
);
67 x
= MulDiv(x
, GetDeviceCaps(hdcref
, LOGPIXELSX
), INCH_HIMETRIC
);
74 GpStatus WINGDIPAPI
GdipBitmapApplyEffect(GpBitmap
* bitmap
, CGpEffect
* effect
,
75 RECT
* roi
, BOOL useAuxData
, VOID
** auxData
, INT
* auxDataSize
)
77 FIXME("(%p %p %p %d %p %p): stub\n", bitmap
, effect
, roi
, useAuxData
, auxData
, auxDataSize
);
79 * Note: According to Jose Roca's GDI+ docs, this function is not
80 * implemented in Windows's GDI+.
82 return NotImplemented
;
85 GpStatus WINGDIPAPI
GdipBitmapCreateApplyEffect(GpBitmap
** inputBitmaps
,
86 INT numInputs
, CGpEffect
* effect
, RECT
* roi
, RECT
* outputRect
,
87 GpBitmap
** outputBitmap
, BOOL useAuxData
, VOID
** auxData
, INT
* auxDataSize
)
89 FIXME("(%p %d %p %p %p %p %d %p %p): stub\n", inputBitmaps
, numInputs
, effect
, roi
, outputRect
, outputBitmap
, useAuxData
, auxData
, auxDataSize
);
91 * Note: According to Jose Roca's GDI+ docs, this function is not
92 * implemented in Windows's GDI+.
94 return NotImplemented
;
97 static inline void getpixel_16bppGrayScale(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
98 const BYTE
*row
, UINT x
)
100 *r
= *g
= *b
= row
[x
*2+1];
104 static inline void getpixel_16bppRGB555(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
105 const BYTE
*row
, UINT x
)
107 WORD pixel
= *((WORD
*)(row
)+x
);
108 *r
= (pixel
>>7&0xf8)|(pixel
>>12&0x7);
109 *g
= (pixel
>>2&0xf8)|(pixel
>>6&0x7);
110 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
114 static inline void getpixel_16bppRGB565(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
115 const BYTE
*row
, UINT x
)
117 WORD pixel
= *((WORD
*)(row
)+x
);
118 *r
= (pixel
>>8&0xf8)|(pixel
>>13&0x7);
119 *g
= (pixel
>>3&0xfc)|(pixel
>>9&0x3);
120 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
124 static inline void getpixel_16bppARGB1555(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
125 const BYTE
*row
, UINT x
)
127 WORD pixel
= *((WORD
*)(row
)+x
);
128 *r
= (pixel
>>7&0xf8)|(pixel
>>12&0x7);
129 *g
= (pixel
>>2&0xf8)|(pixel
>>6&0x7);
130 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
131 if ((pixel
&0x8000) == 0x8000)
137 static inline void getpixel_24bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
138 const BYTE
*row
, UINT x
)
146 static inline void getpixel_32bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
147 const BYTE
*row
, UINT x
)
155 static inline void getpixel_32bppARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
156 const BYTE
*row
, UINT x
)
164 static inline void getpixel_32bppPARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
165 const BYTE
*row
, UINT x
)
172 *r
= row
[x
*4+2] * 255 / *a
;
173 *g
= row
[x
*4+1] * 255 / *a
;
174 *b
= row
[x
*4] * 255 / *a
;
178 static inline void getpixel_48bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
179 const BYTE
*row
, UINT x
)
187 static inline void getpixel_64bppARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
188 const BYTE
*row
, UINT x
)
196 static inline void getpixel_64bppPARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
197 const BYTE
*row
, UINT x
)
204 *r
= row
[x
*8+5] * 255 / *a
;
205 *g
= row
[x
*8+3] * 255 / *a
;
206 *b
= row
[x
*8+1] * 255 / *a
;
210 GpStatus WINGDIPAPI
GdipBitmapGetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
215 TRACE("%p %d %d %p\n", bitmap
, x
, y
, color
);
217 if(!bitmap
|| !color
||
218 x
< 0 || y
< 0 || x
>= bitmap
->width
|| y
>= bitmap
->height
)
219 return InvalidParameter
;
221 row
= bitmap
->bits
+bitmap
->stride
*y
;
223 switch (bitmap
->format
)
225 case PixelFormat16bppGrayScale
:
226 getpixel_16bppGrayScale(&r
,&g
,&b
,&a
,row
,x
);
228 case PixelFormat16bppRGB555
:
229 getpixel_16bppRGB555(&r
,&g
,&b
,&a
,row
,x
);
231 case PixelFormat16bppRGB565
:
232 getpixel_16bppRGB565(&r
,&g
,&b
,&a
,row
,x
);
234 case PixelFormat16bppARGB1555
:
235 getpixel_16bppARGB1555(&r
,&g
,&b
,&a
,row
,x
);
237 case PixelFormat24bppRGB
:
238 getpixel_24bppRGB(&r
,&g
,&b
,&a
,row
,x
);
240 case PixelFormat32bppRGB
:
241 getpixel_32bppRGB(&r
,&g
,&b
,&a
,row
,x
);
243 case PixelFormat32bppARGB
:
244 getpixel_32bppARGB(&r
,&g
,&b
,&a
,row
,x
);
246 case PixelFormat32bppPARGB
:
247 getpixel_32bppPARGB(&r
,&g
,&b
,&a
,row
,x
);
249 case PixelFormat48bppRGB
:
250 getpixel_48bppRGB(&r
,&g
,&b
,&a
,row
,x
);
252 case PixelFormat64bppARGB
:
253 getpixel_64bppARGB(&r
,&g
,&b
,&a
,row
,x
);
255 case PixelFormat64bppPARGB
:
256 getpixel_64bppPARGB(&r
,&g
,&b
,&a
,row
,x
);
259 FIXME("not implemented for format 0x%x\n", bitmap
->format
);
260 return NotImplemented
;
263 *color
= a
<<24|r
<<16|g
<<8|b
;
268 GpStatus WINGDIPAPI
GdipBitmapSetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
272 TRACE("bitmap:%p, x:%d, y:%d, color:%08x\n", bitmap
, x
, y
, color
);
275 return InvalidParameter
;
278 FIXME("not implemented\n");
280 return NotImplemented
;
283 /* This function returns a pointer to an array of pixels that represents the
284 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
285 * flags. It is correct behavior that a user who calls this function with write
286 * privileges can write to the whole bitmap (not just the area in rect).
288 * FIXME: only used portion of format is bits per pixel. */
289 GpStatus WINGDIPAPI
GdipBitmapLockBits(GpBitmap
* bitmap
, GDIPCONST GpRect
* rect
,
290 UINT flags
, PixelFormat format
, BitmapData
* lockeddata
)
293 INT stride
, bitspp
= PIXELFORMATBPP(format
);
295 HBITMAP hbm
, old
= NULL
;
299 GpRect act_rect
; /* actual rect to be used */
301 TRACE("%p %p %d %d %p\n", bitmap
, rect
, flags
, format
, lockeddata
);
303 if(!lockeddata
|| !bitmap
)
304 return InvalidParameter
;
307 if(rect
->X
< 0 || rect
->Y
< 0 || (rect
->X
+ rect
->Width
> bitmap
->width
) ||
308 (rect
->Y
+ rect
->Height
> bitmap
->height
) || !flags
)
309 return InvalidParameter
;
314 act_rect
.X
= act_rect
.Y
= 0;
315 act_rect
.Width
= bitmap
->width
;
316 act_rect
.Height
= bitmap
->height
;
319 if(flags
& ImageLockModeUserInputBuf
)
320 return NotImplemented
;
325 if (bitmap
->bits
&& bitmap
->format
== format
)
327 /* no conversion is necessary; just use the bits directly */
328 lockeddata
->Width
= act_rect
.Width
;
329 lockeddata
->Height
= act_rect
.Height
;
330 lockeddata
->PixelFormat
= format
;
331 lockeddata
->Reserved
= flags
;
332 lockeddata
->Stride
= bitmap
->stride
;
333 lockeddata
->Scan0
= bitmap
->bits
+ (bitspp
/ 8) * act_rect
.X
+
334 bitmap
->stride
* act_rect
.Y
;
336 bitmap
->lockmode
= flags
;
342 hbm
= bitmap
->hbitmap
;
344 bm_is_selected
= (hdc
!= 0);
346 pbmi
= GdipAlloc(sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
349 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
350 pbmi
->bmiHeader
.biBitCount
= 0;
353 hdc
= CreateCompatibleDC(0);
354 old
= SelectObject(hdc
, hbm
);
358 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
360 abs_height
= abs(pbmi
->bmiHeader
.biHeight
);
361 stride
= pbmi
->bmiHeader
.biWidth
* bitspp
/ 8;
362 stride
= (stride
+ 3) & ~3;
364 buff
= GdipAlloc(stride
* abs_height
);
366 pbmi
->bmiHeader
.biBitCount
= bitspp
;
369 GetDIBits(hdc
, hbm
, 0, abs_height
, buff
, pbmi
, DIB_RGB_COLORS
);
372 SelectObject(hdc
, old
);
381 lockeddata
->Width
= act_rect
.Width
;
382 lockeddata
->Height
= act_rect
.Height
;
383 lockeddata
->PixelFormat
= format
;
384 lockeddata
->Reserved
= flags
;
386 if(pbmi
->bmiHeader
.biHeight
> 0){
387 lockeddata
->Stride
= -stride
;
388 lockeddata
->Scan0
= buff
+ (bitspp
/ 8) * act_rect
.X
+
389 stride
* (abs_height
- 1 - act_rect
.Y
);
392 lockeddata
->Stride
= stride
;
393 lockeddata
->Scan0
= buff
+ (bitspp
/ 8) * act_rect
.X
+ stride
* act_rect
.Y
;
396 bitmap
->lockmode
= flags
;
399 bitmap
->bitmapbits
= buff
;
405 GpStatus WINGDIPAPI
GdipBitmapSetResolution(GpBitmap
* bitmap
, REAL xdpi
, REAL ydpi
)
407 FIXME("(%p, %.2f, %.2f)\n", bitmap
, xdpi
, ydpi
);
409 return NotImplemented
;
412 GpStatus WINGDIPAPI
GdipBitmapUnlockBits(GpBitmap
* bitmap
,
413 BitmapData
* lockeddata
)
416 HBITMAP hbm
, old
= NULL
;
420 if(!bitmap
|| !lockeddata
)
421 return InvalidParameter
;
423 if(!bitmap
->lockmode
)
426 if(lockeddata
->Reserved
& ImageLockModeUserInputBuf
)
427 return NotImplemented
;
429 if(lockeddata
->Reserved
& ImageLockModeRead
){
430 if(!(--bitmap
->numlocks
))
431 bitmap
->lockmode
= 0;
433 GdipFree(bitmap
->bitmapbits
);
434 bitmap
->bitmapbits
= NULL
;
438 if (!bitmap
->bitmapbits
)
440 /* we passed a direct reference; no need to do anything */
441 bitmap
->lockmode
= 0;
445 hbm
= bitmap
->hbitmap
;
447 bm_is_selected
= (hdc
!= 0);
449 pbmi
= GdipAlloc(sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
450 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
451 pbmi
->bmiHeader
.biBitCount
= 0;
454 hdc
= CreateCompatibleDC(0);
455 old
= SelectObject(hdc
, hbm
);
458 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
459 pbmi
->bmiHeader
.biBitCount
= PIXELFORMATBPP(lockeddata
->PixelFormat
);
460 SetDIBits(hdc
, hbm
, 0, abs(pbmi
->bmiHeader
.biHeight
),
461 bitmap
->bitmapbits
, pbmi
, DIB_RGB_COLORS
);
464 SelectObject(hdc
, old
);
469 GdipFree(bitmap
->bitmapbits
);
470 bitmap
->bitmapbits
= NULL
;
471 bitmap
->lockmode
= 0;
476 GpStatus WINGDIPAPI
GdipCloneBitmapArea(REAL x
, REAL y
, REAL width
, REAL height
,
477 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
479 FIXME("(%f,%f,%f,%f,%i,%p,%p): stub\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
481 return NotImplemented
;
484 GpStatus WINGDIPAPI
GdipCloneBitmapAreaI(INT x
, INT y
, INT width
, INT height
,
485 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
487 FIXME("(%i,%i,%i,%i,%i,%p,%p): stub\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
489 return NotImplemented
;
492 GpStatus WINGDIPAPI
GdipCloneImage(GpImage
*image
, GpImage
**cloneImage
)
494 GpStatus stat
= GenericError
;
496 TRACE("%p, %p\n", image
, cloneImage
);
498 if (!image
|| !cloneImage
)
499 return InvalidParameter
;
508 hr
= CreateStreamOnHGlobal(0, TRUE
, &stream
);
512 hr
= IPicture_SaveAsFile(image
->picture
, stream
, FALSE
, &size
);
515 WARN("Failed to save image on stream\n");
519 /* Set seek pointer back to the beginning of the picture */
521 hr
= IStream_Seek(stream
, move
, STREAM_SEEK_SET
, NULL
);
525 stat
= GdipLoadImageFromStream(stream
, cloneImage
);
526 if (stat
!= Ok
) WARN("Failed to load image from stream\n");
529 IStream_Release(stream
);
532 else if (image
->type
== ImageTypeBitmap
)
534 GpBitmap
*bitmap
= (GpBitmap
*)image
;
535 BitmapData lockeddata_src
, lockeddata_dst
;
539 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, bitmap
->format
,
541 if (stat
!= Ok
) return stat
;
543 stat
= GdipCreateBitmapFromScan0(lockeddata_src
.Width
, lockeddata_src
.Height
,
544 0, lockeddata_src
.PixelFormat
, NULL
, (GpBitmap
**)cloneImage
);
547 stat
= GdipBitmapLockBits((GpBitmap
*)*cloneImage
, NULL
, ImageLockModeWrite
,
548 lockeddata_src
.PixelFormat
, &lockeddata_dst
);
552 /* copy the image data */
553 row_size
= (lockeddata_src
.Width
* PIXELFORMATBPP(lockeddata_src
.PixelFormat
) +7)/8;
554 for (i
=0; i
<lockeddata_src
.Height
; i
++)
555 memcpy((BYTE
*)lockeddata_dst
.Scan0
+lockeddata_dst
.Stride
*i
,
556 (BYTE
*)lockeddata_src
.Scan0
+lockeddata_src
.Stride
*i
,
559 GdipBitmapUnlockBits((GpBitmap
*)*cloneImage
, &lockeddata_dst
);
562 GdipBitmapUnlockBits(bitmap
, &lockeddata_src
);
567 GdipDisposeImage(*cloneImage
);
570 else memcpy(&(*cloneImage
)->format
, &image
->format
, sizeof(GUID
));
576 ERR("GpImage with no IPicture or bitmap?!\n");
577 return NotImplemented
;
581 GpStatus WINGDIPAPI
GdipCreateBitmapFromFile(GDIPCONST WCHAR
* filename
,
587 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
589 if(!filename
|| !bitmap
)
590 return InvalidParameter
;
592 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
597 stat
= GdipCreateBitmapFromStream(stream
, bitmap
);
599 IStream_Release(stream
);
604 GpStatus WINGDIPAPI
GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO
* info
,
605 VOID
*bits
, GpBitmap
**bitmap
)
607 DWORD height
, stride
;
610 FIXME("(%p, %p, %p) - partially implemented\n", info
, bits
, bitmap
);
612 height
= abs(info
->bmiHeader
.biHeight
);
613 stride
= ((info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
+ 31) >> 3) & ~3;
615 if(info
->bmiHeader
.biHeight
> 0) /* bottom-up */
617 bits
= (BYTE
*)bits
+ (height
- 1) * stride
;
621 switch(info
->bmiHeader
.biBitCount
) {
623 format
= PixelFormat1bppIndexed
;
626 format
= PixelFormat4bppIndexed
;
629 format
= PixelFormat8bppIndexed
;
632 format
= PixelFormat24bppRGB
;
635 FIXME("don't know how to handle %d bpp\n", info
->bmiHeader
.biBitCount
);
637 return InvalidParameter
;
640 return GdipCreateBitmapFromScan0(info
->bmiHeader
.biWidth
, height
, stride
, format
,
646 GpStatus WINGDIPAPI
GdipCreateBitmapFromFileICM(GDIPCONST WCHAR
* filename
,
649 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
651 return GdipCreateBitmapFromFile(filename
, bitmap
);
654 GpStatus WINGDIPAPI
GdipCreateBitmapFromResource(HINSTANCE hInstance
,
655 GDIPCONST WCHAR
* lpBitmapName
, GpBitmap
** bitmap
)
658 GpStatus stat
= InvalidParameter
;
660 TRACE("%p (%s) %p\n", hInstance
, debugstr_w(lpBitmapName
), bitmap
);
662 if(!lpBitmapName
|| !bitmap
)
663 return InvalidParameter
;
666 hbm
= LoadImageW(hInstance
, lpBitmapName
, IMAGE_BITMAP
, 0, 0,
667 LR_CREATEDIBSECTION
);
670 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, bitmap
);
677 GpStatus WINGDIPAPI
GdipCreateHBITMAPFromBitmap(GpBitmap
* bitmap
,
678 HBITMAP
* hbmReturn
, ARGB background
)
681 HBITMAP result
, oldbitmap
;
684 GpGraphics
*graphics
;
685 BITMAPINFOHEADER bih
;
687 TRACE("(%p,%p,%x)\n", bitmap
, hbmReturn
, background
);
689 if (!bitmap
|| !hbmReturn
) return InvalidParameter
;
691 GdipGetImageWidth((GpImage
*)bitmap
, &width
);
692 GdipGetImageHeight((GpImage
*)bitmap
, &height
);
694 bih
.biSize
= sizeof(bih
);
696 bih
.biHeight
= height
;
699 bih
.biCompression
= BI_RGB
;
701 bih
.biXPelsPerMeter
= 0;
702 bih
.biYPelsPerMeter
= 0;
704 bih
.biClrImportant
= 0;
706 hdc
= CreateCompatibleDC(NULL
);
707 if (!hdc
) return GenericError
;
709 result
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
, &bits
,
714 oldbitmap
= SelectObject(hdc
, result
);
716 stat
= GdipCreateFromHDC(hdc
, &graphics
);
719 stat
= GdipGraphicsClear(graphics
, background
);
722 stat
= GdipDrawImage(graphics
, (GpImage
*)bitmap
, 0, 0);
724 GdipDeleteGraphics(graphics
);
727 SelectObject(hdc
, oldbitmap
);
734 if (stat
!= Ok
&& result
)
736 DeleteObject(result
);
745 GpStatus WINGDIPAPI
GdipConvertToEmfPlus(const GpGraphics
* ref
,
746 GpMetafile
* metafile
, BOOL
* succ
, EmfType emfType
,
747 const WCHAR
* description
, GpMetafile
** out_metafile
)
751 if(!ref
|| !metafile
|| !out_metafile
)
752 return InvalidParameter
;
755 *out_metafile
= NULL
;
758 FIXME("not implemented\n");
760 return NotImplemented
;
763 /* FIXME: this should create a bitmap in the given size with the attributes
764 * (resolution etc.) of the graphics object */
765 GpStatus WINGDIPAPI
GdipCreateBitmapFromGraphics(INT width
, INT height
,
766 GpGraphics
* target
, GpBitmap
** bitmap
)
771 if(!target
|| !bitmap
)
772 return InvalidParameter
;
775 FIXME("hacked stub\n");
777 ret
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat24bppRGB
,
783 GpStatus WINGDIPAPI
GdipCreateBitmapFromHICON(HICON hicon
, GpBitmap
** bitmap
)
791 BitmapData lockeddata
;
796 BITMAPINFOHEADER bih
;
801 TRACE("%p, %p\n", hicon
, bitmap
);
803 if(!bitmap
|| !GetIconInfo(hicon
, &iinfo
))
805 DeleteObject(iinfo
.hbmColor
);
806 DeleteObject(iinfo
.hbmMask
);
807 return InvalidParameter
;
810 /* get the size of the icon */
811 ret
= GetObjectA(iinfo
.hbmColor
? iinfo
.hbmColor
: iinfo
.hbmMask
, sizeof(bm
), &bm
);
813 DeleteObject(iinfo
.hbmColor
);
814 DeleteObject(iinfo
.hbmMask
);
821 height
= abs(bm
.bmHeight
);
822 else /* combined bitmap + mask */
823 height
= abs(bm
.bmHeight
) / 2;
825 bits
= HeapAlloc(GetProcessHeap(), 0, 4*width
*height
);
827 DeleteObject(iinfo
.hbmColor
);
828 DeleteObject(iinfo
.hbmMask
);
832 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat32bppARGB
, NULL
, bitmap
);
834 DeleteObject(iinfo
.hbmColor
);
835 DeleteObject(iinfo
.hbmMask
);
836 HeapFree(GetProcessHeap(), 0, bits
);
843 rect
.Height
= height
;
845 stat
= GdipBitmapLockBits(*bitmap
, &rect
, ImageLockModeWrite
, PixelFormat32bppARGB
, &lockeddata
);
847 DeleteObject(iinfo
.hbmColor
);
848 DeleteObject(iinfo
.hbmMask
);
849 HeapFree(GetProcessHeap(), 0, bits
);
850 GdipDisposeImage((GpImage
*)*bitmap
);
854 bih
.biSize
= sizeof(bih
);
856 bih
.biHeight
= -height
;
859 bih
.biCompression
= BI_RGB
;
861 bih
.biXPelsPerMeter
= 0;
862 bih
.biYPelsPerMeter
= 0;
864 bih
.biClrImportant
= 0;
869 GetDIBits(screendc
, iinfo
.hbmColor
, 0, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
871 if (bm
.bmBitsPixel
== 32)
875 /* If any pixel has a non-zero alpha, ignore hbmMask */
877 for (x
=0; x
<width
&& !has_alpha
; x
++)
878 for (y
=0; y
<height
&& !has_alpha
; y
++)
879 if ((*src
++ & 0xff000000) != 0)
882 else has_alpha
= FALSE
;
886 GetDIBits(screendc
, iinfo
.hbmMask
, 0, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
890 /* copy the image data to the Bitmap */
892 dst_row
= lockeddata
.Scan0
;
893 for (y
=0; y
<height
; y
++)
895 memcpy(dst_row
, src
, width
*4);
897 dst_row
+= lockeddata
.Stride
;
904 /* read alpha data from the mask */
906 GetDIBits(screendc
, iinfo
.hbmMask
, 0, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
908 GetDIBits(screendc
, iinfo
.hbmMask
, height
, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
911 dst_row
= lockeddata
.Scan0
;
912 for (y
=0; y
<height
; y
++)
914 dst
= (DWORD
*)dst_row
;
915 for (x
=0; x
<height
; x
++)
917 DWORD src_value
= *src
++;
921 *dst
++ |= 0xff000000;
923 dst_row
+= lockeddata
.Stride
;
928 /* set constant alpha of 255 */
930 for (y
=0; y
<height
; y
++)
932 dst
= (DWORD
*)dst_row
;
933 for (x
=0; x
<height
; x
++)
934 *dst
++ |= 0xff000000;
935 dst_row
+= lockeddata
.Stride
;
940 ReleaseDC(0, screendc
);
942 DeleteObject(iinfo
.hbmColor
);
943 DeleteObject(iinfo
.hbmMask
);
945 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
947 HeapFree(GetProcessHeap(), 0, bits
);
952 GpStatus WINGDIPAPI
GdipCreateBitmapFromScan0(INT width
, INT height
, INT stride
,
953 PixelFormat format
, BYTE
* scan0
, GpBitmap
** bitmap
)
955 BITMAPINFOHEADER bmih
;
957 INT row_size
, dib_stride
;
962 TRACE("%d %d %d %d %p %p\n", width
, height
, stride
, format
, scan0
, bitmap
);
964 if (!bitmap
) return InvalidParameter
;
966 if(width
<= 0 || height
<= 0 || (scan0
&& (stride
% 4))){
968 return InvalidParameter
;
972 return InvalidParameter
;
974 row_size
= (width
* PIXELFORMATBPP(format
)+7) / 8;
975 dib_stride
= (row_size
+ 3) & ~3;
980 bmih
.biSize
= sizeof(BITMAPINFOHEADER
);
981 bmih
.biWidth
= width
;
982 bmih
.biHeight
= -height
;
984 /* FIXME: use the rest of the data from format */
985 bmih
.biBitCount
= PIXELFORMATBPP(format
);
986 bmih
.biCompression
= BI_RGB
;
987 bmih
.biSizeImage
= 0;
988 bmih
.biXPelsPerMeter
= 0;
989 bmih
.biYPelsPerMeter
= 0;
991 bmih
.biClrImportant
= 0;
993 hdc
= CreateCompatibleDC(NULL
);
994 if (!hdc
) return GenericError
;
996 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
, (void**)&bits
,
1001 if (!hbitmap
) return GenericError
;
1003 /* copy bits to the dib if necessary */
1004 /* FIXME: should reference the bits instead of copying them */
1006 for (i
=0; i
<height
; i
++)
1007 memcpy(bits
+i
*dib_stride
, scan0
+i
*stride
, row_size
);
1009 *bitmap
= GdipAlloc(sizeof(GpBitmap
));
1012 DeleteObject(hbitmap
);
1016 (*bitmap
)->image
.type
= ImageTypeBitmap
;
1017 memcpy(&(*bitmap
)->image
.format
, &ImageFormatMemoryBMP
, sizeof(GUID
));
1018 (*bitmap
)->image
.flags
= ImageFlagsNone
;
1019 (*bitmap
)->width
= width
;
1020 (*bitmap
)->height
= height
;
1021 (*bitmap
)->format
= format
;
1022 (*bitmap
)->image
.picture
= NULL
;
1023 (*bitmap
)->hbitmap
= hbitmap
;
1024 (*bitmap
)->hdc
= NULL
;
1025 (*bitmap
)->bits
= bits
;
1026 (*bitmap
)->stride
= dib_stride
;
1031 GpStatus WINGDIPAPI
GdipCreateBitmapFromStream(IStream
* stream
,
1036 TRACE("%p %p\n", stream
, bitmap
);
1038 stat
= GdipLoadImageFromStream(stream
, (GpImage
**) bitmap
);
1043 if((*bitmap
)->image
.type
!= ImageTypeBitmap
){
1044 GdipDisposeImage(&(*bitmap
)->image
);
1046 return GenericError
; /* FIXME: what error to return? */
1053 GpStatus WINGDIPAPI
GdipCreateBitmapFromStreamICM(IStream
* stream
,
1056 TRACE("%p %p\n", stream
, bitmap
);
1058 return GdipCreateBitmapFromStream(stream
, bitmap
);
1061 GpStatus WINGDIPAPI
GdipCreateCachedBitmap(GpBitmap
*bitmap
, GpGraphics
*graphics
,
1062 GpCachedBitmap
**cachedbmp
)
1066 TRACE("%p %p %p\n", bitmap
, graphics
, cachedbmp
);
1068 if(!bitmap
|| !graphics
|| !cachedbmp
)
1069 return InvalidParameter
;
1071 *cachedbmp
= GdipAlloc(sizeof(GpCachedBitmap
));
1075 stat
= GdipCloneImage(&(bitmap
->image
), &(*cachedbmp
)->image
);
1077 GdipFree(*cachedbmp
);
1084 GpStatus WINGDIPAPI
GdipCreateHICONFromBitmap(GpBitmap
*bitmap
, HICON
*hicon
)
1086 FIXME("(%p, %p)\n", bitmap
, hicon
);
1088 return NotImplemented
;
1091 GpStatus WINGDIPAPI
GdipDeleteCachedBitmap(GpCachedBitmap
*cachedbmp
)
1093 TRACE("%p\n", cachedbmp
);
1096 return InvalidParameter
;
1098 GdipDisposeImage(cachedbmp
->image
);
1099 GdipFree(cachedbmp
);
1104 GpStatus WINGDIPAPI
GdipDrawCachedBitmap(GpGraphics
*graphics
,
1105 GpCachedBitmap
*cachedbmp
, INT x
, INT y
)
1107 TRACE("%p %p %d %d\n", graphics
, cachedbmp
, x
, y
);
1109 if(!graphics
|| !cachedbmp
)
1110 return InvalidParameter
;
1112 return GdipDrawImage(graphics
, cachedbmp
->image
, (REAL
)x
, (REAL
)y
);
1115 GpStatus WINGDIPAPI
GdipEmfToWmfBits(HENHMETAFILE hemf
, UINT cbData16
,
1116 LPBYTE pData16
, INT iMapMode
, INT eFlags
)
1118 FIXME("(%p, %d, %p, %d, %d): stub\n", hemf
, cbData16
, pData16
, iMapMode
, eFlags
);
1119 return NotImplemented
;
1122 GpStatus WINGDIPAPI
GdipDisposeImage(GpImage
*image
)
1124 TRACE("%p\n", image
);
1127 return InvalidParameter
;
1130 IPicture_Release(image
->picture
);
1131 if (image
->type
== ImageTypeBitmap
)
1133 GdipFree(((GpBitmap
*)image
)->bitmapbits
);
1134 DeleteDC(((GpBitmap
*)image
)->hdc
);
1141 GpStatus WINGDIPAPI
GdipFindFirstImageItem(GpImage
*image
, ImageItemData
* item
)
1144 return InvalidParameter
;
1146 return NotImplemented
;
1149 GpStatus WINGDIPAPI
GdipGetImageBounds(GpImage
*image
, GpRectF
*srcRect
,
1152 TRACE("%p %p %p\n", image
, srcRect
, srcUnit
);
1154 if(!image
|| !srcRect
|| !srcUnit
)
1155 return InvalidParameter
;
1156 if(image
->type
== ImageTypeMetafile
){
1157 *srcRect
= ((GpMetafile
*)image
)->bounds
;
1158 *srcUnit
= ((GpMetafile
*)image
)->unit
;
1160 else if(image
->type
== ImageTypeBitmap
){
1161 srcRect
->X
= srcRect
->Y
= 0.0;
1162 srcRect
->Width
= (REAL
) ((GpBitmap
*)image
)->width
;
1163 srcRect
->Height
= (REAL
) ((GpBitmap
*)image
)->height
;
1164 *srcUnit
= UnitPixel
;
1167 srcRect
->X
= srcRect
->Y
= 0.0;
1168 srcRect
->Width
= ipicture_pixel_width(image
->picture
);
1169 srcRect
->Height
= ipicture_pixel_height(image
->picture
);
1170 *srcUnit
= UnitPixel
;
1173 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect
->X
, srcRect
->Y
,
1174 srcRect
->Width
, srcRect
->Height
, *srcUnit
);
1179 GpStatus WINGDIPAPI
GdipGetImageDimension(GpImage
*image
, REAL
*width
,
1182 TRACE("%p %p %p\n", image
, width
, height
);
1184 if(!image
|| !height
|| !width
)
1185 return InvalidParameter
;
1187 if(image
->type
== ImageTypeMetafile
){
1190 *height
= convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
1191 ((GpMetafile
*)image
)->bounds
.Height
;
1193 *width
= convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
1194 ((GpMetafile
*)image
)->bounds
.Width
;
1199 else if(image
->type
== ImageTypeBitmap
){
1200 *height
= ((GpBitmap
*)image
)->height
;
1201 *width
= ((GpBitmap
*)image
)->width
;
1204 *height
= ipicture_pixel_height(image
->picture
);
1205 *width
= ipicture_pixel_width(image
->picture
);
1208 TRACE("returning (%f, %f)\n", *height
, *width
);
1212 GpStatus WINGDIPAPI
GdipGetImageGraphicsContext(GpImage
*image
,
1213 GpGraphics
**graphics
)
1217 TRACE("%p %p\n", image
, graphics
);
1219 if(!image
|| !graphics
)
1220 return InvalidParameter
;
1222 if(image
->type
!= ImageTypeBitmap
){
1223 FIXME("not implemented for image type %d\n", image
->type
);
1224 return NotImplemented
;
1227 hdc
= ((GpBitmap
*)image
)->hdc
;
1230 hdc
= CreateCompatibleDC(0);
1231 SelectObject(hdc
, ((GpBitmap
*)image
)->hbitmap
);
1232 ((GpBitmap
*)image
)->hdc
= hdc
;
1235 return GdipCreateFromHDC(hdc
, graphics
);
1238 GpStatus WINGDIPAPI
GdipGetImageHeight(GpImage
*image
, UINT
*height
)
1240 TRACE("%p %p\n", image
, height
);
1242 if(!image
|| !height
)
1243 return InvalidParameter
;
1245 if(image
->type
== ImageTypeMetafile
){
1248 *height
= roundr(convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
1249 ((GpMetafile
*)image
)->bounds
.Height
);
1253 else if(image
->type
== ImageTypeBitmap
)
1254 *height
= ((GpBitmap
*)image
)->height
;
1256 *height
= ipicture_pixel_height(image
->picture
);
1258 TRACE("returning %d\n", *height
);
1263 GpStatus WINGDIPAPI
GdipGetImageHorizontalResolution(GpImage
*image
, REAL
*res
)
1268 return InvalidParameter
;
1271 FIXME("not implemented\n");
1273 return NotImplemented
;
1276 GpStatus WINGDIPAPI
GdipGetImagePaletteSize(GpImage
*image
, INT
*size
)
1278 FIXME("%p %p\n", image
, size
);
1281 return InvalidParameter
;
1283 return NotImplemented
;
1286 /* FIXME: test this function for non-bitmap types */
1287 GpStatus WINGDIPAPI
GdipGetImagePixelFormat(GpImage
*image
, PixelFormat
*format
)
1289 TRACE("%p %p\n", image
, format
);
1291 if(!image
|| !format
)
1292 return InvalidParameter
;
1294 if(image
->type
!= ImageTypeBitmap
)
1295 *format
= PixelFormat24bppRGB
;
1297 *format
= ((GpBitmap
*) image
)->format
;
1302 GpStatus WINGDIPAPI
GdipGetImageRawFormat(GpImage
*image
, GUID
*format
)
1304 if(!image
|| !format
)
1305 return InvalidParameter
;
1307 memcpy(format
, &image
->format
, sizeof(GUID
));
1312 GpStatus WINGDIPAPI
GdipGetImageType(GpImage
*image
, ImageType
*type
)
1314 TRACE("%p %p\n", image
, type
);
1317 return InvalidParameter
;
1319 *type
= image
->type
;
1324 GpStatus WINGDIPAPI
GdipGetImageVerticalResolution(GpImage
*image
, REAL
*res
)
1329 return InvalidParameter
;
1332 FIXME("not implemented\n");
1334 return NotImplemented
;
1337 GpStatus WINGDIPAPI
GdipGetImageWidth(GpImage
*image
, UINT
*width
)
1339 TRACE("%p %p\n", image
, width
);
1341 if(!image
|| !width
)
1342 return InvalidParameter
;
1344 if(image
->type
== ImageTypeMetafile
){
1347 *width
= roundr(convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
1348 ((GpMetafile
*)image
)->bounds
.Width
);
1352 else if(image
->type
== ImageTypeBitmap
)
1353 *width
= ((GpBitmap
*)image
)->width
;
1355 *width
= ipicture_pixel_width(image
->picture
);
1357 TRACE("returning %d\n", *width
);
1362 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromMetafile(GpMetafile
* metafile
,
1363 MetafileHeader
* header
)
1367 if(!metafile
|| !header
)
1368 return InvalidParameter
;
1371 FIXME("not implemented\n");
1376 GpStatus WINGDIPAPI
GdipGetAllPropertyItems(GpImage
*image
, UINT size
,
1377 UINT num
, PropertyItem
* items
)
1382 FIXME("not implemented\n");
1384 return InvalidParameter
;
1387 GpStatus WINGDIPAPI
GdipGetPropertyCount(GpImage
*image
, UINT
* num
)
1392 FIXME("not implemented\n");
1394 return InvalidParameter
;
1397 GpStatus WINGDIPAPI
GdipGetPropertyIdList(GpImage
*image
, UINT num
, PROPID
* list
)
1402 FIXME("not implemented\n");
1404 return InvalidParameter
;
1407 GpStatus WINGDIPAPI
GdipGetPropertyItem(GpImage
*image
, PROPID id
, UINT size
,
1408 PropertyItem
* buffer
)
1413 FIXME("not implemented\n");
1415 return InvalidParameter
;
1418 GpStatus WINGDIPAPI
GdipGetPropertyItemSize(GpImage
*image
, PROPID pid
,
1423 TRACE("%p %x %p\n", image
, pid
, size
);
1426 return InvalidParameter
;
1429 FIXME("not implemented\n");
1431 return NotImplemented
;
1434 GpStatus WINGDIPAPI
GdipGetPropertySize(GpImage
*image
, UINT
* size
, UINT
* num
)
1439 FIXME("not implemented\n");
1441 return InvalidParameter
;
1444 GpStatus WINGDIPAPI
GdipImageGetFrameCount(GpImage
*image
,
1445 GDIPCONST GUID
* dimensionID
, UINT
* count
)
1449 if(!image
|| !dimensionID
|| !count
)
1450 return InvalidParameter
;
1453 FIXME("not implemented\n");
1455 return NotImplemented
;
1458 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsCount(GpImage
*image
,
1461 if(!image
|| !count
)
1462 return InvalidParameter
;
1471 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsList(GpImage
* image
,
1472 GUID
* dimensionIDs
, UINT count
)
1476 if(!image
|| !dimensionIDs
)
1477 return InvalidParameter
;
1480 FIXME("not implemented\n");
1485 GpStatus WINGDIPAPI
GdipImageSelectActiveFrame(GpImage
*image
,
1486 GDIPCONST GUID
* dimensionID
, UINT frameidx
)
1490 if(!image
|| !dimensionID
)
1491 return InvalidParameter
;
1494 FIXME("not implemented\n");
1499 GpStatus WINGDIPAPI
GdipLoadImageFromFile(GDIPCONST WCHAR
* filename
,
1505 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
1507 if (!filename
|| !image
)
1508 return InvalidParameter
;
1510 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
1515 stat
= GdipLoadImageFromStream(stream
, image
);
1517 IStream_Release(stream
);
1522 /* FIXME: no icm handling */
1523 GpStatus WINGDIPAPI
GdipLoadImageFromFileICM(GDIPCONST WCHAR
* filename
,GpImage
**image
)
1525 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
1527 return GdipLoadImageFromFile(filename
, image
);
1530 static const WICPixelFormatGUID
*wic_pixel_formats
[] = {
1531 &GUID_WICPixelFormat16bppBGR555
,
1532 &GUID_WICPixelFormat24bppBGR
,
1533 &GUID_WICPixelFormat32bppBGR
,
1534 &GUID_WICPixelFormat32bppBGRA
,
1535 &GUID_WICPixelFormat32bppPBGRA
,
1539 static const PixelFormat wic_gdip_formats
[] = {
1540 PixelFormat16bppRGB555
,
1541 PixelFormat24bppRGB
,
1542 PixelFormat32bppRGB
,
1543 PixelFormat32bppARGB
,
1544 PixelFormat32bppPARGB
,
1547 static GpStatus
decode_image_wic(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
1552 IWICBitmapDecoder
*decoder
;
1553 IWICBitmapFrameDecode
*frame
;
1554 IWICBitmapSource
*source
=NULL
;
1555 WICPixelFormatGUID wic_format
;
1556 PixelFormat gdip_format
=0;
1559 BitmapData lockeddata
;
1563 initresult
= CoInitialize(NULL
);
1565 hr
= CoCreateInstance(clsid
, NULL
, CLSCTX_INPROC_SERVER
,
1566 &IID_IWICBitmapDecoder
, (void**)&decoder
);
1567 if (FAILED(hr
)) goto end
;
1569 hr
= IWICBitmapDecoder_Initialize(decoder
, (IStream
*)stream
, WICDecodeMetadataCacheOnLoad
);
1571 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
1573 if (SUCCEEDED(hr
)) /* got frame */
1575 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &wic_format
);
1579 for (i
=0; wic_pixel_formats
[i
]; i
++)
1581 if (IsEqualGUID(&wic_format
, wic_pixel_formats
[i
]))
1583 source
= (IWICBitmapSource
*)frame
;
1584 IWICBitmapSource_AddRef(source
);
1585 gdip_format
= wic_gdip_formats
[i
];
1591 /* unknown format; fall back on 32bppARGB */
1592 hr
= WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA
, (IWICBitmapSource
*)frame
, &source
);
1593 gdip_format
= PixelFormat32bppARGB
;
1597 if (SUCCEEDED(hr
)) /* got source */
1599 hr
= IWICBitmapSource_GetSize(source
, &width
, &height
);
1602 status
= GdipCreateBitmapFromScan0(width
, height
, 0, gdip_format
,
1605 if (SUCCEEDED(hr
) && status
== Ok
) /* created bitmap */
1607 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeWrite
,
1608 gdip_format
, &lockeddata
);
1609 if (status
== Ok
) /* locked bitmap */
1614 for (i
=0; i
<height
; i
++)
1617 hr
= IWICBitmapSource_CopyPixels(source
, &wrc
, abs(lockeddata
.Stride
),
1618 abs(lockeddata
.Stride
), (BYTE
*)lockeddata
.Scan0
+lockeddata
.Stride
*i
);
1619 if (FAILED(hr
)) break;
1622 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1625 if (SUCCEEDED(hr
) && status
== Ok
)
1626 *image
= (GpImage
*)bitmap
;
1630 GdipDisposeImage((GpImage
*)bitmap
);
1634 IWICBitmapSource_Release(source
);
1637 IWICBitmapFrameDecode_Release(frame
);
1640 IWICBitmapDecoder_Release(decoder
);
1643 if (SUCCEEDED(initresult
)) CoUninitialize();
1645 if (FAILED(hr
) && status
== Ok
) status
= hresult_to_status(hr
);
1650 static GpStatus
decode_image_icon(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
1652 return decode_image_wic(stream
, &CLSID_WICIcoDecoder
, image
);
1655 static GpStatus
decode_image_bmp(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
1660 status
= decode_image_wic(stream
, &CLSID_WICBmpDecoder
, image
);
1662 bitmap
= (GpBitmap
*)*image
;
1664 if (status
== Ok
&& bitmap
->format
== PixelFormat32bppARGB
)
1666 /* WIC supports bmp files with alpha, but gdiplus does not */
1667 bitmap
->format
= PixelFormat32bppRGB
;
1673 static GpStatus
decode_image_jpeg(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
1675 return decode_image_wic(stream
, &CLSID_WICJpegDecoder
, image
);
1678 static GpStatus
decode_image_png(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
1680 return decode_image_wic(stream
, &CLSID_WICPngDecoder
, image
);
1683 static GpStatus
decode_image_gif(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
1685 return decode_image_wic(stream
, &CLSID_WICGifDecoder
, image
);
1688 static GpStatus
decode_image_olepicture_metafile(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
1692 TRACE("%p %p\n", stream
, image
);
1694 if(!stream
|| !image
)
1695 return InvalidParameter
;
1697 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
1698 (LPVOID
*) &pic
) != S_OK
){
1699 TRACE("Could not load picture\n");
1700 return GenericError
;
1703 /* FIXME: missing initialization code */
1704 *image
= GdipAlloc(sizeof(GpMetafile
));
1705 if(!*image
) return OutOfMemory
;
1706 (*image
)->type
= ImageTypeMetafile
;
1707 (*image
)->picture
= pic
;
1708 (*image
)->flags
= ImageFlagsNone
;
1713 typedef GpStatus (*encode_image_func
)(GpImage
*image
, IStream
* stream
,
1714 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
);
1716 typedef GpStatus (*decode_image_func
)(IStream
*stream
, REFCLSID clsid
, GpImage
** image
);
1718 typedef struct image_codec
{
1719 ImageCodecInfo info
;
1720 encode_image_func encode_func
;
1721 decode_image_func decode_func
;
1735 static const struct image_codec codecs
[NUM_CODECS
];
1737 static GpStatus
get_decoder_info(IStream
* stream
, const struct image_codec
**result
)
1745 /* seek to the start of the stream */
1747 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
1748 if (FAILED(hr
)) return hresult_to_status(hr
);
1750 /* read the first 8 bytes */
1751 /* FIXME: This assumes all codecs have one signature <= 8 bytes in length */
1752 hr
= IStream_Read(stream
, signature
, 8, &bytesread
);
1753 if (FAILED(hr
)) return hresult_to_status(hr
);
1754 if (hr
== S_FALSE
|| bytesread
== 0) return GenericError
;
1756 for (i
= 0; i
< NUM_CODECS
; i
++) {
1757 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
) &&
1758 bytesread
>= codecs
[i
].info
.SigSize
)
1760 for (j
=0; j
<codecs
[i
].info
.SigSize
; j
++)
1761 if ((signature
[j
] & codecs
[i
].info
.SigMask
[j
]) != codecs
[i
].info
.SigPattern
[j
])
1763 if (j
== codecs
[i
].info
.SigSize
)
1765 *result
= &codecs
[i
];
1771 TRACE("no match for %i byte signature %x %x %x %x %x %x %x %x\n", bytesread
,
1772 signature
[0],signature
[1],signature
[2],signature
[3],
1773 signature
[4],signature
[5],signature
[6],signature
[7]);
1775 return GenericError
;
1778 GpStatus WINGDIPAPI
GdipLoadImageFromStream(IStream
* stream
, GpImage
**image
)
1783 const struct image_codec
*codec
=NULL
;
1785 /* choose an appropriate image decoder */
1786 stat
= get_decoder_info(stream
, &codec
);
1787 if (stat
!= Ok
) return stat
;
1789 /* seek to the start of the stream */
1791 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
1792 if (FAILED(hr
)) return hresult_to_status(hr
);
1794 /* call on the image decoder to do the real work */
1795 stat
= codec
->decode_func(stream
, &codec
->info
.Clsid
, image
);
1797 /* take note of the original data format */
1800 memcpy(&(*image
)->format
, &codec
->info
.FormatID
, sizeof(GUID
));
1807 GpStatus WINGDIPAPI
GdipLoadImageFromStreamICM(IStream
* stream
, GpImage
**image
)
1809 TRACE("%p %p\n", stream
, image
);
1811 return GdipLoadImageFromStream(stream
, image
);
1814 GpStatus WINGDIPAPI
GdipRemovePropertyItem(GpImage
*image
, PROPID propId
)
1819 return InvalidParameter
;
1822 FIXME("not implemented\n");
1824 return NotImplemented
;
1827 GpStatus WINGDIPAPI
GdipSetPropertyItem(GpImage
*image
, GDIPCONST PropertyItem
* item
)
1832 FIXME("not implemented\n");
1834 return NotImplemented
;
1837 GpStatus WINGDIPAPI
GdipSaveImageToFile(GpImage
*image
, GDIPCONST WCHAR
* filename
,
1838 GDIPCONST CLSID
*clsidEncoder
,
1839 GDIPCONST EncoderParameters
*encoderParams
)
1844 TRACE("%p (%s) %p %p\n", image
, debugstr_w(filename
), clsidEncoder
, encoderParams
);
1846 if (!image
|| !filename
|| !clsidEncoder
)
1847 return InvalidParameter
;
1849 stat
= GdipCreateStreamOnFile(filename
, GENERIC_WRITE
, &stream
);
1851 return GenericError
;
1853 stat
= GdipSaveImageToStream(image
, stream
, clsidEncoder
, encoderParams
);
1855 IStream_Release(stream
);
1859 /*************************************************************************
1860 * Encoding functions -
1861 * These functions encode an image in different image file formats.
1863 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
1864 #define BITMAP_FORMAT_JPEG 0xd8ff
1865 #define BITMAP_FORMAT_GIF 0x4947
1866 #define BITMAP_FORMAT_PNG 0x5089
1867 #define BITMAP_FORMAT_APM 0xcdd7
1869 static GpStatus
encode_image_WIC(GpImage
*image
, IStream
* stream
,
1870 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
1874 IWICBitmapEncoder
*encoder
;
1875 IWICBitmapFrameEncode
*frameencode
;
1876 IPropertyBag2
*encoderoptions
;
1879 PixelFormat gdipformat
=0;
1880 WICPixelFormatGUID wicformat
;
1882 BitmapData lockeddata
;
1886 if (image
->type
!= ImageTypeBitmap
)
1887 return GenericError
;
1889 bitmap
= (GpBitmap
*)image
;
1891 GdipGetImageWidth(image
, &width
);
1892 GdipGetImageHeight(image
, &height
);
1899 initresult
= CoInitialize(NULL
);
1901 hr
= CoCreateInstance(clsid
, NULL
, CLSCTX_INPROC_SERVER
,
1902 &IID_IWICBitmapEncoder
, (void**)&encoder
);
1905 if (SUCCEEDED(initresult
)) CoUninitialize();
1906 return hresult_to_status(hr
);
1909 hr
= IWICBitmapEncoder_Initialize(encoder
, stream
, WICBitmapEncoderNoCache
);
1913 hr
= IWICBitmapEncoder_CreateNewFrame(encoder
, &frameencode
, &encoderoptions
);
1916 if (SUCCEEDED(hr
)) /* created frame */
1918 hr
= IWICBitmapFrameEncode_Initialize(frameencode
, encoderoptions
);
1921 hr
= IWICBitmapFrameEncode_SetSize(frameencode
, width
, height
);
1924 /* FIXME: use the resolution from the image */
1925 hr
= IWICBitmapFrameEncode_SetResolution(frameencode
, 96.0, 96.0);
1929 for (i
=0; wic_pixel_formats
[i
]; i
++)
1931 if (wic_gdip_formats
[i
] == bitmap
->format
)
1934 if (wic_pixel_formats
[i
])
1935 memcpy(&wicformat
, wic_pixel_formats
[i
], sizeof(GUID
));
1937 memcpy(&wicformat
, &GUID_WICPixelFormat32bppBGRA
, sizeof(GUID
));
1939 hr
= IWICBitmapFrameEncode_SetPixelFormat(frameencode
, &wicformat
);
1941 for (i
=0; wic_pixel_formats
[i
]; i
++)
1943 if (IsEqualGUID(&wicformat
, wic_pixel_formats
[i
]))
1946 if (wic_pixel_formats
[i
])
1947 gdipformat
= wic_gdip_formats
[i
];
1950 ERR("cannot provide pixel format %s\n", debugstr_guid(&wicformat
));
1957 stat
= GdipBitmapLockBits(bitmap
, &rc
, ImageLockModeRead
, gdipformat
,
1962 UINT row_size
= (lockeddata
.Width
* PIXELFORMATBPP(gdipformat
) + 7)/8;
1965 /* write one row at a time in case stride is negative */
1966 row
= lockeddata
.Scan0
;
1967 for (i
=0; i
<lockeddata
.Height
; i
++)
1969 hr
= IWICBitmapFrameEncode_WritePixels(frameencode
, 1, row_size
, row_size
, row
);
1970 if (FAILED(hr
)) break;
1971 row
+= lockeddata
.Stride
;
1974 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1981 hr
= IWICBitmapFrameEncode_Commit(frameencode
);
1983 IWICBitmapFrameEncode_Release(frameencode
);
1984 IPropertyBag2_Release(encoderoptions
);
1988 hr
= IWICBitmapEncoder_Commit(encoder
);
1990 IWICBitmapEncoder_Release(encoder
);
1992 if (SUCCEEDED(initresult
)) CoUninitialize();
1994 return hresult_to_status(hr
);
1997 static GpStatus
encode_image_BMP(GpImage
*image
, IStream
* stream
,
1998 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
2000 return encode_image_WIC(image
, stream
, &CLSID_WICBmpEncoder
, params
);
2003 /*****************************************************************************
2004 * GdipSaveImageToStream [GDIPLUS.@]
2006 GpStatus WINGDIPAPI
GdipSaveImageToStream(GpImage
*image
, IStream
* stream
,
2007 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
2010 encode_image_func encode_image
;
2013 TRACE("%p %p %p %p\n", image
, stream
, clsid
, params
);
2015 if(!image
|| !stream
)
2016 return InvalidParameter
;
2018 /* select correct encoder */
2019 encode_image
= NULL
;
2020 for (i
= 0; i
< NUM_CODECS
; i
++) {
2021 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
) &&
2022 IsEqualCLSID(clsid
, &codecs
[i
].info
.Clsid
))
2023 encode_image
= codecs
[i
].encode_func
;
2025 if (encode_image
== NULL
)
2026 return UnknownImageFormat
;
2028 stat
= encode_image(image
, stream
, clsid
, params
);
2033 /*****************************************************************************
2034 * GdipGetImagePalette [GDIPLUS.@]
2036 GpStatus WINGDIPAPI
GdipGetImagePalette(GpImage
*image
, ColorPalette
*palette
, INT size
)
2038 static int calls
= 0;
2041 return InvalidParameter
;
2044 FIXME("not implemented\n");
2046 return NotImplemented
;
2049 /*****************************************************************************
2050 * GdipSetImagePalette [GDIPLUS.@]
2052 GpStatus WINGDIPAPI
GdipSetImagePalette(GpImage
*image
,
2053 GDIPCONST ColorPalette
*palette
)
2057 if(!image
|| !palette
)
2058 return InvalidParameter
;
2061 FIXME("not implemented\n");
2063 return NotImplemented
;
2066 /*************************************************************************
2068 * Structures that represent which formats we support for encoding.
2071 /* ImageCodecInfo creation routines taken from libgdiplus */
2072 static const WCHAR bmp_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
2073 static const WCHAR bmp_extension
[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
2074 static const WCHAR bmp_mimetype
[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
2075 static const WCHAR bmp_format
[] = {'B', 'M', 'P', 0}; /* BMP */
2076 static const BYTE bmp_sig_pattern
[] = { 0x42, 0x4D };
2077 static const BYTE bmp_sig_mask
[] = { 0xFF, 0xFF };
2079 static const WCHAR jpeg_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'J','P','E','G', 0};
2080 static const WCHAR jpeg_extension
[] = {'*','.','J','P','G',';', '*','.','J','P','E','G',';', '*','.','J','P','E',';', '*','.','J','F','I','F',0};
2081 static const WCHAR jpeg_mimetype
[] = {'i','m','a','g','e','/','j','p','e','g', 0};
2082 static const WCHAR jpeg_format
[] = {'J','P','E','G',0};
2083 static const BYTE jpeg_sig_pattern
[] = { 0xFF, 0xD8 };
2084 static const BYTE jpeg_sig_mask
[] = { 0xFF, 0xFF };
2086 static const WCHAR gif_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'G','I','F', 0};
2087 static const WCHAR gif_extension
[] = {'*','.','G','I','F',0};
2088 static const WCHAR gif_mimetype
[] = {'i','m','a','g','e','/','g','i','f', 0};
2089 static const WCHAR gif_format
[] = {'G','I','F',0};
2090 static const BYTE gif_sig_pattern
[4] = "GIF8";
2091 static const BYTE gif_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
2093 static const WCHAR emf_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'E','M','F', 0};
2094 static const WCHAR emf_extension
[] = {'*','.','E','M','F',0};
2095 static const WCHAR emf_mimetype
[] = {'i','m','a','g','e','/','x','-','e','m','f', 0};
2096 static const WCHAR emf_format
[] = {'E','M','F',0};
2097 static const BYTE emf_sig_pattern
[] = { 0x01, 0x00, 0x00, 0x00 };
2098 static const BYTE emf_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
2100 static const WCHAR wmf_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'W','M','F', 0};
2101 static const WCHAR wmf_extension
[] = {'*','.','W','M','F',0};
2102 static const WCHAR wmf_mimetype
[] = {'i','m','a','g','e','/','x','-','w','m','f', 0};
2103 static const WCHAR wmf_format
[] = {'W','M','F',0};
2104 static const BYTE wmf_sig_pattern
[] = { 0xd7, 0xcd };
2105 static const BYTE wmf_sig_mask
[] = { 0xFF, 0xFF };
2107 static const WCHAR png_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'P','N','G', 0};
2108 static const WCHAR png_extension
[] = {'*','.','P','N','G',0};
2109 static const WCHAR png_mimetype
[] = {'i','m','a','g','e','/','p','n','g', 0};
2110 static const WCHAR png_format
[] = {'P','N','G',0};
2111 static const BYTE png_sig_pattern
[] = { 137, 80, 78, 71, 13, 10, 26, 10, };
2112 static const BYTE png_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
2114 static const WCHAR ico_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'I','C','O', 0};
2115 static const WCHAR ico_extension
[] = {'*','.','I','C','O',0};
2116 static const WCHAR ico_mimetype
[] = {'i','m','a','g','e','/','x','-','i','c','o','n', 0};
2117 static const WCHAR ico_format
[] = {'I','C','O',0};
2118 static const BYTE ico_sig_pattern
[] = { 0x00, 0x00, 0x01, 0x00 };
2119 static const BYTE ico_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
2121 static const struct image_codec codecs
[NUM_CODECS
] = {
2124 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2125 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2126 /* CodecName */ bmp_codecname
,
2128 /* FormatDescription */ bmp_format
,
2129 /* FilenameExtension */ bmp_extension
,
2130 /* MimeType */ bmp_mimetype
,
2131 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
2135 /* SigPattern */ bmp_sig_pattern
,
2136 /* SigMask */ bmp_sig_mask
,
2143 /* Clsid */ { 0x557cf401, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2144 /* FormatID */ { 0xb96b3caeU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2145 /* CodecName */ jpeg_codecname
,
2147 /* FormatDescription */ jpeg_format
,
2148 /* FilenameExtension */ jpeg_extension
,
2149 /* MimeType */ jpeg_mimetype
,
2150 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
2154 /* SigPattern */ jpeg_sig_pattern
,
2155 /* SigMask */ jpeg_sig_mask
,
2162 /* Clsid */ { 0x557cf402, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2163 /* FormatID */ { 0xb96b3cb0U
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2164 /* CodecName */ gif_codecname
,
2166 /* FormatDescription */ gif_format
,
2167 /* FilenameExtension */ gif_extension
,
2168 /* MimeType */ gif_mimetype
,
2169 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
2173 /* SigPattern */ gif_sig_pattern
,
2174 /* SigMask */ gif_sig_mask
,
2181 /* Clsid */ { 0x557cf403, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2182 /* FormatID */ { 0xb96b3cacU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2183 /* CodecName */ emf_codecname
,
2185 /* FormatDescription */ emf_format
,
2186 /* FilenameExtension */ emf_extension
,
2187 /* MimeType */ emf_mimetype
,
2188 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
2192 /* SigPattern */ emf_sig_pattern
,
2193 /* SigMask */ emf_sig_mask
,
2196 decode_image_olepicture_metafile
2200 /* Clsid */ { 0x557cf404, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2201 /* FormatID */ { 0xb96b3cadU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2202 /* CodecName */ wmf_codecname
,
2204 /* FormatDescription */ wmf_format
,
2205 /* FilenameExtension */ wmf_extension
,
2206 /* MimeType */ wmf_mimetype
,
2207 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
2211 /* SigPattern */ wmf_sig_pattern
,
2212 /* SigMask */ wmf_sig_mask
,
2215 decode_image_olepicture_metafile
2219 /* Clsid */ { 0x557cf406, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2220 /* FormatID */ { 0xb96b3cafU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2221 /* CodecName */ png_codecname
,
2223 /* FormatDescription */ png_format
,
2224 /* FilenameExtension */ png_extension
,
2225 /* MimeType */ png_mimetype
,
2226 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
2230 /* SigPattern */ png_sig_pattern
,
2231 /* SigMask */ png_sig_mask
,
2238 /* Clsid */ { 0x557cf407, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2239 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2240 /* CodecName */ ico_codecname
,
2242 /* FormatDescription */ ico_format
,
2243 /* FilenameExtension */ ico_extension
,
2244 /* MimeType */ ico_mimetype
,
2245 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
2249 /* SigPattern */ ico_sig_pattern
,
2250 /* SigMask */ ico_sig_mask
,
2257 /*****************************************************************************
2258 * GdipGetImageDecodersSize [GDIPLUS.@]
2260 GpStatus WINGDIPAPI
GdipGetImageDecodersSize(UINT
*numDecoders
, UINT
*size
)
2262 int decoder_count
=0;
2264 TRACE("%p %p\n", numDecoders
, size
);
2266 if (!numDecoders
|| !size
)
2267 return InvalidParameter
;
2269 for (i
=0; i
<NUM_CODECS
; i
++)
2271 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
2275 *numDecoders
= decoder_count
;
2276 *size
= decoder_count
* sizeof(ImageCodecInfo
);
2281 /*****************************************************************************
2282 * GdipGetImageDecoders [GDIPLUS.@]
2284 GpStatus WINGDIPAPI
GdipGetImageDecoders(UINT numDecoders
, UINT size
, ImageCodecInfo
*decoders
)
2286 int i
, decoder_count
=0;
2287 TRACE("%u %u %p\n", numDecoders
, size
, decoders
);
2290 size
!= numDecoders
* sizeof(ImageCodecInfo
))
2291 return GenericError
;
2293 for (i
=0; i
<NUM_CODECS
; i
++)
2295 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
2297 if (decoder_count
== numDecoders
) return GenericError
;
2298 memcpy(&decoders
[decoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
2303 if (decoder_count
< numDecoders
) return GenericError
;
2308 /*****************************************************************************
2309 * GdipGetImageEncodersSize [GDIPLUS.@]
2311 GpStatus WINGDIPAPI
GdipGetImageEncodersSize(UINT
*numEncoders
, UINT
*size
)
2313 int encoder_count
=0;
2315 TRACE("%p %p\n", numEncoders
, size
);
2317 if (!numEncoders
|| !size
)
2318 return InvalidParameter
;
2320 for (i
=0; i
<NUM_CODECS
; i
++)
2322 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
2326 *numEncoders
= encoder_count
;
2327 *size
= encoder_count
* sizeof(ImageCodecInfo
);
2332 /*****************************************************************************
2333 * GdipGetImageEncoders [GDIPLUS.@]
2335 GpStatus WINGDIPAPI
GdipGetImageEncoders(UINT numEncoders
, UINT size
, ImageCodecInfo
*encoders
)
2337 int i
, encoder_count
=0;
2338 TRACE("%u %u %p\n", numEncoders
, size
, encoders
);
2341 size
!= numEncoders
* sizeof(ImageCodecInfo
))
2342 return GenericError
;
2344 for (i
=0; i
<NUM_CODECS
; i
++)
2346 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
2348 if (encoder_count
== numEncoders
) return GenericError
;
2349 memcpy(&encoders
[encoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
2354 if (encoder_count
< numEncoders
) return GenericError
;
2359 /*****************************************************************************
2360 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
2362 GpStatus WINGDIPAPI
GdipCreateBitmapFromHBITMAP(HBITMAP hbm
, HPALETTE hpal
, GpBitmap
** bitmap
)
2369 TRACE("%p %p %p\n", hbm
, hpal
, bitmap
);
2372 return InvalidParameter
;
2374 /* TODO: Support for device-dependent bitmaps */
2376 FIXME("no support for device-dependent bitmaps\n");
2377 return NotImplemented
;
2380 if (GetObjectA(hbm
, sizeof(bm
), &bm
) != sizeof(bm
))
2381 return InvalidParameter
;
2383 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
2384 switch(bm
.bmBitsPixel
) {
2386 format
= PixelFormat1bppIndexed
;
2389 format
= PixelFormat4bppIndexed
;
2392 format
= PixelFormat8bppIndexed
;
2395 format
= PixelFormat24bppRGB
;
2398 format
= PixelFormat32bppRGB
;
2401 format
= PixelFormat48bppRGB
;
2404 FIXME("don't know how to handle %d bpp\n", bm
.bmBitsPixel
);
2405 return InvalidParameter
;
2409 bits
= (BYTE
*)bm
.bmBits
+ (bm
.bmHeight
- 1) * bm
.bmWidthBytes
;
2412 FIXME("can only get image data from DIB sections\n");
2416 retval
= GdipCreateBitmapFromScan0(bm
.bmWidth
, bm
.bmHeight
, -bm
.bmWidthBytes
,
2417 format
, bits
, bitmap
);
2422 GpStatus WINGDIPAPI
GdipDeleteEffect(CGpEffect
*effect
)
2424 FIXME("(%p): stub\n", effect
);
2425 /* note: According to Jose Roca's GDI+ Docs, this is not implemented
2426 * in Windows's gdiplus */
2427 return NotImplemented
;
2430 /*****************************************************************************
2431 * GdipSetEffectParameters [GDIPLUS.@]
2433 GpStatus WINGDIPAPI
GdipSetEffectParameters(CGpEffect
*effect
,
2434 const VOID
*params
, const UINT size
)
2439 FIXME("not implemented\n");
2441 return NotImplemented
;
2444 /*****************************************************************************
2445 * GdipGetImageFlags [GDIPLUS.@]
2447 GpStatus WINGDIPAPI
GdipGetImageFlags(GpImage
*image
, UINT
*flags
)
2449 TRACE("%p %p\n", image
, flags
);
2451 if(!image
|| !flags
)
2452 return InvalidParameter
;
2454 *flags
= image
->flags
;
2459 GpStatus WINGDIPAPI
GdipTestControl(GpTestControlEnum control
, void *param
)
2461 TRACE("(%d, %p)\n", control
, param
);
2464 case TestControlForceBilinear
:
2466 FIXME("TestControlForceBilinear not handled\n");
2468 case TestControlNoICM
:
2470 FIXME("TestControlNoICM not handled\n");
2472 case TestControlGetBuildNumber
:
2473 *((DWORD
*)param
) = 3102;
2480 GpStatus WINGDIPAPI
GdipRecordMetafileFileName(GDIPCONST WCHAR
* fileName
,
2481 HDC hdc
, EmfType type
, GDIPCONST GpRectF
*pFrameRect
,
2482 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
,
2483 GpMetafile
**metafile
)
2485 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName
), hdc
, type
, pFrameRect
,
2486 frameUnit
, debugstr_w(desc
), metafile
);
2488 return NotImplemented
;
2491 GpStatus WINGDIPAPI
GdipRecordMetafileFileNameI(GDIPCONST WCHAR
* fileName
, HDC hdc
, EmfType type
,
2492 GDIPCONST GpRect
*pFrameRect
, MetafileFrameUnit frameUnit
,
2493 GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
2495 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName
), hdc
, type
, pFrameRect
,
2496 frameUnit
, debugstr_w(desc
), metafile
);
2498 return NotImplemented
;
2501 GpStatus WINGDIPAPI
GdipImageForceValidation(GpImage
*image
)
2503 FIXME("%p\n", image
);
2508 /*****************************************************************************
2509 * GdipGetImageThumbnail [GDIPLUS.@]
2511 GpStatus WINGDIPAPI
GdipGetImageThumbnail(GpImage
*image
, UINT width
, UINT height
,
2512 GpImage
**ret_image
, GetThumbnailImageAbort cb
,
2515 FIXME("(%p %u %u %p %p %p) stub\n",
2516 image
, width
, height
, ret_image
, cb
, cb_data
);
2517 return NotImplemented
;
2520 /*****************************************************************************
2521 * GdipImageRotateFlip [GDIPLUS.@]
2523 GpStatus WINGDIPAPI
GdipImageRotateFlip(GpImage
*image
, RotateFlipType type
)
2525 FIXME("(%p %u) stub\n", image
, type
);
2526 return NotImplemented
;