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
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
)
47 IPicture_get_Height(pic
, &y
);
51 y
= MulDiv(y
, GetDeviceCaps(hdcref
, LOGPIXELSY
), INCH_HIMETRIC
);
57 static INT
ipicture_pixel_width(IPicture
*pic
)
62 IPicture_get_Width(pic
, &x
);
66 x
= MulDiv(x
, GetDeviceCaps(hdcref
, LOGPIXELSX
), INCH_HIMETRIC
);
73 GpStatus WINGDIPAPI
GdipBitmapGetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
77 TRACE("%p %d %d %p\n", bitmap
, x
, y
, color
);
80 return InvalidParameter
;
83 FIXME("not implemented\n");
87 return NotImplemented
;
90 /* This function returns a pointer to an array of pixels that represents the
91 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
92 * flags. It is correct behavior that a user who calls this function with write
93 * privileges can write to the whole bitmap (not just the area in rect).
95 * FIXME: only used portion of format is bits per pixel. */
96 GpStatus WINGDIPAPI
GdipBitmapLockBits(GpBitmap
* bitmap
, GDIPCONST GpRect
* rect
,
97 UINT flags
, PixelFormat format
, BitmapData
* lockeddata
)
100 INT stride
, bitspp
= PIXELFORMATBPP(format
);
102 HBITMAP hbm
, old
= NULL
;
106 GpRect act_rect
; /* actual rect to be used */
108 TRACE("%p %p %d %d %p\n", bitmap
, rect
, flags
, format
, lockeddata
);
110 if(!lockeddata
|| !bitmap
)
111 return InvalidParameter
;
114 if(rect
->X
< 0 || rect
->Y
< 0 || (rect
->X
+ rect
->Width
> bitmap
->width
) ||
115 (rect
->Y
+ rect
->Height
> bitmap
->height
) || !flags
)
116 return InvalidParameter
;
121 act_rect
.X
= act_rect
.Y
= 0;
122 act_rect
.Width
= bitmap
->width
;
123 act_rect
.Height
= bitmap
->height
;
126 if(flags
& ImageLockModeUserInputBuf
)
127 return NotImplemented
;
132 IPicture_get_Handle(bitmap
->image
.picture
, (OLE_HANDLE
*)&hbm
);
133 IPicture_get_CurDC(bitmap
->image
.picture
, &hdc
);
134 bm_is_selected
= (hdc
!= 0);
136 pbmi
= GdipAlloc(sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
139 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
140 pbmi
->bmiHeader
.biBitCount
= 0;
143 hdc
= CreateCompatibleDC(0);
144 old
= SelectObject(hdc
, hbm
);
148 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
150 abs_height
= abs(pbmi
->bmiHeader
.biHeight
);
151 stride
= pbmi
->bmiHeader
.biWidth
* bitspp
/ 8;
152 stride
= (stride
+ 3) & ~3;
154 buff
= GdipAlloc(stride
* abs_height
);
156 pbmi
->bmiHeader
.biBitCount
= bitspp
;
159 GetDIBits(hdc
, hbm
, 0, abs_height
, buff
, pbmi
, DIB_RGB_COLORS
);
162 SelectObject(hdc
, old
);
171 lockeddata
->Width
= act_rect
.Width
;
172 lockeddata
->Height
= act_rect
.Height
;
173 lockeddata
->PixelFormat
= format
;
174 lockeddata
->Reserved
= flags
;
176 if(pbmi
->bmiHeader
.biHeight
> 0){
177 lockeddata
->Stride
= -stride
;
178 lockeddata
->Scan0
= buff
+ (bitspp
/ 8) * act_rect
.X
+
179 stride
* (abs_height
- 1 - act_rect
.Y
);
182 lockeddata
->Stride
= stride
;
183 lockeddata
->Scan0
= buff
+ (bitspp
/ 8) * act_rect
.X
+ stride
* act_rect
.Y
;
186 bitmap
->lockmode
= flags
;
189 bitmap
->bitmapbits
= buff
;
195 GpStatus WINGDIPAPI
GdipBitmapUnlockBits(GpBitmap
* bitmap
,
196 BitmapData
* lockeddata
)
199 HBITMAP hbm
, old
= NULL
;
203 if(!bitmap
|| !lockeddata
)
204 return InvalidParameter
;
206 if(!bitmap
->lockmode
)
209 if(lockeddata
->Reserved
& ImageLockModeUserInputBuf
)
210 return NotImplemented
;
212 if(lockeddata
->Reserved
& ImageLockModeRead
){
213 if(!(--bitmap
->numlocks
))
214 bitmap
->lockmode
= 0;
216 GdipFree(bitmap
->bitmapbits
);
217 bitmap
->bitmapbits
= NULL
;
221 IPicture_get_Handle(bitmap
->image
.picture
, (OLE_HANDLE
*)&hbm
);
222 IPicture_get_CurDC(bitmap
->image
.picture
, &hdc
);
223 bm_is_selected
= (hdc
!= 0);
225 pbmi
= GdipAlloc(sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
226 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
227 pbmi
->bmiHeader
.biBitCount
= 0;
230 hdc
= CreateCompatibleDC(0);
231 old
= SelectObject(hdc
, hbm
);
234 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
235 pbmi
->bmiHeader
.biBitCount
= PIXELFORMATBPP(lockeddata
->PixelFormat
);
236 SetDIBits(hdc
, hbm
, 0, abs(pbmi
->bmiHeader
.biHeight
),
237 bitmap
->bitmapbits
, pbmi
, DIB_RGB_COLORS
);
240 SelectObject(hdc
, old
);
245 GdipFree(bitmap
->bitmapbits
);
246 bitmap
->bitmapbits
= NULL
;
247 bitmap
->lockmode
= 0;
252 GpStatus WINGDIPAPI
GdipCloneImage(GpImage
*image
, GpImage
**cloneImage
)
258 GpStatus stat
= GenericError
;
260 TRACE("%p, %p\n", image
, cloneImage
);
262 if (!image
|| !cloneImage
)
263 return InvalidParameter
;
265 hr
= CreateStreamOnHGlobal(0, TRUE
, &stream
);
269 hr
= IPicture_SaveAsFile(image
->picture
, stream
, FALSE
, &size
);
272 WARN("Failed to save image on stream\n");
276 /* Set seek pointer back to the beginning of the picture */
278 hr
= IStream_Seek(stream
, move
, STREAM_SEEK_SET
, NULL
);
282 stat
= GdipLoadImageFromStream(stream
, cloneImage
);
283 if (stat
!= Ok
) WARN("Failed to load image from stream\n");
286 IStream_Release(stream
);
290 GpStatus WINGDIPAPI
GdipCreateBitmapFromFile(GDIPCONST WCHAR
* filename
,
296 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
298 if(!filename
|| !bitmap
)
299 return InvalidParameter
;
301 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
306 stat
= GdipCreateBitmapFromStream(stream
, bitmap
);
308 IStream_Release(stream
);
313 GpStatus WINGDIPAPI
GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO
* info
,
314 VOID
*bits
, GpBitmap
**bitmap
)
316 DWORD height
, stride
;
319 FIXME("(%p, %p, %p) - partially implemented\n", info
, bits
, bitmap
);
321 height
= abs(info
->bmiHeader
.biHeight
);
322 stride
= ((info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
+ 31) >> 3) & ~3;
324 if(info
->bmiHeader
.biHeight
> 0) /* bottom-up */
326 bits
= (BYTE
*)bits
+ (height
- 1) * stride
;
330 switch(info
->bmiHeader
.biBitCount
) {
332 format
= PixelFormat1bppIndexed
;
335 format
= PixelFormat4bppIndexed
;
338 format
= PixelFormat8bppIndexed
;
341 format
= PixelFormat24bppRGB
;
344 FIXME("don't know how to handle %d bpp\n", info
->bmiHeader
.biBitCount
);
346 return InvalidParameter
;
349 return GdipCreateBitmapFromScan0(info
->bmiHeader
.biWidth
, height
, stride
, format
,
355 GpStatus WINGDIPAPI
GdipCreateBitmapFromFileICM(GDIPCONST WCHAR
* filename
,
358 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
360 return GdipCreateBitmapFromFile(filename
, bitmap
);
363 GpStatus WINGDIPAPI
GdipCreateBitmapFromResource(HINSTANCE hInstance
,
364 GDIPCONST WCHAR
* lpBitmapName
, GpBitmap
** bitmap
)
367 GpStatus stat
= InvalidParameter
;
369 TRACE("%p (%s) %p\n", hInstance
, debugstr_w(lpBitmapName
), bitmap
);
371 if(!lpBitmapName
|| !bitmap
)
372 return InvalidParameter
;
375 hbm
= LoadImageW(hInstance
, lpBitmapName
, IMAGE_BITMAP
, 0, 0,
376 LR_CREATEDIBSECTION
);
379 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, bitmap
);
386 GpStatus WINGDIPAPI
GdipCreateHBITMAPFromBitmap(GpBitmap
* bitmap
,
387 HBITMAP
* hbmReturn
, ARGB background
)
393 return NotImplemented
;
396 GpStatus WINGDIPAPI
GdipConvertToEmfPlus(const GpGraphics
* ref
,
397 GpMetafile
* metafile
, BOOL
* succ
, EmfType emfType
,
398 const WCHAR
* description
, GpMetafile
** out_metafile
)
402 if(!ref
|| !metafile
|| !out_metafile
)
403 return InvalidParameter
;
406 *out_metafile
= NULL
;
409 FIXME("not implemented\n");
411 return NotImplemented
;
414 /* FIXME: this should create a bitmap in the given size with the attributes
415 * (resolution etc.) of the graphics object */
416 GpStatus WINGDIPAPI
GdipCreateBitmapFromGraphics(INT width
, INT height
,
417 GpGraphics
* target
, GpBitmap
** bitmap
)
422 if(!target
|| !bitmap
)
423 return InvalidParameter
;
426 FIXME("hacked stub\n");
428 ret
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat24bppRGB
,
434 GpStatus WINGDIPAPI
GdipCreateBitmapFromHICON(HICON hicon
, GpBitmap
** bitmap
)
440 TRACE("%p, %p\n", hicon
, bitmap
);
442 if(!bitmap
|| !GetIconInfo(hicon
, &iinfo
))
443 return InvalidParameter
;
445 *bitmap
= GdipAlloc(sizeof(GpBitmap
));
446 if(!*bitmap
) return OutOfMemory
;
448 icon_copy
= CreateIconIndirect(&iinfo
);
452 return InvalidParameter
;
455 desc
.cbSizeofstruct
= sizeof(PICTDESC
);
456 desc
.picType
= PICTYPE_ICON
;
457 desc
.u
.icon
.hicon
= icon_copy
;
459 if(OleCreatePictureIndirect(&desc
, &IID_IPicture
, TRUE
,
460 (LPVOID
*) &((*bitmap
)->image
.picture
)) != S_OK
){
461 DestroyIcon(icon_copy
);
466 (*bitmap
)->format
= PixelFormat32bppARGB
;
467 (*bitmap
)->image
.type
= ImageTypeBitmap
;
468 (*bitmap
)->image
.flags
= ImageFlagsNone
;
469 (*bitmap
)->width
= ipicture_pixel_width((*bitmap
)->image
.picture
);
470 (*bitmap
)->height
= ipicture_pixel_height((*bitmap
)->image
.picture
);
472 DeleteObject(iinfo
.hbmColor
);
473 DeleteObject(iinfo
.hbmMask
);
478 GpStatus WINGDIPAPI
GdipCreateBitmapFromScan0(INT width
, INT height
, INT stride
,
479 PixelFormat format
, BYTE
* scan0
, GpBitmap
** bitmap
)
481 BITMAPFILEHEADER
*bmfh
;
482 BITMAPINFOHEADER
*bmih
;
487 TRACE("%d %d %d %d %p %p\n", width
, height
, stride
, format
, scan0
, bitmap
);
489 if (!bitmap
) return InvalidParameter
;
491 if(width
<= 0 || height
<= 0 || (scan0
&& (stride
% 4))){
493 return InvalidParameter
;
497 return InvalidParameter
;
499 *bitmap
= GdipAlloc(sizeof(GpBitmap
));
500 if(!*bitmap
) return OutOfMemory
;
503 stride
= width
* (PIXELFORMATBPP(format
) / 8);
504 stride
= (stride
+ 3) & ~3;
507 datalen
= abs(stride
* height
);
508 size
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
) + datalen
;
509 buff
= GdipAlloc(size
);
515 bmfh
= (BITMAPFILEHEADER
*) buff
;
516 bmih
= (BITMAPINFOHEADER
*) (bmfh
+ 1);
518 bmfh
->bfType
= (((WORD
)'M') << 8) + (WORD
)'B';
520 bmfh
->bfOffBits
= size
- datalen
;
522 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
523 bmih
->biWidth
= width
;
524 /* FIXME: use the rest of the data from format */
525 bmih
->biBitCount
= PIXELFORMATBPP(format
);
526 bmih
->biCompression
= BI_RGB
;
527 bmih
->biSizeImage
= datalen
;
533 bmih
->biHeight
= -height
;
534 memcpy(bmih
+ 1, scan0
, datalen
);
538 bmih
->biHeight
= height
;
539 memcpy(bmih
+ 1, scan0
+ stride
* (height
- 1), datalen
);
544 bmih
->biHeight
= height
;
545 memset(bmih
+ 1, 0, datalen
);
548 if(CreateStreamOnHGlobal(buff
, TRUE
, &stream
) != S_OK
){
549 ERR("could not make stream\n");
555 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
556 (LPVOID
*) &((*bitmap
)->image
.picture
)) != S_OK
){
557 TRACE("Could not load picture\n");
558 IStream_Release(stream
);
564 (*bitmap
)->image
.type
= ImageTypeBitmap
;
565 (*bitmap
)->image
.flags
= ImageFlagsNone
;
566 (*bitmap
)->width
= width
;
567 (*bitmap
)->height
= height
;
568 (*bitmap
)->format
= format
;
573 GpStatus WINGDIPAPI
GdipCreateBitmapFromStream(IStream
* stream
,
578 TRACE("%p %p\n", stream
, bitmap
);
580 stat
= GdipLoadImageFromStream(stream
, (GpImage
**) bitmap
);
585 if((*bitmap
)->image
.type
!= ImageTypeBitmap
){
586 IPicture_Release((*bitmap
)->image
.picture
);
588 return GenericError
; /* FIXME: what error to return? */
595 GpStatus WINGDIPAPI
GdipCreateBitmapFromStreamICM(IStream
* stream
,
598 TRACE("%p %p\n", stream
, bitmap
);
600 return GdipCreateBitmapFromStream(stream
, bitmap
);
603 GpStatus WINGDIPAPI
GdipCreateCachedBitmap(GpBitmap
*bitmap
, GpGraphics
*graphics
,
604 GpCachedBitmap
**cachedbmp
)
608 TRACE("%p %p %p\n", bitmap
, graphics
, cachedbmp
);
610 if(!bitmap
|| !graphics
|| !cachedbmp
)
611 return InvalidParameter
;
613 *cachedbmp
= GdipAlloc(sizeof(GpCachedBitmap
));
617 stat
= GdipCloneImage(&(bitmap
->image
), &(*cachedbmp
)->image
);
619 GdipFree(*cachedbmp
);
626 GpStatus WINGDIPAPI
GdipDeleteCachedBitmap(GpCachedBitmap
*cachedbmp
)
628 TRACE("%p\n", cachedbmp
);
631 return InvalidParameter
;
633 GdipDisposeImage(cachedbmp
->image
);
639 GpStatus WINGDIPAPI
GdipDrawCachedBitmap(GpGraphics
*graphics
,
640 GpCachedBitmap
*cachedbmp
, INT x
, INT y
)
642 TRACE("%p %p %d %d\n", graphics
, cachedbmp
, x
, y
);
644 if(!graphics
|| !cachedbmp
)
645 return InvalidParameter
;
647 return GdipDrawImage(graphics
, cachedbmp
->image
, (REAL
)x
, (REAL
)y
);
650 GpStatus WINGDIPAPI
GdipDisposeImage(GpImage
*image
)
654 TRACE("%p\n", image
);
657 return InvalidParameter
;
659 IPicture_get_CurDC(image
->picture
, &hdc
);
661 IPicture_Release(image
->picture
);
662 if (image
->type
== ImageTypeBitmap
)
663 GdipFree(((GpBitmap
*)image
)->bitmapbits
);
669 GpStatus WINGDIPAPI
GdipFindFirstImageItem(GpImage
*image
, ImageItemData
* item
)
672 return InvalidParameter
;
674 return NotImplemented
;
677 GpStatus WINGDIPAPI
GdipGetImageBounds(GpImage
*image
, GpRectF
*srcRect
,
680 TRACE("%p %p %p\n", image
, srcRect
, srcUnit
);
682 if(!image
|| !srcRect
|| !srcUnit
)
683 return InvalidParameter
;
684 if(image
->type
== ImageTypeMetafile
){
685 *srcRect
= ((GpMetafile
*)image
)->bounds
;
686 *srcUnit
= ((GpMetafile
*)image
)->unit
;
688 else if(image
->type
== ImageTypeBitmap
){
689 srcRect
->X
= srcRect
->Y
= 0.0;
690 srcRect
->Width
= (REAL
) ((GpBitmap
*)image
)->width
;
691 srcRect
->Height
= (REAL
) ((GpBitmap
*)image
)->height
;
692 *srcUnit
= UnitPixel
;
695 srcRect
->X
= srcRect
->Y
= 0.0;
696 srcRect
->Width
= ipicture_pixel_width(image
->picture
);
697 srcRect
->Height
= ipicture_pixel_height(image
->picture
);
698 *srcUnit
= UnitPixel
;
701 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect
->X
, srcRect
->Y
,
702 srcRect
->Width
, srcRect
->Height
, *srcUnit
);
707 GpStatus WINGDIPAPI
GdipGetImageDimension(GpImage
*image
, REAL
*width
,
710 TRACE("%p %p %p\n", image
, width
, height
);
712 if(!image
|| !height
|| !width
)
713 return InvalidParameter
;
715 if(image
->type
== ImageTypeMetafile
){
718 *height
= convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
719 ((GpMetafile
*)image
)->bounds
.Height
;
721 *width
= convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
722 ((GpMetafile
*)image
)->bounds
.Width
;
727 else if(image
->type
== ImageTypeBitmap
){
728 *height
= ((GpBitmap
*)image
)->height
;
729 *width
= ((GpBitmap
*)image
)->width
;
732 *height
= ipicture_pixel_height(image
->picture
);
733 *width
= ipicture_pixel_width(image
->picture
);
736 TRACE("returning (%f, %f)\n", *height
, *width
);
740 GpStatus WINGDIPAPI
GdipGetImageGraphicsContext(GpImage
*image
,
741 GpGraphics
**graphics
)
745 TRACE("%p %p\n", image
, graphics
);
747 if(!image
|| !graphics
)
748 return InvalidParameter
;
750 if(image
->type
!= ImageTypeBitmap
){
751 FIXME("not implemented for image type %d\n", image
->type
);
752 return NotImplemented
;
755 IPicture_get_CurDC(image
->picture
, &hdc
);
758 hdc
= CreateCompatibleDC(0);
759 IPicture_SelectPicture(image
->picture
, hdc
, NULL
, NULL
);
762 return GdipCreateFromHDC(hdc
, graphics
);
765 GpStatus WINGDIPAPI
GdipGetImageHeight(GpImage
*image
, UINT
*height
)
767 TRACE("%p %p\n", image
, height
);
769 if(!image
|| !height
)
770 return InvalidParameter
;
772 if(image
->type
== ImageTypeMetafile
){
775 *height
= roundr(convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
776 ((GpMetafile
*)image
)->bounds
.Height
);
780 else if(image
->type
== ImageTypeBitmap
)
781 *height
= ((GpBitmap
*)image
)->height
;
783 *height
= ipicture_pixel_height(image
->picture
);
785 TRACE("returning %d\n", *height
);
790 GpStatus WINGDIPAPI
GdipGetImageHorizontalResolution(GpImage
*image
, REAL
*res
)
795 return InvalidParameter
;
798 FIXME("not implemented\n");
800 return NotImplemented
;
803 GpStatus WINGDIPAPI
GdipGetImagePaletteSize(GpImage
*image
, INT
*size
)
805 FIXME("%p %p\n", image
, size
);
808 return InvalidParameter
;
810 return NotImplemented
;
813 /* FIXME: test this function for non-bitmap types */
814 GpStatus WINGDIPAPI
GdipGetImagePixelFormat(GpImage
*image
, PixelFormat
*format
)
816 TRACE("%p %p\n", image
, format
);
818 if(!image
|| !format
)
819 return InvalidParameter
;
821 if(image
->type
!= ImageTypeBitmap
)
822 *format
= PixelFormat24bppRGB
;
824 *format
= ((GpBitmap
*) image
)->format
;
829 GpStatus WINGDIPAPI
GdipGetImageRawFormat(GpImage
*image
, GUID
*format
)
833 if(!image
|| !format
)
834 return InvalidParameter
;
839 /* FIXME: should be detected from embedded picture or stored separately */
842 case ImageTypeBitmap
: *format
= ImageFormatBMP
; break;
843 case ImageTypeMetafile
: *format
= ImageFormatEMF
; break;
845 WARN("unknown type %u\n", image
->type
);
846 *format
= ImageFormatUndefined
;
851 GpStatus WINGDIPAPI
GdipGetImageType(GpImage
*image
, ImageType
*type
)
853 TRACE("%p %p\n", image
, type
);
856 return InvalidParameter
;
863 GpStatus WINGDIPAPI
GdipGetImageVerticalResolution(GpImage
*image
, REAL
*res
)
868 return InvalidParameter
;
871 FIXME("not implemented\n");
873 return NotImplemented
;
876 GpStatus WINGDIPAPI
GdipGetImageWidth(GpImage
*image
, UINT
*width
)
878 TRACE("%p %p\n", image
, width
);
881 return InvalidParameter
;
883 if(image
->type
== ImageTypeMetafile
){
886 *width
= roundr(convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
887 ((GpMetafile
*)image
)->bounds
.Width
);
891 else if(image
->type
== ImageTypeBitmap
)
892 *width
= ((GpBitmap
*)image
)->width
;
894 *width
= ipicture_pixel_width(image
->picture
);
896 TRACE("returning %d\n", *width
);
901 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromMetafile(GpMetafile
* metafile
,
902 MetafileHeader
* header
)
906 if(!metafile
|| !header
)
907 return InvalidParameter
;
910 FIXME("not implemented\n");
915 GpStatus WINGDIPAPI
GdipGetAllPropertyItems(GpImage
*image
, UINT size
,
916 UINT num
, PropertyItem
* items
)
921 FIXME("not implemented\n");
923 return InvalidParameter
;
926 GpStatus WINGDIPAPI
GdipGetPropertyCount(GpImage
*image
, UINT
* num
)
931 FIXME("not implemented\n");
933 return InvalidParameter
;
936 GpStatus WINGDIPAPI
GdipGetPropertyIdList(GpImage
*image
, UINT num
, PROPID
* list
)
941 FIXME("not implemented\n");
943 return InvalidParameter
;
946 GpStatus WINGDIPAPI
GdipGetPropertyItem(GpImage
*image
, PROPID id
, UINT size
,
947 PropertyItem
* buffer
)
952 FIXME("not implemented\n");
954 return InvalidParameter
;
957 GpStatus WINGDIPAPI
GdipGetPropertyItemSize(GpImage
*image
, PROPID pid
,
962 TRACE("%p %x %p\n", image
, pid
, size
);
965 return InvalidParameter
;
968 FIXME("not implemented\n");
970 return NotImplemented
;
973 GpStatus WINGDIPAPI
GdipGetPropertySize(GpImage
*image
, UINT
* size
, UINT
* num
)
978 FIXME("not implemented\n");
980 return InvalidParameter
;
983 GpStatus WINGDIPAPI
GdipImageGetFrameCount(GpImage
*image
,
984 GDIPCONST GUID
* dimensionID
, UINT
* count
)
988 if(!image
|| !dimensionID
|| !count
)
989 return InvalidParameter
;
992 FIXME("not implemented\n");
994 return NotImplemented
;
997 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsCount(GpImage
*image
,
1000 if(!image
|| !count
)
1001 return InvalidParameter
;
1010 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsList(GpImage
* image
,
1011 GUID
* dimensionIDs
, UINT count
)
1015 if(!image
|| !dimensionIDs
)
1016 return InvalidParameter
;
1019 FIXME("not implemented\n");
1024 GpStatus WINGDIPAPI
GdipImageSelectActiveFrame(GpImage
*image
,
1025 GDIPCONST GUID
* dimensionID
, UINT frameidx
)
1029 if(!image
|| !dimensionID
)
1030 return InvalidParameter
;
1033 FIXME("not implemented\n");
1038 GpStatus WINGDIPAPI
GdipLoadImageFromFile(GDIPCONST WCHAR
* filename
,
1044 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
1046 if (!filename
|| !image
)
1047 return InvalidParameter
;
1049 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
1054 stat
= GdipLoadImageFromStream(stream
, image
);
1056 IStream_Release(stream
);
1061 /* FIXME: no icm handling */
1062 GpStatus WINGDIPAPI
GdipLoadImageFromFileICM(GDIPCONST WCHAR
* filename
,GpImage
**image
)
1064 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
1066 return GdipLoadImageFromFile(filename
, image
);
1069 GpStatus WINGDIPAPI
GdipLoadImageFromStream(IStream
* stream
, GpImage
**image
)
1074 TRACE("%p %p\n", stream
, image
);
1076 if(!stream
|| !image
)
1077 return InvalidParameter
;
1079 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
1080 (LPVOID
*) &pic
) != S_OK
){
1081 TRACE("Could not load picture\n");
1082 return GenericError
;
1085 IPicture_get_Type(pic
, &type
);
1087 if(type
== PICTYPE_BITMAP
){
1089 BITMAPCOREHEADER
* bmch
;
1093 pbmi
= GdipAlloc(sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1096 *image
= GdipAlloc(sizeof(GpBitmap
));
1101 (*image
)->type
= ImageTypeBitmap
;
1103 (*((GpBitmap
**) image
))->width
= ipicture_pixel_width(pic
);
1104 (*((GpBitmap
**) image
))->height
= ipicture_pixel_height(pic
);
1106 /* get the pixel format */
1107 IPicture_get_Handle(pic
, (OLE_HANDLE
*)&hbm
);
1108 IPicture_get_CurDC(pic
, &hdc
);
1110 bmch
= (BITMAPCOREHEADER
*) (&pbmi
->bmiHeader
);
1111 bmch
->bcSize
= sizeof(BITMAPCOREHEADER
);
1115 hdc
= CreateCompatibleDC(0);
1116 old
= SelectObject(hdc
, hbm
);
1117 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
1118 SelectObject(hdc
, old
);
1122 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
1124 switch(bmch
->bcBitCount
)
1127 (*((GpBitmap
**) image
))->format
= PixelFormat1bppIndexed
;
1130 (*((GpBitmap
**) image
))->format
= PixelFormat4bppIndexed
;
1133 (*((GpBitmap
**) image
))->format
= PixelFormat8bppIndexed
;
1136 (*((GpBitmap
**) image
))->format
= PixelFormat16bppRGB565
;
1139 (*((GpBitmap
**) image
))->format
= PixelFormat24bppRGB
;
1142 (*((GpBitmap
**) image
))->format
= PixelFormat32bppRGB
;
1145 (*((GpBitmap
**) image
))->format
= PixelFormat48bppRGB
;
1148 FIXME("Bit depth %d is not fully supported yet\n", bmch
->bcBitCount
);
1149 (*((GpBitmap
**) image
))->format
= (bmch
->bcBitCount
<< 8) | PixelFormatGDI
;
1155 else if(type
== PICTYPE_METAFILE
|| type
== PICTYPE_ENHMETAFILE
){
1156 /* FIXME: missing initialization code */
1157 *image
= GdipAlloc(sizeof(GpMetafile
));
1158 if(!*image
) return OutOfMemory
;
1159 (*image
)->type
= ImageTypeMetafile
;
1162 *image
= GdipAlloc(sizeof(GpImage
));
1163 if(!*image
) return OutOfMemory
;
1164 (*image
)->type
= ImageTypeUnknown
;
1167 (*image
)->picture
= pic
;
1168 (*image
)->flags
= ImageFlagsNone
;
1174 GpStatus WINGDIPAPI
GdipLoadImageFromStreamICM(IStream
* stream
, GpImage
**image
)
1176 TRACE("%p %p\n", stream
, image
);
1178 return GdipLoadImageFromStream(stream
, image
);
1181 GpStatus WINGDIPAPI
GdipRemovePropertyItem(GpImage
*image
, PROPID propId
)
1186 return InvalidParameter
;
1189 FIXME("not implemented\n");
1191 return NotImplemented
;
1194 GpStatus WINGDIPAPI
GdipSetPropertyItem(GpImage
*image
, GDIPCONST PropertyItem
* item
)
1199 FIXME("not implemented\n");
1201 return NotImplemented
;
1204 GpStatus WINGDIPAPI
GdipSaveImageToFile(GpImage
*image
, GDIPCONST WCHAR
* filename
,
1205 GDIPCONST CLSID
*clsidEncoder
,
1206 GDIPCONST EncoderParameters
*encoderParams
)
1211 TRACE("%p (%s) %p %p\n", image
, debugstr_w(filename
), clsidEncoder
, encoderParams
);
1213 if (!image
|| !filename
|| !clsidEncoder
)
1214 return InvalidParameter
;
1216 if (!(image
->picture
))
1217 return InvalidParameter
;
1219 stat
= GdipCreateStreamOnFile(filename
, GENERIC_WRITE
, &stream
);
1221 return GenericError
;
1223 stat
= GdipSaveImageToStream(image
, stream
, clsidEncoder
, encoderParams
);
1225 IStream_Release(stream
);
1229 /*************************************************************************
1230 * Encoding functions -
1231 * These functions encode an image in different image file formats.
1233 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
1234 #define BITMAP_FORMAT_JPEG 0xd8ff
1235 #define BITMAP_FORMAT_GIF 0x4947
1236 #define BITMAP_FORMAT_PNG 0x5089
1237 #define BITMAP_FORMAT_APM 0xcdd7
1239 static GpStatus
encode_image_BMP(LPVOID bitmap_bits
, LPBITMAPINFO bitmap_info
,
1240 void **output
, unsigned int *output_size
)
1242 int num_palette_entries
;
1243 BITMAPFILEHEADER
*bmp_file_hdr
;
1244 BITMAPINFO
*bmp_info_hdr
;
1246 if (bitmap_info
->bmiHeader
.biClrUsed
) {
1247 num_palette_entries
= bitmap_info
->bmiHeader
.biClrUsed
;
1248 if (num_palette_entries
> 256) num_palette_entries
= 256;
1250 if (bitmap_info
->bmiHeader
.biBitCount
<= 8)
1251 num_palette_entries
= 1 << bitmap_info
->bmiHeader
.biBitCount
;
1253 num_palette_entries
= 0;
1257 sizeof(BITMAPFILEHEADER
) +
1258 sizeof(BITMAPINFOHEADER
) +
1259 num_palette_entries
* sizeof(RGBQUAD
) +
1260 bitmap_info
->bmiHeader
.biSizeImage
;
1262 *output
= GdipAlloc(*output_size
);
1264 bmp_file_hdr
= *output
;
1265 bmp_file_hdr
->bfType
= BITMAP_FORMAT_BMP
;
1266 bmp_file_hdr
->bfSize
= *output_size
;
1267 bmp_file_hdr
->bfOffBits
=
1268 sizeof(BITMAPFILEHEADER
) +
1269 sizeof(BITMAPINFOHEADER
) +
1270 num_palette_entries
* sizeof (RGBQUAD
);
1272 bmp_info_hdr
= (BITMAPINFO
*) ((unsigned char*)(*output
) + sizeof(BITMAPFILEHEADER
));
1273 memcpy(bmp_info_hdr
, bitmap_info
, sizeof(BITMAPINFOHEADER
) + num_palette_entries
* sizeof(RGBQUAD
));
1274 memcpy((unsigned char *)(*output
) +
1275 sizeof(BITMAPFILEHEADER
) +
1276 sizeof(BITMAPINFOHEADER
) +
1277 num_palette_entries
* sizeof(RGBQUAD
),
1278 bitmap_bits
, bitmap_info
->bmiHeader
.biSizeImage
);
1283 typedef GpStatus
encode_image_func(LPVOID bitmap_bits
, LPBITMAPINFO bitmap_info
,
1284 void **output
, unsigned int *output_size
);
1288 NUM_ENCODERS_SUPPORTED
1291 static const ImageCodecInfo codecs
[NUM_ENCODERS_SUPPORTED
];
1292 static encode_image_func
*const encode_image_funcs
[NUM_ENCODERS_SUPPORTED
] = {
1296 /*****************************************************************************
1297 * GdipSaveImageToStream [GDIPLUS.@]
1299 GpStatus WINGDIPAPI
GdipSaveImageToStream(GpImage
*image
, IStream
* stream
,
1300 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
1309 BITMAPINFO bmp_info
;
1311 encode_image_func
* encode_image
;
1313 unsigned int output_size
;
1321 TRACE("%p %p %p %p\n", image
, stream
, clsid
, params
);
1323 if(!image
|| !stream
)
1324 return InvalidParameter
;
1326 if (!image
->picture
)
1327 return GenericError
;
1329 hr
= IPicture_get_Type(image
->picture
, &type
);
1330 if (FAILED(hr
) || type
!= PICTYPE_BITMAP
)
1331 return GenericError
;
1333 /* select correct encoder */
1334 encode_image
= NULL
;
1335 for (i
= 0; i
< NUM_ENCODERS_SUPPORTED
; i
++) {
1336 if (IsEqualCLSID(clsid
, &codecs
[i
].Clsid
))
1337 encode_image
= encode_image_funcs
[i
];
1339 if (encode_image
== NULL
)
1340 return UnknownImageFormat
;
1342 /* extract underlying hbitmap representation from the IPicture */
1343 hr
= IPicture_get_Handle(image
->picture
, (OLE_HANDLE
*)&hbmp
);
1344 if (FAILED(hr
) || !hbmp
)
1345 return GenericError
;
1346 hr
= IPicture_get_CurDC(image
->picture
, &hdc
);
1348 return GenericError
;
1349 bm_is_selected
= (hdc
!= 0);
1350 if (!bm_is_selected
) {
1351 hdc
= CreateCompatibleDC(0);
1352 old_hbmp
= SelectObject(hdc
, hbmp
);
1355 /* get bits from HBITMAP */
1356 bmp_info
.bmiHeader
.biSize
= sizeof(bmp_info
.bmiHeader
);
1357 bmp_info
.bmiHeader
.biBitCount
= 0;
1358 GetDIBits(hdc
, hbmp
, 0, 0, NULL
, &bmp_info
, DIB_RGB_COLORS
);
1360 bmp_bits
= GdipAlloc(bmp_info
.bmiHeader
.biSizeImage
);
1363 GetDIBits(hdc
, hbmp
, 0, abs(bmp_info
.bmiHeader
.biHeight
), bmp_bits
, &bmp_info
, DIB_RGB_COLORS
);
1365 if (!bm_is_selected
) {
1366 SelectObject(hdc
, old_hbmp
);
1373 stat
= encode_image(bmp_bits
, &bmp_info
, &output
, &output_size
);
1375 IStream_Write(stream
, output
, output_size
, &dummy
);
1383 /*****************************************************************************
1384 * GdipSetImagePalette [GDIPLUS.@]
1386 GpStatus WINGDIPAPI
GdipSetImagePalette(GpImage
*image
,
1387 GDIPCONST ColorPalette
*palette
)
1391 if(!image
|| !palette
)
1392 return InvalidParameter
;
1395 FIXME("not implemented\n");
1397 return NotImplemented
;
1400 /*************************************************************************
1402 * Structures that represent which formats we support for encoding.
1405 /* ImageCodecInfo creation routines taken from libgdiplus */
1406 static const WCHAR bmp_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
1407 static const WCHAR bmp_extension
[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
1408 static const WCHAR bmp_mimetype
[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
1409 static const WCHAR bmp_format
[] = {'B', 'M', 'P', 0}; /* BMP */
1410 static const BYTE bmp_sig_pattern
[] = { 0x42, 0x4D };
1411 static const BYTE bmp_sig_mask
[] = { 0xFF, 0xFF };
1413 static const ImageCodecInfo codecs
[NUM_ENCODERS_SUPPORTED
] =
1416 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
1417 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
1418 /* CodecName */ bmp_codecname
,
1420 /* FormatDescription */ bmp_format
,
1421 /* FilenameExtension */ bmp_extension
,
1422 /* MimeType */ bmp_mimetype
,
1423 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
1427 /* SigPattern */ bmp_sig_pattern
,
1428 /* SigMask */ bmp_sig_mask
,
1432 /*****************************************************************************
1433 * GdipGetImageDecodersSize [GDIPLUS.@]
1435 GpStatus WINGDIPAPI
GdipGetImageDecodersSize(UINT
*numDecoders
, UINT
*size
)
1437 FIXME("%p %p stub!\n", numDecoders
, size
);
1439 if (!numDecoders
|| !size
)
1440 return InvalidParameter
;
1448 /*****************************************************************************
1449 * GdipGetImageDecoders [GDIPLUS.@]
1451 GpStatus WINGDIPAPI
GdipGetImageDecoders(UINT numDecoders
, UINT size
, ImageCodecInfo
*decoders
)
1453 FIXME("%u %u %p stub!\n", numDecoders
, size
, decoders
);
1456 return GenericError
;
1458 return NotImplemented
;
1461 /*****************************************************************************
1462 * GdipGetImageEncodersSize [GDIPLUS.@]
1464 GpStatus WINGDIPAPI
GdipGetImageEncodersSize(UINT
*numEncoders
, UINT
*size
)
1466 TRACE("%p %p\n", numEncoders
, size
);
1468 if (!numEncoders
|| !size
)
1469 return InvalidParameter
;
1471 *numEncoders
= NUM_ENCODERS_SUPPORTED
;
1472 *size
= sizeof (codecs
);
1477 /*****************************************************************************
1478 * GdipGetImageEncoders [GDIPLUS.@]
1480 GpStatus WINGDIPAPI
GdipGetImageEncoders(UINT numEncoders
, UINT size
, ImageCodecInfo
*encoders
)
1482 TRACE("%u %u %p\n", numEncoders
, size
, encoders
);
1485 (numEncoders
!= NUM_ENCODERS_SUPPORTED
) ||
1486 (size
!= sizeof (codecs
)))
1487 return GenericError
;
1489 memcpy(encoders
, codecs
, sizeof (codecs
));
1494 /*****************************************************************************
1495 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
1497 GpStatus WINGDIPAPI
GdipCreateBitmapFromHBITMAP(HBITMAP hbm
, HPALETTE hpal
, GpBitmap
** bitmap
)
1504 TRACE("%p %p %p\n", hbm
, hpal
, bitmap
);
1507 return InvalidParameter
;
1509 /* TODO: Support for device-dependent bitmaps */
1511 FIXME("no support for device-dependent bitmaps\n");
1512 return NotImplemented
;
1515 if (GetObjectA(hbm
, sizeof(bm
), &bm
) != sizeof(bm
))
1516 return InvalidParameter
;
1518 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
1519 switch(bm
.bmBitsPixel
) {
1521 format
= PixelFormat1bppIndexed
;
1524 format
= PixelFormat4bppIndexed
;
1527 format
= PixelFormat8bppIndexed
;
1530 format
= PixelFormat24bppRGB
;
1533 format
= PixelFormat32bppRGB
;
1536 format
= PixelFormat48bppRGB
;
1539 FIXME("don't know how to handle %d bpp\n", bm
.bmBitsPixel
);
1540 return InvalidParameter
;
1544 bits
= (BYTE
*)bm
.bmBits
+ (bm
.bmHeight
- 1) * bm
.bmWidthBytes
;
1547 FIXME("can only get image data from DIB sections\n");
1551 retval
= GdipCreateBitmapFromScan0(bm
.bmWidth
, bm
.bmHeight
, -bm
.bmWidthBytes
,
1552 format
, bits
, bitmap
);
1557 /*****************************************************************************
1558 * GdipSetEffectParameters [GDIPLUS.@]
1560 GpStatus WINGDIPAPI
GdipSetEffectParameters(CGpEffect
*effect
,
1561 const VOID
*params
, const UINT size
)
1566 FIXME("not implemented\n");
1568 return NotImplemented
;
1571 /*****************************************************************************
1572 * GdipGetImageFlags [GDIPLUS.@]
1574 GpStatus WINGDIPAPI
GdipGetImageFlags(GpImage
*image
, UINT
*flags
)
1576 TRACE("%p %p\n", image
, flags
);
1578 if(!image
|| !flags
)
1579 return InvalidParameter
;
1581 *flags
= image
->flags
;
1586 GpStatus WINGDIPAPI
GdipTestControl(GpTestControlEnum control
, void *param
)
1588 TRACE("(%d, %p)\n", control
, param
);
1591 case TestControlForceBilinear
:
1593 FIXME("TestControlForceBilinear not handled\n");
1595 case TestControlNoICM
:
1597 FIXME("TestControlNoICM not handled\n");
1599 case TestControlGetBuildNumber
:
1600 *((DWORD
*)param
) = 3102;
1607 GpStatus WINGDIPAPI
GdipRecordMetafileFileName(GDIPCONST WCHAR
* fileName
,
1608 HDC hdc
, EmfType type
, GDIPCONST GpRectF
*pFrameRect
,
1609 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
,
1610 GpMetafile
**metafile
)
1612 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName
), hdc
, type
, pFrameRect
,
1613 frameUnit
, debugstr_w(desc
), metafile
);
1615 return NotImplemented
;
1618 GpStatus WINGDIPAPI
GdipRecordMetafileFileNameI(GDIPCONST WCHAR
* fileName
, HDC hdc
, EmfType type
,
1619 GDIPCONST GpRect
*pFrameRect
, MetafileFrameUnit frameUnit
,
1620 GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
1622 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName
), hdc
, type
, pFrameRect
,
1623 frameUnit
, debugstr_w(desc
), metafile
);
1625 return NotImplemented
;
1628 GpStatus WINGDIPAPI
GdipImageForceValidation(GpImage
*image
)
1630 FIXME("%p\n", image
);