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
GdipBitmapSetResolution(GpBitmap
* bitmap
, REAL xdpi
, REAL ydpi
)
197 FIXME("(%p, %.2f, %.2f)\n", bitmap
, xdpi
, ydpi
);
199 return NotImplemented
;
202 GpStatus WINGDIPAPI
GdipBitmapUnlockBits(GpBitmap
* bitmap
,
203 BitmapData
* lockeddata
)
206 HBITMAP hbm
, old
= NULL
;
210 if(!bitmap
|| !lockeddata
)
211 return InvalidParameter
;
213 if(!bitmap
->lockmode
)
216 if(lockeddata
->Reserved
& ImageLockModeUserInputBuf
)
217 return NotImplemented
;
219 if(lockeddata
->Reserved
& ImageLockModeRead
){
220 if(!(--bitmap
->numlocks
))
221 bitmap
->lockmode
= 0;
223 GdipFree(bitmap
->bitmapbits
);
224 bitmap
->bitmapbits
= NULL
;
228 IPicture_get_Handle(bitmap
->image
.picture
, (OLE_HANDLE
*)&hbm
);
229 IPicture_get_CurDC(bitmap
->image
.picture
, &hdc
);
230 bm_is_selected
= (hdc
!= 0);
232 pbmi
= GdipAlloc(sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
233 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
234 pbmi
->bmiHeader
.biBitCount
= 0;
237 hdc
= CreateCompatibleDC(0);
238 old
= SelectObject(hdc
, hbm
);
241 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
242 pbmi
->bmiHeader
.biBitCount
= PIXELFORMATBPP(lockeddata
->PixelFormat
);
243 SetDIBits(hdc
, hbm
, 0, abs(pbmi
->bmiHeader
.biHeight
),
244 bitmap
->bitmapbits
, pbmi
, DIB_RGB_COLORS
);
247 SelectObject(hdc
, old
);
252 GdipFree(bitmap
->bitmapbits
);
253 bitmap
->bitmapbits
= NULL
;
254 bitmap
->lockmode
= 0;
259 GpStatus WINGDIPAPI
GdipCloneBitmapAreaI(INT x
, INT y
, INT width
, INT height
,
260 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
262 FIXME("(%i,%i,%i,%i,%i,%p,%p)\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
264 return NotImplemented
;
267 GpStatus WINGDIPAPI
GdipCloneImage(GpImage
*image
, GpImage
**cloneImage
)
273 GpStatus stat
= GenericError
;
275 TRACE("%p, %p\n", image
, cloneImage
);
277 if (!image
|| !cloneImage
)
278 return InvalidParameter
;
280 hr
= CreateStreamOnHGlobal(0, TRUE
, &stream
);
284 hr
= IPicture_SaveAsFile(image
->picture
, stream
, FALSE
, &size
);
287 WARN("Failed to save image on stream\n");
291 /* Set seek pointer back to the beginning of the picture */
293 hr
= IStream_Seek(stream
, move
, STREAM_SEEK_SET
, NULL
);
297 stat
= GdipLoadImageFromStream(stream
, cloneImage
);
298 if (stat
!= Ok
) WARN("Failed to load image from stream\n");
301 IStream_Release(stream
);
305 GpStatus WINGDIPAPI
GdipCreateBitmapFromFile(GDIPCONST WCHAR
* filename
,
311 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
313 if(!filename
|| !bitmap
)
314 return InvalidParameter
;
316 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
321 stat
= GdipCreateBitmapFromStream(stream
, bitmap
);
323 IStream_Release(stream
);
328 GpStatus WINGDIPAPI
GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO
* info
,
329 VOID
*bits
, GpBitmap
**bitmap
)
331 DWORD height
, stride
;
334 FIXME("(%p, %p, %p) - partially implemented\n", info
, bits
, bitmap
);
336 height
= abs(info
->bmiHeader
.biHeight
);
337 stride
= ((info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
+ 31) >> 3) & ~3;
339 if(info
->bmiHeader
.biHeight
> 0) /* bottom-up */
341 bits
= (BYTE
*)bits
+ (height
- 1) * stride
;
345 switch(info
->bmiHeader
.biBitCount
) {
347 format
= PixelFormat1bppIndexed
;
350 format
= PixelFormat4bppIndexed
;
353 format
= PixelFormat8bppIndexed
;
356 format
= PixelFormat24bppRGB
;
359 FIXME("don't know how to handle %d bpp\n", info
->bmiHeader
.biBitCount
);
361 return InvalidParameter
;
364 return GdipCreateBitmapFromScan0(info
->bmiHeader
.biWidth
, height
, stride
, format
,
370 GpStatus WINGDIPAPI
GdipCreateBitmapFromFileICM(GDIPCONST WCHAR
* filename
,
373 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
375 return GdipCreateBitmapFromFile(filename
, bitmap
);
378 GpStatus WINGDIPAPI
GdipCreateBitmapFromResource(HINSTANCE hInstance
,
379 GDIPCONST WCHAR
* lpBitmapName
, GpBitmap
** bitmap
)
382 GpStatus stat
= InvalidParameter
;
384 TRACE("%p (%s) %p\n", hInstance
, debugstr_w(lpBitmapName
), bitmap
);
386 if(!lpBitmapName
|| !bitmap
)
387 return InvalidParameter
;
390 hbm
= LoadImageW(hInstance
, lpBitmapName
, IMAGE_BITMAP
, 0, 0,
391 LR_CREATEDIBSECTION
);
394 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, bitmap
);
401 GpStatus WINGDIPAPI
GdipCreateHBITMAPFromBitmap(GpBitmap
* bitmap
,
402 HBITMAP
* hbmReturn
, ARGB background
)
408 return NotImplemented
;
411 GpStatus WINGDIPAPI
GdipConvertToEmfPlus(const GpGraphics
* ref
,
412 GpMetafile
* metafile
, BOOL
* succ
, EmfType emfType
,
413 const WCHAR
* description
, GpMetafile
** out_metafile
)
417 if(!ref
|| !metafile
|| !out_metafile
)
418 return InvalidParameter
;
421 *out_metafile
= NULL
;
424 FIXME("not implemented\n");
426 return NotImplemented
;
429 /* FIXME: this should create a bitmap in the given size with the attributes
430 * (resolution etc.) of the graphics object */
431 GpStatus WINGDIPAPI
GdipCreateBitmapFromGraphics(INT width
, INT height
,
432 GpGraphics
* target
, GpBitmap
** bitmap
)
437 if(!target
|| !bitmap
)
438 return InvalidParameter
;
441 FIXME("hacked stub\n");
443 ret
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat24bppRGB
,
449 GpStatus WINGDIPAPI
GdipCreateBitmapFromHICON(HICON hicon
, GpBitmap
** bitmap
)
455 TRACE("%p, %p\n", hicon
, bitmap
);
457 if(!bitmap
|| !GetIconInfo(hicon
, &iinfo
))
458 return InvalidParameter
;
460 *bitmap
= GdipAlloc(sizeof(GpBitmap
));
461 if(!*bitmap
) return OutOfMemory
;
463 icon_copy
= CreateIconIndirect(&iinfo
);
467 return InvalidParameter
;
470 desc
.cbSizeofstruct
= sizeof(PICTDESC
);
471 desc
.picType
= PICTYPE_ICON
;
472 desc
.u
.icon
.hicon
= icon_copy
;
474 if(OleCreatePictureIndirect(&desc
, &IID_IPicture
, TRUE
,
475 (LPVOID
*) &((*bitmap
)->image
.picture
)) != S_OK
){
476 DestroyIcon(icon_copy
);
481 (*bitmap
)->format
= PixelFormat32bppARGB
;
482 (*bitmap
)->image
.type
= ImageTypeBitmap
;
483 (*bitmap
)->image
.flags
= ImageFlagsNone
;
484 (*bitmap
)->width
= ipicture_pixel_width((*bitmap
)->image
.picture
);
485 (*bitmap
)->height
= ipicture_pixel_height((*bitmap
)->image
.picture
);
487 DeleteObject(iinfo
.hbmColor
);
488 DeleteObject(iinfo
.hbmMask
);
493 GpStatus WINGDIPAPI
GdipCreateBitmapFromScan0(INT width
, INT height
, INT stride
,
494 PixelFormat format
, BYTE
* scan0
, GpBitmap
** bitmap
)
496 BITMAPFILEHEADER
*bmfh
;
497 BITMAPINFOHEADER
*bmih
;
502 TRACE("%d %d %d %d %p %p\n", width
, height
, stride
, format
, scan0
, bitmap
);
504 if (!bitmap
) return InvalidParameter
;
506 if(width
<= 0 || height
<= 0 || (scan0
&& (stride
% 4))){
508 return InvalidParameter
;
512 return InvalidParameter
;
514 *bitmap
= GdipAlloc(sizeof(GpBitmap
));
515 if(!*bitmap
) return OutOfMemory
;
518 stride
= width
* (PIXELFORMATBPP(format
) / 8);
519 stride
= (stride
+ 3) & ~3;
522 datalen
= abs(stride
* height
);
523 size
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
) + datalen
;
524 buff
= GdipAlloc(size
);
530 bmfh
= (BITMAPFILEHEADER
*) buff
;
531 bmih
= (BITMAPINFOHEADER
*) (bmfh
+ 1);
533 bmfh
->bfType
= (((WORD
)'M') << 8) + (WORD
)'B';
535 bmfh
->bfOffBits
= size
- datalen
;
537 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
538 bmih
->biWidth
= width
;
539 /* FIXME: use the rest of the data from format */
540 bmih
->biBitCount
= PIXELFORMATBPP(format
);
541 bmih
->biCompression
= BI_RGB
;
542 bmih
->biSizeImage
= datalen
;
548 bmih
->biHeight
= -height
;
549 memcpy(bmih
+ 1, scan0
, datalen
);
553 bmih
->biHeight
= height
;
554 memcpy(bmih
+ 1, scan0
+ stride
* (height
- 1), datalen
);
559 bmih
->biHeight
= height
;
560 memset(bmih
+ 1, 0, datalen
);
563 if(CreateStreamOnHGlobal(buff
, TRUE
, &stream
) != S_OK
){
564 ERR("could not make stream\n");
571 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
572 (LPVOID
*) &((*bitmap
)->image
.picture
)) != S_OK
){
573 TRACE("Could not load picture\n");
574 IStream_Release(stream
);
581 (*bitmap
)->image
.type
= ImageTypeBitmap
;
582 (*bitmap
)->image
.flags
= ImageFlagsNone
;
583 (*bitmap
)->width
= width
;
584 (*bitmap
)->height
= height
;
585 (*bitmap
)->format
= format
;
590 GpStatus WINGDIPAPI
GdipCreateBitmapFromStream(IStream
* stream
,
595 TRACE("%p %p\n", stream
, bitmap
);
597 stat
= GdipLoadImageFromStream(stream
, (GpImage
**) bitmap
);
602 if((*bitmap
)->image
.type
!= ImageTypeBitmap
){
603 IPicture_Release((*bitmap
)->image
.picture
);
605 return GenericError
; /* FIXME: what error to return? */
612 GpStatus WINGDIPAPI
GdipCreateBitmapFromStreamICM(IStream
* stream
,
615 TRACE("%p %p\n", stream
, bitmap
);
617 return GdipCreateBitmapFromStream(stream
, bitmap
);
620 GpStatus WINGDIPAPI
GdipCreateCachedBitmap(GpBitmap
*bitmap
, GpGraphics
*graphics
,
621 GpCachedBitmap
**cachedbmp
)
625 TRACE("%p %p %p\n", bitmap
, graphics
, cachedbmp
);
627 if(!bitmap
|| !graphics
|| !cachedbmp
)
628 return InvalidParameter
;
630 *cachedbmp
= GdipAlloc(sizeof(GpCachedBitmap
));
634 stat
= GdipCloneImage(&(bitmap
->image
), &(*cachedbmp
)->image
);
636 GdipFree(*cachedbmp
);
643 GpStatus WINGDIPAPI
GdipDeleteCachedBitmap(GpCachedBitmap
*cachedbmp
)
645 TRACE("%p\n", cachedbmp
);
648 return InvalidParameter
;
650 GdipDisposeImage(cachedbmp
->image
);
656 GpStatus WINGDIPAPI
GdipDrawCachedBitmap(GpGraphics
*graphics
,
657 GpCachedBitmap
*cachedbmp
, INT x
, INT y
)
659 TRACE("%p %p %d %d\n", graphics
, cachedbmp
, x
, y
);
661 if(!graphics
|| !cachedbmp
)
662 return InvalidParameter
;
664 return GdipDrawImage(graphics
, cachedbmp
->image
, (REAL
)x
, (REAL
)y
);
667 GpStatus WINGDIPAPI
GdipDisposeImage(GpImage
*image
)
671 TRACE("%p\n", image
);
674 return InvalidParameter
;
676 IPicture_get_CurDC(image
->picture
, &hdc
);
678 IPicture_Release(image
->picture
);
679 if (image
->type
== ImageTypeBitmap
)
680 GdipFree(((GpBitmap
*)image
)->bitmapbits
);
686 GpStatus WINGDIPAPI
GdipFindFirstImageItem(GpImage
*image
, ImageItemData
* item
)
689 return InvalidParameter
;
691 return NotImplemented
;
694 GpStatus WINGDIPAPI
GdipGetImageBounds(GpImage
*image
, GpRectF
*srcRect
,
697 TRACE("%p %p %p\n", image
, srcRect
, srcUnit
);
699 if(!image
|| !srcRect
|| !srcUnit
)
700 return InvalidParameter
;
701 if(image
->type
== ImageTypeMetafile
){
702 *srcRect
= ((GpMetafile
*)image
)->bounds
;
703 *srcUnit
= ((GpMetafile
*)image
)->unit
;
705 else if(image
->type
== ImageTypeBitmap
){
706 srcRect
->X
= srcRect
->Y
= 0.0;
707 srcRect
->Width
= (REAL
) ((GpBitmap
*)image
)->width
;
708 srcRect
->Height
= (REAL
) ((GpBitmap
*)image
)->height
;
709 *srcUnit
= UnitPixel
;
712 srcRect
->X
= srcRect
->Y
= 0.0;
713 srcRect
->Width
= ipicture_pixel_width(image
->picture
);
714 srcRect
->Height
= ipicture_pixel_height(image
->picture
);
715 *srcUnit
= UnitPixel
;
718 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect
->X
, srcRect
->Y
,
719 srcRect
->Width
, srcRect
->Height
, *srcUnit
);
724 GpStatus WINGDIPAPI
GdipGetImageDimension(GpImage
*image
, REAL
*width
,
727 TRACE("%p %p %p\n", image
, width
, height
);
729 if(!image
|| !height
|| !width
)
730 return InvalidParameter
;
732 if(image
->type
== ImageTypeMetafile
){
735 *height
= convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
736 ((GpMetafile
*)image
)->bounds
.Height
;
738 *width
= convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
739 ((GpMetafile
*)image
)->bounds
.Width
;
744 else if(image
->type
== ImageTypeBitmap
){
745 *height
= ((GpBitmap
*)image
)->height
;
746 *width
= ((GpBitmap
*)image
)->width
;
749 *height
= ipicture_pixel_height(image
->picture
);
750 *width
= ipicture_pixel_width(image
->picture
);
753 TRACE("returning (%f, %f)\n", *height
, *width
);
757 GpStatus WINGDIPAPI
GdipGetImageGraphicsContext(GpImage
*image
,
758 GpGraphics
**graphics
)
762 TRACE("%p %p\n", image
, graphics
);
764 if(!image
|| !graphics
)
765 return InvalidParameter
;
767 if(image
->type
!= ImageTypeBitmap
){
768 FIXME("not implemented for image type %d\n", image
->type
);
769 return NotImplemented
;
772 IPicture_get_CurDC(image
->picture
, &hdc
);
775 hdc
= CreateCompatibleDC(0);
776 IPicture_SelectPicture(image
->picture
, hdc
, NULL
, NULL
);
779 return GdipCreateFromHDC(hdc
, graphics
);
782 GpStatus WINGDIPAPI
GdipGetImageHeight(GpImage
*image
, UINT
*height
)
784 TRACE("%p %p\n", image
, height
);
786 if(!image
|| !height
)
787 return InvalidParameter
;
789 if(image
->type
== ImageTypeMetafile
){
792 *height
= roundr(convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
793 ((GpMetafile
*)image
)->bounds
.Height
);
797 else if(image
->type
== ImageTypeBitmap
)
798 *height
= ((GpBitmap
*)image
)->height
;
800 *height
= ipicture_pixel_height(image
->picture
);
802 TRACE("returning %d\n", *height
);
807 GpStatus WINGDIPAPI
GdipGetImageHorizontalResolution(GpImage
*image
, REAL
*res
)
812 return InvalidParameter
;
815 FIXME("not implemented\n");
817 return NotImplemented
;
820 GpStatus WINGDIPAPI
GdipGetImagePaletteSize(GpImage
*image
, INT
*size
)
822 FIXME("%p %p\n", image
, size
);
825 return InvalidParameter
;
827 return NotImplemented
;
830 /* FIXME: test this function for non-bitmap types */
831 GpStatus WINGDIPAPI
GdipGetImagePixelFormat(GpImage
*image
, PixelFormat
*format
)
833 TRACE("%p %p\n", image
, format
);
835 if(!image
|| !format
)
836 return InvalidParameter
;
838 if(image
->type
!= ImageTypeBitmap
)
839 *format
= PixelFormat24bppRGB
;
841 *format
= ((GpBitmap
*) image
)->format
;
846 GpStatus WINGDIPAPI
GdipGetImageRawFormat(GpImage
*image
, GUID
*format
)
850 if(!image
|| !format
)
851 return InvalidParameter
;
856 /* FIXME: should be detected from embedded picture or stored separately */
859 case ImageTypeBitmap
: *format
= ImageFormatBMP
; break;
860 case ImageTypeMetafile
: *format
= ImageFormatEMF
; break;
862 WARN("unknown type %u\n", image
->type
);
863 *format
= ImageFormatUndefined
;
868 GpStatus WINGDIPAPI
GdipGetImageType(GpImage
*image
, ImageType
*type
)
870 TRACE("%p %p\n", image
, type
);
873 return InvalidParameter
;
880 GpStatus WINGDIPAPI
GdipGetImageVerticalResolution(GpImage
*image
, REAL
*res
)
885 return InvalidParameter
;
888 FIXME("not implemented\n");
890 return NotImplemented
;
893 GpStatus WINGDIPAPI
GdipGetImageWidth(GpImage
*image
, UINT
*width
)
895 TRACE("%p %p\n", image
, width
);
898 return InvalidParameter
;
900 if(image
->type
== ImageTypeMetafile
){
903 *width
= roundr(convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
904 ((GpMetafile
*)image
)->bounds
.Width
);
908 else if(image
->type
== ImageTypeBitmap
)
909 *width
= ((GpBitmap
*)image
)->width
;
911 *width
= ipicture_pixel_width(image
->picture
);
913 TRACE("returning %d\n", *width
);
918 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromMetafile(GpMetafile
* metafile
,
919 MetafileHeader
* header
)
923 if(!metafile
|| !header
)
924 return InvalidParameter
;
927 FIXME("not implemented\n");
932 GpStatus WINGDIPAPI
GdipGetAllPropertyItems(GpImage
*image
, UINT size
,
933 UINT num
, PropertyItem
* items
)
938 FIXME("not implemented\n");
940 return InvalidParameter
;
943 GpStatus WINGDIPAPI
GdipGetPropertyCount(GpImage
*image
, UINT
* num
)
948 FIXME("not implemented\n");
950 return InvalidParameter
;
953 GpStatus WINGDIPAPI
GdipGetPropertyIdList(GpImage
*image
, UINT num
, PROPID
* list
)
958 FIXME("not implemented\n");
960 return InvalidParameter
;
963 GpStatus WINGDIPAPI
GdipGetPropertyItem(GpImage
*image
, PROPID id
, UINT size
,
964 PropertyItem
* buffer
)
969 FIXME("not implemented\n");
971 return InvalidParameter
;
974 GpStatus WINGDIPAPI
GdipGetPropertyItemSize(GpImage
*image
, PROPID pid
,
979 TRACE("%p %x %p\n", image
, pid
, size
);
982 return InvalidParameter
;
985 FIXME("not implemented\n");
987 return NotImplemented
;
990 GpStatus WINGDIPAPI
GdipGetPropertySize(GpImage
*image
, UINT
* size
, UINT
* num
)
995 FIXME("not implemented\n");
997 return InvalidParameter
;
1000 GpStatus WINGDIPAPI
GdipImageGetFrameCount(GpImage
*image
,
1001 GDIPCONST GUID
* dimensionID
, UINT
* count
)
1005 if(!image
|| !dimensionID
|| !count
)
1006 return InvalidParameter
;
1009 FIXME("not implemented\n");
1011 return NotImplemented
;
1014 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsCount(GpImage
*image
,
1017 if(!image
|| !count
)
1018 return InvalidParameter
;
1027 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsList(GpImage
* image
,
1028 GUID
* dimensionIDs
, UINT count
)
1032 if(!image
|| !dimensionIDs
)
1033 return InvalidParameter
;
1036 FIXME("not implemented\n");
1041 GpStatus WINGDIPAPI
GdipImageSelectActiveFrame(GpImage
*image
,
1042 GDIPCONST GUID
* dimensionID
, UINT frameidx
)
1046 if(!image
|| !dimensionID
)
1047 return InvalidParameter
;
1050 FIXME("not implemented\n");
1055 GpStatus WINGDIPAPI
GdipLoadImageFromFile(GDIPCONST WCHAR
* filename
,
1061 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
1063 if (!filename
|| !image
)
1064 return InvalidParameter
;
1066 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
1071 stat
= GdipLoadImageFromStream(stream
, image
);
1073 IStream_Release(stream
);
1078 /* FIXME: no icm handling */
1079 GpStatus WINGDIPAPI
GdipLoadImageFromFileICM(GDIPCONST WCHAR
* filename
,GpImage
**image
)
1081 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
1083 return GdipLoadImageFromFile(filename
, image
);
1086 GpStatus WINGDIPAPI
GdipLoadImageFromStream(IStream
* stream
, GpImage
**image
)
1091 TRACE("%p %p\n", stream
, image
);
1093 if(!stream
|| !image
)
1094 return InvalidParameter
;
1096 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
1097 (LPVOID
*) &pic
) != S_OK
){
1098 TRACE("Could not load picture\n");
1099 return GenericError
;
1102 IPicture_get_Type(pic
, &type
);
1104 if(type
== PICTYPE_BITMAP
){
1106 BITMAPCOREHEADER
* bmch
;
1110 pbmi
= GdipAlloc(sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1113 *image
= GdipAlloc(sizeof(GpBitmap
));
1118 (*image
)->type
= ImageTypeBitmap
;
1120 (*((GpBitmap
**) image
))->width
= ipicture_pixel_width(pic
);
1121 (*((GpBitmap
**) image
))->height
= ipicture_pixel_height(pic
);
1123 /* get the pixel format */
1124 IPicture_get_Handle(pic
, (OLE_HANDLE
*)&hbm
);
1125 IPicture_get_CurDC(pic
, &hdc
);
1127 bmch
= (BITMAPCOREHEADER
*) (&pbmi
->bmiHeader
);
1128 bmch
->bcSize
= sizeof(BITMAPCOREHEADER
);
1132 hdc
= CreateCompatibleDC(0);
1133 old
= SelectObject(hdc
, hbm
);
1134 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
1135 SelectObject(hdc
, old
);
1139 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
1141 switch(bmch
->bcBitCount
)
1144 (*((GpBitmap
**) image
))->format
= PixelFormat1bppIndexed
;
1147 (*((GpBitmap
**) image
))->format
= PixelFormat4bppIndexed
;
1150 (*((GpBitmap
**) image
))->format
= PixelFormat8bppIndexed
;
1153 (*((GpBitmap
**) image
))->format
= PixelFormat16bppRGB565
;
1156 (*((GpBitmap
**) image
))->format
= PixelFormat24bppRGB
;
1159 (*((GpBitmap
**) image
))->format
= PixelFormat32bppRGB
;
1162 (*((GpBitmap
**) image
))->format
= PixelFormat48bppRGB
;
1165 FIXME("Bit depth %d is not fully supported yet\n", bmch
->bcBitCount
);
1166 (*((GpBitmap
**) image
))->format
= (bmch
->bcBitCount
<< 8) | PixelFormatGDI
;
1172 else if(type
== PICTYPE_METAFILE
|| type
== PICTYPE_ENHMETAFILE
){
1173 /* FIXME: missing initialization code */
1174 *image
= GdipAlloc(sizeof(GpMetafile
));
1175 if(!*image
) return OutOfMemory
;
1176 (*image
)->type
= ImageTypeMetafile
;
1179 *image
= GdipAlloc(sizeof(GpImage
));
1180 if(!*image
) return OutOfMemory
;
1181 (*image
)->type
= ImageTypeUnknown
;
1184 (*image
)->picture
= pic
;
1185 (*image
)->flags
= ImageFlagsNone
;
1191 GpStatus WINGDIPAPI
GdipLoadImageFromStreamICM(IStream
* stream
, GpImage
**image
)
1193 TRACE("%p %p\n", stream
, image
);
1195 return GdipLoadImageFromStream(stream
, image
);
1198 GpStatus WINGDIPAPI
GdipRemovePropertyItem(GpImage
*image
, PROPID propId
)
1203 return InvalidParameter
;
1206 FIXME("not implemented\n");
1208 return NotImplemented
;
1211 GpStatus WINGDIPAPI
GdipSetPropertyItem(GpImage
*image
, GDIPCONST PropertyItem
* item
)
1216 FIXME("not implemented\n");
1218 return NotImplemented
;
1221 GpStatus WINGDIPAPI
GdipSaveImageToFile(GpImage
*image
, GDIPCONST WCHAR
* filename
,
1222 GDIPCONST CLSID
*clsidEncoder
,
1223 GDIPCONST EncoderParameters
*encoderParams
)
1228 TRACE("%p (%s) %p %p\n", image
, debugstr_w(filename
), clsidEncoder
, encoderParams
);
1230 if (!image
|| !filename
|| !clsidEncoder
)
1231 return InvalidParameter
;
1233 if (!(image
->picture
))
1234 return InvalidParameter
;
1236 stat
= GdipCreateStreamOnFile(filename
, GENERIC_WRITE
, &stream
);
1238 return GenericError
;
1240 stat
= GdipSaveImageToStream(image
, stream
, clsidEncoder
, encoderParams
);
1242 IStream_Release(stream
);
1246 /*************************************************************************
1247 * Encoding functions -
1248 * These functions encode an image in different image file formats.
1250 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
1251 #define BITMAP_FORMAT_JPEG 0xd8ff
1252 #define BITMAP_FORMAT_GIF 0x4947
1253 #define BITMAP_FORMAT_PNG 0x5089
1254 #define BITMAP_FORMAT_APM 0xcdd7
1256 static GpStatus
encode_image_BMP(LPVOID bitmap_bits
, LPBITMAPINFO bitmap_info
,
1257 void **output
, unsigned int *output_size
)
1259 int num_palette_entries
;
1260 BITMAPFILEHEADER
*bmp_file_hdr
;
1261 BITMAPINFO
*bmp_info_hdr
;
1263 if (bitmap_info
->bmiHeader
.biClrUsed
) {
1264 num_palette_entries
= bitmap_info
->bmiHeader
.biClrUsed
;
1265 if (num_palette_entries
> 256) num_palette_entries
= 256;
1267 if (bitmap_info
->bmiHeader
.biBitCount
<= 8)
1268 num_palette_entries
= 1 << bitmap_info
->bmiHeader
.biBitCount
;
1270 num_palette_entries
= 0;
1274 sizeof(BITMAPFILEHEADER
) +
1275 sizeof(BITMAPINFOHEADER
) +
1276 num_palette_entries
* sizeof(RGBQUAD
) +
1277 bitmap_info
->bmiHeader
.biSizeImage
;
1279 *output
= GdipAlloc(*output_size
);
1281 bmp_file_hdr
= *output
;
1282 bmp_file_hdr
->bfType
= BITMAP_FORMAT_BMP
;
1283 bmp_file_hdr
->bfSize
= *output_size
;
1284 bmp_file_hdr
->bfOffBits
=
1285 sizeof(BITMAPFILEHEADER
) +
1286 sizeof(BITMAPINFOHEADER
) +
1287 num_palette_entries
* sizeof (RGBQUAD
);
1289 bmp_info_hdr
= (BITMAPINFO
*) ((unsigned char*)(*output
) + sizeof(BITMAPFILEHEADER
));
1290 memcpy(bmp_info_hdr
, bitmap_info
, sizeof(BITMAPINFOHEADER
) + num_palette_entries
* sizeof(RGBQUAD
));
1291 memcpy((unsigned char *)(*output
) +
1292 sizeof(BITMAPFILEHEADER
) +
1293 sizeof(BITMAPINFOHEADER
) +
1294 num_palette_entries
* sizeof(RGBQUAD
),
1295 bitmap_bits
, bitmap_info
->bmiHeader
.biSizeImage
);
1300 typedef GpStatus
encode_image_func(LPVOID bitmap_bits
, LPBITMAPINFO bitmap_info
,
1301 void **output
, unsigned int *output_size
);
1305 NUM_ENCODERS_SUPPORTED
1308 static const ImageCodecInfo codecs
[NUM_ENCODERS_SUPPORTED
];
1309 static encode_image_func
*const encode_image_funcs
[NUM_ENCODERS_SUPPORTED
] = {
1313 /*****************************************************************************
1314 * GdipSaveImageToStream [GDIPLUS.@]
1316 GpStatus WINGDIPAPI
GdipSaveImageToStream(GpImage
*image
, IStream
* stream
,
1317 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
1326 BITMAPINFO bmp_info
;
1328 encode_image_func
* encode_image
;
1330 unsigned int output_size
;
1338 TRACE("%p %p %p %p\n", image
, stream
, clsid
, params
);
1340 if(!image
|| !stream
)
1341 return InvalidParameter
;
1343 if (!image
->picture
)
1344 return GenericError
;
1346 hr
= IPicture_get_Type(image
->picture
, &type
);
1347 if (FAILED(hr
) || type
!= PICTYPE_BITMAP
)
1348 return GenericError
;
1350 /* select correct encoder */
1351 encode_image
= NULL
;
1352 for (i
= 0; i
< NUM_ENCODERS_SUPPORTED
; i
++) {
1353 if (IsEqualCLSID(clsid
, &codecs
[i
].Clsid
))
1354 encode_image
= encode_image_funcs
[i
];
1356 if (encode_image
== NULL
)
1357 return UnknownImageFormat
;
1359 /* extract underlying hbitmap representation from the IPicture */
1360 hr
= IPicture_get_Handle(image
->picture
, (OLE_HANDLE
*)&hbmp
);
1361 if (FAILED(hr
) || !hbmp
)
1362 return GenericError
;
1363 hr
= IPicture_get_CurDC(image
->picture
, &hdc
);
1365 return GenericError
;
1366 bm_is_selected
= (hdc
!= 0);
1367 if (!bm_is_selected
) {
1368 hdc
= CreateCompatibleDC(0);
1369 old_hbmp
= SelectObject(hdc
, hbmp
);
1372 /* get bits from HBITMAP */
1373 bmp_info
.bmiHeader
.biSize
= sizeof(bmp_info
.bmiHeader
);
1374 bmp_info
.bmiHeader
.biBitCount
= 0;
1375 GetDIBits(hdc
, hbmp
, 0, 0, NULL
, &bmp_info
, DIB_RGB_COLORS
);
1377 bmp_bits
= GdipAlloc(bmp_info
.bmiHeader
.biSizeImage
);
1380 GetDIBits(hdc
, hbmp
, 0, abs(bmp_info
.bmiHeader
.biHeight
), bmp_bits
, &bmp_info
, DIB_RGB_COLORS
);
1382 if (!bm_is_selected
) {
1383 SelectObject(hdc
, old_hbmp
);
1390 stat
= encode_image(bmp_bits
, &bmp_info
, &output
, &output_size
);
1392 IStream_Write(stream
, output
, output_size
, &dummy
);
1400 /*****************************************************************************
1401 * GdipSetImagePalette [GDIPLUS.@]
1403 GpStatus WINGDIPAPI
GdipSetImagePalette(GpImage
*image
,
1404 GDIPCONST ColorPalette
*palette
)
1408 if(!image
|| !palette
)
1409 return InvalidParameter
;
1412 FIXME("not implemented\n");
1414 return NotImplemented
;
1417 /*************************************************************************
1419 * Structures that represent which formats we support for encoding.
1422 /* ImageCodecInfo creation routines taken from libgdiplus */
1423 static const WCHAR bmp_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
1424 static const WCHAR bmp_extension
[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
1425 static const WCHAR bmp_mimetype
[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
1426 static const WCHAR bmp_format
[] = {'B', 'M', 'P', 0}; /* BMP */
1427 static const BYTE bmp_sig_pattern
[] = { 0x42, 0x4D };
1428 static const BYTE bmp_sig_mask
[] = { 0xFF, 0xFF };
1430 static const ImageCodecInfo codecs
[NUM_ENCODERS_SUPPORTED
] =
1433 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
1434 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
1435 /* CodecName */ bmp_codecname
,
1437 /* FormatDescription */ bmp_format
,
1438 /* FilenameExtension */ bmp_extension
,
1439 /* MimeType */ bmp_mimetype
,
1440 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
1444 /* SigPattern */ bmp_sig_pattern
,
1445 /* SigMask */ bmp_sig_mask
,
1449 /*****************************************************************************
1450 * GdipGetImageDecodersSize [GDIPLUS.@]
1452 GpStatus WINGDIPAPI
GdipGetImageDecodersSize(UINT
*numDecoders
, UINT
*size
)
1454 FIXME("%p %p stub!\n", numDecoders
, size
);
1456 if (!numDecoders
|| !size
)
1457 return InvalidParameter
;
1465 /*****************************************************************************
1466 * GdipGetImageDecoders [GDIPLUS.@]
1468 GpStatus WINGDIPAPI
GdipGetImageDecoders(UINT numDecoders
, UINT size
, ImageCodecInfo
*decoders
)
1470 FIXME("%u %u %p stub!\n", numDecoders
, size
, decoders
);
1473 return GenericError
;
1475 return NotImplemented
;
1478 /*****************************************************************************
1479 * GdipGetImageEncodersSize [GDIPLUS.@]
1481 GpStatus WINGDIPAPI
GdipGetImageEncodersSize(UINT
*numEncoders
, UINT
*size
)
1483 TRACE("%p %p\n", numEncoders
, size
);
1485 if (!numEncoders
|| !size
)
1486 return InvalidParameter
;
1488 *numEncoders
= NUM_ENCODERS_SUPPORTED
;
1489 *size
= sizeof (codecs
);
1494 /*****************************************************************************
1495 * GdipGetImageEncoders [GDIPLUS.@]
1497 GpStatus WINGDIPAPI
GdipGetImageEncoders(UINT numEncoders
, UINT size
, ImageCodecInfo
*encoders
)
1499 TRACE("%u %u %p\n", numEncoders
, size
, encoders
);
1502 (numEncoders
!= NUM_ENCODERS_SUPPORTED
) ||
1503 (size
!= sizeof (codecs
)))
1504 return GenericError
;
1506 memcpy(encoders
, codecs
, sizeof (codecs
));
1511 /*****************************************************************************
1512 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
1514 GpStatus WINGDIPAPI
GdipCreateBitmapFromHBITMAP(HBITMAP hbm
, HPALETTE hpal
, GpBitmap
** bitmap
)
1521 TRACE("%p %p %p\n", hbm
, hpal
, bitmap
);
1524 return InvalidParameter
;
1526 /* TODO: Support for device-dependent bitmaps */
1528 FIXME("no support for device-dependent bitmaps\n");
1529 return NotImplemented
;
1532 if (GetObjectA(hbm
, sizeof(bm
), &bm
) != sizeof(bm
))
1533 return InvalidParameter
;
1535 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
1536 switch(bm
.bmBitsPixel
) {
1538 format
= PixelFormat1bppIndexed
;
1541 format
= PixelFormat4bppIndexed
;
1544 format
= PixelFormat8bppIndexed
;
1547 format
= PixelFormat24bppRGB
;
1550 format
= PixelFormat32bppRGB
;
1553 format
= PixelFormat48bppRGB
;
1556 FIXME("don't know how to handle %d bpp\n", bm
.bmBitsPixel
);
1557 return InvalidParameter
;
1561 bits
= (BYTE
*)bm
.bmBits
+ (bm
.bmHeight
- 1) * bm
.bmWidthBytes
;
1564 FIXME("can only get image data from DIB sections\n");
1568 retval
= GdipCreateBitmapFromScan0(bm
.bmWidth
, bm
.bmHeight
, -bm
.bmWidthBytes
,
1569 format
, bits
, bitmap
);
1574 /*****************************************************************************
1575 * GdipSetEffectParameters [GDIPLUS.@]
1577 GpStatus WINGDIPAPI
GdipSetEffectParameters(CGpEffect
*effect
,
1578 const VOID
*params
, const UINT size
)
1583 FIXME("not implemented\n");
1585 return NotImplemented
;
1588 /*****************************************************************************
1589 * GdipGetImageFlags [GDIPLUS.@]
1591 GpStatus WINGDIPAPI
GdipGetImageFlags(GpImage
*image
, UINT
*flags
)
1593 TRACE("%p %p\n", image
, flags
);
1595 if(!image
|| !flags
)
1596 return InvalidParameter
;
1598 *flags
= image
->flags
;
1603 GpStatus WINGDIPAPI
GdipTestControl(GpTestControlEnum control
, void *param
)
1605 TRACE("(%d, %p)\n", control
, param
);
1608 case TestControlForceBilinear
:
1610 FIXME("TestControlForceBilinear not handled\n");
1612 case TestControlNoICM
:
1614 FIXME("TestControlNoICM not handled\n");
1616 case TestControlGetBuildNumber
:
1617 *((DWORD
*)param
) = 3102;
1624 GpStatus WINGDIPAPI
GdipRecordMetafileFileName(GDIPCONST WCHAR
* fileName
,
1625 HDC hdc
, EmfType type
, GDIPCONST GpRectF
*pFrameRect
,
1626 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
,
1627 GpMetafile
**metafile
)
1629 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName
), hdc
, type
, pFrameRect
,
1630 frameUnit
, debugstr_w(desc
), metafile
);
1632 return NotImplemented
;
1635 GpStatus WINGDIPAPI
GdipRecordMetafileFileNameI(GDIPCONST WCHAR
* fileName
, HDC hdc
, EmfType type
,
1636 GDIPCONST GpRect
*pFrameRect
, MetafileFrameUnit frameUnit
,
1637 GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
1639 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName
), hdc
, type
, pFrameRect
,
1640 frameUnit
, debugstr_w(desc
), metafile
);
1642 return NotImplemented
;
1645 GpStatus WINGDIPAPI
GdipImageForceValidation(GpImage
*image
)
1647 FIXME("%p\n", image
);