2 * Copyright (C) 2007 Google (Evan Stade)
3 * Copyright (C) 2012,2016 Dmitry Timoshkov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define NONAMELESSUNION
38 #include "gdiplus_private.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
43 HRESULT WINAPI
WICCreateImagingFactory_Proxy(UINT
, IWICImagingFactory
**);
45 #define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
46 #define WMF_PLACEABLE_KEY 0x9ac6cdd7
50 const WICPixelFormatGUID
*wic_format
;
51 PixelFormat gdip_format
;
52 /* predefined palette type to use for pixel format conversions */
53 WICBitmapPaletteType palette_type
;
56 { &GUID_WICPixelFormatBlackWhite
, PixelFormat1bppIndexed
, WICBitmapPaletteTypeFixedBW
},
57 { &GUID_WICPixelFormat1bppIndexed
, PixelFormat1bppIndexed
, WICBitmapPaletteTypeFixedBW
},
58 { &GUID_WICPixelFormat4bppIndexed
, PixelFormat4bppIndexed
, WICBitmapPaletteTypeFixedHalftone8
},
59 { &GUID_WICPixelFormat8bppGray
, PixelFormat8bppIndexed
, WICBitmapPaletteTypeFixedGray256
},
60 { &GUID_WICPixelFormat8bppIndexed
, PixelFormat8bppIndexed
, WICBitmapPaletteTypeFixedHalftone256
},
61 { &GUID_WICPixelFormat16bppBGR555
, PixelFormat16bppRGB555
, WICBitmapPaletteTypeFixedHalftone256
},
62 { &GUID_WICPixelFormat24bppBGR
, PixelFormat24bppRGB
, WICBitmapPaletteTypeFixedHalftone256
},
63 { &GUID_WICPixelFormat32bppBGR
, PixelFormat32bppRGB
, WICBitmapPaletteTypeFixedHalftone256
},
64 { &GUID_WICPixelFormat32bppBGRA
, PixelFormat32bppARGB
, WICBitmapPaletteTypeFixedHalftone256
},
65 { &GUID_WICPixelFormat32bppPBGRA
, PixelFormat32bppPARGB
, WICBitmapPaletteTypeFixedHalftone256
},
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
);
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
, 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 GpStatus WINGDIPAPI
GdipBitmapApplyEffect(GpBitmap
* bitmap
, CGpEffect
* effect
,
130 RECT
* roi
, BOOL useAuxData
, VOID
** auxData
, INT
* auxDataSize
)
132 FIXME("(%p %p %p %d %p %p): stub\n", bitmap
, effect
, roi
, useAuxData
, auxData
, auxDataSize
);
134 * Note: According to Jose Roca's GDI+ docs, this function is not
135 * implemented in Windows's GDI+.
137 return NotImplemented
;
140 GpStatus WINGDIPAPI
GdipBitmapCreateApplyEffect(GpBitmap
** inputBitmaps
,
141 INT numInputs
, CGpEffect
* effect
, RECT
* roi
, RECT
* outputRect
,
142 GpBitmap
** outputBitmap
, BOOL useAuxData
, VOID
** auxData
, INT
* auxDataSize
)
144 FIXME("(%p %d %p %p %p %p %d %p %p): stub\n", inputBitmaps
, numInputs
, effect
, roi
, outputRect
, outputBitmap
, useAuxData
, auxData
, auxDataSize
);
146 * Note: According to Jose Roca's GDI+ docs, this function is not
147 * implemented in Windows's GDI+.
149 return NotImplemented
;
152 static inline void getpixel_1bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
154 *index
= (row
[x
/8]>>(7-x
%8)) & 1;
157 static inline void getpixel_4bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
160 *index
= row
[x
/2]&0xf;
162 *index
= row
[x
/2]>>4;
165 static inline void getpixel_8bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
170 static inline void getpixel_16bppGrayScale(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
171 const BYTE
*row
, UINT x
)
173 *r
= *g
= *b
= row
[x
*2+1];
177 static inline void getpixel_16bppRGB555(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
178 const BYTE
*row
, UINT x
)
180 WORD pixel
= *((const WORD
*)(row
)+x
);
181 *r
= (pixel
>>7&0xf8)|(pixel
>>12&0x7);
182 *g
= (pixel
>>2&0xf8)|(pixel
>>6&0x7);
183 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
187 static inline void getpixel_16bppRGB565(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
188 const BYTE
*row
, UINT x
)
190 WORD pixel
= *((const WORD
*)(row
)+x
);
191 *r
= (pixel
>>8&0xf8)|(pixel
>>13&0x7);
192 *g
= (pixel
>>3&0xfc)|(pixel
>>9&0x3);
193 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
197 static inline void getpixel_16bppARGB1555(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
198 const BYTE
*row
, UINT x
)
200 WORD pixel
= *((const WORD
*)(row
)+x
);
201 *r
= (pixel
>>7&0xf8)|(pixel
>>12&0x7);
202 *g
= (pixel
>>2&0xf8)|(pixel
>>6&0x7);
203 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
204 if ((pixel
&0x8000) == 0x8000)
210 static inline void getpixel_24bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
211 const BYTE
*row
, UINT x
)
219 static inline void getpixel_32bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
220 const BYTE
*row
, UINT x
)
228 static inline void getpixel_32bppARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
229 const BYTE
*row
, UINT x
)
237 static inline void getpixel_32bppPARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
238 const BYTE
*row
, UINT x
)
245 *r
= row
[x
*4+2] * 255 / *a
;
246 *g
= row
[x
*4+1] * 255 / *a
;
247 *b
= row
[x
*4] * 255 / *a
;
251 static inline void getpixel_48bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
252 const BYTE
*row
, UINT x
)
260 static inline void getpixel_64bppARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
261 const BYTE
*row
, UINT x
)
269 static inline void getpixel_64bppPARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
270 const BYTE
*row
, UINT x
)
277 *r
= row
[x
*8+5] * 255 / *a
;
278 *g
= row
[x
*8+3] * 255 / *a
;
279 *b
= row
[x
*8+1] * 255 / *a
;
283 GpStatus WINGDIPAPI
GdipBitmapGetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
290 if(!bitmap
|| !color
||
291 x
< 0 || y
< 0 || x
>= bitmap
->width
|| y
>= bitmap
->height
)
292 return InvalidParameter
;
294 row
= bitmap
->bits
+bitmap
->stride
*y
;
296 switch (bitmap
->format
)
298 case PixelFormat1bppIndexed
:
299 getpixel_1bppIndexed(&index
,row
,x
);
301 case PixelFormat4bppIndexed
:
302 getpixel_4bppIndexed(&index
,row
,x
);
304 case PixelFormat8bppIndexed
:
305 getpixel_8bppIndexed(&index
,row
,x
);
307 case PixelFormat16bppGrayScale
:
308 getpixel_16bppGrayScale(&r
,&g
,&b
,&a
,row
,x
);
310 case PixelFormat16bppRGB555
:
311 getpixel_16bppRGB555(&r
,&g
,&b
,&a
,row
,x
);
313 case PixelFormat16bppRGB565
:
314 getpixel_16bppRGB565(&r
,&g
,&b
,&a
,row
,x
);
316 case PixelFormat16bppARGB1555
:
317 getpixel_16bppARGB1555(&r
,&g
,&b
,&a
,row
,x
);
319 case PixelFormat24bppRGB
:
320 getpixel_24bppRGB(&r
,&g
,&b
,&a
,row
,x
);
322 case PixelFormat32bppRGB
:
323 getpixel_32bppRGB(&r
,&g
,&b
,&a
,row
,x
);
325 case PixelFormat32bppARGB
:
326 getpixel_32bppARGB(&r
,&g
,&b
,&a
,row
,x
);
328 case PixelFormat32bppPARGB
:
329 getpixel_32bppPARGB(&r
,&g
,&b
,&a
,row
,x
);
331 case PixelFormat48bppRGB
:
332 getpixel_48bppRGB(&r
,&g
,&b
,&a
,row
,x
);
334 case PixelFormat64bppARGB
:
335 getpixel_64bppARGB(&r
,&g
,&b
,&a
,row
,x
);
337 case PixelFormat64bppPARGB
:
338 getpixel_64bppPARGB(&r
,&g
,&b
,&a
,row
,x
);
341 FIXME("not implemented for format 0x%x\n", bitmap
->format
);
342 return NotImplemented
;
345 if (bitmap
->format
& PixelFormatIndexed
)
346 *color
= bitmap
->image
.palette
->Entries
[index
];
348 *color
= a
<<24|r
<<16|g
<<8|b
;
353 static inline UINT
get_palette_index(BYTE r
, BYTE g
, BYTE b
, BYTE a
, ColorPalette
*palette
)
356 int best_distance
= 0x7fff;
360 if (!palette
) return 0;
361 /* This algorithm scans entire palette,
362 computes difference from desired color (all color components have equal weight)
363 and returns the index of color with least difference.
365 Note: Maybe it could be replaced with a better algorithm for better image quality
366 and performance, though better algorithm would probably need some pre-built lookup
367 tables and thus may actually be slower if this method is called only few times per
370 for(i
=0;i
<palette
->Count
;i
++) {
371 ARGB color
=palette
->Entries
[i
];
372 distance
=abs(b
-(color
& 0xff)) + abs(g
-(color
>>8 & 0xff)) + abs(r
-(color
>>16 & 0xff)) + abs(a
-(color
>>24 & 0xff));
373 if (distance
<best_distance
) {
374 best_distance
=distance
;
381 static inline void setpixel_8bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
382 BYTE
*row
, UINT x
, ColorPalette
*palette
)
384 BYTE index
= get_palette_index(r
,g
,b
,a
,palette
);
388 static inline void setpixel_1bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
389 BYTE
*row
, UINT x
, ColorPalette
*palette
)
391 row
[x
/8] = (row
[x
/8] & ~(1<<(7-x
%8))) | (get_palette_index(r
,g
,b
,a
,palette
)<<(7-x
%8));
394 static inline void setpixel_4bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
395 BYTE
*row
, UINT x
, ColorPalette
*palette
)
398 row
[x
/2] = (row
[x
/2] & 0xf0) | get_palette_index(r
,g
,b
,a
,palette
);
400 row
[x
/2] = (row
[x
/2] & 0x0f) | get_palette_index(r
,g
,b
,a
,palette
)<<4;
403 static inline void setpixel_16bppGrayScale(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
406 *((WORD
*)(row
)+x
) = (r
+g
+b
)*85;
409 static inline void setpixel_16bppRGB555(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
412 *((WORD
*)(row
)+x
) = (r
<<7&0x7c00)|
417 static inline void setpixel_16bppRGB565(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
420 *((WORD
*)(row
)+x
) = (r
<<8&0xf800)|
425 static inline void setpixel_16bppARGB1555(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
428 *((WORD
*)(row
)+x
) = (a
<<8&0x8000)|
434 static inline void setpixel_24bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
442 static inline void setpixel_32bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
445 *((DWORD
*)(row
)+x
) = (r
<<16)|(g
<<8)|b
;
448 static inline void setpixel_32bppARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
451 *((DWORD
*)(row
)+x
) = (a
<<24)|(r
<<16)|(g
<<8)|b
;
454 static inline void setpixel_32bppPARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
460 *((DWORD
*)(row
)+x
) = (a
<<24)|(r
<<16)|(g
<<8)|b
;
463 static inline void setpixel_48bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
466 row
[x
*6+5] = row
[x
*6+4] = r
;
467 row
[x
*6+3] = row
[x
*6+2] = g
;
468 row
[x
*6+1] = row
[x
*6] = b
;
471 static inline void setpixel_64bppARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
474 UINT64 a64
=a
, r64
=r
, g64
=g
, b64
=b
;
475 *((UINT64
*)(row
)+x
) = (a64
<<56)|(a64
<<48)|(r64
<<40)|(r64
<<32)|(g64
<<24)|(g64
<<16)|(b64
<<8)|b64
;
478 static inline void setpixel_64bppPARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
481 UINT64 a64
, r64
, g64
, b64
;
486 *((UINT64
*)(row
)+x
) = (a64
<<48)|(r64
<<32)|(g64
<<16)|b64
;
489 GpStatus WINGDIPAPI
GdipBitmapSetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
495 if(!bitmap
|| x
< 0 || y
< 0 || x
>= bitmap
->width
|| y
>= bitmap
->height
)
496 return InvalidParameter
;
503 row
= bitmap
->bits
+ bitmap
->stride
* y
;
505 switch (bitmap
->format
)
507 case PixelFormat16bppGrayScale
:
508 setpixel_16bppGrayScale(r
,g
,b
,a
,row
,x
);
510 case PixelFormat16bppRGB555
:
511 setpixel_16bppRGB555(r
,g
,b
,a
,row
,x
);
513 case PixelFormat16bppRGB565
:
514 setpixel_16bppRGB565(r
,g
,b
,a
,row
,x
);
516 case PixelFormat16bppARGB1555
:
517 setpixel_16bppARGB1555(r
,g
,b
,a
,row
,x
);
519 case PixelFormat24bppRGB
:
520 setpixel_24bppRGB(r
,g
,b
,a
,row
,x
);
522 case PixelFormat32bppRGB
:
523 setpixel_32bppRGB(r
,g
,b
,a
,row
,x
);
525 case PixelFormat32bppARGB
:
526 setpixel_32bppARGB(r
,g
,b
,a
,row
,x
);
528 case PixelFormat32bppPARGB
:
529 setpixel_32bppPARGB(r
,g
,b
,a
,row
,x
);
531 case PixelFormat48bppRGB
:
532 setpixel_48bppRGB(r
,g
,b
,a
,row
,x
);
534 case PixelFormat64bppARGB
:
535 setpixel_64bppARGB(r
,g
,b
,a
,row
,x
);
537 case PixelFormat64bppPARGB
:
538 setpixel_64bppPARGB(r
,g
,b
,a
,row
,x
);
540 case PixelFormat8bppIndexed
:
541 setpixel_8bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
543 case PixelFormat4bppIndexed
:
544 setpixel_4bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
546 case PixelFormat1bppIndexed
:
547 setpixel_1bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
550 FIXME("not implemented for format 0x%x\n", bitmap
->format
);
551 return NotImplemented
;
557 GpStatus
convert_pixels(INT width
, INT height
,
558 INT dst_stride
, BYTE
*dst_bits
, PixelFormat dst_format
,
559 INT src_stride
, const BYTE
*src_bits
, PixelFormat src_format
,
560 ColorPalette
*palette
)
564 if (src_format
== dst_format
||
565 (dst_format
== PixelFormat32bppRGB
&& PIXELFORMATBPP(src_format
) == 32))
567 UINT widthbytes
= PIXELFORMATBPP(src_format
) * width
/ 8;
568 for (y
=0; y
<height
; y
++)
569 memcpy(dst_bits
+dst_stride
*y
, src_bits
+src_stride
*y
, widthbytes
);
573 #define convert_indexed_to_rgb(getpixel_function, setpixel_function) do { \
574 for (y=0; y<height; y++) \
575 for (x=0; x<width; x++) { \
578 BYTE *color = (BYTE *)&argb; \
579 getpixel_function(&index, src_bits+src_stride*y, x); \
580 argb = (palette && index < palette->Count) ? palette->Entries[index] : 0; \
581 setpixel_function(color[2], color[1], color[0], color[3], dst_bits+dst_stride*y, x); \
586 #define convert_rgb_to_rgb(getpixel_function, setpixel_function) do { \
587 for (y=0; y<height; y++) \
588 for (x=0; x<width; x++) { \
590 getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
591 setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x); \
596 #define convert_rgb_to_indexed(getpixel_function, setpixel_function) do { \
597 for (y=0; y<height; y++) \
598 for (x=0; x<width; x++) { \
600 getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
601 setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x, palette); \
608 case PixelFormat1bppIndexed
:
611 case PixelFormat16bppGrayScale
:
612 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppGrayScale
);
613 case PixelFormat16bppRGB555
:
614 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppRGB555
);
615 case PixelFormat16bppRGB565
:
616 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppRGB565
);
617 case PixelFormat16bppARGB1555
:
618 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppARGB1555
);
619 case PixelFormat24bppRGB
:
620 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_24bppRGB
);
621 case PixelFormat32bppRGB
:
622 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppRGB
);
623 case PixelFormat32bppARGB
:
624 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppARGB
);
625 case PixelFormat32bppPARGB
:
626 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppPARGB
);
627 case PixelFormat48bppRGB
:
628 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_48bppRGB
);
629 case PixelFormat64bppARGB
:
630 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_64bppARGB
);
635 case PixelFormat4bppIndexed
:
638 case PixelFormat16bppGrayScale
:
639 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppGrayScale
);
640 case PixelFormat16bppRGB555
:
641 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppRGB555
);
642 case PixelFormat16bppRGB565
:
643 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppRGB565
);
644 case PixelFormat16bppARGB1555
:
645 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppARGB1555
);
646 case PixelFormat24bppRGB
:
647 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_24bppRGB
);
648 case PixelFormat32bppRGB
:
649 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppRGB
);
650 case PixelFormat32bppARGB
:
651 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppARGB
);
652 case PixelFormat32bppPARGB
:
653 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppPARGB
);
654 case PixelFormat48bppRGB
:
655 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_48bppRGB
);
656 case PixelFormat64bppARGB
:
657 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_64bppARGB
);
662 case PixelFormat8bppIndexed
:
665 case PixelFormat16bppGrayScale
:
666 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppGrayScale
);
667 case PixelFormat16bppRGB555
:
668 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppRGB555
);
669 case PixelFormat16bppRGB565
:
670 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppRGB565
);
671 case PixelFormat16bppARGB1555
:
672 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppARGB1555
);
673 case PixelFormat24bppRGB
:
674 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_24bppRGB
);
675 case PixelFormat32bppRGB
:
676 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppRGB
);
677 case PixelFormat32bppARGB
:
678 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppARGB
);
679 case PixelFormat32bppPARGB
:
680 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppPARGB
);
681 case PixelFormat48bppRGB
:
682 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_48bppRGB
);
683 case PixelFormat64bppARGB
:
684 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_64bppARGB
);
689 case PixelFormat16bppGrayScale
:
692 case PixelFormat1bppIndexed
:
693 convert_rgb_to_indexed(getpixel_16bppGrayScale
, setpixel_1bppIndexed
);
694 case PixelFormat8bppIndexed
:
695 convert_rgb_to_indexed(getpixel_16bppGrayScale
, setpixel_8bppIndexed
);
696 case PixelFormat16bppRGB555
:
697 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppRGB555
);
698 case PixelFormat16bppRGB565
:
699 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppRGB565
);
700 case PixelFormat16bppARGB1555
:
701 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppARGB1555
);
702 case PixelFormat24bppRGB
:
703 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_24bppRGB
);
704 case PixelFormat32bppRGB
:
705 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppRGB
);
706 case PixelFormat32bppARGB
:
707 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppARGB
);
708 case PixelFormat32bppPARGB
:
709 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppPARGB
);
710 case PixelFormat48bppRGB
:
711 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_48bppRGB
);
712 case PixelFormat64bppARGB
:
713 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_64bppARGB
);
718 case PixelFormat16bppRGB555
:
721 case PixelFormat1bppIndexed
:
722 convert_rgb_to_indexed(getpixel_16bppRGB555
, setpixel_1bppIndexed
);
723 case PixelFormat8bppIndexed
:
724 convert_rgb_to_indexed(getpixel_16bppRGB555
, setpixel_8bppIndexed
);
725 case PixelFormat16bppGrayScale
:
726 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppGrayScale
);
727 case PixelFormat16bppRGB565
:
728 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppRGB565
);
729 case PixelFormat16bppARGB1555
:
730 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppARGB1555
);
731 case PixelFormat24bppRGB
:
732 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_24bppRGB
);
733 case PixelFormat32bppRGB
:
734 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppRGB
);
735 case PixelFormat32bppARGB
:
736 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppARGB
);
737 case PixelFormat32bppPARGB
:
738 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppPARGB
);
739 case PixelFormat48bppRGB
:
740 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_48bppRGB
);
741 case PixelFormat64bppARGB
:
742 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_64bppARGB
);
747 case PixelFormat16bppRGB565
:
750 case PixelFormat1bppIndexed
:
751 convert_rgb_to_indexed(getpixel_16bppRGB565
, setpixel_1bppIndexed
);
752 case PixelFormat8bppIndexed
:
753 convert_rgb_to_indexed(getpixel_16bppRGB565
, setpixel_8bppIndexed
);
754 case PixelFormat16bppGrayScale
:
755 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppGrayScale
);
756 case PixelFormat16bppRGB555
:
757 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppRGB555
);
758 case PixelFormat16bppARGB1555
:
759 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppARGB1555
);
760 case PixelFormat24bppRGB
:
761 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_24bppRGB
);
762 case PixelFormat32bppRGB
:
763 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppRGB
);
764 case PixelFormat32bppARGB
:
765 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppARGB
);
766 case PixelFormat32bppPARGB
:
767 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppPARGB
);
768 case PixelFormat48bppRGB
:
769 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_48bppRGB
);
770 case PixelFormat64bppARGB
:
771 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_64bppARGB
);
776 case PixelFormat16bppARGB1555
:
779 case PixelFormat1bppIndexed
:
780 convert_rgb_to_indexed(getpixel_16bppARGB1555
, setpixel_1bppIndexed
);
781 case PixelFormat8bppIndexed
:
782 convert_rgb_to_indexed(getpixel_16bppARGB1555
, setpixel_8bppIndexed
);
783 case PixelFormat16bppGrayScale
:
784 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppGrayScale
);
785 case PixelFormat16bppRGB555
:
786 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppRGB555
);
787 case PixelFormat16bppRGB565
:
788 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppRGB565
);
789 case PixelFormat24bppRGB
:
790 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_24bppRGB
);
791 case PixelFormat32bppRGB
:
792 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppRGB
);
793 case PixelFormat32bppARGB
:
794 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppARGB
);
795 case PixelFormat32bppPARGB
:
796 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppPARGB
);
797 case PixelFormat48bppRGB
:
798 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_48bppRGB
);
799 case PixelFormat64bppARGB
:
800 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_64bppARGB
);
805 case PixelFormat24bppRGB
:
808 case PixelFormat1bppIndexed
:
809 convert_rgb_to_indexed(getpixel_24bppRGB
, setpixel_1bppIndexed
);
810 case PixelFormat8bppIndexed
:
811 convert_rgb_to_indexed(getpixel_24bppRGB
, setpixel_8bppIndexed
);
812 case PixelFormat16bppGrayScale
:
813 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppGrayScale
);
814 case PixelFormat16bppRGB555
:
815 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppRGB555
);
816 case PixelFormat16bppRGB565
:
817 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppRGB565
);
818 case PixelFormat16bppARGB1555
:
819 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppARGB1555
);
820 case PixelFormat32bppRGB
:
821 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppRGB
);
822 case PixelFormat32bppARGB
:
823 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppARGB
);
824 case PixelFormat32bppPARGB
:
825 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppPARGB
);
826 case PixelFormat48bppRGB
:
827 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_48bppRGB
);
828 case PixelFormat64bppARGB
:
829 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_64bppARGB
);
834 case PixelFormat32bppRGB
:
837 case PixelFormat1bppIndexed
:
838 convert_rgb_to_indexed(getpixel_32bppRGB
, setpixel_1bppIndexed
);
839 case PixelFormat8bppIndexed
:
840 convert_rgb_to_indexed(getpixel_32bppRGB
, setpixel_8bppIndexed
);
841 case PixelFormat16bppGrayScale
:
842 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppGrayScale
);
843 case PixelFormat16bppRGB555
:
844 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppRGB555
);
845 case PixelFormat16bppRGB565
:
846 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppRGB565
);
847 case PixelFormat16bppARGB1555
:
848 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppARGB1555
);
849 case PixelFormat24bppRGB
:
850 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_24bppRGB
);
851 case PixelFormat32bppARGB
:
852 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_32bppARGB
);
853 case PixelFormat32bppPARGB
:
854 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_32bppPARGB
);
855 case PixelFormat48bppRGB
:
856 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_48bppRGB
);
857 case PixelFormat64bppARGB
:
858 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_64bppARGB
);
863 case PixelFormat32bppARGB
:
866 case PixelFormat1bppIndexed
:
867 convert_rgb_to_indexed(getpixel_32bppARGB
, setpixel_1bppIndexed
);
868 case PixelFormat8bppIndexed
:
869 convert_rgb_to_indexed(getpixel_32bppARGB
, setpixel_8bppIndexed
);
870 case PixelFormat16bppGrayScale
:
871 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppGrayScale
);
872 case PixelFormat16bppRGB555
:
873 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppRGB555
);
874 case PixelFormat16bppRGB565
:
875 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppRGB565
);
876 case PixelFormat16bppARGB1555
:
877 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppARGB1555
);
878 case PixelFormat24bppRGB
:
879 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_24bppRGB
);
880 case PixelFormat32bppPARGB
:
881 convert_32bppARGB_to_32bppPARGB(width
, height
, dst_bits
, dst_stride
, src_bits
, src_stride
);
883 case PixelFormat48bppRGB
:
884 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_48bppRGB
);
885 case PixelFormat64bppARGB
:
886 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_64bppARGB
);
891 case PixelFormat32bppPARGB
:
894 case PixelFormat1bppIndexed
:
895 convert_rgb_to_indexed(getpixel_32bppPARGB
, setpixel_1bppIndexed
);
896 case PixelFormat8bppIndexed
:
897 convert_rgb_to_indexed(getpixel_32bppPARGB
, setpixel_8bppIndexed
);
898 case PixelFormat16bppGrayScale
:
899 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppGrayScale
);
900 case PixelFormat16bppRGB555
:
901 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppRGB555
);
902 case PixelFormat16bppRGB565
:
903 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppRGB565
);
904 case PixelFormat16bppARGB1555
:
905 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppARGB1555
);
906 case PixelFormat24bppRGB
:
907 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_24bppRGB
);
908 case PixelFormat32bppRGB
:
909 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_32bppRGB
);
910 case PixelFormat32bppARGB
:
911 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_32bppARGB
);
912 case PixelFormat48bppRGB
:
913 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_48bppRGB
);
914 case PixelFormat64bppARGB
:
915 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_64bppARGB
);
920 case PixelFormat48bppRGB
:
923 case PixelFormat1bppIndexed
:
924 convert_rgb_to_indexed(getpixel_48bppRGB
, setpixel_1bppIndexed
);
925 case PixelFormat8bppIndexed
:
926 convert_rgb_to_indexed(getpixel_48bppRGB
, setpixel_8bppIndexed
);
927 case PixelFormat16bppGrayScale
:
928 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppGrayScale
);
929 case PixelFormat16bppRGB555
:
930 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppRGB555
);
931 case PixelFormat16bppRGB565
:
932 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppRGB565
);
933 case PixelFormat16bppARGB1555
:
934 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppARGB1555
);
935 case PixelFormat24bppRGB
:
936 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_24bppRGB
);
937 case PixelFormat32bppRGB
:
938 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppRGB
);
939 case PixelFormat32bppARGB
:
940 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppARGB
);
941 case PixelFormat32bppPARGB
:
942 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppPARGB
);
943 case PixelFormat64bppARGB
:
944 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_64bppARGB
);
949 case PixelFormat64bppARGB
:
952 case PixelFormat1bppIndexed
:
953 convert_rgb_to_indexed(getpixel_64bppARGB
, setpixel_1bppIndexed
);
954 case PixelFormat8bppIndexed
:
955 convert_rgb_to_indexed(getpixel_64bppARGB
, setpixel_8bppIndexed
);
956 case PixelFormat16bppGrayScale
:
957 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppGrayScale
);
958 case PixelFormat16bppRGB555
:
959 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppRGB555
);
960 case PixelFormat16bppRGB565
:
961 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppRGB565
);
962 case PixelFormat16bppARGB1555
:
963 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppARGB1555
);
964 case PixelFormat24bppRGB
:
965 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_24bppRGB
);
966 case PixelFormat32bppRGB
:
967 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppRGB
);
968 case PixelFormat32bppARGB
:
969 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppARGB
);
970 case PixelFormat32bppPARGB
:
971 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppPARGB
);
972 case PixelFormat48bppRGB
:
973 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_48bppRGB
);
978 case PixelFormat64bppPARGB
:
981 case PixelFormat1bppIndexed
:
982 convert_rgb_to_indexed(getpixel_64bppPARGB
, setpixel_1bppIndexed
);
983 case PixelFormat8bppIndexed
:
984 convert_rgb_to_indexed(getpixel_64bppPARGB
, setpixel_8bppIndexed
);
985 case PixelFormat16bppGrayScale
:
986 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppGrayScale
);
987 case PixelFormat16bppRGB555
:
988 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppRGB555
);
989 case PixelFormat16bppRGB565
:
990 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppRGB565
);
991 case PixelFormat16bppARGB1555
:
992 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppARGB1555
);
993 case PixelFormat24bppRGB
:
994 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_24bppRGB
);
995 case PixelFormat32bppRGB
:
996 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppRGB
);
997 case PixelFormat32bppARGB
:
998 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppARGB
);
999 case PixelFormat32bppPARGB
:
1000 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppPARGB
);
1001 case PixelFormat48bppRGB
:
1002 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_48bppRGB
);
1003 case PixelFormat64bppARGB
:
1004 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_64bppARGB
);
1013 #undef convert_indexed_to_rgb
1014 #undef convert_rgb_to_rgb
1016 return NotImplemented
;
1019 /* This function returns a pointer to an array of pixels that represents the
1020 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
1021 * flags. It is correct behavior that a user who calls this function with write
1022 * privileges can write to the whole bitmap (not just the area in rect).
1024 * FIXME: only used portion of format is bits per pixel. */
1025 GpStatus WINGDIPAPI
GdipBitmapLockBits(GpBitmap
* bitmap
, GDIPCONST GpRect
* rect
,
1026 UINT flags
, PixelFormat format
, BitmapData
* lockeddata
)
1028 INT bitspp
= PIXELFORMATBPP(format
);
1029 GpRect act_rect
; /* actual rect to be used */
1033 TRACE("%p %p %d 0x%x %p\n", bitmap
, rect
, flags
, format
, lockeddata
);
1035 if(!lockeddata
|| !bitmap
)
1036 return InvalidParameter
;
1037 if(!image_lock(&bitmap
->image
, &unlock
))
1041 if(rect
->X
< 0 || rect
->Y
< 0 || (rect
->X
+ rect
->Width
> bitmap
->width
) ||
1042 (rect
->Y
+ rect
->Height
> bitmap
->height
) || !flags
)
1044 image_unlock(&bitmap
->image
, unlock
);
1045 return InvalidParameter
;
1051 act_rect
.X
= act_rect
.Y
= 0;
1052 act_rect
.Width
= bitmap
->width
;
1053 act_rect
.Height
= bitmap
->height
;
1056 if(bitmap
->lockmode
)
1058 WARN("bitmap is already locked and cannot be locked again\n");
1059 image_unlock(&bitmap
->image
, unlock
);
1063 if (bitmap
->bits
&& bitmap
->format
== format
&& !(flags
& ImageLockModeUserInputBuf
))
1065 /* no conversion is necessary; just use the bits directly */
1066 lockeddata
->Width
= act_rect
.Width
;
1067 lockeddata
->Height
= act_rect
.Height
;
1068 lockeddata
->PixelFormat
= format
;
1069 lockeddata
->Reserved
= flags
;
1070 lockeddata
->Stride
= bitmap
->stride
;
1071 lockeddata
->Scan0
= bitmap
->bits
+ (bitspp
/ 8) * act_rect
.X
+
1072 bitmap
->stride
* act_rect
.Y
;
1074 bitmap
->lockmode
= flags
| ImageLockModeRead
;
1076 image_unlock(&bitmap
->image
, unlock
);
1080 /* Make sure we can convert to the requested format. */
1081 if (flags
& ImageLockModeRead
)
1083 stat
= convert_pixels(0, 0, 0, NULL
, format
, 0, NULL
, bitmap
->format
, NULL
);
1084 if (stat
== NotImplemented
)
1086 FIXME("cannot read bitmap from %x to %x\n", bitmap
->format
, format
);
1087 image_unlock(&bitmap
->image
, unlock
);
1088 return NotImplemented
;
1092 /* If we're opening for writing, make sure we'll be able to write back in
1093 * the original format. */
1094 if (flags
& ImageLockModeWrite
)
1096 stat
= convert_pixels(0, 0, 0, NULL
, bitmap
->format
, 0, NULL
, format
, NULL
);
1097 if (stat
== NotImplemented
)
1099 FIXME("cannot write bitmap from %x to %x\n", format
, bitmap
->format
);
1100 image_unlock(&bitmap
->image
, unlock
);
1101 return NotImplemented
;
1105 lockeddata
->Width
= act_rect
.Width
;
1106 lockeddata
->Height
= act_rect
.Height
;
1107 lockeddata
->PixelFormat
= format
;
1108 lockeddata
->Reserved
= flags
;
1110 if(!(flags
& ImageLockModeUserInputBuf
))
1112 lockeddata
->Stride
= (((act_rect
.Width
* bitspp
+ 7) / 8) + 3) & ~3;
1114 bitmap
->bitmapbits
= heap_alloc_zero(lockeddata
->Stride
* act_rect
.Height
);
1116 if (!bitmap
->bitmapbits
)
1118 image_unlock(&bitmap
->image
, unlock
);
1122 lockeddata
->Scan0
= bitmap
->bitmapbits
;
1125 if (flags
& ImageLockModeRead
)
1127 static BOOL fixme
= FALSE
;
1129 if (!fixme
&& (PIXELFORMATBPP(bitmap
->format
) * act_rect
.X
) % 8 != 0)
1131 FIXME("Cannot copy rows that don't start at a whole byte.\n");
1135 stat
= convert_pixels(act_rect
.Width
, act_rect
.Height
,
1136 lockeddata
->Stride
, lockeddata
->Scan0
, format
,
1138 bitmap
->bits
+ bitmap
->stride
* act_rect
.Y
+ PIXELFORMATBPP(bitmap
->format
) * act_rect
.X
/ 8,
1139 bitmap
->format
, bitmap
->image
.palette
);
1143 heap_free(bitmap
->bitmapbits
);
1144 bitmap
->bitmapbits
= NULL
;
1145 image_unlock(&bitmap
->image
, unlock
);
1150 bitmap
->lockmode
= flags
| ImageLockModeRead
;
1151 bitmap
->lockx
= act_rect
.X
;
1152 bitmap
->locky
= act_rect
.Y
;
1154 image_unlock(&bitmap
->image
, unlock
);
1158 GpStatus WINGDIPAPI
GdipBitmapSetResolution(GpBitmap
* bitmap
, REAL xdpi
, REAL ydpi
)
1160 TRACE("(%p, %.2f, %.2f)\n", bitmap
, xdpi
, ydpi
);
1162 if (!bitmap
|| xdpi
== 0.0 || ydpi
== 0.0)
1163 return InvalidParameter
;
1165 bitmap
->image
.xres
= xdpi
;
1166 bitmap
->image
.yres
= ydpi
;
1171 GpStatus WINGDIPAPI
GdipBitmapUnlockBits(GpBitmap
* bitmap
,
1172 BitmapData
* lockeddata
)
1175 static BOOL fixme
= FALSE
;
1178 TRACE("(%p,%p)\n", bitmap
, lockeddata
);
1180 if(!bitmap
|| !lockeddata
)
1181 return InvalidParameter
;
1182 if(!image_lock(&bitmap
->image
, &unlock
))
1185 if(!bitmap
->lockmode
)
1187 image_unlock(&bitmap
->image
, unlock
);
1191 if(!(lockeddata
->Reserved
& ImageLockModeWrite
)){
1192 bitmap
->lockmode
= 0;
1193 heap_free(bitmap
->bitmapbits
);
1194 bitmap
->bitmapbits
= NULL
;
1195 image_unlock(&bitmap
->image
, unlock
);
1199 if (!bitmap
->bitmapbits
&& !(lockeddata
->Reserved
& ImageLockModeUserInputBuf
))
1201 /* we passed a direct reference; no need to do anything */
1202 bitmap
->lockmode
= 0;
1203 image_unlock(&bitmap
->image
, unlock
);
1207 if (!fixme
&& (PIXELFORMATBPP(bitmap
->format
) * bitmap
->lockx
) % 8 != 0)
1209 FIXME("Cannot copy rows that don't start at a whole byte.\n");
1213 stat
= convert_pixels(lockeddata
->Width
, lockeddata
->Height
,
1215 bitmap
->bits
+ bitmap
->stride
* bitmap
->locky
+ PIXELFORMATBPP(bitmap
->format
) * bitmap
->lockx
/ 8,
1217 lockeddata
->Stride
, lockeddata
->Scan0
, lockeddata
->PixelFormat
, NULL
);
1221 ERR("failed to convert pixels; this should never happen\n");
1224 heap_free(bitmap
->bitmapbits
);
1225 bitmap
->bitmapbits
= NULL
;
1226 bitmap
->lockmode
= 0;
1228 image_unlock(&bitmap
->image
, unlock
);
1232 GpStatus WINGDIPAPI
GdipCloneBitmapArea(REAL x
, REAL y
, REAL width
, REAL height
,
1233 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
1238 TRACE("(%f,%f,%f,%f,0x%x,%p,%p)\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1240 if (!srcBitmap
|| !dstBitmap
|| srcBitmap
->image
.type
!= ImageTypeBitmap
||
1242 x
+ width
> srcBitmap
->width
|| y
+ height
> srcBitmap
->height
)
1244 TRACE("<-- InvalidParameter\n");
1245 return InvalidParameter
;
1248 if (format
== PixelFormatDontCare
)
1249 format
= srcBitmap
->format
;
1251 area
.X
= gdip_round(x
);
1252 area
.Y
= gdip_round(y
);
1253 area
.Width
= gdip_round(width
);
1254 area
.Height
= gdip_round(height
);
1256 stat
= GdipCreateBitmapFromScan0(area
.Width
, area
.Height
, 0, format
, NULL
, dstBitmap
);
1259 stat
= convert_pixels(area
.Width
, area
.Height
, (*dstBitmap
)->stride
, (*dstBitmap
)->bits
, (*dstBitmap
)->format
,
1261 srcBitmap
->bits
+ srcBitmap
->stride
* area
.Y
+ PIXELFORMATBPP(srcBitmap
->format
) * area
.X
/ 8,
1262 srcBitmap
->format
, srcBitmap
->image
.palette
);
1264 if (stat
== Ok
&& srcBitmap
->image
.palette
)
1266 ColorPalette
*src_palette
, *dst_palette
;
1268 src_palette
= srcBitmap
->image
.palette
;
1270 dst_palette
= heap_alloc_zero(sizeof(UINT
) * 2 + sizeof(ARGB
) * src_palette
->Count
);
1274 dst_palette
->Flags
= src_palette
->Flags
;
1275 dst_palette
->Count
= src_palette
->Count
;
1276 memcpy(dst_palette
->Entries
, src_palette
->Entries
, sizeof(ARGB
) * src_palette
->Count
);
1278 heap_free((*dstBitmap
)->image
.palette
);
1279 (*dstBitmap
)->image
.palette
= dst_palette
;
1286 GdipDisposeImage(&(*dstBitmap
)->image
);
1295 GpStatus WINGDIPAPI
GdipCloneBitmapAreaI(INT x
, INT y
, INT width
, INT height
,
1296 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
1298 TRACE("(%i,%i,%i,%i,0x%x,%p,%p)\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1300 return GdipCloneBitmapArea(x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1303 GpStatus WINGDIPAPI
GdipCloneImage(GpImage
*image
, GpImage
**cloneImage
)
1305 TRACE("%p, %p\n", image
, cloneImage
);
1307 if (!image
|| !cloneImage
)
1308 return InvalidParameter
;
1310 if (image
->type
== ImageTypeBitmap
)
1312 GpBitmap
*bitmap
= (GpBitmap
*)image
;
1314 return GdipCloneBitmapAreaI(0, 0, bitmap
->width
, bitmap
->height
,
1315 bitmap
->format
, bitmap
, (GpBitmap
**)cloneImage
);
1317 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
1319 GpMetafile
*result
, *metafile
;
1321 metafile
= (GpMetafile
*)image
;
1323 result
= heap_alloc_zero(sizeof(*result
));
1327 result
->image
.type
= ImageTypeMetafile
;
1328 result
->image
.format
= image
->format
;
1329 result
->image
.flags
= image
->flags
;
1330 result
->image
.frame_count
= 1;
1331 result
->image
.xres
= image
->xres
;
1332 result
->image
.yres
= image
->yres
;
1333 result
->bounds
= metafile
->bounds
;
1334 result
->unit
= metafile
->unit
;
1335 result
->metafile_type
= metafile
->metafile_type
;
1336 result
->hemf
= CopyEnhMetaFileW(metafile
->hemf
, NULL
);
1337 list_init(&result
->containers
);
1345 *cloneImage
= &result
->image
;
1350 WARN("GpImage with no image data (metafile in wrong state?)\n");
1351 return InvalidParameter
;
1355 GpStatus WINGDIPAPI
GdipCreateBitmapFromFile(GDIPCONST WCHAR
* filename
,
1361 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
1363 if(!filename
|| !bitmap
)
1364 return InvalidParameter
;
1368 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
1373 stat
= GdipCreateBitmapFromStream(stream
, bitmap
);
1375 IStream_Release(stream
);
1380 GpStatus WINGDIPAPI
GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO
* info
,
1381 VOID
*bits
, GpBitmap
**bitmap
)
1383 DWORD height
, stride
;
1386 FIXME("(%p, %p, %p) - partially implemented\n", info
, bits
, bitmap
);
1388 if (!info
|| !bits
|| !bitmap
)
1389 return InvalidParameter
;
1391 height
= abs(info
->bmiHeader
.biHeight
);
1392 stride
= ((info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
+ 31) >> 3) & ~3;
1394 if(info
->bmiHeader
.biHeight
> 0) /* bottom-up */
1396 bits
= (BYTE
*)bits
+ (height
- 1) * stride
;
1400 switch(info
->bmiHeader
.biBitCount
) {
1402 format
= PixelFormat1bppIndexed
;
1405 format
= PixelFormat4bppIndexed
;
1408 format
= PixelFormat8bppIndexed
;
1411 format
= PixelFormat16bppRGB555
;
1414 format
= PixelFormat24bppRGB
;
1417 format
= PixelFormat32bppRGB
;
1420 FIXME("don't know how to handle %d bpp\n", info
->bmiHeader
.biBitCount
);
1422 return InvalidParameter
;
1425 return GdipCreateBitmapFromScan0(info
->bmiHeader
.biWidth
, height
, stride
, format
,
1431 GpStatus WINGDIPAPI
GdipCreateBitmapFromFileICM(GDIPCONST WCHAR
* filename
,
1434 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
1436 return GdipCreateBitmapFromFile(filename
, bitmap
);
1439 GpStatus WINGDIPAPI
GdipCreateBitmapFromResource(HINSTANCE hInstance
,
1440 GDIPCONST WCHAR
* lpBitmapName
, GpBitmap
** bitmap
)
1443 GpStatus stat
= InvalidParameter
;
1445 TRACE("%p (%s) %p\n", hInstance
, debugstr_w(lpBitmapName
), bitmap
);
1447 if(!lpBitmapName
|| !bitmap
)
1448 return InvalidParameter
;
1451 hbm
= LoadImageW(hInstance
, lpBitmapName
, IMAGE_BITMAP
, 0, 0,
1452 LR_CREATEDIBSECTION
);
1455 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, bitmap
);
1462 static inline DWORD
blend_argb_no_bkgnd_alpha(DWORD src
, DWORD bkgnd
)
1465 BYTE g
= (BYTE
)(src
>> 8);
1466 BYTE r
= (BYTE
)(src
>> 16);
1467 DWORD alpha
= (BYTE
)(src
>> 24);
1468 return ((b
+ ((BYTE
)bkgnd
* (255 - alpha
) + 127) / 255) |
1469 (g
+ ((BYTE
)(bkgnd
>> 8) * (255 - alpha
) + 127) / 255) << 8 |
1470 (r
+ ((BYTE
)(bkgnd
>> 16) * (255 - alpha
) + 127) / 255) << 16 |
1474 GpStatus WINGDIPAPI
GdipCreateHBITMAPFromBitmap(GpBitmap
* bitmap
,
1475 HBITMAP
* hbmReturn
, ARGB background
)
1480 BITMAPINFOHEADER bih
;
1484 TRACE("(%p,%p,%x)\n", bitmap
, hbmReturn
, background
);
1486 if (!bitmap
|| !hbmReturn
) return InvalidParameter
;
1487 if (!image_lock(&bitmap
->image
, &unlock
)) return ObjectBusy
;
1489 GdipGetImageWidth(&bitmap
->image
, &width
);
1490 GdipGetImageHeight(&bitmap
->image
, &height
);
1492 bih
.biSize
= sizeof(bih
);
1493 bih
.biWidth
= width
;
1494 bih
.biHeight
= height
;
1496 bih
.biBitCount
= 32;
1497 bih
.biCompression
= BI_RGB
;
1498 bih
.biSizeImage
= 0;
1499 bih
.biXPelsPerMeter
= 0;
1500 bih
.biYPelsPerMeter
= 0;
1502 bih
.biClrImportant
= 0;
1504 result
= CreateDIBSection(0, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1507 image_unlock(&bitmap
->image
, unlock
);
1508 return GenericError
;
1511 stat
= convert_pixels(width
, height
, -width
*4,
1512 bits
+ (width
* 4 * (height
- 1)), PixelFormat32bppPARGB
,
1513 bitmap
->stride
, bitmap
->bits
, bitmap
->format
, bitmap
->image
.palette
);
1516 DeleteObject(result
);
1517 image_unlock(&bitmap
->image
, unlock
);
1521 if (background
& 0xffffff)
1525 for (ptr
= (DWORD
*)bits
, i
= 0; i
< width
* height
; ptr
++, i
++)
1527 if ((*ptr
& 0xff000000) == 0xff000000) continue;
1528 *ptr
= blend_argb_no_bkgnd_alpha(*ptr
, background
);
1532 *hbmReturn
= result
;
1533 image_unlock(&bitmap
->image
, unlock
);
1537 GpStatus WINGDIPAPI
GdipCreateBitmapFromGraphics(INT width
, INT height
,
1538 GpGraphics
* target
, GpBitmap
** bitmap
)
1542 TRACE("(%d, %d, %p, %p)\n", width
, height
, target
, bitmap
);
1544 if(!target
|| !bitmap
)
1545 return InvalidParameter
;
1547 ret
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat32bppPARGB
,
1552 GdipGetDpiX(target
, &(*bitmap
)->image
.xres
);
1553 GdipGetDpiY(target
, &(*bitmap
)->image
.yres
);
1559 GpStatus WINGDIPAPI
GdipCreateBitmapFromHICON(HICON hicon
, GpBitmap
** bitmap
)
1565 UINT width
, height
, stride
;
1567 BitmapData lockeddata
;
1571 BITMAPINFOHEADER bih
;
1576 TRACE("%p, %p\n", hicon
, bitmap
);
1578 if(!bitmap
|| !GetIconInfo(hicon
, &iinfo
))
1579 return InvalidParameter
;
1581 /* get the size of the icon */
1582 ret
= GetObjectA(iinfo
.hbmColor
? iinfo
.hbmColor
: iinfo
.hbmMask
, sizeof(bm
), &bm
);
1584 DeleteObject(iinfo
.hbmColor
);
1585 DeleteObject(iinfo
.hbmMask
);
1586 return GenericError
;
1590 height
= iinfo
.hbmColor
? abs(bm
.bmHeight
) : abs(bm
.bmHeight
) / 2;
1593 stat
= GdipCreateBitmapFromScan0(width
, height
, stride
, PixelFormat32bppARGB
, NULL
, bitmap
);
1595 DeleteObject(iinfo
.hbmColor
);
1596 DeleteObject(iinfo
.hbmMask
);
1603 rect
.Height
= height
;
1605 stat
= GdipBitmapLockBits(*bitmap
, &rect
, ImageLockModeWrite
, PixelFormat32bppARGB
, &lockeddata
);
1607 DeleteObject(iinfo
.hbmColor
);
1608 DeleteObject(iinfo
.hbmMask
);
1609 GdipDisposeImage(&(*bitmap
)->image
);
1613 bih
.biSize
= sizeof(bih
);
1614 bih
.biWidth
= width
;
1615 bih
.biHeight
= iinfo
.hbmColor
? -height
: -height
* 2;
1617 bih
.biBitCount
= 32;
1618 bih
.biCompression
= BI_RGB
;
1619 bih
.biSizeImage
= 0;
1620 bih
.biXPelsPerMeter
= 0;
1621 bih
.biYPelsPerMeter
= 0;
1623 bih
.biClrImportant
= 0;
1625 screendc
= CreateCompatibleDC(0);
1628 GetDIBits(screendc
, iinfo
.hbmColor
, 0, height
, lockeddata
.Scan0
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1630 if (bm
.bmBitsPixel
== 32)
1634 /* If any pixel has a non-zero alpha, ignore hbmMask */
1635 src
= (DWORD
*)lockeddata
.Scan0
;
1636 for (x
=0; x
<width
&& !has_alpha
; x
++)
1637 for (y
=0; y
<height
&& !has_alpha
; y
++)
1638 if ((*src
++ & 0xff000000) != 0)
1641 else has_alpha
= FALSE
;
1645 GetDIBits(screendc
, iinfo
.hbmMask
, 0, height
, lockeddata
.Scan0
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1653 BYTE
*bits
= heap_alloc(height
* stride
);
1655 /* read alpha data from the mask */
1657 GetDIBits(screendc
, iinfo
.hbmMask
, 0, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1659 GetDIBits(screendc
, iinfo
.hbmMask
, height
, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1662 dst_row
= lockeddata
.Scan0
;
1663 for (y
=0; y
<height
; y
++)
1665 dst
= (DWORD
*)dst_row
;
1666 for (x
=0; x
<height
; x
++)
1668 DWORD src_value
= *src
++;
1672 *dst
++ |= 0xff000000;
1674 dst_row
+= lockeddata
.Stride
;
1681 /* set constant alpha of 255 */
1682 dst_row
= lockeddata
.Scan0
;
1683 for (y
=0; y
<height
; y
++)
1685 dst
= (DWORD
*)dst_row
;
1686 for (x
=0; x
<height
; x
++)
1687 *dst
++ |= 0xff000000;
1688 dst_row
+= lockeddata
.Stride
;
1695 DeleteObject(iinfo
.hbmColor
);
1696 DeleteObject(iinfo
.hbmMask
);
1698 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
1703 static void generate_halftone_palette(ARGB
*entries
, UINT count
)
1705 static const BYTE halftone_values
[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1708 for (i
=0; i
<8 && i
<count
; i
++)
1710 entries
[i
] = 0xff000000;
1711 if (i
&1) entries
[i
] |= 0x800000;
1712 if (i
&2) entries
[i
] |= 0x8000;
1713 if (i
&4) entries
[i
] |= 0x80;
1717 entries
[i
] = 0xffc0c0c0;
1719 for (i
=9; i
<16 && i
<count
; i
++)
1721 entries
[i
] = 0xff000000;
1722 if (i
&1) entries
[i
] |= 0xff0000;
1723 if (i
&2) entries
[i
] |= 0xff00;
1724 if (i
&4) entries
[i
] |= 0xff;
1727 for (i
=16; i
<40 && i
<count
; i
++)
1732 for (i
=40; i
<256 && i
<count
; i
++)
1734 entries
[i
] = 0xff000000;
1735 entries
[i
] |= halftone_values
[(i
-40)%6];
1736 entries
[i
] |= halftone_values
[((i
-40)/6)%6] << 8;
1737 entries
[i
] |= halftone_values
[((i
-40)/36)%6] << 16;
1741 static GpStatus
get_screen_resolution(REAL
*xres
, REAL
*yres
)
1743 HDC screendc
= CreateCompatibleDC(0);
1745 if (!screendc
) return GenericError
;
1747 *xres
= (REAL
)GetDeviceCaps(screendc
, LOGPIXELSX
);
1748 *yres
= (REAL
)GetDeviceCaps(screendc
, LOGPIXELSY
);
1755 GpStatus WINGDIPAPI
GdipCreateBitmapFromScan0(INT width
, INT height
, INT stride
,
1756 PixelFormat format
, BYTE
* scan0
, GpBitmap
** bitmap
)
1758 HBITMAP hbitmap
=NULL
;
1759 INT row_size
, dib_stride
;
1760 BYTE
*bits
=NULL
, *own_bits
=NULL
;
1764 TRACE("%d %d %d 0x%x %p %p\n", width
, height
, stride
, format
, scan0
, bitmap
);
1766 if (!bitmap
) return InvalidParameter
;
1768 if(width
<= 0 || height
<= 0 || (scan0
&& (stride
% 4))){
1770 return InvalidParameter
;
1773 if(scan0
&& !stride
)
1774 return InvalidParameter
;
1776 stat
= get_screen_resolution(&xres
, &yres
);
1777 if (stat
!= Ok
) return stat
;
1779 row_size
= (width
* PIXELFORMATBPP(format
)+7) / 8;
1780 dib_stride
= (row_size
+ 3) & ~3;
1783 stride
= dib_stride
;
1785 if (format
& PixelFormatGDI
&& !(format
& (PixelFormatAlpha
|PixelFormatIndexed
)) && !scan0
)
1787 char bmibuf
[FIELD_OFFSET(BITMAPINFO
, bmiColors
[256])];
1788 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
1790 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1791 pbmi
->bmiHeader
.biWidth
= width
;
1792 pbmi
->bmiHeader
.biHeight
= -height
;
1793 pbmi
->bmiHeader
.biPlanes
= 1;
1794 /* FIXME: use the rest of the data from format */
1795 pbmi
->bmiHeader
.biBitCount
= PIXELFORMATBPP(format
);
1796 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
1797 pbmi
->bmiHeader
.biSizeImage
= 0;
1798 pbmi
->bmiHeader
.biXPelsPerMeter
= 0;
1799 pbmi
->bmiHeader
.biYPelsPerMeter
= 0;
1800 pbmi
->bmiHeader
.biClrUsed
= 0;
1801 pbmi
->bmiHeader
.biClrImportant
= 0;
1803 hbitmap
= CreateDIBSection(0, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1805 if (!hbitmap
) return GenericError
;
1807 stride
= dib_stride
;
1811 /* Not a GDI format; don't try to make an HBITMAP. */
1816 INT size
= abs(stride
) * height
;
1818 own_bits
= bits
= heap_alloc_zero(size
);
1819 if (!own_bits
) return OutOfMemory
;
1822 bits
+= stride
* (1 - height
);
1826 *bitmap
= heap_alloc_zero(sizeof(GpBitmap
));
1829 DeleteObject(hbitmap
);
1830 heap_free(own_bits
);
1834 (*bitmap
)->image
.type
= ImageTypeBitmap
;
1835 memcpy(&(*bitmap
)->image
.format
, &ImageFormatMemoryBMP
, sizeof(GUID
));
1836 (*bitmap
)->image
.flags
= ImageFlagsNone
;
1837 (*bitmap
)->image
.frame_count
= 1;
1838 (*bitmap
)->image
.current_frame
= 0;
1839 (*bitmap
)->image
.palette
= NULL
;
1840 (*bitmap
)->image
.xres
= xres
;
1841 (*bitmap
)->image
.yres
= yres
;
1842 (*bitmap
)->width
= width
;
1843 (*bitmap
)->height
= height
;
1844 (*bitmap
)->format
= format
;
1845 (*bitmap
)->image
.decoder
= NULL
;
1846 (*bitmap
)->hbitmap
= hbitmap
;
1847 (*bitmap
)->hdc
= NULL
;
1848 (*bitmap
)->bits
= bits
;
1849 (*bitmap
)->stride
= stride
;
1850 (*bitmap
)->own_bits
= own_bits
;
1851 (*bitmap
)->metadata_reader
= NULL
;
1852 (*bitmap
)->prop_count
= 0;
1853 (*bitmap
)->prop_item
= NULL
;
1855 /* set format-related flags */
1856 if (format
& (PixelFormatAlpha
|PixelFormatPAlpha
|PixelFormatIndexed
))
1857 (*bitmap
)->image
.flags
|= ImageFlagsHasAlpha
;
1859 if (format
== PixelFormat1bppIndexed
||
1860 format
== PixelFormat4bppIndexed
||
1861 format
== PixelFormat8bppIndexed
)
1863 (*bitmap
)->image
.palette
= heap_alloc_zero(sizeof(UINT
) * 2 + sizeof(ARGB
) * (1 << PIXELFORMATBPP(format
)));
1865 if (!(*bitmap
)->image
.palette
)
1867 GdipDisposeImage(&(*bitmap
)->image
);
1872 (*bitmap
)->image
.palette
->Count
= 1 << PIXELFORMATBPP(format
);
1874 if (format
== PixelFormat1bppIndexed
)
1876 (*bitmap
)->image
.palette
->Flags
= PaletteFlagsGrayScale
;
1877 (*bitmap
)->image
.palette
->Entries
[0] = 0xff000000;
1878 (*bitmap
)->image
.palette
->Entries
[1] = 0xffffffff;
1882 if (format
== PixelFormat8bppIndexed
)
1883 (*bitmap
)->image
.palette
->Flags
= PaletteFlagsHalftone
;
1885 generate_halftone_palette((*bitmap
)->image
.palette
->Entries
,
1886 (*bitmap
)->image
.palette
->Count
);
1890 TRACE("<-- %p\n", *bitmap
);
1895 GpStatus WINGDIPAPI
GdipCreateBitmapFromStream(IStream
* stream
,
1900 TRACE("%p %p\n", stream
, bitmap
);
1902 stat
= GdipLoadImageFromStream(stream
, (GpImage
**) bitmap
);
1907 if((*bitmap
)->image
.type
!= ImageTypeBitmap
){
1908 GdipDisposeImage(&(*bitmap
)->image
);
1910 return GenericError
; /* FIXME: what error to return? */
1917 GpStatus WINGDIPAPI
GdipCreateBitmapFromStreamICM(IStream
* stream
,
1920 TRACE("%p %p\n", stream
, bitmap
);
1922 return GdipCreateBitmapFromStream(stream
, bitmap
);
1925 GpStatus WINGDIPAPI
GdipCreateCachedBitmap(GpBitmap
*bitmap
, GpGraphics
*graphics
,
1926 GpCachedBitmap
**cachedbmp
)
1930 TRACE("%p %p %p\n", bitmap
, graphics
, cachedbmp
);
1932 if(!bitmap
|| !graphics
|| !cachedbmp
)
1933 return InvalidParameter
;
1935 *cachedbmp
= heap_alloc_zero(sizeof(GpCachedBitmap
));
1939 stat
= GdipCloneImage(&(bitmap
->image
), &(*cachedbmp
)->image
);
1941 heap_free(*cachedbmp
);
1948 GpStatus WINGDIPAPI
GdipCreateHICONFromBitmap(GpBitmap
*bitmap
, HICON
*hicon
)
1951 BitmapData lockeddata
;
1952 ULONG andstride
, xorstride
, bitssize
;
1953 LPBYTE andbits
, xorbits
, androw
, xorrow
, srcrow
;
1956 TRACE("(%p, %p)\n", bitmap
, hicon
);
1958 if (!bitmap
|| !hicon
)
1959 return InvalidParameter
;
1961 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
,
1962 PixelFormat32bppPARGB
, &lockeddata
);
1965 andstride
= ((lockeddata
.Width
+31)/32)*4;
1966 xorstride
= lockeddata
.Width
*4;
1967 bitssize
= (andstride
+ xorstride
) * lockeddata
.Height
;
1969 andbits
= heap_alloc_zero(bitssize
);
1973 xorbits
= andbits
+ andstride
* lockeddata
.Height
;
1975 for (y
=0; y
<lockeddata
.Height
; y
++)
1977 srcrow
= ((LPBYTE
)lockeddata
.Scan0
) + lockeddata
.Stride
* y
;
1979 androw
= andbits
+ andstride
* y
;
1980 for (x
=0; x
<lockeddata
.Width
; x
++)
1981 if (srcrow
[3+4*x
] >= 128)
1982 androw
[x
/8] |= 1 << (7-x
%8);
1984 xorrow
= xorbits
+ xorstride
* y
;
1985 memcpy(xorrow
, srcrow
, xorstride
);
1988 *hicon
= CreateIcon(NULL
, lockeddata
.Width
, lockeddata
.Height
, 1, 32,
1996 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
2002 GpStatus WINGDIPAPI
GdipDeleteCachedBitmap(GpCachedBitmap
*cachedbmp
)
2004 TRACE("%p\n", cachedbmp
);
2007 return InvalidParameter
;
2009 GdipDisposeImage(cachedbmp
->image
);
2010 heap_free(cachedbmp
);
2015 GpStatus WINGDIPAPI
GdipDrawCachedBitmap(GpGraphics
*graphics
,
2016 GpCachedBitmap
*cachedbmp
, INT x
, INT y
)
2018 TRACE("%p %p %d %d\n", graphics
, cachedbmp
, x
, y
);
2020 if(!graphics
|| !cachedbmp
)
2021 return InvalidParameter
;
2023 return GdipDrawImage(graphics
, cachedbmp
->image
, (REAL
)x
, (REAL
)y
);
2026 /* Internal utility function: Replace the image data of dst with that of src,
2028 static void move_bitmap(GpBitmap
*dst
, GpBitmap
*src
, BOOL clobber_palette
)
2030 assert(src
->image
.type
== ImageTypeBitmap
);
2031 assert(dst
->image
.type
== ImageTypeBitmap
);
2033 heap_free(dst
->bitmapbits
);
2034 heap_free(dst
->own_bits
);
2036 DeleteObject(dst
->hbitmap
);
2038 if (clobber_palette
)
2040 heap_free(dst
->image
.palette
);
2041 dst
->image
.palette
= src
->image
.palette
;
2044 heap_free(src
->image
.palette
);
2046 dst
->image
.xres
= src
->image
.xres
;
2047 dst
->image
.yres
= src
->image
.yres
;
2048 dst
->width
= src
->width
;
2049 dst
->height
= src
->height
;
2050 dst
->format
= src
->format
;
2051 dst
->hbitmap
= src
->hbitmap
;
2052 dst
->hdc
= src
->hdc
;
2053 dst
->bits
= src
->bits
;
2054 dst
->stride
= src
->stride
;
2055 dst
->own_bits
= src
->own_bits
;
2056 if (dst
->metadata_reader
)
2057 IWICMetadataReader_Release(dst
->metadata_reader
);
2058 dst
->metadata_reader
= src
->metadata_reader
;
2059 heap_free(dst
->prop_item
);
2060 dst
->prop_item
= src
->prop_item
;
2061 dst
->prop_count
= src
->prop_count
;
2062 if (dst
->image
.decoder
)
2063 IWICBitmapDecoder_Release(dst
->image
.decoder
);
2064 dst
->image
.decoder
= src
->image
.decoder
;
2065 dst
->image
.frame_count
= src
->image
.frame_count
;
2066 dst
->image
.current_frame
= src
->image
.current_frame
;
2067 dst
->image
.format
= src
->image
.format
;
2069 src
->image
.type
= ~0;
2073 static GpStatus
free_image_data(GpImage
*image
)
2076 return InvalidParameter
;
2078 if (image
->type
== ImageTypeBitmap
)
2080 heap_free(((GpBitmap
*)image
)->bitmapbits
);
2081 heap_free(((GpBitmap
*)image
)->own_bits
);
2082 DeleteDC(((GpBitmap
*)image
)->hdc
);
2083 DeleteObject(((GpBitmap
*)image
)->hbitmap
);
2084 if (((GpBitmap
*)image
)->metadata_reader
)
2085 IWICMetadataReader_Release(((GpBitmap
*)image
)->metadata_reader
);
2086 heap_free(((GpBitmap
*)image
)->prop_item
);
2088 else if (image
->type
== ImageTypeMetafile
)
2089 METAFILE_Free((GpMetafile
*)image
);
2092 WARN("invalid image: %p\n", image
);
2096 IWICBitmapDecoder_Release(image
->decoder
);
2097 heap_free(image
->palette
);
2102 GpStatus WINGDIPAPI
GdipDisposeImage(GpImage
*image
)
2106 TRACE("%p\n", image
);
2108 status
= free_image_data(image
);
2109 if (status
!= Ok
) return status
;
2116 GpStatus WINGDIPAPI
GdipFindFirstImageItem(GpImage
*image
, ImageItemData
* item
)
2120 TRACE("(%p,%p)\n", image
, item
);
2123 return InvalidParameter
;
2126 FIXME("not implemented\n");
2128 return NotImplemented
;
2131 GpStatus WINGDIPAPI
GdipGetImageItemData(GpImage
*image
, ImageItemData
*item
)
2135 TRACE("(%p,%p)\n", image
, item
);
2138 FIXME("not implemented\n");
2140 return NotImplemented
;
2143 GpStatus WINGDIPAPI
GdipGetImageBounds(GpImage
*image
, GpRectF
*srcRect
,
2146 TRACE("%p %p %p\n", image
, srcRect
, srcUnit
);
2148 if(!image
|| !srcRect
|| !srcUnit
)
2149 return InvalidParameter
;
2150 if(image
->type
== ImageTypeMetafile
){
2151 *srcRect
= ((GpMetafile
*)image
)->bounds
;
2152 *srcUnit
= ((GpMetafile
*)image
)->unit
;
2154 else if(image
->type
== ImageTypeBitmap
){
2155 srcRect
->X
= srcRect
->Y
= 0.0;
2156 srcRect
->Width
= (REAL
) ((GpBitmap
*)image
)->width
;
2157 srcRect
->Height
= (REAL
) ((GpBitmap
*)image
)->height
;
2158 *srcUnit
= UnitPixel
;
2161 WARN("GpImage with no image data\n");
2162 return InvalidParameter
;
2165 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect
->X
, srcRect
->Y
,
2166 srcRect
->Width
, srcRect
->Height
, *srcUnit
);
2171 GpStatus WINGDIPAPI
GdipGetImageDimension(GpImage
*image
, REAL
*width
,
2174 TRACE("%p %p %p\n", image
, width
, height
);
2176 if(!image
|| !height
|| !width
)
2177 return InvalidParameter
;
2179 if(image
->type
== ImageTypeMetafile
){
2180 *height
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Height
, ((GpMetafile
*)image
)->unit
, image
->yres
);
2181 *width
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Width
, ((GpMetafile
*)image
)->unit
, image
->xres
);
2183 else if(image
->type
== ImageTypeBitmap
){
2184 *height
= ((GpBitmap
*)image
)->height
;
2185 *width
= ((GpBitmap
*)image
)->width
;
2188 WARN("GpImage with no image data\n");
2189 return InvalidParameter
;
2192 TRACE("returning (%f, %f)\n", *height
, *width
);
2196 GpStatus WINGDIPAPI
GdipGetImageGraphicsContext(GpImage
*image
,
2197 GpGraphics
**graphics
)
2202 TRACE("%p %p\n", image
, graphics
);
2204 if(!image
|| !graphics
)
2205 return InvalidParameter
;
2207 if (image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)image
)->hbitmap
)
2209 hdc
= ((GpBitmap
*)image
)->hdc
;
2212 hdc
= CreateCompatibleDC(0);
2213 SelectObject(hdc
, ((GpBitmap
*)image
)->hbitmap
);
2214 ((GpBitmap
*)image
)->hdc
= hdc
;
2217 stat
= GdipCreateFromHDC(hdc
, graphics
);
2221 (*graphics
)->image
= image
;
2222 (*graphics
)->xres
= image
->xres
;
2223 (*graphics
)->yres
= image
->yres
;
2226 else if (image
->type
== ImageTypeMetafile
)
2227 stat
= METAFILE_GetGraphicsContext((GpMetafile
*)image
, graphics
);
2229 stat
= graphics_from_image(image
, graphics
);
2234 GpStatus WINGDIPAPI
GdipGetImageHeight(GpImage
*image
, UINT
*height
)
2236 TRACE("%p %p\n", image
, height
);
2238 if(!image
|| !height
)
2239 return InvalidParameter
;
2241 if(image
->type
== ImageTypeMetafile
)
2242 *height
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Height
, ((GpMetafile
*)image
)->unit
, image
->yres
);
2243 else if(image
->type
== ImageTypeBitmap
)
2244 *height
= ((GpBitmap
*)image
)->height
;
2247 WARN("GpImage with no image data\n");
2248 return InvalidParameter
;
2251 TRACE("returning %d\n", *height
);
2256 GpStatus WINGDIPAPI
GdipGetImageHorizontalResolution(GpImage
*image
, REAL
*res
)
2259 return InvalidParameter
;
2263 TRACE("(%p) <-- %0.2f\n", image
, *res
);
2268 GpStatus WINGDIPAPI
GdipGetImagePaletteSize(GpImage
*image
, INT
*size
)
2270 TRACE("%p %p\n", image
, size
);
2273 return InvalidParameter
;
2275 if (!image
->palette
|| image
->palette
->Count
== 0)
2276 *size
= sizeof(ColorPalette
);
2278 *size
= sizeof(UINT
)*2 + sizeof(ARGB
)*image
->palette
->Count
;
2280 TRACE("<-- %u\n", *size
);
2285 /* FIXME: test this function for non-bitmap types */
2286 GpStatus WINGDIPAPI
GdipGetImagePixelFormat(GpImage
*image
, PixelFormat
*format
)
2288 TRACE("%p %p\n", image
, format
);
2290 if(!image
|| !format
)
2291 return InvalidParameter
;
2293 if(image
->type
!= ImageTypeBitmap
)
2294 *format
= PixelFormat24bppRGB
;
2296 *format
= ((GpBitmap
*) image
)->format
;
2301 GpStatus WINGDIPAPI
GdipGetImageRawFormat(GpImage
*image
, GUID
*format
)
2303 TRACE("(%p, %p)\n", image
, format
);
2305 if(!image
|| !format
)
2306 return InvalidParameter
;
2308 memcpy(format
, &image
->format
, sizeof(GUID
));
2313 GpStatus WINGDIPAPI
GdipGetImageType(GpImage
*image
, ImageType
*type
)
2315 TRACE("%p %p\n", image
, type
);
2318 return InvalidParameter
;
2320 *type
= image
->type
;
2325 GpStatus WINGDIPAPI
GdipGetImageVerticalResolution(GpImage
*image
, REAL
*res
)
2328 return InvalidParameter
;
2332 TRACE("(%p) <-- %0.2f\n", image
, *res
);
2337 GpStatus WINGDIPAPI
GdipGetImageWidth(GpImage
*image
, UINT
*width
)
2339 TRACE("%p %p\n", image
, width
);
2341 if(!image
|| !width
)
2342 return InvalidParameter
;
2344 if(image
->type
== ImageTypeMetafile
)
2345 *width
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Width
, ((GpMetafile
*)image
)->unit
, image
->xres
);
2346 else if(image
->type
== ImageTypeBitmap
)
2347 *width
= ((GpBitmap
*)image
)->width
;
2350 WARN("GpImage with no image data\n");
2351 return InvalidParameter
;
2354 TRACE("returning %d\n", *width
);
2359 GpStatus WINGDIPAPI
GdipGetPropertyCount(GpImage
*image
, UINT
*num
)
2361 TRACE("(%p, %p)\n", image
, num
);
2363 if (!image
|| !num
) return InvalidParameter
;
2367 if (image
->type
== ImageTypeBitmap
)
2369 if (((GpBitmap
*)image
)->prop_item
)
2371 *num
= ((GpBitmap
*)image
)->prop_count
;
2375 if (((GpBitmap
*)image
)->metadata_reader
)
2376 IWICMetadataReader_GetCount(((GpBitmap
*)image
)->metadata_reader
, num
);
2382 GpStatus WINGDIPAPI
GdipGetPropertyIdList(GpImage
*image
, UINT num
, PROPID
*list
)
2385 IWICMetadataReader
*reader
;
2386 IWICEnumMetadataItem
*enumerator
;
2387 UINT prop_count
, i
, items_returned
;
2389 TRACE("(%p, %u, %p)\n", image
, num
, list
);
2391 if (!image
|| !list
) return InvalidParameter
;
2393 if (image
->type
!= ImageTypeBitmap
)
2395 FIXME("Not implemented for type %d\n", image
->type
);
2396 return NotImplemented
;
2399 if (((GpBitmap
*)image
)->prop_item
)
2401 if (num
!= ((GpBitmap
*)image
)->prop_count
) return InvalidParameter
;
2403 for (i
= 0; i
< num
; i
++)
2405 list
[i
] = ((GpBitmap
*)image
)->prop_item
[i
].id
;
2411 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2414 if (num
!= 0) return InvalidParameter
;
2418 hr
= IWICMetadataReader_GetCount(reader
, &prop_count
);
2419 if (FAILED(hr
)) return hresult_to_status(hr
);
2421 if (num
!= prop_count
) return InvalidParameter
;
2423 hr
= IWICMetadataReader_GetEnumerator(reader
, &enumerator
);
2424 if (FAILED(hr
)) return hresult_to_status(hr
);
2426 IWICEnumMetadataItem_Reset(enumerator
);
2428 for (i
= 0; i
< num
; i
++)
2432 hr
= IWICEnumMetadataItem_Next(enumerator
, 1, NULL
, &id
, NULL
, &items_returned
);
2433 if (hr
!= S_OK
) break;
2435 if (id
.vt
!= VT_UI2
)
2437 FIXME("not supported propvariant type for id: %u\n", id
.vt
);
2441 list
[i
] = id
.u
.uiVal
;
2444 IWICEnumMetadataItem_Release(enumerator
);
2446 return hr
== S_OK
? Ok
: hresult_to_status(hr
);
2449 static UINT
propvariant_size(PROPVARIANT
*value
)
2451 switch (value
->vt
& ~VT_VECTOR
)
2457 if (!(value
->vt
& VT_VECTOR
)) return 1;
2458 return value
->u
.caub
.cElems
;
2461 if (!(value
->vt
& VT_VECTOR
)) return 2;
2462 return value
->u
.caui
.cElems
* 2;
2466 if (!(value
->vt
& VT_VECTOR
)) return 4;
2467 return value
->u
.caul
.cElems
* 4;
2471 if (!(value
->vt
& VT_VECTOR
)) return 8;
2472 return value
->u
.cauh
.cElems
* 8;
2474 return value
->u
.pszVal
? strlen(value
->u
.pszVal
) + 1 : 0;
2476 return value
->u
.blob
.cbSize
;
2478 FIXME("not supported variant type %d\n", value
->vt
);
2483 GpStatus WINGDIPAPI
GdipGetPropertyItemSize(GpImage
*image
, PROPID propid
, UINT
*size
)
2486 IWICMetadataReader
*reader
;
2487 PROPVARIANT id
, value
;
2489 TRACE("(%p,%#x,%p)\n", image
, propid
, size
);
2491 if (!size
|| !image
) return InvalidParameter
;
2493 if (image
->type
!= ImageTypeBitmap
)
2495 FIXME("Not implemented for type %d\n", image
->type
);
2496 return NotImplemented
;
2499 if (((GpBitmap
*)image
)->prop_item
)
2503 for (i
= 0; i
< ((GpBitmap
*)image
)->prop_count
; i
++)
2505 if (propid
== ((GpBitmap
*)image
)->prop_item
[i
].id
)
2507 *size
= sizeof(PropertyItem
) + ((GpBitmap
*)image
)->prop_item
[i
].length
;
2512 return PropertyNotFound
;
2515 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2516 if (!reader
) return PropertyNotFound
;
2519 id
.u
.uiVal
= propid
;
2520 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
2521 if (FAILED(hr
)) return PropertyNotFound
;
2523 *size
= propvariant_size(&value
);
2524 if (*size
) *size
+= sizeof(PropertyItem
);
2525 PropVariantClear(&value
);
2530 #ifndef PropertyTagTypeSByte
2531 #define PropertyTagTypeSByte 6
2532 #define PropertyTagTypeSShort 8
2533 #define PropertyTagTypeFloat 11
2534 #define PropertyTagTypeDouble 12
2537 static UINT
vt_to_itemtype(UINT vt
)
2544 { VT_I1
, PropertyTagTypeSByte
},
2545 { VT_UI1
, PropertyTagTypeByte
},
2546 { VT_I2
, PropertyTagTypeSShort
},
2547 { VT_UI2
, PropertyTagTypeShort
},
2548 { VT_I4
, PropertyTagTypeSLONG
},
2549 { VT_UI4
, PropertyTagTypeLong
},
2550 { VT_I8
, PropertyTagTypeSRational
},
2551 { VT_UI8
, PropertyTagTypeRational
},
2552 { VT_R4
, PropertyTagTypeFloat
},
2553 { VT_R8
, PropertyTagTypeDouble
},
2554 { VT_LPSTR
, PropertyTagTypeASCII
},
2555 { VT_BLOB
, PropertyTagTypeUndefined
}
2558 for (i
= 0; i
< ARRAY_SIZE(vt2type
); i
++)
2560 if (vt2type
[i
].vt
== vt
) return vt2type
[i
].type
;
2562 FIXME("not supported variant type %u\n", vt
);
2566 static GpStatus
propvariant_to_item(PROPVARIANT
*value
, PropertyItem
*item
,
2567 UINT size
, PROPID id
)
2569 UINT item_size
, item_type
;
2571 item_size
= propvariant_size(value
);
2572 if (size
!= item_size
+ sizeof(PropertyItem
)) return InvalidParameter
;
2574 item_type
= vt_to_itemtype(value
->vt
& ~VT_VECTOR
);
2575 if (!item_type
) return InvalidParameter
;
2577 item
->value
= item
+ 1;
2579 switch (value
->vt
& ~VT_VECTOR
)
2583 if (!(value
->vt
& VT_VECTOR
))
2584 *(BYTE
*)item
->value
= value
->u
.bVal
;
2586 memcpy(item
->value
, value
->u
.caub
.pElems
, item_size
);
2590 if (!(value
->vt
& VT_VECTOR
))
2591 *(USHORT
*)item
->value
= value
->u
.uiVal
;
2593 memcpy(item
->value
, value
->u
.caui
.pElems
, item_size
);
2598 if (!(value
->vt
& VT_VECTOR
))
2599 *(ULONG
*)item
->value
= value
->u
.ulVal
;
2601 memcpy(item
->value
, value
->u
.caul
.pElems
, item_size
);
2606 if (!(value
->vt
& VT_VECTOR
))
2607 *(ULONGLONG
*)item
->value
= value
->u
.uhVal
.QuadPart
;
2609 memcpy(item
->value
, value
->u
.cauh
.pElems
, item_size
);
2612 memcpy(item
->value
, value
->u
.pszVal
, item_size
);
2615 memcpy(item
->value
, value
->u
.blob
.pBlobData
, item_size
);
2618 FIXME("not supported variant type %d\n", value
->vt
);
2619 return InvalidParameter
;
2622 item
->length
= item_size
;
2623 item
->type
= item_type
;
2629 GpStatus WINGDIPAPI
GdipGetPropertyItem(GpImage
*image
, PROPID propid
, UINT size
,
2630 PropertyItem
*buffer
)
2634 IWICMetadataReader
*reader
;
2635 PROPVARIANT id
, value
;
2637 TRACE("(%p,%#x,%u,%p)\n", image
, propid
, size
, buffer
);
2639 if (!image
|| !buffer
) return InvalidParameter
;
2641 if (image
->type
!= ImageTypeBitmap
)
2643 FIXME("Not implemented for type %d\n", image
->type
);
2644 return NotImplemented
;
2647 if (((GpBitmap
*)image
)->prop_item
)
2651 for (i
= 0; i
< ((GpBitmap
*)image
)->prop_count
; i
++)
2653 if (propid
== ((GpBitmap
*)image
)->prop_item
[i
].id
)
2655 if (size
!= sizeof(PropertyItem
) + ((GpBitmap
*)image
)->prop_item
[i
].length
)
2656 return InvalidParameter
;
2658 *buffer
= ((GpBitmap
*)image
)->prop_item
[i
];
2659 buffer
->value
= buffer
+ 1;
2660 memcpy(buffer
->value
, ((GpBitmap
*)image
)->prop_item
[i
].value
, buffer
->length
);
2665 return PropertyNotFound
;
2668 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2669 if (!reader
) return PropertyNotFound
;
2672 id
.u
.uiVal
= propid
;
2673 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
2674 if (FAILED(hr
)) return PropertyNotFound
;
2676 stat
= propvariant_to_item(&value
, buffer
, size
, propid
);
2677 PropVariantClear(&value
);
2682 GpStatus WINGDIPAPI
GdipGetPropertySize(GpImage
*image
, UINT
*size
, UINT
*count
)
2685 IWICMetadataReader
*reader
;
2686 IWICEnumMetadataItem
*enumerator
;
2687 UINT prop_count
, prop_size
, i
;
2688 PROPVARIANT id
, value
;
2690 TRACE("(%p,%p,%p)\n", image
, size
, count
);
2692 if (!image
|| !size
|| !count
) return InvalidParameter
;
2694 if (image
->type
!= ImageTypeBitmap
)
2696 FIXME("Not implemented for type %d\n", image
->type
);
2697 return NotImplemented
;
2700 if (((GpBitmap
*)image
)->prop_item
)
2702 *count
= ((GpBitmap
*)image
)->prop_count
;
2705 for (i
= 0; i
< ((GpBitmap
*)image
)->prop_count
; i
++)
2707 *size
+= sizeof(PropertyItem
) + ((GpBitmap
*)image
)->prop_item
[i
].length
;
2713 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2714 if (!reader
) return PropertyNotFound
;
2716 hr
= IWICMetadataReader_GetCount(reader
, &prop_count
);
2717 if (FAILED(hr
)) return hresult_to_status(hr
);
2719 hr
= IWICMetadataReader_GetEnumerator(reader
, &enumerator
);
2720 if (FAILED(hr
)) return hresult_to_status(hr
);
2722 IWICEnumMetadataItem_Reset(enumerator
);
2726 PropVariantInit(&id
);
2727 PropVariantInit(&value
);
2729 for (i
= 0; i
< prop_count
; i
++)
2731 UINT items_returned
, item_size
;
2733 hr
= IWICEnumMetadataItem_Next(enumerator
, 1, NULL
, &id
, &value
, &items_returned
);
2734 if (hr
!= S_OK
) break;
2736 item_size
= propvariant_size(&value
);
2737 if (item_size
) prop_size
+= sizeof(PropertyItem
) + item_size
;
2739 PropVariantClear(&id
);
2740 PropVariantClear(&value
);
2743 IWICEnumMetadataItem_Release(enumerator
);
2745 if (hr
!= S_OK
) return PropertyNotFound
;
2747 *count
= prop_count
;
2752 GpStatus WINGDIPAPI
GdipGetAllPropertyItems(GpImage
*image
, UINT size
,
2753 UINT count
, PropertyItem
*buf
)
2757 IWICMetadataReader
*reader
;
2758 IWICEnumMetadataItem
*enumerator
;
2759 UINT prop_count
, prop_size
, i
;
2760 PROPVARIANT id
, value
;
2763 TRACE("(%p,%u,%u,%p)\n", image
, size
, count
, buf
);
2765 if (!image
|| !buf
) return InvalidParameter
;
2767 if (image
->type
!= ImageTypeBitmap
)
2769 FIXME("Not implemented for type %d\n", image
->type
);
2770 return NotImplemented
;
2773 status
= GdipGetPropertySize(image
, &prop_size
, &prop_count
);
2774 if (status
!= Ok
) return status
;
2776 if (prop_count
!= count
|| prop_size
!= size
) return InvalidParameter
;
2778 if (((GpBitmap
*)image
)->prop_item
)
2780 memcpy(buf
, ((GpBitmap
*)image
)->prop_item
, prop_size
);
2782 item_value
= (char *)(buf
+ prop_count
);
2784 for (i
= 0; i
< prop_count
; i
++)
2786 buf
[i
].value
= item_value
;
2787 item_value
+= buf
[i
].length
;
2793 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2794 if (!reader
) return PropertyNotFound
;
2796 hr
= IWICMetadataReader_GetEnumerator(reader
, &enumerator
);
2797 if (FAILED(hr
)) return hresult_to_status(hr
);
2799 IWICEnumMetadataItem_Reset(enumerator
);
2801 item_value
= (char *)(buf
+ prop_count
);
2803 PropVariantInit(&id
);
2804 PropVariantInit(&value
);
2806 for (i
= 0; i
< prop_count
; i
++)
2809 UINT items_returned
, item_size
;
2811 hr
= IWICEnumMetadataItem_Next(enumerator
, 1, NULL
, &id
, &value
, &items_returned
);
2812 if (hr
!= S_OK
) break;
2814 if (id
.vt
!= VT_UI2
)
2816 FIXME("not supported propvariant type for id: %u\n", id
.vt
);
2820 item_size
= propvariant_size(&value
);
2823 item
= heap_alloc(item_size
+ sizeof(*item
));
2825 propvariant_to_item(&value
, item
, item_size
+ sizeof(*item
), id
.u
.uiVal
);
2826 buf
[i
].id
= item
->id
;
2827 buf
[i
].type
= item
->type
;
2828 buf
[i
].length
= item_size
;
2829 buf
[i
].value
= item_value
;
2830 memcpy(item_value
, item
->value
, item_size
);
2831 item_value
+= item_size
;
2836 PropVariantClear(&id
);
2837 PropVariantClear(&value
);
2840 IWICEnumMetadataItem_Release(enumerator
);
2842 if (hr
!= S_OK
) return PropertyNotFound
;
2847 struct image_format_dimension
2850 const GUID
*dimension
;
2853 static const struct image_format_dimension image_format_dimensions
[] =
2855 {&ImageFormatGIF
, &FrameDimensionTime
},
2856 {&ImageFormatIcon
, &FrameDimensionResolution
},
2860 GpStatus WINGDIPAPI
GdipImageGetFrameCount(GpImage
*image
,
2861 GDIPCONST GUID
* dimensionID
, UINT
* count
)
2863 TRACE("(%p,%s,%p)\n", image
, debugstr_guid(dimensionID
), count
);
2865 if(!image
|| !count
)
2866 return InvalidParameter
;
2869 IsEqualGUID(dimensionID
, &image
->format
) ||
2870 IsEqualGUID(dimensionID
, &FrameDimensionPage
) ||
2871 IsEqualGUID(dimensionID
, &FrameDimensionTime
))
2873 *count
= image
->frame_count
;
2877 return InvalidParameter
;
2880 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsCount(GpImage
*image
,
2883 TRACE("(%p, %p)\n", image
, count
);
2885 /* Native gdiplus 1.1 does not yet support multiple frame dimensions. */
2887 if(!image
|| !count
)
2888 return InvalidParameter
;
2895 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsList(GpImage
* image
,
2896 GUID
* dimensionIDs
, UINT count
)
2899 const GUID
*result
=NULL
;
2901 TRACE("(%p,%p,%u)\n", image
, dimensionIDs
, count
);
2903 if(!image
|| !dimensionIDs
|| count
!= 1)
2904 return InvalidParameter
;
2906 for (i
=0; image_format_dimensions
[i
].format
; i
++)
2908 if (IsEqualGUID(&image
->format
, image_format_dimensions
[i
].format
))
2910 result
= image_format_dimensions
[i
].dimension
;
2916 result
= &FrameDimensionPage
;
2918 memcpy(dimensionIDs
, result
, sizeof(GUID
));
2923 GpStatus WINGDIPAPI
GdipLoadImageFromFile(GDIPCONST WCHAR
* filename
,
2929 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
2931 if (!filename
|| !image
)
2932 return InvalidParameter
;
2936 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
2941 stat
= GdipLoadImageFromStream(stream
, image
);
2943 IStream_Release(stream
);
2948 /* FIXME: no icm handling */
2949 GpStatus WINGDIPAPI
GdipLoadImageFromFileICM(GDIPCONST WCHAR
* filename
,GpImage
**image
)
2951 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
2953 return GdipLoadImageFromFile(filename
, image
);
2956 static void add_property(GpBitmap
*bitmap
, PropertyItem
*item
)
2958 UINT prop_size
, prop_count
;
2959 PropertyItem
*prop_item
;
2961 if (bitmap
->prop_item
== NULL
)
2963 prop_size
= prop_count
= 0;
2964 prop_item
= heap_alloc_zero(item
->length
+ sizeof(PropertyItem
));
2965 if (!prop_item
) return;
2972 GdipGetPropertySize(&bitmap
->image
, &prop_size
, &prop_count
);
2974 prop_item
= heap_alloc_zero(prop_size
+ item
->length
+ sizeof(PropertyItem
));
2975 if (!prop_item
) return;
2976 memcpy(prop_item
, bitmap
->prop_item
, sizeof(PropertyItem
) * bitmap
->prop_count
);
2977 prop_size
-= sizeof(PropertyItem
) * bitmap
->prop_count
;
2978 memcpy(prop_item
+ prop_count
+ 1, bitmap
->prop_item
+ prop_count
, prop_size
);
2980 item_value
= (char *)(prop_item
+ prop_count
+ 1);
2982 for (i
= 0; i
< prop_count
; i
++)
2984 prop_item
[i
].value
= item_value
;
2985 item_value
+= prop_item
[i
].length
;
2989 prop_item
[prop_count
].id
= item
->id
;
2990 prop_item
[prop_count
].type
= item
->type
;
2991 prop_item
[prop_count
].length
= item
->length
;
2992 prop_item
[prop_count
].value
= (char *)(prop_item
+ prop_count
+ 1) + prop_size
;
2993 memcpy(prop_item
[prop_count
].value
, item
->value
, item
->length
);
2995 heap_free(bitmap
->prop_item
);
2996 bitmap
->prop_item
= prop_item
;
2997 bitmap
->prop_count
++;
3000 static BOOL
get_bool_property(IWICMetadataReader
*reader
, const GUID
*guid
, const WCHAR
*prop_name
)
3004 PROPVARIANT id
, value
;
3007 hr
= IWICMetadataReader_GetMetadataFormat(reader
, &format
);
3008 if (FAILED(hr
) || !IsEqualGUID(&format
, guid
)) return FALSE
;
3010 PropVariantInit(&id
);
3011 PropVariantInit(&value
);
3014 id
.u
.pwszVal
= CoTaskMemAlloc((lstrlenW(prop_name
) + 1) * sizeof(WCHAR
));
3015 if (!id
.u
.pwszVal
) return FALSE
;
3016 lstrcpyW(id
.u
.pwszVal
, prop_name
);
3017 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
3018 if (hr
== S_OK
&& value
.vt
== VT_BOOL
)
3019 ret
= value
.u
.boolVal
;
3021 PropVariantClear(&id
);
3022 PropVariantClear(&value
);
3027 static PropertyItem
*get_property(IWICMetadataReader
*reader
, const GUID
*guid
, const WCHAR
*prop_name
)
3031 PROPVARIANT id
, value
;
3032 PropertyItem
*item
= NULL
;
3034 hr
= IWICMetadataReader_GetMetadataFormat(reader
, &format
);
3035 if (FAILED(hr
) || !IsEqualGUID(&format
, guid
)) return NULL
;
3037 PropVariantInit(&id
);
3038 PropVariantInit(&value
);
3041 id
.u
.pwszVal
= CoTaskMemAlloc((lstrlenW(prop_name
) + 1) * sizeof(WCHAR
));
3042 if (!id
.u
.pwszVal
) return NULL
;
3043 lstrcpyW(id
.u
.pwszVal
, prop_name
);
3044 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
3047 UINT item_size
= propvariant_size(&value
);
3050 item_size
+= sizeof(*item
);
3051 item
= heap_alloc_zero(item_size
);
3052 if (propvariant_to_item(&value
, item
, item_size
, 0) != Ok
)
3060 PropVariantClear(&id
);
3061 PropVariantClear(&value
);
3066 static PropertyItem
*get_gif_comment(IWICMetadataReader
*reader
)
3068 static const WCHAR textentryW
[] = { 'T','e','x','t','E','n','t','r','y',0 };
3069 PropertyItem
*comment
;
3071 comment
= get_property(reader
, &GUID_MetadataFormatGifComment
, textentryW
);
3073 comment
->id
= PropertyTagExifUserComment
;
3078 static PropertyItem
*get_gif_loopcount(IWICMetadataReader
*reader
)
3080 static const WCHAR applicationW
[] = { 'A','p','p','l','i','c','a','t','i','o','n',0 };
3081 static const WCHAR dataW
[] = { 'D','a','t','a',0 };
3082 PropertyItem
*appext
= NULL
, *appdata
= NULL
, *loop
= NULL
;
3084 appext
= get_property(reader
, &GUID_MetadataFormatAPE
, applicationW
);
3087 if (appext
->type
== PropertyTagTypeByte
&& appext
->length
== 11 &&
3088 (!memcmp(appext
->value
, "NETSCAPE2.0", 11) || !memcmp(appext
->value
, "ANIMEXTS1.0", 11)))
3090 appdata
= get_property(reader
, &GUID_MetadataFormatAPE
, dataW
);
3093 if (appdata
->type
== PropertyTagTypeByte
&& appdata
->length
== 4)
3095 BYTE
*data
= appdata
->value
;
3096 if (data
[0] == 3 && data
[1] == 1)
3098 loop
= heap_alloc_zero(sizeof(*loop
) + sizeof(SHORT
));
3101 loop
->type
= PropertyTagTypeShort
;
3102 loop
->id
= PropertyTagLoopCount
;
3103 loop
->length
= sizeof(SHORT
);
3104 loop
->value
= loop
+ 1;
3105 *(SHORT
*)loop
->value
= data
[2] | (data
[3] << 8);
3119 static PropertyItem
*get_gif_background(IWICMetadataReader
*reader
)
3121 static const WCHAR backgroundW
[] = { 'B','a','c','k','g','r','o','u','n','d','C','o','l','o','r','I','n','d','e','x',0 };
3122 PropertyItem
*background
;
3124 background
= get_property(reader
, &GUID_MetadataFormatLSD
, backgroundW
);
3126 background
->id
= PropertyTagIndexBackground
;
3131 static PropertyItem
*get_gif_palette(IWICBitmapDecoder
*decoder
, IWICMetadataReader
*reader
)
3133 static const WCHAR global_flagW
[] = { 'G','l','o','b','a','l','C','o','l','o','r','T','a','b','l','e','F','l','a','g',0 };
3135 IWICImagingFactory
*factory
;
3136 IWICPalette
*palette
;
3138 WICColor colors
[256];
3140 if (!get_bool_property(reader
, &GUID_MetadataFormatLSD
, global_flagW
))
3143 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
3144 if (hr
!= S_OK
) return NULL
;
3146 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
3149 hr
= IWICBitmapDecoder_CopyPalette(decoder
, palette
);
3151 IWICPalette_GetColors(palette
, 256, colors
, &count
);
3153 IWICPalette_Release(palette
);
3156 IWICImagingFactory_Release(factory
);
3164 pal
= heap_alloc_zero(sizeof(*pal
) + count
* 3);
3165 if (!pal
) return NULL
;
3166 pal
->type
= PropertyTagTypeByte
;
3167 pal
->id
= PropertyTagGlobalPalette
;
3168 pal
->value
= pal
+ 1;
3169 pal
->length
= count
* 3;
3173 for (i
= 0; i
< count
; i
++)
3175 rgb
[i
*3] = (colors
[i
] >> 16) & 0xff;
3176 rgb
[i
*3 + 1] = (colors
[i
] >> 8) & 0xff;
3177 rgb
[i
*3 + 2] = colors
[i
] & 0xff;
3186 static PropertyItem
*get_gif_transparent_idx(IWICMetadataReader
*reader
)
3188 static const WCHAR transparency_flagW
[] = { 'T','r','a','n','s','p','a','r','e','n','c','y','F','l','a','g',0 };
3189 static const WCHAR colorW
[] = { 'T','r','a','n','s','p','a','r','e','n','t','C','o','l','o','r','I','n','d','e','x',0 };
3190 PropertyItem
*index
= NULL
;
3192 if (get_bool_property(reader
, &GUID_MetadataFormatGCE
, transparency_flagW
))
3194 index
= get_property(reader
, &GUID_MetadataFormatGCE
, colorW
);
3196 index
->id
= PropertyTagIndexTransparent
;
3201 static LONG
get_gif_frame_property(IWICBitmapFrameDecode
*frame
, const GUID
*format
, const WCHAR
*property
)
3204 IWICMetadataBlockReader
*block_reader
;
3205 IWICMetadataReader
*reader
;
3206 UINT block_count
, i
;
3210 hr
= IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3213 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3216 for (i
= 0; i
< block_count
; i
++)
3218 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3221 prop
= get_property(reader
, format
, property
);
3224 if (prop
->type
== PropertyTagTypeByte
&& prop
->length
== 1)
3225 value
= *(BYTE
*)prop
->value
;
3226 else if (prop
->type
== PropertyTagTypeShort
&& prop
->length
== 2)
3227 value
= *(SHORT
*)prop
->value
;
3231 IWICMetadataReader_Release(reader
);
3235 IWICMetadataBlockReader_Release(block_reader
);
3241 static void gif_metadata_reader(GpBitmap
*bitmap
, IWICBitmapDecoder
*decoder
, UINT active_frame
)
3243 static const WCHAR delayW
[] = { 'D','e','l','a','y',0 };
3245 IWICBitmapFrameDecode
*frame
;
3246 IWICMetadataBlockReader
*block_reader
;
3247 IWICMetadataReader
*reader
;
3248 UINT frame_count
, block_count
, i
;
3249 PropertyItem
*delay
= NULL
, *comment
= NULL
, *background
= NULL
;
3250 PropertyItem
*transparent_idx
= NULL
, *loop
= NULL
, *palette
= NULL
;
3252 IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
3253 if (frame_count
> 1)
3255 delay
= heap_alloc_zero(sizeof(*delay
) + frame_count
* sizeof(LONG
));
3260 delay
->type
= PropertyTagTypeLong
;
3261 delay
->id
= PropertyTagFrameDelay
;
3262 delay
->length
= frame_count
* sizeof(LONG
);
3263 delay
->value
= delay
+ 1;
3265 value
= delay
->value
;
3267 for (i
= 0; i
< frame_count
; i
++)
3269 hr
= IWICBitmapDecoder_GetFrame(decoder
, i
, &frame
);
3272 value
[i
] = get_gif_frame_property(frame
, &GUID_MetadataFormatGCE
, delayW
);
3273 IWICBitmapFrameDecode_Release(frame
);
3280 hr
= IWICBitmapDecoder_QueryInterface(decoder
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3283 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3286 for (i
= 0; i
< block_count
; i
++)
3288 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3292 comment
= get_gif_comment(reader
);
3294 if (frame_count
> 1 && !loop
)
3295 loop
= get_gif_loopcount(reader
);
3298 background
= get_gif_background(reader
);
3301 palette
= get_gif_palette(decoder
, reader
);
3303 IWICMetadataReader_Release(reader
);
3307 IWICMetadataBlockReader_Release(block_reader
);
3310 if (frame_count
> 1 && !loop
)
3312 loop
= heap_alloc_zero(sizeof(*loop
) + sizeof(SHORT
));
3315 loop
->type
= PropertyTagTypeShort
;
3316 loop
->id
= PropertyTagLoopCount
;
3317 loop
->length
= sizeof(SHORT
);
3318 loop
->value
= loop
+ 1;
3319 *(SHORT
*)loop
->value
= 1;
3323 if (delay
) add_property(bitmap
, delay
);
3324 if (comment
) add_property(bitmap
, comment
);
3325 if (loop
) add_property(bitmap
, loop
);
3326 if (palette
) add_property(bitmap
, palette
);
3327 if (background
) add_property(bitmap
, background
);
3333 heap_free(background
);
3335 /* Win7 gdiplus always returns transparent color index from frame 0 */
3336 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
3337 if (hr
!= S_OK
) return;
3339 hr
= IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3342 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3345 for (i
= 0; i
< block_count
; i
++)
3347 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3350 if (!transparent_idx
)
3351 transparent_idx
= get_gif_transparent_idx(reader
);
3353 IWICMetadataReader_Release(reader
);
3357 IWICMetadataBlockReader_Release(block_reader
);
3360 if (transparent_idx
) add_property(bitmap
, transparent_idx
);
3361 heap_free(transparent_idx
);
3363 IWICBitmapFrameDecode_Release(frame
);
3366 static PropertyItem
* create_prop(PROPID propid
, PROPVARIANT
* value
)
3368 PropertyItem
*item
= NULL
;
3369 UINT item_size
= propvariant_size(value
);
3373 item_size
+= sizeof(*item
);
3374 item
= heap_alloc_zero(item_size
);
3375 if (propvariant_to_item(value
, item
, item_size
, propid
) != Ok
)
3385 static ULONG
get_ulong_by_index(IWICMetadataReader
* reader
, ULONG index
)
3391 hr
= IWICMetadataReader_GetValueByIndex(reader
, index
, NULL
, NULL
, &value
);
3397 result
= value
.u
.ulVal
;
3400 ERR("unhandled case %u\n", value
.vt
);
3403 PropVariantClear(&value
);
3408 static void png_metadata_reader(GpBitmap
*bitmap
, IWICBitmapDecoder
*decoder
, UINT active_frame
)
3411 IWICBitmapFrameDecode
*frame
;
3412 IWICMetadataBlockReader
*block_reader
;
3413 IWICMetadataReader
*reader
;
3414 UINT block_count
, i
, j
;
3415 struct keyword_info
{
3420 { "Title", PropertyTagImageTitle
},
3421 { "Author", PropertyTagArtist
},
3422 { "Description", PropertyTagImageDescription
},
3423 { "Copyright", PropertyTagCopyright
},
3424 { "Software", PropertyTagSoftwareUsed
},
3425 { "Source", PropertyTagEquipModel
},
3426 { "Comment", PropertyTagExifUserComment
},
3428 BOOL seen_gamma
=FALSE
, seen_whitepoint
=FALSE
, seen_chrm
=FALSE
;
3430 hr
= IWICBitmapDecoder_GetFrame(decoder
, active_frame
, &frame
);
3431 if (hr
!= S_OK
) return;
3433 hr
= IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3436 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3439 for (i
= 0; i
< block_count
; i
++)
3441 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3446 hr
= IWICMetadataReader_GetMetadataFormat(reader
, &format
);
3447 if (SUCCEEDED(hr
) && IsEqualGUID(&GUID_MetadataFormatChunktEXt
, &format
))
3449 PROPVARIANT name
, value
;
3452 hr
= IWICMetadataReader_GetValueByIndex(reader
, 0, NULL
, &name
, &value
);
3456 if (name
.vt
== VT_LPSTR
)
3458 for (j
= 0; j
< ARRAY_SIZE(keywords
); j
++)
3459 if (!strcmp(keywords
[j
].name
, name
.u
.pszVal
))
3461 if (j
< ARRAY_SIZE(keywords
) && !keywords
[j
].seen
)
3463 keywords
[j
].seen
= TRUE
;
3464 item
= create_prop(keywords
[j
].propid
, &value
);
3466 add_property(bitmap
, item
);
3471 PropVariantClear(&name
);
3472 PropVariantClear(&value
);
3475 else if (SUCCEEDED(hr
) && IsEqualGUID(&GUID_MetadataFormatChunkgAMA
, &format
))
3481 item
= heap_alloc_zero(sizeof(PropertyItem
) + sizeof(ULONG
) * 2);
3485 item
->length
= sizeof(ULONG
) * 2;
3486 item
->type
= PropertyTagTypeRational
;
3487 item
->id
= PropertyTagGamma
;
3488 rational
= item
->value
= item
+ 1;
3489 rational
[0] = 100000;
3490 rational
[1] = get_ulong_by_index(reader
, 0);
3491 add_property(bitmap
, item
);
3497 else if (SUCCEEDED(hr
) && IsEqualGUID(&GUID_MetadataFormatChunkcHRM
, &format
))
3501 if (!seen_whitepoint
)
3503 item
= GdipAlloc(sizeof(PropertyItem
) + sizeof(ULONG
) * 4);
3507 item
->length
= sizeof(ULONG
) * 4;
3508 item
->type
= PropertyTagTypeRational
;
3509 item
->id
= PropertyTagWhitePoint
;
3510 rational
= item
->value
= item
+ 1;
3511 rational
[0] = get_ulong_by_index(reader
, 0);
3512 rational
[1] = 100000;
3513 rational
[2] = get_ulong_by_index(reader
, 1);
3514 rational
[3] = 100000;
3515 add_property(bitmap
, item
);
3516 seen_whitepoint
= TRUE
;
3522 item
= GdipAlloc(sizeof(PropertyItem
) + sizeof(ULONG
) * 12);
3526 item
->length
= sizeof(ULONG
) * 12;
3527 item
->type
= PropertyTagTypeRational
;
3528 item
->id
= PropertyTagPrimaryChromaticities
;
3529 rational
= item
->value
= item
+ 1;
3530 rational
[0] = get_ulong_by_index(reader
, 2);
3531 rational
[1] = 100000;
3532 rational
[2] = get_ulong_by_index(reader
, 3);
3533 rational
[3] = 100000;
3534 rational
[4] = get_ulong_by_index(reader
, 4);
3535 rational
[5] = 100000;
3536 rational
[6] = get_ulong_by_index(reader
, 5);
3537 rational
[7] = 100000;
3538 rational
[8] = get_ulong_by_index(reader
, 6);
3539 rational
[9] = 100000;
3540 rational
[10] = get_ulong_by_index(reader
, 7);
3541 rational
[11] = 100000;
3542 add_property(bitmap
, item
);
3549 IWICMetadataReader_Release(reader
);
3553 IWICMetadataBlockReader_Release(block_reader
);
3556 IWICBitmapFrameDecode_Release(frame
);
3559 static GpStatus
initialize_decoder_wic(IStream
*stream
, REFGUID container
, IWICBitmapDecoder
**decoder
)
3561 IWICImagingFactory
*factory
;
3564 TRACE("%p,%s\n", stream
, wine_dbgstr_guid(container
));
3566 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
3567 if (FAILED(hr
)) return hresult_to_status(hr
);
3568 hr
= IWICImagingFactory_CreateDecoder(factory
, container
, NULL
, decoder
);
3569 IWICImagingFactory_Release(factory
);
3570 if (FAILED(hr
)) return hresult_to_status(hr
);
3572 hr
= IWICBitmapDecoder_Initialize(*decoder
, stream
, WICDecodeMetadataCacheOnLoad
);
3573 if (FAILED(hr
)) return hresult_to_status(hr
);
3577 typedef void (*metadata_reader_func
)(GpBitmap
*bitmap
, IWICBitmapDecoder
*decoder
, UINT frame
);
3579 static GpStatus
decode_frame_wic(IWICBitmapDecoder
*decoder
, BOOL force_conversion
,
3580 UINT active_frame
, metadata_reader_func metadata_reader
, GpImage
**image
)
3585 IWICBitmapFrameDecode
*frame
;
3586 IWICBitmapSource
*source
=NULL
;
3587 IWICMetadataBlockReader
*block_reader
;
3588 WICPixelFormatGUID wic_format
;
3589 PixelFormat gdip_format
=0;
3590 ColorPalette
*palette
= NULL
;
3591 WICBitmapPaletteType palette_type
= WICBitmapPaletteTypeFixedHalftone256
;
3593 UINT width
, height
, frame_count
;
3594 BitmapData lockeddata
;
3597 TRACE("%p,%u,%p\n", decoder
, active_frame
, image
);
3599 IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
3600 hr
= IWICBitmapDecoder_GetFrame(decoder
, active_frame
, &frame
);
3601 if (SUCCEEDED(hr
)) /* got frame */
3603 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &wic_format
);
3607 if (!force_conversion
)
3609 for (i
=0; pixel_formats
[i
].wic_format
; i
++)
3611 if (IsEqualGUID(&wic_format
, pixel_formats
[i
].wic_format
))
3613 source
= (IWICBitmapSource
*)frame
;
3614 IWICBitmapSource_AddRef(source
);
3615 gdip_format
= pixel_formats
[i
].gdip_format
;
3616 palette_type
= pixel_formats
[i
].palette_type
;
3623 /* unknown format; fall back on 32bppARGB */
3624 hr
= WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA
, (IWICBitmapSource
*)frame
, &source
);
3625 gdip_format
= PixelFormat32bppARGB
;
3627 TRACE("%s => %#x\n", wine_dbgstr_guid(&wic_format
), gdip_format
);
3630 if (SUCCEEDED(hr
)) /* got source */
3632 hr
= IWICBitmapSource_GetSize(source
, &width
, &height
);
3635 status
= GdipCreateBitmapFromScan0(width
, height
, 0, gdip_format
,
3638 if (SUCCEEDED(hr
) && status
== Ok
) /* created bitmap */
3640 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeWrite
,
3641 gdip_format
, &lockeddata
);
3642 if (status
== Ok
) /* locked bitmap */
3647 for (i
=0; i
<height
; i
++)
3650 hr
= IWICBitmapSource_CopyPixels(source
, &wrc
, abs(lockeddata
.Stride
),
3651 abs(lockeddata
.Stride
), (BYTE
*)lockeddata
.Scan0
+lockeddata
.Stride
*i
);
3652 if (FAILED(hr
)) break;
3655 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3658 if (SUCCEEDED(hr
) && status
== Ok
)
3659 *image
= &bitmap
->image
;
3663 GdipDisposeImage(&bitmap
->image
);
3666 if (SUCCEEDED(hr
) && status
== Ok
)
3669 hr
= IWICBitmapSource_GetResolution(source
, &dpix
, &dpiy
);
3672 bitmap
->image
.xres
= dpix
;
3673 bitmap
->image
.yres
= dpiy
;
3679 IWICBitmapSource_Release(source
);
3682 if (SUCCEEDED(hr
)) {
3683 bitmap
->metadata_reader
= NULL
;
3685 if (metadata_reader
)
3686 metadata_reader(bitmap
, decoder
, active_frame
);
3687 else if (IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
) == S_OK
)
3689 UINT block_count
= 0;
3690 if (IWICMetadataBlockReader_GetCount(block_reader
, &block_count
) == S_OK
&& block_count
)
3691 IWICMetadataBlockReader_GetReaderByIndex(block_reader
, 0, &bitmap
->metadata_reader
);
3692 IWICMetadataBlockReader_Release(block_reader
);
3695 palette
= get_palette(frame
, palette_type
);
3696 IWICBitmapFrameDecode_Release(frame
);
3700 if (FAILED(hr
) && status
== Ok
) status
= hresult_to_status(hr
);
3704 /* Native GDI+ used to be smarter, but since Win7 it just sets these flags. */
3705 bitmap
->image
.flags
|= ImageFlagsReadOnly
|ImageFlagsHasRealPixelSize
|ImageFlagsHasRealDPI
;
3706 if (IsEqualGUID(&wic_format
, &GUID_WICPixelFormat2bppGray
) ||
3707 IsEqualGUID(&wic_format
, &GUID_WICPixelFormat4bppGray
) ||
3708 IsEqualGUID(&wic_format
, &GUID_WICPixelFormat8bppGray
) ||
3709 IsEqualGUID(&wic_format
, &GUID_WICPixelFormat16bppGray
))
3710 bitmap
->image
.flags
|= ImageFlagsColorSpaceGRAY
;
3712 bitmap
->image
.flags
|= ImageFlagsColorSpaceRGB
;
3713 bitmap
->image
.frame_count
= frame_count
;
3714 bitmap
->image
.current_frame
= active_frame
;
3715 bitmap
->image
.decoder
= decoder
;
3716 IWICBitmapDecoder_AddRef(decoder
);
3719 heap_free(bitmap
->image
.palette
);
3720 bitmap
->image
.palette
= palette
;
3724 if (IsEqualGUID(&wic_format
, &GUID_WICPixelFormatBlackWhite
))
3725 bitmap
->image
.palette
->Flags
= 0;
3727 TRACE("=> %p\n", *image
);
3733 static GpStatus
decode_image_wic(IStream
*stream
, REFGUID container
,
3734 metadata_reader_func metadata_reader
, GpImage
**image
)
3736 IWICBitmapDecoder
*decoder
;
3739 status
= initialize_decoder_wic(stream
, container
, &decoder
);
3743 status
= decode_frame_wic(decoder
, FALSE
, 0, metadata_reader
, image
);
3744 IWICBitmapDecoder_Release(decoder
);
3748 static GpStatus
select_frame_wic(GpImage
*image
, UINT active_frame
)
3753 status
= decode_frame_wic(image
->decoder
, FALSE
, active_frame
, NULL
, &new_image
);
3757 new_image
->busy
= image
->busy
;
3758 memcpy(&new_image
->format
, &image
->format
, sizeof(GUID
));
3759 free_image_data(image
);
3760 if (image
->type
== ImageTypeBitmap
)
3761 *(GpBitmap
*)image
= *(GpBitmap
*)new_image
;
3762 else if (image
->type
== ImageTypeMetafile
)
3763 *(GpMetafile
*)image
= *(GpMetafile
*)new_image
;
3764 new_image
->type
= ~0;
3765 heap_free(new_image
);
3769 static HRESULT
get_gif_frame_rect(IWICBitmapFrameDecode
*frame
,
3770 UINT
*left
, UINT
*top
, UINT
*width
, UINT
*height
)
3772 static const WCHAR leftW
[] = {'L','e','f','t',0};
3773 static const WCHAR topW
[] = {'T','o','p',0};
3775 *left
= get_gif_frame_property(frame
, &GUID_MetadataFormatIMD
, leftW
);
3776 *top
= get_gif_frame_property(frame
, &GUID_MetadataFormatIMD
, topW
);
3778 return IWICBitmapFrameDecode_GetSize(frame
, width
, height
);
3781 static HRESULT
blit_gif_frame(GpBitmap
*bitmap
, IWICBitmapFrameDecode
*frame
, BOOL first_frame
)
3783 UINT i
, j
, left
, top
, width
, height
;
3784 IWICBitmapSource
*source
;
3788 hr
= get_gif_frame_rect(frame
, &left
, &top
, &width
, &height
);
3792 hr
= WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA
, (IWICBitmapSource
*)frame
, &source
);
3796 new_bits
= heap_alloc_zero(width
*height
*4);
3798 return E_OUTOFMEMORY
;
3800 hr
= IWICBitmapSource_CopyPixels(source
, NULL
, width
*4, width
*height
*4, new_bits
);
3801 IWICBitmapSource_Release(source
);
3803 heap_free(new_bits
);
3807 for(i
=0; i
<height
&& i
+top
<bitmap
->height
; i
++) {
3808 for(j
=0; j
<width
&& j
+left
<bitmap
->width
; j
++) {
3809 DWORD
*src
= (DWORD
*)(new_bits
+i
*width
*4+j
*4);
3810 DWORD
*dst
= (DWORD
*)(bitmap
->bits
+(i
+top
)*bitmap
->stride
+(j
+left
)*4);
3812 if(first_frame
|| *src
>>24 != 0)
3816 heap_free(new_bits
);
3820 static DWORD
get_gif_background_color(GpBitmap
*bitmap
)
3822 BYTE bgcolor_idx
= 0;
3825 for(i
=0; i
<bitmap
->prop_count
; i
++) {
3826 if(bitmap
->prop_item
[i
].id
== PropertyTagIndexBackground
) {
3827 bgcolor_idx
= *(BYTE
*)bitmap
->prop_item
[i
].value
;
3832 for(i
=0; i
<bitmap
->prop_count
; i
++) {
3833 if(bitmap
->prop_item
[i
].id
== PropertyTagIndexTransparent
) {
3834 BYTE transparent_idx
;
3835 transparent_idx
= *(BYTE
*)bitmap
->prop_item
[i
].value
;
3837 if(transparent_idx
== bgcolor_idx
)
3842 for(i
=0; i
<bitmap
->prop_count
; i
++) {
3843 if(bitmap
->prop_item
[i
].id
== PropertyTagGlobalPalette
) {
3844 if(bitmap
->prop_item
[i
].length
/3 > bgcolor_idx
) {
3845 BYTE
*color
= ((BYTE
*)bitmap
->prop_item
[i
].value
)+bgcolor_idx
*3;
3846 return color
[2] + (color
[1]<<8) + (color
[0]<<16) + (0xffu
<<24);
3852 FIXME("can't get gif background color\n");
3856 static GpStatus
select_frame_gif(GpImage
* image
, UINT active_frame
)
3858 static const WCHAR disposalW
[] = {'D','i','s','p','o','s','a','l',0};
3860 GpBitmap
*bitmap
= (GpBitmap
*)image
;
3861 IWICBitmapFrameDecode
*frame
;
3862 int cur_frame
=0, disposal
;
3863 BOOL bgcolor_set
= FALSE
;
3867 if(active_frame
> image
->current_frame
) {
3868 hr
= IWICBitmapDecoder_GetFrame(bitmap
->image
.decoder
, image
->current_frame
, &frame
);
3870 return hresult_to_status(hr
);
3871 disposal
= get_gif_frame_property(frame
, &GUID_MetadataFormatGCE
, disposalW
);
3872 IWICBitmapFrameDecode_Release(frame
);
3874 if(disposal
== GIF_DISPOSE_RESTORE_TO_BKGND
)
3875 cur_frame
= image
->current_frame
;
3876 else if(disposal
!= GIF_DISPOSE_RESTORE_TO_PREV
)
3877 cur_frame
= image
->current_frame
+1;
3880 while(cur_frame
!= active_frame
) {
3881 hr
= IWICBitmapDecoder_GetFrame(bitmap
->image
.decoder
, cur_frame
, &frame
);
3883 return hresult_to_status(hr
);
3884 disposal
= get_gif_frame_property(frame
, &GUID_MetadataFormatGCE
, disposalW
);
3886 if(disposal
==GIF_DISPOSE_UNSPECIFIED
|| disposal
==GIF_DISPOSE_DO_NOT_DISPOSE
) {
3887 hr
= blit_gif_frame(bitmap
, frame
, cur_frame
==0);
3889 return hresult_to_status(hr
);
3890 }else if(disposal
== GIF_DISPOSE_RESTORE_TO_BKGND
) {
3891 UINT left
, top
, width
, height
, i
, j
;
3894 bgcolor
= get_gif_background_color(bitmap
);
3898 hr
= get_gif_frame_rect(frame
, &left
, &top
, &width
, &height
);
3900 return hresult_to_status(hr
);
3901 for(i
=top
; i
<top
+height
&& i
<bitmap
->height
; i
++) {
3902 DWORD
*bits
= (DWORD
*)(bitmap
->bits
+i
*bitmap
->stride
);
3903 for(j
=left
; j
<left
+width
&& j
<bitmap
->width
; j
++)
3908 IWICBitmapFrameDecode_Release(frame
);
3912 hr
= IWICBitmapDecoder_GetFrame(bitmap
->image
.decoder
, active_frame
, &frame
);
3914 return hresult_to_status(hr
);
3916 hr
= blit_gif_frame(bitmap
, frame
, cur_frame
==0);
3917 IWICBitmapFrameDecode_Release(frame
);
3919 return hresult_to_status(hr
);
3921 image
->current_frame
= active_frame
;
3925 static GpStatus
decode_image_icon(IStream
* stream
, GpImage
**image
)
3927 return decode_image_wic(stream
, &GUID_ContainerFormatIco
, NULL
, image
);
3930 static GpStatus
decode_image_bmp(IStream
* stream
, GpImage
**image
)
3935 status
= decode_image_wic(stream
, &GUID_ContainerFormatBmp
, NULL
, image
);
3937 bitmap
= (GpBitmap
*)*image
;
3939 if (status
== Ok
&& bitmap
->format
== PixelFormat32bppARGB
)
3941 /* WIC supports bmp files with alpha, but gdiplus does not */
3942 bitmap
->format
= PixelFormat32bppRGB
;
3948 static GpStatus
decode_image_jpeg(IStream
* stream
, GpImage
**image
)
3950 return decode_image_wic(stream
, &GUID_ContainerFormatJpeg
, NULL
, image
);
3953 static BOOL
has_png_transparency_chunk(IStream
*pIStream
)
3956 BOOL has_tRNS
= FALSE
;
3963 ULARGE_INTEGER chunk_start
;
3964 ULONG bytesread
, chunk_size
;
3966 hr
= IStream_Seek(pIStream
, seek
, STREAM_SEEK_SET
, &chunk_start
);
3967 if (FAILED(hr
)) break;
3969 hr
= IStream_Read(pIStream
, header
, 8, &bytesread
);
3970 if (FAILED(hr
) || bytesread
< 8) break;
3972 chunk_size
= (header
[0] << 24) | (header
[1] << 16) | (header
[2] << 8) | header
[3];
3973 if (!memcmp(&header
[4], "tRNS", 4))
3979 seek
.QuadPart
= chunk_start
.QuadPart
+ chunk_size
+ 12; /* skip data and CRC */
3980 } while (memcmp(&header
[4], "IDAT", 4) && memcmp(&header
[4], "IEND", 4));
3982 TRACE("has_tRNS = %d\n", has_tRNS
);
3986 static GpStatus
decode_image_png(IStream
* stream
, GpImage
**image
)
3988 IWICBitmapDecoder
*decoder
;
3989 IWICBitmapFrameDecode
*frame
;
3993 BOOL force_conversion
= FALSE
;
3995 status
= initialize_decoder_wic(stream
, &GUID_ContainerFormatPng
, &decoder
);
3999 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
4002 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
4005 if (IsEqualGUID(&format
, &GUID_WICPixelFormat8bppGray
))
4006 force_conversion
= TRUE
;
4007 else if ((IsEqualGUID(&format
, &GUID_WICPixelFormat8bppIndexed
) ||
4008 IsEqualGUID(&format
, &GUID_WICPixelFormat4bppIndexed
) ||
4009 IsEqualGUID(&format
, &GUID_WICPixelFormat2bppIndexed
) ||
4010 IsEqualGUID(&format
, &GUID_WICPixelFormat1bppIndexed
) ||
4011 IsEqualGUID(&format
, &GUID_WICPixelFormat24bppBGR
)) &&
4012 has_png_transparency_chunk(stream
))
4013 force_conversion
= TRUE
;
4015 status
= decode_frame_wic(decoder
, force_conversion
, 0, png_metadata_reader
, image
);
4018 status
= hresult_to_status(hr
);
4020 IWICBitmapFrameDecode_Release(frame
);
4023 status
= hresult_to_status(hr
);
4025 IWICBitmapDecoder_Release(decoder
);
4029 static GpStatus
decode_image_gif(IStream
* stream
, GpImage
**image
)
4031 IWICBitmapDecoder
*decoder
;
4036 status
= initialize_decoder_wic(stream
, &GUID_ContainerFormatGif
, &decoder
);
4040 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
4042 return hresult_to_status(hr
);
4044 status
= decode_frame_wic(decoder
, frame_count
> 1, 0, gif_metadata_reader
, image
);
4045 IWICBitmapDecoder_Release(decoder
);
4049 if(frame_count
> 1) {
4050 heap_free((*image
)->palette
);
4051 (*image
)->palette
= NULL
;
4056 static GpStatus
decode_image_tiff(IStream
* stream
, GpImage
**image
)
4058 return decode_image_wic(stream
, &GUID_ContainerFormatTiff
, NULL
, image
);
4061 static GpStatus
load_wmf(IStream
*stream
, GpMetafile
**metafile
)
4063 WmfPlaceableFileHeader pfh
;
4064 BOOL is_placeable
= FALSE
;
4073 hr
= IStream_Read(stream
, &mh
, sizeof(mh
), &size
);
4074 if (hr
!= S_OK
|| size
!= sizeof(mh
))
4075 return GenericError
;
4077 if (((WmfPlaceableFileHeader
*)&mh
)->Key
== WMF_PLACEABLE_KEY
)
4080 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4081 if (FAILED(hr
)) return hresult_to_status(hr
);
4083 hr
= IStream_Read(stream
, &pfh
, sizeof(pfh
), &size
);
4084 if (hr
!= S_OK
|| size
!= sizeof(pfh
))
4085 return GenericError
;
4087 hr
= IStream_Read(stream
, &mh
, sizeof(mh
), &size
);
4088 if (hr
!= S_OK
|| size
!= sizeof(mh
))
4089 return GenericError
;
4091 is_placeable
= TRUE
;
4094 seek
.QuadPart
= is_placeable
? sizeof(pfh
) : 0;
4095 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4096 if (FAILED(hr
)) return hresult_to_status(hr
);
4098 buf
= heap_alloc(mh
.mtSize
* 2);
4099 if (!buf
) return OutOfMemory
;
4101 hr
= IStream_Read(stream
, buf
, mh
.mtSize
* 2, &size
);
4102 if (hr
!= S_OK
|| size
!= mh
.mtSize
* 2)
4105 return GenericError
;
4108 hmf
= SetMetaFileBitsEx(mh
.mtSize
* 2, buf
);
4111 return GenericError
;
4113 status
= GdipCreateMetafileFromWmf(hmf
, TRUE
, is_placeable
? &pfh
: NULL
, metafile
);
4115 DeleteMetaFile(hmf
);
4119 static GpStatus
decode_image_wmf(IStream
*stream
, GpImage
**image
)
4121 GpMetafile
*metafile
;
4124 TRACE("%p %p\n", stream
, image
);
4126 if (!stream
|| !image
)
4127 return InvalidParameter
;
4129 status
= load_wmf(stream
, &metafile
);
4132 TRACE("Could not load metafile\n");
4136 *image
= (GpImage
*)metafile
;
4137 TRACE("<-- %p\n", *image
);
4142 static GpStatus
load_emf(IStream
*stream
, GpMetafile
**metafile
)
4152 hr
= IStream_Read(stream
, &emh
, sizeof(emh
), &size
);
4153 if (hr
!= S_OK
|| size
!= sizeof(emh
) || emh
.dSignature
!= ENHMETA_SIGNATURE
)
4154 return GenericError
;
4157 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4158 if (FAILED(hr
)) return hresult_to_status(hr
);
4160 buf
= heap_alloc(emh
.nBytes
);
4161 if (!buf
) return OutOfMemory
;
4163 hr
= IStream_Read(stream
, buf
, emh
.nBytes
, &size
);
4164 if (hr
!= S_OK
|| size
!= emh
.nBytes
)
4167 return GenericError
;
4170 hemf
= SetEnhMetaFileBits(emh
.nBytes
, buf
);
4173 return GenericError
;
4175 status
= GdipCreateMetafileFromEmf(hemf
, TRUE
, metafile
);
4177 DeleteEnhMetaFile(hemf
);
4181 static GpStatus
decode_image_emf(IStream
*stream
, GpImage
**image
)
4183 GpMetafile
*metafile
;
4186 TRACE("%p %p\n", stream
, image
);
4188 if (!stream
|| !image
)
4189 return InvalidParameter
;
4191 status
= load_emf(stream
, &metafile
);
4194 TRACE("Could not load metafile\n");
4198 *image
= (GpImage
*)metafile
;
4199 TRACE("<-- %p\n", *image
);
4204 typedef GpStatus (*encode_image_func
)(GpImage
*image
, IStream
* stream
,
4205 GDIPCONST EncoderParameters
* params
);
4207 typedef GpStatus (*decode_image_func
)(IStream
*stream
, GpImage
**image
);
4209 typedef GpStatus (*select_image_func
)(GpImage
*image
, UINT active_frame
);
4211 typedef struct image_codec
{
4212 ImageCodecInfo info
;
4213 encode_image_func encode_func
;
4214 decode_image_func decode_func
;
4215 select_image_func select_func
;
4230 static const struct image_codec codecs
[NUM_CODECS
];
4232 static GpStatus
get_decoder_info(IStream
* stream
, const struct image_codec
**result
)
4235 const BYTE
*pattern
, *mask
;
4242 /* seek to the start of the stream */
4244 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4245 if (FAILED(hr
)) return hresult_to_status(hr
);
4247 /* read the first 8 bytes */
4248 /* FIXME: This assumes all codecs have signatures <= 8 bytes in length */
4249 hr
= IStream_Read(stream
, signature
, 8, &bytesread
);
4250 if (FAILED(hr
)) return hresult_to_status(hr
);
4251 if (hr
== S_FALSE
|| bytesread
== 0) return GenericError
;
4253 for (i
= 0; i
< NUM_CODECS
; i
++) {
4254 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
) &&
4255 bytesread
>= codecs
[i
].info
.SigSize
)
4257 for (sig
=0; sig
<codecs
[i
].info
.SigCount
; sig
++)
4259 pattern
= &codecs
[i
].info
.SigPattern
[codecs
[i
].info
.SigSize
*sig
];
4260 mask
= &codecs
[i
].info
.SigMask
[codecs
[i
].info
.SigSize
*sig
];
4261 for (j
=0; j
<codecs
[i
].info
.SigSize
; j
++)
4262 if ((signature
[j
] & mask
[j
]) != pattern
[j
])
4264 if (j
== codecs
[i
].info
.SigSize
)
4266 *result
= &codecs
[i
];
4273 TRACE("no match for %i byte signature %x %x %x %x %x %x %x %x\n", bytesread
,
4274 signature
[0],signature
[1],signature
[2],signature
[3],
4275 signature
[4],signature
[5],signature
[6],signature
[7]);
4277 return GenericError
;
4280 static GpStatus
get_decoder_info_from_image(GpImage
*image
, const struct image_codec
**result
)
4284 for (i
= 0; i
< NUM_CODECS
; i
++) {
4285 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
) &&
4286 IsEqualIID(&codecs
[i
].info
.FormatID
, &image
->format
))
4288 *result
= &codecs
[i
];
4293 TRACE("no match for format: %s\n", wine_dbgstr_guid(&image
->format
));
4294 return GenericError
;
4297 GpStatus WINGDIPAPI
GdipImageSelectActiveFrame(GpImage
*image
, GDIPCONST GUID
*dimensionID
,
4301 const struct image_codec
*codec
= NULL
;
4304 TRACE("(%p,%s,%u)\n", image
, debugstr_guid(dimensionID
), frame
);
4306 if (!image
|| !dimensionID
)
4307 return InvalidParameter
;
4308 if(!image_lock(image
, &unlock
))
4311 if (frame
>= image
->frame_count
)
4313 WARN("requested frame %u, but image has only %u\n", frame
, image
->frame_count
);
4314 image_unlock(image
, unlock
);
4315 return InvalidParameter
;
4318 if (image
->type
!= ImageTypeBitmap
&& image
->type
!= ImageTypeMetafile
)
4320 WARN("invalid image type %d\n", image
->type
);
4321 image_unlock(image
, unlock
);
4322 return InvalidParameter
;
4325 if (image
->current_frame
== frame
)
4327 image_unlock(image
, unlock
);
4331 if (!image
->decoder
)
4333 TRACE("image doesn't have an associated decoder\n");
4334 image_unlock(image
, unlock
);
4338 /* choose an appropriate image decoder */
4339 stat
= get_decoder_info_from_image(image
, &codec
);
4342 WARN("can't find decoder info\n");
4343 image_unlock(image
, unlock
);
4347 stat
= codec
->select_func(image
, frame
);
4348 image_unlock(image
, unlock
);
4352 GpStatus WINGDIPAPI
GdipLoadImageFromStream(IStream
*stream
, GpImage
**image
)
4357 const struct image_codec
*codec
=NULL
;
4359 TRACE("%p %p\n", stream
, image
);
4361 if (!stream
|| !image
)
4362 return InvalidParameter
;
4364 /* choose an appropriate image decoder */
4365 stat
= get_decoder_info(stream
, &codec
);
4366 if (stat
!= Ok
) return stat
;
4368 /* seek to the start of the stream */
4370 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
4371 if (FAILED(hr
)) return hresult_to_status(hr
);
4373 /* call on the image decoder to do the real work */
4374 stat
= codec
->decode_func(stream
, image
);
4376 /* take note of the original data format */
4379 memcpy(&(*image
)->format
, &codec
->info
.FormatID
, sizeof(GUID
));
4387 GpStatus WINGDIPAPI
GdipLoadImageFromStreamICM(IStream
* stream
, GpImage
**image
)
4389 TRACE("%p %p\n", stream
, image
);
4391 return GdipLoadImageFromStream(stream
, image
);
4394 GpStatus WINGDIPAPI
GdipRemovePropertyItem(GpImage
*image
, PROPID propId
)
4398 TRACE("(%p,%u)\n", image
, propId
);
4401 return InvalidParameter
;
4404 FIXME("not implemented\n");
4406 return NotImplemented
;
4409 GpStatus WINGDIPAPI
GdipSetPropertyItem(GpImage
*image
, GDIPCONST PropertyItem
* item
)
4413 if (!image
|| !item
) return InvalidParameter
;
4415 TRACE("(%p,%p:%#x,%u,%u,%p)\n", image
, item
, item
->id
, item
->type
, item
->length
, item
->value
);
4418 FIXME("not implemented\n");
4423 GpStatus WINGDIPAPI
GdipSaveImageToFile(GpImage
*image
, GDIPCONST WCHAR
* filename
,
4424 GDIPCONST CLSID
*clsidEncoder
,
4425 GDIPCONST EncoderParameters
*encoderParams
)
4430 TRACE("%p (%s) %p %p\n", image
, debugstr_w(filename
), clsidEncoder
, encoderParams
);
4432 if (!image
|| !filename
|| !clsidEncoder
)
4433 return InvalidParameter
;
4435 stat
= GdipCreateStreamOnFile(filename
, GENERIC_WRITE
, &stream
);
4437 return GenericError
;
4439 stat
= GdipSaveImageToStream(image
, stream
, clsidEncoder
, encoderParams
);
4441 IStream_Release(stream
);
4445 /*************************************************************************
4446 * Encoding functions -
4447 * These functions encode an image in different image file formats.
4450 static GpStatus
encode_image_wic(GpImage
*image
, IStream
* stream
,
4451 REFGUID container
, GDIPCONST EncoderParameters
* params
)
4455 IWICImagingFactory
*factory
;
4456 IWICBitmapEncoder
*encoder
;
4457 IWICBitmapFrameEncode
*frameencode
;
4458 IPropertyBag2
*encoderoptions
;
4461 PixelFormat gdipformat
=0;
4462 const WICPixelFormatGUID
*desired_wicformat
;
4463 WICPixelFormatGUID wicformat
;
4465 BitmapData lockeddata
;
4468 if (image
->type
!= ImageTypeBitmap
)
4469 return GenericError
;
4471 bitmap
= (GpBitmap
*)image
;
4473 GdipGetImageWidth(image
, &width
);
4474 GdipGetImageHeight(image
, &height
);
4481 hr
= WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION
, &factory
);
4483 return hresult_to_status(hr
);
4484 hr
= IWICImagingFactory_CreateEncoder(factory
, container
, NULL
, &encoder
);
4485 IWICImagingFactory_Release(factory
);
4487 return hresult_to_status(hr
);
4489 hr
= IWICBitmapEncoder_Initialize(encoder
, stream
, WICBitmapEncoderNoCache
);
4493 hr
= IWICBitmapEncoder_CreateNewFrame(encoder
, &frameencode
, &encoderoptions
);
4496 if (SUCCEEDED(hr
)) /* created frame */
4498 hr
= IWICBitmapFrameEncode_Initialize(frameencode
, encoderoptions
);
4501 hr
= IWICBitmapFrameEncode_SetSize(frameencode
, width
, height
);
4504 hr
= IWICBitmapFrameEncode_SetResolution(frameencode
, image
->xres
, image
->yres
);
4508 for (i
=0; pixel_formats
[i
].wic_format
; i
++)
4510 if (pixel_formats
[i
].gdip_format
== bitmap
->format
)
4512 desired_wicformat
= pixel_formats
[i
].wic_format
;
4513 gdipformat
= bitmap
->format
;
4519 desired_wicformat
= &GUID_WICPixelFormat32bppBGRA
;
4520 gdipformat
= PixelFormat32bppARGB
;
4523 memcpy(&wicformat
, desired_wicformat
, sizeof(GUID
));
4524 hr
= IWICBitmapFrameEncode_SetPixelFormat(frameencode
, &wicformat
);
4527 if (SUCCEEDED(hr
) && !IsEqualGUID(desired_wicformat
, &wicformat
))
4529 /* Encoder doesn't support this bitmap's format. */
4531 for (i
=0; pixel_formats
[i
].wic_format
; i
++)
4533 if (IsEqualGUID(&wicformat
, pixel_formats
[i
].wic_format
))
4535 gdipformat
= pixel_formats
[i
].gdip_format
;
4541 ERR("Cannot support encoder format %s\n", debugstr_guid(&wicformat
));
4548 stat
= GdipBitmapLockBits(bitmap
, &rc
, ImageLockModeRead
, gdipformat
,
4553 UINT row_size
= (lockeddata
.Width
* PIXELFORMATBPP(gdipformat
) + 7)/8;
4556 /* write one row at a time in case stride is negative */
4557 row
= lockeddata
.Scan0
;
4558 for (i
=0; i
<lockeddata
.Height
; i
++)
4560 hr
= IWICBitmapFrameEncode_WritePixels(frameencode
, 1, row_size
, row_size
, row
);
4561 if (FAILED(hr
)) break;
4562 row
+= lockeddata
.Stride
;
4565 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
4572 hr
= IWICBitmapFrameEncode_Commit(frameencode
);
4574 IWICBitmapFrameEncode_Release(frameencode
);
4575 IPropertyBag2_Release(encoderoptions
);
4579 hr
= IWICBitmapEncoder_Commit(encoder
);
4581 IWICBitmapEncoder_Release(encoder
);
4582 return hresult_to_status(hr
);
4585 static GpStatus
encode_image_BMP(GpImage
*image
, IStream
* stream
,
4586 GDIPCONST EncoderParameters
* params
)
4588 return encode_image_wic(image
, stream
, &GUID_ContainerFormatBmp
, params
);
4591 static GpStatus
encode_image_tiff(GpImage
*image
, IStream
* stream
,
4592 GDIPCONST EncoderParameters
* params
)
4594 return encode_image_wic(image
, stream
, &GUID_ContainerFormatTiff
, params
);
4597 GpStatus
encode_image_png(GpImage
*image
, IStream
* stream
,
4598 GDIPCONST EncoderParameters
* params
)
4600 return encode_image_wic(image
, stream
, &GUID_ContainerFormatPng
, params
);
4603 static GpStatus
encode_image_jpeg(GpImage
*image
, IStream
* stream
,
4604 GDIPCONST EncoderParameters
* params
)
4606 return encode_image_wic(image
, stream
, &GUID_ContainerFormatJpeg
, params
);
4609 static GpStatus
encode_image_gif(GpImage
*image
, IStream
* stream
,
4610 GDIPCONST EncoderParameters
* params
)
4612 return encode_image_wic(image
, stream
, &GUID_ContainerFormatGif
, params
);
4615 /*****************************************************************************
4616 * GdipSaveImageToStream [GDIPLUS.@]
4618 GpStatus WINGDIPAPI
GdipSaveImageToStream(GpImage
*image
, IStream
* stream
,
4619 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4622 encode_image_func encode_image
;
4625 TRACE("%p, %p, %s, %p\n", image
, stream
, wine_dbgstr_guid(clsid
), params
);
4627 if(!image
|| !stream
)
4628 return InvalidParameter
;
4630 /* select correct encoder */
4631 encode_image
= NULL
;
4632 for (i
= 0; i
< NUM_CODECS
; i
++) {
4633 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
) &&
4634 IsEqualCLSID(clsid
, &codecs
[i
].info
.Clsid
))
4635 encode_image
= codecs
[i
].encode_func
;
4637 if (encode_image
== NULL
)
4638 return UnknownImageFormat
;
4640 stat
= encode_image(image
, stream
, params
);
4645 /*****************************************************************************
4646 * GdipSaveAdd [GDIPLUS.@]
4648 GpStatus WINGDIPAPI
GdipSaveAdd(GpImage
*image
, GDIPCONST EncoderParameters
*params
)
4650 FIXME("(%p,%p): stub\n", image
, params
);
4654 /*****************************************************************************
4655 * GdipGetImagePalette [GDIPLUS.@]
4657 GpStatus WINGDIPAPI
GdipGetImagePalette(GpImage
*image
, ColorPalette
*palette
, INT size
)
4661 TRACE("(%p,%p,%i)\n", image
, palette
, size
);
4663 if (!image
|| !palette
)
4664 return InvalidParameter
;
4666 count
= image
->palette
? image
->palette
->Count
: 0;
4668 if (size
< (sizeof(UINT
)*2+sizeof(ARGB
)*count
))
4670 TRACE("<-- InsufficientBuffer\n");
4671 return InsufficientBuffer
;
4676 palette
->Flags
= image
->palette
->Flags
;
4677 palette
->Count
= image
->palette
->Count
;
4678 memcpy(palette
->Entries
, image
->palette
->Entries
, sizeof(ARGB
)*image
->palette
->Count
);
4688 /*****************************************************************************
4689 * GdipSetImagePalette [GDIPLUS.@]
4691 GpStatus WINGDIPAPI
GdipSetImagePalette(GpImage
*image
,
4692 GDIPCONST ColorPalette
*palette
)
4694 ColorPalette
*new_palette
;
4696 TRACE("(%p,%p)\n", image
, palette
);
4698 if(!image
|| !palette
|| palette
->Count
> 256)
4699 return InvalidParameter
;
4701 new_palette
= heap_alloc_zero(2 * sizeof(UINT
) + palette
->Count
* sizeof(ARGB
));
4702 if (!new_palette
) return OutOfMemory
;
4704 heap_free(image
->palette
);
4705 image
->palette
= new_palette
;
4706 image
->palette
->Flags
= palette
->Flags
;
4707 image
->palette
->Count
= palette
->Count
;
4708 memcpy(image
->palette
->Entries
, palette
->Entries
, sizeof(ARGB
)*palette
->Count
);
4713 /*************************************************************************
4715 * Structures that represent which formats we support for encoding.
4718 /* ImageCodecInfo creation routines taken from libgdiplus */
4719 static const WCHAR bmp_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
4720 static const WCHAR bmp_extension
[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
4721 static const WCHAR bmp_mimetype
[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
4722 static const WCHAR bmp_format
[] = {'B', 'M', 'P', 0}; /* BMP */
4723 static const BYTE bmp_sig_pattern
[] = { 0x42, 0x4D };
4724 static const BYTE bmp_sig_mask
[] = { 0xFF, 0xFF };
4726 static const WCHAR jpeg_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'J','P','E','G', 0};
4727 static const WCHAR jpeg_extension
[] = {'*','.','J','P','G',';', '*','.','J','P','E','G',';', '*','.','J','P','E',';', '*','.','J','F','I','F',0};
4728 static const WCHAR jpeg_mimetype
[] = {'i','m','a','g','e','/','j','p','e','g', 0};
4729 static const WCHAR jpeg_format
[] = {'J','P','E','G',0};
4730 static const BYTE jpeg_sig_pattern
[] = { 0xFF, 0xD8 };
4731 static const BYTE jpeg_sig_mask
[] = { 0xFF, 0xFF };
4733 static const WCHAR gif_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'G','I','F', 0};
4734 static const WCHAR gif_extension
[] = {'*','.','G','I','F',0};
4735 static const WCHAR gif_mimetype
[] = {'i','m','a','g','e','/','g','i','f', 0};
4736 static const WCHAR gif_format
[] = {'G','I','F',0};
4737 static const BYTE gif_sig_pattern
[12] = "GIF87aGIF89a";
4738 static const BYTE gif_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4740 static const WCHAR tiff_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'T','I','F','F', 0};
4741 static const WCHAR tiff_extension
[] = {'*','.','T','I','F','F',';','*','.','T','I','F',0};
4742 static const WCHAR tiff_mimetype
[] = {'i','m','a','g','e','/','t','i','f','f', 0};
4743 static const WCHAR tiff_format
[] = {'T','I','F','F',0};
4744 static const BYTE tiff_sig_pattern
[] = {0x49,0x49,42,0,0x4d,0x4d,0,42};
4745 static const BYTE tiff_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4747 static const WCHAR emf_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'E','M','F', 0};
4748 static const WCHAR emf_extension
[] = {'*','.','E','M','F',0};
4749 static const WCHAR emf_mimetype
[] = {'i','m','a','g','e','/','x','-','e','m','f', 0};
4750 static const WCHAR emf_format
[] = {'E','M','F',0};
4751 static const BYTE emf_sig_pattern
[] = { 0x01, 0x00, 0x00, 0x00 };
4752 static const BYTE emf_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
4754 static const WCHAR wmf_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'W','M','F', 0};
4755 static const WCHAR wmf_extension
[] = {'*','.','W','M','F',0};
4756 static const WCHAR wmf_mimetype
[] = {'i','m','a','g','e','/','x','-','w','m','f', 0};
4757 static const WCHAR wmf_format
[] = {'W','M','F',0};
4758 static const BYTE wmf_sig_pattern
[] = { 0xd7, 0xcd };
4759 static const BYTE wmf_sig_mask
[] = { 0xFF, 0xFF };
4761 static const WCHAR png_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'P','N','G', 0};
4762 static const WCHAR png_extension
[] = {'*','.','P','N','G',0};
4763 static const WCHAR png_mimetype
[] = {'i','m','a','g','e','/','p','n','g', 0};
4764 static const WCHAR png_format
[] = {'P','N','G',0};
4765 static const BYTE png_sig_pattern
[] = { 137, 80, 78, 71, 13, 10, 26, 10, };
4766 static const BYTE png_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4768 static const WCHAR ico_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'I','C','O', 0};
4769 static const WCHAR ico_extension
[] = {'*','.','I','C','O',0};
4770 static const WCHAR ico_mimetype
[] = {'i','m','a','g','e','/','x','-','i','c','o','n', 0};
4771 static const WCHAR ico_format
[] = {'I','C','O',0};
4772 static const BYTE ico_sig_pattern
[] = { 0x00, 0x00, 0x01, 0x00 };
4773 static const BYTE ico_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
4775 static const struct image_codec codecs
[NUM_CODECS
] = {
4778 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4779 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4780 /* CodecName */ bmp_codecname
,
4782 /* FormatDescription */ bmp_format
,
4783 /* FilenameExtension */ bmp_extension
,
4784 /* MimeType */ bmp_mimetype
,
4785 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4789 /* SigPattern */ bmp_sig_pattern
,
4790 /* SigMask */ bmp_sig_mask
,
4798 /* Clsid */ { 0x557cf401, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4799 /* FormatID */ { 0xb96b3caeU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4800 /* CodecName */ jpeg_codecname
,
4802 /* FormatDescription */ jpeg_format
,
4803 /* FilenameExtension */ jpeg_extension
,
4804 /* MimeType */ jpeg_mimetype
,
4805 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4809 /* SigPattern */ jpeg_sig_pattern
,
4810 /* SigMask */ jpeg_sig_mask
,
4818 /* Clsid */ { 0x557cf402, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4819 /* FormatID */ { 0xb96b3cb0U
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4820 /* CodecName */ gif_codecname
,
4822 /* FormatDescription */ gif_format
,
4823 /* FilenameExtension */ gif_extension
,
4824 /* MimeType */ gif_mimetype
,
4825 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsEncoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4829 /* SigPattern */ gif_sig_pattern
,
4830 /* SigMask */ gif_sig_mask
,
4838 /* Clsid */ { 0x557cf405, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4839 /* FormatID */ { 0xb96b3cb1U
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4840 /* CodecName */ tiff_codecname
,
4842 /* FormatDescription */ tiff_format
,
4843 /* FilenameExtension */ tiff_extension
,
4844 /* MimeType */ tiff_mimetype
,
4845 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsEncoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4849 /* SigPattern */ tiff_sig_pattern
,
4850 /* SigMask */ tiff_sig_mask
,
4858 /* Clsid */ { 0x557cf403, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4859 /* FormatID */ { 0xb96b3cacU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4860 /* CodecName */ emf_codecname
,
4862 /* FormatDescription */ emf_format
,
4863 /* FilenameExtension */ emf_extension
,
4864 /* MimeType */ emf_mimetype
,
4865 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
4869 /* SigPattern */ emf_sig_pattern
,
4870 /* SigMask */ emf_sig_mask
,
4878 /* Clsid */ { 0x557cf404, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4879 /* FormatID */ { 0xb96b3cadU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4880 /* CodecName */ wmf_codecname
,
4882 /* FormatDescription */ wmf_format
,
4883 /* FilenameExtension */ wmf_extension
,
4884 /* MimeType */ wmf_mimetype
,
4885 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
4889 /* SigPattern */ wmf_sig_pattern
,
4890 /* SigMask */ wmf_sig_mask
,
4898 /* Clsid */ { 0x557cf406, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4899 /* FormatID */ { 0xb96b3cafU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4900 /* CodecName */ png_codecname
,
4902 /* FormatDescription */ png_format
,
4903 /* FilenameExtension */ png_extension
,
4904 /* MimeType */ png_mimetype
,
4905 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4909 /* SigPattern */ png_sig_pattern
,
4910 /* SigMask */ png_sig_mask
,
4918 /* Clsid */ { 0x557cf407, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4919 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4920 /* CodecName */ ico_codecname
,
4922 /* FormatDescription */ ico_format
,
4923 /* FilenameExtension */ ico_extension
,
4924 /* MimeType */ ico_mimetype
,
4925 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4929 /* SigPattern */ ico_sig_pattern
,
4930 /* SigMask */ ico_sig_mask
,
4938 /*****************************************************************************
4939 * GdipGetImageDecodersSize [GDIPLUS.@]
4941 GpStatus WINGDIPAPI
GdipGetImageDecodersSize(UINT
*numDecoders
, UINT
*size
)
4943 int decoder_count
=0;
4945 TRACE("%p %p\n", numDecoders
, size
);
4947 if (!numDecoders
|| !size
)
4948 return InvalidParameter
;
4950 for (i
=0; i
<NUM_CODECS
; i
++)
4952 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
4956 *numDecoders
= decoder_count
;
4957 *size
= decoder_count
* sizeof(ImageCodecInfo
);
4962 /*****************************************************************************
4963 * GdipGetImageDecoders [GDIPLUS.@]
4965 GpStatus WINGDIPAPI
GdipGetImageDecoders(UINT numDecoders
, UINT size
, ImageCodecInfo
*decoders
)
4967 int i
, decoder_count
=0;
4968 TRACE("%u %u %p\n", numDecoders
, size
, decoders
);
4971 size
!= numDecoders
* sizeof(ImageCodecInfo
))
4972 return GenericError
;
4974 for (i
=0; i
<NUM_CODECS
; i
++)
4976 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
4978 if (decoder_count
== numDecoders
) return GenericError
;
4979 memcpy(&decoders
[decoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
4984 if (decoder_count
< numDecoders
) return GenericError
;
4989 /*****************************************************************************
4990 * GdipGetImageEncodersSize [GDIPLUS.@]
4992 GpStatus WINGDIPAPI
GdipGetImageEncodersSize(UINT
*numEncoders
, UINT
*size
)
4994 int encoder_count
=0;
4996 TRACE("%p %p\n", numEncoders
, size
);
4998 if (!numEncoders
|| !size
)
4999 return InvalidParameter
;
5001 for (i
=0; i
<NUM_CODECS
; i
++)
5003 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
5007 *numEncoders
= encoder_count
;
5008 *size
= encoder_count
* sizeof(ImageCodecInfo
);
5013 /*****************************************************************************
5014 * GdipGetImageEncoders [GDIPLUS.@]
5016 GpStatus WINGDIPAPI
GdipGetImageEncoders(UINT numEncoders
, UINT size
, ImageCodecInfo
*encoders
)
5018 int i
, encoder_count
=0;
5019 TRACE("%u %u %p\n", numEncoders
, size
, encoders
);
5022 size
!= numEncoders
* sizeof(ImageCodecInfo
))
5023 return GenericError
;
5025 for (i
=0; i
<NUM_CODECS
; i
++)
5027 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
5029 if (encoder_count
== numEncoders
) return GenericError
;
5030 memcpy(&encoders
[encoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
5035 if (encoder_count
< numEncoders
) return GenericError
;
5040 GpStatus WINGDIPAPI
GdipGetEncoderParameterListSize(GpImage
*image
,
5041 GDIPCONST CLSID
* clsidEncoder
, UINT
*size
)
5045 TRACE("(%p,%s,%p)\n", image
, debugstr_guid(clsidEncoder
), size
);
5048 FIXME("not implemented\n");
5052 return NotImplemented
;
5055 static PixelFormat
get_16bpp_format(HBITMAP hbm
)
5061 hdc
= CreateCompatibleDC(NULL
);
5063 memset(&bmh
, 0, sizeof(bmh
));
5064 bmh
.bV4Size
= sizeof(bmh
);
5067 bmh
.bV4V4Compression
= BI_BITFIELDS
;
5068 bmh
.bV4BitCount
= 16;
5070 GetDIBits(hdc
, hbm
, 0, 0, NULL
, (BITMAPINFO
*)&bmh
, DIB_RGB_COLORS
);
5072 if (bmh
.bV4RedMask
== 0x7c00 &&
5073 bmh
.bV4GreenMask
== 0x3e0 &&
5074 bmh
.bV4BlueMask
== 0x1f)
5076 result
= PixelFormat16bppRGB555
;
5078 else if (bmh
.bV4RedMask
== 0xf800 &&
5079 bmh
.bV4GreenMask
== 0x7e0 &&
5080 bmh
.bV4BlueMask
== 0x1f)
5082 result
= PixelFormat16bppRGB565
;
5086 FIXME("unrecognized bitfields %x,%x,%x\n", bmh
.bV4RedMask
,
5087 bmh
.bV4GreenMask
, bmh
.bV4BlueMask
);
5088 result
= PixelFormatUndefined
;
5096 /*****************************************************************************
5097 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
5099 GpStatus WINGDIPAPI
GdipCreateBitmapFromHBITMAP(HBITMAP hbm
, HPALETTE hpal
, GpBitmap
** bitmap
)
5104 BitmapData lockeddata
;
5106 TRACE("%p %p %p\n", hbm
, hpal
, bitmap
);
5109 return InvalidParameter
;
5111 if (GetObjectA(hbm
, sizeof(bm
), &bm
) != sizeof(bm
))
5112 return InvalidParameter
;
5114 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
5115 switch(bm
.bmBitsPixel
) {
5117 format
= PixelFormat1bppIndexed
;
5120 format
= PixelFormat4bppIndexed
;
5123 format
= PixelFormat8bppIndexed
;
5126 format
= get_16bpp_format(hbm
);
5127 if (format
== PixelFormatUndefined
)
5128 return InvalidParameter
;
5131 format
= PixelFormat24bppRGB
;
5134 format
= PixelFormat32bppRGB
;
5137 format
= PixelFormat48bppRGB
;
5140 FIXME("don't know how to handle %d bpp\n", bm
.bmBitsPixel
);
5141 return InvalidParameter
;
5144 retval
= GdipCreateBitmapFromScan0(bm
.bmWidth
, bm
.bmHeight
, 0,
5145 format
, NULL
, bitmap
);
5149 retval
= GdipBitmapLockBits(*bitmap
, NULL
, ImageLockModeWrite
,
5150 format
, &lockeddata
);
5154 char bmibuf
[FIELD_OFFSET(BITMAPINFO
, bmiColors
[256])];
5155 BITMAPINFO
*pbmi
= (BITMAPINFO
*)bmibuf
;
5158 hdc
= CreateCompatibleDC(NULL
);
5160 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
5161 pbmi
->bmiHeader
.biBitCount
= 0;
5163 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
5165 src_height
= abs(pbmi
->bmiHeader
.biHeight
);
5166 pbmi
->bmiHeader
.biHeight
= -src_height
;
5168 GetDIBits(hdc
, hbm
, 0, src_height
, lockeddata
.Scan0
, pbmi
, DIB_RGB_COLORS
);
5172 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
5175 if (retval
== Ok
&& hpal
)
5177 PALETTEENTRY entry
[256];
5178 ColorPalette
*palette
=NULL
;
5179 int i
, num_palette_entries
;
5181 num_palette_entries
= GetPaletteEntries(hpal
, 0, 256, entry
);
5182 if (!num_palette_entries
)
5183 retval
= GenericError
;
5185 palette
= heap_alloc_zero(sizeof(ColorPalette
) + sizeof(ARGB
) * (num_palette_entries
-1));
5187 retval
= OutOfMemory
;
5192 palette
->Count
= num_palette_entries
;
5194 for (i
=0; i
<num_palette_entries
; i
++)
5196 palette
->Entries
[i
] = 0xff000000 | entry
[i
].peRed
<< 16 |
5197 entry
[i
].peGreen
<< 8 | entry
[i
].peBlue
;
5200 retval
= GdipSetImagePalette(&(*bitmap
)->image
, palette
);
5208 GdipDisposeImage(&(*bitmap
)->image
);
5216 /*****************************************************************************
5217 * GdipCreateEffect [GDIPLUS.@]
5219 GpStatus WINGDIPAPI
GdipCreateEffect(const GUID guid
, CGpEffect
**effect
)
5221 FIXME("(%s, %p): stub\n", debugstr_guid(&guid
), effect
);
5224 return InvalidParameter
;
5228 return NotImplemented
;
5231 /*****************************************************************************
5232 * GdipDeleteEffect [GDIPLUS.@]
5234 GpStatus WINGDIPAPI
GdipDeleteEffect(CGpEffect
*effect
)
5236 FIXME("(%p): stub\n", effect
);
5237 /* note: According to Jose Roca's GDI+ Docs, this is not implemented
5238 * in Windows's gdiplus */
5239 return NotImplemented
;
5242 /*****************************************************************************
5243 * GdipSetEffectParameters [GDIPLUS.@]
5245 GpStatus WINGDIPAPI
GdipSetEffectParameters(CGpEffect
*effect
,
5246 const VOID
*params
, const UINT size
)
5250 TRACE("(%p,%p,%u)\n", effect
, params
, size
);
5253 FIXME("not implemented\n");
5255 return NotImplemented
;
5258 /*****************************************************************************
5259 * GdipGetImageFlags [GDIPLUS.@]
5261 GpStatus WINGDIPAPI
GdipGetImageFlags(GpImage
*image
, UINT
*flags
)
5263 TRACE("%p %p\n", image
, flags
);
5265 if(!image
|| !flags
)
5266 return InvalidParameter
;
5268 *flags
= image
->flags
;
5273 GpStatus WINGDIPAPI
GdipTestControl(GpTestControlEnum control
, void *param
)
5275 TRACE("(%d, %p)\n", control
, param
);
5278 case TestControlForceBilinear
:
5280 FIXME("TestControlForceBilinear not handled\n");
5282 case TestControlNoICM
:
5284 FIXME("TestControlNoICM not handled\n");
5286 case TestControlGetBuildNumber
:
5287 *((DWORD
*)param
) = 3102;
5294 GpStatus WINGDIPAPI
GdipImageForceValidation(GpImage
*image
)
5296 TRACE("%p\n", image
);
5301 /*****************************************************************************
5302 * GdipGetImageThumbnail [GDIPLUS.@]
5304 GpStatus WINGDIPAPI
GdipGetImageThumbnail(GpImage
*image
, UINT width
, UINT height
,
5305 GpImage
**ret_image
, GetThumbnailImageAbort cb
,
5309 GpGraphics
*graphics
;
5310 UINT srcwidth
, srcheight
;
5312 TRACE("(%p %u %u %p %p %p)\n",
5313 image
, width
, height
, ret_image
, cb
, cb_data
);
5315 if (!image
|| !ret_image
)
5316 return InvalidParameter
;
5318 if (!width
) width
= 120;
5319 if (!height
) height
= 120;
5321 GdipGetImageWidth(image
, &srcwidth
);
5322 GdipGetImageHeight(image
, &srcheight
);
5324 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat32bppPARGB
,
5325 NULL
, (GpBitmap
**)ret_image
);
5329 stat
= GdipGetImageGraphicsContext(*ret_image
, &graphics
);
5333 stat
= GdipDrawImageRectRectI(graphics
, image
,
5334 0, 0, width
, height
, 0, 0, srcwidth
, srcheight
, UnitPixel
,
5337 GdipDeleteGraphics(graphics
);
5342 GdipDisposeImage(*ret_image
);
5350 /*****************************************************************************
5351 * GdipImageRotateFlip [GDIPLUS.@]
5353 GpStatus WINGDIPAPI
GdipImageRotateFlip(GpImage
*image
, RotateFlipType type
)
5355 GpBitmap
*new_bitmap
;
5357 int bpp
, bytesperpixel
;
5358 BOOL rotate_90
, flip_x
, flip_y
;
5359 int src_x_offset
, src_y_offset
;
5361 UINT x
, y
, width
, height
;
5362 BitmapData src_lock
, dst_lock
;
5366 TRACE("(%p, %u)\n", image
, type
);
5369 return InvalidParameter
;
5370 if (!image_lock(image
, &unlock
))
5374 flip_x
= (type
&6) == 2 || (type
&6) == 4;
5375 flip_y
= (type
&3) == 1 || (type
&3) == 2;
5377 if (image
->type
!= ImageTypeBitmap
)
5379 FIXME("Not implemented for type %i\n", image
->type
);
5380 image_unlock(image
, unlock
);
5381 return NotImplemented
;
5384 bitmap
= (GpBitmap
*)image
;
5385 bpp
= PIXELFORMATBPP(bitmap
->format
);
5389 FIXME("Not implemented for %i bit images\n", bpp
);
5390 image_unlock(image
, unlock
);
5391 return NotImplemented
;
5396 width
= bitmap
->height
;
5397 height
= bitmap
->width
;
5401 width
= bitmap
->width
;
5402 height
= bitmap
->height
;
5405 bytesperpixel
= bpp
/8;
5407 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, bitmap
->format
, NULL
, &new_bitmap
);
5411 image_unlock(image
, unlock
);
5415 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, bitmap
->format
, &src_lock
);
5419 stat
= GdipBitmapLockBits(new_bitmap
, NULL
, ImageLockModeWrite
, bitmap
->format
, &dst_lock
);
5423 LPBYTE src_row
, src_pixel
;
5424 LPBYTE dst_row
, dst_pixel
;
5426 src_origin
= src_lock
.Scan0
;
5427 if (flip_x
) src_origin
+= bytesperpixel
* (bitmap
->width
- 1);
5428 if (flip_y
) src_origin
+= src_lock
.Stride
* (bitmap
->height
- 1);
5432 if (flip_y
) src_x_offset
= -src_lock
.Stride
;
5433 else src_x_offset
= src_lock
.Stride
;
5434 if (flip_x
) src_y_offset
= -bytesperpixel
;
5435 else src_y_offset
= bytesperpixel
;
5439 if (flip_x
) src_x_offset
= -bytesperpixel
;
5440 else src_x_offset
= bytesperpixel
;
5441 if (flip_y
) src_y_offset
= -src_lock
.Stride
;
5442 else src_y_offset
= src_lock
.Stride
;
5445 src_row
= src_origin
;
5446 dst_row
= dst_lock
.Scan0
;
5447 for (y
=0; y
<height
; y
++)
5449 src_pixel
= src_row
;
5450 dst_pixel
= dst_row
;
5451 for (x
=0; x
<width
; x
++)
5453 /* FIXME: This could probably be faster without memcpy. */
5454 memcpy(dst_pixel
, src_pixel
, bytesperpixel
);
5455 dst_pixel
+= bytesperpixel
;
5456 src_pixel
+= src_x_offset
;
5458 src_row
+= src_y_offset
;
5459 dst_row
+= dst_lock
.Stride
;
5462 GdipBitmapUnlockBits(new_bitmap
, &dst_lock
);
5465 GdipBitmapUnlockBits(bitmap
, &src_lock
);
5469 move_bitmap(bitmap
, new_bitmap
, FALSE
);
5471 GdipDisposeImage(&new_bitmap
->image
);
5473 image_unlock(image
, unlock
);
5477 /*****************************************************************************
5478 * GdipImageSetAbort [GDIPLUS.@]
5480 GpStatus WINGDIPAPI
GdipImageSetAbort(GpImage
*image
, GdiplusAbort
*pabort
)
5482 TRACE("(%p, %p)\n", image
, pabort
);
5485 return InvalidParameter
;
5488 FIXME("Abort callback is not supported.\n");
5493 /*****************************************************************************
5494 * GdipBitmapConvertFormat [GDIPLUS.@]
5496 GpStatus WINGDIPAPI
GdipBitmapConvertFormat(GpBitmap
*bitmap
, PixelFormat format
, DitherType dithertype
,
5497 PaletteType palettetype
, ColorPalette
*palette
, REAL alphathreshold
)
5499 FIXME("(%p, 0x%08x, %d, %d, %p, %f): stub\n", bitmap
, format
, dithertype
, palettetype
, palette
, alphathreshold
);
5500 return NotImplemented
;
5503 static void set_histogram_point_argb(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5505 ch0
[ color
>> 24 ]++;
5506 ch1
[(color
>> 16) & 0xff]++;
5507 ch2
[(color
>> 8) & 0xff]++;
5508 ch3
[ color
& 0xff]++;
5511 static void set_histogram_point_pargb(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5513 BYTE alpha
= color
>> 24;
5516 ch1
[(((color
>> 16) & 0xff) * alpha
) / 0xff]++;
5517 ch2
[(((color
>> 8) & 0xff) * alpha
) / 0xff]++;
5518 ch3
[(( color
& 0xff) * alpha
) / 0xff]++;
5521 static void set_histogram_point_rgb(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5523 ch0
[(color
>> 16) & 0xff]++;
5524 ch1
[(color
>> 8) & 0xff]++;
5525 ch2
[ color
& 0xff]++;
5528 static void set_histogram_point_gray(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5530 ch0
[(76 * ((color
>> 16) & 0xff) + 150 * ((color
>> 8) & 0xff) + 29 * (color
& 0xff)) / 0xff]++;
5533 static void set_histogram_point_b(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5535 ch0
[color
& 0xff]++;
5538 static void set_histogram_point_g(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5540 ch0
[(color
>> 8) & 0xff]++;
5543 static void set_histogram_point_r(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5545 ch0
[(color
>> 16) & 0xff]++;
5548 static void set_histogram_point_a(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5550 ch0
[(color
>> 24) & 0xff]++;
5553 /*****************************************************************************
5554 * GdipBitmapGetHistogram [GDIPLUS.@]
5556 GpStatus WINGDIPAPI
GdipBitmapGetHistogram(GpBitmap
*bitmap
, HistogramFormat format
, UINT num_of_entries
,
5557 UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
)
5559 static void (* const set_histogram_point
[])(ARGB color
, UINT
*ch0
, UINT
*ch1
, UINT
*ch2
, UINT
*ch3
) =
5561 set_histogram_point_argb
,
5562 set_histogram_point_pargb
,
5563 set_histogram_point_rgb
,
5564 set_histogram_point_gray
,
5565 set_histogram_point_b
,
5566 set_histogram_point_g
,
5567 set_histogram_point_r
,
5568 set_histogram_point_a
,
5570 UINT width
, height
, x
, y
;
5572 TRACE("(%p, %d, %u, %p, %p, %p, %p)\n", bitmap
, format
, num_of_entries
,
5573 ch0
, ch1
, ch2
, ch3
);
5575 if (!bitmap
|| num_of_entries
!= 256)
5576 return InvalidParameter
;
5578 /* Make sure passed channel pointers match requested format */
5581 case HistogramFormatARGB
:
5582 case HistogramFormatPARGB
:
5583 if (!ch0
|| !ch1
|| !ch2
|| !ch3
)
5584 return InvalidParameter
;
5585 memset(ch0
, 0, num_of_entries
* sizeof(UINT
));
5586 memset(ch1
, 0, num_of_entries
* sizeof(UINT
));
5587 memset(ch2
, 0, num_of_entries
* sizeof(UINT
));
5588 memset(ch3
, 0, num_of_entries
* sizeof(UINT
));
5590 case HistogramFormatRGB
:
5591 if (!ch0
|| !ch1
|| !ch2
|| ch3
)
5592 return InvalidParameter
;
5593 memset(ch0
, 0, num_of_entries
* sizeof(UINT
));
5594 memset(ch1
, 0, num_of_entries
* sizeof(UINT
));
5595 memset(ch2
, 0, num_of_entries
* sizeof(UINT
));
5597 case HistogramFormatGray
:
5598 case HistogramFormatB
:
5599 case HistogramFormatG
:
5600 case HistogramFormatR
:
5601 case HistogramFormatA
:
5602 if (!ch0
|| ch1
|| ch2
|| ch3
)
5603 return InvalidParameter
;
5604 memset(ch0
, 0, num_of_entries
* sizeof(UINT
));
5607 WARN("Invalid histogram format requested, %d\n", format
);
5608 return InvalidParameter
;
5611 GdipGetImageWidth(&bitmap
->image
, &width
);
5612 GdipGetImageHeight(&bitmap
->image
, &height
);
5614 for (y
= 0; y
< height
; y
++)
5615 for (x
= 0; x
< width
; x
++)
5619 GdipBitmapGetPixel(bitmap
, x
, y
, &color
);
5620 set_histogram_point
[format
](color
, ch0
, ch1
, ch2
, ch3
);
5626 /*****************************************************************************
5627 * GdipBitmapGetHistogramSize [GDIPLUS.@]
5629 GpStatus WINGDIPAPI
GdipBitmapGetHistogramSize(HistogramFormat format
, UINT
*num_of_entries
)
5631 TRACE("(%d, %p)\n", format
, num_of_entries
);
5633 if (!num_of_entries
)
5634 return InvalidParameter
;
5636 *num_of_entries
= 256;