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 GdipBitmapApplyEffect(GpBitmap* bitmap, CGpEffect* effect,
74 RECT* roi, BOOL useAuxData, VOID** auxData, INT* auxDataSize)
76 FIXME("(%p %p %p %d %p %p): stub\n", bitmap, effect, roi, useAuxData, auxData, auxDataSize);
78 * Note: According to Jose Roca's GDI+ docs, this function is not
79 * implemented in Windows's GDI+.
81 return NotImplemented;
84 GpStatus WINGDIPAPI GdipBitmapCreateApplyEffect(GpBitmap** inputBitmaps,
85 INT numInputs, CGpEffect* effect, RECT* roi, RECT* outputRect,
86 GpBitmap** outputBitmap, BOOL useAuxData, VOID** auxData, INT* auxDataSize)
88 FIXME("(%p %d %p %p %p %p %d %p %p): stub\n", inputBitmaps, numInputs, effect, roi, outputRect, outputBitmap, useAuxData, auxData, auxDataSize);
90 * Note: According to Jose Roca's GDI+ docs, this function is not
91 * implemented in Windows's GDI+.
93 return NotImplemented;
96 GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y,
100 TRACE("%p %d %d %p\n", bitmap, x, y, color);
102 if(!bitmap || !color)
103 return InvalidParameter;
106 FIXME("not implemented\n");
110 return NotImplemented;
113 GpStatus WINGDIPAPI GdipBitmapSetPixel(GpBitmap* bitmap, INT x, INT y,
117 TRACE("bitmap:%p, x:%d, y:%d, color:%08x\n", bitmap, x, y, color);
120 return InvalidParameter;
123 FIXME("not implemented\n");
125 return NotImplemented;
128 /* This function returns a pointer to an array of pixels that represents the
129 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
130 * flags. It is correct behavior that a user who calls this function with write
131 * privileges can write to the whole bitmap (not just the area in rect).
133 * FIXME: only used portion of format is bits per pixel. */
134 GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
135 UINT flags, PixelFormat format, BitmapData* lockeddata)
138 INT stride, bitspp = PIXELFORMATBPP(format);
140 HBITMAP hbm, old = NULL;
144 GpRect act_rect; /* actual rect to be used */
146 TRACE("%p %p %d %d %p\n", bitmap, rect, flags, format, lockeddata);
148 if(!lockeddata || !bitmap)
149 return InvalidParameter;
152 if(rect->X < 0 || rect->Y < 0 || (rect->X + rect->Width > bitmap->width) ||
153 (rect->Y + rect->Height > bitmap->height) || !flags)
154 return InvalidParameter;
159 act_rect.X = act_rect.Y = 0;
160 act_rect.Width = bitmap->width;
161 act_rect.Height = bitmap->height;
164 if(flags & ImageLockModeUserInputBuf)
165 return NotImplemented;
170 IPicture_get_Handle(bitmap->image.picture, (OLE_HANDLE*)&hbm);
171 IPicture_get_CurDC(bitmap->image.picture, &hdc);
172 bm_is_selected = (hdc != 0);
174 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
177 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
178 pbmi->bmiHeader.biBitCount = 0;
181 hdc = CreateCompatibleDC(0);
182 old = SelectObject(hdc, hbm);
186 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
188 abs_height = abs(pbmi->bmiHeader.biHeight);
189 stride = pbmi->bmiHeader.biWidth * bitspp / 8;
190 stride = (stride + 3) & ~3;
192 buff = GdipAlloc(stride * abs_height);
194 pbmi->bmiHeader.biBitCount = bitspp;
197 GetDIBits(hdc, hbm, 0, abs_height, buff, pbmi, DIB_RGB_COLORS);
200 SelectObject(hdc, old);
209 lockeddata->Width = act_rect.Width;
210 lockeddata->Height = act_rect.Height;
211 lockeddata->PixelFormat = format;
212 lockeddata->Reserved = flags;
214 if(pbmi->bmiHeader.biHeight > 0){
215 lockeddata->Stride = -stride;
216 lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X +
217 stride * (abs_height - 1 - act_rect.Y);
220 lockeddata->Stride = stride;
221 lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X + stride * act_rect.Y;
224 bitmap->lockmode = flags;
227 bitmap->bitmapbits = buff;
233 GpStatus WINGDIPAPI GdipBitmapSetResolution(GpBitmap* bitmap, REAL xdpi, REAL ydpi)
235 FIXME("(%p, %.2f, %.2f)\n", bitmap, xdpi, ydpi);
237 return NotImplemented;
240 GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap,
241 BitmapData* lockeddata)
244 HBITMAP hbm, old = NULL;
248 if(!bitmap || !lockeddata)
249 return InvalidParameter;
251 if(!bitmap->lockmode)
254 if(lockeddata->Reserved & ImageLockModeUserInputBuf)
255 return NotImplemented;
257 if(lockeddata->Reserved & ImageLockModeRead){
258 if(!(--bitmap->numlocks))
259 bitmap->lockmode = 0;
261 GdipFree(bitmap->bitmapbits);
262 bitmap->bitmapbits = NULL;
266 IPicture_get_Handle(bitmap->image.picture, (OLE_HANDLE*)&hbm);
267 IPicture_get_CurDC(bitmap->image.picture, &hdc);
268 bm_is_selected = (hdc != 0);
270 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
271 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
272 pbmi->bmiHeader.biBitCount = 0;
275 hdc = CreateCompatibleDC(0);
276 old = SelectObject(hdc, hbm);
279 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
280 pbmi->bmiHeader.biBitCount = PIXELFORMATBPP(lockeddata->PixelFormat);
281 SetDIBits(hdc, hbm, 0, abs(pbmi->bmiHeader.biHeight),
282 bitmap->bitmapbits, pbmi, DIB_RGB_COLORS);
285 SelectObject(hdc, old);
290 GdipFree(bitmap->bitmapbits);
291 bitmap->bitmapbits = NULL;
292 bitmap->lockmode = 0;
297 GpStatus WINGDIPAPI GdipCloneBitmapArea(REAL x, REAL y, REAL width, REAL height,
298 PixelFormat format, GpBitmap* srcBitmap, GpBitmap** dstBitmap)
300 FIXME("(%f,%f,%f,%f,%i,%p,%p): stub\n", x, y, width, height, format, srcBitmap, dstBitmap);
302 return NotImplemented;
305 GpStatus WINGDIPAPI GdipCloneBitmapAreaI(INT x, INT y, INT width, INT height,
306 PixelFormat format, GpBitmap* srcBitmap, GpBitmap** dstBitmap)
308 FIXME("(%i,%i,%i,%i,%i,%p,%p): stub\n", x, y, width, height, format, srcBitmap, dstBitmap);
310 return NotImplemented;
313 GpStatus WINGDIPAPI GdipCloneImage(GpImage *image, GpImage **cloneImage)
319 GpStatus stat = GenericError;
321 TRACE("%p, %p\n", image, cloneImage);
323 if (!image || !cloneImage)
324 return InvalidParameter;
326 hr = CreateStreamOnHGlobal(0, TRUE, &stream);
330 hr = IPicture_SaveAsFile(image->picture, stream, FALSE, &size);
333 WARN("Failed to save image on stream\n");
337 /* Set seek pointer back to the beginning of the picture */
339 hr = IStream_Seek(stream, move, STREAM_SEEK_SET, NULL);
343 stat = GdipLoadImageFromStream(stream, cloneImage);
344 if (stat != Ok) WARN("Failed to load image from stream\n");
347 IStream_Release(stream);
351 GpStatus WINGDIPAPI GdipCreateBitmapFromFile(GDIPCONST WCHAR* filename,
357 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
359 if(!filename || !bitmap)
360 return InvalidParameter;
362 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
367 stat = GdipCreateBitmapFromStream(stream, bitmap);
369 IStream_Release(stream);
374 GpStatus WINGDIPAPI GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO* info,
375 VOID *bits, GpBitmap **bitmap)
377 DWORD height, stride;
380 FIXME("(%p, %p, %p) - partially implemented\n", info, bits, bitmap);
382 height = abs(info->bmiHeader.biHeight);
383 stride = ((info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) >> 3) & ~3;
385 if(info->bmiHeader.biHeight > 0) /* bottom-up */
387 bits = (BYTE*)bits + (height - 1) * stride;
391 switch(info->bmiHeader.biBitCount) {
393 format = PixelFormat1bppIndexed;
396 format = PixelFormat4bppIndexed;
399 format = PixelFormat8bppIndexed;
402 format = PixelFormat24bppRGB;
405 FIXME("don't know how to handle %d bpp\n", info->bmiHeader.biBitCount);
407 return InvalidParameter;
410 return GdipCreateBitmapFromScan0(info->bmiHeader.biWidth, height, stride, format,
416 GpStatus WINGDIPAPI GdipCreateBitmapFromFileICM(GDIPCONST WCHAR* filename,
419 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
421 return GdipCreateBitmapFromFile(filename, bitmap);
424 GpStatus WINGDIPAPI GdipCreateBitmapFromResource(HINSTANCE hInstance,
425 GDIPCONST WCHAR* lpBitmapName, GpBitmap** bitmap)
428 GpStatus stat = InvalidParameter;
430 TRACE("%p (%s) %p\n", hInstance, debugstr_w(lpBitmapName), bitmap);
432 if(!lpBitmapName || !bitmap)
433 return InvalidParameter;
436 hbm = LoadImageW(hInstance, lpBitmapName, IMAGE_BITMAP, 0, 0,
437 LR_CREATEDIBSECTION);
440 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, bitmap);
447 GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
448 HBITMAP* hbmReturn, ARGB background)
452 if (hbmReturn) *hbmReturn = NULL;
454 return NotImplemented;
457 GpStatus WINGDIPAPI GdipConvertToEmfPlus(const GpGraphics* ref,
458 GpMetafile* metafile, BOOL* succ, EmfType emfType,
459 const WCHAR* description, GpMetafile** out_metafile)
463 if(!ref || !metafile || !out_metafile)
464 return InvalidParameter;
467 *out_metafile = NULL;
470 FIXME("not implemented\n");
472 return NotImplemented;
475 /* FIXME: this should create a bitmap in the given size with the attributes
476 * (resolution etc.) of the graphics object */
477 GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT width, INT height,
478 GpGraphics* target, GpBitmap** bitmap)
483 if(!target || !bitmap)
484 return InvalidParameter;
487 FIXME("hacked stub\n");
489 ret = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat24bppRGB,
495 GpStatus WINGDIPAPI GdipCreateBitmapFromHICON(HICON hicon, GpBitmap** bitmap)
501 TRACE("%p, %p\n", hicon, bitmap);
503 if(!bitmap || !GetIconInfo(hicon, &iinfo))
504 return InvalidParameter;
506 *bitmap = GdipAlloc(sizeof(GpBitmap));
507 if(!*bitmap) return OutOfMemory;
509 icon_copy = CreateIconIndirect(&iinfo);
513 return InvalidParameter;
516 desc.cbSizeofstruct = sizeof(PICTDESC);
517 desc.picType = PICTYPE_ICON;
518 desc.u.icon.hicon = icon_copy;
520 if(OleCreatePictureIndirect(&desc, &IID_IPicture, TRUE,
521 (LPVOID*) &((*bitmap)->image.picture)) != S_OK){
522 DestroyIcon(icon_copy);
527 (*bitmap)->format = PixelFormat32bppARGB;
528 (*bitmap)->image.type = ImageTypeBitmap;
529 (*bitmap)->image.flags = ImageFlagsNone;
530 (*bitmap)->width = ipicture_pixel_width((*bitmap)->image.picture);
531 (*bitmap)->height = ipicture_pixel_height((*bitmap)->image.picture);
533 DeleteObject(iinfo.hbmColor);
534 DeleteObject(iinfo.hbmMask);
539 GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
540 PixelFormat format, BYTE* scan0, GpBitmap** bitmap)
542 BITMAPFILEHEADER *bmfh;
543 BITMAPINFOHEADER *bmih;
548 TRACE("%d %d %d %d %p %p\n", width, height, stride, format, scan0, bitmap);
550 if (!bitmap) return InvalidParameter;
552 if(width <= 0 || height <= 0 || (scan0 && (stride % 4))){
554 return InvalidParameter;
558 return InvalidParameter;
560 *bitmap = GdipAlloc(sizeof(GpBitmap));
561 if(!*bitmap) return OutOfMemory;
564 stride = width * (PIXELFORMATBPP(format) / 8);
565 stride = (stride + 3) & ~3;
568 datalen = abs(stride * height);
569 size = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + datalen;
570 buff = GdipAlloc(size);
576 bmfh = (BITMAPFILEHEADER*) buff;
577 bmih = (BITMAPINFOHEADER*) (bmfh + 1);
579 bmfh->bfType = (((WORD)'M') << 8) + (WORD)'B';
581 bmfh->bfOffBits = size - datalen;
583 bmih->biSize = sizeof(BITMAPINFOHEADER);
584 bmih->biWidth = width;
585 /* FIXME: use the rest of the data from format */
586 bmih->biBitCount = PIXELFORMATBPP(format);
587 bmih->biCompression = BI_RGB;
588 bmih->biSizeImage = datalen;
594 bmih->biHeight = -height;
595 memcpy(bmih + 1, scan0, datalen);
599 bmih->biHeight = height;
600 memcpy(bmih + 1, scan0 + stride * (height - 1), datalen);
605 bmih->biHeight = height;
606 memset(bmih + 1, 0, datalen);
609 if(CreateStreamOnHGlobal(buff, TRUE, &stream) != S_OK){
610 ERR("could not make stream\n");
617 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
618 (LPVOID*) &((*bitmap)->image.picture)) != S_OK){
619 TRACE("Could not load picture\n");
620 IStream_Release(stream);
627 (*bitmap)->image.type = ImageTypeBitmap;
628 (*bitmap)->image.flags = ImageFlagsNone;
629 (*bitmap)->width = width;
630 (*bitmap)->height = height;
631 (*bitmap)->format = format;
636 GpStatus WINGDIPAPI GdipCreateBitmapFromStream(IStream* stream,
641 TRACE("%p %p\n", stream, bitmap);
643 stat = GdipLoadImageFromStream(stream, (GpImage**) bitmap);
648 if((*bitmap)->image.type != ImageTypeBitmap){
649 IPicture_Release((*bitmap)->image.picture);
651 return GenericError; /* FIXME: what error to return? */
658 GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream* stream,
661 TRACE("%p %p\n", stream, bitmap);
663 return GdipCreateBitmapFromStream(stream, bitmap);
666 GpStatus WINGDIPAPI GdipCreateCachedBitmap(GpBitmap *bitmap, GpGraphics *graphics,
667 GpCachedBitmap **cachedbmp)
671 TRACE("%p %p %p\n", bitmap, graphics, cachedbmp);
673 if(!bitmap || !graphics || !cachedbmp)
674 return InvalidParameter;
676 *cachedbmp = GdipAlloc(sizeof(GpCachedBitmap));
680 stat = GdipCloneImage(&(bitmap->image), &(*cachedbmp)->image);
682 GdipFree(*cachedbmp);
689 GpStatus WINGDIPAPI GdipCreateHICONFromBitmap(GpBitmap *bitmap, HICON *hicon)
691 FIXME("(%p, %p)\n", bitmap, hicon);
693 return NotImplemented;
696 GpStatus WINGDIPAPI GdipDeleteCachedBitmap(GpCachedBitmap *cachedbmp)
698 TRACE("%p\n", cachedbmp);
701 return InvalidParameter;
703 GdipDisposeImage(cachedbmp->image);
709 GpStatus WINGDIPAPI GdipDrawCachedBitmap(GpGraphics *graphics,
710 GpCachedBitmap *cachedbmp, INT x, INT y)
712 TRACE("%p %p %d %d\n", graphics, cachedbmp, x, y);
714 if(!graphics || !cachedbmp)
715 return InvalidParameter;
717 return GdipDrawImage(graphics, cachedbmp->image, (REAL)x, (REAL)y);
720 GpStatus WINGDIPAPI GdipEmfToWmfBits(HENHMETAFILE hemf, UINT cbData16,
721 LPBYTE pData16, INT iMapMode, INT eFlags)
723 FIXME("(%p, %d, %p, %d, %d): stub\n", hemf, cbData16, pData16, iMapMode, eFlags);
724 return NotImplemented;
727 GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
731 TRACE("%p\n", image);
734 return InvalidParameter;
736 IPicture_get_CurDC(image->picture, &hdc);
738 IPicture_Release(image->picture);
739 if (image->type == ImageTypeBitmap)
740 GdipFree(((GpBitmap*)image)->bitmapbits);
746 GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage *image, ImageItemData* item)
749 return InvalidParameter;
751 return NotImplemented;
754 GpStatus WINGDIPAPI GdipGetImageBounds(GpImage *image, GpRectF *srcRect,
757 TRACE("%p %p %p\n", image, srcRect, srcUnit);
759 if(!image || !srcRect || !srcUnit)
760 return InvalidParameter;
761 if(image->type == ImageTypeMetafile){
762 *srcRect = ((GpMetafile*)image)->bounds;
763 *srcUnit = ((GpMetafile*)image)->unit;
765 else if(image->type == ImageTypeBitmap){
766 srcRect->X = srcRect->Y = 0.0;
767 srcRect->Width = (REAL) ((GpBitmap*)image)->width;
768 srcRect->Height = (REAL) ((GpBitmap*)image)->height;
769 *srcUnit = UnitPixel;
772 srcRect->X = srcRect->Y = 0.0;
773 srcRect->Width = ipicture_pixel_width(image->picture);
774 srcRect->Height = ipicture_pixel_height(image->picture);
775 *srcUnit = UnitPixel;
778 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect->X, srcRect->Y,
779 srcRect->Width, srcRect->Height, *srcUnit);
784 GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
787 TRACE("%p %p %p\n", image, width, height);
789 if(!image || !height || !width)
790 return InvalidParameter;
792 if(image->type == ImageTypeMetafile){
795 *height = convert_unit(hdc, ((GpMetafile*)image)->unit) *
796 ((GpMetafile*)image)->bounds.Height;
798 *width = convert_unit(hdc, ((GpMetafile*)image)->unit) *
799 ((GpMetafile*)image)->bounds.Width;
804 else if(image->type == ImageTypeBitmap){
805 *height = ((GpBitmap*)image)->height;
806 *width = ((GpBitmap*)image)->width;
809 *height = ipicture_pixel_height(image->picture);
810 *width = ipicture_pixel_width(image->picture);
813 TRACE("returning (%f, %f)\n", *height, *width);
817 GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image,
818 GpGraphics **graphics)
822 TRACE("%p %p\n", image, graphics);
824 if(!image || !graphics)
825 return InvalidParameter;
827 if(image->type != ImageTypeBitmap){
828 FIXME("not implemented for image type %d\n", image->type);
829 return NotImplemented;
832 IPicture_get_CurDC(image->picture, &hdc);
835 hdc = CreateCompatibleDC(0);
836 IPicture_SelectPicture(image->picture, hdc, NULL, NULL);
839 return GdipCreateFromHDC(hdc, graphics);
842 GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
844 TRACE("%p %p\n", image, height);
846 if(!image || !height)
847 return InvalidParameter;
849 if(image->type == ImageTypeMetafile){
852 *height = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
853 ((GpMetafile*)image)->bounds.Height);
857 else if(image->type == ImageTypeBitmap)
858 *height = ((GpBitmap*)image)->height;
860 *height = ipicture_pixel_height(image->picture);
862 TRACE("returning %d\n", *height);
867 GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res)
872 return InvalidParameter;
875 FIXME("not implemented\n");
877 return NotImplemented;
880 GpStatus WINGDIPAPI GdipGetImagePaletteSize(GpImage *image, INT *size)
882 FIXME("%p %p\n", image, size);
885 return InvalidParameter;
887 return NotImplemented;
890 /* FIXME: test this function for non-bitmap types */
891 GpStatus WINGDIPAPI GdipGetImagePixelFormat(GpImage *image, PixelFormat *format)
893 TRACE("%p %p\n", image, format);
895 if(!image || !format)
896 return InvalidParameter;
898 if(image->type != ImageTypeBitmap)
899 *format = PixelFormat24bppRGB;
901 *format = ((GpBitmap*) image)->format;
906 GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage *image, GUID *format)
910 if(!image || !format)
911 return InvalidParameter;
916 /* FIXME: should be detected from embedded picture or stored separately */
919 case ImageTypeBitmap: *format = ImageFormatBMP; break;
920 case ImageTypeMetafile: *format = ImageFormatEMF; break;
922 WARN("unknown type %u\n", image->type);
923 *format = ImageFormatUndefined;
928 GpStatus WINGDIPAPI GdipGetImageType(GpImage *image, ImageType *type)
930 TRACE("%p %p\n", image, type);
933 return InvalidParameter;
940 GpStatus WINGDIPAPI GdipGetImageVerticalResolution(GpImage *image, REAL *res)
945 return InvalidParameter;
948 FIXME("not implemented\n");
950 return NotImplemented;
953 GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
955 TRACE("%p %p\n", image, width);
958 return InvalidParameter;
960 if(image->type == ImageTypeMetafile){
963 *width = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
964 ((GpMetafile*)image)->bounds.Width);
968 else if(image->type == ImageTypeBitmap)
969 *width = ((GpBitmap*)image)->width;
971 *width = ipicture_pixel_width(image->picture);
973 TRACE("returning %d\n", *width);
978 GpStatus WINGDIPAPI GdipGetMetafileHeaderFromMetafile(GpMetafile * metafile,
979 MetafileHeader * header)
983 if(!metafile || !header)
984 return InvalidParameter;
987 FIXME("not implemented\n");
992 GpStatus WINGDIPAPI GdipGetAllPropertyItems(GpImage *image, UINT size,
993 UINT num, PropertyItem* items)
998 FIXME("not implemented\n");
1000 return InvalidParameter;
1003 GpStatus WINGDIPAPI GdipGetPropertyCount(GpImage *image, UINT* num)
1008 FIXME("not implemented\n");
1010 return InvalidParameter;
1013 GpStatus WINGDIPAPI GdipGetPropertyIdList(GpImage *image, UINT num, PROPID* list)
1018 FIXME("not implemented\n");
1020 return InvalidParameter;
1023 GpStatus WINGDIPAPI GdipGetPropertyItem(GpImage *image, PROPID id, UINT size,
1024 PropertyItem* buffer)
1029 FIXME("not implemented\n");
1031 return InvalidParameter;
1034 GpStatus WINGDIPAPI GdipGetPropertyItemSize(GpImage *image, PROPID pid,
1039 TRACE("%p %x %p\n", image, pid, size);
1042 return InvalidParameter;
1045 FIXME("not implemented\n");
1047 return NotImplemented;
1050 GpStatus WINGDIPAPI GdipGetPropertySize(GpImage *image, UINT* size, UINT* num)
1055 FIXME("not implemented\n");
1057 return InvalidParameter;
1060 GpStatus WINGDIPAPI GdipImageGetFrameCount(GpImage *image,
1061 GDIPCONST GUID* dimensionID, UINT* count)
1065 if(!image || !dimensionID || !count)
1066 return InvalidParameter;
1069 FIXME("not implemented\n");
1071 return NotImplemented;
1074 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsCount(GpImage *image,
1077 if(!image || !count)
1078 return InvalidParameter;
1087 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsList(GpImage* image,
1088 GUID* dimensionIDs, UINT count)
1092 if(!image || !dimensionIDs)
1093 return InvalidParameter;
1096 FIXME("not implemented\n");
1101 GpStatus WINGDIPAPI GdipImageSelectActiveFrame(GpImage *image,
1102 GDIPCONST GUID* dimensionID, UINT frameidx)
1106 if(!image || !dimensionID)
1107 return InvalidParameter;
1110 FIXME("not implemented\n");
1115 GpStatus WINGDIPAPI GdipLoadImageFromFile(GDIPCONST WCHAR* filename,
1121 TRACE("(%s) %p\n", debugstr_w(filename), image);
1123 if (!filename || !image)
1124 return InvalidParameter;
1126 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
1131 stat = GdipLoadImageFromStream(stream, image);
1133 IStream_Release(stream);
1138 /* FIXME: no icm handling */
1139 GpStatus WINGDIPAPI GdipLoadImageFromFileICM(GDIPCONST WCHAR* filename,GpImage **image)
1141 TRACE("(%s) %p\n", debugstr_w(filename), image);
1143 return GdipLoadImageFromFile(filename, image);
1146 GpStatus WINGDIPAPI GdipLoadImageFromStream(IStream* stream, GpImage **image)
1151 TRACE("%p %p\n", stream, image);
1153 if(!stream || !image)
1154 return InvalidParameter;
1156 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
1157 (LPVOID*) &pic) != S_OK){
1158 TRACE("Could not load picture\n");
1159 return GenericError;
1162 IPicture_get_Type(pic, &type);
1164 if(type == PICTYPE_BITMAP){
1166 BITMAPCOREHEADER* bmch;
1170 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1173 *image = GdipAlloc(sizeof(GpBitmap));
1178 (*image)->type = ImageTypeBitmap;
1180 (*((GpBitmap**) image))->width = ipicture_pixel_width(pic);
1181 (*((GpBitmap**) image))->height = ipicture_pixel_height(pic);
1183 /* get the pixel format */
1184 IPicture_get_Handle(pic, (OLE_HANDLE*)&hbm);
1185 IPicture_get_CurDC(pic, &hdc);
1187 bmch = (BITMAPCOREHEADER*) (&pbmi->bmiHeader);
1188 bmch->bcSize = sizeof(BITMAPCOREHEADER);
1192 hdc = CreateCompatibleDC(0);
1193 old = SelectObject(hdc, hbm);
1194 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
1195 SelectObject(hdc, old);
1199 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
1201 switch(bmch->bcBitCount)
1204 (*((GpBitmap**) image))->format = PixelFormat1bppIndexed;
1207 (*((GpBitmap**) image))->format = PixelFormat4bppIndexed;
1210 (*((GpBitmap**) image))->format = PixelFormat8bppIndexed;
1213 (*((GpBitmap**) image))->format = PixelFormat16bppRGB565;
1216 (*((GpBitmap**) image))->format = PixelFormat24bppRGB;
1219 (*((GpBitmap**) image))->format = PixelFormat32bppRGB;
1222 (*((GpBitmap**) image))->format = PixelFormat48bppRGB;
1225 FIXME("Bit depth %d is not fully supported yet\n", bmch->bcBitCount);
1226 (*((GpBitmap**) image))->format = (bmch->bcBitCount << 8) | PixelFormatGDI;
1232 else if(type == PICTYPE_METAFILE || type == PICTYPE_ENHMETAFILE){
1233 /* FIXME: missing initialization code */
1234 *image = GdipAlloc(sizeof(GpMetafile));
1235 if(!*image) return OutOfMemory;
1236 (*image)->type = ImageTypeMetafile;
1239 *image = GdipAlloc(sizeof(GpImage));
1240 if(!*image) return OutOfMemory;
1241 (*image)->type = ImageTypeUnknown;
1244 (*image)->picture = pic;
1245 (*image)->flags = ImageFlagsNone;
1251 GpStatus WINGDIPAPI GdipLoadImageFromStreamICM(IStream* stream, GpImage **image)
1253 TRACE("%p %p\n", stream, image);
1255 return GdipLoadImageFromStream(stream, image);
1258 GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
1263 return InvalidParameter;
1266 FIXME("not implemented\n");
1268 return NotImplemented;
1271 GpStatus WINGDIPAPI GdipSetPropertyItem(GpImage *image, GDIPCONST PropertyItem* item)
1276 FIXME("not implemented\n");
1278 return NotImplemented;
1281 GpStatus WINGDIPAPI GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
1282 GDIPCONST CLSID *clsidEncoder,
1283 GDIPCONST EncoderParameters *encoderParams)
1288 TRACE("%p (%s) %p %p\n", image, debugstr_w(filename), clsidEncoder, encoderParams);
1290 if (!image || !filename|| !clsidEncoder)
1291 return InvalidParameter;
1293 stat = GdipCreateStreamOnFile(filename, GENERIC_WRITE, &stream);
1295 return GenericError;
1297 stat = GdipSaveImageToStream(image, stream, clsidEncoder, encoderParams);
1299 IStream_Release(stream);
1303 /*************************************************************************
1304 * Encoding functions -
1305 * These functions encode an image in different image file formats.
1307 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
1308 #define BITMAP_FORMAT_JPEG 0xd8ff
1309 #define BITMAP_FORMAT_GIF 0x4947
1310 #define BITMAP_FORMAT_PNG 0x5089
1311 #define BITMAP_FORMAT_APM 0xcdd7
1313 static GpStatus encode_image_BMP(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
1314 void **output, unsigned int *output_size)
1316 int num_palette_entries;
1317 BITMAPFILEHEADER *bmp_file_hdr;
1318 BITMAPINFO *bmp_info_hdr;
1320 if (bitmap_info->bmiHeader.biClrUsed) {
1321 num_palette_entries = bitmap_info->bmiHeader.biClrUsed;
1322 if (num_palette_entries > 256) num_palette_entries = 256;
1324 if (bitmap_info->bmiHeader.biBitCount <= 8)
1325 num_palette_entries = 1 << bitmap_info->bmiHeader.biBitCount;
1327 num_palette_entries = 0;
1331 sizeof(BITMAPFILEHEADER) +
1332 sizeof(BITMAPINFOHEADER) +
1333 num_palette_entries * sizeof(RGBQUAD) +
1334 bitmap_info->bmiHeader.biSizeImage;
1336 *output = GdipAlloc(*output_size);
1338 bmp_file_hdr = *output;
1339 bmp_file_hdr->bfType = BITMAP_FORMAT_BMP;
1340 bmp_file_hdr->bfSize = *output_size;
1341 bmp_file_hdr->bfOffBits =
1342 sizeof(BITMAPFILEHEADER) +
1343 sizeof(BITMAPINFOHEADER) +
1344 num_palette_entries * sizeof (RGBQUAD);
1346 bmp_info_hdr = (BITMAPINFO*) ((unsigned char*)(*output) + sizeof(BITMAPFILEHEADER));
1347 memcpy(bmp_info_hdr, bitmap_info, sizeof(BITMAPINFOHEADER) + num_palette_entries * sizeof(RGBQUAD));
1348 memcpy((unsigned char *)(*output) +
1349 sizeof(BITMAPFILEHEADER) +
1350 sizeof(BITMAPINFOHEADER) +
1351 num_palette_entries * sizeof(RGBQUAD),
1352 bitmap_bits, bitmap_info->bmiHeader.biSizeImage);
1357 typedef GpStatus (*encode_image_func)(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
1358 void **output, unsigned int *output_size);
1360 typedef struct image_codec {
1361 ImageCodecInfo info;
1362 encode_image_func encode_func;
1370 static const struct image_codec codecs[NUM_CODECS];
1372 /*****************************************************************************
1373 * GdipSaveImageToStream [GDIPLUS.@]
1375 GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
1376 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
1385 BITMAPINFO bmp_info;
1387 encode_image_func encode_image;
1389 unsigned int output_size;
1397 TRACE("%p %p %p %p\n", image, stream, clsid, params);
1399 if(!image || !stream)
1400 return InvalidParameter;
1402 if (!image->picture)
1403 return GenericError;
1405 hr = IPicture_get_Type(image->picture, &type);
1406 if (FAILED(hr) || type != PICTYPE_BITMAP)
1407 return GenericError;
1409 /* select correct encoder */
1410 encode_image = NULL;
1411 for (i = 0; i < NUM_CODECS; i++) {
1412 if (IsEqualCLSID(clsid, &codecs[i].info.Clsid))
1413 encode_image = codecs[i].encode_func;
1415 if (encode_image == NULL)
1416 return UnknownImageFormat;
1418 /* extract underlying hbitmap representation from the IPicture */
1419 hr = IPicture_get_Handle(image->picture, (OLE_HANDLE*)&hbmp);
1420 if (FAILED(hr) || !hbmp)
1421 return GenericError;
1422 hr = IPicture_get_CurDC(image->picture, &hdc);
1424 return GenericError;
1425 bm_is_selected = (hdc != 0);
1426 if (!bm_is_selected) {
1427 hdc = CreateCompatibleDC(0);
1428 old_hbmp = SelectObject(hdc, hbmp);
1431 /* get bits from HBITMAP */
1432 bmp_info.bmiHeader.biSize = sizeof(bmp_info.bmiHeader);
1433 bmp_info.bmiHeader.biBitCount = 0;
1434 GetDIBits(hdc, hbmp, 0, 0, NULL, &bmp_info, DIB_RGB_COLORS);
1436 bmp_bits = GdipAlloc(bmp_info.bmiHeader.biSizeImage);
1439 GetDIBits(hdc, hbmp, 0, abs(bmp_info.bmiHeader.biHeight), bmp_bits, &bmp_info, DIB_RGB_COLORS);
1441 if (!bm_is_selected) {
1442 SelectObject(hdc, old_hbmp);
1449 stat = encode_image(bmp_bits, &bmp_info, &output, &output_size);
1451 IStream_Write(stream, output, output_size, &dummy);
1459 /*****************************************************************************
1460 * GdipGetImagePalette [GDIPLUS.@]
1462 GpStatus WINGDIPAPI GdipGetImagePalette(GpImage *image, ColorPalette *palette, INT size)
1464 static int calls = 0;
1467 return InvalidParameter;
1470 FIXME("not implemented\n");
1472 return NotImplemented;
1475 /*****************************************************************************
1476 * GdipSetImagePalette [GDIPLUS.@]
1478 GpStatus WINGDIPAPI GdipSetImagePalette(GpImage *image,
1479 GDIPCONST ColorPalette *palette)
1483 if(!image || !palette)
1484 return InvalidParameter;
1487 FIXME("not implemented\n");
1489 return NotImplemented;
1492 /*************************************************************************
1494 * Structures that represent which formats we support for encoding.
1497 /* ImageCodecInfo creation routines taken from libgdiplus */
1498 static const WCHAR bmp_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
1499 static const WCHAR bmp_extension[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
1500 static const WCHAR bmp_mimetype[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
1501 static const WCHAR bmp_format[] = {'B', 'M', 'P', 0}; /* BMP */
1502 static const BYTE bmp_sig_pattern[] = { 0x42, 0x4D };
1503 static const BYTE bmp_sig_mask[] = { 0xFF, 0xFF };
1505 static const struct image_codec codecs[NUM_CODECS] = {
1508 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
1509 /* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
1510 /* CodecName */ bmp_codecname,
1512 /* FormatDescription */ bmp_format,
1513 /* FilenameExtension */ bmp_extension,
1514 /* MimeType */ bmp_mimetype,
1515 /* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
1519 /* SigPattern */ bmp_sig_pattern,
1520 /* SigMask */ bmp_sig_mask,
1526 /*****************************************************************************
1527 * GdipGetImageDecodersSize [GDIPLUS.@]
1529 GpStatus WINGDIPAPI GdipGetImageDecodersSize(UINT *numDecoders, UINT *size)
1531 int decoder_count=0;
1533 TRACE("%p %p\n", numDecoders, size);
1535 if (!numDecoders || !size)
1536 return InvalidParameter;
1538 for (i=0; i<NUM_CODECS; i++)
1540 if (codecs[i].info.Flags & ImageCodecFlagsDecoder)
1544 *numDecoders = decoder_count;
1545 *size = decoder_count * sizeof(ImageCodecInfo);
1550 /*****************************************************************************
1551 * GdipGetImageDecoders [GDIPLUS.@]
1553 GpStatus WINGDIPAPI GdipGetImageDecoders(UINT numDecoders, UINT size, ImageCodecInfo *decoders)
1555 int i, decoder_count=0;
1556 TRACE("%u %u %p\n", numDecoders, size, decoders);
1559 size != numDecoders * sizeof(ImageCodecInfo))
1560 return GenericError;
1562 for (i=0; i<NUM_CODECS; i++)
1564 if (codecs[i].info.Flags & ImageCodecFlagsDecoder)
1566 if (decoder_count == numDecoders) return GenericError;
1567 memcpy(&decoders[decoder_count], &codecs[i].info, sizeof(ImageCodecInfo));
1572 if (decoder_count < numDecoders) return GenericError;
1577 /*****************************************************************************
1578 * GdipGetImageEncodersSize [GDIPLUS.@]
1580 GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size)
1582 int encoder_count=0;
1584 TRACE("%p %p\n", numEncoders, size);
1586 if (!numEncoders || !size)
1587 return InvalidParameter;
1589 for (i=0; i<NUM_CODECS; i++)
1591 if (codecs[i].info.Flags & ImageCodecFlagsEncoder)
1595 *numEncoders = encoder_count;
1596 *size = encoder_count * sizeof(ImageCodecInfo);
1601 /*****************************************************************************
1602 * GdipGetImageEncoders [GDIPLUS.@]
1604 GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders)
1606 int i, encoder_count=0;
1607 TRACE("%u %u %p\n", numEncoders, size, encoders);
1610 size != numEncoders * sizeof(ImageCodecInfo))
1611 return GenericError;
1613 for (i=0; i<NUM_CODECS; i++)
1615 if (codecs[i].info.Flags & ImageCodecFlagsEncoder)
1617 if (encoder_count == numEncoders) return GenericError;
1618 memcpy(&encoders[encoder_count], &codecs[i].info, sizeof(ImageCodecInfo));
1623 if (encoder_count < numEncoders) return GenericError;
1628 /*****************************************************************************
1629 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
1631 GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBitmap** bitmap)
1638 TRACE("%p %p %p\n", hbm, hpal, bitmap);
1641 return InvalidParameter;
1643 /* TODO: Support for device-dependent bitmaps */
1645 FIXME("no support for device-dependent bitmaps\n");
1646 return NotImplemented;
1649 if (GetObjectA(hbm, sizeof(bm), &bm) != sizeof(bm))
1650 return InvalidParameter;
1652 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
1653 switch(bm.bmBitsPixel) {
1655 format = PixelFormat1bppIndexed;
1658 format = PixelFormat4bppIndexed;
1661 format = PixelFormat8bppIndexed;
1664 format = PixelFormat24bppRGB;
1667 format = PixelFormat32bppRGB;
1670 format = PixelFormat48bppRGB;
1673 FIXME("don't know how to handle %d bpp\n", bm.bmBitsPixel);
1674 return InvalidParameter;
1678 bits = (BYTE*)bm.bmBits + (bm.bmHeight - 1) * bm.bmWidthBytes;
1681 FIXME("can only get image data from DIB sections\n");
1685 retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, -bm.bmWidthBytes,
1686 format, bits, bitmap);
1691 GpStatus WINGDIPAPI GdipDeleteEffect(CGpEffect *effect)
1693 FIXME("(%p): stub\n", effect);
1694 /* note: According to Jose Roca's GDI+ Docs, this is not implemented
1695 * in Windows's gdiplus */
1696 return NotImplemented;
1699 /*****************************************************************************
1700 * GdipSetEffectParameters [GDIPLUS.@]
1702 GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect *effect,
1703 const VOID *params, const UINT size)
1708 FIXME("not implemented\n");
1710 return NotImplemented;
1713 /*****************************************************************************
1714 * GdipGetImageFlags [GDIPLUS.@]
1716 GpStatus WINGDIPAPI GdipGetImageFlags(GpImage *image, UINT *flags)
1718 TRACE("%p %p\n", image, flags);
1720 if(!image || !flags)
1721 return InvalidParameter;
1723 *flags = image->flags;
1728 GpStatus WINGDIPAPI GdipTestControl(GpTestControlEnum control, void *param)
1730 TRACE("(%d, %p)\n", control, param);
1733 case TestControlForceBilinear:
1735 FIXME("TestControlForceBilinear not handled\n");
1737 case TestControlNoICM:
1739 FIXME("TestControlNoICM not handled\n");
1741 case TestControlGetBuildNumber:
1742 *((DWORD*)param) = 3102;
1749 GpStatus WINGDIPAPI GdipRecordMetafileFileName(GDIPCONST WCHAR* fileName,
1750 HDC hdc, EmfType type, GDIPCONST GpRectF *pFrameRect,
1751 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc,
1752 GpMetafile **metafile)
1754 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
1755 frameUnit, debugstr_w(desc), metafile);
1757 return NotImplemented;
1760 GpStatus WINGDIPAPI GdipRecordMetafileFileNameI(GDIPCONST WCHAR* fileName, HDC hdc, EmfType type,
1761 GDIPCONST GpRect *pFrameRect, MetafileFrameUnit frameUnit,
1762 GDIPCONST WCHAR *desc, GpMetafile **metafile)
1764 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
1765 frameUnit, debugstr_w(desc), metafile);
1767 return NotImplemented;
1770 GpStatus WINGDIPAPI GdipImageForceValidation(GpImage *image)
1772 FIXME("%p\n", image);
1777 /*****************************************************************************
1778 * GdipGetImageThumbnail [GDIPLUS.@]
1780 GpStatus WINGDIPAPI GdipGetImageThumbnail(GpImage *image, UINT width, UINT height,
1781 GpImage **ret_image, GetThumbnailImageAbort cb,
1784 FIXME("(%p %u %u %p %p %p) stub\n",
1785 image, width, height, ret_image, cb, cb_data);
1786 return NotImplemented;
1789 /*****************************************************************************
1790 * GdipImageRotateFlip [GDIPLUS.@]
1792 GpStatus WINGDIPAPI GdipImageRotateFlip(GpImage *image, RotateFlipType type)
1794 FIXME("(%p %u) stub\n", image, type);
1795 return NotImplemented;