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
33 #include "gdiplus_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
38 #define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
40 static INT
ipicture_pixel_height(IPicture
*pic
)
45 IPicture_get_Height(pic
, &y
);
49 y
= MulDiv(y
, GetDeviceCaps(hdcref
, LOGPIXELSY
), INCH_HIMETRIC
);
55 static INT
ipicture_pixel_width(IPicture
*pic
)
60 IPicture_get_Width(pic
, &x
);
64 x
= MulDiv(x
, GetDeviceCaps(hdcref
, LOGPIXELSX
), INCH_HIMETRIC
);
71 GpStatus WINGDIPAPI
GdipBitmapGetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
75 TRACE("%p %d %d %p\n", bitmap
, x
, y
, color
);
78 return InvalidParameter
;
81 FIXME("not implemented\n");
85 return NotImplemented
;
88 /* This function returns a pointer to an array of pixels that represents the
89 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
90 * flags. It is correct behavior that a user who calls this function with write
91 * privileges can write to the whole bitmap (not just the area in rect).
93 * FIXME: only used portion of format is bits per pixel. */
94 GpStatus WINGDIPAPI
GdipBitmapLockBits(GpBitmap
* bitmap
, GDIPCONST GpRect
* rect
,
95 UINT flags
, PixelFormat format
, BitmapData
* lockeddata
)
98 INT stride
, bitspp
= PIXELFORMATBPP(format
);
100 HBITMAP hbm
, old
= NULL
;
104 GpRect act_rect
; /* actual rect to be used */
106 TRACE("%p %p %d %d %p\n", bitmap
, rect
, flags
, format
, lockeddata
);
108 if(!lockeddata
|| !bitmap
)
109 return InvalidParameter
;
112 if(rect
->X
< 0 || rect
->Y
< 0 || (rect
->X
+ rect
->Width
> bitmap
->width
) ||
113 (rect
->Y
+ rect
->Height
> bitmap
->height
) || !flags
)
114 return InvalidParameter
;
119 act_rect
.X
= act_rect
.Y
= 0;
120 act_rect
.Width
= bitmap
->width
;
121 act_rect
.Height
= bitmap
->height
;
124 if(flags
& ImageLockModeUserInputBuf
)
125 return NotImplemented
;
130 IPicture_get_Handle(bitmap
->image
.picture
, (OLE_HANDLE
*)&hbm
);
131 IPicture_get_CurDC(bitmap
->image
.picture
, &hdc
);
132 bm_is_selected
= (hdc
!= 0);
134 pbmi
= GdipAlloc(sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
137 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
138 pbmi
->bmiHeader
.biBitCount
= 0;
141 hdc
= CreateCompatibleDC(0);
142 old
= SelectObject(hdc
, hbm
);
146 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
148 abs_height
= abs(pbmi
->bmiHeader
.biHeight
);
149 stride
= pbmi
->bmiHeader
.biWidth
* bitspp
/ 8;
150 stride
= (stride
+ 3) & ~3;
152 buff
= GdipAlloc(stride
* abs_height
);
154 pbmi
->bmiHeader
.biBitCount
= bitspp
;
157 GetDIBits(hdc
, hbm
, 0, abs_height
, buff
, pbmi
, DIB_RGB_COLORS
);
160 SelectObject(hdc
, old
);
169 lockeddata
->Width
= act_rect
.Width
;
170 lockeddata
->Height
= act_rect
.Height
;
171 lockeddata
->PixelFormat
= format
;
172 lockeddata
->Reserved
= flags
;
174 if(pbmi
->bmiHeader
.biHeight
> 0){
175 lockeddata
->Stride
= -stride
;
176 lockeddata
->Scan0
= buff
+ (bitspp
/ 8) * act_rect
.X
+
177 stride
* (abs_height
- 1 - act_rect
.Y
);
180 lockeddata
->Stride
= stride
;
181 lockeddata
->Scan0
= buff
+ (bitspp
/ 8) * act_rect
.X
+ stride
* act_rect
.Y
;
184 bitmap
->lockmode
= flags
;
187 bitmap
->bitmapbits
= buff
;
193 GpStatus WINGDIPAPI
GdipBitmapUnlockBits(GpBitmap
* bitmap
,
194 BitmapData
* lockeddata
)
197 HBITMAP hbm
, old
= NULL
;
201 if(!bitmap
|| !lockeddata
)
202 return InvalidParameter
;
204 if(!bitmap
->lockmode
)
207 if(lockeddata
->Reserved
& ImageLockModeUserInputBuf
)
208 return NotImplemented
;
210 if(lockeddata
->Reserved
& ImageLockModeRead
){
211 if(!(--bitmap
->numlocks
))
212 bitmap
->lockmode
= 0;
214 GdipFree(bitmap
->bitmapbits
);
215 bitmap
->bitmapbits
= NULL
;
219 IPicture_get_Handle(bitmap
->image
.picture
, (OLE_HANDLE
*)&hbm
);
220 IPicture_get_CurDC(bitmap
->image
.picture
, &hdc
);
221 bm_is_selected
= (hdc
!= 0);
223 pbmi
= GdipAlloc(sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
224 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
225 pbmi
->bmiHeader
.biBitCount
= 0;
228 hdc
= CreateCompatibleDC(0);
229 old
= SelectObject(hdc
, hbm
);
232 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
233 pbmi
->bmiHeader
.biBitCount
= PIXELFORMATBPP(lockeddata
->PixelFormat
);
234 SetDIBits(hdc
, hbm
, 0, abs(pbmi
->bmiHeader
.biHeight
),
235 bitmap
->bitmapbits
, pbmi
, DIB_RGB_COLORS
);
238 SelectObject(hdc
, old
);
243 GdipFree(bitmap
->bitmapbits
);
244 bitmap
->bitmapbits
= NULL
;
245 bitmap
->lockmode
= 0;
250 GpStatus WINGDIPAPI
GdipCloneImage(GpImage
*image
, GpImage
**cloneImage
)
256 GpStatus stat
= GenericError
;
258 TRACE("%p, %p\n", image
, cloneImage
);
260 if (!image
|| !cloneImage
)
261 return InvalidParameter
;
263 hr
= CreateStreamOnHGlobal(0, TRUE
, &stream
);
267 hr
= IPicture_SaveAsFile(image
->picture
, stream
, FALSE
, &size
);
270 WARN("Failed to save image on stream\n");
274 /* Set seek pointer back to the beginning of the picture */
276 hr
= IStream_Seek(stream
, move
, STREAM_SEEK_SET
, NULL
);
280 stat
= GdipLoadImageFromStream(stream
, cloneImage
);
281 if (stat
!= Ok
) WARN("Failed to load image from stream\n");
284 IStream_Release(stream
);
288 GpStatus WINGDIPAPI
GdipCreateBitmapFromFile(GDIPCONST WCHAR
* filename
,
294 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
296 if(!filename
|| !bitmap
)
297 return InvalidParameter
;
299 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
304 stat
= GdipCreateBitmapFromStream(stream
, bitmap
);
306 IStream_Release(stream
);
311 GpStatus WINGDIPAPI
GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO
* info
,
312 VOID
*bits
, GpBitmap
**bitmap
)
314 DWORD height
, stride
;
317 FIXME("(%p, %p, %p) - partially implemented\n", info
, bits
, bitmap
);
319 height
= abs(info
->bmiHeader
.biHeight
);
320 stride
= ((info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
+ 31) >> 3) & ~3;
322 if(info
->bmiHeader
.biHeight
> 0) /* bottom-up */
324 bits
= (BYTE
*)bits
+ (height
- 1) * stride
;
328 switch(info
->bmiHeader
.biBitCount
) {
330 format
= PixelFormat1bppIndexed
;
333 format
= PixelFormat4bppIndexed
;
336 format
= PixelFormat8bppIndexed
;
339 format
= PixelFormat24bppRGB
;
342 FIXME("don't know how to handle %d bpp\n", info
->bmiHeader
.biBitCount
);
344 return InvalidParameter
;
347 return GdipCreateBitmapFromScan0(info
->bmiHeader
.biWidth
, height
, stride
, format
,
353 GpStatus WINGDIPAPI
GdipCreateBitmapFromFileICM(GDIPCONST WCHAR
* filename
,
356 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
358 return GdipCreateBitmapFromFile(filename
, bitmap
);
361 GpStatus WINGDIPAPI
GdipCreateBitmapFromResource(HINSTANCE hInstance
,
362 GDIPCONST WCHAR
* lpBitmapName
, GpBitmap
** bitmap
)
365 GpStatus stat
= InvalidParameter
;
367 TRACE("%p (%s) %p\n", hInstance
, debugstr_w(lpBitmapName
), bitmap
);
369 if(!lpBitmapName
|| !bitmap
)
370 return InvalidParameter
;
373 hbm
= LoadImageW(hInstance
, lpBitmapName
, IMAGE_BITMAP
, 0, 0,
374 LR_CREATEDIBSECTION
);
377 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, bitmap
);
384 GpStatus WINGDIPAPI
GdipCreateHBITMAPFromBitmap(GpBitmap
* bitmap
,
385 HBITMAP
* hbmReturn
, ARGB background
)
391 return NotImplemented
;
394 GpStatus WINGDIPAPI
GdipConvertToEmfPlus(const GpGraphics
* ref
,
395 GpMetafile
* metafile
, BOOL
* succ
, EmfType emfType
,
396 const WCHAR
* description
, GpMetafile
** out_metafile
)
400 if(!ref
|| !metafile
|| !out_metafile
)
401 return InvalidParameter
;
404 *out_metafile
= NULL
;
407 FIXME("not implemented\n");
409 return NotImplemented
;
412 /* FIXME: this should create a bitmap in the given size with the attributes
413 * (resolution etc.) of the graphics object */
414 GpStatus WINGDIPAPI
GdipCreateBitmapFromGraphics(INT width
, INT height
,
415 GpGraphics
* target
, GpBitmap
** bitmap
)
420 if(!target
|| !bitmap
)
421 return InvalidParameter
;
424 FIXME("hacked stub\n");
426 ret
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat24bppRGB
,
432 GpStatus WINGDIPAPI
GdipCreateBitmapFromScan0(INT width
, INT height
, INT stride
,
433 PixelFormat format
, BYTE
* scan0
, GpBitmap
** bitmap
)
435 BITMAPFILEHEADER
*bmfh
;
436 BITMAPINFOHEADER
*bmih
;
441 TRACE("%d %d %d %d %p %p\n", width
, height
, stride
, format
, scan0
, bitmap
);
443 if (!bitmap
) return InvalidParameter
;
445 if(width
<= 0 || height
<= 0 || (scan0
&& (stride
% 4))){
447 return InvalidParameter
;
451 return InvalidParameter
;
453 /* FIXME: windows allows negative stride (reads backwards from scan0) */
455 FIXME("negative stride\n");
456 return InvalidParameter
;
459 *bitmap
= GdipAlloc(sizeof(GpBitmap
));
460 if(!*bitmap
) return OutOfMemory
;
463 stride
= width
* (PIXELFORMATBPP(format
) / 8);
464 stride
= (stride
+ 3) & ~3;
467 datalen
= abs(stride
* height
);
468 size
= sizeof(BITMAPFILEHEADER
) + sizeof(BITMAPINFOHEADER
) + datalen
;
469 buff
= GdipAlloc(size
);
475 bmfh
= (BITMAPFILEHEADER
*) buff
;
476 bmih
= (BITMAPINFOHEADER
*) (bmfh
+ 1);
478 bmfh
->bfType
= (((WORD
)'M') << 8) + (WORD
)'B';
480 bmfh
->bfOffBits
= size
- datalen
;
482 bmih
->biSize
= sizeof(BITMAPINFOHEADER
);
483 bmih
->biWidth
= width
;
484 bmih
->biHeight
= -height
;
485 /* FIXME: use the rest of the data from format */
486 bmih
->biBitCount
= PIXELFORMATBPP(format
);
487 bmih
->biCompression
= BI_RGB
;
488 bmih
->biSizeImage
= datalen
;
491 memcpy(bmih
+ 1, scan0
, datalen
);
493 memset(bmih
+ 1, 0, datalen
);
495 if(CreateStreamOnHGlobal(buff
, TRUE
, &stream
) != S_OK
){
496 ERR("could not make stream\n");
502 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
503 (LPVOID
*) &((*bitmap
)->image
.picture
)) != S_OK
){
504 TRACE("Could not load picture\n");
505 IStream_Release(stream
);
511 (*bitmap
)->image
.type
= ImageTypeBitmap
;
512 (*bitmap
)->image
.flags
= ImageFlagsNone
;
513 (*bitmap
)->width
= width
;
514 (*bitmap
)->height
= height
;
515 (*bitmap
)->format
= format
;
520 GpStatus WINGDIPAPI
GdipCreateBitmapFromStream(IStream
* stream
,
525 TRACE("%p %p\n", stream
, bitmap
);
527 stat
= GdipLoadImageFromStream(stream
, (GpImage
**) bitmap
);
532 if((*bitmap
)->image
.type
!= ImageTypeBitmap
){
533 IPicture_Release((*bitmap
)->image
.picture
);
535 return GenericError
; /* FIXME: what error to return? */
542 GpStatus WINGDIPAPI
GdipCreateBitmapFromStreamICM(IStream
* stream
,
545 TRACE("%p %p\n", stream
, bitmap
);
547 return GdipCreateBitmapFromStream(stream
, bitmap
);
550 GpStatus WINGDIPAPI
GdipCreateCachedBitmap(GpBitmap
*bitmap
, GpGraphics
*graphics
,
551 GpCachedBitmap
**cachedbmp
)
555 TRACE("%p %p %p\n", bitmap
, graphics
, cachedbmp
);
557 if(!bitmap
|| !graphics
|| !cachedbmp
)
558 return InvalidParameter
;
560 *cachedbmp
= GdipAlloc(sizeof(GpCachedBitmap
));
564 stat
= GdipCloneImage(&(bitmap
->image
), &(*cachedbmp
)->image
);
566 GdipFree(*cachedbmp
);
573 GpStatus WINGDIPAPI
GdipDeleteCachedBitmap(GpCachedBitmap
*cachedbmp
)
575 TRACE("%p\n", cachedbmp
);
578 return InvalidParameter
;
580 GdipDisposeImage(cachedbmp
->image
);
586 GpStatus WINGDIPAPI
GdipDrawCachedBitmap(GpGraphics
*graphics
,
587 GpCachedBitmap
*cachedbmp
, INT x
, INT y
)
589 TRACE("%p %p %d %d\n", graphics
, cachedbmp
, x
, y
);
591 if(!graphics
|| !cachedbmp
)
592 return InvalidParameter
;
594 return GdipDrawImage(graphics
, cachedbmp
->image
, (REAL
)x
, (REAL
)y
);
597 GpStatus WINGDIPAPI
GdipDisposeImage(GpImage
*image
)
601 TRACE("%p\n", image
);
604 return InvalidParameter
;
606 IPicture_get_CurDC(image
->picture
, &hdc
);
608 IPicture_Release(image
->picture
);
609 if (image
->type
== ImageTypeBitmap
)
610 GdipFree(((GpBitmap
*)image
)->bitmapbits
);
616 GpStatus WINGDIPAPI
GdipFindFirstImageItem(GpImage
*image
, ImageItemData
* item
)
619 return InvalidParameter
;
621 return NotImplemented
;
624 GpStatus WINGDIPAPI
GdipGetImageBounds(GpImage
*image
, GpRectF
*srcRect
,
627 TRACE("%p %p %p\n", image
, srcRect
, srcUnit
);
629 if(!image
|| !srcRect
|| !srcUnit
)
630 return InvalidParameter
;
631 if(image
->type
== ImageTypeMetafile
){
632 *srcRect
= ((GpMetafile
*)image
)->bounds
;
633 *srcUnit
= ((GpMetafile
*)image
)->unit
;
635 else if(image
->type
== ImageTypeBitmap
){
636 srcRect
->X
= srcRect
->Y
= 0.0;
637 srcRect
->Width
= (REAL
) ((GpBitmap
*)image
)->width
;
638 srcRect
->Height
= (REAL
) ((GpBitmap
*)image
)->height
;
639 *srcUnit
= UnitPixel
;
642 srcRect
->X
= srcRect
->Y
= 0.0;
643 srcRect
->Width
= ipicture_pixel_width(image
->picture
);
644 srcRect
->Height
= ipicture_pixel_height(image
->picture
);
645 *srcUnit
= UnitPixel
;
648 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect
->X
, srcRect
->Y
,
649 srcRect
->Width
, srcRect
->Height
, *srcUnit
);
654 GpStatus WINGDIPAPI
GdipGetImageDimension(GpImage
*image
, REAL
*width
,
657 TRACE("%p %p %p\n", image
, width
, height
);
659 if(!image
|| !height
|| !width
)
660 return InvalidParameter
;
662 if(image
->type
== ImageTypeMetafile
){
665 *height
= convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
666 ((GpMetafile
*)image
)->bounds
.Height
;
668 *width
= convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
669 ((GpMetafile
*)image
)->bounds
.Width
;
674 else if(image
->type
== ImageTypeBitmap
){
675 *height
= ((GpBitmap
*)image
)->height
;
676 *width
= ((GpBitmap
*)image
)->width
;
679 *height
= ipicture_pixel_height(image
->picture
);
680 *width
= ipicture_pixel_width(image
->picture
);
683 TRACE("returning (%f, %f)\n", *height
, *width
);
687 GpStatus WINGDIPAPI
GdipGetImageGraphicsContext(GpImage
*image
,
688 GpGraphics
**graphics
)
692 TRACE("%p %p\n", image
, graphics
);
694 if(!image
|| !graphics
)
695 return InvalidParameter
;
697 if(image
->type
!= ImageTypeBitmap
){
698 FIXME("not implemented for image type %d\n", image
->type
);
699 return NotImplemented
;
702 IPicture_get_CurDC(image
->picture
, &hdc
);
705 hdc
= CreateCompatibleDC(0);
706 IPicture_SelectPicture(image
->picture
, hdc
, NULL
, NULL
);
709 return GdipCreateFromHDC(hdc
, graphics
);
712 GpStatus WINGDIPAPI
GdipGetImageHeight(GpImage
*image
, UINT
*height
)
714 TRACE("%p %p\n", image
, height
);
716 if(!image
|| !height
)
717 return InvalidParameter
;
719 if(image
->type
== ImageTypeMetafile
){
722 *height
= roundr(convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
723 ((GpMetafile
*)image
)->bounds
.Height
);
727 else if(image
->type
== ImageTypeBitmap
)
728 *height
= ((GpBitmap
*)image
)->height
;
730 *height
= ipicture_pixel_height(image
->picture
);
732 TRACE("returning %d\n", *height
);
737 GpStatus WINGDIPAPI
GdipGetImageHorizontalResolution(GpImage
*image
, REAL
*res
)
742 return InvalidParameter
;
745 FIXME("not implemented\n");
747 return NotImplemented
;
750 GpStatus WINGDIPAPI
GdipGetImagePaletteSize(GpImage
*image
, INT
*size
)
752 FIXME("%p %p\n", image
, size
);
755 return InvalidParameter
;
757 return NotImplemented
;
760 /* FIXME: test this function for non-bitmap types */
761 GpStatus WINGDIPAPI
GdipGetImagePixelFormat(GpImage
*image
, PixelFormat
*format
)
763 TRACE("%p %p\n", image
, format
);
765 if(!image
|| !format
)
766 return InvalidParameter
;
768 if(image
->type
!= ImageTypeBitmap
)
769 *format
= PixelFormat24bppRGB
;
771 *format
= ((GpBitmap
*) image
)->format
;
776 GpStatus WINGDIPAPI
GdipGetImageRawFormat(GpImage
*image
, GUID
*format
)
780 if(!image
|| !format
)
781 return InvalidParameter
;
786 /* FIXME: should be detected from embedded picture or stored separately */
789 case ImageTypeBitmap
: *format
= ImageFormatBMP
; break;
790 case ImageTypeMetafile
: *format
= ImageFormatEMF
; break;
792 WARN("unknown type %u\n", image
->type
);
793 *format
= ImageFormatUndefined
;
798 GpStatus WINGDIPAPI
GdipGetImageType(GpImage
*image
, ImageType
*type
)
800 TRACE("%p %p\n", image
, type
);
803 return InvalidParameter
;
810 GpStatus WINGDIPAPI
GdipGetImageVerticalResolution(GpImage
*image
, REAL
*res
)
815 return InvalidParameter
;
818 FIXME("not implemented\n");
820 return NotImplemented
;
823 GpStatus WINGDIPAPI
GdipGetImageWidth(GpImage
*image
, UINT
*width
)
825 TRACE("%p %p\n", image
, width
);
828 return InvalidParameter
;
830 if(image
->type
== ImageTypeMetafile
){
833 *width
= roundr(convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
834 ((GpMetafile
*)image
)->bounds
.Width
);
838 else if(image
->type
== ImageTypeBitmap
)
839 *width
= ((GpBitmap
*)image
)->width
;
841 *width
= ipicture_pixel_width(image
->picture
);
843 TRACE("returning %d\n", *width
);
848 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromMetafile(GpMetafile
* metafile
,
849 MetafileHeader
* header
)
853 if(!metafile
|| !header
)
854 return InvalidParameter
;
857 FIXME("not implemented\n");
862 GpStatus WINGDIPAPI
GdipGetAllPropertyItems(GpImage
*image
, UINT size
,
863 UINT num
, PropertyItem
* items
)
868 FIXME("not implemented\n");
870 return InvalidParameter
;
873 GpStatus WINGDIPAPI
GdipGetPropertyCount(GpImage
*image
, UINT
* num
)
878 FIXME("not implemented\n");
880 return InvalidParameter
;
883 GpStatus WINGDIPAPI
GdipGetPropertyIdList(GpImage
*image
, UINT num
, PROPID
* list
)
888 FIXME("not implemented\n");
890 return InvalidParameter
;
893 GpStatus WINGDIPAPI
GdipGetPropertyItem(GpImage
*image
, PROPID id
, UINT size
,
894 PropertyItem
* buffer
)
899 FIXME("not implemented\n");
901 return InvalidParameter
;
904 GpStatus WINGDIPAPI
GdipGetPropertyItemSize(GpImage
*image
, PROPID pid
,
909 TRACE("%p %x %p\n", image
, pid
, size
);
912 return InvalidParameter
;
915 FIXME("not implemented\n");
917 return NotImplemented
;
920 GpStatus WINGDIPAPI
GdipGetPropertySize(GpImage
*image
, UINT
* size
, UINT
* num
)
925 FIXME("not implemented\n");
927 return InvalidParameter
;
930 GpStatus WINGDIPAPI
GdipImageGetFrameCount(GpImage
*image
,
931 GDIPCONST GUID
* dimensionID
, UINT
* count
)
935 if(!image
|| !dimensionID
|| !count
)
936 return InvalidParameter
;
939 FIXME("not implemented\n");
941 return NotImplemented
;
944 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsCount(GpImage
*image
,
948 return InvalidParameter
;
957 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsList(GpImage
* image
,
958 GUID
* dimensionIDs
, UINT count
)
962 if(!image
|| !dimensionIDs
)
963 return InvalidParameter
;
966 FIXME("not implemented\n");
971 GpStatus WINGDIPAPI
GdipImageSelectActiveFrame(GpImage
*image
,
972 GDIPCONST GUID
* dimensionID
, UINT frameidx
)
976 if(!image
|| !dimensionID
)
977 return InvalidParameter
;
980 FIXME("not implemented\n");
985 GpStatus WINGDIPAPI
GdipLoadImageFromFile(GDIPCONST WCHAR
* filename
,
991 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
993 if (!filename
|| !image
)
994 return InvalidParameter
;
996 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
1001 stat
= GdipLoadImageFromStream(stream
, image
);
1003 IStream_Release(stream
);
1008 /* FIXME: no icm handling */
1009 GpStatus WINGDIPAPI
GdipLoadImageFromFileICM(GDIPCONST WCHAR
* filename
,GpImage
**image
)
1011 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
1013 return GdipLoadImageFromFile(filename
, image
);
1016 GpStatus WINGDIPAPI
GdipLoadImageFromStream(IStream
* stream
, GpImage
**image
)
1021 TRACE("%p %p\n", stream
, image
);
1023 if(!stream
|| !image
)
1024 return InvalidParameter
;
1026 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
1027 (LPVOID
*) &pic
) != S_OK
){
1028 TRACE("Could not load picture\n");
1029 return GenericError
;
1032 IPicture_get_Type(pic
, &type
);
1034 if(type
== PICTYPE_BITMAP
){
1036 BITMAPCOREHEADER
* bmch
;
1040 pbmi
= GdipAlloc(sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1043 *image
= GdipAlloc(sizeof(GpBitmap
));
1048 (*image
)->type
= ImageTypeBitmap
;
1050 (*((GpBitmap
**) image
))->width
= ipicture_pixel_width(pic
);
1051 (*((GpBitmap
**) image
))->height
= ipicture_pixel_height(pic
);
1053 /* get the pixel format */
1054 IPicture_get_Handle(pic
, (OLE_HANDLE
*)&hbm
);
1055 IPicture_get_CurDC(pic
, &hdc
);
1057 bmch
= (BITMAPCOREHEADER
*) (&pbmi
->bmiHeader
);
1058 bmch
->bcSize
= sizeof(BITMAPCOREHEADER
);
1062 hdc
= CreateCompatibleDC(0);
1063 old
= SelectObject(hdc
, hbm
);
1064 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
1065 SelectObject(hdc
, old
);
1069 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
1071 (*((GpBitmap
**) image
))->format
= (bmch
->bcBitCount
<< 8) | PixelFormatGDI
;
1074 else if(type
== PICTYPE_METAFILE
|| type
== PICTYPE_ENHMETAFILE
){
1075 /* FIXME: missing initialization code */
1076 *image
= GdipAlloc(sizeof(GpMetafile
));
1077 if(!*image
) return OutOfMemory
;
1078 (*image
)->type
= ImageTypeMetafile
;
1081 *image
= GdipAlloc(sizeof(GpImage
));
1082 if(!*image
) return OutOfMemory
;
1083 (*image
)->type
= ImageTypeUnknown
;
1086 (*image
)->picture
= pic
;
1087 (*image
)->flags
= ImageFlagsNone
;
1093 GpStatus WINGDIPAPI
GdipLoadImageFromStreamICM(IStream
* stream
, GpImage
**image
)
1095 TRACE("%p %p\n", stream
, image
);
1097 return GdipLoadImageFromStream(stream
, image
);
1100 GpStatus WINGDIPAPI
GdipRemovePropertyItem(GpImage
*image
, PROPID propId
)
1105 return InvalidParameter
;
1108 FIXME("not implemented\n");
1110 return NotImplemented
;
1113 GpStatus WINGDIPAPI
GdipSetPropertyItem(GpImage
*image
, GDIPCONST PropertyItem
* item
)
1118 FIXME("not implemented\n");
1120 return NotImplemented
;
1123 GpStatus WINGDIPAPI
GdipSaveImageToFile(GpImage
*image
, GDIPCONST WCHAR
* filename
,
1124 GDIPCONST CLSID
*clsidEncoder
,
1125 GDIPCONST EncoderParameters
*encoderParams
)
1130 TRACE("%p (%s) %p %p\n", image
, debugstr_w(filename
), clsidEncoder
, encoderParams
);
1132 if (!image
|| !filename
|| !clsidEncoder
)
1133 return InvalidParameter
;
1135 if (!(image
->picture
))
1136 return InvalidParameter
;
1138 stat
= GdipCreateStreamOnFile(filename
, GENERIC_WRITE
, &stream
);
1140 return GenericError
;
1142 stat
= GdipSaveImageToStream(image
, stream
, clsidEncoder
, encoderParams
);
1144 IStream_Release(stream
);
1148 /*************************************************************************
1149 * Encoding functions -
1150 * These functions encode an image in different image file formats.
1152 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
1153 #define BITMAP_FORMAT_JPEG 0xd8ff
1154 #define BITMAP_FORMAT_GIF 0x4947
1155 #define BITMAP_FORMAT_PNG 0x5089
1156 #define BITMAP_FORMAT_APM 0xcdd7
1158 static GpStatus
encode_image_BMP(LPVOID bitmap_bits
, LPBITMAPINFO bitmap_info
,
1159 void **output
, unsigned int *output_size
)
1161 int num_palette_entries
;
1162 BITMAPFILEHEADER
*bmp_file_hdr
;
1163 BITMAPINFO
*bmp_info_hdr
;
1165 if (bitmap_info
->bmiHeader
.biClrUsed
) {
1166 num_palette_entries
= bitmap_info
->bmiHeader
.biClrUsed
;
1167 if (num_palette_entries
> 256) num_palette_entries
= 256;
1169 if (bitmap_info
->bmiHeader
.biBitCount
<= 8)
1170 num_palette_entries
= 1 << bitmap_info
->bmiHeader
.biBitCount
;
1172 num_palette_entries
= 0;
1176 sizeof(BITMAPFILEHEADER
) +
1177 sizeof(BITMAPINFOHEADER
) +
1178 num_palette_entries
* sizeof(RGBQUAD
) +
1179 bitmap_info
->bmiHeader
.biSizeImage
;
1181 *output
= GdipAlloc(*output_size
);
1183 bmp_file_hdr
= (BITMAPFILEHEADER
*) *output
;
1184 bmp_file_hdr
->bfType
= BITMAP_FORMAT_BMP
;
1185 bmp_file_hdr
->bfSize
= *output_size
;
1186 bmp_file_hdr
->bfOffBits
=
1187 sizeof(BITMAPFILEHEADER
) +
1188 sizeof(BITMAPINFOHEADER
) +
1189 num_palette_entries
* sizeof (RGBQUAD
);
1191 bmp_info_hdr
= (BITMAPINFO
*) ((unsigned char*)(*output
) + sizeof(BITMAPFILEHEADER
));
1192 memcpy(bmp_info_hdr
, bitmap_info
, sizeof(BITMAPINFOHEADER
) + num_palette_entries
* sizeof(RGBQUAD
));
1193 memcpy((unsigned char *)(*output
) +
1194 sizeof(BITMAPFILEHEADER
) +
1195 sizeof(BITMAPINFOHEADER
) +
1196 num_palette_entries
* sizeof(RGBQUAD
),
1197 bitmap_bits
, bitmap_info
->bmiHeader
.biSizeImage
);
1202 typedef GpStatus
encode_image_func(LPVOID bitmap_bits
, LPBITMAPINFO bitmap_info
,
1203 void **output
, unsigned int *output_size
);
1207 NUM_ENCODERS_SUPPORTED
1210 static const ImageCodecInfo codecs
[NUM_ENCODERS_SUPPORTED
];
1211 static encode_image_func
*const encode_image_funcs
[NUM_ENCODERS_SUPPORTED
] = {
1215 /*****************************************************************************
1216 * GdipSaveImageToStream [GDIPLUS.@]
1218 GpStatus WINGDIPAPI
GdipSaveImageToStream(GpImage
*image
, IStream
* stream
,
1219 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
1228 BITMAPINFO bmp_info
;
1230 encode_image_func
* encode_image
;
1232 unsigned int output_size
;
1240 TRACE("%p %p %p %p\n", image
, stream
, clsid
, params
);
1242 if(!image
|| !stream
)
1243 return InvalidParameter
;
1245 if (!image
->picture
)
1246 return GenericError
;
1248 hr
= IPicture_get_Type(image
->picture
, &type
);
1249 if (FAILED(hr
) || type
!= PICTYPE_BITMAP
)
1250 return GenericError
;
1252 /* select correct encoder */
1253 encode_image
= NULL
;
1254 for (i
= 0; i
< NUM_ENCODERS_SUPPORTED
; i
++) {
1255 if (IsEqualCLSID(clsid
, &codecs
[i
].Clsid
))
1256 encode_image
= encode_image_funcs
[i
];
1258 if (encode_image
== NULL
)
1259 return UnknownImageFormat
;
1261 /* extract underlying hbitmap representation from the IPicture */
1262 hr
= IPicture_get_Handle(image
->picture
, (OLE_HANDLE
*)&hbmp
);
1263 if (FAILED(hr
) || !hbmp
)
1264 return GenericError
;
1265 hr
= IPicture_get_CurDC(image
->picture
, &hdc
);
1267 return GenericError
;
1268 bm_is_selected
= (hdc
!= 0);
1269 if (!bm_is_selected
) {
1270 hdc
= CreateCompatibleDC(0);
1271 old_hbmp
= SelectObject(hdc
, hbmp
);
1274 /* get bits from HBITMAP */
1275 bmp_info
.bmiHeader
.biSize
= sizeof(bmp_info
.bmiHeader
);
1276 bmp_info
.bmiHeader
.biBitCount
= 0;
1277 GetDIBits(hdc
, hbmp
, 0, 0, NULL
, &bmp_info
, DIB_RGB_COLORS
);
1279 bmp_bits
= GdipAlloc(bmp_info
.bmiHeader
.biSizeImage
);
1282 GetDIBits(hdc
, hbmp
, 0, abs(bmp_info
.bmiHeader
.biHeight
), bmp_bits
, &bmp_info
, DIB_RGB_COLORS
);
1284 if (!bm_is_selected
) {
1285 SelectObject(hdc
, old_hbmp
);
1292 stat
= encode_image(bmp_bits
, &bmp_info
, &output
, &output_size
);
1294 IStream_Write(stream
, output
, output_size
, &dummy
);
1302 /*****************************************************************************
1303 * GdipSetImagePalette [GDIPLUS.@]
1305 GpStatus WINGDIPAPI
GdipSetImagePalette(GpImage
*image
,
1306 GDIPCONST ColorPalette
*palette
)
1310 if(!image
|| !palette
)
1311 return InvalidParameter
;
1314 FIXME("not implemented\n");
1316 return NotImplemented
;
1319 /*************************************************************************
1321 * Structures that represent which formats we support for encoding.
1324 /* ImageCodecInfo creation routines taken from libgdiplus */
1325 static const WCHAR bmp_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
1326 static const WCHAR bmp_extension
[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
1327 static const WCHAR bmp_mimetype
[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
1328 static const WCHAR bmp_format
[] = {'B', 'M', 'P', 0}; /* BMP */
1329 static const BYTE bmp_sig_pattern
[] = { 0x42, 0x4D };
1330 static const BYTE bmp_sig_mask
[] = { 0xFF, 0xFF };
1332 static const ImageCodecInfo codecs
[NUM_ENCODERS_SUPPORTED
] =
1335 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
1336 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
1337 /* CodecName */ bmp_codecname
,
1339 /* FormatDescription */ bmp_format
,
1340 /* FilenameExtension */ bmp_extension
,
1341 /* MimeType */ bmp_mimetype
,
1342 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
1346 /* SigPattern */ bmp_sig_pattern
,
1347 /* SigMask */ bmp_sig_mask
,
1351 /*****************************************************************************
1352 * GdipGetImageDecodersSize [GDIPLUS.@]
1354 GpStatus WINGDIPAPI
GdipGetImageDecodersSize(UINT
*numDecoders
, UINT
*size
)
1356 FIXME("%p %p stub!\n", numDecoders
, size
);
1358 if (!numDecoders
|| !size
)
1359 return InvalidParameter
;
1367 /*****************************************************************************
1368 * GdipGetImageDecoders [GDIPLUS.@]
1370 GpStatus WINGDIPAPI
GdipGetImageDecoders(UINT numDecoders
, UINT size
, ImageCodecInfo
*decoders
)
1372 FIXME("%u %u %p stub!\n", numDecoders
, size
, decoders
);
1375 return GenericError
;
1377 return NotImplemented
;
1380 /*****************************************************************************
1381 * GdipGetImageEncodersSize [GDIPLUS.@]
1383 GpStatus WINGDIPAPI
GdipGetImageEncodersSize(UINT
*numEncoders
, UINT
*size
)
1385 TRACE("%p %p\n", numEncoders
, size
);
1387 if (!numEncoders
|| !size
)
1388 return InvalidParameter
;
1390 *numEncoders
= NUM_ENCODERS_SUPPORTED
;
1391 *size
= sizeof (codecs
);
1396 /*****************************************************************************
1397 * GdipGetImageEncoders [GDIPLUS.@]
1399 GpStatus WINGDIPAPI
GdipGetImageEncoders(UINT numEncoders
, UINT size
, ImageCodecInfo
*encoders
)
1401 TRACE("%u %u %p\n", numEncoders
, size
, encoders
);
1404 (numEncoders
!= NUM_ENCODERS_SUPPORTED
) ||
1405 (size
!= sizeof (codecs
)))
1406 return GenericError
;
1408 memcpy(encoders
, codecs
, sizeof (codecs
));
1413 /*****************************************************************************
1414 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
1416 GpStatus WINGDIPAPI
GdipCreateBitmapFromHBITMAP(HBITMAP hbm
, HPALETTE hpal
, GpBitmap
** bitmap
)
1422 TRACE("%p %p %p\n", hbm
, hpal
, bitmap
);
1425 return InvalidParameter
;
1427 /* TODO: Support for device-dependent bitmaps */
1429 FIXME("no support for device-dependent bitmaps\n");
1430 return NotImplemented
;
1433 if (GetObjectA(hbm
, sizeof(bm
), &bm
) != sizeof(bm
))
1434 return InvalidParameter
;
1436 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
1437 switch(bm
.bmBitsPixel
) {
1439 format
= PixelFormat1bppIndexed
;
1442 format
= PixelFormat4bppIndexed
;
1445 format
= PixelFormat8bppIndexed
;
1448 format
= PixelFormat24bppRGB
;
1451 format
= PixelFormat32bppRGB
;
1454 format
= PixelFormat48bppRGB
;
1457 FIXME("don't know how to handle %d bpp\n", bm
.bmBitsPixel
);
1458 return InvalidParameter
;
1461 retval
= GdipCreateBitmapFromScan0(bm
.bmWidth
, bm
.bmHeight
, bm
.bmWidthBytes
,
1462 format
, bm
.bmBits
, bitmap
);
1467 /*****************************************************************************
1468 * GdipSetEffectParameters [GDIPLUS.@]
1470 GpStatus WINGDIPAPI
GdipSetEffectParameters(CGpEffect
*effect
,
1471 const VOID
*params
, const UINT size
)
1476 FIXME("not implemented\n");
1478 return NotImplemented
;
1481 /*****************************************************************************
1482 * GdipGetImageFlags [GDIPLUS.@]
1484 GpStatus WINGDIPAPI
GdipGetImageFlags(GpImage
*image
, UINT
*flags
)
1486 TRACE("%p %p\n", image
, flags
);
1488 if(!image
|| !flags
)
1489 return InvalidParameter
;
1491 *flags
= image
->flags
;
1496 GpStatus WINGDIPAPI
GdipTestControl(GpTestControlEnum control
, void *param
)
1498 TRACE("(%d, %p)\n", control
, param
);
1501 case TestControlForceBilinear
:
1503 FIXME("TestControlForceBilinear not handled\n");
1505 case TestControlNoICM
:
1507 FIXME("TestControlNoICM not handled\n");
1509 case TestControlGetBuildNumber
:
1510 *((DWORD
*)param
) = 3102;
1517 GpStatus WINGDIPAPI
GdipRecordMetafileFileName(GDIPCONST WCHAR
* fileName
,
1518 HDC hdc
, EmfType type
, GDIPCONST GpRectF
*pFrameRect
,
1519 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
,
1520 GpMetafile
**metafile
)
1522 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName
), hdc
, type
, pFrameRect
,
1523 frameUnit
, debugstr_w(desc
), metafile
);
1525 return NotImplemented
;
1528 GpStatus WINGDIPAPI
GdipRecordMetafileFileNameI(GDIPCONST WCHAR
* fileName
, HDC hdc
, EmfType type
,
1529 GDIPCONST GpRect
*pFrameRect
, MetafileFrameUnit frameUnit
,
1530 GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
1532 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName
), hdc
, type
, pFrameRect
,
1533 frameUnit
, debugstr_w(desc
), metafile
);
1535 return NotImplemented
;
1538 GpStatus WINGDIPAPI
GdipImageForceValidation(GpImage
*image
)
1540 FIXME("%p\n", image
);