2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
36 #include "gdiplus_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
41 #define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
43 static INT ipicture_pixel_height(IPicture *pic)
48 IPicture_get_Height(pic, &y);
52 y = MulDiv(y, GetDeviceCaps(hdcref, LOGPIXELSY), INCH_HIMETRIC);
58 static INT ipicture_pixel_width(IPicture *pic)
63 IPicture_get_Width(pic, &x);
67 x = MulDiv(x, GetDeviceCaps(hdcref, LOGPIXELSX), INCH_HIMETRIC);
74 GpStatus WINGDIPAPI GdipBitmapApplyEffect(GpBitmap* bitmap, CGpEffect* effect,
75 RECT* roi, BOOL useAuxData, VOID** auxData, INT* auxDataSize)
77 FIXME("(%p %p %p %d %p %p): stub\n", bitmap, effect, roi, useAuxData, auxData, auxDataSize);
79 * Note: According to Jose Roca's GDI+ docs, this function is not
80 * implemented in Windows's GDI+.
82 return NotImplemented;
85 GpStatus WINGDIPAPI GdipBitmapCreateApplyEffect(GpBitmap** inputBitmaps,
86 INT numInputs, CGpEffect* effect, RECT* roi, RECT* outputRect,
87 GpBitmap** outputBitmap, BOOL useAuxData, VOID** auxData, INT* auxDataSize)
89 FIXME("(%p %d %p %p %p %p %d %p %p): stub\n", inputBitmaps, numInputs, effect, roi, outputRect, outputBitmap, useAuxData, auxData, auxDataSize);
91 * Note: According to Jose Roca's GDI+ docs, this function is not
92 * implemented in Windows's GDI+.
94 return NotImplemented;
97 static inline void getpixel_16bppGrayScale(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
98 const BYTE *row, UINT x)
100 *r = *g = *b = row[x*2+1];
104 static inline void getpixel_16bppRGB555(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
105 const BYTE *row, UINT x)
107 WORD pixel = *((WORD*)(row)+x);
108 *r = (pixel>>7&0xf8)|(pixel>>12&0x7);
109 *g = (pixel>>2&0xf8)|(pixel>>6&0x7);
110 *b = (pixel<<3&0xf8)|(pixel>>2&0x7);
114 static inline void getpixel_16bppRGB565(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
115 const BYTE *row, UINT x)
117 WORD pixel = *((WORD*)(row)+x);
118 *r = (pixel>>8&0xf8)|(pixel>>13&0x7);
119 *g = (pixel>>3&0xfc)|(pixel>>9&0x3);
120 *b = (pixel<<3&0xf8)|(pixel>>2&0x7);
124 static inline void getpixel_16bppARGB1555(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
125 const BYTE *row, UINT x)
127 WORD pixel = *((WORD*)(row)+x);
128 *r = (pixel>>7&0xf8)|(pixel>>12&0x7);
129 *g = (pixel>>2&0xf8)|(pixel>>6&0x7);
130 *b = (pixel<<3&0xf8)|(pixel>>2&0x7);
131 if ((pixel&0x8000) == 0x8000)
137 static inline void getpixel_24bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
138 const BYTE *row, UINT x)
146 static inline void getpixel_32bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
147 const BYTE *row, UINT x)
155 static inline void getpixel_32bppARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
156 const BYTE *row, UINT x)
164 static inline void getpixel_32bppPARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
165 const BYTE *row, UINT x)
172 *r = row[x*4+2] * 255 / *a;
173 *g = row[x*4+1] * 255 / *a;
174 *b = row[x*4] * 255 / *a;
178 static inline void getpixel_48bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
179 const BYTE *row, UINT x)
187 static inline void getpixel_64bppARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
188 const BYTE *row, UINT x)
196 static inline void getpixel_64bppPARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
197 const BYTE *row, UINT x)
204 *r = row[x*8+5] * 255 / *a;
205 *g = row[x*8+3] * 255 / *a;
206 *b = row[x*8+1] * 255 / *a;
210 GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y,
215 TRACE("%p %d %d %p\n", bitmap, x, y, color);
217 if(!bitmap || !color ||
218 x < 0 || y < 0 || x >= bitmap->width || y >= bitmap->height)
219 return InvalidParameter;
221 row = bitmap->bits+bitmap->stride*y;
223 switch (bitmap->format)
225 case PixelFormat16bppGrayScale:
226 getpixel_16bppGrayScale(&r,&g,&b,&a,row,x);
228 case PixelFormat16bppRGB555:
229 getpixel_16bppRGB555(&r,&g,&b,&a,row,x);
231 case PixelFormat16bppRGB565:
232 getpixel_16bppRGB565(&r,&g,&b,&a,row,x);
234 case PixelFormat16bppARGB1555:
235 getpixel_16bppARGB1555(&r,&g,&b,&a,row,x);
237 case PixelFormat24bppRGB:
238 getpixel_24bppRGB(&r,&g,&b,&a,row,x);
240 case PixelFormat32bppRGB:
241 getpixel_32bppRGB(&r,&g,&b,&a,row,x);
243 case PixelFormat32bppARGB:
244 getpixel_32bppARGB(&r,&g,&b,&a,row,x);
246 case PixelFormat32bppPARGB:
247 getpixel_32bppPARGB(&r,&g,&b,&a,row,x);
249 case PixelFormat48bppRGB:
250 getpixel_48bppRGB(&r,&g,&b,&a,row,x);
252 case PixelFormat64bppARGB:
253 getpixel_64bppARGB(&r,&g,&b,&a,row,x);
255 case PixelFormat64bppPARGB:
256 getpixel_64bppPARGB(&r,&g,&b,&a,row,x);
259 FIXME("not implemented for format 0x%x\n", bitmap->format);
260 return NotImplemented;
263 *color = a<<24|r<<16|g<<8|b;
268 static inline void setpixel_16bppGrayScale(BYTE r, BYTE g, BYTE b, BYTE a,
271 *((WORD*)(row)+x) = (r+g+b)*85;
274 static inline void setpixel_16bppRGB555(BYTE r, BYTE g, BYTE b, BYTE a,
277 *((WORD*)(row)+x) = (r<<7&0x7c00)|
282 static inline void setpixel_16bppRGB565(BYTE r, BYTE g, BYTE b, BYTE a,
285 *((WORD*)(row)+x) = (r<<8&0xf800)|
290 static inline void setpixel_16bppARGB1555(BYTE r, BYTE g, BYTE b, BYTE a,
293 *((WORD*)(row)+x) = (a<<8&0x8000)|
299 static inline void setpixel_24bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
307 static inline void setpixel_32bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
310 *((DWORD*)(row)+x) = (r<<16)|(g<<8)|b;
313 static inline void setpixel_32bppARGB(BYTE r, BYTE g, BYTE b, BYTE a,
316 *((DWORD*)(row)+x) = (a<<24)|(r<<16)|(g<<8)|b;
319 static inline void setpixel_32bppPARGB(BYTE r, BYTE g, BYTE b, BYTE a,
325 *((DWORD*)(row)+x) = (a<<24)|(r<<16)|(g<<8)|b;
328 static inline void setpixel_48bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
331 row[x*6+5] = row[x*6+4] = r;
332 row[x*6+3] = row[x*6+2] = g;
333 row[x*6+1] = row[x*6] = b;
336 static inline void setpixel_64bppARGB(BYTE r, BYTE g, BYTE b, BYTE a,
339 UINT64 a64=a, r64=r, g64=g, b64=b;
340 *((UINT64*)(row)+x) = (a64<<56)|(a64<<48)|(r64<<40)|(r64<<32)|(g64<<24)|(g64<<16)|(b64<<8)|b64;
343 static inline void setpixel_64bppPARGB(BYTE r, BYTE g, BYTE b, BYTE a,
346 UINT64 a64, r64, g64, b64;
351 *((UINT64*)(row)+x) = (a64<<48)|(r64<<32)|(g64<<16)|b64;
354 GpStatus WINGDIPAPI GdipBitmapSetPixel(GpBitmap* bitmap, INT x, INT y,
359 TRACE("bitmap:%p, x:%d, y:%d, color:%08x\n", bitmap, x, y, color);
361 if(!bitmap || x < 0 || y < 0 || x >= bitmap->width || y >= bitmap->height)
362 return InvalidParameter;
369 row = bitmap->bits + bitmap->stride * y;
371 switch (bitmap->format)
373 case PixelFormat16bppGrayScale:
374 setpixel_16bppGrayScale(r,g,b,a,row,x);
376 case PixelFormat16bppRGB555:
377 setpixel_16bppRGB555(r,g,b,a,row,x);
379 case PixelFormat16bppRGB565:
380 setpixel_16bppRGB565(r,g,b,a,row,x);
382 case PixelFormat16bppARGB1555:
383 setpixel_16bppARGB1555(r,g,b,a,row,x);
385 case PixelFormat24bppRGB:
386 setpixel_24bppRGB(r,g,b,a,row,x);
388 case PixelFormat32bppRGB:
389 setpixel_32bppRGB(r,g,b,a,row,x);
391 case PixelFormat32bppARGB:
392 setpixel_32bppARGB(r,g,b,a,row,x);
394 case PixelFormat32bppPARGB:
395 setpixel_32bppPARGB(r,g,b,a,row,x);
397 case PixelFormat48bppRGB:
398 setpixel_48bppRGB(r,g,b,a,row,x);
400 case PixelFormat64bppARGB:
401 setpixel_64bppARGB(r,g,b,a,row,x);
403 case PixelFormat64bppPARGB:
404 setpixel_64bppPARGB(r,g,b,a,row,x);
407 FIXME("not implemented for format 0x%x\n", bitmap->format);
408 return NotImplemented;
414 /* This function returns a pointer to an array of pixels that represents the
415 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
416 * flags. It is correct behavior that a user who calls this function with write
417 * privileges can write to the whole bitmap (not just the area in rect).
419 * FIXME: only used portion of format is bits per pixel. */
420 GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
421 UINT flags, PixelFormat format, BitmapData* lockeddata)
424 INT stride, bitspp = PIXELFORMATBPP(format);
426 HBITMAP hbm, old = NULL;
430 GpRect act_rect; /* actual rect to be used */
432 TRACE("%p %p %d %d %p\n", bitmap, rect, flags, format, lockeddata);
434 if(!lockeddata || !bitmap)
435 return InvalidParameter;
438 if(rect->X < 0 || rect->Y < 0 || (rect->X + rect->Width > bitmap->width) ||
439 (rect->Y + rect->Height > bitmap->height) || !flags)
440 return InvalidParameter;
445 act_rect.X = act_rect.Y = 0;
446 act_rect.Width = bitmap->width;
447 act_rect.Height = bitmap->height;
450 if(flags & ImageLockModeUserInputBuf)
451 return NotImplemented;
456 if (bitmap->bits && bitmap->format == format)
458 /* no conversion is necessary; just use the bits directly */
459 lockeddata->Width = act_rect.Width;
460 lockeddata->Height = act_rect.Height;
461 lockeddata->PixelFormat = format;
462 lockeddata->Reserved = flags;
463 lockeddata->Stride = bitmap->stride;
464 lockeddata->Scan0 = bitmap->bits + (bitspp / 8) * act_rect.X +
465 bitmap->stride * act_rect.Y;
467 bitmap->lockmode = flags;
473 hbm = bitmap->hbitmap;
475 bm_is_selected = (hdc != 0);
477 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
480 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
481 pbmi->bmiHeader.biBitCount = 0;
484 hdc = CreateCompatibleDC(0);
485 old = SelectObject(hdc, hbm);
489 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
491 abs_height = abs(pbmi->bmiHeader.biHeight);
492 stride = pbmi->bmiHeader.biWidth * bitspp / 8;
493 stride = (stride + 3) & ~3;
495 buff = GdipAlloc(stride * abs_height);
497 pbmi->bmiHeader.biBitCount = bitspp;
500 GetDIBits(hdc, hbm, 0, abs_height, buff, pbmi, DIB_RGB_COLORS);
503 SelectObject(hdc, old);
512 lockeddata->Width = act_rect.Width;
513 lockeddata->Height = act_rect.Height;
514 lockeddata->PixelFormat = format;
515 lockeddata->Reserved = flags;
517 if(pbmi->bmiHeader.biHeight > 0){
518 lockeddata->Stride = -stride;
519 lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X +
520 stride * (abs_height - 1 - act_rect.Y);
523 lockeddata->Stride = stride;
524 lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X + stride * act_rect.Y;
527 bitmap->lockmode = flags;
530 bitmap->bitmapbits = buff;
536 GpStatus WINGDIPAPI GdipBitmapSetResolution(GpBitmap* bitmap, REAL xdpi, REAL ydpi)
538 TRACE("(%p, %.2f, %.2f)\n", bitmap, xdpi, ydpi);
540 if (!bitmap || xdpi == 0.0 || ydpi == 0.0)
541 return InvalidParameter;
543 bitmap->image.xres = xdpi;
544 bitmap->image.yres = ydpi;
549 GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap,
550 BitmapData* lockeddata)
553 HBITMAP hbm, old = NULL;
557 TRACE("(%p,%p)\n", bitmap, lockeddata);
559 if(!bitmap || !lockeddata)
560 return InvalidParameter;
562 if(!bitmap->lockmode)
565 if(lockeddata->Reserved & ImageLockModeUserInputBuf)
566 return NotImplemented;
568 if(lockeddata->Reserved & ImageLockModeRead){
569 if(!(--bitmap->numlocks))
570 bitmap->lockmode = 0;
572 GdipFree(bitmap->bitmapbits);
573 bitmap->bitmapbits = NULL;
577 if (!bitmap->bitmapbits)
579 /* we passed a direct reference; no need to do anything */
580 bitmap->lockmode = 0;
581 bitmap->numlocks = 0;
585 hbm = bitmap->hbitmap;
587 bm_is_selected = (hdc != 0);
589 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
590 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
591 pbmi->bmiHeader.biBitCount = 0;
594 hdc = CreateCompatibleDC(0);
595 old = SelectObject(hdc, hbm);
598 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
599 pbmi->bmiHeader.biBitCount = PIXELFORMATBPP(lockeddata->PixelFormat);
600 SetDIBits(hdc, hbm, 0, abs(pbmi->bmiHeader.biHeight),
601 bitmap->bitmapbits, pbmi, DIB_RGB_COLORS);
604 SelectObject(hdc, old);
609 GdipFree(bitmap->bitmapbits);
610 bitmap->bitmapbits = NULL;
611 bitmap->lockmode = 0;
612 bitmap->numlocks = 0;
617 GpStatus WINGDIPAPI GdipCloneBitmapArea(REAL x, REAL y, REAL width, REAL height,
618 PixelFormat format, GpBitmap* srcBitmap, GpBitmap** dstBitmap)
620 BitmapData lockeddata_src, lockeddata_dst;
626 TRACE("(%f,%f,%f,%f,%i,%p,%p)\n", x, y, width, height, format, srcBitmap, dstBitmap);
628 if (!srcBitmap || !dstBitmap || srcBitmap->image.type != ImageTypeBitmap ||
630 x + width > srcBitmap->width || y + height > srcBitmap->height)
632 TRACE("<-- InvalidParameter\n");
633 return InvalidParameter;
636 if (format == PixelFormatDontCare)
637 format = srcBitmap->format;
641 area.Width = roundr(width);
642 area.Height = roundr(height);
644 stat = GdipBitmapLockBits(srcBitmap, &area, ImageLockModeRead, format,
646 if (stat != Ok) return stat;
648 stat = GdipCreateBitmapFromScan0(lockeddata_src.Width, lockeddata_src.Height,
649 0, lockeddata_src.PixelFormat, NULL, dstBitmap);
652 stat = GdipBitmapLockBits(*dstBitmap, NULL, ImageLockModeWrite,
653 lockeddata_src.PixelFormat, &lockeddata_dst);
657 /* copy the image data */
658 row_size = (lockeddata_src.Width * PIXELFORMATBPP(lockeddata_src.PixelFormat) +7)/8;
659 for (i=0; i<lockeddata_src.Height; i++)
660 memcpy((BYTE*)lockeddata_dst.Scan0+lockeddata_dst.Stride*i,
661 (BYTE*)lockeddata_src.Scan0+lockeddata_src.Stride*i,
664 GdipBitmapUnlockBits(*dstBitmap, &lockeddata_dst);
668 GdipDisposeImage((GpImage*)*dstBitmap);
671 GdipBitmapUnlockBits(srcBitmap, &lockeddata_src);
681 GpStatus WINGDIPAPI GdipCloneBitmapAreaI(INT x, INT y, INT width, INT height,
682 PixelFormat format, GpBitmap* srcBitmap, GpBitmap** dstBitmap)
684 TRACE("(%i,%i,%i,%i,%i,%p,%p)\n", x, y, width, height, format, srcBitmap, dstBitmap);
686 return GdipCloneBitmapArea(x, y, width, height, format, srcBitmap, dstBitmap);
689 GpStatus WINGDIPAPI GdipCloneImage(GpImage *image, GpImage **cloneImage)
691 GpStatus stat = GenericError;
693 TRACE("%p, %p\n", image, cloneImage);
695 if (!image || !cloneImage)
696 return InvalidParameter;
705 hr = CreateStreamOnHGlobal(0, TRUE, &stream);
709 hr = IPicture_SaveAsFile(image->picture, stream, FALSE, &size);
712 WARN("Failed to save image on stream\n");
716 /* Set seek pointer back to the beginning of the picture */
718 hr = IStream_Seek(stream, move, STREAM_SEEK_SET, NULL);
722 stat = GdipLoadImageFromStream(stream, cloneImage);
723 if (stat != Ok) WARN("Failed to load image from stream\n");
726 IStream_Release(stream);
729 else if (image->type == ImageTypeBitmap)
731 GpBitmap *bitmap = (GpBitmap*)image;
732 BitmapData lockeddata_src, lockeddata_dst;
736 stat = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, bitmap->format,
738 if (stat != Ok) return stat;
740 stat = GdipCreateBitmapFromScan0(lockeddata_src.Width, lockeddata_src.Height,
741 0, lockeddata_src.PixelFormat, NULL, (GpBitmap**)cloneImage);
744 stat = GdipBitmapLockBits((GpBitmap*)*cloneImage, NULL, ImageLockModeWrite,
745 lockeddata_src.PixelFormat, &lockeddata_dst);
749 /* copy the image data */
750 row_size = (lockeddata_src.Width * PIXELFORMATBPP(lockeddata_src.PixelFormat) +7)/8;
751 for (i=0; i<lockeddata_src.Height; i++)
752 memcpy((BYTE*)lockeddata_dst.Scan0+lockeddata_dst.Stride*i,
753 (BYTE*)lockeddata_src.Scan0+lockeddata_src.Stride*i,
756 GdipBitmapUnlockBits((GpBitmap*)*cloneImage, &lockeddata_dst);
760 GdipDisposeImage(*cloneImage);
763 GdipBitmapUnlockBits(bitmap, &lockeddata_src);
769 else memcpy(&(*cloneImage)->format, &image->format, sizeof(GUID));
775 ERR("GpImage with no IPicture or bitmap?!\n");
776 return NotImplemented;
780 GpStatus WINGDIPAPI GdipCreateBitmapFromFile(GDIPCONST WCHAR* filename,
786 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
788 if(!filename || !bitmap)
789 return InvalidParameter;
791 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
796 stat = GdipCreateBitmapFromStream(stream, bitmap);
798 IStream_Release(stream);
803 GpStatus WINGDIPAPI GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO* info,
804 VOID *bits, GpBitmap **bitmap)
806 DWORD height, stride;
809 FIXME("(%p, %p, %p) - partially implemented\n", info, bits, bitmap);
811 height = abs(info->bmiHeader.biHeight);
812 stride = ((info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) >> 3) & ~3;
814 if(info->bmiHeader.biHeight > 0) /* bottom-up */
816 bits = (BYTE*)bits + (height - 1) * stride;
820 switch(info->bmiHeader.biBitCount) {
822 format = PixelFormat1bppIndexed;
825 format = PixelFormat4bppIndexed;
828 format = PixelFormat8bppIndexed;
831 format = PixelFormat24bppRGB;
834 FIXME("don't know how to handle %d bpp\n", info->bmiHeader.biBitCount);
836 return InvalidParameter;
839 return GdipCreateBitmapFromScan0(info->bmiHeader.biWidth, height, stride, format,
845 GpStatus WINGDIPAPI GdipCreateBitmapFromFileICM(GDIPCONST WCHAR* filename,
848 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
850 return GdipCreateBitmapFromFile(filename, bitmap);
853 GpStatus WINGDIPAPI GdipCreateBitmapFromResource(HINSTANCE hInstance,
854 GDIPCONST WCHAR* lpBitmapName, GpBitmap** bitmap)
857 GpStatus stat = InvalidParameter;
859 TRACE("%p (%s) %p\n", hInstance, debugstr_w(lpBitmapName), bitmap);
861 if(!lpBitmapName || !bitmap)
862 return InvalidParameter;
865 hbm = LoadImageW(hInstance, lpBitmapName, IMAGE_BITMAP, 0, 0,
866 LR_CREATEDIBSECTION);
869 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, bitmap);
876 GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
877 HBITMAP* hbmReturn, ARGB background)
880 HBITMAP result, oldbitmap;
883 GpGraphics *graphics;
884 BITMAPINFOHEADER bih;
886 TRACE("(%p,%p,%x)\n", bitmap, hbmReturn, background);
888 if (!bitmap || !hbmReturn) return InvalidParameter;
890 GdipGetImageWidth((GpImage*)bitmap, &width);
891 GdipGetImageHeight((GpImage*)bitmap, &height);
893 bih.biSize = sizeof(bih);
895 bih.biHeight = height;
898 bih.biCompression = BI_RGB;
900 bih.biXPelsPerMeter = 0;
901 bih.biYPelsPerMeter = 0;
903 bih.biClrImportant = 0;
905 hdc = CreateCompatibleDC(NULL);
906 if (!hdc) return GenericError;
908 result = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS, &bits,
913 oldbitmap = SelectObject(hdc, result);
915 stat = GdipCreateFromHDC(hdc, &graphics);
918 stat = GdipGraphicsClear(graphics, background);
921 stat = GdipDrawImage(graphics, (GpImage*)bitmap, 0, 0);
923 GdipDeleteGraphics(graphics);
926 SelectObject(hdc, oldbitmap);
933 if (stat != Ok && result)
935 DeleteObject(result);
944 GpStatus WINGDIPAPI GdipConvertToEmfPlus(const GpGraphics* ref,
945 GpMetafile* metafile, BOOL* succ, EmfType emfType,
946 const WCHAR* description, GpMetafile** out_metafile)
950 TRACE("(%p,%p,%p,%u,%s,%p)\n", ref, metafile, succ, emfType,
951 debugstr_w(description), out_metafile);
953 if(!ref || !metafile || !out_metafile)
954 return InvalidParameter;
957 *out_metafile = NULL;
960 FIXME("not implemented\n");
962 return NotImplemented;
965 /* FIXME: this should create a bitmap in the given size with the attributes
966 * (resolution etc.) of the graphics object */
967 GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT width, INT height,
968 GpGraphics* target, GpBitmap** bitmap)
973 if(!target || !bitmap)
974 return InvalidParameter;
977 FIXME("hacked stub\n");
979 ret = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat24bppRGB,
985 GpStatus WINGDIPAPI GdipCreateBitmapFromHICON(HICON hicon, GpBitmap** bitmap)
993 BitmapData lockeddata;
998 BITMAPINFOHEADER bih;
1003 TRACE("%p, %p\n", hicon, bitmap);
1005 if(!bitmap || !GetIconInfo(hicon, &iinfo))
1006 return InvalidParameter;
1008 /* get the size of the icon */
1009 ret = GetObjectA(iinfo.hbmColor ? iinfo.hbmColor : iinfo.hbmMask, sizeof(bm), &bm);
1011 DeleteObject(iinfo.hbmColor);
1012 DeleteObject(iinfo.hbmMask);
1013 return GenericError;
1019 height = abs(bm.bmHeight);
1020 else /* combined bitmap + mask */
1021 height = abs(bm.bmHeight) / 2;
1023 bits = HeapAlloc(GetProcessHeap(), 0, 4*width*height);
1025 DeleteObject(iinfo.hbmColor);
1026 DeleteObject(iinfo.hbmMask);
1030 stat = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat32bppARGB, NULL, bitmap);
1032 DeleteObject(iinfo.hbmColor);
1033 DeleteObject(iinfo.hbmMask);
1034 HeapFree(GetProcessHeap(), 0, bits);
1041 rect.Height = height;
1043 stat = GdipBitmapLockBits(*bitmap, &rect, ImageLockModeWrite, PixelFormat32bppARGB, &lockeddata);
1045 DeleteObject(iinfo.hbmColor);
1046 DeleteObject(iinfo.hbmMask);
1047 HeapFree(GetProcessHeap(), 0, bits);
1048 GdipDisposeImage((GpImage*)*bitmap);
1052 bih.biSize = sizeof(bih);
1053 bih.biWidth = width;
1054 bih.biHeight = -height;
1056 bih.biBitCount = 32;
1057 bih.biCompression = BI_RGB;
1058 bih.biSizeImage = 0;
1059 bih.biXPelsPerMeter = 0;
1060 bih.biYPelsPerMeter = 0;
1062 bih.biClrImportant = 0;
1064 screendc = GetDC(0);
1067 GetDIBits(screendc, iinfo.hbmColor, 0, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
1069 if (bm.bmBitsPixel == 32)
1073 /* If any pixel has a non-zero alpha, ignore hbmMask */
1075 for (x=0; x<width && !has_alpha; x++)
1076 for (y=0; y<height && !has_alpha; y++)
1077 if ((*src++ & 0xff000000) != 0)
1080 else has_alpha = FALSE;
1084 GetDIBits(screendc, iinfo.hbmMask, 0, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
1088 /* copy the image data to the Bitmap */
1090 dst_row = lockeddata.Scan0;
1091 for (y=0; y<height; y++)
1093 memcpy(dst_row, src, width*4);
1095 dst_row += lockeddata.Stride;
1102 /* read alpha data from the mask */
1104 GetDIBits(screendc, iinfo.hbmMask, 0, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
1106 GetDIBits(screendc, iinfo.hbmMask, height, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
1109 dst_row = lockeddata.Scan0;
1110 for (y=0; y<height; y++)
1112 dst = (DWORD*)dst_row;
1113 for (x=0; x<height; x++)
1115 DWORD src_value = *src++;
1119 *dst++ |= 0xff000000;
1121 dst_row += lockeddata.Stride;
1126 /* set constant alpha of 255 */
1128 for (y=0; y<height; y++)
1130 dst = (DWORD*)dst_row;
1131 for (x=0; x<height; x++)
1132 *dst++ |= 0xff000000;
1133 dst_row += lockeddata.Stride;
1138 ReleaseDC(0, screendc);
1140 DeleteObject(iinfo.hbmColor);
1141 DeleteObject(iinfo.hbmMask);
1143 GdipBitmapUnlockBits(*bitmap, &lockeddata);
1145 HeapFree(GetProcessHeap(), 0, bits);
1150 static void generate_halftone_palette(ARGB *entries, UINT count)
1152 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1155 for (i=0; i<8 && i<count; i++)
1157 entries[i] = 0xff000000;
1158 if (i&1) entries[i] |= 0x800000;
1159 if (i&2) entries[i] |= 0x8000;
1160 if (i&4) entries[i] |= 0x80;
1164 entries[i] = 0xffc0c0c0;
1166 for (i=9; i<16 && i<count; i++)
1168 entries[i] = 0xff000000;
1169 if (i&1) entries[i] |= 0xff0000;
1170 if (i&2) entries[i] |= 0xff00;
1171 if (i&4) entries[i] |= 0xff;
1174 for (i=16; i<40 && i<count; i++)
1179 for (i=40; i<256 && i<count; i++)
1181 entries[i] = 0xff000000;
1182 entries[i] |= halftone_values[(i-40)%6];
1183 entries[i] |= halftone_values[((i-40)/6)%6] << 8;
1184 entries[i] |= halftone_values[((i-40)/36)%6] << 16;
1188 static GpStatus get_screen_resolution(REAL *xres, REAL *yres)
1190 HDC screendc = GetDC(0);
1192 if (!screendc) return GenericError;
1194 *xres = (REAL)GetDeviceCaps(screendc, LOGPIXELSX);
1195 *yres = (REAL)GetDeviceCaps(screendc, LOGPIXELSY);
1197 ReleaseDC(0, screendc);
1202 GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
1203 PixelFormat format, BYTE* scan0, GpBitmap** bitmap)
1205 BITMAPINFOHEADER bmih;
1207 INT row_size, dib_stride;
1214 TRACE("%d %d %d %d %p %p\n", width, height, stride, format, scan0, bitmap);
1216 if (!bitmap) return InvalidParameter;
1218 if(width <= 0 || height <= 0 || (scan0 && (stride % 4))){
1220 return InvalidParameter;
1223 if(scan0 && !stride)
1224 return InvalidParameter;
1226 stat = get_screen_resolution(&xres, &yres);
1227 if (stat != Ok) return stat;
1229 row_size = (width * PIXELFORMATBPP(format)+7) / 8;
1230 dib_stride = (row_size + 3) & ~3;
1233 stride = dib_stride;
1235 bmih.biSize = sizeof(BITMAPINFOHEADER);
1236 bmih.biWidth = width;
1237 bmih.biHeight = -height;
1239 /* FIXME: use the rest of the data from format */
1240 bmih.biBitCount = PIXELFORMATBPP(format);
1241 bmih.biCompression = BI_RGB;
1242 bmih.biSizeImage = 0;
1243 bmih.biXPelsPerMeter = 0;
1244 bmih.biYPelsPerMeter = 0;
1246 bmih.biClrImportant = 0;
1248 hdc = CreateCompatibleDC(NULL);
1249 if (!hdc) return GenericError;
1251 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, (void**)&bits,
1256 if (!hbitmap) return GenericError;
1258 /* copy bits to the dib if necessary */
1259 /* FIXME: should reference the bits instead of copying them */
1261 for (i=0; i<height; i++)
1262 memcpy(bits+i*dib_stride, scan0+i*stride, row_size);
1264 *bitmap = GdipAlloc(sizeof(GpBitmap));
1267 DeleteObject(hbitmap);
1271 (*bitmap)->image.type = ImageTypeBitmap;
1272 memcpy(&(*bitmap)->image.format, &ImageFormatMemoryBMP, sizeof(GUID));
1273 (*bitmap)->image.flags = ImageFlagsNone;
1274 (*bitmap)->image.palette_flags = 0;
1275 (*bitmap)->image.palette_count = 0;
1276 (*bitmap)->image.palette_size = 0;
1277 (*bitmap)->image.palette_entries = NULL;
1278 (*bitmap)->image.xres = xres;
1279 (*bitmap)->image.yres = yres;
1280 (*bitmap)->width = width;
1281 (*bitmap)->height = height;
1282 (*bitmap)->format = format;
1283 (*bitmap)->image.picture = NULL;
1284 (*bitmap)->hbitmap = hbitmap;
1285 (*bitmap)->hdc = NULL;
1286 (*bitmap)->bits = bits;
1287 (*bitmap)->stride = dib_stride;
1289 if (format == PixelFormat1bppIndexed ||
1290 format == PixelFormat4bppIndexed ||
1291 format == PixelFormat8bppIndexed)
1293 (*bitmap)->image.palette_size = (*bitmap)->image.palette_count = 1 << PIXELFORMATBPP(format);
1294 (*bitmap)->image.palette_entries = GdipAlloc(sizeof(ARGB) * ((*bitmap)->image.palette_size));
1296 if (!(*bitmap)->image.palette_entries)
1298 GdipDisposeImage(&(*bitmap)->image);
1303 if (format == PixelFormat1bppIndexed)
1305 (*bitmap)->image.palette_flags = PaletteFlagsGrayScale;
1306 (*bitmap)->image.palette_entries[0] = 0xff000000;
1307 (*bitmap)->image.palette_entries[1] = 0xffffffff;
1311 if (format == PixelFormat8bppIndexed)
1312 (*bitmap)->image.palette_flags = PaletteFlagsHalftone;
1314 generate_halftone_palette((*bitmap)->image.palette_entries,
1315 (*bitmap)->image.palette_count);
1319 TRACE("<-- %p\n", *bitmap);
1324 GpStatus WINGDIPAPI GdipCreateBitmapFromStream(IStream* stream,
1329 TRACE("%p %p\n", stream, bitmap);
1331 stat = GdipLoadImageFromStream(stream, (GpImage**) bitmap);
1336 if((*bitmap)->image.type != ImageTypeBitmap){
1337 GdipDisposeImage(&(*bitmap)->image);
1339 return GenericError; /* FIXME: what error to return? */
1346 GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream* stream,
1349 TRACE("%p %p\n", stream, bitmap);
1351 return GdipCreateBitmapFromStream(stream, bitmap);
1354 GpStatus WINGDIPAPI GdipCreateCachedBitmap(GpBitmap *bitmap, GpGraphics *graphics,
1355 GpCachedBitmap **cachedbmp)
1359 TRACE("%p %p %p\n", bitmap, graphics, cachedbmp);
1361 if(!bitmap || !graphics || !cachedbmp)
1362 return InvalidParameter;
1364 *cachedbmp = GdipAlloc(sizeof(GpCachedBitmap));
1368 stat = GdipCloneImage(&(bitmap->image), &(*cachedbmp)->image);
1370 GdipFree(*cachedbmp);
1377 GpStatus WINGDIPAPI GdipCreateHICONFromBitmap(GpBitmap *bitmap, HICON *hicon)
1379 FIXME("(%p, %p)\n", bitmap, hicon);
1381 return NotImplemented;
1384 GpStatus WINGDIPAPI GdipDeleteCachedBitmap(GpCachedBitmap *cachedbmp)
1386 TRACE("%p\n", cachedbmp);
1389 return InvalidParameter;
1391 GdipDisposeImage(cachedbmp->image);
1392 GdipFree(cachedbmp);
1397 GpStatus WINGDIPAPI GdipDrawCachedBitmap(GpGraphics *graphics,
1398 GpCachedBitmap *cachedbmp, INT x, INT y)
1400 TRACE("%p %p %d %d\n", graphics, cachedbmp, x, y);
1402 if(!graphics || !cachedbmp)
1403 return InvalidParameter;
1405 return GdipDrawImage(graphics, cachedbmp->image, (REAL)x, (REAL)y);
1408 GpStatus WINGDIPAPI GdipEmfToWmfBits(HENHMETAFILE hemf, UINT cbData16,
1409 LPBYTE pData16, INT iMapMode, INT eFlags)
1411 FIXME("(%p, %d, %p, %d, %d): stub\n", hemf, cbData16, pData16, iMapMode, eFlags);
1412 return NotImplemented;
1415 GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
1417 TRACE("%p\n", image);
1420 return InvalidParameter;
1423 IPicture_Release(image->picture);
1424 if (image->type == ImageTypeBitmap)
1426 GdipFree(((GpBitmap*)image)->bitmapbits);
1427 DeleteDC(((GpBitmap*)image)->hdc);
1429 GdipFree(image->palette_entries);
1435 GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage *image, ImageItemData* item)
1439 TRACE("(%p,%p)\n", image, item);
1442 return InvalidParameter;
1445 FIXME("not implemented\n");
1447 return NotImplemented;
1450 GpStatus WINGDIPAPI GdipGetImageBounds(GpImage *image, GpRectF *srcRect,
1453 TRACE("%p %p %p\n", image, srcRect, srcUnit);
1455 if(!image || !srcRect || !srcUnit)
1456 return InvalidParameter;
1457 if(image->type == ImageTypeMetafile){
1458 *srcRect = ((GpMetafile*)image)->bounds;
1459 *srcUnit = ((GpMetafile*)image)->unit;
1461 else if(image->type == ImageTypeBitmap){
1462 srcRect->X = srcRect->Y = 0.0;
1463 srcRect->Width = (REAL) ((GpBitmap*)image)->width;
1464 srcRect->Height = (REAL) ((GpBitmap*)image)->height;
1465 *srcUnit = UnitPixel;
1468 srcRect->X = srcRect->Y = 0.0;
1469 srcRect->Width = ipicture_pixel_width(image->picture);
1470 srcRect->Height = ipicture_pixel_height(image->picture);
1471 *srcUnit = UnitPixel;
1474 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect->X, srcRect->Y,
1475 srcRect->Width, srcRect->Height, *srcUnit);
1480 GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
1483 TRACE("%p %p %p\n", image, width, height);
1485 if(!image || !height || !width)
1486 return InvalidParameter;
1488 if(image->type == ImageTypeMetafile){
1491 *height = convert_unit(hdc, ((GpMetafile*)image)->unit) *
1492 ((GpMetafile*)image)->bounds.Height;
1494 *width = convert_unit(hdc, ((GpMetafile*)image)->unit) *
1495 ((GpMetafile*)image)->bounds.Width;
1500 else if(image->type == ImageTypeBitmap){
1501 *height = ((GpBitmap*)image)->height;
1502 *width = ((GpBitmap*)image)->width;
1505 *height = ipicture_pixel_height(image->picture);
1506 *width = ipicture_pixel_width(image->picture);
1509 TRACE("returning (%f, %f)\n", *height, *width);
1513 GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image,
1514 GpGraphics **graphics)
1518 TRACE("%p %p\n", image, graphics);
1520 if(!image || !graphics)
1521 return InvalidParameter;
1523 if(image->type != ImageTypeBitmap){
1524 FIXME("not implemented for image type %d\n", image->type);
1525 return NotImplemented;
1528 hdc = ((GpBitmap*)image)->hdc;
1531 hdc = CreateCompatibleDC(0);
1532 SelectObject(hdc, ((GpBitmap*)image)->hbitmap);
1533 ((GpBitmap*)image)->hdc = hdc;
1536 return GdipCreateFromHDC(hdc, graphics);
1539 GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
1541 TRACE("%p %p\n", image, height);
1543 if(!image || !height)
1544 return InvalidParameter;
1546 if(image->type == ImageTypeMetafile){
1549 *height = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
1550 ((GpMetafile*)image)->bounds.Height);
1554 else if(image->type == ImageTypeBitmap)
1555 *height = ((GpBitmap*)image)->height;
1557 *height = ipicture_pixel_height(image->picture);
1559 TRACE("returning %d\n", *height);
1564 GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res)
1567 return InvalidParameter;
1571 TRACE("(%p) <-- %0.2f\n", image, *res);
1576 GpStatus WINGDIPAPI GdipGetImagePaletteSize(GpImage *image, INT *size)
1578 TRACE("%p %p\n", image, size);
1581 return InvalidParameter;
1583 if (image->palette_count == 0)
1584 *size = sizeof(ColorPalette);
1586 *size = sizeof(UINT)*2 + sizeof(ARGB)*image->palette_count;
1588 TRACE("<-- %u\n", *size);
1593 /* FIXME: test this function for non-bitmap types */
1594 GpStatus WINGDIPAPI GdipGetImagePixelFormat(GpImage *image, PixelFormat *format)
1596 TRACE("%p %p\n", image, format);
1598 if(!image || !format)
1599 return InvalidParameter;
1601 if(image->type != ImageTypeBitmap)
1602 *format = PixelFormat24bppRGB;
1604 *format = ((GpBitmap*) image)->format;
1609 GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage *image, GUID *format)
1611 if(!image || !format)
1612 return InvalidParameter;
1614 memcpy(format, &image->format, sizeof(GUID));
1619 GpStatus WINGDIPAPI GdipGetImageType(GpImage *image, ImageType *type)
1621 TRACE("%p %p\n", image, type);
1624 return InvalidParameter;
1626 *type = image->type;
1631 GpStatus WINGDIPAPI GdipGetImageVerticalResolution(GpImage *image, REAL *res)
1634 return InvalidParameter;
1638 TRACE("(%p) <-- %0.2f\n", image, *res);
1643 GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
1645 TRACE("%p %p\n", image, width);
1647 if(!image || !width)
1648 return InvalidParameter;
1650 if(image->type == ImageTypeMetafile){
1653 *width = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
1654 ((GpMetafile*)image)->bounds.Width);
1658 else if(image->type == ImageTypeBitmap)
1659 *width = ((GpBitmap*)image)->width;
1661 *width = ipicture_pixel_width(image->picture);
1663 TRACE("returning %d\n", *width);
1668 GpStatus WINGDIPAPI GdipGetMetafileHeaderFromMetafile(GpMetafile * metafile,
1669 MetafileHeader * header)
1673 if(!metafile || !header)
1674 return InvalidParameter;
1677 FIXME("not implemented\n");
1682 GpStatus WINGDIPAPI GdipGetAllPropertyItems(GpImage *image, UINT size,
1683 UINT num, PropertyItem* items)
1688 FIXME("not implemented\n");
1690 return InvalidParameter;
1693 GpStatus WINGDIPAPI GdipGetPropertyCount(GpImage *image, UINT* num)
1698 FIXME("not implemented\n");
1700 return InvalidParameter;
1703 GpStatus WINGDIPAPI GdipGetPropertyIdList(GpImage *image, UINT num, PROPID* list)
1708 FIXME("not implemented\n");
1710 return InvalidParameter;
1713 GpStatus WINGDIPAPI GdipGetPropertyItem(GpImage *image, PROPID id, UINT size,
1714 PropertyItem* buffer)
1719 FIXME("not implemented\n");
1721 return InvalidParameter;
1724 GpStatus WINGDIPAPI GdipGetPropertyItemSize(GpImage *image, PROPID pid,
1729 TRACE("%p %x %p\n", image, pid, size);
1732 return InvalidParameter;
1735 FIXME("not implemented\n");
1737 return NotImplemented;
1740 GpStatus WINGDIPAPI GdipGetPropertySize(GpImage *image, UINT* size, UINT* num)
1744 TRACE("(%p,%p,%p)\n", image, size, num);
1747 FIXME("not implemented\n");
1749 return InvalidParameter;
1752 struct image_format_dimension
1755 const GUID *dimension;
1758 struct image_format_dimension image_format_dimensions[] =
1760 {&ImageFormatGIF, &FrameDimensionTime},
1761 {&ImageFormatIcon, &FrameDimensionResolution},
1765 GpStatus WINGDIPAPI GdipImageGetFrameCount(GpImage *image,
1766 GDIPCONST GUID* dimensionID, UINT* count)
1770 TRACE("(%p,%s,%p)\n", image, debugstr_guid(dimensionID), count);
1772 if(!image || !dimensionID || !count)
1773 return InvalidParameter;
1776 FIXME("not implemented\n");
1778 return NotImplemented;
1781 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsCount(GpImage *image,
1784 /* Native gdiplus 1.1 does not yet support multiple frame dimensions. */
1786 if(!image || !count)
1787 return InvalidParameter;
1794 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsList(GpImage* image,
1795 GUID* dimensionIDs, UINT count)
1798 const GUID *result=NULL;
1800 TRACE("(%p,%p,%u)\n", image, dimensionIDs, count);
1802 if(!image || !dimensionIDs || count != 1)
1803 return InvalidParameter;
1805 for (i=0; image_format_dimensions[i].format; i++)
1807 if (IsEqualGUID(&image->format, image_format_dimensions[i].format))
1809 result = image_format_dimensions[i].dimension;
1815 result = &FrameDimensionPage;
1817 memcpy(dimensionIDs, result, sizeof(GUID));
1822 GpStatus WINGDIPAPI GdipImageSelectActiveFrame(GpImage *image,
1823 GDIPCONST GUID* dimensionID, UINT frameidx)
1827 if(!image || !dimensionID)
1828 return InvalidParameter;
1831 FIXME("not implemented\n");
1836 GpStatus WINGDIPAPI GdipLoadImageFromFile(GDIPCONST WCHAR* filename,
1842 TRACE("(%s) %p\n", debugstr_w(filename), image);
1844 if (!filename || !image)
1845 return InvalidParameter;
1847 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
1852 stat = GdipLoadImageFromStream(stream, image);
1854 IStream_Release(stream);
1859 /* FIXME: no icm handling */
1860 GpStatus WINGDIPAPI GdipLoadImageFromFileICM(GDIPCONST WCHAR* filename,GpImage **image)
1862 TRACE("(%s) %p\n", debugstr_w(filename), image);
1864 return GdipLoadImageFromFile(filename, image);
1867 static const WICPixelFormatGUID *wic_pixel_formats[] = {
1868 &GUID_WICPixelFormat16bppBGR555,
1869 &GUID_WICPixelFormat24bppBGR,
1870 &GUID_WICPixelFormat32bppBGR,
1871 &GUID_WICPixelFormat32bppBGRA,
1872 &GUID_WICPixelFormat32bppPBGRA,
1876 static const PixelFormat wic_gdip_formats[] = {
1877 PixelFormat16bppRGB555,
1878 PixelFormat24bppRGB,
1879 PixelFormat32bppRGB,
1880 PixelFormat32bppARGB,
1881 PixelFormat32bppPARGB,
1884 static GpStatus decode_image_wic(IStream* stream, REFCLSID clsid, GpImage **image)
1889 IWICBitmapDecoder *decoder;
1890 IWICBitmapFrameDecode *frame;
1891 IWICBitmapSource *source=NULL;
1892 WICPixelFormatGUID wic_format;
1893 PixelFormat gdip_format=0;
1896 BitmapData lockeddata;
1900 initresult = CoInitialize(NULL);
1902 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER,
1903 &IID_IWICBitmapDecoder, (void**)&decoder);
1904 if (FAILED(hr)) goto end;
1906 hr = IWICBitmapDecoder_Initialize(decoder, (IStream*)stream, WICDecodeMetadataCacheOnLoad);
1908 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
1910 if (SUCCEEDED(hr)) /* got frame */
1912 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &wic_format);
1916 for (i=0; wic_pixel_formats[i]; i++)
1918 if (IsEqualGUID(&wic_format, wic_pixel_formats[i]))
1920 source = (IWICBitmapSource*)frame;
1921 IWICBitmapSource_AddRef(source);
1922 gdip_format = wic_gdip_formats[i];
1928 /* unknown format; fall back on 32bppARGB */
1929 hr = WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA, (IWICBitmapSource*)frame, &source);
1930 gdip_format = PixelFormat32bppARGB;
1934 if (SUCCEEDED(hr)) /* got source */
1936 hr = IWICBitmapSource_GetSize(source, &width, &height);
1939 status = GdipCreateBitmapFromScan0(width, height, 0, gdip_format,
1942 if (SUCCEEDED(hr) && status == Ok) /* created bitmap */
1944 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeWrite,
1945 gdip_format, &lockeddata);
1946 if (status == Ok) /* locked bitmap */
1951 for (i=0; i<height; i++)
1954 hr = IWICBitmapSource_CopyPixels(source, &wrc, abs(lockeddata.Stride),
1955 abs(lockeddata.Stride), (BYTE*)lockeddata.Scan0+lockeddata.Stride*i);
1956 if (FAILED(hr)) break;
1959 GdipBitmapUnlockBits(bitmap, &lockeddata);
1962 if (SUCCEEDED(hr) && status == Ok)
1963 *image = (GpImage*)bitmap;
1967 GdipDisposeImage((GpImage*)bitmap);
1971 IWICBitmapSource_Release(source);
1974 IWICBitmapFrameDecode_Release(frame);
1977 IWICBitmapDecoder_Release(decoder);
1980 if (SUCCEEDED(initresult)) CoUninitialize();
1982 if (FAILED(hr) && status == Ok) status = hresult_to_status(hr);
1987 static GpStatus decode_image_icon(IStream* stream, REFCLSID clsid, GpImage **image)
1989 return decode_image_wic(stream, &CLSID_WICIcoDecoder, image);
1992 static GpStatus decode_image_bmp(IStream* stream, REFCLSID clsid, GpImage **image)
1997 status = decode_image_wic(stream, &CLSID_WICBmpDecoder, image);
1999 bitmap = (GpBitmap*)*image;
2001 if (status == Ok && bitmap->format == PixelFormat32bppARGB)
2003 /* WIC supports bmp files with alpha, but gdiplus does not */
2004 bitmap->format = PixelFormat32bppRGB;
2010 static GpStatus decode_image_jpeg(IStream* stream, REFCLSID clsid, GpImage **image)
2012 return decode_image_wic(stream, &CLSID_WICJpegDecoder, image);
2015 static GpStatus decode_image_png(IStream* stream, REFCLSID clsid, GpImage **image)
2017 return decode_image_wic(stream, &CLSID_WICPngDecoder, image);
2020 static GpStatus decode_image_gif(IStream* stream, REFCLSID clsid, GpImage **image)
2022 return decode_image_wic(stream, &CLSID_WICGifDecoder, image);
2025 static GpStatus decode_image_olepicture_metafile(IStream* stream, REFCLSID clsid, GpImage **image)
2029 TRACE("%p %p\n", stream, image);
2031 if(!stream || !image)
2032 return InvalidParameter;
2034 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
2035 (LPVOID*) &pic) != S_OK){
2036 TRACE("Could not load picture\n");
2037 return GenericError;
2040 /* FIXME: missing initialization code */
2041 *image = GdipAlloc(sizeof(GpMetafile));
2042 if(!*image) return OutOfMemory;
2043 (*image)->type = ImageTypeMetafile;
2044 (*image)->picture = pic;
2045 (*image)->flags = ImageFlagsNone;
2046 (*image)->palette_flags = 0;
2047 (*image)->palette_count = 0;
2048 (*image)->palette_size = 0;
2049 (*image)->palette_entries = NULL;
2051 TRACE("<-- %p\n", *image);
2056 typedef GpStatus (*encode_image_func)(GpImage *image, IStream* stream,
2057 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params);
2059 typedef GpStatus (*decode_image_func)(IStream *stream, REFCLSID clsid, GpImage** image);
2061 typedef struct image_codec {
2062 ImageCodecInfo info;
2063 encode_image_func encode_func;
2064 decode_image_func decode_func;
2078 static const struct image_codec codecs[NUM_CODECS];
2080 static GpStatus get_decoder_info(IStream* stream, const struct image_codec **result)
2088 /* seek to the start of the stream */
2090 hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL);
2091 if (FAILED(hr)) return hresult_to_status(hr);
2093 /* read the first 8 bytes */
2094 /* FIXME: This assumes all codecs have one signature <= 8 bytes in length */
2095 hr = IStream_Read(stream, signature, 8, &bytesread);
2096 if (FAILED(hr)) return hresult_to_status(hr);
2097 if (hr == S_FALSE || bytesread == 0) return GenericError;
2099 for (i = 0; i < NUM_CODECS; i++) {
2100 if ((codecs[i].info.Flags & ImageCodecFlagsDecoder) &&
2101 bytesread >= codecs[i].info.SigSize)
2103 for (j=0; j<codecs[i].info.SigSize; j++)
2104 if ((signature[j] & codecs[i].info.SigMask[j]) != codecs[i].info.SigPattern[j])
2106 if (j == codecs[i].info.SigSize)
2108 *result = &codecs[i];
2114 TRACE("no match for %i byte signature %x %x %x %x %x %x %x %x\n", bytesread,
2115 signature[0],signature[1],signature[2],signature[3],
2116 signature[4],signature[5],signature[6],signature[7]);
2118 return GenericError;
2121 GpStatus WINGDIPAPI GdipLoadImageFromStream(IStream* stream, GpImage **image)
2126 const struct image_codec *codec=NULL;
2128 /* choose an appropriate image decoder */
2129 stat = get_decoder_info(stream, &codec);
2130 if (stat != Ok) return stat;
2132 /* seek to the start of the stream */
2134 hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL);
2135 if (FAILED(hr)) return hresult_to_status(hr);
2137 /* call on the image decoder to do the real work */
2138 stat = codec->decode_func(stream, &codec->info.Clsid, image);
2140 /* take note of the original data format */
2143 memcpy(&(*image)->format, &codec->info.FormatID, sizeof(GUID));
2150 GpStatus WINGDIPAPI GdipLoadImageFromStreamICM(IStream* stream, GpImage **image)
2152 TRACE("%p %p\n", stream, image);
2154 return GdipLoadImageFromStream(stream, image);
2157 GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
2161 TRACE("(%p,%u)\n", image, propId);
2164 return InvalidParameter;
2167 FIXME("not implemented\n");
2169 return NotImplemented;
2172 GpStatus WINGDIPAPI GdipSetPropertyItem(GpImage *image, GDIPCONST PropertyItem* item)
2176 TRACE("(%p,%p)\n", image, item);
2179 FIXME("not implemented\n");
2181 return NotImplemented;
2184 GpStatus WINGDIPAPI GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
2185 GDIPCONST CLSID *clsidEncoder,
2186 GDIPCONST EncoderParameters *encoderParams)
2191 TRACE("%p (%s) %p %p\n", image, debugstr_w(filename), clsidEncoder, encoderParams);
2193 if (!image || !filename|| !clsidEncoder)
2194 return InvalidParameter;
2196 stat = GdipCreateStreamOnFile(filename, GENERIC_WRITE, &stream);
2198 return GenericError;
2200 stat = GdipSaveImageToStream(image, stream, clsidEncoder, encoderParams);
2202 IStream_Release(stream);
2206 /*************************************************************************
2207 * Encoding functions -
2208 * These functions encode an image in different image file formats.
2210 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
2211 #define BITMAP_FORMAT_JPEG 0xd8ff
2212 #define BITMAP_FORMAT_GIF 0x4947
2213 #define BITMAP_FORMAT_PNG 0x5089
2214 #define BITMAP_FORMAT_APM 0xcdd7
2216 static GpStatus encode_image_WIC(GpImage *image, IStream* stream,
2217 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
2221 IWICBitmapEncoder *encoder;
2222 IWICBitmapFrameEncode *frameencode;
2223 IPropertyBag2 *encoderoptions;
2226 PixelFormat gdipformat=0;
2227 WICPixelFormatGUID wicformat;
2229 BitmapData lockeddata;
2233 if (image->type != ImageTypeBitmap)
2234 return GenericError;
2236 bitmap = (GpBitmap*)image;
2238 GdipGetImageWidth(image, &width);
2239 GdipGetImageHeight(image, &height);
2246 initresult = CoInitialize(NULL);
2248 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER,
2249 &IID_IWICBitmapEncoder, (void**)&encoder);
2252 if (SUCCEEDED(initresult)) CoUninitialize();
2253 return hresult_to_status(hr);
2256 hr = IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache);
2260 hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frameencode, &encoderoptions);
2263 if (SUCCEEDED(hr)) /* created frame */
2265 hr = IWICBitmapFrameEncode_Initialize(frameencode, encoderoptions);
2268 hr = IWICBitmapFrameEncode_SetSize(frameencode, width, height);
2271 /* FIXME: use the resolution from the image */
2272 hr = IWICBitmapFrameEncode_SetResolution(frameencode, 96.0, 96.0);
2276 for (i=0; wic_pixel_formats[i]; i++)
2278 if (wic_gdip_formats[i] == bitmap->format)
2281 if (wic_pixel_formats[i])
2282 memcpy(&wicformat, wic_pixel_formats[i], sizeof(GUID));
2284 memcpy(&wicformat, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID));
2286 hr = IWICBitmapFrameEncode_SetPixelFormat(frameencode, &wicformat);
2288 for (i=0; wic_pixel_formats[i]; i++)
2290 if (IsEqualGUID(&wicformat, wic_pixel_formats[i]))
2293 if (wic_pixel_formats[i])
2294 gdipformat = wic_gdip_formats[i];
2297 ERR("cannot provide pixel format %s\n", debugstr_guid(&wicformat));
2304 stat = GdipBitmapLockBits(bitmap, &rc, ImageLockModeRead, gdipformat,
2309 UINT row_size = (lockeddata.Width * PIXELFORMATBPP(gdipformat) + 7)/8;
2312 /* write one row at a time in case stride is negative */
2313 row = lockeddata.Scan0;
2314 for (i=0; i<lockeddata.Height; i++)
2316 hr = IWICBitmapFrameEncode_WritePixels(frameencode, 1, row_size, row_size, row);
2317 if (FAILED(hr)) break;
2318 row += lockeddata.Stride;
2321 GdipBitmapUnlockBits(bitmap, &lockeddata);
2328 hr = IWICBitmapFrameEncode_Commit(frameencode);
2330 IWICBitmapFrameEncode_Release(frameencode);
2331 IPropertyBag2_Release(encoderoptions);
2335 hr = IWICBitmapEncoder_Commit(encoder);
2337 IWICBitmapEncoder_Release(encoder);
2339 if (SUCCEEDED(initresult)) CoUninitialize();
2341 return hresult_to_status(hr);
2344 static GpStatus encode_image_BMP(GpImage *image, IStream* stream,
2345 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
2347 return encode_image_WIC(image, stream, &CLSID_WICBmpEncoder, params);
2350 static GpStatus encode_image_png(GpImage *image, IStream* stream,
2351 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
2353 return encode_image_WIC(image, stream, &CLSID_WICPngEncoder, params);
2356 /*****************************************************************************
2357 * GdipSaveImageToStream [GDIPLUS.@]
2359 GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
2360 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
2363 encode_image_func encode_image;
2366 TRACE("%p %p %p %p\n", image, stream, clsid, params);
2368 if(!image || !stream)
2369 return InvalidParameter;
2371 /* select correct encoder */
2372 encode_image = NULL;
2373 for (i = 0; i < NUM_CODECS; i++) {
2374 if ((codecs[i].info.Flags & ImageCodecFlagsEncoder) &&
2375 IsEqualCLSID(clsid, &codecs[i].info.Clsid))
2376 encode_image = codecs[i].encode_func;
2378 if (encode_image == NULL)
2379 return UnknownImageFormat;
2381 stat = encode_image(image, stream, clsid, params);
2386 /*****************************************************************************
2387 * GdipGetImagePalette [GDIPLUS.@]
2389 GpStatus WINGDIPAPI GdipGetImagePalette(GpImage *image, ColorPalette *palette, INT size)
2391 TRACE("(%p,%p,%i)\n", image, palette, size);
2393 if (!image || !palette)
2394 return InvalidParameter;
2396 if (size < (sizeof(UINT)*2+sizeof(ARGB)*image->palette_count))
2398 TRACE("<-- InsufficientBuffer\n");
2399 return InsufficientBuffer;
2402 palette->Flags = image->palette_flags;
2403 palette->Count = image->palette_count;
2404 memcpy(palette->Entries, image->palette_entries, sizeof(ARGB)*image->palette_count);
2409 /*****************************************************************************
2410 * GdipSetImagePalette [GDIPLUS.@]
2412 GpStatus WINGDIPAPI GdipSetImagePalette(GpImage *image,
2413 GDIPCONST ColorPalette *palette)
2415 TRACE("(%p,%p)\n", image, palette);
2417 if(!image || !palette || palette->Count > 256)
2418 return InvalidParameter;
2420 if (palette->Count > image->palette_size)
2424 new_palette = GdipAlloc(sizeof(ARGB) * palette->Count);
2425 if (!new_palette) return OutOfMemory;
2427 GdipFree(image->palette_entries);
2428 image->palette_entries = new_palette;
2429 image->palette_size = palette->Count;
2432 image->palette_flags = palette->Flags;
2433 image->palette_count = palette->Count;
2434 memcpy(image->palette_entries, palette->Entries, sizeof(ARGB)*palette->Count);
2439 /*************************************************************************
2441 * Structures that represent which formats we support for encoding.
2444 /* ImageCodecInfo creation routines taken from libgdiplus */
2445 static const WCHAR bmp_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
2446 static const WCHAR bmp_extension[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
2447 static const WCHAR bmp_mimetype[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
2448 static const WCHAR bmp_format[] = {'B', 'M', 'P', 0}; /* BMP */
2449 static const BYTE bmp_sig_pattern[] = { 0x42, 0x4D };
2450 static const BYTE bmp_sig_mask[] = { 0xFF, 0xFF };
2452 static const WCHAR jpeg_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'J','P','E','G', 0};
2453 static const WCHAR jpeg_extension[] = {'*','.','J','P','G',';', '*','.','J','P','E','G',';', '*','.','J','P','E',';', '*','.','J','F','I','F',0};
2454 static const WCHAR jpeg_mimetype[] = {'i','m','a','g','e','/','j','p','e','g', 0};
2455 static const WCHAR jpeg_format[] = {'J','P','E','G',0};
2456 static const BYTE jpeg_sig_pattern[] = { 0xFF, 0xD8 };
2457 static const BYTE jpeg_sig_mask[] = { 0xFF, 0xFF };
2459 static const WCHAR gif_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'G','I','F', 0};
2460 static const WCHAR gif_extension[] = {'*','.','G','I','F',0};
2461 static const WCHAR gif_mimetype[] = {'i','m','a','g','e','/','g','i','f', 0};
2462 static const WCHAR gif_format[] = {'G','I','F',0};
2463 static const BYTE gif_sig_pattern[4] = "GIF8";
2464 static const BYTE gif_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF };
2466 static const WCHAR emf_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'E','M','F', 0};
2467 static const WCHAR emf_extension[] = {'*','.','E','M','F',0};
2468 static const WCHAR emf_mimetype[] = {'i','m','a','g','e','/','x','-','e','m','f', 0};
2469 static const WCHAR emf_format[] = {'E','M','F',0};
2470 static const BYTE emf_sig_pattern[] = { 0x01, 0x00, 0x00, 0x00 };
2471 static const BYTE emf_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF };
2473 static const WCHAR wmf_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'W','M','F', 0};
2474 static const WCHAR wmf_extension[] = {'*','.','W','M','F',0};
2475 static const WCHAR wmf_mimetype[] = {'i','m','a','g','e','/','x','-','w','m','f', 0};
2476 static const WCHAR wmf_format[] = {'W','M','F',0};
2477 static const BYTE wmf_sig_pattern[] = { 0xd7, 0xcd };
2478 static const BYTE wmf_sig_mask[] = { 0xFF, 0xFF };
2480 static const WCHAR png_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'P','N','G', 0};
2481 static const WCHAR png_extension[] = {'*','.','P','N','G',0};
2482 static const WCHAR png_mimetype[] = {'i','m','a','g','e','/','p','n','g', 0};
2483 static const WCHAR png_format[] = {'P','N','G',0};
2484 static const BYTE png_sig_pattern[] = { 137, 80, 78, 71, 13, 10, 26, 10, };
2485 static const BYTE png_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
2487 static const WCHAR ico_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'I','C','O', 0};
2488 static const WCHAR ico_extension[] = {'*','.','I','C','O',0};
2489 static const WCHAR ico_mimetype[] = {'i','m','a','g','e','/','x','-','i','c','o','n', 0};
2490 static const WCHAR ico_format[] = {'I','C','O',0};
2491 static const BYTE ico_sig_pattern[] = { 0x00, 0x00, 0x01, 0x00 };
2492 static const BYTE ico_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF };
2494 static const struct image_codec codecs[NUM_CODECS] = {
2497 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2498 /* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2499 /* CodecName */ bmp_codecname,
2501 /* FormatDescription */ bmp_format,
2502 /* FilenameExtension */ bmp_extension,
2503 /* MimeType */ bmp_mimetype,
2504 /* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2508 /* SigPattern */ bmp_sig_pattern,
2509 /* SigMask */ bmp_sig_mask,
2516 /* Clsid */ { 0x557cf401, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2517 /* FormatID */ { 0xb96b3caeU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2518 /* CodecName */ jpeg_codecname,
2520 /* FormatDescription */ jpeg_format,
2521 /* FilenameExtension */ jpeg_extension,
2522 /* MimeType */ jpeg_mimetype,
2523 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2527 /* SigPattern */ jpeg_sig_pattern,
2528 /* SigMask */ jpeg_sig_mask,
2535 /* Clsid */ { 0x557cf402, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2536 /* FormatID */ { 0xb96b3cb0U, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2537 /* CodecName */ gif_codecname,
2539 /* FormatDescription */ gif_format,
2540 /* FilenameExtension */ gif_extension,
2541 /* MimeType */ gif_mimetype,
2542 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2546 /* SigPattern */ gif_sig_pattern,
2547 /* SigMask */ gif_sig_mask,
2554 /* Clsid */ { 0x557cf403, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2555 /* FormatID */ { 0xb96b3cacU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2556 /* CodecName */ emf_codecname,
2558 /* FormatDescription */ emf_format,
2559 /* FilenameExtension */ emf_extension,
2560 /* MimeType */ emf_mimetype,
2561 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportVector | ImageCodecFlagsBuiltin,
2565 /* SigPattern */ emf_sig_pattern,
2566 /* SigMask */ emf_sig_mask,
2569 decode_image_olepicture_metafile
2573 /* Clsid */ { 0x557cf404, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2574 /* FormatID */ { 0xb96b3cadU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2575 /* CodecName */ wmf_codecname,
2577 /* FormatDescription */ wmf_format,
2578 /* FilenameExtension */ wmf_extension,
2579 /* MimeType */ wmf_mimetype,
2580 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportVector | ImageCodecFlagsBuiltin,
2584 /* SigPattern */ wmf_sig_pattern,
2585 /* SigMask */ wmf_sig_mask,
2588 decode_image_olepicture_metafile
2592 /* Clsid */ { 0x557cf406, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2593 /* FormatID */ { 0xb96b3cafU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2594 /* CodecName */ png_codecname,
2596 /* FormatDescription */ png_format,
2597 /* FilenameExtension */ png_extension,
2598 /* MimeType */ png_mimetype,
2599 /* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2603 /* SigPattern */ png_sig_pattern,
2604 /* SigMask */ png_sig_mask,
2611 /* Clsid */ { 0x557cf407, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2612 /* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2613 /* CodecName */ ico_codecname,
2615 /* FormatDescription */ ico_format,
2616 /* FilenameExtension */ ico_extension,
2617 /* MimeType */ ico_mimetype,
2618 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2622 /* SigPattern */ ico_sig_pattern,
2623 /* SigMask */ ico_sig_mask,
2630 /*****************************************************************************
2631 * GdipGetImageDecodersSize [GDIPLUS.@]
2633 GpStatus WINGDIPAPI GdipGetImageDecodersSize(UINT *numDecoders, UINT *size)
2635 int decoder_count=0;
2637 TRACE("%p %p\n", numDecoders, size);
2639 if (!numDecoders || !size)
2640 return InvalidParameter;
2642 for (i=0; i<NUM_CODECS; i++)
2644 if (codecs[i].info.Flags & ImageCodecFlagsDecoder)
2648 *numDecoders = decoder_count;
2649 *size = decoder_count * sizeof(ImageCodecInfo);
2654 /*****************************************************************************
2655 * GdipGetImageDecoders [GDIPLUS.@]
2657 GpStatus WINGDIPAPI GdipGetImageDecoders(UINT numDecoders, UINT size, ImageCodecInfo *decoders)
2659 int i, decoder_count=0;
2660 TRACE("%u %u %p\n", numDecoders, size, decoders);
2663 size != numDecoders * sizeof(ImageCodecInfo))
2664 return GenericError;
2666 for (i=0; i<NUM_CODECS; i++)
2668 if (codecs[i].info.Flags & ImageCodecFlagsDecoder)
2670 if (decoder_count == numDecoders) return GenericError;
2671 memcpy(&decoders[decoder_count], &codecs[i].info, sizeof(ImageCodecInfo));
2676 if (decoder_count < numDecoders) return GenericError;
2681 /*****************************************************************************
2682 * GdipGetImageEncodersSize [GDIPLUS.@]
2684 GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size)
2686 int encoder_count=0;
2688 TRACE("%p %p\n", numEncoders, size);
2690 if (!numEncoders || !size)
2691 return InvalidParameter;
2693 for (i=0; i<NUM_CODECS; i++)
2695 if (codecs[i].info.Flags & ImageCodecFlagsEncoder)
2699 *numEncoders = encoder_count;
2700 *size = encoder_count * sizeof(ImageCodecInfo);
2705 /*****************************************************************************
2706 * GdipGetImageEncoders [GDIPLUS.@]
2708 GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders)
2710 int i, encoder_count=0;
2711 TRACE("%u %u %p\n", numEncoders, size, encoders);
2714 size != numEncoders * sizeof(ImageCodecInfo))
2715 return GenericError;
2717 for (i=0; i<NUM_CODECS; i++)
2719 if (codecs[i].info.Flags & ImageCodecFlagsEncoder)
2721 if (encoder_count == numEncoders) return GenericError;
2722 memcpy(&encoders[encoder_count], &codecs[i].info, sizeof(ImageCodecInfo));
2727 if (encoder_count < numEncoders) return GenericError;
2732 /*****************************************************************************
2733 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
2735 GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBitmap** bitmap)
2740 BitmapData lockeddata;
2743 TRACE("%p %p %p\n", hbm, hpal, bitmap);
2746 return InvalidParameter;
2748 /* TODO: Support for device-dependent bitmaps */
2750 FIXME("no support for device-dependent bitmaps\n");
2751 return NotImplemented;
2754 if (GetObjectA(hbm, sizeof(bm), &bm) != sizeof(bm))
2755 return InvalidParameter;
2757 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
2758 switch(bm.bmBitsPixel) {
2760 format = PixelFormat1bppIndexed;
2763 format = PixelFormat4bppIndexed;
2766 format = PixelFormat8bppIndexed;
2769 format = PixelFormat24bppRGB;
2772 format = PixelFormat32bppRGB;
2775 format = PixelFormat48bppRGB;
2778 FIXME("don't know how to handle %d bpp\n", bm.bmBitsPixel);
2779 return InvalidParameter;
2782 retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, 0,
2783 format, NULL, bitmap);
2787 retval = GdipBitmapLockBits(*bitmap, NULL, ImageLockModeWrite,
2788 format, &lockeddata);
2793 for (y=0; y<bm.bmHeight; y++)
2795 memcpy((BYTE*)lockeddata.Scan0+lockeddata.Stride*y,
2796 (BYTE*)bm.bmBits+bm.bmWidthBytes*(bm.bmHeight-1-y),
2805 INT src_height, dst_stride;
2808 hdc = CreateCompatibleDC(NULL);
2809 oldhbm = SelectObject(hdc, hbm);
2811 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
2815 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2816 pbmi->bmiHeader.biBitCount = 0;
2818 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
2820 src_height = abs(pbmi->bmiHeader.biHeight);
2822 if (pbmi->bmiHeader.biHeight > 0)
2824 dst_bits = (BYTE*)lockeddata.Scan0+lockeddata.Stride*(src_height-1);
2825 dst_stride = -lockeddata.Stride;
2829 dst_bits = lockeddata.Scan0;
2830 dst_stride = lockeddata.Stride;
2833 for (y=0; y<src_height; y++)
2835 GetDIBits(hdc, hbm, y, 1, dst_bits+dst_stride*y,
2836 pbmi, DIB_RGB_COLORS);
2842 retval = OutOfMemory;
2844 SelectObject(hdc, oldhbm);
2848 GdipBitmapUnlockBits(*bitmap, &lockeddata);
2855 GpStatus WINGDIPAPI GdipDeleteEffect(CGpEffect *effect)
2857 FIXME("(%p): stub\n", effect);
2858 /* note: According to Jose Roca's GDI+ Docs, this is not implemented
2859 * in Windows's gdiplus */
2860 return NotImplemented;
2863 /*****************************************************************************
2864 * GdipSetEffectParameters [GDIPLUS.@]
2866 GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect *effect,
2867 const VOID *params, const UINT size)
2871 TRACE("(%p,%p,%u)\n", effect, params, size);
2874 FIXME("not implemented\n");
2876 return NotImplemented;
2879 /*****************************************************************************
2880 * GdipGetImageFlags [GDIPLUS.@]
2882 GpStatus WINGDIPAPI GdipGetImageFlags(GpImage *image, UINT *flags)
2884 TRACE("%p %p\n", image, flags);
2886 if(!image || !flags)
2887 return InvalidParameter;
2889 *flags = image->flags;
2894 GpStatus WINGDIPAPI GdipTestControl(GpTestControlEnum control, void *param)
2896 TRACE("(%d, %p)\n", control, param);
2899 case TestControlForceBilinear:
2901 FIXME("TestControlForceBilinear not handled\n");
2903 case TestControlNoICM:
2905 FIXME("TestControlNoICM not handled\n");
2907 case TestControlGetBuildNumber:
2908 *((DWORD*)param) = 3102;
2915 GpStatus WINGDIPAPI GdipRecordMetafileFileName(GDIPCONST WCHAR* fileName,
2916 HDC hdc, EmfType type, GDIPCONST GpRectF *pFrameRect,
2917 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc,
2918 GpMetafile **metafile)
2920 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
2921 frameUnit, debugstr_w(desc), metafile);
2923 return NotImplemented;
2926 GpStatus WINGDIPAPI GdipRecordMetafileFileNameI(GDIPCONST WCHAR* fileName, HDC hdc, EmfType type,
2927 GDIPCONST GpRect *pFrameRect, MetafileFrameUnit frameUnit,
2928 GDIPCONST WCHAR *desc, GpMetafile **metafile)
2930 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
2931 frameUnit, debugstr_w(desc), metafile);
2933 return NotImplemented;
2936 GpStatus WINGDIPAPI GdipImageForceValidation(GpImage *image)
2938 FIXME("%p\n", image);
2943 /*****************************************************************************
2944 * GdipGetImageThumbnail [GDIPLUS.@]
2946 GpStatus WINGDIPAPI GdipGetImageThumbnail(GpImage *image, UINT width, UINT height,
2947 GpImage **ret_image, GetThumbnailImageAbort cb,
2950 FIXME("(%p %u %u %p %p %p) stub\n",
2951 image, width, height, ret_image, cb, cb_data);
2952 return NotImplemented;
2955 /*****************************************************************************
2956 * GdipImageRotateFlip [GDIPLUS.@]
2958 GpStatus WINGDIPAPI GdipImageRotateFlip(GpImage *image, RotateFlipType type)
2960 FIXME("(%p %u) stub\n", image, type);
2961 return NotImplemented;