2 * Copyright (C) 2007 Google (Evan Stade)
3 * Copyright (C) 2012,2016 Dmitry Timoshkov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define NONAMELESSUNION
38 #include "gdiplus_private.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
43 HRESULT WINAPI
WICCreateImagingFactory_Proxy(UINT
, IWICImagingFactory
**);
45 #define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
46 #define WMF_PLACEABLE_KEY 0x9ac6cdd7
50 const WICPixelFormatGUID
*wic_format
;
51 PixelFormat gdip_format
;
52 /* predefined palette type to use for pixel format conversions */
53 WICBitmapPaletteType palette_type
;
56 { &GUID_WICPixelFormat1bppIndexed
, PixelFormat1bppIndexed
, WICBitmapPaletteTypeFixedBW
},
57 { &GUID_WICPixelFormatBlackWhite
, PixelFormat1bppIndexed
, WICBitmapPaletteTypeFixedBW
},
58 { &GUID_WICPixelFormat4bppIndexed
, PixelFormat4bppIndexed
, WICBitmapPaletteTypeFixedHalftone8
},
59 { &GUID_WICPixelFormat8bppIndexed
, PixelFormat8bppIndexed
, WICBitmapPaletteTypeFixedHalftone256
},
60 { &GUID_WICPixelFormat8bppGray
, PixelFormat8bppIndexed
, WICBitmapPaletteTypeFixedGray256
},
61 { &GUID_WICPixelFormat16bppBGR555
, PixelFormat16bppRGB555
, 0 },
62 { &GUID_WICPixelFormat24bppBGR
, PixelFormat24bppRGB
, 0 },
63 { &GUID_WICPixelFormat32bppBGR
, PixelFormat32bppRGB
, 0 },
64 { &GUID_WICPixelFormat32bppBGRA
, PixelFormat32bppARGB
, 0 },
65 { &GUID_WICPixelFormat32bppPBGRA
, PixelFormat32bppPARGB
, 0 },
69 static ColorPalette
*get_palette(IWICBitmapFrameDecode
*frame
, WICBitmapPaletteType palette_type
)
72 IWICImagingFactory
*factory
;
73 IWICPalette
*wic_palette
;
74 ColorPalette
*palette
= NULL
;
76 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
77 if (hr
!= S_OK
) return NULL
;
79 hr
= IWICImagingFactory_CreatePalette(factory
, &wic_palette
);
82 hr
= WINCODEC_ERR_PALETTEUNAVAILABLE
;
84 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, wic_palette
);
85 if (hr
!= S_OK
&& palette_type
!= 0)
87 TRACE("using predefined palette %#x\n", palette_type
);
88 hr
= IWICPalette_InitializePredefined(wic_palette
, palette_type
, FALSE
);
92 WICBitmapPaletteType type
;
96 IWICPalette_GetColorCount(wic_palette
, &count
);
97 palette
= heap_alloc(2 * sizeof(UINT
) + count
* sizeof(ARGB
));
98 IWICPalette_GetColors(wic_palette
, count
, (UINT
*)palette
->Entries
, &palette
->Count
);
100 IWICPalette_GetType(wic_palette
, &type
);
102 case WICBitmapPaletteTypeFixedGray4
:
103 case WICBitmapPaletteTypeFixedGray16
:
104 case WICBitmapPaletteTypeFixedGray256
:
105 palette
->Flags
= PaletteFlagsGrayScale
;
107 case WICBitmapPaletteTypeFixedHalftone8
:
108 case WICBitmapPaletteTypeFixedHalftone27
:
109 case WICBitmapPaletteTypeFixedHalftone64
:
110 case WICBitmapPaletteTypeFixedHalftone125
:
111 case WICBitmapPaletteTypeFixedHalftone216
:
112 case WICBitmapPaletteTypeFixedHalftone252
:
113 case WICBitmapPaletteTypeFixedHalftone256
:
114 palette
->Flags
= PaletteFlagsHalftone
;
119 IWICPalette_HasAlpha(wic_palette
, &alpha
);
121 palette
->Flags
|= PaletteFlagsHasAlpha
;
123 IWICPalette_Release(wic_palette
);
125 IWICImagingFactory_Release(factory
);
129 static HRESULT
set_palette(IWICBitmapFrameEncode
*frame
, ColorPalette
*palette
)
132 IWICImagingFactory
*factory
;
133 IWICPalette
*wic_palette
;
135 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
139 hr
= IWICImagingFactory_CreatePalette(factory
, &wic_palette
);
140 IWICImagingFactory_Release(factory
);
143 hr
= IWICPalette_InitializeCustom(wic_palette
, (UINT
*)palette
->Entries
, palette
->Count
);
146 hr
= IWICBitmapFrameEncode_SetPalette(frame
, wic_palette
);
148 IWICPalette_Release(wic_palette
);
154 GpStatus WINGDIPAPI
GdipBitmapApplyEffect(GpBitmap
* bitmap
, CGpEffect
* effect
,
155 RECT
* roi
, BOOL useAuxData
, VOID
** auxData
, INT
* auxDataSize
)
157 FIXME("(%p %p %p %d %p %p): stub\n", bitmap
, effect
, roi
, useAuxData
, auxData
, auxDataSize
);
159 * Note: According to Jose Roca's GDI+ docs, this function is not
160 * implemented in Windows's GDI+.
162 return NotImplemented
;
165 GpStatus WINGDIPAPI
GdipBitmapCreateApplyEffect(GpBitmap
** inputBitmaps
,
166 INT numInputs
, CGpEffect
* effect
, RECT
* roi
, RECT
* outputRect
,
167 GpBitmap
** outputBitmap
, BOOL useAuxData
, VOID
** auxData
, INT
* auxDataSize
)
169 FIXME("(%p %d %p %p %p %p %d %p %p): stub\n", inputBitmaps
, numInputs
, effect
, roi
, outputRect
, outputBitmap
, useAuxData
, auxData
, auxDataSize
);
171 * Note: According to Jose Roca's GDI+ docs, this function is not
172 * implemented in Windows's GDI+.
174 return NotImplemented
;
177 static inline void getpixel_1bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
179 *index
= (row
[x
/8]>>(7-x
%8)) & 1;
182 static inline void getpixel_4bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
185 *index
= row
[x
/2]&0xf;
187 *index
= row
[x
/2]>>4;
190 static inline void getpixel_8bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
195 static inline void getpixel_16bppGrayScale(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
196 const BYTE
*row
, UINT x
)
198 *r
= *g
= *b
= row
[x
*2+1];
202 static inline void getpixel_16bppRGB555(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
203 const BYTE
*row
, UINT x
)
205 WORD pixel
= *((const WORD
*)(row
)+x
);
206 *r
= (pixel
>>7&0xf8)|(pixel
>>12&0x7);
207 *g
= (pixel
>>2&0xf8)|(pixel
>>6&0x7);
208 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
212 static inline void getpixel_16bppRGB565(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
213 const BYTE
*row
, UINT x
)
215 WORD pixel
= *((const WORD
*)(row
)+x
);
216 *r
= (pixel
>>8&0xf8)|(pixel
>>13&0x7);
217 *g
= (pixel
>>3&0xfc)|(pixel
>>9&0x3);
218 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
222 static inline void getpixel_16bppARGB1555(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
223 const BYTE
*row
, UINT x
)
225 WORD pixel
= *((const WORD
*)(row
)+x
);
226 *r
= (pixel
>>7&0xf8)|(pixel
>>12&0x7);
227 *g
= (pixel
>>2&0xf8)|(pixel
>>6&0x7);
228 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
229 if ((pixel
&0x8000) == 0x8000)
235 static inline void getpixel_24bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
236 const BYTE
*row
, UINT x
)
244 static inline void getpixel_32bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
245 const BYTE
*row
, UINT x
)
253 static inline void getpixel_32bppARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
254 const BYTE
*row
, UINT x
)
262 static inline void getpixel_32bppPARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
263 const BYTE
*row
, UINT x
)
274 DWORD scaled_q
= (255 << 15) / *a
;
275 *r
= (row
[x
*4+2] > *a
) ? 0xff : (row
[x
*4+2] * scaled_q
) >> 15;
276 *g
= (row
[x
*4+1] > *a
) ? 0xff : (row
[x
*4+1] * scaled_q
) >> 15;
277 *b
= (row
[x
*4] > *a
) ? 0xff : (row
[x
*4] * scaled_q
) >> 15;
281 static inline void getpixel_48bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
282 const BYTE
*row
, UINT x
)
290 static inline void getpixel_64bppARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
291 const BYTE
*row
, UINT x
)
299 static inline void getpixel_64bppPARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
300 const BYTE
*row
, UINT x
)
307 *r
= row
[x
*8+5] * 255 / *a
;
308 *g
= row
[x
*8+3] * 255 / *a
;
309 *b
= row
[x
*8+1] * 255 / *a
;
313 GpStatus WINGDIPAPI
GdipBitmapGetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
320 if(!bitmap
|| !color
||
321 x
< 0 || y
< 0 || x
>= bitmap
->width
|| y
>= bitmap
->height
)
322 return InvalidParameter
;
324 row
= bitmap
->bits
+bitmap
->stride
*y
;
326 switch (bitmap
->format
)
328 case PixelFormat1bppIndexed
:
329 getpixel_1bppIndexed(&index
,row
,x
);
331 case PixelFormat4bppIndexed
:
332 getpixel_4bppIndexed(&index
,row
,x
);
334 case PixelFormat8bppIndexed
:
335 getpixel_8bppIndexed(&index
,row
,x
);
337 case PixelFormat16bppGrayScale
:
338 getpixel_16bppGrayScale(&r
,&g
,&b
,&a
,row
,x
);
340 case PixelFormat16bppRGB555
:
341 getpixel_16bppRGB555(&r
,&g
,&b
,&a
,row
,x
);
343 case PixelFormat16bppRGB565
:
344 getpixel_16bppRGB565(&r
,&g
,&b
,&a
,row
,x
);
346 case PixelFormat16bppARGB1555
:
347 getpixel_16bppARGB1555(&r
,&g
,&b
,&a
,row
,x
);
349 case PixelFormat24bppRGB
:
350 getpixel_24bppRGB(&r
,&g
,&b
,&a
,row
,x
);
352 case PixelFormat32bppRGB
:
353 getpixel_32bppRGB(&r
,&g
,&b
,&a
,row
,x
);
355 case PixelFormat32bppARGB
:
356 getpixel_32bppARGB(&r
,&g
,&b
,&a
,row
,x
);
358 case PixelFormat32bppPARGB
:
359 getpixel_32bppPARGB(&r
,&g
,&b
,&a
,row
,x
);
361 case PixelFormat48bppRGB
:
362 getpixel_48bppRGB(&r
,&g
,&b
,&a
,row
,x
);
364 case PixelFormat64bppARGB
:
365 getpixel_64bppARGB(&r
,&g
,&b
,&a
,row
,x
);
367 case PixelFormat64bppPARGB
:
368 getpixel_64bppPARGB(&r
,&g
,&b
,&a
,row
,x
);
371 FIXME("not implemented for format 0x%x\n", bitmap
->format
);
372 return NotImplemented
;
375 if (bitmap
->format
& PixelFormatIndexed
)
376 *color
= bitmap
->image
.palette
->Entries
[index
];
378 *color
= a
<<24|r
<<16|g
<<8|b
;
383 static unsigned int absdiff(unsigned int x
, unsigned int y
)
385 return x
> y
? x
- y
: y
- x
;
388 static inline UINT
get_palette_index(BYTE r
, BYTE g
, BYTE b
, BYTE a
, ColorPalette
*palette
)
391 int best_distance
= 0x7fff;
395 if (!palette
) return 0;
396 /* This algorithm scans entire palette,
397 computes difference from desired color (all color components have equal weight)
398 and returns the index of color with least difference.
400 Note: Maybe it could be replaced with a better algorithm for better image quality
401 and performance, though better algorithm would probably need some pre-built lookup
402 tables and thus may actually be slower if this method is called only few times per
405 for(i
=0;i
<palette
->Count
;i
++) {
406 ARGB color
=palette
->Entries
[i
];
407 distance
=absdiff(b
, color
& 0xff) + absdiff(g
, color
>>8 & 0xff) + absdiff(r
, color
>>16 & 0xff) + absdiff(a
, color
>>24 & 0xff);
408 if (distance
<best_distance
) {
409 best_distance
=distance
;
416 static inline void setpixel_8bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
417 BYTE
*row
, UINT x
, ColorPalette
*palette
)
419 BYTE index
= get_palette_index(r
,g
,b
,a
,palette
);
423 static inline void setpixel_1bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
424 BYTE
*row
, UINT x
, ColorPalette
*palette
)
426 row
[x
/8] = (row
[x
/8] & ~(1<<(7-x
%8))) | (get_palette_index(r
,g
,b
,a
,palette
)<<(7-x
%8));
429 static inline void setpixel_4bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
430 BYTE
*row
, UINT x
, ColorPalette
*palette
)
433 row
[x
/2] = (row
[x
/2] & 0xf0) | get_palette_index(r
,g
,b
,a
,palette
);
435 row
[x
/2] = (row
[x
/2] & 0x0f) | get_palette_index(r
,g
,b
,a
,palette
)<<4;
438 static inline void setpixel_16bppGrayScale(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
441 *((WORD
*)(row
)+x
) = (r
+g
+b
)*85;
444 static inline void setpixel_16bppRGB555(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
447 *((WORD
*)(row
)+x
) = (r
<<7&0x7c00)|
452 static inline void setpixel_16bppRGB565(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
455 *((WORD
*)(row
)+x
) = (r
<<8&0xf800)|
460 static inline void setpixel_16bppARGB1555(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
463 *((WORD
*)(row
)+x
) = (a
<<8&0x8000)|
469 static inline void setpixel_24bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
477 static inline void setpixel_32bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
480 *((DWORD
*)(row
)+x
) = (r
<<16)|(g
<<8)|b
;
483 static inline void setpixel_32bppARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
486 *((DWORD
*)(row
)+x
) = (a
<<24)|(r
<<16)|(g
<<8)|b
;
489 static inline void setpixel_32bppPARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
492 r
= (r
* a
+ 127) / 255;
493 g
= (g
* a
+ 127) / 255;
494 b
= (b
* a
+ 127) / 255;
495 *((DWORD
*)(row
)+x
) = (a
<<24)|(r
<<16)|(g
<<8)|b
;
498 static inline void setpixel_48bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
501 row
[x
*6+5] = row
[x
*6+4] = r
;
502 row
[x
*6+3] = row
[x
*6+2] = g
;
503 row
[x
*6+1] = row
[x
*6] = b
;
506 static inline void setpixel_64bppARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
509 UINT64 a64
=a
, r64
=r
, g64
=g
, b64
=b
;
510 *((UINT64
*)(row
)+x
) = (a64
<<56)|(a64
<<48)|(r64
<<40)|(r64
<<32)|(g64
<<24)|(g64
<<16)|(b64
<<8)|b64
;
513 static inline void setpixel_64bppPARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
516 UINT64 a64
, r64
, g64
, b64
;
521 *((UINT64
*)(row
)+x
) = (a64
<<48)|(r64
<<32)|(g64
<<16)|b64
;
524 GpStatus WINGDIPAPI
GdipBitmapSetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
530 if(!bitmap
|| x
< 0 || y
< 0 || x
>= bitmap
->width
|| y
>= bitmap
->height
)
531 return InvalidParameter
;
538 row
= bitmap
->bits
+ bitmap
->stride
* y
;
540 switch (bitmap
->format
)
542 case PixelFormat16bppGrayScale
:
543 setpixel_16bppGrayScale(r
,g
,b
,a
,row
,x
);
545 case PixelFormat16bppRGB555
:
546 setpixel_16bppRGB555(r
,g
,b
,a
,row
,x
);
548 case PixelFormat16bppRGB565
:
549 setpixel_16bppRGB565(r
,g
,b
,a
,row
,x
);
551 case PixelFormat16bppARGB1555
:
552 setpixel_16bppARGB1555(r
,g
,b
,a
,row
,x
);
554 case PixelFormat24bppRGB
:
555 setpixel_24bppRGB(r
,g
,b
,a
,row
,x
);
557 case PixelFormat32bppRGB
:
558 setpixel_32bppRGB(r
,g
,b
,a
,row
,x
);
560 case PixelFormat32bppARGB
:
561 setpixel_32bppARGB(r
,g
,b
,a
,row
,x
);
563 case PixelFormat32bppPARGB
:
564 setpixel_32bppPARGB(r
,g
,b
,a
,row
,x
);
566 case PixelFormat48bppRGB
:
567 setpixel_48bppRGB(r
,g
,b
,a
,row
,x
);
569 case PixelFormat64bppARGB
:
570 setpixel_64bppARGB(r
,g
,b
,a
,row
,x
);
572 case PixelFormat64bppPARGB
:
573 setpixel_64bppPARGB(r
,g
,b
,a
,row
,x
);
575 case PixelFormat8bppIndexed
:
576 setpixel_8bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
578 case PixelFormat4bppIndexed
:
579 setpixel_4bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
581 case PixelFormat1bppIndexed
:
582 setpixel_1bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
585 FIXME("not implemented for format 0x%x\n", bitmap
->format
);
586 return NotImplemented
;
592 GpStatus
convert_pixels(INT width
, INT height
,
593 INT dst_stride
, BYTE
*dst_bits
, PixelFormat dst_format
,
594 ColorPalette
*dst_palette
,
595 INT src_stride
, const BYTE
*src_bits
, PixelFormat src_format
,
596 ColorPalette
*src_palette
)
600 if (src_format
== dst_format
||
601 (dst_format
== PixelFormat32bppRGB
&& PIXELFORMATBPP(src_format
) == 32))
603 UINT widthbytes
= PIXELFORMATBPP(src_format
) * width
/ 8;
604 for (y
=0; y
<height
; y
++)
605 memcpy(dst_bits
+dst_stride
*y
, src_bits
+src_stride
*y
, widthbytes
);
609 #define convert_indexed_to_rgb(getpixel_function, setpixel_function) do { \
610 for (y=0; y<height; y++) \
611 for (x=0; x<width; x++) { \
614 BYTE *color = (BYTE *)&argb; \
615 getpixel_function(&index, src_bits+src_stride*y, x); \
616 argb = (src_palette && index < src_palette->Count) ? src_palette->Entries[index] : 0; \
617 setpixel_function(color[2], color[1], color[0], color[3], dst_bits+dst_stride*y, x); \
622 #define convert_rgb_to_rgb(getpixel_function, setpixel_function) do { \
623 for (y=0; y<height; y++) \
624 for (x=0; x<width; x++) { \
626 getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
627 setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x); \
632 #define convert_rgb_to_indexed(getpixel_function, setpixel_function) do { \
633 for (y=0; y<height; y++) \
634 for (x=0; x<width; x++) { \
636 getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
637 setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x, dst_palette); \
644 case PixelFormat1bppIndexed
:
647 case PixelFormat16bppGrayScale
:
648 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppGrayScale
);
649 case PixelFormat16bppRGB555
:
650 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppRGB555
);
651 case PixelFormat16bppRGB565
:
652 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppRGB565
);
653 case PixelFormat16bppARGB1555
:
654 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppARGB1555
);
655 case PixelFormat24bppRGB
:
656 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_24bppRGB
);
657 case PixelFormat32bppRGB
:
658 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppRGB
);
659 case PixelFormat32bppARGB
:
660 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppARGB
);
661 case PixelFormat32bppPARGB
:
662 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppPARGB
);
663 case PixelFormat48bppRGB
:
664 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_48bppRGB
);
665 case PixelFormat64bppARGB
:
666 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_64bppARGB
);
671 case PixelFormat4bppIndexed
:
674 case PixelFormat16bppGrayScale
:
675 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppGrayScale
);
676 case PixelFormat16bppRGB555
:
677 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppRGB555
);
678 case PixelFormat16bppRGB565
:
679 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppRGB565
);
680 case PixelFormat16bppARGB1555
:
681 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppARGB1555
);
682 case PixelFormat24bppRGB
:
683 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_24bppRGB
);
684 case PixelFormat32bppRGB
:
685 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppRGB
);
686 case PixelFormat32bppARGB
:
687 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppARGB
);
688 case PixelFormat32bppPARGB
:
689 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppPARGB
);
690 case PixelFormat48bppRGB
:
691 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_48bppRGB
);
692 case PixelFormat64bppARGB
:
693 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_64bppARGB
);
698 case PixelFormat8bppIndexed
:
701 case PixelFormat16bppGrayScale
:
702 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppGrayScale
);
703 case PixelFormat16bppRGB555
:
704 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppRGB555
);
705 case PixelFormat16bppRGB565
:
706 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppRGB565
);
707 case PixelFormat16bppARGB1555
:
708 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppARGB1555
);
709 case PixelFormat24bppRGB
:
710 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_24bppRGB
);
711 case PixelFormat32bppRGB
:
712 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppRGB
);
713 case PixelFormat32bppARGB
:
714 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppARGB
);
715 case PixelFormat32bppPARGB
:
716 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppPARGB
);
717 case PixelFormat48bppRGB
:
718 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_48bppRGB
);
719 case PixelFormat64bppARGB
:
720 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_64bppARGB
);
725 case PixelFormat16bppGrayScale
:
728 case PixelFormat1bppIndexed
:
729 convert_rgb_to_indexed(getpixel_16bppGrayScale
, setpixel_1bppIndexed
);
730 case PixelFormat4bppIndexed
:
731 convert_rgb_to_indexed(getpixel_16bppGrayScale
, setpixel_4bppIndexed
);
732 case PixelFormat8bppIndexed
:
733 convert_rgb_to_indexed(getpixel_16bppGrayScale
, setpixel_8bppIndexed
);
734 case PixelFormat16bppRGB555
:
735 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppRGB555
);
736 case PixelFormat16bppRGB565
:
737 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppRGB565
);
738 case PixelFormat16bppARGB1555
:
739 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppARGB1555
);
740 case PixelFormat24bppRGB
:
741 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_24bppRGB
);
742 case PixelFormat32bppRGB
:
743 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppRGB
);
744 case PixelFormat32bppARGB
:
745 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppARGB
);
746 case PixelFormat32bppPARGB
:
747 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppPARGB
);
748 case PixelFormat48bppRGB
:
749 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_48bppRGB
);
750 case PixelFormat64bppARGB
:
751 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_64bppARGB
);
756 case PixelFormat16bppRGB555
:
759 case PixelFormat1bppIndexed
:
760 convert_rgb_to_indexed(getpixel_16bppRGB555
, setpixel_1bppIndexed
);
761 case PixelFormat4bppIndexed
:
762 convert_rgb_to_indexed(getpixel_16bppRGB555
, setpixel_4bppIndexed
);
763 case PixelFormat8bppIndexed
:
764 convert_rgb_to_indexed(getpixel_16bppRGB555
, setpixel_8bppIndexed
);
765 case PixelFormat16bppGrayScale
:
766 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppGrayScale
);
767 case PixelFormat16bppRGB565
:
768 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppRGB565
);
769 case PixelFormat16bppARGB1555
:
770 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppARGB1555
);
771 case PixelFormat24bppRGB
:
772 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_24bppRGB
);
773 case PixelFormat32bppRGB
:
774 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppRGB
);
775 case PixelFormat32bppARGB
:
776 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppARGB
);
777 case PixelFormat32bppPARGB
:
778 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppPARGB
);
779 case PixelFormat48bppRGB
:
780 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_48bppRGB
);
781 case PixelFormat64bppARGB
:
782 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_64bppARGB
);
787 case PixelFormat16bppRGB565
:
790 case PixelFormat1bppIndexed
:
791 convert_rgb_to_indexed(getpixel_16bppRGB565
, setpixel_1bppIndexed
);
792 case PixelFormat4bppIndexed
:
793 convert_rgb_to_indexed(getpixel_16bppRGB565
, setpixel_4bppIndexed
);
794 case PixelFormat8bppIndexed
:
795 convert_rgb_to_indexed(getpixel_16bppRGB565
, setpixel_8bppIndexed
);
796 case PixelFormat16bppGrayScale
:
797 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppGrayScale
);
798 case PixelFormat16bppRGB555
:
799 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppRGB555
);
800 case PixelFormat16bppARGB1555
:
801 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppARGB1555
);
802 case PixelFormat24bppRGB
:
803 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_24bppRGB
);
804 case PixelFormat32bppRGB
:
805 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppRGB
);
806 case PixelFormat32bppARGB
:
807 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppARGB
);
808 case PixelFormat32bppPARGB
:
809 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppPARGB
);
810 case PixelFormat48bppRGB
:
811 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_48bppRGB
);
812 case PixelFormat64bppARGB
:
813 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_64bppARGB
);
818 case PixelFormat16bppARGB1555
:
821 case PixelFormat1bppIndexed
:
822 convert_rgb_to_indexed(getpixel_16bppARGB1555
, setpixel_1bppIndexed
);
823 case PixelFormat4bppIndexed
:
824 convert_rgb_to_indexed(getpixel_16bppARGB1555
, setpixel_4bppIndexed
);
825 case PixelFormat8bppIndexed
:
826 convert_rgb_to_indexed(getpixel_16bppARGB1555
, setpixel_8bppIndexed
);
827 case PixelFormat16bppGrayScale
:
828 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppGrayScale
);
829 case PixelFormat16bppRGB555
:
830 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppRGB555
);
831 case PixelFormat16bppRGB565
:
832 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppRGB565
);
833 case PixelFormat24bppRGB
:
834 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_24bppRGB
);
835 case PixelFormat32bppRGB
:
836 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppRGB
);
837 case PixelFormat32bppARGB
:
838 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppARGB
);
839 case PixelFormat32bppPARGB
:
840 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppPARGB
);
841 case PixelFormat48bppRGB
:
842 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_48bppRGB
);
843 case PixelFormat64bppARGB
:
844 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_64bppARGB
);
849 case PixelFormat24bppRGB
:
852 case PixelFormat1bppIndexed
:
853 convert_rgb_to_indexed(getpixel_24bppRGB
, setpixel_1bppIndexed
);
854 case PixelFormat4bppIndexed
:
855 convert_rgb_to_indexed(getpixel_24bppRGB
, setpixel_4bppIndexed
);
856 case PixelFormat8bppIndexed
:
857 convert_rgb_to_indexed(getpixel_24bppRGB
, setpixel_8bppIndexed
);
858 case PixelFormat16bppGrayScale
:
859 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppGrayScale
);
860 case PixelFormat16bppRGB555
:
861 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppRGB555
);
862 case PixelFormat16bppRGB565
:
863 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppRGB565
);
864 case PixelFormat16bppARGB1555
:
865 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppARGB1555
);
866 case PixelFormat32bppRGB
:
867 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppRGB
);
868 case PixelFormat32bppARGB
:
869 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppARGB
);
870 case PixelFormat32bppPARGB
:
871 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppPARGB
);
872 case PixelFormat48bppRGB
:
873 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_48bppRGB
);
874 case PixelFormat64bppARGB
:
875 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_64bppARGB
);
880 case PixelFormat32bppRGB
:
883 case PixelFormat1bppIndexed
:
884 convert_rgb_to_indexed(getpixel_32bppRGB
, setpixel_1bppIndexed
);
885 case PixelFormat4bppIndexed
:
886 convert_rgb_to_indexed(getpixel_32bppRGB
, setpixel_4bppIndexed
);
887 case PixelFormat8bppIndexed
:
888 convert_rgb_to_indexed(getpixel_32bppRGB
, setpixel_8bppIndexed
);
889 case PixelFormat16bppGrayScale
:
890 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppGrayScale
);
891 case PixelFormat16bppRGB555
:
892 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppRGB555
);
893 case PixelFormat16bppRGB565
:
894 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppRGB565
);
895 case PixelFormat16bppARGB1555
:
896 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppARGB1555
);
897 case PixelFormat24bppRGB
:
898 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_24bppRGB
);
899 case PixelFormat32bppARGB
:
900 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_32bppARGB
);
901 case PixelFormat32bppPARGB
:
902 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_32bppPARGB
);
903 case PixelFormat48bppRGB
:
904 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_48bppRGB
);
905 case PixelFormat64bppARGB
:
906 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_64bppARGB
);
911 case PixelFormat32bppARGB
:
914 case PixelFormat1bppIndexed
:
915 convert_rgb_to_indexed(getpixel_32bppARGB
, setpixel_1bppIndexed
);
916 case PixelFormat4bppIndexed
:
917 convert_rgb_to_indexed(getpixel_32bppARGB
, setpixel_4bppIndexed
);
918 case PixelFormat8bppIndexed
:
919 convert_rgb_to_indexed(getpixel_32bppARGB
, setpixel_8bppIndexed
);
920 case PixelFormat16bppGrayScale
:
921 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppGrayScale
);
922 case PixelFormat16bppRGB555
:
923 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppRGB555
);
924 case PixelFormat16bppRGB565
:
925 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppRGB565
);
926 case PixelFormat16bppARGB1555
:
927 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppARGB1555
);
928 case PixelFormat24bppRGB
:
929 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_24bppRGB
);
930 case PixelFormat32bppPARGB
:
931 convert_32bppARGB_to_32bppPARGB(width
, height
, dst_bits
, dst_stride
, src_bits
, src_stride
);
933 case PixelFormat48bppRGB
:
934 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_48bppRGB
);
935 case PixelFormat64bppARGB
:
936 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_64bppARGB
);
941 case PixelFormat32bppPARGB
:
944 case PixelFormat1bppIndexed
:
945 convert_rgb_to_indexed(getpixel_32bppPARGB
, setpixel_1bppIndexed
);
946 case PixelFormat4bppIndexed
:
947 convert_rgb_to_indexed(getpixel_32bppPARGB
, setpixel_4bppIndexed
);
948 case PixelFormat8bppIndexed
:
949 convert_rgb_to_indexed(getpixel_32bppPARGB
, setpixel_8bppIndexed
);
950 case PixelFormat16bppGrayScale
:
951 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppGrayScale
);
952 case PixelFormat16bppRGB555
:
953 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppRGB555
);
954 case PixelFormat16bppRGB565
:
955 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppRGB565
);
956 case PixelFormat16bppARGB1555
:
957 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppARGB1555
);
958 case PixelFormat24bppRGB
:
959 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_24bppRGB
);
960 case PixelFormat32bppRGB
:
961 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_32bppRGB
);
962 case PixelFormat32bppARGB
:
963 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_32bppARGB
);
964 case PixelFormat48bppRGB
:
965 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_48bppRGB
);
966 case PixelFormat64bppARGB
:
967 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_64bppARGB
);
972 case PixelFormat48bppRGB
:
975 case PixelFormat1bppIndexed
:
976 convert_rgb_to_indexed(getpixel_48bppRGB
, setpixel_1bppIndexed
);
977 case PixelFormat4bppIndexed
:
978 convert_rgb_to_indexed(getpixel_48bppRGB
, setpixel_4bppIndexed
);
979 case PixelFormat8bppIndexed
:
980 convert_rgb_to_indexed(getpixel_48bppRGB
, setpixel_8bppIndexed
);
981 case PixelFormat16bppGrayScale
:
982 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppGrayScale
);
983 case PixelFormat16bppRGB555
:
984 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppRGB555
);
985 case PixelFormat16bppRGB565
:
986 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppRGB565
);
987 case PixelFormat16bppARGB1555
:
988 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppARGB1555
);
989 case PixelFormat24bppRGB
:
990 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_24bppRGB
);
991 case PixelFormat32bppRGB
:
992 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppRGB
);
993 case PixelFormat32bppARGB
:
994 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppARGB
);
995 case PixelFormat32bppPARGB
:
996 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppPARGB
);
997 case PixelFormat64bppARGB
:
998 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_64bppARGB
);
1003 case PixelFormat64bppARGB
:
1006 case PixelFormat1bppIndexed
:
1007 convert_rgb_to_indexed(getpixel_64bppARGB
, setpixel_1bppIndexed
);
1008 case PixelFormat4bppIndexed
:
1009 convert_rgb_to_indexed(getpixel_64bppARGB
, setpixel_4bppIndexed
);
1010 case PixelFormat8bppIndexed
:
1011 convert_rgb_to_indexed(getpixel_64bppARGB
, setpixel_8bppIndexed
);
1012 case PixelFormat16bppGrayScale
:
1013 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppGrayScale
);
1014 case PixelFormat16bppRGB555
:
1015 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppRGB555
);
1016 case PixelFormat16bppRGB565
:
1017 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppRGB565
);
1018 case PixelFormat16bppARGB1555
:
1019 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppARGB1555
);
1020 case PixelFormat24bppRGB
:
1021 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_24bppRGB
);
1022 case PixelFormat32bppRGB
:
1023 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppRGB
);
1024 case PixelFormat32bppARGB
:
1025 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppARGB
);
1026 case PixelFormat32bppPARGB
:
1027 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppPARGB
);
1028 case PixelFormat48bppRGB
:
1029 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_48bppRGB
);
1034 case PixelFormat64bppPARGB
:
1037 case PixelFormat1bppIndexed
:
1038 convert_rgb_to_indexed(getpixel_64bppPARGB
, setpixel_1bppIndexed
);
1039 case PixelFormat4bppIndexed
:
1040 convert_rgb_to_indexed(getpixel_64bppPARGB
, setpixel_4bppIndexed
);
1041 case PixelFormat8bppIndexed
:
1042 convert_rgb_to_indexed(getpixel_64bppPARGB
, setpixel_8bppIndexed
);
1043 case PixelFormat16bppGrayScale
:
1044 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppGrayScale
);
1045 case PixelFormat16bppRGB555
:
1046 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppRGB555
);
1047 case PixelFormat16bppRGB565
:
1048 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppRGB565
);
1049 case PixelFormat16bppARGB1555
:
1050 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppARGB1555
);
1051 case PixelFormat24bppRGB
:
1052 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_24bppRGB
);
1053 case PixelFormat32bppRGB
:
1054 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppRGB
);
1055 case PixelFormat32bppARGB
:
1056 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppARGB
);
1057 case PixelFormat32bppPARGB
:
1058 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppPARGB
);
1059 case PixelFormat48bppRGB
:
1060 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_48bppRGB
);
1061 case PixelFormat64bppARGB
:
1062 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_64bppARGB
);
1071 #undef convert_indexed_to_rgb
1072 #undef convert_rgb_to_rgb
1074 return NotImplemented
;
1077 /* This function returns a pointer to an array of pixels that represents the
1078 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
1079 * flags. It is correct behavior that a user who calls this function with write
1080 * privileges can write to the whole bitmap (not just the area in rect).
1082 * FIXME: only used portion of format is bits per pixel. */
1083 GpStatus WINGDIPAPI
GdipBitmapLockBits(GpBitmap
* bitmap
, GDIPCONST GpRect
* rect
,
1084 UINT flags
, PixelFormat format
, BitmapData
* lockeddata
)
1086 INT bitspp
= PIXELFORMATBPP(format
);
1087 GpRect act_rect
; /* actual rect to be used */
1091 TRACE("%p %p %d 0x%x %p\n", bitmap
, rect
, flags
, format
, lockeddata
);
1093 if(!lockeddata
|| !bitmap
)
1094 return InvalidParameter
;
1095 if(!image_lock(&bitmap
->image
, &unlock
))
1099 if(rect
->X
< 0 || rect
->Y
< 0 || (rect
->X
+ rect
->Width
> bitmap
->width
) ||
1100 (rect
->Y
+ rect
->Height
> bitmap
->height
) || !flags
)
1102 image_unlock(&bitmap
->image
, unlock
);
1103 return InvalidParameter
;
1109 act_rect
.X
= act_rect
.Y
= 0;
1110 act_rect
.Width
= bitmap
->width
;
1111 act_rect
.Height
= bitmap
->height
;
1114 if(bitmap
->lockmode
)
1116 WARN("bitmap is already locked and cannot be locked again\n");
1117 image_unlock(&bitmap
->image
, unlock
);
1121 if (bitmap
->bits
&& bitmap
->format
== format
&& !(flags
& ImageLockModeUserInputBuf
))
1123 /* no conversion is necessary; just use the bits directly */
1124 lockeddata
->Width
= act_rect
.Width
;
1125 lockeddata
->Height
= act_rect
.Height
;
1126 lockeddata
->PixelFormat
= format
;
1127 lockeddata
->Reserved
= flags
;
1128 lockeddata
->Stride
= bitmap
->stride
;
1129 lockeddata
->Scan0
= bitmap
->bits
+ (bitspp
/ 8) * act_rect
.X
+
1130 bitmap
->stride
* act_rect
.Y
;
1132 bitmap
->lockmode
= flags
| ImageLockModeRead
;
1134 image_unlock(&bitmap
->image
, unlock
);
1138 /* Make sure we can convert to the requested format. */
1139 if (flags
& ImageLockModeRead
)
1141 stat
= convert_pixels(0, 0, 0, NULL
, format
, NULL
, 0, NULL
, bitmap
->format
, NULL
);
1142 if (stat
== NotImplemented
)
1144 FIXME("cannot read bitmap from %x to %x\n", bitmap
->format
, format
);
1145 image_unlock(&bitmap
->image
, unlock
);
1146 return NotImplemented
;
1150 /* If we're opening for writing, make sure we'll be able to write back in
1151 * the original format. */
1152 if (flags
& ImageLockModeWrite
)
1154 stat
= convert_pixels(0, 0, 0, NULL
, bitmap
->format
, NULL
, 0, NULL
, format
, NULL
);
1155 if (stat
== NotImplemented
)
1157 FIXME("cannot write bitmap from %x to %x\n", format
, bitmap
->format
);
1158 image_unlock(&bitmap
->image
, unlock
);
1159 return NotImplemented
;
1163 lockeddata
->Width
= act_rect
.Width
;
1164 lockeddata
->Height
= act_rect
.Height
;
1165 lockeddata
->PixelFormat
= format
;
1166 lockeddata
->Reserved
= flags
;
1168 if(!(flags
& ImageLockModeUserInputBuf
))
1170 lockeddata
->Stride
= (((act_rect
.Width
* bitspp
+ 7) / 8) + 3) & ~3;
1172 bitmap
->bitmapbits
= heap_alloc_zero(lockeddata
->Stride
* act_rect
.Height
);
1174 if (!bitmap
->bitmapbits
)
1176 image_unlock(&bitmap
->image
, unlock
);
1180 lockeddata
->Scan0
= bitmap
->bitmapbits
;
1183 if (flags
& ImageLockModeRead
)
1185 static BOOL fixme
= FALSE
;
1187 if (!fixme
&& (PIXELFORMATBPP(bitmap
->format
) * act_rect
.X
) % 8 != 0)
1189 FIXME("Cannot copy rows that don't start at a whole byte.\n");
1193 stat
= convert_pixels(act_rect
.Width
, act_rect
.Height
,
1194 lockeddata
->Stride
, lockeddata
->Scan0
, format
, bitmap
->image
.palette
,
1196 bitmap
->bits
+ bitmap
->stride
* act_rect
.Y
+ PIXELFORMATBPP(bitmap
->format
) * act_rect
.X
/ 8,
1197 bitmap
->format
, bitmap
->image
.palette
);
1201 heap_free(bitmap
->bitmapbits
);
1202 bitmap
->bitmapbits
= NULL
;
1203 image_unlock(&bitmap
->image
, unlock
);
1208 bitmap
->lockmode
= flags
| ImageLockModeRead
;
1209 bitmap
->lockx
= act_rect
.X
;
1210 bitmap
->locky
= act_rect
.Y
;
1212 image_unlock(&bitmap
->image
, unlock
);
1216 GpStatus WINGDIPAPI
GdipBitmapSetResolution(GpBitmap
* bitmap
, REAL xdpi
, REAL ydpi
)
1218 TRACE("(%p, %.2f, %.2f)\n", bitmap
, xdpi
, ydpi
);
1220 if (!bitmap
|| xdpi
== 0.0 || ydpi
== 0.0)
1221 return InvalidParameter
;
1223 bitmap
->image
.xres
= xdpi
;
1224 bitmap
->image
.yres
= ydpi
;
1229 GpStatus WINGDIPAPI
GdipBitmapUnlockBits(GpBitmap
* bitmap
,
1230 BitmapData
* lockeddata
)
1233 static BOOL fixme
= FALSE
;
1236 TRACE("(%p,%p)\n", bitmap
, lockeddata
);
1238 if(!bitmap
|| !lockeddata
)
1239 return InvalidParameter
;
1240 if(!image_lock(&bitmap
->image
, &unlock
))
1243 if(!bitmap
->lockmode
)
1245 image_unlock(&bitmap
->image
, unlock
);
1249 if(!(lockeddata
->Reserved
& ImageLockModeWrite
)){
1250 bitmap
->lockmode
= 0;
1251 heap_free(bitmap
->bitmapbits
);
1252 bitmap
->bitmapbits
= NULL
;
1253 image_unlock(&bitmap
->image
, unlock
);
1257 if (!bitmap
->bitmapbits
&& !(lockeddata
->Reserved
& ImageLockModeUserInputBuf
))
1259 /* we passed a direct reference; no need to do anything */
1260 bitmap
->lockmode
= 0;
1261 image_unlock(&bitmap
->image
, unlock
);
1265 if (!fixme
&& (PIXELFORMATBPP(bitmap
->format
) * bitmap
->lockx
) % 8 != 0)
1267 FIXME("Cannot copy rows that don't start at a whole byte.\n");
1271 /* FIXME: Pass src_palette generated from lockeddata->PixelFormat. */
1272 stat
= convert_pixels(lockeddata
->Width
, lockeddata
->Height
,
1274 bitmap
->bits
+ bitmap
->stride
* bitmap
->locky
+ PIXELFORMATBPP(bitmap
->format
) * bitmap
->lockx
/ 8,
1275 bitmap
->format
, bitmap
->image
.palette
,
1276 lockeddata
->Stride
, lockeddata
->Scan0
, lockeddata
->PixelFormat
, NULL
);
1280 ERR("failed to convert pixels; this should never happen\n");
1283 heap_free(bitmap
->bitmapbits
);
1284 bitmap
->bitmapbits
= NULL
;
1285 bitmap
->lockmode
= 0;
1287 image_unlock(&bitmap
->image
, unlock
);
1291 GpStatus WINGDIPAPI
GdipCloneBitmapArea(REAL x
, REAL y
, REAL width
, REAL height
,
1292 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
1297 TRACE("(%f,%f,%f,%f,0x%x,%p,%p)\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1299 if (!srcBitmap
|| !dstBitmap
|| srcBitmap
->image
.type
!= ImageTypeBitmap
||
1301 x
+ width
> srcBitmap
->width
|| y
+ height
> srcBitmap
->height
)
1303 TRACE("<-- InvalidParameter\n");
1304 return InvalidParameter
;
1307 if (format
== PixelFormatDontCare
)
1308 format
= srcBitmap
->format
;
1310 area
.X
= gdip_round(x
);
1311 area
.Y
= gdip_round(y
);
1312 area
.Width
= gdip_round(width
);
1313 area
.Height
= gdip_round(height
);
1315 stat
= GdipCreateBitmapFromScan0(area
.Width
, area
.Height
, 0, format
, NULL
, dstBitmap
);
1318 stat
= convert_pixels(area
.Width
, area
.Height
, (*dstBitmap
)->stride
, (*dstBitmap
)->bits
, (*dstBitmap
)->format
,
1319 (*dstBitmap
)->image
.palette
, srcBitmap
->stride
,
1320 srcBitmap
->bits
+ srcBitmap
->stride
* area
.Y
+ PIXELFORMATBPP(srcBitmap
->format
) * area
.X
/ 8,
1321 srcBitmap
->format
, srcBitmap
->image
.palette
);
1323 if (stat
== Ok
&& srcBitmap
->image
.palette
)
1325 ColorPalette
*src_palette
, *dst_palette
;
1327 src_palette
= srcBitmap
->image
.palette
;
1329 dst_palette
= heap_alloc_zero(sizeof(UINT
) * 2 + sizeof(ARGB
) * src_palette
->Count
);
1333 dst_palette
->Flags
= src_palette
->Flags
;
1334 dst_palette
->Count
= src_palette
->Count
;
1335 memcpy(dst_palette
->Entries
, src_palette
->Entries
, sizeof(ARGB
) * src_palette
->Count
);
1337 heap_free((*dstBitmap
)->image
.palette
);
1338 (*dstBitmap
)->image
.palette
= dst_palette
;
1345 GdipDisposeImage(&(*dstBitmap
)->image
);
1354 GpStatus WINGDIPAPI
GdipCloneBitmapAreaI(INT x
, INT y
, INT width
, INT height
,
1355 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
1357 TRACE("(%i,%i,%i,%i,0x%x,%p,%p)\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1359 return GdipCloneBitmapArea(x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1362 GpStatus WINGDIPAPI
GdipCloneImage(GpImage
*image
, GpImage
**cloneImage
)
1364 TRACE("%p, %p\n", image
, cloneImage
);
1366 if (!image
|| !cloneImage
)
1367 return InvalidParameter
;
1369 if (image
->type
== ImageTypeBitmap
)
1371 GpBitmap
*bitmap
= (GpBitmap
*)image
;
1373 return GdipCloneBitmapAreaI(0, 0, bitmap
->width
, bitmap
->height
,
1374 bitmap
->format
, bitmap
, (GpBitmap
**)cloneImage
);
1376 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
1378 GpMetafile
*result
, *metafile
;
1380 metafile
= (GpMetafile
*)image
;
1382 result
= heap_alloc_zero(sizeof(*result
));
1386 result
->image
.type
= ImageTypeMetafile
;
1387 result
->image
.format
= image
->format
;
1388 result
->image
.flags
= image
->flags
;
1389 result
->image
.frame_count
= 1;
1390 result
->image
.xres
= image
->xres
;
1391 result
->image
.yres
= image
->yres
;
1392 result
->bounds
= metafile
->bounds
;
1393 result
->unit
= metafile
->unit
;
1394 result
->metafile_type
= metafile
->metafile_type
;
1395 result
->hemf
= CopyEnhMetaFileW(metafile
->hemf
, NULL
);
1396 list_init(&result
->containers
);
1404 *cloneImage
= &result
->image
;
1409 WARN("GpImage with no image data (metafile in wrong state?)\n");
1410 return InvalidParameter
;
1414 GpStatus WINGDIPAPI
GdipCreateBitmapFromFile(GDIPCONST WCHAR
* filename
,
1420 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
1422 if(!filename
|| !bitmap
)
1423 return InvalidParameter
;
1427 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
1432 stat
= GdipCreateBitmapFromStream(stream
, bitmap
);
1434 IStream_Release(stream
);
1439 GpStatus WINGDIPAPI
GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO
* info
,
1440 VOID
*bits
, GpBitmap
**bitmap
)
1442 DWORD height
, stride
;
1447 TRACE("(%p, %p, %p)\n", info
, bits
, bitmap
);
1449 if (!info
|| !bits
|| !bitmap
)
1450 return InvalidParameter
;
1452 hbm
= CreateDIBSection(0, info
, DIB_RGB_COLORS
, &bmbits
, NULL
, 0);
1454 return InvalidParameter
;
1456 height
= abs(info
->bmiHeader
.biHeight
);
1457 stride
= ((info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
+ 31) >> 3) & ~3;
1458 TRACE("height %lu, stride %lu, image size %lu\n", height
, stride
, height
* stride
);
1460 memcpy(bmbits
, bits
, height
* stride
);
1462 status
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, bitmap
);
1469 GpStatus WINGDIPAPI
GdipCreateBitmapFromFileICM(GDIPCONST WCHAR
* filename
,
1472 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
1474 return GdipCreateBitmapFromFile(filename
, bitmap
);
1477 GpStatus WINGDIPAPI
GdipCreateBitmapFromResource(HINSTANCE hInstance
,
1478 GDIPCONST WCHAR
* lpBitmapName
, GpBitmap
** bitmap
)
1481 GpStatus stat
= InvalidParameter
;
1483 TRACE("%p (%s) %p\n", hInstance
, debugstr_w(lpBitmapName
), bitmap
);
1485 if(!lpBitmapName
|| !bitmap
)
1486 return InvalidParameter
;
1489 hbm
= LoadImageW(hInstance
, lpBitmapName
, IMAGE_BITMAP
, 0, 0,
1490 LR_CREATEDIBSECTION
);
1493 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, bitmap
);
1500 static inline DWORD
blend_argb_no_bkgnd_alpha(DWORD src
, DWORD bkgnd
)
1503 BYTE g
= (BYTE
)(src
>> 8);
1504 BYTE r
= (BYTE
)(src
>> 16);
1505 DWORD alpha
= (BYTE
)(src
>> 24);
1506 return ((b
+ ((BYTE
)bkgnd
* (255 - alpha
) + 127) / 255) |
1507 (g
+ ((BYTE
)(bkgnd
>> 8) * (255 - alpha
) + 127) / 255) << 8 |
1508 (r
+ ((BYTE
)(bkgnd
>> 16) * (255 - alpha
) + 127) / 255) << 16 |
1512 GpStatus WINGDIPAPI
GdipCreateHBITMAPFromBitmap(GpBitmap
* bitmap
,
1513 HBITMAP
* hbmReturn
, ARGB background
)
1518 BITMAPINFOHEADER bih
;
1522 TRACE("(%p,%p,%lx)\n", bitmap
, hbmReturn
, background
);
1524 if (!bitmap
|| !hbmReturn
) return InvalidParameter
;
1525 if (!image_lock(&bitmap
->image
, &unlock
)) return ObjectBusy
;
1527 GdipGetImageWidth(&bitmap
->image
, &width
);
1528 GdipGetImageHeight(&bitmap
->image
, &height
);
1530 bih
.biSize
= sizeof(bih
);
1531 bih
.biWidth
= width
;
1532 bih
.biHeight
= height
;
1534 bih
.biBitCount
= 32;
1535 bih
.biCompression
= BI_RGB
;
1536 bih
.biSizeImage
= 0;
1537 bih
.biXPelsPerMeter
= 0;
1538 bih
.biYPelsPerMeter
= 0;
1540 bih
.biClrImportant
= 0;
1542 result
= CreateDIBSection(0, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1545 image_unlock(&bitmap
->image
, unlock
);
1546 return GenericError
;
1549 stat
= convert_pixels(width
, height
, -width
*4,
1550 bits
+ (width
* 4 * (height
- 1)), PixelFormat32bppPARGB
, bitmap
->image
.palette
,
1551 bitmap
->stride
, bitmap
->bits
, bitmap
->format
, bitmap
->image
.palette
);
1554 DeleteObject(result
);
1555 image_unlock(&bitmap
->image
, unlock
);
1559 if (background
& 0xffffff)
1563 for (ptr
= (DWORD
*)bits
, i
= 0; i
< width
* height
; ptr
++, i
++)
1565 if ((*ptr
& 0xff000000) == 0xff000000) continue;
1566 *ptr
= blend_argb_no_bkgnd_alpha(*ptr
, background
);
1570 *hbmReturn
= result
;
1571 image_unlock(&bitmap
->image
, unlock
);
1575 GpStatus WINGDIPAPI
GdipCreateBitmapFromGraphics(INT width
, INT height
,
1576 GpGraphics
* target
, GpBitmap
** bitmap
)
1580 TRACE("(%d, %d, %p, %p)\n", width
, height
, target
, bitmap
);
1582 if(!target
|| !bitmap
)
1583 return InvalidParameter
;
1585 ret
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat32bppPARGB
,
1590 GdipGetDpiX(target
, &(*bitmap
)->image
.xres
);
1591 GdipGetDpiY(target
, &(*bitmap
)->image
.yres
);
1597 GpStatus WINGDIPAPI
GdipCreateBitmapFromHICON(HICON hicon
, GpBitmap
** bitmap
)
1603 UINT width
, height
, stride
;
1605 BitmapData lockeddata
;
1609 BITMAPINFOHEADER bih
;
1614 TRACE("%p, %p\n", hicon
, bitmap
);
1616 if(!bitmap
|| !GetIconInfo(hicon
, &iinfo
))
1617 return InvalidParameter
;
1619 /* get the size of the icon */
1620 ret
= GetObjectA(iinfo
.hbmColor
? iinfo
.hbmColor
: iinfo
.hbmMask
, sizeof(bm
), &bm
);
1622 DeleteObject(iinfo
.hbmColor
);
1623 DeleteObject(iinfo
.hbmMask
);
1624 return GenericError
;
1628 height
= iinfo
.hbmColor
? abs(bm
.bmHeight
) : abs(bm
.bmHeight
) / 2;
1631 stat
= GdipCreateBitmapFromScan0(width
, height
, stride
, PixelFormat32bppARGB
, NULL
, bitmap
);
1633 DeleteObject(iinfo
.hbmColor
);
1634 DeleteObject(iinfo
.hbmMask
);
1641 rect
.Height
= height
;
1643 stat
= GdipBitmapLockBits(*bitmap
, &rect
, ImageLockModeWrite
, PixelFormat32bppARGB
, &lockeddata
);
1645 DeleteObject(iinfo
.hbmColor
);
1646 DeleteObject(iinfo
.hbmMask
);
1647 GdipDisposeImage(&(*bitmap
)->image
);
1651 bih
.biSize
= sizeof(bih
);
1652 bih
.biWidth
= width
;
1653 bih
.biHeight
= iinfo
.hbmColor
? -height
: -height
* 2;
1655 bih
.biBitCount
= 32;
1656 bih
.biCompression
= BI_RGB
;
1657 bih
.biSizeImage
= 0;
1658 bih
.biXPelsPerMeter
= 0;
1659 bih
.biYPelsPerMeter
= 0;
1661 bih
.biClrImportant
= 0;
1663 screendc
= CreateCompatibleDC(0);
1666 GetDIBits(screendc
, iinfo
.hbmColor
, 0, height
, lockeddata
.Scan0
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1668 if (bm
.bmBitsPixel
== 32)
1672 /* If any pixel has a non-zero alpha, ignore hbmMask */
1673 src
= (DWORD
*)lockeddata
.Scan0
;
1674 for (x
=0; x
<width
&& !has_alpha
; x
++)
1675 for (y
=0; y
<height
&& !has_alpha
; y
++)
1676 if ((*src
++ & 0xff000000) != 0)
1679 else has_alpha
= FALSE
;
1683 GetDIBits(screendc
, iinfo
.hbmMask
, 0, height
, lockeddata
.Scan0
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1691 BYTE
*bits
= heap_alloc(height
* stride
);
1693 /* read alpha data from the mask */
1695 GetDIBits(screendc
, iinfo
.hbmMask
, 0, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1697 GetDIBits(screendc
, iinfo
.hbmMask
, height
, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1700 dst_row
= lockeddata
.Scan0
;
1701 for (y
=0; y
<height
; y
++)
1703 dst
= (DWORD
*)dst_row
;
1704 for (x
=0; x
<height
; x
++)
1706 DWORD src_value
= *src
++;
1710 *dst
++ |= 0xff000000;
1712 dst_row
+= lockeddata
.Stride
;
1719 /* set constant alpha of 255 */
1720 dst_row
= lockeddata
.Scan0
;
1721 for (y
=0; y
<height
; y
++)
1723 dst
= (DWORD
*)dst_row
;
1724 for (x
=0; x
<height
; x
++)
1725 *dst
++ |= 0xff000000;
1726 dst_row
+= lockeddata
.Stride
;
1733 DeleteObject(iinfo
.hbmColor
);
1734 DeleteObject(iinfo
.hbmMask
);
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
;
2768 if (!reader
) return PropertyNotFound
;
2770 hr
= IWICMetadataReader_GetCount(reader
, &prop_count
);
2771 if (FAILED(hr
)) return hresult_to_status(hr
);
2773 hr
= IWICMetadataReader_GetEnumerator(reader
, &enumerator
);
2774 if (FAILED(hr
)) return hresult_to_status(hr
);
2776 IWICEnumMetadataItem_Reset(enumerator
);
2780 PropVariantInit(&id
);
2781 PropVariantInit(&value
);
2783 for (i
= 0; i
< prop_count
; i
++)
2785 ULONG items_returned
;
2788 hr
= IWICEnumMetadataItem_Next(enumerator
, 1, NULL
, &id
, &value
, &items_returned
);
2789 if (hr
!= S_OK
) break;
2791 item_size
= propvariant_size(&value
);
2792 if (item_size
) prop_size
+= sizeof(PropertyItem
) + item_size
;
2794 PropVariantClear(&id
);
2795 PropVariantClear(&value
);
2798 IWICEnumMetadataItem_Release(enumerator
);
2800 if (hr
!= S_OK
) return PropertyNotFound
;
2802 *count
= prop_count
;
2807 GpStatus WINGDIPAPI
GdipGetAllPropertyItems(GpImage
*image
, UINT size
,
2808 UINT count
, PropertyItem
*buf
)
2812 IWICMetadataReader
*reader
;
2813 IWICEnumMetadataItem
*enumerator
;
2814 UINT prop_count
, prop_size
, i
;
2815 PROPVARIANT id
, value
;
2818 TRACE("(%p,%u,%u,%p)\n", image
, size
, count
, buf
);
2820 if (!image
|| !buf
) return InvalidParameter
;
2822 if (image
->type
!= ImageTypeBitmap
)
2824 FIXME("Not implemented for type %d\n", image
->type
);
2825 return NotImplemented
;
2828 status
= GdipGetPropertySize(image
, &prop_size
, &prop_count
);
2829 if (status
!= Ok
) return status
;
2831 if (prop_count
!= count
|| prop_size
!= size
) return InvalidParameter
;
2833 if (((GpBitmap
*)image
)->prop_item
)
2835 memcpy(buf
, ((GpBitmap
*)image
)->prop_item
, prop_size
);
2837 item_value
= (char *)(buf
+ prop_count
);
2839 for (i
= 0; i
< prop_count
; i
++)
2841 buf
[i
].value
= item_value
;
2842 item_value
+= buf
[i
].length
;
2848 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2849 if (!reader
) return PropertyNotFound
;
2851 hr
= IWICMetadataReader_GetEnumerator(reader
, &enumerator
);
2852 if (FAILED(hr
)) return hresult_to_status(hr
);
2854 IWICEnumMetadataItem_Reset(enumerator
);
2856 item_value
= (char *)(buf
+ prop_count
);
2858 PropVariantInit(&id
);
2859 PropVariantInit(&value
);
2861 for (i
= 0; i
< prop_count
; i
++)
2864 ULONG items_returned
;
2867 hr
= IWICEnumMetadataItem_Next(enumerator
, 1, NULL
, &id
, &value
, &items_returned
);
2868 if (hr
!= S_OK
) break;
2870 if (id
.vt
!= VT_UI2
)
2872 FIXME("not supported propvariant type for id: %u\n", id
.vt
);
2876 item_size
= propvariant_size(&value
);
2879 item
= heap_alloc(item_size
+ sizeof(*item
));
2881 propvariant_to_item(&value
, item
, item_size
+ sizeof(*item
), id
.uiVal
);
2882 buf
[i
].id
= item
->id
;
2883 buf
[i
].type
= item
->type
;
2884 buf
[i
].length
= item_size
;
2885 buf
[i
].value
= item_value
;
2886 memcpy(item_value
, item
->value
, item_size
);
2887 item_value
+= item_size
;
2892 PropVariantClear(&id
);
2893 PropVariantClear(&value
);
2896 IWICEnumMetadataItem_Release(enumerator
);
2898 if (hr
!= S_OK
) return PropertyNotFound
;
2903 struct image_format_dimension
2906 const GUID
*dimension
;
2909 static const struct image_format_dimension image_format_dimensions
[] =
2911 {&ImageFormatGIF
, &FrameDimensionTime
},
2912 {&ImageFormatIcon
, &FrameDimensionResolution
},
2916 GpStatus WINGDIPAPI
GdipImageGetFrameCount(GpImage
*image
,
2917 GDIPCONST GUID
* dimensionID
, UINT
* count
)
2919 TRACE("(%p,%s,%p)\n", image
, debugstr_guid(dimensionID
), count
);
2921 if(!image
|| !count
)
2922 return InvalidParameter
;
2925 IsEqualGUID(dimensionID
, &image
->format
) ||
2926 IsEqualGUID(dimensionID
, &FrameDimensionPage
) ||
2927 IsEqualGUID(dimensionID
, &FrameDimensionTime
))
2929 *count
= image
->frame_count
;
2933 return InvalidParameter
;
2936 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsCount(GpImage
*image
,
2939 TRACE("(%p, %p)\n", image
, count
);
2941 /* Native gdiplus 1.1 does not yet support multiple frame dimensions. */
2943 if(!image
|| !count
)
2944 return InvalidParameter
;
2951 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsList(GpImage
* image
,
2952 GUID
* dimensionIDs
, UINT count
)
2955 const GUID
*result
=NULL
;
2957 TRACE("(%p,%p,%u)\n", image
, dimensionIDs
, count
);
2959 if(!image
|| !dimensionIDs
|| count
!= 1)
2960 return InvalidParameter
;
2962 for (i
=0; image_format_dimensions
[i
].format
; i
++)
2964 if (IsEqualGUID(&image
->format
, image_format_dimensions
[i
].format
))
2966 result
= image_format_dimensions
[i
].dimension
;
2972 result
= &FrameDimensionPage
;
2974 memcpy(dimensionIDs
, result
, sizeof(GUID
));
2979 GpStatus WINGDIPAPI
GdipLoadImageFromFile(GDIPCONST WCHAR
* filename
,
2985 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
2987 if (!filename
|| !image
)
2988 return InvalidParameter
;
2992 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
2997 stat
= GdipLoadImageFromStream(stream
, image
);
2999 IStream_Release(stream
);
3004 /* FIXME: no icm handling */
3005 GpStatus WINGDIPAPI
GdipLoadImageFromFileICM(GDIPCONST WCHAR
* filename
,GpImage
**image
)
3007 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
3009 return GdipLoadImageFromFile(filename
, image
);
3012 static void add_property(GpBitmap
*bitmap
, PropertyItem
*item
)
3014 UINT prop_size
, prop_count
;
3015 PropertyItem
*prop_item
;
3017 if (bitmap
->prop_item
== NULL
)
3019 prop_size
= prop_count
= 0;
3020 prop_item
= heap_alloc_zero(item
->length
+ sizeof(PropertyItem
));
3021 if (!prop_item
) return;
3028 GdipGetPropertySize(&bitmap
->image
, &prop_size
, &prop_count
);
3030 prop_item
= heap_alloc_zero(prop_size
+ item
->length
+ sizeof(PropertyItem
));
3031 if (!prop_item
) return;
3032 memcpy(prop_item
, bitmap
->prop_item
, sizeof(PropertyItem
) * bitmap
->prop_count
);
3033 prop_size
-= sizeof(PropertyItem
) * bitmap
->prop_count
;
3034 memcpy(prop_item
+ prop_count
+ 1, bitmap
->prop_item
+ prop_count
, prop_size
);
3036 item_value
= (char *)(prop_item
+ prop_count
+ 1);
3038 for (i
= 0; i
< prop_count
; i
++)
3040 prop_item
[i
].value
= item_value
;
3041 item_value
+= prop_item
[i
].length
;
3045 prop_item
[prop_count
].id
= item
->id
;
3046 prop_item
[prop_count
].type
= item
->type
;
3047 prop_item
[prop_count
].length
= item
->length
;
3048 prop_item
[prop_count
].value
= (char *)(prop_item
+ prop_count
+ 1) + prop_size
;
3049 memcpy(prop_item
[prop_count
].value
, item
->value
, item
->length
);
3051 heap_free(bitmap
->prop_item
);
3052 bitmap
->prop_item
= prop_item
;
3053 bitmap
->prop_count
++;
3056 static BOOL
get_bool_property(IWICMetadataReader
*reader
, const GUID
*guid
, const WCHAR
*prop_name
)
3060 PROPVARIANT id
, value
;
3063 hr
= IWICMetadataReader_GetMetadataFormat(reader
, &format
);
3064 if (FAILED(hr
) || !IsEqualGUID(&format
, guid
)) return FALSE
;
3066 PropVariantInit(&id
);
3067 PropVariantInit(&value
);
3070 id
.pwszVal
= CoTaskMemAlloc((lstrlenW(prop_name
) + 1) * sizeof(WCHAR
));
3071 if (!id
.pwszVal
) return FALSE
;
3072 lstrcpyW(id
.pwszVal
, prop_name
);
3073 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
3074 if (hr
== S_OK
&& value
.vt
== VT_BOOL
)
3075 ret
= value
.boolVal
;
3077 PropVariantClear(&id
);
3078 PropVariantClear(&value
);
3083 static PropertyItem
*get_property(IWICMetadataReader
*reader
, const GUID
*guid
, const WCHAR
*prop_name
)
3087 PROPVARIANT id
, value
;
3088 PropertyItem
*item
= NULL
;
3090 hr
= IWICMetadataReader_GetMetadataFormat(reader
, &format
);
3091 if (FAILED(hr
) || !IsEqualGUID(&format
, guid
)) return NULL
;
3093 PropVariantInit(&id
);
3094 PropVariantInit(&value
);
3097 id
.pwszVal
= CoTaskMemAlloc((lstrlenW(prop_name
) + 1) * sizeof(WCHAR
));
3098 if (!id
.pwszVal
) return NULL
;
3099 lstrcpyW(id
.pwszVal
, prop_name
);
3100 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
3103 UINT item_size
= propvariant_size(&value
);
3106 item_size
+= sizeof(*item
);
3107 item
= heap_alloc_zero(item_size
);
3108 if (propvariant_to_item(&value
, item
, item_size
, 0) != Ok
)
3116 PropVariantClear(&id
);
3117 PropVariantClear(&value
);
3122 static PropertyItem
*get_gif_comment(IWICMetadataReader
*reader
)
3124 PropertyItem
*comment
;
3126 comment
= get_property(reader
, &GUID_MetadataFormatGifComment
, L
"TextEntry");
3128 comment
->id
= PropertyTagExifUserComment
;
3133 static PropertyItem
*get_gif_loopcount(IWICMetadataReader
*reader
)
3135 PropertyItem
*appext
= NULL
, *appdata
= NULL
, *loop
= NULL
;
3137 appext
= get_property(reader
, &GUID_MetadataFormatAPE
, L
"Application");
3140 if (appext
->type
== PropertyTagTypeByte
&& appext
->length
== 11 &&
3141 (!memcmp(appext
->value
, "NETSCAPE2.0", 11) || !memcmp(appext
->value
, "ANIMEXTS1.0", 11)))
3143 appdata
= get_property(reader
, &GUID_MetadataFormatAPE
, L
"Data");
3146 if (appdata
->type
== PropertyTagTypeByte
&& appdata
->length
== 4)
3148 BYTE
*data
= appdata
->value
;
3149 if (data
[0] == 3 && data
[1] == 1)
3151 loop
= heap_alloc_zero(sizeof(*loop
) + sizeof(SHORT
));
3154 loop
->type
= PropertyTagTypeShort
;
3155 loop
->id
= PropertyTagLoopCount
;
3156 loop
->length
= sizeof(SHORT
);
3157 loop
->value
= loop
+ 1;
3158 *(SHORT
*)loop
->value
= data
[2] | (data
[3] << 8);
3172 static PropertyItem
*get_gif_background(IWICMetadataReader
*reader
)
3174 PropertyItem
*background
;
3176 background
= get_property(reader
, &GUID_MetadataFormatLSD
, L
"BackgroundColorIndex");
3178 background
->id
= PropertyTagIndexBackground
;
3183 static PropertyItem
*get_gif_palette(IWICBitmapDecoder
*decoder
, IWICMetadataReader
*reader
)
3186 IWICImagingFactory
*factory
;
3187 IWICPalette
*palette
;
3189 WICColor colors
[256];
3191 if (!get_bool_property(reader
, &GUID_MetadataFormatLSD
, L
"GlobalColorTableFlag"))
3194 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
3195 if (hr
!= S_OK
) return NULL
;
3197 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
3200 hr
= IWICBitmapDecoder_CopyPalette(decoder
, palette
);
3202 IWICPalette_GetColors(palette
, 256, colors
, &count
);
3204 IWICPalette_Release(palette
);
3207 IWICImagingFactory_Release(factory
);
3215 pal
= heap_alloc_zero(sizeof(*pal
) + count
* 3);
3216 if (!pal
) return NULL
;
3217 pal
->type
= PropertyTagTypeByte
;
3218 pal
->id
= PropertyTagGlobalPalette
;
3219 pal
->value
= pal
+ 1;
3220 pal
->length
= count
* 3;
3224 for (i
= 0; i
< count
; i
++)
3226 rgb
[i
*3] = (colors
[i
] >> 16) & 0xff;
3227 rgb
[i
*3 + 1] = (colors
[i
] >> 8) & 0xff;
3228 rgb
[i
*3 + 2] = colors
[i
] & 0xff;
3237 static PropertyItem
*get_gif_transparent_idx(IWICMetadataReader
*reader
)
3239 PropertyItem
*index
= NULL
;
3241 if (get_bool_property(reader
, &GUID_MetadataFormatGCE
, L
"TransparencyFlag"))
3243 index
= get_property(reader
, &GUID_MetadataFormatGCE
, L
"TransparentColorIndex");
3245 index
->id
= PropertyTagIndexTransparent
;
3250 static LONG
get_gif_frame_property(IWICBitmapFrameDecode
*frame
, const GUID
*format
, const WCHAR
*property
)
3253 IWICMetadataBlockReader
*block_reader
;
3254 IWICMetadataReader
*reader
;
3255 UINT block_count
, i
;
3259 hr
= IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3262 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3265 for (i
= 0; i
< block_count
; i
++)
3267 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3270 prop
= get_property(reader
, format
, property
);
3273 if (prop
->type
== PropertyTagTypeByte
&& prop
->length
== 1)
3274 value
= *(BYTE
*)prop
->value
;
3275 else if (prop
->type
== PropertyTagTypeShort
&& prop
->length
== 2)
3276 value
= *(SHORT
*)prop
->value
;
3280 IWICMetadataReader_Release(reader
);
3284 IWICMetadataBlockReader_Release(block_reader
);
3290 static void gif_metadata_reader(GpBitmap
*bitmap
, IWICBitmapDecoder
*decoder
, UINT active_frame
)
3293 IWICBitmapFrameDecode
*frame
;
3294 IWICMetadataBlockReader
*block_reader
;
3295 IWICMetadataReader
*reader
;
3296 UINT frame_count
, block_count
, i
;
3297 PropertyItem
*delay
= NULL
, *comment
= NULL
, *background
= NULL
;
3298 PropertyItem
*transparent_idx
= NULL
, *loop
= NULL
, *palette
= NULL
;
3300 IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
3301 if (frame_count
> 1)
3303 delay
= heap_alloc_zero(sizeof(*delay
) + frame_count
* sizeof(LONG
));
3308 delay
->type
= PropertyTagTypeLong
;
3309 delay
->id
= PropertyTagFrameDelay
;
3310 delay
->length
= frame_count
* sizeof(LONG
);
3311 delay
->value
= delay
+ 1;
3313 value
= delay
->value
;
3315 for (i
= 0; i
< frame_count
; i
++)
3317 hr
= IWICBitmapDecoder_GetFrame(decoder
, i
, &frame
);
3320 value
[i
] = get_gif_frame_property(frame
, &GUID_MetadataFormatGCE
, L
"Delay");
3321 IWICBitmapFrameDecode_Release(frame
);
3328 hr
= IWICBitmapDecoder_QueryInterface(decoder
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3331 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3334 for (i
= 0; i
< block_count
; i
++)
3336 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3340 comment
= get_gif_comment(reader
);
3342 if (frame_count
> 1 && !loop
)
3343 loop
= get_gif_loopcount(reader
);
3346 background
= get_gif_background(reader
);
3349 palette
= get_gif_palette(decoder
, reader
);
3351 IWICMetadataReader_Release(reader
);
3355 IWICMetadataBlockReader_Release(block_reader
);
3358 if (frame_count
> 1 && !loop
)
3360 loop
= heap_alloc_zero(sizeof(*loop
) + sizeof(SHORT
));
3363 loop
->type
= PropertyTagTypeShort
;
3364 loop
->id
= PropertyTagLoopCount
;
3365 loop
->length
= sizeof(SHORT
);
3366 loop
->value
= loop
+ 1;
3367 *(SHORT
*)loop
->value
= 1;
3371 if (delay
) add_property(bitmap
, delay
);
3372 if (comment
) add_property(bitmap
, comment
);
3373 if (loop
) add_property(bitmap
, loop
);
3374 if (palette
) add_property(bitmap
, palette
);
3375 if (background
) add_property(bitmap
, background
);
3381 heap_free(background
);
3383 /* Win7 gdiplus always returns transparent color index from frame 0 */
3384 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
3385 if (hr
!= S_OK
) return;
3387 hr
= IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3390 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3393 for (i
= 0; i
< block_count
; i
++)
3395 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3398 if (!transparent_idx
)
3399 transparent_idx
= get_gif_transparent_idx(reader
);
3401 IWICMetadataReader_Release(reader
);
3405 IWICMetadataBlockReader_Release(block_reader
);
3408 if (transparent_idx
) add_property(bitmap
, transparent_idx
);
3409 heap_free(transparent_idx
);
3411 IWICBitmapFrameDecode_Release(frame
);
3414 static PropertyItem
* create_prop(PROPID propid
, PROPVARIANT
* value
)
3416 PropertyItem
*item
= NULL
;
3417 UINT item_size
= propvariant_size(value
);
3421 item_size
+= sizeof(*item
);
3422 item
= heap_alloc_zero(item_size
);
3423 if (propvariant_to_item(value
, item
, item_size
, propid
) != Ok
)
3433 static ULONG
get_ulong_by_index(IWICMetadataReader
* reader
, ULONG index
)
3439 hr
= IWICMetadataReader_GetValueByIndex(reader
, index
, NULL
, NULL
, &value
);
3445 result
= value
.ulVal
;
3448 ERR("unhandled case %u\n", value
.vt
);
3451 PropVariantClear(&value
);
3456 static void png_metadata_reader(GpBitmap
*bitmap
, IWICBitmapDecoder
*decoder
, UINT active_frame
)
3459 IWICBitmapFrameDecode
*frame
;
3460 IWICMetadataBlockReader
*block_reader
;
3461 IWICMetadataReader
*reader
;
3462 UINT block_count
, i
, j
;
3463 struct keyword_info
{
3468 { "Title", PropertyTagImageTitle
},
3469 { "Author", PropertyTagArtist
},
3470 { "Description", PropertyTagImageDescription
},
3471 { "Copyright", PropertyTagCopyright
},
3472 { "Software", PropertyTagSoftwareUsed
},
3473 { "Source", PropertyTagEquipModel
},
3474 { "Comment", PropertyTagExifUserComment
},
3476 BOOL seen_gamma
=FALSE
, seen_whitepoint
=FALSE
, seen_chrm
=FALSE
;
3478 hr
= IWICBitmapDecoder_GetFrame(decoder
, active_frame
, &frame
);
3479 if (hr
!= S_OK
) return;
3481 hr
= IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3484 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3487 for (i
= 0; i
< block_count
; i
++)
3489 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3494 hr
= IWICMetadataReader_GetMetadataFormat(reader
, &format
);
3495 if (SUCCEEDED(hr
) && IsEqualGUID(&GUID_MetadataFormatChunktEXt
, &format
))
3497 PROPVARIANT name
, value
;
3500 hr
= IWICMetadataReader_GetValueByIndex(reader
, 0, NULL
, &name
, &value
);
3504 if (name
.vt
== VT_LPSTR
)
3506 for (j
= 0; j
< ARRAY_SIZE(keywords
); j
++)
3507 if (!strcmp(keywords
[j
].name
, name
.pszVal
))
3509 if (j
< ARRAY_SIZE(keywords
) && !keywords
[j
].seen
)
3511 keywords
[j
].seen
= TRUE
;
3512 item
= create_prop(keywords
[j
].propid
, &value
);
3514 add_property(bitmap
, item
);
3519 PropVariantClear(&name
);
3520 PropVariantClear(&value
);
3523 else if (SUCCEEDED(hr
) && IsEqualGUID(&GUID_MetadataFormatChunkgAMA
, &format
))
3529 item
= heap_alloc_zero(sizeof(PropertyItem
) + sizeof(ULONG
) * 2);
3533 item
->length
= sizeof(ULONG
) * 2;
3534 item
->type
= PropertyTagTypeRational
;
3535 item
->id
= PropertyTagGamma
;
3536 rational
= item
->value
= item
+ 1;
3537 rational
[0] = 100000;
3538 rational
[1] = get_ulong_by_index(reader
, 0);
3539 add_property(bitmap
, item
);
3545 else if (SUCCEEDED(hr
) && IsEqualGUID(&GUID_MetadataFormatChunkcHRM
, &format
))
3549 if (!seen_whitepoint
)
3551 item
= GdipAlloc(sizeof(PropertyItem
) + sizeof(ULONG
) * 4);
3555 item
->length
= sizeof(ULONG
) * 4;
3556 item
->type
= PropertyTagTypeRational
;
3557 item
->id
= PropertyTagWhitePoint
;
3558 rational
= item
->value
= item
+ 1;
3559 rational
[0] = get_ulong_by_index(reader
, 0);
3560 rational
[1] = 100000;
3561 rational
[2] = get_ulong_by_index(reader
, 1);
3562 rational
[3] = 100000;
3563 add_property(bitmap
, item
);
3564 seen_whitepoint
= TRUE
;
3570 item
= GdipAlloc(sizeof(PropertyItem
) + sizeof(ULONG
) * 12);
3574 item
->length
= sizeof(ULONG
) * 12;
3575 item
->type
= PropertyTagTypeRational
;
3576 item
->id
= PropertyTagPrimaryChromaticities
;
3577 rational
= item
->value
= item
+ 1;
3578 rational
[0] = get_ulong_by_index(reader
, 2);
3579 rational
[1] = 100000;
3580 rational
[2] = get_ulong_by_index(reader
, 3);
3581 rational
[3] = 100000;
3582 rational
[4] = get_ulong_by_index(reader
, 4);
3583 rational
[5] = 100000;
3584 rational
[6] = get_ulong_by_index(reader
, 5);
3585 rational
[7] = 100000;
3586 rational
[8] = get_ulong_by_index(reader
, 6);
3587 rational
[9] = 100000;
3588 rational
[10] = get_ulong_by_index(reader
, 7);
3589 rational
[11] = 100000;
3590 add_property(bitmap
, item
);
3597 IWICMetadataReader_Release(reader
);
3601 IWICMetadataBlockReader_Release(block_reader
);
3604 IWICBitmapFrameDecode_Release(frame
);
3607 static GpStatus
initialize_decoder_wic(IStream
*stream
, REFGUID container
, IWICBitmapDecoder
**decoder
)
3609 IWICImagingFactory
*factory
;
3612 TRACE("%p,%s\n", stream
, wine_dbgstr_guid(container
));
3614 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
3615 if (FAILED(hr
)) return hresult_to_status(hr
);
3616 hr
= IWICImagingFactory_CreateDecoder(factory
, container
, NULL
, decoder
);
3617 IWICImagingFactory_Release(factory
);
3618 if (FAILED(hr
)) return hresult_to_status(hr
);
3620 hr
= IWICBitmapDecoder_Initialize(*decoder
, stream
, WICDecodeMetadataCacheOnLoad
);
3623 IWICBitmapDecoder_Release(*decoder
);
3624 return hresult_to_status(hr
);
3629 typedef void (*metadata_reader_func
)(GpBitmap
*bitmap
, IWICBitmapDecoder
*decoder
, UINT frame
);
3631 static GpStatus
decode_frame_wic(IWICBitmapDecoder
*decoder
, BOOL force_conversion
,
3632 UINT active_frame
, metadata_reader_func metadata_reader
, GpImage
**image
)
3637 IWICBitmapFrameDecode
*frame
;
3638 IWICBitmapSource
*source
=NULL
;
3639 IWICMetadataBlockReader
*block_reader
;
3640 WICPixelFormatGUID wic_format
;
3641 PixelFormat gdip_format
=0;
3642 ColorPalette
*palette
= NULL
;
3643 WICBitmapPaletteType palette_type
= WICBitmapPaletteTypeFixedHalftone256
;
3645 UINT width
, height
, frame_count
;
3646 BitmapData lockeddata
;
3649 TRACE("%p,%u,%p\n", decoder
, active_frame
, image
);
3651 IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
3652 hr
= IWICBitmapDecoder_GetFrame(decoder
, active_frame
, &frame
);
3653 if (SUCCEEDED(hr
)) /* got frame */
3655 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &wic_format
);
3659 if (!force_conversion
)
3661 for (i
=0; pixel_formats
[i
].wic_format
; i
++)
3663 if (IsEqualGUID(&wic_format
, pixel_formats
[i
].wic_format
))
3665 source
= (IWICBitmapSource
*)frame
;
3666 IWICBitmapSource_AddRef(source
);
3667 gdip_format
= pixel_formats
[i
].gdip_format
;
3668 palette_type
= pixel_formats
[i
].palette_type
;
3675 /* unknown format; fall back on 32bppARGB */
3676 hr
= WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA
, (IWICBitmapSource
*)frame
, &source
);
3677 gdip_format
= PixelFormat32bppARGB
;
3679 TRACE("%s => %#x\n", wine_dbgstr_guid(&wic_format
), gdip_format
);
3682 if (SUCCEEDED(hr
)) /* got source */
3684 hr
= IWICBitmapSource_GetSize(source
, &width
, &height
);
3687 status
= GdipCreateBitmapFromScan0(width
, height
, 0, gdip_format
,
3690 if (SUCCEEDED(hr
) && status
== Ok
) /* created bitmap */
3692 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeWrite
,
3693 gdip_format
, &lockeddata
);
3694 if (status
== Ok
) /* locked bitmap */
3699 for (i
=0; i
<height
; i
++)
3702 hr
= IWICBitmapSource_CopyPixels(source
, &wrc
, abs(lockeddata
.Stride
),
3703 abs(lockeddata
.Stride
), (BYTE
*)lockeddata
.Scan0
+lockeddata
.Stride
*i
);
3704 if (FAILED(hr
)) break;
3707 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3710 if (SUCCEEDED(hr
) && status
== Ok
)
3711 *image
= &bitmap
->image
;
3715 GdipDisposeImage(&bitmap
->image
);
3718 if (SUCCEEDED(hr
) && status
== Ok
)
3721 hr
= IWICBitmapSource_GetResolution(source
, &dpix
, &dpiy
);
3724 bitmap
->image
.xres
= dpix
;
3725 bitmap
->image
.yres
= dpiy
;
3731 IWICBitmapSource_Release(source
);
3734 if (SUCCEEDED(hr
) && status
== Ok
) {
3735 bitmap
->metadata_reader
= NULL
;
3737 if (metadata_reader
)
3738 metadata_reader(bitmap
, decoder
, active_frame
);
3739 else if (IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
) == S_OK
)
3741 UINT block_count
= 0;
3742 if (IWICMetadataBlockReader_GetCount(block_reader
, &block_count
) == S_OK
&& block_count
)
3743 IWICMetadataBlockReader_GetReaderByIndex(block_reader
, 0, &bitmap
->metadata_reader
);
3744 IWICMetadataBlockReader_Release(block_reader
);
3747 palette
= get_palette(frame
, palette_type
);
3748 IWICBitmapFrameDecode_Release(frame
);
3752 if (FAILED(hr
) && status
== Ok
) status
= hresult_to_status(hr
);
3756 /* Native GDI+ used to be smarter, but since Win7 it just sets these flags. */
3757 bitmap
->image
.flags
|= ImageFlagsReadOnly
|ImageFlagsHasRealPixelSize
|ImageFlagsHasRealDPI
;
3758 if (IsEqualGUID(&wic_format
, &GUID_WICPixelFormat2bppGray
) ||
3759 IsEqualGUID(&wic_format
, &GUID_WICPixelFormat4bppGray
) ||
3760 IsEqualGUID(&wic_format
, &GUID_WICPixelFormat8bppGray
) ||
3761 IsEqualGUID(&wic_format
, &GUID_WICPixelFormat16bppGray
))
3762 bitmap
->image
.flags
|= ImageFlagsColorSpaceGRAY
;
3764 bitmap
->image
.flags
|= ImageFlagsColorSpaceRGB
;
3765 bitmap
->image
.frame_count
= frame_count
;
3766 bitmap
->image
.current_frame
= active_frame
;
3767 bitmap
->image
.decoder
= decoder
;
3768 IWICBitmapDecoder_AddRef(decoder
);
3771 heap_free(bitmap
->image
.palette
);
3772 bitmap
->image
.palette
= palette
;
3776 if (IsEqualGUID(&wic_format
, &GUID_WICPixelFormatBlackWhite
))
3777 bitmap
->image
.palette
->Flags
= 0;
3779 TRACE("=> %p\n", *image
);
3785 static GpStatus
decode_image_wic(IStream
*stream
, REFGUID container
,
3786 metadata_reader_func metadata_reader
, GpImage
**image
)
3788 IWICBitmapDecoder
*decoder
;
3791 status
= initialize_decoder_wic(stream
, container
, &decoder
);
3795 status
= decode_frame_wic(decoder
, FALSE
, 0, metadata_reader
, image
);
3796 IWICBitmapDecoder_Release(decoder
);
3800 static GpStatus
select_frame_wic(GpImage
*image
, UINT active_frame
)
3805 status
= decode_frame_wic(image
->decoder
, FALSE
, active_frame
, NULL
, &new_image
);
3809 new_image
->busy
= image
->busy
;
3810 memcpy(&new_image
->format
, &image
->format
, sizeof(GUID
));
3811 new_image
->encoder
= image
->encoder
;
3812 image
->encoder
= NULL
;
3813 free_image_data(image
);
3814 if (image
->type
== ImageTypeBitmap
)
3815 *(GpBitmap
*)image
= *(GpBitmap
*)new_image
;
3816 else if (image
->type
== ImageTypeMetafile
)
3817 *(GpMetafile
*)image
= *(GpMetafile
*)new_image
;
3818 new_image
->type
= ~0;
3819 heap_free(new_image
);
3823 static HRESULT
get_gif_frame_rect(IWICBitmapFrameDecode
*frame
,
3824 UINT
*left
, UINT
*top
, UINT
*width
, UINT
*height
)
3826 *left
= get_gif_frame_property(frame
, &GUID_MetadataFormatIMD
, L
"Left");
3827 *top
= get_gif_frame_property(frame
, &GUID_MetadataFormatIMD
, L
"Top");
3829 return IWICBitmapFrameDecode_GetSize(frame
, width
, height
);
3832 static HRESULT
blit_gif_frame(GpBitmap
*bitmap
, IWICBitmapFrameDecode
*frame
, BOOL first_frame
)
3834 UINT i
, j
, left
, top
, width
, height
;
3835 IWICBitmapSource
*source
;
3839 hr
= get_gif_frame_rect(frame
, &left
, &top
, &width
, &height
);
3843 hr
= WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA
, (IWICBitmapSource
*)frame
, &source
);
3847 new_bits
= heap_alloc_zero(width
*height
*4);
3849 return E_OUTOFMEMORY
;
3851 hr
= IWICBitmapSource_CopyPixels(source
, NULL
, width
*4, width
*height
*4, new_bits
);
3852 IWICBitmapSource_Release(source
);
3854 heap_free(new_bits
);
3858 for(i
=0; i
<height
&& i
+top
<bitmap
->height
; i
++) {
3859 for(j
=0; j
<width
&& j
+left
<bitmap
->width
; j
++) {
3860 DWORD
*src
= (DWORD
*)(new_bits
+i
*width
*4+j
*4);
3861 DWORD
*dst
= (DWORD
*)(bitmap
->bits
+(i
+top
)*bitmap
->stride
+(j
+left
)*4);
3863 if(first_frame
|| *src
>>24 != 0)
3867 heap_free(new_bits
);
3871 static DWORD
get_gif_background_color(GpBitmap
*bitmap
)
3873 BYTE bgcolor_idx
= 0;
3876 for(i
=0; i
<bitmap
->prop_count
; i
++) {
3877 if(bitmap
->prop_item
[i
].id
== PropertyTagIndexBackground
) {
3878 bgcolor_idx
= *(BYTE
*)bitmap
->prop_item
[i
].value
;
3883 for(i
=0; i
<bitmap
->prop_count
; i
++) {
3884 if(bitmap
->prop_item
[i
].id
== PropertyTagIndexTransparent
) {
3885 BYTE transparent_idx
;
3886 transparent_idx
= *(BYTE
*)bitmap
->prop_item
[i
].value
;
3888 if(transparent_idx
== bgcolor_idx
)
3893 for(i
=0; i
<bitmap
->prop_count
; i
++) {
3894 if(bitmap
->prop_item
[i
].id
== PropertyTagGlobalPalette
) {
3895 if(bitmap
->prop_item
[i
].length
/3 > bgcolor_idx
) {
3896 BYTE
*color
= ((BYTE
*)bitmap
->prop_item
[i
].value
)+bgcolor_idx
*3;
3897 return color
[2] + (color
[1]<<8) + (color
[0]<<16) + (0xffu
<<24);
3903 FIXME("can't get gif background color\n");
3907 static GpStatus
select_frame_gif(GpImage
* image
, UINT active_frame
)
3909 GpBitmap
*bitmap
= (GpBitmap
*)image
;
3910 IWICBitmapFrameDecode
*frame
;
3911 int cur_frame
=0, disposal
;
3912 BOOL bgcolor_set
= FALSE
;
3916 if(active_frame
> image
->current_frame
) {
3917 hr
= IWICBitmapDecoder_GetFrame(bitmap
->image
.decoder
, image
->current_frame
, &frame
);
3919 return hresult_to_status(hr
);
3920 disposal
= get_gif_frame_property(frame
, &GUID_MetadataFormatGCE
, L
"Disposal");
3921 IWICBitmapFrameDecode_Release(frame
);
3923 if(disposal
== GIF_DISPOSE_RESTORE_TO_BKGND
)
3924 cur_frame
= image
->current_frame
;
3925 else if(disposal
!= GIF_DISPOSE_RESTORE_TO_PREV
)
3926 cur_frame
= image
->current_frame
+1;
3929 while(cur_frame
!= active_frame
) {
3930 hr
= IWICBitmapDecoder_GetFrame(bitmap
->image
.decoder
, cur_frame
, &frame
);
3932 return hresult_to_status(hr
);
3933 disposal
= get_gif_frame_property(frame
, &GUID_MetadataFormatGCE
, L
"Disposal");
3935 if(disposal
==GIF_DISPOSE_UNSPECIFIED
|| disposal
==GIF_DISPOSE_DO_NOT_DISPOSE
) {
3936 hr
= blit_gif_frame(bitmap
, frame
, cur_frame
==0);
3938 return hresult_to_status(hr
);
3939 }else if(disposal
== GIF_DISPOSE_RESTORE_TO_BKGND
) {
3940 UINT left
, top
, width
, height
, i
, j
;
3943 bgcolor
= get_gif_background_color(bitmap
);
3947 hr
= get_gif_frame_rect(frame
, &left
, &top
, &width
, &height
);
3949 return hresult_to_status(hr
);
3950 for(i
=top
; i
<top
+height
&& i
<bitmap
->height
; i
++) {
3951 DWORD
*bits
= (DWORD
*)(bitmap
->bits
+i
*bitmap
->stride
);
3952 for(j
=left
; j
<left
+width
&& j
<bitmap
->width
; j
++)
3957 IWICBitmapFrameDecode_Release(frame
);
3961 hr
= IWICBitmapDecoder_GetFrame(bitmap
->image
.decoder
, active_frame
, &frame
);
3963 return hresult_to_status(hr
);
3965 hr
= blit_gif_frame(bitmap
, frame
, cur_frame
==0);
3966 IWICBitmapFrameDecode_Release(frame
);
3968 return hresult_to_status(hr
);
3970 image
->current_frame
= active_frame
;
3974 static GpStatus
decode_image_icon(IStream
* stream
, GpImage
**image
)
3976 return decode_image_wic(stream
, &GUID_ContainerFormatIco
, NULL
, image
);
3979 static GpStatus
decode_image_bmp(IStream
* stream
, GpImage
**image
)
3984 status
= decode_image_wic(stream
, &GUID_ContainerFormatBmp
, NULL
, image
);
3986 bitmap
= (GpBitmap
*)*image
;
3988 if (status
== Ok
&& bitmap
->format
== PixelFormat32bppARGB
)
3990 /* WIC supports bmp files with alpha, but gdiplus does not */
3991 bitmap
->format
= PixelFormat32bppRGB
;
3997 static GpStatus
decode_image_jpeg(IStream
* stream
, GpImage
**image
)
3999 return decode_image_wic(stream
, &GUID_ContainerFormatJpeg
, NULL
, image
);
4002 static BOOL
has_png_transparency_chunk(IStream
*pIStream
)
4005 BOOL has_tRNS
= FALSE
;
4012 ULARGE_INTEGER chunk_start
;
4013 ULONG bytesread
, chunk_size
;
4015 hr
= IStream_Seek(pIStream
, seek
, STREAM_SEEK_SET
, &chunk_start
);
4016 if (FAILED(hr
)) break;
4018 hr
= IStream_Read(pIStream
, header
, 8, &bytesread
);
4019 if (FAILED(hr
) || bytesread
< 8) break;
4021 chunk_size
= (header
[0] << 24) | (header
[1] << 16) | (header
[2] << 8) | header
[3];
4022 if (!memcmp(&header
[4], "tRNS", 4))
4028 seek
.QuadPart
= chunk_start
.QuadPart
+ chunk_size
+ 12; /* skip data and CRC */
4029 } while (memcmp(&header
[4], "IDAT", 4) && memcmp(&header
[4], "IEND", 4));
4031 TRACE("has_tRNS = %d\n", has_tRNS
);
4035 static GpStatus
decode_image_png(IStream
* stream
, GpImage
**image
)
4037 IWICBitmapDecoder
*decoder
;
4038 IWICBitmapFrameDecode
*frame
;
4042 BOOL force_conversion
= FALSE
;
4044 status
= initialize_decoder_wic(stream
, &GUID_ContainerFormatPng
, &decoder
);
4048 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
4051 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
4054 if (IsEqualGUID(&format
, &GUID_WICPixelFormat8bppGray
))
4055 force_conversion
= TRUE
;
4056 else if ((IsEqualGUID(&format
, &GUID_WICPixelFormat8bppIndexed
) ||
4057 IsEqualGUID(&format
, &GUID_WICPixelFormat4bppIndexed
) ||
4058 IsEqualGUID(&format
, &GUID_WICPixelFormat2bppIndexed
) ||
4059 IsEqualGUID(&format
, &GUID_WICPixelFormat1bppIndexed
) ||
4060 IsEqualGUID(&format
, &GUID_WICPixelFormat24bppBGR
)) &&
4061 has_png_transparency_chunk(stream
))
4062 force_conversion
= TRUE
;
4064 status
= decode_frame_wic(decoder
, force_conversion
, 0, png_metadata_reader
, image
);
4067 status
= hresult_to_status(hr
);
4069 IWICBitmapFrameDecode_Release(frame
);
4072 status
= hresult_to_status(hr
);
4074 IWICBitmapDecoder_Release(decoder
);
4078 static GpStatus
decode_image_gif(IStream
* stream
, GpImage
**image
)
4080 IWICBitmapDecoder
*decoder
;
4085 status
= initialize_decoder_wic(stream
, &GUID_ContainerFormatGif
, &decoder
);
4089 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
4091 return hresult_to_status(hr
);
4093 status
= decode_frame_wic(decoder
, frame_count
> 1, 0, gif_metadata_reader
, image
);
4094 IWICBitmapDecoder_Release(decoder
);
4098 if(frame_count
> 1) {
4099 heap_free((*image
)->palette
);
4100 (*image
)->palette
= NULL
;
4105 static GpStatus
decode_image_tiff(IStream
* stream
, GpImage
**image
)
4107 return decode_image_wic(stream
, &GUID_ContainerFormatTiff
, NULL
, image
);
4110 C_ASSERT(offsetof(WmfPlaceableFileHeader
, Key
) == 0);
4112 static GpStatus
load_wmf(IStream
*stream
, GpMetafile
**metafile
)
4114 WmfPlaceableFileHeader pfh
;
4115 BOOL is_placeable
= FALSE
;
4124 hr
= IStream_Read(stream
, &mh
, sizeof(mh
), &size
);
4125 if (hr
!= S_OK
|| size
!= sizeof(mh
))
4126 return GenericError
;
4128 /* detect whether stream starts with a WmfPlaceablefileheader */
4129 if (*(UINT32
*)&mh
== WMF_PLACEABLE_KEY
)
4132 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4133 if (FAILED(hr
)) return hresult_to_status(hr
);
4135 hr
= IStream_Read(stream
, &pfh
, sizeof(pfh
), &size
);
4136 if (hr
!= S_OK
|| size
!= sizeof(pfh
))
4137 return GenericError
;
4139 hr
= IStream_Read(stream
, &mh
, sizeof(mh
), &size
);
4140 if (hr
!= S_OK
|| size
!= sizeof(mh
))
4141 return GenericError
;
4143 is_placeable
= TRUE
;
4146 seek
.QuadPart
= is_placeable
? sizeof(pfh
) : 0;
4147 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4148 if (FAILED(hr
)) return hresult_to_status(hr
);
4150 buf
= heap_alloc(mh
.mtSize
* 2);
4151 if (!buf
) return OutOfMemory
;
4153 hr
= IStream_Read(stream
, buf
, mh
.mtSize
* 2, &size
);
4154 if (hr
!= S_OK
|| size
!= mh
.mtSize
* 2)
4157 return GenericError
;
4160 hmf
= SetMetaFileBitsEx(mh
.mtSize
* 2, buf
);
4163 return GenericError
;
4165 status
= GdipCreateMetafileFromWmf(hmf
, TRUE
, is_placeable
? &pfh
: NULL
, metafile
);
4167 DeleteMetaFile(hmf
);
4171 static GpStatus
decode_image_wmf(IStream
*stream
, GpImage
**image
)
4173 GpMetafile
*metafile
;
4176 TRACE("%p %p\n", stream
, image
);
4178 if (!stream
|| !image
)
4179 return InvalidParameter
;
4181 status
= load_wmf(stream
, &metafile
);
4184 TRACE("Could not load metafile\n");
4188 *image
= (GpImage
*)metafile
;
4189 TRACE("<-- %p\n", *image
);
4194 static GpStatus
load_emf(IStream
*stream
, GpMetafile
**metafile
)
4204 hr
= IStream_Read(stream
, &emh
, sizeof(emh
), &size
);
4205 if (hr
!= S_OK
|| size
!= sizeof(emh
) || emh
.dSignature
!= ENHMETA_SIGNATURE
)
4206 return GenericError
;
4209 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4210 if (FAILED(hr
)) return hresult_to_status(hr
);
4212 buf
= heap_alloc(emh
.nBytes
);
4213 if (!buf
) return OutOfMemory
;
4215 hr
= IStream_Read(stream
, buf
, emh
.nBytes
, &size
);
4216 if (hr
!= S_OK
|| size
!= emh
.nBytes
)
4219 return GenericError
;
4222 hemf
= SetEnhMetaFileBits(emh
.nBytes
, buf
);
4225 return GenericError
;
4227 status
= GdipCreateMetafileFromEmf(hemf
, TRUE
, metafile
);
4229 DeleteEnhMetaFile(hemf
);
4233 static GpStatus
decode_image_emf(IStream
*stream
, GpImage
**image
)
4235 GpMetafile
*metafile
;
4238 TRACE("%p %p\n", stream
, image
);
4240 if (!stream
|| !image
)
4241 return InvalidParameter
;
4243 status
= load_emf(stream
, &metafile
);
4246 TRACE("Could not load metafile\n");
4250 *image
= (GpImage
*)metafile
;
4251 TRACE("<-- %p\n", *image
);
4256 typedef GpStatus (*encode_image_func
)(GpImage
*image
, IStream
* stream
,
4257 GDIPCONST EncoderParameters
* params
);
4259 typedef GpStatus (*decode_image_func
)(IStream
*stream
, GpImage
**image
);
4261 typedef GpStatus (*select_image_func
)(GpImage
*image
, UINT active_frame
);
4263 typedef struct image_codec
{
4264 ImageCodecInfo info
;
4265 encode_image_func encode_func
;
4266 decode_image_func decode_func
;
4267 select_image_func select_func
;
4282 static const struct image_codec codecs
[NUM_CODECS
];
4284 static GpStatus
get_decoder_info(IStream
* stream
, const struct image_codec
**result
)
4287 const BYTE
*pattern
, *mask
;
4294 /* seek to the start of the stream */
4296 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4297 if (FAILED(hr
)) return hresult_to_status(hr
);
4299 /* read the first 8 bytes */
4300 /* FIXME: This assumes all codecs have signatures <= 8 bytes in length */
4301 hr
= IStream_Read(stream
, signature
, 8, &bytesread
);
4302 if (FAILED(hr
)) return hresult_to_status(hr
);
4303 if (hr
== S_FALSE
|| bytesread
== 0) return GenericError
;
4305 for (i
= 0; i
< NUM_CODECS
; i
++) {
4306 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
) &&
4307 bytesread
>= codecs
[i
].info
.SigSize
)
4309 for (sig
=0; sig
<codecs
[i
].info
.SigCount
; sig
++)
4311 pattern
= &codecs
[i
].info
.SigPattern
[codecs
[i
].info
.SigSize
*sig
];
4312 mask
= &codecs
[i
].info
.SigMask
[codecs
[i
].info
.SigSize
*sig
];
4313 for (j
=0; j
<codecs
[i
].info
.SigSize
; j
++)
4314 if ((signature
[j
] & mask
[j
]) != pattern
[j
])
4316 if (j
== codecs
[i
].info
.SigSize
)
4318 *result
= &codecs
[i
];
4325 TRACE("no match for %lu byte signature %x %x %x %x %x %x %x %x\n", bytesread
,
4326 signature
[0],signature
[1],signature
[2],signature
[3],
4327 signature
[4],signature
[5],signature
[6],signature
[7]);
4329 return GenericError
;
4332 static GpStatus
get_decoder_info_from_image(GpImage
*image
, const struct image_codec
**result
)
4336 for (i
= 0; i
< NUM_CODECS
; i
++) {
4337 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
) &&
4338 IsEqualIID(&codecs
[i
].info
.FormatID
, &image
->format
))
4340 *result
= &codecs
[i
];
4345 TRACE("no match for format: %s\n", wine_dbgstr_guid(&image
->format
));
4346 return GenericError
;
4349 GpStatus WINGDIPAPI
GdipImageSelectActiveFrame(GpImage
*image
, GDIPCONST GUID
*dimensionID
,
4353 const struct image_codec
*codec
= NULL
;
4356 TRACE("(%p,%s,%u)\n", image
, debugstr_guid(dimensionID
), frame
);
4358 if (!image
|| !dimensionID
)
4359 return InvalidParameter
;
4360 if(!image_lock(image
, &unlock
))
4363 if (frame
>= image
->frame_count
)
4365 WARN("requested frame %u, but image has only %u\n", frame
, image
->frame_count
);
4366 image_unlock(image
, unlock
);
4367 return InvalidParameter
;
4370 if (image
->type
!= ImageTypeBitmap
&& image
->type
!= ImageTypeMetafile
)
4372 WARN("invalid image type %d\n", image
->type
);
4373 image_unlock(image
, unlock
);
4374 return InvalidParameter
;
4377 if (image
->current_frame
== frame
)
4379 image_unlock(image
, unlock
);
4383 if (!image
->decoder
)
4385 TRACE("image doesn't have an associated decoder\n");
4386 image_unlock(image
, unlock
);
4390 /* choose an appropriate image decoder */
4391 stat
= get_decoder_info_from_image(image
, &codec
);
4394 WARN("can't find decoder info\n");
4395 image_unlock(image
, unlock
);
4399 stat
= codec
->select_func(image
, frame
);
4400 image_unlock(image
, unlock
);
4404 GpStatus WINGDIPAPI
GdipLoadImageFromStream(IStream
*stream
, GpImage
**image
)
4409 const struct image_codec
*codec
=NULL
;
4411 TRACE("%p %p\n", stream
, image
);
4413 if (!stream
|| !image
)
4414 return InvalidParameter
;
4416 /* choose an appropriate image decoder */
4417 stat
= get_decoder_info(stream
, &codec
);
4418 if (stat
!= Ok
) return stat
;
4420 /* seek to the start of the stream */
4422 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4423 if (FAILED(hr
)) return hresult_to_status(hr
);
4425 /* call on the image decoder to do the real work */
4426 stat
= codec
->decode_func(stream
, image
);
4428 /* take note of the original data format */
4431 memcpy(&(*image
)->format
, &codec
->info
.FormatID
, sizeof(GUID
));
4439 GpStatus WINGDIPAPI
GdipLoadImageFromStreamICM(IStream
* stream
, GpImage
**image
)
4441 TRACE("%p %p\n", stream
, image
);
4443 return GdipLoadImageFromStream(stream
, image
);
4446 GpStatus WINGDIPAPI
GdipRemovePropertyItem(GpImage
*image
, PROPID propId
)
4450 TRACE("(%p,%lu)\n", image
, propId
);
4453 return InvalidParameter
;
4456 FIXME("not implemented\n");
4458 return NotImplemented
;
4461 GpStatus WINGDIPAPI
GdipSetPropertyItem(GpImage
*image
, GDIPCONST PropertyItem
* item
)
4465 if (!image
|| !item
) return InvalidParameter
;
4467 TRACE("(%p,%p:%#lx,%u,%lu,%p)\n", image
, item
, item
->id
, item
->type
, item
->length
, item
->value
);
4470 FIXME("not implemented\n");
4475 GpStatus WINGDIPAPI
GdipSaveImageToFile(GpImage
*image
, GDIPCONST WCHAR
* filename
,
4476 GDIPCONST CLSID
*clsidEncoder
,
4477 GDIPCONST EncoderParameters
*encoderParams
)
4482 TRACE("%p (%s) %p %p\n", image
, debugstr_w(filename
), clsidEncoder
, encoderParams
);
4484 if (!image
|| !filename
|| !clsidEncoder
)
4485 return InvalidParameter
;
4487 /* this might release an old file stream held by the encoder so we can re-create it below */
4488 terminate_encoder_wic(image
);
4490 stat
= GdipCreateStreamOnFile(filename
, GENERIC_WRITE
, &stream
);
4492 return GenericError
;
4494 stat
= GdipSaveImageToStream(image
, stream
, clsidEncoder
, encoderParams
);
4496 IStream_Release(stream
);
4500 /*************************************************************************
4501 * Encoding functions -
4502 * These functions encode an image in different image file formats.
4505 static GpStatus
initialize_encoder_wic(IStream
*stream
, REFGUID container
, GpImage
*image
)
4507 IWICImagingFactory
*factory
;
4510 TRACE("%p,%s\n", stream
, wine_dbgstr_guid(container
));
4512 terminate_encoder_wic(image
); /* terminate previous encoder if it exists */
4514 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
4515 if (FAILED(hr
)) return hresult_to_status(hr
);
4516 hr
= IWICImagingFactory_CreateEncoder(factory
, container
, NULL
, &image
->encoder
);
4517 IWICImagingFactory_Release(factory
);
4520 image
->encoder
= NULL
;
4521 return hresult_to_status(hr
);
4524 hr
= IWICBitmapEncoder_Initialize(image
->encoder
, stream
, WICBitmapEncoderNoCache
);
4527 IWICBitmapEncoder_Release(image
->encoder
);
4528 image
->encoder
= NULL
;
4529 return hresult_to_status(hr
);
4534 GpStatus
terminate_encoder_wic(GpImage
*image
)
4536 if (!image
->encoder
)
4540 HRESULT hr
= IWICBitmapEncoder_Commit(image
->encoder
);
4541 IWICBitmapEncoder_Release(image
->encoder
);
4542 image
->encoder
= NULL
;
4543 return hresult_to_status(hr
);
4547 static GpStatus
encode_frame_wic(IWICBitmapEncoder
*encoder
, GpImage
*image
)
4551 IWICBitmapFrameEncode
*frameencode
;
4552 IPropertyBag2
*encoderoptions
;
4553 GUID container_format
;
4556 PixelFormat gdipformat
=0;
4557 const WICPixelFormatGUID
*desired_wicformat
;
4558 WICPixelFormatGUID wicformat
;
4560 BitmapData lockeddata
;
4563 if (image
->type
!= ImageTypeBitmap
)
4564 return GenericError
;
4566 bitmap
= (GpBitmap
*)image
;
4568 GdipGetImageWidth(image
, &width
);
4569 GdipGetImageHeight(image
, &height
);
4576 hr
= IWICBitmapEncoder_CreateNewFrame(encoder
, &frameencode
, &encoderoptions
);
4578 if (SUCCEEDED(hr
)) /* created frame */
4580 hr
= IWICBitmapEncoder_GetContainerFormat(encoder
, &container_format
);
4581 if (SUCCEEDED(hr
) && IsEqualGUID(&container_format
, &GUID_ContainerFormatPng
))
4583 /* disable PNG filters for faster encoding */
4584 PROPBAG2 filter_option
= { .pstrName
= (LPOLESTR
) L
"FilterOption" };
4585 VARIANT filter_value
;
4586 VariantInit(&filter_value
);
4587 V_VT(&filter_value
) = VT_UI1
;
4588 V_UI1(&filter_value
) = WICPngFilterNone
;
4589 hr
= IPropertyBag2_Write(encoderoptions
, 1, &filter_option
, &filter_value
);
4593 hr
= IWICBitmapFrameEncode_Initialize(frameencode
, encoderoptions
);
4596 hr
= IWICBitmapFrameEncode_SetSize(frameencode
, width
, height
);
4599 hr
= IWICBitmapFrameEncode_SetResolution(frameencode
, image
->xres
, image
->yres
);
4603 for (i
=0; pixel_formats
[i
].wic_format
; i
++)
4605 if (pixel_formats
[i
].gdip_format
== bitmap
->format
)
4607 desired_wicformat
= pixel_formats
[i
].wic_format
;
4608 gdipformat
= bitmap
->format
;
4614 desired_wicformat
= &GUID_WICPixelFormat32bppBGRA
;
4615 gdipformat
= PixelFormat32bppARGB
;
4618 memcpy(&wicformat
, desired_wicformat
, sizeof(GUID
));
4619 hr
= IWICBitmapFrameEncode_SetPixelFormat(frameencode
, &wicformat
);
4622 if (SUCCEEDED(hr
) && !IsEqualGUID(desired_wicformat
, &wicformat
))
4624 /* Encoder doesn't support this bitmap's format. */
4626 for (i
=0; pixel_formats
[i
].wic_format
; i
++)
4628 if (IsEqualGUID(&wicformat
, pixel_formats
[i
].wic_format
))
4630 gdipformat
= pixel_formats
[i
].gdip_format
;
4636 ERR("Cannot support encoder format %s\n", debugstr_guid(&wicformat
));
4641 if (SUCCEEDED(hr
) && IsIndexedPixelFormat(gdipformat
) && image
->palette
)
4642 hr
= set_palette(frameencode
, image
->palette
);
4646 stat
= GdipBitmapLockBits(bitmap
, &rc
, ImageLockModeRead
, gdipformat
,
4651 UINT row_size
= (lockeddata
.Width
* PIXELFORMATBPP(gdipformat
) + 7)/8;
4654 /* write one row at a time in case stride is negative */
4655 row
= lockeddata
.Scan0
;
4656 for (i
=0; i
<lockeddata
.Height
; i
++)
4658 hr
= IWICBitmapFrameEncode_WritePixels(frameencode
, 1, row_size
, row_size
, row
);
4659 if (FAILED(hr
)) break;
4660 row
+= lockeddata
.Stride
;
4663 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
4670 hr
= IWICBitmapFrameEncode_Commit(frameencode
);
4672 IWICBitmapFrameEncode_Release(frameencode
);
4673 IPropertyBag2_Release(encoderoptions
);
4676 return hresult_to_status(hr
);
4679 static BOOL
has_encoder_param_long(GDIPCONST EncoderParameters
*params
, GUID param_guid
, ULONG val
)
4681 int param_idx
, value_idx
;
4686 for (param_idx
= 0; param_idx
< params
->Count
; param_idx
++)
4688 EncoderParameter param
= params
->Parameter
[param_idx
];
4689 if (param
.Type
== EncoderParameterValueTypeLong
&& IsEqualCLSID(¶m
.Guid
, ¶m_guid
))
4691 ULONG
*value_array
= (ULONG
*) param
.Value
;
4692 for (value_idx
= 0; value_idx
< param
.NumberOfValues
; value_idx
++)
4694 if (value_array
[value_idx
] == val
)
4702 static GpStatus
encode_image_wic(GpImage
*image
, IStream
*stream
,
4703 REFGUID container
, GDIPCONST EncoderParameters
*params
)
4705 GpStatus status
, terminate_status
;
4707 if (image
->type
!= ImageTypeBitmap
)
4708 return GenericError
;
4710 status
= initialize_encoder_wic(stream
, container
, image
);
4713 status
= encode_frame_wic(image
->encoder
, image
);
4715 if (!has_encoder_param_long(params
, EncoderSaveFlag
, EncoderValueMultiFrame
))
4717 /* always try to terminate, but if something already failed earlier, keep the old status. */
4718 terminate_status
= terminate_encoder_wic(image
);
4720 status
= terminate_status
;
4726 static GpStatus
encode_image_BMP(GpImage
*image
, IStream
* stream
,
4727 GDIPCONST EncoderParameters
* params
)
4729 return encode_image_wic(image
, stream
, &GUID_ContainerFormatBmp
, params
);
4732 static GpStatus
encode_image_tiff(GpImage
*image
, IStream
* stream
,
4733 GDIPCONST EncoderParameters
* params
)
4735 return encode_image_wic(image
, stream
, &GUID_ContainerFormatTiff
, params
);
4738 GpStatus
encode_image_png(GpImage
*image
, IStream
* stream
,
4739 GDIPCONST EncoderParameters
* params
)
4741 return encode_image_wic(image
, stream
, &GUID_ContainerFormatPng
, params
);
4744 static GpStatus
encode_image_jpeg(GpImage
*image
, IStream
* stream
,
4745 GDIPCONST EncoderParameters
* params
)
4747 return encode_image_wic(image
, stream
, &GUID_ContainerFormatJpeg
, params
);
4750 static GpStatus
encode_image_gif(GpImage
*image
, IStream
* stream
,
4751 GDIPCONST EncoderParameters
* params
)
4753 return encode_image_wic(image
, stream
, &GUID_ContainerFormatGif
, params
);
4756 /*****************************************************************************
4757 * GdipSaveImageToStream [GDIPLUS.@]
4759 GpStatus WINGDIPAPI
GdipSaveImageToStream(GpImage
*image
, IStream
* stream
,
4760 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4763 encode_image_func encode_image
;
4766 TRACE("%p, %p, %s, %p\n", image
, stream
, wine_dbgstr_guid(clsid
), params
);
4768 if(!image
|| !stream
)
4769 return InvalidParameter
;
4771 /* select correct encoder */
4772 encode_image
= NULL
;
4773 for (i
= 0; i
< NUM_CODECS
; i
++) {
4774 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
) &&
4775 IsEqualCLSID(clsid
, &codecs
[i
].info
.Clsid
))
4776 encode_image
= codecs
[i
].encode_func
;
4778 if (encode_image
== NULL
)
4779 return UnknownImageFormat
;
4781 stat
= encode_image(image
, stream
, params
);
4786 /*****************************************************************************
4787 * GdipSaveAdd [GDIPLUS.@]
4789 * Like GdipSaveAddImage(), but encode the currently active frame of the given image into the file
4790 * or stream that is currently being encoded.
4792 GpStatus WINGDIPAPI
GdipSaveAdd(GpImage
*image
, GDIPCONST EncoderParameters
*params
)
4794 return GdipSaveAddImage(image
, image
, params
);
4797 /*****************************************************************************
4798 * GdipSaveAddImage [GDIPLUS.@]
4800 * Encode the currently active frame of additional_image into the file or stream that is currently
4801 * being encoded by the image given in the image parameter. The first frame of a multi-frame image
4802 * must be encoded using the normal GdipSaveImageToStream() or GdipSaveImageToFile() functions,
4803 * but with the "MultiFrame" encoding parameter set. The multi-frame encoding process must be
4804 * finished after adding the last frame by calling GdipSaveAdd() with the "Flush" encoding parameter
4807 GpStatus WINGDIPAPI
GdipSaveAddImage(GpImage
*image
, GpImage
*additional_image
,
4808 GDIPCONST EncoderParameters
*params
)
4810 TRACE("%p, %p, %p\n", image
, additional_image
, params
);
4812 if (!image
|| !additional_image
|| !params
)
4813 return InvalidParameter
;
4815 if (!image
->encoder
)
4818 if (has_encoder_param_long(params
, EncoderSaveFlag
, EncoderValueFlush
))
4819 return terminate_encoder_wic(image
);
4820 else if (has_encoder_param_long(params
, EncoderSaveFlag
, EncoderValueFrameDimensionPage
))
4821 return encode_frame_wic(image
->encoder
, additional_image
);
4823 return InvalidParameter
;
4826 /*****************************************************************************
4827 * GdipGetImagePalette [GDIPLUS.@]
4829 GpStatus WINGDIPAPI
GdipGetImagePalette(GpImage
*image
, ColorPalette
*palette
, INT size
)
4833 TRACE("(%p,%p,%i)\n", image
, palette
, size
);
4835 if (!image
|| !palette
)
4836 return InvalidParameter
;
4838 count
= image
->palette
? image
->palette
->Count
: 0;
4840 if (size
< (sizeof(UINT
)*2+sizeof(ARGB
)*count
))
4842 TRACE("<-- InsufficientBuffer\n");
4843 return InsufficientBuffer
;
4848 palette
->Flags
= image
->palette
->Flags
;
4849 palette
->Count
= image
->palette
->Count
;
4850 memcpy(palette
->Entries
, image
->palette
->Entries
, sizeof(ARGB
)*image
->palette
->Count
);
4860 /*****************************************************************************
4861 * GdipSetImagePalette [GDIPLUS.@]
4863 GpStatus WINGDIPAPI
GdipSetImagePalette(GpImage
*image
,
4864 GDIPCONST ColorPalette
*palette
)
4866 ColorPalette
*new_palette
;
4868 TRACE("(%p,%p)\n", image
, palette
);
4870 if(!image
|| !palette
|| palette
->Count
> 256)
4871 return InvalidParameter
;
4873 new_palette
= heap_alloc_zero(2 * sizeof(UINT
) + palette
->Count
* sizeof(ARGB
));
4874 if (!new_palette
) return OutOfMemory
;
4876 heap_free(image
->palette
);
4877 image
->palette
= new_palette
;
4878 image
->palette
->Flags
= palette
->Flags
;
4879 image
->palette
->Count
= palette
->Count
;
4880 memcpy(image
->palette
->Entries
, palette
->Entries
, sizeof(ARGB
)*palette
->Count
);
4885 /*************************************************************************
4887 * Structures that represent which formats we support for encoding.
4890 /* ImageCodecInfo creation routines taken from libgdiplus */
4891 static const WCHAR bmp_codecname
[] = L
"Built-in BMP";
4892 static const WCHAR bmp_extension
[] = L
"*.BMP;*.DIB;*.RLE";
4893 static const WCHAR bmp_mimetype
[] = L
"image/bmp";
4894 static const WCHAR bmp_format
[] = L
"BMP";
4895 static const BYTE bmp_sig_pattern
[] = { 0x42, 0x4D };
4896 static const BYTE bmp_sig_mask
[] = { 0xFF, 0xFF };
4898 static const WCHAR jpeg_codecname
[] = L
"Built-in JPEG";
4899 static const WCHAR jpeg_extension
[] = L
"*.JPG;*.JPEG;*.JPE;*.JFIF";
4900 static const WCHAR jpeg_mimetype
[] = L
"image/jpeg";
4901 static const WCHAR jpeg_format
[] = L
"JPEG";
4902 static const BYTE jpeg_sig_pattern
[] = { 0xFF, 0xD8 };
4903 static const BYTE jpeg_sig_mask
[] = { 0xFF, 0xFF };
4905 static const WCHAR gif_codecname
[] = L
"Built-in GIF";
4906 static const WCHAR gif_extension
[] = L
"*.GIF";
4907 static const WCHAR gif_mimetype
[] = L
"image/gif";
4908 static const WCHAR gif_format
[] = L
"GIF";
4909 static const BYTE gif_sig_pattern
[12] = "GIF87aGIF89a";
4910 static const BYTE gif_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4912 static const WCHAR tiff_codecname
[] = L
"Built-in TIFF";
4913 static const WCHAR tiff_extension
[] = L
"*.TIFF;*.TIF";
4914 static const WCHAR tiff_mimetype
[] = L
"image/tiff";
4915 static const WCHAR tiff_format
[] = L
"TIFF";
4916 static const BYTE tiff_sig_pattern
[] = {0x49,0x49,42,0,0x4d,0x4d,0,42};
4917 static const BYTE tiff_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4919 static const WCHAR emf_codecname
[] = L
"Built-in EMF";
4920 static const WCHAR emf_extension
[] = L
"*.EMF";
4921 static const WCHAR emf_mimetype
[] = L
"image/x-emf";
4922 static const WCHAR emf_format
[] = L
"EMF";
4923 static const BYTE emf_sig_pattern
[] = { 0x01, 0x00, 0x00, 0x00 };
4924 static const BYTE emf_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
4926 static const WCHAR wmf_codecname
[] = L
"Built-in WMF";
4927 static const WCHAR wmf_extension
[] = L
"*.WMF";
4928 static const WCHAR wmf_mimetype
[] = L
"image/x-wmf";
4929 static const WCHAR wmf_format
[] = L
"WMF";
4930 static const BYTE wmf_sig_pattern
[] = { 0xd7, 0xcd };
4931 static const BYTE wmf_sig_mask
[] = { 0xFF, 0xFF };
4933 static const WCHAR png_codecname
[] = L
"Built-in PNG";
4934 static const WCHAR png_extension
[] = L
"*.PNG";
4935 static const WCHAR png_mimetype
[] = L
"image/png";
4936 static const WCHAR png_format
[] = L
"PNG";
4937 static const BYTE png_sig_pattern
[] = { 137, 80, 78, 71, 13, 10, 26, 10, };
4938 static const BYTE png_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4940 static const WCHAR ico_codecname
[] = L
"Built-in ICO";
4941 static const WCHAR ico_extension
[] = L
"*.ICO";
4942 static const WCHAR ico_mimetype
[] = L
"image/x-icon";
4943 static const WCHAR ico_format
[] = L
"ICO";
4944 static const BYTE ico_sig_pattern
[] = { 0x00, 0x00, 0x01, 0x00 };
4945 static const BYTE ico_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
4947 static const struct image_codec codecs
[NUM_CODECS
] = {
4950 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4951 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4952 /* CodecName */ bmp_codecname
,
4954 /* FormatDescription */ bmp_format
,
4955 /* FilenameExtension */ bmp_extension
,
4956 /* MimeType */ bmp_mimetype
,
4957 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4961 /* SigPattern */ bmp_sig_pattern
,
4962 /* SigMask */ bmp_sig_mask
,
4970 /* Clsid */ { 0x557cf401, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4971 /* FormatID */ { 0xb96b3caeU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4972 /* CodecName */ jpeg_codecname
,
4974 /* FormatDescription */ jpeg_format
,
4975 /* FilenameExtension */ jpeg_extension
,
4976 /* MimeType */ jpeg_mimetype
,
4977 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4981 /* SigPattern */ jpeg_sig_pattern
,
4982 /* SigMask */ jpeg_sig_mask
,
4990 /* Clsid */ { 0x557cf402, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4991 /* FormatID */ { 0xb96b3cb0U
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4992 /* CodecName */ gif_codecname
,
4994 /* FormatDescription */ gif_format
,
4995 /* FilenameExtension */ gif_extension
,
4996 /* MimeType */ gif_mimetype
,
4997 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsEncoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
5001 /* SigPattern */ gif_sig_pattern
,
5002 /* SigMask */ gif_sig_mask
,
5010 /* Clsid */ { 0x557cf405, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
5011 /* FormatID */ { 0xb96b3cb1U
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
5012 /* CodecName */ tiff_codecname
,
5014 /* FormatDescription */ tiff_format
,
5015 /* FilenameExtension */ tiff_extension
,
5016 /* MimeType */ tiff_mimetype
,
5017 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsEncoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
5021 /* SigPattern */ tiff_sig_pattern
,
5022 /* SigMask */ tiff_sig_mask
,
5030 /* Clsid */ { 0x557cf403, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
5031 /* FormatID */ { 0xb96b3cacU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
5032 /* CodecName */ emf_codecname
,
5034 /* FormatDescription */ emf_format
,
5035 /* FilenameExtension */ emf_extension
,
5036 /* MimeType */ emf_mimetype
,
5037 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
5041 /* SigPattern */ emf_sig_pattern
,
5042 /* SigMask */ emf_sig_mask
,
5050 /* Clsid */ { 0x557cf404, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
5051 /* FormatID */ { 0xb96b3cadU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
5052 /* CodecName */ wmf_codecname
,
5054 /* FormatDescription */ wmf_format
,
5055 /* FilenameExtension */ wmf_extension
,
5056 /* MimeType */ wmf_mimetype
,
5057 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
5061 /* SigPattern */ wmf_sig_pattern
,
5062 /* SigMask */ wmf_sig_mask
,
5070 /* Clsid */ { 0x557cf406, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
5071 /* FormatID */ { 0xb96b3cafU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
5072 /* CodecName */ png_codecname
,
5074 /* FormatDescription */ png_format
,
5075 /* FilenameExtension */ png_extension
,
5076 /* MimeType */ png_mimetype
,
5077 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
5081 /* SigPattern */ png_sig_pattern
,
5082 /* SigMask */ png_sig_mask
,
5090 /* Clsid */ { 0x557cf407, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
5091 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
5092 /* CodecName */ ico_codecname
,
5094 /* FormatDescription */ ico_format
,
5095 /* FilenameExtension */ ico_extension
,
5096 /* MimeType */ ico_mimetype
,
5097 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
5101 /* SigPattern */ ico_sig_pattern
,
5102 /* SigMask */ ico_sig_mask
,
5110 /*****************************************************************************
5111 * GdipGetImageDecodersSize [GDIPLUS.@]
5113 GpStatus WINGDIPAPI
GdipGetImageDecodersSize(UINT
*numDecoders
, UINT
*size
)
5115 int decoder_count
=0;
5117 TRACE("%p %p\n", numDecoders
, size
);
5119 if (!numDecoders
|| !size
)
5120 return InvalidParameter
;
5122 for (i
=0; i
<NUM_CODECS
; i
++)
5124 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
5128 *numDecoders
= decoder_count
;
5129 *size
= decoder_count
* sizeof(ImageCodecInfo
);
5134 /*****************************************************************************
5135 * GdipGetImageDecoders [GDIPLUS.@]
5137 GpStatus WINGDIPAPI
GdipGetImageDecoders(UINT numDecoders
, UINT size
, ImageCodecInfo
*decoders
)
5139 int i
, decoder_count
=0;
5140 TRACE("%u %u %p\n", numDecoders
, size
, decoders
);
5143 size
!= numDecoders
* sizeof(ImageCodecInfo
))
5144 return GenericError
;
5146 for (i
=0; i
<NUM_CODECS
; i
++)
5148 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
5150 if (decoder_count
== numDecoders
) return GenericError
;
5151 memcpy(&decoders
[decoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
5156 if (decoder_count
< numDecoders
) return GenericError
;
5161 /*****************************************************************************
5162 * GdipGetImageEncodersSize [GDIPLUS.@]
5164 GpStatus WINGDIPAPI
GdipGetImageEncodersSize(UINT
*numEncoders
, UINT
*size
)
5166 int encoder_count
=0;
5168 TRACE("%p %p\n", numEncoders
, size
);
5170 if (!numEncoders
|| !size
)
5171 return InvalidParameter
;
5173 for (i
=0; i
<NUM_CODECS
; i
++)
5175 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
5179 *numEncoders
= encoder_count
;
5180 *size
= encoder_count
* sizeof(ImageCodecInfo
);
5185 /*****************************************************************************
5186 * GdipGetImageEncoders [GDIPLUS.@]
5188 GpStatus WINGDIPAPI
GdipGetImageEncoders(UINT numEncoders
, UINT size
, ImageCodecInfo
*encoders
)
5190 int i
, encoder_count
=0;
5191 TRACE("%u %u %p\n", numEncoders
, size
, encoders
);
5194 size
!= numEncoders
* sizeof(ImageCodecInfo
))
5195 return GenericError
;
5197 for (i
=0; i
<NUM_CODECS
; i
++)
5199 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
5201 if (encoder_count
== numEncoders
) return GenericError
;
5202 memcpy(&encoders
[encoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
5207 if (encoder_count
< numEncoders
) return GenericError
;
5212 GpStatus WINGDIPAPI
GdipGetEncoderParameterListSize(GpImage
*image
,
5213 GDIPCONST CLSID
* clsidEncoder
, UINT
*size
)
5217 TRACE("(%p,%s,%p)\n", image
, debugstr_guid(clsidEncoder
), size
);
5220 FIXME("not implemented\n");
5224 return NotImplemented
;
5227 static PixelFormat
get_16bpp_format(HBITMAP hbm
)
5233 hdc
= CreateCompatibleDC(NULL
);
5235 memset(&bmh
, 0, sizeof(bmh
));
5236 bmh
.bV4Size
= sizeof(bmh
);
5239 bmh
.bV4V4Compression
= BI_BITFIELDS
;
5240 bmh
.bV4BitCount
= 16;
5242 GetDIBits(hdc
, hbm
, 0, 0, NULL
, (BITMAPINFO
*)&bmh
, DIB_RGB_COLORS
);
5244 if (bmh
.bV4RedMask
== 0x7c00 &&
5245 bmh
.bV4GreenMask
== 0x3e0 &&
5246 bmh
.bV4BlueMask
== 0x1f)
5248 result
= PixelFormat16bppRGB555
;
5250 else if (bmh
.bV4RedMask
== 0xf800 &&
5251 bmh
.bV4GreenMask
== 0x7e0 &&
5252 bmh
.bV4BlueMask
== 0x1f)
5254 result
= PixelFormat16bppRGB565
;
5258 FIXME("unrecognized bitfields %lx,%lx,%lx\n", bmh
.bV4RedMask
,
5259 bmh
.bV4GreenMask
, bmh
.bV4BlueMask
);
5260 result
= PixelFormatUndefined
;
5268 /*****************************************************************************
5269 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
5271 GpStatus WINGDIPAPI
GdipCreateBitmapFromHBITMAP(HBITMAP hbm
, HPALETTE hpal
, GpBitmap
** bitmap
)
5276 BitmapData lockeddata
;
5277 char bmibuf
[FIELD_OFFSET(BITMAPINFO
, bmiColors
[256])];
5278 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
5280 TRACE("%p %p %p\n", hbm
, hpal
, bitmap
);
5283 return InvalidParameter
;
5285 if (GetObjectA(hbm
, sizeof(bm
), &bm
) != sizeof(bm
))
5286 return InvalidParameter
;
5288 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
5289 switch(bm
.bmBitsPixel
) {
5291 format
= PixelFormat1bppIndexed
;
5294 format
= PixelFormat4bppIndexed
;
5297 format
= PixelFormat8bppIndexed
;
5300 format
= get_16bpp_format(hbm
);
5301 if (format
== PixelFormatUndefined
)
5302 return InvalidParameter
;
5305 format
= PixelFormat24bppRGB
;
5308 format
= PixelFormat32bppRGB
;
5311 format
= PixelFormat48bppRGB
;
5314 FIXME("don't know how to handle %d bpp\n", bm
.bmBitsPixel
);
5315 return InvalidParameter
;
5318 retval
= GdipCreateBitmapFromScan0(bm
.bmWidth
, bm
.bmHeight
, 0,
5319 format
, NULL
, bitmap
);
5323 retval
= GdipBitmapLockBits(*bitmap
, NULL
, ImageLockModeWrite
,
5324 format
, &lockeddata
);
5330 hdc
= CreateCompatibleDC(NULL
);
5332 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
5333 pbmi
->bmiHeader
.biBitCount
= 0;
5335 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
5337 src_height
= abs(pbmi
->bmiHeader
.biHeight
);
5338 pbmi
->bmiHeader
.biHeight
= -src_height
;
5340 GetDIBits(hdc
, hbm
, 0, src_height
, lockeddata
.Scan0
, pbmi
, DIB_RGB_COLORS
);
5344 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
5347 /* According to the tests hpal is ignored */
5348 if (retval
== Ok
&& pbmi
->bmiHeader
.biBitCount
<= 8)
5350 ColorPalette
*palette
;
5351 int i
, num_palette_entries
;
5353 num_palette_entries
= pbmi
->bmiHeader
.biClrUsed
;
5354 if (!num_palette_entries
)
5355 num_palette_entries
= 1 << pbmi
->bmiHeader
.biBitCount
;
5357 palette
= heap_alloc_zero(sizeof(ColorPalette
) + sizeof(ARGB
) * (num_palette_entries
-1));
5359 retval
= OutOfMemory
;
5363 palette
->Count
= num_palette_entries
;
5365 for (i
=0; i
<num_palette_entries
; i
++)
5367 palette
->Entries
[i
] = 0xff000000 | pbmi
->bmiColors
[i
].rgbRed
<< 16 |
5368 pbmi
->bmiColors
[i
].rgbGreen
<< 8 | pbmi
->bmiColors
[i
].rgbBlue
;
5371 retval
= GdipSetImagePalette(&(*bitmap
)->image
, palette
);
5379 GdipDisposeImage(&(*bitmap
)->image
);
5387 /*****************************************************************************
5388 * GdipCreateEffect [GDIPLUS.@]
5390 GpStatus WINGDIPAPI
GdipCreateEffect(const GUID guid
, CGpEffect
**effect
)
5392 FIXME("(%s, %p): stub\n", debugstr_guid(&guid
), effect
);
5395 return InvalidParameter
;
5399 return NotImplemented
;
5402 /*****************************************************************************
5403 * GdipDeleteEffect [GDIPLUS.@]
5405 GpStatus WINGDIPAPI
GdipDeleteEffect(CGpEffect
*effect
)
5407 FIXME("(%p): stub\n", effect
);
5408 /* note: According to Jose Roca's GDI+ Docs, this is not implemented
5409 * in Windows's gdiplus */
5410 return NotImplemented
;
5413 /*****************************************************************************
5414 * GdipSetEffectParameters [GDIPLUS.@]
5416 GpStatus WINGDIPAPI
GdipSetEffectParameters(CGpEffect
*effect
,
5417 const VOID
*params
, const UINT size
)
5421 TRACE("(%p,%p,%u)\n", effect
, params
, size
);
5424 FIXME("not implemented\n");
5426 return NotImplemented
;
5429 /*****************************************************************************
5430 * GdipGetImageFlags [GDIPLUS.@]
5432 GpStatus WINGDIPAPI
GdipGetImageFlags(GpImage
*image
, UINT
*flags
)
5434 TRACE("%p %p\n", image
, flags
);
5436 if(!image
|| !flags
)
5437 return InvalidParameter
;
5439 *flags
= image
->flags
;
5444 GpStatus WINGDIPAPI
GdipTestControl(GpTestControlEnum control
, void *param
)
5446 TRACE("(%d, %p)\n", control
, param
);
5449 case TestControlForceBilinear
:
5451 FIXME("TestControlForceBilinear not handled\n");
5453 case TestControlNoICM
:
5455 FIXME("TestControlNoICM not handled\n");
5457 case TestControlGetBuildNumber
:
5458 *((DWORD
*)param
) = 3102;
5465 GpStatus WINGDIPAPI
GdipImageForceValidation(GpImage
*image
)
5467 TRACE("%p\n", image
);
5472 /*****************************************************************************
5473 * GdipGetImageThumbnail [GDIPLUS.@]
5475 GpStatus WINGDIPAPI
GdipGetImageThumbnail(GpImage
*image
, UINT width
, UINT height
,
5476 GpImage
**ret_image
, GetThumbnailImageAbort cb
,
5480 GpGraphics
*graphics
;
5481 UINT srcwidth
, srcheight
;
5483 TRACE("(%p %u %u %p %p %p)\n",
5484 image
, width
, height
, ret_image
, cb
, cb_data
);
5486 if (!image
|| !ret_image
)
5487 return InvalidParameter
;
5489 if (!width
) width
= 120;
5490 if (!height
) height
= 120;
5492 GdipGetImageWidth(image
, &srcwidth
);
5493 GdipGetImageHeight(image
, &srcheight
);
5495 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat32bppPARGB
,
5496 NULL
, (GpBitmap
**)ret_image
);
5500 stat
= GdipGetImageGraphicsContext(*ret_image
, &graphics
);
5504 stat
= GdipDrawImageRectRectI(graphics
, image
,
5505 0, 0, width
, height
, 0, 0, srcwidth
, srcheight
, UnitPixel
,
5508 GdipDeleteGraphics(graphics
);
5513 GdipDisposeImage(*ret_image
);
5521 /*****************************************************************************
5522 * GdipImageRotateFlip [GDIPLUS.@]
5524 GpStatus WINGDIPAPI
GdipImageRotateFlip(GpImage
*image
, RotateFlipType type
)
5526 GpBitmap
*new_bitmap
;
5528 int bpp
, bytesperpixel
;
5529 BOOL rotate_90
, flip_x
, flip_y
;
5530 int src_x_offset
, src_y_offset
;
5532 UINT x
, y
, width
, height
;
5533 BitmapData src_lock
, dst_lock
;
5537 TRACE("(%p, %u)\n", image
, type
);
5540 return InvalidParameter
;
5541 if (!image_lock(image
, &unlock
))
5545 flip_x
= (type
&6) == 2 || (type
&6) == 4;
5546 flip_y
= (type
&3) == 1 || (type
&3) == 2;
5548 if (image
->type
!= ImageTypeBitmap
)
5550 FIXME("Not implemented for type %i\n", image
->type
);
5551 image_unlock(image
, unlock
);
5552 return NotImplemented
;
5555 bitmap
= (GpBitmap
*)image
;
5556 bpp
= PIXELFORMATBPP(bitmap
->format
);
5560 FIXME("Not implemented for %i bit images\n", bpp
);
5561 image_unlock(image
, unlock
);
5562 return NotImplemented
;
5567 width
= bitmap
->height
;
5568 height
= bitmap
->width
;
5572 width
= bitmap
->width
;
5573 height
= bitmap
->height
;
5576 bytesperpixel
= bpp
/8;
5578 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, bitmap
->format
, NULL
, &new_bitmap
);
5582 image_unlock(image
, unlock
);
5586 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, bitmap
->format
, &src_lock
);
5590 stat
= GdipBitmapLockBits(new_bitmap
, NULL
, ImageLockModeWrite
, bitmap
->format
, &dst_lock
);
5594 LPBYTE src_row
, src_pixel
;
5595 LPBYTE dst_row
, dst_pixel
;
5597 src_origin
= src_lock
.Scan0
;
5598 if (flip_x
) src_origin
+= bytesperpixel
* (bitmap
->width
- 1);
5599 if (flip_y
) src_origin
+= src_lock
.Stride
* (bitmap
->height
- 1);
5603 if (flip_y
) src_x_offset
= -src_lock
.Stride
;
5604 else src_x_offset
= src_lock
.Stride
;
5605 if (flip_x
) src_y_offset
= -bytesperpixel
;
5606 else src_y_offset
= bytesperpixel
;
5610 if (flip_x
) src_x_offset
= -bytesperpixel
;
5611 else src_x_offset
= bytesperpixel
;
5612 if (flip_y
) src_y_offset
= -src_lock
.Stride
;
5613 else src_y_offset
= src_lock
.Stride
;
5616 src_row
= src_origin
;
5617 dst_row
= dst_lock
.Scan0
;
5618 for (y
=0; y
<height
; y
++)
5620 src_pixel
= src_row
;
5621 dst_pixel
= dst_row
;
5622 for (x
=0; x
<width
; x
++)
5624 /* FIXME: This could probably be faster without memcpy. */
5625 memcpy(dst_pixel
, src_pixel
, bytesperpixel
);
5626 dst_pixel
+= bytesperpixel
;
5627 src_pixel
+= src_x_offset
;
5629 src_row
+= src_y_offset
;
5630 dst_row
+= dst_lock
.Stride
;
5633 GdipBitmapUnlockBits(new_bitmap
, &dst_lock
);
5636 GdipBitmapUnlockBits(bitmap
, &src_lock
);
5640 move_bitmap(bitmap
, new_bitmap
, FALSE
);
5642 GdipDisposeImage(&new_bitmap
->image
);
5644 image_unlock(image
, unlock
);
5648 /*****************************************************************************
5649 * GdipImageSetAbort [GDIPLUS.@]
5651 GpStatus WINGDIPAPI
GdipImageSetAbort(GpImage
*image
, GdiplusAbort
*pabort
)
5653 TRACE("(%p, %p)\n", image
, pabort
);
5656 return InvalidParameter
;
5659 FIXME("Abort callback is not supported.\n");
5664 /*****************************************************************************
5665 * GdipBitmapConvertFormat [GDIPLUS.@]
5667 GpStatus WINGDIPAPI
GdipBitmapConvertFormat(GpBitmap
*bitmap
, PixelFormat format
, DitherType dithertype
,
5668 PaletteType palettetype
, ColorPalette
*palette
, REAL alphathreshold
)
5670 FIXME("(%p, 0x%08x, %d, %d, %p, %f): stub\n", bitmap
, format
, dithertype
, palettetype
, palette
, alphathreshold
);
5671 return NotImplemented
;
5674 static void set_histogram_point_argb(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5676 ch0
[ color
>> 24 ]++;
5677 ch1
[(color
>> 16) & 0xff]++;
5678 ch2
[(color
>> 8) & 0xff]++;
5679 ch3
[ color
& 0xff]++;
5682 static void set_histogram_point_pargb(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5684 BYTE alpha
= color
>> 24;
5687 ch1
[(((color
>> 16) & 0xff) * alpha
) / 0xff]++;
5688 ch2
[(((color
>> 8) & 0xff) * alpha
) / 0xff]++;
5689 ch3
[(( color
& 0xff) * alpha
) / 0xff]++;
5692 static void set_histogram_point_rgb(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5694 ch0
[(color
>> 16) & 0xff]++;
5695 ch1
[(color
>> 8) & 0xff]++;
5696 ch2
[ color
& 0xff]++;
5699 static void set_histogram_point_gray(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5701 ch0
[(76 * ((color
>> 16) & 0xff) + 150 * ((color
>> 8) & 0xff) + 29 * (color
& 0xff)) / 0xff]++;
5704 static void set_histogram_point_b(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5706 ch0
[color
& 0xff]++;
5709 static void set_histogram_point_g(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5711 ch0
[(color
>> 8) & 0xff]++;
5714 static void set_histogram_point_r(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5716 ch0
[(color
>> 16) & 0xff]++;
5719 static void set_histogram_point_a(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5721 ch0
[(color
>> 24) & 0xff]++;
5724 /*****************************************************************************
5725 * GdipBitmapGetHistogram [GDIPLUS.@]
5727 GpStatus WINGDIPAPI
GdipBitmapGetHistogram(GpBitmap
*bitmap
, HistogramFormat format
, UINT num_of_entries
,
5728 UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5730 static void (* const set_histogram_point
[])(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
) =
5732 set_histogram_point_argb
,
5733 set_histogram_point_pargb
,
5734 set_histogram_point_rgb
,
5735 set_histogram_point_gray
,
5736 set_histogram_point_b
,
5737 set_histogram_point_g
,
5738 set_histogram_point_r
,
5739 set_histogram_point_a
,
5741 UINT width
, height
, x
, y
;
5743 TRACE("(%p, %d, %u, %p, %p, %p, %p)\n", bitmap
, format
, num_of_entries
,
5744 ch0
, ch1
, ch2
, ch3
);
5746 if (!bitmap
|| num_of_entries
!= 256)
5747 return InvalidParameter
;
5749 /* Make sure passed channel pointers match requested format */
5752 case HistogramFormatARGB
:
5753 case HistogramFormatPARGB
:
5754 if (!ch0
|| !ch1
|| !ch2
|| !ch3
)
5755 return InvalidParameter
;
5756 memset(ch0
, 0, num_of_entries
* sizeof(UINT
));
5757 memset(ch1
, 0, num_of_entries
* sizeof(UINT
));
5758 memset(ch2
, 0, num_of_entries
* sizeof(UINT
));
5759 memset(ch3
, 0, num_of_entries
* sizeof(UINT
));
5761 case HistogramFormatRGB
:
5762 if (!ch0
|| !ch1
|| !ch2
|| ch3
)
5763 return InvalidParameter
;
5764 memset(ch0
, 0, num_of_entries
* sizeof(UINT
));
5765 memset(ch1
, 0, num_of_entries
* sizeof(UINT
));
5766 memset(ch2
, 0, num_of_entries
* sizeof(UINT
));
5768 case HistogramFormatGray
:
5769 case HistogramFormatB
:
5770 case HistogramFormatG
:
5771 case HistogramFormatR
:
5772 case HistogramFormatA
:
5773 if (!ch0
|| ch1
|| ch2
|| ch3
)
5774 return InvalidParameter
;
5775 memset(ch0
, 0, num_of_entries
* sizeof(UINT
));
5778 WARN("Invalid histogram format requested, %d\n", format
);
5779 return InvalidParameter
;
5782 GdipGetImageWidth(&bitmap
->image
, &width
);
5783 GdipGetImageHeight(&bitmap
->image
, &height
);
5785 for (y
= 0; y
< height
; y
++)
5786 for (x
= 0; x
< width
; x
++)
5790 GdipBitmapGetPixel(bitmap
, x
, y
, &color
);
5791 set_histogram_point
[format
](color
, ch0
, ch1
, ch2
, ch3
);
5797 /*****************************************************************************
5798 * GdipBitmapGetHistogramSize [GDIPLUS.@]
5800 GpStatus WINGDIPAPI
GdipBitmapGetHistogramSize(HistogramFormat format
, UINT
*num_of_entries
)
5802 TRACE("(%d, %p)\n", format
, num_of_entries
);
5804 if (!num_of_entries
)
5805 return InvalidParameter
;
5807 *num_of_entries
= 256;
5811 static GpStatus
create_optimal_palette(ColorPalette
*palette
, INT desired
,
5812 BOOL transparent
, GpBitmap
*bitmap
)
5817 IWICImagingFactory
*factory
;
5818 IWICPalette
*wic_palette
;
5820 if (!bitmap
) return InvalidParameter
;
5821 if (palette
->Count
< desired
) return GenericError
;
5823 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, PixelFormat24bppRGB
, &data
);
5824 if (status
!= Ok
) return status
;
5826 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
5829 GdipBitmapUnlockBits(bitmap
, &data
);
5830 return hresult_to_status(hr
);
5833 hr
= IWICImagingFactory_CreatePalette(factory
, &wic_palette
);
5838 /* PixelFormat24bppRGB actually stores the bitmap bits as BGR. */
5839 hr
= IWICImagingFactory_CreateBitmapFromMemory(factory
, data
.Width
, data
.Height
,
5840 &GUID_WICPixelFormat24bppBGR
, data
.Stride
, data
.Stride
* data
.Width
, data
.Scan0
, &bitmap
);
5843 hr
= IWICPalette_InitializeFromBitmap(wic_palette
, (IWICBitmapSource
*)bitmap
, desired
, transparent
);
5847 IWICPalette_GetColorCount(wic_palette
, &palette
->Count
);
5848 IWICPalette_GetColors(wic_palette
, palette
->Count
, (UINT
*)palette
->Entries
, &palette
->Count
);
5851 IWICBitmap_Release(bitmap
);
5854 IWICPalette_Release(wic_palette
);
5857 IWICImagingFactory_Release(factory
);
5858 GdipBitmapUnlockBits(bitmap
, &data
);
5860 return hresult_to_status(hr
);
5863 /*****************************************************************************
5864 * GdipInitializePalette [GDIPLUS.@]
5866 GpStatus WINGDIPAPI
GdipInitializePalette(ColorPalette
*palette
,
5867 PaletteType type
, INT desired
, BOOL transparent
, GpBitmap
*bitmap
)
5869 TRACE("(%p,%d,%d,%d,%p)\n", palette
, type
, desired
, transparent
, bitmap
);
5871 if (!palette
) return InvalidParameter
;
5875 case PaletteTypeCustom
:
5878 case PaletteTypeOptimal
:
5879 return create_optimal_palette(palette
, desired
, transparent
, bitmap
);
5881 /* WIC palette type enumeration matches these gdiplus enums */
5882 case PaletteTypeFixedBW
:
5883 case PaletteTypeFixedHalftone8
:
5884 case PaletteTypeFixedHalftone27
:
5885 case PaletteTypeFixedHalftone64
:
5886 case PaletteTypeFixedHalftone125
:
5887 case PaletteTypeFixedHalftone216
:
5888 case PaletteTypeFixedHalftone252
:
5889 case PaletteTypeFixedHalftone256
:
5891 ColorPalette
*wic_palette
;
5892 GpStatus status
= Ok
;
5894 wic_palette
= get_palette(NULL
, type
);
5895 if (!wic_palette
) return OutOfMemory
;
5897 if (palette
->Count
>= wic_palette
->Count
)
5899 palette
->Flags
= wic_palette
->Flags
;
5900 palette
->Count
= wic_palette
->Count
;
5901 memcpy(palette
->Entries
, wic_palette
->Entries
, wic_palette
->Count
* sizeof(wic_palette
->Entries
[0]));
5904 status
= GenericError
;
5906 heap_free(wic_palette
);
5912 FIXME("unknown palette type %d\n", type
);
5916 return InvalidParameter
;