2 * Copyright (C) 2007 Google (Evan Stade)
3 * Copyright (C) 2012 Dmitry Timoshkov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "gdiplus_private.h"
25 #define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
29 const WICPixelFormatGUID
*wic_format
;
30 PixelFormat gdip_format
;
31 /* predefined palette type to use for pixel format conversions */
32 WICBitmapPaletteType palette_type
;
35 { &GUID_WICPixelFormatBlackWhite
, PixelFormat1bppIndexed
, WICBitmapPaletteTypeFixedBW
},
36 { &GUID_WICPixelFormat1bppIndexed
, PixelFormat1bppIndexed
, WICBitmapPaletteTypeFixedBW
},
37 { &GUID_WICPixelFormat8bppGray
, PixelFormat8bppIndexed
, WICBitmapPaletteTypeFixedGray256
},
38 { &GUID_WICPixelFormat8bppIndexed
, PixelFormat8bppIndexed
, WICBitmapPaletteTypeFixedHalftone256
},
39 { &GUID_WICPixelFormat16bppBGR555
, PixelFormat16bppRGB555
, WICBitmapPaletteTypeFixedHalftone256
},
40 { &GUID_WICPixelFormat24bppBGR
, PixelFormat24bppRGB
, WICBitmapPaletteTypeFixedHalftone256
},
41 { &GUID_WICPixelFormat32bppBGR
, PixelFormat32bppRGB
, WICBitmapPaletteTypeFixedHalftone256
},
42 { &GUID_WICPixelFormat32bppBGRA
, PixelFormat32bppARGB
, WICBitmapPaletteTypeFixedHalftone256
},
43 { &GUID_WICPixelFormat32bppPBGRA
, PixelFormat32bppPARGB
, WICBitmapPaletteTypeFixedHalftone256
},
47 static ColorPalette
*get_palette(IWICBitmapFrameDecode
*frame
, WICBitmapPaletteType palette_type
)
50 IWICImagingFactory
*factory
;
51 IWICPalette
*wic_palette
;
52 ColorPalette
*palette
= NULL
;
54 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
,
55 &IID_IWICImagingFactory
, (void **)&factory
);
56 if (hr
!= S_OK
) return NULL
;
58 hr
= IWICImagingFactory_CreatePalette(factory
, &wic_palette
);
61 hr
= WINCODEC_ERR_PALETTEUNAVAILABLE
;
63 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, wic_palette
);
66 TRACE("using predefined palette %#x\n", palette_type
);
67 hr
= IWICPalette_InitializePredefined(wic_palette
, palette_type
, FALSE
);
74 IWICPalette_IsBlackWhite(wic_palette
, &mono
);
75 IWICPalette_IsGrayscale(wic_palette
, &gray
);
77 IWICPalette_GetColorCount(wic_palette
, &count
);
78 palette
= HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(UINT
) + count
* sizeof(ARGB
));
79 IWICPalette_GetColors(wic_palette
, count
, palette
->Entries
, &palette
->Count
);
84 palette
->Flags
= PaletteFlagsGrayScale
;
86 palette
->Flags
= PaletteFlagsHalftone
;
88 IWICPalette_Release(wic_palette
);
90 IWICImagingFactory_Release(factory
);
94 static INT
ipicture_pixel_height(IPicture
*pic
)
99 IPicture_get_Height(pic
, &y
);
101 hdcref
= CreateCompatibleDC(0);
102 y
= MulDiv(y
, GetDeviceCaps(hdcref
, LOGPIXELSY
), INCH_HIMETRIC
);
108 static INT
ipicture_pixel_width(IPicture
*pic
)
111 OLE_XSIZE_HIMETRIC x
;
113 IPicture_get_Width(pic
, &x
);
115 hdcref
= CreateCompatibleDC(0);
116 x
= MulDiv(x
, GetDeviceCaps(hdcref
, LOGPIXELSX
), INCH_HIMETRIC
);
122 GpStatus WINGDIPAPI
GdipBitmapApplyEffect(GpBitmap
* bitmap
, CGpEffect
* effect
,
123 RECT
* roi
, BOOL useAuxData
, VOID
** auxData
, INT
* auxDataSize
)
125 FIXME("(%p %p %p %d %p %p): stub\n", bitmap
, effect
, roi
, useAuxData
, auxData
, auxDataSize
);
127 * Note: According to Jose Roca's GDI+ docs, this function is not
128 * implemented in Windows's GDI+.
130 return NotImplemented
;
133 GpStatus WINGDIPAPI
GdipBitmapCreateApplyEffect(GpBitmap
** inputBitmaps
,
134 INT numInputs
, CGpEffect
* effect
, RECT
* roi
, RECT
* outputRect
,
135 GpBitmap
** outputBitmap
, BOOL useAuxData
, VOID
** auxData
, INT
* auxDataSize
)
137 FIXME("(%p %d %p %p %p %p %d %p %p): stub\n", inputBitmaps
, numInputs
, effect
, roi
, outputRect
, outputBitmap
, useAuxData
, auxData
, auxDataSize
);
139 * Note: According to Jose Roca's GDI+ docs, this function is not
140 * implemented in Windows's GDI+.
142 return NotImplemented
;
145 static inline void getpixel_1bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
147 *index
= (row
[x
/8]>>(7-x
%8)) & 1;
150 static inline void getpixel_4bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
153 *index
= row
[x
/2]&0xf;
155 *index
= row
[x
/2]>>4;
158 static inline void getpixel_8bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
163 static inline void getpixel_16bppGrayScale(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
164 const BYTE
*row
, UINT x
)
166 *r
= *g
= *b
= row
[x
*2+1];
170 static inline void getpixel_16bppRGB555(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
171 const BYTE
*row
, UINT x
)
173 WORD pixel
= *((const WORD
*)(row
)+x
);
174 *r
= (pixel
>>7&0xf8)|(pixel
>>12&0x7);
175 *g
= (pixel
>>2&0xf8)|(pixel
>>6&0x7);
176 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
180 static inline void getpixel_16bppRGB565(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
181 const BYTE
*row
, UINT x
)
183 WORD pixel
= *((const WORD
*)(row
)+x
);
184 *r
= (pixel
>>8&0xf8)|(pixel
>>13&0x7);
185 *g
= (pixel
>>3&0xfc)|(pixel
>>9&0x3);
186 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
190 static inline void getpixel_16bppARGB1555(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
191 const BYTE
*row
, UINT x
)
193 WORD pixel
= *((const WORD
*)(row
)+x
);
194 *r
= (pixel
>>7&0xf8)|(pixel
>>12&0x7);
195 *g
= (pixel
>>2&0xf8)|(pixel
>>6&0x7);
196 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
197 if ((pixel
&0x8000) == 0x8000)
203 static inline void getpixel_24bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
204 const BYTE
*row
, UINT x
)
212 static inline void getpixel_32bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
213 const BYTE
*row
, UINT x
)
221 static inline void getpixel_32bppARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
222 const BYTE
*row
, UINT x
)
230 static inline void getpixel_32bppPARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
231 const BYTE
*row
, UINT x
)
238 *r
= row
[x
*4+2] * 255 / *a
;
239 *g
= row
[x
*4+1] * 255 / *a
;
240 *b
= row
[x
*4] * 255 / *a
;
244 static inline void getpixel_48bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
245 const BYTE
*row
, UINT x
)
253 static inline void getpixel_64bppARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
254 const BYTE
*row
, UINT x
)
262 static inline void getpixel_64bppPARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
263 const BYTE
*row
, UINT x
)
270 *r
= row
[x
*8+5] * 255 / *a
;
271 *g
= row
[x
*8+3] * 255 / *a
;
272 *b
= row
[x
*8+1] * 255 / *a
;
276 GpStatus WINGDIPAPI
GdipBitmapGetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
283 if(!bitmap
|| !color
||
284 x
< 0 || y
< 0 || x
>= bitmap
->width
|| y
>= bitmap
->height
)
285 return InvalidParameter
;
287 row
= bitmap
->bits
+bitmap
->stride
*y
;
289 switch (bitmap
->format
)
291 case PixelFormat1bppIndexed
:
292 getpixel_1bppIndexed(&index
,row
,x
);
294 case PixelFormat4bppIndexed
:
295 getpixel_4bppIndexed(&index
,row
,x
);
297 case PixelFormat8bppIndexed
:
298 getpixel_8bppIndexed(&index
,row
,x
);
300 case PixelFormat16bppGrayScale
:
301 getpixel_16bppGrayScale(&r
,&g
,&b
,&a
,row
,x
);
303 case PixelFormat16bppRGB555
:
304 getpixel_16bppRGB555(&r
,&g
,&b
,&a
,row
,x
);
306 case PixelFormat16bppRGB565
:
307 getpixel_16bppRGB565(&r
,&g
,&b
,&a
,row
,x
);
309 case PixelFormat16bppARGB1555
:
310 getpixel_16bppARGB1555(&r
,&g
,&b
,&a
,row
,x
);
312 case PixelFormat24bppRGB
:
313 getpixel_24bppRGB(&r
,&g
,&b
,&a
,row
,x
);
315 case PixelFormat32bppRGB
:
316 getpixel_32bppRGB(&r
,&g
,&b
,&a
,row
,x
);
318 case PixelFormat32bppARGB
:
319 getpixel_32bppARGB(&r
,&g
,&b
,&a
,row
,x
);
321 case PixelFormat32bppPARGB
:
322 getpixel_32bppPARGB(&r
,&g
,&b
,&a
,row
,x
);
324 case PixelFormat48bppRGB
:
325 getpixel_48bppRGB(&r
,&g
,&b
,&a
,row
,x
);
327 case PixelFormat64bppARGB
:
328 getpixel_64bppARGB(&r
,&g
,&b
,&a
,row
,x
);
330 case PixelFormat64bppPARGB
:
331 getpixel_64bppPARGB(&r
,&g
,&b
,&a
,row
,x
);
334 FIXME("not implemented for format 0x%x\n", bitmap
->format
);
335 return NotImplemented
;
338 if (bitmap
->format
& PixelFormatIndexed
)
339 *color
= bitmap
->image
.palette
->Entries
[index
];
341 *color
= a
<<24|r
<<16|g
<<8|b
;
346 static inline UINT
get_palette_index(BYTE r
, BYTE g
, BYTE b
, BYTE a
, ColorPalette
*palette
)
349 int best_distance
= 0x7fff;
353 if (!palette
) return 0;
354 /* This algorithm scans entire palette,
355 computes difference from desired color (all color components have equal weight)
356 and returns the index of color with least difference.
358 Note: Maybe it could be replaced with a better algorithm for better image quality
359 and performance, though better algorithm would probably need some pre-built lookup
360 tables and thus may actually be slower if this method is called only few times per
363 for(i
=0;i
<palette
->Count
;i
++) {
364 ARGB color
=palette
->Entries
[i
];
365 distance
=abs(b
-(color
& 0xff)) + abs(g
-(color
>>8 & 0xff)) + abs(r
-(color
>>16 & 0xff)) + abs(a
-(color
>>24 & 0xff));
366 if (distance
<best_distance
) {
367 best_distance
=distance
;
374 static inline void setpixel_8bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
375 BYTE
*row
, UINT x
, ColorPalette
*palette
)
377 BYTE index
= get_palette_index(r
,g
,b
,a
,palette
);
381 static inline void setpixel_1bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
382 BYTE
*row
, UINT x
, ColorPalette
*palette
)
384 row
[x
/8] = (row
[x
/8] & ~(1<<(7-x
%8))) | (get_palette_index(r
,g
,b
,a
,palette
)<<(7-x
%8));
387 static inline void setpixel_4bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
388 BYTE
*row
, UINT x
, ColorPalette
*palette
)
391 row
[x
/2] = (row
[x
/2] & 0xf0) | get_palette_index(r
,g
,b
,a
,palette
);
393 row
[x
/2] = (row
[x
/2] & 0x0f) | get_palette_index(r
,g
,b
,a
,palette
)<<4;
396 static inline void setpixel_16bppGrayScale(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
399 *((WORD
*)(row
)+x
) = (r
+g
+b
)*85;
402 static inline void setpixel_16bppRGB555(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
405 *((WORD
*)(row
)+x
) = (r
<<7&0x7c00)|
410 static inline void setpixel_16bppRGB565(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
413 *((WORD
*)(row
)+x
) = (r
<<8&0xf800)|
418 static inline void setpixel_16bppARGB1555(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
421 *((WORD
*)(row
)+x
) = (a
<<8&0x8000)|
427 static inline void setpixel_24bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
435 static inline void setpixel_32bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
438 *((DWORD
*)(row
)+x
) = (r
<<16)|(g
<<8)|b
;
441 static inline void setpixel_32bppARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
444 *((DWORD
*)(row
)+x
) = (a
<<24)|(r
<<16)|(g
<<8)|b
;
447 static inline void setpixel_32bppPARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
453 *((DWORD
*)(row
)+x
) = (a
<<24)|(r
<<16)|(g
<<8)|b
;
456 static inline void setpixel_48bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
459 row
[x
*6+5] = row
[x
*6+4] = r
;
460 row
[x
*6+3] = row
[x
*6+2] = g
;
461 row
[x
*6+1] = row
[x
*6] = b
;
464 static inline void setpixel_64bppARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
467 UINT64 a64
=a
, r64
=r
, g64
=g
, b64
=b
;
468 *((UINT64
*)(row
)+x
) = (a64
<<56)|(a64
<<48)|(r64
<<40)|(r64
<<32)|(g64
<<24)|(g64
<<16)|(b64
<<8)|b64
;
471 static inline void setpixel_64bppPARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
474 UINT64 a64
, r64
, g64
, b64
;
479 *((UINT64
*)(row
)+x
) = (a64
<<48)|(r64
<<32)|(g64
<<16)|b64
;
482 GpStatus WINGDIPAPI
GdipBitmapSetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
488 if(!bitmap
|| x
< 0 || y
< 0 || x
>= bitmap
->width
|| y
>= bitmap
->height
)
489 return InvalidParameter
;
496 row
= bitmap
->bits
+ bitmap
->stride
* y
;
498 switch (bitmap
->format
)
500 case PixelFormat16bppGrayScale
:
501 setpixel_16bppGrayScale(r
,g
,b
,a
,row
,x
);
503 case PixelFormat16bppRGB555
:
504 setpixel_16bppRGB555(r
,g
,b
,a
,row
,x
);
506 case PixelFormat16bppRGB565
:
507 setpixel_16bppRGB565(r
,g
,b
,a
,row
,x
);
509 case PixelFormat16bppARGB1555
:
510 setpixel_16bppARGB1555(r
,g
,b
,a
,row
,x
);
512 case PixelFormat24bppRGB
:
513 setpixel_24bppRGB(r
,g
,b
,a
,row
,x
);
515 case PixelFormat32bppRGB
:
516 setpixel_32bppRGB(r
,g
,b
,a
,row
,x
);
518 case PixelFormat32bppARGB
:
519 setpixel_32bppARGB(r
,g
,b
,a
,row
,x
);
521 case PixelFormat32bppPARGB
:
522 setpixel_32bppPARGB(r
,g
,b
,a
,row
,x
);
524 case PixelFormat48bppRGB
:
525 setpixel_48bppRGB(r
,g
,b
,a
,row
,x
);
527 case PixelFormat64bppARGB
:
528 setpixel_64bppARGB(r
,g
,b
,a
,row
,x
);
530 case PixelFormat64bppPARGB
:
531 setpixel_64bppPARGB(r
,g
,b
,a
,row
,x
);
533 case PixelFormat8bppIndexed
:
534 setpixel_8bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
536 case PixelFormat4bppIndexed
:
537 setpixel_4bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
539 case PixelFormat1bppIndexed
:
540 setpixel_1bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
->image
.palette
);
543 FIXME("not implemented for format 0x%x\n", bitmap
->format
);
544 return NotImplemented
;
550 GpStatus
convert_pixels(INT width
, INT height
,
551 INT dst_stride
, BYTE
*dst_bits
, PixelFormat dst_format
,
552 INT src_stride
, const BYTE
*src_bits
, PixelFormat src_format
,
553 ColorPalette
*palette
)
557 if (src_format
== dst_format
||
558 (dst_format
== PixelFormat32bppRGB
&& PIXELFORMATBPP(src_format
) == 32))
560 UINT widthbytes
= PIXELFORMATBPP(src_format
) * width
/ 8;
561 for (y
=0; y
<height
; y
++)
562 memcpy(dst_bits
+dst_stride
*y
, src_bits
+src_stride
*y
, widthbytes
);
566 #define convert_indexed_to_rgb(getpixel_function, setpixel_function) do { \
567 for (x=0; x<width; x++) \
568 for (y=0; y<height; y++) { \
571 BYTE *color = (BYTE *)&argb; \
572 getpixel_function(&index, src_bits+src_stride*y, x); \
573 argb = (palette && index < palette->Count) ? palette->Entries[index] : 0; \
574 setpixel_function(color[2], color[1], color[0], color[3], dst_bits+dst_stride*y, x); \
579 #define convert_rgb_to_rgb(getpixel_function, setpixel_function) do { \
580 for (x=0; x<width; x++) \
581 for (y=0; y<height; y++) { \
583 getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
584 setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x); \
589 #define convert_rgb_to_indexed(getpixel_function, setpixel_function) do { \
590 for (x=0; x<width; x++) \
591 for (y=0; y<height; y++) { \
593 getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
594 setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x, palette); \
601 case PixelFormat1bppIndexed
:
604 case PixelFormat16bppGrayScale
:
605 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppGrayScale
);
606 case PixelFormat16bppRGB555
:
607 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppRGB555
);
608 case PixelFormat16bppRGB565
:
609 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppRGB565
);
610 case PixelFormat16bppARGB1555
:
611 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppARGB1555
);
612 case PixelFormat24bppRGB
:
613 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_24bppRGB
);
614 case PixelFormat32bppRGB
:
615 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppRGB
);
616 case PixelFormat32bppARGB
:
617 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppARGB
);
618 case PixelFormat32bppPARGB
:
619 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppPARGB
);
620 case PixelFormat48bppRGB
:
621 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_48bppRGB
);
622 case PixelFormat64bppARGB
:
623 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_64bppARGB
);
628 case PixelFormat4bppIndexed
:
631 case PixelFormat16bppGrayScale
:
632 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppGrayScale
);
633 case PixelFormat16bppRGB555
:
634 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppRGB555
);
635 case PixelFormat16bppRGB565
:
636 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppRGB565
);
637 case PixelFormat16bppARGB1555
:
638 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppARGB1555
);
639 case PixelFormat24bppRGB
:
640 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_24bppRGB
);
641 case PixelFormat32bppRGB
:
642 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppRGB
);
643 case PixelFormat32bppARGB
:
644 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppARGB
);
645 case PixelFormat32bppPARGB
:
646 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppPARGB
);
647 case PixelFormat48bppRGB
:
648 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_48bppRGB
);
649 case PixelFormat64bppARGB
:
650 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_64bppARGB
);
655 case PixelFormat8bppIndexed
:
658 case PixelFormat16bppGrayScale
:
659 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppGrayScale
);
660 case PixelFormat16bppRGB555
:
661 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppRGB555
);
662 case PixelFormat16bppRGB565
:
663 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppRGB565
);
664 case PixelFormat16bppARGB1555
:
665 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppARGB1555
);
666 case PixelFormat24bppRGB
:
667 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_24bppRGB
);
668 case PixelFormat32bppRGB
:
669 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppRGB
);
670 case PixelFormat32bppARGB
:
671 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppARGB
);
672 case PixelFormat32bppPARGB
:
673 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppPARGB
);
674 case PixelFormat48bppRGB
:
675 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_48bppRGB
);
676 case PixelFormat64bppARGB
:
677 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_64bppARGB
);
682 case PixelFormat16bppGrayScale
:
685 case PixelFormat1bppIndexed
:
686 convert_rgb_to_indexed(getpixel_16bppGrayScale
, setpixel_1bppIndexed
);
687 case PixelFormat8bppIndexed
:
688 convert_rgb_to_indexed(getpixel_16bppGrayScale
, setpixel_8bppIndexed
);
689 case PixelFormat16bppRGB555
:
690 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppRGB555
);
691 case PixelFormat16bppRGB565
:
692 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppRGB565
);
693 case PixelFormat16bppARGB1555
:
694 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppARGB1555
);
695 case PixelFormat24bppRGB
:
696 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_24bppRGB
);
697 case PixelFormat32bppRGB
:
698 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppRGB
);
699 case PixelFormat32bppARGB
:
700 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppARGB
);
701 case PixelFormat32bppPARGB
:
702 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppPARGB
);
703 case PixelFormat48bppRGB
:
704 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_48bppRGB
);
705 case PixelFormat64bppARGB
:
706 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_64bppARGB
);
711 case PixelFormat16bppRGB555
:
714 case PixelFormat1bppIndexed
:
715 convert_rgb_to_indexed(getpixel_16bppRGB555
, setpixel_1bppIndexed
);
716 case PixelFormat8bppIndexed
:
717 convert_rgb_to_indexed(getpixel_16bppRGB555
, setpixel_8bppIndexed
);
718 case PixelFormat16bppGrayScale
:
719 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppGrayScale
);
720 case PixelFormat16bppRGB565
:
721 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppRGB565
);
722 case PixelFormat16bppARGB1555
:
723 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppARGB1555
);
724 case PixelFormat24bppRGB
:
725 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_24bppRGB
);
726 case PixelFormat32bppRGB
:
727 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppRGB
);
728 case PixelFormat32bppARGB
:
729 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppARGB
);
730 case PixelFormat32bppPARGB
:
731 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppPARGB
);
732 case PixelFormat48bppRGB
:
733 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_48bppRGB
);
734 case PixelFormat64bppARGB
:
735 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_64bppARGB
);
740 case PixelFormat16bppRGB565
:
743 case PixelFormat1bppIndexed
:
744 convert_rgb_to_indexed(getpixel_16bppRGB565
, setpixel_1bppIndexed
);
745 case PixelFormat8bppIndexed
:
746 convert_rgb_to_indexed(getpixel_16bppRGB565
, setpixel_8bppIndexed
);
747 case PixelFormat16bppGrayScale
:
748 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppGrayScale
);
749 case PixelFormat16bppRGB555
:
750 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppRGB555
);
751 case PixelFormat16bppARGB1555
:
752 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppARGB1555
);
753 case PixelFormat24bppRGB
:
754 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_24bppRGB
);
755 case PixelFormat32bppRGB
:
756 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppRGB
);
757 case PixelFormat32bppARGB
:
758 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppARGB
);
759 case PixelFormat32bppPARGB
:
760 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppPARGB
);
761 case PixelFormat48bppRGB
:
762 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_48bppRGB
);
763 case PixelFormat64bppARGB
:
764 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_64bppARGB
);
769 case PixelFormat16bppARGB1555
:
772 case PixelFormat1bppIndexed
:
773 convert_rgb_to_indexed(getpixel_16bppARGB1555
, setpixel_1bppIndexed
);
774 case PixelFormat8bppIndexed
:
775 convert_rgb_to_indexed(getpixel_16bppARGB1555
, setpixel_8bppIndexed
);
776 case PixelFormat16bppGrayScale
:
777 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppGrayScale
);
778 case PixelFormat16bppRGB555
:
779 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppRGB555
);
780 case PixelFormat16bppRGB565
:
781 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppRGB565
);
782 case PixelFormat24bppRGB
:
783 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_24bppRGB
);
784 case PixelFormat32bppRGB
:
785 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppRGB
);
786 case PixelFormat32bppARGB
:
787 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppARGB
);
788 case PixelFormat32bppPARGB
:
789 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppPARGB
);
790 case PixelFormat48bppRGB
:
791 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_48bppRGB
);
792 case PixelFormat64bppARGB
:
793 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_64bppARGB
);
798 case PixelFormat24bppRGB
:
801 case PixelFormat1bppIndexed
:
802 convert_rgb_to_indexed(getpixel_24bppRGB
, setpixel_1bppIndexed
);
803 case PixelFormat8bppIndexed
:
804 convert_rgb_to_indexed(getpixel_24bppRGB
, setpixel_8bppIndexed
);
805 case PixelFormat16bppGrayScale
:
806 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppGrayScale
);
807 case PixelFormat16bppRGB555
:
808 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppRGB555
);
809 case PixelFormat16bppRGB565
:
810 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppRGB565
);
811 case PixelFormat16bppARGB1555
:
812 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppARGB1555
);
813 case PixelFormat32bppRGB
:
814 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppRGB
);
815 case PixelFormat32bppARGB
:
816 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppARGB
);
817 case PixelFormat32bppPARGB
:
818 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppPARGB
);
819 case PixelFormat48bppRGB
:
820 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_48bppRGB
);
821 case PixelFormat64bppARGB
:
822 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_64bppARGB
);
827 case PixelFormat32bppRGB
:
830 case PixelFormat1bppIndexed
:
831 convert_rgb_to_indexed(getpixel_32bppRGB
, setpixel_1bppIndexed
);
832 case PixelFormat8bppIndexed
:
833 convert_rgb_to_indexed(getpixel_32bppRGB
, setpixel_8bppIndexed
);
834 case PixelFormat16bppGrayScale
:
835 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppGrayScale
);
836 case PixelFormat16bppRGB555
:
837 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppRGB555
);
838 case PixelFormat16bppRGB565
:
839 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppRGB565
);
840 case PixelFormat16bppARGB1555
:
841 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppARGB1555
);
842 case PixelFormat24bppRGB
:
843 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_24bppRGB
);
844 case PixelFormat32bppARGB
:
845 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_32bppARGB
);
846 case PixelFormat32bppPARGB
:
847 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_32bppPARGB
);
848 case PixelFormat48bppRGB
:
849 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_48bppRGB
);
850 case PixelFormat64bppARGB
:
851 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_64bppARGB
);
856 case PixelFormat32bppARGB
:
859 case PixelFormat1bppIndexed
:
860 convert_rgb_to_indexed(getpixel_32bppARGB
, setpixel_1bppIndexed
);
861 case PixelFormat8bppIndexed
:
862 convert_rgb_to_indexed(getpixel_32bppARGB
, setpixel_8bppIndexed
);
863 case PixelFormat16bppGrayScale
:
864 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppGrayScale
);
865 case PixelFormat16bppRGB555
:
866 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppRGB555
);
867 case PixelFormat16bppRGB565
:
868 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppRGB565
);
869 case PixelFormat16bppARGB1555
:
870 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppARGB1555
);
871 case PixelFormat24bppRGB
:
872 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_24bppRGB
);
873 case PixelFormat32bppPARGB
:
874 convert_32bppARGB_to_32bppPARGB(width
, height
, dst_bits
, dst_stride
, src_bits
, src_stride
);
876 case PixelFormat48bppRGB
:
877 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_48bppRGB
);
878 case PixelFormat64bppARGB
:
879 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_64bppARGB
);
884 case PixelFormat32bppPARGB
:
887 case PixelFormat1bppIndexed
:
888 convert_rgb_to_indexed(getpixel_32bppPARGB
, setpixel_1bppIndexed
);
889 case PixelFormat8bppIndexed
:
890 convert_rgb_to_indexed(getpixel_32bppPARGB
, setpixel_8bppIndexed
);
891 case PixelFormat16bppGrayScale
:
892 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppGrayScale
);
893 case PixelFormat16bppRGB555
:
894 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppRGB555
);
895 case PixelFormat16bppRGB565
:
896 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppRGB565
);
897 case PixelFormat16bppARGB1555
:
898 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppARGB1555
);
899 case PixelFormat24bppRGB
:
900 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_24bppRGB
);
901 case PixelFormat32bppRGB
:
902 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_32bppRGB
);
903 case PixelFormat32bppARGB
:
904 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_32bppARGB
);
905 case PixelFormat48bppRGB
:
906 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_48bppRGB
);
907 case PixelFormat64bppARGB
:
908 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_64bppARGB
);
913 case PixelFormat48bppRGB
:
916 case PixelFormat1bppIndexed
:
917 convert_rgb_to_indexed(getpixel_48bppRGB
, setpixel_1bppIndexed
);
918 case PixelFormat8bppIndexed
:
919 convert_rgb_to_indexed(getpixel_48bppRGB
, setpixel_8bppIndexed
);
920 case PixelFormat16bppGrayScale
:
921 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppGrayScale
);
922 case PixelFormat16bppRGB555
:
923 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppRGB555
);
924 case PixelFormat16bppRGB565
:
925 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppRGB565
);
926 case PixelFormat16bppARGB1555
:
927 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppARGB1555
);
928 case PixelFormat24bppRGB
:
929 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_24bppRGB
);
930 case PixelFormat32bppRGB
:
931 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppRGB
);
932 case PixelFormat32bppARGB
:
933 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppARGB
);
934 case PixelFormat32bppPARGB
:
935 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppPARGB
);
936 case PixelFormat64bppARGB
:
937 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_64bppARGB
);
942 case PixelFormat64bppARGB
:
945 case PixelFormat1bppIndexed
:
946 convert_rgb_to_indexed(getpixel_64bppARGB
, setpixel_1bppIndexed
);
947 case PixelFormat8bppIndexed
:
948 convert_rgb_to_indexed(getpixel_64bppARGB
, setpixel_8bppIndexed
);
949 case PixelFormat16bppGrayScale
:
950 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppGrayScale
);
951 case PixelFormat16bppRGB555
:
952 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppRGB555
);
953 case PixelFormat16bppRGB565
:
954 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppRGB565
);
955 case PixelFormat16bppARGB1555
:
956 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppARGB1555
);
957 case PixelFormat24bppRGB
:
958 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_24bppRGB
);
959 case PixelFormat32bppRGB
:
960 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppRGB
);
961 case PixelFormat32bppARGB
:
962 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppARGB
);
963 case PixelFormat32bppPARGB
:
964 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppPARGB
);
965 case PixelFormat48bppRGB
:
966 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_48bppRGB
);
971 case PixelFormat64bppPARGB
:
974 case PixelFormat1bppIndexed
:
975 convert_rgb_to_indexed(getpixel_64bppPARGB
, setpixel_1bppIndexed
);
976 case PixelFormat8bppIndexed
:
977 convert_rgb_to_indexed(getpixel_64bppPARGB
, setpixel_8bppIndexed
);
978 case PixelFormat16bppGrayScale
:
979 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppGrayScale
);
980 case PixelFormat16bppRGB555
:
981 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppRGB555
);
982 case PixelFormat16bppRGB565
:
983 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppRGB565
);
984 case PixelFormat16bppARGB1555
:
985 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppARGB1555
);
986 case PixelFormat24bppRGB
:
987 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_24bppRGB
);
988 case PixelFormat32bppRGB
:
989 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppRGB
);
990 case PixelFormat32bppARGB
:
991 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppARGB
);
992 case PixelFormat32bppPARGB
:
993 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppPARGB
);
994 case PixelFormat48bppRGB
:
995 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_48bppRGB
);
996 case PixelFormat64bppARGB
:
997 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_64bppARGB
);
1006 #undef convert_indexed_to_rgb
1007 #undef convert_rgb_to_rgb
1009 return NotImplemented
;
1012 /* This function returns a pointer to an array of pixels that represents the
1013 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
1014 * flags. It is correct behavior that a user who calls this function with write
1015 * privileges can write to the whole bitmap (not just the area in rect).
1017 * FIXME: only used portion of format is bits per pixel. */
1018 GpStatus WINGDIPAPI
GdipBitmapLockBits(GpBitmap
* bitmap
, GDIPCONST GpRect
* rect
,
1019 UINT flags
, PixelFormat format
, BitmapData
* lockeddata
)
1021 INT bitspp
= PIXELFORMATBPP(format
);
1022 GpRect act_rect
; /* actual rect to be used */
1025 TRACE("%p %p %d 0x%x %p\n", bitmap
, rect
, flags
, format
, lockeddata
);
1027 if(!lockeddata
|| !bitmap
)
1028 return InvalidParameter
;
1031 if(rect
->X
< 0 || rect
->Y
< 0 || (rect
->X
+ rect
->Width
> bitmap
->width
) ||
1032 (rect
->Y
+ rect
->Height
> bitmap
->height
) || !flags
)
1033 return InvalidParameter
;
1038 act_rect
.X
= act_rect
.Y
= 0;
1039 act_rect
.Width
= bitmap
->width
;
1040 act_rect
.Height
= bitmap
->height
;
1043 if(bitmap
->lockmode
)
1045 WARN("bitmap is already locked and cannot be locked again\n");
1049 if (bitmap
->bits
&& bitmap
->format
== format
&& !(flags
& ImageLockModeUserInputBuf
))
1051 /* no conversion is necessary; just use the bits directly */
1052 lockeddata
->Width
= act_rect
.Width
;
1053 lockeddata
->Height
= act_rect
.Height
;
1054 lockeddata
->PixelFormat
= format
;
1055 lockeddata
->Reserved
= flags
;
1056 lockeddata
->Stride
= bitmap
->stride
;
1057 lockeddata
->Scan0
= bitmap
->bits
+ (bitspp
/ 8) * act_rect
.X
+
1058 bitmap
->stride
* act_rect
.Y
;
1060 bitmap
->lockmode
= flags
| ImageLockModeRead
;
1066 /* Make sure we can convert to the requested format. */
1067 if (flags
& ImageLockModeRead
)
1069 stat
= convert_pixels(0, 0, 0, NULL
, format
, 0, NULL
, bitmap
->format
, NULL
);
1070 if (stat
== NotImplemented
)
1072 FIXME("cannot read bitmap from %x to %x\n", bitmap
->format
, format
);
1073 return NotImplemented
;
1077 /* If we're opening for writing, make sure we'll be able to write back in
1078 * the original format. */
1079 if (flags
& ImageLockModeWrite
)
1081 stat
= convert_pixels(0, 0, 0, NULL
, bitmap
->format
, 0, NULL
, format
, NULL
);
1082 if (stat
== NotImplemented
)
1084 FIXME("cannot write bitmap from %x to %x\n", format
, bitmap
->format
);
1085 return NotImplemented
;
1089 lockeddata
->Width
= act_rect
.Width
;
1090 lockeddata
->Height
= act_rect
.Height
;
1091 lockeddata
->PixelFormat
= format
;
1092 lockeddata
->Reserved
= flags
;
1094 if(!(flags
& ImageLockModeUserInputBuf
))
1096 lockeddata
->Stride
= (((act_rect
.Width
* bitspp
+ 7) / 8) + 3) & ~3;
1098 bitmap
->bitmapbits
= GdipAlloc(lockeddata
->Stride
* act_rect
.Height
);
1100 if (!bitmap
->bitmapbits
) return OutOfMemory
;
1102 lockeddata
->Scan0
= bitmap
->bitmapbits
;
1105 if (flags
& ImageLockModeRead
)
1109 if (!fixme
&& (PIXELFORMATBPP(bitmap
->format
) * act_rect
.X
) % 8 != 0)
1111 FIXME("Cannot copy rows that don't start at a whole byte.\n");
1115 stat
= convert_pixels(act_rect
.Width
, act_rect
.Height
,
1116 lockeddata
->Stride
, lockeddata
->Scan0
, format
,
1118 bitmap
->bits
+ bitmap
->stride
* act_rect
.Y
+ PIXELFORMATBPP(bitmap
->format
) * act_rect
.X
/ 8,
1119 bitmap
->format
, bitmap
->image
.palette
);
1123 GdipFree(bitmap
->bitmapbits
);
1124 bitmap
->bitmapbits
= NULL
;
1129 bitmap
->lockmode
= flags
| ImageLockModeRead
;
1131 bitmap
->lockx
= act_rect
.X
;
1132 bitmap
->locky
= act_rect
.Y
;
1137 GpStatus WINGDIPAPI
GdipBitmapSetResolution(GpBitmap
* bitmap
, REAL xdpi
, REAL ydpi
)
1139 TRACE("(%p, %.2f, %.2f)\n", bitmap
, xdpi
, ydpi
);
1141 if (!bitmap
|| xdpi
== 0.0 || ydpi
== 0.0)
1142 return InvalidParameter
;
1144 bitmap
->image
.xres
= xdpi
;
1145 bitmap
->image
.yres
= ydpi
;
1150 GpStatus WINGDIPAPI
GdipBitmapUnlockBits(GpBitmap
* bitmap
,
1151 BitmapData
* lockeddata
)
1156 TRACE("(%p,%p)\n", bitmap
, lockeddata
);
1158 if(!bitmap
|| !lockeddata
)
1159 return InvalidParameter
;
1161 if(!bitmap
->lockmode
)
1164 if(!(lockeddata
->Reserved
& ImageLockModeWrite
)){
1165 if(!(--bitmap
->numlocks
))
1166 bitmap
->lockmode
= 0;
1168 GdipFree(bitmap
->bitmapbits
);
1169 bitmap
->bitmapbits
= NULL
;
1173 if (!bitmap
->bitmapbits
&& !(lockeddata
->Reserved
& ImageLockModeUserInputBuf
))
1175 /* we passed a direct reference; no need to do anything */
1176 bitmap
->lockmode
= 0;
1177 bitmap
->numlocks
= 0;
1181 if (!fixme
&& (PIXELFORMATBPP(bitmap
->format
) * bitmap
->lockx
) % 8 != 0)
1183 FIXME("Cannot copy rows that don't start at a whole byte.\n");
1187 stat
= convert_pixels(lockeddata
->Width
, lockeddata
->Height
,
1189 bitmap
->bits
+ bitmap
->stride
* bitmap
->locky
+ PIXELFORMATBPP(bitmap
->format
) * bitmap
->lockx
/ 8,
1191 lockeddata
->Stride
, lockeddata
->Scan0
, lockeddata
->PixelFormat
, NULL
);
1195 ERR("failed to convert pixels; this should never happen\n");
1198 GdipFree(bitmap
->bitmapbits
);
1199 bitmap
->bitmapbits
= NULL
;
1200 bitmap
->lockmode
= 0;
1201 bitmap
->numlocks
= 0;
1206 GpStatus WINGDIPAPI
GdipCloneBitmapArea(REAL x
, REAL y
, REAL width
, REAL height
,
1207 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
1209 BitmapData lockeddata_src
, lockeddata_dst
;
1215 TRACE("(%f,%f,%f,%f,0x%x,%p,%p)\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1217 if (!srcBitmap
|| !dstBitmap
|| srcBitmap
->image
.type
!= ImageTypeBitmap
||
1219 x
+ width
> srcBitmap
->width
|| y
+ height
> srcBitmap
->height
)
1221 TRACE("<-- InvalidParameter\n");
1222 return InvalidParameter
;
1225 if (format
== PixelFormatDontCare
)
1226 format
= srcBitmap
->format
;
1228 area
.X
= gdip_round(x
);
1229 area
.Y
= gdip_round(y
);
1230 area
.Width
= gdip_round(width
);
1231 area
.Height
= gdip_round(height
);
1233 stat
= GdipBitmapLockBits(srcBitmap
, &area
, ImageLockModeRead
, format
,
1235 if (stat
!= Ok
) return stat
;
1237 stat
= GdipCreateBitmapFromScan0(lockeddata_src
.Width
, lockeddata_src
.Height
,
1238 0, lockeddata_src
.PixelFormat
, NULL
, dstBitmap
);
1241 stat
= GdipBitmapLockBits(*dstBitmap
, NULL
, ImageLockModeWrite
,
1242 lockeddata_src
.PixelFormat
, &lockeddata_dst
);
1246 /* copy the image data */
1247 row_size
= (lockeddata_src
.Width
* PIXELFORMATBPP(lockeddata_src
.PixelFormat
) +7)/8;
1248 for (i
=0; i
<lockeddata_src
.Height
; i
++)
1249 memcpy((BYTE
*)lockeddata_dst
.Scan0
+lockeddata_dst
.Stride
*i
,
1250 (BYTE
*)lockeddata_src
.Scan0
+lockeddata_src
.Stride
*i
,
1253 GdipBitmapUnlockBits(*dstBitmap
, &lockeddata_dst
);
1257 GdipDisposeImage((GpImage
*)*dstBitmap
);
1260 GdipBitmapUnlockBits(srcBitmap
, &lockeddata_src
);
1270 GpStatus WINGDIPAPI
GdipCloneBitmapAreaI(INT x
, INT y
, INT width
, INT height
,
1271 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
1273 TRACE("(%i,%i,%i,%i,0x%x,%p,%p)\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1275 return GdipCloneBitmapArea(x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1278 GpStatus WINGDIPAPI
GdipCloneImage(GpImage
*image
, GpImage
**cloneImage
)
1280 GpStatus stat
= GenericError
;
1282 TRACE("%p, %p\n", image
, cloneImage
);
1284 if (!image
|| !cloneImage
)
1285 return InvalidParameter
;
1294 hr
= CreateStreamOnHGlobal(0, TRUE
, &stream
);
1296 return GenericError
;
1298 hr
= IPicture_SaveAsFile(image
->picture
, stream
, FALSE
, &size
);
1301 WARN("Failed to save image on stream\n");
1305 /* Set seek pointer back to the beginning of the picture */
1307 hr
= IStream_Seek(stream
, move
, STREAM_SEEK_SET
, NULL
);
1311 stat
= GdipLoadImageFromStream(stream
, cloneImage
);
1312 if (stat
!= Ok
) WARN("Failed to load image from stream\n");
1315 IStream_Release(stream
);
1318 else if (image
->type
== ImageTypeBitmap
)
1320 GpBitmap
*bitmap
= (GpBitmap
*)image
;
1321 BitmapData lockeddata_src
, lockeddata_dst
;
1325 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, bitmap
->format
,
1327 if (stat
!= Ok
) return stat
;
1329 stat
= GdipCreateBitmapFromScan0(lockeddata_src
.Width
, lockeddata_src
.Height
,
1330 0, lockeddata_src
.PixelFormat
, NULL
, (GpBitmap
**)cloneImage
);
1333 stat
= GdipBitmapLockBits((GpBitmap
*)*cloneImage
, NULL
, ImageLockModeWrite
,
1334 lockeddata_src
.PixelFormat
, &lockeddata_dst
);
1338 /* copy the image data */
1339 row_size
= (lockeddata_src
.Width
* PIXELFORMATBPP(lockeddata_src
.PixelFormat
) +7)/8;
1340 for (i
=0; i
<lockeddata_src
.Height
; i
++)
1341 memcpy((BYTE
*)lockeddata_dst
.Scan0
+lockeddata_dst
.Stride
*i
,
1342 (BYTE
*)lockeddata_src
.Scan0
+lockeddata_src
.Stride
*i
,
1345 GdipBitmapUnlockBits((GpBitmap
*)*cloneImage
, &lockeddata_dst
);
1349 GdipDisposeImage(*cloneImage
);
1352 GdipBitmapUnlockBits(bitmap
, &lockeddata_src
);
1358 else memcpy(&(*cloneImage
)->format
, &image
->format
, sizeof(GUID
));
1362 else if (image
->type
== ImageTypeMetafile
&& ((GpMetafile
*)image
)->hemf
)
1364 GpMetafile
*result
, *metafile
;
1366 metafile
= (GpMetafile
*)image
;
1368 result
= GdipAlloc(sizeof(*result
));
1372 result
->image
.type
= ImageTypeMetafile
;
1373 result
->image
.format
= image
->format
;
1374 result
->image
.flags
= image
->flags
;
1375 result
->image
.frame_count
= 1;
1376 result
->image
.xres
= image
->xres
;
1377 result
->image
.yres
= image
->yres
;
1378 result
->bounds
= metafile
->bounds
;
1379 result
->unit
= metafile
->unit
;
1380 result
->metafile_type
= metafile
->metafile_type
;
1381 result
->hemf
= CopyEnhMetaFileW(metafile
->hemf
, NULL
);
1389 *cloneImage
= &result
->image
;
1394 WARN("GpImage with no image data (metafile in wrong state?)\n");
1395 return InvalidParameter
;
1399 GpStatus WINGDIPAPI
GdipCreateBitmapFromFile(GDIPCONST WCHAR
* filename
,
1405 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
1407 if(!filename
|| !bitmap
)
1408 return InvalidParameter
;
1410 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
1415 stat
= GdipCreateBitmapFromStream(stream
, bitmap
);
1417 IStream_Release(stream
);
1422 GpStatus WINGDIPAPI
GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO
* info
,
1423 VOID
*bits
, GpBitmap
**bitmap
)
1425 DWORD height
, stride
;
1428 FIXME("(%p, %p, %p) - partially implemented\n", info
, bits
, bitmap
);
1430 if (!info
|| !bits
|| !bitmap
)
1431 return InvalidParameter
;
1433 height
= abs(info
->bmiHeader
.biHeight
);
1434 stride
= ((info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
+ 31) >> 3) & ~3;
1436 if(info
->bmiHeader
.biHeight
> 0) /* bottom-up */
1438 bits
= (BYTE
*)bits
+ (height
- 1) * stride
;
1442 switch(info
->bmiHeader
.biBitCount
) {
1444 format
= PixelFormat1bppIndexed
;
1447 format
= PixelFormat4bppIndexed
;
1450 format
= PixelFormat8bppIndexed
;
1453 format
= PixelFormat16bppRGB555
;
1456 format
= PixelFormat24bppRGB
;
1459 format
= PixelFormat32bppRGB
;
1462 FIXME("don't know how to handle %d bpp\n", info
->bmiHeader
.biBitCount
);
1464 return InvalidParameter
;
1467 return GdipCreateBitmapFromScan0(info
->bmiHeader
.biWidth
, height
, stride
, format
,
1473 GpStatus WINGDIPAPI
GdipCreateBitmapFromFileICM(GDIPCONST WCHAR
* filename
,
1476 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
1478 return GdipCreateBitmapFromFile(filename
, bitmap
);
1481 GpStatus WINGDIPAPI
GdipCreateBitmapFromResource(HINSTANCE hInstance
,
1482 GDIPCONST WCHAR
* lpBitmapName
, GpBitmap
** bitmap
)
1485 GpStatus stat
= InvalidParameter
;
1487 TRACE("%p (%s) %p\n", hInstance
, debugstr_w(lpBitmapName
), bitmap
);
1489 if(!lpBitmapName
|| !bitmap
)
1490 return InvalidParameter
;
1493 hbm
= LoadImageW(hInstance
, lpBitmapName
, IMAGE_BITMAP
, 0, 0,
1494 LR_CREATEDIBSECTION
);
1497 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, bitmap
);
1504 GpStatus WINGDIPAPI
GdipCreateHBITMAPFromBitmap(GpBitmap
* bitmap
,
1505 HBITMAP
* hbmReturn
, ARGB background
)
1510 BITMAPINFOHEADER bih
;
1512 BitmapData lockeddata
;
1513 TRACE("(%p,%p,%x)\n", bitmap
, hbmReturn
, background
);
1515 if (!bitmap
|| !hbmReturn
) return InvalidParameter
;
1517 GdipGetImageWidth((GpImage
*)bitmap
, &width
);
1518 GdipGetImageHeight((GpImage
*)bitmap
, &height
);
1520 bih
.biSize
= sizeof(bih
);
1521 bih
.biWidth
= width
;
1522 bih
.biHeight
= height
;
1524 bih
.biBitCount
= 32;
1525 bih
.biCompression
= BI_RGB
;
1526 bih
.biSizeImage
= 0;
1527 bih
.biXPelsPerMeter
= 0;
1528 bih
.biYPelsPerMeter
= 0;
1530 bih
.biClrImportant
= 0;
1532 result
= CreateDIBSection(0, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1536 lockeddata
.Stride
= -width
* 4;
1537 lockeddata
.Scan0
= bits
+ (width
* 4 * (height
- 1));
1539 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1540 PixelFormat32bppPARGB
, &lockeddata
);
1543 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1546 stat
= GenericError
;
1548 if (stat
!= Ok
&& result
)
1550 DeleteObject(result
);
1554 *hbmReturn
= result
;
1559 GpStatus WINGDIPAPI
GdipConvertToEmfPlus(const GpGraphics
* ref
,
1560 GpMetafile
* metafile
, BOOL
* succ
, EmfType emfType
,
1561 const WCHAR
* description
, GpMetafile
** out_metafile
)
1565 TRACE("(%p,%p,%p,%u,%s,%p)\n", ref
, metafile
, succ
, emfType
,
1566 debugstr_w(description
), out_metafile
);
1568 if(!ref
|| !metafile
|| !out_metafile
)
1569 return InvalidParameter
;
1572 *out_metafile
= NULL
;
1575 FIXME("not implemented\n");
1577 return NotImplemented
;
1580 GpStatus WINGDIPAPI
GdipCreateBitmapFromGraphics(INT width
, INT height
,
1581 GpGraphics
* target
, GpBitmap
** bitmap
)
1585 TRACE("(%d, %d, %p, %p)\n", width
, height
, target
, bitmap
);
1587 if(!target
|| !bitmap
)
1588 return InvalidParameter
;
1590 ret
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat32bppPARGB
,
1595 GdipGetDpiX(target
, &(*bitmap
)->image
.xres
);
1596 GdipGetDpiY(target
, &(*bitmap
)->image
.yres
);
1602 GpStatus WINGDIPAPI
GdipCreateBitmapFromHICON(HICON hicon
, GpBitmap
** bitmap
)
1608 UINT width
, height
, stride
;
1610 BitmapData lockeddata
;
1614 BITMAPINFOHEADER bih
;
1619 TRACE("%p, %p\n", hicon
, bitmap
);
1621 if(!bitmap
|| !GetIconInfo(hicon
, &iinfo
))
1622 return InvalidParameter
;
1624 /* get the size of the icon */
1625 ret
= GetObjectA(iinfo
.hbmColor
? iinfo
.hbmColor
: iinfo
.hbmMask
, sizeof(bm
), &bm
);
1627 DeleteObject(iinfo
.hbmColor
);
1628 DeleteObject(iinfo
.hbmMask
);
1629 return GenericError
;
1633 height
= iinfo
.hbmColor
? abs(bm
.bmHeight
) : abs(bm
.bmHeight
) / 2;
1636 stat
= GdipCreateBitmapFromScan0(width
, height
, stride
, PixelFormat32bppARGB
, NULL
, bitmap
);
1638 DeleteObject(iinfo
.hbmColor
);
1639 DeleteObject(iinfo
.hbmMask
);
1646 rect
.Height
= height
;
1648 stat
= GdipBitmapLockBits(*bitmap
, &rect
, ImageLockModeWrite
, PixelFormat32bppARGB
, &lockeddata
);
1650 DeleteObject(iinfo
.hbmColor
);
1651 DeleteObject(iinfo
.hbmMask
);
1652 GdipDisposeImage((GpImage
*)*bitmap
);
1656 bih
.biSize
= sizeof(bih
);
1657 bih
.biWidth
= width
;
1658 bih
.biHeight
= iinfo
.hbmColor
? -height
: -height
* 2;
1660 bih
.biBitCount
= 32;
1661 bih
.biCompression
= BI_RGB
;
1662 bih
.biSizeImage
= 0;
1663 bih
.biXPelsPerMeter
= 0;
1664 bih
.biYPelsPerMeter
= 0;
1666 bih
.biClrImportant
= 0;
1668 screendc
= CreateCompatibleDC(0);
1671 GetDIBits(screendc
, iinfo
.hbmColor
, 0, height
, lockeddata
.Scan0
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1673 if (bm
.bmBitsPixel
== 32)
1677 /* If any pixel has a non-zero alpha, ignore hbmMask */
1678 src
= (DWORD
*)lockeddata
.Scan0
;
1679 for (x
=0; x
<width
&& !has_alpha
; x
++)
1680 for (y
=0; y
<height
&& !has_alpha
; y
++)
1681 if ((*src
++ & 0xff000000) != 0)
1684 else has_alpha
= FALSE
;
1688 GetDIBits(screendc
, iinfo
.hbmMask
, 0, height
, lockeddata
.Scan0
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1696 BYTE
*bits
= HeapAlloc(GetProcessHeap(), 0, height
* stride
);
1698 /* read alpha data from the mask */
1700 GetDIBits(screendc
, iinfo
.hbmMask
, 0, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1702 GetDIBits(screendc
, iinfo
.hbmMask
, height
, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1705 dst_row
= lockeddata
.Scan0
;
1706 for (y
=0; y
<height
; y
++)
1708 dst
= (DWORD
*)dst_row
;
1709 for (x
=0; x
<height
; x
++)
1711 DWORD src_value
= *src
++;
1715 *dst
++ |= 0xff000000;
1717 dst_row
+= lockeddata
.Stride
;
1720 HeapFree(GetProcessHeap(), 0, bits
);
1724 /* set constant alpha of 255 */
1725 dst_row
= lockeddata
.Scan0
;
1726 for (y
=0; y
<height
; y
++)
1728 dst
= (DWORD
*)dst_row
;
1729 for (x
=0; x
<height
; x
++)
1730 *dst
++ |= 0xff000000;
1731 dst_row
+= lockeddata
.Stride
;
1738 DeleteObject(iinfo
.hbmColor
);
1739 DeleteObject(iinfo
.hbmMask
);
1741 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
1746 static void generate_halftone_palette(ARGB
*entries
, UINT count
)
1748 static const BYTE halftone_values
[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1751 for (i
=0; i
<8 && i
<count
; i
++)
1753 entries
[i
] = 0xff000000;
1754 if (i
&1) entries
[i
] |= 0x800000;
1755 if (i
&2) entries
[i
] |= 0x8000;
1756 if (i
&4) entries
[i
] |= 0x80;
1760 entries
[i
] = 0xffc0c0c0;
1762 for (i
=9; i
<16 && i
<count
; i
++)
1764 entries
[i
] = 0xff000000;
1765 if (i
&1) entries
[i
] |= 0xff0000;
1766 if (i
&2) entries
[i
] |= 0xff00;
1767 if (i
&4) entries
[i
] |= 0xff;
1770 for (i
=16; i
<40 && i
<count
; i
++)
1775 for (i
=40; i
<256 && i
<count
; i
++)
1777 entries
[i
] = 0xff000000;
1778 entries
[i
] |= halftone_values
[(i
-40)%6];
1779 entries
[i
] |= halftone_values
[((i
-40)/6)%6] << 8;
1780 entries
[i
] |= halftone_values
[((i
-40)/36)%6] << 16;
1784 static GpStatus
get_screen_resolution(REAL
*xres
, REAL
*yres
)
1786 HDC screendc
= CreateCompatibleDC(0);
1788 if (!screendc
) return GenericError
;
1790 *xres
= (REAL
)GetDeviceCaps(screendc
, LOGPIXELSX
);
1791 *yres
= (REAL
)GetDeviceCaps(screendc
, LOGPIXELSY
);
1798 GpStatus WINGDIPAPI
GdipCreateBitmapFromScan0(INT width
, INT height
, INT stride
,
1799 PixelFormat format
, BYTE
* scan0
, GpBitmap
** bitmap
)
1802 HBITMAP hbitmap
=NULL
;
1803 INT row_size
, dib_stride
;
1804 BYTE
*bits
=NULL
, *own_bits
=NULL
;
1808 TRACE("%d %d %d 0x%x %p %p\n", width
, height
, stride
, format
, scan0
, bitmap
);
1810 if (!bitmap
) return InvalidParameter
;
1812 if(width
<= 0 || height
<= 0 || (scan0
&& (stride
% 4))){
1814 return InvalidParameter
;
1817 if(scan0
&& !stride
)
1818 return InvalidParameter
;
1820 stat
= get_screen_resolution(&xres
, &yres
);
1821 if (stat
!= Ok
) return stat
;
1823 row_size
= (width
* PIXELFORMATBPP(format
)+7) / 8;
1824 dib_stride
= (row_size
+ 3) & ~3;
1827 stride
= dib_stride
;
1829 if (format
& PixelFormatGDI
&& !(format
& (PixelFormatAlpha
|PixelFormatIndexed
)) && !scan0
)
1831 pbmi
= GdipAlloc(sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1835 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1836 pbmi
->bmiHeader
.biWidth
= width
;
1837 pbmi
->bmiHeader
.biHeight
= -height
;
1838 pbmi
->bmiHeader
.biPlanes
= 1;
1839 /* FIXME: use the rest of the data from format */
1840 pbmi
->bmiHeader
.biBitCount
= PIXELFORMATBPP(format
);
1841 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
1842 pbmi
->bmiHeader
.biSizeImage
= 0;
1843 pbmi
->bmiHeader
.biXPelsPerMeter
= 0;
1844 pbmi
->bmiHeader
.biYPelsPerMeter
= 0;
1845 pbmi
->bmiHeader
.biClrUsed
= 0;
1846 pbmi
->bmiHeader
.biClrImportant
= 0;
1848 hbitmap
= CreateDIBSection(0, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1852 if (!hbitmap
) return GenericError
;
1854 stride
= dib_stride
;
1858 /* Not a GDI format; don't try to make an HBITMAP. */
1863 INT size
= abs(stride
) * height
;
1865 own_bits
= bits
= GdipAlloc(size
);
1866 if (!own_bits
) return OutOfMemory
;
1869 bits
+= stride
* (1 - height
);
1873 *bitmap
= GdipAlloc(sizeof(GpBitmap
));
1876 DeleteObject(hbitmap
);
1881 (*bitmap
)->image
.type
= ImageTypeBitmap
;
1882 memcpy(&(*bitmap
)->image
.format
, &ImageFormatMemoryBMP
, sizeof(GUID
));
1883 (*bitmap
)->image
.flags
= ImageFlagsNone
;
1884 (*bitmap
)->image
.frame_count
= 1;
1885 (*bitmap
)->image
.current_frame
= 0;
1886 (*bitmap
)->image
.palette
= NULL
;
1887 (*bitmap
)->image
.xres
= xres
;
1888 (*bitmap
)->image
.yres
= yres
;
1889 (*bitmap
)->width
= width
;
1890 (*bitmap
)->height
= height
;
1891 (*bitmap
)->format
= format
;
1892 (*bitmap
)->image
.picture
= NULL
;
1893 (*bitmap
)->image
.stream
= NULL
;
1894 (*bitmap
)->hbitmap
= hbitmap
;
1895 (*bitmap
)->hdc
= NULL
;
1896 (*bitmap
)->bits
= bits
;
1897 (*bitmap
)->stride
= stride
;
1898 (*bitmap
)->own_bits
= own_bits
;
1899 (*bitmap
)->metadata_reader
= NULL
;
1900 (*bitmap
)->prop_count
= 0;
1901 (*bitmap
)->prop_item
= NULL
;
1903 /* set format-related flags */
1904 if (format
& (PixelFormatAlpha
|PixelFormatPAlpha
|PixelFormatIndexed
))
1905 (*bitmap
)->image
.flags
|= ImageFlagsHasAlpha
;
1907 if (format
== PixelFormat1bppIndexed
||
1908 format
== PixelFormat4bppIndexed
||
1909 format
== PixelFormat8bppIndexed
)
1911 (*bitmap
)->image
.palette
= GdipAlloc(sizeof(UINT
) * 2 + sizeof(ARGB
) * (1 << PIXELFORMATBPP(format
)));
1913 if (!(*bitmap
)->image
.palette
)
1915 GdipDisposeImage(&(*bitmap
)->image
);
1920 (*bitmap
)->image
.palette
->Count
= 1 << PIXELFORMATBPP(format
);
1922 if (format
== PixelFormat1bppIndexed
)
1924 (*bitmap
)->image
.palette
->Flags
= PaletteFlagsGrayScale
;
1925 (*bitmap
)->image
.palette
->Entries
[0] = 0xff000000;
1926 (*bitmap
)->image
.palette
->Entries
[1] = 0xffffffff;
1930 if (format
== PixelFormat8bppIndexed
)
1931 (*bitmap
)->image
.palette
->Flags
= PaletteFlagsHalftone
;
1933 generate_halftone_palette((*bitmap
)->image
.palette
->Entries
,
1934 (*bitmap
)->image
.palette
->Count
);
1938 TRACE("<-- %p\n", *bitmap
);
1943 GpStatus WINGDIPAPI
GdipCreateBitmapFromStream(IStream
* stream
,
1948 TRACE("%p %p\n", stream
, bitmap
);
1950 stat
= GdipLoadImageFromStream(stream
, (GpImage
**) bitmap
);
1955 if((*bitmap
)->image
.type
!= ImageTypeBitmap
){
1956 GdipDisposeImage(&(*bitmap
)->image
);
1958 return GenericError
; /* FIXME: what error to return? */
1965 GpStatus WINGDIPAPI
GdipCreateBitmapFromStreamICM(IStream
* stream
,
1968 TRACE("%p %p\n", stream
, bitmap
);
1970 return GdipCreateBitmapFromStream(stream
, bitmap
);
1973 GpStatus WINGDIPAPI
GdipCreateCachedBitmap(GpBitmap
*bitmap
, GpGraphics
*graphics
,
1974 GpCachedBitmap
**cachedbmp
)
1978 TRACE("%p %p %p\n", bitmap
, graphics
, cachedbmp
);
1980 if(!bitmap
|| !graphics
|| !cachedbmp
)
1981 return InvalidParameter
;
1983 *cachedbmp
= GdipAlloc(sizeof(GpCachedBitmap
));
1987 stat
= GdipCloneImage(&(bitmap
->image
), &(*cachedbmp
)->image
);
1989 GdipFree(*cachedbmp
);
1996 GpStatus WINGDIPAPI
GdipCreateHICONFromBitmap(GpBitmap
*bitmap
, HICON
*hicon
)
1999 BitmapData lockeddata
;
2000 ULONG andstride
, xorstride
, bitssize
;
2001 LPBYTE andbits
, xorbits
, androw
, xorrow
, srcrow
;
2004 TRACE("(%p, %p)\n", bitmap
, hicon
);
2006 if (!bitmap
|| !hicon
)
2007 return InvalidParameter
;
2009 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
,
2010 PixelFormat32bppPARGB
, &lockeddata
);
2013 andstride
= ((lockeddata
.Width
+31)/32)*4;
2014 xorstride
= lockeddata
.Width
*4;
2015 bitssize
= (andstride
+ xorstride
) * lockeddata
.Height
;
2017 andbits
= GdipAlloc(bitssize
);
2021 xorbits
= andbits
+ andstride
* lockeddata
.Height
;
2023 for (y
=0; y
<lockeddata
.Height
; y
++)
2025 srcrow
= ((LPBYTE
)lockeddata
.Scan0
) + lockeddata
.Stride
* y
;
2027 androw
= andbits
+ andstride
* y
;
2028 for (x
=0; x
<lockeddata
.Width
; x
++)
2029 if (srcrow
[3+4*x
] >= 128)
2030 androw
[x
/8] |= 1 << (7-x
%8);
2032 xorrow
= xorbits
+ xorstride
* y
;
2033 memcpy(xorrow
, srcrow
, xorstride
);
2036 *hicon
= CreateIcon(NULL
, lockeddata
.Width
, lockeddata
.Height
, 1, 32,
2044 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
2050 GpStatus WINGDIPAPI
GdipDeleteCachedBitmap(GpCachedBitmap
*cachedbmp
)
2052 TRACE("%p\n", cachedbmp
);
2055 return InvalidParameter
;
2057 GdipDisposeImage(cachedbmp
->image
);
2058 GdipFree(cachedbmp
);
2063 GpStatus WINGDIPAPI
GdipDrawCachedBitmap(GpGraphics
*graphics
,
2064 GpCachedBitmap
*cachedbmp
, INT x
, INT y
)
2066 TRACE("%p %p %d %d\n", graphics
, cachedbmp
, x
, y
);
2068 if(!graphics
|| !cachedbmp
)
2069 return InvalidParameter
;
2071 return GdipDrawImage(graphics
, cachedbmp
->image
, (REAL
)x
, (REAL
)y
);
2074 GpStatus WINGDIPAPI
GdipEmfToWmfBits(HENHMETAFILE hemf
, UINT cbData16
,
2075 LPBYTE pData16
, INT iMapMode
, INT eFlags
)
2077 FIXME("(%p, %d, %p, %d, %d): stub\n", hemf
, cbData16
, pData16
, iMapMode
, eFlags
);
2078 return NotImplemented
;
2081 /* Internal utility function: Replace the image data of dst with that of src,
2083 static void move_bitmap(GpBitmap
*dst
, GpBitmap
*src
, BOOL clobber_palette
)
2085 assert(src
->image
.type
== ImageTypeBitmap
);
2086 assert(dst
->image
.type
== ImageTypeBitmap
);
2088 GdipFree(dst
->bitmapbits
);
2089 GdipFree(dst
->own_bits
);
2091 DeleteObject(dst
->hbitmap
);
2093 if (clobber_palette
)
2095 GdipFree(dst
->image
.palette
);
2096 dst
->image
.palette
= src
->image
.palette
;
2099 GdipFree(src
->image
.palette
);
2101 dst
->image
.xres
= src
->image
.xres
;
2102 dst
->image
.yres
= src
->image
.yres
;
2103 dst
->width
= src
->width
;
2104 dst
->height
= src
->height
;
2105 dst
->format
= src
->format
;
2106 dst
->hbitmap
= src
->hbitmap
;
2107 dst
->hdc
= src
->hdc
;
2108 dst
->bits
= src
->bits
;
2109 dst
->stride
= src
->stride
;
2110 dst
->own_bits
= src
->own_bits
;
2111 if (dst
->metadata_reader
)
2112 IWICMetadataReader_Release(dst
->metadata_reader
);
2113 dst
->metadata_reader
= src
->metadata_reader
;
2114 GdipFree(dst
->prop_item
);
2115 dst
->prop_item
= src
->prop_item
;
2116 dst
->prop_count
= src
->prop_count
;
2117 if (dst
->image
.stream
)
2118 IStream_Release(dst
->image
.stream
);
2119 dst
->image
.stream
= src
->image
.stream
;
2120 dst
->image
.frame_count
= src
->image
.frame_count
;
2121 dst
->image
.current_frame
= src
->image
.current_frame
;
2122 dst
->image
.format
= src
->image
.format
;
2124 src
->image
.type
= ~0;
2128 static GpStatus
free_image_data(GpImage
*image
)
2131 return InvalidParameter
;
2133 if (image
->type
== ImageTypeBitmap
)
2135 GdipFree(((GpBitmap
*)image
)->bitmapbits
);
2136 GdipFree(((GpBitmap
*)image
)->own_bits
);
2137 DeleteDC(((GpBitmap
*)image
)->hdc
);
2138 DeleteObject(((GpBitmap
*)image
)->hbitmap
);
2139 if (((GpBitmap
*)image
)->metadata_reader
)
2140 IWICMetadataReader_Release(((GpBitmap
*)image
)->metadata_reader
);
2141 GdipFree(((GpBitmap
*)image
)->prop_item
);
2143 else if (image
->type
== ImageTypeMetafile
)
2145 GpMetafile
*metafile
= (GpMetafile
*)image
;
2146 GdipFree(metafile
->comment_data
);
2147 DeleteEnhMetaFile(CloseEnhMetaFile(metafile
->record_dc
));
2148 if (!metafile
->preserve_hemf
)
2149 DeleteEnhMetaFile(metafile
->hemf
);
2150 if (metafile
->record_graphics
)
2152 WARN("metafile closed while recording\n");
2153 /* not sure what to do here; for now just prevent the graphics from functioning or using this object */
2154 metafile
->record_graphics
->image
= NULL
;
2155 metafile
->record_graphics
->busy
= TRUE
;
2160 WARN("invalid image: %p\n", image
);
2164 IPicture_Release(image
->picture
);
2166 IStream_Release(image
->stream
);
2167 GdipFree(image
->palette
);
2172 GpStatus WINGDIPAPI
GdipDisposeImage(GpImage
*image
)
2176 TRACE("%p\n", image
);
2178 status
= free_image_data(image
);
2179 if (status
!= Ok
) return status
;
2186 GpStatus WINGDIPAPI
GdipFindFirstImageItem(GpImage
*image
, ImageItemData
* item
)
2190 TRACE("(%p,%p)\n", image
, item
);
2193 return InvalidParameter
;
2196 FIXME("not implemented\n");
2198 return NotImplemented
;
2201 GpStatus WINGDIPAPI
GdipGetImageItemData(GpImage
*image
, ImageItemData
*item
)
2205 TRACE("(%p,%p)\n", image
, item
);
2208 FIXME("not implemented\n");
2210 return NotImplemented
;
2213 GpStatus WINGDIPAPI
GdipGetImageBounds(GpImage
*image
, GpRectF
*srcRect
,
2216 TRACE("%p %p %p\n", image
, srcRect
, srcUnit
);
2218 if(!image
|| !srcRect
|| !srcUnit
)
2219 return InvalidParameter
;
2220 if(image
->type
== ImageTypeMetafile
){
2221 *srcRect
= ((GpMetafile
*)image
)->bounds
;
2222 *srcUnit
= ((GpMetafile
*)image
)->unit
;
2224 else if(image
->type
== ImageTypeBitmap
){
2225 srcRect
->X
= srcRect
->Y
= 0.0;
2226 srcRect
->Width
= (REAL
) ((GpBitmap
*)image
)->width
;
2227 srcRect
->Height
= (REAL
) ((GpBitmap
*)image
)->height
;
2228 *srcUnit
= UnitPixel
;
2231 srcRect
->X
= srcRect
->Y
= 0.0;
2232 srcRect
->Width
= ipicture_pixel_width(image
->picture
);
2233 srcRect
->Height
= ipicture_pixel_height(image
->picture
);
2234 *srcUnit
= UnitPixel
;
2237 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect
->X
, srcRect
->Y
,
2238 srcRect
->Width
, srcRect
->Height
, *srcUnit
);
2243 GpStatus WINGDIPAPI
GdipGetImageDimension(GpImage
*image
, REAL
*width
,
2246 TRACE("%p %p %p\n", image
, width
, height
);
2248 if(!image
|| !height
|| !width
)
2249 return InvalidParameter
;
2251 if(image
->type
== ImageTypeMetafile
){
2252 *height
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Height
, ((GpMetafile
*)image
)->unit
, image
->yres
);
2253 *width
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Width
, ((GpMetafile
*)image
)->unit
, image
->xres
);
2255 else if(image
->type
== ImageTypeBitmap
){
2256 *height
= ((GpBitmap
*)image
)->height
;
2257 *width
= ((GpBitmap
*)image
)->width
;
2260 *height
= ipicture_pixel_height(image
->picture
);
2261 *width
= ipicture_pixel_width(image
->picture
);
2264 TRACE("returning (%f, %f)\n", *height
, *width
);
2268 GpStatus WINGDIPAPI
GdipGetImageGraphicsContext(GpImage
*image
,
2269 GpGraphics
**graphics
)
2274 TRACE("%p %p\n", image
, graphics
);
2276 if(!image
|| !graphics
)
2277 return InvalidParameter
;
2279 if (image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)image
)->hbitmap
)
2281 hdc
= ((GpBitmap
*)image
)->hdc
;
2284 hdc
= CreateCompatibleDC(0);
2285 SelectObject(hdc
, ((GpBitmap
*)image
)->hbitmap
);
2286 ((GpBitmap
*)image
)->hdc
= hdc
;
2289 stat
= GdipCreateFromHDC(hdc
, graphics
);
2293 (*graphics
)->image
= image
;
2294 (*graphics
)->xres
= image
->xres
;
2295 (*graphics
)->yres
= image
->yres
;
2298 else if (image
->type
== ImageTypeMetafile
)
2299 stat
= METAFILE_GetGraphicsContext((GpMetafile
*)image
, graphics
);
2301 stat
= graphics_from_image(image
, graphics
);
2306 GpStatus WINGDIPAPI
GdipGetImageHeight(GpImage
*image
, UINT
*height
)
2308 TRACE("%p %p\n", image
, height
);
2310 if(!image
|| !height
)
2311 return InvalidParameter
;
2313 if(image
->type
== ImageTypeMetafile
)
2314 *height
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Height
, ((GpMetafile
*)image
)->unit
, image
->yres
);
2315 else if(image
->type
== ImageTypeBitmap
)
2316 *height
= ((GpBitmap
*)image
)->height
;
2318 *height
= ipicture_pixel_height(image
->picture
);
2320 TRACE("returning %d\n", *height
);
2325 GpStatus WINGDIPAPI
GdipGetImageHorizontalResolution(GpImage
*image
, REAL
*res
)
2328 return InvalidParameter
;
2332 TRACE("(%p) <-- %0.2f\n", image
, *res
);
2337 GpStatus WINGDIPAPI
GdipGetImagePaletteSize(GpImage
*image
, INT
*size
)
2339 TRACE("%p %p\n", image
, size
);
2342 return InvalidParameter
;
2344 if (!image
->palette
|| image
->palette
->Count
== 0)
2345 *size
= sizeof(ColorPalette
);
2347 *size
= sizeof(UINT
)*2 + sizeof(ARGB
)*image
->palette
->Count
;
2349 TRACE("<-- %u\n", *size
);
2354 /* FIXME: test this function for non-bitmap types */
2355 GpStatus WINGDIPAPI
GdipGetImagePixelFormat(GpImage
*image
, PixelFormat
*format
)
2357 TRACE("%p %p\n", image
, format
);
2359 if(!image
|| !format
)
2360 return InvalidParameter
;
2362 if(image
->type
!= ImageTypeBitmap
)
2363 *format
= PixelFormat24bppRGB
;
2365 *format
= ((GpBitmap
*) image
)->format
;
2370 GpStatus WINGDIPAPI
GdipGetImageRawFormat(GpImage
*image
, GUID
*format
)
2372 TRACE("(%p, %p)\n", image
, format
);
2374 if(!image
|| !format
)
2375 return InvalidParameter
;
2377 memcpy(format
, &image
->format
, sizeof(GUID
));
2382 GpStatus WINGDIPAPI
GdipGetImageType(GpImage
*image
, ImageType
*type
)
2384 TRACE("%p %p\n", image
, type
);
2387 return InvalidParameter
;
2389 *type
= image
->type
;
2394 GpStatus WINGDIPAPI
GdipGetImageVerticalResolution(GpImage
*image
, REAL
*res
)
2397 return InvalidParameter
;
2401 TRACE("(%p) <-- %0.2f\n", image
, *res
);
2406 GpStatus WINGDIPAPI
GdipGetImageWidth(GpImage
*image
, UINT
*width
)
2408 TRACE("%p %p\n", image
, width
);
2410 if(!image
|| !width
)
2411 return InvalidParameter
;
2413 if(image
->type
== ImageTypeMetafile
)
2414 *width
= units_to_pixels(((GpMetafile
*)image
)->bounds
.Width
, ((GpMetafile
*)image
)->unit
, image
->xres
);
2415 else if(image
->type
== ImageTypeBitmap
)
2416 *width
= ((GpBitmap
*)image
)->width
;
2418 *width
= ipicture_pixel_width(image
->picture
);
2420 TRACE("returning %d\n", *width
);
2425 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromMetafile(GpMetafile
* metafile
,
2426 MetafileHeader
* header
)
2430 TRACE("(%p, %p)\n", metafile
, header
);
2432 if(!metafile
|| !header
)
2433 return InvalidParameter
;
2436 FIXME("not implemented\n");
2438 memset(header
, 0, sizeof(MetafileHeader
));
2443 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromEmf(HENHMETAFILE hEmf
,
2444 MetafileHeader
*header
)
2448 if(!hEmf
|| !header
)
2449 return InvalidParameter
;
2452 FIXME("not implemented\n");
2454 memset(header
, 0, sizeof(MetafileHeader
));
2459 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromFile(GDIPCONST WCHAR
*filename
,
2460 MetafileHeader
*header
)
2464 TRACE("(%s,%p)\n", debugstr_w(filename
), header
);
2466 if(!filename
|| !header
)
2467 return InvalidParameter
;
2470 FIXME("not implemented\n");
2472 memset(header
, 0, sizeof(MetafileHeader
));
2477 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromStream(IStream
*stream
,
2478 MetafileHeader
*header
)
2482 TRACE("(%p,%p)\n", stream
, header
);
2484 if(!stream
|| !header
)
2485 return InvalidParameter
;
2488 FIXME("not implemented\n");
2490 memset(header
, 0, sizeof(MetafileHeader
));
2495 GpStatus WINGDIPAPI
GdipGetPropertyCount(GpImage
*image
, UINT
*num
)
2497 TRACE("(%p, %p)\n", image
, num
);
2499 if (!image
|| !num
) return InvalidParameter
;
2503 if (image
->type
== ImageTypeBitmap
)
2505 if (((GpBitmap
*)image
)->prop_item
)
2507 *num
= ((GpBitmap
*)image
)->prop_count
;
2511 if (((GpBitmap
*)image
)->metadata_reader
)
2512 IWICMetadataReader_GetCount(((GpBitmap
*)image
)->metadata_reader
, num
);
2518 GpStatus WINGDIPAPI
GdipGetPropertyIdList(GpImage
*image
, UINT num
, PROPID
*list
)
2521 IWICMetadataReader
*reader
;
2522 IWICEnumMetadataItem
*enumerator
;
2523 UINT prop_count
, i
, items_returned
;
2525 TRACE("(%p, %u, %p)\n", image
, num
, list
);
2527 if (!image
|| !list
) return InvalidParameter
;
2529 if (image
->type
!= ImageTypeBitmap
)
2531 FIXME("Not implemented for type %d\n", image
->type
);
2532 return NotImplemented
;
2535 if (((GpBitmap
*)image
)->prop_item
)
2537 if (num
!= ((GpBitmap
*)image
)->prop_count
) return InvalidParameter
;
2539 for (i
= 0; i
< num
; i
++)
2541 list
[i
] = ((GpBitmap
*)image
)->prop_item
[i
].id
;
2547 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2550 if (num
!= 0) return InvalidParameter
;
2554 hr
= IWICMetadataReader_GetCount(reader
, &prop_count
);
2555 if (FAILED(hr
)) return hresult_to_status(hr
);
2557 if (num
!= prop_count
) return InvalidParameter
;
2559 hr
= IWICMetadataReader_GetEnumerator(reader
, &enumerator
);
2560 if (FAILED(hr
)) return hresult_to_status(hr
);
2562 IWICEnumMetadataItem_Reset(enumerator
);
2564 for (i
= 0; i
< num
; i
++)
2568 hr
= IWICEnumMetadataItem_Next(enumerator
, 1, NULL
, &id
, NULL
, &items_returned
);
2569 if (hr
!= S_OK
) break;
2571 if (id
.vt
!= VT_UI2
)
2573 FIXME("not supported propvariant type for id: %u\n", id
.vt
);
2577 list
[i
] = id
.u
.uiVal
;
2580 IWICEnumMetadataItem_Release(enumerator
);
2582 return hr
== S_OK
? Ok
: hresult_to_status(hr
);
2585 static UINT
propvariant_size(PROPVARIANT
*value
)
2587 switch (value
->vt
& ~VT_VECTOR
)
2593 if (!(value
->vt
& VT_VECTOR
)) return 1;
2594 return value
->u
.caub
.cElems
;
2597 if (!(value
->vt
& VT_VECTOR
)) return 2;
2598 return value
->u
.caui
.cElems
* 2;
2602 if (!(value
->vt
& VT_VECTOR
)) return 4;
2603 return value
->u
.caul
.cElems
* 4;
2607 if (!(value
->vt
& VT_VECTOR
)) return 8;
2608 return value
->u
.cauh
.cElems
* 8;
2610 return value
->u
.pszVal
? strlen(value
->u
.pszVal
) + 1 : 0;
2612 return value
->u
.blob
.cbSize
;
2614 FIXME("not supported variant type %d\n", value
->vt
);
2619 GpStatus WINGDIPAPI
GdipGetPropertyItemSize(GpImage
*image
, PROPID propid
, UINT
*size
)
2622 IWICMetadataReader
*reader
;
2623 PROPVARIANT id
, value
;
2625 TRACE("(%p,%#x,%p)\n", image
, propid
, size
);
2627 if (!size
|| !image
) return InvalidParameter
;
2629 if (image
->type
!= ImageTypeBitmap
)
2631 FIXME("Not implemented for type %d\n", image
->type
);
2632 return NotImplemented
;
2635 if (((GpBitmap
*)image
)->prop_item
)
2639 for (i
= 0; i
< ((GpBitmap
*)image
)->prop_count
; i
++)
2641 if (propid
== ((GpBitmap
*)image
)->prop_item
[i
].id
)
2643 *size
= sizeof(PropertyItem
) + ((GpBitmap
*)image
)->prop_item
[i
].length
;
2648 return PropertyNotFound
;
2651 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2652 if (!reader
) return PropertyNotFound
;
2655 id
.u
.uiVal
= propid
;
2656 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
2657 if (FAILED(hr
)) return PropertyNotFound
;
2659 *size
= propvariant_size(&value
);
2660 if (*size
) *size
+= sizeof(PropertyItem
);
2661 PropVariantClear(&value
);
2666 #ifndef PropertyTagTypeSByte
2667 #define PropertyTagTypeSByte 6
2668 #define PropertyTagTypeSShort 8
2669 #define PropertyTagTypeFloat 11
2670 #define PropertyTagTypeDouble 12
2673 static UINT
vt_to_itemtype(UINT vt
)
2680 { VT_I1
, PropertyTagTypeSByte
},
2681 { VT_UI1
, PropertyTagTypeByte
},
2682 { VT_I2
, PropertyTagTypeSShort
},
2683 { VT_UI2
, PropertyTagTypeShort
},
2684 { VT_I4
, PropertyTagTypeSLONG
},
2685 { VT_UI4
, PropertyTagTypeLong
},
2686 { VT_I8
, PropertyTagTypeSRational
},
2687 { VT_UI8
, PropertyTagTypeRational
},
2688 { VT_R4
, PropertyTagTypeFloat
},
2689 { VT_R8
, PropertyTagTypeDouble
},
2690 { VT_LPSTR
, PropertyTagTypeASCII
},
2691 { VT_BLOB
, PropertyTagTypeUndefined
}
2694 for (i
= 0; i
< sizeof(vt2type
)/sizeof(vt2type
[0]); i
++)
2696 if (vt2type
[i
].vt
== vt
) return vt2type
[i
].type
;
2698 FIXME("not supported variant type %u\n", vt
);
2702 static GpStatus
propvariant_to_item(PROPVARIANT
*value
, PropertyItem
*item
,
2703 UINT size
, PROPID id
)
2705 UINT item_size
, item_type
;
2707 item_size
= propvariant_size(value
);
2708 if (size
!= item_size
+ sizeof(PropertyItem
)) return InvalidParameter
;
2710 item_type
= vt_to_itemtype(value
->vt
& ~VT_VECTOR
);
2711 if (!item_type
) return InvalidParameter
;
2713 item
->value
= item
+ 1;
2715 switch (value
->vt
& ~VT_VECTOR
)
2719 if (!(value
->vt
& VT_VECTOR
))
2720 *(BYTE
*)item
->value
= value
->u
.bVal
;
2722 memcpy(item
->value
, value
->u
.caub
.pElems
, item_size
);
2726 if (!(value
->vt
& VT_VECTOR
))
2727 *(USHORT
*)item
->value
= value
->u
.uiVal
;
2729 memcpy(item
->value
, value
->u
.caui
.pElems
, item_size
);
2734 if (!(value
->vt
& VT_VECTOR
))
2735 *(ULONG
*)item
->value
= value
->u
.ulVal
;
2737 memcpy(item
->value
, value
->u
.caul
.pElems
, item_size
);
2742 if (!(value
->vt
& VT_VECTOR
))
2743 *(ULONGLONG
*)item
->value
= value
->u
.uhVal
.QuadPart
;
2745 memcpy(item
->value
, value
->u
.cauh
.pElems
, item_size
);
2748 memcpy(item
->value
, value
->u
.pszVal
, item_size
);
2751 memcpy(item
->value
, value
->u
.blob
.pBlobData
, item_size
);
2754 FIXME("not supported variant type %d\n", value
->vt
);
2755 return InvalidParameter
;
2758 item
->length
= item_size
;
2759 item
->type
= item_type
;
2765 GpStatus WINGDIPAPI
GdipGetPropertyItem(GpImage
*image
, PROPID propid
, UINT size
,
2766 PropertyItem
*buffer
)
2770 IWICMetadataReader
*reader
;
2771 PROPVARIANT id
, value
;
2773 TRACE("(%p,%#x,%u,%p)\n", image
, propid
, size
, buffer
);
2775 if (!image
|| !buffer
) return InvalidParameter
;
2777 if (image
->type
!= ImageTypeBitmap
)
2779 FIXME("Not implemented for type %d\n", image
->type
);
2780 return NotImplemented
;
2783 if (((GpBitmap
*)image
)->prop_item
)
2787 for (i
= 0; i
< ((GpBitmap
*)image
)->prop_count
; i
++)
2789 if (propid
== ((GpBitmap
*)image
)->prop_item
[i
].id
)
2791 if (size
!= sizeof(PropertyItem
) + ((GpBitmap
*)image
)->prop_item
[i
].length
)
2792 return InvalidParameter
;
2794 *buffer
= ((GpBitmap
*)image
)->prop_item
[i
];
2795 buffer
->value
= buffer
+ 1;
2796 memcpy(buffer
->value
, ((GpBitmap
*)image
)->prop_item
[i
].value
, buffer
->length
);
2801 return PropertyNotFound
;
2804 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2805 if (!reader
) return PropertyNotFound
;
2808 id
.u
.uiVal
= propid
;
2809 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
2810 if (FAILED(hr
)) return PropertyNotFound
;
2812 stat
= propvariant_to_item(&value
, buffer
, size
, propid
);
2813 PropVariantClear(&value
);
2818 GpStatus WINGDIPAPI
GdipGetPropertySize(GpImage
*image
, UINT
*size
, UINT
*count
)
2821 IWICMetadataReader
*reader
;
2822 IWICEnumMetadataItem
*enumerator
;
2823 UINT prop_count
, prop_size
, i
;
2824 PROPVARIANT id
, value
;
2826 TRACE("(%p,%p,%p)\n", image
, size
, count
);
2828 if (!image
|| !size
|| !count
) return InvalidParameter
;
2830 if (image
->type
!= ImageTypeBitmap
)
2832 FIXME("Not implemented for type %d\n", image
->type
);
2833 return NotImplemented
;
2836 if (((GpBitmap
*)image
)->prop_item
)
2838 *count
= ((GpBitmap
*)image
)->prop_count
;
2841 for (i
= 0; i
< ((GpBitmap
*)image
)->prop_count
; i
++)
2843 *size
+= sizeof(PropertyItem
) + ((GpBitmap
*)image
)->prop_item
[i
].length
;
2849 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2850 if (!reader
) return PropertyNotFound
;
2852 hr
= IWICMetadataReader_GetCount(reader
, &prop_count
);
2853 if (FAILED(hr
)) return hresult_to_status(hr
);
2855 hr
= IWICMetadataReader_GetEnumerator(reader
, &enumerator
);
2856 if (FAILED(hr
)) return hresult_to_status(hr
);
2858 IWICEnumMetadataItem_Reset(enumerator
);
2862 PropVariantInit(&id
);
2863 PropVariantInit(&value
);
2865 for (i
= 0; i
< prop_count
; i
++)
2867 UINT items_returned
, item_size
;
2869 hr
= IWICEnumMetadataItem_Next(enumerator
, 1, NULL
, &id
, &value
, &items_returned
);
2870 if (hr
!= S_OK
) break;
2872 item_size
= propvariant_size(&value
);
2873 if (item_size
) prop_size
+= sizeof(PropertyItem
) + item_size
;
2875 PropVariantClear(&id
);
2876 PropVariantClear(&value
);
2879 IWICEnumMetadataItem_Release(enumerator
);
2881 if (hr
!= S_OK
) return PropertyNotFound
;
2883 *count
= prop_count
;
2888 GpStatus WINGDIPAPI
GdipGetAllPropertyItems(GpImage
*image
, UINT size
,
2889 UINT count
, PropertyItem
*buf
)
2893 IWICMetadataReader
*reader
;
2894 IWICEnumMetadataItem
*enumerator
;
2895 UINT prop_count
, prop_size
, i
;
2896 PROPVARIANT id
, value
;
2899 TRACE("(%p,%u,%u,%p)\n", image
, size
, count
, buf
);
2901 if (!image
|| !buf
) return InvalidParameter
;
2903 if (image
->type
!= ImageTypeBitmap
)
2905 FIXME("Not implemented for type %d\n", image
->type
);
2906 return NotImplemented
;
2909 status
= GdipGetPropertySize(image
, &prop_size
, &prop_count
);
2910 if (status
!= Ok
) return status
;
2912 if (prop_count
!= count
|| prop_size
!= size
) return InvalidParameter
;
2914 if (((GpBitmap
*)image
)->prop_item
)
2916 memcpy(buf
, ((GpBitmap
*)image
)->prop_item
, prop_size
);
2918 item_value
= (char *)(buf
+ prop_count
);
2920 for (i
= 0; i
< prop_count
; i
++)
2922 buf
[i
].value
= item_value
;
2923 item_value
+= buf
[i
].length
;
2929 reader
= ((GpBitmap
*)image
)->metadata_reader
;
2930 if (!reader
) return PropertyNotFound
;
2932 hr
= IWICMetadataReader_GetEnumerator(reader
, &enumerator
);
2933 if (FAILED(hr
)) return hresult_to_status(hr
);
2935 IWICEnumMetadataItem_Reset(enumerator
);
2937 item_value
= (char *)(buf
+ prop_count
);
2939 PropVariantInit(&id
);
2940 PropVariantInit(&value
);
2942 for (i
= 0; i
< prop_count
; i
++)
2945 UINT items_returned
, item_size
;
2947 hr
= IWICEnumMetadataItem_Next(enumerator
, 1, NULL
, &id
, &value
, &items_returned
);
2948 if (hr
!= S_OK
) break;
2950 if (id
.vt
!= VT_UI2
)
2952 FIXME("not supported propvariant type for id: %u\n", id
.vt
);
2956 item_size
= propvariant_size(&value
);
2959 item
= HeapAlloc(GetProcessHeap(), 0, item_size
+ sizeof(*item
));
2961 propvariant_to_item(&value
, item
, item_size
+ sizeof(*item
), id
.u
.uiVal
);
2962 buf
[i
].id
= item
->id
;
2963 buf
[i
].type
= item
->type
;
2964 buf
[i
].length
= item_size
;
2965 buf
[i
].value
= item_value
;
2966 memcpy(item_value
, item
->value
, item_size
);
2967 item_value
+= item_size
;
2969 HeapFree(GetProcessHeap(), 0, item
);
2972 PropVariantClear(&id
);
2973 PropVariantClear(&value
);
2976 IWICEnumMetadataItem_Release(enumerator
);
2978 if (hr
!= S_OK
) return PropertyNotFound
;
2983 struct image_format_dimension
2986 const GUID
*dimension
;
2989 static const struct image_format_dimension image_format_dimensions
[] =
2991 {&ImageFormatGIF
, &FrameDimensionTime
},
2992 {&ImageFormatIcon
, &FrameDimensionResolution
},
2996 GpStatus WINGDIPAPI
GdipImageGetFrameCount(GpImage
*image
,
2997 GDIPCONST GUID
* dimensionID
, UINT
* count
)
2999 TRACE("(%p,%s,%p)\n", image
, debugstr_guid(dimensionID
), count
);
3001 if(!image
|| !count
)
3002 return InvalidParameter
;
3005 IsEqualGUID(dimensionID
, &image
->format
) ||
3006 IsEqualGUID(dimensionID
, &FrameDimensionPage
) ||
3007 IsEqualGUID(dimensionID
, &FrameDimensionTime
))
3009 *count
= image
->frame_count
;
3013 return InvalidParameter
;
3016 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsCount(GpImage
*image
,
3019 TRACE("(%p, %p)\n", image
, count
);
3021 /* Native gdiplus 1.1 does not yet support multiple frame dimensions. */
3023 if(!image
|| !count
)
3024 return InvalidParameter
;
3031 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsList(GpImage
* image
,
3032 GUID
* dimensionIDs
, UINT count
)
3035 const GUID
*result
=NULL
;
3037 TRACE("(%p,%p,%u)\n", image
, dimensionIDs
, count
);
3039 if(!image
|| !dimensionIDs
|| count
!= 1)
3040 return InvalidParameter
;
3042 for (i
=0; image_format_dimensions
[i
].format
; i
++)
3044 if (IsEqualGUID(&image
->format
, image_format_dimensions
[i
].format
))
3046 result
= image_format_dimensions
[i
].dimension
;
3052 result
= &FrameDimensionPage
;
3054 memcpy(dimensionIDs
, result
, sizeof(GUID
));
3059 GpStatus WINGDIPAPI
GdipLoadImageFromFile(GDIPCONST WCHAR
* filename
,
3065 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
3067 if (!filename
|| !image
)
3068 return InvalidParameter
;
3070 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
3075 stat
= GdipLoadImageFromStream(stream
, image
);
3077 IStream_Release(stream
);
3082 /* FIXME: no icm handling */
3083 GpStatus WINGDIPAPI
GdipLoadImageFromFileICM(GDIPCONST WCHAR
* filename
,GpImage
**image
)
3085 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
3087 return GdipLoadImageFromFile(filename
, image
);
3090 static void add_property(GpBitmap
*bitmap
, PropertyItem
*item
)
3092 UINT prop_size
, prop_count
;
3093 PropertyItem
*prop_item
;
3095 if (bitmap
->prop_item
== NULL
)
3097 prop_size
= prop_count
= 0;
3098 prop_item
= GdipAlloc(item
->length
+ sizeof(PropertyItem
));
3099 if (!prop_item
) return;
3106 GdipGetPropertySize((GpImage
*)bitmap
, &prop_size
, &prop_count
);
3108 prop_item
= GdipAlloc(prop_size
+ item
->length
+ sizeof(PropertyItem
));
3109 if (!prop_item
) return;
3110 memcpy(prop_item
, bitmap
->prop_item
, sizeof(PropertyItem
) * bitmap
->prop_count
);
3111 prop_size
-= sizeof(PropertyItem
) * bitmap
->prop_count
;
3112 memcpy(prop_item
+ prop_count
+ 1, bitmap
->prop_item
+ prop_count
, prop_size
);
3114 item_value
= (char *)(prop_item
+ prop_count
+ 1);
3116 for (i
= 0; i
< prop_count
; i
++)
3118 prop_item
[i
].value
= item_value
;
3119 item_value
+= prop_item
[i
].length
;
3123 prop_item
[prop_count
].id
= item
->id
;
3124 prop_item
[prop_count
].type
= item
->type
;
3125 prop_item
[prop_count
].length
= item
->length
;
3126 prop_item
[prop_count
].value
= (char *)(prop_item
+ prop_count
+ 1) + prop_size
;
3127 memcpy(prop_item
[prop_count
].value
, item
->value
, item
->length
);
3129 GdipFree(bitmap
->prop_item
);
3130 bitmap
->prop_item
= prop_item
;
3131 bitmap
->prop_count
++;
3134 static BOOL
get_bool_property(IWICMetadataReader
*reader
, const GUID
*guid
, const WCHAR
*prop_name
)
3138 PROPVARIANT id
, value
;
3141 IWICMetadataReader_GetMetadataFormat(reader
, &format
);
3142 if (!IsEqualGUID(&format
, guid
)) return FALSE
;
3144 PropVariantInit(&id
);
3145 PropVariantInit(&value
);
3148 id
.u
.pwszVal
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(prop_name
) + 1) * sizeof(WCHAR
));
3149 if (!id
.u
.pwszVal
) return FALSE
;
3150 lstrcpyW(id
.u
.pwszVal
, prop_name
);
3151 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
3152 if (hr
== S_OK
&& value
.vt
== VT_BOOL
)
3153 ret
= value
.u
.boolVal
;
3155 PropVariantClear(&id
);
3156 PropVariantClear(&value
);
3161 static PropertyItem
*get_property(IWICMetadataReader
*reader
, const GUID
*guid
, const WCHAR
*prop_name
)
3165 PROPVARIANT id
, value
;
3166 PropertyItem
*item
= NULL
;
3168 IWICMetadataReader_GetMetadataFormat(reader
, &format
);
3169 if (!IsEqualGUID(&format
, guid
)) return NULL
;
3171 PropVariantInit(&id
);
3172 PropVariantInit(&value
);
3175 id
.u
.pwszVal
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(prop_name
) + 1) * sizeof(WCHAR
));
3176 if (!id
.u
.pwszVal
) return NULL
;
3177 lstrcpyW(id
.u
.pwszVal
, prop_name
);
3178 hr
= IWICMetadataReader_GetValue(reader
, NULL
, &id
, &value
);
3181 UINT item_size
= propvariant_size(&value
);
3184 item_size
+= sizeof(*item
);
3185 item
= GdipAlloc(item_size
);
3186 if (propvariant_to_item(&value
, item
, item_size
, 0) != Ok
)
3194 PropVariantClear(&id
);
3195 PropVariantClear(&value
);
3200 static PropertyItem
*get_gif_comment(IWICMetadataReader
*reader
)
3202 static const WCHAR textentryW
[] = { 'T','e','x','t','E','n','t','r','y',0 };
3203 PropertyItem
*comment
;
3205 comment
= get_property(reader
, &GUID_MetadataFormatGifComment
, textentryW
);
3207 comment
->id
= PropertyTagExifUserComment
;
3212 static PropertyItem
*get_gif_loopcount(IWICMetadataReader
*reader
)
3214 static const WCHAR applicationW
[] = { 'A','p','p','l','i','c','a','t','i','o','n',0 };
3215 static const WCHAR dataW
[] = { 'D','a','t','a',0 };
3216 PropertyItem
*appext
= NULL
, *appdata
= NULL
, *loop
= NULL
;
3218 appext
= get_property(reader
, &GUID_MetadataFormatAPE
, applicationW
);
3221 if (appext
->type
== PropertyTagTypeByte
&& appext
->length
== 11 &&
3222 (!memcmp(appext
->value
, "NETSCAPE2.0", 11) || !memcmp(appext
->value
, "ANIMEXTS1.0", 11)))
3224 appdata
= get_property(reader
, &GUID_MetadataFormatAPE
, dataW
);
3227 if (appdata
->type
== PropertyTagTypeByte
&& appdata
->length
== 4)
3229 BYTE
*data
= appdata
->value
;
3230 if (data
[0] == 3 && data
[1] == 1)
3232 loop
= GdipAlloc(sizeof(*loop
) + sizeof(SHORT
));
3235 loop
->type
= PropertyTagTypeShort
;
3236 loop
->id
= PropertyTagLoopCount
;
3237 loop
->length
= sizeof(SHORT
);
3238 loop
->value
= loop
+ 1;
3239 *(SHORT
*)loop
->value
= data
[2] | (data
[3] << 8);
3253 static PropertyItem
*get_gif_background(IWICMetadataReader
*reader
)
3255 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 };
3256 PropertyItem
*background
;
3258 background
= get_property(reader
, &GUID_MetadataFormatLSD
, backgroundW
);
3260 background
->id
= PropertyTagIndexBackground
;
3265 static PropertyItem
*get_gif_palette(IWICBitmapDecoder
*decoder
, IWICMetadataReader
*reader
)
3267 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 };
3269 IWICImagingFactory
*factory
;
3270 IWICPalette
*palette
;
3272 WICColor colors
[256];
3274 if (!get_bool_property(reader
, &GUID_MetadataFormatLSD
, global_flagW
))
3277 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
,
3278 &IID_IWICImagingFactory
, (void **)&factory
);
3279 if (hr
!= S_OK
) return NULL
;
3281 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
3284 hr
= IWICBitmapDecoder_CopyPalette(decoder
, palette
);
3286 IWICPalette_GetColors(palette
, 256, colors
, &count
);
3288 IWICPalette_Release(palette
);
3291 IWICImagingFactory_Release(factory
);
3299 pal
= GdipAlloc(sizeof(*pal
) + count
* 3);
3300 if (!pal
) return NULL
;
3301 pal
->type
= PropertyTagTypeByte
;
3302 pal
->id
= PropertyTagGlobalPalette
;
3303 pal
->value
= pal
+ 1;
3304 pal
->length
= count
* 3;
3308 for (i
= 0; i
< count
; i
++)
3310 rgb
[i
*3] = (colors
[i
] >> 16) & 0xff;
3311 rgb
[i
*3 + 1] = (colors
[i
] >> 8) & 0xff;
3312 rgb
[i
*3 + 2] = colors
[i
] & 0xff;
3321 static PropertyItem
*get_gif_transparent_idx(IWICMetadataReader
*reader
)
3323 static const WCHAR transparency_flagW
[] = { 'T','r','a','n','s','p','a','r','e','n','c','y','F','l','a','g',0 };
3324 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 };
3325 PropertyItem
*index
= NULL
;
3327 if (get_bool_property(reader
, &GUID_MetadataFormatGCE
, transparency_flagW
))
3329 index
= get_property(reader
, &GUID_MetadataFormatGCE
, colorW
);
3331 index
->id
= PropertyTagIndexTransparent
;
3336 static LONG
get_gif_frame_delay(IWICBitmapFrameDecode
*frame
)
3338 static const WCHAR delayW
[] = { 'D','e','l','a','y',0 };
3340 IWICMetadataBlockReader
*block_reader
;
3341 IWICMetadataReader
*reader
;
3342 UINT block_count
, i
;
3343 PropertyItem
*delay
;
3346 hr
= IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3349 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3352 for (i
= 0; i
< block_count
; i
++)
3354 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3357 delay
= get_property(reader
, &GUID_MetadataFormatGCE
, delayW
);
3360 if (delay
->type
== PropertyTagTypeShort
&& delay
->length
== 2)
3361 value
= *(SHORT
*)delay
->value
;
3365 IWICMetadataReader_Release(reader
);
3369 IWICMetadataBlockReader_Release(block_reader
);
3375 static void gif_metadata_reader(GpBitmap
*bitmap
, IWICBitmapDecoder
*decoder
, UINT active_frame
)
3378 IWICBitmapFrameDecode
*frame
;
3379 IWICMetadataBlockReader
*block_reader
;
3380 IWICMetadataReader
*reader
;
3381 UINT frame_count
, block_count
, i
;
3382 PropertyItem
*delay
= NULL
, *comment
= NULL
, *background
= NULL
;
3383 PropertyItem
*transparent_idx
= NULL
, *loop
= NULL
, *palette
= NULL
;
3385 IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
3386 if (frame_count
> 1)
3388 delay
= GdipAlloc(sizeof(*delay
) + frame_count
* sizeof(LONG
));
3393 delay
->type
= PropertyTagTypeLong
;
3394 delay
->id
= PropertyTagFrameDelay
;
3395 delay
->length
= frame_count
* sizeof(LONG
);
3396 delay
->value
= delay
+ 1;
3398 value
= delay
->value
;
3400 for (i
= 0; i
< frame_count
; i
++)
3402 hr
= IWICBitmapDecoder_GetFrame(decoder
, i
, &frame
);
3405 value
[i
] = get_gif_frame_delay(frame
);
3406 IWICBitmapFrameDecode_Release(frame
);
3413 hr
= IWICBitmapDecoder_QueryInterface(decoder
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3416 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3419 for (i
= 0; i
< block_count
; i
++)
3421 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3425 comment
= get_gif_comment(reader
);
3427 if (frame_count
> 1 && !loop
)
3428 loop
= get_gif_loopcount(reader
);
3431 background
= get_gif_background(reader
);
3434 palette
= get_gif_palette(decoder
, reader
);
3436 IWICMetadataReader_Release(reader
);
3440 IWICMetadataBlockReader_Release(block_reader
);
3443 if (frame_count
> 1 && !loop
)
3445 loop
= GdipAlloc(sizeof(*loop
) + sizeof(SHORT
));
3448 loop
->type
= PropertyTagTypeShort
;
3449 loop
->id
= PropertyTagLoopCount
;
3450 loop
->length
= sizeof(SHORT
);
3451 loop
->value
= loop
+ 1;
3452 *(SHORT
*)loop
->value
= 1;
3456 if (delay
) add_property(bitmap
, delay
);
3457 if (comment
) add_property(bitmap
, comment
);
3458 if (loop
) add_property(bitmap
, loop
);
3459 if (palette
) add_property(bitmap
, palette
);
3460 if (background
) add_property(bitmap
, background
);
3466 GdipFree(background
);
3468 /* Win7 gdiplus always returns transparent color index from frame 0 */
3469 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
3470 if (hr
!= S_OK
) return;
3472 hr
= IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
);
3475 hr
= IWICMetadataBlockReader_GetCount(block_reader
, &block_count
);
3478 for (i
= 0; i
< block_count
; i
++)
3480 hr
= IWICMetadataBlockReader_GetReaderByIndex(block_reader
, i
, &reader
);
3483 if (!transparent_idx
)
3484 transparent_idx
= get_gif_transparent_idx(reader
);
3486 IWICMetadataReader_Release(reader
);
3490 IWICMetadataBlockReader_Release(block_reader
);
3493 if (transparent_idx
) add_property(bitmap
, transparent_idx
);
3494 GdipFree(transparent_idx
);
3496 IWICBitmapFrameDecode_Release(frame
);
3499 typedef void (*metadata_reader_func
)(GpBitmap
*bitmap
, IWICBitmapDecoder
*decoder
, UINT frame
);
3501 static GpStatus
decode_image_wic(IStream
*stream
, GDIPCONST CLSID
*clsid
,
3502 UINT active_frame
, metadata_reader_func metadata_reader
, GpImage
**image
)
3507 IWICBitmapDecoder
*decoder
;
3508 IWICBitmapFrameDecode
*frame
;
3509 IWICBitmapSource
*source
=NULL
;
3510 IWICMetadataBlockReader
*block_reader
;
3511 WICPixelFormatGUID wic_format
;
3512 PixelFormat gdip_format
=0;
3513 ColorPalette
*palette
= NULL
;
3514 WICBitmapPaletteType palette_type
= WICBitmapPaletteTypeFixedHalftone256
;
3516 UINT width
, height
, frame_count
;
3517 BitmapData lockeddata
;
3521 TRACE("%p,%s,%u,%p\n", stream
, wine_dbgstr_guid(clsid
), active_frame
, image
);
3523 initresult
= CoInitialize(NULL
);
3525 hr
= CoCreateInstance(clsid
, NULL
, CLSCTX_INPROC_SERVER
,
3526 &IID_IWICBitmapDecoder
, (void**)&decoder
);
3527 if (FAILED(hr
)) goto end
;
3529 hr
= IWICBitmapDecoder_Initialize(decoder
, stream
, WICDecodeMetadataCacheOnLoad
);
3532 IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
3533 hr
= IWICBitmapDecoder_GetFrame(decoder
, active_frame
, &frame
);
3536 if (SUCCEEDED(hr
)) /* got frame */
3538 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &wic_format
);
3542 IWICBitmapSource
*bmp_source
;
3543 IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICBitmapSource
, (void **)&bmp_source
);
3545 for (i
=0; pixel_formats
[i
].wic_format
; i
++)
3547 if (IsEqualGUID(&wic_format
, pixel_formats
[i
].wic_format
))
3549 source
= bmp_source
;
3550 gdip_format
= pixel_formats
[i
].gdip_format
;
3551 palette_type
= pixel_formats
[i
].palette_type
;
3557 /* unknown format; fall back on 32bppARGB */
3558 hr
= WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA
, bmp_source
, &source
);
3559 gdip_format
= PixelFormat32bppARGB
;
3560 IWICBitmapSource_Release(bmp_source
);
3562 TRACE("%s => %#x\n", wine_dbgstr_guid(&wic_format
), gdip_format
);
3565 if (SUCCEEDED(hr
)) /* got source */
3567 hr
= IWICBitmapSource_GetSize(source
, &width
, &height
);
3570 status
= GdipCreateBitmapFromScan0(width
, height
, 0, gdip_format
,
3573 if (SUCCEEDED(hr
) && status
== Ok
) /* created bitmap */
3575 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeWrite
,
3576 gdip_format
, &lockeddata
);
3577 if (status
== Ok
) /* locked bitmap */
3582 for (i
=0; i
<height
; i
++)
3585 hr
= IWICBitmapSource_CopyPixels(source
, &wrc
, abs(lockeddata
.Stride
),
3586 abs(lockeddata
.Stride
), (BYTE
*)lockeddata
.Scan0
+lockeddata
.Stride
*i
);
3587 if (FAILED(hr
)) break;
3590 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3593 if (SUCCEEDED(hr
) && status
== Ok
)
3594 *image
= (GpImage
*)bitmap
;
3598 GdipDisposeImage((GpImage
*)bitmap
);
3601 if (SUCCEEDED(hr
) && status
== Ok
)
3604 hr
= IWICBitmapSource_GetResolution(source
, &dpix
, &dpiy
);
3607 bitmap
->image
.xres
= dpix
;
3608 bitmap
->image
.yres
= dpiy
;
3614 IWICBitmapSource_Release(source
);
3617 if (SUCCEEDED(hr
)) {
3618 bitmap
->metadata_reader
= NULL
;
3620 if (metadata_reader
)
3621 metadata_reader(bitmap
, decoder
, active_frame
);
3622 else if (IWICBitmapFrameDecode_QueryInterface(frame
, &IID_IWICMetadataBlockReader
, (void **)&block_reader
) == S_OK
)
3624 UINT block_count
= 0;
3625 if (IWICMetadataBlockReader_GetCount(block_reader
, &block_count
) == S_OK
&& block_count
)
3626 IWICMetadataBlockReader_GetReaderByIndex(block_reader
, 0, &bitmap
->metadata_reader
);
3627 IWICMetadataBlockReader_Release(block_reader
);
3630 palette
= get_palette(frame
, palette_type
);
3631 IWICBitmapFrameDecode_Release(frame
);
3635 IWICBitmapDecoder_Release(decoder
);
3638 if (SUCCEEDED(initresult
)) CoUninitialize();
3640 if (FAILED(hr
) && status
== Ok
) status
= hresult_to_status(hr
);
3644 /* Native GDI+ used to be smarter, but since Win7 it just sets these flags. */
3645 bitmap
->image
.flags
|= ImageFlagsReadOnly
|ImageFlagsHasRealPixelSize
|ImageFlagsHasRealDPI
|ImageFlagsColorSpaceRGB
;
3646 bitmap
->image
.frame_count
= frame_count
;
3647 bitmap
->image
.current_frame
= active_frame
;
3648 bitmap
->image
.stream
= stream
;
3651 GdipFree(bitmap
->image
.palette
);
3652 bitmap
->image
.palette
= palette
;
3656 if (IsEqualGUID(&wic_format
, &GUID_WICPixelFormatBlackWhite
))
3657 bitmap
->image
.palette
->Flags
= 0;
3659 /* Pin the source stream */
3660 IStream_AddRef(stream
);
3661 TRACE("=> %p\n", *image
);
3667 static GpStatus
decode_image_icon(IStream
* stream
, REFCLSID clsid
, UINT active_frame
, GpImage
**image
)
3669 return decode_image_wic(stream
, &CLSID_WICIcoDecoder
, active_frame
, NULL
, image
);
3672 static GpStatus
decode_image_bmp(IStream
* stream
, REFCLSID clsid
, UINT active_frame
, GpImage
**image
)
3677 status
= decode_image_wic(stream
, &CLSID_WICBmpDecoder
, active_frame
, NULL
, image
);
3679 bitmap
= (GpBitmap
*)*image
;
3681 if (status
== Ok
&& bitmap
->format
== PixelFormat32bppARGB
)
3683 /* WIC supports bmp files with alpha, but gdiplus does not */
3684 bitmap
->format
= PixelFormat32bppRGB
;
3690 static GpStatus
decode_image_jpeg(IStream
* stream
, REFCLSID clsid
, UINT active_frame
, GpImage
**image
)
3692 return decode_image_wic(stream
, &CLSID_WICJpegDecoder
, active_frame
, NULL
, image
);
3695 static GpStatus
decode_image_png(IStream
* stream
, REFCLSID clsid
, UINT active_frame
, GpImage
**image
)
3697 return decode_image_wic(stream
, &CLSID_WICPngDecoder
, active_frame
, NULL
, image
);
3700 static GpStatus
decode_image_gif(IStream
* stream
, REFCLSID clsid
, UINT active_frame
, GpImage
**image
)
3702 return decode_image_wic(stream
, &CLSID_WICGifDecoder
, active_frame
, gif_metadata_reader
, image
);
3705 static GpStatus
decode_image_tiff(IStream
* stream
, REFCLSID clsid
, UINT active_frame
, GpImage
**image
)
3707 return decode_image_wic(stream
, &CLSID_WICTiffDecoder
, active_frame
, NULL
, image
);
3710 static GpStatus
decode_image_olepicture_metafile(IStream
* stream
, REFCLSID clsid
, UINT active_frame
, GpImage
**image
)
3714 TRACE("%p %p\n", stream
, image
);
3716 if(!stream
|| !image
)
3717 return InvalidParameter
;
3719 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
3720 (LPVOID
*) &pic
) != S_OK
){
3721 TRACE("Could not load picture\n");
3722 return GenericError
;
3725 /* FIXME: missing initialization code */
3726 *image
= GdipAlloc(sizeof(GpMetafile
));
3727 if(!*image
) return OutOfMemory
;
3728 (*image
)->type
= ImageTypeMetafile
;
3729 (*image
)->stream
= NULL
;
3730 (*image
)->picture
= pic
;
3731 (*image
)->flags
= ImageFlagsNone
;
3732 (*image
)->frame_count
= 1;
3733 (*image
)->current_frame
= 0;
3734 (*image
)->palette
= NULL
;
3736 TRACE("<-- %p\n", *image
);
3741 typedef GpStatus (*encode_image_func
)(GpImage
*image
, IStream
* stream
,
3742 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
);
3744 typedef GpStatus (*decode_image_func
)(IStream
*stream
, REFCLSID clsid
, UINT active_frame
, GpImage
**image
);
3746 typedef struct image_codec
{
3747 ImageCodecInfo info
;
3748 encode_image_func encode_func
;
3749 decode_image_func decode_func
;
3764 static const struct image_codec codecs
[NUM_CODECS
];
3766 static GpStatus
get_decoder_info(IStream
* stream
, const struct image_codec
**result
)
3769 const BYTE
*pattern
, *mask
;
3776 /* seek to the start of the stream */
3778 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
3779 if (FAILED(hr
)) return hresult_to_status(hr
);
3781 /* read the first 8 bytes */
3782 /* FIXME: This assumes all codecs have signatures <= 8 bytes in length */
3783 hr
= IStream_Read(stream
, signature
, 8, &bytesread
);
3784 if (FAILED(hr
)) return hresult_to_status(hr
);
3785 if (hr
== S_FALSE
|| bytesread
== 0) return GenericError
;
3787 for (i
= 0; i
< NUM_CODECS
; i
++) {
3788 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
) &&
3789 bytesread
>= codecs
[i
].info
.SigSize
)
3791 for (sig
=0; sig
<codecs
[i
].info
.SigCount
; sig
++)
3793 pattern
= &codecs
[i
].info
.SigPattern
[codecs
[i
].info
.SigSize
*sig
];
3794 mask
= &codecs
[i
].info
.SigMask
[codecs
[i
].info
.SigSize
*sig
];
3795 for (j
=0; j
<codecs
[i
].info
.SigSize
; j
++)
3796 if ((signature
[j
] & mask
[j
]) != pattern
[j
])
3798 if (j
== codecs
[i
].info
.SigSize
)
3800 *result
= &codecs
[i
];
3807 TRACE("no match for %i byte signature %x %x %x %x %x %x %x %x\n", bytesread
,
3808 signature
[0],signature
[1],signature
[2],signature
[3],
3809 signature
[4],signature
[5],signature
[6],signature
[7]);
3811 return GenericError
;
3814 GpStatus WINGDIPAPI
GdipImageSelectActiveFrame(GpImage
*image
, GDIPCONST GUID
*dimensionID
,
3820 const struct image_codec
*codec
= NULL
;
3823 TRACE("(%p,%s,%u)\n", image
, debugstr_guid(dimensionID
), frame
);
3825 if (!image
|| !dimensionID
)
3826 return InvalidParameter
;
3828 if (frame
>= image
->frame_count
)
3830 WARN("requested frame %u, but image has only %u\n", frame
, image
->frame_count
);
3831 return InvalidParameter
;
3834 if (image
->type
!= ImageTypeBitmap
&& image
->type
!= ImageTypeMetafile
)
3836 WARN("invalid image type %d\n", image
->type
);
3837 return InvalidParameter
;
3840 if (image
->current_frame
== frame
)
3845 TRACE("image doesn't have an associated stream\n");
3849 /* choose an appropriate image decoder */
3850 stat
= get_decoder_info(image
->stream
, &codec
);
3853 WARN("can't find decoder info\n");
3857 /* seek to the start of the stream */
3859 hr
= IStream_Seek(image
->stream
, seek
, STREAM_SEEK_SET
, NULL
);
3861 return hresult_to_status(hr
);
3863 /* call on the image decoder to do the real work */
3864 stat
= codec
->decode_func(image
->stream
, &codec
->info
.Clsid
, frame
, &new_image
);
3868 memcpy(&new_image
->format
, &codec
->info
.FormatID
, sizeof(GUID
));
3869 free_image_data(image
);
3870 if (image
->type
== ImageTypeBitmap
)
3871 *(GpBitmap
*)image
= *(GpBitmap
*)new_image
;
3872 else if (image
->type
== ImageTypeMetafile
)
3873 *(GpMetafile
*)image
= *(GpMetafile
*)new_image
;
3874 new_image
->type
= ~0;
3875 GdipFree(new_image
);
3882 GpStatus WINGDIPAPI
GdipLoadImageFromStream(IStream
*stream
, GpImage
**image
)
3887 const struct image_codec
*codec
=NULL
;
3889 /* choose an appropriate image decoder */
3890 stat
= get_decoder_info(stream
, &codec
);
3891 if (stat
!= Ok
) return stat
;
3893 /* seek to the start of the stream */
3895 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
3896 if (FAILED(hr
)) return hresult_to_status(hr
);
3898 /* call on the image decoder to do the real work */
3899 stat
= codec
->decode_func(stream
, &codec
->info
.Clsid
, 0, image
);
3901 /* take note of the original data format */
3904 memcpy(&(*image
)->format
, &codec
->info
.FormatID
, sizeof(GUID
));
3912 GpStatus WINGDIPAPI
GdipLoadImageFromStreamICM(IStream
* stream
, GpImage
**image
)
3914 TRACE("%p %p\n", stream
, image
);
3916 return GdipLoadImageFromStream(stream
, image
);
3919 GpStatus WINGDIPAPI
GdipRemovePropertyItem(GpImage
*image
, PROPID propId
)
3923 TRACE("(%p,%u)\n", image
, propId
);
3926 return InvalidParameter
;
3929 FIXME("not implemented\n");
3931 return NotImplemented
;
3934 GpStatus WINGDIPAPI
GdipSetPropertyItem(GpImage
*image
, GDIPCONST PropertyItem
* item
)
3938 if (!image
|| !item
) return InvalidParameter
;
3940 TRACE("(%p,%p:%#x,%u,%u,%p)\n", image
, item
, item
->id
, item
->type
, item
->length
, item
->value
);
3943 FIXME("not implemented\n");
3948 GpStatus WINGDIPAPI
GdipSaveImageToFile(GpImage
*image
, GDIPCONST WCHAR
* filename
,
3949 GDIPCONST CLSID
*clsidEncoder
,
3950 GDIPCONST EncoderParameters
*encoderParams
)
3955 TRACE("%p (%s) %p %p\n", image
, debugstr_w(filename
), clsidEncoder
, encoderParams
);
3957 if (!image
|| !filename
|| !clsidEncoder
)
3958 return InvalidParameter
;
3960 stat
= GdipCreateStreamOnFile(filename
, GENERIC_WRITE
, &stream
);
3962 return GenericError
;
3964 stat
= GdipSaveImageToStream(image
, stream
, clsidEncoder
, encoderParams
);
3966 IStream_Release(stream
);
3970 /*************************************************************************
3971 * Encoding functions -
3972 * These functions encode an image in different image file formats.
3974 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
3975 #define BITMAP_FORMAT_JPEG 0xd8ff
3976 #define BITMAP_FORMAT_GIF 0x4947
3977 #define BITMAP_FORMAT_PNG 0x5089
3978 #define BITMAP_FORMAT_APM 0xcdd7
3980 static GpStatus
encode_image_WIC(GpImage
*image
, IStream
* stream
,
3981 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
3985 IWICBitmapEncoder
*encoder
;
3986 IWICBitmapFrameEncode
*frameencode
;
3987 IPropertyBag2
*encoderoptions
;
3990 PixelFormat gdipformat
=0;
3991 WICPixelFormatGUID wicformat
;
3993 BitmapData lockeddata
;
3997 if (image
->type
!= ImageTypeBitmap
)
3998 return GenericError
;
4000 bitmap
= (GpBitmap
*)image
;
4002 GdipGetImageWidth(image
, &width
);
4003 GdipGetImageHeight(image
, &height
);
4010 initresult
= CoInitialize(NULL
);
4012 hr
= CoCreateInstance(clsid
, NULL
, CLSCTX_INPROC_SERVER
,
4013 &IID_IWICBitmapEncoder
, (void**)&encoder
);
4016 if (SUCCEEDED(initresult
)) CoUninitialize();
4017 return hresult_to_status(hr
);
4020 hr
= IWICBitmapEncoder_Initialize(encoder
, stream
, WICBitmapEncoderNoCache
);
4024 hr
= IWICBitmapEncoder_CreateNewFrame(encoder
, &frameencode
, &encoderoptions
);
4027 if (SUCCEEDED(hr
)) /* created frame */
4029 hr
= IWICBitmapFrameEncode_Initialize(frameencode
, encoderoptions
);
4032 hr
= IWICBitmapFrameEncode_SetSize(frameencode
, width
, height
);
4035 hr
= IWICBitmapFrameEncode_SetResolution(frameencode
, image
->xres
, image
->yres
);
4039 for (i
=0; pixel_formats
[i
].wic_format
; i
++)
4041 if (pixel_formats
[i
].gdip_format
== bitmap
->format
)
4043 memcpy(&wicformat
, pixel_formats
[i
].wic_format
, sizeof(GUID
));
4044 gdipformat
= bitmap
->format
;
4050 memcpy(&wicformat
, &GUID_WICPixelFormat32bppBGRA
, sizeof(GUID
));
4051 gdipformat
= PixelFormat32bppARGB
;
4054 hr
= IWICBitmapFrameEncode_SetPixelFormat(frameencode
, &wicformat
);
4059 stat
= GdipBitmapLockBits(bitmap
, &rc
, ImageLockModeRead
, gdipformat
,
4064 UINT row_size
= (lockeddata
.Width
* PIXELFORMATBPP(gdipformat
) + 7)/8;
4067 /* write one row at a time in case stride is negative */
4068 row
= lockeddata
.Scan0
;
4069 for (i
=0; i
<lockeddata
.Height
; i
++)
4071 hr
= IWICBitmapFrameEncode_WritePixels(frameencode
, 1, row_size
, row_size
, row
);
4072 if (FAILED(hr
)) break;
4073 row
+= lockeddata
.Stride
;
4076 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
4083 hr
= IWICBitmapFrameEncode_Commit(frameencode
);
4085 IWICBitmapFrameEncode_Release(frameencode
);
4086 IPropertyBag2_Release(encoderoptions
);
4090 hr
= IWICBitmapEncoder_Commit(encoder
);
4092 IWICBitmapEncoder_Release(encoder
);
4094 if (SUCCEEDED(initresult
)) CoUninitialize();
4096 return hresult_to_status(hr
);
4099 static GpStatus
encode_image_BMP(GpImage
*image
, IStream
* stream
,
4100 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4102 return encode_image_WIC(image
, stream
, &CLSID_WICBmpEncoder
, params
);
4105 static GpStatus
encode_image_tiff(GpImage
*image
, IStream
* stream
,
4106 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4108 return encode_image_WIC(image
, stream
, &CLSID_WICTiffEncoder
, params
);
4111 static GpStatus
encode_image_png(GpImage
*image
, IStream
* stream
,
4112 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4114 return encode_image_WIC(image
, stream
, &CLSID_WICPngEncoder
, params
);
4117 static GpStatus
encode_image_jpeg(GpImage
*image
, IStream
* stream
,
4118 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4120 return encode_image_WIC(image
, stream
, &CLSID_WICJpegEncoder
, params
);
4123 /*****************************************************************************
4124 * GdipSaveImageToStream [GDIPLUS.@]
4126 GpStatus WINGDIPAPI
GdipSaveImageToStream(GpImage
*image
, IStream
* stream
,
4127 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
4130 encode_image_func encode_image
;
4133 TRACE("%p %p %p %p\n", image
, stream
, clsid
, params
);
4135 if(!image
|| !stream
)
4136 return InvalidParameter
;
4138 /* select correct encoder */
4139 encode_image
= NULL
;
4140 for (i
= 0; i
< NUM_CODECS
; i
++) {
4141 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
) &&
4142 IsEqualCLSID(clsid
, &codecs
[i
].info
.Clsid
))
4143 encode_image
= codecs
[i
].encode_func
;
4145 if (encode_image
== NULL
)
4146 return UnknownImageFormat
;
4148 stat
= encode_image(image
, stream
, clsid
, params
);
4153 /*****************************************************************************
4154 * GdipSaveAdd [GDIPLUS.@]
4156 GpStatus WINGDIPAPI
GdipSaveAdd(GpImage
*image
, GDIPCONST EncoderParameters
*params
)
4158 FIXME("(%p,%p): stub\n", image
, params
);
4162 /*****************************************************************************
4163 * GdipGetImagePalette [GDIPLUS.@]
4165 GpStatus WINGDIPAPI
GdipGetImagePalette(GpImage
*image
, ColorPalette
*palette
, INT size
)
4169 TRACE("(%p,%p,%i)\n", image
, palette
, size
);
4171 if (!image
|| !palette
)
4172 return InvalidParameter
;
4174 count
= image
->palette
? image
->palette
->Count
: 0;
4176 if (size
< (sizeof(UINT
)*2+sizeof(ARGB
)*count
))
4178 TRACE("<-- InsufficientBuffer\n");
4179 return InsufficientBuffer
;
4184 palette
->Flags
= image
->palette
->Flags
;
4185 palette
->Count
= image
->palette
->Count
;
4186 memcpy(palette
->Entries
, image
->palette
->Entries
, sizeof(ARGB
)*image
->palette
->Count
);
4196 /*****************************************************************************
4197 * GdipSetImagePalette [GDIPLUS.@]
4199 GpStatus WINGDIPAPI
GdipSetImagePalette(GpImage
*image
,
4200 GDIPCONST ColorPalette
*palette
)
4202 ColorPalette
*new_palette
;
4204 TRACE("(%p,%p)\n", image
, palette
);
4206 if(!image
|| !palette
|| palette
->Count
> 256)
4207 return InvalidParameter
;
4209 new_palette
= GdipAlloc(2 * sizeof(UINT
) + palette
->Count
* sizeof(ARGB
));
4210 if (!new_palette
) return OutOfMemory
;
4212 GdipFree(image
->palette
);
4213 image
->palette
= new_palette
;
4214 image
->palette
->Flags
= palette
->Flags
;
4215 image
->palette
->Count
= palette
->Count
;
4216 memcpy(image
->palette
->Entries
, palette
->Entries
, sizeof(ARGB
)*palette
->Count
);
4221 /*************************************************************************
4223 * Structures that represent which formats we support for encoding.
4226 /* ImageCodecInfo creation routines taken from libgdiplus */
4227 static const WCHAR bmp_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
4228 static const WCHAR bmp_extension
[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
4229 static const WCHAR bmp_mimetype
[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
4230 static const WCHAR bmp_format
[] = {'B', 'M', 'P', 0}; /* BMP */
4231 static const BYTE bmp_sig_pattern
[] = { 0x42, 0x4D };
4232 static const BYTE bmp_sig_mask
[] = { 0xFF, 0xFF };
4234 static const WCHAR jpeg_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'J','P','E','G', 0};
4235 static const WCHAR jpeg_extension
[] = {'*','.','J','P','G',';', '*','.','J','P','E','G',';', '*','.','J','P','E',';', '*','.','J','F','I','F',0};
4236 static const WCHAR jpeg_mimetype
[] = {'i','m','a','g','e','/','j','p','e','g', 0};
4237 static const WCHAR jpeg_format
[] = {'J','P','E','G',0};
4238 static const BYTE jpeg_sig_pattern
[] = { 0xFF, 0xD8 };
4239 static const BYTE jpeg_sig_mask
[] = { 0xFF, 0xFF };
4241 static const WCHAR gif_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'G','I','F', 0};
4242 static const WCHAR gif_extension
[] = {'*','.','G','I','F',0};
4243 static const WCHAR gif_mimetype
[] = {'i','m','a','g','e','/','g','i','f', 0};
4244 static const WCHAR gif_format
[] = {'G','I','F',0};
4245 static const BYTE gif_sig_pattern
[12] = "GIF87aGIF89a";
4246 static const BYTE gif_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4248 static const WCHAR tiff_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'T','I','F','F', 0};
4249 static const WCHAR tiff_extension
[] = {'*','.','T','I','F','F',';','*','.','T','I','F',0};
4250 static const WCHAR tiff_mimetype
[] = {'i','m','a','g','e','/','t','i','f','f', 0};
4251 static const WCHAR tiff_format
[] = {'T','I','F','F',0};
4252 static const BYTE tiff_sig_pattern
[] = {0x49,0x49,42,0,0x4d,0x4d,0,42};
4253 static const BYTE tiff_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4255 static const WCHAR emf_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'E','M','F', 0};
4256 static const WCHAR emf_extension
[] = {'*','.','E','M','F',0};
4257 static const WCHAR emf_mimetype
[] = {'i','m','a','g','e','/','x','-','e','m','f', 0};
4258 static const WCHAR emf_format
[] = {'E','M','F',0};
4259 static const BYTE emf_sig_pattern
[] = { 0x01, 0x00, 0x00, 0x00 };
4260 static const BYTE emf_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
4262 static const WCHAR wmf_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'W','M','F', 0};
4263 static const WCHAR wmf_extension
[] = {'*','.','W','M','F',0};
4264 static const WCHAR wmf_mimetype
[] = {'i','m','a','g','e','/','x','-','w','m','f', 0};
4265 static const WCHAR wmf_format
[] = {'W','M','F',0};
4266 static const BYTE wmf_sig_pattern
[] = { 0xd7, 0xcd };
4267 static const BYTE wmf_sig_mask
[] = { 0xFF, 0xFF };
4269 static const WCHAR png_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'P','N','G', 0};
4270 static const WCHAR png_extension
[] = {'*','.','P','N','G',0};
4271 static const WCHAR png_mimetype
[] = {'i','m','a','g','e','/','p','n','g', 0};
4272 static const WCHAR png_format
[] = {'P','N','G',0};
4273 static const BYTE png_sig_pattern
[] = { 137, 80, 78, 71, 13, 10, 26, 10, };
4274 static const BYTE png_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
4276 static const WCHAR ico_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'I','C','O', 0};
4277 static const WCHAR ico_extension
[] = {'*','.','I','C','O',0};
4278 static const WCHAR ico_mimetype
[] = {'i','m','a','g','e','/','x','-','i','c','o','n', 0};
4279 static const WCHAR ico_format
[] = {'I','C','O',0};
4280 static const BYTE ico_sig_pattern
[] = { 0x00, 0x00, 0x01, 0x00 };
4281 static const BYTE ico_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
4283 static const struct image_codec codecs
[NUM_CODECS
] = {
4286 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4287 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4288 /* CodecName */ bmp_codecname
,
4290 /* FormatDescription */ bmp_format
,
4291 /* FilenameExtension */ bmp_extension
,
4292 /* MimeType */ bmp_mimetype
,
4293 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4297 /* SigPattern */ bmp_sig_pattern
,
4298 /* SigMask */ bmp_sig_mask
,
4305 /* Clsid */ { 0x557cf401, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4306 /* FormatID */ { 0xb96b3caeU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4307 /* CodecName */ jpeg_codecname
,
4309 /* FormatDescription */ jpeg_format
,
4310 /* FilenameExtension */ jpeg_extension
,
4311 /* MimeType */ jpeg_mimetype
,
4312 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4316 /* SigPattern */ jpeg_sig_pattern
,
4317 /* SigMask */ jpeg_sig_mask
,
4324 /* Clsid */ { 0x557cf402, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4325 /* FormatID */ { 0xb96b3cb0U
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4326 /* CodecName */ gif_codecname
,
4328 /* FormatDescription */ gif_format
,
4329 /* FilenameExtension */ gif_extension
,
4330 /* MimeType */ gif_mimetype
,
4331 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4335 /* SigPattern */ gif_sig_pattern
,
4336 /* SigMask */ gif_sig_mask
,
4343 /* Clsid */ { 0x557cf405, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4344 /* FormatID */ { 0xb96b3cb1U
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4345 /* CodecName */ tiff_codecname
,
4347 /* FormatDescription */ tiff_format
,
4348 /* FilenameExtension */ tiff_extension
,
4349 /* MimeType */ tiff_mimetype
,
4350 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsEncoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4354 /* SigPattern */ tiff_sig_pattern
,
4355 /* SigMask */ tiff_sig_mask
,
4362 /* Clsid */ { 0x557cf403, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4363 /* FormatID */ { 0xb96b3cacU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4364 /* CodecName */ emf_codecname
,
4366 /* FormatDescription */ emf_format
,
4367 /* FilenameExtension */ emf_extension
,
4368 /* MimeType */ emf_mimetype
,
4369 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
4373 /* SigPattern */ emf_sig_pattern
,
4374 /* SigMask */ emf_sig_mask
,
4377 decode_image_olepicture_metafile
4381 /* Clsid */ { 0x557cf404, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4382 /* FormatID */ { 0xb96b3cadU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4383 /* CodecName */ wmf_codecname
,
4385 /* FormatDescription */ wmf_format
,
4386 /* FilenameExtension */ wmf_extension
,
4387 /* MimeType */ wmf_mimetype
,
4388 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
4392 /* SigPattern */ wmf_sig_pattern
,
4393 /* SigMask */ wmf_sig_mask
,
4396 decode_image_olepicture_metafile
4400 /* Clsid */ { 0x557cf406, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4401 /* FormatID */ { 0xb96b3cafU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4402 /* CodecName */ png_codecname
,
4404 /* FormatDescription */ png_format
,
4405 /* FilenameExtension */ png_extension
,
4406 /* MimeType */ png_mimetype
,
4407 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4411 /* SigPattern */ png_sig_pattern
,
4412 /* SigMask */ png_sig_mask
,
4419 /* Clsid */ { 0x557cf407, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
4420 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
4421 /* CodecName */ ico_codecname
,
4423 /* FormatDescription */ ico_format
,
4424 /* FilenameExtension */ ico_extension
,
4425 /* MimeType */ ico_mimetype
,
4426 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
4430 /* SigPattern */ ico_sig_pattern
,
4431 /* SigMask */ ico_sig_mask
,
4438 /*****************************************************************************
4439 * GdipGetImageDecodersSize [GDIPLUS.@]
4441 GpStatus WINGDIPAPI
GdipGetImageDecodersSize(UINT
*numDecoders
, UINT
*size
)
4443 int decoder_count
=0;
4445 TRACE("%p %p\n", numDecoders
, size
);
4447 if (!numDecoders
|| !size
)
4448 return InvalidParameter
;
4450 for (i
=0; i
<NUM_CODECS
; i
++)
4452 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
4456 *numDecoders
= decoder_count
;
4457 *size
= decoder_count
* sizeof(ImageCodecInfo
);
4462 /*****************************************************************************
4463 * GdipGetImageDecoders [GDIPLUS.@]
4465 GpStatus WINGDIPAPI
GdipGetImageDecoders(UINT numDecoders
, UINT size
, ImageCodecInfo
*decoders
)
4467 int i
, decoder_count
=0;
4468 TRACE("%u %u %p\n", numDecoders
, size
, decoders
);
4471 size
!= numDecoders
* sizeof(ImageCodecInfo
))
4472 return GenericError
;
4474 for (i
=0; i
<NUM_CODECS
; i
++)
4476 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
4478 if (decoder_count
== numDecoders
) return GenericError
;
4479 memcpy(&decoders
[decoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
4484 if (decoder_count
< numDecoders
) return GenericError
;
4489 /*****************************************************************************
4490 * GdipGetImageEncodersSize [GDIPLUS.@]
4492 GpStatus WINGDIPAPI
GdipGetImageEncodersSize(UINT
*numEncoders
, UINT
*size
)
4494 int encoder_count
=0;
4496 TRACE("%p %p\n", numEncoders
, size
);
4498 if (!numEncoders
|| !size
)
4499 return InvalidParameter
;
4501 for (i
=0; i
<NUM_CODECS
; i
++)
4503 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
4507 *numEncoders
= encoder_count
;
4508 *size
= encoder_count
* sizeof(ImageCodecInfo
);
4513 /*****************************************************************************
4514 * GdipGetImageEncoders [GDIPLUS.@]
4516 GpStatus WINGDIPAPI
GdipGetImageEncoders(UINT numEncoders
, UINT size
, ImageCodecInfo
*encoders
)
4518 int i
, encoder_count
=0;
4519 TRACE("%u %u %p\n", numEncoders
, size
, encoders
);
4522 size
!= numEncoders
* sizeof(ImageCodecInfo
))
4523 return GenericError
;
4525 for (i
=0; i
<NUM_CODECS
; i
++)
4527 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
4529 if (encoder_count
== numEncoders
) return GenericError
;
4530 memcpy(&encoders
[encoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
4535 if (encoder_count
< numEncoders
) return GenericError
;
4540 GpStatus WINGDIPAPI
GdipGetEncoderParameterListSize(GpImage
*image
,
4541 GDIPCONST CLSID
* clsidEncoder
, UINT
*size
)
4545 TRACE("(%p,%s,%p)\n", image
, debugstr_guid(clsidEncoder
), size
);
4548 FIXME("not implemented\n");
4552 return NotImplemented
;
4555 static PixelFormat
get_16bpp_format(HBITMAP hbm
)
4561 hdc
= CreateCompatibleDC(NULL
);
4563 memset(&bmh
, 0, sizeof(bmh
));
4564 bmh
.bV4Size
= sizeof(bmh
);
4567 bmh
.bV4V4Compression
= BI_BITFIELDS
;
4568 bmh
.bV4BitCount
= 16;
4570 GetDIBits(hdc
, hbm
, 0, 0, NULL
, (BITMAPINFO
*)&bmh
, DIB_RGB_COLORS
);
4572 if (bmh
.bV4RedMask
== 0x7c00 &&
4573 bmh
.bV4GreenMask
== 0x3e0 &&
4574 bmh
.bV4BlueMask
== 0x1f)
4576 result
= PixelFormat16bppRGB555
;
4578 else if (bmh
.bV4RedMask
== 0xf800 &&
4579 bmh
.bV4GreenMask
== 0x7e0 &&
4580 bmh
.bV4BlueMask
== 0x1f)
4582 result
= PixelFormat16bppRGB565
;
4586 FIXME("unrecognized bitfields %x,%x,%x\n", bmh
.bV4RedMask
,
4587 bmh
.bV4GreenMask
, bmh
.bV4BlueMask
);
4588 result
= PixelFormatUndefined
;
4596 /*****************************************************************************
4597 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
4599 GpStatus WINGDIPAPI
GdipCreateBitmapFromHBITMAP(HBITMAP hbm
, HPALETTE hpal
, GpBitmap
** bitmap
)
4604 BitmapData lockeddata
;
4606 TRACE("%p %p %p\n", hbm
, hpal
, bitmap
);
4609 return InvalidParameter
;
4611 if (GetObjectA(hbm
, sizeof(bm
), &bm
) != sizeof(bm
))
4612 return InvalidParameter
;
4614 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
4615 switch(bm
.bmBitsPixel
) {
4617 format
= PixelFormat1bppIndexed
;
4620 format
= PixelFormat4bppIndexed
;
4623 format
= PixelFormat8bppIndexed
;
4626 format
= get_16bpp_format(hbm
);
4627 if (format
== PixelFormatUndefined
)
4628 return InvalidParameter
;
4631 format
= PixelFormat24bppRGB
;
4634 format
= PixelFormat32bppRGB
;
4637 format
= PixelFormat48bppRGB
;
4640 FIXME("don't know how to handle %d bpp\n", bm
.bmBitsPixel
);
4641 return InvalidParameter
;
4644 retval
= GdipCreateBitmapFromScan0(bm
.bmWidth
, bm
.bmHeight
, 0,
4645 format
, NULL
, bitmap
);
4649 retval
= GdipBitmapLockBits(*bitmap
, NULL
, ImageLockModeWrite
,
4650 format
, &lockeddata
);
4657 hdc
= CreateCompatibleDC(NULL
);
4658 pbmi
= GdipAlloc(sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
4662 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
4663 pbmi
->bmiHeader
.biBitCount
= 0;
4665 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
4667 src_height
= abs(pbmi
->bmiHeader
.biHeight
);
4668 pbmi
->bmiHeader
.biHeight
= -src_height
;
4670 GetDIBits(hdc
, hbm
, 0, src_height
, lockeddata
.Scan0
, pbmi
, DIB_RGB_COLORS
);
4675 retval
= OutOfMemory
;
4679 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
4682 if (retval
== Ok
&& hpal
)
4684 PALETTEENTRY entry
[256];
4685 ColorPalette
*palette
=NULL
;
4686 int i
, num_palette_entries
;
4688 num_palette_entries
= GetPaletteEntries(hpal
, 0, 256, entry
);
4689 if (!num_palette_entries
)
4690 retval
= GenericError
;
4692 palette
= GdipAlloc(sizeof(ColorPalette
) + sizeof(ARGB
) * (num_palette_entries
-1));
4694 retval
= OutOfMemory
;
4699 palette
->Count
= num_palette_entries
;
4701 for (i
=0; i
<num_palette_entries
; i
++)
4703 palette
->Entries
[i
] = 0xff000000 | entry
[i
].peRed
<< 16 |
4704 entry
[i
].peGreen
<< 8 | entry
[i
].peBlue
;
4707 retval
= GdipSetImagePalette((GpImage
*)*bitmap
, palette
);
4715 GdipDisposeImage((GpImage
*)*bitmap
);
4723 GpStatus WINGDIPAPI
GdipDeleteEffect(CGpEffect
*effect
)
4725 FIXME("(%p): stub\n", effect
);
4726 /* note: According to Jose Roca's GDI+ Docs, this is not implemented
4727 * in Windows's gdiplus */
4728 return NotImplemented
;
4731 /*****************************************************************************
4732 * GdipSetEffectParameters [GDIPLUS.@]
4734 GpStatus WINGDIPAPI
GdipSetEffectParameters(CGpEffect
*effect
,
4735 const VOID
*params
, const UINT size
)
4739 TRACE("(%p,%p,%u)\n", effect
, params
, size
);
4742 FIXME("not implemented\n");
4744 return NotImplemented
;
4747 /*****************************************************************************
4748 * GdipGetImageFlags [GDIPLUS.@]
4750 GpStatus WINGDIPAPI
GdipGetImageFlags(GpImage
*image
, UINT
*flags
)
4752 TRACE("%p %p\n", image
, flags
);
4754 if(!image
|| !flags
)
4755 return InvalidParameter
;
4757 *flags
= image
->flags
;
4762 GpStatus WINGDIPAPI
GdipTestControl(GpTestControlEnum control
, void *param
)
4764 TRACE("(%d, %p)\n", control
, param
);
4767 case TestControlForceBilinear
:
4769 FIXME("TestControlForceBilinear not handled\n");
4771 case TestControlNoICM
:
4773 FIXME("TestControlNoICM not handled\n");
4775 case TestControlGetBuildNumber
:
4776 *((DWORD
*)param
) = 3102;
4783 GpStatus WINGDIPAPI
GdipRecordMetafileFileName(GDIPCONST WCHAR
* fileName
,
4784 HDC hdc
, EmfType type
, GDIPCONST GpRectF
*pFrameRect
,
4785 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
,
4786 GpMetafile
**metafile
)
4788 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName
), hdc
, type
, pFrameRect
,
4789 frameUnit
, debugstr_w(desc
), metafile
);
4791 return NotImplemented
;
4794 GpStatus WINGDIPAPI
GdipRecordMetafileFileNameI(GDIPCONST WCHAR
* fileName
, HDC hdc
, EmfType type
,
4795 GDIPCONST GpRect
*pFrameRect
, MetafileFrameUnit frameUnit
,
4796 GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
4798 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName
), hdc
, type
, pFrameRect
,
4799 frameUnit
, debugstr_w(desc
), metafile
);
4801 return NotImplemented
;
4804 GpStatus WINGDIPAPI
GdipImageForceValidation(GpImage
*image
)
4806 TRACE("%p\n", image
);
4811 /*****************************************************************************
4812 * GdipGetImageThumbnail [GDIPLUS.@]
4814 GpStatus WINGDIPAPI
GdipGetImageThumbnail(GpImage
*image
, UINT width
, UINT height
,
4815 GpImage
**ret_image
, GetThumbnailImageAbort cb
,
4819 GpGraphics
*graphics
;
4820 UINT srcwidth
, srcheight
;
4822 TRACE("(%p %u %u %p %p %p)\n",
4823 image
, width
, height
, ret_image
, cb
, cb_data
);
4825 if (!image
|| !ret_image
)
4826 return InvalidParameter
;
4828 if (!width
) width
= 120;
4829 if (!height
) height
= 120;
4831 GdipGetImageWidth(image
, &srcwidth
);
4832 GdipGetImageHeight(image
, &srcheight
);
4834 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat32bppPARGB
,
4835 NULL
, (GpBitmap
**)ret_image
);
4839 stat
= GdipGetImageGraphicsContext(*ret_image
, &graphics
);
4843 stat
= GdipDrawImageRectRectI(graphics
, image
,
4844 0, 0, width
, height
, 0, 0, srcwidth
, srcheight
, UnitPixel
,
4847 GdipDeleteGraphics(graphics
);
4852 GdipDisposeImage(*ret_image
);
4860 /*****************************************************************************
4861 * GdipImageRotateFlip [GDIPLUS.@]
4863 GpStatus WINGDIPAPI
GdipImageRotateFlip(GpImage
*image
, RotateFlipType type
)
4865 GpBitmap
*new_bitmap
;
4867 int bpp
, bytesperpixel
;
4868 int rotate_90
, flip_x
, flip_y
;
4869 int src_x_offset
, src_y_offset
;
4871 UINT x
, y
, width
, height
;
4872 BitmapData src_lock
, dst_lock
;
4875 TRACE("(%p, %u)\n", image
, type
);
4878 return InvalidParameter
;
4881 flip_x
= (type
&6) == 2 || (type
&6) == 4;
4882 flip_y
= (type
&3) == 1 || (type
&3) == 2;
4884 if (image
->type
!= ImageTypeBitmap
)
4886 FIXME("Not implemented for type %i\n", image
->type
);
4887 return NotImplemented
;
4890 bitmap
= (GpBitmap
*)image
;
4891 bpp
= PIXELFORMATBPP(bitmap
->format
);
4895 FIXME("Not implemented for %i bit images\n", bpp
);
4896 return NotImplemented
;
4901 width
= bitmap
->height
;
4902 height
= bitmap
->width
;
4906 width
= bitmap
->width
;
4907 height
= bitmap
->height
;
4910 bytesperpixel
= bpp
/8;
4912 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, bitmap
->format
, NULL
, &new_bitmap
);
4917 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, bitmap
->format
, &src_lock
);
4921 stat
= GdipBitmapLockBits(new_bitmap
, NULL
, ImageLockModeWrite
, bitmap
->format
, &dst_lock
);
4925 LPBYTE src_row
, src_pixel
;
4926 LPBYTE dst_row
, dst_pixel
;
4928 src_origin
= src_lock
.Scan0
;
4929 if (flip_x
) src_origin
+= bytesperpixel
* (bitmap
->width
- 1);
4930 if (flip_y
) src_origin
+= src_lock
.Stride
* (bitmap
->height
- 1);
4934 if (flip_y
) src_x_offset
= -src_lock
.Stride
;
4935 else src_x_offset
= src_lock
.Stride
;
4936 if (flip_x
) src_y_offset
= -bytesperpixel
;
4937 else src_y_offset
= bytesperpixel
;
4941 if (flip_x
) src_x_offset
= -bytesperpixel
;
4942 else src_x_offset
= bytesperpixel
;
4943 if (flip_y
) src_y_offset
= -src_lock
.Stride
;
4944 else src_y_offset
= src_lock
.Stride
;
4947 src_row
= src_origin
;
4948 dst_row
= dst_lock
.Scan0
;
4949 for (y
=0; y
<height
; y
++)
4951 src_pixel
= src_row
;
4952 dst_pixel
= dst_row
;
4953 for (x
=0; x
<width
; x
++)
4955 /* FIXME: This could probably be faster without memcpy. */
4956 memcpy(dst_pixel
, src_pixel
, bytesperpixel
);
4957 dst_pixel
+= bytesperpixel
;
4958 src_pixel
+= src_x_offset
;
4960 src_row
+= src_y_offset
;
4961 dst_row
+= dst_lock
.Stride
;
4964 GdipBitmapUnlockBits(new_bitmap
, &dst_lock
);
4967 GdipBitmapUnlockBits(bitmap
, &src_lock
);
4971 move_bitmap(bitmap
, new_bitmap
, FALSE
);
4973 GdipDisposeImage((GpImage
*)new_bitmap
);
4978 /*****************************************************************************
4979 * GdipConvertToEmfPlusToFile [GDIPLUS.@]
4982 GpStatus WINGDIPAPI
GdipConvertToEmfPlusToFile(const GpGraphics
* refGraphics
,
4983 GpMetafile
* metafile
, BOOL
* conversionSuccess
,
4984 const WCHAR
* filename
, EmfType emfType
,
4985 const WCHAR
* description
, GpMetafile
** out_metafile
)
4987 FIXME("stub: %p, %p, %p, %p, %u, %p, %p\n", refGraphics
, metafile
, conversionSuccess
, filename
, emfType
, description
, out_metafile
);
4988 return NotImplemented
;