2 * Copyright (C) 2007 Google (Evan Stade)
3 * Copyright (C) 2012,2016 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)
46 #define WMF_PLACEABLE_KEY 0x9ac6cdd7
50 const WICPixelFormatGUID
*wic_format
;
51 PixelFormat gdip_format
;
52 /* predefined palette type to use for pixel format conversions */
53 WICBitmapPaletteType palette_type
;
56 { &GUID_WICPixelFormatBlackWhite
, PixelFormat1bppIndexed
, WICBitmapPaletteTypeFixedBW
},
57 { &GUID_WICPixelFormat1bppIndexed
, PixelFormat1bppIndexed
, WICBitmapPaletteTypeFixedBW
},
58 { &GUID_WICPixelFormat8bppGray
, PixelFormat8bppIndexed
, WICBitmapPaletteTypeFixedGray256
},
59 { &GUID_WICPixelFormat8bppIndexed
, PixelFormat8bppIndexed
, WICBitmapPaletteTypeFixedHalftone256
},
60 { &GUID_WICPixelFormat16bppBGR555
, PixelFormat16bppRGB555
, WICBitmapPaletteTypeFixedHalftone256
},
61 { &GUID_WICPixelFormat24bppBGR
, PixelFormat24bppRGB
, WICBitmapPaletteTypeFixedHalftone256
},
62 { &GUID_WICPixelFormat32bppBGR
, PixelFormat32bppRGB
, WICBitmapPaletteTypeFixedHalftone256
},
63 { &GUID_WICPixelFormat32bppBGRA
, PixelFormat32bppARGB
, WICBitmapPaletteTypeFixedHalftone256
},
64 { &GUID_WICPixelFormat32bppPBGRA
, PixelFormat32bppPARGB
, WICBitmapPaletteTypeFixedHalftone256
},
68 static ColorPalette
*get_palette(IWICBitmapFrameDecode
*frame
, WICBitmapPaletteType palette_type
)
71 IWICImagingFactory
*factory
;
72 IWICPalette
*wic_palette
;
73 ColorPalette
*palette
= NULL
;
75 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
76 if (hr
!= S_OK
) return NULL
;
78 hr
= IWICImagingFactory_CreatePalette(factory
, &wic_palette
);
81 hr
= WINCODEC_ERR_PALETTEUNAVAILABLE
;
83 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, wic_palette
);
86 TRACE("using predefined palette %#x\n", palette_type
);
87 hr
= IWICPalette_InitializePredefined(wic_palette
, palette_type
, FALSE
);
91 WICBitmapPaletteType type
;
95 IWICPalette_GetColorCount(wic_palette
, &count
);
96 palette
= heap_alloc(2 * sizeof(UINT
) + count
* sizeof(ARGB
));
97 IWICPalette_GetColors(wic_palette
, count
, palette
->Entries
, &palette
->Count
);
99 IWICPalette_GetType(wic_palette
, &type
);
101 case WICBitmapPaletteTypeFixedGray4
:
102 case WICBitmapPaletteTypeFixedGray16
:
103 case WICBitmapPaletteTypeFixedGray256
:
104 palette
->Flags
= PaletteFlagsGrayScale
;
106 case WICBitmapPaletteTypeFixedHalftone8
:
107 case WICBitmapPaletteTypeFixedHalftone27
:
108 case WICBitmapPaletteTypeFixedHalftone64
:
109 case WICBitmapPaletteTypeFixedHalftone125
:
110 case WICBitmapPaletteTypeFixedHalftone216
:
111 case WICBitmapPaletteTypeFixedHalftone252
:
112 case WICBitmapPaletteTypeFixedHalftone256
:
113 palette
->Flags
= PaletteFlagsHalftone
;
118 IWICPalette_HasAlpha(wic_palette
, &alpha
);
120 palette
->Flags
|= PaletteFlagsHasAlpha
;
122 IWICPalette_Release(wic_palette
);
124 IWICImagingFactory_Release(factory
);
128 GpStatus WINGDIPAPI
GdipBitmapApplyEffect(GpBitmap
* bitmap
, CGpEffect
* effect
,
129 RECT
* roi
, BOOL useAuxData
, VOID
** auxData
, INT
* auxDataSize
)
131 FIXME("(%p %p %p %d %p %p): stub\n", bitmap
, effect
, roi
, useAuxData
, auxData
, auxDataSize
);
133 * Note: According to Jose Roca's GDI+ docs, this function is not
134 * implemented in Windows's GDI+.
136 return NotImplemented
;
139 GpStatus WINGDIPAPI
GdipBitmapCreateApplyEffect(GpBitmap
** inputBitmaps
,
140 INT numInputs
, CGpEffect
* effect
, RECT
* roi
, RECT
* outputRect
,
141 GpBitmap
** outputBitmap
, BOOL useAuxData
, VOID
** auxData
, INT
* auxDataSize
)
143 FIXME("(%p %d %p %p %p %p %d %p %p): stub\n", inputBitmaps
, numInputs
, effect
, roi
, outputRect
, outputBitmap
, useAuxData
, auxData
, auxDataSize
);
145 * Note: According to Jose Roca's GDI+ docs, this function is not
146 * implemented in Windows's GDI+.
148 return NotImplemented
;
151 static inline void getpixel_1bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
153 *index
= (row
[x
/8]>>(7-x
%8)) & 1;
156 static inline void getpixel_4bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
159 *index
= row
[x
/2]&0xf;
161 *index
= row
[x
/2]>>4;
164 static inline void getpixel_8bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
169 static inline void getpixel_16bppGrayScale(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
170 const BYTE
*row
, UINT x
)
172 *r
= *g
= *b
= row
[x
*2+1];
176 static inline void getpixel_16bppRGB555(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
177 const BYTE
*row
, UINT x
)
179 WORD pixel
= *((const WORD
*)(row
)+x
);
180 *r
= (pixel
>>7&0xf8)|(pixel
>>12&0x7);
181 *g
= (pixel
>>2&0xf8)|(pixel
>>6&0x7);
182 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
186 static inline void getpixel_16bppRGB565(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
187 const BYTE
*row
, UINT x
)
189 WORD pixel
= *((const WORD
*)(row
)+x
);
190 *r
= (pixel
>>8&0xf8)|(pixel
>>13&0x7);
191 *g
= (pixel
>>3&0xfc)|(pixel
>>9&0x3);
192 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
196 static inline void getpixel_16bppARGB1555(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
197 const BYTE
*row
, UINT x
)
199 WORD pixel
= *((const WORD
*)(row
)+x
);
200 *r
= (pixel
>>7&0xf8)|(pixel
>>12&0x7);
201 *g
= (pixel
>>2&0xf8)|(pixel
>>6&0x7);
202 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
203 if ((pixel
&0x8000) == 0x8000)
209 static inline void getpixel_24bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
210 const BYTE
*row
, UINT x
)
218 static inline void getpixel_32bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
219 const BYTE
*row
, UINT x
)
227 static inline void getpixel_32bppARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
228 const BYTE
*row
, UINT x
)
236 static inline void getpixel_32bppPARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
237 const BYTE
*row
, UINT x
)
244 *r
= row
[x
*4+2] * 255 / *a
;
245 *g
= row
[x
*4+1] * 255 / *a
;
246 *b
= row
[x
*4] * 255 / *a
;
250 static inline void getpixel_48bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
251 const BYTE
*row
, UINT x
)
259 static inline void getpixel_64bppARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
260 const BYTE
*row
, UINT x
)
268 static inline void getpixel_64bppPARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
269 const BYTE
*row
, UINT x
)
276 *r
= row
[x
*8+5] * 255 / *a
;
277 *g
= row
[x
*8+3] * 255 / *a
;
278 *b
= row
[x
*8+1] * 255 / *a
;
282 GpStatus WINGDIPAPI
GdipBitmapGetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
289 if(!bitmap
|| !color
||
290 x
< 0 || y
< 0 || x
>= bitmap
->width
|| y
>= bitmap
->height
)
291 return InvalidParameter
;
293 row
= bitmap
->bits
+bitmap
->stride
*y
;
295 switch (bitmap
->format
)
297 case PixelFormat1bppIndexed
:
298 getpixel_1bppIndexed(&index
,row
,x
);
300 case PixelFormat4bppIndexed
:
301 getpixel_4bppIndexed(&index
,row
,x
);
303 case PixelFormat8bppIndexed
:
304 getpixel_8bppIndexed(&index
,row
,x
);
306 case PixelFormat16bppGrayScale
:
307 getpixel_16bppGrayScale(&r
,&g
,&b
,&a
,row
,x
);
309 case PixelFormat16bppRGB555
:
310 getpixel_16bppRGB555(&r
,&g
,&b
,&a
,row
,x
);
312 case PixelFormat16bppRGB565
:
313 getpixel_16bppRGB565(&r
,&g
,&b
,&a
,row
,x
);
315 case PixelFormat16bppARGB1555
:
316 getpixel_16bppARGB1555(&r
,&g
,&b
,&a
,row
,x
);
318 case PixelFormat24bppRGB
:
319 getpixel_24bppRGB(&r
,&g
,&b
,&a
,row
,x
);
321 case PixelFormat32bppRGB
:
322 getpixel_32bppRGB(&r
,&g
,&b
,&a
,row
,x
);
324 case PixelFormat32bppARGB
:
325 getpixel_32bppARGB(&r
,&g
,&b
,&a
,row
,x
);
327 case PixelFormat32bppPARGB
:
328 getpixel_32bppPARGB(&r
,&g
,&b
,&a
,row
,x
);
330 case PixelFormat48bppRGB
:
331 getpixel_48bppRGB(&r
,&g
,&b
,&a
,row
,x
);
333 case PixelFormat64bppARGB
:
334 getpixel_64bppARGB(&r
,&g
,&b
,&a
,row
,x
);
336 case PixelFormat64bppPARGB
:
337 getpixel_64bppPARGB(&r
,&g
,&b
,&a
,row
,x
);
340 FIXME("not implemented for format 0x%x\n", bitmap
->format
);
341 return NotImplemented
;
344 if (bitmap
->format
& PixelFormatIndexed
)
345 *color
= bitmap
->image
.palette
->Entries
[index
];
347 *color
= a
<<24|r
<<16|g
<<8|b
;
352 static inline UINT
get_palette_index(BYTE r
, BYTE g
, BYTE b
, BYTE a
, ColorPalette
*palette
)
355 int best_distance
= 0x7fff;
359 if (!palette
) return 0;
360 /* This algorithm scans entire palette,
361 computes difference from desired color (all color components have equal weight)
362 and returns the index of color with least difference.
364 Note: Maybe it could be replaced with a better algorithm for better image quality
365 and performance, though better algorithm would probably need some pre-built lookup
366 tables and thus may actually be slower if this method is called only few times per
369 for(i
=0;i
<palette
->Count
;i
++) {
370 ARGB color
=palette
->Entries
[i
];
371 distance
=abs(b
-(color
& 0xff)) + abs(g
-(color
>>8 & 0xff)) + abs(r
-(color
>>16 & 0xff)) + abs(a
-(color
>>24 & 0xff));
372 if (distance
<best_distance
) {
373 best_distance
=distance
;
380 static inline void setpixel_8bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
381 BYTE
*row
, UINT x
, ColorPalette
*palette
)
383 BYTE index
= get_palette_index(r
,g
,b
,a
,palette
);
387 static inline void setpixel_1bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
388 BYTE
*row
, UINT x
, ColorPalette
*palette
)
390 row
[x
/8] = (row
[x
/8] & ~(1<<(7-x
%8))) | (get_palette_index(r
,g
,b
,a
,palette
)<<(7-x
%8));
393 static inline void setpixel_4bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
394 BYTE
*row
, UINT x
, ColorPalette
*palette
)
397 row
[x
/2] = (row
[x
/2] & 0xf0) | get_palette_index(r
,g
,b
,a
,palette
);
399 row
[x
/2] = (row
[x
/2] & 0x0f) | get_palette_index(r
,g
,b
,a
,palette
)<<4;
402 static inline void setpixel_16bppGrayScale(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
405 *((WORD
*)(row
)+x
) = (r
+g
+b
)*85;
408 static inline void setpixel_16bppRGB555(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
411 *((WORD
*)(row
)+x
) = (r
<<7&0x7c00)|
416 static inline void setpixel_16bppRGB565(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
419 *((WORD
*)(row
)+x
) = (r
<<8&0xf800)|
424 static inline void setpixel_16bppARGB1555(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
427 *((WORD
*)(row
)+x
) = (a
<<8&0x8000)|
433 static inline void setpixel_24bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
441 static inline void setpixel_32bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
444 *((DWORD
*)(row
)+x
) = (r
<<16)|(g
<<8)|b
;
447 static inline void setpixel_32bppARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
450 *((DWORD
*)(row
)+x
) = (a
<<24)|(r
<<16)|(g
<<8)|b
;
453 static inline void setpixel_32bppPARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
459 *((DWORD
*)(row
)+x
) = (a
<<24)|(r
<<16)|(g
<<8)|b
;
462 static inline void setpixel_48bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
465 row
[x
*6+5] = row
[x
*6+4] = r
;
466 row
[x
*6+3] = row
[x
*6+2] = g
;
467 row
[x
*6+1] = row
[x
*6] = b
;
470 static inline void setpixel_64bppARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
473 UINT64 a64
=a
, r64
=r
, g64
=g
, b64
=b
;
474 *((UINT64
*)(row
)+x
) = (a64
<<56)|(a64
<<48)|(r64
<<40)|(r64
<<32)|(g64
<<24)|(g64
<<16)|(b64
<<8)|b64
;
477 static inline void setpixel_64bppPARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
480 UINT64 a64
, r64
, g64
, b64
;
485 *((UINT64
*)(row
)+x
) = (a64
<<48)|(r64
<<32)|(g64
<<16)|b64
;
488 GpStatus WINGDIPAPI
GdipBitmapSetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
494 if(!bitmap
|| x
< 0 || y
< 0 || x
>= bitmap
->width
|| y
>= bitmap
->height
)
495 return InvalidParameter
;
502 row
= bitmap
->bits
+ bitmap
->stride
* y
;
504 switch (bitmap
->format
)
506 case PixelFormat16bppGrayScale
:
507 setpixel_16bppGrayScale(r
,g
,b
,a
,row
,x
);
509 case PixelFormat16bppRGB555
:
510 setpixel_16bppRGB555(r
,g
,b
,a
,row
,x
);
512 case PixelFormat16bppRGB565
:
513 setpixel_16bppRGB565(r
,g
,b
,a
,row
,x
);
515 case PixelFormat16bppARGB1555
:
516 setpixel_16bppARGB1555(r
,g
,b
,a
,row
,x
);
518 case PixelFormat24bppRGB
:
519 setpixel_24bppRGB(r
,g
,b
,a
,row
,x
);
521 case PixelFormat32bppRGB
:
522 setpixel_32bppRGB(r
,g
,b
,a
,row
,x
);
524 case PixelFormat32bppARGB
:
525 setpixel_32bppARGB(r
,g
,b
,a
,row
,x
);
527 case PixelFormat32bppPARGB
:
528 setpixel_32bppPARGB(r
,g
,b
,a
,row
,x
);
530 case PixelFormat48bppRGB
:
531 setpixel_48bppRGB(r
,g
,b
,a
,row
,x
);
533 case PixelFormat64bppARGB
:
534 setpixel_64bppARGB(r
,g
,b
,a
,row
,x
);
536 case PixelFormat64bppPARGB
:
537 setpixel_64bppPARGB(r
,g
,b
,a
,row
,x
);
539 case PixelFormat8bppIndexed
:
540 setpixel_8bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
542 case PixelFormat4bppIndexed
:
543 setpixel_4bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
545 case PixelFormat1bppIndexed
:
546 setpixel_1bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
549 FIXME("not implemented for format 0x%x\n", bitmap
->format
);
550 return NotImplemented
;
556 GpStatus
convert_pixels(INT width
, INT height
,
557 INT dst_stride
, BYTE
*dst_bits
, PixelFormat dst_format
,
558 INT src_stride
, const BYTE
*src_bits
, PixelFormat src_format
,
559 ColorPalette
*palette
)
563 if (src_format
== dst_format
||
564 (dst_format
== PixelFormat32bppRGB
&& PIXELFORMATBPP(src_format
) == 32))
566 UINT widthbytes
= PIXELFORMATBPP(src_format
) * width
/ 8;
567 for (y
=0; y
<height
; y
++)
568 memcpy(dst_bits
+dst_stride
*y
, src_bits
+src_stride
*y
, widthbytes
);
572 #define convert_indexed_to_rgb(getpixel_function, setpixel_function) do { \
573 for (y=0; y<height; y++) \
574 for (x=0; x<width; x++) { \
577 BYTE *color = (BYTE *)&argb; \
578 getpixel_function(&index, src_bits+src_stride*y, x); \
579 argb = (palette && index < palette->Count) ? palette->Entries[index] : 0; \
580 setpixel_function(color[2], color[1], color[0], color[3], dst_bits+dst_stride*y, x); \
585 #define convert_rgb_to_rgb(getpixel_function, setpixel_function) do { \
586 for (y=0; y<height; y++) \
587 for (x=0; x<width; x++) { \
589 getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
590 setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x); \
595 #define convert_rgb_to_indexed(getpixel_function, setpixel_function) do { \
596 for (y=0; y<height; y++) \
597 for (x=0; x<width; x++) { \
599 getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
600 setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x, palette); \
607 case PixelFormat1bppIndexed
:
610 case PixelFormat16bppGrayScale
:
611 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppGrayScale
);
612 case PixelFormat16bppRGB555
:
613 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppRGB555
);
614 case PixelFormat16bppRGB565
:
615 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppRGB565
);
616 case PixelFormat16bppARGB1555
:
617 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppARGB1555
);
618 case PixelFormat24bppRGB
:
619 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_24bppRGB
);
620 case PixelFormat32bppRGB
:
621 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppRGB
);
622 case PixelFormat32bppARGB
:
623 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppARGB
);
624 case PixelFormat32bppPARGB
:
625 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppPARGB
);
626 case PixelFormat48bppRGB
:
627 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_48bppRGB
);
628 case PixelFormat64bppARGB
:
629 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_64bppARGB
);
634 case PixelFormat4bppIndexed
:
637 case PixelFormat16bppGrayScale
:
638 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppGrayScale
);
639 case PixelFormat16bppRGB555
:
640 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppRGB555
);
641 case PixelFormat16bppRGB565
:
642 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppRGB565
);
643 case PixelFormat16bppARGB1555
:
644 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppARGB1555
);
645 case PixelFormat24bppRGB
:
646 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_24bppRGB
);
647 case PixelFormat32bppRGB
:
648 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppRGB
);
649 case PixelFormat32bppARGB
:
650 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppARGB
);
651 case PixelFormat32bppPARGB
:
652 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppPARGB
);
653 case PixelFormat48bppRGB
:
654 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_48bppRGB
);
655 case PixelFormat64bppARGB
:
656 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_64bppARGB
);
661 case PixelFormat8bppIndexed
:
664 case PixelFormat16bppGrayScale
:
665 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppGrayScale
);
666 case PixelFormat16bppRGB555
:
667 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppRGB555
);
668 case PixelFormat16bppRGB565
:
669 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppRGB565
);
670 case PixelFormat16bppARGB1555
:
671 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppARGB1555
);
672 case PixelFormat24bppRGB
:
673 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_24bppRGB
);
674 case PixelFormat32bppRGB
:
675 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppRGB
);
676 case PixelFormat32bppARGB
:
677 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppARGB
);
678 case PixelFormat32bppPARGB
:
679 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppPARGB
);
680 case PixelFormat48bppRGB
:
681 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_48bppRGB
);
682 case PixelFormat64bppARGB
:
683 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_64bppARGB
);
688 case PixelFormat16bppGrayScale
:
691 case PixelFormat1bppIndexed
:
692 convert_rgb_to_indexed(getpixel_16bppGrayScale
, setpixel_1bppIndexed
);
693 case PixelFormat8bppIndexed
:
694 convert_rgb_to_indexed(getpixel_16bppGrayScale
, setpixel_8bppIndexed
);
695 case PixelFormat16bppRGB555
:
696 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppRGB555
);
697 case PixelFormat16bppRGB565
:
698 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppRGB565
);
699 case PixelFormat16bppARGB1555
:
700 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppARGB1555
);
701 case PixelFormat24bppRGB
:
702 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_24bppRGB
);
703 case PixelFormat32bppRGB
:
704 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppRGB
);
705 case PixelFormat32bppARGB
:
706 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppARGB
);
707 case PixelFormat32bppPARGB
:
708 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppPARGB
);
709 case PixelFormat48bppRGB
:
710 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_48bppRGB
);
711 case PixelFormat64bppARGB
:
712 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_64bppARGB
);
717 case PixelFormat16bppRGB555
:
720 case PixelFormat1bppIndexed
:
721 convert_rgb_to_indexed(getpixel_16bppRGB555
, setpixel_1bppIndexed
);
722 case PixelFormat8bppIndexed
:
723 convert_rgb_to_indexed(getpixel_16bppRGB555
, setpixel_8bppIndexed
);
724 case PixelFormat16bppGrayScale
:
725 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppGrayScale
);
726 case PixelFormat16bppRGB565
:
727 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppRGB565
);
728 case PixelFormat16bppARGB1555
:
729 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppARGB1555
);
730 case PixelFormat24bppRGB
:
731 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_24bppRGB
);
732 case PixelFormat32bppRGB
:
733 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppRGB
);
734 case PixelFormat32bppARGB
:
735 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppARGB
);
736 case PixelFormat32bppPARGB
:
737 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppPARGB
);
738 case PixelFormat48bppRGB
:
739 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_48bppRGB
);
740 case PixelFormat64bppARGB
:
741 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_64bppARGB
);
746 case PixelFormat16bppRGB565
:
749 case PixelFormat1bppIndexed
:
750 convert_rgb_to_indexed(getpixel_16bppRGB565
, setpixel_1bppIndexed
);
751 case PixelFormat8bppIndexed
:
752 convert_rgb_to_indexed(getpixel_16bppRGB565
, setpixel_8bppIndexed
);
753 case PixelFormat16bppGrayScale
:
754 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppGrayScale
);
755 case PixelFormat16bppRGB555
:
756 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppRGB555
);
757 case PixelFormat16bppARGB1555
:
758 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppARGB1555
);
759 case PixelFormat24bppRGB
:
760 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_24bppRGB
);
761 case PixelFormat32bppRGB
:
762 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppRGB
);
763 case PixelFormat32bppARGB
:
764 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppARGB
);
765 case PixelFormat32bppPARGB
:
766 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppPARGB
);
767 case PixelFormat48bppRGB
:
768 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_48bppRGB
);
769 case PixelFormat64bppARGB
:
770 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_64bppARGB
);
775 case PixelFormat16bppARGB1555
:
778 case PixelFormat1bppIndexed
:
779 convert_rgb_to_indexed(getpixel_16bppARGB1555
, setpixel_1bppIndexed
);
780 case PixelFormat8bppIndexed
:
781 convert_rgb_to_indexed(getpixel_16bppARGB1555
, setpixel_8bppIndexed
);
782 case PixelFormat16bppGrayScale
:
783 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppGrayScale
);
784 case PixelFormat16bppRGB555
:
785 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppRGB555
);
786 case PixelFormat16bppRGB565
:
787 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppRGB565
);
788 case PixelFormat24bppRGB
:
789 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_24bppRGB
);
790 case PixelFormat32bppRGB
:
791 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppRGB
);
792 case PixelFormat32bppARGB
:
793 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppARGB
);
794 case PixelFormat32bppPARGB
:
795 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppPARGB
);
796 case PixelFormat48bppRGB
:
797 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_48bppRGB
);
798 case PixelFormat64bppARGB
:
799 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_64bppARGB
);
804 case PixelFormat24bppRGB
:
807 case PixelFormat1bppIndexed
:
808 convert_rgb_to_indexed(getpixel_24bppRGB
, setpixel_1bppIndexed
);
809 case PixelFormat8bppIndexed
:
810 convert_rgb_to_indexed(getpixel_24bppRGB
, setpixel_8bppIndexed
);
811 case PixelFormat16bppGrayScale
:
812 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppGrayScale
);
813 case PixelFormat16bppRGB555
:
814 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppRGB555
);
815 case PixelFormat16bppRGB565
:
816 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppRGB565
);
817 case PixelFormat16bppARGB1555
:
818 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppARGB1555
);
819 case PixelFormat32bppRGB
:
820 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppRGB
);
821 case PixelFormat32bppARGB
:
822 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppARGB
);
823 case PixelFormat32bppPARGB
:
824 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppPARGB
);
825 case PixelFormat48bppRGB
:
826 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_48bppRGB
);
827 case PixelFormat64bppARGB
:
828 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_64bppARGB
);
833 case PixelFormat32bppRGB
:
836 case PixelFormat1bppIndexed
:
837 convert_rgb_to_indexed(getpixel_32bppRGB
, setpixel_1bppIndexed
);
838 case PixelFormat8bppIndexed
:
839 convert_rgb_to_indexed(getpixel_32bppRGB
, setpixel_8bppIndexed
);
840 case PixelFormat16bppGrayScale
:
841 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppGrayScale
);
842 case PixelFormat16bppRGB555
:
843 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppRGB555
);
844 case PixelFormat16bppRGB565
:
845 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppRGB565
);
846 case PixelFormat16bppARGB1555
:
847 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppARGB1555
);
848 case PixelFormat24bppRGB
:
849 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_24bppRGB
);
850 case PixelFormat32bppARGB
:
851 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_32bppARGB
);
852 case PixelFormat32bppPARGB
:
853 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_32bppPARGB
);
854 case PixelFormat48bppRGB
:
855 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_48bppRGB
);
856 case PixelFormat64bppARGB
:
857 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_64bppARGB
);
862 case PixelFormat32bppARGB
:
865 case PixelFormat1bppIndexed
:
866 convert_rgb_to_indexed(getpixel_32bppARGB
, setpixel_1bppIndexed
);
867 case PixelFormat8bppIndexed
:
868 convert_rgb_to_indexed(getpixel_32bppARGB
, setpixel_8bppIndexed
);
869 case PixelFormat16bppGrayScale
:
870 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppGrayScale
);
871 case PixelFormat16bppRGB555
:
872 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppRGB555
);
873 case PixelFormat16bppRGB565
:
874 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppRGB565
);
875 case PixelFormat16bppARGB1555
:
876 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppARGB1555
);
877 case PixelFormat24bppRGB
:
878 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_24bppRGB
);
879 case PixelFormat32bppPARGB
:
880 convert_32bppARGB_to_32bppPARGB(width
, height
, dst_bits
, dst_stride
, src_bits
, src_stride
);
882 case PixelFormat48bppRGB
:
883 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_48bppRGB
);
884 case PixelFormat64bppARGB
:
885 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_64bppARGB
);
890 case PixelFormat32bppPARGB
:
893 case PixelFormat1bppIndexed
:
894 convert_rgb_to_indexed(getpixel_32bppPARGB
, setpixel_1bppIndexed
);
895 case PixelFormat8bppIndexed
:
896 convert_rgb_to_indexed(getpixel_32bppPARGB
, setpixel_8bppIndexed
);
897 case PixelFormat16bppGrayScale
:
898 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppGrayScale
);
899 case PixelFormat16bppRGB555
:
900 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppRGB555
);
901 case PixelFormat16bppRGB565
:
902 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppRGB565
);
903 case PixelFormat16bppARGB1555
:
904 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppARGB1555
);
905 case PixelFormat24bppRGB
:
906 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_24bppRGB
);
907 case PixelFormat32bppRGB
:
908 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_32bppRGB
);
909 case PixelFormat32bppARGB
:
910 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_32bppARGB
);
911 case PixelFormat48bppRGB
:
912 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_48bppRGB
);
913 case PixelFormat64bppARGB
:
914 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_64bppARGB
);
919 case PixelFormat48bppRGB
:
922 case PixelFormat1bppIndexed
:
923 convert_rgb_to_indexed(getpixel_48bppRGB
, setpixel_1bppIndexed
);
924 case PixelFormat8bppIndexed
:
925 convert_rgb_to_indexed(getpixel_48bppRGB
, setpixel_8bppIndexed
);
926 case PixelFormat16bppGrayScale
:
927 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppGrayScale
);
928 case PixelFormat16bppRGB555
:
929 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppRGB555
);
930 case PixelFormat16bppRGB565
:
931 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppRGB565
);
932 case PixelFormat16bppARGB1555
:
933 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppARGB1555
);
934 case PixelFormat24bppRGB
:
935 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_24bppRGB
);
936 case PixelFormat32bppRGB
:
937 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppRGB
);
938 case PixelFormat32bppARGB
:
939 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppARGB
);
940 case PixelFormat32bppPARGB
:
941 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppPARGB
);
942 case PixelFormat64bppARGB
:
943 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_64bppARGB
);
948 case PixelFormat64bppARGB
:
951 case PixelFormat1bppIndexed
:
952 convert_rgb_to_indexed(getpixel_64bppARGB
, setpixel_1bppIndexed
);
953 case PixelFormat8bppIndexed
:
954 convert_rgb_to_indexed(getpixel_64bppARGB
, setpixel_8bppIndexed
);
955 case PixelFormat16bppGrayScale
:
956 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppGrayScale
);
957 case PixelFormat16bppRGB555
:
958 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppRGB555
);
959 case PixelFormat16bppRGB565
:
960 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppRGB565
);
961 case PixelFormat16bppARGB1555
:
962 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppARGB1555
);
963 case PixelFormat24bppRGB
:
964 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_24bppRGB
);
965 case PixelFormat32bppRGB
:
966 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppRGB
);
967 case PixelFormat32bppARGB
:
968 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppARGB
);
969 case PixelFormat32bppPARGB
:
970 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppPARGB
);
971 case PixelFormat48bppRGB
:
972 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_48bppRGB
);
977 case PixelFormat64bppPARGB
:
980 case PixelFormat1bppIndexed
:
981 convert_rgb_to_indexed(getpixel_64bppPARGB
, setpixel_1bppIndexed
);
982 case PixelFormat8bppIndexed
:
983 convert_rgb_to_indexed(getpixel_64bppPARGB
, setpixel_8bppIndexed
);
984 case PixelFormat16bppGrayScale
:
985 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppGrayScale
);
986 case PixelFormat16bppRGB555
:
987 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppRGB555
);
988 case PixelFormat16bppRGB565
:
989 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppRGB565
);
990 case PixelFormat16bppARGB1555
:
991 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppARGB1555
);
992 case PixelFormat24bppRGB
:
993 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_24bppRGB
);
994 case PixelFormat32bppRGB
:
995 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppRGB
);
996 case PixelFormat32bppARGB
:
997 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppARGB
);
998 case PixelFormat32bppPARGB
:
999 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppPARGB
);
1000 case PixelFormat48bppRGB
:
1001 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_48bppRGB
);
1002 case PixelFormat64bppARGB
:
1003 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_64bppARGB
);
1012 #undef convert_indexed_to_rgb
1013 #undef convert_rgb_to_rgb
1015 return NotImplemented
;
1018 /* This function returns a pointer to an array of pixels that represents the
1019 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
1020 * flags. It is correct behavior that a user who calls this function with write
1021 * privileges can write to the whole bitmap (not just the area in rect).
1023 * FIXME: only used portion of format is bits per pixel. */
1024 GpStatus WINGDIPAPI
GdipBitmapLockBits(GpBitmap
* bitmap
, GDIPCONST GpRect
* rect
,
1025 UINT flags
, PixelFormat format
, BitmapData
* lockeddata
)
1027 INT bitspp
= PIXELFORMATBPP(format
);
1028 GpRect act_rect
; /* actual rect to be used */
1031 TRACE("%p %p %d 0x%x %p\n", bitmap
, rect
, flags
, format
, lockeddata
);
1033 if(!lockeddata
|| !bitmap
)
1034 return InvalidParameter
;
1037 if(rect
->X
< 0 || rect
->Y
< 0 || (rect
->X
+ rect
->Width
> bitmap
->width
) ||
1038 (rect
->Y
+ rect
->Height
> bitmap
->height
) || !flags
)
1039 return InvalidParameter
;
1044 act_rect
.X
= act_rect
.Y
= 0;
1045 act_rect
.Width
= bitmap
->width
;
1046 act_rect
.Height
= bitmap
->height
;
1049 if(bitmap
->lockmode
)
1051 WARN("bitmap is already locked and cannot be locked again\n");
1055 if (bitmap
->bits
&& bitmap
->format
== format
&& !(flags
& ImageLockModeUserInputBuf
))
1057 /* no conversion is necessary; just use the bits directly */
1058 lockeddata
->Width
= act_rect
.Width
;
1059 lockeddata
->Height
= act_rect
.Height
;
1060 lockeddata
->PixelFormat
= format
;
1061 lockeddata
->Reserved
= flags
;
1062 lockeddata
->Stride
= bitmap
->stride
;
1063 lockeddata
->Scan0
= bitmap
->bits
+ (bitspp
/ 8) * act_rect
.X
+
1064 bitmap
->stride
* act_rect
.Y
;
1066 bitmap
->lockmode
= flags
| ImageLockModeRead
;
1072 /* Make sure we can convert to the requested format. */
1073 if (flags
& ImageLockModeRead
)
1075 stat
= convert_pixels(0, 0, 0, NULL
, format
, 0, NULL
, bitmap
->format
, NULL
);
1076 if (stat
== NotImplemented
)
1078 FIXME("cannot read bitmap from %x to %x\n", bitmap
->format
, format
);
1079 return NotImplemented
;
1083 /* If we're opening for writing, make sure we'll be able to write back in
1084 * the original format. */
1085 if (flags
& ImageLockModeWrite
)
1087 stat
= convert_pixels(0, 0, 0, NULL
, bitmap
->format
, 0, NULL
, format
, NULL
);
1088 if (stat
== NotImplemented
)
1090 FIXME("cannot write bitmap from %x to %x\n", format
, bitmap
->format
);
1091 return NotImplemented
;
1095 lockeddata
->Width
= act_rect
.Width
;
1096 lockeddata
->Height
= act_rect
.Height
;
1097 lockeddata
->PixelFormat
= format
;
1098 lockeddata
->Reserved
= flags
;
1100 if(!(flags
& ImageLockModeUserInputBuf
))
1102 lockeddata
->Stride
= (((act_rect
.Width
* bitspp
+ 7) / 8) + 3) & ~3;
1104 bitmap
->bitmapbits
= heap_alloc_zero(lockeddata
->Stride
* act_rect
.Height
);
1106 if (!bitmap
->bitmapbits
) return OutOfMemory
;
1108 lockeddata
->Scan0
= bitmap
->bitmapbits
;
1111 if (flags
& ImageLockModeRead
)
1113 static BOOL fixme
= FALSE
;
1115 if (!fixme
&& (PIXELFORMATBPP(bitmap
->format
) * act_rect
.X
) % 8 != 0)
1117 FIXME("Cannot copy rows that don't start at a whole byte.\n");
1121 stat
= convert_pixels(act_rect
.Width
, act_rect
.Height
,
1122 lockeddata
->Stride
, lockeddata
->Scan0
, format
,
1124 bitmap
->bits
+ bitmap
->stride
* act_rect
.Y
+ PIXELFORMATBPP(bitmap
->format
) * act_rect
.X
/ 8,
1125 bitmap
->format
, bitmap
->image
.palette
);
1129 heap_free(bitmap
->bitmapbits
);
1130 bitmap
->bitmapbits
= NULL
;
1135 bitmap
->lockmode
= flags
| ImageLockModeRead
;
1137 bitmap
->lockx
= act_rect
.X
;
1138 bitmap
->locky
= act_rect
.Y
;
1143 GpStatus WINGDIPAPI
GdipBitmapSetResolution(GpBitmap
* bitmap
, REAL xdpi
, REAL ydpi
)
1145 TRACE("(%p, %.2f, %.2f)\n", bitmap
, xdpi
, ydpi
);
1147 if (!bitmap
|| xdpi
== 0.0 || ydpi
== 0.0)
1148 return InvalidParameter
;
1150 bitmap
->image
.xres
= xdpi
;
1151 bitmap
->image
.yres
= ydpi
;
1156 GpStatus WINGDIPAPI
GdipBitmapUnlockBits(GpBitmap
* bitmap
,
1157 BitmapData
* lockeddata
)
1160 static BOOL fixme
= FALSE
;
1162 TRACE("(%p,%p)\n", bitmap
, lockeddata
);
1164 if(!bitmap
|| !lockeddata
)
1165 return InvalidParameter
;
1167 if(!bitmap
->lockmode
)
1170 if(!(lockeddata
->Reserved
& ImageLockModeWrite
)){
1171 if(!(--bitmap
->numlocks
))
1172 bitmap
->lockmode
= 0;
1174 heap_free(bitmap
->bitmapbits
);
1175 bitmap
->bitmapbits
= NULL
;
1179 if (!bitmap
->bitmapbits
&& !(lockeddata
->Reserved
& ImageLockModeUserInputBuf
))
1181 /* we passed a direct reference; no need to do anything */
1182 bitmap
->lockmode
= 0;
1183 bitmap
->numlocks
= 0;
1187 if (!fixme
&& (PIXELFORMATBPP(bitmap
->format
) * bitmap
->lockx
) % 8 != 0)
1189 FIXME("Cannot copy rows that don't start at a whole byte.\n");
1193 stat
= convert_pixels(lockeddata
->Width
, lockeddata
->Height
,
1195 bitmap
->bits
+ bitmap
->stride
* bitmap
->locky
+ PIXELFORMATBPP(bitmap
->format
) * bitmap
->lockx
/ 8,
1197 lockeddata
->Stride
, lockeddata
->Scan0
, lockeddata
->PixelFormat
, NULL
);
1201 ERR("failed to convert pixels; this should never happen\n");
1204 heap_free(bitmap
->bitmapbits
);
1205 bitmap
->bitmapbits
= NULL
;
1206 bitmap
->lockmode
= 0;
1207 bitmap
->numlocks
= 0;
1212 GpStatus WINGDIPAPI
GdipCloneBitmapArea(REAL x
, REAL y
, REAL width
, REAL height
,
1213 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
1218 TRACE("(%f,%f,%f,%f,0x%x,%p,%p)\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1220 if (!srcBitmap
|| !dstBitmap
|| srcBitmap
->image
.type
!= ImageTypeBitmap
||
1222 x
+ width
> srcBitmap
->width
|| y
+ height
> srcBitmap
->height
)
1224 TRACE("<-- InvalidParameter\n");
1225 return InvalidParameter
;
1228 if (format
== PixelFormatDontCare
)
1229 format
= srcBitmap
->format
;
1231 area
.X
= gdip_round(x
);
1232 area
.Y
= gdip_round(y
);
1233 area
.Width
= gdip_round(width
);
1234 area
.Height
= gdip_round(height
);
1236 stat
= GdipCreateBitmapFromScan0(area
.Width
, area
.Height
, 0, format
, NULL
, dstBitmap
);
1239 stat
= convert_pixels(area
.Width
, area
.Height
, (*dstBitmap
)->stride
, (*dstBitmap
)->bits
, (*dstBitmap
)->format
,
1241 srcBitmap
->bits
+ srcBitmap
->stride
* area
.Y
+ PIXELFORMATBPP(srcBitmap
->format
) * area
.X
/ 8,
1242 srcBitmap
->format
, srcBitmap
->image
.palette
);
1244 if (stat
== Ok
&& srcBitmap
->image
.palette
)
1246 ColorPalette
*src_palette
, *dst_palette
;
1248 src_palette
= srcBitmap
->image
.palette
;
1250 dst_palette
= heap_alloc_zero(sizeof(UINT
) * 2 + sizeof(ARGB
) * src_palette
->Count
);
1254 dst_palette
->Flags
= src_palette
->Flags
;
1255 dst_palette
->Count
= src_palette
->Count
;
1256 memcpy(dst_palette
->Entries
, src_palette
->Entries
, sizeof(ARGB
) * src_palette
->Count
);
1258 heap_free((*dstBitmap
)->image
.palette
);
1259 (*dstBitmap
)->image
.palette
= dst_palette
;
1266 GdipDisposeImage(&(*dstBitmap
)->image
);
1275 GpStatus WINGDIPAPI
GdipCloneBitmapAreaI(INT x
, INT y
, INT width
, INT height
,
1276 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
1278 TRACE("(%i,%i,%i,%i,0x%x,%p,%p)\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1280 return GdipCloneBitmapArea(x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1283 GpStatus WINGDIPAPI
GdipCloneImage(GpImage
*image
, GpImage
**cloneImage
)
1285 TRACE("%p, %p\n", image
, cloneImage
);
1287 if (!image
|| !cloneImage
)
1288 return InvalidParameter
;
1290 if (image
->type
== ImageTypeBitmap
)
1292 GpBitmap
*bitmap
= (GpBitmap
*)image
;
1294 return GdipCloneBitmapAreaI(0, 0, bitmap
->width
, bitmap
->height
,
1295 bitmap
->format
, bitmap
, (GpBitmap
**)cloneImage
);
1297 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
1299 GpMetafile
*result
, *metafile
;
1301 metafile
= (GpMetafile
*)image
;
1303 result
= heap_alloc_zero(sizeof(*result
));
1307 result
->image
.type
= ImageTypeMetafile
;
1308 result
->image
.format
= image
->format
;
1309 result
->image
.flags
= image
->flags
;
1310 result
->image
.frame_count
= 1;
1311 result
->image
.xres
= image
->xres
;
1312 result
->image
.yres
= image
->yres
;
1313 result
->bounds
= metafile
->bounds
;
1314 result
->unit
= metafile
->unit
;
1315 result
->metafile_type
= metafile
->metafile_type
;
1316 result
->hemf
= CopyEnhMetaFileW(metafile
->hemf
, NULL
);
1324 *cloneImage
= &result
->image
;
1329 WARN("GpImage with no image data (metafile in wrong state?)\n");
1330 return InvalidParameter
;
1334 GpStatus WINGDIPAPI
GdipCreateBitmapFromFile(GDIPCONST WCHAR
* filename
,
1340 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
1342 if(!filename
|| !bitmap
)
1343 return InvalidParameter
;
1347 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
1352 stat
= GdipCreateBitmapFromStream(stream
, bitmap
);
1354 IStream_Release(stream
);
1359 GpStatus WINGDIPAPI
GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO
* info
,
1360 VOID
*bits
, GpBitmap
**bitmap
)
1362 DWORD height
, stride
;
1365 FIXME("(%p, %p, %p) - partially implemented\n", info
, bits
, bitmap
);
1367 if (!info
|| !bits
|| !bitmap
)
1368 return InvalidParameter
;
1370 height
= abs(info
->bmiHeader
.biHeight
);
1371 stride
= ((info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
+ 31) >> 3) & ~3;
1373 if(info
->bmiHeader
.biHeight
> 0) /* bottom-up */
1375 bits
= (BYTE
*)bits
+ (height
- 1) * stride
;
1379 switch(info
->bmiHeader
.biBitCount
) {
1381 format
= PixelFormat1bppIndexed
;
1384 format
= PixelFormat4bppIndexed
;
1387 format
= PixelFormat8bppIndexed
;
1390 format
= PixelFormat16bppRGB555
;
1393 format
= PixelFormat24bppRGB
;
1396 format
= PixelFormat32bppRGB
;
1399 FIXME("don't know how to handle %d bpp\n", info
->bmiHeader
.biBitCount
);
1401 return InvalidParameter
;
1404 return GdipCreateBitmapFromScan0(info
->bmiHeader
.biWidth
, height
, stride
, format
,
1410 GpStatus WINGDIPAPI
GdipCreateBitmapFromFileICM(GDIPCONST WCHAR
* filename
,
1413 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
1415 return GdipCreateBitmapFromFile(filename
, bitmap
);
1418 GpStatus WINGDIPAPI
GdipCreateBitmapFromResource(HINSTANCE hInstance
,
1419 GDIPCONST WCHAR
* lpBitmapName
, GpBitmap
** bitmap
)
1422 GpStatus stat
= InvalidParameter
;
1424 TRACE("%p (%s) %p\n", hInstance
, debugstr_w(lpBitmapName
), bitmap
);
1426 if(!lpBitmapName
|| !bitmap
)
1427 return InvalidParameter
;
1430 hbm
= LoadImageW(hInstance
, lpBitmapName
, IMAGE_BITMAP
, 0, 0,
1431 LR_CREATEDIBSECTION
);
1434 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, bitmap
);
1441 static inline DWORD
blend_argb_no_bkgnd_alpha(DWORD src
, DWORD bkgnd
)
1444 BYTE g
= (BYTE
)(src
>> 8);
1445 BYTE r
= (BYTE
)(src
>> 16);
1446 DWORD alpha
= (BYTE
)(src
>> 24);
1447 return ((b
+ ((BYTE
)bkgnd
* (255 - alpha
) + 127) / 255) |
1448 (g
+ ((BYTE
)(bkgnd
>> 8) * (255 - alpha
) + 127) / 255) << 8 |
1449 (r
+ ((BYTE
)(bkgnd
>> 16) * (255 - alpha
) + 127) / 255) << 16 |
1453 GpStatus WINGDIPAPI
GdipCreateHBITMAPFromBitmap(GpBitmap
* bitmap
,
1454 HBITMAP
* hbmReturn
, ARGB background
)
1459 BITMAPINFOHEADER bih
;
1461 BitmapData lockeddata
;
1462 TRACE("(%p,%p,%x)\n", bitmap
, hbmReturn
, background
);
1464 if (!bitmap
|| !hbmReturn
) return InvalidParameter
;
1466 GdipGetImageWidth(&bitmap
->image
, &width
);
1467 GdipGetImageHeight(&bitmap
->image
, &height
);
1469 bih
.biSize
= sizeof(bih
);
1470 bih
.biWidth
= width
;
1471 bih
.biHeight
= height
;
1473 bih
.biBitCount
= 32;
1474 bih
.biCompression
= BI_RGB
;
1475 bih
.biSizeImage
= 0;
1476 bih
.biXPelsPerMeter
= 0;
1477 bih
.biYPelsPerMeter
= 0;
1479 bih
.biClrImportant
= 0;
1481 result
= CreateDIBSection(0, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1485 lockeddata
.Stride
= -width
* 4;
1486 lockeddata
.Scan0
= bits
+ (width
* 4 * (height
- 1));
1488 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1489 PixelFormat32bppPARGB
, &lockeddata
);
1492 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1494 if (stat
== Ok
&& (background
& 0xffffff))
1498 for (ptr
= (DWORD
*)bits
, i
= 0; i
< width
* height
; ptr
++, i
++)
1500 if ((*ptr
& 0xff000000) == 0xff000000) continue;
1501 *ptr
= blend_argb_no_bkgnd_alpha(*ptr
, background
);
1506 stat
= GenericError
;
1508 if (stat
!= Ok
&& result
)
1510 DeleteObject(result
);
1514 *hbmReturn
= result
;
1519 GpStatus WINGDIPAPI
GdipCreateBitmapFromGraphics(INT width
, INT height
,
1520 GpGraphics
* target
, GpBitmap
** bitmap
)
1524 TRACE("(%d, %d, %p, %p)\n", width
, height
, target
, bitmap
);
1526 if(!target
|| !bitmap
)
1527 return InvalidParameter
;
1529 ret
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat32bppPARGB
,
1534 GdipGetDpiX(target
, &(*bitmap
)->image
.xres
);
1535 GdipGetDpiY(target
, &(*bitmap
)->image
.yres
);
1541 GpStatus WINGDIPAPI
GdipCreateBitmapFromHICON(HICON hicon
, GpBitmap
** bitmap
)
1547 UINT width
, height
, stride
;
1549 BitmapData lockeddata
;
1553 BITMAPINFOHEADER bih
;
1558 TRACE("%p, %p\n", hicon
, bitmap
);
1560 if(!bitmap
|| !GetIconInfo(hicon
, &iinfo
))
1561 return InvalidParameter
;
1563 /* get the size of the icon */
1564 ret
= GetObjectA(iinfo
.hbmColor
? iinfo
.hbmColor
: iinfo
.hbmMask
, sizeof(bm
), &bm
);
1566 DeleteObject(iinfo
.hbmColor
);
1567 DeleteObject(iinfo
.hbmMask
);
1568 return GenericError
;
1572 height
= iinfo
.hbmColor
? abs(bm
.bmHeight
) : abs(bm
.bmHeight
) / 2;
1575 stat
= GdipCreateBitmapFromScan0(width
, height
, stride
, PixelFormat32bppARGB
, NULL
, bitmap
);
1577 DeleteObject(iinfo
.hbmColor
);
1578 DeleteObject(iinfo
.hbmMask
);
1585 rect
.Height
= height
;
1587 stat
= GdipBitmapLockBits(*bitmap
, &rect
, ImageLockModeWrite
, PixelFormat32bppARGB
, &lockeddata
);
1589 DeleteObject(iinfo
.hbmColor
);
1590 DeleteObject(iinfo
.hbmMask
);
1591 GdipDisposeImage(&(*bitmap
)->image
);
1595 bih
.biSize
= sizeof(bih
);
1596 bih
.biWidth
= width
;
1597 bih
.biHeight
= iinfo
.hbmColor
? -height
: -height
* 2;
1599 bih
.biBitCount
= 32;
1600 bih
.biCompression
= BI_RGB
;
1601 bih
.biSizeImage
= 0;
1602 bih
.biXPelsPerMeter
= 0;
1603 bih
.biYPelsPerMeter
= 0;
1605 bih
.biClrImportant
= 0;
1607 screendc
= CreateCompatibleDC(0);
1610 GetDIBits(screendc
, iinfo
.hbmColor
, 0, height
, lockeddata
.Scan0
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1612 if (bm
.bmBitsPixel
== 32)
1616 /* If any pixel has a non-zero alpha, ignore hbmMask */
1617 src
= (DWORD
*)lockeddata
.Scan0
;
1618 for (x
=0; x
<width
&& !has_alpha
; x
++)
1619 for (y
=0; y
<height
&& !has_alpha
; y
++)
1620 if ((*src
++ & 0xff000000) != 0)
1623 else has_alpha
= FALSE
;
1627 GetDIBits(screendc
, iinfo
.hbmMask
, 0, height
, lockeddata
.Scan0
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1635 BYTE
*bits
= heap_alloc(height
* stride
);
1637 /* read alpha data from the mask */
1639 GetDIBits(screendc
, iinfo
.hbmMask
, 0, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1641 GetDIBits(screendc
, iinfo
.hbmMask
, height
, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1644 dst_row
= lockeddata
.Scan0
;
1645 for (y
=0; y
<height
; y
++)
1647 dst
= (DWORD
*)dst_row
;
1648 for (x
=0; x
<height
; x
++)
1650 DWORD src_value
= *src
++;
1654 *dst
++ |= 0xff000000;
1656 dst_row
+= lockeddata
.Stride
;
1663 /* set constant alpha of 255 */
1664 dst_row
= lockeddata
.Scan0
;
1665 for (y
=0; y
<height
; y
++)
1667 dst
= (DWORD
*)dst_row
;
1668 for (x
=0; x
<height
; x
++)
1669 *dst
++ |= 0xff000000;
1670 dst_row
+= lockeddata
.Stride
;
1677 DeleteObject(iinfo
.hbmColor
);
1678 DeleteObject(iinfo
.hbmMask
);
1680 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
1685 static void generate_halftone_palette(ARGB
*entries
, UINT count
)
1687 static const BYTE halftone_values
[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1690 for (i
=0; i
<8 && i
<count
; i
++)
1692 entries
[i
] = 0xff000000;
1693 if (i
&1) entries
[i
] |= 0x800000;
1694 if (i
&2) entries
[i
] |= 0x8000;
1695 if (i
&4) entries
[i
] |= 0x80;
1699 entries
[i
] = 0xffc0c0c0;
1701 for (i
=9; i
<16 && i
<count
; i
++)
1703 entries
[i
] = 0xff000000;
1704 if (i
&1) entries
[i
] |= 0xff0000;
1705 if (i
&2) entries
[i
] |= 0xff00;
1706 if (i
&4) entries
[i
] |= 0xff;
1709 for (i
=16; i
<40 && i
<count
; i
++)
1714 for (i
=40; i
<256 && i
<count
; i
++)
1716 entries
[i
] = 0xff000000;
1717 entries
[i
] |= halftone_values
[(i
-40)%6];
1718 entries
[i
] |= halftone_values
[((i
-40)/6)%6] << 8;
1719 entries
[i
] |= halftone_values
[((i
-40)/36)%6] << 16;
1723 static GpStatus
get_screen_resolution(REAL
*xres
, REAL
*yres
)
1725 HDC screendc
= CreateCompatibleDC(0);
1727 if (!screendc
) return GenericError
;
1729 *xres
= (REAL
)GetDeviceCaps(screendc
, LOGPIXELSX
);
1730 *yres
= (REAL
)GetDeviceCaps(screendc
, LOGPIXELSY
);
1737 GpStatus WINGDIPAPI
GdipCreateBitmapFromScan0(INT width
, INT height
, INT stride
,
1738 PixelFormat format
, BYTE
* scan0
, GpBitmap
** bitmap
)
1740 HBITMAP hbitmap
=NULL
;
1741 INT row_size
, dib_stride
;
1742 BYTE
*bits
=NULL
, *own_bits
=NULL
;
1746 TRACE("%d %d %d 0x%x %p %p\n", width
, height
, stride
, format
, scan0
, bitmap
);
1748 if (!bitmap
) return InvalidParameter
;
1750 if(width
<= 0 || height
<= 0 || (scan0
&& (stride
% 4))){
1752 return InvalidParameter
;
1755 if(scan0
&& !stride
)
1756 return InvalidParameter
;
1758 stat
= get_screen_resolution(&xres
, &yres
);
1759 if (stat
!= Ok
) return stat
;
1761 row_size
= (width
* PIXELFORMATBPP(format
)+7) / 8;
1762 dib_stride
= (row_size
+ 3) & ~3;
1765 stride
= dib_stride
;
1767 if (format
& PixelFormatGDI
&& !(format
& (PixelFormatAlpha
|PixelFormatIndexed
)) && !scan0
)
1769 char bmibuf
[FIELD_OFFSET(BITMAPINFO
, bmiColors
[256])];
1770 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
1772 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1773 pbmi
->bmiHeader
.biWidth
= width
;
1774 pbmi
->bmiHeader
.biHeight
= -height
;
1775 pbmi
->bmiHeader
.biPlanes
= 1;
1776 /* FIXME: use the rest of the data from format */
1777 pbmi
->bmiHeader
.biBitCount
= PIXELFORMATBPP(format
);
1778 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
1779 pbmi
->bmiHeader
.biSizeImage
= 0;
1780 pbmi
->bmiHeader
.biXPelsPerMeter
= 0;
1781 pbmi
->bmiHeader
.biYPelsPerMeter
= 0;
1782 pbmi
->bmiHeader
.biClrUsed
= 0;
1783 pbmi
->bmiHeader
.biClrImportant
= 0;
1785 hbitmap
= CreateDIBSection(0, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1787 if (!hbitmap
) return GenericError
;
1789 stride
= dib_stride
;
1793 /* Not a GDI format; don't try to make an HBITMAP. */
1798 INT size
= abs(stride
) * height
;
1800 own_bits
= bits
= heap_alloc_zero(size
);
1801 if (!own_bits
) return OutOfMemory
;
1804 bits
+= stride
* (1 - height
);
1808 *bitmap
= heap_alloc_zero(sizeof(GpBitmap
));
1811 DeleteObject(hbitmap
);
1812 heap_free(own_bits
);
1816 (*bitmap
)->image
.type
= ImageTypeBitmap
;
1817 memcpy(&(*bitmap
)->image
.format
, &ImageFormatMemoryBMP
, sizeof(GUID
));
1818 (*bitmap
)->image
.flags
= ImageFlagsNone
;
1819 (*bitmap
)->image
.frame_count
= 1;
1820 (*bitmap
)->image
.current_frame
= 0;
1821 (*bitmap
)->image
.palette
= NULL
;
1822 (*bitmap
)->image
.xres
= xres
;
1823 (*bitmap
)->image
.yres
= yres
;
1824 (*bitmap
)->width
= width
;
1825 (*bitmap
)->height
= height
;
1826 (*bitmap
)->format
= format
;
1827 (*bitmap
)->image
.decoder
= NULL
;
1828 (*bitmap
)->hbitmap
= hbitmap
;
1829 (*bitmap
)->hdc
= NULL
;
1830 (*bitmap
)->bits
= bits
;
1831 (*bitmap
)->stride
= stride
;
1832 (*bitmap
)->own_bits
= own_bits
;
1833 (*bitmap
)->metadata_reader
= NULL
;
1834 (*bitmap
)->prop_count
= 0;
1835 (*bitmap
)->prop_item
= NULL
;
1837 /* set format-related flags */
1838 if (format
& (PixelFormatAlpha
|PixelFormatPAlpha
|PixelFormatIndexed
))
1839 (*bitmap
)->image
.flags
|= ImageFlagsHasAlpha
;
1841 if (format
== PixelFormat1bppIndexed
||
1842 format
== PixelFormat4bppIndexed
||
1843 format
== PixelFormat8bppIndexed
)
1845 (*bitmap
)->image
.palette
= heap_alloc_zero(sizeof(UINT
) * 2 + sizeof(ARGB
) * (1 << PIXELFORMATBPP(format
)));
1847 if (!(*bitmap
)->image
.palette
)
1849 GdipDisposeImage(&(*bitmap
)->image
);
1854 (*bitmap
)->image
.palette
->Count
= 1 << PIXELFORMATBPP(format
);
1856 if (format
== PixelFormat1bppIndexed
)
1858 (*bitmap
)->image
.palette
->Flags
= PaletteFlagsGrayScale
;
1859 (*bitmap
)->image
.palette
->Entries
[0] = 0xff000000;
1860 (*bitmap
)->image
.palette
->Entries
[1] = 0xffffffff;
1864 if (format
== PixelFormat8bppIndexed
)
1865 (*bitmap
)->image
.palette
->Flags
= PaletteFlagsHalftone
;
1867 generate_halftone_palette((*bitmap
)->image
.palette
->Entries
,
1868 (*bitmap
)->image
.palette
->Count
);
1872 TRACE("<-- %p\n", *bitmap
);
1877 GpStatus WINGDIPAPI
GdipCreateBitmapFromStream(IStream
* stream
,
1882 TRACE("%p %p\n", stream
, bitmap
);
1884 stat
= GdipLoadImageFromStream(stream
, (GpImage
**) bitmap
);
1889 if((*bitmap
)->image
.type
!= ImageTypeBitmap
){
1890 GdipDisposeImage(&(*bitmap
)->image
);
1892 return GenericError
; /* FIXME: what error to return? */
1899 GpStatus WINGDIPAPI
GdipCreateBitmapFromStreamICM(IStream
* stream
,
1902 TRACE("%p %p\n", stream
, bitmap
);
1904 return GdipCreateBitmapFromStream(stream
, bitmap
);
1907 GpStatus WINGDIPAPI
GdipCreateCachedBitmap(GpBitmap
*bitmap
, GpGraphics
*graphics
,
1908 GpCachedBitmap
**cachedbmp
)
1912 TRACE("%p %p %p\n", bitmap
, graphics
, cachedbmp
);
1914 if(!bitmap
|| !graphics
|| !cachedbmp
)
1915 return InvalidParameter
;
1917 *cachedbmp
= heap_alloc_zero(sizeof(GpCachedBitmap
));
1921 stat
= GdipCloneImage(&(bitmap
->image
), &(*cachedbmp
)->image
);
1923 heap_free(*cachedbmp
);
1930 GpStatus WINGDIPAPI
GdipCreateHICONFromBitmap(GpBitmap
*bitmap
, HICON
*hicon
)
1933 BitmapData lockeddata
;
1934 ULONG andstride
, xorstride
, bitssize
;
1935 LPBYTE andbits
, xorbits
, androw
, xorrow
, srcrow
;
1938 TRACE("(%p, %p)\n", bitmap
, hicon
);
1940 if (!bitmap
|| !hicon
)
1941 return InvalidParameter
;
1943 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
,
1944 PixelFormat32bppPARGB
, &lockeddata
);
1947 andstride
= ((lockeddata
.Width
+31)/32)*4;
1948 xorstride
= lockeddata
.Width
*4;
1949 bitssize
= (andstride
+ xorstride
) * lockeddata
.Height
;
1951 andbits
= heap_alloc_zero(bitssize
);
1955 xorbits
= andbits
+ andstride
* lockeddata
.Height
;
1957 for (y
=0; y
<lockeddata
.Height
; y
++)
1959 srcrow
= ((LPBYTE
)lockeddata
.Scan0
) + lockeddata
.Stride
* y
;
1961 androw
= andbits
+ andstride
* y
;
1962 for (x
=0; x
<lockeddata
.Width
; x
++)
1963 if (srcrow
[3+4*x
] >= 128)
1964 androw
[x
/8] |= 1 << (7-x
%8);
1966 xorrow
= xorbits
+ xorstride
* y
;
1967 memcpy(xorrow
, srcrow
, xorstride
);
1970 *hicon
= CreateIcon(NULL
, lockeddata
.Width
, lockeddata
.Height
, 1, 32,
1978 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1984 GpStatus WINGDIPAPI
GdipDeleteCachedBitmap(GpCachedBitmap
*cachedbmp
)
1986 TRACE("%p\n", cachedbmp
);
1989 return InvalidParameter
;
1991 GdipDisposeImage(cachedbmp
->image
);
1992 heap_free(cachedbmp
);
1997 GpStatus WINGDIPAPI
GdipDrawCachedBitmap(GpGraphics
*graphics
,
1998 GpCachedBitmap
*cachedbmp
, INT x
, INT y
)
2000 TRACE("%p %p %d %d\n", graphics
, cachedbmp
, x
, y
);
2002 if(!graphics
|| !cachedbmp
)
2003 return InvalidParameter
;
2005 return GdipDrawImage(graphics
, cachedbmp
->image
, (REAL
)x
, (REAL
)y
);
2008 /* Internal utility function: Replace the image data of dst with that of src,
2010 static void move_bitmap(GpBitmap
*dst
, GpBitmap
*src
, BOOL clobber_palette
)
2012 assert(src
->image
.type
== ImageTypeBitmap
);
2013 assert(dst
->image
.type
== ImageTypeBitmap
);
2015 heap_free(dst
->bitmapbits
);
2016 heap_free(dst
->own_bits
);
2018 DeleteObject(dst
->hbitmap
);
2020 if (clobber_palette
)
2022 heap_free(dst
->image
.palette
);
2023 dst
->image
.palette
= src
->image
.palette
;
2026 heap_free(src
->image
.palette
);
2028 dst
->image
.xres
= src
->image
.xres
;
2029 dst
->image
.yres
= src
->image
.yres
;
2030 dst
->width
= src
->width
;
2031 dst
->height
= src
->height
;
2032 dst
->format
= src
->format
;
2033 dst
->hbitmap
= src
->hbitmap
;
2034 dst
->hdc
= src
->hdc
;
2035 dst
->bits
= src
->bits
;
2036 dst
->stride
= src
->stride
;
2037 dst
->own_bits
= src
->own_bits
;
2038 if (dst
->metadata_reader
)
2039 IWICMetadataReader_Release(dst
->metadata_reader
);
2040 dst
->metadata_reader
= src
->metadata_reader
;
2041 heap_free(dst
->prop_item
);
2042 dst
->prop_item
= src
->prop_item
;
2043 dst
->prop_count
= src
->prop_count
;
2044 if (dst
->image
.decoder
)
2045 IWICBitmapDecoder_Release(dst
->image
.decoder
);
2046 dst
->image
.decoder
= src
->image
.decoder
;
2047 dst
->image
.frame_count
= src
->image
.frame_count
;
2048 dst
->image
.current_frame
= src
->image
.current_frame
;
2049 dst
->image
.format
= src
->image
.format
;
2051 src
->image
.type
= ~0;
2055 static GpStatus
free_image_data(GpImage
*image
)
2058 return InvalidParameter
;
2060 if (image
->type
== ImageTypeBitmap
)
2062 heap_free(((GpBitmap
*)image
)->bitmapbits
);
2063 heap_free(((GpBitmap
*)image
)->own_bits
);
2064 DeleteDC(((GpBitmap
*)image
)->hdc
);
2065 DeleteObject(((GpBitmap
*)image
)->hbitmap
);
2066 if (((GpBitmap
*)image
)->metadata_reader
)
2067 IWICMetadataReader_Release(((GpBitmap
*)image
)->metadata_reader
);
2068 heap_free(((GpBitmap
*)image
)->prop_item
);
2070 else if (image
->type
== ImageTypeMetafile
)
2072 GpMetafile
*metafile
= (GpMetafile
*)image
;
2073 heap_free(metafile
->comment_data
);
2074 DeleteEnhMetaFile(CloseEnhMetaFile(metafile
->record_dc
));
2075 if (!metafile
->preserve_hemf
)
2076 DeleteEnhMetaFile(metafile
->hemf
);
2077 if (metafile
->record_graphics
)
2079 WARN("metafile closed while recording\n");
2080 /* not sure what to do here; for now just prevent the graphics from functioning or using this object */
2081 metafile
->record_graphics
->image
= NULL
;
2082 metafile
->record_graphics
->busy
= TRUE
;
2084 if (metafile
->record_stream
)
2086 IStream_Release(metafile
->record_stream
);
2091 WARN("invalid image: %p\n", image
);
2095 IWICBitmapDecoder_Release(image
->decoder
);
2096 heap_free(image
->palette
);
2101 GpStatus WINGDIPAPI
GdipDisposeImage(GpImage
*image
)
2105 TRACE("%p\n", image
);
2107 status
= free_image_data(image
);
2108 if (status
!= Ok
) return status
;
2115 GpStatus WINGDIPAPI
GdipFindFirstImageItem(GpImage
*image
, ImageItemData
* item
)
2119 TRACE("(%p,%p)\n", image
, item
);
2122 return InvalidParameter
;
2125 FIXME("not implemented\n");
2127 return NotImplemented
;
2130 GpStatus WINGDIPAPI
GdipGetImageItemData(GpImage
*image
, ImageItemData
*item
)
2134 TRACE("(%p,%p)\n", image
, item
);
2137 FIXME("not implemented\n");
2139 return NotImplemented
;
2142 GpStatus WINGDIPAPI
GdipGetImageBounds(GpImage
*image
, GpRectF
*srcRect
,
2145 TRACE("%p %p %p\n", image
, srcRect
, srcUnit
);
2147 if(!image
|| !srcRect
|| !srcUnit
)
2148 return InvalidParameter
;
2149 if(image
->type
== ImageTypeMetafile
){
2150 *srcRect
= ((GpMetafile
*)image
)->bounds
;
2151 *srcUnit
= ((GpMetafile
*)image
)->unit
;
2153 else if(image
->type
== ImageTypeBitmap
){
2154 srcRect
->X
= srcRect
->Y
= 0.0;
2155 srcRect
->Width
= (REAL
) ((GpBitmap
*)image
)->width
;
2156 srcRect
->Height
= (REAL
) ((GpBitmap
*)image
)->height
;
2157 *srcUnit
= UnitPixel
;
2160 WARN("GpImage with no image data\n");
2161 return InvalidParameter
;
2164 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect
->X
, srcRect
->Y
,
2165 srcRect
->Width
, srcRect
->Height
, *srcUnit
);
2170 GpStatus WINGDIPAPI
GdipGetImageDimension(GpImage
*image
, REAL
*width
,
2173 TRACE("%p %p %p\n", image
, width
, height
);
2175 if(!image
|| !height
|| !width
)
2176 return InvalidParameter
;
2178 if(image
->type
== ImageTypeMetafile
){
2179 *height
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Height
, ((GpMetafile
*)image
)->unit
, image
->yres
);
2180 *width
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Width
, ((GpMetafile
*)image
)->unit
, image
->xres
);
2182 else if(image
->type
== ImageTypeBitmap
){
2183 *height
= ((GpBitmap
*)image
)->height
;
2184 *width
= ((GpBitmap
*)image
)->width
;
2187 WARN("GpImage with no image data\n");
2188 return InvalidParameter
;
2191 TRACE("returning (%f, %f)\n", *height
, *width
);
2195 GpStatus WINGDIPAPI
GdipGetImageGraphicsContext(GpImage
*image
,
2196 GpGraphics
**graphics
)
2201 TRACE("%p %p\n", image
, graphics
);
2203 if(!image
|| !graphics
)
2204 return InvalidParameter
;
2206 if (image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)image
)->hbitmap
)
2208 hdc
= ((GpBitmap
*)image
)->hdc
;
2211 hdc
= CreateCompatibleDC(0);
2212 SelectObject(hdc
, ((GpBitmap
*)image
)->hbitmap
);
2213 ((GpBitmap
*)image
)->hdc
= hdc
;
2216 stat
= GdipCreateFromHDC(hdc
, graphics
);
2220 (*graphics
)->image
= image
;
2221 (*graphics
)->xres
= image
->xres
;
2222 (*graphics
)->yres
= image
->yres
;
2225 else if (image
->type
== ImageTypeMetafile
)
2226 stat
= METAFILE_GetGraphicsContext((GpMetafile
*)image
, graphics
);
2228 stat
= graphics_from_image(image
, graphics
);
2233 GpStatus WINGDIPAPI
GdipGetImageHeight(GpImage
*image
, UINT
*height
)
2235 TRACE("%p %p\n", image
, height
);
2237 if(!image
|| !height
)
2238 return InvalidParameter
;
2240 if(image
->type
== ImageTypeMetafile
)
2241 *height
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Height
, ((GpMetafile
*)image
)->unit
, image
->yres
);
2242 else if(image
->type
== ImageTypeBitmap
)
2243 *height
= ((GpBitmap
*)image
)->height
;
2246 WARN("GpImage with no image data\n");
2247 return InvalidParameter
;
2250 TRACE("returning %d\n", *height
);
2255 GpStatus WINGDIPAPI
GdipGetImageHorizontalResolution(GpImage
*image
, REAL
*res
)
2258 return InvalidParameter
;
2262 TRACE("(%p) <-- %0.2f\n", image
, *res
);
2267 GpStatus WINGDIPAPI
GdipGetImagePaletteSize(GpImage
*image
, INT
*size
)
2269 TRACE("%p %p\n", image
, size
);
2272 return InvalidParameter
;
2274 if (!image
->palette
|| image
->palette
->Count
== 0)
2275 *size
= sizeof(ColorPalette
);
2277 *size
= sizeof(UINT
)*2 + sizeof(ARGB
)*image
->palette
->Count
;
2279 TRACE("<-- %u\n", *size
);
2284 /* FIXME: test this function for non-bitmap types */
2285 GpStatus WINGDIPAPI
GdipGetImagePixelFormat(GpImage
*image
, PixelFormat
*format
)
2287 TRACE("%p %p\n", image
, format
);
2289 if(!image
|| !format
)
2290 return InvalidParameter
;
2292 if(image
->type
!= ImageTypeBitmap
)
2293 *format
= PixelFormat24bppRGB
;
2295 *format
= ((GpBitmap
*) image
)->format
;
2300 GpStatus WINGDIPAPI
GdipGetImageRawFormat(GpImage
*image
, GUID
*format
)
2302 TRACE("(%p, %p)\n", image
, format
);
2304 if(!image
|| !format
)
2305 return InvalidParameter
;
2307 memcpy(format
, &image
->format
, sizeof(GUID
));
2312 GpStatus WINGDIPAPI
GdipGetImageType(GpImage
*image
, ImageType
*type
)
2314 TRACE("%p %p\n", image
, type
);
2317 return InvalidParameter
;
2319 *type
= image
->type
;
2324 GpStatus WINGDIPAPI
GdipGetImageVerticalResolution(GpImage
*image
, REAL
*res
)
2327 return InvalidParameter
;
2331 TRACE("(%p) <-- %0.2f\n", image
, *res
);
2336 GpStatus WINGDIPAPI
GdipGetImageWidth(GpImage
*image
, UINT
*width
)
2338 TRACE("%p %p\n", image
, width
);
2340 if(!image
|| !width
)
2341 return InvalidParameter
;
2343 if(image
->type
== ImageTypeMetafile
)
2344 *width
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Width
, ((GpMetafile
*)image
)->unit
, image
->xres
);
2345 else if(image
->type
== ImageTypeBitmap
)
2346 *width
= ((GpBitmap
*)image
)->width
;
2349 WARN("GpImage with no image data\n");
2350 return InvalidParameter
;
2353 TRACE("returning %d\n", *width
);
2358 GpStatus WINGDIPAPI
GdipGetPropertyCount(GpImage
*image
, UINT
*num
)
2360 TRACE("(%p, %p)\n", image
, num
);
2362 if (!image
|| !num
) return InvalidParameter
;
2366 if (image
->type
== ImageTypeBitmap
)
2368 if (((GpBitmap
*)image
)->prop_item
)
2370 *num
= ((GpBitmap
*)image
)->prop_count
;
2374 if (((GpBitmap
*)image
)->metadata_reader
)
2375 IWICMetadataReader_GetCount(((GpBitmap
*)image
)->metadata_reader
, num
);
2381 GpStatus WINGDIPAPI
GdipGetPropertyIdList(GpImage
*image
, UINT num
, PROPID
*list
)
2384 IWICMetadataReader
*reader
;
2385 IWICEnumMetadataItem
*enumerator
;
2386 UINT prop_count
, i
, items_returned
;
2388 TRACE("(%p, %u, %p)\n", image
, num
, list
);
2390 if (!image
|| !list
) return InvalidParameter
;
2392 if (image
->type
!= ImageTypeBitmap
)
2394 FIXME("Not implemented for type %d\n", image
->type
);
2395 return NotImplemented
;
2398 if (((GpBitmap
*)image
)->prop_item
)
2400 if (num
!= ((GpBitmap
*)image
)->prop_count
) return InvalidParameter
;
2402 for (i
= 0; i
< num
; i
++)
2404 list
[i
] = ((GpBitmap
*)image
)->prop_item
[i
].id
;
2410 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2413 if (num
!= 0) return InvalidParameter
;
2417 hr
= IWICMetadataReader_GetCount(reader
, &prop_count
);
2418 if (FAILED(hr
)) return hresult_to_status(hr
);
2420 if (num
!= prop_count
) return InvalidParameter
;
2422 hr
= IWICMetadataReader_GetEnumerator(reader
, &enumerator
);
2423 if (FAILED(hr
)) return hresult_to_status(hr
);
2425 IWICEnumMetadataItem_Reset(enumerator
);
2427 for (i
= 0; i
< num
; i
++)
2431 hr
= IWICEnumMetadataItem_Next(enumerator
, 1, NULL
, &id
, NULL
, &items_returned
);
2432 if (hr
!= S_OK
) break;
2434 if (id
.vt
!= VT_UI2
)
2436 FIXME("not supported propvariant type for id: %u\n", id
.vt
);
2440 list
[i
] = id
.u
.uiVal
;
2443 IWICEnumMetadataItem_Release(enumerator
);
2445 return hr
== S_OK
? Ok
: hresult_to_status(hr
);
2448 static UINT
propvariant_size(PROPVARIANT
*value
)
2450 switch (value
->vt
& ~VT_VECTOR
)
2456 if (!(value
->vt
& VT_VECTOR
)) return 1;
2457 return value
->u
.caub
.cElems
;
2460 if (!(value
->vt
& VT_VECTOR
)) return 2;
2461 return value
->u
.caui
.cElems
* 2;
2465 if (!(value
->vt
& VT_VECTOR
)) return 4;
2466 return value
->u
.caul
.cElems
* 4;
2470 if (!(value
->vt
& VT_VECTOR
)) return 8;
2471 return value
->u
.cauh
.cElems
* 8;
2473 return value
->u
.pszVal
? strlen(value
->u
.pszVal
) + 1 : 0;
2475 return value
->u
.blob
.cbSize
;
2477 FIXME("not supported variant type %d\n", value
->vt
);
2482 GpStatus WINGDIPAPI
GdipGetPropertyItemSize(GpImage
*image
, PROPID propid
, UINT
*size
)
2485 IWICMetadataReader
*reader
;
2486 PROPVARIANT id
, value
;
2488 TRACE("(%p,%#x,%p)\n", image
, propid
, size
);
2490 if (!size
|| !image
) return InvalidParameter
;
2492 if (image
->type
!= ImageTypeBitmap
)
2494 FIXME("Not implemented for type %d\n", image
->type
);
2495 return NotImplemented
;
2498 if (((GpBitmap
*)image
)->prop_item
)
2502 for (i
= 0; i
< ((GpBitmap
*)image
)->prop_count
; i
++)
2504 if (propid
== ((GpBitmap
*)image
)->prop_item
[i
].id
)
2506 *size
= sizeof(PropertyItem
) + ((GpBitmap
*)image
)->prop_item
[i
].length
;
2511 return PropertyNotFound
;
2514 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2515 if (!reader
) return PropertyNotFound
;
2518 id
.u
.uiVal
= propid
;
2519 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
2520 if (FAILED(hr
)) return PropertyNotFound
;
2522 *size
= propvariant_size(&value
);
2523 if (*size
) *size
+= sizeof(PropertyItem
);
2524 PropVariantClear(&value
);
2529 #ifndef PropertyTagTypeSByte
2530 #define PropertyTagTypeSByte 6
2531 #define PropertyTagTypeSShort 8
2532 #define PropertyTagTypeFloat 11
2533 #define PropertyTagTypeDouble 12
2536 static UINT
vt_to_itemtype(UINT vt
)
2543 { VT_I1
, PropertyTagTypeSByte
},
2544 { VT_UI1
, PropertyTagTypeByte
},
2545 { VT_I2
, PropertyTagTypeSShort
},
2546 { VT_UI2
, PropertyTagTypeShort
},
2547 { VT_I4
, PropertyTagTypeSLONG
},
2548 { VT_UI4
, PropertyTagTypeLong
},
2549 { VT_I8
, PropertyTagTypeSRational
},
2550 { VT_UI8
, PropertyTagTypeRational
},
2551 { VT_R4
, PropertyTagTypeFloat
},
2552 { VT_R8
, PropertyTagTypeDouble
},
2553 { VT_LPSTR
, PropertyTagTypeASCII
},
2554 { VT_BLOB
, PropertyTagTypeUndefined
}
2557 for (i
= 0; i
< sizeof(vt2type
)/sizeof(vt2type
[0]); i
++)
2559 if (vt2type
[i
].vt
== vt
) return vt2type
[i
].type
;
2561 FIXME("not supported variant type %u\n", vt
);
2565 static GpStatus
propvariant_to_item(PROPVARIANT
*value
, PropertyItem
*item
,
2566 UINT size
, PROPID id
)
2568 UINT item_size
, item_type
;
2570 item_size
= propvariant_size(value
);
2571 if (size
!= item_size
+ sizeof(PropertyItem
)) return InvalidParameter
;
2573 item_type
= vt_to_itemtype(value
->vt
& ~VT_VECTOR
);
2574 if (!item_type
) return InvalidParameter
;
2576 item
->value
= item
+ 1;
2578 switch (value
->vt
& ~VT_VECTOR
)
2582 if (!(value
->vt
& VT_VECTOR
))
2583 *(BYTE
*)item
->value
= value
->u
.bVal
;
2585 memcpy(item
->value
, value
->u
.caub
.pElems
, item_size
);
2589 if (!(value
->vt
& VT_VECTOR
))
2590 *(USHORT
*)item
->value
= value
->u
.uiVal
;
2592 memcpy(item
->value
, value
->u
.caui
.pElems
, item_size
);
2597 if (!(value
->vt
& VT_VECTOR
))
2598 *(ULONG
*)item
->value
= value
->u
.ulVal
;
2600 memcpy(item
->value
, value
->u
.caul
.pElems
, item_size
);
2605 if (!(value
->vt
& VT_VECTOR
))
2606 *(ULONGLONG
*)item
->value
= value
->u
.uhVal
.QuadPart
;
2608 memcpy(item
->value
, value
->u
.cauh
.pElems
, item_size
);
2611 memcpy(item
->value
, value
->u
.pszVal
, item_size
);
2614 memcpy(item
->value
, value
->u
.blob
.pBlobData
, item_size
);
2617 FIXME("not supported variant type %d\n", value
->vt
);
2618 return InvalidParameter
;
2621 item
->length
= item_size
;
2622 item
->type
= item_type
;
2628 GpStatus WINGDIPAPI
GdipGetPropertyItem(GpImage
*image
, PROPID propid
, UINT size
,
2629 PropertyItem
*buffer
)
2633 IWICMetadataReader
*reader
;
2634 PROPVARIANT id
, value
;
2636 TRACE("(%p,%#x,%u,%p)\n", image
, propid
, size
, buffer
);
2638 if (!image
|| !buffer
) return InvalidParameter
;
2640 if (image
->type
!= ImageTypeBitmap
)
2642 FIXME("Not implemented for type %d\n", image
->type
);
2643 return NotImplemented
;
2646 if (((GpBitmap
*)image
)->prop_item
)
2650 for (i
= 0; i
< ((GpBitmap
*)image
)->prop_count
; i
++)
2652 if (propid
== ((GpBitmap
*)image
)->prop_item
[i
].id
)
2654 if (size
!= sizeof(PropertyItem
) + ((GpBitmap
*)image
)->prop_item
[i
].length
)
2655 return InvalidParameter
;
2657 *buffer
= ((GpBitmap
*)image
)->prop_item
[i
];
2658 buffer
->value
= buffer
+ 1;
2659 memcpy(buffer
->value
, ((GpBitmap
*)image
)->prop_item
[i
].value
, buffer
->length
);
2664 return PropertyNotFound
;
2667 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2668 if (!reader
) return PropertyNotFound
;
2671 id
.u
.uiVal
= propid
;
2672 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
2673 if (FAILED(hr
)) return PropertyNotFound
;
2675 stat
= propvariant_to_item(&value
, buffer
, size
, propid
);
2676 PropVariantClear(&value
);
2681 GpStatus WINGDIPAPI
GdipGetPropertySize(GpImage
*image
, UINT
*size
, UINT
*count
)
2684 IWICMetadataReader
*reader
;
2685 IWICEnumMetadataItem
*enumerator
;
2686 UINT prop_count
, prop_size
, i
;
2687 PROPVARIANT id
, value
;
2689 TRACE("(%p,%p,%p)\n", image
, size
, count
);
2691 if (!image
|| !size
|| !count
) return InvalidParameter
;
2693 if (image
->type
!= ImageTypeBitmap
)
2695 FIXME("Not implemented for type %d\n", image
->type
);
2696 return NotImplemented
;
2699 if (((GpBitmap
*)image
)->prop_item
)
2701 *count
= ((GpBitmap
*)image
)->prop_count
;
2704 for (i
= 0; i
< ((GpBitmap
*)image
)->prop_count
; i
++)
2706 *size
+= sizeof(PropertyItem
) + ((GpBitmap
*)image
)->prop_item
[i
].length
;
2712 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2713 if (!reader
) return PropertyNotFound
;
2715 hr
= IWICMetadataReader_GetCount(reader
, &prop_count
);
2716 if (FAILED(hr
)) return hresult_to_status(hr
);
2718 hr
= IWICMetadataReader_GetEnumerator(reader
, &enumerator
);
2719 if (FAILED(hr
)) return hresult_to_status(hr
);
2721 IWICEnumMetadataItem_Reset(enumerator
);
2725 PropVariantInit(&id
);
2726 PropVariantInit(&value
);
2728 for (i
= 0; i
< prop_count
; i
++)
2730 UINT items_returned
, item_size
;
2732 hr
= IWICEnumMetadataItem_Next(enumerator
, 1, NULL
, &id
, &value
, &items_returned
);
2733 if (hr
!= S_OK
) break;
2735 item_size
= propvariant_size(&value
);
2736 if (item_size
) prop_size
+= sizeof(PropertyItem
) + item_size
;
2738 PropVariantClear(&id
);
2739 PropVariantClear(&value
);
2742 IWICEnumMetadataItem_Release(enumerator
);
2744 if (hr
!= S_OK
) return PropertyNotFound
;
2746 *count
= prop_count
;
2751 GpStatus WINGDIPAPI
GdipGetAllPropertyItems(GpImage
*image
, UINT size
,
2752 UINT count
, PropertyItem
*buf
)
2756 IWICMetadataReader
*reader
;
2757 IWICEnumMetadataItem
*enumerator
;
2758 UINT prop_count
, prop_size
, i
;
2759 PROPVARIANT id
, value
;
2762 TRACE("(%p,%u,%u,%p)\n", image
, size
, count
, buf
);
2764 if (!image
|| !buf
) return InvalidParameter
;
2766 if (image
->type
!= ImageTypeBitmap
)
2768 FIXME("Not implemented for type %d\n", image
->type
);
2769 return NotImplemented
;
2772 status
= GdipGetPropertySize(image
, &prop_size
, &prop_count
);
2773 if (status
!= Ok
) return status
;
2775 if (prop_count
!= count
|| prop_size
!= size
) return InvalidParameter
;
2777 if (((GpBitmap
*)image
)->prop_item
)
2779 memcpy(buf
, ((GpBitmap
*)image
)->prop_item
, prop_size
);
2781 item_value
= (char *)(buf
+ prop_count
);
2783 for (i
= 0; i
< prop_count
; i
++)
2785 buf
[i
].value
= item_value
;
2786 item_value
+= buf
[i
].length
;
2792 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2793 if (!reader
) return PropertyNotFound
;
2795 hr
= IWICMetadataReader_GetEnumerator(reader
, &enumerator
);
2796 if (FAILED(hr
)) return hresult_to_status(hr
);
2798 IWICEnumMetadataItem_Reset(enumerator
);
2800 item_value
= (char *)(buf
+ prop_count
);
2802 PropVariantInit(&id
);
2803 PropVariantInit(&value
);
2805 for (i
= 0; i
< prop_count
; i
++)
2808 UINT items_returned
, item_size
;
2810 hr
= IWICEnumMetadataItem_Next(enumerator
, 1, NULL
, &id
, &value
, &items_returned
);
2811 if (hr
!= S_OK
) break;
2813 if (id
.vt
!= VT_UI2
)
2815 FIXME("not supported propvariant type for id: %u\n", id
.vt
);
2819 item_size
= propvariant_size(&value
);
2822 item
= heap_alloc(item_size
+ sizeof(*item
));
2824 propvariant_to_item(&value
, item
, item_size
+ sizeof(*item
), id
.u
.uiVal
);
2825 buf
[i
].id
= item
->id
;
2826 buf
[i
].type
= item
->type
;
2827 buf
[i
].length
= item_size
;
2828 buf
[i
].value
= item_value
;
2829 memcpy(item_value
, item
->value
, item_size
);
2830 item_value
+= item_size
;
2835 PropVariantClear(&id
);
2836 PropVariantClear(&value
);
2839 IWICEnumMetadataItem_Release(enumerator
);
2841 if (hr
!= S_OK
) return PropertyNotFound
;
2846 struct image_format_dimension
2849 const GUID
*dimension
;
2852 static const struct image_format_dimension image_format_dimensions
[] =
2854 {&ImageFormatGIF
, &FrameDimensionTime
},
2855 {&ImageFormatIcon
, &FrameDimensionResolution
},
2859 GpStatus WINGDIPAPI
GdipImageGetFrameCount(GpImage
*image
,
2860 GDIPCONST GUID
* dimensionID
, UINT
* count
)
2862 TRACE("(%p,%s,%p)\n", image
, debugstr_guid(dimensionID
), count
);
2864 if(!image
|| !count
)
2865 return InvalidParameter
;
2868 IsEqualGUID(dimensionID
, &image
->format
) ||
2869 IsEqualGUID(dimensionID
, &FrameDimensionPage
) ||
2870 IsEqualGUID(dimensionID
, &FrameDimensionTime
))
2872 *count
= image
->frame_count
;
2876 return InvalidParameter
;
2879 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsCount(GpImage
*image
,
2882 TRACE("(%p, %p)\n", image
, count
);
2884 /* Native gdiplus 1.1 does not yet support multiple frame dimensions. */
2886 if(!image
|| !count
)
2887 return InvalidParameter
;
2894 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsList(GpImage
* image
,
2895 GUID
* dimensionIDs
, UINT count
)
2898 const GUID
*result
=NULL
;
2900 TRACE("(%p,%p,%u)\n", image
, dimensionIDs
, count
);
2902 if(!image
|| !dimensionIDs
|| count
!= 1)
2903 return InvalidParameter
;
2905 for (i
=0; image_format_dimensions
[i
].format
; i
++)
2907 if (IsEqualGUID(&image
->format
, image_format_dimensions
[i
].format
))
2909 result
= image_format_dimensions
[i
].dimension
;
2915 result
= &FrameDimensionPage
;
2917 memcpy(dimensionIDs
, result
, sizeof(GUID
));
2922 GpStatus WINGDIPAPI
GdipLoadImageFromFile(GDIPCONST WCHAR
* filename
,
2928 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
2930 if (!filename
|| !image
)
2931 return InvalidParameter
;
2935 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
2940 stat
= GdipLoadImageFromStream(stream
, image
);
2942 IStream_Release(stream
);
2947 /* FIXME: no icm handling */
2948 GpStatus WINGDIPAPI
GdipLoadImageFromFileICM(GDIPCONST WCHAR
* filename
,GpImage
**image
)
2950 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
2952 return GdipLoadImageFromFile(filename
, image
);
2955 static void add_property(GpBitmap
*bitmap
, PropertyItem
*item
)
2957 UINT prop_size
, prop_count
;
2958 PropertyItem
*prop_item
;
2960 if (bitmap
->prop_item
== NULL
)
2962 prop_size
= prop_count
= 0;
2963 prop_item
= heap_alloc_zero(item
->length
+ sizeof(PropertyItem
));
2964 if (!prop_item
) return;
2971 GdipGetPropertySize(&bitmap
->image
, &prop_size
, &prop_count
);
2973 prop_item
= heap_alloc_zero(prop_size
+ item
->length
+ sizeof(PropertyItem
));
2974 if (!prop_item
) return;
2975 memcpy(prop_item
, bitmap
->prop_item
, sizeof(PropertyItem
) * bitmap
->prop_count
);
2976 prop_size
-= sizeof(PropertyItem
) * bitmap
->prop_count
;
2977 memcpy(prop_item
+ prop_count
+ 1, bitmap
->prop_item
+ prop_count
, prop_size
);
2979 item_value
= (char *)(prop_item
+ prop_count
+ 1);
2981 for (i
= 0; i
< prop_count
; i
++)
2983 prop_item
[i
].value
= item_value
;
2984 item_value
+= prop_item
[i
].length
;
2988 prop_item
[prop_count
].id
= item
->id
;
2989 prop_item
[prop_count
].type
= item
->type
;
2990 prop_item
[prop_count
].length
= item
->length
;
2991 prop_item
[prop_count
].value
= (char *)(prop_item
+ prop_count
+ 1) + prop_size
;
2992 memcpy(prop_item
[prop_count
].value
, item
->value
, item
->length
);
2994 heap_free(bitmap
->prop_item
);
2995 bitmap
->prop_item
= prop_item
;
2996 bitmap
->prop_count
++;
2999 static BOOL
get_bool_property(IWICMetadataReader
*reader
, const GUID
*guid
, const WCHAR
*prop_name
)
3003 PROPVARIANT id
, value
;
3006 hr
= IWICMetadataReader_GetMetadataFormat(reader
, &format
);
3007 if (FAILED(hr
) || !IsEqualGUID(&format
, guid
)) return FALSE
;
3009 PropVariantInit(&id
);
3010 PropVariantInit(&value
);
3013 id
.u
.pwszVal
= CoTaskMemAlloc((lstrlenW(prop_name
) + 1) * sizeof(WCHAR
));
3014 if (!id
.u
.pwszVal
) return FALSE
;
3015 lstrcpyW(id
.u
.pwszVal
, prop_name
);
3016 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
3017 if (hr
== S_OK
&& value
.vt
== VT_BOOL
)
3018 ret
= value
.u
.boolVal
;
3020 PropVariantClear(&id
);
3021 PropVariantClear(&value
);
3026 static PropertyItem
*get_property(IWICMetadataReader
*reader
, const GUID
*guid
, const WCHAR
*prop_name
)
3030 PROPVARIANT id
, value
;
3031 PropertyItem
*item
= NULL
;
3033 hr
= IWICMetadataReader_GetMetadataFormat(reader
, &format
);
3034 if (FAILED(hr
) || !IsEqualGUID(&format
, guid
)) return NULL
;
3036 PropVariantInit(&id
);
3037 PropVariantInit(&value
);
3040 id
.u
.pwszVal
= CoTaskMemAlloc((lstrlenW(prop_name
) + 1) * sizeof(WCHAR
));
3041 if (!id
.u
.pwszVal
) return NULL
;
3042 lstrcpyW(id
.u
.pwszVal
, prop_name
);
3043 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
3046 UINT item_size
= propvariant_size(&value
);
3049 item_size
+= sizeof(*item
);
3050 item
= heap_alloc_zero(item_size
);
3051 if (propvariant_to_item(&value
, item
, item_size
, 0) != Ok
)
3059 PropVariantClear(&id
);
3060 PropVariantClear(&value
);
3065 static PropertyItem
*get_gif_comment(IWICMetadataReader
*reader
)
3067 static const WCHAR textentryW
[] = { 'T','e','x','t','E','n','t','r','y',0 };
3068 PropertyItem
*comment
;
3070 comment
= get_property(reader
, &GUID_MetadataFormatGifComment
, textentryW
);
3072 comment
->id
= PropertyTagExifUserComment
;
3077 static PropertyItem
*get_gif_loopcount(IWICMetadataReader
*reader
)
3079 static const WCHAR applicationW
[] = { 'A','p','p','l','i','c','a','t','i','o','n',0 };
3080 static const WCHAR dataW
[] = { 'D','a','t','a',0 };
3081 PropertyItem
*appext
= NULL
, *appdata
= NULL
, *loop
= NULL
;
3083 appext
= get_property(reader
, &GUID_MetadataFormatAPE
, applicationW
);
3086 if (appext
->type
== PropertyTagTypeByte
&& appext
->length
== 11 &&
3087 (!memcmp(appext
->value
, "NETSCAPE2.0", 11) || !memcmp(appext
->value
, "ANIMEXTS1.0", 11)))
3089 appdata
= get_property(reader
, &GUID_MetadataFormatAPE
, dataW
);
3092 if (appdata
->type
== PropertyTagTypeByte
&& appdata
->length
== 4)
3094 BYTE
*data
= appdata
->value
;
3095 if (data
[0] == 3 && data
[1] == 1)
3097 loop
= heap_alloc_zero(sizeof(*loop
) + sizeof(SHORT
));
3100 loop
->type
= PropertyTagTypeShort
;
3101 loop
->id
= PropertyTagLoopCount
;
3102 loop
->length
= sizeof(SHORT
);
3103 loop
->value
= loop
+ 1;
3104 *(SHORT
*)loop
->value
= data
[2] | (data
[3] << 8);
3118 static PropertyItem
*get_gif_background(IWICMetadataReader
*reader
)
3120 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 };
3121 PropertyItem
*background
;
3123 background
= get_property(reader
, &GUID_MetadataFormatLSD
, backgroundW
);
3125 background
->id
= PropertyTagIndexBackground
;
3130 static PropertyItem
*get_gif_palette(IWICBitmapDecoder
*decoder
, IWICMetadataReader
*reader
)
3132 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 };
3134 IWICImagingFactory
*factory
;
3135 IWICPalette
*palette
;
3137 WICColor colors
[256];
3139 if (!get_bool_property(reader
, &GUID_MetadataFormatLSD
, global_flagW
))
3142 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
3143 if (hr
!= S_OK
) return NULL
;
3145 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
3148 hr
= IWICBitmapDecoder_CopyPalette(decoder
, palette
);
3150 IWICPalette_GetColors(palette
, 256, colors
, &count
);
3152 IWICPalette_Release(palette
);
3155 IWICImagingFactory_Release(factory
);
3163 pal
= heap_alloc_zero(sizeof(*pal
) + count
* 3);
3164 if (!pal
) return NULL
;
3165 pal
->type
= PropertyTagTypeByte
;
3166 pal
->id
= PropertyTagGlobalPalette
;
3167 pal
->value
= pal
+ 1;
3168 pal
->length
= count
* 3;
3172 for (i
= 0; i
< count
; i
++)
3174 rgb
[i
*3] = (colors
[i
] >> 16) & 0xff;
3175 rgb
[i
*3 + 1] = (colors
[i
] >> 8) & 0xff;
3176 rgb
[i
*3 + 2] = colors
[i
] & 0xff;
3185 static PropertyItem
*get_gif_transparent_idx(IWICMetadataReader
*reader
)
3187 static const WCHAR transparency_flagW
[] = { 'T','r','a','n','s','p','a','r','e','n','c','y','F','l','a','g',0 };
3188 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 };
3189 PropertyItem
*index
= NULL
;
3191 if (get_bool_property(reader
, &GUID_MetadataFormatGCE
, transparency_flagW
))
3193 index
= get_property(reader
, &GUID_MetadataFormatGCE
, colorW
);
3195 index
->id
= PropertyTagIndexTransparent
;
3200 static LONG
get_gif_frame_property(IWICBitmapFrameDecode
*frame
, const GUID
*format
, const WCHAR
*property
)
3203 IWICMetadataBlockReader
*block_reader
;
3204 IWICMetadataReader
*reader
;
3205 UINT block_count
, i
;
3209 hr
= IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3212 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3215 for (i
= 0; i
< block_count
; i
++)
3217 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3220 prop
= get_property(reader
, format
, property
);
3223 if (prop
->type
== PropertyTagTypeByte
&& prop
->length
== 1)
3224 value
= *(BYTE
*)prop
->value
;
3225 else if (prop
->type
== PropertyTagTypeShort
&& prop
->length
== 2)
3226 value
= *(SHORT
*)prop
->value
;
3230 IWICMetadataReader_Release(reader
);
3234 IWICMetadataBlockReader_Release(block_reader
);
3240 static void gif_metadata_reader(GpBitmap
*bitmap
, IWICBitmapDecoder
*decoder
, UINT active_frame
)
3242 static const WCHAR delayW
[] = { 'D','e','l','a','y',0 };
3244 IWICBitmapFrameDecode
*frame
;
3245 IWICMetadataBlockReader
*block_reader
;
3246 IWICMetadataReader
*reader
;
3247 UINT frame_count
, block_count
, i
;
3248 PropertyItem
*delay
= NULL
, *comment
= NULL
, *background
= NULL
;
3249 PropertyItem
*transparent_idx
= NULL
, *loop
= NULL
, *palette
= NULL
;
3251 IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
3252 if (frame_count
> 1)
3254 delay
= heap_alloc_zero(sizeof(*delay
) + frame_count
* sizeof(LONG
));
3259 delay
->type
= PropertyTagTypeLong
;
3260 delay
->id
= PropertyTagFrameDelay
;
3261 delay
->length
= frame_count
* sizeof(LONG
);
3262 delay
->value
= delay
+ 1;
3264 value
= delay
->value
;
3266 for (i
= 0; i
< frame_count
; i
++)
3268 hr
= IWICBitmapDecoder_GetFrame(decoder
, i
, &frame
);
3271 value
[i
] = get_gif_frame_property(frame
, &GUID_MetadataFormatGCE
, delayW
);
3272 IWICBitmapFrameDecode_Release(frame
);
3279 hr
= IWICBitmapDecoder_QueryInterface(decoder
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3282 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3285 for (i
= 0; i
< block_count
; i
++)
3287 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3291 comment
= get_gif_comment(reader
);
3293 if (frame_count
> 1 && !loop
)
3294 loop
= get_gif_loopcount(reader
);
3297 background
= get_gif_background(reader
);
3300 palette
= get_gif_palette(decoder
, reader
);
3302 IWICMetadataReader_Release(reader
);
3306 IWICMetadataBlockReader_Release(block_reader
);
3309 if (frame_count
> 1 && !loop
)
3311 loop
= heap_alloc_zero(sizeof(*loop
) + sizeof(SHORT
));
3314 loop
->type
= PropertyTagTypeShort
;
3315 loop
->id
= PropertyTagLoopCount
;
3316 loop
->length
= sizeof(SHORT
);
3317 loop
->value
= loop
+ 1;
3318 *(SHORT
*)loop
->value
= 1;
3322 if (delay
) add_property(bitmap
, delay
);
3323 if (comment
) add_property(bitmap
, comment
);
3324 if (loop
) add_property(bitmap
, loop
);
3325 if (palette
) add_property(bitmap
, palette
);
3326 if (background
) add_property(bitmap
, background
);
3332 heap_free(background
);
3334 /* Win7 gdiplus always returns transparent color index from frame 0 */
3335 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
3336 if (hr
!= S_OK
) return;
3338 hr
= IWICBitmapFrameDecode_QueryInterface(frame
, &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
);
3349 if (!transparent_idx
)
3350 transparent_idx
= get_gif_transparent_idx(reader
);
3352 IWICMetadataReader_Release(reader
);
3356 IWICMetadataBlockReader_Release(block_reader
);
3359 if (transparent_idx
) add_property(bitmap
, transparent_idx
);
3360 heap_free(transparent_idx
);
3362 IWICBitmapFrameDecode_Release(frame
);
3365 static PropertyItem
* create_prop(PROPID propid
, PROPVARIANT
* value
)
3367 PropertyItem
*item
= NULL
;
3368 UINT item_size
= propvariant_size(value
);
3372 item_size
+= sizeof(*item
);
3373 item
= heap_alloc_zero(item_size
);
3374 if (propvariant_to_item(value
, item
, item_size
, propid
) != Ok
)
3384 static ULONG
get_ulong_by_index(IWICMetadataReader
* reader
, ULONG index
)
3390 hr
= IWICMetadataReader_GetValueByIndex(reader
, index
, NULL
, NULL
, &value
);
3396 result
= value
.u
.ulVal
;
3399 ERR("unhandled case %u\n", value
.vt
);
3402 PropVariantClear(&value
);
3407 static void png_metadata_reader(GpBitmap
*bitmap
, IWICBitmapDecoder
*decoder
, UINT active_frame
)
3410 IWICBitmapFrameDecode
*frame
;
3411 IWICMetadataBlockReader
*block_reader
;
3412 IWICMetadataReader
*reader
;
3413 UINT block_count
, i
, j
;
3414 struct keyword_info
{
3419 { "Title", PropertyTagImageTitle
},
3420 { "Author", PropertyTagArtist
},
3421 { "Description", PropertyTagImageDescription
},
3422 { "Copyright", PropertyTagCopyright
},
3423 { "Software", PropertyTagSoftwareUsed
},
3424 { "Source", PropertyTagEquipModel
},
3425 { "Comment", PropertyTagExifUserComment
},
3427 BOOL seen_gamma
=FALSE
, seen_whitepoint
=FALSE
, seen_chrm
=FALSE
;
3429 hr
= IWICBitmapDecoder_GetFrame(decoder
, active_frame
, &frame
);
3430 if (hr
!= S_OK
) return;
3432 hr
= IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3435 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3438 for (i
= 0; i
< block_count
; i
++)
3440 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3445 hr
= IWICMetadataReader_GetMetadataFormat(reader
, &format
);
3446 if (SUCCEEDED(hr
) && IsEqualGUID(&GUID_MetadataFormatChunktEXt
, &format
))
3448 PROPVARIANT name
, value
;
3451 hr
= IWICMetadataReader_GetValueByIndex(reader
, 0, NULL
, &name
, &value
);
3455 if (name
.vt
== VT_LPSTR
)
3457 for (j
=0; j
<sizeof(keywords
)/sizeof(keywords
[0]); j
++)
3458 if (!strcmp(keywords
[j
].name
, name
.u
.pszVal
))
3460 if (j
< sizeof(keywords
)/sizeof(keywords
[0]) && !keywords
[j
].seen
)
3462 keywords
[j
].seen
= TRUE
;
3463 item
= create_prop(keywords
[j
].propid
, &value
);
3465 add_property(bitmap
, item
);
3470 PropVariantClear(&name
);
3471 PropVariantClear(&value
);
3474 else if (SUCCEEDED(hr
) && IsEqualGUID(&GUID_MetadataFormatChunkgAMA
, &format
))
3480 item
= heap_alloc_zero(sizeof(PropertyItem
) + sizeof(ULONG
) * 2);
3484 item
->length
= sizeof(ULONG
) * 2;
3485 item
->type
= PropertyTagTypeRational
;
3486 item
->id
= PropertyTagGamma
;
3487 rational
= item
->value
= item
+ 1;
3488 rational
[0] = 100000;
3489 rational
[1] = get_ulong_by_index(reader
, 0);
3490 add_property(bitmap
, item
);
3496 else if (SUCCEEDED(hr
) && IsEqualGUID(&GUID_MetadataFormatChunkcHRM
, &format
))
3500 if (!seen_whitepoint
)
3502 item
= GdipAlloc(sizeof(PropertyItem
) + sizeof(ULONG
) * 4);
3506 item
->length
= sizeof(ULONG
) * 4;
3507 item
->type
= PropertyTagTypeRational
;
3508 item
->id
= PropertyTagWhitePoint
;
3509 rational
= item
->value
= item
+ 1;
3510 rational
[0] = get_ulong_by_index(reader
, 0);
3511 rational
[1] = 100000;
3512 rational
[2] = get_ulong_by_index(reader
, 1);
3513 rational
[3] = 100000;
3514 add_property(bitmap
, item
);
3515 seen_whitepoint
= TRUE
;
3521 item
= GdipAlloc(sizeof(PropertyItem
) + sizeof(ULONG
) * 12);
3525 item
->length
= sizeof(ULONG
) * 12;
3526 item
->type
= PropertyTagTypeRational
;
3527 item
->id
= PropertyTagPrimaryChromaticities
;
3528 rational
= item
->value
= item
+ 1;
3529 rational
[0] = get_ulong_by_index(reader
, 2);
3530 rational
[1] = 100000;
3531 rational
[2] = get_ulong_by_index(reader
, 3);
3532 rational
[3] = 100000;
3533 rational
[4] = get_ulong_by_index(reader
, 4);
3534 rational
[5] = 100000;
3535 rational
[6] = get_ulong_by_index(reader
, 5);
3536 rational
[7] = 100000;
3537 rational
[8] = get_ulong_by_index(reader
, 6);
3538 rational
[9] = 100000;
3539 rational
[10] = get_ulong_by_index(reader
, 7);
3540 rational
[11] = 100000;
3541 add_property(bitmap
, item
);
3548 IWICMetadataReader_Release(reader
);
3552 IWICMetadataBlockReader_Release(block_reader
);
3555 IWICBitmapFrameDecode_Release(frame
);
3558 static GpStatus
initialize_decoder_wic(IStream
*stream
, REFGUID container
, IWICBitmapDecoder
**decoder
)
3560 IWICImagingFactory
*factory
;
3563 TRACE("%p,%s\n", stream
, wine_dbgstr_guid(container
));
3565 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
3566 if (FAILED(hr
)) return hresult_to_status(hr
);
3567 hr
= IWICImagingFactory_CreateDecoder(factory
, container
, NULL
, decoder
);
3568 IWICImagingFactory_Release(factory
);
3569 if (FAILED(hr
)) return hresult_to_status(hr
);
3571 hr
= IWICBitmapDecoder_Initialize(*decoder
, stream
, WICDecodeMetadataCacheOnLoad
);
3572 if (FAILED(hr
)) return hresult_to_status(hr
);
3576 typedef void (*metadata_reader_func
)(GpBitmap
*bitmap
, IWICBitmapDecoder
*decoder
, UINT frame
);
3578 static GpStatus
decode_frame_wic(IWICBitmapDecoder
*decoder
, BOOL force_conversion
,
3579 UINT active_frame
, metadata_reader_func metadata_reader
, GpImage
**image
)
3584 IWICBitmapFrameDecode
*frame
;
3585 IWICBitmapSource
*source
=NULL
;
3586 IWICMetadataBlockReader
*block_reader
;
3587 WICPixelFormatGUID wic_format
;
3588 PixelFormat gdip_format
=0;
3589 ColorPalette
*palette
= NULL
;
3590 WICBitmapPaletteType palette_type
= WICBitmapPaletteTypeFixedHalftone256
;
3592 UINT width
, height
, frame_count
;
3593 BitmapData lockeddata
;
3596 TRACE("%p,%u,%p\n", decoder
, active_frame
, image
);
3598 IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
3599 hr
= IWICBitmapDecoder_GetFrame(decoder
, active_frame
, &frame
);
3600 if (SUCCEEDED(hr
)) /* got frame */
3602 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &wic_format
);
3606 if (!force_conversion
)
3608 for (i
=0; pixel_formats
[i
].wic_format
; i
++)
3610 if (IsEqualGUID(&wic_format
, pixel_formats
[i
].wic_format
))
3612 source
= (IWICBitmapSource
*)frame
;
3613 IWICBitmapSource_AddRef(source
);
3614 gdip_format
= pixel_formats
[i
].gdip_format
;
3615 palette_type
= pixel_formats
[i
].palette_type
;
3622 /* unknown format; fall back on 32bppARGB */
3623 hr
= WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA
, (IWICBitmapSource
*)frame
, &source
);
3624 gdip_format
= PixelFormat32bppARGB
;
3626 TRACE("%s => %#x\n", wine_dbgstr_guid(&wic_format
), gdip_format
);
3629 if (SUCCEEDED(hr
)) /* got source */
3631 hr
= IWICBitmapSource_GetSize(source
, &width
, &height
);
3634 status
= GdipCreateBitmapFromScan0(width
, height
, 0, gdip_format
,
3637 if (SUCCEEDED(hr
) && status
== Ok
) /* created bitmap */
3639 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeWrite
,
3640 gdip_format
, &lockeddata
);
3641 if (status
== Ok
) /* locked bitmap */
3646 for (i
=0; i
<height
; i
++)
3649 hr
= IWICBitmapSource_CopyPixels(source
, &wrc
, abs(lockeddata
.Stride
),
3650 abs(lockeddata
.Stride
), (BYTE
*)lockeddata
.Scan0
+lockeddata
.Stride
*i
);
3651 if (FAILED(hr
)) break;
3654 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3657 if (SUCCEEDED(hr
) && status
== Ok
)
3658 *image
= &bitmap
->image
;
3662 GdipDisposeImage(&bitmap
->image
);
3665 if (SUCCEEDED(hr
) && status
== Ok
)
3668 hr
= IWICBitmapSource_GetResolution(source
, &dpix
, &dpiy
);
3671 bitmap
->image
.xres
= dpix
;
3672 bitmap
->image
.yres
= dpiy
;
3678 IWICBitmapSource_Release(source
);
3681 if (SUCCEEDED(hr
)) {
3682 bitmap
->metadata_reader
= NULL
;
3684 if (metadata_reader
)
3685 metadata_reader(bitmap
, decoder
, active_frame
);
3686 else if (IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
) == S_OK
)
3688 UINT block_count
= 0;
3689 if (IWICMetadataBlockReader_GetCount(block_reader
, &block_count
) == S_OK
&& block_count
)
3690 IWICMetadataBlockReader_GetReaderByIndex(block_reader
, 0, &bitmap
->metadata_reader
);
3691 IWICMetadataBlockReader_Release(block_reader
);
3694 palette
= get_palette(frame
, palette_type
);
3695 IWICBitmapFrameDecode_Release(frame
);
3699 if (FAILED(hr
) && status
== Ok
) status
= hresult_to_status(hr
);
3703 /* Native GDI+ used to be smarter, but since Win7 it just sets these flags. */
3704 bitmap
->image
.flags
|= ImageFlagsReadOnly
|ImageFlagsHasRealPixelSize
|ImageFlagsHasRealDPI
|ImageFlagsColorSpaceRGB
;
3705 bitmap
->image
.frame_count
= frame_count
;
3706 bitmap
->image
.current_frame
= active_frame
;
3707 bitmap
->image
.decoder
= decoder
;
3708 IWICBitmapDecoder_AddRef(decoder
);
3711 heap_free(bitmap
->image
.palette
);
3712 bitmap
->image
.palette
= palette
;
3716 if (IsEqualGUID(&wic_format
, &GUID_WICPixelFormatBlackWhite
))
3717 bitmap
->image
.palette
->Flags
= 0;
3719 TRACE("=> %p\n", *image
);
3725 static GpStatus
decode_image_wic(IStream
*stream
, REFGUID container
,
3726 metadata_reader_func metadata_reader
, GpImage
**image
)
3728 IWICBitmapDecoder
*decoder
;
3731 status
= initialize_decoder_wic(stream
, container
, &decoder
);
3735 status
= decode_frame_wic(decoder
, FALSE
, 0, metadata_reader
, image
);
3736 IWICBitmapDecoder_Release(decoder
);
3740 static GpStatus
select_frame_wic(GpImage
*image
, UINT active_frame
)
3745 status
= decode_frame_wic(image
->decoder
, FALSE
, active_frame
, NULL
, &new_image
);
3749 memcpy(&new_image
->format
, &image
->format
, sizeof(GUID
));
3750 free_image_data(image
);
3751 if (image
->type
== ImageTypeBitmap
)
3752 *(GpBitmap
*)image
= *(GpBitmap
*)new_image
;
3753 else if (image
->type
== ImageTypeMetafile
)
3754 *(GpMetafile
*)image
= *(GpMetafile
*)new_image
;
3755 new_image
->type
= ~0;
3756 heap_free(new_image
);
3760 static HRESULT
get_gif_frame_rect(IWICBitmapFrameDecode
*frame
,
3761 UINT
*left
, UINT
*top
, UINT
*width
, UINT
*height
)
3763 static const WCHAR leftW
[] = {'L','e','f','t',0};
3764 static const WCHAR topW
[] = {'T','o','p',0};
3766 *left
= get_gif_frame_property(frame
, &GUID_MetadataFormatIMD
, leftW
);
3767 *top
= get_gif_frame_property(frame
, &GUID_MetadataFormatIMD
, topW
);
3769 return IWICBitmapFrameDecode_GetSize(frame
, width
, height
);
3772 static HRESULT
blit_gif_frame(GpBitmap
*bitmap
, IWICBitmapFrameDecode
*frame
, BOOL first_frame
)
3774 UINT i
, j
, left
, top
, width
, height
;
3775 IWICBitmapSource
*source
;
3779 hr
= get_gif_frame_rect(frame
, &left
, &top
, &width
, &height
);
3783 hr
= WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA
, (IWICBitmapSource
*)frame
, &source
);
3787 new_bits
= heap_alloc_zero(width
*height
*4);
3789 return E_OUTOFMEMORY
;
3791 hr
= IWICBitmapSource_CopyPixels(source
, NULL
, width
*4, width
*height
*4, new_bits
);
3792 IWICBitmapSource_Release(source
);
3794 heap_free(new_bits
);
3798 for(i
=0; i
<height
&& i
+top
<bitmap
->height
; i
++) {
3799 for(j
=0; j
<width
&& j
+left
<bitmap
->width
; j
++) {
3800 DWORD
*src
= (DWORD
*)(new_bits
+i
*width
*4+j
*4);
3801 DWORD
*dst
= (DWORD
*)(bitmap
->bits
+(i
+top
)*bitmap
->stride
+(j
+left
)*4);
3803 if(first_frame
|| *src
>>24 != 0)
3807 heap_free(new_bits
);
3811 static DWORD
get_gif_background_color(GpBitmap
*bitmap
)
3813 BYTE bgcolor_idx
= 0;
3816 for(i
=0; i
<bitmap
->prop_count
; i
++) {
3817 if(bitmap
->prop_item
[i
].id
== PropertyTagIndexBackground
) {
3818 bgcolor_idx
= *(BYTE
*)bitmap
->prop_item
[i
].value
;
3823 for(i
=0; i
<bitmap
->prop_count
; i
++) {
3824 if(bitmap
->prop_item
[i
].id
== PropertyTagIndexTransparent
) {
3825 BYTE transparent_idx
;
3826 transparent_idx
= *(BYTE
*)bitmap
->prop_item
[i
].value
;
3828 if(transparent_idx
== bgcolor_idx
)
3833 for(i
=0; i
<bitmap
->prop_count
; i
++) {
3834 if(bitmap
->prop_item
[i
].id
== PropertyTagGlobalPalette
) {
3835 if(bitmap
->prop_item
[i
].length
/3 > bgcolor_idx
) {
3836 BYTE
*color
= ((BYTE
*)bitmap
->prop_item
[i
].value
)+bgcolor_idx
*3;
3837 return color
[2] + (color
[1]<<8) + (color
[0]<<16) + (0xffu
<<24);
3843 FIXME("can't get gif background color\n");
3847 static GpStatus
select_frame_gif(GpImage
* image
, UINT active_frame
)
3849 static const WCHAR disposalW
[] = {'D','i','s','p','o','s','a','l',0};
3851 GpBitmap
*bitmap
= (GpBitmap
*)image
;
3852 IWICBitmapFrameDecode
*frame
;
3853 int cur_frame
=0, disposal
;
3854 BOOL bgcolor_set
= FALSE
;
3858 if(active_frame
> image
->current_frame
) {
3859 hr
= IWICBitmapDecoder_GetFrame(bitmap
->image
.decoder
, image
->current_frame
, &frame
);
3861 return hresult_to_status(hr
);
3862 disposal
= get_gif_frame_property(frame
, &GUID_MetadataFormatGCE
, disposalW
);
3863 IWICBitmapFrameDecode_Release(frame
);
3865 if(disposal
== GIF_DISPOSE_RESTORE_TO_BKGND
)
3866 cur_frame
= image
->current_frame
;
3867 else if(disposal
!= GIF_DISPOSE_RESTORE_TO_PREV
)
3868 cur_frame
= image
->current_frame
+1;
3871 while(cur_frame
!= active_frame
) {
3872 hr
= IWICBitmapDecoder_GetFrame(bitmap
->image
.decoder
, cur_frame
, &frame
);
3874 return hresult_to_status(hr
);
3875 disposal
= get_gif_frame_property(frame
, &GUID_MetadataFormatGCE
, disposalW
);
3877 if(disposal
==GIF_DISPOSE_UNSPECIFIED
|| disposal
==GIF_DISPOSE_DO_NOT_DISPOSE
) {
3878 hr
= blit_gif_frame(bitmap
, frame
, cur_frame
==0);
3880 return hresult_to_status(hr
);
3881 }else if(disposal
== GIF_DISPOSE_RESTORE_TO_BKGND
) {
3882 UINT left
, top
, width
, height
, i
, j
;
3885 bgcolor
= get_gif_background_color(bitmap
);
3889 hr
= get_gif_frame_rect(frame
, &left
, &top
, &width
, &height
);
3891 return hresult_to_status(hr
);
3892 for(i
=top
; i
<top
+height
&& i
<bitmap
->height
; i
++) {
3893 DWORD
*bits
= (DWORD
*)(bitmap
->bits
+i
*bitmap
->stride
);
3894 for(j
=left
; j
<left
+width
&& j
<bitmap
->width
; j
++)
3899 IWICBitmapFrameDecode_Release(frame
);
3903 hr
= IWICBitmapDecoder_GetFrame(bitmap
->image
.decoder
, active_frame
, &frame
);
3905 return hresult_to_status(hr
);
3907 hr
= blit_gif_frame(bitmap
, frame
, cur_frame
==0);
3908 IWICBitmapFrameDecode_Release(frame
);
3910 return hresult_to_status(hr
);
3912 image
->current_frame
= active_frame
;
3916 static GpStatus
decode_image_icon(IStream
* stream
, GpImage
**image
)
3918 return decode_image_wic(stream
, &GUID_ContainerFormatIco
, NULL
, image
);
3921 static GpStatus
decode_image_bmp(IStream
* stream
, GpImage
**image
)
3926 status
= decode_image_wic(stream
, &GUID_ContainerFormatBmp
, NULL
, image
);
3928 bitmap
= (GpBitmap
*)*image
;
3930 if (status
== Ok
&& bitmap
->format
== PixelFormat32bppARGB
)
3932 /* WIC supports bmp files with alpha, but gdiplus does not */
3933 bitmap
->format
= PixelFormat32bppRGB
;
3939 static GpStatus
decode_image_jpeg(IStream
* stream
, GpImage
**image
)
3941 return decode_image_wic(stream
, &GUID_ContainerFormatJpeg
, NULL
, image
);
3944 static GpStatus
decode_image_png(IStream
* stream
, GpImage
**image
)
3946 return decode_image_wic(stream
, &GUID_ContainerFormatPng
, png_metadata_reader
, image
);
3949 static GpStatus
decode_image_gif(IStream
* stream
, GpImage
**image
)
3951 IWICBitmapDecoder
*decoder
;
3956 status
= initialize_decoder_wic(stream
, &GUID_ContainerFormatGif
, &decoder
);
3960 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
3962 return hresult_to_status(hr
);
3964 status
= decode_frame_wic(decoder
, frame_count
> 1, 0, gif_metadata_reader
, image
);
3965 IWICBitmapDecoder_Release(decoder
);
3969 if(frame_count
> 1) {
3970 heap_free((*image
)->palette
);
3971 (*image
)->palette
= NULL
;
3976 static GpStatus
decode_image_tiff(IStream
* stream
, GpImage
**image
)
3978 return decode_image_wic(stream
, &GUID_ContainerFormatTiff
, NULL
, image
);
3981 static GpStatus
load_wmf(IStream
*stream
, GpMetafile
**metafile
)
3983 WmfPlaceableFileHeader pfh
;
3984 BOOL is_placeable
= FALSE
;
3993 hr
= IStream_Read(stream
, &mh
, sizeof(mh
), &size
);
3994 if (hr
!= S_OK
|| size
!= sizeof(mh
))
3995 return GenericError
;
3997 if (((WmfPlaceableFileHeader
*)&mh
)->Key
== WMF_PLACEABLE_KEY
)
4000 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4001 if (FAILED(hr
)) return hresult_to_status(hr
);
4003 hr
= IStream_Read(stream
, &pfh
, sizeof(pfh
), &size
);
4004 if (hr
!= S_OK
|| size
!= sizeof(pfh
))
4005 return GenericError
;
4007 hr
= IStream_Read(stream
, &mh
, sizeof(mh
), &size
);
4008 if (hr
!= S_OK
|| size
!= sizeof(mh
))
4009 return GenericError
;
4011 is_placeable
= TRUE
;
4014 seek
.QuadPart
= is_placeable
? sizeof(pfh
) : 0;
4015 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4016 if (FAILED(hr
)) return hresult_to_status(hr
);
4018 buf
= heap_alloc(mh
.mtSize
* 2);
4019 if (!buf
) return OutOfMemory
;
4021 hr
= IStream_Read(stream
, buf
, mh
.mtSize
* 2, &size
);
4022 if (hr
!= S_OK
|| size
!= mh
.mtSize
* 2)
4025 return GenericError
;
4028 hmf
= SetMetaFileBitsEx(mh
.mtSize
* 2, buf
);
4031 return GenericError
;
4033 status
= GdipCreateMetafileFromWmf(hmf
, TRUE
, is_placeable
? &pfh
: NULL
, metafile
);
4035 DeleteMetaFile(hmf
);
4039 static GpStatus
decode_image_wmf(IStream
*stream
, GpImage
**image
)
4041 GpMetafile
*metafile
;
4044 TRACE("%p %p\n", stream
, image
);
4046 if (!stream
|| !image
)
4047 return InvalidParameter
;
4049 status
= load_wmf(stream
, &metafile
);
4052 TRACE("Could not load metafile\n");
4056 *image
= (GpImage
*)metafile
;
4057 TRACE("<-- %p\n", *image
);
4062 static GpStatus
load_emf(IStream
*stream
, GpMetafile
**metafile
)
4072 hr
= IStream_Read(stream
, &emh
, sizeof(emh
), &size
);
4073 if (hr
!= S_OK
|| size
!= sizeof(emh
) || emh
.dSignature
!= ENHMETA_SIGNATURE
)
4074 return GenericError
;
4077 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4078 if (FAILED(hr
)) return hresult_to_status(hr
);
4080 buf
= heap_alloc(emh
.nBytes
);
4081 if (!buf
) return OutOfMemory
;
4083 hr
= IStream_Read(stream
, buf
, emh
.nBytes
, &size
);
4084 if (hr
!= S_OK
|| size
!= emh
.nBytes
)
4087 return GenericError
;
4090 hemf
= SetEnhMetaFileBits(emh
.nBytes
, buf
);
4093 return GenericError
;
4095 status
= GdipCreateMetafileFromEmf(hemf
, TRUE
, metafile
);
4097 DeleteEnhMetaFile(hemf
);
4101 static GpStatus
decode_image_emf(IStream
*stream
, GpImage
**image
)
4103 GpMetafile
*metafile
;
4106 TRACE("%p %p\n", stream
, image
);
4108 if (!stream
|| !image
)
4109 return InvalidParameter
;
4111 status
= load_emf(stream
, &metafile
);
4114 TRACE("Could not load metafile\n");
4118 *image
= (GpImage
*)metafile
;
4119 TRACE("<-- %p\n", *image
);
4124 typedef GpStatus (*encode_image_func
)(GpImage
*image
, IStream
* stream
,
4125 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
);
4127 typedef GpStatus (*decode_image_func
)(IStream
*stream
, GpImage
**image
);
4129 typedef GpStatus (*select_image_func
)(GpImage
*image
, UINT active_frame
);
4131 typedef struct image_codec
{
4132 ImageCodecInfo info
;
4133 encode_image_func encode_func
;
4134 decode_image_func decode_func
;
4135 select_image_func select_func
;
4150 static const struct image_codec codecs
[NUM_CODECS
];
4152 static GpStatus
get_decoder_info(IStream
* stream
, const struct image_codec
**result
)
4155 const BYTE
*pattern
, *mask
;
4162 /* seek to the start of the stream */
4164 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4165 if (FAILED(hr
)) return hresult_to_status(hr
);
4167 /* read the first 8 bytes */
4168 /* FIXME: This assumes all codecs have signatures <= 8 bytes in length */
4169 hr
= IStream_Read(stream
, signature
, 8, &bytesread
);
4170 if (FAILED(hr
)) return hresult_to_status(hr
);
4171 if (hr
== S_FALSE
|| bytesread
== 0) return GenericError
;
4173 for (i
= 0; i
< NUM_CODECS
; i
++) {
4174 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
) &&
4175 bytesread
>= codecs
[i
].info
.SigSize
)
4177 for (sig
=0; sig
<codecs
[i
].info
.SigCount
; sig
++)
4179 pattern
= &codecs
[i
].info
.SigPattern
[codecs
[i
].info
.SigSize
*sig
];
4180 mask
= &codecs
[i
].info
.SigMask
[codecs
[i
].info
.SigSize
*sig
];
4181 for (j
=0; j
<codecs
[i
].info
.SigSize
; j
++)
4182 if ((signature
[j
] & mask
[j
]) != pattern
[j
])
4184 if (j
== codecs
[i
].info
.SigSize
)
4186 *result
= &codecs
[i
];
4193 TRACE("no match for %i byte signature %x %x %x %x %x %x %x %x\n", bytesread
,
4194 signature
[0],signature
[1],signature
[2],signature
[3],
4195 signature
[4],signature
[5],signature
[6],signature
[7]);
4197 return GenericError
;
4200 static GpStatus
get_decoder_info_from_image(GpImage
*image
, const struct image_codec
**result
)
4204 for (i
= 0; i
< NUM_CODECS
; i
++) {
4205 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
) &&
4206 IsEqualIID(&codecs
[i
].info
.FormatID
, &image
->format
))
4208 *result
= &codecs
[i
];
4213 TRACE("no match for format: %s\n", wine_dbgstr_guid(&image
->format
));
4214 return GenericError
;
4217 GpStatus WINGDIPAPI
GdipImageSelectActiveFrame(GpImage
*image
, GDIPCONST GUID
*dimensionID
,
4221 const struct image_codec
*codec
= NULL
;
4223 TRACE("(%p,%s,%u)\n", image
, debugstr_guid(dimensionID
), frame
);
4225 if (!image
|| !dimensionID
)
4226 return InvalidParameter
;
4228 if (frame
>= image
->frame_count
)
4230 WARN("requested frame %u, but image has only %u\n", frame
, image
->frame_count
);
4231 return InvalidParameter
;
4234 if (image
->type
!= ImageTypeBitmap
&& image
->type
!= ImageTypeMetafile
)
4236 WARN("invalid image type %d\n", image
->type
);
4237 return InvalidParameter
;
4240 if (image
->current_frame
== frame
)
4243 if (!image
->decoder
)
4245 TRACE("image doesn't have an associated decoder\n");
4249 /* choose an appropriate image decoder */
4250 stat
= get_decoder_info_from_image(image
, &codec
);
4253 WARN("can't find decoder info\n");
4257 return codec
->select_func(image
, frame
);
4260 GpStatus WINGDIPAPI
GdipLoadImageFromStream(IStream
*stream
, GpImage
**image
)
4265 const struct image_codec
*codec
=NULL
;
4267 /* choose an appropriate image decoder */
4268 stat
= get_decoder_info(stream
, &codec
);
4269 if (stat
!= Ok
) return stat
;
4271 /* seek to the start of the stream */
4273 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4274 if (FAILED(hr
)) return hresult_to_status(hr
);
4276 /* call on the image decoder to do the real work */
4277 stat
= codec
->decode_func(stream
, image
);
4279 /* take note of the original data format */
4282 memcpy(&(*image
)->format
, &codec
->info
.FormatID
, sizeof(GUID
));
4290 GpStatus WINGDIPAPI
GdipLoadImageFromStreamICM(IStream
* stream
, GpImage
**image
)
4292 TRACE("%p %p\n", stream
, image
);
4294 return GdipLoadImageFromStream(stream
, image
);
4297 GpStatus WINGDIPAPI
GdipRemovePropertyItem(GpImage
*image
, PROPID propId
)
4301 TRACE("(%p,%u)\n", image
, propId
);
4304 return InvalidParameter
;
4307 FIXME("not implemented\n");
4309 return NotImplemented
;
4312 GpStatus WINGDIPAPI
GdipSetPropertyItem(GpImage
*image
, GDIPCONST PropertyItem
* item
)
4316 if (!image
|| !item
) return InvalidParameter
;
4318 TRACE("(%p,%p:%#x,%u,%u,%p)\n", image
, item
, item
->id
, item
->type
, item
->length
, item
->value
);
4321 FIXME("not implemented\n");
4326 GpStatus WINGDIPAPI
GdipSaveImageToFile(GpImage
*image
, GDIPCONST WCHAR
* filename
,
4327 GDIPCONST CLSID
*clsidEncoder
,
4328 GDIPCONST EncoderParameters
*encoderParams
)
4333 TRACE("%p (%s) %p %p\n", image
, debugstr_w(filename
), clsidEncoder
, encoderParams
);
4335 if (!image
|| !filename
|| !clsidEncoder
)
4336 return InvalidParameter
;
4338 stat
= GdipCreateStreamOnFile(filename
, GENERIC_WRITE
, &stream
);
4340 return GenericError
;
4342 stat
= GdipSaveImageToStream(image
, stream
, clsidEncoder
, encoderParams
);
4344 IStream_Release(stream
);
4348 /*************************************************************************
4349 * Encoding functions -
4350 * These functions encode an image in different image file formats.
4353 static GpStatus
encode_image_wic(GpImage
*image
, IStream
* stream
,
4354 REFGUID container
, GDIPCONST EncoderParameters
* params
)
4358 IWICImagingFactory
*factory
;
4359 IWICBitmapEncoder
*encoder
;
4360 IWICBitmapFrameEncode
*frameencode
;
4361 IPropertyBag2
*encoderoptions
;
4364 PixelFormat gdipformat
=0;
4365 const WICPixelFormatGUID
*desired_wicformat
;
4366 WICPixelFormatGUID wicformat
;
4368 BitmapData lockeddata
;
4371 if (image
->type
!= ImageTypeBitmap
)
4372 return GenericError
;
4374 bitmap
= (GpBitmap
*)image
;
4376 GdipGetImageWidth(image
, &width
);
4377 GdipGetImageHeight(image
, &height
);
4384 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
4386 return hresult_to_status(hr
);
4387 hr
= IWICImagingFactory_CreateEncoder(factory
, container
, NULL
, &encoder
);
4388 IWICImagingFactory_Release(factory
);
4390 return hresult_to_status(hr
);
4392 hr
= IWICBitmapEncoder_Initialize(encoder
, stream
, WICBitmapEncoderNoCache
);
4396 hr
= IWICBitmapEncoder_CreateNewFrame(encoder
, &frameencode
, &encoderoptions
);
4399 if (SUCCEEDED(hr
)) /* created frame */
4401 hr
= IWICBitmapFrameEncode_Initialize(frameencode
, encoderoptions
);
4404 hr
= IWICBitmapFrameEncode_SetSize(frameencode
, width
, height
);
4407 hr
= IWICBitmapFrameEncode_SetResolution(frameencode
, image
->xres
, image
->yres
);
4411 for (i
=0; pixel_formats
[i
].wic_format
; i
++)
4413 if (pixel_formats
[i
].gdip_format
== bitmap
->format
)
4415 desired_wicformat
= pixel_formats
[i
].wic_format
;
4416 gdipformat
= bitmap
->format
;
4422 desired_wicformat
= &GUID_WICPixelFormat32bppBGRA
;
4423 gdipformat
= PixelFormat32bppARGB
;
4426 memcpy(&wicformat
, desired_wicformat
, sizeof(GUID
));
4427 hr
= IWICBitmapFrameEncode_SetPixelFormat(frameencode
, &wicformat
);
4430 if (SUCCEEDED(hr
) && !IsEqualGUID(desired_wicformat
, &wicformat
))
4432 /* Encoder doesn't support this bitmap's format. */
4434 for (i
=0; pixel_formats
[i
].wic_format
; i
++)
4436 if (IsEqualGUID(&wicformat
, pixel_formats
[i
].wic_format
))
4438 gdipformat
= pixel_formats
[i
].gdip_format
;
4444 ERR("Cannot support encoder format %s\n", debugstr_guid(&wicformat
));
4451 stat
= GdipBitmapLockBits(bitmap
, &rc
, ImageLockModeRead
, gdipformat
,
4456 UINT row_size
= (lockeddata
.Width
* PIXELFORMATBPP(gdipformat
) + 7)/8;
4459 /* write one row at a time in case stride is negative */
4460 row
= lockeddata
.Scan0
;
4461 for (i
=0; i
<lockeddata
.Height
; i
++)
4463 hr
= IWICBitmapFrameEncode_WritePixels(frameencode
, 1, row_size
, row_size
, row
);
4464 if (FAILED(hr
)) break;
4465 row
+= lockeddata
.Stride
;
4468 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
4475 hr
= IWICBitmapFrameEncode_Commit(frameencode
);
4477 IWICBitmapFrameEncode_Release(frameencode
);
4478 IPropertyBag2_Release(encoderoptions
);
4482 hr
= IWICBitmapEncoder_Commit(encoder
);
4484 IWICBitmapEncoder_Release(encoder
);
4485 return hresult_to_status(hr
);
4488 static GpStatus
encode_image_BMP(GpImage
*image
, IStream
* stream
,
4489 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4491 return encode_image_wic(image
, stream
, &GUID_ContainerFormatBmp
, params
);
4494 static GpStatus
encode_image_tiff(GpImage
*image
, IStream
* stream
,
4495 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4497 return encode_image_wic(image
, stream
, &GUID_ContainerFormatTiff
, params
);
4500 static GpStatus
encode_image_png(GpImage
*image
, IStream
* stream
,
4501 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4503 return encode_image_wic(image
, stream
, &GUID_ContainerFormatPng
, params
);
4506 static GpStatus
encode_image_jpeg(GpImage
*image
, IStream
* stream
,
4507 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4509 return encode_image_wic(image
, stream
, &GUID_ContainerFormatJpeg
, params
);
4512 static GpStatus
encode_image_gif(GpImage
*image
, IStream
* stream
,
4513 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4515 return encode_image_wic(image
, stream
, &CLSID_WICGifEncoder
, params
);
4518 /*****************************************************************************
4519 * GdipSaveImageToStream [GDIPLUS.@]
4521 GpStatus WINGDIPAPI
GdipSaveImageToStream(GpImage
*image
, IStream
* stream
,
4522 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4525 encode_image_func encode_image
;
4528 TRACE("%p %p %p %p\n", image
, stream
, clsid
, params
);
4530 if(!image
|| !stream
)
4531 return InvalidParameter
;
4533 /* select correct encoder */
4534 encode_image
= NULL
;
4535 for (i
= 0; i
< NUM_CODECS
; i
++) {
4536 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
) &&
4537 IsEqualCLSID(clsid
, &codecs
[i
].info
.Clsid
))
4538 encode_image
= codecs
[i
].encode_func
;
4540 if (encode_image
== NULL
)
4541 return UnknownImageFormat
;
4543 stat
= encode_image(image
, stream
, clsid
, params
);
4548 /*****************************************************************************
4549 * GdipSaveAdd [GDIPLUS.@]
4551 GpStatus WINGDIPAPI
GdipSaveAdd(GpImage
*image
, GDIPCONST EncoderParameters
*params
)
4553 FIXME("(%p,%p): stub\n", image
, params
);
4557 /*****************************************************************************
4558 * GdipGetImagePalette [GDIPLUS.@]
4560 GpStatus WINGDIPAPI
GdipGetImagePalette(GpImage
*image
, ColorPalette
*palette
, INT size
)
4564 TRACE("(%p,%p,%i)\n", image
, palette
, size
);
4566 if (!image
|| !palette
)
4567 return InvalidParameter
;
4569 count
= image
->palette
? image
->palette
->Count
: 0;
4571 if (size
< (sizeof(UINT
)*2+sizeof(ARGB
)*count
))
4573 TRACE("<-- InsufficientBuffer\n");
4574 return InsufficientBuffer
;
4579 palette
->Flags
= image
->palette
->Flags
;
4580 palette
->Count
= image
->palette
->Count
;
4581 memcpy(palette
->Entries
, image
->palette
->Entries
, sizeof(ARGB
)*image
->palette
->Count
);
4591 /*****************************************************************************
4592 * GdipSetImagePalette [GDIPLUS.@]
4594 GpStatus WINGDIPAPI
GdipSetImagePalette(GpImage
*image
,
4595 GDIPCONST ColorPalette
*palette
)
4597 ColorPalette
*new_palette
;
4599 TRACE("(%p,%p)\n", image
, palette
);
4601 if(!image
|| !palette
|| palette
->Count
> 256)
4602 return InvalidParameter
;
4604 new_palette
= heap_alloc_zero(2 * sizeof(UINT
) + palette
->Count
* sizeof(ARGB
));
4605 if (!new_palette
) return OutOfMemory
;
4607 heap_free(image
->palette
);
4608 image
->palette
= new_palette
;
4609 image
->palette
->Flags
= palette
->Flags
;
4610 image
->palette
->Count
= palette
->Count
;
4611 memcpy(image
->palette
->Entries
, palette
->Entries
, sizeof(ARGB
)*palette
->Count
);
4616 /*************************************************************************
4618 * Structures that represent which formats we support for encoding.
4621 /* ImageCodecInfo creation routines taken from libgdiplus */
4622 static const WCHAR bmp_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
4623 static const WCHAR bmp_extension
[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
4624 static const WCHAR bmp_mimetype
[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
4625 static const WCHAR bmp_format
[] = {'B', 'M', 'P', 0}; /* BMP */
4626 static const BYTE bmp_sig_pattern
[] = { 0x42, 0x4D };
4627 static const BYTE bmp_sig_mask
[] = { 0xFF, 0xFF };
4629 static const WCHAR jpeg_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'J','P','E','G', 0};
4630 static const WCHAR jpeg_extension
[] = {'*','.','J','P','G',';', '*','.','J','P','E','G',';', '*','.','J','P','E',';', '*','.','J','F','I','F',0};
4631 static const WCHAR jpeg_mimetype
[] = {'i','m','a','g','e','/','j','p','e','g', 0};
4632 static const WCHAR jpeg_format
[] = {'J','P','E','G',0};
4633 static const BYTE jpeg_sig_pattern
[] = { 0xFF, 0xD8 };
4634 static const BYTE jpeg_sig_mask
[] = { 0xFF, 0xFF };
4636 static const WCHAR gif_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'G','I','F', 0};
4637 static const WCHAR gif_extension
[] = {'*','.','G','I','F',0};
4638 static const WCHAR gif_mimetype
[] = {'i','m','a','g','e','/','g','i','f', 0};
4639 static const WCHAR gif_format
[] = {'G','I','F',0};
4640 static const BYTE gif_sig_pattern
[12] = "GIF87aGIF89a";
4641 static const BYTE gif_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4643 static const WCHAR tiff_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'T','I','F','F', 0};
4644 static const WCHAR tiff_extension
[] = {'*','.','T','I','F','F',';','*','.','T','I','F',0};
4645 static const WCHAR tiff_mimetype
[] = {'i','m','a','g','e','/','t','i','f','f', 0};
4646 static const WCHAR tiff_format
[] = {'T','I','F','F',0};
4647 static const BYTE tiff_sig_pattern
[] = {0x49,0x49,42,0,0x4d,0x4d,0,42};
4648 static const BYTE tiff_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4650 static const WCHAR emf_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'E','M','F', 0};
4651 static const WCHAR emf_extension
[] = {'*','.','E','M','F',0};
4652 static const WCHAR emf_mimetype
[] = {'i','m','a','g','e','/','x','-','e','m','f', 0};
4653 static const WCHAR emf_format
[] = {'E','M','F',0};
4654 static const BYTE emf_sig_pattern
[] = { 0x01, 0x00, 0x00, 0x00 };
4655 static const BYTE emf_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
4657 static const WCHAR wmf_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'W','M','F', 0};
4658 static const WCHAR wmf_extension
[] = {'*','.','W','M','F',0};
4659 static const WCHAR wmf_mimetype
[] = {'i','m','a','g','e','/','x','-','w','m','f', 0};
4660 static const WCHAR wmf_format
[] = {'W','M','F',0};
4661 static const BYTE wmf_sig_pattern
[] = { 0xd7, 0xcd };
4662 static const BYTE wmf_sig_mask
[] = { 0xFF, 0xFF };
4664 static const WCHAR png_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'P','N','G', 0};
4665 static const WCHAR png_extension
[] = {'*','.','P','N','G',0};
4666 static const WCHAR png_mimetype
[] = {'i','m','a','g','e','/','p','n','g', 0};
4667 static const WCHAR png_format
[] = {'P','N','G',0};
4668 static const BYTE png_sig_pattern
[] = { 137, 80, 78, 71, 13, 10, 26, 10, };
4669 static const BYTE png_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4671 static const WCHAR ico_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'I','C','O', 0};
4672 static const WCHAR ico_extension
[] = {'*','.','I','C','O',0};
4673 static const WCHAR ico_mimetype
[] = {'i','m','a','g','e','/','x','-','i','c','o','n', 0};
4674 static const WCHAR ico_format
[] = {'I','C','O',0};
4675 static const BYTE ico_sig_pattern
[] = { 0x00, 0x00, 0x01, 0x00 };
4676 static const BYTE ico_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
4678 static const struct image_codec codecs
[NUM_CODECS
] = {
4681 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4682 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4683 /* CodecName */ bmp_codecname
,
4685 /* FormatDescription */ bmp_format
,
4686 /* FilenameExtension */ bmp_extension
,
4687 /* MimeType */ bmp_mimetype
,
4688 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4692 /* SigPattern */ bmp_sig_pattern
,
4693 /* SigMask */ bmp_sig_mask
,
4701 /* Clsid */ { 0x557cf401, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4702 /* FormatID */ { 0xb96b3caeU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4703 /* CodecName */ jpeg_codecname
,
4705 /* FormatDescription */ jpeg_format
,
4706 /* FilenameExtension */ jpeg_extension
,
4707 /* MimeType */ jpeg_mimetype
,
4708 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4712 /* SigPattern */ jpeg_sig_pattern
,
4713 /* SigMask */ jpeg_sig_mask
,
4721 /* Clsid */ { 0x557cf402, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4722 /* FormatID */ { 0xb96b3cb0U
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4723 /* CodecName */ gif_codecname
,
4725 /* FormatDescription */ gif_format
,
4726 /* FilenameExtension */ gif_extension
,
4727 /* MimeType */ gif_mimetype
,
4728 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsEncoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4732 /* SigPattern */ gif_sig_pattern
,
4733 /* SigMask */ gif_sig_mask
,
4741 /* Clsid */ { 0x557cf405, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4742 /* FormatID */ { 0xb96b3cb1U
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4743 /* CodecName */ tiff_codecname
,
4745 /* FormatDescription */ tiff_format
,
4746 /* FilenameExtension */ tiff_extension
,
4747 /* MimeType */ tiff_mimetype
,
4748 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsEncoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4752 /* SigPattern */ tiff_sig_pattern
,
4753 /* SigMask */ tiff_sig_mask
,
4761 /* Clsid */ { 0x557cf403, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4762 /* FormatID */ { 0xb96b3cacU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4763 /* CodecName */ emf_codecname
,
4765 /* FormatDescription */ emf_format
,
4766 /* FilenameExtension */ emf_extension
,
4767 /* MimeType */ emf_mimetype
,
4768 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
4772 /* SigPattern */ emf_sig_pattern
,
4773 /* SigMask */ emf_sig_mask
,
4781 /* Clsid */ { 0x557cf404, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4782 /* FormatID */ { 0xb96b3cadU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4783 /* CodecName */ wmf_codecname
,
4785 /* FormatDescription */ wmf_format
,
4786 /* FilenameExtension */ wmf_extension
,
4787 /* MimeType */ wmf_mimetype
,
4788 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
4792 /* SigPattern */ wmf_sig_pattern
,
4793 /* SigMask */ wmf_sig_mask
,
4801 /* Clsid */ { 0x557cf406, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4802 /* FormatID */ { 0xb96b3cafU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4803 /* CodecName */ png_codecname
,
4805 /* FormatDescription */ png_format
,
4806 /* FilenameExtension */ png_extension
,
4807 /* MimeType */ png_mimetype
,
4808 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4812 /* SigPattern */ png_sig_pattern
,
4813 /* SigMask */ png_sig_mask
,
4821 /* Clsid */ { 0x557cf407, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4822 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4823 /* CodecName */ ico_codecname
,
4825 /* FormatDescription */ ico_format
,
4826 /* FilenameExtension */ ico_extension
,
4827 /* MimeType */ ico_mimetype
,
4828 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4832 /* SigPattern */ ico_sig_pattern
,
4833 /* SigMask */ ico_sig_mask
,
4841 /*****************************************************************************
4842 * GdipGetImageDecodersSize [GDIPLUS.@]
4844 GpStatus WINGDIPAPI
GdipGetImageDecodersSize(UINT
*numDecoders
, UINT
*size
)
4846 int decoder_count
=0;
4848 TRACE("%p %p\n", numDecoders
, size
);
4850 if (!numDecoders
|| !size
)
4851 return InvalidParameter
;
4853 for (i
=0; i
<NUM_CODECS
; i
++)
4855 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
4859 *numDecoders
= decoder_count
;
4860 *size
= decoder_count
* sizeof(ImageCodecInfo
);
4865 /*****************************************************************************
4866 * GdipGetImageDecoders [GDIPLUS.@]
4868 GpStatus WINGDIPAPI
GdipGetImageDecoders(UINT numDecoders
, UINT size
, ImageCodecInfo
*decoders
)
4870 int i
, decoder_count
=0;
4871 TRACE("%u %u %p\n", numDecoders
, size
, decoders
);
4874 size
!= numDecoders
* sizeof(ImageCodecInfo
))
4875 return GenericError
;
4877 for (i
=0; i
<NUM_CODECS
; i
++)
4879 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
4881 if (decoder_count
== numDecoders
) return GenericError
;
4882 memcpy(&decoders
[decoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
4887 if (decoder_count
< numDecoders
) return GenericError
;
4892 /*****************************************************************************
4893 * GdipGetImageEncodersSize [GDIPLUS.@]
4895 GpStatus WINGDIPAPI
GdipGetImageEncodersSize(UINT
*numEncoders
, UINT
*size
)
4897 int encoder_count
=0;
4899 TRACE("%p %p\n", numEncoders
, size
);
4901 if (!numEncoders
|| !size
)
4902 return InvalidParameter
;
4904 for (i
=0; i
<NUM_CODECS
; i
++)
4906 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
4910 *numEncoders
= encoder_count
;
4911 *size
= encoder_count
* sizeof(ImageCodecInfo
);
4916 /*****************************************************************************
4917 * GdipGetImageEncoders [GDIPLUS.@]
4919 GpStatus WINGDIPAPI
GdipGetImageEncoders(UINT numEncoders
, UINT size
, ImageCodecInfo
*encoders
)
4921 int i
, encoder_count
=0;
4922 TRACE("%u %u %p\n", numEncoders
, size
, encoders
);
4925 size
!= numEncoders
* sizeof(ImageCodecInfo
))
4926 return GenericError
;
4928 for (i
=0; i
<NUM_CODECS
; i
++)
4930 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
4932 if (encoder_count
== numEncoders
) return GenericError
;
4933 memcpy(&encoders
[encoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
4938 if (encoder_count
< numEncoders
) return GenericError
;
4943 GpStatus WINGDIPAPI
GdipGetEncoderParameterListSize(GpImage
*image
,
4944 GDIPCONST CLSID
* clsidEncoder
, UINT
*size
)
4948 TRACE("(%p,%s,%p)\n", image
, debugstr_guid(clsidEncoder
), size
);
4951 FIXME("not implemented\n");
4955 return NotImplemented
;
4958 static PixelFormat
get_16bpp_format(HBITMAP hbm
)
4964 hdc
= CreateCompatibleDC(NULL
);
4966 memset(&bmh
, 0, sizeof(bmh
));
4967 bmh
.bV4Size
= sizeof(bmh
);
4970 bmh
.bV4V4Compression
= BI_BITFIELDS
;
4971 bmh
.bV4BitCount
= 16;
4973 GetDIBits(hdc
, hbm
, 0, 0, NULL
, (BITMAPINFO
*)&bmh
, DIB_RGB_COLORS
);
4975 if (bmh
.bV4RedMask
== 0x7c00 &&
4976 bmh
.bV4GreenMask
== 0x3e0 &&
4977 bmh
.bV4BlueMask
== 0x1f)
4979 result
= PixelFormat16bppRGB555
;
4981 else if (bmh
.bV4RedMask
== 0xf800 &&
4982 bmh
.bV4GreenMask
== 0x7e0 &&
4983 bmh
.bV4BlueMask
== 0x1f)
4985 result
= PixelFormat16bppRGB565
;
4989 FIXME("unrecognized bitfields %x,%x,%x\n", bmh
.bV4RedMask
,
4990 bmh
.bV4GreenMask
, bmh
.bV4BlueMask
);
4991 result
= PixelFormatUndefined
;
4999 /*****************************************************************************
5000 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
5002 GpStatus WINGDIPAPI
GdipCreateBitmapFromHBITMAP(HBITMAP hbm
, HPALETTE hpal
, GpBitmap
** bitmap
)
5007 BitmapData lockeddata
;
5009 TRACE("%p %p %p\n", hbm
, hpal
, bitmap
);
5012 return InvalidParameter
;
5014 if (GetObjectA(hbm
, sizeof(bm
), &bm
) != sizeof(bm
))
5015 return InvalidParameter
;
5017 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
5018 switch(bm
.bmBitsPixel
) {
5020 format
= PixelFormat1bppIndexed
;
5023 format
= PixelFormat4bppIndexed
;
5026 format
= PixelFormat8bppIndexed
;
5029 format
= get_16bpp_format(hbm
);
5030 if (format
== PixelFormatUndefined
)
5031 return InvalidParameter
;
5034 format
= PixelFormat24bppRGB
;
5037 format
= PixelFormat32bppRGB
;
5040 format
= PixelFormat48bppRGB
;
5043 FIXME("don't know how to handle %d bpp\n", bm
.bmBitsPixel
);
5044 return InvalidParameter
;
5047 retval
= GdipCreateBitmapFromScan0(bm
.bmWidth
, bm
.bmHeight
, 0,
5048 format
, NULL
, bitmap
);
5052 retval
= GdipBitmapLockBits(*bitmap
, NULL
, ImageLockModeWrite
,
5053 format
, &lockeddata
);
5057 char bmibuf
[FIELD_OFFSET(BITMAPINFO
, bmiColors
[256])];
5058 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
5061 hdc
= CreateCompatibleDC(NULL
);
5063 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
5064 pbmi
->bmiHeader
.biBitCount
= 0;
5066 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
5068 src_height
= abs(pbmi
->bmiHeader
.biHeight
);
5069 pbmi
->bmiHeader
.biHeight
= -src_height
;
5071 GetDIBits(hdc
, hbm
, 0, src_height
, lockeddata
.Scan0
, pbmi
, DIB_RGB_COLORS
);
5075 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
5078 if (retval
== Ok
&& hpal
)
5080 PALETTEENTRY entry
[256];
5081 ColorPalette
*palette
=NULL
;
5082 int i
, num_palette_entries
;
5084 num_palette_entries
= GetPaletteEntries(hpal
, 0, 256, entry
);
5085 if (!num_palette_entries
)
5086 retval
= GenericError
;
5088 palette
= heap_alloc_zero(sizeof(ColorPalette
) + sizeof(ARGB
) * (num_palette_entries
-1));
5090 retval
= OutOfMemory
;
5095 palette
->Count
= num_palette_entries
;
5097 for (i
=0; i
<num_palette_entries
; i
++)
5099 palette
->Entries
[i
] = 0xff000000 | entry
[i
].peRed
<< 16 |
5100 entry
[i
].peGreen
<< 8 | entry
[i
].peBlue
;
5103 retval
= GdipSetImagePalette(&(*bitmap
)->image
, palette
);
5111 GdipDisposeImage(&(*bitmap
)->image
);
5119 /*****************************************************************************
5120 * GdipCreateEffect [GDIPLUS.@]
5122 GpStatus WINGDIPAPI
GdipCreateEffect(const GUID guid
, CGpEffect
**effect
)
5124 FIXME("(%s, %p): stub\n", debugstr_guid(&guid
), effect
);
5127 return InvalidParameter
;
5131 return NotImplemented
;
5134 /*****************************************************************************
5135 * GdipDeleteEffect [GDIPLUS.@]
5137 GpStatus WINGDIPAPI
GdipDeleteEffect(CGpEffect
*effect
)
5139 FIXME("(%p): stub\n", effect
);
5140 /* note: According to Jose Roca's GDI+ Docs, this is not implemented
5141 * in Windows's gdiplus */
5142 return NotImplemented
;
5145 /*****************************************************************************
5146 * GdipSetEffectParameters [GDIPLUS.@]
5148 GpStatus WINGDIPAPI
GdipSetEffectParameters(CGpEffect
*effect
,
5149 const VOID
*params
, const UINT size
)
5153 TRACE("(%p,%p,%u)\n", effect
, params
, size
);
5156 FIXME("not implemented\n");
5158 return NotImplemented
;
5161 /*****************************************************************************
5162 * GdipGetImageFlags [GDIPLUS.@]
5164 GpStatus WINGDIPAPI
GdipGetImageFlags(GpImage
*image
, UINT
*flags
)
5166 TRACE("%p %p\n", image
, flags
);
5168 if(!image
|| !flags
)
5169 return InvalidParameter
;
5171 *flags
= image
->flags
;
5176 GpStatus WINGDIPAPI
GdipTestControl(GpTestControlEnum control
, void *param
)
5178 TRACE("(%d, %p)\n", control
, param
);
5181 case TestControlForceBilinear
:
5183 FIXME("TestControlForceBilinear not handled\n");
5185 case TestControlNoICM
:
5187 FIXME("TestControlNoICM not handled\n");
5189 case TestControlGetBuildNumber
:
5190 *((DWORD
*)param
) = 3102;
5197 GpStatus WINGDIPAPI
GdipImageForceValidation(GpImage
*image
)
5199 TRACE("%p\n", image
);
5204 /*****************************************************************************
5205 * GdipGetImageThumbnail [GDIPLUS.@]
5207 GpStatus WINGDIPAPI
GdipGetImageThumbnail(GpImage
*image
, UINT width
, UINT height
,
5208 GpImage
**ret_image
, GetThumbnailImageAbort cb
,
5212 GpGraphics
*graphics
;
5213 UINT srcwidth
, srcheight
;
5215 TRACE("(%p %u %u %p %p %p)\n",
5216 image
, width
, height
, ret_image
, cb
, cb_data
);
5218 if (!image
|| !ret_image
)
5219 return InvalidParameter
;
5221 if (!width
) width
= 120;
5222 if (!height
) height
= 120;
5224 GdipGetImageWidth(image
, &srcwidth
);
5225 GdipGetImageHeight(image
, &srcheight
);
5227 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat32bppPARGB
,
5228 NULL
, (GpBitmap
**)ret_image
);
5232 stat
= GdipGetImageGraphicsContext(*ret_image
, &graphics
);
5236 stat
= GdipDrawImageRectRectI(graphics
, image
,
5237 0, 0, width
, height
, 0, 0, srcwidth
, srcheight
, UnitPixel
,
5240 GdipDeleteGraphics(graphics
);
5245 GdipDisposeImage(*ret_image
);
5253 /*****************************************************************************
5254 * GdipImageRotateFlip [GDIPLUS.@]
5256 GpStatus WINGDIPAPI
GdipImageRotateFlip(GpImage
*image
, RotateFlipType type
)
5258 GpBitmap
*new_bitmap
;
5260 int bpp
, bytesperpixel
;
5261 BOOL rotate_90
, flip_x
, flip_y
;
5262 int src_x_offset
, src_y_offset
;
5264 UINT x
, y
, width
, height
;
5265 BitmapData src_lock
, dst_lock
;
5268 TRACE("(%p, %u)\n", image
, type
);
5271 return InvalidParameter
;
5274 flip_x
= (type
&6) == 2 || (type
&6) == 4;
5275 flip_y
= (type
&3) == 1 || (type
&3) == 2;
5277 if (image
->type
!= ImageTypeBitmap
)
5279 FIXME("Not implemented for type %i\n", image
->type
);
5280 return NotImplemented
;
5283 bitmap
= (GpBitmap
*)image
;
5284 bpp
= PIXELFORMATBPP(bitmap
->format
);
5288 FIXME("Not implemented for %i bit images\n", bpp
);
5289 return NotImplemented
;
5294 width
= bitmap
->height
;
5295 height
= bitmap
->width
;
5299 width
= bitmap
->width
;
5300 height
= bitmap
->height
;
5303 bytesperpixel
= bpp
/8;
5305 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, bitmap
->format
, NULL
, &new_bitmap
);
5310 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, bitmap
->format
, &src_lock
);
5314 stat
= GdipBitmapLockBits(new_bitmap
, NULL
, ImageLockModeWrite
, bitmap
->format
, &dst_lock
);
5318 LPBYTE src_row
, src_pixel
;
5319 LPBYTE dst_row
, dst_pixel
;
5321 src_origin
= src_lock
.Scan0
;
5322 if (flip_x
) src_origin
+= bytesperpixel
* (bitmap
->width
- 1);
5323 if (flip_y
) src_origin
+= src_lock
.Stride
* (bitmap
->height
- 1);
5327 if (flip_y
) src_x_offset
= -src_lock
.Stride
;
5328 else src_x_offset
= src_lock
.Stride
;
5329 if (flip_x
) src_y_offset
= -bytesperpixel
;
5330 else src_y_offset
= bytesperpixel
;
5334 if (flip_x
) src_x_offset
= -bytesperpixel
;
5335 else src_x_offset
= bytesperpixel
;
5336 if (flip_y
) src_y_offset
= -src_lock
.Stride
;
5337 else src_y_offset
= src_lock
.Stride
;
5340 src_row
= src_origin
;
5341 dst_row
= dst_lock
.Scan0
;
5342 for (y
=0; y
<height
; y
++)
5344 src_pixel
= src_row
;
5345 dst_pixel
= dst_row
;
5346 for (x
=0; x
<width
; x
++)
5348 /* FIXME: This could probably be faster without memcpy. */
5349 memcpy(dst_pixel
, src_pixel
, bytesperpixel
);
5350 dst_pixel
+= bytesperpixel
;
5351 src_pixel
+= src_x_offset
;
5353 src_row
+= src_y_offset
;
5354 dst_row
+= dst_lock
.Stride
;
5357 GdipBitmapUnlockBits(new_bitmap
, &dst_lock
);
5360 GdipBitmapUnlockBits(bitmap
, &src_lock
);
5364 move_bitmap(bitmap
, new_bitmap
, FALSE
);
5366 GdipDisposeImage(&new_bitmap
->image
);
5371 /*****************************************************************************
5372 * GdipImageSetAbort [GDIPLUS.@]
5374 GpStatus WINGDIPAPI
GdipImageSetAbort(GpImage
*image
, GdiplusAbort
*pabort
)
5376 FIXME("(%p, %p): stub\n", image
, pabort
);
5377 return NotImplemented
;
5380 /*****************************************************************************
5381 * GdipBitmapConvertFormat [GDIPLUS.@]
5383 GpStatus WINGDIPAPI
GdipBitmapConvertFormat(GpBitmap
*bitmap
, PixelFormat format
, DitherType dithertype
,
5384 PaletteType palettetype
, ColorPalette
*palette
, REAL alphathreshold
)
5386 FIXME("(%p, 0x%08x, %d, %d, %p, %f): stub\n", bitmap
, format
, dithertype
, palettetype
, palette
, alphathreshold
);
5387 return NotImplemented
;
5390 /*****************************************************************************
5391 * GdipBitmapGetHistogramSize [GDIPLUS.@]
5393 GpStatus WINGDIPAPI
GdipBitmapGetHistogramSize(HistogramFormat format
, UINT
*num_of_entries
)
5395 TRACE("(%d, %p)\n", format
, num_of_entries
);
5397 if (!num_of_entries
)
5398 return InvalidParameter
;
5400 *num_of_entries
= 256;