2 * Copyright (C) 2007 Google (Evan Stade)
3 * Copyright (C) 2012 Dmitry Timoshkov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define NONAMELESSUNION
38 #include "gdiplus_private.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
43 HRESULT WINAPI
WICCreateImagingFactory_Proxy(UINT
, IWICImagingFactory
**);
45 #define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
49 const WICPixelFormatGUID
*wic_format
;
50 PixelFormat gdip_format
;
51 /* predefined palette type to use for pixel format conversions */
52 WICBitmapPaletteType palette_type
;
55 { &GUID_WICPixelFormatBlackWhite
, PixelFormat1bppIndexed
, WICBitmapPaletteTypeFixedBW
},
56 { &GUID_WICPixelFormat1bppIndexed
, PixelFormat1bppIndexed
, WICBitmapPaletteTypeFixedBW
},
57 { &GUID_WICPixelFormat8bppGray
, PixelFormat8bppIndexed
, WICBitmapPaletteTypeFixedGray256
},
58 { &GUID_WICPixelFormat8bppIndexed
, PixelFormat8bppIndexed
, WICBitmapPaletteTypeFixedHalftone256
},
59 { &GUID_WICPixelFormat16bppBGR555
, PixelFormat16bppRGB555
, WICBitmapPaletteTypeFixedHalftone256
},
60 { &GUID_WICPixelFormat24bppBGR
, PixelFormat24bppRGB
, WICBitmapPaletteTypeFixedHalftone256
},
61 { &GUID_WICPixelFormat32bppBGR
, PixelFormat32bppRGB
, WICBitmapPaletteTypeFixedHalftone256
},
62 { &GUID_WICPixelFormat32bppBGRA
, PixelFormat32bppARGB
, WICBitmapPaletteTypeFixedHalftone256
},
63 { &GUID_WICPixelFormat32bppPBGRA
, PixelFormat32bppPARGB
, WICBitmapPaletteTypeFixedHalftone256
},
67 static ColorPalette
*get_palette(IWICBitmapFrameDecode
*frame
, WICBitmapPaletteType palette_type
)
70 IWICImagingFactory
*factory
;
71 IWICPalette
*wic_palette
;
72 ColorPalette
*palette
= NULL
;
74 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
75 if (hr
!= S_OK
) return NULL
;
77 hr
= IWICImagingFactory_CreatePalette(factory
, &wic_palette
);
80 hr
= WINCODEC_ERR_PALETTEUNAVAILABLE
;
82 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, wic_palette
);
85 TRACE("using predefined palette %#x\n", palette_type
);
86 hr
= IWICPalette_InitializePredefined(wic_palette
, palette_type
, FALSE
);
90 WICBitmapPaletteType type
;
94 IWICPalette_GetColorCount(wic_palette
, &count
);
95 palette
= heap_alloc(2 * sizeof(UINT
) + count
* sizeof(ARGB
));
96 IWICPalette_GetColors(wic_palette
, count
, palette
->Entries
, &palette
->Count
);
98 IWICPalette_GetType(wic_palette
, &type
);
100 case WICBitmapPaletteTypeFixedGray4
:
101 case WICBitmapPaletteTypeFixedGray16
:
102 case WICBitmapPaletteTypeFixedGray256
:
103 palette
->Flags
= PaletteFlagsGrayScale
;
105 case WICBitmapPaletteTypeFixedHalftone8
:
106 case WICBitmapPaletteTypeFixedHalftone27
:
107 case WICBitmapPaletteTypeFixedHalftone64
:
108 case WICBitmapPaletteTypeFixedHalftone125
:
109 case WICBitmapPaletteTypeFixedHalftone216
:
110 case WICBitmapPaletteTypeFixedHalftone252
:
111 case WICBitmapPaletteTypeFixedHalftone256
:
112 palette
->Flags
= PaletteFlagsHalftone
;
117 IWICPalette_HasAlpha(wic_palette
, &alpha
);
119 palette
->Flags
|= PaletteFlagsHasAlpha
;
121 IWICPalette_Release(wic_palette
);
123 IWICImagingFactory_Release(factory
);
127 static INT
ipicture_pixel_height(IPicture
*pic
)
130 OLE_YSIZE_HIMETRIC y
;
132 IPicture_get_Height(pic
, &y
);
134 hdcref
= CreateCompatibleDC(0);
135 y
= MulDiv(y
, GetDeviceCaps(hdcref
, LOGPIXELSY
), INCH_HIMETRIC
);
141 static INT
ipicture_pixel_width(IPicture
*pic
)
144 OLE_XSIZE_HIMETRIC x
;
146 IPicture_get_Width(pic
, &x
);
148 hdcref
= CreateCompatibleDC(0);
149 x
= MulDiv(x
, GetDeviceCaps(hdcref
, LOGPIXELSX
), INCH_HIMETRIC
);
155 GpStatus WINGDIPAPI
GdipBitmapApplyEffect(GpBitmap
* bitmap
, CGpEffect
* effect
,
156 RECT
* roi
, BOOL useAuxData
, VOID
** auxData
, INT
* auxDataSize
)
158 FIXME("(%p %p %p %d %p %p): stub\n", bitmap
, effect
, roi
, useAuxData
, auxData
, auxDataSize
);
160 * Note: According to Jose Roca's GDI+ docs, this function is not
161 * implemented in Windows's GDI+.
163 return NotImplemented
;
166 GpStatus WINGDIPAPI
GdipBitmapCreateApplyEffect(GpBitmap
** inputBitmaps
,
167 INT numInputs
, CGpEffect
* effect
, RECT
* roi
, RECT
* outputRect
,
168 GpBitmap
** outputBitmap
, BOOL useAuxData
, VOID
** auxData
, INT
* auxDataSize
)
170 FIXME("(%p %d %p %p %p %p %d %p %p): stub\n", inputBitmaps
, numInputs
, effect
, roi
, outputRect
, outputBitmap
, useAuxData
, auxData
, auxDataSize
);
172 * Note: According to Jose Roca's GDI+ docs, this function is not
173 * implemented in Windows's GDI+.
175 return NotImplemented
;
178 static inline void getpixel_1bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
180 *index
= (row
[x
/8]>>(7-x
%8)) & 1;
183 static inline void getpixel_4bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
186 *index
= row
[x
/2]&0xf;
188 *index
= row
[x
/2]>>4;
191 static inline void getpixel_8bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
196 static inline void getpixel_16bppGrayScale(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
197 const BYTE
*row
, UINT x
)
199 *r
= *g
= *b
= row
[x
*2+1];
203 static inline void getpixel_16bppRGB555(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
204 const BYTE
*row
, UINT x
)
206 WORD pixel
= *((const WORD
*)(row
)+x
);
207 *r
= (pixel
>>7&0xf8)|(pixel
>>12&0x7);
208 *g
= (pixel
>>2&0xf8)|(pixel
>>6&0x7);
209 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
213 static inline void getpixel_16bppRGB565(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
214 const BYTE
*row
, UINT x
)
216 WORD pixel
= *((const WORD
*)(row
)+x
);
217 *r
= (pixel
>>8&0xf8)|(pixel
>>13&0x7);
218 *g
= (pixel
>>3&0xfc)|(pixel
>>9&0x3);
219 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
223 static inline void getpixel_16bppARGB1555(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
224 const BYTE
*row
, UINT x
)
226 WORD pixel
= *((const WORD
*)(row
)+x
);
227 *r
= (pixel
>>7&0xf8)|(pixel
>>12&0x7);
228 *g
= (pixel
>>2&0xf8)|(pixel
>>6&0x7);
229 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
230 if ((pixel
&0x8000) == 0x8000)
236 static inline void getpixel_24bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
237 const BYTE
*row
, UINT x
)
245 static inline void getpixel_32bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
246 const BYTE
*row
, UINT x
)
254 static inline void getpixel_32bppARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
255 const BYTE
*row
, UINT x
)
263 static inline void getpixel_32bppPARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
264 const BYTE
*row
, UINT x
)
271 *r
= row
[x
*4+2] * 255 / *a
;
272 *g
= row
[x
*4+1] * 255 / *a
;
273 *b
= row
[x
*4] * 255 / *a
;
277 static inline void getpixel_48bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
278 const BYTE
*row
, UINT x
)
286 static inline void getpixel_64bppARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
287 const BYTE
*row
, UINT x
)
295 static inline void getpixel_64bppPARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
296 const BYTE
*row
, UINT x
)
303 *r
= row
[x
*8+5] * 255 / *a
;
304 *g
= row
[x
*8+3] * 255 / *a
;
305 *b
= row
[x
*8+1] * 255 / *a
;
309 GpStatus WINGDIPAPI
GdipBitmapGetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
316 if(!bitmap
|| !color
||
317 x
< 0 || y
< 0 || x
>= bitmap
->width
|| y
>= bitmap
->height
)
318 return InvalidParameter
;
320 row
= bitmap
->bits
+bitmap
->stride
*y
;
322 switch (bitmap
->format
)
324 case PixelFormat1bppIndexed
:
325 getpixel_1bppIndexed(&index
,row
,x
);
327 case PixelFormat4bppIndexed
:
328 getpixel_4bppIndexed(&index
,row
,x
);
330 case PixelFormat8bppIndexed
:
331 getpixel_8bppIndexed(&index
,row
,x
);
333 case PixelFormat16bppGrayScale
:
334 getpixel_16bppGrayScale(&r
,&g
,&b
,&a
,row
,x
);
336 case PixelFormat16bppRGB555
:
337 getpixel_16bppRGB555(&r
,&g
,&b
,&a
,row
,x
);
339 case PixelFormat16bppRGB565
:
340 getpixel_16bppRGB565(&r
,&g
,&b
,&a
,row
,x
);
342 case PixelFormat16bppARGB1555
:
343 getpixel_16bppARGB1555(&r
,&g
,&b
,&a
,row
,x
);
345 case PixelFormat24bppRGB
:
346 getpixel_24bppRGB(&r
,&g
,&b
,&a
,row
,x
);
348 case PixelFormat32bppRGB
:
349 getpixel_32bppRGB(&r
,&g
,&b
,&a
,row
,x
);
351 case PixelFormat32bppARGB
:
352 getpixel_32bppARGB(&r
,&g
,&b
,&a
,row
,x
);
354 case PixelFormat32bppPARGB
:
355 getpixel_32bppPARGB(&r
,&g
,&b
,&a
,row
,x
);
357 case PixelFormat48bppRGB
:
358 getpixel_48bppRGB(&r
,&g
,&b
,&a
,row
,x
);
360 case PixelFormat64bppARGB
:
361 getpixel_64bppARGB(&r
,&g
,&b
,&a
,row
,x
);
363 case PixelFormat64bppPARGB
:
364 getpixel_64bppPARGB(&r
,&g
,&b
,&a
,row
,x
);
367 FIXME("not implemented for format 0x%x\n", bitmap
->format
);
368 return NotImplemented
;
371 if (bitmap
->format
& PixelFormatIndexed
)
372 *color
= bitmap
->image
.palette
->Entries
[index
];
374 *color
= a
<<24|r
<<16|g
<<8|b
;
379 static inline UINT
get_palette_index(BYTE r
, BYTE g
, BYTE b
, BYTE a
, ColorPalette
*palette
)
382 int best_distance
= 0x7fff;
386 if (!palette
) return 0;
387 /* This algorithm scans entire palette,
388 computes difference from desired color (all color components have equal weight)
389 and returns the index of color with least difference.
391 Note: Maybe it could be replaced with a better algorithm for better image quality
392 and performance, though better algorithm would probably need some pre-built lookup
393 tables and thus may actually be slower if this method is called only few times per
396 for(i
=0;i
<palette
->Count
;i
++) {
397 ARGB color
=palette
->Entries
[i
];
398 distance
=abs(b
-(color
& 0xff)) + abs(g
-(color
>>8 & 0xff)) + abs(r
-(color
>>16 & 0xff)) + abs(a
-(color
>>24 & 0xff));
399 if (distance
<best_distance
) {
400 best_distance
=distance
;
407 static inline void setpixel_8bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
408 BYTE
*row
, UINT x
, ColorPalette
*palette
)
410 BYTE index
= get_palette_index(r
,g
,b
,a
,palette
);
414 static inline void setpixel_1bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
415 BYTE
*row
, UINT x
, ColorPalette
*palette
)
417 row
[x
/8] = (row
[x
/8] & ~(1<<(7-x
%8))) | (get_palette_index(r
,g
,b
,a
,palette
)<<(7-x
%8));
420 static inline void setpixel_4bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
421 BYTE
*row
, UINT x
, ColorPalette
*palette
)
424 row
[x
/2] = (row
[x
/2] & 0xf0) | get_palette_index(r
,g
,b
,a
,palette
);
426 row
[x
/2] = (row
[x
/2] & 0x0f) | get_palette_index(r
,g
,b
,a
,palette
)<<4;
429 static inline void setpixel_16bppGrayScale(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
432 *((WORD
*)(row
)+x
) = (r
+g
+b
)*85;
435 static inline void setpixel_16bppRGB555(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
438 *((WORD
*)(row
)+x
) = (r
<<7&0x7c00)|
443 static inline void setpixel_16bppRGB565(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
446 *((WORD
*)(row
)+x
) = (r
<<8&0xf800)|
451 static inline void setpixel_16bppARGB1555(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
454 *((WORD
*)(row
)+x
) = (a
<<8&0x8000)|
460 static inline void setpixel_24bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
468 static inline void setpixel_32bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
471 *((DWORD
*)(row
)+x
) = (r
<<16)|(g
<<8)|b
;
474 static inline void setpixel_32bppARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
477 *((DWORD
*)(row
)+x
) = (a
<<24)|(r
<<16)|(g
<<8)|b
;
480 static inline void setpixel_32bppPARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
486 *((DWORD
*)(row
)+x
) = (a
<<24)|(r
<<16)|(g
<<8)|b
;
489 static inline void setpixel_48bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
492 row
[x
*6+5] = row
[x
*6+4] = r
;
493 row
[x
*6+3] = row
[x
*6+2] = g
;
494 row
[x
*6+1] = row
[x
*6] = b
;
497 static inline void setpixel_64bppARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
500 UINT64 a64
=a
, r64
=r
, g64
=g
, b64
=b
;
501 *((UINT64
*)(row
)+x
) = (a64
<<56)|(a64
<<48)|(r64
<<40)|(r64
<<32)|(g64
<<24)|(g64
<<16)|(b64
<<8)|b64
;
504 static inline void setpixel_64bppPARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
507 UINT64 a64
, r64
, g64
, b64
;
512 *((UINT64
*)(row
)+x
) = (a64
<<48)|(r64
<<32)|(g64
<<16)|b64
;
515 GpStatus WINGDIPAPI
GdipBitmapSetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
521 if(!bitmap
|| x
< 0 || y
< 0 || x
>= bitmap
->width
|| y
>= bitmap
->height
)
522 return InvalidParameter
;
529 row
= bitmap
->bits
+ bitmap
->stride
* y
;
531 switch (bitmap
->format
)
533 case PixelFormat16bppGrayScale
:
534 setpixel_16bppGrayScale(r
,g
,b
,a
,row
,x
);
536 case PixelFormat16bppRGB555
:
537 setpixel_16bppRGB555(r
,g
,b
,a
,row
,x
);
539 case PixelFormat16bppRGB565
:
540 setpixel_16bppRGB565(r
,g
,b
,a
,row
,x
);
542 case PixelFormat16bppARGB1555
:
543 setpixel_16bppARGB1555(r
,g
,b
,a
,row
,x
);
545 case PixelFormat24bppRGB
:
546 setpixel_24bppRGB(r
,g
,b
,a
,row
,x
);
548 case PixelFormat32bppRGB
:
549 setpixel_32bppRGB(r
,g
,b
,a
,row
,x
);
551 case PixelFormat32bppARGB
:
552 setpixel_32bppARGB(r
,g
,b
,a
,row
,x
);
554 case PixelFormat32bppPARGB
:
555 setpixel_32bppPARGB(r
,g
,b
,a
,row
,x
);
557 case PixelFormat48bppRGB
:
558 setpixel_48bppRGB(r
,g
,b
,a
,row
,x
);
560 case PixelFormat64bppARGB
:
561 setpixel_64bppARGB(r
,g
,b
,a
,row
,x
);
563 case PixelFormat64bppPARGB
:
564 setpixel_64bppPARGB(r
,g
,b
,a
,row
,x
);
566 case PixelFormat8bppIndexed
:
567 setpixel_8bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
569 case PixelFormat4bppIndexed
:
570 setpixel_4bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
572 case PixelFormat1bppIndexed
:
573 setpixel_1bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
576 FIXME("not implemented for format 0x%x\n", bitmap
->format
);
577 return NotImplemented
;
583 GpStatus
convert_pixels(INT width
, INT height
,
584 INT dst_stride
, BYTE
*dst_bits
, PixelFormat dst_format
,
585 INT src_stride
, const BYTE
*src_bits
, PixelFormat src_format
,
586 ColorPalette
*palette
)
590 if (src_format
== dst_format
||
591 (dst_format
== PixelFormat32bppRGB
&& PIXELFORMATBPP(src_format
) == 32))
593 UINT widthbytes
= PIXELFORMATBPP(src_format
) * width
/ 8;
594 for (y
=0; y
<height
; y
++)
595 memcpy(dst_bits
+dst_stride
*y
, src_bits
+src_stride
*y
, widthbytes
);
599 #define convert_indexed_to_rgb(getpixel_function, setpixel_function) do { \
600 for (y=0; y<height; y++) \
601 for (x=0; x<width; x++) { \
604 BYTE *color = (BYTE *)&argb; \
605 getpixel_function(&index, src_bits+src_stride*y, x); \
606 argb = (palette && index < palette->Count) ? palette->Entries[index] : 0; \
607 setpixel_function(color[2], color[1], color[0], color[3], dst_bits+dst_stride*y, x); \
612 #define convert_rgb_to_rgb(getpixel_function, setpixel_function) do { \
613 for (y=0; y<height; y++) \
614 for (x=0; x<width; x++) { \
616 getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
617 setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x); \
622 #define convert_rgb_to_indexed(getpixel_function, setpixel_function) do { \
623 for (y=0; y<height; y++) \
624 for (x=0; x<width; x++) { \
626 getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
627 setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x, palette); \
634 case PixelFormat1bppIndexed
:
637 case PixelFormat16bppGrayScale
:
638 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppGrayScale
);
639 case PixelFormat16bppRGB555
:
640 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppRGB555
);
641 case PixelFormat16bppRGB565
:
642 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppRGB565
);
643 case PixelFormat16bppARGB1555
:
644 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppARGB1555
);
645 case PixelFormat24bppRGB
:
646 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_24bppRGB
);
647 case PixelFormat32bppRGB
:
648 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppRGB
);
649 case PixelFormat32bppARGB
:
650 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppARGB
);
651 case PixelFormat32bppPARGB
:
652 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppPARGB
);
653 case PixelFormat48bppRGB
:
654 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_48bppRGB
);
655 case PixelFormat64bppARGB
:
656 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_64bppARGB
);
661 case PixelFormat4bppIndexed
:
664 case PixelFormat16bppGrayScale
:
665 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppGrayScale
);
666 case PixelFormat16bppRGB555
:
667 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppRGB555
);
668 case PixelFormat16bppRGB565
:
669 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppRGB565
);
670 case PixelFormat16bppARGB1555
:
671 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppARGB1555
);
672 case PixelFormat24bppRGB
:
673 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_24bppRGB
);
674 case PixelFormat32bppRGB
:
675 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppRGB
);
676 case PixelFormat32bppARGB
:
677 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppARGB
);
678 case PixelFormat32bppPARGB
:
679 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppPARGB
);
680 case PixelFormat48bppRGB
:
681 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_48bppRGB
);
682 case PixelFormat64bppARGB
:
683 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_64bppARGB
);
688 case PixelFormat8bppIndexed
:
691 case PixelFormat16bppGrayScale
:
692 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppGrayScale
);
693 case PixelFormat16bppRGB555
:
694 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppRGB555
);
695 case PixelFormat16bppRGB565
:
696 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppRGB565
);
697 case PixelFormat16bppARGB1555
:
698 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppARGB1555
);
699 case PixelFormat24bppRGB
:
700 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_24bppRGB
);
701 case PixelFormat32bppRGB
:
702 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppRGB
);
703 case PixelFormat32bppARGB
:
704 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppARGB
);
705 case PixelFormat32bppPARGB
:
706 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppPARGB
);
707 case PixelFormat48bppRGB
:
708 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_48bppRGB
);
709 case PixelFormat64bppARGB
:
710 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_64bppARGB
);
715 case PixelFormat16bppGrayScale
:
718 case PixelFormat1bppIndexed
:
719 convert_rgb_to_indexed(getpixel_16bppGrayScale
, setpixel_1bppIndexed
);
720 case PixelFormat8bppIndexed
:
721 convert_rgb_to_indexed(getpixel_16bppGrayScale
, setpixel_8bppIndexed
);
722 case PixelFormat16bppRGB555
:
723 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppRGB555
);
724 case PixelFormat16bppRGB565
:
725 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppRGB565
);
726 case PixelFormat16bppARGB1555
:
727 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppARGB1555
);
728 case PixelFormat24bppRGB
:
729 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_24bppRGB
);
730 case PixelFormat32bppRGB
:
731 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppRGB
);
732 case PixelFormat32bppARGB
:
733 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppARGB
);
734 case PixelFormat32bppPARGB
:
735 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppPARGB
);
736 case PixelFormat48bppRGB
:
737 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_48bppRGB
);
738 case PixelFormat64bppARGB
:
739 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_64bppARGB
);
744 case PixelFormat16bppRGB555
:
747 case PixelFormat1bppIndexed
:
748 convert_rgb_to_indexed(getpixel_16bppRGB555
, setpixel_1bppIndexed
);
749 case PixelFormat8bppIndexed
:
750 convert_rgb_to_indexed(getpixel_16bppRGB555
, setpixel_8bppIndexed
);
751 case PixelFormat16bppGrayScale
:
752 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppGrayScale
);
753 case PixelFormat16bppRGB565
:
754 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppRGB565
);
755 case PixelFormat16bppARGB1555
:
756 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppARGB1555
);
757 case PixelFormat24bppRGB
:
758 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_24bppRGB
);
759 case PixelFormat32bppRGB
:
760 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppRGB
);
761 case PixelFormat32bppARGB
:
762 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppARGB
);
763 case PixelFormat32bppPARGB
:
764 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppPARGB
);
765 case PixelFormat48bppRGB
:
766 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_48bppRGB
);
767 case PixelFormat64bppARGB
:
768 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_64bppARGB
);
773 case PixelFormat16bppRGB565
:
776 case PixelFormat1bppIndexed
:
777 convert_rgb_to_indexed(getpixel_16bppRGB565
, setpixel_1bppIndexed
);
778 case PixelFormat8bppIndexed
:
779 convert_rgb_to_indexed(getpixel_16bppRGB565
, setpixel_8bppIndexed
);
780 case PixelFormat16bppGrayScale
:
781 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppGrayScale
);
782 case PixelFormat16bppRGB555
:
783 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppRGB555
);
784 case PixelFormat16bppARGB1555
:
785 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppARGB1555
);
786 case PixelFormat24bppRGB
:
787 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_24bppRGB
);
788 case PixelFormat32bppRGB
:
789 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppRGB
);
790 case PixelFormat32bppARGB
:
791 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppARGB
);
792 case PixelFormat32bppPARGB
:
793 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppPARGB
);
794 case PixelFormat48bppRGB
:
795 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_48bppRGB
);
796 case PixelFormat64bppARGB
:
797 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_64bppARGB
);
802 case PixelFormat16bppARGB1555
:
805 case PixelFormat1bppIndexed
:
806 convert_rgb_to_indexed(getpixel_16bppARGB1555
, setpixel_1bppIndexed
);
807 case PixelFormat8bppIndexed
:
808 convert_rgb_to_indexed(getpixel_16bppARGB1555
, setpixel_8bppIndexed
);
809 case PixelFormat16bppGrayScale
:
810 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppGrayScale
);
811 case PixelFormat16bppRGB555
:
812 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppRGB555
);
813 case PixelFormat16bppRGB565
:
814 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppRGB565
);
815 case PixelFormat24bppRGB
:
816 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_24bppRGB
);
817 case PixelFormat32bppRGB
:
818 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppRGB
);
819 case PixelFormat32bppARGB
:
820 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppARGB
);
821 case PixelFormat32bppPARGB
:
822 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppPARGB
);
823 case PixelFormat48bppRGB
:
824 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_48bppRGB
);
825 case PixelFormat64bppARGB
:
826 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_64bppARGB
);
831 case PixelFormat24bppRGB
:
834 case PixelFormat1bppIndexed
:
835 convert_rgb_to_indexed(getpixel_24bppRGB
, setpixel_1bppIndexed
);
836 case PixelFormat8bppIndexed
:
837 convert_rgb_to_indexed(getpixel_24bppRGB
, setpixel_8bppIndexed
);
838 case PixelFormat16bppGrayScale
:
839 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppGrayScale
);
840 case PixelFormat16bppRGB555
:
841 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppRGB555
);
842 case PixelFormat16bppRGB565
:
843 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppRGB565
);
844 case PixelFormat16bppARGB1555
:
845 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppARGB1555
);
846 case PixelFormat32bppRGB
:
847 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppRGB
);
848 case PixelFormat32bppARGB
:
849 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppARGB
);
850 case PixelFormat32bppPARGB
:
851 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppPARGB
);
852 case PixelFormat48bppRGB
:
853 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_48bppRGB
);
854 case PixelFormat64bppARGB
:
855 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_64bppARGB
);
860 case PixelFormat32bppRGB
:
863 case PixelFormat1bppIndexed
:
864 convert_rgb_to_indexed(getpixel_32bppRGB
, setpixel_1bppIndexed
);
865 case PixelFormat8bppIndexed
:
866 convert_rgb_to_indexed(getpixel_32bppRGB
, setpixel_8bppIndexed
);
867 case PixelFormat16bppGrayScale
:
868 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppGrayScale
);
869 case PixelFormat16bppRGB555
:
870 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppRGB555
);
871 case PixelFormat16bppRGB565
:
872 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppRGB565
);
873 case PixelFormat16bppARGB1555
:
874 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppARGB1555
);
875 case PixelFormat24bppRGB
:
876 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_24bppRGB
);
877 case PixelFormat32bppARGB
:
878 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_32bppARGB
);
879 case PixelFormat32bppPARGB
:
880 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_32bppPARGB
);
881 case PixelFormat48bppRGB
:
882 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_48bppRGB
);
883 case PixelFormat64bppARGB
:
884 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_64bppARGB
);
889 case PixelFormat32bppARGB
:
892 case PixelFormat1bppIndexed
:
893 convert_rgb_to_indexed(getpixel_32bppARGB
, setpixel_1bppIndexed
);
894 case PixelFormat8bppIndexed
:
895 convert_rgb_to_indexed(getpixel_32bppARGB
, setpixel_8bppIndexed
);
896 case PixelFormat16bppGrayScale
:
897 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppGrayScale
);
898 case PixelFormat16bppRGB555
:
899 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppRGB555
);
900 case PixelFormat16bppRGB565
:
901 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppRGB565
);
902 case PixelFormat16bppARGB1555
:
903 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppARGB1555
);
904 case PixelFormat24bppRGB
:
905 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_24bppRGB
);
906 case PixelFormat32bppPARGB
:
907 convert_32bppARGB_to_32bppPARGB(width
, height
, dst_bits
, dst_stride
, src_bits
, src_stride
);
909 case PixelFormat48bppRGB
:
910 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_48bppRGB
);
911 case PixelFormat64bppARGB
:
912 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_64bppARGB
);
917 case PixelFormat32bppPARGB
:
920 case PixelFormat1bppIndexed
:
921 convert_rgb_to_indexed(getpixel_32bppPARGB
, setpixel_1bppIndexed
);
922 case PixelFormat8bppIndexed
:
923 convert_rgb_to_indexed(getpixel_32bppPARGB
, setpixel_8bppIndexed
);
924 case PixelFormat16bppGrayScale
:
925 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppGrayScale
);
926 case PixelFormat16bppRGB555
:
927 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppRGB555
);
928 case PixelFormat16bppRGB565
:
929 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppRGB565
);
930 case PixelFormat16bppARGB1555
:
931 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppARGB1555
);
932 case PixelFormat24bppRGB
:
933 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_24bppRGB
);
934 case PixelFormat32bppRGB
:
935 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_32bppRGB
);
936 case PixelFormat32bppARGB
:
937 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_32bppARGB
);
938 case PixelFormat48bppRGB
:
939 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_48bppRGB
);
940 case PixelFormat64bppARGB
:
941 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_64bppARGB
);
946 case PixelFormat48bppRGB
:
949 case PixelFormat1bppIndexed
:
950 convert_rgb_to_indexed(getpixel_48bppRGB
, setpixel_1bppIndexed
);
951 case PixelFormat8bppIndexed
:
952 convert_rgb_to_indexed(getpixel_48bppRGB
, setpixel_8bppIndexed
);
953 case PixelFormat16bppGrayScale
:
954 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppGrayScale
);
955 case PixelFormat16bppRGB555
:
956 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppRGB555
);
957 case PixelFormat16bppRGB565
:
958 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppRGB565
);
959 case PixelFormat16bppARGB1555
:
960 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppARGB1555
);
961 case PixelFormat24bppRGB
:
962 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_24bppRGB
);
963 case PixelFormat32bppRGB
:
964 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppRGB
);
965 case PixelFormat32bppARGB
:
966 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppARGB
);
967 case PixelFormat32bppPARGB
:
968 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppPARGB
);
969 case PixelFormat64bppARGB
:
970 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_64bppARGB
);
975 case PixelFormat64bppARGB
:
978 case PixelFormat1bppIndexed
:
979 convert_rgb_to_indexed(getpixel_64bppARGB
, setpixel_1bppIndexed
);
980 case PixelFormat8bppIndexed
:
981 convert_rgb_to_indexed(getpixel_64bppARGB
, setpixel_8bppIndexed
);
982 case PixelFormat16bppGrayScale
:
983 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppGrayScale
);
984 case PixelFormat16bppRGB555
:
985 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppRGB555
);
986 case PixelFormat16bppRGB565
:
987 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppRGB565
);
988 case PixelFormat16bppARGB1555
:
989 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppARGB1555
);
990 case PixelFormat24bppRGB
:
991 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_24bppRGB
);
992 case PixelFormat32bppRGB
:
993 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppRGB
);
994 case PixelFormat32bppARGB
:
995 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppARGB
);
996 case PixelFormat32bppPARGB
:
997 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppPARGB
);
998 case PixelFormat48bppRGB
:
999 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_48bppRGB
);
1004 case PixelFormat64bppPARGB
:
1007 case PixelFormat1bppIndexed
:
1008 convert_rgb_to_indexed(getpixel_64bppPARGB
, setpixel_1bppIndexed
);
1009 case PixelFormat8bppIndexed
:
1010 convert_rgb_to_indexed(getpixel_64bppPARGB
, setpixel_8bppIndexed
);
1011 case PixelFormat16bppGrayScale
:
1012 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppGrayScale
);
1013 case PixelFormat16bppRGB555
:
1014 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppRGB555
);
1015 case PixelFormat16bppRGB565
:
1016 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppRGB565
);
1017 case PixelFormat16bppARGB1555
:
1018 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppARGB1555
);
1019 case PixelFormat24bppRGB
:
1020 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_24bppRGB
);
1021 case PixelFormat32bppRGB
:
1022 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppRGB
);
1023 case PixelFormat32bppARGB
:
1024 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppARGB
);
1025 case PixelFormat32bppPARGB
:
1026 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppPARGB
);
1027 case PixelFormat48bppRGB
:
1028 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_48bppRGB
);
1029 case PixelFormat64bppARGB
:
1030 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_64bppARGB
);
1039 #undef convert_indexed_to_rgb
1040 #undef convert_rgb_to_rgb
1042 return NotImplemented
;
1045 /* This function returns a pointer to an array of pixels that represents the
1046 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
1047 * flags. It is correct behavior that a user who calls this function with write
1048 * privileges can write to the whole bitmap (not just the area in rect).
1050 * FIXME: only used portion of format is bits per pixel. */
1051 GpStatus WINGDIPAPI
GdipBitmapLockBits(GpBitmap
* bitmap
, GDIPCONST GpRect
* rect
,
1052 UINT flags
, PixelFormat format
, BitmapData
* lockeddata
)
1054 INT bitspp
= PIXELFORMATBPP(format
);
1055 GpRect act_rect
; /* actual rect to be used */
1058 TRACE("%p %p %d 0x%x %p\n", bitmap
, rect
, flags
, format
, lockeddata
);
1060 if(!lockeddata
|| !bitmap
)
1061 return InvalidParameter
;
1064 if(rect
->X
< 0 || rect
->Y
< 0 || (rect
->X
+ rect
->Width
> bitmap
->width
) ||
1065 (rect
->Y
+ rect
->Height
> bitmap
->height
) || !flags
)
1066 return InvalidParameter
;
1071 act_rect
.X
= act_rect
.Y
= 0;
1072 act_rect
.Width
= bitmap
->width
;
1073 act_rect
.Height
= bitmap
->height
;
1076 if(bitmap
->lockmode
)
1078 WARN("bitmap is already locked and cannot be locked again\n");
1082 if (bitmap
->bits
&& bitmap
->format
== format
&& !(flags
& ImageLockModeUserInputBuf
))
1084 /* no conversion is necessary; just use the bits directly */
1085 lockeddata
->Width
= act_rect
.Width
;
1086 lockeddata
->Height
= act_rect
.Height
;
1087 lockeddata
->PixelFormat
= format
;
1088 lockeddata
->Reserved
= flags
;
1089 lockeddata
->Stride
= bitmap
->stride
;
1090 lockeddata
->Scan0
= bitmap
->bits
+ (bitspp
/ 8) * act_rect
.X
+
1091 bitmap
->stride
* act_rect
.Y
;
1093 bitmap
->lockmode
= flags
| ImageLockModeRead
;
1099 /* Make sure we can convert to the requested format. */
1100 if (flags
& ImageLockModeRead
)
1102 stat
= convert_pixels(0, 0, 0, NULL
, format
, 0, NULL
, bitmap
->format
, NULL
);
1103 if (stat
== NotImplemented
)
1105 FIXME("cannot read bitmap from %x to %x\n", bitmap
->format
, format
);
1106 return NotImplemented
;
1110 /* If we're opening for writing, make sure we'll be able to write back in
1111 * the original format. */
1112 if (flags
& ImageLockModeWrite
)
1114 stat
= convert_pixels(0, 0, 0, NULL
, bitmap
->format
, 0, NULL
, format
, NULL
);
1115 if (stat
== NotImplemented
)
1117 FIXME("cannot write bitmap from %x to %x\n", format
, bitmap
->format
);
1118 return NotImplemented
;
1122 lockeddata
->Width
= act_rect
.Width
;
1123 lockeddata
->Height
= act_rect
.Height
;
1124 lockeddata
->PixelFormat
= format
;
1125 lockeddata
->Reserved
= flags
;
1127 if(!(flags
& ImageLockModeUserInputBuf
))
1129 lockeddata
->Stride
= (((act_rect
.Width
* bitspp
+ 7) / 8) + 3) & ~3;
1131 bitmap
->bitmapbits
= heap_alloc_zero(lockeddata
->Stride
* act_rect
.Height
);
1133 if (!bitmap
->bitmapbits
) return OutOfMemory
;
1135 lockeddata
->Scan0
= bitmap
->bitmapbits
;
1138 if (flags
& ImageLockModeRead
)
1140 static BOOL fixme
= FALSE
;
1142 if (!fixme
&& (PIXELFORMATBPP(bitmap
->format
) * act_rect
.X
) % 8 != 0)
1144 FIXME("Cannot copy rows that don't start at a whole byte.\n");
1148 stat
= convert_pixels(act_rect
.Width
, act_rect
.Height
,
1149 lockeddata
->Stride
, lockeddata
->Scan0
, format
,
1151 bitmap
->bits
+ bitmap
->stride
* act_rect
.Y
+ PIXELFORMATBPP(bitmap
->format
) * act_rect
.X
/ 8,
1152 bitmap
->format
, bitmap
->image
.palette
);
1156 heap_free(bitmap
->bitmapbits
);
1157 bitmap
->bitmapbits
= NULL
;
1162 bitmap
->lockmode
= flags
| ImageLockModeRead
;
1164 bitmap
->lockx
= act_rect
.X
;
1165 bitmap
->locky
= act_rect
.Y
;
1170 GpStatus WINGDIPAPI
GdipBitmapSetResolution(GpBitmap
* bitmap
, REAL xdpi
, REAL ydpi
)
1172 TRACE("(%p, %.2f, %.2f)\n", bitmap
, xdpi
, ydpi
);
1174 if (!bitmap
|| xdpi
== 0.0 || ydpi
== 0.0)
1175 return InvalidParameter
;
1177 bitmap
->image
.xres
= xdpi
;
1178 bitmap
->image
.yres
= ydpi
;
1183 GpStatus WINGDIPAPI
GdipBitmapUnlockBits(GpBitmap
* bitmap
,
1184 BitmapData
* lockeddata
)
1187 static BOOL fixme
= FALSE
;
1189 TRACE("(%p,%p)\n", bitmap
, lockeddata
);
1191 if(!bitmap
|| !lockeddata
)
1192 return InvalidParameter
;
1194 if(!bitmap
->lockmode
)
1197 if(!(lockeddata
->Reserved
& ImageLockModeWrite
)){
1198 if(!(--bitmap
->numlocks
))
1199 bitmap
->lockmode
= 0;
1201 heap_free(bitmap
->bitmapbits
);
1202 bitmap
->bitmapbits
= NULL
;
1206 if (!bitmap
->bitmapbits
&& !(lockeddata
->Reserved
& ImageLockModeUserInputBuf
))
1208 /* we passed a direct reference; no need to do anything */
1209 bitmap
->lockmode
= 0;
1210 bitmap
->numlocks
= 0;
1214 if (!fixme
&& (PIXELFORMATBPP(bitmap
->format
) * bitmap
->lockx
) % 8 != 0)
1216 FIXME("Cannot copy rows that don't start at a whole byte.\n");
1220 stat
= convert_pixels(lockeddata
->Width
, lockeddata
->Height
,
1222 bitmap
->bits
+ bitmap
->stride
* bitmap
->locky
+ PIXELFORMATBPP(bitmap
->format
) * bitmap
->lockx
/ 8,
1224 lockeddata
->Stride
, lockeddata
->Scan0
, lockeddata
->PixelFormat
, NULL
);
1228 ERR("failed to convert pixels; this should never happen\n");
1231 heap_free(bitmap
->bitmapbits
);
1232 bitmap
->bitmapbits
= NULL
;
1233 bitmap
->lockmode
= 0;
1234 bitmap
->numlocks
= 0;
1239 GpStatus WINGDIPAPI
GdipCloneBitmapArea(REAL x
, REAL y
, REAL width
, REAL height
,
1240 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
1245 TRACE("(%f,%f,%f,%f,0x%x,%p,%p)\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1247 if (!srcBitmap
|| !dstBitmap
|| srcBitmap
->image
.type
!= ImageTypeBitmap
||
1249 x
+ width
> srcBitmap
->width
|| y
+ height
> srcBitmap
->height
)
1251 TRACE("<-- InvalidParameter\n");
1252 return InvalidParameter
;
1255 if (format
== PixelFormatDontCare
)
1256 format
= srcBitmap
->format
;
1258 area
.X
= gdip_round(x
);
1259 area
.Y
= gdip_round(y
);
1260 area
.Width
= gdip_round(width
);
1261 area
.Height
= gdip_round(height
);
1263 stat
= GdipCreateBitmapFromScan0(area
.Width
, area
.Height
, 0, format
, NULL
, dstBitmap
);
1266 stat
= convert_pixels(area
.Width
, area
.Height
, (*dstBitmap
)->stride
, (*dstBitmap
)->bits
, (*dstBitmap
)->format
,
1268 srcBitmap
->bits
+ srcBitmap
->stride
* area
.Y
+ PIXELFORMATBPP(srcBitmap
->format
) * area
.X
/ 8,
1269 srcBitmap
->format
, srcBitmap
->image
.palette
);
1271 if (stat
== Ok
&& srcBitmap
->image
.palette
)
1273 ColorPalette
*src_palette
, *dst_palette
;
1275 src_palette
= srcBitmap
->image
.palette
;
1277 dst_palette
= heap_alloc_zero(sizeof(UINT
) * 2 + sizeof(ARGB
) * src_palette
->Count
);
1281 dst_palette
->Flags
= src_palette
->Flags
;
1282 dst_palette
->Count
= src_palette
->Count
;
1283 memcpy(dst_palette
->Entries
, src_palette
->Entries
, sizeof(ARGB
) * src_palette
->Count
);
1285 heap_free((*dstBitmap
)->image
.palette
);
1286 (*dstBitmap
)->image
.palette
= dst_palette
;
1293 GdipDisposeImage((GpImage
*)*dstBitmap
);
1302 GpStatus WINGDIPAPI
GdipCloneBitmapAreaI(INT x
, INT y
, INT width
, INT height
,
1303 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
1305 TRACE("(%i,%i,%i,%i,0x%x,%p,%p)\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1307 return GdipCloneBitmapArea(x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1310 GpStatus WINGDIPAPI
GdipCloneImage(GpImage
*image
, GpImage
**cloneImage
)
1312 GpStatus stat
= GenericError
;
1314 TRACE("%p, %p\n", image
, cloneImage
);
1316 if (!image
|| !cloneImage
)
1317 return InvalidParameter
;
1326 hr
= CreateStreamOnHGlobal(0, TRUE
, &stream
);
1328 return GenericError
;
1330 hr
= IPicture_SaveAsFile(image
->picture
, stream
, FALSE
, &size
);
1333 WARN("Failed to save image on stream\n");
1337 /* Set seek pointer back to the beginning of the picture */
1339 hr
= IStream_Seek(stream
, move
, STREAM_SEEK_SET
, NULL
);
1343 stat
= GdipLoadImageFromStream(stream
, cloneImage
);
1344 if (stat
!= Ok
) WARN("Failed to load image from stream\n");
1347 IStream_Release(stream
);
1350 else if (image
->type
== ImageTypeBitmap
)
1352 GpBitmap
*bitmap
= (GpBitmap
*)image
;
1354 return GdipCloneBitmapAreaI(0, 0, bitmap
->width
, bitmap
->height
,
1355 bitmap
->format
, bitmap
, (GpBitmap
**)cloneImage
);
1357 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
1359 GpMetafile
*result
, *metafile
;
1361 metafile
= (GpMetafile
*)image
;
1363 result
= heap_alloc_zero(sizeof(*result
));
1367 result
->image
.type
= ImageTypeMetafile
;
1368 result
->image
.format
= image
->format
;
1369 result
->image
.flags
= image
->flags
;
1370 result
->image
.frame_count
= 1;
1371 result
->image
.xres
= image
->xres
;
1372 result
->image
.yres
= image
->yres
;
1373 result
->bounds
= metafile
->bounds
;
1374 result
->unit
= metafile
->unit
;
1375 result
->metafile_type
= metafile
->metafile_type
;
1376 result
->hemf
= CopyEnhMetaFileW(metafile
->hemf
, NULL
);
1384 *cloneImage
= &result
->image
;
1389 WARN("GpImage with no image data (metafile in wrong state?)\n");
1390 return InvalidParameter
;
1394 GpStatus WINGDIPAPI
GdipCreateBitmapFromFile(GDIPCONST WCHAR
* filename
,
1400 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
1402 if(!filename
|| !bitmap
)
1403 return InvalidParameter
;
1407 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
1412 stat
= GdipCreateBitmapFromStream(stream
, bitmap
);
1414 IStream_Release(stream
);
1419 GpStatus WINGDIPAPI
GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO
* info
,
1420 VOID
*bits
, GpBitmap
**bitmap
)
1422 DWORD height
, stride
;
1425 FIXME("(%p, %p, %p) - partially implemented\n", info
, bits
, bitmap
);
1427 if (!info
|| !bits
|| !bitmap
)
1428 return InvalidParameter
;
1430 height
= abs(info
->bmiHeader
.biHeight
);
1431 stride
= ((info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
+ 31) >> 3) & ~3;
1433 if(info
->bmiHeader
.biHeight
> 0) /* bottom-up */
1435 bits
= (BYTE
*)bits
+ (height
- 1) * stride
;
1439 switch(info
->bmiHeader
.biBitCount
) {
1441 format
= PixelFormat1bppIndexed
;
1444 format
= PixelFormat4bppIndexed
;
1447 format
= PixelFormat8bppIndexed
;
1450 format
= PixelFormat16bppRGB555
;
1453 format
= PixelFormat24bppRGB
;
1456 format
= PixelFormat32bppRGB
;
1459 FIXME("don't know how to handle %d bpp\n", info
->bmiHeader
.biBitCount
);
1461 return InvalidParameter
;
1464 return GdipCreateBitmapFromScan0(info
->bmiHeader
.biWidth
, height
, stride
, format
,
1470 GpStatus WINGDIPAPI
GdipCreateBitmapFromFileICM(GDIPCONST WCHAR
* filename
,
1473 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
1475 return GdipCreateBitmapFromFile(filename
, bitmap
);
1478 GpStatus WINGDIPAPI
GdipCreateBitmapFromResource(HINSTANCE hInstance
,
1479 GDIPCONST WCHAR
* lpBitmapName
, GpBitmap
** bitmap
)
1482 GpStatus stat
= InvalidParameter
;
1484 TRACE("%p (%s) %p\n", hInstance
, debugstr_w(lpBitmapName
), bitmap
);
1486 if(!lpBitmapName
|| !bitmap
)
1487 return InvalidParameter
;
1490 hbm
= LoadImageW(hInstance
, lpBitmapName
, IMAGE_BITMAP
, 0, 0,
1491 LR_CREATEDIBSECTION
);
1494 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, bitmap
);
1501 static inline DWORD
blend_argb_no_bkgnd_alpha(DWORD src
, DWORD bkgnd
)
1504 BYTE g
= (BYTE
)(src
>> 8);
1505 BYTE r
= (BYTE
)(src
>> 16);
1506 DWORD alpha
= (BYTE
)(src
>> 24);
1507 return ((b
+ ((BYTE
)bkgnd
* (255 - alpha
) + 127) / 255) |
1508 (g
+ ((BYTE
)(bkgnd
>> 8) * (255 - alpha
) + 127) / 255) << 8 |
1509 (r
+ ((BYTE
)(bkgnd
>> 16) * (255 - alpha
) + 127) / 255) << 16 |
1513 GpStatus WINGDIPAPI
GdipCreateHBITMAPFromBitmap(GpBitmap
* bitmap
,
1514 HBITMAP
* hbmReturn
, ARGB background
)
1519 BITMAPINFOHEADER bih
;
1521 BitmapData lockeddata
;
1522 TRACE("(%p,%p,%x)\n", bitmap
, hbmReturn
, background
);
1524 if (!bitmap
|| !hbmReturn
) return InvalidParameter
;
1526 GdipGetImageWidth((GpImage
*)bitmap
, &width
);
1527 GdipGetImageHeight((GpImage
*)bitmap
, &height
);
1529 bih
.biSize
= sizeof(bih
);
1530 bih
.biWidth
= width
;
1531 bih
.biHeight
= height
;
1533 bih
.biBitCount
= 32;
1534 bih
.biCompression
= BI_RGB
;
1535 bih
.biSizeImage
= 0;
1536 bih
.biXPelsPerMeter
= 0;
1537 bih
.biYPelsPerMeter
= 0;
1539 bih
.biClrImportant
= 0;
1541 result
= CreateDIBSection(0, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1545 lockeddata
.Stride
= -width
* 4;
1546 lockeddata
.Scan0
= bits
+ (width
* 4 * (height
- 1));
1548 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1549 PixelFormat32bppPARGB
, &lockeddata
);
1552 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1554 if (stat
== Ok
&& (background
& 0xffffff))
1558 for (ptr
= (DWORD
*)bits
, i
= 0; i
< width
* height
; ptr
++, i
++)
1560 if ((*ptr
& 0xff000000) == 0xff000000) continue;
1561 *ptr
= blend_argb_no_bkgnd_alpha(*ptr
, background
);
1566 stat
= GenericError
;
1568 if (stat
!= Ok
&& result
)
1570 DeleteObject(result
);
1574 *hbmReturn
= result
;
1579 GpStatus WINGDIPAPI
GdipCreateBitmapFromGraphics(INT width
, INT height
,
1580 GpGraphics
* target
, GpBitmap
** bitmap
)
1584 TRACE("(%d, %d, %p, %p)\n", width
, height
, target
, bitmap
);
1586 if(!target
|| !bitmap
)
1587 return InvalidParameter
;
1589 ret
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat32bppPARGB
,
1594 GdipGetDpiX(target
, &(*bitmap
)->image
.xres
);
1595 GdipGetDpiY(target
, &(*bitmap
)->image
.yres
);
1601 GpStatus WINGDIPAPI
GdipCreateBitmapFromHICON(HICON hicon
, GpBitmap
** bitmap
)
1607 UINT width
, height
, stride
;
1609 BitmapData lockeddata
;
1613 BITMAPINFOHEADER bih
;
1618 TRACE("%p, %p\n", hicon
, bitmap
);
1620 if(!bitmap
|| !GetIconInfo(hicon
, &iinfo
))
1621 return InvalidParameter
;
1623 /* get the size of the icon */
1624 ret
= GetObjectA(iinfo
.hbmColor
? iinfo
.hbmColor
: iinfo
.hbmMask
, sizeof(bm
), &bm
);
1626 DeleteObject(iinfo
.hbmColor
);
1627 DeleteObject(iinfo
.hbmMask
);
1628 return GenericError
;
1632 height
= iinfo
.hbmColor
? abs(bm
.bmHeight
) : abs(bm
.bmHeight
) / 2;
1635 stat
= GdipCreateBitmapFromScan0(width
, height
, stride
, PixelFormat32bppARGB
, NULL
, bitmap
);
1637 DeleteObject(iinfo
.hbmColor
);
1638 DeleteObject(iinfo
.hbmMask
);
1645 rect
.Height
= height
;
1647 stat
= GdipBitmapLockBits(*bitmap
, &rect
, ImageLockModeWrite
, PixelFormat32bppARGB
, &lockeddata
);
1649 DeleteObject(iinfo
.hbmColor
);
1650 DeleteObject(iinfo
.hbmMask
);
1651 GdipDisposeImage((GpImage
*)*bitmap
);
1655 bih
.biSize
= sizeof(bih
);
1656 bih
.biWidth
= width
;
1657 bih
.biHeight
= iinfo
.hbmColor
? -height
: -height
* 2;
1659 bih
.biBitCount
= 32;
1660 bih
.biCompression
= BI_RGB
;
1661 bih
.biSizeImage
= 0;
1662 bih
.biXPelsPerMeter
= 0;
1663 bih
.biYPelsPerMeter
= 0;
1665 bih
.biClrImportant
= 0;
1667 screendc
= CreateCompatibleDC(0);
1670 GetDIBits(screendc
, iinfo
.hbmColor
, 0, height
, lockeddata
.Scan0
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1672 if (bm
.bmBitsPixel
== 32)
1676 /* If any pixel has a non-zero alpha, ignore hbmMask */
1677 src
= (DWORD
*)lockeddata
.Scan0
;
1678 for (x
=0; x
<width
&& !has_alpha
; x
++)
1679 for (y
=0; y
<height
&& !has_alpha
; y
++)
1680 if ((*src
++ & 0xff000000) != 0)
1683 else has_alpha
= FALSE
;
1687 GetDIBits(screendc
, iinfo
.hbmMask
, 0, height
, lockeddata
.Scan0
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1695 BYTE
*bits
= heap_alloc(height
* stride
);
1697 /* read alpha data from the mask */
1699 GetDIBits(screendc
, iinfo
.hbmMask
, 0, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1701 GetDIBits(screendc
, iinfo
.hbmMask
, height
, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1704 dst_row
= lockeddata
.Scan0
;
1705 for (y
=0; y
<height
; y
++)
1707 dst
= (DWORD
*)dst_row
;
1708 for (x
=0; x
<height
; x
++)
1710 DWORD src_value
= *src
++;
1714 *dst
++ |= 0xff000000;
1716 dst_row
+= lockeddata
.Stride
;
1723 /* set constant alpha of 255 */
1724 dst_row
= lockeddata
.Scan0
;
1725 for (y
=0; y
<height
; y
++)
1727 dst
= (DWORD
*)dst_row
;
1728 for (x
=0; x
<height
; x
++)
1729 *dst
++ |= 0xff000000;
1730 dst_row
+= lockeddata
.Stride
;
1737 DeleteObject(iinfo
.hbmColor
);
1738 DeleteObject(iinfo
.hbmMask
);
1740 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
1745 static void generate_halftone_palette(ARGB
*entries
, UINT count
)
1747 static const BYTE halftone_values
[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1750 for (i
=0; i
<8 && i
<count
; i
++)
1752 entries
[i
] = 0xff000000;
1753 if (i
&1) entries
[i
] |= 0x800000;
1754 if (i
&2) entries
[i
] |= 0x8000;
1755 if (i
&4) entries
[i
] |= 0x80;
1759 entries
[i
] = 0xffc0c0c0;
1761 for (i
=9; i
<16 && i
<count
; i
++)
1763 entries
[i
] = 0xff000000;
1764 if (i
&1) entries
[i
] |= 0xff0000;
1765 if (i
&2) entries
[i
] |= 0xff00;
1766 if (i
&4) entries
[i
] |= 0xff;
1769 for (i
=16; i
<40 && i
<count
; i
++)
1774 for (i
=40; i
<256 && i
<count
; i
++)
1776 entries
[i
] = 0xff000000;
1777 entries
[i
] |= halftone_values
[(i
-40)%6];
1778 entries
[i
] |= halftone_values
[((i
-40)/6)%6] << 8;
1779 entries
[i
] |= halftone_values
[((i
-40)/36)%6] << 16;
1783 static GpStatus
get_screen_resolution(REAL
*xres
, REAL
*yres
)
1785 HDC screendc
= CreateCompatibleDC(0);
1787 if (!screendc
) return GenericError
;
1789 *xres
= (REAL
)GetDeviceCaps(screendc
, LOGPIXELSX
);
1790 *yres
= (REAL
)GetDeviceCaps(screendc
, LOGPIXELSY
);
1797 GpStatus WINGDIPAPI
GdipCreateBitmapFromScan0(INT width
, INT height
, INT stride
,
1798 PixelFormat format
, BYTE
* scan0
, GpBitmap
** bitmap
)
1800 HBITMAP hbitmap
=NULL
;
1801 INT row_size
, dib_stride
;
1802 BYTE
*bits
=NULL
, *own_bits
=NULL
;
1806 TRACE("%d %d %d 0x%x %p %p\n", width
, height
, stride
, format
, scan0
, bitmap
);
1808 if (!bitmap
) return InvalidParameter
;
1810 if(width
<= 0 || height
<= 0 || (scan0
&& (stride
% 4))){
1812 return InvalidParameter
;
1815 if(scan0
&& !stride
)
1816 return InvalidParameter
;
1818 stat
= get_screen_resolution(&xres
, &yres
);
1819 if (stat
!= Ok
) return stat
;
1821 row_size
= (width
* PIXELFORMATBPP(format
)+7) / 8;
1822 dib_stride
= (row_size
+ 3) & ~3;
1825 stride
= dib_stride
;
1827 if (format
& PixelFormatGDI
&& !(format
& (PixelFormatAlpha
|PixelFormatIndexed
)) && !scan0
)
1829 char bmibuf
[FIELD_OFFSET(BITMAPINFO
, bmiColors
[256])];
1830 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
1832 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1833 pbmi
->bmiHeader
.biWidth
= width
;
1834 pbmi
->bmiHeader
.biHeight
= -height
;
1835 pbmi
->bmiHeader
.biPlanes
= 1;
1836 /* FIXME: use the rest of the data from format */
1837 pbmi
->bmiHeader
.biBitCount
= PIXELFORMATBPP(format
);
1838 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
1839 pbmi
->bmiHeader
.biSizeImage
= 0;
1840 pbmi
->bmiHeader
.biXPelsPerMeter
= 0;
1841 pbmi
->bmiHeader
.biYPelsPerMeter
= 0;
1842 pbmi
->bmiHeader
.biClrUsed
= 0;
1843 pbmi
->bmiHeader
.biClrImportant
= 0;
1845 hbitmap
= CreateDIBSection(0, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1847 if (!hbitmap
) return GenericError
;
1849 stride
= dib_stride
;
1853 /* Not a GDI format; don't try to make an HBITMAP. */
1858 INT size
= abs(stride
) * height
;
1860 own_bits
= bits
= heap_alloc_zero(size
);
1861 if (!own_bits
) return OutOfMemory
;
1864 bits
+= stride
* (1 - height
);
1868 *bitmap
= heap_alloc_zero(sizeof(GpBitmap
));
1871 DeleteObject(hbitmap
);
1872 heap_free(own_bits
);
1876 (*bitmap
)->image
.type
= ImageTypeBitmap
;
1877 memcpy(&(*bitmap
)->image
.format
, &ImageFormatMemoryBMP
, sizeof(GUID
));
1878 (*bitmap
)->image
.flags
= ImageFlagsNone
;
1879 (*bitmap
)->image
.frame_count
= 1;
1880 (*bitmap
)->image
.current_frame
= 0;
1881 (*bitmap
)->image
.palette
= NULL
;
1882 (*bitmap
)->image
.xres
= xres
;
1883 (*bitmap
)->image
.yres
= yres
;
1884 (*bitmap
)->width
= width
;
1885 (*bitmap
)->height
= height
;
1886 (*bitmap
)->format
= format
;
1887 (*bitmap
)->image
.picture
= NULL
;
1888 (*bitmap
)->image
.decoder
= NULL
;
1889 (*bitmap
)->hbitmap
= hbitmap
;
1890 (*bitmap
)->hdc
= NULL
;
1891 (*bitmap
)->bits
= bits
;
1892 (*bitmap
)->stride
= stride
;
1893 (*bitmap
)->own_bits
= own_bits
;
1894 (*bitmap
)->metadata_reader
= NULL
;
1895 (*bitmap
)->prop_count
= 0;
1896 (*bitmap
)->prop_item
= NULL
;
1898 /* set format-related flags */
1899 if (format
& (PixelFormatAlpha
|PixelFormatPAlpha
|PixelFormatIndexed
))
1900 (*bitmap
)->image
.flags
|= ImageFlagsHasAlpha
;
1902 if (format
== PixelFormat1bppIndexed
||
1903 format
== PixelFormat4bppIndexed
||
1904 format
== PixelFormat8bppIndexed
)
1906 (*bitmap
)->image
.palette
= heap_alloc_zero(sizeof(UINT
) * 2 + sizeof(ARGB
) * (1 << PIXELFORMATBPP(format
)));
1908 if (!(*bitmap
)->image
.palette
)
1910 GdipDisposeImage(&(*bitmap
)->image
);
1915 (*bitmap
)->image
.palette
->Count
= 1 << PIXELFORMATBPP(format
);
1917 if (format
== PixelFormat1bppIndexed
)
1919 (*bitmap
)->image
.palette
->Flags
= PaletteFlagsGrayScale
;
1920 (*bitmap
)->image
.palette
->Entries
[0] = 0xff000000;
1921 (*bitmap
)->image
.palette
->Entries
[1] = 0xffffffff;
1925 if (format
== PixelFormat8bppIndexed
)
1926 (*bitmap
)->image
.palette
->Flags
= PaletteFlagsHalftone
;
1928 generate_halftone_palette((*bitmap
)->image
.palette
->Entries
,
1929 (*bitmap
)->image
.palette
->Count
);
1933 TRACE("<-- %p\n", *bitmap
);
1938 GpStatus WINGDIPAPI
GdipCreateBitmapFromStream(IStream
* stream
,
1943 TRACE("%p %p\n", stream
, bitmap
);
1945 stat
= GdipLoadImageFromStream(stream
, (GpImage
**) bitmap
);
1950 if((*bitmap
)->image
.type
!= ImageTypeBitmap
){
1951 GdipDisposeImage(&(*bitmap
)->image
);
1953 return GenericError
; /* FIXME: what error to return? */
1960 GpStatus WINGDIPAPI
GdipCreateBitmapFromStreamICM(IStream
* stream
,
1963 TRACE("%p %p\n", stream
, bitmap
);
1965 return GdipCreateBitmapFromStream(stream
, bitmap
);
1968 GpStatus WINGDIPAPI
GdipCreateCachedBitmap(GpBitmap
*bitmap
, GpGraphics
*graphics
,
1969 GpCachedBitmap
**cachedbmp
)
1973 TRACE("%p %p %p\n", bitmap
, graphics
, cachedbmp
);
1975 if(!bitmap
|| !graphics
|| !cachedbmp
)
1976 return InvalidParameter
;
1978 *cachedbmp
= heap_alloc_zero(sizeof(GpCachedBitmap
));
1982 stat
= GdipCloneImage(&(bitmap
->image
), &(*cachedbmp
)->image
);
1984 heap_free(*cachedbmp
);
1991 GpStatus WINGDIPAPI
GdipCreateHICONFromBitmap(GpBitmap
*bitmap
, HICON
*hicon
)
1994 BitmapData lockeddata
;
1995 ULONG andstride
, xorstride
, bitssize
;
1996 LPBYTE andbits
, xorbits
, androw
, xorrow
, srcrow
;
1999 TRACE("(%p, %p)\n", bitmap
, hicon
);
2001 if (!bitmap
|| !hicon
)
2002 return InvalidParameter
;
2004 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
,
2005 PixelFormat32bppPARGB
, &lockeddata
);
2008 andstride
= ((lockeddata
.Width
+31)/32)*4;
2009 xorstride
= lockeddata
.Width
*4;
2010 bitssize
= (andstride
+ xorstride
) * lockeddata
.Height
;
2012 andbits
= heap_alloc_zero(bitssize
);
2016 xorbits
= andbits
+ andstride
* lockeddata
.Height
;
2018 for (y
=0; y
<lockeddata
.Height
; y
++)
2020 srcrow
= ((LPBYTE
)lockeddata
.Scan0
) + lockeddata
.Stride
* y
;
2022 androw
= andbits
+ andstride
* y
;
2023 for (x
=0; x
<lockeddata
.Width
; x
++)
2024 if (srcrow
[3+4*x
] >= 128)
2025 androw
[x
/8] |= 1 << (7-x
%8);
2027 xorrow
= xorbits
+ xorstride
* y
;
2028 memcpy(xorrow
, srcrow
, xorstride
);
2031 *hicon
= CreateIcon(NULL
, lockeddata
.Width
, lockeddata
.Height
, 1, 32,
2039 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
2045 GpStatus WINGDIPAPI
GdipDeleteCachedBitmap(GpCachedBitmap
*cachedbmp
)
2047 TRACE("%p\n", cachedbmp
);
2050 return InvalidParameter
;
2052 GdipDisposeImage(cachedbmp
->image
);
2053 heap_free(cachedbmp
);
2058 GpStatus WINGDIPAPI
GdipDrawCachedBitmap(GpGraphics
*graphics
,
2059 GpCachedBitmap
*cachedbmp
, INT x
, INT y
)
2061 TRACE("%p %p %d %d\n", graphics
, cachedbmp
, x
, y
);
2063 if(!graphics
|| !cachedbmp
)
2064 return InvalidParameter
;
2066 return GdipDrawImage(graphics
, cachedbmp
->image
, (REAL
)x
, (REAL
)y
);
2069 /* Internal utility function: Replace the image data of dst with that of src,
2071 static void move_bitmap(GpBitmap
*dst
, GpBitmap
*src
, BOOL clobber_palette
)
2073 assert(src
->image
.type
== ImageTypeBitmap
);
2074 assert(dst
->image
.type
== ImageTypeBitmap
);
2076 heap_free(dst
->bitmapbits
);
2077 heap_free(dst
->own_bits
);
2079 DeleteObject(dst
->hbitmap
);
2081 if (clobber_palette
)
2083 heap_free(dst
->image
.palette
);
2084 dst
->image
.palette
= src
->image
.palette
;
2087 heap_free(src
->image
.palette
);
2089 dst
->image
.xres
= src
->image
.xres
;
2090 dst
->image
.yres
= src
->image
.yres
;
2091 dst
->width
= src
->width
;
2092 dst
->height
= src
->height
;
2093 dst
->format
= src
->format
;
2094 dst
->hbitmap
= src
->hbitmap
;
2095 dst
->hdc
= src
->hdc
;
2096 dst
->bits
= src
->bits
;
2097 dst
->stride
= src
->stride
;
2098 dst
->own_bits
= src
->own_bits
;
2099 if (dst
->metadata_reader
)
2100 IWICMetadataReader_Release(dst
->metadata_reader
);
2101 dst
->metadata_reader
= src
->metadata_reader
;
2102 heap_free(dst
->prop_item
);
2103 dst
->prop_item
= src
->prop_item
;
2104 dst
->prop_count
= src
->prop_count
;
2105 if (dst
->image
.decoder
)
2106 IWICBitmapDecoder_Release(dst
->image
.decoder
);
2107 dst
->image
.decoder
= src
->image
.decoder
;
2108 dst
->image
.frame_count
= src
->image
.frame_count
;
2109 dst
->image
.current_frame
= src
->image
.current_frame
;
2110 dst
->image
.format
= src
->image
.format
;
2112 src
->image
.type
= ~0;
2116 static GpStatus
free_image_data(GpImage
*image
)
2119 return InvalidParameter
;
2121 if (image
->type
== ImageTypeBitmap
)
2123 heap_free(((GpBitmap
*)image
)->bitmapbits
);
2124 heap_free(((GpBitmap
*)image
)->own_bits
);
2125 DeleteDC(((GpBitmap
*)image
)->hdc
);
2126 DeleteObject(((GpBitmap
*)image
)->hbitmap
);
2127 if (((GpBitmap
*)image
)->metadata_reader
)
2128 IWICMetadataReader_Release(((GpBitmap
*)image
)->metadata_reader
);
2129 heap_free(((GpBitmap
*)image
)->prop_item
);
2131 else if (image
->type
== ImageTypeMetafile
)
2133 GpMetafile
*metafile
= (GpMetafile
*)image
;
2134 heap_free(metafile
->comment_data
);
2135 DeleteEnhMetaFile(CloseEnhMetaFile(metafile
->record_dc
));
2136 if (!metafile
->preserve_hemf
)
2137 DeleteEnhMetaFile(metafile
->hemf
);
2138 if (metafile
->record_graphics
)
2140 WARN("metafile closed while recording\n");
2141 /* not sure what to do here; for now just prevent the graphics from functioning or using this object */
2142 metafile
->record_graphics
->image
= NULL
;
2143 metafile
->record_graphics
->busy
= TRUE
;
2145 if (metafile
->record_stream
)
2147 IStream_Release(metafile
->record_stream
);
2152 WARN("invalid image: %p\n", image
);
2156 IPicture_Release(image
->picture
);
2158 IWICBitmapDecoder_Release(image
->decoder
);
2159 heap_free(image
->palette
);
2164 GpStatus WINGDIPAPI
GdipDisposeImage(GpImage
*image
)
2168 TRACE("%p\n", image
);
2170 status
= free_image_data(image
);
2171 if (status
!= Ok
) return status
;
2178 GpStatus WINGDIPAPI
GdipFindFirstImageItem(GpImage
*image
, ImageItemData
* item
)
2182 TRACE("(%p,%p)\n", image
, item
);
2185 return InvalidParameter
;
2188 FIXME("not implemented\n");
2190 return NotImplemented
;
2193 GpStatus WINGDIPAPI
GdipGetImageItemData(GpImage
*image
, ImageItemData
*item
)
2197 TRACE("(%p,%p)\n", image
, item
);
2200 FIXME("not implemented\n");
2202 return NotImplemented
;
2205 GpStatus WINGDIPAPI
GdipGetImageBounds(GpImage
*image
, GpRectF
*srcRect
,
2208 TRACE("%p %p %p\n", image
, srcRect
, srcUnit
);
2210 if(!image
|| !srcRect
|| !srcUnit
)
2211 return InvalidParameter
;
2212 if(image
->type
== ImageTypeMetafile
){
2213 *srcRect
= ((GpMetafile
*)image
)->bounds
;
2214 *srcUnit
= ((GpMetafile
*)image
)->unit
;
2216 else if(image
->type
== ImageTypeBitmap
){
2217 srcRect
->X
= srcRect
->Y
= 0.0;
2218 srcRect
->Width
= (REAL
) ((GpBitmap
*)image
)->width
;
2219 srcRect
->Height
= (REAL
) ((GpBitmap
*)image
)->height
;
2220 *srcUnit
= UnitPixel
;
2223 srcRect
->X
= srcRect
->Y
= 0.0;
2224 srcRect
->Width
= ipicture_pixel_width(image
->picture
);
2225 srcRect
->Height
= ipicture_pixel_height(image
->picture
);
2226 *srcUnit
= UnitPixel
;
2229 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect
->X
, srcRect
->Y
,
2230 srcRect
->Width
, srcRect
->Height
, *srcUnit
);
2235 GpStatus WINGDIPAPI
GdipGetImageDimension(GpImage
*image
, REAL
*width
,
2238 TRACE("%p %p %p\n", image
, width
, height
);
2240 if(!image
|| !height
|| !width
)
2241 return InvalidParameter
;
2243 if(image
->type
== ImageTypeMetafile
){
2244 *height
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Height
, ((GpMetafile
*)image
)->unit
, image
->yres
);
2245 *width
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Width
, ((GpMetafile
*)image
)->unit
, image
->xres
);
2247 else if(image
->type
== ImageTypeBitmap
){
2248 *height
= ((GpBitmap
*)image
)->height
;
2249 *width
= ((GpBitmap
*)image
)->width
;
2252 *height
= ipicture_pixel_height(image
->picture
);
2253 *width
= ipicture_pixel_width(image
->picture
);
2256 TRACE("returning (%f, %f)\n", *height
, *width
);
2260 GpStatus WINGDIPAPI
GdipGetImageGraphicsContext(GpImage
*image
,
2261 GpGraphics
**graphics
)
2266 TRACE("%p %p\n", image
, graphics
);
2268 if(!image
|| !graphics
)
2269 return InvalidParameter
;
2271 if (image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)image
)->hbitmap
)
2273 hdc
= ((GpBitmap
*)image
)->hdc
;
2276 hdc
= CreateCompatibleDC(0);
2277 SelectObject(hdc
, ((GpBitmap
*)image
)->hbitmap
);
2278 ((GpBitmap
*)image
)->hdc
= hdc
;
2281 stat
= GdipCreateFromHDC(hdc
, graphics
);
2285 (*graphics
)->image
= image
;
2286 (*graphics
)->xres
= image
->xres
;
2287 (*graphics
)->yres
= image
->yres
;
2290 else if (image
->type
== ImageTypeMetafile
)
2291 stat
= METAFILE_GetGraphicsContext((GpMetafile
*)image
, graphics
);
2293 stat
= graphics_from_image(image
, graphics
);
2298 GpStatus WINGDIPAPI
GdipGetImageHeight(GpImage
*image
, UINT
*height
)
2300 TRACE("%p %p\n", image
, height
);
2302 if(!image
|| !height
)
2303 return InvalidParameter
;
2305 if(image
->type
== ImageTypeMetafile
)
2306 *height
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Height
, ((GpMetafile
*)image
)->unit
, image
->yres
);
2307 else if(image
->type
== ImageTypeBitmap
)
2308 *height
= ((GpBitmap
*)image
)->height
;
2310 *height
= ipicture_pixel_height(image
->picture
);
2312 TRACE("returning %d\n", *height
);
2317 GpStatus WINGDIPAPI
GdipGetImageHorizontalResolution(GpImage
*image
, REAL
*res
)
2320 return InvalidParameter
;
2324 TRACE("(%p) <-- %0.2f\n", image
, *res
);
2329 GpStatus WINGDIPAPI
GdipGetImagePaletteSize(GpImage
*image
, INT
*size
)
2331 TRACE("%p %p\n", image
, size
);
2334 return InvalidParameter
;
2336 if (!image
->palette
|| image
->palette
->Count
== 0)
2337 *size
= sizeof(ColorPalette
);
2339 *size
= sizeof(UINT
)*2 + sizeof(ARGB
)*image
->palette
->Count
;
2341 TRACE("<-- %u\n", *size
);
2346 /* FIXME: test this function for non-bitmap types */
2347 GpStatus WINGDIPAPI
GdipGetImagePixelFormat(GpImage
*image
, PixelFormat
*format
)
2349 TRACE("%p %p\n", image
, format
);
2351 if(!image
|| !format
)
2352 return InvalidParameter
;
2354 if(image
->type
!= ImageTypeBitmap
)
2355 *format
= PixelFormat24bppRGB
;
2357 *format
= ((GpBitmap
*) image
)->format
;
2362 GpStatus WINGDIPAPI
GdipGetImageRawFormat(GpImage
*image
, GUID
*format
)
2364 TRACE("(%p, %p)\n", image
, format
);
2366 if(!image
|| !format
)
2367 return InvalidParameter
;
2369 memcpy(format
, &image
->format
, sizeof(GUID
));
2374 GpStatus WINGDIPAPI
GdipGetImageType(GpImage
*image
, ImageType
*type
)
2376 TRACE("%p %p\n", image
, type
);
2379 return InvalidParameter
;
2381 *type
= image
->type
;
2386 GpStatus WINGDIPAPI
GdipGetImageVerticalResolution(GpImage
*image
, REAL
*res
)
2389 return InvalidParameter
;
2393 TRACE("(%p) <-- %0.2f\n", image
, *res
);
2398 GpStatus WINGDIPAPI
GdipGetImageWidth(GpImage
*image
, UINT
*width
)
2400 TRACE("%p %p\n", image
, width
);
2402 if(!image
|| !width
)
2403 return InvalidParameter
;
2405 if(image
->type
== ImageTypeMetafile
)
2406 *width
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Width
, ((GpMetafile
*)image
)->unit
, image
->xres
);
2407 else if(image
->type
== ImageTypeBitmap
)
2408 *width
= ((GpBitmap
*)image
)->width
;
2410 *width
= ipicture_pixel_width(image
->picture
);
2412 TRACE("returning %d\n", *width
);
2417 GpStatus WINGDIPAPI
GdipGetPropertyCount(GpImage
*image
, UINT
*num
)
2419 TRACE("(%p, %p)\n", image
, num
);
2421 if (!image
|| !num
) return InvalidParameter
;
2425 if (image
->type
== ImageTypeBitmap
)
2427 if (((GpBitmap
*)image
)->prop_item
)
2429 *num
= ((GpBitmap
*)image
)->prop_count
;
2433 if (((GpBitmap
*)image
)->metadata_reader
)
2434 IWICMetadataReader_GetCount(((GpBitmap
*)image
)->metadata_reader
, num
);
2440 GpStatus WINGDIPAPI
GdipGetPropertyIdList(GpImage
*image
, UINT num
, PROPID
*list
)
2443 IWICMetadataReader
*reader
;
2444 IWICEnumMetadataItem
*enumerator
;
2445 UINT prop_count
, i
, items_returned
;
2447 TRACE("(%p, %u, %p)\n", image
, num
, list
);
2449 if (!image
|| !list
) return InvalidParameter
;
2451 if (image
->type
!= ImageTypeBitmap
)
2453 FIXME("Not implemented for type %d\n", image
->type
);
2454 return NotImplemented
;
2457 if (((GpBitmap
*)image
)->prop_item
)
2459 if (num
!= ((GpBitmap
*)image
)->prop_count
) return InvalidParameter
;
2461 for (i
= 0; i
< num
; i
++)
2463 list
[i
] = ((GpBitmap
*)image
)->prop_item
[i
].id
;
2469 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2472 if (num
!= 0) return InvalidParameter
;
2476 hr
= IWICMetadataReader_GetCount(reader
, &prop_count
);
2477 if (FAILED(hr
)) return hresult_to_status(hr
);
2479 if (num
!= prop_count
) return InvalidParameter
;
2481 hr
= IWICMetadataReader_GetEnumerator(reader
, &enumerator
);
2482 if (FAILED(hr
)) return hresult_to_status(hr
);
2484 IWICEnumMetadataItem_Reset(enumerator
);
2486 for (i
= 0; i
< num
; i
++)
2490 hr
= IWICEnumMetadataItem_Next(enumerator
, 1, NULL
, &id
, NULL
, &items_returned
);
2491 if (hr
!= S_OK
) break;
2493 if (id
.vt
!= VT_UI2
)
2495 FIXME("not supported propvariant type for id: %u\n", id
.vt
);
2499 list
[i
] = id
.u
.uiVal
;
2502 IWICEnumMetadataItem_Release(enumerator
);
2504 return hr
== S_OK
? Ok
: hresult_to_status(hr
);
2507 static UINT
propvariant_size(PROPVARIANT
*value
)
2509 switch (value
->vt
& ~VT_VECTOR
)
2515 if (!(value
->vt
& VT_VECTOR
)) return 1;
2516 return value
->u
.caub
.cElems
;
2519 if (!(value
->vt
& VT_VECTOR
)) return 2;
2520 return value
->u
.caui
.cElems
* 2;
2524 if (!(value
->vt
& VT_VECTOR
)) return 4;
2525 return value
->u
.caul
.cElems
* 4;
2529 if (!(value
->vt
& VT_VECTOR
)) return 8;
2530 return value
->u
.cauh
.cElems
* 8;
2532 return value
->u
.pszVal
? strlen(value
->u
.pszVal
) + 1 : 0;
2534 return value
->u
.blob
.cbSize
;
2536 FIXME("not supported variant type %d\n", value
->vt
);
2541 GpStatus WINGDIPAPI
GdipGetPropertyItemSize(GpImage
*image
, PROPID propid
, UINT
*size
)
2544 IWICMetadataReader
*reader
;
2545 PROPVARIANT id
, value
;
2547 TRACE("(%p,%#x,%p)\n", image
, propid
, size
);
2549 if (!size
|| !image
) return InvalidParameter
;
2551 if (image
->type
!= ImageTypeBitmap
)
2553 FIXME("Not implemented for type %d\n", image
->type
);
2554 return NotImplemented
;
2557 if (((GpBitmap
*)image
)->prop_item
)
2561 for (i
= 0; i
< ((GpBitmap
*)image
)->prop_count
; i
++)
2563 if (propid
== ((GpBitmap
*)image
)->prop_item
[i
].id
)
2565 *size
= sizeof(PropertyItem
) + ((GpBitmap
*)image
)->prop_item
[i
].length
;
2570 return PropertyNotFound
;
2573 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2574 if (!reader
) return PropertyNotFound
;
2577 id
.u
.uiVal
= propid
;
2578 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
2579 if (FAILED(hr
)) return PropertyNotFound
;
2581 *size
= propvariant_size(&value
);
2582 if (*size
) *size
+= sizeof(PropertyItem
);
2583 PropVariantClear(&value
);
2588 #ifndef PropertyTagTypeSByte
2589 #define PropertyTagTypeSByte 6
2590 #define PropertyTagTypeSShort 8
2591 #define PropertyTagTypeFloat 11
2592 #define PropertyTagTypeDouble 12
2595 static UINT
vt_to_itemtype(UINT vt
)
2602 { VT_I1
, PropertyTagTypeSByte
},
2603 { VT_UI1
, PropertyTagTypeByte
},
2604 { VT_I2
, PropertyTagTypeSShort
},
2605 { VT_UI2
, PropertyTagTypeShort
},
2606 { VT_I4
, PropertyTagTypeSLONG
},
2607 { VT_UI4
, PropertyTagTypeLong
},
2608 { VT_I8
, PropertyTagTypeSRational
},
2609 { VT_UI8
, PropertyTagTypeRational
},
2610 { VT_R4
, PropertyTagTypeFloat
},
2611 { VT_R8
, PropertyTagTypeDouble
},
2612 { VT_LPSTR
, PropertyTagTypeASCII
},
2613 { VT_BLOB
, PropertyTagTypeUndefined
}
2616 for (i
= 0; i
< sizeof(vt2type
)/sizeof(vt2type
[0]); i
++)
2618 if (vt2type
[i
].vt
== vt
) return vt2type
[i
].type
;
2620 FIXME("not supported variant type %u\n", vt
);
2624 static GpStatus
propvariant_to_item(PROPVARIANT
*value
, PropertyItem
*item
,
2625 UINT size
, PROPID id
)
2627 UINT item_size
, item_type
;
2629 item_size
= propvariant_size(value
);
2630 if (size
!= item_size
+ sizeof(PropertyItem
)) return InvalidParameter
;
2632 item_type
= vt_to_itemtype(value
->vt
& ~VT_VECTOR
);
2633 if (!item_type
) return InvalidParameter
;
2635 item
->value
= item
+ 1;
2637 switch (value
->vt
& ~VT_VECTOR
)
2641 if (!(value
->vt
& VT_VECTOR
))
2642 *(BYTE
*)item
->value
= value
->u
.bVal
;
2644 memcpy(item
->value
, value
->u
.caub
.pElems
, item_size
);
2648 if (!(value
->vt
& VT_VECTOR
))
2649 *(USHORT
*)item
->value
= value
->u
.uiVal
;
2651 memcpy(item
->value
, value
->u
.caui
.pElems
, item_size
);
2656 if (!(value
->vt
& VT_VECTOR
))
2657 *(ULONG
*)item
->value
= value
->u
.ulVal
;
2659 memcpy(item
->value
, value
->u
.caul
.pElems
, item_size
);
2664 if (!(value
->vt
& VT_VECTOR
))
2665 *(ULONGLONG
*)item
->value
= value
->u
.uhVal
.QuadPart
;
2667 memcpy(item
->value
, value
->u
.cauh
.pElems
, item_size
);
2670 memcpy(item
->value
, value
->u
.pszVal
, item_size
);
2673 memcpy(item
->value
, value
->u
.blob
.pBlobData
, item_size
);
2676 FIXME("not supported variant type %d\n", value
->vt
);
2677 return InvalidParameter
;
2680 item
->length
= item_size
;
2681 item
->type
= item_type
;
2687 GpStatus WINGDIPAPI
GdipGetPropertyItem(GpImage
*image
, PROPID propid
, UINT size
,
2688 PropertyItem
*buffer
)
2692 IWICMetadataReader
*reader
;
2693 PROPVARIANT id
, value
;
2695 TRACE("(%p,%#x,%u,%p)\n", image
, propid
, size
, buffer
);
2697 if (!image
|| !buffer
) return InvalidParameter
;
2699 if (image
->type
!= ImageTypeBitmap
)
2701 FIXME("Not implemented for type %d\n", image
->type
);
2702 return NotImplemented
;
2705 if (((GpBitmap
*)image
)->prop_item
)
2709 for (i
= 0; i
< ((GpBitmap
*)image
)->prop_count
; i
++)
2711 if (propid
== ((GpBitmap
*)image
)->prop_item
[i
].id
)
2713 if (size
!= sizeof(PropertyItem
) + ((GpBitmap
*)image
)->prop_item
[i
].length
)
2714 return InvalidParameter
;
2716 *buffer
= ((GpBitmap
*)image
)->prop_item
[i
];
2717 buffer
->value
= buffer
+ 1;
2718 memcpy(buffer
->value
, ((GpBitmap
*)image
)->prop_item
[i
].value
, buffer
->length
);
2723 return PropertyNotFound
;
2726 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2727 if (!reader
) return PropertyNotFound
;
2730 id
.u
.uiVal
= propid
;
2731 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
2732 if (FAILED(hr
)) return PropertyNotFound
;
2734 stat
= propvariant_to_item(&value
, buffer
, size
, propid
);
2735 PropVariantClear(&value
);
2740 GpStatus WINGDIPAPI
GdipGetPropertySize(GpImage
*image
, UINT
*size
, UINT
*count
)
2743 IWICMetadataReader
*reader
;
2744 IWICEnumMetadataItem
*enumerator
;
2745 UINT prop_count
, prop_size
, i
;
2746 PROPVARIANT id
, value
;
2748 TRACE("(%p,%p,%p)\n", image
, size
, count
);
2750 if (!image
|| !size
|| !count
) return InvalidParameter
;
2752 if (image
->type
!= ImageTypeBitmap
)
2754 FIXME("Not implemented for type %d\n", image
->type
);
2755 return NotImplemented
;
2758 if (((GpBitmap
*)image
)->prop_item
)
2760 *count
= ((GpBitmap
*)image
)->prop_count
;
2763 for (i
= 0; i
< ((GpBitmap
*)image
)->prop_count
; i
++)
2765 *size
+= sizeof(PropertyItem
) + ((GpBitmap
*)image
)->prop_item
[i
].length
;
2771 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2772 if (!reader
) return PropertyNotFound
;
2774 hr
= IWICMetadataReader_GetCount(reader
, &prop_count
);
2775 if (FAILED(hr
)) return hresult_to_status(hr
);
2777 hr
= IWICMetadataReader_GetEnumerator(reader
, &enumerator
);
2778 if (FAILED(hr
)) return hresult_to_status(hr
);
2780 IWICEnumMetadataItem_Reset(enumerator
);
2784 PropVariantInit(&id
);
2785 PropVariantInit(&value
);
2787 for (i
= 0; i
< prop_count
; i
++)
2789 UINT items_returned
, item_size
;
2791 hr
= IWICEnumMetadataItem_Next(enumerator
, 1, NULL
, &id
, &value
, &items_returned
);
2792 if (hr
!= S_OK
) break;
2794 item_size
= propvariant_size(&value
);
2795 if (item_size
) prop_size
+= sizeof(PropertyItem
) + item_size
;
2797 PropVariantClear(&id
);
2798 PropVariantClear(&value
);
2801 IWICEnumMetadataItem_Release(enumerator
);
2803 if (hr
!= S_OK
) return PropertyNotFound
;
2805 *count
= prop_count
;
2810 GpStatus WINGDIPAPI
GdipGetAllPropertyItems(GpImage
*image
, UINT size
,
2811 UINT count
, PropertyItem
*buf
)
2815 IWICMetadataReader
*reader
;
2816 IWICEnumMetadataItem
*enumerator
;
2817 UINT prop_count
, prop_size
, i
;
2818 PROPVARIANT id
, value
;
2821 TRACE("(%p,%u,%u,%p)\n", image
, size
, count
, buf
);
2823 if (!image
|| !buf
) return InvalidParameter
;
2825 if (image
->type
!= ImageTypeBitmap
)
2827 FIXME("Not implemented for type %d\n", image
->type
);
2828 return NotImplemented
;
2831 status
= GdipGetPropertySize(image
, &prop_size
, &prop_count
);
2832 if (status
!= Ok
) return status
;
2834 if (prop_count
!= count
|| prop_size
!= size
) return InvalidParameter
;
2836 if (((GpBitmap
*)image
)->prop_item
)
2838 memcpy(buf
, ((GpBitmap
*)image
)->prop_item
, prop_size
);
2840 item_value
= (char *)(buf
+ prop_count
);
2842 for (i
= 0; i
< prop_count
; i
++)
2844 buf
[i
].value
= item_value
;
2845 item_value
+= buf
[i
].length
;
2851 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2852 if (!reader
) return PropertyNotFound
;
2854 hr
= IWICMetadataReader_GetEnumerator(reader
, &enumerator
);
2855 if (FAILED(hr
)) return hresult_to_status(hr
);
2857 IWICEnumMetadataItem_Reset(enumerator
);
2859 item_value
= (char *)(buf
+ prop_count
);
2861 PropVariantInit(&id
);
2862 PropVariantInit(&value
);
2864 for (i
= 0; i
< prop_count
; i
++)
2867 UINT items_returned
, item_size
;
2869 hr
= IWICEnumMetadataItem_Next(enumerator
, 1, NULL
, &id
, &value
, &items_returned
);
2870 if (hr
!= S_OK
) break;
2872 if (id
.vt
!= VT_UI2
)
2874 FIXME("not supported propvariant type for id: %u\n", id
.vt
);
2878 item_size
= propvariant_size(&value
);
2881 item
= heap_alloc(item_size
+ sizeof(*item
));
2883 propvariant_to_item(&value
, item
, item_size
+ sizeof(*item
), id
.u
.uiVal
);
2884 buf
[i
].id
= item
->id
;
2885 buf
[i
].type
= item
->type
;
2886 buf
[i
].length
= item_size
;
2887 buf
[i
].value
= item_value
;
2888 memcpy(item_value
, item
->value
, item_size
);
2889 item_value
+= item_size
;
2894 PropVariantClear(&id
);
2895 PropVariantClear(&value
);
2898 IWICEnumMetadataItem_Release(enumerator
);
2900 if (hr
!= S_OK
) return PropertyNotFound
;
2905 struct image_format_dimension
2908 const GUID
*dimension
;
2911 static const struct image_format_dimension image_format_dimensions
[] =
2913 {&ImageFormatGIF
, &FrameDimensionTime
},
2914 {&ImageFormatIcon
, &FrameDimensionResolution
},
2918 GpStatus WINGDIPAPI
GdipImageGetFrameCount(GpImage
*image
,
2919 GDIPCONST GUID
* dimensionID
, UINT
* count
)
2921 TRACE("(%p,%s,%p)\n", image
, debugstr_guid(dimensionID
), count
);
2923 if(!image
|| !count
)
2924 return InvalidParameter
;
2927 IsEqualGUID(dimensionID
, &image
->format
) ||
2928 IsEqualGUID(dimensionID
, &FrameDimensionPage
) ||
2929 IsEqualGUID(dimensionID
, &FrameDimensionTime
))
2931 *count
= image
->frame_count
;
2935 return InvalidParameter
;
2938 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsCount(GpImage
*image
,
2941 TRACE("(%p, %p)\n", image
, count
);
2943 /* Native gdiplus 1.1 does not yet support multiple frame dimensions. */
2945 if(!image
|| !count
)
2946 return InvalidParameter
;
2953 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsList(GpImage
* image
,
2954 GUID
* dimensionIDs
, UINT count
)
2957 const GUID
*result
=NULL
;
2959 TRACE("(%p,%p,%u)\n", image
, dimensionIDs
, count
);
2961 if(!image
|| !dimensionIDs
|| count
!= 1)
2962 return InvalidParameter
;
2964 for (i
=0; image_format_dimensions
[i
].format
; i
++)
2966 if (IsEqualGUID(&image
->format
, image_format_dimensions
[i
].format
))
2968 result
= image_format_dimensions
[i
].dimension
;
2974 result
= &FrameDimensionPage
;
2976 memcpy(dimensionIDs
, result
, sizeof(GUID
));
2981 GpStatus WINGDIPAPI
GdipLoadImageFromFile(GDIPCONST WCHAR
* filename
,
2987 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
2989 if (!filename
|| !image
)
2990 return InvalidParameter
;
2994 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
2999 stat
= GdipLoadImageFromStream(stream
, image
);
3001 IStream_Release(stream
);
3006 /* FIXME: no icm handling */
3007 GpStatus WINGDIPAPI
GdipLoadImageFromFileICM(GDIPCONST WCHAR
* filename
,GpImage
**image
)
3009 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
3011 return GdipLoadImageFromFile(filename
, image
);
3014 static void add_property(GpBitmap
*bitmap
, PropertyItem
*item
)
3016 UINT prop_size
, prop_count
;
3017 PropertyItem
*prop_item
;
3019 if (bitmap
->prop_item
== NULL
)
3021 prop_size
= prop_count
= 0;
3022 prop_item
= heap_alloc_zero(item
->length
+ sizeof(PropertyItem
));
3023 if (!prop_item
) return;
3030 GdipGetPropertySize((GpImage
*)bitmap
, &prop_size
, &prop_count
);
3032 prop_item
= heap_alloc_zero(prop_size
+ item
->length
+ sizeof(PropertyItem
));
3033 if (!prop_item
) return;
3034 memcpy(prop_item
, bitmap
->prop_item
, sizeof(PropertyItem
) * bitmap
->prop_count
);
3035 prop_size
-= sizeof(PropertyItem
) * bitmap
->prop_count
;
3036 memcpy(prop_item
+ prop_count
+ 1, bitmap
->prop_item
+ prop_count
, prop_size
);
3038 item_value
= (char *)(prop_item
+ prop_count
+ 1);
3040 for (i
= 0; i
< prop_count
; i
++)
3042 prop_item
[i
].value
= item_value
;
3043 item_value
+= prop_item
[i
].length
;
3047 prop_item
[prop_count
].id
= item
->id
;
3048 prop_item
[prop_count
].type
= item
->type
;
3049 prop_item
[prop_count
].length
= item
->length
;
3050 prop_item
[prop_count
].value
= (char *)(prop_item
+ prop_count
+ 1) + prop_size
;
3051 memcpy(prop_item
[prop_count
].value
, item
->value
, item
->length
);
3053 heap_free(bitmap
->prop_item
);
3054 bitmap
->prop_item
= prop_item
;
3055 bitmap
->prop_count
++;
3058 static BOOL
get_bool_property(IWICMetadataReader
*reader
, const GUID
*guid
, const WCHAR
*prop_name
)
3062 PROPVARIANT id
, value
;
3065 hr
= IWICMetadataReader_GetMetadataFormat(reader
, &format
);
3066 if (FAILED(hr
) || !IsEqualGUID(&format
, guid
)) return FALSE
;
3068 PropVariantInit(&id
);
3069 PropVariantInit(&value
);
3072 id
.u
.pwszVal
= CoTaskMemAlloc((lstrlenW(prop_name
) + 1) * sizeof(WCHAR
));
3073 if (!id
.u
.pwszVal
) return FALSE
;
3074 lstrcpyW(id
.u
.pwszVal
, prop_name
);
3075 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
3076 if (hr
== S_OK
&& value
.vt
== VT_BOOL
)
3077 ret
= value
.u
.boolVal
;
3079 PropVariantClear(&id
);
3080 PropVariantClear(&value
);
3085 static PropertyItem
*get_property(IWICMetadataReader
*reader
, const GUID
*guid
, const WCHAR
*prop_name
)
3089 PROPVARIANT id
, value
;
3090 PropertyItem
*item
= NULL
;
3092 hr
= IWICMetadataReader_GetMetadataFormat(reader
, &format
);
3093 if (FAILED(hr
) || !IsEqualGUID(&format
, guid
)) return NULL
;
3095 PropVariantInit(&id
);
3096 PropVariantInit(&value
);
3099 id
.u
.pwszVal
= CoTaskMemAlloc((lstrlenW(prop_name
) + 1) * sizeof(WCHAR
));
3100 if (!id
.u
.pwszVal
) return NULL
;
3101 lstrcpyW(id
.u
.pwszVal
, prop_name
);
3102 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
3105 UINT item_size
= propvariant_size(&value
);
3108 item_size
+= sizeof(*item
);
3109 item
= heap_alloc_zero(item_size
);
3110 if (propvariant_to_item(&value
, item
, item_size
, 0) != Ok
)
3118 PropVariantClear(&id
);
3119 PropVariantClear(&value
);
3124 static PropertyItem
*get_gif_comment(IWICMetadataReader
*reader
)
3126 static const WCHAR textentryW
[] = { 'T','e','x','t','E','n','t','r','y',0 };
3127 PropertyItem
*comment
;
3129 comment
= get_property(reader
, &GUID_MetadataFormatGifComment
, textentryW
);
3131 comment
->id
= PropertyTagExifUserComment
;
3136 static PropertyItem
*get_gif_loopcount(IWICMetadataReader
*reader
)
3138 static const WCHAR applicationW
[] = { 'A','p','p','l','i','c','a','t','i','o','n',0 };
3139 static const WCHAR dataW
[] = { 'D','a','t','a',0 };
3140 PropertyItem
*appext
= NULL
, *appdata
= NULL
, *loop
= NULL
;
3142 appext
= get_property(reader
, &GUID_MetadataFormatAPE
, applicationW
);
3145 if (appext
->type
== PropertyTagTypeByte
&& appext
->length
== 11 &&
3146 (!memcmp(appext
->value
, "NETSCAPE2.0", 11) || !memcmp(appext
->value
, "ANIMEXTS1.0", 11)))
3148 appdata
= get_property(reader
, &GUID_MetadataFormatAPE
, dataW
);
3151 if (appdata
->type
== PropertyTagTypeByte
&& appdata
->length
== 4)
3153 BYTE
*data
= appdata
->value
;
3154 if (data
[0] == 3 && data
[1] == 1)
3156 loop
= heap_alloc_zero(sizeof(*loop
) + sizeof(SHORT
));
3159 loop
->type
= PropertyTagTypeShort
;
3160 loop
->id
= PropertyTagLoopCount
;
3161 loop
->length
= sizeof(SHORT
);
3162 loop
->value
= loop
+ 1;
3163 *(SHORT
*)loop
->value
= data
[2] | (data
[3] << 8);
3177 static PropertyItem
*get_gif_background(IWICMetadataReader
*reader
)
3179 static const WCHAR backgroundW
[] = { 'B','a','c','k','g','r','o','u','n','d','C','o','l','o','r','I','n','d','e','x',0 };
3180 PropertyItem
*background
;
3182 background
= get_property(reader
, &GUID_MetadataFormatLSD
, backgroundW
);
3184 background
->id
= PropertyTagIndexBackground
;
3189 static PropertyItem
*get_gif_palette(IWICBitmapDecoder
*decoder
, IWICMetadataReader
*reader
)
3191 static const WCHAR global_flagW
[] = { 'G','l','o','b','a','l','C','o','l','o','r','T','a','b','l','e','F','l','a','g',0 };
3193 IWICImagingFactory
*factory
;
3194 IWICPalette
*palette
;
3196 WICColor colors
[256];
3198 if (!get_bool_property(reader
, &GUID_MetadataFormatLSD
, global_flagW
))
3201 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
3202 if (hr
!= S_OK
) return NULL
;
3204 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
3207 hr
= IWICBitmapDecoder_CopyPalette(decoder
, palette
);
3209 IWICPalette_GetColors(palette
, 256, colors
, &count
);
3211 IWICPalette_Release(palette
);
3214 IWICImagingFactory_Release(factory
);
3222 pal
= heap_alloc_zero(sizeof(*pal
) + count
* 3);
3223 if (!pal
) return NULL
;
3224 pal
->type
= PropertyTagTypeByte
;
3225 pal
->id
= PropertyTagGlobalPalette
;
3226 pal
->value
= pal
+ 1;
3227 pal
->length
= count
* 3;
3231 for (i
= 0; i
< count
; i
++)
3233 rgb
[i
*3] = (colors
[i
] >> 16) & 0xff;
3234 rgb
[i
*3 + 1] = (colors
[i
] >> 8) & 0xff;
3235 rgb
[i
*3 + 2] = colors
[i
] & 0xff;
3244 static PropertyItem
*get_gif_transparent_idx(IWICMetadataReader
*reader
)
3246 static const WCHAR transparency_flagW
[] = { 'T','r','a','n','s','p','a','r','e','n','c','y','F','l','a','g',0 };
3247 static const WCHAR colorW
[] = { 'T','r','a','n','s','p','a','r','e','n','t','C','o','l','o','r','I','n','d','e','x',0 };
3248 PropertyItem
*index
= NULL
;
3250 if (get_bool_property(reader
, &GUID_MetadataFormatGCE
, transparency_flagW
))
3252 index
= get_property(reader
, &GUID_MetadataFormatGCE
, colorW
);
3254 index
->id
= PropertyTagIndexTransparent
;
3259 static LONG
get_gif_frame_property(IWICBitmapFrameDecode
*frame
, const GUID
*format
, const WCHAR
*property
)
3262 IWICMetadataBlockReader
*block_reader
;
3263 IWICMetadataReader
*reader
;
3264 UINT block_count
, i
;
3268 hr
= IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3271 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3274 for (i
= 0; i
< block_count
; i
++)
3276 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3279 prop
= get_property(reader
, format
, property
);
3282 if (prop
->type
== PropertyTagTypeByte
&& prop
->length
== 1)
3283 value
= *(BYTE
*)prop
->value
;
3284 else if (prop
->type
== PropertyTagTypeShort
&& prop
->length
== 2)
3285 value
= *(SHORT
*)prop
->value
;
3289 IWICMetadataReader_Release(reader
);
3293 IWICMetadataBlockReader_Release(block_reader
);
3299 static void gif_metadata_reader(GpBitmap
*bitmap
, IWICBitmapDecoder
*decoder
, UINT active_frame
)
3301 static const WCHAR delayW
[] = { 'D','e','l','a','y',0 };
3303 IWICBitmapFrameDecode
*frame
;
3304 IWICMetadataBlockReader
*block_reader
;
3305 IWICMetadataReader
*reader
;
3306 UINT frame_count
, block_count
, i
;
3307 PropertyItem
*delay
= NULL
, *comment
= NULL
, *background
= NULL
;
3308 PropertyItem
*transparent_idx
= NULL
, *loop
= NULL
, *palette
= NULL
;
3310 IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
3311 if (frame_count
> 1)
3313 delay
= heap_alloc_zero(sizeof(*delay
) + frame_count
* sizeof(LONG
));
3318 delay
->type
= PropertyTagTypeLong
;
3319 delay
->id
= PropertyTagFrameDelay
;
3320 delay
->length
= frame_count
* sizeof(LONG
);
3321 delay
->value
= delay
+ 1;
3323 value
= delay
->value
;
3325 for (i
= 0; i
< frame_count
; i
++)
3327 hr
= IWICBitmapDecoder_GetFrame(decoder
, i
, &frame
);
3330 value
[i
] = get_gif_frame_property(frame
, &GUID_MetadataFormatGCE
, delayW
);
3331 IWICBitmapFrameDecode_Release(frame
);
3338 hr
= IWICBitmapDecoder_QueryInterface(decoder
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3341 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3344 for (i
= 0; i
< block_count
; i
++)
3346 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3350 comment
= get_gif_comment(reader
);
3352 if (frame_count
> 1 && !loop
)
3353 loop
= get_gif_loopcount(reader
);
3356 background
= get_gif_background(reader
);
3359 palette
= get_gif_palette(decoder
, reader
);
3361 IWICMetadataReader_Release(reader
);
3365 IWICMetadataBlockReader_Release(block_reader
);
3368 if (frame_count
> 1 && !loop
)
3370 loop
= heap_alloc_zero(sizeof(*loop
) + sizeof(SHORT
));
3373 loop
->type
= PropertyTagTypeShort
;
3374 loop
->id
= PropertyTagLoopCount
;
3375 loop
->length
= sizeof(SHORT
);
3376 loop
->value
= loop
+ 1;
3377 *(SHORT
*)loop
->value
= 1;
3381 if (delay
) add_property(bitmap
, delay
);
3382 if (comment
) add_property(bitmap
, comment
);
3383 if (loop
) add_property(bitmap
, loop
);
3384 if (palette
) add_property(bitmap
, palette
);
3385 if (background
) add_property(bitmap
, background
);
3391 heap_free(background
);
3393 /* Win7 gdiplus always returns transparent color index from frame 0 */
3394 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
3395 if (hr
!= S_OK
) return;
3397 hr
= IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3400 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3403 for (i
= 0; i
< block_count
; i
++)
3405 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3408 if (!transparent_idx
)
3409 transparent_idx
= get_gif_transparent_idx(reader
);
3411 IWICMetadataReader_Release(reader
);
3415 IWICMetadataBlockReader_Release(block_reader
);
3418 if (transparent_idx
) add_property(bitmap
, transparent_idx
);
3419 heap_free(transparent_idx
);
3421 IWICBitmapFrameDecode_Release(frame
);
3424 static PropertyItem
* create_prop(PROPID propid
, PROPVARIANT
* value
)
3426 PropertyItem
*item
= NULL
;
3427 UINT item_size
= propvariant_size(value
);
3431 item_size
+= sizeof(*item
);
3432 item
= heap_alloc_zero(item_size
);
3433 if (propvariant_to_item(value
, item
, item_size
, propid
) != Ok
)
3443 static ULONG
get_ulong_by_index(IWICMetadataReader
* reader
, ULONG index
)
3449 hr
= IWICMetadataReader_GetValueByIndex(reader
, index
, NULL
, NULL
, &value
);
3455 result
= value
.u
.ulVal
;
3458 ERR("unhandled case %u\n", value
.vt
);
3461 PropVariantClear(&value
);
3466 static void png_metadata_reader(GpBitmap
*bitmap
, IWICBitmapDecoder
*decoder
, UINT active_frame
)
3469 IWICBitmapFrameDecode
*frame
;
3470 IWICMetadataBlockReader
*block_reader
;
3471 IWICMetadataReader
*reader
;
3472 UINT block_count
, i
, j
;
3473 struct keyword_info
{
3478 { "Title", PropertyTagImageTitle
},
3479 { "Author", PropertyTagArtist
},
3480 { "Description", PropertyTagImageDescription
},
3481 { "Copyright", PropertyTagCopyright
},
3482 { "Software", PropertyTagSoftwareUsed
},
3483 { "Source", PropertyTagEquipModel
},
3484 { "Comment", PropertyTagExifUserComment
},
3486 BOOL seen_gamma
=FALSE
;
3488 hr
= IWICBitmapDecoder_GetFrame(decoder
, active_frame
, &frame
);
3489 if (hr
!= S_OK
) return;
3491 hr
= IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3494 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3497 for (i
= 0; i
< block_count
; i
++)
3499 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3504 hr
= IWICMetadataReader_GetMetadataFormat(reader
, &format
);
3505 if (SUCCEEDED(hr
) && IsEqualGUID(&GUID_MetadataFormatChunktEXt
, &format
))
3507 PROPVARIANT name
, value
;
3510 hr
= IWICMetadataReader_GetValueByIndex(reader
, 0, NULL
, &name
, &value
);
3514 if (name
.vt
== VT_LPSTR
)
3516 for (j
=0; j
<sizeof(keywords
)/sizeof(keywords
[0]); j
++)
3517 if (!strcmp(keywords
[j
].name
, name
.u
.pszVal
))
3519 if (j
< sizeof(keywords
)/sizeof(keywords
[0]) && !keywords
[j
].seen
)
3521 keywords
[j
].seen
= TRUE
;
3522 item
= create_prop(keywords
[j
].propid
, &value
);
3524 add_property(bitmap
, item
);
3529 PropVariantClear(&name
);
3530 PropVariantClear(&value
);
3533 else if (SUCCEEDED(hr
) && IsEqualGUID(&GUID_MetadataFormatChunkgAMA
, &format
))
3539 item
= heap_alloc_zero(sizeof(PropertyItem
) + sizeof(ULONG
) * 2);
3543 item
->length
= sizeof(ULONG
) * 2;
3544 item
->type
= PropertyTagTypeRational
;
3545 item
->id
= PropertyTagGamma
;
3546 rational
= item
->value
= item
+ 1;
3547 rational
[0] = 100000;
3548 rational
[1] = get_ulong_by_index(reader
, 0);
3549 add_property(bitmap
, item
);
3556 IWICMetadataReader_Release(reader
);
3560 IWICMetadataBlockReader_Release(block_reader
);
3563 IWICBitmapFrameDecode_Release(frame
);
3566 static GpStatus
initialize_decoder_wic(IStream
*stream
, REFGUID container
, IWICBitmapDecoder
**decoder
)
3568 IWICImagingFactory
*factory
;
3571 TRACE("%p,%s\n", stream
, wine_dbgstr_guid(container
));
3573 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
3574 if (FAILED(hr
)) return hresult_to_status(hr
);
3575 hr
= IWICImagingFactory_CreateDecoder(factory
, container
, NULL
, decoder
);
3576 IWICImagingFactory_Release(factory
);
3577 if (FAILED(hr
)) return hresult_to_status(hr
);
3579 hr
= IWICBitmapDecoder_Initialize(*decoder
, stream
, WICDecodeMetadataCacheOnLoad
);
3580 if (FAILED(hr
)) return hresult_to_status(hr
);
3584 typedef void (*metadata_reader_func
)(GpBitmap
*bitmap
, IWICBitmapDecoder
*decoder
, UINT frame
);
3586 static GpStatus
decode_frame_wic(IWICBitmapDecoder
*decoder
, BOOL force_conversion
,
3587 UINT active_frame
, metadata_reader_func metadata_reader
, GpImage
**image
)
3592 IWICBitmapFrameDecode
*frame
;
3593 IWICBitmapSource
*source
=NULL
;
3594 IWICMetadataBlockReader
*block_reader
;
3595 WICPixelFormatGUID wic_format
;
3596 PixelFormat gdip_format
=0;
3597 ColorPalette
*palette
= NULL
;
3598 WICBitmapPaletteType palette_type
= WICBitmapPaletteTypeFixedHalftone256
;
3600 UINT width
, height
, frame_count
;
3601 BitmapData lockeddata
;
3604 TRACE("%p,%u,%p\n", decoder
, active_frame
, image
);
3606 IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
3607 hr
= IWICBitmapDecoder_GetFrame(decoder
, active_frame
, &frame
);
3608 if (SUCCEEDED(hr
)) /* got frame */
3610 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &wic_format
);
3614 if (!force_conversion
)
3616 for (i
=0; pixel_formats
[i
].wic_format
; i
++)
3618 if (IsEqualGUID(&wic_format
, pixel_formats
[i
].wic_format
))
3620 source
= (IWICBitmapSource
*)frame
;
3621 IWICBitmapSource_AddRef(source
);
3622 gdip_format
= pixel_formats
[i
].gdip_format
;
3623 palette_type
= pixel_formats
[i
].palette_type
;
3630 /* unknown format; fall back on 32bppARGB */
3631 hr
= WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA
, (IWICBitmapSource
*)frame
, &source
);
3632 gdip_format
= PixelFormat32bppARGB
;
3634 TRACE("%s => %#x\n", wine_dbgstr_guid(&wic_format
), gdip_format
);
3637 if (SUCCEEDED(hr
)) /* got source */
3639 hr
= IWICBitmapSource_GetSize(source
, &width
, &height
);
3642 status
= GdipCreateBitmapFromScan0(width
, height
, 0, gdip_format
,
3645 if (SUCCEEDED(hr
) && status
== Ok
) /* created bitmap */
3647 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeWrite
,
3648 gdip_format
, &lockeddata
);
3649 if (status
== Ok
) /* locked bitmap */
3654 for (i
=0; i
<height
; i
++)
3657 hr
= IWICBitmapSource_CopyPixels(source
, &wrc
, abs(lockeddata
.Stride
),
3658 abs(lockeddata
.Stride
), (BYTE
*)lockeddata
.Scan0
+lockeddata
.Stride
*i
);
3659 if (FAILED(hr
)) break;
3662 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3665 if (SUCCEEDED(hr
) && status
== Ok
)
3666 *image
= (GpImage
*)bitmap
;
3670 GdipDisposeImage((GpImage
*)bitmap
);
3673 if (SUCCEEDED(hr
) && status
== Ok
)
3676 hr
= IWICBitmapSource_GetResolution(source
, &dpix
, &dpiy
);
3679 bitmap
->image
.xres
= dpix
;
3680 bitmap
->image
.yres
= dpiy
;
3686 IWICBitmapSource_Release(source
);
3689 if (SUCCEEDED(hr
)) {
3690 bitmap
->metadata_reader
= NULL
;
3692 if (metadata_reader
)
3693 metadata_reader(bitmap
, decoder
, active_frame
);
3694 else if (IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
) == S_OK
)
3696 UINT block_count
= 0;
3697 if (IWICMetadataBlockReader_GetCount(block_reader
, &block_count
) == S_OK
&& block_count
)
3698 IWICMetadataBlockReader_GetReaderByIndex(block_reader
, 0, &bitmap
->metadata_reader
);
3699 IWICMetadataBlockReader_Release(block_reader
);
3702 palette
= get_palette(frame
, palette_type
);
3703 IWICBitmapFrameDecode_Release(frame
);
3707 if (FAILED(hr
) && status
== Ok
) status
= hresult_to_status(hr
);
3711 /* Native GDI+ used to be smarter, but since Win7 it just sets these flags. */
3712 bitmap
->image
.flags
|= ImageFlagsReadOnly
|ImageFlagsHasRealPixelSize
|ImageFlagsHasRealDPI
|ImageFlagsColorSpaceRGB
;
3713 bitmap
->image
.frame_count
= frame_count
;
3714 bitmap
->image
.current_frame
= active_frame
;
3715 bitmap
->image
.decoder
= decoder
;
3716 IWICBitmapDecoder_AddRef(decoder
);
3719 heap_free(bitmap
->image
.palette
);
3720 bitmap
->image
.palette
= palette
;
3724 if (IsEqualGUID(&wic_format
, &GUID_WICPixelFormatBlackWhite
))
3725 bitmap
->image
.palette
->Flags
= 0;
3727 TRACE("=> %p\n", *image
);
3733 static GpStatus
decode_image_wic(IStream
*stream
, REFGUID container
,
3734 metadata_reader_func metadata_reader
, GpImage
**image
)
3736 IWICBitmapDecoder
*decoder
;
3739 status
= initialize_decoder_wic(stream
, container
, &decoder
);
3743 status
= decode_frame_wic(decoder
, FALSE
, 0, metadata_reader
, image
);
3744 IWICBitmapDecoder_Release(decoder
);
3748 static GpStatus
select_frame_wic(GpImage
*image
, UINT active_frame
)
3753 status
= decode_frame_wic(image
->decoder
, FALSE
, active_frame
, NULL
, &new_image
);
3757 memcpy(&new_image
->format
, &image
->format
, sizeof(GUID
));
3758 free_image_data(image
);
3759 if (image
->type
== ImageTypeBitmap
)
3760 *(GpBitmap
*)image
= *(GpBitmap
*)new_image
;
3761 else if (image
->type
== ImageTypeMetafile
)
3762 *(GpMetafile
*)image
= *(GpMetafile
*)new_image
;
3763 new_image
->type
= ~0;
3764 heap_free(new_image
);
3768 static HRESULT
get_gif_frame_rect(IWICBitmapFrameDecode
*frame
,
3769 UINT
*left
, UINT
*top
, UINT
*width
, UINT
*height
)
3771 static const WCHAR leftW
[] = {'L','e','f','t',0};
3772 static const WCHAR topW
[] = {'T','o','p',0};
3774 *left
= get_gif_frame_property(frame
, &GUID_MetadataFormatIMD
, leftW
);
3775 *top
= get_gif_frame_property(frame
, &GUID_MetadataFormatIMD
, topW
);
3777 return IWICBitmapFrameDecode_GetSize(frame
, width
, height
);
3780 static HRESULT
blit_gif_frame(GpBitmap
*bitmap
, IWICBitmapFrameDecode
*frame
, BOOL first_frame
)
3782 UINT i
, j
, left
, top
, width
, height
;
3783 IWICBitmapSource
*source
;
3787 hr
= get_gif_frame_rect(frame
, &left
, &top
, &width
, &height
);
3791 hr
= WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA
, (IWICBitmapSource
*)frame
, &source
);
3795 new_bits
= heap_alloc_zero(width
*height
*4);
3797 return E_OUTOFMEMORY
;
3799 hr
= IWICBitmapSource_CopyPixels(source
, NULL
, width
*4, width
*height
*4, new_bits
);
3800 IWICBitmapSource_Release(source
);
3802 heap_free(new_bits
);
3806 for(i
=0; i
<height
&& i
+top
<bitmap
->height
; i
++) {
3807 for(j
=0; j
<width
&& j
+left
<bitmap
->width
; j
++) {
3808 DWORD
*src
= (DWORD
*)(new_bits
+i
*width
*4+j
*4);
3809 DWORD
*dst
= (DWORD
*)(bitmap
->bits
+(i
+top
)*bitmap
->stride
+(j
+left
)*4);
3811 if(first_frame
|| *src
>>24 != 0)
3815 heap_free(new_bits
);
3819 static DWORD
get_gif_background_color(GpBitmap
*bitmap
)
3821 BYTE bgcolor_idx
= 0;
3824 for(i
=0; i
<bitmap
->prop_count
; i
++) {
3825 if(bitmap
->prop_item
[i
].id
== PropertyTagIndexBackground
) {
3826 bgcolor_idx
= *(BYTE
*)bitmap
->prop_item
[i
].value
;
3831 for(i
=0; i
<bitmap
->prop_count
; i
++) {
3832 if(bitmap
->prop_item
[i
].id
== PropertyTagIndexTransparent
) {
3833 BYTE transparent_idx
;
3834 transparent_idx
= *(BYTE
*)bitmap
->prop_item
[i
].value
;
3836 if(transparent_idx
== bgcolor_idx
)
3841 for(i
=0; i
<bitmap
->prop_count
; i
++) {
3842 if(bitmap
->prop_item
[i
].id
== PropertyTagGlobalPalette
) {
3843 if(bitmap
->prop_item
[i
].length
/3 > bgcolor_idx
) {
3844 BYTE
*color
= ((BYTE
*)bitmap
->prop_item
[i
].value
)+bgcolor_idx
*3;
3845 return color
[2] + (color
[1]<<8) + (color
[0]<<16) + (0xffu
<<24);
3851 FIXME("can't get gif background color\n");
3855 static GpStatus
select_frame_gif(GpImage
* image
, UINT active_frame
)
3857 static const WCHAR disposalW
[] = {'D','i','s','p','o','s','a','l',0};
3859 GpBitmap
*bitmap
= (GpBitmap
*)image
;
3860 IWICBitmapFrameDecode
*frame
;
3861 int cur_frame
=0, disposal
;
3862 BOOL bgcolor_set
= FALSE
;
3866 if(active_frame
> image
->current_frame
) {
3867 hr
= IWICBitmapDecoder_GetFrame(bitmap
->image
.decoder
, image
->current_frame
, &frame
);
3869 return hresult_to_status(hr
);
3870 disposal
= get_gif_frame_property(frame
, &GUID_MetadataFormatGCE
, disposalW
);
3871 IWICBitmapFrameDecode_Release(frame
);
3873 if(disposal
== GIF_DISPOSE_RESTORE_TO_BKGND
)
3874 cur_frame
= image
->current_frame
;
3875 else if(disposal
!= GIF_DISPOSE_RESTORE_TO_PREV
)
3876 cur_frame
= image
->current_frame
+1;
3879 while(cur_frame
!= active_frame
) {
3880 hr
= IWICBitmapDecoder_GetFrame(bitmap
->image
.decoder
, cur_frame
, &frame
);
3882 return hresult_to_status(hr
);
3883 disposal
= get_gif_frame_property(frame
, &GUID_MetadataFormatGCE
, disposalW
);
3885 if(disposal
==GIF_DISPOSE_UNSPECIFIED
|| disposal
==GIF_DISPOSE_DO_NOT_DISPOSE
) {
3886 hr
= blit_gif_frame(bitmap
, frame
, cur_frame
==0);
3888 return hresult_to_status(hr
);
3889 }else if(disposal
== GIF_DISPOSE_RESTORE_TO_BKGND
) {
3890 UINT left
, top
, width
, height
, i
, j
;
3893 bgcolor
= get_gif_background_color(bitmap
);
3897 hr
= get_gif_frame_rect(frame
, &left
, &top
, &width
, &height
);
3899 return hresult_to_status(hr
);
3900 for(i
=top
; i
<top
+height
&& i
<bitmap
->height
; i
++) {
3901 DWORD
*bits
= (DWORD
*)(bitmap
->bits
+i
*bitmap
->stride
);
3902 for(j
=left
; j
<left
+width
&& j
<bitmap
->width
; j
++)
3907 IWICBitmapFrameDecode_Release(frame
);
3911 hr
= IWICBitmapDecoder_GetFrame(bitmap
->image
.decoder
, active_frame
, &frame
);
3913 return hresult_to_status(hr
);
3915 hr
= blit_gif_frame(bitmap
, frame
, cur_frame
==0);
3916 IWICBitmapFrameDecode_Release(frame
);
3918 return hresult_to_status(hr
);
3920 image
->current_frame
= active_frame
;
3924 static GpStatus
decode_image_icon(IStream
* stream
, GpImage
**image
)
3926 return decode_image_wic(stream
, &GUID_ContainerFormatIco
, NULL
, image
);
3929 static GpStatus
decode_image_bmp(IStream
* stream
, GpImage
**image
)
3934 status
= decode_image_wic(stream
, &GUID_ContainerFormatBmp
, NULL
, image
);
3936 bitmap
= (GpBitmap
*)*image
;
3938 if (status
== Ok
&& bitmap
->format
== PixelFormat32bppARGB
)
3940 /* WIC supports bmp files with alpha, but gdiplus does not */
3941 bitmap
->format
= PixelFormat32bppRGB
;
3947 static GpStatus
decode_image_jpeg(IStream
* stream
, GpImage
**image
)
3949 return decode_image_wic(stream
, &GUID_ContainerFormatJpeg
, NULL
, image
);
3952 static GpStatus
decode_image_png(IStream
* stream
, GpImage
**image
)
3954 return decode_image_wic(stream
, &GUID_ContainerFormatPng
, png_metadata_reader
, image
);
3957 static GpStatus
decode_image_gif(IStream
* stream
, GpImage
**image
)
3959 IWICBitmapDecoder
*decoder
;
3964 status
= initialize_decoder_wic(stream
, &GUID_ContainerFormatGif
, &decoder
);
3968 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
3970 return hresult_to_status(hr
);
3972 status
= decode_frame_wic(decoder
, frame_count
> 1, 0, gif_metadata_reader
, image
);
3973 IWICBitmapDecoder_Release(decoder
);
3977 if(frame_count
> 1) {
3978 heap_free((*image
)->palette
);
3979 (*image
)->palette
= NULL
;
3984 static GpStatus
decode_image_tiff(IStream
* stream
, GpImage
**image
)
3986 return decode_image_wic(stream
, &GUID_ContainerFormatTiff
, NULL
, image
);
3989 static GpStatus
decode_image_olepicture_metafile(IStream
* stream
, GpImage
**image
)
3993 TRACE("%p %p\n", stream
, image
);
3995 if(!stream
|| !image
)
3996 return InvalidParameter
;
3998 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
3999 (LPVOID
*) &pic
) != S_OK
){
4000 TRACE("Could not load picture\n");
4001 return GenericError
;
4004 /* FIXME: missing initialization code */
4005 *image
= heap_alloc_zero(sizeof(GpMetafile
));
4006 if(!*image
) return OutOfMemory
;
4007 (*image
)->type
= ImageTypeMetafile
;
4008 (*image
)->decoder
= NULL
;
4009 (*image
)->picture
= pic
;
4010 (*image
)->flags
= ImageFlagsNone
;
4011 (*image
)->frame_count
= 1;
4012 (*image
)->current_frame
= 0;
4013 (*image
)->palette
= NULL
;
4015 TRACE("<-- %p\n", *image
);
4020 typedef GpStatus (*encode_image_func
)(GpImage
*image
, IStream
* stream
,
4021 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
);
4023 typedef GpStatus (*decode_image_func
)(IStream
*stream
, GpImage
**image
);
4025 typedef GpStatus (*select_image_func
)(GpImage
*image
, UINT active_frame
);
4027 typedef struct image_codec
{
4028 ImageCodecInfo info
;
4029 encode_image_func encode_func
;
4030 decode_image_func decode_func
;
4031 select_image_func select_func
;
4046 static const struct image_codec codecs
[NUM_CODECS
];
4048 static GpStatus
get_decoder_info(IStream
* stream
, const struct image_codec
**result
)
4051 const BYTE
*pattern
, *mask
;
4058 /* seek to the start of the stream */
4060 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4061 if (FAILED(hr
)) return hresult_to_status(hr
);
4063 /* read the first 8 bytes */
4064 /* FIXME: This assumes all codecs have signatures <= 8 bytes in length */
4065 hr
= IStream_Read(stream
, signature
, 8, &bytesread
);
4066 if (FAILED(hr
)) return hresult_to_status(hr
);
4067 if (hr
== S_FALSE
|| bytesread
== 0) return GenericError
;
4069 for (i
= 0; i
< NUM_CODECS
; i
++) {
4070 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
) &&
4071 bytesread
>= codecs
[i
].info
.SigSize
)
4073 for (sig
=0; sig
<codecs
[i
].info
.SigCount
; sig
++)
4075 pattern
= &codecs
[i
].info
.SigPattern
[codecs
[i
].info
.SigSize
*sig
];
4076 mask
= &codecs
[i
].info
.SigMask
[codecs
[i
].info
.SigSize
*sig
];
4077 for (j
=0; j
<codecs
[i
].info
.SigSize
; j
++)
4078 if ((signature
[j
] & mask
[j
]) != pattern
[j
])
4080 if (j
== codecs
[i
].info
.SigSize
)
4082 *result
= &codecs
[i
];
4089 TRACE("no match for %i byte signature %x %x %x %x %x %x %x %x\n", bytesread
,
4090 signature
[0],signature
[1],signature
[2],signature
[3],
4091 signature
[4],signature
[5],signature
[6],signature
[7]);
4093 return GenericError
;
4096 static GpStatus
get_decoder_info_from_image(GpImage
*image
, const struct image_codec
**result
)
4100 for (i
= 0; i
< NUM_CODECS
; i
++) {
4101 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
) &&
4102 IsEqualIID(&codecs
[i
].info
.FormatID
, &image
->format
))
4104 *result
= &codecs
[i
];
4109 TRACE("no match for format: %s\n", wine_dbgstr_guid(&image
->format
));
4110 return GenericError
;
4113 GpStatus WINGDIPAPI
GdipImageSelectActiveFrame(GpImage
*image
, GDIPCONST GUID
*dimensionID
,
4117 const struct image_codec
*codec
= NULL
;
4119 TRACE("(%p,%s,%u)\n", image
, debugstr_guid(dimensionID
), frame
);
4121 if (!image
|| !dimensionID
)
4122 return InvalidParameter
;
4124 if (frame
>= image
->frame_count
)
4126 WARN("requested frame %u, but image has only %u\n", frame
, image
->frame_count
);
4127 return InvalidParameter
;
4130 if (image
->type
!= ImageTypeBitmap
&& image
->type
!= ImageTypeMetafile
)
4132 WARN("invalid image type %d\n", image
->type
);
4133 return InvalidParameter
;
4136 if (image
->current_frame
== frame
)
4139 if (!image
->decoder
)
4141 TRACE("image doesn't have an associated decoder\n");
4145 /* choose an appropriate image decoder */
4146 stat
= get_decoder_info_from_image(image
, &codec
);
4149 WARN("can't find decoder info\n");
4153 return codec
->select_func(image
, frame
);
4156 GpStatus WINGDIPAPI
GdipLoadImageFromStream(IStream
*stream
, GpImage
**image
)
4161 const struct image_codec
*codec
=NULL
;
4163 /* choose an appropriate image decoder */
4164 stat
= get_decoder_info(stream
, &codec
);
4165 if (stat
!= Ok
) return stat
;
4167 /* seek to the start of the stream */
4169 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4170 if (FAILED(hr
)) return hresult_to_status(hr
);
4172 /* call on the image decoder to do the real work */
4173 stat
= codec
->decode_func(stream
, image
);
4175 /* take note of the original data format */
4178 memcpy(&(*image
)->format
, &codec
->info
.FormatID
, sizeof(GUID
));
4186 GpStatus WINGDIPAPI
GdipLoadImageFromStreamICM(IStream
* stream
, GpImage
**image
)
4188 TRACE("%p %p\n", stream
, image
);
4190 return GdipLoadImageFromStream(stream
, image
);
4193 GpStatus WINGDIPAPI
GdipRemovePropertyItem(GpImage
*image
, PROPID propId
)
4197 TRACE("(%p,%u)\n", image
, propId
);
4200 return InvalidParameter
;
4203 FIXME("not implemented\n");
4205 return NotImplemented
;
4208 GpStatus WINGDIPAPI
GdipSetPropertyItem(GpImage
*image
, GDIPCONST PropertyItem
* item
)
4212 if (!image
|| !item
) return InvalidParameter
;
4214 TRACE("(%p,%p:%#x,%u,%u,%p)\n", image
, item
, item
->id
, item
->type
, item
->length
, item
->value
);
4217 FIXME("not implemented\n");
4222 GpStatus WINGDIPAPI
GdipSaveImageToFile(GpImage
*image
, GDIPCONST WCHAR
* filename
,
4223 GDIPCONST CLSID
*clsidEncoder
,
4224 GDIPCONST EncoderParameters
*encoderParams
)
4229 TRACE("%p (%s) %p %p\n", image
, debugstr_w(filename
), clsidEncoder
, encoderParams
);
4231 if (!image
|| !filename
|| !clsidEncoder
)
4232 return InvalidParameter
;
4234 stat
= GdipCreateStreamOnFile(filename
, GENERIC_WRITE
, &stream
);
4236 return GenericError
;
4238 stat
= GdipSaveImageToStream(image
, stream
, clsidEncoder
, encoderParams
);
4240 IStream_Release(stream
);
4244 /*************************************************************************
4245 * Encoding functions -
4246 * These functions encode an image in different image file formats.
4249 static GpStatus
encode_image_wic(GpImage
*image
, IStream
* stream
,
4250 REFGUID container
, GDIPCONST EncoderParameters
* params
)
4254 IWICImagingFactory
*factory
;
4255 IWICBitmapEncoder
*encoder
;
4256 IWICBitmapFrameEncode
*frameencode
;
4257 IPropertyBag2
*encoderoptions
;
4260 PixelFormat gdipformat
=0;
4261 const WICPixelFormatGUID
*desired_wicformat
;
4262 WICPixelFormatGUID wicformat
;
4264 BitmapData lockeddata
;
4267 if (image
->type
!= ImageTypeBitmap
)
4268 return GenericError
;
4270 bitmap
= (GpBitmap
*)image
;
4272 GdipGetImageWidth(image
, &width
);
4273 GdipGetImageHeight(image
, &height
);
4280 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
4282 return hresult_to_status(hr
);
4283 hr
= IWICImagingFactory_CreateEncoder(factory
, container
, NULL
, &encoder
);
4284 IWICImagingFactory_Release(factory
);
4286 return hresult_to_status(hr
);
4288 hr
= IWICBitmapEncoder_Initialize(encoder
, stream
, WICBitmapEncoderNoCache
);
4292 hr
= IWICBitmapEncoder_CreateNewFrame(encoder
, &frameencode
, &encoderoptions
);
4295 if (SUCCEEDED(hr
)) /* created frame */
4297 hr
= IWICBitmapFrameEncode_Initialize(frameencode
, encoderoptions
);
4300 hr
= IWICBitmapFrameEncode_SetSize(frameencode
, width
, height
);
4303 hr
= IWICBitmapFrameEncode_SetResolution(frameencode
, image
->xres
, image
->yres
);
4307 for (i
=0; pixel_formats
[i
].wic_format
; i
++)
4309 if (pixel_formats
[i
].gdip_format
== bitmap
->format
)
4311 desired_wicformat
= pixel_formats
[i
].wic_format
;
4312 gdipformat
= bitmap
->format
;
4318 desired_wicformat
= &GUID_WICPixelFormat32bppBGRA
;
4319 gdipformat
= PixelFormat32bppARGB
;
4322 memcpy(&wicformat
, desired_wicformat
, sizeof(GUID
));
4323 hr
= IWICBitmapFrameEncode_SetPixelFormat(frameencode
, &wicformat
);
4326 if (SUCCEEDED(hr
) && !IsEqualGUID(desired_wicformat
, &wicformat
))
4328 /* Encoder doesn't support this bitmap's format. */
4330 for (i
=0; pixel_formats
[i
].wic_format
; i
++)
4332 if (IsEqualGUID(&wicformat
, pixel_formats
[i
].wic_format
))
4334 gdipformat
= pixel_formats
[i
].gdip_format
;
4340 ERR("Cannot support encoder format %s\n", debugstr_guid(&wicformat
));
4347 stat
= GdipBitmapLockBits(bitmap
, &rc
, ImageLockModeRead
, gdipformat
,
4352 UINT row_size
= (lockeddata
.Width
* PIXELFORMATBPP(gdipformat
) + 7)/8;
4355 /* write one row at a time in case stride is negative */
4356 row
= lockeddata
.Scan0
;
4357 for (i
=0; i
<lockeddata
.Height
; i
++)
4359 hr
= IWICBitmapFrameEncode_WritePixels(frameencode
, 1, row_size
, row_size
, row
);
4360 if (FAILED(hr
)) break;
4361 row
+= lockeddata
.Stride
;
4364 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
4371 hr
= IWICBitmapFrameEncode_Commit(frameencode
);
4373 IWICBitmapFrameEncode_Release(frameencode
);
4374 IPropertyBag2_Release(encoderoptions
);
4378 hr
= IWICBitmapEncoder_Commit(encoder
);
4380 IWICBitmapEncoder_Release(encoder
);
4381 return hresult_to_status(hr
);
4384 static GpStatus
encode_image_BMP(GpImage
*image
, IStream
* stream
,
4385 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4387 return encode_image_wic(image
, stream
, &GUID_ContainerFormatBmp
, params
);
4390 static GpStatus
encode_image_tiff(GpImage
*image
, IStream
* stream
,
4391 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4393 return encode_image_wic(image
, stream
, &GUID_ContainerFormatTiff
, params
);
4396 static GpStatus
encode_image_png(GpImage
*image
, IStream
* stream
,
4397 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4399 return encode_image_wic(image
, stream
, &GUID_ContainerFormatPng
, params
);
4402 static GpStatus
encode_image_jpeg(GpImage
*image
, IStream
* stream
,
4403 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4405 return encode_image_wic(image
, stream
, &GUID_ContainerFormatJpeg
, params
);
4408 static GpStatus
encode_image_gif(GpImage
*image
, IStream
* stream
,
4409 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4411 return encode_image_wic(image
, stream
, &CLSID_WICGifEncoder
, params
);
4414 /*****************************************************************************
4415 * GdipSaveImageToStream [GDIPLUS.@]
4417 GpStatus WINGDIPAPI
GdipSaveImageToStream(GpImage
*image
, IStream
* stream
,
4418 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4421 encode_image_func encode_image
;
4424 TRACE("%p %p %p %p\n", image
, stream
, clsid
, params
);
4426 if(!image
|| !stream
)
4427 return InvalidParameter
;
4429 /* select correct encoder */
4430 encode_image
= NULL
;
4431 for (i
= 0; i
< NUM_CODECS
; i
++) {
4432 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
) &&
4433 IsEqualCLSID(clsid
, &codecs
[i
].info
.Clsid
))
4434 encode_image
= codecs
[i
].encode_func
;
4436 if (encode_image
== NULL
)
4437 return UnknownImageFormat
;
4439 stat
= encode_image(image
, stream
, clsid
, params
);
4444 /*****************************************************************************
4445 * GdipSaveAdd [GDIPLUS.@]
4447 GpStatus WINGDIPAPI
GdipSaveAdd(GpImage
*image
, GDIPCONST EncoderParameters
*params
)
4449 FIXME("(%p,%p): stub\n", image
, params
);
4453 /*****************************************************************************
4454 * GdipGetImagePalette [GDIPLUS.@]
4456 GpStatus WINGDIPAPI
GdipGetImagePalette(GpImage
*image
, ColorPalette
*palette
, INT size
)
4460 TRACE("(%p,%p,%i)\n", image
, palette
, size
);
4462 if (!image
|| !palette
)
4463 return InvalidParameter
;
4465 count
= image
->palette
? image
->palette
->Count
: 0;
4467 if (size
< (sizeof(UINT
)*2+sizeof(ARGB
)*count
))
4469 TRACE("<-- InsufficientBuffer\n");
4470 return InsufficientBuffer
;
4475 palette
->Flags
= image
->palette
->Flags
;
4476 palette
->Count
= image
->palette
->Count
;
4477 memcpy(palette
->Entries
, image
->palette
->Entries
, sizeof(ARGB
)*image
->palette
->Count
);
4487 /*****************************************************************************
4488 * GdipSetImagePalette [GDIPLUS.@]
4490 GpStatus WINGDIPAPI
GdipSetImagePalette(GpImage
*image
,
4491 GDIPCONST ColorPalette
*palette
)
4493 ColorPalette
*new_palette
;
4495 TRACE("(%p,%p)\n", image
, palette
);
4497 if(!image
|| !palette
|| palette
->Count
> 256)
4498 return InvalidParameter
;
4500 new_palette
= heap_alloc_zero(2 * sizeof(UINT
) + palette
->Count
* sizeof(ARGB
));
4501 if (!new_palette
) return OutOfMemory
;
4503 heap_free(image
->palette
);
4504 image
->palette
= new_palette
;
4505 image
->palette
->Flags
= palette
->Flags
;
4506 image
->palette
->Count
= palette
->Count
;
4507 memcpy(image
->palette
->Entries
, palette
->Entries
, sizeof(ARGB
)*palette
->Count
);
4512 /*************************************************************************
4514 * Structures that represent which formats we support for encoding.
4517 /* ImageCodecInfo creation routines taken from libgdiplus */
4518 static const WCHAR bmp_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
4519 static const WCHAR bmp_extension
[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
4520 static const WCHAR bmp_mimetype
[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
4521 static const WCHAR bmp_format
[] = {'B', 'M', 'P', 0}; /* BMP */
4522 static const BYTE bmp_sig_pattern
[] = { 0x42, 0x4D };
4523 static const BYTE bmp_sig_mask
[] = { 0xFF, 0xFF };
4525 static const WCHAR jpeg_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'J','P','E','G', 0};
4526 static const WCHAR jpeg_extension
[] = {'*','.','J','P','G',';', '*','.','J','P','E','G',';', '*','.','J','P','E',';', '*','.','J','F','I','F',0};
4527 static const WCHAR jpeg_mimetype
[] = {'i','m','a','g','e','/','j','p','e','g', 0};
4528 static const WCHAR jpeg_format
[] = {'J','P','E','G',0};
4529 static const BYTE jpeg_sig_pattern
[] = { 0xFF, 0xD8 };
4530 static const BYTE jpeg_sig_mask
[] = { 0xFF, 0xFF };
4532 static const WCHAR gif_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'G','I','F', 0};
4533 static const WCHAR gif_extension
[] = {'*','.','G','I','F',0};
4534 static const WCHAR gif_mimetype
[] = {'i','m','a','g','e','/','g','i','f', 0};
4535 static const WCHAR gif_format
[] = {'G','I','F',0};
4536 static const BYTE gif_sig_pattern
[12] = "GIF87aGIF89a";
4537 static const BYTE gif_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4539 static const WCHAR tiff_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'T','I','F','F', 0};
4540 static const WCHAR tiff_extension
[] = {'*','.','T','I','F','F',';','*','.','T','I','F',0};
4541 static const WCHAR tiff_mimetype
[] = {'i','m','a','g','e','/','t','i','f','f', 0};
4542 static const WCHAR tiff_format
[] = {'T','I','F','F',0};
4543 static const BYTE tiff_sig_pattern
[] = {0x49,0x49,42,0,0x4d,0x4d,0,42};
4544 static const BYTE tiff_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4546 static const WCHAR emf_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'E','M','F', 0};
4547 static const WCHAR emf_extension
[] = {'*','.','E','M','F',0};
4548 static const WCHAR emf_mimetype
[] = {'i','m','a','g','e','/','x','-','e','m','f', 0};
4549 static const WCHAR emf_format
[] = {'E','M','F',0};
4550 static const BYTE emf_sig_pattern
[] = { 0x01, 0x00, 0x00, 0x00 };
4551 static const BYTE emf_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
4553 static const WCHAR wmf_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'W','M','F', 0};
4554 static const WCHAR wmf_extension
[] = {'*','.','W','M','F',0};
4555 static const WCHAR wmf_mimetype
[] = {'i','m','a','g','e','/','x','-','w','m','f', 0};
4556 static const WCHAR wmf_format
[] = {'W','M','F',0};
4557 static const BYTE wmf_sig_pattern
[] = { 0xd7, 0xcd };
4558 static const BYTE wmf_sig_mask
[] = { 0xFF, 0xFF };
4560 static const WCHAR png_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'P','N','G', 0};
4561 static const WCHAR png_extension
[] = {'*','.','P','N','G',0};
4562 static const WCHAR png_mimetype
[] = {'i','m','a','g','e','/','p','n','g', 0};
4563 static const WCHAR png_format
[] = {'P','N','G',0};
4564 static const BYTE png_sig_pattern
[] = { 137, 80, 78, 71, 13, 10, 26, 10, };
4565 static const BYTE png_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4567 static const WCHAR ico_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'I','C','O', 0};
4568 static const WCHAR ico_extension
[] = {'*','.','I','C','O',0};
4569 static const WCHAR ico_mimetype
[] = {'i','m','a','g','e','/','x','-','i','c','o','n', 0};
4570 static const WCHAR ico_format
[] = {'I','C','O',0};
4571 static const BYTE ico_sig_pattern
[] = { 0x00, 0x00, 0x01, 0x00 };
4572 static const BYTE ico_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
4574 static const struct image_codec codecs
[NUM_CODECS
] = {
4577 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4578 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4579 /* CodecName */ bmp_codecname
,
4581 /* FormatDescription */ bmp_format
,
4582 /* FilenameExtension */ bmp_extension
,
4583 /* MimeType */ bmp_mimetype
,
4584 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4588 /* SigPattern */ bmp_sig_pattern
,
4589 /* SigMask */ bmp_sig_mask
,
4597 /* Clsid */ { 0x557cf401, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4598 /* FormatID */ { 0xb96b3caeU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4599 /* CodecName */ jpeg_codecname
,
4601 /* FormatDescription */ jpeg_format
,
4602 /* FilenameExtension */ jpeg_extension
,
4603 /* MimeType */ jpeg_mimetype
,
4604 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4608 /* SigPattern */ jpeg_sig_pattern
,
4609 /* SigMask */ jpeg_sig_mask
,
4617 /* Clsid */ { 0x557cf402, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4618 /* FormatID */ { 0xb96b3cb0U
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4619 /* CodecName */ gif_codecname
,
4621 /* FormatDescription */ gif_format
,
4622 /* FilenameExtension */ gif_extension
,
4623 /* MimeType */ gif_mimetype
,
4624 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsEncoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4628 /* SigPattern */ gif_sig_pattern
,
4629 /* SigMask */ gif_sig_mask
,
4637 /* Clsid */ { 0x557cf405, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4638 /* FormatID */ { 0xb96b3cb1U
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4639 /* CodecName */ tiff_codecname
,
4641 /* FormatDescription */ tiff_format
,
4642 /* FilenameExtension */ tiff_extension
,
4643 /* MimeType */ tiff_mimetype
,
4644 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsEncoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4648 /* SigPattern */ tiff_sig_pattern
,
4649 /* SigMask */ tiff_sig_mask
,
4657 /* Clsid */ { 0x557cf403, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4658 /* FormatID */ { 0xb96b3cacU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4659 /* CodecName */ emf_codecname
,
4661 /* FormatDescription */ emf_format
,
4662 /* FilenameExtension */ emf_extension
,
4663 /* MimeType */ emf_mimetype
,
4664 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
4668 /* SigPattern */ emf_sig_pattern
,
4669 /* SigMask */ emf_sig_mask
,
4672 decode_image_olepicture_metafile
,
4677 /* Clsid */ { 0x557cf404, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4678 /* FormatID */ { 0xb96b3cadU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4679 /* CodecName */ wmf_codecname
,
4681 /* FormatDescription */ wmf_format
,
4682 /* FilenameExtension */ wmf_extension
,
4683 /* MimeType */ wmf_mimetype
,
4684 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
4688 /* SigPattern */ wmf_sig_pattern
,
4689 /* SigMask */ wmf_sig_mask
,
4692 decode_image_olepicture_metafile
,
4697 /* Clsid */ { 0x557cf406, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4698 /* FormatID */ { 0xb96b3cafU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4699 /* CodecName */ png_codecname
,
4701 /* FormatDescription */ png_format
,
4702 /* FilenameExtension */ png_extension
,
4703 /* MimeType */ png_mimetype
,
4704 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4708 /* SigPattern */ png_sig_pattern
,
4709 /* SigMask */ png_sig_mask
,
4717 /* Clsid */ { 0x557cf407, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4718 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4719 /* CodecName */ ico_codecname
,
4721 /* FormatDescription */ ico_format
,
4722 /* FilenameExtension */ ico_extension
,
4723 /* MimeType */ ico_mimetype
,
4724 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4728 /* SigPattern */ ico_sig_pattern
,
4729 /* SigMask */ ico_sig_mask
,
4737 /*****************************************************************************
4738 * GdipGetImageDecodersSize [GDIPLUS.@]
4740 GpStatus WINGDIPAPI
GdipGetImageDecodersSize(UINT
*numDecoders
, UINT
*size
)
4742 int decoder_count
=0;
4744 TRACE("%p %p\n", numDecoders
, size
);
4746 if (!numDecoders
|| !size
)
4747 return InvalidParameter
;
4749 for (i
=0; i
<NUM_CODECS
; i
++)
4751 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
4755 *numDecoders
= decoder_count
;
4756 *size
= decoder_count
* sizeof(ImageCodecInfo
);
4761 /*****************************************************************************
4762 * GdipGetImageDecoders [GDIPLUS.@]
4764 GpStatus WINGDIPAPI
GdipGetImageDecoders(UINT numDecoders
, UINT size
, ImageCodecInfo
*decoders
)
4766 int i
, decoder_count
=0;
4767 TRACE("%u %u %p\n", numDecoders
, size
, decoders
);
4770 size
!= numDecoders
* sizeof(ImageCodecInfo
))
4771 return GenericError
;
4773 for (i
=0; i
<NUM_CODECS
; i
++)
4775 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
4777 if (decoder_count
== numDecoders
) return GenericError
;
4778 memcpy(&decoders
[decoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
4783 if (decoder_count
< numDecoders
) return GenericError
;
4788 /*****************************************************************************
4789 * GdipGetImageEncodersSize [GDIPLUS.@]
4791 GpStatus WINGDIPAPI
GdipGetImageEncodersSize(UINT
*numEncoders
, UINT
*size
)
4793 int encoder_count
=0;
4795 TRACE("%p %p\n", numEncoders
, size
);
4797 if (!numEncoders
|| !size
)
4798 return InvalidParameter
;
4800 for (i
=0; i
<NUM_CODECS
; i
++)
4802 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
4806 *numEncoders
= encoder_count
;
4807 *size
= encoder_count
* sizeof(ImageCodecInfo
);
4812 /*****************************************************************************
4813 * GdipGetImageEncoders [GDIPLUS.@]
4815 GpStatus WINGDIPAPI
GdipGetImageEncoders(UINT numEncoders
, UINT size
, ImageCodecInfo
*encoders
)
4817 int i
, encoder_count
=0;
4818 TRACE("%u %u %p\n", numEncoders
, size
, encoders
);
4821 size
!= numEncoders
* sizeof(ImageCodecInfo
))
4822 return GenericError
;
4824 for (i
=0; i
<NUM_CODECS
; i
++)
4826 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
4828 if (encoder_count
== numEncoders
) return GenericError
;
4829 memcpy(&encoders
[encoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
4834 if (encoder_count
< numEncoders
) return GenericError
;
4839 GpStatus WINGDIPAPI
GdipGetEncoderParameterListSize(GpImage
*image
,
4840 GDIPCONST CLSID
* clsidEncoder
, UINT
*size
)
4844 TRACE("(%p,%s,%p)\n", image
, debugstr_guid(clsidEncoder
), size
);
4847 FIXME("not implemented\n");
4851 return NotImplemented
;
4854 static PixelFormat
get_16bpp_format(HBITMAP hbm
)
4860 hdc
= CreateCompatibleDC(NULL
);
4862 memset(&bmh
, 0, sizeof(bmh
));
4863 bmh
.bV4Size
= sizeof(bmh
);
4866 bmh
.bV4V4Compression
= BI_BITFIELDS
;
4867 bmh
.bV4BitCount
= 16;
4869 GetDIBits(hdc
, hbm
, 0, 0, NULL
, (BITMAPINFO
*)&bmh
, DIB_RGB_COLORS
);
4871 if (bmh
.bV4RedMask
== 0x7c00 &&
4872 bmh
.bV4GreenMask
== 0x3e0 &&
4873 bmh
.bV4BlueMask
== 0x1f)
4875 result
= PixelFormat16bppRGB555
;
4877 else if (bmh
.bV4RedMask
== 0xf800 &&
4878 bmh
.bV4GreenMask
== 0x7e0 &&
4879 bmh
.bV4BlueMask
== 0x1f)
4881 result
= PixelFormat16bppRGB565
;
4885 FIXME("unrecognized bitfields %x,%x,%x\n", bmh
.bV4RedMask
,
4886 bmh
.bV4GreenMask
, bmh
.bV4BlueMask
);
4887 result
= PixelFormatUndefined
;
4895 /*****************************************************************************
4896 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
4898 GpStatus WINGDIPAPI
GdipCreateBitmapFromHBITMAP(HBITMAP hbm
, HPALETTE hpal
, GpBitmap
** bitmap
)
4903 BitmapData lockeddata
;
4905 TRACE("%p %p %p\n", hbm
, hpal
, bitmap
);
4908 return InvalidParameter
;
4910 if (GetObjectA(hbm
, sizeof(bm
), &bm
) != sizeof(bm
))
4911 return InvalidParameter
;
4913 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
4914 switch(bm
.bmBitsPixel
) {
4916 format
= PixelFormat1bppIndexed
;
4919 format
= PixelFormat4bppIndexed
;
4922 format
= PixelFormat8bppIndexed
;
4925 format
= get_16bpp_format(hbm
);
4926 if (format
== PixelFormatUndefined
)
4927 return InvalidParameter
;
4930 format
= PixelFormat24bppRGB
;
4933 format
= PixelFormat32bppRGB
;
4936 format
= PixelFormat48bppRGB
;
4939 FIXME("don't know how to handle %d bpp\n", bm
.bmBitsPixel
);
4940 return InvalidParameter
;
4943 retval
= GdipCreateBitmapFromScan0(bm
.bmWidth
, bm
.bmHeight
, 0,
4944 format
, NULL
, bitmap
);
4948 retval
= GdipBitmapLockBits(*bitmap
, NULL
, ImageLockModeWrite
,
4949 format
, &lockeddata
);
4953 char bmibuf
[FIELD_OFFSET(BITMAPINFO
, bmiColors
[256])];
4954 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
4957 hdc
= CreateCompatibleDC(NULL
);
4959 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
4960 pbmi
->bmiHeader
.biBitCount
= 0;
4962 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
4964 src_height
= abs(pbmi
->bmiHeader
.biHeight
);
4965 pbmi
->bmiHeader
.biHeight
= -src_height
;
4967 GetDIBits(hdc
, hbm
, 0, src_height
, lockeddata
.Scan0
, pbmi
, DIB_RGB_COLORS
);
4971 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
4974 if (retval
== Ok
&& hpal
)
4976 PALETTEENTRY entry
[256];
4977 ColorPalette
*palette
=NULL
;
4978 int i
, num_palette_entries
;
4980 num_palette_entries
= GetPaletteEntries(hpal
, 0, 256, entry
);
4981 if (!num_palette_entries
)
4982 retval
= GenericError
;
4984 palette
= heap_alloc_zero(sizeof(ColorPalette
) + sizeof(ARGB
) * (num_palette_entries
-1));
4986 retval
= OutOfMemory
;
4991 palette
->Count
= num_palette_entries
;
4993 for (i
=0; i
<num_palette_entries
; i
++)
4995 palette
->Entries
[i
] = 0xff000000 | entry
[i
].peRed
<< 16 |
4996 entry
[i
].peGreen
<< 8 | entry
[i
].peBlue
;
4999 retval
= GdipSetImagePalette((GpImage
*)*bitmap
, palette
);
5007 GdipDisposeImage((GpImage
*)*bitmap
);
5015 /*****************************************************************************
5016 * GdipCreateEffect [GDIPLUS.@]
5018 GpStatus WINGDIPAPI
GdipCreateEffect(const GUID guid
, CGpEffect
**effect
)
5020 FIXME("(%s, %p): stub\n", debugstr_guid(&guid
), effect
);
5023 return InvalidParameter
;
5027 return NotImplemented
;
5030 /*****************************************************************************
5031 * GdipDeleteEffect [GDIPLUS.@]
5033 GpStatus WINGDIPAPI
GdipDeleteEffect(CGpEffect
*effect
)
5035 FIXME("(%p): stub\n", effect
);
5036 /* note: According to Jose Roca's GDI+ Docs, this is not implemented
5037 * in Windows's gdiplus */
5038 return NotImplemented
;
5041 /*****************************************************************************
5042 * GdipSetEffectParameters [GDIPLUS.@]
5044 GpStatus WINGDIPAPI
GdipSetEffectParameters(CGpEffect
*effect
,
5045 const VOID
*params
, const UINT size
)
5049 TRACE("(%p,%p,%u)\n", effect
, params
, size
);
5052 FIXME("not implemented\n");
5054 return NotImplemented
;
5057 /*****************************************************************************
5058 * GdipGetImageFlags [GDIPLUS.@]
5060 GpStatus WINGDIPAPI
GdipGetImageFlags(GpImage
*image
, UINT
*flags
)
5062 TRACE("%p %p\n", image
, flags
);
5064 if(!image
|| !flags
)
5065 return InvalidParameter
;
5067 *flags
= image
->flags
;
5072 GpStatus WINGDIPAPI
GdipTestControl(GpTestControlEnum control
, void *param
)
5074 TRACE("(%d, %p)\n", control
, param
);
5077 case TestControlForceBilinear
:
5079 FIXME("TestControlForceBilinear not handled\n");
5081 case TestControlNoICM
:
5083 FIXME("TestControlNoICM not handled\n");
5085 case TestControlGetBuildNumber
:
5086 *((DWORD
*)param
) = 3102;
5093 GpStatus WINGDIPAPI
GdipImageForceValidation(GpImage
*image
)
5095 TRACE("%p\n", image
);
5100 /*****************************************************************************
5101 * GdipGetImageThumbnail [GDIPLUS.@]
5103 GpStatus WINGDIPAPI
GdipGetImageThumbnail(GpImage
*image
, UINT width
, UINT height
,
5104 GpImage
**ret_image
, GetThumbnailImageAbort cb
,
5108 GpGraphics
*graphics
;
5109 UINT srcwidth
, srcheight
;
5111 TRACE("(%p %u %u %p %p %p)\n",
5112 image
, width
, height
, ret_image
, cb
, cb_data
);
5114 if (!image
|| !ret_image
)
5115 return InvalidParameter
;
5117 if (!width
) width
= 120;
5118 if (!height
) height
= 120;
5120 GdipGetImageWidth(image
, &srcwidth
);
5121 GdipGetImageHeight(image
, &srcheight
);
5123 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat32bppPARGB
,
5124 NULL
, (GpBitmap
**)ret_image
);
5128 stat
= GdipGetImageGraphicsContext(*ret_image
, &graphics
);
5132 stat
= GdipDrawImageRectRectI(graphics
, image
,
5133 0, 0, width
, height
, 0, 0, srcwidth
, srcheight
, UnitPixel
,
5136 GdipDeleteGraphics(graphics
);
5141 GdipDisposeImage(*ret_image
);
5149 /*****************************************************************************
5150 * GdipImageRotateFlip [GDIPLUS.@]
5152 GpStatus WINGDIPAPI
GdipImageRotateFlip(GpImage
*image
, RotateFlipType type
)
5154 GpBitmap
*new_bitmap
;
5156 int bpp
, bytesperpixel
;
5157 BOOL rotate_90
, flip_x
, flip_y
;
5158 int src_x_offset
, src_y_offset
;
5160 UINT x
, y
, width
, height
;
5161 BitmapData src_lock
, dst_lock
;
5164 TRACE("(%p, %u)\n", image
, type
);
5167 return InvalidParameter
;
5170 flip_x
= (type
&6) == 2 || (type
&6) == 4;
5171 flip_y
= (type
&3) == 1 || (type
&3) == 2;
5173 if (image
->type
!= ImageTypeBitmap
)
5175 FIXME("Not implemented for type %i\n", image
->type
);
5176 return NotImplemented
;
5179 bitmap
= (GpBitmap
*)image
;
5180 bpp
= PIXELFORMATBPP(bitmap
->format
);
5184 FIXME("Not implemented for %i bit images\n", bpp
);
5185 return NotImplemented
;
5190 width
= bitmap
->height
;
5191 height
= bitmap
->width
;
5195 width
= bitmap
->width
;
5196 height
= bitmap
->height
;
5199 bytesperpixel
= bpp
/8;
5201 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, bitmap
->format
, NULL
, &new_bitmap
);
5206 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, bitmap
->format
, &src_lock
);
5210 stat
= GdipBitmapLockBits(new_bitmap
, NULL
, ImageLockModeWrite
, bitmap
->format
, &dst_lock
);
5214 LPBYTE src_row
, src_pixel
;
5215 LPBYTE dst_row
, dst_pixel
;
5217 src_origin
= src_lock
.Scan0
;
5218 if (flip_x
) src_origin
+= bytesperpixel
* (bitmap
->width
- 1);
5219 if (flip_y
) src_origin
+= src_lock
.Stride
* (bitmap
->height
- 1);
5223 if (flip_y
) src_x_offset
= -src_lock
.Stride
;
5224 else src_x_offset
= src_lock
.Stride
;
5225 if (flip_x
) src_y_offset
= -bytesperpixel
;
5226 else src_y_offset
= bytesperpixel
;
5230 if (flip_x
) src_x_offset
= -bytesperpixel
;
5231 else src_x_offset
= bytesperpixel
;
5232 if (flip_y
) src_y_offset
= -src_lock
.Stride
;
5233 else src_y_offset
= src_lock
.Stride
;
5236 src_row
= src_origin
;
5237 dst_row
= dst_lock
.Scan0
;
5238 for (y
=0; y
<height
; y
++)
5240 src_pixel
= src_row
;
5241 dst_pixel
= dst_row
;
5242 for (x
=0; x
<width
; x
++)
5244 /* FIXME: This could probably be faster without memcpy. */
5245 memcpy(dst_pixel
, src_pixel
, bytesperpixel
);
5246 dst_pixel
+= bytesperpixel
;
5247 src_pixel
+= src_x_offset
;
5249 src_row
+= src_y_offset
;
5250 dst_row
+= dst_lock
.Stride
;
5253 GdipBitmapUnlockBits(new_bitmap
, &dst_lock
);
5256 GdipBitmapUnlockBits(bitmap
, &src_lock
);
5260 move_bitmap(bitmap
, new_bitmap
, FALSE
);
5262 GdipDisposeImage((GpImage
*)new_bitmap
);
5267 /*****************************************************************************
5268 * GdipImageSetAbort [GDIPLUS.@]
5270 GpStatus WINGDIPAPI
GdipImageSetAbort(GpImage
*image
, GdiplusAbort
*pabort
)
5272 FIXME("(%p, %p): stub\n", image
, pabort
);
5273 return NotImplemented
;
5276 /*****************************************************************************
5277 * GdipBitmapConvertFormat [GDIPLUS.@]
5279 GpStatus WINGDIPAPI
GdipBitmapConvertFormat(GpBitmap
*bitmap
, PixelFormat format
, DitherType dithertype
,
5280 PaletteType palettetype
, ColorPalette
*palette
, REAL alphathreshold
)
5282 FIXME("(%p, 0x%08x, %d, %d, %p, %f): stub\n", bitmap
, format
, dithertype
, palettetype
, palette
, alphathreshold
);
5283 return NotImplemented
;