2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
36 #include "gdiplus_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
41 #define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
43 static INT
ipicture_pixel_height(IPicture
*pic
)
48 IPicture_get_Height(pic
, &y
);
52 y
= MulDiv(y
, GetDeviceCaps(hdcref
, LOGPIXELSY
), INCH_HIMETRIC
);
58 static INT
ipicture_pixel_width(IPicture
*pic
)
63 IPicture_get_Width(pic
, &x
);
67 x
= MulDiv(x
, GetDeviceCaps(hdcref
, LOGPIXELSX
), INCH_HIMETRIC
);
74 GpStatus WINGDIPAPI
GdipBitmapApplyEffect(GpBitmap
* bitmap
, CGpEffect
* effect
,
75 RECT
* roi
, BOOL useAuxData
, VOID
** auxData
, INT
* auxDataSize
)
77 FIXME("(%p %p %p %d %p %p): stub\n", bitmap
, effect
, roi
, useAuxData
, auxData
, auxDataSize
);
79 * Note: According to Jose Roca's GDI+ docs, this function is not
80 * implemented in Windows's GDI+.
82 return NotImplemented
;
85 GpStatus WINGDIPAPI
GdipBitmapCreateApplyEffect(GpBitmap
** inputBitmaps
,
86 INT numInputs
, CGpEffect
* effect
, RECT
* roi
, RECT
* outputRect
,
87 GpBitmap
** outputBitmap
, BOOL useAuxData
, VOID
** auxData
, INT
* auxDataSize
)
89 FIXME("(%p %d %p %p %p %p %d %p %p): stub\n", inputBitmaps
, numInputs
, effect
, roi
, outputRect
, outputBitmap
, useAuxData
, auxData
, auxDataSize
);
91 * Note: According to Jose Roca's GDI+ docs, this function is not
92 * implemented in Windows's GDI+.
94 return NotImplemented
;
97 static inline void getpixel_1bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
99 *index
= (row
[x
/8]>>(7-x
%8)) & 1;
102 static inline void getpixel_4bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
105 *index
= row
[x
/2]&0xf;
107 *index
= row
[x
/2]>>4;
110 static inline void getpixel_8bppIndexed(BYTE
*index
, const BYTE
*row
, UINT x
)
115 static inline void getpixel_16bppGrayScale(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
116 const BYTE
*row
, UINT x
)
118 *r
= *g
= *b
= row
[x
*2+1];
122 static inline void getpixel_16bppRGB555(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
123 const BYTE
*row
, UINT x
)
125 WORD pixel
= *((const WORD
*)(row
)+x
);
126 *r
= (pixel
>>7&0xf8)|(pixel
>>12&0x7);
127 *g
= (pixel
>>2&0xf8)|(pixel
>>6&0x7);
128 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
132 static inline void getpixel_16bppRGB565(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
133 const BYTE
*row
, UINT x
)
135 WORD pixel
= *((const WORD
*)(row
)+x
);
136 *r
= (pixel
>>8&0xf8)|(pixel
>>13&0x7);
137 *g
= (pixel
>>3&0xfc)|(pixel
>>9&0x3);
138 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
142 static inline void getpixel_16bppARGB1555(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
143 const BYTE
*row
, UINT x
)
145 WORD pixel
= *((const WORD
*)(row
)+x
);
146 *r
= (pixel
>>7&0xf8)|(pixel
>>12&0x7);
147 *g
= (pixel
>>2&0xf8)|(pixel
>>6&0x7);
148 *b
= (pixel
<<3&0xf8)|(pixel
>>2&0x7);
149 if ((pixel
&0x8000) == 0x8000)
155 static inline void getpixel_24bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
156 const BYTE
*row
, UINT x
)
164 static inline void getpixel_32bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
165 const BYTE
*row
, UINT x
)
173 static inline void getpixel_32bppARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
174 const BYTE
*row
, UINT x
)
182 static inline void getpixel_32bppPARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
183 const BYTE
*row
, UINT x
)
190 *r
= row
[x
*4+2] * 255 / *a
;
191 *g
= row
[x
*4+1] * 255 / *a
;
192 *b
= row
[x
*4] * 255 / *a
;
196 static inline void getpixel_48bppRGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
197 const BYTE
*row
, UINT x
)
205 static inline void getpixel_64bppARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
206 const BYTE
*row
, UINT x
)
214 static inline void getpixel_64bppPARGB(BYTE
*r
, BYTE
*g
, BYTE
*b
, BYTE
*a
,
215 const BYTE
*row
, UINT x
)
222 *r
= row
[x
*8+5] * 255 / *a
;
223 *g
= row
[x
*8+3] * 255 / *a
;
224 *b
= row
[x
*8+1] * 255 / *a
;
228 GpStatus WINGDIPAPI
GdipBitmapGetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
234 TRACE("%p %d %d %p\n", bitmap
, x
, y
, color
);
236 if(!bitmap
|| !color
||
237 x
< 0 || y
< 0 || x
>= bitmap
->width
|| y
>= bitmap
->height
)
238 return InvalidParameter
;
240 row
= bitmap
->bits
+bitmap
->stride
*y
;
242 switch (bitmap
->format
)
244 case PixelFormat1bppIndexed
:
245 getpixel_1bppIndexed(&index
,row
,x
);
247 case PixelFormat4bppIndexed
:
248 getpixel_4bppIndexed(&index
,row
,x
);
250 case PixelFormat8bppIndexed
:
251 getpixel_8bppIndexed(&index
,row
,x
);
253 case PixelFormat16bppGrayScale
:
254 getpixel_16bppGrayScale(&r
,&g
,&b
,&a
,row
,x
);
256 case PixelFormat16bppRGB555
:
257 getpixel_16bppRGB555(&r
,&g
,&b
,&a
,row
,x
);
259 case PixelFormat16bppRGB565
:
260 getpixel_16bppRGB565(&r
,&g
,&b
,&a
,row
,x
);
262 case PixelFormat16bppARGB1555
:
263 getpixel_16bppARGB1555(&r
,&g
,&b
,&a
,row
,x
);
265 case PixelFormat24bppRGB
:
266 getpixel_24bppRGB(&r
,&g
,&b
,&a
,row
,x
);
268 case PixelFormat32bppRGB
:
269 getpixel_32bppRGB(&r
,&g
,&b
,&a
,row
,x
);
271 case PixelFormat32bppARGB
:
272 getpixel_32bppARGB(&r
,&g
,&b
,&a
,row
,x
);
274 case PixelFormat32bppPARGB
:
275 getpixel_32bppPARGB(&r
,&g
,&b
,&a
,row
,x
);
277 case PixelFormat48bppRGB
:
278 getpixel_48bppRGB(&r
,&g
,&b
,&a
,row
,x
);
280 case PixelFormat64bppARGB
:
281 getpixel_64bppARGB(&r
,&g
,&b
,&a
,row
,x
);
283 case PixelFormat64bppPARGB
:
284 getpixel_64bppPARGB(&r
,&g
,&b
,&a
,row
,x
);
287 FIXME("not implemented for format 0x%x\n", bitmap
->format
);
288 return NotImplemented
;
291 if (bitmap
->format
& PixelFormatIndexed
)
292 *color
= bitmap
->image
.palette_entries
[index
];
294 *color
= a
<<24|r
<<16|g
<<8|b
;
299 static inline UINT
get_palette_index(BYTE r
, BYTE g
, BYTE b
, BYTE a
, GpBitmap
* bitmap
) {
301 int best_distance
= 0x7fff;
304 /* This algorithm scans entire palette,
305 computes difference from desired color (all color components have equal weight)
306 and returns the index of color with least difference.
308 Note: Maybe it could be replaced with a better algorithm for better image quality
309 and performance, though better algorithm would probably need some pre-built lookup
310 tables and thus may actually be slower if this method is called only few times per
313 for(i
=0;i
<bitmap
->image
.palette_size
;i
++) {
314 ARGB color
=bitmap
->image
.palette_entries
[i
];
315 distance
=abs(b
-(color
& 0xff)) + abs(g
-(color
>>8 & 0xff)) + abs(r
-(color
>>16 & 0xff)) + abs(a
-(color
>>24 & 0xff));
316 if (distance
<best_distance
) {
317 best_distance
=distance
;
324 static inline void setpixel_8bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
325 BYTE
*row
, UINT x
, GpBitmap
* bitmap
)
327 BYTE index
= get_palette_index(r
,g
,b
,a
,bitmap
);
331 static inline void setpixel_1bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
332 BYTE
*row
, UINT x
, GpBitmap
* bitmap
)
334 row
[x
/8] = (row
[x
/8] & ~(1<<(7-x
%8))) | (get_palette_index(r
,g
,b
,a
,bitmap
)<<(7-x
%8));
337 static inline void setpixel_4bppIndexed(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
338 BYTE
*row
, UINT x
, GpBitmap
* bitmap
)
341 row
[x
/2] = (row
[x
/2] & 0xf0) | get_palette_index(r
,g
,b
,a
,bitmap
);
343 row
[x
/2] = (row
[x
/2] & 0x0f) | get_palette_index(r
,g
,b
,a
,bitmap
)<<4;
346 static inline void setpixel_16bppGrayScale(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
349 *((WORD
*)(row
)+x
) = (r
+g
+b
)*85;
352 static inline void setpixel_16bppRGB555(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
355 *((WORD
*)(row
)+x
) = (r
<<7&0x7c00)|
360 static inline void setpixel_16bppRGB565(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
363 *((WORD
*)(row
)+x
) = (r
<<8&0xf800)|
368 static inline void setpixel_16bppARGB1555(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
371 *((WORD
*)(row
)+x
) = (a
<<8&0x8000)|
377 static inline void setpixel_24bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
385 static inline void setpixel_32bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
388 *((DWORD
*)(row
)+x
) = (r
<<16)|(g
<<8)|b
;
391 static inline void setpixel_32bppARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
394 *((DWORD
*)(row
)+x
) = (a
<<24)|(r
<<16)|(g
<<8)|b
;
397 static inline void setpixel_32bppPARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
403 *((DWORD
*)(row
)+x
) = (a
<<24)|(r
<<16)|(g
<<8)|b
;
406 static inline void setpixel_48bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
409 row
[x
*6+5] = row
[x
*6+4] = r
;
410 row
[x
*6+3] = row
[x
*6+2] = g
;
411 row
[x
*6+1] = row
[x
*6] = b
;
414 static inline void setpixel_64bppARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
417 UINT64 a64
=a
, r64
=r
, g64
=g
, b64
=b
;
418 *((UINT64
*)(row
)+x
) = (a64
<<56)|(a64
<<48)|(r64
<<40)|(r64
<<32)|(g64
<<24)|(g64
<<16)|(b64
<<8)|b64
;
421 static inline void setpixel_64bppPARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
424 UINT64 a64
, r64
, g64
, b64
;
429 *((UINT64
*)(row
)+x
) = (a64
<<48)|(r64
<<32)|(g64
<<16)|b64
;
432 GpStatus WINGDIPAPI
GdipBitmapSetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
437 TRACE("bitmap:%p, x:%d, y:%d, color:%08x\n", bitmap
, x
, y
, color
);
439 if(!bitmap
|| x
< 0 || y
< 0 || x
>= bitmap
->width
|| y
>= bitmap
->height
)
440 return InvalidParameter
;
447 row
= bitmap
->bits
+ bitmap
->stride
* y
;
449 switch (bitmap
->format
)
451 case PixelFormat16bppGrayScale
:
452 setpixel_16bppGrayScale(r
,g
,b
,a
,row
,x
);
454 case PixelFormat16bppRGB555
:
455 setpixel_16bppRGB555(r
,g
,b
,a
,row
,x
);
457 case PixelFormat16bppRGB565
:
458 setpixel_16bppRGB565(r
,g
,b
,a
,row
,x
);
460 case PixelFormat16bppARGB1555
:
461 setpixel_16bppARGB1555(r
,g
,b
,a
,row
,x
);
463 case PixelFormat24bppRGB
:
464 setpixel_24bppRGB(r
,g
,b
,a
,row
,x
);
466 case PixelFormat32bppRGB
:
467 setpixel_32bppRGB(r
,g
,b
,a
,row
,x
);
469 case PixelFormat32bppARGB
:
470 setpixel_32bppARGB(r
,g
,b
,a
,row
,x
);
472 case PixelFormat32bppPARGB
:
473 setpixel_32bppPARGB(r
,g
,b
,a
,row
,x
);
475 case PixelFormat48bppRGB
:
476 setpixel_48bppRGB(r
,g
,b
,a
,row
,x
);
478 case PixelFormat64bppARGB
:
479 setpixel_64bppARGB(r
,g
,b
,a
,row
,x
);
481 case PixelFormat64bppPARGB
:
482 setpixel_64bppPARGB(r
,g
,b
,a
,row
,x
);
484 case PixelFormat8bppIndexed
:
485 setpixel_8bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
);
487 case PixelFormat4bppIndexed
:
488 setpixel_4bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
);
490 case PixelFormat1bppIndexed
:
491 setpixel_1bppIndexed(r
,g
,b
,a
,row
,x
,bitmap
);
494 FIXME("not implemented for format 0x%x\n", bitmap
->format
);
495 return NotImplemented
;
501 GpStatus
convert_pixels(INT width
, INT height
,
502 INT dst_stride
, BYTE
*dst_bits
, PixelFormat dst_format
,
503 INT src_stride
, const BYTE
*src_bits
, PixelFormat src_format
, ARGB
*src_palette
)
507 if (src_format
== dst_format
||
508 (dst_format
== PixelFormat32bppRGB
&& PIXELFORMATBPP(src_format
) == 32))
510 UINT widthbytes
= PIXELFORMATBPP(src_format
) * width
/ 8;
511 for (y
=0; y
<height
; y
++)
512 memcpy(dst_bits
+dst_stride
*y
, src_bits
+src_stride
*y
, widthbytes
);
516 #define convert_indexed_to_rgb(getpixel_function, setpixel_function) do { \
517 for (x=0; x<width; x++) \
518 for (y=0; y<height; y++) { \
521 getpixel_function(&index, src_bits+src_stride*y, x); \
522 color = (BYTE*)(&src_palette[index]); \
523 setpixel_function(color[2], color[1], color[0], color[3], dst_bits+dst_stride*y, x); \
528 #define convert_rgb_to_rgb(getpixel_function, setpixel_function) do { \
529 for (x=0; x<width; x++) \
530 for (y=0; y<height; y++) { \
532 getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
533 setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x); \
540 case PixelFormat1bppIndexed
:
543 case PixelFormat16bppGrayScale
:
544 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppGrayScale
);
545 case PixelFormat16bppRGB555
:
546 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppRGB555
);
547 case PixelFormat16bppRGB565
:
548 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppRGB565
);
549 case PixelFormat16bppARGB1555
:
550 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppARGB1555
);
551 case PixelFormat24bppRGB
:
552 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_24bppRGB
);
553 case PixelFormat32bppRGB
:
554 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppRGB
);
555 case PixelFormat32bppARGB
:
556 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppARGB
);
557 case PixelFormat32bppPARGB
:
558 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppPARGB
);
559 case PixelFormat48bppRGB
:
560 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_48bppRGB
);
561 case PixelFormat64bppARGB
:
562 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_64bppARGB
);
567 case PixelFormat4bppIndexed
:
570 case PixelFormat16bppGrayScale
:
571 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppGrayScale
);
572 case PixelFormat16bppRGB555
:
573 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppRGB555
);
574 case PixelFormat16bppRGB565
:
575 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppRGB565
);
576 case PixelFormat16bppARGB1555
:
577 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppARGB1555
);
578 case PixelFormat24bppRGB
:
579 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_24bppRGB
);
580 case PixelFormat32bppRGB
:
581 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppRGB
);
582 case PixelFormat32bppARGB
:
583 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppARGB
);
584 case PixelFormat32bppPARGB
:
585 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppPARGB
);
586 case PixelFormat48bppRGB
:
587 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_48bppRGB
);
588 case PixelFormat64bppARGB
:
589 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_64bppARGB
);
594 case PixelFormat8bppIndexed
:
597 case PixelFormat16bppGrayScale
:
598 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppGrayScale
);
599 case PixelFormat16bppRGB555
:
600 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppRGB555
);
601 case PixelFormat16bppRGB565
:
602 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppRGB565
);
603 case PixelFormat16bppARGB1555
:
604 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppARGB1555
);
605 case PixelFormat24bppRGB
:
606 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_24bppRGB
);
607 case PixelFormat32bppRGB
:
608 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppRGB
);
609 case PixelFormat32bppARGB
:
610 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppARGB
);
611 case PixelFormat32bppPARGB
:
612 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppPARGB
);
613 case PixelFormat48bppRGB
:
614 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_48bppRGB
);
615 case PixelFormat64bppARGB
:
616 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_64bppARGB
);
621 case PixelFormat16bppGrayScale
:
624 case PixelFormat16bppRGB555
:
625 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppRGB555
);
626 case PixelFormat16bppRGB565
:
627 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppRGB565
);
628 case PixelFormat16bppARGB1555
:
629 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppARGB1555
);
630 case PixelFormat24bppRGB
:
631 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_24bppRGB
);
632 case PixelFormat32bppRGB
:
633 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppRGB
);
634 case PixelFormat32bppARGB
:
635 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppARGB
);
636 case PixelFormat32bppPARGB
:
637 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppPARGB
);
638 case PixelFormat48bppRGB
:
639 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_48bppRGB
);
640 case PixelFormat64bppARGB
:
641 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_64bppARGB
);
646 case PixelFormat16bppRGB555
:
649 case PixelFormat16bppGrayScale
:
650 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppGrayScale
);
651 case PixelFormat16bppRGB565
:
652 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppRGB565
);
653 case PixelFormat16bppARGB1555
:
654 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppARGB1555
);
655 case PixelFormat24bppRGB
:
656 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_24bppRGB
);
657 case PixelFormat32bppRGB
:
658 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppRGB
);
659 case PixelFormat32bppARGB
:
660 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppARGB
);
661 case PixelFormat32bppPARGB
:
662 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppPARGB
);
663 case PixelFormat48bppRGB
:
664 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_48bppRGB
);
665 case PixelFormat64bppARGB
:
666 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_64bppARGB
);
671 case PixelFormat16bppRGB565
:
674 case PixelFormat16bppGrayScale
:
675 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppGrayScale
);
676 case PixelFormat16bppRGB555
:
677 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppRGB555
);
678 case PixelFormat16bppARGB1555
:
679 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppARGB1555
);
680 case PixelFormat24bppRGB
:
681 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_24bppRGB
);
682 case PixelFormat32bppRGB
:
683 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppRGB
);
684 case PixelFormat32bppARGB
:
685 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppARGB
);
686 case PixelFormat32bppPARGB
:
687 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppPARGB
);
688 case PixelFormat48bppRGB
:
689 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_48bppRGB
);
690 case PixelFormat64bppARGB
:
691 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_64bppARGB
);
696 case PixelFormat16bppARGB1555
:
699 case PixelFormat16bppGrayScale
:
700 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppGrayScale
);
701 case PixelFormat16bppRGB555
:
702 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppRGB555
);
703 case PixelFormat16bppRGB565
:
704 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppRGB565
);
705 case PixelFormat24bppRGB
:
706 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_24bppRGB
);
707 case PixelFormat32bppRGB
:
708 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppRGB
);
709 case PixelFormat32bppARGB
:
710 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppARGB
);
711 case PixelFormat32bppPARGB
:
712 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppPARGB
);
713 case PixelFormat48bppRGB
:
714 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_48bppRGB
);
715 case PixelFormat64bppARGB
:
716 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_64bppARGB
);
721 case PixelFormat24bppRGB
:
724 case PixelFormat16bppGrayScale
:
725 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppGrayScale
);
726 case PixelFormat16bppRGB555
:
727 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppRGB555
);
728 case PixelFormat16bppRGB565
:
729 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppRGB565
);
730 case PixelFormat16bppARGB1555
:
731 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppARGB1555
);
732 case PixelFormat32bppRGB
:
733 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppRGB
);
734 case PixelFormat32bppARGB
:
735 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppARGB
);
736 case PixelFormat32bppPARGB
:
737 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppPARGB
);
738 case PixelFormat48bppRGB
:
739 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_48bppRGB
);
740 case PixelFormat64bppARGB
:
741 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_64bppARGB
);
746 case PixelFormat32bppRGB
:
749 case PixelFormat16bppGrayScale
:
750 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppGrayScale
);
751 case PixelFormat16bppRGB555
:
752 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppRGB555
);
753 case PixelFormat16bppRGB565
:
754 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppRGB565
);
755 case PixelFormat16bppARGB1555
:
756 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppARGB1555
);
757 case PixelFormat24bppRGB
:
758 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_24bppRGB
);
759 case PixelFormat32bppARGB
:
760 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_32bppARGB
);
761 case PixelFormat32bppPARGB
:
762 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_32bppPARGB
);
763 case PixelFormat48bppRGB
:
764 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_48bppRGB
);
765 case PixelFormat64bppARGB
:
766 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_64bppARGB
);
771 case PixelFormat32bppARGB
:
774 case PixelFormat16bppGrayScale
:
775 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppGrayScale
);
776 case PixelFormat16bppRGB555
:
777 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppRGB555
);
778 case PixelFormat16bppRGB565
:
779 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppRGB565
);
780 case PixelFormat16bppARGB1555
:
781 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppARGB1555
);
782 case PixelFormat24bppRGB
:
783 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_24bppRGB
);
784 case PixelFormat32bppPARGB
:
785 convert_32bppARGB_to_32bppPARGB(width
, height
, dst_bits
, dst_stride
, src_bits
, src_stride
);
787 case PixelFormat48bppRGB
:
788 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_48bppRGB
);
789 case PixelFormat64bppARGB
:
790 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_64bppARGB
);
795 case PixelFormat32bppPARGB
:
798 case PixelFormat16bppGrayScale
:
799 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppGrayScale
);
800 case PixelFormat16bppRGB555
:
801 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppRGB555
);
802 case PixelFormat16bppRGB565
:
803 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppRGB565
);
804 case PixelFormat16bppARGB1555
:
805 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppARGB1555
);
806 case PixelFormat24bppRGB
:
807 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_24bppRGB
);
808 case PixelFormat32bppRGB
:
809 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_32bppRGB
);
810 case PixelFormat32bppARGB
:
811 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_32bppARGB
);
812 case PixelFormat48bppRGB
:
813 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_48bppRGB
);
814 case PixelFormat64bppARGB
:
815 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_64bppARGB
);
820 case PixelFormat48bppRGB
:
823 case PixelFormat16bppGrayScale
:
824 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppGrayScale
);
825 case PixelFormat16bppRGB555
:
826 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppRGB555
);
827 case PixelFormat16bppRGB565
:
828 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppRGB565
);
829 case PixelFormat16bppARGB1555
:
830 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppARGB1555
);
831 case PixelFormat24bppRGB
:
832 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_24bppRGB
);
833 case PixelFormat32bppRGB
:
834 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppRGB
);
835 case PixelFormat32bppARGB
:
836 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppARGB
);
837 case PixelFormat32bppPARGB
:
838 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppPARGB
);
839 case PixelFormat64bppARGB
:
840 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_64bppARGB
);
845 case PixelFormat64bppARGB
:
848 case PixelFormat16bppGrayScale
:
849 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppGrayScale
);
850 case PixelFormat16bppRGB555
:
851 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppRGB555
);
852 case PixelFormat16bppRGB565
:
853 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppRGB565
);
854 case PixelFormat16bppARGB1555
:
855 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppARGB1555
);
856 case PixelFormat24bppRGB
:
857 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_24bppRGB
);
858 case PixelFormat32bppRGB
:
859 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppRGB
);
860 case PixelFormat32bppARGB
:
861 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppARGB
);
862 case PixelFormat32bppPARGB
:
863 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppPARGB
);
864 case PixelFormat48bppRGB
:
865 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_48bppRGB
);
870 case PixelFormat64bppPARGB
:
873 case PixelFormat16bppGrayScale
:
874 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppGrayScale
);
875 case PixelFormat16bppRGB555
:
876 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppRGB555
);
877 case PixelFormat16bppRGB565
:
878 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppRGB565
);
879 case PixelFormat16bppARGB1555
:
880 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppARGB1555
);
881 case PixelFormat24bppRGB
:
882 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_24bppRGB
);
883 case PixelFormat32bppRGB
:
884 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppRGB
);
885 case PixelFormat32bppARGB
:
886 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppARGB
);
887 case PixelFormat32bppPARGB
:
888 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppPARGB
);
889 case PixelFormat48bppRGB
:
890 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_48bppRGB
);
891 case PixelFormat64bppARGB
:
892 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_64bppARGB
);
901 #undef convert_indexed_to_rgb
902 #undef convert_rgb_to_rgb
904 return NotImplemented
;
907 /* This function returns a pointer to an array of pixels that represents the
908 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
909 * flags. It is correct behavior that a user who calls this function with write
910 * privileges can write to the whole bitmap (not just the area in rect).
912 * FIXME: only used portion of format is bits per pixel. */
913 GpStatus WINGDIPAPI
GdipBitmapLockBits(GpBitmap
* bitmap
, GDIPCONST GpRect
* rect
,
914 UINT flags
, PixelFormat format
, BitmapData
* lockeddata
)
916 INT bitspp
= PIXELFORMATBPP(format
);
917 GpRect act_rect
; /* actual rect to be used */
920 TRACE("%p %p %d 0x%x %p\n", bitmap
, rect
, flags
, format
, lockeddata
);
922 if(!lockeddata
|| !bitmap
)
923 return InvalidParameter
;
926 if(rect
->X
< 0 || rect
->Y
< 0 || (rect
->X
+ rect
->Width
> bitmap
->width
) ||
927 (rect
->Y
+ rect
->Height
> bitmap
->height
) || !flags
)
928 return InvalidParameter
;
933 act_rect
.X
= act_rect
.Y
= 0;
934 act_rect
.Width
= bitmap
->width
;
935 act_rect
.Height
= bitmap
->height
;
940 WARN("bitmap is already locked and cannot be locked again\n");
944 if (bitmap
->bits
&& bitmap
->format
== format
&& !(flags
& ImageLockModeUserInputBuf
))
946 /* no conversion is necessary; just use the bits directly */
947 lockeddata
->Width
= act_rect
.Width
;
948 lockeddata
->Height
= act_rect
.Height
;
949 lockeddata
->PixelFormat
= format
;
950 lockeddata
->Reserved
= flags
;
951 lockeddata
->Stride
= bitmap
->stride
;
952 lockeddata
->Scan0
= bitmap
->bits
+ (bitspp
/ 8) * act_rect
.X
+
953 bitmap
->stride
* act_rect
.Y
;
955 bitmap
->lockmode
= flags
;
961 /* Make sure we can convert to the requested format. */
962 if (flags
& ImageLockModeRead
)
964 stat
= convert_pixels(0, 0, 0, NULL
, format
, 0, NULL
, bitmap
->format
, NULL
);
965 if (stat
== NotImplemented
)
967 FIXME("cannot read bitmap from %x to %x\n", bitmap
->format
, format
);
968 return NotImplemented
;
972 /* If we're opening for writing, make sure we'll be able to write back in
973 * the original format. */
974 if (flags
& ImageLockModeWrite
)
976 stat
= convert_pixels(0, 0, 0, NULL
, bitmap
->format
, 0, NULL
, format
, NULL
);
977 if (stat
== NotImplemented
)
979 FIXME("cannot write bitmap from %x to %x\n", format
, bitmap
->format
);
980 return NotImplemented
;
984 lockeddata
->Width
= act_rect
.Width
;
985 lockeddata
->Height
= act_rect
.Height
;
986 lockeddata
->PixelFormat
= format
;
987 lockeddata
->Reserved
= flags
;
989 if(!(flags
& ImageLockModeUserInputBuf
))
991 lockeddata
->Stride
= (((act_rect
.Width
* bitspp
+ 7) / 8) + 3) & ~3;
993 bitmap
->bitmapbits
= GdipAlloc(lockeddata
->Stride
* act_rect
.Height
);
995 if (!bitmap
->bitmapbits
) return OutOfMemory
;
997 lockeddata
->Scan0
= bitmap
->bitmapbits
;
1000 if (flags
& ImageLockModeRead
)
1004 if (!fixme
&& (PIXELFORMATBPP(bitmap
->format
) * act_rect
.X
) % 8 != 0)
1006 FIXME("Cannot copy rows that don't start at a whole byte.\n");
1010 stat
= convert_pixels(act_rect
.Width
, act_rect
.Height
,
1011 lockeddata
->Stride
, lockeddata
->Scan0
, format
,
1013 bitmap
->bits
+ bitmap
->stride
* act_rect
.Y
+ PIXELFORMATBPP(bitmap
->format
) * act_rect
.X
/ 8,
1014 bitmap
->format
, bitmap
->image
.palette_entries
);
1018 GdipFree(bitmap
->bitmapbits
);
1019 bitmap
->bitmapbits
= NULL
;
1024 bitmap
->lockmode
= flags
;
1026 bitmap
->lockx
= act_rect
.X
;
1027 bitmap
->locky
= act_rect
.Y
;
1032 GpStatus WINGDIPAPI
GdipBitmapSetResolution(GpBitmap
* bitmap
, REAL xdpi
, REAL ydpi
)
1034 TRACE("(%p, %.2f, %.2f)\n", bitmap
, xdpi
, ydpi
);
1036 if (!bitmap
|| xdpi
== 0.0 || ydpi
== 0.0)
1037 return InvalidParameter
;
1039 bitmap
->image
.xres
= xdpi
;
1040 bitmap
->image
.yres
= ydpi
;
1045 GpStatus WINGDIPAPI
GdipBitmapUnlockBits(GpBitmap
* bitmap
,
1046 BitmapData
* lockeddata
)
1051 TRACE("(%p,%p)\n", bitmap
, lockeddata
);
1053 if(!bitmap
|| !lockeddata
)
1054 return InvalidParameter
;
1056 if(!bitmap
->lockmode
)
1059 if(!(lockeddata
->Reserved
& ImageLockModeWrite
)){
1060 if(!(--bitmap
->numlocks
))
1061 bitmap
->lockmode
= 0;
1063 GdipFree(bitmap
->bitmapbits
);
1064 bitmap
->bitmapbits
= NULL
;
1068 if (!bitmap
->bitmapbits
&& !(lockeddata
->Reserved
& ImageLockModeUserInputBuf
))
1070 /* we passed a direct reference; no need to do anything */
1071 bitmap
->lockmode
= 0;
1072 bitmap
->numlocks
= 0;
1076 if (!fixme
&& (PIXELFORMATBPP(bitmap
->format
) * bitmap
->lockx
) % 8 != 0)
1078 FIXME("Cannot copy rows that don't start at a whole byte.\n");
1082 stat
= convert_pixels(lockeddata
->Width
, lockeddata
->Height
,
1084 bitmap
->bits
+ bitmap
->stride
* bitmap
->locky
+ PIXELFORMATBPP(bitmap
->format
) * bitmap
->lockx
/ 8,
1086 lockeddata
->Stride
, lockeddata
->Scan0
, lockeddata
->PixelFormat
, NULL
);
1090 ERR("failed to convert pixels; this should never happen\n");
1093 GdipFree(bitmap
->bitmapbits
);
1094 bitmap
->bitmapbits
= NULL
;
1095 bitmap
->lockmode
= 0;
1096 bitmap
->numlocks
= 0;
1101 GpStatus WINGDIPAPI
GdipCloneBitmapArea(REAL x
, REAL y
, REAL width
, REAL height
,
1102 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
1104 BitmapData lockeddata_src
, lockeddata_dst
;
1110 TRACE("(%f,%f,%f,%f,0x%x,%p,%p)\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1112 if (!srcBitmap
|| !dstBitmap
|| srcBitmap
->image
.type
!= ImageTypeBitmap
||
1114 x
+ width
> srcBitmap
->width
|| y
+ height
> srcBitmap
->height
)
1116 TRACE("<-- InvalidParameter\n");
1117 return InvalidParameter
;
1120 if (format
== PixelFormatDontCare
)
1121 format
= srcBitmap
->format
;
1125 area
.Width
= roundr(width
);
1126 area
.Height
= roundr(height
);
1128 stat
= GdipBitmapLockBits(srcBitmap
, &area
, ImageLockModeRead
, format
,
1130 if (stat
!= Ok
) return stat
;
1132 stat
= GdipCreateBitmapFromScan0(lockeddata_src
.Width
, lockeddata_src
.Height
,
1133 0, lockeddata_src
.PixelFormat
, NULL
, dstBitmap
);
1136 stat
= GdipBitmapLockBits(*dstBitmap
, NULL
, ImageLockModeWrite
,
1137 lockeddata_src
.PixelFormat
, &lockeddata_dst
);
1141 /* copy the image data */
1142 row_size
= (lockeddata_src
.Width
* PIXELFORMATBPP(lockeddata_src
.PixelFormat
) +7)/8;
1143 for (i
=0; i
<lockeddata_src
.Height
; i
++)
1144 memcpy((BYTE
*)lockeddata_dst
.Scan0
+lockeddata_dst
.Stride
*i
,
1145 (BYTE
*)lockeddata_src
.Scan0
+lockeddata_src
.Stride
*i
,
1148 GdipBitmapUnlockBits(*dstBitmap
, &lockeddata_dst
);
1152 GdipDisposeImage((GpImage
*)*dstBitmap
);
1155 GdipBitmapUnlockBits(srcBitmap
, &lockeddata_src
);
1165 GpStatus WINGDIPAPI
GdipCloneBitmapAreaI(INT x
, INT y
, INT width
, INT height
,
1166 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
1168 TRACE("(%i,%i,%i,%i,0x%x,%p,%p)\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1170 return GdipCloneBitmapArea(x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1173 GpStatus WINGDIPAPI
GdipCloneImage(GpImage
*image
, GpImage
**cloneImage
)
1175 GpStatus stat
= GenericError
;
1177 TRACE("%p, %p\n", image
, cloneImage
);
1179 if (!image
|| !cloneImage
)
1180 return InvalidParameter
;
1189 hr
= CreateStreamOnHGlobal(0, TRUE
, &stream
);
1191 return GenericError
;
1193 hr
= IPicture_SaveAsFile(image
->picture
, stream
, FALSE
, &size
);
1196 WARN("Failed to save image on stream\n");
1200 /* Set seek pointer back to the beginning of the picture */
1202 hr
= IStream_Seek(stream
, move
, STREAM_SEEK_SET
, NULL
);
1206 stat
= GdipLoadImageFromStream(stream
, cloneImage
);
1207 if (stat
!= Ok
) WARN("Failed to load image from stream\n");
1210 IStream_Release(stream
);
1213 else if (image
->type
== ImageTypeBitmap
)
1215 GpBitmap
*bitmap
= (GpBitmap
*)image
;
1216 BitmapData lockeddata_src
, lockeddata_dst
;
1220 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, bitmap
->format
,
1222 if (stat
!= Ok
) return stat
;
1224 stat
= GdipCreateBitmapFromScan0(lockeddata_src
.Width
, lockeddata_src
.Height
,
1225 0, lockeddata_src
.PixelFormat
, NULL
, (GpBitmap
**)cloneImage
);
1228 stat
= GdipBitmapLockBits((GpBitmap
*)*cloneImage
, NULL
, ImageLockModeWrite
,
1229 lockeddata_src
.PixelFormat
, &lockeddata_dst
);
1233 /* copy the image data */
1234 row_size
= (lockeddata_src
.Width
* PIXELFORMATBPP(lockeddata_src
.PixelFormat
) +7)/8;
1235 for (i
=0; i
<lockeddata_src
.Height
; i
++)
1236 memcpy((BYTE
*)lockeddata_dst
.Scan0
+lockeddata_dst
.Stride
*i
,
1237 (BYTE
*)lockeddata_src
.Scan0
+lockeddata_src
.Stride
*i
,
1240 GdipBitmapUnlockBits((GpBitmap
*)*cloneImage
, &lockeddata_dst
);
1244 GdipDisposeImage(*cloneImage
);
1247 GdipBitmapUnlockBits(bitmap
, &lockeddata_src
);
1253 else memcpy(&(*cloneImage
)->format
, &image
->format
, sizeof(GUID
));
1259 ERR("GpImage with no IPicture or bitmap?!\n");
1260 return NotImplemented
;
1264 GpStatus WINGDIPAPI
GdipCreateBitmapFromFile(GDIPCONST WCHAR
* filename
,
1270 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
1272 if(!filename
|| !bitmap
)
1273 return InvalidParameter
;
1275 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
1280 stat
= GdipCreateBitmapFromStream(stream
, bitmap
);
1282 IStream_Release(stream
);
1287 GpStatus WINGDIPAPI
GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO
* info
,
1288 VOID
*bits
, GpBitmap
**bitmap
)
1290 DWORD height
, stride
;
1293 FIXME("(%p, %p, %p) - partially implemented\n", info
, bits
, bitmap
);
1295 if (!info
|| !bits
|| !bitmap
)
1296 return InvalidParameter
;
1298 height
= abs(info
->bmiHeader
.biHeight
);
1299 stride
= ((info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
+ 31) >> 3) & ~3;
1301 if(info
->bmiHeader
.biHeight
> 0) /* bottom-up */
1303 bits
= (BYTE
*)bits
+ (height
- 1) * stride
;
1307 switch(info
->bmiHeader
.biBitCount
) {
1309 format
= PixelFormat1bppIndexed
;
1312 format
= PixelFormat4bppIndexed
;
1315 format
= PixelFormat8bppIndexed
;
1318 format
= PixelFormat16bppRGB555
;
1321 format
= PixelFormat24bppRGB
;
1324 format
= PixelFormat32bppRGB
;
1327 FIXME("don't know how to handle %d bpp\n", info
->bmiHeader
.biBitCount
);
1329 return InvalidParameter
;
1332 return GdipCreateBitmapFromScan0(info
->bmiHeader
.biWidth
, height
, stride
, format
,
1338 GpStatus WINGDIPAPI
GdipCreateBitmapFromFileICM(GDIPCONST WCHAR
* filename
,
1341 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
1343 return GdipCreateBitmapFromFile(filename
, bitmap
);
1346 GpStatus WINGDIPAPI
GdipCreateBitmapFromResource(HINSTANCE hInstance
,
1347 GDIPCONST WCHAR
* lpBitmapName
, GpBitmap
** bitmap
)
1350 GpStatus stat
= InvalidParameter
;
1352 TRACE("%p (%s) %p\n", hInstance
, debugstr_w(lpBitmapName
), bitmap
);
1354 if(!lpBitmapName
|| !bitmap
)
1355 return InvalidParameter
;
1358 hbm
= LoadImageW(hInstance
, lpBitmapName
, IMAGE_BITMAP
, 0, 0,
1359 LR_CREATEDIBSECTION
);
1362 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, bitmap
);
1369 GpStatus WINGDIPAPI
GdipCreateHBITMAPFromBitmap(GpBitmap
* bitmap
,
1370 HBITMAP
* hbmReturn
, ARGB background
)
1375 BITMAPINFOHEADER bih
;
1377 BitmapData lockeddata
;
1378 TRACE("(%p,%p,%x)\n", bitmap
, hbmReturn
, background
);
1380 if (!bitmap
|| !hbmReturn
) return InvalidParameter
;
1382 GdipGetImageWidth((GpImage
*)bitmap
, &width
);
1383 GdipGetImageHeight((GpImage
*)bitmap
, &height
);
1385 bih
.biSize
= sizeof(bih
);
1386 bih
.biWidth
= width
;
1387 bih
.biHeight
= height
;
1389 bih
.biBitCount
= 32;
1390 bih
.biCompression
= BI_RGB
;
1391 bih
.biSizeImage
= 0;
1392 bih
.biXPelsPerMeter
= 0;
1393 bih
.biYPelsPerMeter
= 0;
1395 bih
.biClrImportant
= 0;
1397 result
= CreateDIBSection(0, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1401 lockeddata
.Stride
= -width
* 4;
1402 lockeddata
.Scan0
= bits
+ (width
* 4 * (height
- 1));
1404 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
|ImageLockModeUserInputBuf
,
1405 PixelFormat32bppPARGB
, &lockeddata
);
1408 stat
= GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1411 stat
= GenericError
;
1413 if (stat
!= Ok
&& result
)
1415 DeleteObject(result
);
1419 *hbmReturn
= result
;
1424 GpStatus WINGDIPAPI
GdipConvertToEmfPlus(const GpGraphics
* ref
,
1425 GpMetafile
* metafile
, BOOL
* succ
, EmfType emfType
,
1426 const WCHAR
* description
, GpMetafile
** out_metafile
)
1430 TRACE("(%p,%p,%p,%u,%s,%p)\n", ref
, metafile
, succ
, emfType
,
1431 debugstr_w(description
), out_metafile
);
1433 if(!ref
|| !metafile
|| !out_metafile
)
1434 return InvalidParameter
;
1437 *out_metafile
= NULL
;
1440 FIXME("not implemented\n");
1442 return NotImplemented
;
1445 /* FIXME: this should create a bitmap in the given size with the attributes
1446 * (resolution etc.) of the graphics object */
1447 GpStatus WINGDIPAPI
GdipCreateBitmapFromGraphics(INT width
, INT height
,
1448 GpGraphics
* target
, GpBitmap
** bitmap
)
1453 TRACE("(%d, %d, %p, %p)\n", width
, height
, target
, bitmap
);
1455 if(!target
|| !bitmap
)
1456 return InvalidParameter
;
1459 FIXME("hacked stub\n");
1461 ret
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat24bppRGB
,
1467 GpStatus WINGDIPAPI
GdipCreateBitmapFromHICON(HICON hicon
, GpBitmap
** bitmap
)
1475 BitmapData lockeddata
;
1480 BITMAPINFOHEADER bih
;
1485 TRACE("%p, %p\n", hicon
, bitmap
);
1487 if(!bitmap
|| !GetIconInfo(hicon
, &iinfo
))
1488 return InvalidParameter
;
1490 /* get the size of the icon */
1491 ret
= GetObjectA(iinfo
.hbmColor
? iinfo
.hbmColor
: iinfo
.hbmMask
, sizeof(bm
), &bm
);
1493 DeleteObject(iinfo
.hbmColor
);
1494 DeleteObject(iinfo
.hbmMask
);
1495 return GenericError
;
1501 height
= abs(bm
.bmHeight
);
1502 else /* combined bitmap + mask */
1503 height
= abs(bm
.bmHeight
) / 2;
1505 bits
= HeapAlloc(GetProcessHeap(), 0, 4*width
*height
);
1507 DeleteObject(iinfo
.hbmColor
);
1508 DeleteObject(iinfo
.hbmMask
);
1512 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat32bppARGB
, NULL
, bitmap
);
1514 DeleteObject(iinfo
.hbmColor
);
1515 DeleteObject(iinfo
.hbmMask
);
1516 HeapFree(GetProcessHeap(), 0, bits
);
1523 rect
.Height
= height
;
1525 stat
= GdipBitmapLockBits(*bitmap
, &rect
, ImageLockModeWrite
, PixelFormat32bppARGB
, &lockeddata
);
1527 DeleteObject(iinfo
.hbmColor
);
1528 DeleteObject(iinfo
.hbmMask
);
1529 HeapFree(GetProcessHeap(), 0, bits
);
1530 GdipDisposeImage((GpImage
*)*bitmap
);
1534 bih
.biSize
= sizeof(bih
);
1535 bih
.biWidth
= width
;
1536 bih
.biHeight
= -height
;
1538 bih
.biBitCount
= 32;
1539 bih
.biCompression
= BI_RGB
;
1540 bih
.biSizeImage
= 0;
1541 bih
.biXPelsPerMeter
= 0;
1542 bih
.biYPelsPerMeter
= 0;
1544 bih
.biClrImportant
= 0;
1546 screendc
= GetDC(0);
1549 GetDIBits(screendc
, iinfo
.hbmColor
, 0, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1551 if (bm
.bmBitsPixel
== 32)
1555 /* If any pixel has a non-zero alpha, ignore hbmMask */
1557 for (x
=0; x
<width
&& !has_alpha
; x
++)
1558 for (y
=0; y
<height
&& !has_alpha
; y
++)
1559 if ((*src
++ & 0xff000000) != 0)
1562 else has_alpha
= FALSE
;
1566 GetDIBits(screendc
, iinfo
.hbmMask
, 0, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1570 /* copy the image data to the Bitmap */
1572 dst_row
= lockeddata
.Scan0
;
1573 for (y
=0; y
<height
; y
++)
1575 memcpy(dst_row
, src
, width
*4);
1577 dst_row
+= lockeddata
.Stride
;
1584 /* read alpha data from the mask */
1586 GetDIBits(screendc
, iinfo
.hbmMask
, 0, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1588 GetDIBits(screendc
, iinfo
.hbmMask
, height
, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1591 dst_row
= lockeddata
.Scan0
;
1592 for (y
=0; y
<height
; y
++)
1594 dst
= (DWORD
*)dst_row
;
1595 for (x
=0; x
<height
; x
++)
1597 DWORD src_value
= *src
++;
1601 *dst
++ |= 0xff000000;
1603 dst_row
+= lockeddata
.Stride
;
1608 /* set constant alpha of 255 */
1610 for (y
=0; y
<height
; y
++)
1612 dst
= (DWORD
*)dst_row
;
1613 for (x
=0; x
<height
; x
++)
1614 *dst
++ |= 0xff000000;
1615 dst_row
+= lockeddata
.Stride
;
1620 ReleaseDC(0, screendc
);
1622 DeleteObject(iinfo
.hbmColor
);
1623 DeleteObject(iinfo
.hbmMask
);
1625 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
1627 HeapFree(GetProcessHeap(), 0, bits
);
1632 static void generate_halftone_palette(ARGB
*entries
, UINT count
)
1634 static const BYTE halftone_values
[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1637 for (i
=0; i
<8 && i
<count
; i
++)
1639 entries
[i
] = 0xff000000;
1640 if (i
&1) entries
[i
] |= 0x800000;
1641 if (i
&2) entries
[i
] |= 0x8000;
1642 if (i
&4) entries
[i
] |= 0x80;
1646 entries
[i
] = 0xffc0c0c0;
1648 for (i
=9; i
<16 && i
<count
; i
++)
1650 entries
[i
] = 0xff000000;
1651 if (i
&1) entries
[i
] |= 0xff0000;
1652 if (i
&2) entries
[i
] |= 0xff00;
1653 if (i
&4) entries
[i
] |= 0xff;
1656 for (i
=16; i
<40 && i
<count
; i
++)
1661 for (i
=40; i
<256 && i
<count
; i
++)
1663 entries
[i
] = 0xff000000;
1664 entries
[i
] |= halftone_values
[(i
-40)%6];
1665 entries
[i
] |= halftone_values
[((i
-40)/6)%6] << 8;
1666 entries
[i
] |= halftone_values
[((i
-40)/36)%6] << 16;
1670 static GpStatus
get_screen_resolution(REAL
*xres
, REAL
*yres
)
1672 HDC screendc
= GetDC(0);
1674 if (!screendc
) return GenericError
;
1676 *xres
= (REAL
)GetDeviceCaps(screendc
, LOGPIXELSX
);
1677 *yres
= (REAL
)GetDeviceCaps(screendc
, LOGPIXELSY
);
1679 ReleaseDC(0, screendc
);
1684 GpStatus WINGDIPAPI
GdipCreateBitmapFromScan0(INT width
, INT height
, INT stride
,
1685 PixelFormat format
, BYTE
* scan0
, GpBitmap
** bitmap
)
1688 HBITMAP hbitmap
=NULL
;
1689 INT row_size
, dib_stride
;
1690 BYTE
*bits
=NULL
, *own_bits
=NULL
;
1694 TRACE("%d %d %d 0x%x %p %p\n", width
, height
, stride
, format
, scan0
, bitmap
);
1696 if (!bitmap
) return InvalidParameter
;
1698 if(width
<= 0 || height
<= 0 || (scan0
&& (stride
% 4))){
1700 return InvalidParameter
;
1703 if(scan0
&& !stride
)
1704 return InvalidParameter
;
1706 stat
= get_screen_resolution(&xres
, &yres
);
1707 if (stat
!= Ok
) return stat
;
1709 row_size
= (width
* PIXELFORMATBPP(format
)+7) / 8;
1710 dib_stride
= (row_size
+ 3) & ~3;
1713 stride
= dib_stride
;
1715 if (format
& PixelFormatGDI
&& !(format
& (PixelFormatAlpha
|PixelFormatIndexed
)) && !scan0
)
1717 pbmi
= GdipAlloc(sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1721 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1722 pbmi
->bmiHeader
.biWidth
= width
;
1723 pbmi
->bmiHeader
.biHeight
= -height
;
1724 pbmi
->bmiHeader
.biPlanes
= 1;
1725 /* FIXME: use the rest of the data from format */
1726 pbmi
->bmiHeader
.biBitCount
= PIXELFORMATBPP(format
);
1727 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
1728 pbmi
->bmiHeader
.biSizeImage
= 0;
1729 pbmi
->bmiHeader
.biXPelsPerMeter
= 0;
1730 pbmi
->bmiHeader
.biYPelsPerMeter
= 0;
1731 pbmi
->bmiHeader
.biClrUsed
= 0;
1732 pbmi
->bmiHeader
.biClrImportant
= 0;
1734 hbitmap
= CreateDIBSection(0, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1738 if (!hbitmap
) return GenericError
;
1740 stride
= dib_stride
;
1744 /* Not a GDI format; don't try to make an HBITMAP. */
1749 INT size
= abs(stride
) * height
;
1751 own_bits
= bits
= GdipAlloc(size
);
1752 if (!own_bits
) return OutOfMemory
;
1755 bits
+= stride
* (1 - height
);
1759 *bitmap
= GdipAlloc(sizeof(GpBitmap
));
1762 DeleteObject(hbitmap
);
1767 (*bitmap
)->image
.type
= ImageTypeBitmap
;
1768 memcpy(&(*bitmap
)->image
.format
, &ImageFormatMemoryBMP
, sizeof(GUID
));
1769 (*bitmap
)->image
.flags
= ImageFlagsNone
;
1770 (*bitmap
)->image
.frame_count
= 1;
1771 (*bitmap
)->image
.current_frame
= 0;
1772 (*bitmap
)->image
.palette_flags
= 0;
1773 (*bitmap
)->image
.palette_count
= 0;
1774 (*bitmap
)->image
.palette_size
= 0;
1775 (*bitmap
)->image
.palette_entries
= NULL
;
1776 (*bitmap
)->image
.xres
= xres
;
1777 (*bitmap
)->image
.yres
= yres
;
1778 (*bitmap
)->width
= width
;
1779 (*bitmap
)->height
= height
;
1780 (*bitmap
)->format
= format
;
1781 (*bitmap
)->image
.picture
= NULL
;
1782 (*bitmap
)->hbitmap
= hbitmap
;
1783 (*bitmap
)->hdc
= NULL
;
1784 (*bitmap
)->bits
= bits
;
1785 (*bitmap
)->stride
= stride
;
1786 (*bitmap
)->own_bits
= own_bits
;
1788 /* set format-related flags */
1789 if (format
& (PixelFormatAlpha
|PixelFormatPAlpha
|PixelFormatIndexed
))
1790 (*bitmap
)->image
.flags
|= ImageFlagsHasAlpha
;
1792 if (format
== PixelFormat1bppIndexed
||
1793 format
== PixelFormat4bppIndexed
||
1794 format
== PixelFormat8bppIndexed
)
1796 (*bitmap
)->image
.palette_size
= (*bitmap
)->image
.palette_count
= 1 << PIXELFORMATBPP(format
);
1797 (*bitmap
)->image
.palette_entries
= GdipAlloc(sizeof(ARGB
) * ((*bitmap
)->image
.palette_size
));
1799 if (!(*bitmap
)->image
.palette_entries
)
1801 GdipDisposeImage(&(*bitmap
)->image
);
1806 if (format
== PixelFormat1bppIndexed
)
1808 (*bitmap
)->image
.palette_flags
= PaletteFlagsGrayScale
;
1809 (*bitmap
)->image
.palette_entries
[0] = 0xff000000;
1810 (*bitmap
)->image
.palette_entries
[1] = 0xffffffff;
1814 if (format
== PixelFormat8bppIndexed
)
1815 (*bitmap
)->image
.palette_flags
= PaletteFlagsHalftone
;
1817 generate_halftone_palette((*bitmap
)->image
.palette_entries
,
1818 (*bitmap
)->image
.palette_count
);
1822 TRACE("<-- %p\n", *bitmap
);
1827 GpStatus WINGDIPAPI
GdipCreateBitmapFromStream(IStream
* stream
,
1832 TRACE("%p %p\n", stream
, bitmap
);
1834 stat
= GdipLoadImageFromStream(stream
, (GpImage
**) bitmap
);
1839 if((*bitmap
)->image
.type
!= ImageTypeBitmap
){
1840 GdipDisposeImage(&(*bitmap
)->image
);
1842 return GenericError
; /* FIXME: what error to return? */
1849 GpStatus WINGDIPAPI
GdipCreateBitmapFromStreamICM(IStream
* stream
,
1852 TRACE("%p %p\n", stream
, bitmap
);
1854 return GdipCreateBitmapFromStream(stream
, bitmap
);
1857 GpStatus WINGDIPAPI
GdipCreateCachedBitmap(GpBitmap
*bitmap
, GpGraphics
*graphics
,
1858 GpCachedBitmap
**cachedbmp
)
1862 TRACE("%p %p %p\n", bitmap
, graphics
, cachedbmp
);
1864 if(!bitmap
|| !graphics
|| !cachedbmp
)
1865 return InvalidParameter
;
1867 *cachedbmp
= GdipAlloc(sizeof(GpCachedBitmap
));
1871 stat
= GdipCloneImage(&(bitmap
->image
), &(*cachedbmp
)->image
);
1873 GdipFree(*cachedbmp
);
1880 GpStatus WINGDIPAPI
GdipCreateHICONFromBitmap(GpBitmap
*bitmap
, HICON
*hicon
)
1883 BitmapData lockeddata
;
1884 ULONG andstride
, xorstride
, bitssize
;
1885 LPBYTE andbits
, xorbits
, androw
, xorrow
, srcrow
;
1888 TRACE("(%p, %p)\n", bitmap
, hicon
);
1890 if (!bitmap
|| !hicon
)
1891 return InvalidParameter
;
1893 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
,
1894 PixelFormat32bppPARGB
, &lockeddata
);
1897 andstride
= ((lockeddata
.Width
+31)/32)*4;
1898 xorstride
= lockeddata
.Width
*4;
1899 bitssize
= (andstride
+ xorstride
) * lockeddata
.Height
;
1901 andbits
= GdipAlloc(bitssize
);
1905 xorbits
= andbits
+ andstride
* lockeddata
.Height
;
1907 for (y
=0; y
<lockeddata
.Height
; y
++)
1909 srcrow
= ((LPBYTE
)lockeddata
.Scan0
) + lockeddata
.Stride
* y
;
1911 androw
= andbits
+ andstride
* y
;
1912 for (x
=0; x
<lockeddata
.Width
; x
++)
1913 if (srcrow
[3+4*x
] >= 128)
1914 androw
[x
/8] |= 1 << (7-x
%8);
1916 xorrow
= xorbits
+ xorstride
* y
;
1917 memcpy(xorrow
, srcrow
, xorstride
);
1920 *hicon
= CreateIcon(NULL
, lockeddata
.Width
, lockeddata
.Height
, 1, 32,
1928 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1934 GpStatus WINGDIPAPI
GdipDeleteCachedBitmap(GpCachedBitmap
*cachedbmp
)
1936 TRACE("%p\n", cachedbmp
);
1939 return InvalidParameter
;
1941 GdipDisposeImage(cachedbmp
->image
);
1942 GdipFree(cachedbmp
);
1947 GpStatus WINGDIPAPI
GdipDrawCachedBitmap(GpGraphics
*graphics
,
1948 GpCachedBitmap
*cachedbmp
, INT x
, INT y
)
1950 TRACE("%p %p %d %d\n", graphics
, cachedbmp
, x
, y
);
1952 if(!graphics
|| !cachedbmp
)
1953 return InvalidParameter
;
1955 return GdipDrawImage(graphics
, cachedbmp
->image
, (REAL
)x
, (REAL
)y
);
1958 GpStatus WINGDIPAPI
GdipEmfToWmfBits(HENHMETAFILE hemf
, UINT cbData16
,
1959 LPBYTE pData16
, INT iMapMode
, INT eFlags
)
1961 FIXME("(%p, %d, %p, %d, %d): stub\n", hemf
, cbData16
, pData16
, iMapMode
, eFlags
);
1962 return NotImplemented
;
1965 /* Internal utility function: Replace the image data of dst with that of src,
1967 static void move_bitmap(GpBitmap
*dst
, GpBitmap
*src
, BOOL clobber_palette
)
1969 GdipFree(dst
->bitmapbits
);
1971 DeleteObject(dst
->hbitmap
);
1973 if (clobber_palette
)
1975 GdipFree(dst
->image
.palette_entries
);
1976 dst
->image
.palette_flags
= src
->image
.palette_flags
;
1977 dst
->image
.palette_count
= src
->image
.palette_count
;
1978 dst
->image
.palette_entries
= src
->image
.palette_entries
;
1981 GdipFree(src
->image
.palette_entries
);
1983 dst
->image
.xres
= src
->image
.xres
;
1984 dst
->image
.yres
= src
->image
.yres
;
1985 dst
->width
= src
->width
;
1986 dst
->height
= src
->height
;
1987 dst
->format
= src
->format
;
1988 dst
->hbitmap
= src
->hbitmap
;
1989 dst
->hdc
= src
->hdc
;
1990 dst
->bits
= src
->bits
;
1991 dst
->stride
= src
->stride
;
1992 dst
->own_bits
= src
->own_bits
;
1997 GpStatus WINGDIPAPI
GdipDisposeImage(GpImage
*image
)
1999 TRACE("%p\n", image
);
2002 return InvalidParameter
;
2004 if (image
->type
== ImageTypeBitmap
)
2006 GdipFree(((GpBitmap
*)image
)->bitmapbits
);
2007 GdipFree(((GpBitmap
*)image
)->own_bits
);
2008 DeleteDC(((GpBitmap
*)image
)->hdc
);
2009 DeleteObject(((GpBitmap
*)image
)->hbitmap
);
2011 else if (image
->type
== ImageTypeMetafile
)
2013 GpMetafile
*metafile
= (GpMetafile
*)image
;
2014 GdipFree(metafile
->comment_data
);
2015 DeleteEnhMetaFile(CloseEnhMetaFile(metafile
->record_dc
));
2016 DeleteEnhMetaFile(metafile
->hemf
);
2017 if (metafile
->record_graphics
)
2019 WARN("metafile closed while recording\n");
2020 /* not sure what to do here; for now just prevent the graphics from functioning or using this object */
2021 metafile
->record_graphics
->image
= NULL
;
2022 metafile
->record_graphics
->busy
= TRUE
;
2027 WARN("invalid image: %p\n", image
);
2031 IPicture_Release(image
->picture
);
2032 GdipFree(image
->palette_entries
);
2039 GpStatus WINGDIPAPI
GdipFindFirstImageItem(GpImage
*image
, ImageItemData
* item
)
2043 TRACE("(%p,%p)\n", image
, item
);
2046 return InvalidParameter
;
2049 FIXME("not implemented\n");
2051 return NotImplemented
;
2054 GpStatus WINGDIPAPI
GdipGetImageItemData(GpImage
*image
, ImageItemData
*item
)
2058 TRACE("(%p,%p)\n", image
, item
);
2061 FIXME("not implemented\n");
2063 return NotImplemented
;
2066 GpStatus WINGDIPAPI
GdipGetImageBounds(GpImage
*image
, GpRectF
*srcRect
,
2069 TRACE("%p %p %p\n", image
, srcRect
, srcUnit
);
2071 if(!image
|| !srcRect
|| !srcUnit
)
2072 return InvalidParameter
;
2073 if(image
->type
== ImageTypeMetafile
){
2074 *srcRect
= ((GpMetafile
*)image
)->bounds
;
2075 *srcUnit
= ((GpMetafile
*)image
)->unit
;
2077 else if(image
->type
== ImageTypeBitmap
){
2078 srcRect
->X
= srcRect
->Y
= 0.0;
2079 srcRect
->Width
= (REAL
) ((GpBitmap
*)image
)->width
;
2080 srcRect
->Height
= (REAL
) ((GpBitmap
*)image
)->height
;
2081 *srcUnit
= UnitPixel
;
2084 srcRect
->X
= srcRect
->Y
= 0.0;
2085 srcRect
->Width
= ipicture_pixel_width(image
->picture
);
2086 srcRect
->Height
= ipicture_pixel_height(image
->picture
);
2087 *srcUnit
= UnitPixel
;
2090 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect
->X
, srcRect
->Y
,
2091 srcRect
->Width
, srcRect
->Height
, *srcUnit
);
2096 GpStatus WINGDIPAPI
GdipGetImageDimension(GpImage
*image
, REAL
*width
,
2099 TRACE("%p %p %p\n", image
, width
, height
);
2101 if(!image
|| !height
|| !width
)
2102 return InvalidParameter
;
2104 if(image
->type
== ImageTypeMetafile
){
2106 REAL res
= (REAL
)GetDeviceCaps(hdc
, LOGPIXELSX
);
2110 *height
= convert_unit(res
, ((GpMetafile
*)image
)->unit
) *
2111 ((GpMetafile
*)image
)->bounds
.Height
;
2113 *width
= convert_unit(res
, ((GpMetafile
*)image
)->unit
) *
2114 ((GpMetafile
*)image
)->bounds
.Width
;
2117 else if(image
->type
== ImageTypeBitmap
){
2118 *height
= ((GpBitmap
*)image
)->height
;
2119 *width
= ((GpBitmap
*)image
)->width
;
2122 *height
= ipicture_pixel_height(image
->picture
);
2123 *width
= ipicture_pixel_width(image
->picture
);
2126 TRACE("returning (%f, %f)\n", *height
, *width
);
2130 GpStatus WINGDIPAPI
GdipGetImageGraphicsContext(GpImage
*image
,
2131 GpGraphics
**graphics
)
2136 TRACE("%p %p\n", image
, graphics
);
2138 if(!image
|| !graphics
)
2139 return InvalidParameter
;
2141 if (image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)image
)->hbitmap
)
2143 hdc
= ((GpBitmap
*)image
)->hdc
;
2146 hdc
= CreateCompatibleDC(0);
2147 SelectObject(hdc
, ((GpBitmap
*)image
)->hbitmap
);
2148 ((GpBitmap
*)image
)->hdc
= hdc
;
2151 stat
= GdipCreateFromHDC(hdc
, graphics
);
2154 (*graphics
)->image
= image
;
2156 else if (image
->type
== ImageTypeMetafile
)
2157 stat
= METAFILE_GetGraphicsContext((GpMetafile
*)image
, graphics
);
2159 stat
= graphics_from_image(image
, graphics
);
2164 GpStatus WINGDIPAPI
GdipGetImageHeight(GpImage
*image
, UINT
*height
)
2166 TRACE("%p %p\n", image
, height
);
2168 if(!image
|| !height
)
2169 return InvalidParameter
;
2171 if(image
->type
== ImageTypeMetafile
){
2173 REAL res
= (REAL
)GetDeviceCaps(hdc
, LOGPIXELSX
);
2177 *height
= roundr(convert_unit(res
, ((GpMetafile
*)image
)->unit
) *
2178 ((GpMetafile
*)image
)->bounds
.Height
);
2180 else if(image
->type
== ImageTypeBitmap
)
2181 *height
= ((GpBitmap
*)image
)->height
;
2183 *height
= ipicture_pixel_height(image
->picture
);
2185 TRACE("returning %d\n", *height
);
2190 GpStatus WINGDIPAPI
GdipGetImageHorizontalResolution(GpImage
*image
, REAL
*res
)
2193 return InvalidParameter
;
2197 TRACE("(%p) <-- %0.2f\n", image
, *res
);
2202 GpStatus WINGDIPAPI
GdipGetImagePaletteSize(GpImage
*image
, INT
*size
)
2204 TRACE("%p %p\n", image
, size
);
2207 return InvalidParameter
;
2209 if (image
->palette_count
== 0)
2210 *size
= sizeof(ColorPalette
);
2212 *size
= sizeof(UINT
)*2 + sizeof(ARGB
)*image
->palette_count
;
2214 TRACE("<-- %u\n", *size
);
2219 /* FIXME: test this function for non-bitmap types */
2220 GpStatus WINGDIPAPI
GdipGetImagePixelFormat(GpImage
*image
, PixelFormat
*format
)
2222 TRACE("%p %p\n", image
, format
);
2224 if(!image
|| !format
)
2225 return InvalidParameter
;
2227 if(image
->type
!= ImageTypeBitmap
)
2228 *format
= PixelFormat24bppRGB
;
2230 *format
= ((GpBitmap
*) image
)->format
;
2235 GpStatus WINGDIPAPI
GdipGetImageRawFormat(GpImage
*image
, GUID
*format
)
2237 TRACE("(%p, %p)\n", image
, format
);
2239 if(!image
|| !format
)
2240 return InvalidParameter
;
2242 memcpy(format
, &image
->format
, sizeof(GUID
));
2247 GpStatus WINGDIPAPI
GdipGetImageType(GpImage
*image
, ImageType
*type
)
2249 TRACE("%p %p\n", image
, type
);
2252 return InvalidParameter
;
2254 *type
= image
->type
;
2259 GpStatus WINGDIPAPI
GdipGetImageVerticalResolution(GpImage
*image
, REAL
*res
)
2262 return InvalidParameter
;
2266 TRACE("(%p) <-- %0.2f\n", image
, *res
);
2271 GpStatus WINGDIPAPI
GdipGetImageWidth(GpImage
*image
, UINT
*width
)
2273 TRACE("%p %p\n", image
, width
);
2275 if(!image
|| !width
)
2276 return InvalidParameter
;
2278 if(image
->type
== ImageTypeMetafile
){
2280 REAL res
= (REAL
)GetDeviceCaps(hdc
, LOGPIXELSX
);
2284 *width
= roundr(convert_unit(res
, ((GpMetafile
*)image
)->unit
) *
2285 ((GpMetafile
*)image
)->bounds
.Width
);
2287 else if(image
->type
== ImageTypeBitmap
)
2288 *width
= ((GpBitmap
*)image
)->width
;
2290 *width
= ipicture_pixel_width(image
->picture
);
2292 TRACE("returning %d\n", *width
);
2297 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromMetafile(GpMetafile
* metafile
,
2298 MetafileHeader
* header
)
2302 TRACE("(%p, %p)\n", metafile
, header
);
2304 if(!metafile
|| !header
)
2305 return InvalidParameter
;
2308 FIXME("not implemented\n");
2310 memset(header
, 0, sizeof(MetafileHeader
));
2315 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromEmf(HENHMETAFILE hEmf
,
2316 MetafileHeader
*header
)
2320 if(!hEmf
|| !header
)
2321 return InvalidParameter
;
2324 FIXME("not implemented\n");
2326 memset(header
, 0, sizeof(MetafileHeader
));
2331 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromFile(GDIPCONST WCHAR
*filename
,
2332 MetafileHeader
*header
)
2336 TRACE("(%s,%p)\n", debugstr_w(filename
), header
);
2338 if(!filename
|| !header
)
2339 return InvalidParameter
;
2342 FIXME("not implemented\n");
2344 memset(header
, 0, sizeof(MetafileHeader
));
2349 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromStream(IStream
*stream
,
2350 MetafileHeader
*header
)
2354 TRACE("(%p,%p)\n", stream
, header
);
2356 if(!stream
|| !header
)
2357 return InvalidParameter
;
2360 FIXME("not implemented\n");
2362 memset(header
, 0, sizeof(MetafileHeader
));
2367 GpStatus WINGDIPAPI
GdipGetAllPropertyItems(GpImage
*image
, UINT size
,
2368 UINT num
, PropertyItem
* items
)
2372 TRACE("(%p, %u, %u, %p)\n", image
, size
, num
, items
);
2375 FIXME("not implemented\n");
2377 return InvalidParameter
;
2380 GpStatus WINGDIPAPI
GdipGetPropertyCount(GpImage
*image
, UINT
* num
)
2384 TRACE("(%p, %p)\n", image
, num
);
2387 FIXME("not implemented\n");
2393 GpStatus WINGDIPAPI
GdipGetPropertyIdList(GpImage
*image
, UINT num
, PROPID
* list
)
2397 TRACE("(%p, %u, %p)\n", image
, num
, list
);
2400 FIXME("not implemented\n");
2402 return InvalidParameter
;
2405 GpStatus WINGDIPAPI
GdipGetPropertyItem(GpImage
*image
, PROPID id
, UINT size
,
2406 PropertyItem
* buffer
)
2410 TRACE("(%p, %u, %u, %p)\n", image
, id
, size
, buffer
);
2413 FIXME("not implemented\n");
2415 return InvalidParameter
;
2418 GpStatus WINGDIPAPI
GdipGetPropertyItemSize(GpImage
*image
, PROPID pid
,
2423 TRACE("%p %x %p\n", image
, pid
, size
);
2426 return InvalidParameter
;
2429 FIXME("not implemented\n");
2431 return NotImplemented
;
2434 GpStatus WINGDIPAPI
GdipGetPropertySize(GpImage
*image
, UINT
* size
, UINT
* num
)
2438 TRACE("(%p,%p,%p)\n", image
, size
, num
);
2441 FIXME("not implemented\n");
2443 return InvalidParameter
;
2446 struct image_format_dimension
2449 const GUID
*dimension
;
2452 static struct image_format_dimension image_format_dimensions
[] =
2454 {&ImageFormatGIF
, &FrameDimensionTime
},
2455 {&ImageFormatIcon
, &FrameDimensionResolution
},
2459 GpStatus WINGDIPAPI
GdipImageGetFrameCount(GpImage
*image
,
2460 GDIPCONST GUID
* dimensionID
, UINT
* count
)
2462 TRACE("(%p,%s,%p)\n", image
, debugstr_guid(dimensionID
), count
);
2464 if(!image
|| !count
)
2465 return InvalidParameter
;
2468 IsEqualGUID(dimensionID
, &image
->format
) ||
2469 IsEqualGUID(dimensionID
, &FrameDimensionPage
) ||
2470 IsEqualGUID(dimensionID
, &FrameDimensionTime
))
2472 *count
= image
->frame_count
;
2476 return InvalidParameter
;
2479 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsCount(GpImage
*image
,
2482 TRACE("(%p, %p)\n", image
, count
);
2484 /* Native gdiplus 1.1 does not yet support multiple frame dimensions. */
2486 if(!image
|| !count
)
2487 return InvalidParameter
;
2494 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsList(GpImage
* image
,
2495 GUID
* dimensionIDs
, UINT count
)
2498 const GUID
*result
=NULL
;
2500 TRACE("(%p,%p,%u)\n", image
, dimensionIDs
, count
);
2502 if(!image
|| !dimensionIDs
|| count
!= 1)
2503 return InvalidParameter
;
2505 for (i
=0; image_format_dimensions
[i
].format
; i
++)
2507 if (IsEqualGUID(&image
->format
, image_format_dimensions
[i
].format
))
2509 result
= image_format_dimensions
[i
].dimension
;
2515 result
= &FrameDimensionPage
;
2517 memcpy(dimensionIDs
, result
, sizeof(GUID
));
2522 GpStatus WINGDIPAPI
GdipImageSelectActiveFrame(GpImage
*image
,
2523 GDIPCONST GUID
* dimensionID
, UINT frameidx
)
2527 TRACE("(%p, %s, %u)\n", image
, debugstr_guid(dimensionID
), frameidx
);
2529 if(!image
|| !dimensionID
)
2530 return InvalidParameter
;
2533 FIXME("not implemented\n");
2538 GpStatus WINGDIPAPI
GdipLoadImageFromFile(GDIPCONST WCHAR
* filename
,
2544 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
2546 if (!filename
|| !image
)
2547 return InvalidParameter
;
2549 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
2554 stat
= GdipLoadImageFromStream(stream
, image
);
2556 IStream_Release(stream
);
2561 /* FIXME: no icm handling */
2562 GpStatus WINGDIPAPI
GdipLoadImageFromFileICM(GDIPCONST WCHAR
* filename
,GpImage
**image
)
2564 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
2566 return GdipLoadImageFromFile(filename
, image
);
2569 static const WICPixelFormatGUID
*wic_pixel_formats
[] = {
2570 &GUID_WICPixelFormat16bppBGR555
,
2571 &GUID_WICPixelFormat24bppBGR
,
2572 &GUID_WICPixelFormat32bppBGR
,
2573 &GUID_WICPixelFormat32bppBGRA
,
2574 &GUID_WICPixelFormat32bppPBGRA
,
2578 static const PixelFormat wic_gdip_formats
[] = {
2579 PixelFormat16bppRGB555
,
2580 PixelFormat24bppRGB
,
2581 PixelFormat32bppRGB
,
2582 PixelFormat32bppARGB
,
2583 PixelFormat32bppPARGB
,
2586 static GpStatus
decode_image_wic(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
2591 IWICBitmapDecoder
*decoder
;
2592 IWICBitmapFrameDecode
*frame
;
2593 IWICBitmapSource
*source
=NULL
;
2594 WICPixelFormatGUID wic_format
;
2595 PixelFormat gdip_format
=0;
2597 UINT width
, height
, frame_count
;
2598 BitmapData lockeddata
;
2602 initresult
= CoInitialize(NULL
);
2604 hr
= CoCreateInstance(clsid
, NULL
, CLSCTX_INPROC_SERVER
,
2605 &IID_IWICBitmapDecoder
, (void**)&decoder
);
2606 if (FAILED(hr
)) goto end
;
2608 hr
= IWICBitmapDecoder_Initialize(decoder
, (IStream
*)stream
, WICDecodeMetadataCacheOnLoad
);
2611 IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
2612 /* FIXME: set current frame */
2613 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
2616 if (SUCCEEDED(hr
)) /* got frame */
2618 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &wic_format
);
2622 for (i
=0; wic_pixel_formats
[i
]; i
++)
2624 if (IsEqualGUID(&wic_format
, wic_pixel_formats
[i
]))
2626 source
= (IWICBitmapSource
*)frame
;
2627 IWICBitmapSource_AddRef(source
);
2628 gdip_format
= wic_gdip_formats
[i
];
2634 /* unknown format; fall back on 32bppARGB */
2635 hr
= WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA
, (IWICBitmapSource
*)frame
, &source
);
2636 gdip_format
= PixelFormat32bppARGB
;
2640 if (SUCCEEDED(hr
)) /* got source */
2642 hr
= IWICBitmapSource_GetSize(source
, &width
, &height
);
2645 status
= GdipCreateBitmapFromScan0(width
, height
, 0, gdip_format
,
2648 if (SUCCEEDED(hr
) && status
== Ok
) /* created bitmap */
2650 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeWrite
,
2651 gdip_format
, &lockeddata
);
2652 if (status
== Ok
) /* locked bitmap */
2657 for (i
=0; i
<height
; i
++)
2660 hr
= IWICBitmapSource_CopyPixels(source
, &wrc
, abs(lockeddata
.Stride
),
2661 abs(lockeddata
.Stride
), (BYTE
*)lockeddata
.Scan0
+lockeddata
.Stride
*i
);
2662 if (FAILED(hr
)) break;
2665 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
2668 if (SUCCEEDED(hr
) && status
== Ok
)
2669 *image
= (GpImage
*)bitmap
;
2673 GdipDisposeImage((GpImage
*)bitmap
);
2676 if (SUCCEEDED(hr
) && status
== Ok
)
2679 hr
= IWICBitmapSource_GetResolution(source
, &dpix
, &dpiy
);
2682 bitmap
->image
.xres
= dpix
;
2683 bitmap
->image
.yres
= dpiy
;
2689 IWICBitmapSource_Release(source
);
2692 IWICBitmapFrameDecode_Release(frame
);
2695 IWICBitmapDecoder_Release(decoder
);
2698 if (SUCCEEDED(initresult
)) CoUninitialize();
2700 if (FAILED(hr
) && status
== Ok
) status
= hresult_to_status(hr
);
2704 /* Native GDI+ used to be smarter, but since Win7 it just sets these flags. */
2705 bitmap
->image
.flags
|= ImageFlagsReadOnly
|ImageFlagsHasRealPixelSize
|ImageFlagsHasRealDPI
|ImageFlagsColorSpaceRGB
;
2706 bitmap
->image
.frame_count
= frame_count
;
2707 bitmap
->image
.current_frame
= 0;
2713 static GpStatus
decode_image_icon(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
2715 return decode_image_wic(stream
, &CLSID_WICIcoDecoder
, image
);
2718 static GpStatus
decode_image_bmp(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
2723 status
= decode_image_wic(stream
, &CLSID_WICBmpDecoder
, image
);
2725 bitmap
= (GpBitmap
*)*image
;
2727 if (status
== Ok
&& bitmap
->format
== PixelFormat32bppARGB
)
2729 /* WIC supports bmp files with alpha, but gdiplus does not */
2730 bitmap
->format
= PixelFormat32bppRGB
;
2736 static GpStatus
decode_image_jpeg(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
2738 return decode_image_wic(stream
, &CLSID_WICJpegDecoder
, image
);
2741 static GpStatus
decode_image_png(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
2743 return decode_image_wic(stream
, &CLSID_WICPngDecoder
, image
);
2746 static GpStatus
decode_image_gif(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
2748 return decode_image_wic(stream
, &CLSID_WICGifDecoder
, image
);
2751 static GpStatus
decode_image_tiff(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
2753 return decode_image_wic(stream
, &CLSID_WICTiffDecoder
, image
);
2756 static GpStatus
decode_image_olepicture_metafile(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
2760 TRACE("%p %p\n", stream
, image
);
2762 if(!stream
|| !image
)
2763 return InvalidParameter
;
2765 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
2766 (LPVOID
*) &pic
) != S_OK
){
2767 TRACE("Could not load picture\n");
2768 return GenericError
;
2771 /* FIXME: missing initialization code */
2772 *image
= GdipAlloc(sizeof(GpMetafile
));
2773 if(!*image
) return OutOfMemory
;
2774 (*image
)->type
= ImageTypeMetafile
;
2775 (*image
)->picture
= pic
;
2776 (*image
)->flags
= ImageFlagsNone
;
2777 (*image
)->frame_count
= 1;
2778 (*image
)->current_frame
= 0;
2779 (*image
)->palette_flags
= 0;
2780 (*image
)->palette_count
= 0;
2781 (*image
)->palette_size
= 0;
2782 (*image
)->palette_entries
= NULL
;
2784 TRACE("<-- %p\n", *image
);
2789 typedef GpStatus (*encode_image_func
)(GpImage
*image
, IStream
* stream
,
2790 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
);
2792 typedef GpStatus (*decode_image_func
)(IStream
*stream
, REFCLSID clsid
, GpImage
** image
);
2794 typedef struct image_codec
{
2795 ImageCodecInfo info
;
2796 encode_image_func encode_func
;
2797 decode_image_func decode_func
;
2812 static const struct image_codec codecs
[NUM_CODECS
];
2814 static GpStatus
get_decoder_info(IStream
* stream
, const struct image_codec
**result
)
2817 const BYTE
*pattern
, *mask
;
2823 /* seek to the start of the stream */
2825 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
2826 if (FAILED(hr
)) return hresult_to_status(hr
);
2828 /* read the first 8 bytes */
2829 /* FIXME: This assumes all codecs have signatures <= 8 bytes in length */
2830 hr
= IStream_Read(stream
, signature
, 8, &bytesread
);
2831 if (FAILED(hr
)) return hresult_to_status(hr
);
2832 if (hr
== S_FALSE
|| bytesread
== 0) return GenericError
;
2834 for (i
= 0; i
< NUM_CODECS
; i
++) {
2835 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
) &&
2836 bytesread
>= codecs
[i
].info
.SigSize
)
2838 for (sig
=0; sig
<codecs
[i
].info
.SigCount
; sig
++)
2840 pattern
= &codecs
[i
].info
.SigPattern
[codecs
[i
].info
.SigSize
*sig
];
2841 mask
= &codecs
[i
].info
.SigMask
[codecs
[i
].info
.SigSize
*sig
];
2842 for (j
=0; j
<codecs
[i
].info
.SigSize
; j
++)
2843 if ((signature
[j
] & mask
[j
]) != pattern
[j
])
2845 if (j
== codecs
[i
].info
.SigSize
)
2847 *result
= &codecs
[i
];
2854 TRACE("no match for %i byte signature %x %x %x %x %x %x %x %x\n", bytesread
,
2855 signature
[0],signature
[1],signature
[2],signature
[3],
2856 signature
[4],signature
[5],signature
[6],signature
[7]);
2858 return GenericError
;
2861 GpStatus WINGDIPAPI
GdipLoadImageFromStream(IStream
* stream
, GpImage
**image
)
2866 const struct image_codec
*codec
=NULL
;
2868 /* choose an appropriate image decoder */
2869 stat
= get_decoder_info(stream
, &codec
);
2870 if (stat
!= Ok
) return stat
;
2872 /* seek to the start of the stream */
2874 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
2875 if (FAILED(hr
)) return hresult_to_status(hr
);
2877 /* call on the image decoder to do the real work */
2878 stat
= codec
->decode_func(stream
, &codec
->info
.Clsid
, image
);
2880 /* take note of the original data format */
2883 memcpy(&(*image
)->format
, &codec
->info
.FormatID
, sizeof(GUID
));
2890 GpStatus WINGDIPAPI
GdipLoadImageFromStreamICM(IStream
* stream
, GpImage
**image
)
2892 TRACE("%p %p\n", stream
, image
);
2894 return GdipLoadImageFromStream(stream
, image
);
2897 GpStatus WINGDIPAPI
GdipRemovePropertyItem(GpImage
*image
, PROPID propId
)
2901 TRACE("(%p,%u)\n", image
, propId
);
2904 return InvalidParameter
;
2907 FIXME("not implemented\n");
2909 return NotImplemented
;
2912 GpStatus WINGDIPAPI
GdipSetPropertyItem(GpImage
*image
, GDIPCONST PropertyItem
* item
)
2916 TRACE("(%p,%p)\n", image
, item
);
2919 FIXME("not implemented\n");
2921 return NotImplemented
;
2924 GpStatus WINGDIPAPI
GdipSaveImageToFile(GpImage
*image
, GDIPCONST WCHAR
* filename
,
2925 GDIPCONST CLSID
*clsidEncoder
,
2926 GDIPCONST EncoderParameters
*encoderParams
)
2931 TRACE("%p (%s) %p %p\n", image
, debugstr_w(filename
), clsidEncoder
, encoderParams
);
2933 if (!image
|| !filename
|| !clsidEncoder
)
2934 return InvalidParameter
;
2936 stat
= GdipCreateStreamOnFile(filename
, GENERIC_WRITE
, &stream
);
2938 return GenericError
;
2940 stat
= GdipSaveImageToStream(image
, stream
, clsidEncoder
, encoderParams
);
2942 IStream_Release(stream
);
2946 /*************************************************************************
2947 * Encoding functions -
2948 * These functions encode an image in different image file formats.
2950 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
2951 #define BITMAP_FORMAT_JPEG 0xd8ff
2952 #define BITMAP_FORMAT_GIF 0x4947
2953 #define BITMAP_FORMAT_PNG 0x5089
2954 #define BITMAP_FORMAT_APM 0xcdd7
2956 static GpStatus
encode_image_WIC(GpImage
*image
, IStream
* stream
,
2957 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
2961 IWICBitmapEncoder
*encoder
;
2962 IWICBitmapFrameEncode
*frameencode
;
2963 IPropertyBag2
*encoderoptions
;
2966 PixelFormat gdipformat
=0;
2967 WICPixelFormatGUID wicformat
;
2969 BitmapData lockeddata
;
2973 if (image
->type
!= ImageTypeBitmap
)
2974 return GenericError
;
2976 bitmap
= (GpBitmap
*)image
;
2978 GdipGetImageWidth(image
, &width
);
2979 GdipGetImageHeight(image
, &height
);
2986 initresult
= CoInitialize(NULL
);
2988 hr
= CoCreateInstance(clsid
, NULL
, CLSCTX_INPROC_SERVER
,
2989 &IID_IWICBitmapEncoder
, (void**)&encoder
);
2992 if (SUCCEEDED(initresult
)) CoUninitialize();
2993 return hresult_to_status(hr
);
2996 hr
= IWICBitmapEncoder_Initialize(encoder
, stream
, WICBitmapEncoderNoCache
);
3000 hr
= IWICBitmapEncoder_CreateNewFrame(encoder
, &frameencode
, &encoderoptions
);
3003 if (SUCCEEDED(hr
)) /* created frame */
3005 hr
= IWICBitmapFrameEncode_Initialize(frameencode
, encoderoptions
);
3008 hr
= IWICBitmapFrameEncode_SetSize(frameencode
, width
, height
);
3011 /* FIXME: use the resolution from the image */
3012 hr
= IWICBitmapFrameEncode_SetResolution(frameencode
, 96.0, 96.0);
3016 for (i
=0; wic_pixel_formats
[i
]; i
++)
3018 if (wic_gdip_formats
[i
] == bitmap
->format
)
3021 if (wic_pixel_formats
[i
])
3022 memcpy(&wicformat
, wic_pixel_formats
[i
], sizeof(GUID
));
3024 memcpy(&wicformat
, &GUID_WICPixelFormat32bppBGRA
, sizeof(GUID
));
3026 hr
= IWICBitmapFrameEncode_SetPixelFormat(frameencode
, &wicformat
);
3028 for (i
=0; wic_pixel_formats
[i
]; i
++)
3030 if (IsEqualGUID(&wicformat
, wic_pixel_formats
[i
]))
3033 if (wic_pixel_formats
[i
])
3034 gdipformat
= wic_gdip_formats
[i
];
3037 ERR("cannot provide pixel format %s\n", debugstr_guid(&wicformat
));
3044 stat
= GdipBitmapLockBits(bitmap
, &rc
, ImageLockModeRead
, gdipformat
,
3049 UINT row_size
= (lockeddata
.Width
* PIXELFORMATBPP(gdipformat
) + 7)/8;
3052 /* write one row at a time in case stride is negative */
3053 row
= lockeddata
.Scan0
;
3054 for (i
=0; i
<lockeddata
.Height
; i
++)
3056 hr
= IWICBitmapFrameEncode_WritePixels(frameencode
, 1, row_size
, row_size
, row
);
3057 if (FAILED(hr
)) break;
3058 row
+= lockeddata
.Stride
;
3061 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
3068 hr
= IWICBitmapFrameEncode_Commit(frameencode
);
3070 IWICBitmapFrameEncode_Release(frameencode
);
3071 IPropertyBag2_Release(encoderoptions
);
3075 hr
= IWICBitmapEncoder_Commit(encoder
);
3077 IWICBitmapEncoder_Release(encoder
);
3079 if (SUCCEEDED(initresult
)) CoUninitialize();
3081 return hresult_to_status(hr
);
3084 static GpStatus
encode_image_BMP(GpImage
*image
, IStream
* stream
,
3085 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
3087 return encode_image_WIC(image
, stream
, &CLSID_WICBmpEncoder
, params
);
3090 static GpStatus
encode_image_tiff(GpImage
*image
, IStream
* stream
,
3091 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
3093 return encode_image_WIC(image
, stream
, &CLSID_WICTiffEncoder
, params
);
3096 static GpStatus
encode_image_png(GpImage
*image
, IStream
* stream
,
3097 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
3099 return encode_image_WIC(image
, stream
, &CLSID_WICPngEncoder
, params
);
3102 static GpStatus
encode_image_jpeg(GpImage
*image
, IStream
* stream
,
3103 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
3105 return encode_image_WIC(image
, stream
, &CLSID_WICJpegEncoder
, params
);
3108 /*****************************************************************************
3109 * GdipSaveImageToStream [GDIPLUS.@]
3111 GpStatus WINGDIPAPI
GdipSaveImageToStream(GpImage
*image
, IStream
* stream
,
3112 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
3115 encode_image_func encode_image
;
3118 TRACE("%p %p %p %p\n", image
, stream
, clsid
, params
);
3120 if(!image
|| !stream
)
3121 return InvalidParameter
;
3123 /* select correct encoder */
3124 encode_image
= NULL
;
3125 for (i
= 0; i
< NUM_CODECS
; i
++) {
3126 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
) &&
3127 IsEqualCLSID(clsid
, &codecs
[i
].info
.Clsid
))
3128 encode_image
= codecs
[i
].encode_func
;
3130 if (encode_image
== NULL
)
3131 return UnknownImageFormat
;
3133 stat
= encode_image(image
, stream
, clsid
, params
);
3138 /*****************************************************************************
3139 * GdipGetImagePalette [GDIPLUS.@]
3141 GpStatus WINGDIPAPI
GdipGetImagePalette(GpImage
*image
, ColorPalette
*palette
, INT size
)
3143 TRACE("(%p,%p,%i)\n", image
, palette
, size
);
3145 if (!image
|| !palette
)
3146 return InvalidParameter
;
3148 if (size
< (sizeof(UINT
)*2+sizeof(ARGB
)*image
->palette_count
))
3150 TRACE("<-- InsufficientBuffer\n");
3151 return InsufficientBuffer
;
3154 palette
->Flags
= image
->palette_flags
;
3155 palette
->Count
= image
->palette_count
;
3156 memcpy(palette
->Entries
, image
->palette_entries
, sizeof(ARGB
)*image
->palette_count
);
3161 /*****************************************************************************
3162 * GdipSetImagePalette [GDIPLUS.@]
3164 GpStatus WINGDIPAPI
GdipSetImagePalette(GpImage
*image
,
3165 GDIPCONST ColorPalette
*palette
)
3167 TRACE("(%p,%p)\n", image
, palette
);
3169 if(!image
|| !palette
|| palette
->Count
> 256)
3170 return InvalidParameter
;
3172 if (palette
->Count
> image
->palette_size
)
3176 new_palette
= GdipAlloc(sizeof(ARGB
) * palette
->Count
);
3177 if (!new_palette
) return OutOfMemory
;
3179 GdipFree(image
->palette_entries
);
3180 image
->palette_entries
= new_palette
;
3181 image
->palette_size
= palette
->Count
;
3184 image
->palette_flags
= palette
->Flags
;
3185 image
->palette_count
= palette
->Count
;
3186 memcpy(image
->palette_entries
, palette
->Entries
, sizeof(ARGB
)*palette
->Count
);
3191 /*************************************************************************
3193 * Structures that represent which formats we support for encoding.
3196 /* ImageCodecInfo creation routines taken from libgdiplus */
3197 static const WCHAR bmp_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
3198 static const WCHAR bmp_extension
[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
3199 static const WCHAR bmp_mimetype
[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
3200 static const WCHAR bmp_format
[] = {'B', 'M', 'P', 0}; /* BMP */
3201 static const BYTE bmp_sig_pattern
[] = { 0x42, 0x4D };
3202 static const BYTE bmp_sig_mask
[] = { 0xFF, 0xFF };
3204 static const WCHAR jpeg_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'J','P','E','G', 0};
3205 static const WCHAR jpeg_extension
[] = {'*','.','J','P','G',';', '*','.','J','P','E','G',';', '*','.','J','P','E',';', '*','.','J','F','I','F',0};
3206 static const WCHAR jpeg_mimetype
[] = {'i','m','a','g','e','/','j','p','e','g', 0};
3207 static const WCHAR jpeg_format
[] = {'J','P','E','G',0};
3208 static const BYTE jpeg_sig_pattern
[] = { 0xFF, 0xD8 };
3209 static const BYTE jpeg_sig_mask
[] = { 0xFF, 0xFF };
3211 static const WCHAR gif_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'G','I','F', 0};
3212 static const WCHAR gif_extension
[] = {'*','.','G','I','F',0};
3213 static const WCHAR gif_mimetype
[] = {'i','m','a','g','e','/','g','i','f', 0};
3214 static const WCHAR gif_format
[] = {'G','I','F',0};
3215 static const BYTE gif_sig_pattern
[4] = "GIF8";
3216 static const BYTE gif_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
3218 static const WCHAR tiff_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'T','I','F','F', 0};
3219 static const WCHAR tiff_extension
[] = {'*','.','T','I','F','F',';','*','.','T','I','F',0};
3220 static const WCHAR tiff_mimetype
[] = {'i','m','a','g','e','/','t','i','f','f', 0};
3221 static const WCHAR tiff_format
[] = {'T','I','F','F',0};
3222 static const BYTE tiff_sig_pattern
[] = {0x49,0x49,42,0,0x4d,0x4d,0,42};
3223 static const BYTE tiff_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
3225 static const WCHAR emf_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'E','M','F', 0};
3226 static const WCHAR emf_extension
[] = {'*','.','E','M','F',0};
3227 static const WCHAR emf_mimetype
[] = {'i','m','a','g','e','/','x','-','e','m','f', 0};
3228 static const WCHAR emf_format
[] = {'E','M','F',0};
3229 static const BYTE emf_sig_pattern
[] = { 0x01, 0x00, 0x00, 0x00 };
3230 static const BYTE emf_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
3232 static const WCHAR wmf_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'W','M','F', 0};
3233 static const WCHAR wmf_extension
[] = {'*','.','W','M','F',0};
3234 static const WCHAR wmf_mimetype
[] = {'i','m','a','g','e','/','x','-','w','m','f', 0};
3235 static const WCHAR wmf_format
[] = {'W','M','F',0};
3236 static const BYTE wmf_sig_pattern
[] = { 0xd7, 0xcd };
3237 static const BYTE wmf_sig_mask
[] = { 0xFF, 0xFF };
3239 static const WCHAR png_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'P','N','G', 0};
3240 static const WCHAR png_extension
[] = {'*','.','P','N','G',0};
3241 static const WCHAR png_mimetype
[] = {'i','m','a','g','e','/','p','n','g', 0};
3242 static const WCHAR png_format
[] = {'P','N','G',0};
3243 static const BYTE png_sig_pattern
[] = { 137, 80, 78, 71, 13, 10, 26, 10, };
3244 static const BYTE png_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
3246 static const WCHAR ico_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'I','C','O', 0};
3247 static const WCHAR ico_extension
[] = {'*','.','I','C','O',0};
3248 static const WCHAR ico_mimetype
[] = {'i','m','a','g','e','/','x','-','i','c','o','n', 0};
3249 static const WCHAR ico_format
[] = {'I','C','O',0};
3250 static const BYTE ico_sig_pattern
[] = { 0x00, 0x00, 0x01, 0x00 };
3251 static const BYTE ico_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
3253 static const struct image_codec codecs
[NUM_CODECS
] = {
3256 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
3257 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
3258 /* CodecName */ bmp_codecname
,
3260 /* FormatDescription */ bmp_format
,
3261 /* FilenameExtension */ bmp_extension
,
3262 /* MimeType */ bmp_mimetype
,
3263 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
3267 /* SigPattern */ bmp_sig_pattern
,
3268 /* SigMask */ bmp_sig_mask
,
3275 /* Clsid */ { 0x557cf401, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
3276 /* FormatID */ { 0xb96b3caeU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
3277 /* CodecName */ jpeg_codecname
,
3279 /* FormatDescription */ jpeg_format
,
3280 /* FilenameExtension */ jpeg_extension
,
3281 /* MimeType */ jpeg_mimetype
,
3282 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
3286 /* SigPattern */ jpeg_sig_pattern
,
3287 /* SigMask */ jpeg_sig_mask
,
3294 /* Clsid */ { 0x557cf402, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
3295 /* FormatID */ { 0xb96b3cb0U
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
3296 /* CodecName */ gif_codecname
,
3298 /* FormatDescription */ gif_format
,
3299 /* FilenameExtension */ gif_extension
,
3300 /* MimeType */ gif_mimetype
,
3301 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
3305 /* SigPattern */ gif_sig_pattern
,
3306 /* SigMask */ gif_sig_mask
,
3313 /* Clsid */ { 0x557cf405, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
3314 /* FormatID */ { 0xb96b3cb1U
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
3315 /* CodecName */ tiff_codecname
,
3317 /* FormatDescription */ tiff_format
,
3318 /* FilenameExtension */ tiff_extension
,
3319 /* MimeType */ tiff_mimetype
,
3320 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsEncoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
3324 /* SigPattern */ tiff_sig_pattern
,
3325 /* SigMask */ tiff_sig_mask
,
3332 /* Clsid */ { 0x557cf403, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
3333 /* FormatID */ { 0xb96b3cacU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
3334 /* CodecName */ emf_codecname
,
3336 /* FormatDescription */ emf_format
,
3337 /* FilenameExtension */ emf_extension
,
3338 /* MimeType */ emf_mimetype
,
3339 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
3343 /* SigPattern */ emf_sig_pattern
,
3344 /* SigMask */ emf_sig_mask
,
3347 decode_image_olepicture_metafile
3351 /* Clsid */ { 0x557cf404, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
3352 /* FormatID */ { 0xb96b3cadU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
3353 /* CodecName */ wmf_codecname
,
3355 /* FormatDescription */ wmf_format
,
3356 /* FilenameExtension */ wmf_extension
,
3357 /* MimeType */ wmf_mimetype
,
3358 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
3362 /* SigPattern */ wmf_sig_pattern
,
3363 /* SigMask */ wmf_sig_mask
,
3366 decode_image_olepicture_metafile
3370 /* Clsid */ { 0x557cf406, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
3371 /* FormatID */ { 0xb96b3cafU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
3372 /* CodecName */ png_codecname
,
3374 /* FormatDescription */ png_format
,
3375 /* FilenameExtension */ png_extension
,
3376 /* MimeType */ png_mimetype
,
3377 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
3381 /* SigPattern */ png_sig_pattern
,
3382 /* SigMask */ png_sig_mask
,
3389 /* Clsid */ { 0x557cf407, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
3390 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
3391 /* CodecName */ ico_codecname
,
3393 /* FormatDescription */ ico_format
,
3394 /* FilenameExtension */ ico_extension
,
3395 /* MimeType */ ico_mimetype
,
3396 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
3400 /* SigPattern */ ico_sig_pattern
,
3401 /* SigMask */ ico_sig_mask
,
3408 /*****************************************************************************
3409 * GdipGetImageDecodersSize [GDIPLUS.@]
3411 GpStatus WINGDIPAPI
GdipGetImageDecodersSize(UINT
*numDecoders
, UINT
*size
)
3413 int decoder_count
=0;
3415 TRACE("%p %p\n", numDecoders
, size
);
3417 if (!numDecoders
|| !size
)
3418 return InvalidParameter
;
3420 for (i
=0; i
<NUM_CODECS
; i
++)
3422 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
3426 *numDecoders
= decoder_count
;
3427 *size
= decoder_count
* sizeof(ImageCodecInfo
);
3432 /*****************************************************************************
3433 * GdipGetImageDecoders [GDIPLUS.@]
3435 GpStatus WINGDIPAPI
GdipGetImageDecoders(UINT numDecoders
, UINT size
, ImageCodecInfo
*decoders
)
3437 int i
, decoder_count
=0;
3438 TRACE("%u %u %p\n", numDecoders
, size
, decoders
);
3441 size
!= numDecoders
* sizeof(ImageCodecInfo
))
3442 return GenericError
;
3444 for (i
=0; i
<NUM_CODECS
; i
++)
3446 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
3448 if (decoder_count
== numDecoders
) return GenericError
;
3449 memcpy(&decoders
[decoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
3454 if (decoder_count
< numDecoders
) return GenericError
;
3459 /*****************************************************************************
3460 * GdipGetImageEncodersSize [GDIPLUS.@]
3462 GpStatus WINGDIPAPI
GdipGetImageEncodersSize(UINT
*numEncoders
, UINT
*size
)
3464 int encoder_count
=0;
3466 TRACE("%p %p\n", numEncoders
, size
);
3468 if (!numEncoders
|| !size
)
3469 return InvalidParameter
;
3471 for (i
=0; i
<NUM_CODECS
; i
++)
3473 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
3477 *numEncoders
= encoder_count
;
3478 *size
= encoder_count
* sizeof(ImageCodecInfo
);
3483 /*****************************************************************************
3484 * GdipGetImageEncoders [GDIPLUS.@]
3486 GpStatus WINGDIPAPI
GdipGetImageEncoders(UINT numEncoders
, UINT size
, ImageCodecInfo
*encoders
)
3488 int i
, encoder_count
=0;
3489 TRACE("%u %u %p\n", numEncoders
, size
, encoders
);
3492 size
!= numEncoders
* sizeof(ImageCodecInfo
))
3493 return GenericError
;
3495 for (i
=0; i
<NUM_CODECS
; i
++)
3497 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
3499 if (encoder_count
== numEncoders
) return GenericError
;
3500 memcpy(&encoders
[encoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
3505 if (encoder_count
< numEncoders
) return GenericError
;
3510 GpStatus WINGDIPAPI
GdipGetEncoderParameterListSize(GpImage
*image
,
3511 GDIPCONST CLSID
* clsidEncoder
, UINT
*size
)
3515 TRACE("(%p,%s,%p)\n", image
, debugstr_guid(clsidEncoder
), size
);
3518 FIXME("not implemented\n");
3522 return NotImplemented
;
3525 static PixelFormat
get_16bpp_format(HBITMAP hbm
)
3531 hdc
= CreateCompatibleDC(NULL
);
3533 memset(&bmh
, 0, sizeof(bmh
));
3534 bmh
.bV4Size
= sizeof(bmh
);
3537 bmh
.bV4V4Compression
= BI_BITFIELDS
;
3538 bmh
.bV4BitCount
= 16;
3540 GetDIBits(hdc
, hbm
, 0, 0, NULL
, (BITMAPINFO
*)&bmh
, DIB_RGB_COLORS
);
3542 if (bmh
.bV4RedMask
== 0x7c00 &&
3543 bmh
.bV4GreenMask
== 0x3e0 &&
3544 bmh
.bV4BlueMask
== 0x1f)
3546 result
= PixelFormat16bppRGB555
;
3548 else if (bmh
.bV4RedMask
== 0xf800 &&
3549 bmh
.bV4GreenMask
== 0x7e0 &&
3550 bmh
.bV4BlueMask
== 0x1f)
3552 result
= PixelFormat16bppRGB565
;
3556 FIXME("unrecognized bitfields %x,%x,%x\n", bmh
.bV4RedMask
,
3557 bmh
.bV4GreenMask
, bmh
.bV4BlueMask
);
3558 result
= PixelFormatUndefined
;
3566 /*****************************************************************************
3567 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
3569 GpStatus WINGDIPAPI
GdipCreateBitmapFromHBITMAP(HBITMAP hbm
, HPALETTE hpal
, GpBitmap
** bitmap
)
3574 BitmapData lockeddata
;
3577 TRACE("%p %p %p\n", hbm
, hpal
, bitmap
);
3580 return InvalidParameter
;
3582 if (GetObjectA(hbm
, sizeof(bm
), &bm
) != sizeof(bm
))
3583 return InvalidParameter
;
3585 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
3586 switch(bm
.bmBitsPixel
) {
3588 format
= PixelFormat1bppIndexed
;
3591 format
= PixelFormat4bppIndexed
;
3594 format
= PixelFormat8bppIndexed
;
3597 format
= get_16bpp_format(hbm
);
3598 if (format
== PixelFormatUndefined
)
3599 return InvalidParameter
;
3602 format
= PixelFormat24bppRGB
;
3605 format
= PixelFormat32bppRGB
;
3608 format
= PixelFormat48bppRGB
;
3611 FIXME("don't know how to handle %d bpp\n", bm
.bmBitsPixel
);
3612 return InvalidParameter
;
3615 retval
= GdipCreateBitmapFromScan0(bm
.bmWidth
, bm
.bmHeight
, 0,
3616 format
, NULL
, bitmap
);
3620 retval
= GdipBitmapLockBits(*bitmap
, NULL
, ImageLockModeWrite
,
3621 format
, &lockeddata
);
3626 for (y
=0; y
<bm
.bmHeight
; y
++)
3628 memcpy((BYTE
*)lockeddata
.Scan0
+lockeddata
.Stride
*y
,
3629 (BYTE
*)bm
.bmBits
+bm
.bmWidthBytes
*(bm
.bmHeight
-1-y
),
3638 INT src_height
, dst_stride
;
3641 hdc
= CreateCompatibleDC(NULL
);
3642 oldhbm
= SelectObject(hdc
, hbm
);
3644 pbmi
= GdipAlloc(sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
3648 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3649 pbmi
->bmiHeader
.biBitCount
= 0;
3651 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
3653 src_height
= abs(pbmi
->bmiHeader
.biHeight
);
3655 if (pbmi
->bmiHeader
.biHeight
> 0)
3657 dst_bits
= (BYTE
*)lockeddata
.Scan0
+lockeddata
.Stride
*(src_height
-1);
3658 dst_stride
= -lockeddata
.Stride
;
3662 dst_bits
= lockeddata
.Scan0
;
3663 dst_stride
= lockeddata
.Stride
;
3666 for (y
=0; y
<src_height
; y
++)
3668 GetDIBits(hdc
, hbm
, y
, 1, dst_bits
+dst_stride
*y
,
3669 pbmi
, DIB_RGB_COLORS
);
3675 retval
= OutOfMemory
;
3677 SelectObject(hdc
, oldhbm
);
3681 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
3684 if (retval
== Ok
&& hpal
)
3686 WORD num_palette_entries
;
3687 PALETTEENTRY
*palette_entries
=NULL
;
3688 ColorPalette
*palette
=NULL
;
3691 if (!GetObjectW(hpal
, sizeof(num_palette_entries
), &num_palette_entries
))
3692 retval
= GenericError
;
3696 palette_entries
= GdipAlloc(sizeof(PALETTEENTRY
) * num_palette_entries
);
3697 palette
= GdipAlloc(sizeof(ColorPalette
) + sizeof(ARGB
) * (num_palette_entries
-1));
3699 if (!palette_entries
|| !palette
)
3700 retval
= OutOfMemory
;
3705 if (!GetPaletteEntries(hpal
, 0, num_palette_entries
, palette_entries
))
3706 retval
= GenericError
;
3712 palette
->Count
= num_palette_entries
;
3714 for (i
=0; i
<num_palette_entries
; i
++)
3716 PALETTEENTRY
* entry
= &palette_entries
[i
];
3717 palette
->Entries
[i
] = 0xff000000 | entry
->peRed
<< 16 |
3718 entry
->peGreen
<< 8 | entry
->peBlue
;
3721 retval
= GdipSetImagePalette((GpImage
*)*bitmap
, palette
);
3724 GdipFree(palette_entries
);
3730 GdipDisposeImage((GpImage
*)*bitmap
);
3738 GpStatus WINGDIPAPI
GdipDeleteEffect(CGpEffect
*effect
)
3740 FIXME("(%p): stub\n", effect
);
3741 /* note: According to Jose Roca's GDI+ Docs, this is not implemented
3742 * in Windows's gdiplus */
3743 return NotImplemented
;
3746 /*****************************************************************************
3747 * GdipSetEffectParameters [GDIPLUS.@]
3749 GpStatus WINGDIPAPI
GdipSetEffectParameters(CGpEffect
*effect
,
3750 const VOID
*params
, const UINT size
)
3754 TRACE("(%p,%p,%u)\n", effect
, params
, size
);
3757 FIXME("not implemented\n");
3759 return NotImplemented
;
3762 /*****************************************************************************
3763 * GdipGetImageFlags [GDIPLUS.@]
3765 GpStatus WINGDIPAPI
GdipGetImageFlags(GpImage
*image
, UINT
*flags
)
3767 TRACE("%p %p\n", image
, flags
);
3769 if(!image
|| !flags
)
3770 return InvalidParameter
;
3772 *flags
= image
->flags
;
3777 GpStatus WINGDIPAPI
GdipTestControl(GpTestControlEnum control
, void *param
)
3779 TRACE("(%d, %p)\n", control
, param
);
3782 case TestControlForceBilinear
:
3784 FIXME("TestControlForceBilinear not handled\n");
3786 case TestControlNoICM
:
3788 FIXME("TestControlNoICM not handled\n");
3790 case TestControlGetBuildNumber
:
3791 *((DWORD
*)param
) = 3102;
3798 GpStatus WINGDIPAPI
GdipRecordMetafileFileName(GDIPCONST WCHAR
* fileName
,
3799 HDC hdc
, EmfType type
, GDIPCONST GpRectF
*pFrameRect
,
3800 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
,
3801 GpMetafile
**metafile
)
3803 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName
), hdc
, type
, pFrameRect
,
3804 frameUnit
, debugstr_w(desc
), metafile
);
3806 return NotImplemented
;
3809 GpStatus WINGDIPAPI
GdipRecordMetafileFileNameI(GDIPCONST WCHAR
* fileName
, HDC hdc
, EmfType type
,
3810 GDIPCONST GpRect
*pFrameRect
, MetafileFrameUnit frameUnit
,
3811 GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
3813 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName
), hdc
, type
, pFrameRect
,
3814 frameUnit
, debugstr_w(desc
), metafile
);
3816 return NotImplemented
;
3819 GpStatus WINGDIPAPI
GdipImageForceValidation(GpImage
*image
)
3821 TRACE("%p\n", image
);
3826 /*****************************************************************************
3827 * GdipGetImageThumbnail [GDIPLUS.@]
3829 GpStatus WINGDIPAPI
GdipGetImageThumbnail(GpImage
*image
, UINT width
, UINT height
,
3830 GpImage
**ret_image
, GetThumbnailImageAbort cb
,
3834 GpGraphics
*graphics
;
3835 UINT srcwidth
, srcheight
;
3837 TRACE("(%p %u %u %p %p %p)\n",
3838 image
, width
, height
, ret_image
, cb
, cb_data
);
3840 if (!image
|| !ret_image
)
3841 return InvalidParameter
;
3843 if (!width
) width
= 120;
3844 if (!height
) height
= 120;
3846 GdipGetImageWidth(image
, &srcwidth
);
3847 GdipGetImageHeight(image
, &srcheight
);
3849 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat32bppARGB
,
3850 NULL
, (GpBitmap
**)ret_image
);
3854 stat
= GdipGetImageGraphicsContext(*ret_image
, &graphics
);
3858 stat
= GdipDrawImageRectRectI(graphics
, image
,
3859 0, 0, width
, height
, 0, 0, srcwidth
, srcheight
, UnitPixel
,
3862 GdipDeleteGraphics(graphics
);
3867 GdipDisposeImage(*ret_image
);
3875 /*****************************************************************************
3876 * GdipImageRotateFlip [GDIPLUS.@]
3878 GpStatus WINGDIPAPI
GdipImageRotateFlip(GpImage
*image
, RotateFlipType type
)
3880 GpBitmap
*new_bitmap
;
3882 int bpp
, bytesperpixel
;
3883 int rotate_90
, flip_x
, flip_y
;
3884 int src_x_offset
, src_y_offset
;
3886 UINT x
, y
, width
, height
;
3887 BitmapData src_lock
, dst_lock
;
3890 TRACE("(%p, %u)\n", image
, type
);
3893 flip_x
= (type
&6) == 2 || (type
&6) == 4;
3894 flip_y
= (type
&3) == 1 || (type
&3) == 2;
3896 if (image
->type
!= ImageTypeBitmap
)
3898 FIXME("Not implemented for type %i\n", image
->type
);
3899 return NotImplemented
;
3902 bitmap
= (GpBitmap
*)image
;
3903 bpp
= PIXELFORMATBPP(bitmap
->format
);
3907 FIXME("Not implemented for %i bit images\n", bpp
);
3908 return NotImplemented
;
3913 width
= bitmap
->height
;
3914 height
= bitmap
->width
;
3918 width
= bitmap
->width
;
3919 height
= bitmap
->height
;
3922 bytesperpixel
= bpp
/8;
3924 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, bitmap
->format
, NULL
, &new_bitmap
);
3929 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, bitmap
->format
, &src_lock
);
3933 stat
= GdipBitmapLockBits(new_bitmap
, NULL
, ImageLockModeWrite
, bitmap
->format
, &dst_lock
);
3937 LPBYTE src_row
, src_pixel
;
3938 LPBYTE dst_row
, dst_pixel
;
3940 src_origin
= src_lock
.Scan0
;
3941 if (flip_x
) src_origin
+= bytesperpixel
* (bitmap
->width
- 1);
3942 if (flip_y
) src_origin
+= src_lock
.Stride
* (bitmap
->height
- 1);
3946 if (flip_y
) src_x_offset
= -src_lock
.Stride
;
3947 else src_x_offset
= src_lock
.Stride
;
3948 if (flip_x
) src_y_offset
= -bytesperpixel
;
3949 else src_y_offset
= bytesperpixel
;
3953 if (flip_x
) src_x_offset
= -bytesperpixel
;
3954 else src_x_offset
= bytesperpixel
;
3955 if (flip_y
) src_y_offset
= -src_lock
.Stride
;
3956 else src_y_offset
= src_lock
.Stride
;
3959 src_row
= src_origin
;
3960 dst_row
= dst_lock
.Scan0
;
3961 for (y
=0; y
<height
; y
++)
3963 src_pixel
= src_row
;
3964 dst_pixel
= dst_row
;
3965 for (x
=0; x
<width
; x
++)
3967 /* FIXME: This could probably be faster without memcpy. */
3968 memcpy(dst_pixel
, src_pixel
, bytesperpixel
);
3969 dst_pixel
+= bytesperpixel
;
3970 src_pixel
+= src_x_offset
;
3972 src_row
+= src_y_offset
;
3973 dst_row
+= dst_lock
.Stride
;
3976 GdipBitmapUnlockBits(new_bitmap
, &dst_lock
);
3979 GdipBitmapUnlockBits(bitmap
, &src_lock
);
3983 move_bitmap(bitmap
, new_bitmap
, FALSE
);
3985 GdipDisposeImage((GpImage
*)new_bitmap
);
3990 /*****************************************************************************
3991 * GdipConvertToEmfPlusToFile [GDIPLUS.@]
3994 GpStatus WINGDIPAPI
GdipConvertToEmfPlusToFile(const GpGraphics
* refGraphics
,
3995 GpMetafile
* metafile
, BOOL
* conversionSuccess
,
3996 const WCHAR
* filename
, EmfType emfType
,
3997 const WCHAR
* description
, GpMetafile
** out_metafile
)
3999 FIXME("stub: %p, %p, %p, %p, %u, %p, %p\n", refGraphics
, metafile
, conversionSuccess
, filename
, emfType
, description
, out_metafile
);
4000 return NotImplemented
;