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_1bppIndexed(BYTE *index, const BYTE *row, UINT x)
99 *index = (row[x/8]>>(7-x%8)) & 1;
102 static inline void getpixel_4bppIndexed(BYTE *index, const BYTE *row, UINT x)
105 *index = row[x/2]&0xf;
107 *index = row[x/2]>>4;
110 static inline void getpixel_8bppIndexed(BYTE *index, const BYTE *row, UINT x)
115 static inline void getpixel_16bppGrayScale(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
116 const BYTE *row, UINT x)
118 *r = *g = *b = row[x*2+1];
122 static inline void getpixel_16bppRGB555(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
123 const BYTE *row, UINT x)
125 WORD pixel = *((WORD*)(row)+x);
126 *r = (pixel>>7&0xf8)|(pixel>>12&0x7);
127 *g = (pixel>>2&0xf8)|(pixel>>6&0x7);
128 *b = (pixel<<3&0xf8)|(pixel>>2&0x7);
132 static inline void getpixel_16bppRGB565(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
133 const BYTE *row, UINT x)
135 WORD pixel = *((WORD*)(row)+x);
136 *r = (pixel>>8&0xf8)|(pixel>>13&0x7);
137 *g = (pixel>>3&0xfc)|(pixel>>9&0x3);
138 *b = (pixel<<3&0xf8)|(pixel>>2&0x7);
142 static inline void getpixel_16bppARGB1555(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
143 const BYTE *row, UINT x)
145 WORD pixel = *((WORD*)(row)+x);
146 *r = (pixel>>7&0xf8)|(pixel>>12&0x7);
147 *g = (pixel>>2&0xf8)|(pixel>>6&0x7);
148 *b = (pixel<<3&0xf8)|(pixel>>2&0x7);
149 if ((pixel&0x8000) == 0x8000)
155 static inline void getpixel_24bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
156 const BYTE *row, UINT x)
164 static inline void getpixel_32bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
165 const BYTE *row, UINT x)
173 static inline void getpixel_32bppARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
174 const BYTE *row, UINT x)
182 static inline void getpixel_32bppPARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
183 const BYTE *row, UINT x)
190 *r = row[x*4+2] * 255 / *a;
191 *g = row[x*4+1] * 255 / *a;
192 *b = row[x*4] * 255 / *a;
196 static inline void getpixel_48bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
197 const BYTE *row, UINT x)
205 static inline void getpixel_64bppARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
206 const BYTE *row, UINT x)
214 static inline void getpixel_64bppPARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
215 const BYTE *row, UINT x)
222 *r = row[x*8+5] * 255 / *a;
223 *g = row[x*8+3] * 255 / *a;
224 *b = row[x*8+1] * 255 / *a;
228 GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y,
234 TRACE("%p %d %d %p\n", bitmap, x, y, color);
236 if(!bitmap || !color ||
237 x < 0 || y < 0 || x >= bitmap->width || y >= bitmap->height)
238 return InvalidParameter;
240 row = bitmap->bits+bitmap->stride*y;
242 switch (bitmap->format)
244 case PixelFormat1bppIndexed:
245 getpixel_1bppIndexed(&index,row,x);
247 case PixelFormat4bppIndexed:
248 getpixel_4bppIndexed(&index,row,x);
250 case PixelFormat8bppIndexed:
251 getpixel_8bppIndexed(&index,row,x);
253 case PixelFormat16bppGrayScale:
254 getpixel_16bppGrayScale(&r,&g,&b,&a,row,x);
256 case PixelFormat16bppRGB555:
257 getpixel_16bppRGB555(&r,&g,&b,&a,row,x);
259 case PixelFormat16bppRGB565:
260 getpixel_16bppRGB565(&r,&g,&b,&a,row,x);
262 case PixelFormat16bppARGB1555:
263 getpixel_16bppARGB1555(&r,&g,&b,&a,row,x);
265 case PixelFormat24bppRGB:
266 getpixel_24bppRGB(&r,&g,&b,&a,row,x);
268 case PixelFormat32bppRGB:
269 getpixel_32bppRGB(&r,&g,&b,&a,row,x);
271 case PixelFormat32bppARGB:
272 getpixel_32bppARGB(&r,&g,&b,&a,row,x);
274 case PixelFormat32bppPARGB:
275 getpixel_32bppPARGB(&r,&g,&b,&a,row,x);
277 case PixelFormat48bppRGB:
278 getpixel_48bppRGB(&r,&g,&b,&a,row,x);
280 case PixelFormat64bppARGB:
281 getpixel_64bppARGB(&r,&g,&b,&a,row,x);
283 case PixelFormat64bppPARGB:
284 getpixel_64bppPARGB(&r,&g,&b,&a,row,x);
287 FIXME("not implemented for format 0x%x\n", bitmap->format);
288 return NotImplemented;
291 if (bitmap->format & PixelFormatIndexed)
292 *color = bitmap->image.palette_entries[index];
294 *color = a<<24|r<<16|g<<8|b;
299 static inline void setpixel_16bppGrayScale(BYTE r, BYTE g, BYTE b, BYTE a,
302 *((WORD*)(row)+x) = (r+g+b)*85;
305 static inline void setpixel_16bppRGB555(BYTE r, BYTE g, BYTE b, BYTE a,
308 *((WORD*)(row)+x) = (r<<7&0x7c00)|
313 static inline void setpixel_16bppRGB565(BYTE r, BYTE g, BYTE b, BYTE a,
316 *((WORD*)(row)+x) = (r<<8&0xf800)|
321 static inline void setpixel_16bppARGB1555(BYTE r, BYTE g, BYTE b, BYTE a,
324 *((WORD*)(row)+x) = (a<<8&0x8000)|
330 static inline void setpixel_24bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
338 static inline void setpixel_32bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
341 *((DWORD*)(row)+x) = (r<<16)|(g<<8)|b;
344 static inline void setpixel_32bppARGB(BYTE r, BYTE g, BYTE b, BYTE a,
347 *((DWORD*)(row)+x) = (a<<24)|(r<<16)|(g<<8)|b;
350 static inline void setpixel_32bppPARGB(BYTE r, BYTE g, BYTE b, BYTE a,
356 *((DWORD*)(row)+x) = (a<<24)|(r<<16)|(g<<8)|b;
359 static inline void setpixel_48bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
362 row[x*6+5] = row[x*6+4] = r;
363 row[x*6+3] = row[x*6+2] = g;
364 row[x*6+1] = row[x*6] = b;
367 static inline void setpixel_64bppARGB(BYTE r, BYTE g, BYTE b, BYTE a,
370 UINT64 a64=a, r64=r, g64=g, b64=b;
371 *((UINT64*)(row)+x) = (a64<<56)|(a64<<48)|(r64<<40)|(r64<<32)|(g64<<24)|(g64<<16)|(b64<<8)|b64;
374 static inline void setpixel_64bppPARGB(BYTE r, BYTE g, BYTE b, BYTE a,
377 UINT64 a64, r64, g64, b64;
382 *((UINT64*)(row)+x) = (a64<<48)|(r64<<32)|(g64<<16)|b64;
385 GpStatus WINGDIPAPI GdipBitmapSetPixel(GpBitmap* bitmap, INT x, INT y,
390 TRACE("bitmap:%p, x:%d, y:%d, color:%08x\n", bitmap, x, y, color);
392 if(!bitmap || x < 0 || y < 0 || x >= bitmap->width || y >= bitmap->height)
393 return InvalidParameter;
400 row = bitmap->bits + bitmap->stride * y;
402 switch (bitmap->format)
404 case PixelFormat16bppGrayScale:
405 setpixel_16bppGrayScale(r,g,b,a,row,x);
407 case PixelFormat16bppRGB555:
408 setpixel_16bppRGB555(r,g,b,a,row,x);
410 case PixelFormat16bppRGB565:
411 setpixel_16bppRGB565(r,g,b,a,row,x);
413 case PixelFormat16bppARGB1555:
414 setpixel_16bppARGB1555(r,g,b,a,row,x);
416 case PixelFormat24bppRGB:
417 setpixel_24bppRGB(r,g,b,a,row,x);
419 case PixelFormat32bppRGB:
420 setpixel_32bppRGB(r,g,b,a,row,x);
422 case PixelFormat32bppARGB:
423 setpixel_32bppARGB(r,g,b,a,row,x);
425 case PixelFormat32bppPARGB:
426 setpixel_32bppPARGB(r,g,b,a,row,x);
428 case PixelFormat48bppRGB:
429 setpixel_48bppRGB(r,g,b,a,row,x);
431 case PixelFormat64bppARGB:
432 setpixel_64bppARGB(r,g,b,a,row,x);
434 case PixelFormat64bppPARGB:
435 setpixel_64bppPARGB(r,g,b,a,row,x);
438 FIXME("not implemented for format 0x%x\n", bitmap->format);
439 return NotImplemented;
445 /* This function returns a pointer to an array of pixels that represents the
446 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
447 * flags. It is correct behavior that a user who calls this function with write
448 * privileges can write to the whole bitmap (not just the area in rect).
450 * FIXME: only used portion of format is bits per pixel. */
451 GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
452 UINT flags, PixelFormat format, BitmapData* lockeddata)
455 INT stride, bitspp = PIXELFORMATBPP(format);
457 HBITMAP hbm, old = NULL;
461 GpRect act_rect; /* actual rect to be used */
463 TRACE("%p %p %d 0x%x %p\n", bitmap, rect, flags, format, lockeddata);
465 if(!lockeddata || !bitmap)
466 return InvalidParameter;
469 if(rect->X < 0 || rect->Y < 0 || (rect->X + rect->Width > bitmap->width) ||
470 (rect->Y + rect->Height > bitmap->height) || !flags)
471 return InvalidParameter;
476 act_rect.X = act_rect.Y = 0;
477 act_rect.Width = bitmap->width;
478 act_rect.Height = bitmap->height;
481 if(flags & ImageLockModeUserInputBuf)
482 return NotImplemented;
487 if (bitmap->bits && bitmap->format == format)
489 /* no conversion is necessary; just use the bits directly */
490 lockeddata->Width = act_rect.Width;
491 lockeddata->Height = act_rect.Height;
492 lockeddata->PixelFormat = format;
493 lockeddata->Reserved = flags;
494 lockeddata->Stride = bitmap->stride;
495 lockeddata->Scan0 = bitmap->bits + (bitspp / 8) * act_rect.X +
496 bitmap->stride * act_rect.Y;
498 bitmap->lockmode = flags;
504 hbm = bitmap->hbitmap;
506 bm_is_selected = (hdc != 0);
508 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
511 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
512 pbmi->bmiHeader.biBitCount = 0;
515 hdc = CreateCompatibleDC(0);
516 old = SelectObject(hdc, hbm);
520 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
522 abs_height = abs(pbmi->bmiHeader.biHeight);
523 stride = pbmi->bmiHeader.biWidth * bitspp / 8;
524 stride = (stride + 3) & ~3;
526 buff = GdipAlloc(stride * abs_height);
528 pbmi->bmiHeader.biBitCount = bitspp;
531 GetDIBits(hdc, hbm, 0, abs_height, buff, pbmi, DIB_RGB_COLORS);
534 SelectObject(hdc, old);
543 lockeddata->Width = act_rect.Width;
544 lockeddata->Height = act_rect.Height;
545 lockeddata->PixelFormat = format;
546 lockeddata->Reserved = flags;
548 if(pbmi->bmiHeader.biHeight > 0){
549 lockeddata->Stride = -stride;
550 lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X +
551 stride * (abs_height - 1 - act_rect.Y);
554 lockeddata->Stride = stride;
555 lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X + stride * act_rect.Y;
558 bitmap->lockmode = flags;
561 bitmap->bitmapbits = buff;
567 GpStatus WINGDIPAPI GdipBitmapSetResolution(GpBitmap* bitmap, REAL xdpi, REAL ydpi)
569 TRACE("(%p, %.2f, %.2f)\n", bitmap, xdpi, ydpi);
571 if (!bitmap || xdpi == 0.0 || ydpi == 0.0)
572 return InvalidParameter;
574 bitmap->image.xres = xdpi;
575 bitmap->image.yres = ydpi;
580 GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap,
581 BitmapData* lockeddata)
584 HBITMAP hbm, old = NULL;
588 TRACE("(%p,%p)\n", bitmap, lockeddata);
590 if(!bitmap || !lockeddata)
591 return InvalidParameter;
593 if(!bitmap->lockmode)
596 if(lockeddata->Reserved & ImageLockModeUserInputBuf)
597 return NotImplemented;
599 if(lockeddata->Reserved & ImageLockModeRead){
600 if(!(--bitmap->numlocks))
601 bitmap->lockmode = 0;
603 GdipFree(bitmap->bitmapbits);
604 bitmap->bitmapbits = NULL;
608 if (!bitmap->bitmapbits)
610 /* we passed a direct reference; no need to do anything */
611 bitmap->lockmode = 0;
612 bitmap->numlocks = 0;
616 hbm = bitmap->hbitmap;
618 bm_is_selected = (hdc != 0);
620 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
621 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
622 pbmi->bmiHeader.biBitCount = 0;
625 hdc = CreateCompatibleDC(0);
626 old = SelectObject(hdc, hbm);
629 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
630 pbmi->bmiHeader.biBitCount = PIXELFORMATBPP(lockeddata->PixelFormat);
631 SetDIBits(hdc, hbm, 0, abs(pbmi->bmiHeader.biHeight),
632 bitmap->bitmapbits, pbmi, DIB_RGB_COLORS);
635 SelectObject(hdc, old);
640 GdipFree(bitmap->bitmapbits);
641 bitmap->bitmapbits = NULL;
642 bitmap->lockmode = 0;
643 bitmap->numlocks = 0;
648 GpStatus WINGDIPAPI GdipCloneBitmapArea(REAL x, REAL y, REAL width, REAL height,
649 PixelFormat format, GpBitmap* srcBitmap, GpBitmap** dstBitmap)
651 BitmapData lockeddata_src, lockeddata_dst;
657 TRACE("(%f,%f,%f,%f,0x%x,%p,%p)\n", x, y, width, height, format, srcBitmap, dstBitmap);
659 if (!srcBitmap || !dstBitmap || srcBitmap->image.type != ImageTypeBitmap ||
661 x + width > srcBitmap->width || y + height > srcBitmap->height)
663 TRACE("<-- InvalidParameter\n");
664 return InvalidParameter;
667 if (format == PixelFormatDontCare)
668 format = srcBitmap->format;
672 area.Width = roundr(width);
673 area.Height = roundr(height);
675 stat = GdipBitmapLockBits(srcBitmap, &area, ImageLockModeRead, format,
677 if (stat != Ok) return stat;
679 stat = GdipCreateBitmapFromScan0(lockeddata_src.Width, lockeddata_src.Height,
680 0, lockeddata_src.PixelFormat, NULL, dstBitmap);
683 stat = GdipBitmapLockBits(*dstBitmap, NULL, ImageLockModeWrite,
684 lockeddata_src.PixelFormat, &lockeddata_dst);
688 /* copy the image data */
689 row_size = (lockeddata_src.Width * PIXELFORMATBPP(lockeddata_src.PixelFormat) +7)/8;
690 for (i=0; i<lockeddata_src.Height; i++)
691 memcpy((BYTE*)lockeddata_dst.Scan0+lockeddata_dst.Stride*i,
692 (BYTE*)lockeddata_src.Scan0+lockeddata_src.Stride*i,
695 GdipBitmapUnlockBits(*dstBitmap, &lockeddata_dst);
699 GdipDisposeImage((GpImage*)*dstBitmap);
702 GdipBitmapUnlockBits(srcBitmap, &lockeddata_src);
712 GpStatus WINGDIPAPI GdipCloneBitmapAreaI(INT x, INT y, INT width, INT height,
713 PixelFormat format, GpBitmap* srcBitmap, GpBitmap** dstBitmap)
715 TRACE("(%i,%i,%i,%i,0x%x,%p,%p)\n", x, y, width, height, format, srcBitmap, dstBitmap);
717 return GdipCloneBitmapArea(x, y, width, height, format, srcBitmap, dstBitmap);
720 GpStatus WINGDIPAPI GdipCloneImage(GpImage *image, GpImage **cloneImage)
722 GpStatus stat = GenericError;
724 TRACE("%p, %p\n", image, cloneImage);
726 if (!image || !cloneImage)
727 return InvalidParameter;
736 hr = CreateStreamOnHGlobal(0, TRUE, &stream);
740 hr = IPicture_SaveAsFile(image->picture, stream, FALSE, &size);
743 WARN("Failed to save image on stream\n");
747 /* Set seek pointer back to the beginning of the picture */
749 hr = IStream_Seek(stream, move, STREAM_SEEK_SET, NULL);
753 stat = GdipLoadImageFromStream(stream, cloneImage);
754 if (stat != Ok) WARN("Failed to load image from stream\n");
757 IStream_Release(stream);
760 else if (image->type == ImageTypeBitmap)
762 GpBitmap *bitmap = (GpBitmap*)image;
763 BitmapData lockeddata_src, lockeddata_dst;
767 stat = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, bitmap->format,
769 if (stat != Ok) return stat;
771 stat = GdipCreateBitmapFromScan0(lockeddata_src.Width, lockeddata_src.Height,
772 0, lockeddata_src.PixelFormat, NULL, (GpBitmap**)cloneImage);
775 stat = GdipBitmapLockBits((GpBitmap*)*cloneImage, NULL, ImageLockModeWrite,
776 lockeddata_src.PixelFormat, &lockeddata_dst);
780 /* copy the image data */
781 row_size = (lockeddata_src.Width * PIXELFORMATBPP(lockeddata_src.PixelFormat) +7)/8;
782 for (i=0; i<lockeddata_src.Height; i++)
783 memcpy((BYTE*)lockeddata_dst.Scan0+lockeddata_dst.Stride*i,
784 (BYTE*)lockeddata_src.Scan0+lockeddata_src.Stride*i,
787 GdipBitmapUnlockBits((GpBitmap*)*cloneImage, &lockeddata_dst);
791 GdipDisposeImage(*cloneImage);
794 GdipBitmapUnlockBits(bitmap, &lockeddata_src);
800 else memcpy(&(*cloneImage)->format, &image->format, sizeof(GUID));
806 ERR("GpImage with no IPicture or bitmap?!\n");
807 return NotImplemented;
811 GpStatus WINGDIPAPI GdipCreateBitmapFromFile(GDIPCONST WCHAR* filename,
817 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
819 if(!filename || !bitmap)
820 return InvalidParameter;
822 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
827 stat = GdipCreateBitmapFromStream(stream, bitmap);
829 IStream_Release(stream);
834 GpStatus WINGDIPAPI GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO* info,
835 VOID *bits, GpBitmap **bitmap)
837 DWORD height, stride;
840 FIXME("(%p, %p, %p) - partially implemented\n", info, bits, bitmap);
842 height = abs(info->bmiHeader.biHeight);
843 stride = ((info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) >> 3) & ~3;
845 if(info->bmiHeader.biHeight > 0) /* bottom-up */
847 bits = (BYTE*)bits + (height - 1) * stride;
851 switch(info->bmiHeader.biBitCount) {
853 format = PixelFormat1bppIndexed;
856 format = PixelFormat4bppIndexed;
859 format = PixelFormat8bppIndexed;
862 format = PixelFormat24bppRGB;
865 FIXME("don't know how to handle %d bpp\n", info->bmiHeader.biBitCount);
867 return InvalidParameter;
870 return GdipCreateBitmapFromScan0(info->bmiHeader.biWidth, height, stride, format,
876 GpStatus WINGDIPAPI GdipCreateBitmapFromFileICM(GDIPCONST WCHAR* filename,
879 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
881 return GdipCreateBitmapFromFile(filename, bitmap);
884 GpStatus WINGDIPAPI GdipCreateBitmapFromResource(HINSTANCE hInstance,
885 GDIPCONST WCHAR* lpBitmapName, GpBitmap** bitmap)
888 GpStatus stat = InvalidParameter;
890 TRACE("%p (%s) %p\n", hInstance, debugstr_w(lpBitmapName), bitmap);
892 if(!lpBitmapName || !bitmap)
893 return InvalidParameter;
896 hbm = LoadImageW(hInstance, lpBitmapName, IMAGE_BITMAP, 0, 0,
897 LR_CREATEDIBSECTION);
900 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, bitmap);
907 GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
908 HBITMAP* hbmReturn, ARGB background)
911 HBITMAP result, oldbitmap;
914 GpGraphics *graphics;
915 BITMAPINFOHEADER bih;
917 TRACE("(%p,%p,%x)\n", bitmap, hbmReturn, background);
919 if (!bitmap || !hbmReturn) return InvalidParameter;
921 GdipGetImageWidth((GpImage*)bitmap, &width);
922 GdipGetImageHeight((GpImage*)bitmap, &height);
924 bih.biSize = sizeof(bih);
926 bih.biHeight = height;
929 bih.biCompression = BI_RGB;
931 bih.biXPelsPerMeter = 0;
932 bih.biYPelsPerMeter = 0;
934 bih.biClrImportant = 0;
936 hdc = CreateCompatibleDC(NULL);
937 if (!hdc) return GenericError;
939 result = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS, &bits,
944 oldbitmap = SelectObject(hdc, result);
946 stat = GdipCreateFromHDC(hdc, &graphics);
949 stat = GdipGraphicsClear(graphics, background);
952 stat = GdipDrawImage(graphics, (GpImage*)bitmap, 0, 0);
954 GdipDeleteGraphics(graphics);
957 SelectObject(hdc, oldbitmap);
964 if (stat != Ok && result)
966 DeleteObject(result);
975 GpStatus WINGDIPAPI GdipConvertToEmfPlus(const GpGraphics* ref,
976 GpMetafile* metafile, BOOL* succ, EmfType emfType,
977 const WCHAR* description, GpMetafile** out_metafile)
981 TRACE("(%p,%p,%p,%u,%s,%p)\n", ref, metafile, succ, emfType,
982 debugstr_w(description), out_metafile);
984 if(!ref || !metafile || !out_metafile)
985 return InvalidParameter;
988 *out_metafile = NULL;
991 FIXME("not implemented\n");
993 return NotImplemented;
996 /* FIXME: this should create a bitmap in the given size with the attributes
997 * (resolution etc.) of the graphics object */
998 GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT width, INT height,
999 GpGraphics* target, GpBitmap** bitmap)
1004 if(!target || !bitmap)
1005 return InvalidParameter;
1008 FIXME("hacked stub\n");
1010 ret = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat24bppRGB,
1016 GpStatus WINGDIPAPI GdipCreateBitmapFromHICON(HICON hicon, GpBitmap** bitmap)
1024 BitmapData lockeddata;
1029 BITMAPINFOHEADER bih;
1034 TRACE("%p, %p\n", hicon, bitmap);
1036 if(!bitmap || !GetIconInfo(hicon, &iinfo))
1037 return InvalidParameter;
1039 /* get the size of the icon */
1040 ret = GetObjectA(iinfo.hbmColor ? iinfo.hbmColor : iinfo.hbmMask, sizeof(bm), &bm);
1042 DeleteObject(iinfo.hbmColor);
1043 DeleteObject(iinfo.hbmMask);
1044 return GenericError;
1050 height = abs(bm.bmHeight);
1051 else /* combined bitmap + mask */
1052 height = abs(bm.bmHeight) / 2;
1054 bits = HeapAlloc(GetProcessHeap(), 0, 4*width*height);
1056 DeleteObject(iinfo.hbmColor);
1057 DeleteObject(iinfo.hbmMask);
1061 stat = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat32bppARGB, NULL, bitmap);
1063 DeleteObject(iinfo.hbmColor);
1064 DeleteObject(iinfo.hbmMask);
1065 HeapFree(GetProcessHeap(), 0, bits);
1072 rect.Height = height;
1074 stat = GdipBitmapLockBits(*bitmap, &rect, ImageLockModeWrite, PixelFormat32bppARGB, &lockeddata);
1076 DeleteObject(iinfo.hbmColor);
1077 DeleteObject(iinfo.hbmMask);
1078 HeapFree(GetProcessHeap(), 0, bits);
1079 GdipDisposeImage((GpImage*)*bitmap);
1083 bih.biSize = sizeof(bih);
1084 bih.biWidth = width;
1085 bih.biHeight = -height;
1087 bih.biBitCount = 32;
1088 bih.biCompression = BI_RGB;
1089 bih.biSizeImage = 0;
1090 bih.biXPelsPerMeter = 0;
1091 bih.biYPelsPerMeter = 0;
1093 bih.biClrImportant = 0;
1095 screendc = GetDC(0);
1098 GetDIBits(screendc, iinfo.hbmColor, 0, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
1100 if (bm.bmBitsPixel == 32)
1104 /* If any pixel has a non-zero alpha, ignore hbmMask */
1106 for (x=0; x<width && !has_alpha; x++)
1107 for (y=0; y<height && !has_alpha; y++)
1108 if ((*src++ & 0xff000000) != 0)
1111 else has_alpha = FALSE;
1115 GetDIBits(screendc, iinfo.hbmMask, 0, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
1119 /* copy the image data to the Bitmap */
1121 dst_row = lockeddata.Scan0;
1122 for (y=0; y<height; y++)
1124 memcpy(dst_row, src, width*4);
1126 dst_row += lockeddata.Stride;
1133 /* read alpha data from the mask */
1135 GetDIBits(screendc, iinfo.hbmMask, 0, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
1137 GetDIBits(screendc, iinfo.hbmMask, height, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
1140 dst_row = lockeddata.Scan0;
1141 for (y=0; y<height; y++)
1143 dst = (DWORD*)dst_row;
1144 for (x=0; x<height; x++)
1146 DWORD src_value = *src++;
1150 *dst++ |= 0xff000000;
1152 dst_row += lockeddata.Stride;
1157 /* set constant alpha of 255 */
1159 for (y=0; y<height; y++)
1161 dst = (DWORD*)dst_row;
1162 for (x=0; x<height; x++)
1163 *dst++ |= 0xff000000;
1164 dst_row += lockeddata.Stride;
1169 ReleaseDC(0, screendc);
1171 DeleteObject(iinfo.hbmColor);
1172 DeleteObject(iinfo.hbmMask);
1174 GdipBitmapUnlockBits(*bitmap, &lockeddata);
1176 HeapFree(GetProcessHeap(), 0, bits);
1181 static void generate_halftone_palette(ARGB *entries, UINT count)
1183 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1186 for (i=0; i<8 && i<count; i++)
1188 entries[i] = 0xff000000;
1189 if (i&1) entries[i] |= 0x800000;
1190 if (i&2) entries[i] |= 0x8000;
1191 if (i&4) entries[i] |= 0x80;
1195 entries[i] = 0xffc0c0c0;
1197 for (i=9; i<16 && i<count; i++)
1199 entries[i] = 0xff000000;
1200 if (i&1) entries[i] |= 0xff0000;
1201 if (i&2) entries[i] |= 0xff00;
1202 if (i&4) entries[i] |= 0xff;
1205 for (i=16; i<40 && i<count; i++)
1210 for (i=40; i<256 && i<count; i++)
1212 entries[i] = 0xff000000;
1213 entries[i] |= halftone_values[(i-40)%6];
1214 entries[i] |= halftone_values[((i-40)/6)%6] << 8;
1215 entries[i] |= halftone_values[((i-40)/36)%6] << 16;
1219 static GpStatus get_screen_resolution(REAL *xres, REAL *yres)
1221 HDC screendc = GetDC(0);
1223 if (!screendc) return GenericError;
1225 *xres = (REAL)GetDeviceCaps(screendc, LOGPIXELSX);
1226 *yres = (REAL)GetDeviceCaps(screendc, LOGPIXELSY);
1228 ReleaseDC(0, screendc);
1233 GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
1234 PixelFormat format, BYTE* scan0, GpBitmap** bitmap)
1236 BITMAPINFOHEADER bmih;
1238 INT row_size, dib_stride;
1245 TRACE("%d %d %d 0x%x %p %p\n", width, height, stride, format, scan0, bitmap);
1247 if (!bitmap) return InvalidParameter;
1249 if(width <= 0 || height <= 0 || (scan0 && (stride % 4))){
1251 return InvalidParameter;
1254 if(scan0 && !stride)
1255 return InvalidParameter;
1257 stat = get_screen_resolution(&xres, &yres);
1258 if (stat != Ok) return stat;
1260 row_size = (width * PIXELFORMATBPP(format)+7) / 8;
1261 dib_stride = (row_size + 3) & ~3;
1264 stride = dib_stride;
1266 bmih.biSize = sizeof(BITMAPINFOHEADER);
1267 bmih.biWidth = width;
1268 bmih.biHeight = -height;
1270 /* FIXME: use the rest of the data from format */
1271 bmih.biBitCount = PIXELFORMATBPP(format);
1272 bmih.biCompression = BI_RGB;
1273 bmih.biSizeImage = 0;
1274 bmih.biXPelsPerMeter = 0;
1275 bmih.biYPelsPerMeter = 0;
1277 bmih.biClrImportant = 0;
1279 hdc = CreateCompatibleDC(NULL);
1280 if (!hdc) return GenericError;
1282 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, (void**)&bits,
1287 if (!hbitmap) return GenericError;
1289 /* copy bits to the dib if necessary */
1290 /* FIXME: should reference the bits instead of copying them */
1292 for (i=0; i<height; i++)
1293 memcpy(bits+i*dib_stride, scan0+i*stride, row_size);
1295 *bitmap = GdipAlloc(sizeof(GpBitmap));
1298 DeleteObject(hbitmap);
1302 (*bitmap)->image.type = ImageTypeBitmap;
1303 memcpy(&(*bitmap)->image.format, &ImageFormatMemoryBMP, sizeof(GUID));
1304 (*bitmap)->image.flags = ImageFlagsNone;
1305 (*bitmap)->image.palette_flags = 0;
1306 (*bitmap)->image.palette_count = 0;
1307 (*bitmap)->image.palette_size = 0;
1308 (*bitmap)->image.palette_entries = NULL;
1309 (*bitmap)->image.xres = xres;
1310 (*bitmap)->image.yres = yres;
1311 (*bitmap)->width = width;
1312 (*bitmap)->height = height;
1313 (*bitmap)->format = format;
1314 (*bitmap)->image.picture = NULL;
1315 (*bitmap)->hbitmap = hbitmap;
1316 (*bitmap)->hdc = NULL;
1317 (*bitmap)->bits = bits;
1318 (*bitmap)->stride = dib_stride;
1320 if (format == PixelFormat1bppIndexed ||
1321 format == PixelFormat4bppIndexed ||
1322 format == PixelFormat8bppIndexed)
1324 (*bitmap)->image.palette_size = (*bitmap)->image.palette_count = 1 << PIXELFORMATBPP(format);
1325 (*bitmap)->image.palette_entries = GdipAlloc(sizeof(ARGB) * ((*bitmap)->image.palette_size));
1327 if (!(*bitmap)->image.palette_entries)
1329 GdipDisposeImage(&(*bitmap)->image);
1334 if (format == PixelFormat1bppIndexed)
1336 (*bitmap)->image.palette_flags = PaletteFlagsGrayScale;
1337 (*bitmap)->image.palette_entries[0] = 0xff000000;
1338 (*bitmap)->image.palette_entries[1] = 0xffffffff;
1342 if (format == PixelFormat8bppIndexed)
1343 (*bitmap)->image.palette_flags = PaletteFlagsHalftone;
1345 generate_halftone_palette((*bitmap)->image.palette_entries,
1346 (*bitmap)->image.palette_count);
1350 TRACE("<-- %p\n", *bitmap);
1355 GpStatus WINGDIPAPI GdipCreateBitmapFromStream(IStream* stream,
1360 TRACE("%p %p\n", stream, bitmap);
1362 stat = GdipLoadImageFromStream(stream, (GpImage**) bitmap);
1367 if((*bitmap)->image.type != ImageTypeBitmap){
1368 GdipDisposeImage(&(*bitmap)->image);
1370 return GenericError; /* FIXME: what error to return? */
1377 GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream* stream,
1380 TRACE("%p %p\n", stream, bitmap);
1382 return GdipCreateBitmapFromStream(stream, bitmap);
1385 GpStatus WINGDIPAPI GdipCreateCachedBitmap(GpBitmap *bitmap, GpGraphics *graphics,
1386 GpCachedBitmap **cachedbmp)
1390 TRACE("%p %p %p\n", bitmap, graphics, cachedbmp);
1392 if(!bitmap || !graphics || !cachedbmp)
1393 return InvalidParameter;
1395 *cachedbmp = GdipAlloc(sizeof(GpCachedBitmap));
1399 stat = GdipCloneImage(&(bitmap->image), &(*cachedbmp)->image);
1401 GdipFree(*cachedbmp);
1408 GpStatus WINGDIPAPI GdipCreateHICONFromBitmap(GpBitmap *bitmap, HICON *hicon)
1410 FIXME("(%p, %p)\n", bitmap, hicon);
1412 return NotImplemented;
1415 GpStatus WINGDIPAPI GdipDeleteCachedBitmap(GpCachedBitmap *cachedbmp)
1417 TRACE("%p\n", cachedbmp);
1420 return InvalidParameter;
1422 GdipDisposeImage(cachedbmp->image);
1423 GdipFree(cachedbmp);
1428 GpStatus WINGDIPAPI GdipDrawCachedBitmap(GpGraphics *graphics,
1429 GpCachedBitmap *cachedbmp, INT x, INT y)
1431 TRACE("%p %p %d %d\n", graphics, cachedbmp, x, y);
1433 if(!graphics || !cachedbmp)
1434 return InvalidParameter;
1436 return GdipDrawImage(graphics, cachedbmp->image, (REAL)x, (REAL)y);
1439 GpStatus WINGDIPAPI GdipEmfToWmfBits(HENHMETAFILE hemf, UINT cbData16,
1440 LPBYTE pData16, INT iMapMode, INT eFlags)
1442 FIXME("(%p, %d, %p, %d, %d): stub\n", hemf, cbData16, pData16, iMapMode, eFlags);
1443 return NotImplemented;
1446 GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
1448 TRACE("%p\n", image);
1451 return InvalidParameter;
1454 IPicture_Release(image->picture);
1455 if (image->type == ImageTypeBitmap)
1457 GdipFree(((GpBitmap*)image)->bitmapbits);
1458 DeleteDC(((GpBitmap*)image)->hdc);
1460 GdipFree(image->palette_entries);
1466 GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage *image, ImageItemData* item)
1470 TRACE("(%p,%p)\n", image, item);
1473 return InvalidParameter;
1476 FIXME("not implemented\n");
1478 return NotImplemented;
1481 GpStatus WINGDIPAPI GdipGetImageBounds(GpImage *image, GpRectF *srcRect,
1484 TRACE("%p %p %p\n", image, srcRect, srcUnit);
1486 if(!image || !srcRect || !srcUnit)
1487 return InvalidParameter;
1488 if(image->type == ImageTypeMetafile){
1489 *srcRect = ((GpMetafile*)image)->bounds;
1490 *srcUnit = ((GpMetafile*)image)->unit;
1492 else if(image->type == ImageTypeBitmap){
1493 srcRect->X = srcRect->Y = 0.0;
1494 srcRect->Width = (REAL) ((GpBitmap*)image)->width;
1495 srcRect->Height = (REAL) ((GpBitmap*)image)->height;
1496 *srcUnit = UnitPixel;
1499 srcRect->X = srcRect->Y = 0.0;
1500 srcRect->Width = ipicture_pixel_width(image->picture);
1501 srcRect->Height = ipicture_pixel_height(image->picture);
1502 *srcUnit = UnitPixel;
1505 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect->X, srcRect->Y,
1506 srcRect->Width, srcRect->Height, *srcUnit);
1511 GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
1514 TRACE("%p %p %p\n", image, width, height);
1516 if(!image || !height || !width)
1517 return InvalidParameter;
1519 if(image->type == ImageTypeMetafile){
1522 *height = convert_unit(hdc, ((GpMetafile*)image)->unit) *
1523 ((GpMetafile*)image)->bounds.Height;
1525 *width = convert_unit(hdc, ((GpMetafile*)image)->unit) *
1526 ((GpMetafile*)image)->bounds.Width;
1531 else if(image->type == ImageTypeBitmap){
1532 *height = ((GpBitmap*)image)->height;
1533 *width = ((GpBitmap*)image)->width;
1536 *height = ipicture_pixel_height(image->picture);
1537 *width = ipicture_pixel_width(image->picture);
1540 TRACE("returning (%f, %f)\n", *height, *width);
1544 GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image,
1545 GpGraphics **graphics)
1549 TRACE("%p %p\n", image, graphics);
1551 if(!image || !graphics)
1552 return InvalidParameter;
1554 if(image->type != ImageTypeBitmap){
1555 FIXME("not implemented for image type %d\n", image->type);
1556 return NotImplemented;
1559 hdc = ((GpBitmap*)image)->hdc;
1562 hdc = CreateCompatibleDC(0);
1563 SelectObject(hdc, ((GpBitmap*)image)->hbitmap);
1564 ((GpBitmap*)image)->hdc = hdc;
1567 return GdipCreateFromHDC(hdc, graphics);
1570 GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
1572 TRACE("%p %p\n", image, height);
1574 if(!image || !height)
1575 return InvalidParameter;
1577 if(image->type == ImageTypeMetafile){
1580 *height = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
1581 ((GpMetafile*)image)->bounds.Height);
1585 else if(image->type == ImageTypeBitmap)
1586 *height = ((GpBitmap*)image)->height;
1588 *height = ipicture_pixel_height(image->picture);
1590 TRACE("returning %d\n", *height);
1595 GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res)
1598 return InvalidParameter;
1602 TRACE("(%p) <-- %0.2f\n", image, *res);
1607 GpStatus WINGDIPAPI GdipGetImagePaletteSize(GpImage *image, INT *size)
1609 TRACE("%p %p\n", image, size);
1612 return InvalidParameter;
1614 if (image->palette_count == 0)
1615 *size = sizeof(ColorPalette);
1617 *size = sizeof(UINT)*2 + sizeof(ARGB)*image->palette_count;
1619 TRACE("<-- %u\n", *size);
1624 /* FIXME: test this function for non-bitmap types */
1625 GpStatus WINGDIPAPI GdipGetImagePixelFormat(GpImage *image, PixelFormat *format)
1627 TRACE("%p %p\n", image, format);
1629 if(!image || !format)
1630 return InvalidParameter;
1632 if(image->type != ImageTypeBitmap)
1633 *format = PixelFormat24bppRGB;
1635 *format = ((GpBitmap*) image)->format;
1640 GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage *image, GUID *format)
1642 if(!image || !format)
1643 return InvalidParameter;
1645 memcpy(format, &image->format, sizeof(GUID));
1650 GpStatus WINGDIPAPI GdipGetImageType(GpImage *image, ImageType *type)
1652 TRACE("%p %p\n", image, type);
1655 return InvalidParameter;
1657 *type = image->type;
1662 GpStatus WINGDIPAPI GdipGetImageVerticalResolution(GpImage *image, REAL *res)
1665 return InvalidParameter;
1669 TRACE("(%p) <-- %0.2f\n", image, *res);
1674 GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
1676 TRACE("%p %p\n", image, width);
1678 if(!image || !width)
1679 return InvalidParameter;
1681 if(image->type == ImageTypeMetafile){
1684 *width = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
1685 ((GpMetafile*)image)->bounds.Width);
1689 else if(image->type == ImageTypeBitmap)
1690 *width = ((GpBitmap*)image)->width;
1692 *width = ipicture_pixel_width(image->picture);
1694 TRACE("returning %d\n", *width);
1699 GpStatus WINGDIPAPI GdipGetMetafileHeaderFromMetafile(GpMetafile * metafile,
1700 MetafileHeader * header)
1704 if(!metafile || !header)
1705 return InvalidParameter;
1708 FIXME("not implemented\n");
1713 GpStatus WINGDIPAPI GdipGetAllPropertyItems(GpImage *image, UINT size,
1714 UINT num, PropertyItem* items)
1719 FIXME("not implemented\n");
1721 return InvalidParameter;
1724 GpStatus WINGDIPAPI GdipGetPropertyCount(GpImage *image, UINT* num)
1729 FIXME("not implemented\n");
1731 return InvalidParameter;
1734 GpStatus WINGDIPAPI GdipGetPropertyIdList(GpImage *image, UINT num, PROPID* list)
1739 FIXME("not implemented\n");
1741 return InvalidParameter;
1744 GpStatus WINGDIPAPI GdipGetPropertyItem(GpImage *image, PROPID id, UINT size,
1745 PropertyItem* buffer)
1750 FIXME("not implemented\n");
1752 return InvalidParameter;
1755 GpStatus WINGDIPAPI GdipGetPropertyItemSize(GpImage *image, PROPID pid,
1760 TRACE("%p %x %p\n", image, pid, size);
1763 return InvalidParameter;
1766 FIXME("not implemented\n");
1768 return NotImplemented;
1771 GpStatus WINGDIPAPI GdipGetPropertySize(GpImage *image, UINT* size, UINT* num)
1775 TRACE("(%p,%p,%p)\n", image, size, num);
1778 FIXME("not implemented\n");
1780 return InvalidParameter;
1783 struct image_format_dimension
1786 const GUID *dimension;
1789 struct image_format_dimension image_format_dimensions[] =
1791 {&ImageFormatGIF, &FrameDimensionTime},
1792 {&ImageFormatIcon, &FrameDimensionResolution},
1796 GpStatus WINGDIPAPI GdipImageGetFrameCount(GpImage *image,
1797 GDIPCONST GUID* dimensionID, UINT* count)
1801 TRACE("(%p,%s,%p)\n", image, debugstr_guid(dimensionID), count);
1803 if(!image || !dimensionID || !count)
1804 return InvalidParameter;
1807 FIXME("not implemented\n");
1809 return NotImplemented;
1812 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsCount(GpImage *image,
1815 /* Native gdiplus 1.1 does not yet support multiple frame dimensions. */
1817 if(!image || !count)
1818 return InvalidParameter;
1825 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsList(GpImage* image,
1826 GUID* dimensionIDs, UINT count)
1829 const GUID *result=NULL;
1831 TRACE("(%p,%p,%u)\n", image, dimensionIDs, count);
1833 if(!image || !dimensionIDs || count != 1)
1834 return InvalidParameter;
1836 for (i=0; image_format_dimensions[i].format; i++)
1838 if (IsEqualGUID(&image->format, image_format_dimensions[i].format))
1840 result = image_format_dimensions[i].dimension;
1846 result = &FrameDimensionPage;
1848 memcpy(dimensionIDs, result, sizeof(GUID));
1853 GpStatus WINGDIPAPI GdipImageSelectActiveFrame(GpImage *image,
1854 GDIPCONST GUID* dimensionID, UINT frameidx)
1858 if(!image || !dimensionID)
1859 return InvalidParameter;
1862 FIXME("not implemented\n");
1867 GpStatus WINGDIPAPI GdipLoadImageFromFile(GDIPCONST WCHAR* filename,
1873 TRACE("(%s) %p\n", debugstr_w(filename), image);
1875 if (!filename || !image)
1876 return InvalidParameter;
1878 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
1883 stat = GdipLoadImageFromStream(stream, image);
1885 IStream_Release(stream);
1890 /* FIXME: no icm handling */
1891 GpStatus WINGDIPAPI GdipLoadImageFromFileICM(GDIPCONST WCHAR* filename,GpImage **image)
1893 TRACE("(%s) %p\n", debugstr_w(filename), image);
1895 return GdipLoadImageFromFile(filename, image);
1898 static const WICPixelFormatGUID *wic_pixel_formats[] = {
1899 &GUID_WICPixelFormat16bppBGR555,
1900 &GUID_WICPixelFormat24bppBGR,
1901 &GUID_WICPixelFormat32bppBGR,
1902 &GUID_WICPixelFormat32bppBGRA,
1903 &GUID_WICPixelFormat32bppPBGRA,
1907 static const PixelFormat wic_gdip_formats[] = {
1908 PixelFormat16bppRGB555,
1909 PixelFormat24bppRGB,
1910 PixelFormat32bppRGB,
1911 PixelFormat32bppARGB,
1912 PixelFormat32bppPARGB,
1915 static GpStatus decode_image_wic(IStream* stream, REFCLSID clsid, GpImage **image)
1920 IWICBitmapDecoder *decoder;
1921 IWICBitmapFrameDecode *frame;
1922 IWICBitmapSource *source=NULL;
1923 WICPixelFormatGUID wic_format;
1924 PixelFormat gdip_format=0;
1927 BitmapData lockeddata;
1931 initresult = CoInitialize(NULL);
1933 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER,
1934 &IID_IWICBitmapDecoder, (void**)&decoder);
1935 if (FAILED(hr)) goto end;
1937 hr = IWICBitmapDecoder_Initialize(decoder, (IStream*)stream, WICDecodeMetadataCacheOnLoad);
1939 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
1941 if (SUCCEEDED(hr)) /* got frame */
1943 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &wic_format);
1947 for (i=0; wic_pixel_formats[i]; i++)
1949 if (IsEqualGUID(&wic_format, wic_pixel_formats[i]))
1951 source = (IWICBitmapSource*)frame;
1952 IWICBitmapSource_AddRef(source);
1953 gdip_format = wic_gdip_formats[i];
1959 /* unknown format; fall back on 32bppARGB */
1960 hr = WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA, (IWICBitmapSource*)frame, &source);
1961 gdip_format = PixelFormat32bppARGB;
1965 if (SUCCEEDED(hr)) /* got source */
1967 hr = IWICBitmapSource_GetSize(source, &width, &height);
1970 status = GdipCreateBitmapFromScan0(width, height, 0, gdip_format,
1973 if (SUCCEEDED(hr) && status == Ok) /* created bitmap */
1975 status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeWrite,
1976 gdip_format, &lockeddata);
1977 if (status == Ok) /* locked bitmap */
1982 for (i=0; i<height; i++)
1985 hr = IWICBitmapSource_CopyPixels(source, &wrc, abs(lockeddata.Stride),
1986 abs(lockeddata.Stride), (BYTE*)lockeddata.Scan0+lockeddata.Stride*i);
1987 if (FAILED(hr)) break;
1990 GdipBitmapUnlockBits(bitmap, &lockeddata);
1993 if (SUCCEEDED(hr) && status == Ok)
1994 *image = (GpImage*)bitmap;
1998 GdipDisposeImage((GpImage*)bitmap);
2002 IWICBitmapSource_Release(source);
2005 IWICBitmapFrameDecode_Release(frame);
2008 IWICBitmapDecoder_Release(decoder);
2011 if (SUCCEEDED(initresult)) CoUninitialize();
2013 if (FAILED(hr) && status == Ok) status = hresult_to_status(hr);
2018 static GpStatus decode_image_icon(IStream* stream, REFCLSID clsid, GpImage **image)
2020 return decode_image_wic(stream, &CLSID_WICIcoDecoder, image);
2023 static GpStatus decode_image_bmp(IStream* stream, REFCLSID clsid, GpImage **image)
2028 status = decode_image_wic(stream, &CLSID_WICBmpDecoder, image);
2030 bitmap = (GpBitmap*)*image;
2032 if (status == Ok && bitmap->format == PixelFormat32bppARGB)
2034 /* WIC supports bmp files with alpha, but gdiplus does not */
2035 bitmap->format = PixelFormat32bppRGB;
2041 static GpStatus decode_image_jpeg(IStream* stream, REFCLSID clsid, GpImage **image)
2043 return decode_image_wic(stream, &CLSID_WICJpegDecoder, image);
2046 static GpStatus decode_image_png(IStream* stream, REFCLSID clsid, GpImage **image)
2048 return decode_image_wic(stream, &CLSID_WICPngDecoder, image);
2051 static GpStatus decode_image_gif(IStream* stream, REFCLSID clsid, GpImage **image)
2053 return decode_image_wic(stream, &CLSID_WICGifDecoder, image);
2056 static GpStatus decode_image_olepicture_metafile(IStream* stream, REFCLSID clsid, GpImage **image)
2060 TRACE("%p %p\n", stream, image);
2062 if(!stream || !image)
2063 return InvalidParameter;
2065 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
2066 (LPVOID*) &pic) != S_OK){
2067 TRACE("Could not load picture\n");
2068 return GenericError;
2071 /* FIXME: missing initialization code */
2072 *image = GdipAlloc(sizeof(GpMetafile));
2073 if(!*image) return OutOfMemory;
2074 (*image)->type = ImageTypeMetafile;
2075 (*image)->picture = pic;
2076 (*image)->flags = ImageFlagsNone;
2077 (*image)->palette_flags = 0;
2078 (*image)->palette_count = 0;
2079 (*image)->palette_size = 0;
2080 (*image)->palette_entries = NULL;
2082 TRACE("<-- %p\n", *image);
2087 typedef GpStatus (*encode_image_func)(GpImage *image, IStream* stream,
2088 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params);
2090 typedef GpStatus (*decode_image_func)(IStream *stream, REFCLSID clsid, GpImage** image);
2092 typedef struct image_codec {
2093 ImageCodecInfo info;
2094 encode_image_func encode_func;
2095 decode_image_func decode_func;
2109 static const struct image_codec codecs[NUM_CODECS];
2111 static GpStatus get_decoder_info(IStream* stream, const struct image_codec **result)
2119 /* seek to the start of the stream */
2121 hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL);
2122 if (FAILED(hr)) return hresult_to_status(hr);
2124 /* read the first 8 bytes */
2125 /* FIXME: This assumes all codecs have one signature <= 8 bytes in length */
2126 hr = IStream_Read(stream, signature, 8, &bytesread);
2127 if (FAILED(hr)) return hresult_to_status(hr);
2128 if (hr == S_FALSE || bytesread == 0) return GenericError;
2130 for (i = 0; i < NUM_CODECS; i++) {
2131 if ((codecs[i].info.Flags & ImageCodecFlagsDecoder) &&
2132 bytesread >= codecs[i].info.SigSize)
2134 for (j=0; j<codecs[i].info.SigSize; j++)
2135 if ((signature[j] & codecs[i].info.SigMask[j]) != codecs[i].info.SigPattern[j])
2137 if (j == codecs[i].info.SigSize)
2139 *result = &codecs[i];
2145 TRACE("no match for %i byte signature %x %x %x %x %x %x %x %x\n", bytesread,
2146 signature[0],signature[1],signature[2],signature[3],
2147 signature[4],signature[5],signature[6],signature[7]);
2149 return GenericError;
2152 GpStatus WINGDIPAPI GdipLoadImageFromStream(IStream* stream, GpImage **image)
2157 const struct image_codec *codec=NULL;
2159 /* choose an appropriate image decoder */
2160 stat = get_decoder_info(stream, &codec);
2161 if (stat != Ok) return stat;
2163 /* seek to the start of the stream */
2165 hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL);
2166 if (FAILED(hr)) return hresult_to_status(hr);
2168 /* call on the image decoder to do the real work */
2169 stat = codec->decode_func(stream, &codec->info.Clsid, image);
2171 /* take note of the original data format */
2174 memcpy(&(*image)->format, &codec->info.FormatID, sizeof(GUID));
2181 GpStatus WINGDIPAPI GdipLoadImageFromStreamICM(IStream* stream, GpImage **image)
2183 TRACE("%p %p\n", stream, image);
2185 return GdipLoadImageFromStream(stream, image);
2188 GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
2192 TRACE("(%p,%u)\n", image, propId);
2195 return InvalidParameter;
2198 FIXME("not implemented\n");
2200 return NotImplemented;
2203 GpStatus WINGDIPAPI GdipSetPropertyItem(GpImage *image, GDIPCONST PropertyItem* item)
2207 TRACE("(%p,%p)\n", image, item);
2210 FIXME("not implemented\n");
2212 return NotImplemented;
2215 GpStatus WINGDIPAPI GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
2216 GDIPCONST CLSID *clsidEncoder,
2217 GDIPCONST EncoderParameters *encoderParams)
2222 TRACE("%p (%s) %p %p\n", image, debugstr_w(filename), clsidEncoder, encoderParams);
2224 if (!image || !filename|| !clsidEncoder)
2225 return InvalidParameter;
2227 stat = GdipCreateStreamOnFile(filename, GENERIC_WRITE, &stream);
2229 return GenericError;
2231 stat = GdipSaveImageToStream(image, stream, clsidEncoder, encoderParams);
2233 IStream_Release(stream);
2237 /*************************************************************************
2238 * Encoding functions -
2239 * These functions encode an image in different image file formats.
2241 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
2242 #define BITMAP_FORMAT_JPEG 0xd8ff
2243 #define BITMAP_FORMAT_GIF 0x4947
2244 #define BITMAP_FORMAT_PNG 0x5089
2245 #define BITMAP_FORMAT_APM 0xcdd7
2247 static GpStatus encode_image_WIC(GpImage *image, IStream* stream,
2248 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
2252 IWICBitmapEncoder *encoder;
2253 IWICBitmapFrameEncode *frameencode;
2254 IPropertyBag2 *encoderoptions;
2257 PixelFormat gdipformat=0;
2258 WICPixelFormatGUID wicformat;
2260 BitmapData lockeddata;
2264 if (image->type != ImageTypeBitmap)
2265 return GenericError;
2267 bitmap = (GpBitmap*)image;
2269 GdipGetImageWidth(image, &width);
2270 GdipGetImageHeight(image, &height);
2277 initresult = CoInitialize(NULL);
2279 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER,
2280 &IID_IWICBitmapEncoder, (void**)&encoder);
2283 if (SUCCEEDED(initresult)) CoUninitialize();
2284 return hresult_to_status(hr);
2287 hr = IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache);
2291 hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frameencode, &encoderoptions);
2294 if (SUCCEEDED(hr)) /* created frame */
2296 hr = IWICBitmapFrameEncode_Initialize(frameencode, encoderoptions);
2299 hr = IWICBitmapFrameEncode_SetSize(frameencode, width, height);
2302 /* FIXME: use the resolution from the image */
2303 hr = IWICBitmapFrameEncode_SetResolution(frameencode, 96.0, 96.0);
2307 for (i=0; wic_pixel_formats[i]; i++)
2309 if (wic_gdip_formats[i] == bitmap->format)
2312 if (wic_pixel_formats[i])
2313 memcpy(&wicformat, wic_pixel_formats[i], sizeof(GUID));
2315 memcpy(&wicformat, &GUID_WICPixelFormat32bppBGRA, sizeof(GUID));
2317 hr = IWICBitmapFrameEncode_SetPixelFormat(frameencode, &wicformat);
2319 for (i=0; wic_pixel_formats[i]; i++)
2321 if (IsEqualGUID(&wicformat, wic_pixel_formats[i]))
2324 if (wic_pixel_formats[i])
2325 gdipformat = wic_gdip_formats[i];
2328 ERR("cannot provide pixel format %s\n", debugstr_guid(&wicformat));
2335 stat = GdipBitmapLockBits(bitmap, &rc, ImageLockModeRead, gdipformat,
2340 UINT row_size = (lockeddata.Width * PIXELFORMATBPP(gdipformat) + 7)/8;
2343 /* write one row at a time in case stride is negative */
2344 row = lockeddata.Scan0;
2345 for (i=0; i<lockeddata.Height; i++)
2347 hr = IWICBitmapFrameEncode_WritePixels(frameencode, 1, row_size, row_size, row);
2348 if (FAILED(hr)) break;
2349 row += lockeddata.Stride;
2352 GdipBitmapUnlockBits(bitmap, &lockeddata);
2359 hr = IWICBitmapFrameEncode_Commit(frameencode);
2361 IWICBitmapFrameEncode_Release(frameencode);
2362 IPropertyBag2_Release(encoderoptions);
2366 hr = IWICBitmapEncoder_Commit(encoder);
2368 IWICBitmapEncoder_Release(encoder);
2370 if (SUCCEEDED(initresult)) CoUninitialize();
2372 return hresult_to_status(hr);
2375 static GpStatus encode_image_BMP(GpImage *image, IStream* stream,
2376 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
2378 return encode_image_WIC(image, stream, &CLSID_WICBmpEncoder, params);
2381 static GpStatus encode_image_png(GpImage *image, IStream* stream,
2382 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
2384 return encode_image_WIC(image, stream, &CLSID_WICPngEncoder, params);
2387 /*****************************************************************************
2388 * GdipSaveImageToStream [GDIPLUS.@]
2390 GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
2391 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
2394 encode_image_func encode_image;
2397 TRACE("%p %p %p %p\n", image, stream, clsid, params);
2399 if(!image || !stream)
2400 return InvalidParameter;
2402 /* select correct encoder */
2403 encode_image = NULL;
2404 for (i = 0; i < NUM_CODECS; i++) {
2405 if ((codecs[i].info.Flags & ImageCodecFlagsEncoder) &&
2406 IsEqualCLSID(clsid, &codecs[i].info.Clsid))
2407 encode_image = codecs[i].encode_func;
2409 if (encode_image == NULL)
2410 return UnknownImageFormat;
2412 stat = encode_image(image, stream, clsid, params);
2417 /*****************************************************************************
2418 * GdipGetImagePalette [GDIPLUS.@]
2420 GpStatus WINGDIPAPI GdipGetImagePalette(GpImage *image, ColorPalette *palette, INT size)
2422 TRACE("(%p,%p,%i)\n", image, palette, size);
2424 if (!image || !palette)
2425 return InvalidParameter;
2427 if (size < (sizeof(UINT)*2+sizeof(ARGB)*image->palette_count))
2429 TRACE("<-- InsufficientBuffer\n");
2430 return InsufficientBuffer;
2433 palette->Flags = image->palette_flags;
2434 palette->Count = image->palette_count;
2435 memcpy(palette->Entries, image->palette_entries, sizeof(ARGB)*image->palette_count);
2440 /*****************************************************************************
2441 * GdipSetImagePalette [GDIPLUS.@]
2443 GpStatus WINGDIPAPI GdipSetImagePalette(GpImage *image,
2444 GDIPCONST ColorPalette *palette)
2446 TRACE("(%p,%p)\n", image, palette);
2448 if(!image || !palette || palette->Count > 256)
2449 return InvalidParameter;
2451 if (palette->Count > image->palette_size)
2455 new_palette = GdipAlloc(sizeof(ARGB) * palette->Count);
2456 if (!new_palette) return OutOfMemory;
2458 GdipFree(image->palette_entries);
2459 image->palette_entries = new_palette;
2460 image->palette_size = palette->Count;
2463 image->palette_flags = palette->Flags;
2464 image->palette_count = palette->Count;
2465 memcpy(image->palette_entries, palette->Entries, sizeof(ARGB)*palette->Count);
2470 /*************************************************************************
2472 * Structures that represent which formats we support for encoding.
2475 /* ImageCodecInfo creation routines taken from libgdiplus */
2476 static const WCHAR bmp_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
2477 static const WCHAR bmp_extension[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
2478 static const WCHAR bmp_mimetype[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
2479 static const WCHAR bmp_format[] = {'B', 'M', 'P', 0}; /* BMP */
2480 static const BYTE bmp_sig_pattern[] = { 0x42, 0x4D };
2481 static const BYTE bmp_sig_mask[] = { 0xFF, 0xFF };
2483 static const WCHAR jpeg_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'J','P','E','G', 0};
2484 static const WCHAR jpeg_extension[] = {'*','.','J','P','G',';', '*','.','J','P','E','G',';', '*','.','J','P','E',';', '*','.','J','F','I','F',0};
2485 static const WCHAR jpeg_mimetype[] = {'i','m','a','g','e','/','j','p','e','g', 0};
2486 static const WCHAR jpeg_format[] = {'J','P','E','G',0};
2487 static const BYTE jpeg_sig_pattern[] = { 0xFF, 0xD8 };
2488 static const BYTE jpeg_sig_mask[] = { 0xFF, 0xFF };
2490 static const WCHAR gif_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'G','I','F', 0};
2491 static const WCHAR gif_extension[] = {'*','.','G','I','F',0};
2492 static const WCHAR gif_mimetype[] = {'i','m','a','g','e','/','g','i','f', 0};
2493 static const WCHAR gif_format[] = {'G','I','F',0};
2494 static const BYTE gif_sig_pattern[4] = "GIF8";
2495 static const BYTE gif_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF };
2497 static const WCHAR emf_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'E','M','F', 0};
2498 static const WCHAR emf_extension[] = {'*','.','E','M','F',0};
2499 static const WCHAR emf_mimetype[] = {'i','m','a','g','e','/','x','-','e','m','f', 0};
2500 static const WCHAR emf_format[] = {'E','M','F',0};
2501 static const BYTE emf_sig_pattern[] = { 0x01, 0x00, 0x00, 0x00 };
2502 static const BYTE emf_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF };
2504 static const WCHAR wmf_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'W','M','F', 0};
2505 static const WCHAR wmf_extension[] = {'*','.','W','M','F',0};
2506 static const WCHAR wmf_mimetype[] = {'i','m','a','g','e','/','x','-','w','m','f', 0};
2507 static const WCHAR wmf_format[] = {'W','M','F',0};
2508 static const BYTE wmf_sig_pattern[] = { 0xd7, 0xcd };
2509 static const BYTE wmf_sig_mask[] = { 0xFF, 0xFF };
2511 static const WCHAR png_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'P','N','G', 0};
2512 static const WCHAR png_extension[] = {'*','.','P','N','G',0};
2513 static const WCHAR png_mimetype[] = {'i','m','a','g','e','/','p','n','g', 0};
2514 static const WCHAR png_format[] = {'P','N','G',0};
2515 static const BYTE png_sig_pattern[] = { 137, 80, 78, 71, 13, 10, 26, 10, };
2516 static const BYTE png_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
2518 static const WCHAR ico_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'I','C','O', 0};
2519 static const WCHAR ico_extension[] = {'*','.','I','C','O',0};
2520 static const WCHAR ico_mimetype[] = {'i','m','a','g','e','/','x','-','i','c','o','n', 0};
2521 static const WCHAR ico_format[] = {'I','C','O',0};
2522 static const BYTE ico_sig_pattern[] = { 0x00, 0x00, 0x01, 0x00 };
2523 static const BYTE ico_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF };
2525 static const struct image_codec codecs[NUM_CODECS] = {
2528 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2529 /* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2530 /* CodecName */ bmp_codecname,
2532 /* FormatDescription */ bmp_format,
2533 /* FilenameExtension */ bmp_extension,
2534 /* MimeType */ bmp_mimetype,
2535 /* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2539 /* SigPattern */ bmp_sig_pattern,
2540 /* SigMask */ bmp_sig_mask,
2547 /* Clsid */ { 0x557cf401, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2548 /* FormatID */ { 0xb96b3caeU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2549 /* CodecName */ jpeg_codecname,
2551 /* FormatDescription */ jpeg_format,
2552 /* FilenameExtension */ jpeg_extension,
2553 /* MimeType */ jpeg_mimetype,
2554 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2558 /* SigPattern */ jpeg_sig_pattern,
2559 /* SigMask */ jpeg_sig_mask,
2566 /* Clsid */ { 0x557cf402, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2567 /* FormatID */ { 0xb96b3cb0U, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2568 /* CodecName */ gif_codecname,
2570 /* FormatDescription */ gif_format,
2571 /* FilenameExtension */ gif_extension,
2572 /* MimeType */ gif_mimetype,
2573 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2577 /* SigPattern */ gif_sig_pattern,
2578 /* SigMask */ gif_sig_mask,
2585 /* Clsid */ { 0x557cf403, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2586 /* FormatID */ { 0xb96b3cacU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2587 /* CodecName */ emf_codecname,
2589 /* FormatDescription */ emf_format,
2590 /* FilenameExtension */ emf_extension,
2591 /* MimeType */ emf_mimetype,
2592 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportVector | ImageCodecFlagsBuiltin,
2596 /* SigPattern */ emf_sig_pattern,
2597 /* SigMask */ emf_sig_mask,
2600 decode_image_olepicture_metafile
2604 /* Clsid */ { 0x557cf404, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2605 /* FormatID */ { 0xb96b3cadU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2606 /* CodecName */ wmf_codecname,
2608 /* FormatDescription */ wmf_format,
2609 /* FilenameExtension */ wmf_extension,
2610 /* MimeType */ wmf_mimetype,
2611 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportVector | ImageCodecFlagsBuiltin,
2615 /* SigPattern */ wmf_sig_pattern,
2616 /* SigMask */ wmf_sig_mask,
2619 decode_image_olepicture_metafile
2623 /* Clsid */ { 0x557cf406, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2624 /* FormatID */ { 0xb96b3cafU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2625 /* CodecName */ png_codecname,
2627 /* FormatDescription */ png_format,
2628 /* FilenameExtension */ png_extension,
2629 /* MimeType */ png_mimetype,
2630 /* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2634 /* SigPattern */ png_sig_pattern,
2635 /* SigMask */ png_sig_mask,
2642 /* Clsid */ { 0x557cf407, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
2643 /* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
2644 /* CodecName */ ico_codecname,
2646 /* FormatDescription */ ico_format,
2647 /* FilenameExtension */ ico_extension,
2648 /* MimeType */ ico_mimetype,
2649 /* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
2653 /* SigPattern */ ico_sig_pattern,
2654 /* SigMask */ ico_sig_mask,
2661 /*****************************************************************************
2662 * GdipGetImageDecodersSize [GDIPLUS.@]
2664 GpStatus WINGDIPAPI GdipGetImageDecodersSize(UINT *numDecoders, UINT *size)
2666 int decoder_count=0;
2668 TRACE("%p %p\n", numDecoders, size);
2670 if (!numDecoders || !size)
2671 return InvalidParameter;
2673 for (i=0; i<NUM_CODECS; i++)
2675 if (codecs[i].info.Flags & ImageCodecFlagsDecoder)
2679 *numDecoders = decoder_count;
2680 *size = decoder_count * sizeof(ImageCodecInfo);
2685 /*****************************************************************************
2686 * GdipGetImageDecoders [GDIPLUS.@]
2688 GpStatus WINGDIPAPI GdipGetImageDecoders(UINT numDecoders, UINT size, ImageCodecInfo *decoders)
2690 int i, decoder_count=0;
2691 TRACE("%u %u %p\n", numDecoders, size, decoders);
2694 size != numDecoders * sizeof(ImageCodecInfo))
2695 return GenericError;
2697 for (i=0; i<NUM_CODECS; i++)
2699 if (codecs[i].info.Flags & ImageCodecFlagsDecoder)
2701 if (decoder_count == numDecoders) return GenericError;
2702 memcpy(&decoders[decoder_count], &codecs[i].info, sizeof(ImageCodecInfo));
2707 if (decoder_count < numDecoders) return GenericError;
2712 /*****************************************************************************
2713 * GdipGetImageEncodersSize [GDIPLUS.@]
2715 GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size)
2717 int encoder_count=0;
2719 TRACE("%p %p\n", numEncoders, size);
2721 if (!numEncoders || !size)
2722 return InvalidParameter;
2724 for (i=0; i<NUM_CODECS; i++)
2726 if (codecs[i].info.Flags & ImageCodecFlagsEncoder)
2730 *numEncoders = encoder_count;
2731 *size = encoder_count * sizeof(ImageCodecInfo);
2736 /*****************************************************************************
2737 * GdipGetImageEncoders [GDIPLUS.@]
2739 GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders)
2741 int i, encoder_count=0;
2742 TRACE("%u %u %p\n", numEncoders, size, encoders);
2745 size != numEncoders * sizeof(ImageCodecInfo))
2746 return GenericError;
2748 for (i=0; i<NUM_CODECS; i++)
2750 if (codecs[i].info.Flags & ImageCodecFlagsEncoder)
2752 if (encoder_count == numEncoders) return GenericError;
2753 memcpy(&encoders[encoder_count], &codecs[i].info, sizeof(ImageCodecInfo));
2758 if (encoder_count < numEncoders) return GenericError;
2763 /*****************************************************************************
2764 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
2766 GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBitmap** bitmap)
2771 BitmapData lockeddata;
2774 TRACE("%p %p %p\n", hbm, hpal, bitmap);
2777 return InvalidParameter;
2779 /* TODO: Support for device-dependent bitmaps */
2781 FIXME("no support for device-dependent bitmaps\n");
2782 return NotImplemented;
2785 if (GetObjectA(hbm, sizeof(bm), &bm) != sizeof(bm))
2786 return InvalidParameter;
2788 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
2789 switch(bm.bmBitsPixel) {
2791 format = PixelFormat1bppIndexed;
2794 format = PixelFormat4bppIndexed;
2797 format = PixelFormat8bppIndexed;
2800 format = PixelFormat24bppRGB;
2803 format = PixelFormat32bppRGB;
2806 format = PixelFormat48bppRGB;
2809 FIXME("don't know how to handle %d bpp\n", bm.bmBitsPixel);
2810 return InvalidParameter;
2813 retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, 0,
2814 format, NULL, bitmap);
2818 retval = GdipBitmapLockBits(*bitmap, NULL, ImageLockModeWrite,
2819 format, &lockeddata);
2824 for (y=0; y<bm.bmHeight; y++)
2826 memcpy((BYTE*)lockeddata.Scan0+lockeddata.Stride*y,
2827 (BYTE*)bm.bmBits+bm.bmWidthBytes*(bm.bmHeight-1-y),
2836 INT src_height, dst_stride;
2839 hdc = CreateCompatibleDC(NULL);
2840 oldhbm = SelectObject(hdc, hbm);
2842 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
2846 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
2847 pbmi->bmiHeader.biBitCount = 0;
2849 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
2851 src_height = abs(pbmi->bmiHeader.biHeight);
2853 if (pbmi->bmiHeader.biHeight > 0)
2855 dst_bits = (BYTE*)lockeddata.Scan0+lockeddata.Stride*(src_height-1);
2856 dst_stride = -lockeddata.Stride;
2860 dst_bits = lockeddata.Scan0;
2861 dst_stride = lockeddata.Stride;
2864 for (y=0; y<src_height; y++)
2866 GetDIBits(hdc, hbm, y, 1, dst_bits+dst_stride*y,
2867 pbmi, DIB_RGB_COLORS);
2873 retval = OutOfMemory;
2875 SelectObject(hdc, oldhbm);
2879 GdipBitmapUnlockBits(*bitmap, &lockeddata);
2886 GpStatus WINGDIPAPI GdipDeleteEffect(CGpEffect *effect)
2888 FIXME("(%p): stub\n", effect);
2889 /* note: According to Jose Roca's GDI+ Docs, this is not implemented
2890 * in Windows's gdiplus */
2891 return NotImplemented;
2894 /*****************************************************************************
2895 * GdipSetEffectParameters [GDIPLUS.@]
2897 GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect *effect,
2898 const VOID *params, const UINT size)
2902 TRACE("(%p,%p,%u)\n", effect, params, size);
2905 FIXME("not implemented\n");
2907 return NotImplemented;
2910 /*****************************************************************************
2911 * GdipGetImageFlags [GDIPLUS.@]
2913 GpStatus WINGDIPAPI GdipGetImageFlags(GpImage *image, UINT *flags)
2915 TRACE("%p %p\n", image, flags);
2917 if(!image || !flags)
2918 return InvalidParameter;
2920 *flags = image->flags;
2925 GpStatus WINGDIPAPI GdipTestControl(GpTestControlEnum control, void *param)
2927 TRACE("(%d, %p)\n", control, param);
2930 case TestControlForceBilinear:
2932 FIXME("TestControlForceBilinear not handled\n");
2934 case TestControlNoICM:
2936 FIXME("TestControlNoICM not handled\n");
2938 case TestControlGetBuildNumber:
2939 *((DWORD*)param) = 3102;
2946 GpStatus WINGDIPAPI GdipRecordMetafileFileName(GDIPCONST WCHAR* fileName,
2947 HDC hdc, EmfType type, GDIPCONST GpRectF *pFrameRect,
2948 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc,
2949 GpMetafile **metafile)
2951 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
2952 frameUnit, debugstr_w(desc), metafile);
2954 return NotImplemented;
2957 GpStatus WINGDIPAPI GdipRecordMetafileFileNameI(GDIPCONST WCHAR* fileName, HDC hdc, EmfType type,
2958 GDIPCONST GpRect *pFrameRect, MetafileFrameUnit frameUnit,
2959 GDIPCONST WCHAR *desc, GpMetafile **metafile)
2961 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
2962 frameUnit, debugstr_w(desc), metafile);
2964 return NotImplemented;
2967 GpStatus WINGDIPAPI GdipImageForceValidation(GpImage *image)
2969 FIXME("%p\n", image);
2974 /*****************************************************************************
2975 * GdipGetImageThumbnail [GDIPLUS.@]
2977 GpStatus WINGDIPAPI GdipGetImageThumbnail(GpImage *image, UINT width, UINT height,
2978 GpImage **ret_image, GetThumbnailImageAbort cb,
2981 FIXME("(%p %u %u %p %p %p) stub\n",
2982 image, width, height, ret_image, cb, cb_data);
2983 return NotImplemented;
2986 /*****************************************************************************
2987 * GdipImageRotateFlip [GDIPLUS.@]
2989 GpStatus WINGDIPAPI GdipImageRotateFlip(GpImage *image, RotateFlipType type)
2991 FIXME("(%p %u) stub\n", image, type);
2992 return NotImplemented;