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
36 #include "gdiplus_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
41 HRESULT WINAPI
WICCreateImagingFactory_Proxy(UINT
, IWICImagingFactory
**);
43 #define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
44 #define WMF_PLACEABLE_KEY 0x9ac6cdd7
48 const WICPixelFormatGUID
*wic_format
;
49 PixelFormat gdip_format
;
50 /* predefined palette type to use for pixel format conversions */
51 WICBitmapPaletteType palette_type
;
54 { &GUID_WICPixelFormat1bppIndexed
, PixelFormat1bppIndexed
, WICBitmapPaletteTypeFixedBW
},
55 { &GUID_WICPixelFormatBlackWhite
, PixelFormat1bppIndexed
, WICBitmapPaletteTypeFixedBW
},
56 { &GUID_WICPixelFormat4bppIndexed
, PixelFormat4bppIndexed
, WICBitmapPaletteTypeFixedHalftone8
},
57 { &GUID_WICPixelFormat8bppIndexed
, PixelFormat8bppIndexed
, WICBitmapPaletteTypeFixedHalftone256
},
58 { &GUID_WICPixelFormat8bppGray
, PixelFormat8bppIndexed
, WICBitmapPaletteTypeFixedGray256
},
59 { &GUID_WICPixelFormat16bppBGR555
, PixelFormat16bppRGB555
, 0 },
60 { &GUID_WICPixelFormat24bppBGR
, PixelFormat24bppRGB
, 0 },
61 { &GUID_WICPixelFormat32bppBGR
, PixelFormat32bppRGB
, 0 },
62 { &GUID_WICPixelFormat32bppBGRA
, PixelFormat32bppARGB
, 0 },
63 { &GUID_WICPixelFormat32bppPBGRA
, PixelFormat32bppPARGB
, 0 },
67 static ColorPalette
*get_palette(IWICBitmapFrameDecode
*frame
, WICBitmapPaletteType palette_type
)
70 IWICImagingFactory
*factory
;
71 IWICPalette
*wic_palette
;
72 ColorPalette
*palette
= NULL
;
74 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
75 if (hr
!= S_OK
) return NULL
;
77 hr
= IWICImagingFactory_CreatePalette(factory
, &wic_palette
);
80 hr
= WINCODEC_ERR_PALETTEUNAVAILABLE
;
82 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, wic_palette
);
83 if (hr
!= S_OK
&& palette_type
!= 0)
85 TRACE("using predefined palette %#x\n", palette_type
);
86 hr
= IWICPalette_InitializePredefined(wic_palette
, palette_type
, FALSE
);
90 WICBitmapPaletteType type
;
94 IWICPalette_GetColorCount(wic_palette
, &count
);
95 palette
= heap_alloc(2 * sizeof(UINT
) + count
* sizeof(ARGB
));
96 IWICPalette_GetColors(wic_palette
, count
, (UINT
*)palette
->Entries
, &palette
->Count
);
98 IWICPalette_GetType(wic_palette
, &type
);
100 case WICBitmapPaletteTypeFixedGray4
:
101 case WICBitmapPaletteTypeFixedGray16
:
102 case WICBitmapPaletteTypeFixedGray256
:
103 palette
->Flags
= PaletteFlagsGrayScale
;
105 case WICBitmapPaletteTypeFixedHalftone8
:
106 case WICBitmapPaletteTypeFixedHalftone27
:
107 case WICBitmapPaletteTypeFixedHalftone64
:
108 case WICBitmapPaletteTypeFixedHalftone125
:
109 case WICBitmapPaletteTypeFixedHalftone216
:
110 case WICBitmapPaletteTypeFixedHalftone252
:
111 case WICBitmapPaletteTypeFixedHalftone256
:
112 palette
->Flags
= PaletteFlagsHalftone
;
117 IWICPalette_HasAlpha(wic_palette
, &alpha
);
119 palette
->Flags
|= PaletteFlagsHasAlpha
;
121 IWICPalette_Release(wic_palette
);
123 IWICImagingFactory_Release(factory
);
127 static HRESULT
set_palette(IWICBitmapFrameEncode
*frame
, ColorPalette
*palette
)
130 IWICImagingFactory
*factory
;
131 IWICPalette
*wic_palette
;
133 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
137 hr
= IWICImagingFactory_CreatePalette(factory
, &wic_palette
);
138 IWICImagingFactory_Release(factory
);
141 hr
= IWICPalette_InitializeCustom(wic_palette
, (UINT
*)palette
->Entries
, palette
->Count
);
144 hr
= IWICBitmapFrameEncode_SetPalette(frame
, wic_palette
);
146 IWICPalette_Release(wic_palette
);
152 GpStatus WINGDIPAPI
GdipBitmapApplyEffect(GpBitmap
* bitmap
, CGpEffect
* effect
,
153 RECT
* roi
, BOOL useAuxData
, VOID
** auxData
, INT
* auxDataSize
)
155 FIXME("(%p %p %p %d %p %p): stub\n", bitmap
, effect
, roi
, useAuxData
, auxData
, auxDataSize
);
157 * Note: According to Jose Roca's GDI+ docs, this function is not
158 * implemented in Windows's GDI+.
160 return NotImplemented
;
163 GpStatus WINGDIPAPI
GdipBitmapCreateApplyEffect(GpBitmap
** inputBitmaps
,
164 INT numInputs
, CGpEffect
* effect
, RECT
* roi
, RECT
* outputRect
,
165 GpBitmap
** outputBitmap
, BOOL useAuxData
, VOID
** auxData
, INT
* auxDataSize
)
167 FIXME("(%p %d %p %p %p %p %d %p %p): stub\n", inputBitmaps
, numInputs
, effect
, roi
, outputRect
, outputBitmap
, useAuxData
, auxData
, auxDataSize
);
169 * Note: According to Jose Roca's GDI+ docs, this function is not
170 * implemented in Windows's GDI+.
172 return NotImplemented
;
175 static inline void getpixel_1bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
177 *index
= (row
[x
/8]>>(7-x
%8)) & 1;
180 static inline void getpixel_4bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
183 *index
= row
[x
/2]&0xf;
185 *index
= row
[x
/2]>>4;
188 static inline void getpixel_8bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
193 static inline void getpixel_16bppGrayScale(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
194 const BYTE
*row
, UINT x
)
196 *r
= *g
= *b
= row
[x
*2+1];
200 static inline void getpixel_16bppRGB555(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
201 const BYTE
*row
, UINT x
)
203 WORD pixel
= *((const WORD
*)(row
)+x
);
204 *r
= (pixel
>>7&0xf8)|(pixel
>>12&0x7);
205 *g
= (pixel
>>2&0xf8)|(pixel
>>6&0x7);
206 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
210 static inline void getpixel_16bppRGB565(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
211 const BYTE
*row
, UINT x
)
213 WORD pixel
= *((const WORD
*)(row
)+x
);
214 *r
= (pixel
>>8&0xf8)|(pixel
>>13&0x7);
215 *g
= (pixel
>>3&0xfc)|(pixel
>>9&0x3);
216 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
220 static inline void getpixel_16bppARGB1555(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
221 const BYTE
*row
, UINT x
)
223 WORD pixel
= *((const WORD
*)(row
)+x
);
224 *r
= (pixel
>>7&0xf8)|(pixel
>>12&0x7);
225 *g
= (pixel
>>2&0xf8)|(pixel
>>6&0x7);
226 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
227 if ((pixel
&0x8000) == 0x8000)
233 static inline void getpixel_24bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
234 const BYTE
*row
, UINT x
)
242 static inline void getpixel_32bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
243 const BYTE
*row
, UINT x
)
251 static inline void getpixel_32bppARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
252 const BYTE
*row
, UINT x
)
260 static inline void getpixel_32bppPARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
261 const BYTE
*row
, UINT x
)
272 DWORD scaled_q
= (255 << 15) / *a
;
273 *r
= (row
[x
*4+2] > *a
) ? 0xff : (row
[x
*4+2] * scaled_q
) >> 15;
274 *g
= (row
[x
*4+1] > *a
) ? 0xff : (row
[x
*4+1] * scaled_q
) >> 15;
275 *b
= (row
[x
*4] > *a
) ? 0xff : (row
[x
*4] * scaled_q
) >> 15;
279 static inline void getpixel_48bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
280 const BYTE
*row
, UINT x
)
288 static inline void getpixel_64bppARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
289 const BYTE
*row
, UINT x
)
297 static inline void getpixel_64bppPARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
298 const BYTE
*row
, UINT x
)
305 *r
= row
[x
*8+5] * 255 / *a
;
306 *g
= row
[x
*8+3] * 255 / *a
;
307 *b
= row
[x
*8+1] * 255 / *a
;
311 GpStatus WINGDIPAPI
GdipBitmapGetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
318 if(!bitmap
|| !color
||
319 x
< 0 || y
< 0 || x
>= bitmap
->width
|| y
>= bitmap
->height
)
320 return InvalidParameter
;
322 row
= bitmap
->bits
+bitmap
->stride
*y
;
324 switch (bitmap
->format
)
326 case PixelFormat1bppIndexed
:
327 getpixel_1bppIndexed(&index
,row
,x
);
329 case PixelFormat4bppIndexed
:
330 getpixel_4bppIndexed(&index
,row
,x
);
332 case PixelFormat8bppIndexed
:
333 getpixel_8bppIndexed(&index
,row
,x
);
335 case PixelFormat16bppGrayScale
:
336 getpixel_16bppGrayScale(&r
,&g
,&b
,&a
,row
,x
);
338 case PixelFormat16bppRGB555
:
339 getpixel_16bppRGB555(&r
,&g
,&b
,&a
,row
,x
);
341 case PixelFormat16bppRGB565
:
342 getpixel_16bppRGB565(&r
,&g
,&b
,&a
,row
,x
);
344 case PixelFormat16bppARGB1555
:
345 getpixel_16bppARGB1555(&r
,&g
,&b
,&a
,row
,x
);
347 case PixelFormat24bppRGB
:
348 getpixel_24bppRGB(&r
,&g
,&b
,&a
,row
,x
);
350 case PixelFormat32bppRGB
:
351 getpixel_32bppRGB(&r
,&g
,&b
,&a
,row
,x
);
353 case PixelFormat32bppARGB
:
354 getpixel_32bppARGB(&r
,&g
,&b
,&a
,row
,x
);
356 case PixelFormat32bppPARGB
:
357 getpixel_32bppPARGB(&r
,&g
,&b
,&a
,row
,x
);
359 case PixelFormat48bppRGB
:
360 getpixel_48bppRGB(&r
,&g
,&b
,&a
,row
,x
);
362 case PixelFormat64bppARGB
:
363 getpixel_64bppARGB(&r
,&g
,&b
,&a
,row
,x
);
365 case PixelFormat64bppPARGB
:
366 getpixel_64bppPARGB(&r
,&g
,&b
,&a
,row
,x
);
369 FIXME("not implemented for format 0x%x\n", bitmap
->format
);
370 return NotImplemented
;
373 if (bitmap
->format
& PixelFormatIndexed
)
374 *color
= bitmap
->image
.palette
->Entries
[index
];
376 *color
= a
<<24|r
<<16|g
<<8|b
;
381 static unsigned int absdiff(unsigned int x
, unsigned int y
)
383 return x
> y
? x
- y
: y
- x
;
386 static inline UINT
get_palette_index(BYTE r
, BYTE g
, BYTE b
, BYTE a
, ColorPalette
*palette
)
389 int best_distance
= 0x7fff;
393 if (!palette
) return 0;
394 /* This algorithm scans entire palette,
395 computes difference from desired color (all color components have equal weight)
396 and returns the index of color with least difference.
398 Note: Maybe it could be replaced with a better algorithm for better image quality
399 and performance, though better algorithm would probably need some pre-built lookup
400 tables and thus may actually be slower if this method is called only few times per
403 for(i
=0;i
<palette
->Count
;i
++) {
404 ARGB color
=palette
->Entries
[i
];
405 distance
=absdiff(b
, color
& 0xff) + absdiff(g
, color
>>8 & 0xff) + absdiff(r
, color
>>16 & 0xff) + absdiff(a
, color
>>24 & 0xff);
406 if (distance
<best_distance
) {
407 best_distance
=distance
;
414 static inline void setpixel_8bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
415 BYTE
*row
, UINT x
, ColorPalette
*palette
)
417 BYTE index
= get_palette_index(r
,g
,b
,a
,palette
);
421 static inline void setpixel_1bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
422 BYTE
*row
, UINT x
, ColorPalette
*palette
)
424 row
[x
/8] = (row
[x
/8] & ~(1<<(7-x
%8))) | (get_palette_index(r
,g
,b
,a
,palette
)<<(7-x
%8));
427 static inline void setpixel_4bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
428 BYTE
*row
, UINT x
, ColorPalette
*palette
)
431 row
[x
/2] = (row
[x
/2] & 0xf0) | get_palette_index(r
,g
,b
,a
,palette
);
433 row
[x
/2] = (row
[x
/2] & 0x0f) | get_palette_index(r
,g
,b
,a
,palette
)<<4;
436 static inline void setpixel_16bppGrayScale(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
439 *((WORD
*)(row
)+x
) = (r
+g
+b
)*85;
442 static inline void setpixel_16bppRGB555(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
445 *((WORD
*)(row
)+x
) = (r
<<7&0x7c00)|
450 static inline void setpixel_16bppRGB565(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
453 *((WORD
*)(row
)+x
) = (r
<<8&0xf800)|
458 static inline void setpixel_16bppARGB1555(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
461 *((WORD
*)(row
)+x
) = (a
<<8&0x8000)|
467 static inline void setpixel_24bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
475 static inline void setpixel_32bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
478 *((DWORD
*)(row
)+x
) = (r
<<16)|(g
<<8)|b
;
481 static inline void setpixel_32bppARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
484 *((DWORD
*)(row
)+x
) = (a
<<24)|(r
<<16)|(g
<<8)|b
;
487 static inline void setpixel_32bppPARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
490 r
= (r
* a
+ 127) / 255;
491 g
= (g
* a
+ 127) / 255;
492 b
= (b
* a
+ 127) / 255;
493 *((DWORD
*)(row
)+x
) = (a
<<24)|(r
<<16)|(g
<<8)|b
;
496 static inline void setpixel_48bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
499 row
[x
*6+5] = row
[x
*6+4] = r
;
500 row
[x
*6+3] = row
[x
*6+2] = g
;
501 row
[x
*6+1] = row
[x
*6] = b
;
504 static inline void setpixel_64bppARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
507 UINT64 a64
=a
, r64
=r
, g64
=g
, b64
=b
;
508 *((UINT64
*)(row
)+x
) = (a64
<<56)|(a64
<<48)|(r64
<<40)|(r64
<<32)|(g64
<<24)|(g64
<<16)|(b64
<<8)|b64
;
511 static inline void setpixel_64bppPARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
514 UINT64 a64
, r64
, g64
, b64
;
519 *((UINT64
*)(row
)+x
) = (a64
<<48)|(r64
<<32)|(g64
<<16)|b64
;
522 GpStatus WINGDIPAPI
GdipBitmapSetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
528 if(!bitmap
|| x
< 0 || y
< 0 || x
>= bitmap
->width
|| y
>= bitmap
->height
)
529 return InvalidParameter
;
536 row
= bitmap
->bits
+ bitmap
->stride
* y
;
538 switch (bitmap
->format
)
540 case PixelFormat16bppGrayScale
:
541 setpixel_16bppGrayScale(r
,g
,b
,a
,row
,x
);
543 case PixelFormat16bppRGB555
:
544 setpixel_16bppRGB555(r
,g
,b
,a
,row
,x
);
546 case PixelFormat16bppRGB565
:
547 setpixel_16bppRGB565(r
,g
,b
,a
,row
,x
);
549 case PixelFormat16bppARGB1555
:
550 setpixel_16bppARGB1555(r
,g
,b
,a
,row
,x
);
552 case PixelFormat24bppRGB
:
553 setpixel_24bppRGB(r
,g
,b
,a
,row
,x
);
555 case PixelFormat32bppRGB
:
556 setpixel_32bppRGB(r
,g
,b
,a
,row
,x
);
558 case PixelFormat32bppARGB
:
559 setpixel_32bppARGB(r
,g
,b
,a
,row
,x
);
561 case PixelFormat32bppPARGB
:
562 setpixel_32bppPARGB(r
,g
,b
,a
,row
,x
);
564 case PixelFormat48bppRGB
:
565 setpixel_48bppRGB(r
,g
,b
,a
,row
,x
);
567 case PixelFormat64bppARGB
:
568 setpixel_64bppARGB(r
,g
,b
,a
,row
,x
);
570 case PixelFormat64bppPARGB
:
571 setpixel_64bppPARGB(r
,g
,b
,a
,row
,x
);
573 case PixelFormat8bppIndexed
:
574 setpixel_8bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
576 case PixelFormat4bppIndexed
:
577 setpixel_4bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
579 case PixelFormat1bppIndexed
:
580 setpixel_1bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
583 FIXME("not implemented for format 0x%x\n", bitmap
->format
);
584 return NotImplemented
;
590 GpStatus
convert_pixels(INT width
, INT height
,
591 INT dst_stride
, BYTE
*dst_bits
, PixelFormat dst_format
,
592 ColorPalette
*dst_palette
,
593 INT src_stride
, const BYTE
*src_bits
, PixelFormat src_format
,
594 ColorPalette
*src_palette
)
598 if (src_format
== dst_format
||
599 (dst_format
== PixelFormat32bppRGB
&& PIXELFORMATBPP(src_format
) == 32))
601 UINT widthbytes
= PIXELFORMATBPP(src_format
) * width
/ 8;
602 for (y
=0; y
<height
; y
++)
603 memcpy(dst_bits
+dst_stride
*y
, src_bits
+src_stride
*y
, widthbytes
);
607 #define convert_indexed_to_rgb(getpixel_function, setpixel_function) do { \
608 for (y=0; y<height; y++) \
609 for (x=0; x<width; x++) { \
612 BYTE *color = (BYTE *)&argb; \
613 getpixel_function(&index, src_bits+src_stride*y, x); \
614 argb = (src_palette && index < src_palette->Count) ? src_palette->Entries[index] : 0; \
615 setpixel_function(color[2], color[1], color[0], color[3], dst_bits+dst_stride*y, x); \
620 #define convert_indexed_to_indexed(getpixel_function, setpixel_function) do { \
621 for (y=0; y<height; y++) \
622 for (x=0; x<width; x++) { \
625 BYTE *color = (BYTE *)&argb; \
626 getpixel_function(&index, src_bits+src_stride*y, x); \
627 argb = (src_palette && index < src_palette->Count) ? src_palette->Entries[index] : 0; \
628 setpixel_function(color[2], color[1], color[0], color[3], dst_bits+dst_stride*y, x, dst_palette); \
633 #define convert_rgb_to_rgb(getpixel_function, setpixel_function) do { \
634 for (y=0; y<height; y++) \
635 for (x=0; x<width; x++) { \
637 getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
638 setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x); \
643 #define convert_rgb_to_indexed(getpixel_function, setpixel_function) do { \
644 for (y=0; y<height; y++) \
645 for (x=0; x<width; x++) { \
647 getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
648 setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x, dst_palette); \
655 case PixelFormat1bppIndexed
:
658 case PixelFormat4bppIndexed
:
659 convert_indexed_to_indexed(getpixel_1bppIndexed
, setpixel_4bppIndexed
);
660 case PixelFormat8bppIndexed
:
661 convert_indexed_to_indexed(getpixel_1bppIndexed
, setpixel_8bppIndexed
);
662 case PixelFormat16bppGrayScale
:
663 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppGrayScale
);
664 case PixelFormat16bppRGB555
:
665 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppRGB555
);
666 case PixelFormat16bppRGB565
:
667 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppRGB565
);
668 case PixelFormat16bppARGB1555
:
669 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppARGB1555
);
670 case PixelFormat24bppRGB
:
671 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_24bppRGB
);
672 case PixelFormat32bppRGB
:
673 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppRGB
);
674 case PixelFormat32bppARGB
:
675 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppARGB
);
676 case PixelFormat32bppPARGB
:
677 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppPARGB
);
678 case PixelFormat48bppRGB
:
679 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_48bppRGB
);
680 case PixelFormat64bppARGB
:
681 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_64bppARGB
);
686 case PixelFormat4bppIndexed
:
689 case PixelFormat1bppIndexed
:
690 convert_indexed_to_indexed(getpixel_4bppIndexed
, setpixel_1bppIndexed
);
691 case PixelFormat8bppIndexed
:
692 convert_indexed_to_indexed(getpixel_4bppIndexed
, setpixel_8bppIndexed
);
693 case PixelFormat16bppGrayScale
:
694 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppGrayScale
);
695 case PixelFormat16bppRGB555
:
696 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppRGB555
);
697 case PixelFormat16bppRGB565
:
698 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppRGB565
);
699 case PixelFormat16bppARGB1555
:
700 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppARGB1555
);
701 case PixelFormat24bppRGB
:
702 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_24bppRGB
);
703 case PixelFormat32bppRGB
:
704 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppRGB
);
705 case PixelFormat32bppARGB
:
706 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppARGB
);
707 case PixelFormat32bppPARGB
:
708 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppPARGB
);
709 case PixelFormat48bppRGB
:
710 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_48bppRGB
);
711 case PixelFormat64bppARGB
:
712 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_64bppARGB
);
717 case PixelFormat8bppIndexed
:
720 case PixelFormat1bppIndexed
:
721 convert_indexed_to_indexed(getpixel_8bppIndexed
, setpixel_1bppIndexed
);
722 case PixelFormat4bppIndexed
:
723 convert_indexed_to_indexed(getpixel_8bppIndexed
, setpixel_4bppIndexed
);
724 case PixelFormat16bppGrayScale
:
725 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppGrayScale
);
726 case PixelFormat16bppRGB555
:
727 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppRGB555
);
728 case PixelFormat16bppRGB565
:
729 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppRGB565
);
730 case PixelFormat16bppARGB1555
:
731 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppARGB1555
);
732 case PixelFormat24bppRGB
:
733 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_24bppRGB
);
734 case PixelFormat32bppRGB
:
735 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppRGB
);
736 case PixelFormat32bppARGB
:
737 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppARGB
);
738 case PixelFormat32bppPARGB
:
739 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppPARGB
);
740 case PixelFormat48bppRGB
:
741 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_48bppRGB
);
742 case PixelFormat64bppARGB
:
743 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_64bppARGB
);
748 case PixelFormat16bppGrayScale
:
751 case PixelFormat1bppIndexed
:
752 convert_rgb_to_indexed(getpixel_16bppGrayScale
, setpixel_1bppIndexed
);
753 case PixelFormat4bppIndexed
:
754 convert_rgb_to_indexed(getpixel_16bppGrayScale
, setpixel_4bppIndexed
);
755 case PixelFormat8bppIndexed
:
756 convert_rgb_to_indexed(getpixel_16bppGrayScale
, setpixel_8bppIndexed
);
757 case PixelFormat16bppRGB555
:
758 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppRGB555
);
759 case PixelFormat16bppRGB565
:
760 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppRGB565
);
761 case PixelFormat16bppARGB1555
:
762 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppARGB1555
);
763 case PixelFormat24bppRGB
:
764 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_24bppRGB
);
765 case PixelFormat32bppRGB
:
766 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppRGB
);
767 case PixelFormat32bppARGB
:
768 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppARGB
);
769 case PixelFormat32bppPARGB
:
770 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppPARGB
);
771 case PixelFormat48bppRGB
:
772 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_48bppRGB
);
773 case PixelFormat64bppARGB
:
774 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_64bppARGB
);
779 case PixelFormat16bppRGB555
:
782 case PixelFormat1bppIndexed
:
783 convert_rgb_to_indexed(getpixel_16bppRGB555
, setpixel_1bppIndexed
);
784 case PixelFormat4bppIndexed
:
785 convert_rgb_to_indexed(getpixel_16bppRGB555
, setpixel_4bppIndexed
);
786 case PixelFormat8bppIndexed
:
787 convert_rgb_to_indexed(getpixel_16bppRGB555
, setpixel_8bppIndexed
);
788 case PixelFormat16bppGrayScale
:
789 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppGrayScale
);
790 case PixelFormat16bppRGB565
:
791 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppRGB565
);
792 case PixelFormat16bppARGB1555
:
793 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppARGB1555
);
794 case PixelFormat24bppRGB
:
795 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_24bppRGB
);
796 case PixelFormat32bppRGB
:
797 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppRGB
);
798 case PixelFormat32bppARGB
:
799 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppARGB
);
800 case PixelFormat32bppPARGB
:
801 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppPARGB
);
802 case PixelFormat48bppRGB
:
803 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_48bppRGB
);
804 case PixelFormat64bppARGB
:
805 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_64bppARGB
);
810 case PixelFormat16bppRGB565
:
813 case PixelFormat1bppIndexed
:
814 convert_rgb_to_indexed(getpixel_16bppRGB565
, setpixel_1bppIndexed
);
815 case PixelFormat4bppIndexed
:
816 convert_rgb_to_indexed(getpixel_16bppRGB565
, setpixel_4bppIndexed
);
817 case PixelFormat8bppIndexed
:
818 convert_rgb_to_indexed(getpixel_16bppRGB565
, setpixel_8bppIndexed
);
819 case PixelFormat16bppGrayScale
:
820 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppGrayScale
);
821 case PixelFormat16bppRGB555
:
822 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppRGB555
);
823 case PixelFormat16bppARGB1555
:
824 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppARGB1555
);
825 case PixelFormat24bppRGB
:
826 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_24bppRGB
);
827 case PixelFormat32bppRGB
:
828 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppRGB
);
829 case PixelFormat32bppARGB
:
830 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppARGB
);
831 case PixelFormat32bppPARGB
:
832 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppPARGB
);
833 case PixelFormat48bppRGB
:
834 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_48bppRGB
);
835 case PixelFormat64bppARGB
:
836 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_64bppARGB
);
841 case PixelFormat16bppARGB1555
:
844 case PixelFormat1bppIndexed
:
845 convert_rgb_to_indexed(getpixel_16bppARGB1555
, setpixel_1bppIndexed
);
846 case PixelFormat4bppIndexed
:
847 convert_rgb_to_indexed(getpixel_16bppARGB1555
, setpixel_4bppIndexed
);
848 case PixelFormat8bppIndexed
:
849 convert_rgb_to_indexed(getpixel_16bppARGB1555
, setpixel_8bppIndexed
);
850 case PixelFormat16bppGrayScale
:
851 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppGrayScale
);
852 case PixelFormat16bppRGB555
:
853 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppRGB555
);
854 case PixelFormat16bppRGB565
:
855 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppRGB565
);
856 case PixelFormat24bppRGB
:
857 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_24bppRGB
);
858 case PixelFormat32bppRGB
:
859 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppRGB
);
860 case PixelFormat32bppARGB
:
861 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppARGB
);
862 case PixelFormat32bppPARGB
:
863 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppPARGB
);
864 case PixelFormat48bppRGB
:
865 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_48bppRGB
);
866 case PixelFormat64bppARGB
:
867 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_64bppARGB
);
872 case PixelFormat24bppRGB
:
875 case PixelFormat1bppIndexed
:
876 convert_rgb_to_indexed(getpixel_24bppRGB
, setpixel_1bppIndexed
);
877 case PixelFormat4bppIndexed
:
878 convert_rgb_to_indexed(getpixel_24bppRGB
, setpixel_4bppIndexed
);
879 case PixelFormat8bppIndexed
:
880 convert_rgb_to_indexed(getpixel_24bppRGB
, setpixel_8bppIndexed
);
881 case PixelFormat16bppGrayScale
:
882 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppGrayScale
);
883 case PixelFormat16bppRGB555
:
884 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppRGB555
);
885 case PixelFormat16bppRGB565
:
886 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppRGB565
);
887 case PixelFormat16bppARGB1555
:
888 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppARGB1555
);
889 case PixelFormat32bppRGB
:
890 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppRGB
);
891 case PixelFormat32bppARGB
:
892 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppARGB
);
893 case PixelFormat32bppPARGB
:
894 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppPARGB
);
895 case PixelFormat48bppRGB
:
896 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_48bppRGB
);
897 case PixelFormat64bppARGB
:
898 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_64bppARGB
);
903 case PixelFormat32bppRGB
:
906 case PixelFormat1bppIndexed
:
907 convert_rgb_to_indexed(getpixel_32bppRGB
, setpixel_1bppIndexed
);
908 case PixelFormat4bppIndexed
:
909 convert_rgb_to_indexed(getpixel_32bppRGB
, setpixel_4bppIndexed
);
910 case PixelFormat8bppIndexed
:
911 convert_rgb_to_indexed(getpixel_32bppRGB
, setpixel_8bppIndexed
);
912 case PixelFormat16bppGrayScale
:
913 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppGrayScale
);
914 case PixelFormat16bppRGB555
:
915 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppRGB555
);
916 case PixelFormat16bppRGB565
:
917 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppRGB565
);
918 case PixelFormat16bppARGB1555
:
919 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppARGB1555
);
920 case PixelFormat24bppRGB
:
921 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_24bppRGB
);
922 case PixelFormat32bppARGB
:
923 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_32bppARGB
);
924 case PixelFormat32bppPARGB
:
925 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_32bppPARGB
);
926 case PixelFormat48bppRGB
:
927 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_48bppRGB
);
928 case PixelFormat64bppARGB
:
929 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_64bppARGB
);
934 case PixelFormat32bppARGB
:
937 case PixelFormat1bppIndexed
:
938 convert_rgb_to_indexed(getpixel_32bppARGB
, setpixel_1bppIndexed
);
939 case PixelFormat4bppIndexed
:
940 convert_rgb_to_indexed(getpixel_32bppARGB
, setpixel_4bppIndexed
);
941 case PixelFormat8bppIndexed
:
942 convert_rgb_to_indexed(getpixel_32bppARGB
, setpixel_8bppIndexed
);
943 case PixelFormat16bppGrayScale
:
944 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppGrayScale
);
945 case PixelFormat16bppRGB555
:
946 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppRGB555
);
947 case PixelFormat16bppRGB565
:
948 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppRGB565
);
949 case PixelFormat16bppARGB1555
:
950 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppARGB1555
);
951 case PixelFormat24bppRGB
:
952 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_24bppRGB
);
953 case PixelFormat32bppPARGB
:
954 convert_32bppARGB_to_32bppPARGB(width
, height
, dst_bits
, dst_stride
, src_bits
, src_stride
);
956 case PixelFormat48bppRGB
:
957 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_48bppRGB
);
958 case PixelFormat64bppARGB
:
959 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_64bppARGB
);
964 case PixelFormat32bppPARGB
:
967 case PixelFormat1bppIndexed
:
968 convert_rgb_to_indexed(getpixel_32bppPARGB
, setpixel_1bppIndexed
);
969 case PixelFormat4bppIndexed
:
970 convert_rgb_to_indexed(getpixel_32bppPARGB
, setpixel_4bppIndexed
);
971 case PixelFormat8bppIndexed
:
972 convert_rgb_to_indexed(getpixel_32bppPARGB
, setpixel_8bppIndexed
);
973 case PixelFormat16bppGrayScale
:
974 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppGrayScale
);
975 case PixelFormat16bppRGB555
:
976 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppRGB555
);
977 case PixelFormat16bppRGB565
:
978 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppRGB565
);
979 case PixelFormat16bppARGB1555
:
980 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppARGB1555
);
981 case PixelFormat24bppRGB
:
982 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_24bppRGB
);
983 case PixelFormat32bppRGB
:
984 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_32bppRGB
);
985 case PixelFormat32bppARGB
:
986 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_32bppARGB
);
987 case PixelFormat48bppRGB
:
988 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_48bppRGB
);
989 case PixelFormat64bppARGB
:
990 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_64bppARGB
);
995 case PixelFormat48bppRGB
:
998 case PixelFormat1bppIndexed
:
999 convert_rgb_to_indexed(getpixel_48bppRGB
, setpixel_1bppIndexed
);
1000 case PixelFormat4bppIndexed
:
1001 convert_rgb_to_indexed(getpixel_48bppRGB
, setpixel_4bppIndexed
);
1002 case PixelFormat8bppIndexed
:
1003 convert_rgb_to_indexed(getpixel_48bppRGB
, setpixel_8bppIndexed
);
1004 case PixelFormat16bppGrayScale
:
1005 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppGrayScale
);
1006 case PixelFormat16bppRGB555
:
1007 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppRGB555
);
1008 case PixelFormat16bppRGB565
:
1009 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppRGB565
);
1010 case PixelFormat16bppARGB1555
:
1011 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppARGB1555
);
1012 case PixelFormat24bppRGB
:
1013 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_24bppRGB
);
1014 case PixelFormat32bppRGB
:
1015 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppRGB
);
1016 case PixelFormat32bppARGB
:
1017 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppARGB
);
1018 case PixelFormat32bppPARGB
:
1019 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppPARGB
);
1020 case PixelFormat64bppARGB
:
1021 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_64bppARGB
);
1026 case PixelFormat64bppARGB
:
1029 case PixelFormat1bppIndexed
:
1030 convert_rgb_to_indexed(getpixel_64bppARGB
, setpixel_1bppIndexed
);
1031 case PixelFormat4bppIndexed
:
1032 convert_rgb_to_indexed(getpixel_64bppARGB
, setpixel_4bppIndexed
);
1033 case PixelFormat8bppIndexed
:
1034 convert_rgb_to_indexed(getpixel_64bppARGB
, setpixel_8bppIndexed
);
1035 case PixelFormat16bppGrayScale
:
1036 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppGrayScale
);
1037 case PixelFormat16bppRGB555
:
1038 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppRGB555
);
1039 case PixelFormat16bppRGB565
:
1040 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppRGB565
);
1041 case PixelFormat16bppARGB1555
:
1042 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppARGB1555
);
1043 case PixelFormat24bppRGB
:
1044 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_24bppRGB
);
1045 case PixelFormat32bppRGB
:
1046 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppRGB
);
1047 case PixelFormat32bppARGB
:
1048 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppARGB
);
1049 case PixelFormat32bppPARGB
:
1050 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppPARGB
);
1051 case PixelFormat48bppRGB
:
1052 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_48bppRGB
);
1057 case PixelFormat64bppPARGB
:
1060 case PixelFormat1bppIndexed
:
1061 convert_rgb_to_indexed(getpixel_64bppPARGB
, setpixel_1bppIndexed
);
1062 case PixelFormat4bppIndexed
:
1063 convert_rgb_to_indexed(getpixel_64bppPARGB
, setpixel_4bppIndexed
);
1064 case PixelFormat8bppIndexed
:
1065 convert_rgb_to_indexed(getpixel_64bppPARGB
, setpixel_8bppIndexed
);
1066 case PixelFormat16bppGrayScale
:
1067 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppGrayScale
);
1068 case PixelFormat16bppRGB555
:
1069 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppRGB555
);
1070 case PixelFormat16bppRGB565
:
1071 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppRGB565
);
1072 case PixelFormat16bppARGB1555
:
1073 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppARGB1555
);
1074 case PixelFormat24bppRGB
:
1075 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_24bppRGB
);
1076 case PixelFormat32bppRGB
:
1077 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppRGB
);
1078 case PixelFormat32bppARGB
:
1079 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppARGB
);
1080 case PixelFormat32bppPARGB
:
1081 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppPARGB
);
1082 case PixelFormat48bppRGB
:
1083 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_48bppRGB
);
1084 case PixelFormat64bppARGB
:
1085 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_64bppARGB
);
1094 #undef convert_indexed_to_rgb
1095 #undef convert_indexed_to_indexed
1096 #undef convert_rgb_to_rgb
1097 #undef convert_rgb_to_indexed
1099 return NotImplemented
;
1102 /* This function returns a pointer to an array of pixels that represents the
1103 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
1104 * flags. It is correct behavior that a user who calls this function with write
1105 * privileges can write to the whole bitmap (not just the area in rect).
1107 * FIXME: only used portion of format is bits per pixel. */
1108 GpStatus WINGDIPAPI
GdipBitmapLockBits(GpBitmap
* bitmap
, GDIPCONST GpRect
* rect
,
1109 UINT flags
, PixelFormat format
, BitmapData
* lockeddata
)
1111 INT bitspp
= PIXELFORMATBPP(format
);
1112 GpRect act_rect
; /* actual rect to be used */
1115 TRACE("%p %p %d 0x%x %p\n", bitmap
, rect
, flags
, format
, lockeddata
);
1117 if(!lockeddata
|| !bitmap
)
1118 return InvalidParameter
;
1119 if(!image_lock(&bitmap
->image
))
1123 if(rect
->X
< 0 || rect
->Y
< 0 || (rect
->X
+ rect
->Width
> bitmap
->width
) ||
1124 (rect
->Y
+ rect
->Height
> bitmap
->height
) || !flags
)
1126 image_unlock(&bitmap
->image
);
1127 return InvalidParameter
;
1133 act_rect
.X
= act_rect
.Y
= 0;
1134 act_rect
.Width
= bitmap
->width
;
1135 act_rect
.Height
= bitmap
->height
;
1138 if(bitmap
->lockmode
)
1140 WARN("bitmap is already locked and cannot be locked again\n");
1141 image_unlock(&bitmap
->image
);
1145 if (bitmap
->bits
&& bitmap
->format
== format
&& !(flags
& ImageLockModeUserInputBuf
))
1147 /* no conversion is necessary; just use the bits directly */
1148 lockeddata
->Width
= act_rect
.Width
;
1149 lockeddata
->Height
= act_rect
.Height
;
1150 lockeddata
->PixelFormat
= format
;
1151 lockeddata
->Reserved
= flags
;
1152 lockeddata
->Stride
= bitmap
->stride
;
1153 lockeddata
->Scan0
= bitmap
->bits
+ (bitspp
/ 8) * act_rect
.X
+
1154 bitmap
->stride
* act_rect
.Y
;
1156 bitmap
->lockmode
= flags
| ImageLockModeRead
;
1158 image_unlock(&bitmap
->image
);
1162 /* Make sure we can convert to the requested format. */
1163 if (flags
& ImageLockModeRead
)
1165 stat
= convert_pixels(0, 0, 0, NULL
, format
, NULL
, 0, NULL
, bitmap
->format
, NULL
);
1166 if (stat
== NotImplemented
)
1168 FIXME("cannot read bitmap from %x to %x\n", bitmap
->format
, format
);
1169 image_unlock(&bitmap
->image
);
1170 return NotImplemented
;
1174 /* If we're opening for writing, make sure we'll be able to write back in
1175 * the original format. */
1176 if (flags
& ImageLockModeWrite
)
1178 stat
= convert_pixels(0, 0, 0, NULL
, bitmap
->format
, NULL
, 0, NULL
, format
, NULL
);
1179 if (stat
== NotImplemented
)
1181 FIXME("cannot write bitmap from %x to %x\n", format
, bitmap
->format
);
1182 image_unlock(&bitmap
->image
);
1183 return NotImplemented
;
1187 lockeddata
->Width
= act_rect
.Width
;
1188 lockeddata
->Height
= act_rect
.Height
;
1189 lockeddata
->PixelFormat
= format
;
1190 lockeddata
->Reserved
= flags
;
1192 if(!(flags
& ImageLockModeUserInputBuf
))
1194 lockeddata
->Stride
= (((act_rect
.Width
* bitspp
+ 7) / 8) + 3) & ~3;
1196 bitmap
->bitmapbits
= heap_alloc_zero(lockeddata
->Stride
* act_rect
.Height
);
1198 if (!bitmap
->bitmapbits
)
1200 image_unlock(&bitmap
->image
);
1204 lockeddata
->Scan0
= bitmap
->bitmapbits
;
1207 if (flags
& ImageLockModeRead
)
1209 static BOOL fixme
= FALSE
;
1211 if (!fixme
&& (PIXELFORMATBPP(bitmap
->format
) * act_rect
.X
) % 8 != 0)
1213 FIXME("Cannot copy rows that don't start at a whole byte.\n");
1217 stat
= convert_pixels(act_rect
.Width
, act_rect
.Height
,
1218 lockeddata
->Stride
, lockeddata
->Scan0
, format
, bitmap
->image
.palette
,
1220 bitmap
->bits
+ bitmap
->stride
* act_rect
.Y
+ PIXELFORMATBPP(bitmap
->format
) * act_rect
.X
/ 8,
1221 bitmap
->format
, bitmap
->image
.palette
);
1225 heap_free(bitmap
->bitmapbits
);
1226 bitmap
->bitmapbits
= NULL
;
1227 image_unlock(&bitmap
->image
);
1232 bitmap
->lockmode
= flags
| ImageLockModeRead
;
1233 bitmap
->lockx
= act_rect
.X
;
1234 bitmap
->locky
= act_rect
.Y
;
1236 image_unlock(&bitmap
->image
);
1240 GpStatus WINGDIPAPI
GdipBitmapSetResolution(GpBitmap
* bitmap
, REAL xdpi
, REAL ydpi
)
1242 TRACE("(%p, %.2f, %.2f)\n", bitmap
, xdpi
, ydpi
);
1244 if (!bitmap
|| xdpi
== 0.0 || ydpi
== 0.0)
1245 return InvalidParameter
;
1247 bitmap
->image
.xres
= xdpi
;
1248 bitmap
->image
.yres
= ydpi
;
1253 GpStatus WINGDIPAPI
GdipBitmapUnlockBits(GpBitmap
* bitmap
,
1254 BitmapData
* lockeddata
)
1257 static BOOL fixme
= FALSE
;
1259 TRACE("(%p,%p)\n", bitmap
, lockeddata
);
1261 if(!bitmap
|| !lockeddata
)
1262 return InvalidParameter
;
1263 if(!image_lock(&bitmap
->image
))
1266 if(!bitmap
->lockmode
)
1268 image_unlock(&bitmap
->image
);
1272 if(!(lockeddata
->Reserved
& ImageLockModeWrite
)){
1273 bitmap
->lockmode
= 0;
1274 heap_free(bitmap
->bitmapbits
);
1275 bitmap
->bitmapbits
= NULL
;
1276 image_unlock(&bitmap
->image
);
1280 if (!bitmap
->bitmapbits
&& !(lockeddata
->Reserved
& ImageLockModeUserInputBuf
))
1282 /* we passed a direct reference; no need to do anything */
1283 bitmap
->lockmode
= 0;
1284 image_unlock(&bitmap
->image
);
1288 if (!fixme
&& (PIXELFORMATBPP(bitmap
->format
) * bitmap
->lockx
) % 8 != 0)
1290 FIXME("Cannot copy rows that don't start at a whole byte.\n");
1294 /* FIXME: Pass src_palette generated from lockeddata->PixelFormat. */
1295 stat
= convert_pixels(lockeddata
->Width
, lockeddata
->Height
,
1297 bitmap
->bits
+ bitmap
->stride
* bitmap
->locky
+ PIXELFORMATBPP(bitmap
->format
) * bitmap
->lockx
/ 8,
1298 bitmap
->format
, bitmap
->image
.palette
,
1299 lockeddata
->Stride
, lockeddata
->Scan0
, lockeddata
->PixelFormat
, NULL
);
1303 ERR("failed to convert pixels; this should never happen\n");
1306 heap_free(bitmap
->bitmapbits
);
1307 bitmap
->bitmapbits
= NULL
;
1308 bitmap
->lockmode
= 0;
1310 image_unlock(&bitmap
->image
);
1314 GpStatus WINGDIPAPI
GdipCloneBitmapArea(REAL x
, REAL y
, REAL width
, REAL height
,
1315 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
1320 TRACE("(%f,%f,%f,%f,0x%x,%p,%p)\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1322 if (!srcBitmap
|| !dstBitmap
|| srcBitmap
->image
.type
!= ImageTypeBitmap
||
1324 x
+ width
> srcBitmap
->width
|| y
+ height
> srcBitmap
->height
)
1326 TRACE("<-- InvalidParameter\n");
1327 return InvalidParameter
;
1330 if (format
== PixelFormatDontCare
)
1331 format
= srcBitmap
->format
;
1333 area
.X
= gdip_round(x
);
1334 area
.Y
= gdip_round(y
);
1335 area
.Width
= gdip_round(width
);
1336 area
.Height
= gdip_round(height
);
1338 stat
= GdipCreateBitmapFromScan0(area
.Width
, area
.Height
, 0, format
, NULL
, dstBitmap
);
1341 stat
= convert_pixels(area
.Width
, area
.Height
, (*dstBitmap
)->stride
, (*dstBitmap
)->bits
, (*dstBitmap
)->format
,
1342 (*dstBitmap
)->image
.palette
, srcBitmap
->stride
,
1343 srcBitmap
->bits
+ srcBitmap
->stride
* area
.Y
+ PIXELFORMATBPP(srcBitmap
->format
) * area
.X
/ 8,
1344 srcBitmap
->format
, srcBitmap
->image
.palette
);
1346 if (stat
== Ok
&& srcBitmap
->image
.palette
)
1348 ColorPalette
*src_palette
, *dst_palette
;
1350 src_palette
= srcBitmap
->image
.palette
;
1352 dst_palette
= heap_alloc_zero(sizeof(UINT
) * 2 + sizeof(ARGB
) * src_palette
->Count
);
1356 dst_palette
->Flags
= src_palette
->Flags
;
1357 dst_palette
->Count
= src_palette
->Count
;
1358 memcpy(dst_palette
->Entries
, src_palette
->Entries
, sizeof(ARGB
) * src_palette
->Count
);
1360 heap_free((*dstBitmap
)->image
.palette
);
1361 (*dstBitmap
)->image
.palette
= dst_palette
;
1368 GdipDisposeImage(&(*dstBitmap
)->image
);
1377 GpStatus WINGDIPAPI
GdipCloneBitmapAreaI(INT x
, INT y
, INT width
, INT height
,
1378 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
1380 TRACE("(%i,%i,%i,%i,0x%x,%p,%p)\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1382 return GdipCloneBitmapArea(x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1385 GpStatus WINGDIPAPI
GdipCloneImage(GpImage
*image
, GpImage
**cloneImage
)
1387 TRACE("%p, %p\n", image
, cloneImage
);
1389 if (!image
|| !cloneImage
)
1390 return InvalidParameter
;
1392 if (image
->type
== ImageTypeBitmap
)
1394 GpBitmap
*bitmap
= (GpBitmap
*)image
;
1396 return GdipCloneBitmapAreaI(0, 0, bitmap
->width
, bitmap
->height
,
1397 bitmap
->format
, bitmap
, (GpBitmap
**)cloneImage
);
1399 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
1401 GpMetafile
*result
, *metafile
;
1403 metafile
= (GpMetafile
*)image
;
1405 result
= heap_alloc_zero(sizeof(*result
));
1409 result
->image
.type
= ImageTypeMetafile
;
1410 result
->image
.format
= image
->format
;
1411 result
->image
.flags
= image
->flags
;
1412 result
->image
.frame_count
= 1;
1413 result
->image
.xres
= image
->xres
;
1414 result
->image
.yres
= image
->yres
;
1415 result
->bounds
= metafile
->bounds
;
1416 result
->unit
= metafile
->unit
;
1417 result
->metafile_type
= metafile
->metafile_type
;
1418 result
->hemf
= CopyEnhMetaFileW(metafile
->hemf
, NULL
);
1419 list_init(&result
->containers
);
1427 *cloneImage
= &result
->image
;
1432 WARN("GpImage with no image data (metafile in wrong state?)\n");
1433 return InvalidParameter
;
1437 GpStatus WINGDIPAPI
GdipCreateBitmapFromFile(GDIPCONST WCHAR
* filename
,
1443 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
1445 if(!filename
|| !bitmap
)
1446 return InvalidParameter
;
1450 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
1455 stat
= GdipCreateBitmapFromStream(stream
, bitmap
);
1457 IStream_Release(stream
);
1462 GpStatus WINGDIPAPI
GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO
* info
,
1463 VOID
*bits
, GpBitmap
**bitmap
)
1465 DWORD height
, stride
;
1470 TRACE("(%p, %p, %p)\n", info
, bits
, bitmap
);
1472 if (!info
|| !bits
|| !bitmap
)
1473 return InvalidParameter
;
1475 hbm
= CreateDIBSection(0, info
, DIB_RGB_COLORS
, &bmbits
, NULL
, 0);
1477 return InvalidParameter
;
1479 height
= abs(info
->bmiHeader
.biHeight
);
1480 stride
= ((info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
+ 31) >> 3) & ~3;
1481 TRACE("height %lu, stride %lu, image size %lu\n", height
, stride
, height
* stride
);
1483 memcpy(bmbits
, bits
, height
* stride
);
1485 status
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, bitmap
);
1492 GpStatus WINGDIPAPI
GdipCreateBitmapFromFileICM(GDIPCONST WCHAR
* filename
,
1495 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
1497 return GdipCreateBitmapFromFile(filename
, bitmap
);
1500 GpStatus WINGDIPAPI
GdipCreateBitmapFromResource(HINSTANCE hInstance
,
1501 GDIPCONST WCHAR
* lpBitmapName
, GpBitmap
** bitmap
)
1504 GpStatus stat
= InvalidParameter
;
1506 TRACE("%p (%s) %p\n", hInstance
, debugstr_w(lpBitmapName
), bitmap
);
1508 if(!lpBitmapName
|| !bitmap
)
1509 return InvalidParameter
;
1512 hbm
= LoadImageW(hInstance
, lpBitmapName
, IMAGE_BITMAP
, 0, 0,
1513 LR_CREATEDIBSECTION
);
1516 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, bitmap
);
1523 static inline DWORD
blend_argb_no_bkgnd_alpha(DWORD src
, DWORD bkgnd
)
1526 BYTE g
= (BYTE
)(src
>> 8);
1527 BYTE r
= (BYTE
)(src
>> 16);
1528 DWORD alpha
= (BYTE
)(src
>> 24);
1529 return ((b
+ ((BYTE
)bkgnd
* (255 - alpha
) + 127) / 255) |
1530 (g
+ ((BYTE
)(bkgnd
>> 8) * (255 - alpha
) + 127) / 255) << 8 |
1531 (r
+ ((BYTE
)(bkgnd
>> 16) * (255 - alpha
) + 127) / 255) << 16 |
1535 GpStatus WINGDIPAPI
GdipCreateHBITMAPFromBitmap(GpBitmap
* bitmap
,
1536 HBITMAP
* hbmReturn
, ARGB background
)
1541 BITMAPINFOHEADER bih
;
1544 TRACE("(%p,%p,%lx)\n", bitmap
, hbmReturn
, background
);
1546 if (!bitmap
|| !hbmReturn
) return InvalidParameter
;
1547 if (!image_lock(&bitmap
->image
)) return ObjectBusy
;
1549 GdipGetImageWidth(&bitmap
->image
, &width
);
1550 GdipGetImageHeight(&bitmap
->image
, &height
);
1552 bih
.biSize
= sizeof(bih
);
1553 bih
.biWidth
= width
;
1554 bih
.biHeight
= height
;
1556 bih
.biBitCount
= 32;
1557 bih
.biCompression
= BI_RGB
;
1558 bih
.biSizeImage
= 0;
1559 bih
.biXPelsPerMeter
= 0;
1560 bih
.biYPelsPerMeter
= 0;
1562 bih
.biClrImportant
= 0;
1564 result
= CreateDIBSection(0, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1567 image_unlock(&bitmap
->image
);
1568 return GenericError
;
1571 stat
= convert_pixels(width
, height
, -width
*4,
1572 bits
+ (width
* 4 * (height
- 1)), PixelFormat32bppPARGB
, bitmap
->image
.palette
,
1573 bitmap
->stride
, bitmap
->bits
, bitmap
->format
, bitmap
->image
.palette
);
1576 DeleteObject(result
);
1577 image_unlock(&bitmap
->image
);
1581 if (background
& 0xffffff)
1585 for (ptr
= (DWORD
*)bits
, i
= 0; i
< width
* height
; ptr
++, i
++)
1587 if ((*ptr
& 0xff000000) == 0xff000000) continue;
1588 *ptr
= blend_argb_no_bkgnd_alpha(*ptr
, background
);
1592 *hbmReturn
= result
;
1593 image_unlock(&bitmap
->image
);
1597 GpStatus WINGDIPAPI
GdipCreateBitmapFromGraphics(INT width
, INT height
,
1598 GpGraphics
* target
, GpBitmap
** bitmap
)
1602 TRACE("(%d, %d, %p, %p)\n", width
, height
, target
, bitmap
);
1604 if(!target
|| !bitmap
)
1605 return InvalidParameter
;
1607 ret
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat32bppPARGB
,
1612 GdipGetDpiX(target
, &(*bitmap
)->image
.xres
);
1613 GdipGetDpiY(target
, &(*bitmap
)->image
.yres
);
1619 GpStatus WINGDIPAPI
GdipCreateBitmapFromHICON(HICON hicon
, GpBitmap
** bitmap
)
1625 UINT width
, height
, stride
;
1627 BitmapData lockeddata
;
1630 BITMAPINFOHEADER bih
;
1635 int mask_scanlines
= 0, color_scanlines
= 0;
1637 TRACE("%p, %p\n", hicon
, bitmap
);
1639 if(!bitmap
|| !GetIconInfo(hicon
, &iinfo
) || !iinfo
.hbmColor
|| !iinfo
.fIcon
)
1640 return InvalidParameter
;
1642 /* get the size of the icon */
1643 ret
= GetObjectA(iinfo
.hbmColor
, sizeof(bm
), &bm
);
1645 DeleteObject(iinfo
.hbmColor
);
1646 DeleteObject(iinfo
.hbmMask
);
1647 return GenericError
;
1651 height
= abs(bm
.bmHeight
);
1654 stat
= GdipCreateBitmapFromScan0(width
, height
, stride
, PixelFormat32bppARGB
, NULL
, bitmap
);
1656 DeleteObject(iinfo
.hbmColor
);
1657 DeleteObject(iinfo
.hbmMask
);
1664 rect
.Height
= height
;
1666 stat
= GdipBitmapLockBits(*bitmap
, &rect
, ImageLockModeWrite
, PixelFormat32bppARGB
, &lockeddata
);
1668 DeleteObject(iinfo
.hbmColor
);
1669 DeleteObject(iinfo
.hbmMask
);
1670 GdipDisposeImage(&(*bitmap
)->image
);
1674 bih
.biSize
= sizeof(bih
);
1675 bih
.biWidth
= width
;
1676 bih
.biHeight
= -height
;
1678 bih
.biBitCount
= 32;
1679 bih
.biCompression
= BI_RGB
;
1680 bih
.biSizeImage
= 0;
1681 bih
.biXPelsPerMeter
= 0;
1682 bih
.biYPelsPerMeter
= 0;
1684 bih
.biClrImportant
= 0;
1686 bits
= heap_alloc(height
* stride
);
1689 DeleteObject(iinfo
.hbmColor
);
1690 DeleteObject(iinfo
.hbmMask
);
1691 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
1692 GdipDisposeImage(&(*bitmap
)->image
);
1696 screendc
= CreateCompatibleDC(0);
1699 color_scanlines
= GetDIBits(screendc
, iinfo
.hbmColor
, 0, height
, lockeddata
.Scan0
,
1700 (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1701 mask_scanlines
= GetDIBits(screendc
, iinfo
.hbmMask
, 0, height
, bits
,
1702 (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1706 DeleteObject(iinfo
.hbmColor
);
1707 DeleteObject(iinfo
.hbmMask
);
1709 if (!screendc
|| ((color_scanlines
== 0 || mask_scanlines
== 0) &&
1710 GetLastError() == ERROR_INVALID_PARAMETER
))
1713 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
1714 GdipDisposeImage(&(*bitmap
)->image
);
1715 return GenericError
;
1719 dst_row
= lockeddata
.Scan0
;
1720 for (y
=0; y
<height
; y
++)
1722 dst
= (DWORD
*)dst_row
;
1723 for (x
=0; x
<width
; x
++)
1725 DWORD src_value
= *src
++;
1729 *dst
++ |= 0xff000000;
1731 dst_row
+= lockeddata
.Stride
;
1736 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
1741 static void generate_halftone_palette(ARGB
*entries
, UINT count
)
1743 static const BYTE halftone_values
[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1746 for (i
=0; i
<8 && i
<count
; i
++)
1748 entries
[i
] = 0xff000000;
1749 if (i
&1) entries
[i
] |= 0x800000;
1750 if (i
&2) entries
[i
] |= 0x8000;
1751 if (i
&4) entries
[i
] |= 0x80;
1755 entries
[i
] = 0xffc0c0c0;
1757 for (i
=9; i
<16 && i
<count
; i
++)
1759 entries
[i
] = 0xff000000;
1760 if (i
&1) entries
[i
] |= 0xff0000;
1761 if (i
&2) entries
[i
] |= 0xff00;
1762 if (i
&4) entries
[i
] |= 0xff;
1765 for (i
=16; i
<40 && i
<count
; i
++)
1770 for (i
=40; i
<256 && i
<count
; i
++)
1772 entries
[i
] = 0xff000000;
1773 entries
[i
] |= halftone_values
[(i
-40)%6];
1774 entries
[i
] |= halftone_values
[((i
-40)/6)%6] << 8;
1775 entries
[i
] |= halftone_values
[((i
-40)/36)%6] << 16;
1779 static GpStatus
get_screen_resolution(REAL
*xres
, REAL
*yres
)
1781 HDC screendc
= CreateCompatibleDC(0);
1783 if (!screendc
) return GenericError
;
1785 *xres
= (REAL
)GetDeviceCaps(screendc
, LOGPIXELSX
);
1786 *yres
= (REAL
)GetDeviceCaps(screendc
, LOGPIXELSY
);
1793 GpStatus WINGDIPAPI
GdipCreateBitmapFromScan0(INT width
, INT height
, INT stride
,
1794 PixelFormat format
, BYTE
* scan0
, GpBitmap
** bitmap
)
1796 HBITMAP hbitmap
=NULL
;
1797 INT row_size
, dib_stride
;
1798 BYTE
*bits
=NULL
, *own_bits
=NULL
;
1802 TRACE("%d %d %d 0x%x %p %p\n", width
, height
, stride
, format
, scan0
, bitmap
);
1804 if (!bitmap
) return InvalidParameter
;
1806 if(width
<= 0 || height
<= 0 || (scan0
&& (stride
% 4))){
1808 return InvalidParameter
;
1811 if(scan0
&& !stride
)
1812 return InvalidParameter
;
1814 stat
= get_screen_resolution(&xres
, &yres
);
1815 if (stat
!= Ok
) return stat
;
1817 row_size
= (width
* PIXELFORMATBPP(format
)+7) / 8;
1818 dib_stride
= (row_size
+ 3) & ~3;
1821 stride
= dib_stride
;
1823 if (format
& PixelFormatGDI
&& !(format
& (PixelFormatAlpha
|PixelFormatIndexed
)) && !scan0
)
1825 char bmibuf
[FIELD_OFFSET(BITMAPINFO
, bmiColors
[256])];
1826 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
1828 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1829 pbmi
->bmiHeader
.biWidth
= width
;
1830 pbmi
->bmiHeader
.biHeight
= -height
;
1831 pbmi
->bmiHeader
.biPlanes
= 1;
1832 /* FIXME: use the rest of the data from format */
1833 pbmi
->bmiHeader
.biBitCount
= PIXELFORMATBPP(format
);
1834 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
1835 pbmi
->bmiHeader
.biSizeImage
= 0;
1836 pbmi
->bmiHeader
.biXPelsPerMeter
= 0;
1837 pbmi
->bmiHeader
.biYPelsPerMeter
= 0;
1838 pbmi
->bmiHeader
.biClrUsed
= 0;
1839 pbmi
->bmiHeader
.biClrImportant
= 0;
1841 hbitmap
= CreateDIBSection(0, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1843 if (!hbitmap
) return GenericError
;
1845 stride
= dib_stride
;
1849 /* Not a GDI format; don't try to make an HBITMAP. */
1854 INT size
= abs(stride
) * height
;
1856 own_bits
= bits
= heap_alloc_zero(size
);
1857 if (!own_bits
) return OutOfMemory
;
1860 bits
+= stride
* (1 - height
);
1864 *bitmap
= heap_alloc_zero(sizeof(GpBitmap
));
1867 DeleteObject(hbitmap
);
1868 heap_free(own_bits
);
1872 (*bitmap
)->image
.type
= ImageTypeBitmap
;
1873 memcpy(&(*bitmap
)->image
.format
, &ImageFormatMemoryBMP
, sizeof(GUID
));
1874 (*bitmap
)->image
.flags
= ImageFlagsNone
;
1875 (*bitmap
)->image
.frame_count
= 1;
1876 (*bitmap
)->image
.current_frame
= 0;
1877 (*bitmap
)->image
.palette
= NULL
;
1878 (*bitmap
)->image
.xres
= xres
;
1879 (*bitmap
)->image
.yres
= yres
;
1880 (*bitmap
)->width
= width
;
1881 (*bitmap
)->height
= height
;
1882 (*bitmap
)->format
= format
;
1883 (*bitmap
)->image
.decoder
= NULL
;
1884 (*bitmap
)->image
.encoder
= NULL
;
1885 (*bitmap
)->hbitmap
= hbitmap
;
1886 (*bitmap
)->hdc
= NULL
;
1887 (*bitmap
)->bits
= bits
;
1888 (*bitmap
)->stride
= stride
;
1889 (*bitmap
)->own_bits
= own_bits
;
1890 (*bitmap
)->metadata_reader
= NULL
;
1891 (*bitmap
)->prop_count
= 0;
1892 (*bitmap
)->prop_item
= NULL
;
1894 /* set format-related flags */
1895 if (format
& (PixelFormatAlpha
|PixelFormatPAlpha
|PixelFormatIndexed
))
1896 (*bitmap
)->image
.flags
|= ImageFlagsHasAlpha
;
1898 if (format
== PixelFormat1bppIndexed
||
1899 format
== PixelFormat4bppIndexed
||
1900 format
== PixelFormat8bppIndexed
)
1902 (*bitmap
)->image
.palette
= heap_alloc_zero(sizeof(UINT
) * 2 + sizeof(ARGB
) * (1 << PIXELFORMATBPP(format
)));
1904 if (!(*bitmap
)->image
.palette
)
1906 GdipDisposeImage(&(*bitmap
)->image
);
1911 (*bitmap
)->image
.palette
->Count
= 1 << PIXELFORMATBPP(format
);
1913 if (format
== PixelFormat1bppIndexed
)
1915 (*bitmap
)->image
.palette
->Flags
= PaletteFlagsGrayScale
;
1916 (*bitmap
)->image
.palette
->Entries
[0] = 0xff000000;
1917 (*bitmap
)->image
.palette
->Entries
[1] = 0xffffffff;
1921 if (format
== PixelFormat8bppIndexed
)
1922 (*bitmap
)->image
.palette
->Flags
= PaletteFlagsHalftone
;
1924 generate_halftone_palette((*bitmap
)->image
.palette
->Entries
,
1925 (*bitmap
)->image
.palette
->Count
);
1929 TRACE("<-- %p\n", *bitmap
);
1934 GpStatus WINGDIPAPI
GdipCreateBitmapFromStream(IStream
* stream
,
1939 TRACE("%p %p\n", stream
, bitmap
);
1941 stat
= GdipLoadImageFromStream(stream
, (GpImage
**) bitmap
);
1946 if((*bitmap
)->image
.type
!= ImageTypeBitmap
){
1947 GdipDisposeImage(&(*bitmap
)->image
);
1949 return GenericError
; /* FIXME: what error to return? */
1956 GpStatus WINGDIPAPI
GdipCreateBitmapFromStreamICM(IStream
* stream
,
1959 TRACE("%p %p\n", stream
, bitmap
);
1961 return GdipCreateBitmapFromStream(stream
, bitmap
);
1964 GpStatus WINGDIPAPI
GdipCreateCachedBitmap(GpBitmap
*bitmap
, GpGraphics
*graphics
,
1965 GpCachedBitmap
**cachedbmp
)
1969 TRACE("%p %p %p\n", bitmap
, graphics
, cachedbmp
);
1971 if(!bitmap
|| !graphics
|| !cachedbmp
)
1972 return InvalidParameter
;
1974 *cachedbmp
= heap_alloc_zero(sizeof(GpCachedBitmap
));
1978 stat
= GdipCloneImage(&(bitmap
->image
), &(*cachedbmp
)->image
);
1980 heap_free(*cachedbmp
);
1987 GpStatus WINGDIPAPI
GdipCreateHICONFromBitmap(GpBitmap
*bitmap
, HICON
*hicon
)
1990 BitmapData lockeddata
;
1991 ULONG andstride
, xorstride
, bitssize
;
1992 LPBYTE andbits
, xorbits
, androw
, xorrow
, srcrow
;
1995 TRACE("(%p, %p)\n", bitmap
, hicon
);
1997 if (!bitmap
|| !hicon
)
1998 return InvalidParameter
;
2000 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
,
2001 PixelFormat32bppPARGB
, &lockeddata
);
2004 andstride
= ((lockeddata
.Width
+31)/32)*4;
2005 xorstride
= lockeddata
.Width
*4;
2006 bitssize
= (andstride
+ xorstride
) * lockeddata
.Height
;
2008 andbits
= heap_alloc_zero(bitssize
);
2012 xorbits
= andbits
+ andstride
* lockeddata
.Height
;
2014 for (y
=0; y
<lockeddata
.Height
; y
++)
2016 srcrow
= ((LPBYTE
)lockeddata
.Scan0
) + lockeddata
.Stride
* y
;
2018 androw
= andbits
+ andstride
* y
;
2019 for (x
=0; x
<lockeddata
.Width
; x
++)
2020 if (srcrow
[3+4*x
] >= 128)
2021 androw
[x
/8] |= 1 << (7-x
%8);
2023 xorrow
= xorbits
+ xorstride
* y
;
2024 memcpy(xorrow
, srcrow
, xorstride
);
2027 *hicon
= CreateIcon(NULL
, lockeddata
.Width
, lockeddata
.Height
, 1, 32,
2035 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
2041 GpStatus WINGDIPAPI
GdipDeleteCachedBitmap(GpCachedBitmap
*cachedbmp
)
2043 TRACE("%p\n", cachedbmp
);
2046 return InvalidParameter
;
2048 GdipDisposeImage(cachedbmp
->image
);
2049 heap_free(cachedbmp
);
2054 GpStatus WINGDIPAPI
GdipDrawCachedBitmap(GpGraphics
*graphics
,
2055 GpCachedBitmap
*cachedbmp
, INT x
, INT y
)
2057 TRACE("%p %p %d %d\n", graphics
, cachedbmp
, x
, y
);
2059 if(!graphics
|| !cachedbmp
)
2060 return InvalidParameter
;
2062 return GdipDrawImage(graphics
, cachedbmp
->image
, (REAL
)x
, (REAL
)y
);
2065 /* Internal utility function: Replace the image data of dst with that of src,
2067 static void move_bitmap(GpBitmap
*dst
, GpBitmap
*src
, BOOL clobber_palette
)
2069 assert(src
->image
.type
== ImageTypeBitmap
);
2070 assert(dst
->image
.type
== ImageTypeBitmap
);
2072 heap_free(dst
->bitmapbits
);
2073 heap_free(dst
->own_bits
);
2075 DeleteObject(dst
->hbitmap
);
2077 if (clobber_palette
)
2079 heap_free(dst
->image
.palette
);
2080 dst
->image
.palette
= src
->image
.palette
;
2083 heap_free(src
->image
.palette
);
2085 dst
->image
.xres
= src
->image
.xres
;
2086 dst
->image
.yres
= src
->image
.yres
;
2087 dst
->width
= src
->width
;
2088 dst
->height
= src
->height
;
2089 dst
->format
= src
->format
;
2090 dst
->hbitmap
= src
->hbitmap
;
2091 dst
->hdc
= src
->hdc
;
2092 dst
->bits
= src
->bits
;
2093 dst
->stride
= src
->stride
;
2094 dst
->own_bits
= src
->own_bits
;
2095 if (dst
->metadata_reader
)
2096 IWICMetadataReader_Release(dst
->metadata_reader
);
2097 dst
->metadata_reader
= src
->metadata_reader
;
2098 heap_free(dst
->prop_item
);
2099 dst
->prop_item
= src
->prop_item
;
2100 dst
->prop_count
= src
->prop_count
;
2101 if (dst
->image
.decoder
)
2102 IWICBitmapDecoder_Release(dst
->image
.decoder
);
2103 dst
->image
.decoder
= src
->image
.decoder
;
2104 terminate_encoder_wic(&dst
->image
); /* terminate active encoder before overwriting with src */
2105 dst
->image
.encoder
= src
->image
.encoder
;
2106 dst
->image
.frame_count
= src
->image
.frame_count
;
2107 dst
->image
.current_frame
= src
->image
.current_frame
;
2108 dst
->image
.format
= src
->image
.format
;
2110 src
->image
.type
= ~0;
2114 static GpStatus
free_image_data(GpImage
*image
)
2117 return InvalidParameter
;
2119 if (image
->type
== ImageTypeBitmap
)
2121 heap_free(((GpBitmap
*)image
)->bitmapbits
);
2122 heap_free(((GpBitmap
*)image
)->own_bits
);
2123 DeleteDC(((GpBitmap
*)image
)->hdc
);
2124 DeleteObject(((GpBitmap
*)image
)->hbitmap
);
2125 if (((GpBitmap
*)image
)->metadata_reader
)
2126 IWICMetadataReader_Release(((GpBitmap
*)image
)->metadata_reader
);
2127 heap_free(((GpBitmap
*)image
)->prop_item
);
2129 else if (image
->type
== ImageTypeMetafile
)
2130 METAFILE_Free((GpMetafile
*)image
);
2133 WARN("invalid image: %p\n", image
);
2137 IWICBitmapDecoder_Release(image
->decoder
);
2138 terminate_encoder_wic(image
);
2139 heap_free(image
->palette
);
2144 GpStatus WINGDIPAPI
GdipDisposeImage(GpImage
*image
)
2148 TRACE("%p\n", image
);
2150 status
= free_image_data(image
);
2151 if (status
!= Ok
) return status
;
2158 GpStatus WINGDIPAPI
GdipFindFirstImageItem(GpImage
*image
, ImageItemData
* item
)
2162 TRACE("(%p,%p)\n", image
, item
);
2165 return InvalidParameter
;
2168 FIXME("not implemented\n");
2170 return NotImplemented
;
2173 GpStatus WINGDIPAPI
GdipGetImageItemData(GpImage
*image
, ImageItemData
*item
)
2177 TRACE("(%p,%p)\n", image
, item
);
2180 FIXME("not implemented\n");
2182 return NotImplemented
;
2185 GpStatus WINGDIPAPI
GdipGetImageBounds(GpImage
*image
, GpRectF
*srcRect
,
2188 TRACE("%p %p %p\n", image
, srcRect
, srcUnit
);
2190 if(!image
|| !srcRect
|| !srcUnit
)
2191 return InvalidParameter
;
2192 if(image
->type
== ImageTypeMetafile
){
2193 *srcRect
= ((GpMetafile
*)image
)->bounds
;
2194 *srcUnit
= ((GpMetafile
*)image
)->unit
;
2196 else if(image
->type
== ImageTypeBitmap
){
2197 srcRect
->X
= srcRect
->Y
= 0.0;
2198 srcRect
->Width
= (REAL
) ((GpBitmap
*)image
)->width
;
2199 srcRect
->Height
= (REAL
) ((GpBitmap
*)image
)->height
;
2200 *srcUnit
= UnitPixel
;
2203 WARN("GpImage with no image data\n");
2204 return InvalidParameter
;
2207 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect
->X
, srcRect
->Y
,
2208 srcRect
->Width
, srcRect
->Height
, *srcUnit
);
2213 GpStatus WINGDIPAPI
GdipGetImageDimension(GpImage
*image
, REAL
*width
,
2216 TRACE("%p %p %p\n", image
, width
, height
);
2218 if(!image
|| !height
|| !width
)
2219 return InvalidParameter
;
2221 if(image
->type
== ImageTypeMetafile
){
2222 *height
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Height
, ((GpMetafile
*)image
)->unit
,
2223 image
->yres
, ((GpMetafile
*)image
)->printer_display
);
2224 *width
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Width
, ((GpMetafile
*)image
)->unit
,
2225 image
->xres
, ((GpMetafile
*)image
)->printer_display
);
2227 else if(image
->type
== ImageTypeBitmap
){
2228 *height
= ((GpBitmap
*)image
)->height
;
2229 *width
= ((GpBitmap
*)image
)->width
;
2232 WARN("GpImage with no image data\n");
2233 return InvalidParameter
;
2236 TRACE("returning (%f, %f)\n", *height
, *width
);
2240 GpStatus WINGDIPAPI
GdipGetImageGraphicsContext(GpImage
*image
,
2241 GpGraphics
**graphics
)
2246 TRACE("%p %p\n", image
, graphics
);
2248 if(!image
|| !graphics
)
2249 return InvalidParameter
;
2251 if (image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)image
)->hbitmap
)
2253 hdc
= ((GpBitmap
*)image
)->hdc
;
2256 hdc
= CreateCompatibleDC(0);
2257 SelectObject(hdc
, ((GpBitmap
*)image
)->hbitmap
);
2258 ((GpBitmap
*)image
)->hdc
= hdc
;
2261 stat
= GdipCreateFromHDC(hdc
, graphics
);
2265 (*graphics
)->image
= image
;
2266 (*graphics
)->image_type
= image
->type
;
2267 (*graphics
)->xres
= image
->xres
;
2268 (*graphics
)->yres
= image
->yres
;
2271 else if (image
->type
== ImageTypeMetafile
)
2272 stat
= METAFILE_GetGraphicsContext((GpMetafile
*)image
, graphics
);
2274 stat
= graphics_from_image(image
, graphics
);
2279 GpStatus WINGDIPAPI
GdipGetImageHeight(GpImage
*image
, UINT
*height
)
2281 TRACE("%p %p\n", image
, height
);
2283 if(!image
|| !height
)
2284 return InvalidParameter
;
2286 if(image
->type
== ImageTypeMetafile
)
2287 *height
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Height
, ((GpMetafile
*)image
)->unit
,
2288 image
->yres
, ((GpMetafile
*)image
)->printer_display
);
2289 else if(image
->type
== ImageTypeBitmap
)
2290 *height
= ((GpBitmap
*)image
)->height
;
2293 WARN("GpImage with no image data\n");
2294 return InvalidParameter
;
2297 TRACE("returning %d\n", *height
);
2302 GpStatus WINGDIPAPI
GdipGetImageHorizontalResolution(GpImage
*image
, REAL
*res
)
2305 return InvalidParameter
;
2309 TRACE("(%p) <-- %0.2f\n", image
, *res
);
2314 GpStatus WINGDIPAPI
GdipGetImagePaletteSize(GpImage
*image
, INT
*size
)
2316 TRACE("%p %p\n", image
, size
);
2319 return InvalidParameter
;
2321 if (image
->type
== ImageTypeMetafile
)
2324 return GenericError
;
2327 if (!image
->palette
|| image
->palette
->Count
== 0)
2328 *size
= sizeof(ColorPalette
);
2330 *size
= sizeof(UINT
)*2 + sizeof(ARGB
)*image
->palette
->Count
;
2332 TRACE("<-- %u\n", *size
);
2337 /* FIXME: test this function for non-bitmap types */
2338 GpStatus WINGDIPAPI
GdipGetImagePixelFormat(GpImage
*image
, PixelFormat
*format
)
2340 TRACE("%p %p\n", image
, format
);
2342 if(!image
|| !format
)
2343 return InvalidParameter
;
2345 if(image
->type
!= ImageTypeBitmap
)
2346 *format
= PixelFormat24bppRGB
;
2348 *format
= ((GpBitmap
*) image
)->format
;
2353 GpStatus WINGDIPAPI
GdipGetImageRawFormat(GpImage
*image
, GUID
*format
)
2355 TRACE("(%p, %p)\n", image
, format
);
2357 if(!image
|| !format
)
2358 return InvalidParameter
;
2360 memcpy(format
, &image
->format
, sizeof(GUID
));
2365 GpStatus WINGDIPAPI
GdipGetImageType(GpImage
*image
, ImageType
*type
)
2367 TRACE("%p %p\n", image
, type
);
2370 return InvalidParameter
;
2372 *type
= image
->type
;
2377 GpStatus WINGDIPAPI
GdipGetImageVerticalResolution(GpImage
*image
, REAL
*res
)
2380 return InvalidParameter
;
2384 TRACE("(%p) <-- %0.2f\n", image
, *res
);
2389 GpStatus WINGDIPAPI
GdipGetImageWidth(GpImage
*image
, UINT
*width
)
2391 TRACE("%p %p\n", image
, width
);
2393 if(!image
|| !width
)
2394 return InvalidParameter
;
2396 if(image
->type
== ImageTypeMetafile
)
2397 *width
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Width
, ((GpMetafile
*)image
)->unit
,
2398 image
->xres
, ((GpMetafile
*)image
)->printer_display
);
2399 else if(image
->type
== ImageTypeBitmap
)
2400 *width
= ((GpBitmap
*)image
)->width
;
2403 WARN("GpImage with no image data\n");
2404 return InvalidParameter
;
2407 TRACE("returning %d\n", *width
);
2412 GpStatus WINGDIPAPI
GdipGetPropertyCount(GpImage
*image
, UINT
*num
)
2414 TRACE("(%p, %p)\n", image
, num
);
2416 if (!image
|| !num
) return InvalidParameter
;
2420 if (image
->type
== ImageTypeBitmap
)
2422 if (((GpBitmap
*)image
)->prop_item
)
2424 *num
= ((GpBitmap
*)image
)->prop_count
;
2428 if (((GpBitmap
*)image
)->metadata_reader
)
2429 IWICMetadataReader_GetCount(((GpBitmap
*)image
)->metadata_reader
, num
);
2435 GpStatus WINGDIPAPI
GdipGetPropertyIdList(GpImage
*image
, UINT num
, PROPID
*list
)
2438 IWICMetadataReader
*reader
;
2439 IWICEnumMetadataItem
*enumerator
;
2441 ULONG items_returned
;
2443 TRACE("(%p, %u, %p)\n", image
, num
, list
);
2445 if (!image
|| !list
) return InvalidParameter
;
2447 if (image
->type
!= ImageTypeBitmap
)
2449 FIXME("Not implemented for type %d\n", image
->type
);
2450 return NotImplemented
;
2453 if (((GpBitmap
*)image
)->prop_item
)
2455 if (num
!= ((GpBitmap
*)image
)->prop_count
) return InvalidParameter
;
2457 for (i
= 0; i
< num
; i
++)
2459 list
[i
] = ((GpBitmap
*)image
)->prop_item
[i
].id
;
2465 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2468 if (num
!= 0) return InvalidParameter
;
2472 hr
= IWICMetadataReader_GetCount(reader
, &prop_count
);
2473 if (FAILED(hr
)) return hresult_to_status(hr
);
2475 if (num
!= prop_count
) return InvalidParameter
;
2477 hr
= IWICMetadataReader_GetEnumerator(reader
, &enumerator
);
2478 if (FAILED(hr
)) return hresult_to_status(hr
);
2480 IWICEnumMetadataItem_Reset(enumerator
);
2482 for (i
= 0; i
< num
; i
++)
2486 hr
= IWICEnumMetadataItem_Next(enumerator
, 1, NULL
, &id
, NULL
, &items_returned
);
2487 if (hr
!= S_OK
) break;
2489 if (id
.vt
!= VT_UI2
)
2491 FIXME("not supported propvariant type for id: %u\n", id
.vt
);
2498 IWICEnumMetadataItem_Release(enumerator
);
2500 return hr
== S_OK
? Ok
: hresult_to_status(hr
);
2503 static UINT
propvariant_size(PROPVARIANT
*value
)
2505 switch (value
->vt
& ~VT_VECTOR
)
2511 if (!(value
->vt
& VT_VECTOR
)) return 1;
2512 return value
->caub
.cElems
;
2515 if (!(value
->vt
& VT_VECTOR
)) return 2;
2516 return value
->caui
.cElems
* 2;
2520 if (!(value
->vt
& VT_VECTOR
)) return 4;
2521 return value
->caul
.cElems
* 4;
2525 if (!(value
->vt
& VT_VECTOR
)) return 8;
2526 return value
->cauh
.cElems
* 8;
2528 return value
->pszVal
? strlen(value
->pszVal
) + 1 : 0;
2530 return value
->blob
.cbSize
;
2532 FIXME("not supported variant type %d\n", value
->vt
);
2537 GpStatus WINGDIPAPI
GdipGetPropertyItemSize(GpImage
*image
, PROPID propid
, UINT
*size
)
2540 IWICMetadataReader
*reader
;
2541 PROPVARIANT id
, value
;
2543 TRACE("(%p,%#lx,%p)\n", image
, propid
, size
);
2545 if (!size
|| !image
) return InvalidParameter
;
2547 if (image
->type
!= ImageTypeBitmap
)
2549 FIXME("Not implemented for type %d\n", image
->type
);
2550 return NotImplemented
;
2553 if (((GpBitmap
*)image
)->prop_item
)
2557 for (i
= 0; i
< ((GpBitmap
*)image
)->prop_count
; i
++)
2559 if (propid
== ((GpBitmap
*)image
)->prop_item
[i
].id
)
2561 *size
= sizeof(PropertyItem
) + ((GpBitmap
*)image
)->prop_item
[i
].length
;
2566 return PropertyNotFound
;
2569 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2570 if (!reader
) return PropertyNotFound
;
2574 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
2575 if (FAILED(hr
)) return PropertyNotFound
;
2577 *size
= propvariant_size(&value
);
2578 if (*size
) *size
+= sizeof(PropertyItem
);
2579 PropVariantClear(&value
);
2584 #ifndef PropertyTagTypeSByte
2585 #define PropertyTagTypeSByte 6
2586 #define PropertyTagTypeSShort 8
2587 #define PropertyTagTypeFloat 11
2588 #define PropertyTagTypeDouble 12
2591 static UINT
vt_to_itemtype(UINT vt
)
2598 { VT_I1
, PropertyTagTypeSByte
},
2599 { VT_UI1
, PropertyTagTypeByte
},
2600 { VT_I2
, PropertyTagTypeSShort
},
2601 { VT_UI2
, PropertyTagTypeShort
},
2602 { VT_I4
, PropertyTagTypeSLONG
},
2603 { VT_UI4
, PropertyTagTypeLong
},
2604 { VT_I8
, PropertyTagTypeSRational
},
2605 { VT_UI8
, PropertyTagTypeRational
},
2606 { VT_R4
, PropertyTagTypeFloat
},
2607 { VT_R8
, PropertyTagTypeDouble
},
2608 { VT_LPSTR
, PropertyTagTypeASCII
},
2609 { VT_BLOB
, PropertyTagTypeUndefined
}
2612 for (i
= 0; i
< ARRAY_SIZE(vt2type
); i
++)
2614 if (vt2type
[i
].vt
== vt
) return vt2type
[i
].type
;
2616 FIXME("not supported variant type %u\n", vt
);
2620 static GpStatus
propvariant_to_item(PROPVARIANT
*value
, PropertyItem
*item
,
2621 UINT size
, PROPID id
)
2623 UINT item_size
, item_type
;
2625 item_size
= propvariant_size(value
);
2626 if (size
!= item_size
+ sizeof(PropertyItem
)) return InvalidParameter
;
2628 item_type
= vt_to_itemtype(value
->vt
& ~VT_VECTOR
);
2629 if (!item_type
) return InvalidParameter
;
2631 item
->value
= item
+ 1;
2633 switch (value
->vt
& ~VT_VECTOR
)
2637 if (!(value
->vt
& VT_VECTOR
))
2638 *(BYTE
*)item
->value
= value
->bVal
;
2640 memcpy(item
->value
, value
->caub
.pElems
, item_size
);
2644 if (!(value
->vt
& VT_VECTOR
))
2645 *(USHORT
*)item
->value
= value
->uiVal
;
2647 memcpy(item
->value
, value
->caui
.pElems
, item_size
);
2652 if (!(value
->vt
& VT_VECTOR
))
2653 *(ULONG
*)item
->value
= value
->ulVal
;
2655 memcpy(item
->value
, value
->caul
.pElems
, item_size
);
2660 if (!(value
->vt
& VT_VECTOR
))
2661 *(ULONGLONG
*)item
->value
= value
->uhVal
.QuadPart
;
2663 memcpy(item
->value
, value
->cauh
.pElems
, item_size
);
2666 memcpy(item
->value
, value
->pszVal
, item_size
);
2669 memcpy(item
->value
, value
->blob
.pBlobData
, item_size
);
2672 FIXME("not supported variant type %d\n", value
->vt
);
2673 return InvalidParameter
;
2676 item
->length
= item_size
;
2677 item
->type
= item_type
;
2683 GpStatus WINGDIPAPI
GdipGetPropertyItem(GpImage
*image
, PROPID propid
, UINT size
,
2684 PropertyItem
*buffer
)
2688 IWICMetadataReader
*reader
;
2689 PROPVARIANT id
, value
;
2691 TRACE("(%p,%#lx,%u,%p)\n", image
, propid
, size
, buffer
);
2693 if (!image
|| !buffer
) return InvalidParameter
;
2695 if (image
->type
!= ImageTypeBitmap
)
2697 FIXME("Not implemented for type %d\n", image
->type
);
2698 return NotImplemented
;
2701 if (((GpBitmap
*)image
)->prop_item
)
2705 for (i
= 0; i
< ((GpBitmap
*)image
)->prop_count
; i
++)
2707 if (propid
== ((GpBitmap
*)image
)->prop_item
[i
].id
)
2709 if (size
!= sizeof(PropertyItem
) + ((GpBitmap
*)image
)->prop_item
[i
].length
)
2710 return InvalidParameter
;
2712 *buffer
= ((GpBitmap
*)image
)->prop_item
[i
];
2713 buffer
->value
= buffer
+ 1;
2714 memcpy(buffer
->value
, ((GpBitmap
*)image
)->prop_item
[i
].value
, buffer
->length
);
2719 return PropertyNotFound
;
2722 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2723 if (!reader
) return PropertyNotFound
;
2727 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
2728 if (FAILED(hr
)) return PropertyNotFound
;
2730 stat
= propvariant_to_item(&value
, buffer
, size
, propid
);
2731 PropVariantClear(&value
);
2736 GpStatus WINGDIPAPI
GdipGetPropertySize(GpImage
*image
, UINT
*size
, UINT
*count
)
2739 IWICMetadataReader
*reader
;
2740 IWICEnumMetadataItem
*enumerator
;
2741 UINT prop_count
, prop_size
, i
;
2742 PROPVARIANT id
, value
;
2744 TRACE("(%p,%p,%p)\n", image
, size
, count
);
2746 if (!image
|| !size
|| !count
) return InvalidParameter
;
2748 if (image
->type
!= ImageTypeBitmap
)
2750 FIXME("Not implemented for type %d\n", image
->type
);
2751 return NotImplemented
;
2754 if (((GpBitmap
*)image
)->prop_item
)
2756 *count
= ((GpBitmap
*)image
)->prop_count
;
2759 for (i
= 0; i
< ((GpBitmap
*)image
)->prop_count
; i
++)
2761 *size
+= sizeof(PropertyItem
) + ((GpBitmap
*)image
)->prop_item
[i
].length
;
2767 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2775 hr
= IWICMetadataReader_GetCount(reader
, &prop_count
);
2776 if (FAILED(hr
)) return hresult_to_status(hr
);
2778 hr
= IWICMetadataReader_GetEnumerator(reader
, &enumerator
);
2779 if (FAILED(hr
)) return hresult_to_status(hr
);
2781 IWICEnumMetadataItem_Reset(enumerator
);
2785 PropVariantInit(&id
);
2786 PropVariantInit(&value
);
2788 for (i
= 0; i
< prop_count
; i
++)
2790 ULONG items_returned
;
2793 hr
= IWICEnumMetadataItem_Next(enumerator
, 1, NULL
, &id
, &value
, &items_returned
);
2794 if (hr
!= S_OK
) break;
2796 item_size
= propvariant_size(&value
);
2797 if (item_size
) prop_size
+= sizeof(PropertyItem
) + item_size
;
2799 PropVariantClear(&id
);
2800 PropVariantClear(&value
);
2803 IWICEnumMetadataItem_Release(enumerator
);
2805 if (hr
!= S_OK
) return PropertyNotFound
;
2807 *count
= prop_count
;
2812 GpStatus WINGDIPAPI
GdipGetAllPropertyItems(GpImage
*image
, UINT size
,
2813 UINT count
, PropertyItem
*buf
)
2817 IWICMetadataReader
*reader
;
2818 IWICEnumMetadataItem
*enumerator
;
2819 UINT prop_count
, prop_size
, i
;
2820 PROPVARIANT id
, value
;
2823 TRACE("(%p,%u,%u,%p)\n", image
, size
, count
, buf
);
2825 if (!image
|| !buf
) return InvalidParameter
;
2827 if (image
->type
!= ImageTypeBitmap
)
2829 FIXME("Not implemented for type %d\n", image
->type
);
2830 return NotImplemented
;
2833 status
= GdipGetPropertySize(image
, &prop_size
, &prop_count
);
2834 if (status
!= Ok
) return status
;
2836 if (prop_count
!= count
|| prop_size
!= size
) return InvalidParameter
;
2838 if (((GpBitmap
*)image
)->prop_item
)
2840 memcpy(buf
, ((GpBitmap
*)image
)->prop_item
, prop_size
);
2842 item_value
= (char *)(buf
+ prop_count
);
2844 for (i
= 0; i
< prop_count
; i
++)
2846 buf
[i
].value
= item_value
;
2847 item_value
+= buf
[i
].length
;
2853 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2854 if (!reader
) return GenericError
;
2856 hr
= IWICMetadataReader_GetEnumerator(reader
, &enumerator
);
2857 if (FAILED(hr
)) return hresult_to_status(hr
);
2859 IWICEnumMetadataItem_Reset(enumerator
);
2861 item_value
= (char *)(buf
+ prop_count
);
2863 PropVariantInit(&id
);
2864 PropVariantInit(&value
);
2866 for (i
= 0; i
< prop_count
; i
++)
2869 ULONG items_returned
;
2872 hr
= IWICEnumMetadataItem_Next(enumerator
, 1, NULL
, &id
, &value
, &items_returned
);
2873 if (hr
!= S_OK
) break;
2875 if (id
.vt
!= VT_UI2
)
2877 FIXME("not supported propvariant type for id: %u\n", id
.vt
);
2881 item_size
= propvariant_size(&value
);
2884 item
= heap_alloc(item_size
+ sizeof(*item
));
2886 propvariant_to_item(&value
, item
, item_size
+ sizeof(*item
), id
.uiVal
);
2887 buf
[i
].id
= item
->id
;
2888 buf
[i
].type
= item
->type
;
2889 buf
[i
].length
= item_size
;
2890 buf
[i
].value
= item_value
;
2891 memcpy(item_value
, item
->value
, item_size
);
2892 item_value
+= item_size
;
2897 PropVariantClear(&id
);
2898 PropVariantClear(&value
);
2901 IWICEnumMetadataItem_Release(enumerator
);
2903 if (hr
!= S_OK
) return PropertyNotFound
;
2908 struct image_format_dimension
2911 const GUID
*dimension
;
2914 static const struct image_format_dimension image_format_dimensions
[] =
2916 {&ImageFormatGIF
, &FrameDimensionTime
},
2917 {&ImageFormatIcon
, &FrameDimensionResolution
},
2921 GpStatus WINGDIPAPI
GdipImageGetFrameCount(GpImage
*image
,
2922 GDIPCONST GUID
* dimensionID
, UINT
* count
)
2924 TRACE("(%p,%s,%p)\n", image
, debugstr_guid(dimensionID
), count
);
2926 if(!image
|| !count
)
2927 return InvalidParameter
;
2930 IsEqualGUID(dimensionID
, &image
->format
) ||
2931 IsEqualGUID(dimensionID
, &FrameDimensionPage
) ||
2932 IsEqualGUID(dimensionID
, &FrameDimensionTime
))
2934 *count
= image
->frame_count
;
2938 return InvalidParameter
;
2941 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsCount(GpImage
*image
,
2944 TRACE("(%p, %p)\n", image
, count
);
2946 /* Native gdiplus 1.1 does not yet support multiple frame dimensions. */
2948 if(!image
|| !count
)
2949 return InvalidParameter
;
2956 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsList(GpImage
* image
,
2957 GUID
* dimensionIDs
, UINT count
)
2960 const GUID
*result
=NULL
;
2962 TRACE("(%p,%p,%u)\n", image
, dimensionIDs
, count
);
2964 if(!image
|| !dimensionIDs
|| count
!= 1)
2965 return InvalidParameter
;
2967 for (i
=0; image_format_dimensions
[i
].format
; i
++)
2969 if (IsEqualGUID(&image
->format
, image_format_dimensions
[i
].format
))
2971 result
= image_format_dimensions
[i
].dimension
;
2977 result
= &FrameDimensionPage
;
2979 memcpy(dimensionIDs
, result
, sizeof(GUID
));
2984 GpStatus WINGDIPAPI
GdipLoadImageFromFile(GDIPCONST WCHAR
* filename
,
2990 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
2992 if (!filename
|| !image
)
2993 return InvalidParameter
;
2997 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
3002 stat
= GdipLoadImageFromStream(stream
, image
);
3004 IStream_Release(stream
);
3009 /* FIXME: no icm handling */
3010 GpStatus WINGDIPAPI
GdipLoadImageFromFileICM(GDIPCONST WCHAR
* filename
,GpImage
**image
)
3012 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
3014 return GdipLoadImageFromFile(filename
, image
);
3017 static void add_property(GpBitmap
*bitmap
, PropertyItem
*item
)
3019 UINT prop_size
, prop_count
;
3020 PropertyItem
*prop_item
;
3022 if (bitmap
->prop_item
== NULL
)
3024 prop_size
= prop_count
= 0;
3025 prop_item
= heap_alloc_zero(item
->length
+ sizeof(PropertyItem
));
3026 if (!prop_item
) return;
3033 GdipGetPropertySize(&bitmap
->image
, &prop_size
, &prop_count
);
3035 prop_item
= heap_alloc_zero(prop_size
+ item
->length
+ sizeof(PropertyItem
));
3036 if (!prop_item
) return;
3037 memcpy(prop_item
, bitmap
->prop_item
, sizeof(PropertyItem
) * bitmap
->prop_count
);
3038 prop_size
-= sizeof(PropertyItem
) * bitmap
->prop_count
;
3039 memcpy(prop_item
+ prop_count
+ 1, bitmap
->prop_item
+ prop_count
, prop_size
);
3041 item_value
= (char *)(prop_item
+ prop_count
+ 1);
3043 for (i
= 0; i
< prop_count
; i
++)
3045 prop_item
[i
].value
= item_value
;
3046 item_value
+= prop_item
[i
].length
;
3050 prop_item
[prop_count
].id
= item
->id
;
3051 prop_item
[prop_count
].type
= item
->type
;
3052 prop_item
[prop_count
].length
= item
->length
;
3053 prop_item
[prop_count
].value
= (char *)(prop_item
+ prop_count
+ 1) + prop_size
;
3054 memcpy(prop_item
[prop_count
].value
, item
->value
, item
->length
);
3056 heap_free(bitmap
->prop_item
);
3057 bitmap
->prop_item
= prop_item
;
3058 bitmap
->prop_count
++;
3061 static BOOL
get_bool_property(IWICMetadataReader
*reader
, const GUID
*guid
, const WCHAR
*prop_name
)
3065 PROPVARIANT id
, value
;
3068 hr
= IWICMetadataReader_GetMetadataFormat(reader
, &format
);
3069 if (FAILED(hr
) || !IsEqualGUID(&format
, guid
)) return FALSE
;
3071 PropVariantInit(&id
);
3072 PropVariantInit(&value
);
3075 id
.pwszVal
= CoTaskMemAlloc((lstrlenW(prop_name
) + 1) * sizeof(WCHAR
));
3076 if (!id
.pwszVal
) return FALSE
;
3077 lstrcpyW(id
.pwszVal
, prop_name
);
3078 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
3079 if (hr
== S_OK
&& value
.vt
== VT_BOOL
)
3080 ret
= value
.boolVal
;
3082 PropVariantClear(&id
);
3083 PropVariantClear(&value
);
3088 static PropertyItem
*get_property(IWICMetadataReader
*reader
, const GUID
*guid
, const WCHAR
*prop_name
)
3092 PROPVARIANT id
, value
;
3093 PropertyItem
*item
= NULL
;
3095 hr
= IWICMetadataReader_GetMetadataFormat(reader
, &format
);
3096 if (FAILED(hr
) || !IsEqualGUID(&format
, guid
)) return NULL
;
3098 PropVariantInit(&id
);
3099 PropVariantInit(&value
);
3102 id
.pwszVal
= CoTaskMemAlloc((lstrlenW(prop_name
) + 1) * sizeof(WCHAR
));
3103 if (!id
.pwszVal
) return NULL
;
3104 lstrcpyW(id
.pwszVal
, prop_name
);
3105 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
3108 UINT item_size
= propvariant_size(&value
);
3111 item_size
+= sizeof(*item
);
3112 item
= heap_alloc_zero(item_size
);
3113 if (propvariant_to_item(&value
, item
, item_size
, 0) != Ok
)
3121 PropVariantClear(&id
);
3122 PropVariantClear(&value
);
3127 static PropertyItem
*get_gif_comment(IWICMetadataReader
*reader
)
3129 PropertyItem
*comment
;
3131 comment
= get_property(reader
, &GUID_MetadataFormatGifComment
, L
"TextEntry");
3133 comment
->id
= PropertyTagExifUserComment
;
3138 static PropertyItem
*get_gif_loopcount(IWICMetadataReader
*reader
)
3140 PropertyItem
*appext
= NULL
, *appdata
= NULL
, *loop
= NULL
;
3142 appext
= get_property(reader
, &GUID_MetadataFormatAPE
, L
"Application");
3145 if (appext
->type
== PropertyTagTypeByte
&& appext
->length
== 11 &&
3146 (!memcmp(appext
->value
, "NETSCAPE2.0", 11) || !memcmp(appext
->value
, "ANIMEXTS1.0", 11)))
3148 appdata
= get_property(reader
, &GUID_MetadataFormatAPE
, L
"Data");
3151 if (appdata
->type
== PropertyTagTypeByte
&& appdata
->length
== 4)
3153 BYTE
*data
= appdata
->value
;
3154 if (data
[0] == 3 && data
[1] == 1)
3156 loop
= heap_alloc_zero(sizeof(*loop
) + sizeof(SHORT
));
3159 loop
->type
= PropertyTagTypeShort
;
3160 loop
->id
= PropertyTagLoopCount
;
3161 loop
->length
= sizeof(SHORT
);
3162 loop
->value
= loop
+ 1;
3163 *(SHORT
*)loop
->value
= data
[2] | (data
[3] << 8);
3177 static PropertyItem
*get_gif_background(IWICMetadataReader
*reader
)
3179 PropertyItem
*background
= NULL
;
3181 if (get_bool_property(reader
, &GUID_MetadataFormatLSD
, L
"GlobalColorTableFlag"))
3183 background
= get_property(reader
, &GUID_MetadataFormatLSD
, L
"BackgroundColorIndex");
3185 background
->id
= PropertyTagIndexBackground
;
3191 static PropertyItem
*get_gif_palette(IWICBitmapDecoder
*decoder
, IWICMetadataReader
*reader
)
3194 IWICImagingFactory
*factory
;
3195 IWICPalette
*palette
;
3197 WICColor colors
[256];
3199 if (!get_bool_property(reader
, &GUID_MetadataFormatLSD
, L
"GlobalColorTableFlag"))
3202 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
3203 if (hr
!= S_OK
) return NULL
;
3205 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
3208 hr
= IWICBitmapDecoder_CopyPalette(decoder
, palette
);
3210 IWICPalette_GetColors(palette
, 256, colors
, &count
);
3212 IWICPalette_Release(palette
);
3215 IWICImagingFactory_Release(factory
);
3223 pal
= heap_alloc_zero(sizeof(*pal
) + count
* 3);
3224 if (!pal
) return NULL
;
3225 pal
->type
= PropertyTagTypeByte
;
3226 pal
->id
= PropertyTagGlobalPalette
;
3227 pal
->value
= pal
+ 1;
3228 pal
->length
= count
* 3;
3232 for (i
= 0; i
< count
; i
++)
3234 rgb
[i
*3] = (colors
[i
] >> 16) & 0xff;
3235 rgb
[i
*3 + 1] = (colors
[i
] >> 8) & 0xff;
3236 rgb
[i
*3 + 2] = colors
[i
] & 0xff;
3245 static PropertyItem
*get_gif_transparent_idx(IWICMetadataReader
*reader
)
3247 PropertyItem
*index
= NULL
;
3249 if (get_bool_property(reader
, &GUID_MetadataFormatGCE
, L
"TransparencyFlag"))
3251 index
= get_property(reader
, &GUID_MetadataFormatGCE
, L
"TransparentColorIndex");
3253 index
->id
= PropertyTagIndexTransparent
;
3258 static void get_gif_frame_property(IWICBitmapFrameDecode
*frame
, const GUID
*format
, const WCHAR
*property
, LONG
*value
)
3261 IWICMetadataBlockReader
*block_reader
;
3262 IWICMetadataReader
*reader
;
3263 UINT block_count
, i
;
3266 hr
= IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3269 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3272 for (i
= 0; i
< block_count
; i
++)
3274 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3277 prop
= get_property(reader
, format
, property
);
3280 if (prop
->type
== PropertyTagTypeByte
&& prop
->length
== 1)
3281 *value
= *(BYTE
*)prop
->value
;
3282 else if (prop
->type
== PropertyTagTypeShort
&& prop
->length
== 2)
3283 *value
= *(SHORT
*)prop
->value
;
3287 IWICMetadataReader_Release(reader
);
3291 IWICMetadataBlockReader_Release(block_reader
);
3295 static void gif_metadata_reader(GpBitmap
*bitmap
, IWICBitmapDecoder
*decoder
, UINT active_frame
)
3298 IWICBitmapFrameDecode
*frame
;
3299 IWICMetadataBlockReader
*block_reader
;
3300 IWICMetadataReader
*reader
;
3301 UINT frame_count
, block_count
, i
;
3302 PropertyItem
*delay
= NULL
, *comment
= NULL
, *background
= NULL
;
3303 PropertyItem
*transparent_idx
= NULL
, *loop
= NULL
, *palette
= NULL
;
3305 IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
3306 delay
= heap_alloc_zero(sizeof(*delay
) + frame_count
* sizeof(LONG
));
3310 LONG frame_delay
= 0;
3312 delay
->type
= PropertyTagTypeLong
;
3313 delay
->id
= PropertyTagFrameDelay
;
3314 delay
->length
= frame_count
* sizeof(LONG
);
3315 delay
->value
= delay
+ 1;
3317 value
= delay
->value
;
3319 for (i
= 0; i
< frame_count
; i
++)
3321 hr
= IWICBitmapDecoder_GetFrame(decoder
, i
, &frame
);
3324 get_gif_frame_property(frame
, &GUID_MetadataFormatGCE
, L
"Delay", &frame_delay
);
3325 IWICBitmapFrameDecode_Release(frame
);
3327 value
[i
] = frame_delay
;
3331 hr
= IWICBitmapDecoder_QueryInterface(decoder
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3334 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3337 for (i
= 0; i
< block_count
; i
++)
3339 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3343 comment
= get_gif_comment(reader
);
3346 loop
= get_gif_loopcount(reader
);
3349 background
= get_gif_background(reader
);
3352 palette
= get_gif_palette(decoder
, reader
);
3354 IWICMetadataReader_Release(reader
);
3358 IWICMetadataBlockReader_Release(block_reader
);
3363 loop
= heap_alloc_zero(sizeof(*loop
) + sizeof(SHORT
));
3366 loop
->type
= PropertyTagTypeShort
;
3367 loop
->id
= PropertyTagLoopCount
;
3368 loop
->length
= sizeof(SHORT
);
3369 loop
->value
= loop
+ 1;
3370 *(SHORT
*)loop
->value
= 1;
3374 if (delay
) add_property(bitmap
, delay
);
3375 if (comment
) add_property(bitmap
, comment
);
3376 if (loop
) add_property(bitmap
, loop
);
3377 if (palette
) add_property(bitmap
, palette
);
3378 if (background
) add_property(bitmap
, background
);
3384 heap_free(background
);
3386 /* Win7 gdiplus always returns transparent color index from frame 0 */
3387 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
3388 if (hr
!= S_OK
) return;
3390 hr
= IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3393 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3396 for (i
= 0; i
< block_count
; i
++)
3398 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3401 if (!transparent_idx
)
3402 transparent_idx
= get_gif_transparent_idx(reader
);
3404 IWICMetadataReader_Release(reader
);
3408 IWICMetadataBlockReader_Release(block_reader
);
3411 if (transparent_idx
) add_property(bitmap
, transparent_idx
);
3412 heap_free(transparent_idx
);
3414 IWICBitmapFrameDecode_Release(frame
);
3417 static PropertyItem
* create_prop(PROPID propid
, PROPVARIANT
* value
)
3419 PropertyItem
*item
= NULL
;
3420 UINT item_size
= propvariant_size(value
);
3424 item_size
+= sizeof(*item
);
3425 item
= heap_alloc_zero(item_size
);
3426 if (propvariant_to_item(value
, item
, item_size
, propid
) != Ok
)
3436 static ULONG
get_ulong_by_index(IWICMetadataReader
* reader
, ULONG index
)
3442 hr
= IWICMetadataReader_GetValueByIndex(reader
, index
, NULL
, NULL
, &value
);
3448 result
= value
.ulVal
;
3451 ERR("unhandled case %u\n", value
.vt
);
3454 PropVariantClear(&value
);
3459 static HRESULT
png_read_text(IWICMetadataReader
*reader
, GpBitmap
*bitmap
, BOOL
**seen_text
)
3463 PROPVARIANT name
, value
;
3465 static const struct keyword_info
{
3469 { "Title", PropertyTagImageTitle
},
3470 { "Author", PropertyTagArtist
},
3471 { "Description", PropertyTagImageDescription
},
3472 { "Copyright", PropertyTagCopyright
},
3473 { "Software", PropertyTagSoftwareUsed
},
3474 { "Source", PropertyTagEquipModel
},
3475 { "Comment", PropertyTagExifUserComment
},
3478 if (*seen_text
== NULL
)
3479 *seen_text
= heap_alloc_zero(sizeof(BOOL
) * ARRAY_SIZE(keywords
));
3480 if (*seen_text
== NULL
)
3481 return E_OUTOFMEMORY
;
3483 hr
= IWICMetadataReader_GetValueByIndex(reader
, 0, NULL
, &name
, &value
);
3487 if (name
.vt
== VT_LPSTR
)
3489 for (i
= 0; i
< ARRAY_SIZE(keywords
); i
++)
3491 if (!strcmp(keywords
[i
].name
, name
.pszVal
))
3494 if (i
< ARRAY_SIZE(keywords
) && !(*seen_text
)[i
])
3496 (*seen_text
)[i
] = TRUE
;
3497 item
= create_prop(keywords
[i
].propid
, &value
);
3499 add_property(bitmap
, item
);
3504 PropVariantClear(&name
);
3505 PropVariantClear(&value
);
3510 static HRESULT
png_read_gamma(IWICMetadataReader
*reader
, GpBitmap
*bitmap
)
3515 item
= heap_alloc_zero(sizeof(*item
) + sizeof(ULONG
) * 2);
3517 return E_OUTOFMEMORY
;
3519 item
->length
= sizeof(ULONG
) * 2;
3520 item
->type
= PropertyTagTypeRational
;
3521 item
->id
= PropertyTagGamma
;
3522 rational
= item
->value
= item
+ 1;
3523 rational
[0] = 100000;
3524 rational
[1] = get_ulong_by_index(reader
, 0);
3525 add_property(bitmap
, item
);
3531 static HRESULT
png_read_whitepoint(IWICMetadataReader
*reader
, GpBitmap
*bitmap
)
3536 item
= heap_alloc_zero(sizeof(*item
) + sizeof(ULONG
) * 4);
3538 return E_OUTOFMEMORY
;
3540 item
->length
= sizeof(ULONG
) * 4;
3541 item
->type
= PropertyTagTypeRational
;
3542 item
->id
= PropertyTagWhitePoint
;
3543 rational
= item
->value
= item
+ 1;
3544 rational
[0] = get_ulong_by_index(reader
, 0);
3545 rational
[1] = 100000;
3546 rational
[2] = get_ulong_by_index(reader
, 1);
3547 rational
[3] = 100000;
3548 add_property(bitmap
, item
);
3554 static HRESULT
png_read_chromaticity(IWICMetadataReader
*reader
, GpBitmap
*bitmap
)
3559 item
= heap_alloc_zero(sizeof(*item
) + sizeof(ULONG
) * 12);
3561 return E_OUTOFMEMORY
;
3563 item
->length
= sizeof(ULONG
) * 12;
3564 item
->type
= PropertyTagTypeRational
;
3565 item
->id
= PropertyTagPrimaryChromaticities
;
3566 rational
= item
->value
= item
+ 1;
3567 rational
[0] = get_ulong_by_index(reader
, 2);
3568 rational
[1] = 100000;
3569 rational
[2] = get_ulong_by_index(reader
, 3);
3570 rational
[3] = 100000;
3571 rational
[4] = get_ulong_by_index(reader
, 4);
3572 rational
[5] = 100000;
3573 rational
[6] = get_ulong_by_index(reader
, 5);
3574 rational
[7] = 100000;
3575 rational
[8] = get_ulong_by_index(reader
, 6);
3576 rational
[9] = 100000;
3577 rational
[10] = get_ulong_by_index(reader
, 7);
3578 rational
[11] = 100000;
3579 add_property(bitmap
, item
);
3585 static HRESULT
png_read_time(IWICMetadataReader
*reader
, GpBitmap
*bitmap
)
3593 for (i
= 0; i
< 6; i
++)
3595 hr
= IWICMetadataReader_GetValueByIndex(reader
, i
, NULL
, NULL
, &value
);
3598 if (i
== 0 && value
.vt
== VT_UI2
)
3599 datetime
[0] = value
.uiVal
;
3600 else if (i
> 0 && value
.vt
== VT_UI1
)
3601 datetime
[i
] = value
.bVal
;
3604 PropVariantClear(&value
);
3607 PropVariantClear(&value
);
3611 item
= heap_alloc_zero(sizeof(*item
) + item_size
);
3613 return E_OUTOFMEMORY
;
3615 item
->id
= PropertyTagDateTime
;
3616 item
->type
= PropertyTagTypeASCII
;
3617 item
->length
= item_size
;
3618 item
->value
= item
+ 1;
3619 snprintf(item
->value
, item_size
, "%04u:%02u:%02u %02u:%02u:%02u",
3620 datetime
[0], datetime
[1], datetime
[2], datetime
[3], datetime
[4], datetime
[5]);
3622 add_property(bitmap
, item
);
3628 static HRESULT
png_read_histogram(IWICMetadataReader
*reader
, GpBitmap
*bitmap
)
3634 hr
= IWICMetadataReader_GetValueByIndex(reader
, 0, NULL
, NULL
, &value
);
3638 item
= create_prop(PropertyTagPaletteHistogram
, &value
);
3640 add_property(bitmap
, item
);
3643 PropVariantClear(&value
);
3648 static HRESULT
png_add_unit_properties(IWICBitmapFrameDecode
*frame
, GpBitmap
*bitmap
)
3652 PropertyItem
*unit
, *unitX
, *unitY
;
3654 hr
= IWICBitmapFrameDecode_GetResolution(frame
, &dpiX
, &dpiY
);
3658 unit
= heap_alloc_zero(sizeof(*unit
) + 1);
3659 unitX
= heap_alloc_zero(sizeof(*unitX
) + 4);
3660 unitY
= heap_alloc_zero(sizeof(*unitY
) + 4);
3662 if (!unit
|| !unitX
|| !unitY
)
3667 return E_OUTOFMEMORY
;
3670 unit
->type
= PropertyTagTypeByte
;
3671 unit
->id
= PropertyTagPixelUnit
;
3673 unit
->value
= unit
+ 1;
3674 *(BYTE
*)unit
->value
= 1;
3675 add_property(bitmap
, unit
);
3678 unitX
->type
= PropertyTagTypeLong
;
3679 unitX
->id
= PropertyTagPixelPerUnitX
;
3681 unitX
->value
= unitX
+ 1;
3682 *(ULONG
*)unitX
->value
= (dpiX
== 96.0) ? 0 : gdip_round(dpiX
/ 0.0254);
3683 add_property(bitmap
, unitX
);
3686 unitY
->type
= PropertyTagTypeLong
;
3687 unitY
->id
= PropertyTagPixelPerUnitY
;
3689 unitY
->value
= unitY
+ 1;
3690 *(ULONG
*)unitY
->value
= (dpiY
== 96.0) ? 0 : gdip_round(dpiY
/ 0.0254);
3691 add_property(bitmap
, unitY
);
3697 static void png_metadata_reader(GpBitmap
*bitmap
, IWICBitmapDecoder
*decoder
, UINT active_frame
)
3700 IWICBitmapFrameDecode
*frame
;
3701 IWICMetadataBlockReader
*block_reader
;
3702 UINT block_count
, i
;
3703 BOOL seen_gamma
=FALSE
, seen_whitepoint
=FALSE
, seen_chrm
=FALSE
, seen_time
=FALSE
, seen_histogram
=FALSE
;
3704 BOOL
*seen_text
= NULL
;
3706 hr
= IWICBitmapDecoder_GetFrame(decoder
, active_frame
, &frame
);
3710 hr
= IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3713 IWICBitmapFrameDecode_Release(frame
);
3717 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3720 IWICMetadataBlockReader_Release(block_reader
);
3721 IWICBitmapFrameDecode_Release(frame
);
3725 for (i
= 0; i
< block_count
; i
++)
3727 IWICMetadataReader
*reader
;
3730 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3734 hr
= IWICMetadataReader_GetMetadataFormat(reader
, &format
);
3737 IWICMetadataReader_Release(reader
);
3741 if (IsEqualGUID(&GUID_MetadataFormatChunktEXt
, &format
))
3742 png_read_text(reader
, bitmap
, &seen_text
);
3743 else if (IsEqualGUID(&GUID_MetadataFormatChunkgAMA
, &format
))
3747 hr
= png_read_gamma(reader
, bitmap
);
3748 seen_gamma
= SUCCEEDED(hr
);
3751 else if (IsEqualGUID(&GUID_MetadataFormatChunkcHRM
, &format
))
3753 if (!seen_whitepoint
)
3755 hr
= png_read_whitepoint(reader
, bitmap
);
3756 seen_whitepoint
= SUCCEEDED(hr
);
3760 hr
= png_read_chromaticity(reader
, bitmap
);
3761 seen_chrm
= SUCCEEDED(hr
);
3764 else if (IsEqualGUID(&GUID_MetadataFormatChunktIME
, &format
))
3768 hr
= png_read_time(reader
, bitmap
);
3769 seen_time
= SUCCEEDED(hr
);
3772 else if (IsEqualGUID(&GUID_MetadataFormatChunkhIST
, &format
))
3774 if (!seen_histogram
)
3776 hr
= png_read_histogram(reader
, bitmap
);
3777 seen_histogram
= SUCCEEDED(hr
);
3781 IWICMetadataReader_Release(reader
);
3785 heap_free(seen_text
);
3787 png_add_unit_properties(frame
, bitmap
);
3789 IWICMetadataBlockReader_Release(block_reader
);
3791 IWICBitmapFrameDecode_Release(frame
);
3794 static GpStatus
initialize_decoder_wic(IStream
*stream
, REFGUID container
, IWICBitmapDecoder
**decoder
)
3796 IWICImagingFactory
*factory
;
3799 TRACE("%p,%s\n", stream
, wine_dbgstr_guid(container
));
3801 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
3802 if (FAILED(hr
)) return hresult_to_status(hr
);
3803 hr
= IWICImagingFactory_CreateDecoder(factory
, container
, NULL
, decoder
);
3804 IWICImagingFactory_Release(factory
);
3805 if (FAILED(hr
)) return hresult_to_status(hr
);
3807 hr
= IWICBitmapDecoder_Initialize(*decoder
, stream
, WICDecodeMetadataCacheOnLoad
);
3810 IWICBitmapDecoder_Release(*decoder
);
3811 return hresult_to_status(hr
);
3816 typedef void (*metadata_reader_func
)(GpBitmap
*bitmap
, IWICBitmapDecoder
*decoder
, UINT frame
);
3818 static GpStatus
decode_frame_wic(IWICBitmapDecoder
*decoder
, BOOL force_conversion
,
3819 UINT active_frame
, metadata_reader_func metadata_reader
, GpImage
**image
)
3824 IWICBitmapFrameDecode
*frame
;
3825 IWICBitmapSource
*source
=NULL
;
3826 IWICMetadataBlockReader
*block_reader
;
3827 WICPixelFormatGUID wic_format
;
3828 PixelFormat gdip_format
=0;
3829 ColorPalette
*palette
= NULL
;
3830 WICBitmapPaletteType palette_type
= WICBitmapPaletteTypeFixedHalftone256
;
3832 UINT width
, height
, frame_count
;
3833 BitmapData lockeddata
;
3836 TRACE("%p,%u,%p\n", decoder
, active_frame
, image
);
3838 IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
3839 hr
= IWICBitmapDecoder_GetFrame(decoder
, active_frame
, &frame
);
3840 if (SUCCEEDED(hr
)) /* got frame */
3842 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &wic_format
);
3846 if (!force_conversion
)
3848 for (i
=0; pixel_formats
[i
].wic_format
; i
++)
3850 if (IsEqualGUID(&wic_format
, pixel_formats
[i
].wic_format
))
3852 source
= (IWICBitmapSource
*)frame
;
3853 IWICBitmapSource_AddRef(source
);
3854 gdip_format
= pixel_formats
[i
].gdip_format
;
3855 palette_type
= pixel_formats
[i
].palette_type
;
3862 /* unknown format; fall back on 32bppARGB */
3863 hr
= WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA
, (IWICBitmapSource
*)frame
, &source
);
3864 gdip_format
= PixelFormat32bppARGB
;
3866 TRACE("%s => %#x\n", wine_dbgstr_guid(&wic_format
), gdip_format
);
3869 if (SUCCEEDED(hr
)) /* got source */
3871 hr
= IWICBitmapSource_GetSize(source
, &width
, &height
);
3874 status
= GdipCreateBitmapFromScan0(width
, height
, 0, gdip_format
,
3877 if (SUCCEEDED(hr
) && status
== Ok
) /* created bitmap */
3879 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeWrite
,
3880 gdip_format
, &lockeddata
);
3881 if (status
== Ok
) /* locked bitmap */
3886 for (i
=0; i
<height
; i
++)
3889 hr
= IWICBitmapSource_CopyPixels(source
, &wrc
, abs(lockeddata
.Stride
),
3890 abs(lockeddata
.Stride
), (BYTE
*)lockeddata
.Scan0
+lockeddata
.Stride
*i
);
3891 if (FAILED(hr
)) break;
3894 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3897 if (SUCCEEDED(hr
) && status
== Ok
)
3898 *image
= &bitmap
->image
;
3902 GdipDisposeImage(&bitmap
->image
);
3905 if (SUCCEEDED(hr
) && status
== Ok
)
3908 hr
= IWICBitmapSource_GetResolution(source
, &dpix
, &dpiy
);
3911 bitmap
->image
.xres
= dpix
;
3912 bitmap
->image
.yres
= dpiy
;
3918 IWICBitmapSource_Release(source
);
3921 if (SUCCEEDED(hr
) && status
== Ok
) {
3922 bitmap
->metadata_reader
= NULL
;
3924 if (metadata_reader
)
3925 metadata_reader(bitmap
, decoder
, active_frame
);
3926 else if (IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
) == S_OK
)
3928 UINT block_count
= 0;
3929 if (IWICMetadataBlockReader_GetCount(block_reader
, &block_count
) == S_OK
&& block_count
)
3930 IWICMetadataBlockReader_GetReaderByIndex(block_reader
, 0, &bitmap
->metadata_reader
);
3931 IWICMetadataBlockReader_Release(block_reader
);
3934 palette
= get_palette(frame
, palette_type
);
3935 IWICBitmapFrameDecode_Release(frame
);
3939 if (FAILED(hr
) && status
== Ok
) status
= hresult_to_status(hr
);
3943 /* Native GDI+ used to be smarter, but since Win7 it just sets these flags. */
3944 bitmap
->image
.flags
|= ImageFlagsReadOnly
|ImageFlagsHasRealPixelSize
|ImageFlagsHasRealDPI
;
3945 if (IsEqualGUID(&wic_format
, &GUID_WICPixelFormat2bppGray
) ||
3946 IsEqualGUID(&wic_format
, &GUID_WICPixelFormat4bppGray
) ||
3947 IsEqualGUID(&wic_format
, &GUID_WICPixelFormat8bppGray
) ||
3948 IsEqualGUID(&wic_format
, &GUID_WICPixelFormat16bppGray
))
3949 bitmap
->image
.flags
|= ImageFlagsColorSpaceGRAY
;
3951 bitmap
->image
.flags
|= ImageFlagsColorSpaceRGB
;
3952 bitmap
->image
.frame_count
= frame_count
;
3953 bitmap
->image
.current_frame
= active_frame
;
3954 bitmap
->image
.decoder
= decoder
;
3955 IWICBitmapDecoder_AddRef(decoder
);
3958 heap_free(bitmap
->image
.palette
);
3959 bitmap
->image
.palette
= palette
;
3963 if (IsEqualGUID(&wic_format
, &GUID_WICPixelFormatBlackWhite
))
3964 bitmap
->image
.palette
->Flags
= 0;
3966 TRACE("=> %p\n", *image
);
3972 static GpStatus
decode_image_wic(IStream
*stream
, REFGUID container
,
3973 metadata_reader_func metadata_reader
, GpImage
**image
)
3975 IWICBitmapDecoder
*decoder
;
3978 status
= initialize_decoder_wic(stream
, container
, &decoder
);
3982 status
= decode_frame_wic(decoder
, FALSE
, 0, metadata_reader
, image
);
3983 IWICBitmapDecoder_Release(decoder
);
3987 static GpStatus
select_frame_wic(GpImage
*image
, UINT active_frame
)
3989 size_t obj_size
, body_offset
;
3993 status
= decode_frame_wic(image
->decoder
, FALSE
, active_frame
, NULL
, &new_image
);
3997 if (image
->type
== ImageTypeBitmap
)
3998 obj_size
= sizeof(GpBitmap
);
3999 else if (image
->type
== ImageTypeMetafile
)
4000 obj_size
= sizeof(GpMetafile
);
4003 ERR("unknown image type: %d\n", image
->type
);
4004 GdipDisposeImage(new_image
);
4005 return GenericError
;
4008 memcpy(&new_image
->format
, &image
->format
, sizeof(GUID
));
4009 new_image
->encoder
= image
->encoder
;
4010 image
->encoder
= NULL
;
4011 free_image_data(image
);
4012 memcpy(image
, new_image
, FIELD_OFFSET(GpImage
, lock
));
4013 body_offset
= RTL_SIZEOF_THROUGH_FIELD(GpImage
, lock
);
4014 memcpy((char *)image
+ body_offset
, (char *)new_image
+ body_offset
, obj_size
- body_offset
);
4015 new_image
->type
= ~0;
4016 heap_free(new_image
);
4020 static HRESULT
get_gif_frame_rect(IWICBitmapFrameDecode
*frame
,
4021 UINT
*left
, UINT
*top
, UINT
*width
, UINT
*height
)
4023 LONG frame_left
= 0, frame_top
= 0;
4024 get_gif_frame_property(frame
, &GUID_MetadataFormatIMD
, L
"Left", &frame_left
);
4025 get_gif_frame_property(frame
, &GUID_MetadataFormatIMD
, L
"Top", &frame_top
);
4029 return IWICBitmapFrameDecode_GetSize(frame
, width
, height
);
4032 static HRESULT
blit_gif_frame(GpBitmap
*bitmap
, IWICBitmapFrameDecode
*frame
, BOOL first_frame
)
4034 UINT i
, j
, left
, top
, width
, height
;
4035 IWICBitmapSource
*source
;
4039 hr
= get_gif_frame_rect(frame
, &left
, &top
, &width
, &height
);
4043 hr
= WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA
, (IWICBitmapSource
*)frame
, &source
);
4047 new_bits
= heap_alloc_zero(width
*height
*4);
4049 return E_OUTOFMEMORY
;
4051 hr
= IWICBitmapSource_CopyPixels(source
, NULL
, width
*4, width
*height
*4, new_bits
);
4052 IWICBitmapSource_Release(source
);
4054 heap_free(new_bits
);
4058 for(i
=0; i
<height
&& i
+top
<bitmap
->height
; i
++) {
4059 for(j
=0; j
<width
&& j
+left
<bitmap
->width
; j
++) {
4060 DWORD
*src
= (DWORD
*)(new_bits
+i
*width
*4+j
*4);
4061 DWORD
*dst
= (DWORD
*)(bitmap
->bits
+(i
+top
)*bitmap
->stride
+(j
+left
)*4);
4063 if(first_frame
|| *src
>>24 != 0)
4067 heap_free(new_bits
);
4071 static DWORD
get_gif_background_color(GpBitmap
*bitmap
)
4073 BYTE bgcolor_idx
= 0;
4076 for(i
=0; i
<bitmap
->prop_count
; i
++) {
4077 if(bitmap
->prop_item
[i
].id
== PropertyTagIndexBackground
)
4078 bgcolor_idx
= *(BYTE
*)bitmap
->prop_item
[i
].value
;
4079 else if(bitmap
->prop_item
[i
].id
== PropertyTagIndexTransparent
)
4083 for(i
=0; i
<bitmap
->prop_count
; i
++) {
4084 if(bitmap
->prop_item
[i
].id
== PropertyTagGlobalPalette
) {
4085 if(bitmap
->prop_item
[i
].length
/3 > bgcolor_idx
) {
4086 BYTE
*color
= ((BYTE
*)bitmap
->prop_item
[i
].value
)+bgcolor_idx
*3;
4087 return color
[2] + (color
[1]<<8) + (color
[0]<<16) + (0xffu
<<24);
4093 FIXME("can't get gif background color\n");
4097 static GpStatus
select_frame_gif(GpImage
* image
, UINT active_frame
)
4099 GpBitmap
*bitmap
= (GpBitmap
*)image
;
4100 IWICBitmapFrameDecode
*frame
;
4103 BOOL bgcolor_set
= FALSE
;
4107 if(active_frame
> image
->current_frame
) {
4108 hr
= IWICBitmapDecoder_GetFrame(bitmap
->image
.decoder
, image
->current_frame
, &frame
);
4110 return hresult_to_status(hr
);
4112 get_gif_frame_property(frame
, &GUID_MetadataFormatGCE
, L
"Disposal", &disposal
);
4113 IWICBitmapFrameDecode_Release(frame
);
4115 if(disposal
== GIF_DISPOSE_RESTORE_TO_BKGND
)
4116 cur_frame
= image
->current_frame
;
4117 else if(disposal
!= GIF_DISPOSE_RESTORE_TO_PREV
)
4118 cur_frame
= image
->current_frame
+1;
4121 while(cur_frame
!= active_frame
) {
4122 hr
= IWICBitmapDecoder_GetFrame(bitmap
->image
.decoder
, cur_frame
, &frame
);
4124 return hresult_to_status(hr
);
4126 get_gif_frame_property(frame
, &GUID_MetadataFormatGCE
, L
"Disposal", &disposal
);
4128 if(disposal
==GIF_DISPOSE_UNSPECIFIED
|| disposal
==GIF_DISPOSE_DO_NOT_DISPOSE
) {
4129 hr
= blit_gif_frame(bitmap
, frame
, cur_frame
==0);
4131 return hresult_to_status(hr
);
4132 }else if(disposal
== GIF_DISPOSE_RESTORE_TO_BKGND
) {
4133 UINT left
, top
, width
, height
, i
, j
;
4136 bgcolor
= get_gif_background_color(bitmap
);
4140 hr
= get_gif_frame_rect(frame
, &left
, &top
, &width
, &height
);
4142 return hresult_to_status(hr
);
4143 for(i
=top
; i
<top
+height
&& i
<bitmap
->height
; i
++) {
4144 DWORD
*bits
= (DWORD
*)(bitmap
->bits
+i
*bitmap
->stride
);
4145 for(j
=left
; j
<left
+width
&& j
<bitmap
->width
; j
++)
4150 IWICBitmapFrameDecode_Release(frame
);
4154 hr
= IWICBitmapDecoder_GetFrame(bitmap
->image
.decoder
, active_frame
, &frame
);
4156 return hresult_to_status(hr
);
4158 hr
= blit_gif_frame(bitmap
, frame
, cur_frame
==0);
4159 IWICBitmapFrameDecode_Release(frame
);
4161 return hresult_to_status(hr
);
4163 image
->current_frame
= active_frame
;
4167 static GpStatus
decode_image_icon(IStream
* stream
, GpImage
**image
)
4169 return decode_image_wic(stream
, &GUID_ContainerFormatIco
, NULL
, image
);
4172 static GpStatus
decode_image_bmp(IStream
* stream
, GpImage
**image
)
4177 status
= decode_image_wic(stream
, &GUID_ContainerFormatBmp
, NULL
, image
);
4179 bitmap
= (GpBitmap
*)*image
;
4181 if (status
== Ok
&& bitmap
->format
== PixelFormat32bppARGB
)
4183 /* WIC supports bmp files with alpha, but gdiplus does not */
4184 bitmap
->format
= PixelFormat32bppRGB
;
4190 static GpStatus
decode_image_jpeg(IStream
* stream
, GpImage
**image
)
4192 return decode_image_wic(stream
, &GUID_ContainerFormatJpeg
, NULL
, image
);
4195 static BOOL
has_png_transparency_chunk(IStream
*pIStream
)
4198 BOOL has_tRNS
= FALSE
;
4205 ULARGE_INTEGER chunk_start
;
4206 ULONG bytesread
, chunk_size
;
4208 hr
= IStream_Seek(pIStream
, seek
, STREAM_SEEK_SET
, &chunk_start
);
4209 if (FAILED(hr
)) break;
4211 hr
= IStream_Read(pIStream
, header
, 8, &bytesread
);
4212 if (FAILED(hr
) || bytesread
< 8) break;
4214 chunk_size
= (header
[0] << 24) | (header
[1] << 16) | (header
[2] << 8) | header
[3];
4215 if (!memcmp(&header
[4], "tRNS", 4))
4221 seek
.QuadPart
= chunk_start
.QuadPart
+ chunk_size
+ 12; /* skip data and CRC */
4222 } while (memcmp(&header
[4], "IDAT", 4) && memcmp(&header
[4], "IEND", 4));
4224 TRACE("has_tRNS = %d\n", has_tRNS
);
4228 static GpStatus
decode_image_png(IStream
* stream
, GpImage
**image
)
4230 IWICBitmapDecoder
*decoder
;
4231 IWICBitmapFrameDecode
*frame
;
4235 BOOL force_conversion
= FALSE
;
4237 status
= initialize_decoder_wic(stream
, &GUID_ContainerFormatPng
, &decoder
);
4241 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
4244 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
4247 if (IsEqualGUID(&format
, &GUID_WICPixelFormat8bppGray
))
4248 force_conversion
= TRUE
;
4249 else if ((IsEqualGUID(&format
, &GUID_WICPixelFormat8bppIndexed
) ||
4250 IsEqualGUID(&format
, &GUID_WICPixelFormat4bppIndexed
) ||
4251 IsEqualGUID(&format
, &GUID_WICPixelFormat2bppIndexed
) ||
4252 IsEqualGUID(&format
, &GUID_WICPixelFormat1bppIndexed
) ||
4253 IsEqualGUID(&format
, &GUID_WICPixelFormat24bppBGR
)) &&
4254 has_png_transparency_chunk(stream
))
4255 force_conversion
= TRUE
;
4257 status
= decode_frame_wic(decoder
, force_conversion
, 0, png_metadata_reader
, image
);
4260 status
= hresult_to_status(hr
);
4262 IWICBitmapFrameDecode_Release(frame
);
4265 status
= hresult_to_status(hr
);
4267 IWICBitmapDecoder_Release(decoder
);
4271 static GpStatus
decode_image_gif(IStream
* stream
, GpImage
**image
)
4273 IWICBitmapDecoder
*decoder
;
4278 status
= initialize_decoder_wic(stream
, &GUID_ContainerFormatGif
, &decoder
);
4282 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
4284 return hresult_to_status(hr
);
4286 status
= decode_frame_wic(decoder
, frame_count
> 1, 0, gif_metadata_reader
, image
);
4287 IWICBitmapDecoder_Release(decoder
);
4291 if(frame_count
> 1) {
4292 heap_free((*image
)->palette
);
4293 (*image
)->palette
= NULL
;
4298 static GpStatus
decode_image_tiff(IStream
* stream
, GpImage
**image
)
4300 return decode_image_wic(stream
, &GUID_ContainerFormatTiff
, NULL
, image
);
4303 C_ASSERT(offsetof(WmfPlaceableFileHeader
, Key
) == 0);
4305 static GpStatus
load_wmf(IStream
*stream
, GpMetafile
**metafile
)
4307 WmfPlaceableFileHeader pfh
;
4308 BOOL is_placeable
= FALSE
;
4317 hr
= IStream_Read(stream
, &mh
, sizeof(mh
), &size
);
4318 if (hr
!= S_OK
|| size
!= sizeof(mh
))
4319 return GenericError
;
4321 /* detect whether stream starts with a WmfPlaceablefileheader */
4322 if (*(UINT32
*)&mh
== WMF_PLACEABLE_KEY
)
4325 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4326 if (FAILED(hr
)) return hresult_to_status(hr
);
4328 hr
= IStream_Read(stream
, &pfh
, sizeof(pfh
), &size
);
4329 if (hr
!= S_OK
|| size
!= sizeof(pfh
))
4330 return GenericError
;
4332 hr
= IStream_Read(stream
, &mh
, sizeof(mh
), &size
);
4333 if (hr
!= S_OK
|| size
!= sizeof(mh
))
4334 return GenericError
;
4336 is_placeable
= TRUE
;
4339 seek
.QuadPart
= is_placeable
? sizeof(pfh
) : 0;
4340 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4341 if (FAILED(hr
)) return hresult_to_status(hr
);
4343 buf
= heap_alloc(mh
.mtSize
* 2);
4344 if (!buf
) return OutOfMemory
;
4346 hr
= IStream_Read(stream
, buf
, mh
.mtSize
* 2, &size
);
4347 if (hr
!= S_OK
|| size
!= mh
.mtSize
* 2)
4350 return GenericError
;
4353 hmf
= SetMetaFileBitsEx(mh
.mtSize
* 2, buf
);
4356 return GenericError
;
4358 status
= GdipCreateMetafileFromWmf(hmf
, TRUE
, is_placeable
? &pfh
: NULL
, metafile
);
4360 DeleteMetaFile(hmf
);
4364 static GpStatus
decode_image_wmf(IStream
*stream
, GpImage
**image
)
4366 GpMetafile
*metafile
;
4369 TRACE("%p %p\n", stream
, image
);
4371 if (!stream
|| !image
)
4372 return InvalidParameter
;
4374 status
= load_wmf(stream
, &metafile
);
4377 TRACE("Could not load metafile\n");
4381 *image
= (GpImage
*)metafile
;
4382 TRACE("<-- %p\n", *image
);
4387 static GpStatus
load_emf(IStream
*stream
, GpMetafile
**metafile
)
4397 hr
= IStream_Read(stream
, &emh
, sizeof(emh
), &size
);
4398 if (hr
!= S_OK
|| size
!= sizeof(emh
) || emh
.dSignature
!= ENHMETA_SIGNATURE
)
4399 return GenericError
;
4402 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4403 if (FAILED(hr
)) return hresult_to_status(hr
);
4405 buf
= heap_alloc(emh
.nBytes
);
4406 if (!buf
) return OutOfMemory
;
4408 hr
= IStream_Read(stream
, buf
, emh
.nBytes
, &size
);
4409 if (hr
!= S_OK
|| size
!= emh
.nBytes
)
4412 return GenericError
;
4415 hemf
= SetEnhMetaFileBits(emh
.nBytes
, buf
);
4418 return GenericError
;
4420 status
= GdipCreateMetafileFromEmf(hemf
, TRUE
, metafile
);
4422 DeleteEnhMetaFile(hemf
);
4426 static GpStatus
decode_image_emf(IStream
*stream
, GpImage
**image
)
4428 GpMetafile
*metafile
;
4431 TRACE("%p %p\n", stream
, image
);
4433 if (!stream
|| !image
)
4434 return InvalidParameter
;
4436 status
= load_emf(stream
, &metafile
);
4439 TRACE("Could not load metafile\n");
4443 *image
= (GpImage
*)metafile
;
4444 TRACE("<-- %p\n", *image
);
4449 typedef GpStatus (*encode_image_func
)(GpImage
*image
, IStream
* stream
,
4450 GDIPCONST EncoderParameters
* params
);
4452 typedef GpStatus (*decode_image_func
)(IStream
*stream
, GpImage
**image
);
4454 typedef GpStatus (*select_image_func
)(GpImage
*image
, UINT active_frame
);
4456 typedef struct image_codec
{
4457 ImageCodecInfo info
;
4458 encode_image_func encode_func
;
4459 decode_image_func decode_func
;
4460 select_image_func select_func
;
4475 static const struct image_codec codecs
[NUM_CODECS
];
4477 static GpStatus
get_decoder_info(IStream
* stream
, const struct image_codec
**result
)
4480 const BYTE
*pattern
, *mask
;
4487 /* seek to the start of the stream */
4489 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4490 if (FAILED(hr
)) return hresult_to_status(hr
);
4492 /* read the first 8 bytes */
4493 /* FIXME: This assumes all codecs have signatures <= 8 bytes in length */
4494 hr
= IStream_Read(stream
, signature
, 8, &bytesread
);
4495 if (FAILED(hr
)) return hresult_to_status(hr
);
4496 if (hr
== S_FALSE
|| bytesread
== 0) return GenericError
;
4498 for (i
= 0; i
< NUM_CODECS
; i
++) {
4499 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
) &&
4500 bytesread
>= codecs
[i
].info
.SigSize
)
4502 for (sig
=0; sig
<codecs
[i
].info
.SigCount
; sig
++)
4504 pattern
= &codecs
[i
].info
.SigPattern
[codecs
[i
].info
.SigSize
*sig
];
4505 mask
= &codecs
[i
].info
.SigMask
[codecs
[i
].info
.SigSize
*sig
];
4506 for (j
=0; j
<codecs
[i
].info
.SigSize
; j
++)
4507 if ((signature
[j
] & mask
[j
]) != pattern
[j
])
4509 if (j
== codecs
[i
].info
.SigSize
)
4511 *result
= &codecs
[i
];
4518 TRACE("no match for %lu byte signature %x %x %x %x %x %x %x %x\n", bytesread
,
4519 signature
[0],signature
[1],signature
[2],signature
[3],
4520 signature
[4],signature
[5],signature
[6],signature
[7]);
4522 return GenericError
;
4525 static GpStatus
get_decoder_info_from_image(GpImage
*image
, const struct image_codec
**result
)
4529 for (i
= 0; i
< NUM_CODECS
; i
++) {
4530 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
) &&
4531 IsEqualIID(&codecs
[i
].info
.FormatID
, &image
->format
))
4533 *result
= &codecs
[i
];
4538 TRACE("no match for format: %s\n", wine_dbgstr_guid(&image
->format
));
4539 return GenericError
;
4542 GpStatus WINGDIPAPI
GdipImageSelectActiveFrame(GpImage
*image
, GDIPCONST GUID
*dimensionID
,
4546 const struct image_codec
*codec
= NULL
;
4548 TRACE("(%p,%s,%u)\n", image
, debugstr_guid(dimensionID
), frame
);
4550 if (!image
|| !dimensionID
)
4551 return InvalidParameter
;
4552 if(!image_lock(image
))
4555 if (frame
>= image
->frame_count
)
4556 WARN("requested frame %u, but image has only %u\n", frame
, image
->frame_count
);
4557 /* rely on codec->select_func() to fail */
4559 if (image
->type
!= ImageTypeBitmap
&& image
->type
!= ImageTypeMetafile
)
4561 WARN("invalid image type %d\n", image
->type
);
4562 image_unlock(image
);
4563 return InvalidParameter
;
4566 if (image
->current_frame
== frame
)
4568 image_unlock(image
);
4572 if (!image
->decoder
)
4574 TRACE("image doesn't have an associated decoder\n");
4575 image_unlock(image
);
4579 /* choose an appropriate image decoder */
4580 stat
= get_decoder_info_from_image(image
, &codec
);
4583 WARN("can't find decoder info\n");
4584 image_unlock(image
);
4588 stat
= codec
->select_func(image
, frame
);
4589 image_unlock(image
);
4593 GpStatus WINGDIPAPI
GdipLoadImageFromStream(IStream
*stream
, GpImage
**image
)
4598 const struct image_codec
*codec
=NULL
;
4600 TRACE("%p %p\n", stream
, image
);
4602 if (!stream
|| !image
)
4603 return InvalidParameter
;
4605 /* choose an appropriate image decoder */
4606 stat
= get_decoder_info(stream
, &codec
);
4607 if (stat
!= Ok
) return stat
;
4609 /* seek to the start of the stream */
4611 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4612 if (FAILED(hr
)) return hresult_to_status(hr
);
4614 /* call on the image decoder to do the real work */
4615 stat
= codec
->decode_func(stream
, image
);
4617 /* take note of the original data format */
4620 memcpy(&(*image
)->format
, &codec
->info
.FormatID
, sizeof(GUID
));
4628 GpStatus WINGDIPAPI
GdipLoadImageFromStreamICM(IStream
* stream
, GpImage
**image
)
4630 TRACE("%p %p\n", stream
, image
);
4632 return GdipLoadImageFromStream(stream
, image
);
4635 GpStatus WINGDIPAPI
GdipRemovePropertyItem(GpImage
*image
, PROPID propId
)
4639 TRACE("(%p,%lu)\n", image
, propId
);
4642 return InvalidParameter
;
4645 FIXME("not implemented\n");
4647 return NotImplemented
;
4650 GpStatus WINGDIPAPI
GdipSetPropertyItem(GpImage
*image
, GDIPCONST PropertyItem
* item
)
4654 if (!image
|| !item
) return InvalidParameter
;
4656 TRACE("(%p,%p:%#lx,%u,%lu,%p)\n", image
, item
, item
->id
, item
->type
, item
->length
, item
->value
);
4659 FIXME("not implemented\n");
4664 GpStatus WINGDIPAPI
GdipSaveImageToFile(GpImage
*image
, GDIPCONST WCHAR
* filename
,
4665 GDIPCONST CLSID
*clsidEncoder
,
4666 GDIPCONST EncoderParameters
*encoderParams
)
4671 TRACE("%p (%s) %p %p\n", image
, debugstr_w(filename
), clsidEncoder
, encoderParams
);
4673 if (!image
|| !filename
|| !clsidEncoder
)
4674 return InvalidParameter
;
4676 /* this might release an old file stream held by the encoder so we can re-create it below */
4677 terminate_encoder_wic(image
);
4679 stat
= GdipCreateStreamOnFile(filename
, GENERIC_WRITE
, &stream
);
4681 return GenericError
;
4683 stat
= GdipSaveImageToStream(image
, stream
, clsidEncoder
, encoderParams
);
4685 IStream_Release(stream
);
4689 /*************************************************************************
4690 * Encoding functions -
4691 * These functions encode an image in different image file formats.
4694 static GpStatus
initialize_encoder_wic(IStream
*stream
, REFGUID container
, GpImage
*image
)
4696 IWICImagingFactory
*factory
;
4699 TRACE("%p,%s\n", stream
, wine_dbgstr_guid(container
));
4701 terminate_encoder_wic(image
); /* terminate previous encoder if it exists */
4703 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
4704 if (FAILED(hr
)) return hresult_to_status(hr
);
4705 hr
= IWICImagingFactory_CreateEncoder(factory
, container
, NULL
, &image
->encoder
);
4706 IWICImagingFactory_Release(factory
);
4709 image
->encoder
= NULL
;
4710 return hresult_to_status(hr
);
4713 hr
= IWICBitmapEncoder_Initialize(image
->encoder
, stream
, WICBitmapEncoderNoCache
);
4716 IWICBitmapEncoder_Release(image
->encoder
);
4717 image
->encoder
= NULL
;
4718 return hresult_to_status(hr
);
4723 GpStatus
terminate_encoder_wic(GpImage
*image
)
4725 if (!image
->encoder
)
4729 HRESULT hr
= IWICBitmapEncoder_Commit(image
->encoder
);
4730 IWICBitmapEncoder_Release(image
->encoder
);
4731 image
->encoder
= NULL
;
4732 return hresult_to_status(hr
);
4736 static GpStatus
encode_frame_wic(IWICBitmapEncoder
*encoder
, GpImage
*image
)
4740 IWICBitmapFrameEncode
*frameencode
;
4741 IPropertyBag2
*encoderoptions
;
4742 GUID container_format
;
4745 PixelFormat gdipformat
=0;
4746 const WICPixelFormatGUID
*desired_wicformat
;
4747 WICPixelFormatGUID wicformat
;
4749 BitmapData lockeddata
;
4752 if (image
->type
!= ImageTypeBitmap
)
4753 return GenericError
;
4755 bitmap
= (GpBitmap
*)image
;
4757 GdipGetImageWidth(image
, &width
);
4758 GdipGetImageHeight(image
, &height
);
4765 hr
= IWICBitmapEncoder_CreateNewFrame(encoder
, &frameencode
, &encoderoptions
);
4767 if (SUCCEEDED(hr
)) /* created frame */
4769 hr
= IWICBitmapEncoder_GetContainerFormat(encoder
, &container_format
);
4770 if (SUCCEEDED(hr
) && IsEqualGUID(&container_format
, &GUID_ContainerFormatPng
))
4772 /* disable PNG filters for faster encoding */
4773 PROPBAG2 filter_option
= { .pstrName
= (LPOLESTR
) L
"FilterOption" };
4774 VARIANT filter_value
;
4775 VariantInit(&filter_value
);
4776 V_VT(&filter_value
) = VT_UI1
;
4777 V_UI1(&filter_value
) = WICPngFilterNone
;
4778 hr
= IPropertyBag2_Write(encoderoptions
, 1, &filter_option
, &filter_value
);
4782 hr
= IWICBitmapFrameEncode_Initialize(frameencode
, encoderoptions
);
4785 hr
= IWICBitmapFrameEncode_SetSize(frameencode
, width
, height
);
4788 hr
= IWICBitmapFrameEncode_SetResolution(frameencode
, image
->xres
, image
->yres
);
4792 for (i
=0; pixel_formats
[i
].wic_format
; i
++)
4794 if (pixel_formats
[i
].gdip_format
== bitmap
->format
)
4796 desired_wicformat
= pixel_formats
[i
].wic_format
;
4797 gdipformat
= bitmap
->format
;
4803 desired_wicformat
= &GUID_WICPixelFormat32bppBGRA
;
4804 gdipformat
= PixelFormat32bppARGB
;
4807 memcpy(&wicformat
, desired_wicformat
, sizeof(GUID
));
4808 hr
= IWICBitmapFrameEncode_SetPixelFormat(frameencode
, &wicformat
);
4811 if (SUCCEEDED(hr
) && !IsEqualGUID(desired_wicformat
, &wicformat
))
4813 /* Encoder doesn't support this bitmap's format. */
4815 for (i
=0; pixel_formats
[i
].wic_format
; i
++)
4817 if (IsEqualGUID(&wicformat
, pixel_formats
[i
].wic_format
))
4819 gdipformat
= pixel_formats
[i
].gdip_format
;
4825 ERR("Cannot support encoder format %s\n", debugstr_guid(&wicformat
));
4830 if (SUCCEEDED(hr
) && IsIndexedPixelFormat(gdipformat
) && image
->palette
)
4831 hr
= set_palette(frameencode
, image
->palette
);
4835 stat
= GdipBitmapLockBits(bitmap
, &rc
, ImageLockModeRead
, gdipformat
,
4840 UINT row_size
= (lockeddata
.Width
* PIXELFORMATBPP(gdipformat
) + 7)/8;
4843 /* write one row at a time in case stride is negative */
4844 row
= lockeddata
.Scan0
;
4845 for (i
=0; i
<lockeddata
.Height
; i
++)
4847 hr
= IWICBitmapFrameEncode_WritePixels(frameencode
, 1, row_size
, row_size
, row
);
4848 if (FAILED(hr
)) break;
4849 row
+= lockeddata
.Stride
;
4852 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
4859 hr
= IWICBitmapFrameEncode_Commit(frameencode
);
4861 IWICBitmapFrameEncode_Release(frameencode
);
4862 IPropertyBag2_Release(encoderoptions
);
4865 return hresult_to_status(hr
);
4868 static BOOL
has_encoder_param_long(GDIPCONST EncoderParameters
*params
, GUID param_guid
, ULONG val
)
4870 int param_idx
, value_idx
;
4875 for (param_idx
= 0; param_idx
< params
->Count
; param_idx
++)
4877 EncoderParameter param
= params
->Parameter
[param_idx
];
4878 if (param
.Type
== EncoderParameterValueTypeLong
&& IsEqualCLSID(¶m
.Guid
, ¶m_guid
))
4880 ULONG
*value_array
= (ULONG
*) param
.Value
;
4881 for (value_idx
= 0; value_idx
< param
.NumberOfValues
; value_idx
++)
4883 if (value_array
[value_idx
] == val
)
4891 static GpStatus
encode_image_wic(GpImage
*image
, IStream
*stream
,
4892 REFGUID container
, GDIPCONST EncoderParameters
*params
)
4894 GpStatus status
, terminate_status
;
4896 if (image
->type
!= ImageTypeBitmap
)
4897 return GenericError
;
4899 status
= initialize_encoder_wic(stream
, container
, image
);
4902 status
= encode_frame_wic(image
->encoder
, image
);
4904 if (!has_encoder_param_long(params
, EncoderSaveFlag
, EncoderValueMultiFrame
))
4906 /* always try to terminate, but if something already failed earlier, keep the old status. */
4907 terminate_status
= terminate_encoder_wic(image
);
4909 status
= terminate_status
;
4915 static GpStatus
encode_image_BMP(GpImage
*image
, IStream
* stream
,
4916 GDIPCONST EncoderParameters
* params
)
4918 return encode_image_wic(image
, stream
, &GUID_ContainerFormatBmp
, params
);
4921 static GpStatus
encode_image_tiff(GpImage
*image
, IStream
* stream
,
4922 GDIPCONST EncoderParameters
* params
)
4924 return encode_image_wic(image
, stream
, &GUID_ContainerFormatTiff
, params
);
4927 GpStatus
encode_image_png(GpImage
*image
, IStream
* stream
,
4928 GDIPCONST EncoderParameters
* params
)
4930 return encode_image_wic(image
, stream
, &GUID_ContainerFormatPng
, params
);
4933 static GpStatus
encode_image_jpeg(GpImage
*image
, IStream
* stream
,
4934 GDIPCONST EncoderParameters
* params
)
4936 return encode_image_wic(image
, stream
, &GUID_ContainerFormatJpeg
, params
);
4939 static GpStatus
encode_image_gif(GpImage
*image
, IStream
* stream
,
4940 GDIPCONST EncoderParameters
* params
)
4942 return encode_image_wic(image
, stream
, &GUID_ContainerFormatGif
, params
);
4945 /*****************************************************************************
4946 * GdipSaveImageToStream [GDIPLUS.@]
4948 GpStatus WINGDIPAPI
GdipSaveImageToStream(GpImage
*image
, IStream
* stream
,
4949 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4952 encode_image_func encode_image
;
4955 TRACE("%p, %p, %s, %p\n", image
, stream
, wine_dbgstr_guid(clsid
), params
);
4957 if(!image
|| !stream
)
4958 return InvalidParameter
;
4960 /* select correct encoder */
4961 encode_image
= NULL
;
4962 for (i
= 0; i
< NUM_CODECS
; i
++) {
4963 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
) &&
4964 IsEqualCLSID(clsid
, &codecs
[i
].info
.Clsid
))
4965 encode_image
= codecs
[i
].encode_func
;
4967 if (encode_image
== NULL
)
4968 return UnknownImageFormat
;
4970 stat
= encode_image(image
, stream
, params
);
4975 /*****************************************************************************
4976 * GdipSaveAdd [GDIPLUS.@]
4978 * Like GdipSaveAddImage(), but encode the currently active frame of the given image into the file
4979 * or stream that is currently being encoded.
4981 GpStatus WINGDIPAPI
GdipSaveAdd(GpImage
*image
, GDIPCONST EncoderParameters
*params
)
4983 return GdipSaveAddImage(image
, image
, params
);
4986 /*****************************************************************************
4987 * GdipSaveAddImage [GDIPLUS.@]
4989 * Encode the currently active frame of additional_image into the file or stream that is currently
4990 * being encoded by the image given in the image parameter. The first frame of a multi-frame image
4991 * must be encoded using the normal GdipSaveImageToStream() or GdipSaveImageToFile() functions,
4992 * but with the "MultiFrame" encoding parameter set. The multi-frame encoding process must be
4993 * finished after adding the last frame by calling GdipSaveAdd() with the "Flush" encoding parameter
4996 GpStatus WINGDIPAPI
GdipSaveAddImage(GpImage
*image
, GpImage
*additional_image
,
4997 GDIPCONST EncoderParameters
*params
)
4999 TRACE("%p, %p, %p\n", image
, additional_image
, params
);
5001 if (!image
|| !additional_image
|| !params
)
5002 return InvalidParameter
;
5004 if (!image
->encoder
)
5007 if (has_encoder_param_long(params
, EncoderSaveFlag
, EncoderValueFlush
))
5008 return terminate_encoder_wic(image
);
5009 else if (has_encoder_param_long(params
, EncoderSaveFlag
, EncoderValueFrameDimensionPage
))
5010 return encode_frame_wic(image
->encoder
, additional_image
);
5012 return InvalidParameter
;
5015 /*****************************************************************************
5016 * GdipGetImagePalette [GDIPLUS.@]
5018 GpStatus WINGDIPAPI
GdipGetImagePalette(GpImage
*image
, ColorPalette
*palette
, INT size
)
5022 TRACE("(%p,%p,%i)\n", image
, palette
, size
);
5024 if (!image
|| !palette
)
5025 return InvalidParameter
;
5027 count
= image
->palette
? image
->palette
->Count
: 0;
5029 if (size
< (sizeof(UINT
)*2+sizeof(ARGB
)*count
))
5031 TRACE("<-- InsufficientBuffer\n");
5032 return InsufficientBuffer
;
5037 palette
->Flags
= image
->palette
->Flags
;
5038 palette
->Count
= image
->palette
->Count
;
5039 memcpy(palette
->Entries
, image
->palette
->Entries
, sizeof(ARGB
)*image
->palette
->Count
);
5049 /*****************************************************************************
5050 * GdipSetImagePalette [GDIPLUS.@]
5052 GpStatus WINGDIPAPI
GdipSetImagePalette(GpImage
*image
,
5053 GDIPCONST ColorPalette
*palette
)
5055 ColorPalette
*new_palette
;
5057 TRACE("(%p,%p)\n", image
, palette
);
5059 if(!image
|| !palette
|| palette
->Count
> 256)
5060 return InvalidParameter
;
5062 new_palette
= heap_alloc_zero(2 * sizeof(UINT
) + palette
->Count
* sizeof(ARGB
));
5063 if (!new_palette
) return OutOfMemory
;
5065 heap_free(image
->palette
);
5066 image
->palette
= new_palette
;
5067 image
->palette
->Flags
= palette
->Flags
;
5068 image
->palette
->Count
= palette
->Count
;
5069 memcpy(image
->palette
->Entries
, palette
->Entries
, sizeof(ARGB
)*palette
->Count
);
5074 /*************************************************************************
5076 * Structures that represent which formats we support for encoding.
5079 /* ImageCodecInfo creation routines taken from libgdiplus */
5080 static const WCHAR bmp_codecname
[] = L
"Built-in BMP";
5081 static const WCHAR bmp_extension
[] = L
"*.BMP;*.DIB;*.RLE";
5082 static const WCHAR bmp_mimetype
[] = L
"image/bmp";
5083 static const WCHAR bmp_format
[] = L
"BMP";
5084 static const BYTE bmp_sig_pattern
[] = { 0x42, 0x4D };
5085 static const BYTE bmp_sig_mask
[] = { 0xFF, 0xFF };
5087 static const WCHAR jpeg_codecname
[] = L
"Built-in JPEG";
5088 static const WCHAR jpeg_extension
[] = L
"*.JPG;*.JPEG;*.JPE;*.JFIF";
5089 static const WCHAR jpeg_mimetype
[] = L
"image/jpeg";
5090 static const WCHAR jpeg_format
[] = L
"JPEG";
5091 static const BYTE jpeg_sig_pattern
[] = { 0xFF, 0xD8 };
5092 static const BYTE jpeg_sig_mask
[] = { 0xFF, 0xFF };
5094 static const WCHAR gif_codecname
[] = L
"Built-in GIF";
5095 static const WCHAR gif_extension
[] = L
"*.GIF";
5096 static const WCHAR gif_mimetype
[] = L
"image/gif";
5097 static const WCHAR gif_format
[] = L
"GIF";
5098 static const BYTE gif_sig_pattern
[12] = "GIF87aGIF89a";
5099 static const BYTE gif_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
5101 static const WCHAR tiff_codecname
[] = L
"Built-in TIFF";
5102 static const WCHAR tiff_extension
[] = L
"*.TIFF;*.TIF";
5103 static const WCHAR tiff_mimetype
[] = L
"image/tiff";
5104 static const WCHAR tiff_format
[] = L
"TIFF";
5105 static const BYTE tiff_sig_pattern
[] = {0x49,0x49,42,0,0x4d,0x4d,0,42};
5106 static const BYTE tiff_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
5108 static const WCHAR emf_codecname
[] = L
"Built-in EMF";
5109 static const WCHAR emf_extension
[] = L
"*.EMF";
5110 static const WCHAR emf_mimetype
[] = L
"image/x-emf";
5111 static const WCHAR emf_format
[] = L
"EMF";
5112 static const BYTE emf_sig_pattern
[] = { 0x01, 0x00, 0x00, 0x00 };
5113 static const BYTE emf_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
5115 static const WCHAR wmf_codecname
[] = L
"Built-in WMF";
5116 static const WCHAR wmf_extension
[] = L
"*.WMF";
5117 static const WCHAR wmf_mimetype
[] = L
"image/x-wmf";
5118 static const WCHAR wmf_format
[] = L
"WMF";
5119 static const BYTE wmf_sig_pattern
[] = { 0xd7, 0xcd };
5120 static const BYTE wmf_sig_mask
[] = { 0xFF, 0xFF };
5122 static const WCHAR png_codecname
[] = L
"Built-in PNG";
5123 static const WCHAR png_extension
[] = L
"*.PNG";
5124 static const WCHAR png_mimetype
[] = L
"image/png";
5125 static const WCHAR png_format
[] = L
"PNG";
5126 static const BYTE png_sig_pattern
[] = { 137, 80, 78, 71, 13, 10, 26, 10, };
5127 static const BYTE png_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
5129 static const WCHAR ico_codecname
[] = L
"Built-in ICO";
5130 static const WCHAR ico_extension
[] = L
"*.ICO";
5131 static const WCHAR ico_mimetype
[] = L
"image/x-icon";
5132 static const WCHAR ico_format
[] = L
"ICO";
5133 static const BYTE ico_sig_pattern
[] = { 0x00, 0x00, 0x01, 0x00 };
5134 static const BYTE ico_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
5136 static const struct image_codec codecs
[NUM_CODECS
] = {
5139 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
5140 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
5141 /* CodecName */ bmp_codecname
,
5143 /* FormatDescription */ bmp_format
,
5144 /* FilenameExtension */ bmp_extension
,
5145 /* MimeType */ bmp_mimetype
,
5146 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
5150 /* SigPattern */ bmp_sig_pattern
,
5151 /* SigMask */ bmp_sig_mask
,
5159 /* Clsid */ { 0x557cf401, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
5160 /* FormatID */ { 0xb96b3caeU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
5161 /* CodecName */ jpeg_codecname
,
5163 /* FormatDescription */ jpeg_format
,
5164 /* FilenameExtension */ jpeg_extension
,
5165 /* MimeType */ jpeg_mimetype
,
5166 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
5170 /* SigPattern */ jpeg_sig_pattern
,
5171 /* SigMask */ jpeg_sig_mask
,
5179 /* Clsid */ { 0x557cf402, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
5180 /* FormatID */ { 0xb96b3cb0U
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
5181 /* CodecName */ gif_codecname
,
5183 /* FormatDescription */ gif_format
,
5184 /* FilenameExtension */ gif_extension
,
5185 /* MimeType */ gif_mimetype
,
5186 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsEncoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
5190 /* SigPattern */ gif_sig_pattern
,
5191 /* SigMask */ gif_sig_mask
,
5199 /* Clsid */ { 0x557cf405, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
5200 /* FormatID */ { 0xb96b3cb1U
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
5201 /* CodecName */ tiff_codecname
,
5203 /* FormatDescription */ tiff_format
,
5204 /* FilenameExtension */ tiff_extension
,
5205 /* MimeType */ tiff_mimetype
,
5206 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsEncoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
5210 /* SigPattern */ tiff_sig_pattern
,
5211 /* SigMask */ tiff_sig_mask
,
5219 /* Clsid */ { 0x557cf403, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
5220 /* FormatID */ { 0xb96b3cacU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
5221 /* CodecName */ emf_codecname
,
5223 /* FormatDescription */ emf_format
,
5224 /* FilenameExtension */ emf_extension
,
5225 /* MimeType */ emf_mimetype
,
5226 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
5230 /* SigPattern */ emf_sig_pattern
,
5231 /* SigMask */ emf_sig_mask
,
5239 /* Clsid */ { 0x557cf404, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
5240 /* FormatID */ { 0xb96b3cadU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
5241 /* CodecName */ wmf_codecname
,
5243 /* FormatDescription */ wmf_format
,
5244 /* FilenameExtension */ wmf_extension
,
5245 /* MimeType */ wmf_mimetype
,
5246 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
5250 /* SigPattern */ wmf_sig_pattern
,
5251 /* SigMask */ wmf_sig_mask
,
5259 /* Clsid */ { 0x557cf406, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
5260 /* FormatID */ { 0xb96b3cafU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
5261 /* CodecName */ png_codecname
,
5263 /* FormatDescription */ png_format
,
5264 /* FilenameExtension */ png_extension
,
5265 /* MimeType */ png_mimetype
,
5266 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
5270 /* SigPattern */ png_sig_pattern
,
5271 /* SigMask */ png_sig_mask
,
5279 /* Clsid */ { 0x557cf407, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
5280 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
5281 /* CodecName */ ico_codecname
,
5283 /* FormatDescription */ ico_format
,
5284 /* FilenameExtension */ ico_extension
,
5285 /* MimeType */ ico_mimetype
,
5286 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
5290 /* SigPattern */ ico_sig_pattern
,
5291 /* SigMask */ ico_sig_mask
,
5299 /*****************************************************************************
5300 * GdipGetImageDecodersSize [GDIPLUS.@]
5302 GpStatus WINGDIPAPI
GdipGetImageDecodersSize(UINT
*numDecoders
, UINT
*size
)
5304 int decoder_count
=0;
5306 TRACE("%p %p\n", numDecoders
, size
);
5308 if (!numDecoders
|| !size
)
5309 return InvalidParameter
;
5311 for (i
=0; i
<NUM_CODECS
; i
++)
5313 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
5317 *numDecoders
= decoder_count
;
5318 *size
= decoder_count
* sizeof(ImageCodecInfo
);
5323 /*****************************************************************************
5324 * GdipGetImageDecoders [GDIPLUS.@]
5326 GpStatus WINGDIPAPI
GdipGetImageDecoders(UINT numDecoders
, UINT size
, ImageCodecInfo
*decoders
)
5328 int i
, decoder_count
=0;
5329 TRACE("%u %u %p\n", numDecoders
, size
, decoders
);
5332 size
!= numDecoders
* sizeof(ImageCodecInfo
))
5333 return GenericError
;
5335 for (i
=0; i
<NUM_CODECS
; i
++)
5337 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
5339 if (decoder_count
== numDecoders
) return GenericError
;
5340 memcpy(&decoders
[decoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
5345 if (decoder_count
< numDecoders
) return GenericError
;
5350 /*****************************************************************************
5351 * GdipGetImageEncodersSize [GDIPLUS.@]
5353 GpStatus WINGDIPAPI
GdipGetImageEncodersSize(UINT
*numEncoders
, UINT
*size
)
5355 int encoder_count
=0;
5357 TRACE("%p %p\n", numEncoders
, size
);
5359 if (!numEncoders
|| !size
)
5360 return InvalidParameter
;
5362 for (i
=0; i
<NUM_CODECS
; i
++)
5364 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
5368 *numEncoders
= encoder_count
;
5369 *size
= encoder_count
* sizeof(ImageCodecInfo
);
5374 /*****************************************************************************
5375 * GdipGetImageEncoders [GDIPLUS.@]
5377 GpStatus WINGDIPAPI
GdipGetImageEncoders(UINT numEncoders
, UINT size
, ImageCodecInfo
*encoders
)
5379 int i
, encoder_count
=0;
5380 TRACE("%u %u %p\n", numEncoders
, size
, encoders
);
5383 size
!= numEncoders
* sizeof(ImageCodecInfo
))
5384 return GenericError
;
5386 for (i
=0; i
<NUM_CODECS
; i
++)
5388 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
5390 if (encoder_count
== numEncoders
) return GenericError
;
5391 memcpy(&encoders
[encoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
5396 if (encoder_count
< numEncoders
) return GenericError
;
5401 GpStatus WINGDIPAPI
GdipGetEncoderParameterListSize(GpImage
*image
,
5402 GDIPCONST CLSID
* clsidEncoder
, UINT
*size
)
5406 TRACE("(%p,%s,%p)\n", image
, debugstr_guid(clsidEncoder
), size
);
5409 FIXME("not implemented\n");
5413 return NotImplemented
;
5416 static PixelFormat
get_16bpp_format(HBITMAP hbm
)
5422 hdc
= CreateCompatibleDC(NULL
);
5424 memset(&bmh
, 0, sizeof(bmh
));
5425 bmh
.bV4Size
= sizeof(bmh
);
5428 bmh
.bV4V4Compression
= BI_BITFIELDS
;
5429 bmh
.bV4BitCount
= 16;
5431 GetDIBits(hdc
, hbm
, 0, 0, NULL
, (BITMAPINFO
*)&bmh
, DIB_RGB_COLORS
);
5433 if (bmh
.bV4RedMask
== 0x7c00 &&
5434 bmh
.bV4GreenMask
== 0x3e0 &&
5435 bmh
.bV4BlueMask
== 0x1f)
5437 result
= PixelFormat16bppRGB555
;
5439 else if (bmh
.bV4RedMask
== 0xf800 &&
5440 bmh
.bV4GreenMask
== 0x7e0 &&
5441 bmh
.bV4BlueMask
== 0x1f)
5443 result
= PixelFormat16bppRGB565
;
5447 FIXME("unrecognized bitfields %lx,%lx,%lx\n", bmh
.bV4RedMask
,
5448 bmh
.bV4GreenMask
, bmh
.bV4BlueMask
);
5449 result
= PixelFormatUndefined
;
5457 /*****************************************************************************
5458 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
5460 GpStatus WINGDIPAPI
GdipCreateBitmapFromHBITMAP(HBITMAP hbm
, HPALETTE hpal
, GpBitmap
** bitmap
)
5465 BitmapData lockeddata
;
5466 char bmibuf
[FIELD_OFFSET(BITMAPINFO
, bmiColors
[256])];
5467 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
5469 TRACE("%p %p %p\n", hbm
, hpal
, bitmap
);
5472 return InvalidParameter
;
5474 if (GetObjectA(hbm
, sizeof(bm
), &bm
) != sizeof(bm
))
5475 return InvalidParameter
;
5477 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
5478 switch(bm
.bmBitsPixel
) {
5480 format
= PixelFormat1bppIndexed
;
5483 format
= PixelFormat4bppIndexed
;
5486 format
= PixelFormat8bppIndexed
;
5489 format
= get_16bpp_format(hbm
);
5490 if (format
== PixelFormatUndefined
)
5491 return InvalidParameter
;
5494 format
= PixelFormat24bppRGB
;
5497 format
= PixelFormat32bppRGB
;
5500 format
= PixelFormat48bppRGB
;
5503 FIXME("don't know how to handle %d bpp\n", bm
.bmBitsPixel
);
5504 return InvalidParameter
;
5507 retval
= GdipCreateBitmapFromScan0(bm
.bmWidth
, bm
.bmHeight
, 0,
5508 format
, NULL
, bitmap
);
5512 retval
= GdipBitmapLockBits(*bitmap
, NULL
, ImageLockModeWrite
,
5513 format
, &lockeddata
);
5519 hdc
= CreateCompatibleDC(NULL
);
5521 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
5522 pbmi
->bmiHeader
.biBitCount
= 0;
5524 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
5526 src_height
= abs(pbmi
->bmiHeader
.biHeight
);
5527 pbmi
->bmiHeader
.biHeight
= -src_height
;
5529 GetDIBits(hdc
, hbm
, 0, src_height
, lockeddata
.Scan0
, pbmi
, DIB_RGB_COLORS
);
5533 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
5536 /* According to the tests hpal is ignored */
5537 if (retval
== Ok
&& pbmi
->bmiHeader
.biBitCount
<= 8)
5539 ColorPalette
*palette
;
5540 int i
, num_palette_entries
;
5542 num_palette_entries
= pbmi
->bmiHeader
.biClrUsed
;
5543 if (!num_palette_entries
)
5544 num_palette_entries
= 1 << pbmi
->bmiHeader
.biBitCount
;
5546 palette
= heap_alloc_zero(sizeof(ColorPalette
) + sizeof(ARGB
) * (num_palette_entries
-1));
5548 retval
= OutOfMemory
;
5552 palette
->Count
= num_palette_entries
;
5554 for (i
=0; i
<num_palette_entries
; i
++)
5556 palette
->Entries
[i
] = 0xff000000 | pbmi
->bmiColors
[i
].rgbRed
<< 16 |
5557 pbmi
->bmiColors
[i
].rgbGreen
<< 8 | pbmi
->bmiColors
[i
].rgbBlue
;
5560 retval
= GdipSetImagePalette(&(*bitmap
)->image
, palette
);
5568 GdipDisposeImage(&(*bitmap
)->image
);
5576 /*****************************************************************************
5577 * GdipCreateEffect [GDIPLUS.@]
5579 GpStatus WINGDIPAPI
GdipCreateEffect(const GUID guid
, CGpEffect
**effect
)
5581 FIXME("(%s, %p): stub\n", debugstr_guid(&guid
), effect
);
5584 return InvalidParameter
;
5588 return NotImplemented
;
5591 /*****************************************************************************
5592 * GdipDeleteEffect [GDIPLUS.@]
5594 GpStatus WINGDIPAPI
GdipDeleteEffect(CGpEffect
*effect
)
5596 FIXME("(%p): stub\n", effect
);
5597 /* note: According to Jose Roca's GDI+ Docs, this is not implemented
5598 * in Windows's gdiplus */
5599 return NotImplemented
;
5602 /*****************************************************************************
5603 * GdipSetEffectParameters [GDIPLUS.@]
5605 GpStatus WINGDIPAPI
GdipSetEffectParameters(CGpEffect
*effect
,
5606 const VOID
*params
, const UINT size
)
5610 TRACE("(%p,%p,%u)\n", effect
, params
, size
);
5613 FIXME("not implemented\n");
5615 return NotImplemented
;
5618 /*****************************************************************************
5619 * GdipGetImageFlags [GDIPLUS.@]
5621 GpStatus WINGDIPAPI
GdipGetImageFlags(GpImage
*image
, UINT
*flags
)
5623 TRACE("%p %p\n", image
, flags
);
5625 if(!image
|| !flags
)
5626 return InvalidParameter
;
5628 *flags
= image
->flags
;
5633 GpStatus WINGDIPAPI
GdipTestControl(GpTestControlEnum control
, void *param
)
5635 TRACE("(%d, %p)\n", control
, param
);
5638 case TestControlForceBilinear
:
5640 FIXME("TestControlForceBilinear not handled\n");
5642 case TestControlNoICM
:
5644 FIXME("TestControlNoICM not handled\n");
5646 case TestControlGetBuildNumber
:
5647 *((DWORD
*)param
) = 3102;
5654 GpStatus WINGDIPAPI
GdipImageForceValidation(GpImage
*image
)
5656 TRACE("%p\n", image
);
5661 /*****************************************************************************
5662 * GdipGetImageThumbnail [GDIPLUS.@]
5664 GpStatus WINGDIPAPI
GdipGetImageThumbnail(GpImage
*image
, UINT width
, UINT height
,
5665 GpImage
**ret_image
, GetThumbnailImageAbort cb
,
5669 GpGraphics
*graphics
;
5670 UINT srcwidth
, srcheight
;
5672 TRACE("(%p %u %u %p %p %p)\n",
5673 image
, width
, height
, ret_image
, cb
, cb_data
);
5675 if (!image
|| !ret_image
)
5676 return InvalidParameter
;
5678 if (!width
) width
= 120;
5679 if (!height
) height
= 120;
5681 GdipGetImageWidth(image
, &srcwidth
);
5682 GdipGetImageHeight(image
, &srcheight
);
5684 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat32bppPARGB
,
5685 NULL
, (GpBitmap
**)ret_image
);
5689 stat
= GdipGetImageGraphicsContext(*ret_image
, &graphics
);
5693 stat
= GdipDrawImageRectRectI(graphics
, image
,
5694 0, 0, width
, height
, 0, 0, srcwidth
, srcheight
, UnitPixel
,
5697 GdipDeleteGraphics(graphics
);
5702 GdipDisposeImage(*ret_image
);
5710 /*****************************************************************************
5711 * GdipImageRotateFlip [GDIPLUS.@]
5713 GpStatus WINGDIPAPI
GdipImageRotateFlip(GpImage
*image
, RotateFlipType type
)
5715 GpBitmap
*new_bitmap
;
5717 int bpp
, bytesperpixel
;
5718 BOOL rotate_90
, flip_x
, flip_y
;
5719 int src_x_offset
, src_y_offset
;
5721 UINT x
, y
, width
, height
;
5722 BitmapData dst_lock
;
5725 TRACE("(%p, %u)\n", image
, type
);
5728 return InvalidParameter
;
5729 if (!image_lock(image
))
5733 flip_x
= (type
&6) == 2 || (type
&6) == 4;
5734 flip_y
= (type
&3) == 1 || (type
&3) == 2;
5736 if (image
->type
!= ImageTypeBitmap
)
5738 FIXME("Not implemented for type %i\n", image
->type
);
5739 image_unlock(image
);
5740 return NotImplemented
;
5743 bitmap
= (GpBitmap
*)image
;
5744 bpp
= PIXELFORMATBPP(bitmap
->format
);
5748 FIXME("Not implemented for %i bit images\n", bpp
);
5749 image_unlock(image
);
5750 return NotImplemented
;
5755 width
= bitmap
->height
;
5756 height
= bitmap
->width
;
5760 width
= bitmap
->width
;
5761 height
= bitmap
->height
;
5764 bytesperpixel
= bpp
/8;
5766 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, bitmap
->format
, NULL
, &new_bitmap
);
5770 stat
= GdipBitmapLockBits(new_bitmap
, NULL
, ImageLockModeWrite
, bitmap
->format
, &dst_lock
);
5774 LPBYTE src_row
, src_pixel
;
5775 LPBYTE dst_row
, dst_pixel
;
5777 src_origin
= bitmap
->bits
;
5778 if (flip_x
) src_origin
+= bytesperpixel
* (bitmap
->width
- 1);
5779 if (flip_y
) src_origin
+= bitmap
->stride
* (bitmap
->height
- 1);
5783 if (flip_y
) src_x_offset
= -bitmap
->stride
;
5784 else src_x_offset
= bitmap
->stride
;
5785 if (flip_x
) src_y_offset
= -bytesperpixel
;
5786 else src_y_offset
= bytesperpixel
;
5790 if (flip_x
) src_x_offset
= -bytesperpixel
;
5791 else src_x_offset
= bytesperpixel
;
5792 if (flip_y
) src_y_offset
= -bitmap
->stride
;
5793 else src_y_offset
= bitmap
->stride
;
5796 src_row
= src_origin
;
5797 dst_row
= dst_lock
.Scan0
;
5798 for (y
=0; y
<height
; y
++)
5800 src_pixel
= src_row
;
5801 dst_pixel
= dst_row
;
5802 for (x
=0; x
<width
; x
++)
5804 /* FIXME: This could probably be faster without memcpy. */
5805 memcpy(dst_pixel
, src_pixel
, bytesperpixel
);
5806 dst_pixel
+= bytesperpixel
;
5807 src_pixel
+= src_x_offset
;
5809 src_row
+= src_y_offset
;
5810 dst_row
+= dst_lock
.Stride
;
5813 GdipBitmapUnlockBits(new_bitmap
, &dst_lock
);
5814 move_bitmap(bitmap
, new_bitmap
, FALSE
);
5816 else GdipDisposeImage(&new_bitmap
->image
);
5819 image_unlock(image
);
5823 /*****************************************************************************
5824 * GdipImageSetAbort [GDIPLUS.@]
5826 GpStatus WINGDIPAPI
GdipImageSetAbort(GpImage
*image
, GdiplusAbort
*pabort
)
5828 TRACE("(%p, %p)\n", image
, pabort
);
5831 return InvalidParameter
;
5834 FIXME("Abort callback is not supported.\n");
5839 /*****************************************************************************
5840 * GdipBitmapConvertFormat [GDIPLUS.@]
5842 GpStatus WINGDIPAPI
GdipBitmapConvertFormat(GpBitmap
*bitmap
, PixelFormat format
, DitherType dithertype
,
5843 PaletteType palettetype
, ColorPalette
*palette
, REAL alphathreshold
)
5845 FIXME("(%p, 0x%08x, %d, %d, %p, %f): stub\n", bitmap
, format
, dithertype
, palettetype
, palette
, alphathreshold
);
5846 return NotImplemented
;
5849 static void set_histogram_point_argb(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5851 ch0
[ color
>> 24 ]++;
5852 ch1
[(color
>> 16) & 0xff]++;
5853 ch2
[(color
>> 8) & 0xff]++;
5854 ch3
[ color
& 0xff]++;
5857 static void set_histogram_point_pargb(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5859 BYTE alpha
= color
>> 24;
5862 ch1
[(((color
>> 16) & 0xff) * alpha
) / 0xff]++;
5863 ch2
[(((color
>> 8) & 0xff) * alpha
) / 0xff]++;
5864 ch3
[(( color
& 0xff) * alpha
) / 0xff]++;
5867 static void set_histogram_point_rgb(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5869 ch0
[(color
>> 16) & 0xff]++;
5870 ch1
[(color
>> 8) & 0xff]++;
5871 ch2
[ color
& 0xff]++;
5874 static void set_histogram_point_gray(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5876 ch0
[(76 * ((color
>> 16) & 0xff) + 150 * ((color
>> 8) & 0xff) + 29 * (color
& 0xff)) / 0xff]++;
5879 static void set_histogram_point_b(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5881 ch0
[color
& 0xff]++;
5884 static void set_histogram_point_g(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5886 ch0
[(color
>> 8) & 0xff]++;
5889 static void set_histogram_point_r(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5891 ch0
[(color
>> 16) & 0xff]++;
5894 static void set_histogram_point_a(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5896 ch0
[(color
>> 24) & 0xff]++;
5899 /*****************************************************************************
5900 * GdipBitmapGetHistogram [GDIPLUS.@]
5902 GpStatus WINGDIPAPI
GdipBitmapGetHistogram(GpBitmap
*bitmap
, HistogramFormat format
, UINT num_of_entries
,
5903 UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5905 static void (* const set_histogram_point
[])(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
) =
5907 set_histogram_point_argb
,
5908 set_histogram_point_pargb
,
5909 set_histogram_point_rgb
,
5910 set_histogram_point_gray
,
5911 set_histogram_point_b
,
5912 set_histogram_point_g
,
5913 set_histogram_point_r
,
5914 set_histogram_point_a
,
5916 UINT width
, height
, x
, y
;
5918 TRACE("(%p, %d, %u, %p, %p, %p, %p)\n", bitmap
, format
, num_of_entries
,
5919 ch0
, ch1
, ch2
, ch3
);
5921 if (!bitmap
|| num_of_entries
!= 256)
5922 return InvalidParameter
;
5924 /* Make sure passed channel pointers match requested format */
5927 case HistogramFormatARGB
:
5928 case HistogramFormatPARGB
:
5929 if (!ch0
|| !ch1
|| !ch2
|| !ch3
)
5930 return InvalidParameter
;
5931 memset(ch0
, 0, num_of_entries
* sizeof(UINT
));
5932 memset(ch1
, 0, num_of_entries
* sizeof(UINT
));
5933 memset(ch2
, 0, num_of_entries
* sizeof(UINT
));
5934 memset(ch3
, 0, num_of_entries
* sizeof(UINT
));
5936 case HistogramFormatRGB
:
5937 if (!ch0
|| !ch1
|| !ch2
|| ch3
)
5938 return InvalidParameter
;
5939 memset(ch0
, 0, num_of_entries
* sizeof(UINT
));
5940 memset(ch1
, 0, num_of_entries
* sizeof(UINT
));
5941 memset(ch2
, 0, num_of_entries
* sizeof(UINT
));
5943 case HistogramFormatGray
:
5944 case HistogramFormatB
:
5945 case HistogramFormatG
:
5946 case HistogramFormatR
:
5947 case HistogramFormatA
:
5948 if (!ch0
|| ch1
|| ch2
|| ch3
)
5949 return InvalidParameter
;
5950 memset(ch0
, 0, num_of_entries
* sizeof(UINT
));
5953 WARN("Invalid histogram format requested, %d\n", format
);
5954 return InvalidParameter
;
5957 GdipGetImageWidth(&bitmap
->image
, &width
);
5958 GdipGetImageHeight(&bitmap
->image
, &height
);
5960 for (y
= 0; y
< height
; y
++)
5961 for (x
= 0; x
< width
; x
++)
5965 GdipBitmapGetPixel(bitmap
, x
, y
, &color
);
5966 set_histogram_point
[format
](color
, ch0
, ch1
, ch2
, ch3
);
5972 /*****************************************************************************
5973 * GdipBitmapGetHistogramSize [GDIPLUS.@]
5975 GpStatus WINGDIPAPI
GdipBitmapGetHistogramSize(HistogramFormat format
, UINT
*num_of_entries
)
5977 TRACE("(%d, %p)\n", format
, num_of_entries
);
5979 if (!num_of_entries
)
5980 return InvalidParameter
;
5982 *num_of_entries
= 256;
5986 static GpStatus
create_optimal_palette(ColorPalette
*palette
, INT desired
,
5987 BOOL transparent
, GpBitmap
*bitmap
)
5992 IWICImagingFactory
*factory
;
5993 IWICPalette
*wic_palette
;
5995 if (!bitmap
) return InvalidParameter
;
5996 if (palette
->Count
< desired
) return GenericError
;
5998 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat24bppRGB
, &data
);
5999 if (status
!= Ok
) return status
;
6001 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
6004 GdipBitmapUnlockBits(bitmap
, &data
);
6005 return hresult_to_status(hr
);
6008 hr
= IWICImagingFactory_CreatePalette(factory
, &wic_palette
);
6013 /* PixelFormat24bppRGB actually stores the bitmap bits as BGR. */
6014 hr
= IWICImagingFactory_CreateBitmapFromMemory(factory
, data
.Width
, data
.Height
,
6015 &GUID_WICPixelFormat24bppBGR
, data
.Stride
, data
.Stride
* data
.Width
, data
.Scan0
, &bitmap
);
6018 hr
= IWICPalette_InitializeFromBitmap(wic_palette
, (IWICBitmapSource
*)bitmap
, desired
, transparent
);
6022 IWICPalette_GetColorCount(wic_palette
, &palette
->Count
);
6023 IWICPalette_GetColors(wic_palette
, palette
->Count
, (UINT
*)palette
->Entries
, &palette
->Count
);
6026 IWICBitmap_Release(bitmap
);
6029 IWICPalette_Release(wic_palette
);
6032 IWICImagingFactory_Release(factory
);
6033 GdipBitmapUnlockBits(bitmap
, &data
);
6035 return hresult_to_status(hr
);
6038 /*****************************************************************************
6039 * GdipInitializePalette [GDIPLUS.@]
6041 GpStatus WINGDIPAPI
GdipInitializePalette(ColorPalette
*palette
,
6042 PaletteType type
, INT desired
, BOOL transparent
, GpBitmap
*bitmap
)
6044 TRACE("(%p,%d,%d,%d,%p)\n", palette
, type
, desired
, transparent
, bitmap
);
6046 if (!palette
) return InvalidParameter
;
6050 case PaletteTypeCustom
:
6053 case PaletteTypeOptimal
:
6054 return create_optimal_palette(palette
, desired
, transparent
, bitmap
);
6056 /* WIC palette type enumeration matches these gdiplus enums */
6057 case PaletteTypeFixedBW
:
6058 case PaletteTypeFixedHalftone8
:
6059 case PaletteTypeFixedHalftone27
:
6060 case PaletteTypeFixedHalftone64
:
6061 case PaletteTypeFixedHalftone125
:
6062 case PaletteTypeFixedHalftone216
:
6063 case PaletteTypeFixedHalftone252
:
6064 case PaletteTypeFixedHalftone256
:
6066 ColorPalette
*wic_palette
;
6067 GpStatus status
= Ok
;
6069 wic_palette
= get_palette(NULL
, type
);
6070 if (!wic_palette
) return OutOfMemory
;
6072 if (palette
->Count
>= wic_palette
->Count
)
6074 palette
->Flags
= wic_palette
->Flags
;
6075 palette
->Count
= wic_palette
->Count
;
6076 memcpy(palette
->Entries
, wic_palette
->Entries
, wic_palette
->Count
* sizeof(wic_palette
->Entries
[0]));
6079 status
= GenericError
;
6081 heap_free(wic_palette
);
6087 FIXME("unknown palette type %d\n", type
);
6091 return InvalidParameter
;