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 void setpixel_16bppGrayScale(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
302 *((WORD
*)(row
)+x
) = (r
+g
+b
)*85;
305 static inline void setpixel_16bppRGB555(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
308 *((WORD
*)(row
)+x
) = (r
<<7&0x7c00)|
313 static inline void setpixel_16bppRGB565(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
316 *((WORD
*)(row
)+x
) = (r
<<8&0xf800)|
321 static inline void setpixel_16bppARGB1555(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
324 *((WORD
*)(row
)+x
) = (a
<<8&0x8000)|
330 static inline void setpixel_24bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
338 static inline void setpixel_32bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
341 *((DWORD
*)(row
)+x
) = (r
<<16)|(g
<<8)|b
;
344 static inline void setpixel_32bppARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
347 *((DWORD
*)(row
)+x
) = (a
<<24)|(r
<<16)|(g
<<8)|b
;
350 static inline void setpixel_32bppPARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
356 *((DWORD
*)(row
)+x
) = (a
<<24)|(r
<<16)|(g
<<8)|b
;
359 static inline void setpixel_48bppRGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
362 row
[x
*6+5] = row
[x
*6+4] = r
;
363 row
[x
*6+3] = row
[x
*6+2] = g
;
364 row
[x
*6+1] = row
[x
*6] = b
;
367 static inline void setpixel_64bppARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
370 UINT64 a64
=a
, r64
=r
, g64
=g
, b64
=b
;
371 *((UINT64
*)(row
)+x
) = (a64
<<56)|(a64
<<48)|(r64
<<40)|(r64
<<32)|(g64
<<24)|(g64
<<16)|(b64
<<8)|b64
;
374 static inline void setpixel_64bppPARGB(BYTE r
, BYTE g
, BYTE b
, BYTE a
,
377 UINT64 a64
, r64
, g64
, b64
;
382 *((UINT64
*)(row
)+x
) = (a64
<<48)|(r64
<<32)|(g64
<<16)|b64
;
385 GpStatus WINGDIPAPI
GdipBitmapSetPixel(GpBitmap
* bitmap
, INT x
, INT y
,
390 TRACE("bitmap:%p, x:%d, y:%d, color:%08x\n", bitmap
, x
, y
, color
);
392 if(!bitmap
|| x
< 0 || y
< 0 || x
>= bitmap
->width
|| y
>= bitmap
->height
)
393 return InvalidParameter
;
400 row
= bitmap
->bits
+ bitmap
->stride
* y
;
402 switch (bitmap
->format
)
404 case PixelFormat16bppGrayScale
:
405 setpixel_16bppGrayScale(r
,g
,b
,a
,row
,x
);
407 case PixelFormat16bppRGB555
:
408 setpixel_16bppRGB555(r
,g
,b
,a
,row
,x
);
410 case PixelFormat16bppRGB565
:
411 setpixel_16bppRGB565(r
,g
,b
,a
,row
,x
);
413 case PixelFormat16bppARGB1555
:
414 setpixel_16bppARGB1555(r
,g
,b
,a
,row
,x
);
416 case PixelFormat24bppRGB
:
417 setpixel_24bppRGB(r
,g
,b
,a
,row
,x
);
419 case PixelFormat32bppRGB
:
420 setpixel_32bppRGB(r
,g
,b
,a
,row
,x
);
422 case PixelFormat32bppARGB
:
423 setpixel_32bppARGB(r
,g
,b
,a
,row
,x
);
425 case PixelFormat32bppPARGB
:
426 setpixel_32bppPARGB(r
,g
,b
,a
,row
,x
);
428 case PixelFormat48bppRGB
:
429 setpixel_48bppRGB(r
,g
,b
,a
,row
,x
);
431 case PixelFormat64bppARGB
:
432 setpixel_64bppARGB(r
,g
,b
,a
,row
,x
);
434 case PixelFormat64bppPARGB
:
435 setpixel_64bppPARGB(r
,g
,b
,a
,row
,x
);
438 FIXME("not implemented for format 0x%x\n", bitmap
->format
);
439 return NotImplemented
;
445 GpStatus
convert_pixels(UINT width
, UINT height
,
446 INT dst_stride
, BYTE
*dst_bits
, PixelFormat dst_format
,
447 INT src_stride
, const BYTE
*src_bits
, PixelFormat src_format
, ARGB
*src_palette
)
451 if (src_format
== dst_format
||
452 (dst_format
== PixelFormat32bppRGB
&& PIXELFORMATBPP(src_format
) == 32))
454 UINT widthbytes
= PIXELFORMATBPP(src_format
) * width
/ 8;
455 for (y
=0; y
<height
; y
++)
456 memcpy(dst_bits
+dst_stride
*y
, src_bits
+src_stride
*y
, widthbytes
);
460 #define convert_indexed_to_rgb(getpixel_function, setpixel_function) do { \
461 for (x=0; x<width; x++) \
462 for (y=0; y<height; y++) { \
465 getpixel_function(&index, src_bits+src_stride*y, x); \
466 color = (BYTE*)(&src_palette[index]); \
467 setpixel_function(color[2], color[1], color[0], color[3], dst_bits+dst_stride*y, x); \
472 #define convert_rgb_to_rgb(getpixel_function, setpixel_function) do { \
473 for (x=0; x<width; x++) \
474 for (y=0; y<height; y++) { \
476 getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
477 setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x); \
484 case PixelFormat1bppIndexed
:
487 case PixelFormat16bppGrayScale
:
488 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppGrayScale
);
489 case PixelFormat16bppRGB555
:
490 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppRGB555
);
491 case PixelFormat16bppRGB565
:
492 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppRGB565
);
493 case PixelFormat16bppARGB1555
:
494 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_16bppARGB1555
);
495 case PixelFormat24bppRGB
:
496 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_24bppRGB
);
497 case PixelFormat32bppRGB
:
498 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppRGB
);
499 case PixelFormat32bppARGB
:
500 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppARGB
);
501 case PixelFormat32bppPARGB
:
502 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_32bppPARGB
);
503 case PixelFormat48bppRGB
:
504 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_48bppRGB
);
505 case PixelFormat64bppARGB
:
506 convert_indexed_to_rgb(getpixel_1bppIndexed
, setpixel_64bppARGB
);
511 case PixelFormat4bppIndexed
:
514 case PixelFormat16bppGrayScale
:
515 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppGrayScale
);
516 case PixelFormat16bppRGB555
:
517 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppRGB555
);
518 case PixelFormat16bppRGB565
:
519 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppRGB565
);
520 case PixelFormat16bppARGB1555
:
521 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_16bppARGB1555
);
522 case PixelFormat24bppRGB
:
523 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_24bppRGB
);
524 case PixelFormat32bppRGB
:
525 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppRGB
);
526 case PixelFormat32bppARGB
:
527 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppARGB
);
528 case PixelFormat32bppPARGB
:
529 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_32bppPARGB
);
530 case PixelFormat48bppRGB
:
531 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_48bppRGB
);
532 case PixelFormat64bppARGB
:
533 convert_indexed_to_rgb(getpixel_4bppIndexed
, setpixel_64bppARGB
);
538 case PixelFormat8bppIndexed
:
541 case PixelFormat16bppGrayScale
:
542 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppGrayScale
);
543 case PixelFormat16bppRGB555
:
544 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppRGB555
);
545 case PixelFormat16bppRGB565
:
546 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppRGB565
);
547 case PixelFormat16bppARGB1555
:
548 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_16bppARGB1555
);
549 case PixelFormat24bppRGB
:
550 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_24bppRGB
);
551 case PixelFormat32bppRGB
:
552 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppRGB
);
553 case PixelFormat32bppARGB
:
554 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppARGB
);
555 case PixelFormat32bppPARGB
:
556 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_32bppPARGB
);
557 case PixelFormat48bppRGB
:
558 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_48bppRGB
);
559 case PixelFormat64bppARGB
:
560 convert_indexed_to_rgb(getpixel_8bppIndexed
, setpixel_64bppARGB
);
565 case PixelFormat16bppGrayScale
:
568 case PixelFormat16bppRGB555
:
569 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppRGB555
);
570 case PixelFormat16bppRGB565
:
571 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppRGB565
);
572 case PixelFormat16bppARGB1555
:
573 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_16bppARGB1555
);
574 case PixelFormat24bppRGB
:
575 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_24bppRGB
);
576 case PixelFormat32bppRGB
:
577 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppRGB
);
578 case PixelFormat32bppARGB
:
579 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppARGB
);
580 case PixelFormat32bppPARGB
:
581 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_32bppPARGB
);
582 case PixelFormat48bppRGB
:
583 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_48bppRGB
);
584 case PixelFormat64bppARGB
:
585 convert_rgb_to_rgb(getpixel_16bppGrayScale
, setpixel_64bppARGB
);
590 case PixelFormat16bppRGB555
:
593 case PixelFormat16bppGrayScale
:
594 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppGrayScale
);
595 case PixelFormat16bppRGB565
:
596 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppRGB565
);
597 case PixelFormat16bppARGB1555
:
598 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_16bppARGB1555
);
599 case PixelFormat24bppRGB
:
600 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_24bppRGB
);
601 case PixelFormat32bppRGB
:
602 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppRGB
);
603 case PixelFormat32bppARGB
:
604 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppARGB
);
605 case PixelFormat32bppPARGB
:
606 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_32bppPARGB
);
607 case PixelFormat48bppRGB
:
608 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_48bppRGB
);
609 case PixelFormat64bppARGB
:
610 convert_rgb_to_rgb(getpixel_16bppRGB555
, setpixel_64bppARGB
);
615 case PixelFormat16bppRGB565
:
618 case PixelFormat16bppGrayScale
:
619 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppGrayScale
);
620 case PixelFormat16bppRGB555
:
621 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppRGB555
);
622 case PixelFormat16bppARGB1555
:
623 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_16bppARGB1555
);
624 case PixelFormat24bppRGB
:
625 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_24bppRGB
);
626 case PixelFormat32bppRGB
:
627 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppRGB
);
628 case PixelFormat32bppARGB
:
629 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppARGB
);
630 case PixelFormat32bppPARGB
:
631 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_32bppPARGB
);
632 case PixelFormat48bppRGB
:
633 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_48bppRGB
);
634 case PixelFormat64bppARGB
:
635 convert_rgb_to_rgb(getpixel_16bppRGB565
, setpixel_64bppARGB
);
640 case PixelFormat16bppARGB1555
:
643 case PixelFormat16bppGrayScale
:
644 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppGrayScale
);
645 case PixelFormat16bppRGB555
:
646 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppRGB555
);
647 case PixelFormat16bppRGB565
:
648 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_16bppRGB565
);
649 case PixelFormat24bppRGB
:
650 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_24bppRGB
);
651 case PixelFormat32bppRGB
:
652 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppRGB
);
653 case PixelFormat32bppARGB
:
654 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppARGB
);
655 case PixelFormat32bppPARGB
:
656 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_32bppPARGB
);
657 case PixelFormat48bppRGB
:
658 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_48bppRGB
);
659 case PixelFormat64bppARGB
:
660 convert_rgb_to_rgb(getpixel_16bppARGB1555
, setpixel_64bppARGB
);
665 case PixelFormat24bppRGB
:
668 case PixelFormat16bppGrayScale
:
669 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppGrayScale
);
670 case PixelFormat16bppRGB555
:
671 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppRGB555
);
672 case PixelFormat16bppRGB565
:
673 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppRGB565
);
674 case PixelFormat16bppARGB1555
:
675 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_16bppARGB1555
);
676 case PixelFormat32bppRGB
:
677 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppRGB
);
678 case PixelFormat32bppARGB
:
679 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppARGB
);
680 case PixelFormat32bppPARGB
:
681 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_32bppPARGB
);
682 case PixelFormat48bppRGB
:
683 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_48bppRGB
);
684 case PixelFormat64bppARGB
:
685 convert_rgb_to_rgb(getpixel_24bppRGB
, setpixel_64bppARGB
);
690 case PixelFormat32bppRGB
:
693 case PixelFormat16bppGrayScale
:
694 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppGrayScale
);
695 case PixelFormat16bppRGB555
:
696 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppRGB555
);
697 case PixelFormat16bppRGB565
:
698 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppRGB565
);
699 case PixelFormat16bppARGB1555
:
700 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_16bppARGB1555
);
701 case PixelFormat24bppRGB
:
702 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_24bppRGB
);
703 case PixelFormat32bppARGB
:
704 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_32bppARGB
);
705 case PixelFormat32bppPARGB
:
706 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_32bppPARGB
);
707 case PixelFormat48bppRGB
:
708 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_48bppRGB
);
709 case PixelFormat64bppARGB
:
710 convert_rgb_to_rgb(getpixel_32bppRGB
, setpixel_64bppARGB
);
715 case PixelFormat32bppARGB
:
718 case PixelFormat16bppGrayScale
:
719 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppGrayScale
);
720 case PixelFormat16bppRGB555
:
721 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppRGB555
);
722 case PixelFormat16bppRGB565
:
723 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppRGB565
);
724 case PixelFormat16bppARGB1555
:
725 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_16bppARGB1555
);
726 case PixelFormat24bppRGB
:
727 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_24bppRGB
);
728 case PixelFormat32bppPARGB
:
729 convert_32bppARGB_to_32bppPARGB(width
, height
, dst_bits
, dst_stride
, src_bits
, src_stride
);
731 case PixelFormat48bppRGB
:
732 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_48bppRGB
);
733 case PixelFormat64bppARGB
:
734 convert_rgb_to_rgb(getpixel_32bppARGB
, setpixel_64bppARGB
);
739 case PixelFormat32bppPARGB
:
742 case PixelFormat16bppGrayScale
:
743 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppGrayScale
);
744 case PixelFormat16bppRGB555
:
745 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppRGB555
);
746 case PixelFormat16bppRGB565
:
747 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppRGB565
);
748 case PixelFormat16bppARGB1555
:
749 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_16bppARGB1555
);
750 case PixelFormat24bppRGB
:
751 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_24bppRGB
);
752 case PixelFormat32bppRGB
:
753 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_32bppRGB
);
754 case PixelFormat32bppARGB
:
755 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_32bppARGB
);
756 case PixelFormat48bppRGB
:
757 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_48bppRGB
);
758 case PixelFormat64bppARGB
:
759 convert_rgb_to_rgb(getpixel_32bppPARGB
, setpixel_64bppARGB
);
764 case PixelFormat48bppRGB
:
767 case PixelFormat16bppGrayScale
:
768 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppGrayScale
);
769 case PixelFormat16bppRGB555
:
770 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppRGB555
);
771 case PixelFormat16bppRGB565
:
772 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppRGB565
);
773 case PixelFormat16bppARGB1555
:
774 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_16bppARGB1555
);
775 case PixelFormat24bppRGB
:
776 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_24bppRGB
);
777 case PixelFormat32bppRGB
:
778 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppRGB
);
779 case PixelFormat32bppARGB
:
780 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppARGB
);
781 case PixelFormat32bppPARGB
:
782 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_32bppPARGB
);
783 case PixelFormat64bppARGB
:
784 convert_rgb_to_rgb(getpixel_48bppRGB
, setpixel_64bppARGB
);
789 case PixelFormat64bppARGB
:
792 case PixelFormat16bppGrayScale
:
793 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppGrayScale
);
794 case PixelFormat16bppRGB555
:
795 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppRGB555
);
796 case PixelFormat16bppRGB565
:
797 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppRGB565
);
798 case PixelFormat16bppARGB1555
:
799 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_16bppARGB1555
);
800 case PixelFormat24bppRGB
:
801 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_24bppRGB
);
802 case PixelFormat32bppRGB
:
803 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppRGB
);
804 case PixelFormat32bppARGB
:
805 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppARGB
);
806 case PixelFormat32bppPARGB
:
807 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_32bppPARGB
);
808 case PixelFormat48bppRGB
:
809 convert_rgb_to_rgb(getpixel_64bppARGB
, setpixel_48bppRGB
);
814 case PixelFormat64bppPARGB
:
817 case PixelFormat16bppGrayScale
:
818 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppGrayScale
);
819 case PixelFormat16bppRGB555
:
820 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppRGB555
);
821 case PixelFormat16bppRGB565
:
822 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppRGB565
);
823 case PixelFormat16bppARGB1555
:
824 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_16bppARGB1555
);
825 case PixelFormat24bppRGB
:
826 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_24bppRGB
);
827 case PixelFormat32bppRGB
:
828 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppRGB
);
829 case PixelFormat32bppARGB
:
830 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppARGB
);
831 case PixelFormat32bppPARGB
:
832 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_32bppPARGB
);
833 case PixelFormat48bppRGB
:
834 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_48bppRGB
);
835 case PixelFormat64bppARGB
:
836 convert_rgb_to_rgb(getpixel_64bppPARGB
, setpixel_64bppARGB
);
845 #undef convert_indexed_to_rgb
846 #undef convert_rgb_to_rgb
848 return NotImplemented
;
851 /* This function returns a pointer to an array of pixels that represents the
852 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
853 * flags. It is correct behavior that a user who calls this function with write
854 * privileges can write to the whole bitmap (not just the area in rect).
856 * FIXME: only used portion of format is bits per pixel. */
857 GpStatus WINGDIPAPI
GdipBitmapLockBits(GpBitmap
* bitmap
, GDIPCONST GpRect
* rect
,
858 UINT flags
, PixelFormat format
, BitmapData
* lockeddata
)
860 INT stride
, bitspp
= PIXELFORMATBPP(format
);
863 GpRect act_rect
; /* actual rect to be used */
866 TRACE("%p %p %d 0x%x %p\n", bitmap
, rect
, flags
, format
, lockeddata
);
868 if(!lockeddata
|| !bitmap
)
869 return InvalidParameter
;
872 if(rect
->X
< 0 || rect
->Y
< 0 || (rect
->X
+ rect
->Width
> bitmap
->width
) ||
873 (rect
->Y
+ rect
->Height
> bitmap
->height
) || !flags
)
874 return InvalidParameter
;
879 act_rect
.X
= act_rect
.Y
= 0;
880 act_rect
.Width
= bitmap
->width
;
881 act_rect
.Height
= bitmap
->height
;
884 if(flags
& ImageLockModeUserInputBuf
)
887 if (!fixme
++) FIXME("ImageLockModeUserInputBuf not implemented\n");
888 return NotImplemented
;
893 WARN("bitmap is already locked and cannot be locked again\n");
897 if (bitmap
->bits
&& bitmap
->format
== format
)
899 /* no conversion is necessary; just use the bits directly */
900 lockeddata
->Width
= act_rect
.Width
;
901 lockeddata
->Height
= act_rect
.Height
;
902 lockeddata
->PixelFormat
= format
;
903 lockeddata
->Reserved
= flags
;
904 lockeddata
->Stride
= bitmap
->stride
;
905 lockeddata
->Scan0
= bitmap
->bits
+ (bitspp
/ 8) * act_rect
.X
+
906 bitmap
->stride
* act_rect
.Y
;
908 bitmap
->lockmode
= flags
;
914 /* Make sure we can convert to the requested format. */
915 stat
= convert_pixels(0, 0, 0, NULL
, format
, 0, NULL
, bitmap
->format
, NULL
);
916 if (stat
== NotImplemented
)
918 FIXME("cannot read bitmap from %x to %x\n", bitmap
->format
, format
);
919 return NotImplemented
;
922 /* If we're opening for writing, make sure we'll be able to write back in
923 * the original format. */
924 if (flags
& ImageLockModeWrite
)
926 stat
= convert_pixels(0, 0, 0, NULL
, bitmap
->format
, 0, NULL
, format
, NULL
);
927 if (stat
== NotImplemented
)
929 FIXME("cannot write bitmap from %x to %x\n", format
, bitmap
->format
);
930 return NotImplemented
;
934 abs_height
= bitmap
->height
;
935 stride
= (bitmap
->width
* bitspp
+ 7) / 8;
936 stride
= (stride
+ 3) & ~3;
938 buff
= GdipAlloc(stride
* abs_height
);
940 if (!buff
) return OutOfMemory
;
942 stat
= convert_pixels(bitmap
->width
, bitmap
->height
,
943 stride
, buff
, format
,
944 bitmap
->stride
, bitmap
->bits
, bitmap
->format
, bitmap
->image
.palette_entries
);
952 lockeddata
->Width
= act_rect
.Width
;
953 lockeddata
->Height
= act_rect
.Height
;
954 lockeddata
->PixelFormat
= format
;
955 lockeddata
->Reserved
= flags
;
956 lockeddata
->Stride
= stride
;
957 lockeddata
->Scan0
= buff
+ (bitspp
/ 8) * act_rect
.X
+ stride
* act_rect
.Y
;
959 bitmap
->lockmode
= flags
;
961 bitmap
->bitmapbits
= buff
;
966 GpStatus WINGDIPAPI
GdipBitmapSetResolution(GpBitmap
* bitmap
, REAL xdpi
, REAL ydpi
)
968 TRACE("(%p, %.2f, %.2f)\n", bitmap
, xdpi
, ydpi
);
970 if (!bitmap
|| xdpi
== 0.0 || ydpi
== 0.0)
971 return InvalidParameter
;
973 bitmap
->image
.xres
= xdpi
;
974 bitmap
->image
.yres
= ydpi
;
979 GpStatus WINGDIPAPI
GdipBitmapUnlockBits(GpBitmap
* bitmap
,
980 BitmapData
* lockeddata
)
984 TRACE("(%p,%p)\n", bitmap
, lockeddata
);
986 if(!bitmap
|| !lockeddata
)
987 return InvalidParameter
;
989 if(!bitmap
->lockmode
)
992 if(lockeddata
->Reserved
& ImageLockModeUserInputBuf
)
993 return NotImplemented
;
995 if(lockeddata
->Reserved
& ImageLockModeRead
){
996 if(!(--bitmap
->numlocks
))
997 bitmap
->lockmode
= 0;
999 GdipFree(bitmap
->bitmapbits
);
1000 bitmap
->bitmapbits
= NULL
;
1004 if (!bitmap
->bitmapbits
)
1006 /* we passed a direct reference; no need to do anything */
1007 bitmap
->lockmode
= 0;
1008 bitmap
->numlocks
= 0;
1012 stat
= convert_pixels(bitmap
->width
, bitmap
->height
,
1013 bitmap
->stride
, bitmap
->bits
, bitmap
->format
,
1014 lockeddata
->Stride
, bitmap
->bitmapbits
, lockeddata
->PixelFormat
, NULL
);
1018 ERR("failed to convert pixels; this should never happen\n");
1021 GdipFree(bitmap
->bitmapbits
);
1022 bitmap
->bitmapbits
= NULL
;
1023 bitmap
->lockmode
= 0;
1024 bitmap
->numlocks
= 0;
1029 GpStatus WINGDIPAPI
GdipCloneBitmapArea(REAL x
, REAL y
, REAL width
, REAL height
,
1030 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
1032 BitmapData lockeddata_src
, lockeddata_dst
;
1038 TRACE("(%f,%f,%f,%f,0x%x,%p,%p)\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1040 if (!srcBitmap
|| !dstBitmap
|| srcBitmap
->image
.type
!= ImageTypeBitmap
||
1042 x
+ width
> srcBitmap
->width
|| y
+ height
> srcBitmap
->height
)
1044 TRACE("<-- InvalidParameter\n");
1045 return InvalidParameter
;
1048 if (format
== PixelFormatDontCare
)
1049 format
= srcBitmap
->format
;
1053 area
.Width
= roundr(width
);
1054 area
.Height
= roundr(height
);
1056 stat
= GdipBitmapLockBits(srcBitmap
, &area
, ImageLockModeRead
, format
,
1058 if (stat
!= Ok
) return stat
;
1060 stat
= GdipCreateBitmapFromScan0(lockeddata_src
.Width
, lockeddata_src
.Height
,
1061 0, lockeddata_src
.PixelFormat
, NULL
, dstBitmap
);
1064 stat
= GdipBitmapLockBits(*dstBitmap
, NULL
, ImageLockModeWrite
,
1065 lockeddata_src
.PixelFormat
, &lockeddata_dst
);
1069 /* copy the image data */
1070 row_size
= (lockeddata_src
.Width
* PIXELFORMATBPP(lockeddata_src
.PixelFormat
) +7)/8;
1071 for (i
=0; i
<lockeddata_src
.Height
; i
++)
1072 memcpy((BYTE
*)lockeddata_dst
.Scan0
+lockeddata_dst
.Stride
*i
,
1073 (BYTE
*)lockeddata_src
.Scan0
+lockeddata_src
.Stride
*i
,
1076 GdipBitmapUnlockBits(*dstBitmap
, &lockeddata_dst
);
1080 GdipDisposeImage((GpImage
*)*dstBitmap
);
1083 GdipBitmapUnlockBits(srcBitmap
, &lockeddata_src
);
1093 GpStatus WINGDIPAPI
GdipCloneBitmapAreaI(INT x
, INT y
, INT width
, INT height
,
1094 PixelFormat format
, GpBitmap
* srcBitmap
, GpBitmap
** dstBitmap
)
1096 TRACE("(%i,%i,%i,%i,0x%x,%p,%p)\n", x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1098 return GdipCloneBitmapArea(x
, y
, width
, height
, format
, srcBitmap
, dstBitmap
);
1101 GpStatus WINGDIPAPI
GdipCloneImage(GpImage
*image
, GpImage
**cloneImage
)
1103 GpStatus stat
= GenericError
;
1105 TRACE("%p, %p\n", image
, cloneImage
);
1107 if (!image
|| !cloneImage
)
1108 return InvalidParameter
;
1117 hr
= CreateStreamOnHGlobal(0, TRUE
, &stream
);
1119 return GenericError
;
1121 hr
= IPicture_SaveAsFile(image
->picture
, stream
, FALSE
, &size
);
1124 WARN("Failed to save image on stream\n");
1128 /* Set seek pointer back to the beginning of the picture */
1130 hr
= IStream_Seek(stream
, move
, STREAM_SEEK_SET
, NULL
);
1134 stat
= GdipLoadImageFromStream(stream
, cloneImage
);
1135 if (stat
!= Ok
) WARN("Failed to load image from stream\n");
1138 IStream_Release(stream
);
1141 else if (image
->type
== ImageTypeBitmap
)
1143 GpBitmap
*bitmap
= (GpBitmap
*)image
;
1144 BitmapData lockeddata_src
, lockeddata_dst
;
1148 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, bitmap
->format
,
1150 if (stat
!= Ok
) return stat
;
1152 stat
= GdipCreateBitmapFromScan0(lockeddata_src
.Width
, lockeddata_src
.Height
,
1153 0, lockeddata_src
.PixelFormat
, NULL
, (GpBitmap
**)cloneImage
);
1156 stat
= GdipBitmapLockBits((GpBitmap
*)*cloneImage
, NULL
, ImageLockModeWrite
,
1157 lockeddata_src
.PixelFormat
, &lockeddata_dst
);
1161 /* copy the image data */
1162 row_size
= (lockeddata_src
.Width
* PIXELFORMATBPP(lockeddata_src
.PixelFormat
) +7)/8;
1163 for (i
=0; i
<lockeddata_src
.Height
; i
++)
1164 memcpy((BYTE
*)lockeddata_dst
.Scan0
+lockeddata_dst
.Stride
*i
,
1165 (BYTE
*)lockeddata_src
.Scan0
+lockeddata_src
.Stride
*i
,
1168 GdipBitmapUnlockBits((GpBitmap
*)*cloneImage
, &lockeddata_dst
);
1172 GdipDisposeImage(*cloneImage
);
1175 GdipBitmapUnlockBits(bitmap
, &lockeddata_src
);
1181 else memcpy(&(*cloneImage
)->format
, &image
->format
, sizeof(GUID
));
1187 ERR("GpImage with no IPicture or bitmap?!\n");
1188 return NotImplemented
;
1192 GpStatus WINGDIPAPI
GdipCreateBitmapFromFile(GDIPCONST WCHAR
* filename
,
1198 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
1200 if(!filename
|| !bitmap
)
1201 return InvalidParameter
;
1203 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
1208 stat
= GdipCreateBitmapFromStream(stream
, bitmap
);
1210 IStream_Release(stream
);
1215 GpStatus WINGDIPAPI
GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO
* info
,
1216 VOID
*bits
, GpBitmap
**bitmap
)
1218 DWORD height
, stride
;
1221 FIXME("(%p, %p, %p) - partially implemented\n", info
, bits
, bitmap
);
1223 if (!info
|| !bits
|| !bitmap
)
1224 return InvalidParameter
;
1226 height
= abs(info
->bmiHeader
.biHeight
);
1227 stride
= ((info
->bmiHeader
.biWidth
* info
->bmiHeader
.biBitCount
+ 31) >> 3) & ~3;
1229 if(info
->bmiHeader
.biHeight
> 0) /* bottom-up */
1231 bits
= (BYTE
*)bits
+ (height
- 1) * stride
;
1235 switch(info
->bmiHeader
.biBitCount
) {
1237 format
= PixelFormat1bppIndexed
;
1240 format
= PixelFormat4bppIndexed
;
1243 format
= PixelFormat8bppIndexed
;
1246 format
= PixelFormat16bppRGB555
;
1249 format
= PixelFormat24bppRGB
;
1252 format
= PixelFormat32bppRGB
;
1255 FIXME("don't know how to handle %d bpp\n", info
->bmiHeader
.biBitCount
);
1257 return InvalidParameter
;
1260 return GdipCreateBitmapFromScan0(info
->bmiHeader
.biWidth
, height
, stride
, format
,
1266 GpStatus WINGDIPAPI
GdipCreateBitmapFromFileICM(GDIPCONST WCHAR
* filename
,
1269 TRACE("(%s) %p\n", debugstr_w(filename
), bitmap
);
1271 return GdipCreateBitmapFromFile(filename
, bitmap
);
1274 GpStatus WINGDIPAPI
GdipCreateBitmapFromResource(HINSTANCE hInstance
,
1275 GDIPCONST WCHAR
* lpBitmapName
, GpBitmap
** bitmap
)
1278 GpStatus stat
= InvalidParameter
;
1280 TRACE("%p (%s) %p\n", hInstance
, debugstr_w(lpBitmapName
), bitmap
);
1282 if(!lpBitmapName
|| !bitmap
)
1283 return InvalidParameter
;
1286 hbm
= LoadImageW(hInstance
, lpBitmapName
, IMAGE_BITMAP
, 0, 0,
1287 LR_CREATEDIBSECTION
);
1290 stat
= GdipCreateBitmapFromHBITMAP(hbm
, NULL
, bitmap
);
1297 GpStatus WINGDIPAPI
GdipCreateHBITMAPFromBitmap(GpBitmap
* bitmap
,
1298 HBITMAP
* hbmReturn
, ARGB background
)
1301 HBITMAP result
, oldbitmap
;
1304 GpGraphics
*graphics
;
1305 BITMAPINFOHEADER bih
;
1307 TRACE("(%p,%p,%x)\n", bitmap
, hbmReturn
, background
);
1309 if (!bitmap
|| !hbmReturn
) return InvalidParameter
;
1311 GdipGetImageWidth((GpImage
*)bitmap
, &width
);
1312 GdipGetImageHeight((GpImage
*)bitmap
, &height
);
1314 bih
.biSize
= sizeof(bih
);
1315 bih
.biWidth
= width
;
1316 bih
.biHeight
= height
;
1318 bih
.biBitCount
= 32;
1319 bih
.biCompression
= BI_RGB
;
1320 bih
.biSizeImage
= 0;
1321 bih
.biXPelsPerMeter
= 0;
1322 bih
.biYPelsPerMeter
= 0;
1324 bih
.biClrImportant
= 0;
1326 hdc
= CreateCompatibleDC(NULL
);
1327 if (!hdc
) return GenericError
;
1329 result
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
, &bits
,
1334 oldbitmap
= SelectObject(hdc
, result
);
1336 stat
= GdipCreateFromHDC(hdc
, &graphics
);
1339 stat
= GdipGraphicsClear(graphics
, background
);
1342 stat
= GdipDrawImage(graphics
, (GpImage
*)bitmap
, 0, 0);
1344 GdipDeleteGraphics(graphics
);
1347 SelectObject(hdc
, oldbitmap
);
1350 stat
= GenericError
;
1354 if (stat
!= Ok
&& result
)
1356 DeleteObject(result
);
1360 *hbmReturn
= result
;
1365 GpStatus WINGDIPAPI
GdipConvertToEmfPlus(const GpGraphics
* ref
,
1366 GpMetafile
* metafile
, BOOL
* succ
, EmfType emfType
,
1367 const WCHAR
* description
, GpMetafile
** out_metafile
)
1371 TRACE("(%p,%p,%p,%u,%s,%p)\n", ref
, metafile
, succ
, emfType
,
1372 debugstr_w(description
), out_metafile
);
1374 if(!ref
|| !metafile
|| !out_metafile
)
1375 return InvalidParameter
;
1378 *out_metafile
= NULL
;
1381 FIXME("not implemented\n");
1383 return NotImplemented
;
1386 /* FIXME: this should create a bitmap in the given size with the attributes
1387 * (resolution etc.) of the graphics object */
1388 GpStatus WINGDIPAPI
GdipCreateBitmapFromGraphics(INT width
, INT height
,
1389 GpGraphics
* target
, GpBitmap
** bitmap
)
1394 TRACE("(%d, %d, %p, %p)\n", width
, height
, target
, bitmap
);
1396 if(!target
|| !bitmap
)
1397 return InvalidParameter
;
1400 FIXME("hacked stub\n");
1402 ret
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat24bppRGB
,
1408 GpStatus WINGDIPAPI
GdipCreateBitmapFromHICON(HICON hicon
, GpBitmap
** bitmap
)
1416 BitmapData lockeddata
;
1421 BITMAPINFOHEADER bih
;
1426 TRACE("%p, %p\n", hicon
, bitmap
);
1428 if(!bitmap
|| !GetIconInfo(hicon
, &iinfo
))
1429 return InvalidParameter
;
1431 /* get the size of the icon */
1432 ret
= GetObjectA(iinfo
.hbmColor
? iinfo
.hbmColor
: iinfo
.hbmMask
, sizeof(bm
), &bm
);
1434 DeleteObject(iinfo
.hbmColor
);
1435 DeleteObject(iinfo
.hbmMask
);
1436 return GenericError
;
1442 height
= abs(bm
.bmHeight
);
1443 else /* combined bitmap + mask */
1444 height
= abs(bm
.bmHeight
) / 2;
1446 bits
= HeapAlloc(GetProcessHeap(), 0, 4*width
*height
);
1448 DeleteObject(iinfo
.hbmColor
);
1449 DeleteObject(iinfo
.hbmMask
);
1453 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat32bppARGB
, NULL
, bitmap
);
1455 DeleteObject(iinfo
.hbmColor
);
1456 DeleteObject(iinfo
.hbmMask
);
1457 HeapFree(GetProcessHeap(), 0, bits
);
1464 rect
.Height
= height
;
1466 stat
= GdipBitmapLockBits(*bitmap
, &rect
, ImageLockModeWrite
, PixelFormat32bppARGB
, &lockeddata
);
1468 DeleteObject(iinfo
.hbmColor
);
1469 DeleteObject(iinfo
.hbmMask
);
1470 HeapFree(GetProcessHeap(), 0, bits
);
1471 GdipDisposeImage((GpImage
*)*bitmap
);
1475 bih
.biSize
= sizeof(bih
);
1476 bih
.biWidth
= width
;
1477 bih
.biHeight
= -height
;
1479 bih
.biBitCount
= 32;
1480 bih
.biCompression
= BI_RGB
;
1481 bih
.biSizeImage
= 0;
1482 bih
.biXPelsPerMeter
= 0;
1483 bih
.biYPelsPerMeter
= 0;
1485 bih
.biClrImportant
= 0;
1487 screendc
= GetDC(0);
1490 GetDIBits(screendc
, iinfo
.hbmColor
, 0, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1492 if (bm
.bmBitsPixel
== 32)
1496 /* If any pixel has a non-zero alpha, ignore hbmMask */
1498 for (x
=0; x
<width
&& !has_alpha
; x
++)
1499 for (y
=0; y
<height
&& !has_alpha
; y
++)
1500 if ((*src
++ & 0xff000000) != 0)
1503 else has_alpha
= FALSE
;
1507 GetDIBits(screendc
, iinfo
.hbmMask
, 0, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1511 /* copy the image data to the Bitmap */
1513 dst_row
= lockeddata
.Scan0
;
1514 for (y
=0; y
<height
; y
++)
1516 memcpy(dst_row
, src
, width
*4);
1518 dst_row
+= lockeddata
.Stride
;
1525 /* read alpha data from the mask */
1527 GetDIBits(screendc
, iinfo
.hbmMask
, 0, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1529 GetDIBits(screendc
, iinfo
.hbmMask
, height
, height
, bits
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
);
1532 dst_row
= lockeddata
.Scan0
;
1533 for (y
=0; y
<height
; y
++)
1535 dst
= (DWORD
*)dst_row
;
1536 for (x
=0; x
<height
; x
++)
1538 DWORD src_value
= *src
++;
1542 *dst
++ |= 0xff000000;
1544 dst_row
+= lockeddata
.Stride
;
1549 /* set constant alpha of 255 */
1551 for (y
=0; y
<height
; y
++)
1553 dst
= (DWORD
*)dst_row
;
1554 for (x
=0; x
<height
; x
++)
1555 *dst
++ |= 0xff000000;
1556 dst_row
+= lockeddata
.Stride
;
1561 ReleaseDC(0, screendc
);
1563 DeleteObject(iinfo
.hbmColor
);
1564 DeleteObject(iinfo
.hbmMask
);
1566 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
1568 HeapFree(GetProcessHeap(), 0, bits
);
1573 static void generate_halftone_palette(ARGB
*entries
, UINT count
)
1575 static const BYTE halftone_values
[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1578 for (i
=0; i
<8 && i
<count
; i
++)
1580 entries
[i
] = 0xff000000;
1581 if (i
&1) entries
[i
] |= 0x800000;
1582 if (i
&2) entries
[i
] |= 0x8000;
1583 if (i
&4) entries
[i
] |= 0x80;
1587 entries
[i
] = 0xffc0c0c0;
1589 for (i
=9; i
<16 && i
<count
; i
++)
1591 entries
[i
] = 0xff000000;
1592 if (i
&1) entries
[i
] |= 0xff0000;
1593 if (i
&2) entries
[i
] |= 0xff00;
1594 if (i
&4) entries
[i
] |= 0xff;
1597 for (i
=16; i
<40 && i
<count
; i
++)
1602 for (i
=40; i
<256 && i
<count
; i
++)
1604 entries
[i
] = 0xff000000;
1605 entries
[i
] |= halftone_values
[(i
-40)%6];
1606 entries
[i
] |= halftone_values
[((i
-40)/6)%6] << 8;
1607 entries
[i
] |= halftone_values
[((i
-40)/36)%6] << 16;
1611 static GpStatus
get_screen_resolution(REAL
*xres
, REAL
*yres
)
1613 HDC screendc
= GetDC(0);
1615 if (!screendc
) return GenericError
;
1617 *xres
= (REAL
)GetDeviceCaps(screendc
, LOGPIXELSX
);
1618 *yres
= (REAL
)GetDeviceCaps(screendc
, LOGPIXELSY
);
1620 ReleaseDC(0, screendc
);
1625 GpStatus WINGDIPAPI
GdipCreateBitmapFromScan0(INT width
, INT height
, INT stride
,
1626 PixelFormat format
, BYTE
* scan0
, GpBitmap
** bitmap
)
1630 INT row_size
, dib_stride
;
1637 TRACE("%d %d %d 0x%x %p %p\n", width
, height
, stride
, format
, scan0
, bitmap
);
1639 if (!bitmap
) return InvalidParameter
;
1641 if(width
<= 0 || height
<= 0 || (scan0
&& (stride
% 4))){
1643 return InvalidParameter
;
1646 if(scan0
&& !stride
)
1647 return InvalidParameter
;
1649 stat
= get_screen_resolution(&xres
, &yres
);
1650 if (stat
!= Ok
) return stat
;
1652 row_size
= (width
* PIXELFORMATBPP(format
)+7) / 8;
1653 dib_stride
= (row_size
+ 3) & ~3;
1656 stride
= dib_stride
;
1658 pbmi
= GdipAlloc(sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1662 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1663 pbmi
->bmiHeader
.biWidth
= width
;
1664 pbmi
->bmiHeader
.biHeight
= -height
;
1665 pbmi
->bmiHeader
.biPlanes
= 1;
1666 /* FIXME: use the rest of the data from format */
1667 pbmi
->bmiHeader
.biBitCount
= PIXELFORMATBPP(format
);
1668 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
1669 pbmi
->bmiHeader
.biSizeImage
= 0;
1670 pbmi
->bmiHeader
.biXPelsPerMeter
= 0;
1671 pbmi
->bmiHeader
.biYPelsPerMeter
= 0;
1672 pbmi
->bmiHeader
.biClrUsed
= 0;
1673 pbmi
->bmiHeader
.biClrImportant
= 0;
1675 hdc
= CreateCompatibleDC(NULL
);
1678 return GenericError
;
1681 hbitmap
= CreateDIBSection(hdc
, pbmi
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1686 if (!hbitmap
) return GenericError
;
1688 /* copy bits to the dib if necessary */
1689 /* FIXME: should reference the bits instead of copying them */
1691 for (i
=0; i
<height
; i
++)
1692 memcpy(bits
+i
*dib_stride
, scan0
+i
*stride
, row_size
);
1694 *bitmap
= GdipAlloc(sizeof(GpBitmap
));
1697 DeleteObject(hbitmap
);
1701 (*bitmap
)->image
.type
= ImageTypeBitmap
;
1702 memcpy(&(*bitmap
)->image
.format
, &ImageFormatMemoryBMP
, sizeof(GUID
));
1703 (*bitmap
)->image
.flags
= ImageFlagsNone
;
1704 (*bitmap
)->image
.palette_flags
= 0;
1705 (*bitmap
)->image
.palette_count
= 0;
1706 (*bitmap
)->image
.palette_size
= 0;
1707 (*bitmap
)->image
.palette_entries
= NULL
;
1708 (*bitmap
)->image
.xres
= xres
;
1709 (*bitmap
)->image
.yres
= yres
;
1710 (*bitmap
)->width
= width
;
1711 (*bitmap
)->height
= height
;
1712 (*bitmap
)->format
= format
;
1713 (*bitmap
)->image
.picture
= NULL
;
1714 (*bitmap
)->hbitmap
= hbitmap
;
1715 (*bitmap
)->hdc
= NULL
;
1716 (*bitmap
)->bits
= bits
;
1717 (*bitmap
)->stride
= dib_stride
;
1719 if (format
== PixelFormat1bppIndexed
||
1720 format
== PixelFormat4bppIndexed
||
1721 format
== PixelFormat8bppIndexed
)
1723 (*bitmap
)->image
.palette_size
= (*bitmap
)->image
.palette_count
= 1 << PIXELFORMATBPP(format
);
1724 (*bitmap
)->image
.palette_entries
= GdipAlloc(sizeof(ARGB
) * ((*bitmap
)->image
.palette_size
));
1726 if (!(*bitmap
)->image
.palette_entries
)
1728 GdipDisposeImage(&(*bitmap
)->image
);
1733 if (format
== PixelFormat1bppIndexed
)
1735 (*bitmap
)->image
.palette_flags
= PaletteFlagsGrayScale
;
1736 (*bitmap
)->image
.palette_entries
[0] = 0xff000000;
1737 (*bitmap
)->image
.palette_entries
[1] = 0xffffffff;
1741 if (format
== PixelFormat8bppIndexed
)
1742 (*bitmap
)->image
.palette_flags
= PaletteFlagsHalftone
;
1744 generate_halftone_palette((*bitmap
)->image
.palette_entries
,
1745 (*bitmap
)->image
.palette_count
);
1749 TRACE("<-- %p\n", *bitmap
);
1754 GpStatus WINGDIPAPI
GdipCreateBitmapFromStream(IStream
* stream
,
1759 TRACE("%p %p\n", stream
, bitmap
);
1761 stat
= GdipLoadImageFromStream(stream
, (GpImage
**) bitmap
);
1766 if((*bitmap
)->image
.type
!= ImageTypeBitmap
){
1767 GdipDisposeImage(&(*bitmap
)->image
);
1769 return GenericError
; /* FIXME: what error to return? */
1776 GpStatus WINGDIPAPI
GdipCreateBitmapFromStreamICM(IStream
* stream
,
1779 TRACE("%p %p\n", stream
, bitmap
);
1781 return GdipCreateBitmapFromStream(stream
, bitmap
);
1784 GpStatus WINGDIPAPI
GdipCreateCachedBitmap(GpBitmap
*bitmap
, GpGraphics
*graphics
,
1785 GpCachedBitmap
**cachedbmp
)
1789 TRACE("%p %p %p\n", bitmap
, graphics
, cachedbmp
);
1791 if(!bitmap
|| !graphics
|| !cachedbmp
)
1792 return InvalidParameter
;
1794 *cachedbmp
= GdipAlloc(sizeof(GpCachedBitmap
));
1798 stat
= GdipCloneImage(&(bitmap
->image
), &(*cachedbmp
)->image
);
1800 GdipFree(*cachedbmp
);
1807 GpStatus WINGDIPAPI
GdipCreateHICONFromBitmap(GpBitmap
*bitmap
, HICON
*hicon
)
1810 BitmapData lockeddata
;
1811 ULONG andstride
, xorstride
, bitssize
;
1812 LPBYTE andbits
, xorbits
, androw
, xorrow
, srcrow
;
1815 TRACE("(%p, %p)\n", bitmap
, hicon
);
1817 if (!bitmap
|| !hicon
)
1818 return InvalidParameter
;
1820 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
,
1821 PixelFormat32bppPARGB
, &lockeddata
);
1824 andstride
= ((lockeddata
.Width
+31)/32)*4;
1825 xorstride
= lockeddata
.Width
*4;
1826 bitssize
= (andstride
+ xorstride
) * lockeddata
.Height
;
1828 andbits
= GdipAlloc(bitssize
);
1832 xorbits
= andbits
+ andstride
* lockeddata
.Height
;
1834 for (y
=0; y
<lockeddata
.Height
; y
++)
1836 srcrow
= ((LPBYTE
)lockeddata
.Scan0
) + lockeddata
.Stride
* y
;
1838 androw
= andbits
+ andstride
* y
;
1839 for (x
=0; x
<lockeddata
.Width
; x
++)
1840 if (srcrow
[3+4*x
] >= 128)
1841 androw
[x
/8] |= 1 << (7-x
%8);
1843 xorrow
= xorbits
+ xorstride
* y
;
1844 memcpy(xorrow
, srcrow
, xorstride
);
1847 *hicon
= CreateIcon(NULL
, lockeddata
.Width
, lockeddata
.Height
, 1, 32,
1855 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
1861 GpStatus WINGDIPAPI
GdipDeleteCachedBitmap(GpCachedBitmap
*cachedbmp
)
1863 TRACE("%p\n", cachedbmp
);
1866 return InvalidParameter
;
1868 GdipDisposeImage(cachedbmp
->image
);
1869 GdipFree(cachedbmp
);
1874 GpStatus WINGDIPAPI
GdipDrawCachedBitmap(GpGraphics
*graphics
,
1875 GpCachedBitmap
*cachedbmp
, INT x
, INT y
)
1877 TRACE("%p %p %d %d\n", graphics
, cachedbmp
, x
, y
);
1879 if(!graphics
|| !cachedbmp
)
1880 return InvalidParameter
;
1882 return GdipDrawImage(graphics
, cachedbmp
->image
, (REAL
)x
, (REAL
)y
);
1885 GpStatus WINGDIPAPI
GdipEmfToWmfBits(HENHMETAFILE hemf
, UINT cbData16
,
1886 LPBYTE pData16
, INT iMapMode
, INT eFlags
)
1888 FIXME("(%p, %d, %p, %d, %d): stub\n", hemf
, cbData16
, pData16
, iMapMode
, eFlags
);
1889 return NotImplemented
;
1892 /* Internal utility function: Replace the image data of dst with that of src,
1894 static void move_bitmap(GpBitmap
*dst
, GpBitmap
*src
, BOOL clobber_palette
)
1896 GdipFree(dst
->bitmapbits
);
1898 DeleteObject(dst
->hbitmap
);
1900 if (clobber_palette
)
1902 GdipFree(dst
->image
.palette_entries
);
1903 dst
->image
.palette_flags
= src
->image
.palette_flags
;
1904 dst
->image
.palette_count
= src
->image
.palette_count
;
1905 dst
->image
.palette_entries
= src
->image
.palette_entries
;
1908 GdipFree(src
->image
.palette_entries
);
1910 dst
->image
.xres
= src
->image
.xres
;
1911 dst
->image
.yres
= src
->image
.yres
;
1912 dst
->width
= src
->width
;
1913 dst
->height
= src
->height
;
1914 dst
->format
= src
->format
;
1915 dst
->hbitmap
= src
->hbitmap
;
1916 dst
->hdc
= src
->hdc
;
1917 dst
->bits
= src
->bits
;
1918 dst
->stride
= src
->stride
;
1923 GpStatus WINGDIPAPI
GdipDisposeImage(GpImage
*image
)
1925 TRACE("%p\n", image
);
1928 return InvalidParameter
;
1931 IPicture_Release(image
->picture
);
1932 if (image
->type
== ImageTypeBitmap
)
1934 GdipFree(((GpBitmap
*)image
)->bitmapbits
);
1935 DeleteDC(((GpBitmap
*)image
)->hdc
);
1936 DeleteObject(((GpBitmap
*)image
)->hbitmap
);
1938 GdipFree(image
->palette_entries
);
1944 GpStatus WINGDIPAPI
GdipFindFirstImageItem(GpImage
*image
, ImageItemData
* item
)
1948 TRACE("(%p,%p)\n", image
, item
);
1951 return InvalidParameter
;
1954 FIXME("not implemented\n");
1956 return NotImplemented
;
1959 GpStatus WINGDIPAPI
GdipGetImageItemData(GpImage
*image
, ImageItemData
*item
)
1963 TRACE("(%p,%p)\n", image
, item
);
1966 FIXME("not implemented\n");
1968 return NotImplemented
;
1971 GpStatus WINGDIPAPI
GdipGetImageBounds(GpImage
*image
, GpRectF
*srcRect
,
1974 TRACE("%p %p %p\n", image
, srcRect
, srcUnit
);
1976 if(!image
|| !srcRect
|| !srcUnit
)
1977 return InvalidParameter
;
1978 if(image
->type
== ImageTypeMetafile
){
1979 *srcRect
= ((GpMetafile
*)image
)->bounds
;
1980 *srcUnit
= ((GpMetafile
*)image
)->unit
;
1982 else if(image
->type
== ImageTypeBitmap
){
1983 srcRect
->X
= srcRect
->Y
= 0.0;
1984 srcRect
->Width
= (REAL
) ((GpBitmap
*)image
)->width
;
1985 srcRect
->Height
= (REAL
) ((GpBitmap
*)image
)->height
;
1986 *srcUnit
= UnitPixel
;
1989 srcRect
->X
= srcRect
->Y
= 0.0;
1990 srcRect
->Width
= ipicture_pixel_width(image
->picture
);
1991 srcRect
->Height
= ipicture_pixel_height(image
->picture
);
1992 *srcUnit
= UnitPixel
;
1995 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect
->X
, srcRect
->Y
,
1996 srcRect
->Width
, srcRect
->Height
, *srcUnit
);
2001 GpStatus WINGDIPAPI
GdipGetImageDimension(GpImage
*image
, REAL
*width
,
2004 TRACE("%p %p %p\n", image
, width
, height
);
2006 if(!image
|| !height
|| !width
)
2007 return InvalidParameter
;
2009 if(image
->type
== ImageTypeMetafile
){
2012 *height
= convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
2013 ((GpMetafile
*)image
)->bounds
.Height
;
2015 *width
= convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
2016 ((GpMetafile
*)image
)->bounds
.Width
;
2021 else if(image
->type
== ImageTypeBitmap
){
2022 *height
= ((GpBitmap
*)image
)->height
;
2023 *width
= ((GpBitmap
*)image
)->width
;
2026 *height
= ipicture_pixel_height(image
->picture
);
2027 *width
= ipicture_pixel_width(image
->picture
);
2030 TRACE("returning (%f, %f)\n", *height
, *width
);
2034 GpStatus WINGDIPAPI
GdipGetImageGraphicsContext(GpImage
*image
,
2035 GpGraphics
**graphics
)
2040 TRACE("%p %p\n", image
, graphics
);
2042 if(!image
|| !graphics
)
2043 return InvalidParameter
;
2045 if(image
->type
!= ImageTypeBitmap
){
2046 FIXME("not implemented for image type %d\n", image
->type
);
2047 return NotImplemented
;
2050 hdc
= ((GpBitmap
*)image
)->hdc
;
2053 hdc
= CreateCompatibleDC(0);
2054 SelectObject(hdc
, ((GpBitmap
*)image
)->hbitmap
);
2055 ((GpBitmap
*)image
)->hdc
= hdc
;
2058 stat
= GdipCreateFromHDC(hdc
, graphics
);
2061 (*graphics
)->image
= image
;
2066 GpStatus WINGDIPAPI
GdipGetImageHeight(GpImage
*image
, UINT
*height
)
2068 TRACE("%p %p\n", image
, height
);
2070 if(!image
|| !height
)
2071 return InvalidParameter
;
2073 if(image
->type
== ImageTypeMetafile
){
2076 *height
= roundr(convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
2077 ((GpMetafile
*)image
)->bounds
.Height
);
2081 else if(image
->type
== ImageTypeBitmap
)
2082 *height
= ((GpBitmap
*)image
)->height
;
2084 *height
= ipicture_pixel_height(image
->picture
);
2086 TRACE("returning %d\n", *height
);
2091 GpStatus WINGDIPAPI
GdipGetImageHorizontalResolution(GpImage
*image
, REAL
*res
)
2094 return InvalidParameter
;
2098 TRACE("(%p) <-- %0.2f\n", image
, *res
);
2103 GpStatus WINGDIPAPI
GdipGetImagePaletteSize(GpImage
*image
, INT
*size
)
2105 TRACE("%p %p\n", image
, size
);
2108 return InvalidParameter
;
2110 if (image
->palette_count
== 0)
2111 *size
= sizeof(ColorPalette
);
2113 *size
= sizeof(UINT
)*2 + sizeof(ARGB
)*image
->palette_count
;
2115 TRACE("<-- %u\n", *size
);
2120 /* FIXME: test this function for non-bitmap types */
2121 GpStatus WINGDIPAPI
GdipGetImagePixelFormat(GpImage
*image
, PixelFormat
*format
)
2123 TRACE("%p %p\n", image
, format
);
2125 if(!image
|| !format
)
2126 return InvalidParameter
;
2128 if(image
->type
!= ImageTypeBitmap
)
2129 *format
= PixelFormat24bppRGB
;
2131 *format
= ((GpBitmap
*) image
)->format
;
2136 GpStatus WINGDIPAPI
GdipGetImageRawFormat(GpImage
*image
, GUID
*format
)
2138 TRACE("(%p, %p)\n", image
, format
);
2140 if(!image
|| !format
)
2141 return InvalidParameter
;
2143 memcpy(format
, &image
->format
, sizeof(GUID
));
2148 GpStatus WINGDIPAPI
GdipGetImageType(GpImage
*image
, ImageType
*type
)
2150 TRACE("%p %p\n", image
, type
);
2153 return InvalidParameter
;
2155 *type
= image
->type
;
2160 GpStatus WINGDIPAPI
GdipGetImageVerticalResolution(GpImage
*image
, REAL
*res
)
2163 return InvalidParameter
;
2167 TRACE("(%p) <-- %0.2f\n", image
, *res
);
2172 GpStatus WINGDIPAPI
GdipGetImageWidth(GpImage
*image
, UINT
*width
)
2174 TRACE("%p %p\n", image
, width
);
2176 if(!image
|| !width
)
2177 return InvalidParameter
;
2179 if(image
->type
== ImageTypeMetafile
){
2182 *width
= roundr(convert_unit(hdc
, ((GpMetafile
*)image
)->unit
) *
2183 ((GpMetafile
*)image
)->bounds
.Width
);
2187 else if(image
->type
== ImageTypeBitmap
)
2188 *width
= ((GpBitmap
*)image
)->width
;
2190 *width
= ipicture_pixel_width(image
->picture
);
2192 TRACE("returning %d\n", *width
);
2197 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromMetafile(GpMetafile
* metafile
,
2198 MetafileHeader
* header
)
2202 TRACE("(%p, %p)\n", metafile
, header
);
2204 if(!metafile
|| !header
)
2205 return InvalidParameter
;
2208 FIXME("not implemented\n");
2210 memset(header
, 0, sizeof(MetafileHeader
));
2215 GpStatus WINGDIPAPI
GdipGetMetafileHeaderFromEmf(HENHMETAFILE hEmf
,
2216 MetafileHeader
*header
)
2220 if(!hEmf
|| !header
)
2221 return InvalidParameter
;
2224 FIXME("not implemented\n");
2226 memset(header
, 0, sizeof(MetafileHeader
));
2231 GpStatus WINGDIPAPI
GdipGetAllPropertyItems(GpImage
*image
, UINT size
,
2232 UINT num
, PropertyItem
* items
)
2236 TRACE("(%p, %u, %u, %p)\n", image
, size
, num
, items
);
2239 FIXME("not implemented\n");
2241 return InvalidParameter
;
2244 GpStatus WINGDIPAPI
GdipGetPropertyCount(GpImage
*image
, UINT
* num
)
2248 TRACE("(%p, %p)\n", image
, num
);
2251 FIXME("not implemented\n");
2253 return InvalidParameter
;
2256 GpStatus WINGDIPAPI
GdipGetPropertyIdList(GpImage
*image
, UINT num
, PROPID
* list
)
2260 TRACE("(%p, %u, %p)\n", image
, num
, list
);
2263 FIXME("not implemented\n");
2265 return InvalidParameter
;
2268 GpStatus WINGDIPAPI
GdipGetPropertyItem(GpImage
*image
, PROPID id
, UINT size
,
2269 PropertyItem
* buffer
)
2273 TRACE("(%p, %u, %u, %p)\n", image
, id
, size
, buffer
);
2276 FIXME("not implemented\n");
2278 return InvalidParameter
;
2281 GpStatus WINGDIPAPI
GdipGetPropertyItemSize(GpImage
*image
, PROPID pid
,
2286 TRACE("%p %x %p\n", image
, pid
, size
);
2289 return InvalidParameter
;
2292 FIXME("not implemented\n");
2294 return NotImplemented
;
2297 GpStatus WINGDIPAPI
GdipGetPropertySize(GpImage
*image
, UINT
* size
, UINT
* num
)
2301 TRACE("(%p,%p,%p)\n", image
, size
, num
);
2304 FIXME("not implemented\n");
2306 return InvalidParameter
;
2309 struct image_format_dimension
2312 const GUID
*dimension
;
2315 struct image_format_dimension image_format_dimensions
[] =
2317 {&ImageFormatGIF
, &FrameDimensionTime
},
2318 {&ImageFormatIcon
, &FrameDimensionResolution
},
2322 /* FIXME: Need to handle multi-framed images */
2323 GpStatus WINGDIPAPI
GdipImageGetFrameCount(GpImage
*image
,
2324 GDIPCONST GUID
* dimensionID
, UINT
* count
)
2328 TRACE("(%p,%s,%p)\n", image
, debugstr_guid(dimensionID
), count
);
2330 if(!image
|| !count
)
2331 return InvalidParameter
;
2334 FIXME("returning frame count of 1\n");
2341 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsCount(GpImage
*image
,
2344 TRACE("(%p, %p)\n", image
, count
);
2346 /* Native gdiplus 1.1 does not yet support multiple frame dimensions. */
2348 if(!image
|| !count
)
2349 return InvalidParameter
;
2356 GpStatus WINGDIPAPI
GdipImageGetFrameDimensionsList(GpImage
* image
,
2357 GUID
* dimensionIDs
, UINT count
)
2360 const GUID
*result
=NULL
;
2362 TRACE("(%p,%p,%u)\n", image
, dimensionIDs
, count
);
2364 if(!image
|| !dimensionIDs
|| count
!= 1)
2365 return InvalidParameter
;
2367 for (i
=0; image_format_dimensions
[i
].format
; i
++)
2369 if (IsEqualGUID(&image
->format
, image_format_dimensions
[i
].format
))
2371 result
= image_format_dimensions
[i
].dimension
;
2377 result
= &FrameDimensionPage
;
2379 memcpy(dimensionIDs
, result
, sizeof(GUID
));
2384 GpStatus WINGDIPAPI
GdipImageSelectActiveFrame(GpImage
*image
,
2385 GDIPCONST GUID
* dimensionID
, UINT frameidx
)
2389 TRACE("(%p, %s, %u)\n", image
, debugstr_guid(dimensionID
), frameidx
);
2391 if(!image
|| !dimensionID
)
2392 return InvalidParameter
;
2395 FIXME("not implemented\n");
2400 GpStatus WINGDIPAPI
GdipLoadImageFromFile(GDIPCONST WCHAR
* filename
,
2406 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
2408 if (!filename
|| !image
)
2409 return InvalidParameter
;
2411 stat
= GdipCreateStreamOnFile(filename
, GENERIC_READ
, &stream
);
2416 stat
= GdipLoadImageFromStream(stream
, image
);
2418 IStream_Release(stream
);
2423 /* FIXME: no icm handling */
2424 GpStatus WINGDIPAPI
GdipLoadImageFromFileICM(GDIPCONST WCHAR
* filename
,GpImage
**image
)
2426 TRACE("(%s) %p\n", debugstr_w(filename
), image
);
2428 return GdipLoadImageFromFile(filename
, image
);
2431 static const WICPixelFormatGUID
*wic_pixel_formats
[] = {
2432 &GUID_WICPixelFormat16bppBGR555
,
2433 &GUID_WICPixelFormat24bppBGR
,
2434 &GUID_WICPixelFormat32bppBGR
,
2435 &GUID_WICPixelFormat32bppBGRA
,
2436 &GUID_WICPixelFormat32bppPBGRA
,
2440 static const PixelFormat wic_gdip_formats
[] = {
2441 PixelFormat16bppRGB555
,
2442 PixelFormat24bppRGB
,
2443 PixelFormat32bppRGB
,
2444 PixelFormat32bppARGB
,
2445 PixelFormat32bppPARGB
,
2448 static GpStatus
decode_image_wic(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
2453 IWICBitmapDecoder
*decoder
;
2454 IWICBitmapFrameDecode
*frame
;
2455 IWICBitmapSource
*source
=NULL
;
2456 WICPixelFormatGUID wic_format
;
2457 PixelFormat gdip_format
=0;
2460 BitmapData lockeddata
;
2464 initresult
= CoInitialize(NULL
);
2466 hr
= CoCreateInstance(clsid
, NULL
, CLSCTX_INPROC_SERVER
,
2467 &IID_IWICBitmapDecoder
, (void**)&decoder
);
2468 if (FAILED(hr
)) goto end
;
2470 hr
= IWICBitmapDecoder_Initialize(decoder
, (IStream
*)stream
, WICDecodeMetadataCacheOnLoad
);
2472 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
2474 if (SUCCEEDED(hr
)) /* got frame */
2476 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &wic_format
);
2480 for (i
=0; wic_pixel_formats
[i
]; i
++)
2482 if (IsEqualGUID(&wic_format
, wic_pixel_formats
[i
]))
2484 source
= (IWICBitmapSource
*)frame
;
2485 IWICBitmapSource_AddRef(source
);
2486 gdip_format
= wic_gdip_formats
[i
];
2492 /* unknown format; fall back on 32bppARGB */
2493 hr
= WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA
, (IWICBitmapSource
*)frame
, &source
);
2494 gdip_format
= PixelFormat32bppARGB
;
2498 if (SUCCEEDED(hr
)) /* got source */
2500 hr
= IWICBitmapSource_GetSize(source
, &width
, &height
);
2503 status
= GdipCreateBitmapFromScan0(width
, height
, 0, gdip_format
,
2506 if (SUCCEEDED(hr
) && status
== Ok
) /* created bitmap */
2508 status
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeWrite
,
2509 gdip_format
, &lockeddata
);
2510 if (status
== Ok
) /* locked bitmap */
2515 for (i
=0; i
<height
; i
++)
2518 hr
= IWICBitmapSource_CopyPixels(source
, &wrc
, abs(lockeddata
.Stride
),
2519 abs(lockeddata
.Stride
), (BYTE
*)lockeddata
.Scan0
+lockeddata
.Stride
*i
);
2520 if (FAILED(hr
)) break;
2523 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
2526 if (SUCCEEDED(hr
) && status
== Ok
)
2527 *image
= (GpImage
*)bitmap
;
2531 GdipDisposeImage((GpImage
*)bitmap
);
2535 IWICBitmapSource_Release(source
);
2538 IWICBitmapFrameDecode_Release(frame
);
2541 IWICBitmapDecoder_Release(decoder
);
2544 if (SUCCEEDED(initresult
)) CoUninitialize();
2546 if (FAILED(hr
) && status
== Ok
) status
= hresult_to_status(hr
);
2551 static GpStatus
decode_image_icon(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
2553 return decode_image_wic(stream
, &CLSID_WICIcoDecoder
, image
);
2556 static GpStatus
decode_image_bmp(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
2561 status
= decode_image_wic(stream
, &CLSID_WICBmpDecoder
, image
);
2563 bitmap
= (GpBitmap
*)*image
;
2565 if (status
== Ok
&& bitmap
->format
== PixelFormat32bppARGB
)
2567 /* WIC supports bmp files with alpha, but gdiplus does not */
2568 bitmap
->format
= PixelFormat32bppRGB
;
2574 static GpStatus
decode_image_jpeg(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
2576 return decode_image_wic(stream
, &CLSID_WICJpegDecoder
, image
);
2579 static GpStatus
decode_image_png(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
2581 return decode_image_wic(stream
, &CLSID_WICPngDecoder
, image
);
2584 static GpStatus
decode_image_gif(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
2586 return decode_image_wic(stream
, &CLSID_WICGifDecoder
, image
);
2589 static GpStatus
decode_image_tiff(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
2591 return decode_image_wic(stream
, &CLSID_WICTiffDecoder
, image
);
2594 static GpStatus
decode_image_olepicture_metafile(IStream
* stream
, REFCLSID clsid
, GpImage
**image
)
2598 TRACE("%p %p\n", stream
, image
);
2600 if(!stream
|| !image
)
2601 return InvalidParameter
;
2603 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
2604 (LPVOID
*) &pic
) != S_OK
){
2605 TRACE("Could not load picture\n");
2606 return GenericError
;
2609 /* FIXME: missing initialization code */
2610 *image
= GdipAlloc(sizeof(GpMetafile
));
2611 if(!*image
) return OutOfMemory
;
2612 (*image
)->type
= ImageTypeMetafile
;
2613 (*image
)->picture
= pic
;
2614 (*image
)->flags
= ImageFlagsNone
;
2615 (*image
)->palette_flags
= 0;
2616 (*image
)->palette_count
= 0;
2617 (*image
)->palette_size
= 0;
2618 (*image
)->palette_entries
= NULL
;
2620 TRACE("<-- %p\n", *image
);
2625 typedef GpStatus (*encode_image_func
)(GpImage
*image
, IStream
* stream
,
2626 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
);
2628 typedef GpStatus (*decode_image_func
)(IStream
*stream
, REFCLSID clsid
, GpImage
** image
);
2630 typedef struct image_codec
{
2631 ImageCodecInfo info
;
2632 encode_image_func encode_func
;
2633 decode_image_func decode_func
;
2648 static const struct image_codec codecs
[NUM_CODECS
];
2650 static GpStatus
get_decoder_info(IStream
* stream
, const struct image_codec
**result
)
2653 const BYTE
*pattern
, *mask
;
2659 /* seek to the start of the stream */
2661 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
2662 if (FAILED(hr
)) return hresult_to_status(hr
);
2664 /* read the first 8 bytes */
2665 /* FIXME: This assumes all codecs have signatures <= 8 bytes in length */
2666 hr
= IStream_Read(stream
, signature
, 8, &bytesread
);
2667 if (FAILED(hr
)) return hresult_to_status(hr
);
2668 if (hr
== S_FALSE
|| bytesread
== 0) return GenericError
;
2670 for (i
= 0; i
< NUM_CODECS
; i
++) {
2671 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
) &&
2672 bytesread
>= codecs
[i
].info
.SigSize
)
2674 for (sig
=0; sig
<codecs
[i
].info
.SigCount
; sig
++)
2676 pattern
= &codecs
[i
].info
.SigPattern
[codecs
[i
].info
.SigSize
*sig
];
2677 mask
= &codecs
[i
].info
.SigMask
[codecs
[i
].info
.SigSize
*sig
];
2678 for (j
=0; j
<codecs
[i
].info
.SigSize
; j
++)
2679 if ((signature
[j
] & mask
[j
]) != pattern
[j
])
2681 if (j
== codecs
[i
].info
.SigSize
)
2683 *result
= &codecs
[i
];
2690 TRACE("no match for %i byte signature %x %x %x %x %x %x %x %x\n", bytesread
,
2691 signature
[0],signature
[1],signature
[2],signature
[3],
2692 signature
[4],signature
[5],signature
[6],signature
[7]);
2694 return GenericError
;
2697 GpStatus WINGDIPAPI
GdipLoadImageFromStream(IStream
* stream
, GpImage
**image
)
2702 const struct image_codec
*codec
=NULL
;
2704 /* choose an appropriate image decoder */
2705 stat
= get_decoder_info(stream
, &codec
);
2706 if (stat
!= Ok
) return stat
;
2708 /* seek to the start of the stream */
2710 hr
= IStream_Seek(stream
, seek
, STREAM_SEEK_SET
, NULL
);
2711 if (FAILED(hr
)) return hresult_to_status(hr
);
2713 /* call on the image decoder to do the real work */
2714 stat
= codec
->decode_func(stream
, &codec
->info
.Clsid
, image
);
2716 /* take note of the original data format */
2719 memcpy(&(*image
)->format
, &codec
->info
.FormatID
, sizeof(GUID
));
2726 GpStatus WINGDIPAPI
GdipLoadImageFromStreamICM(IStream
* stream
, GpImage
**image
)
2728 TRACE("%p %p\n", stream
, image
);
2730 return GdipLoadImageFromStream(stream
, image
);
2733 GpStatus WINGDIPAPI
GdipRemovePropertyItem(GpImage
*image
, PROPID propId
)
2737 TRACE("(%p,%u)\n", image
, propId
);
2740 return InvalidParameter
;
2743 FIXME("not implemented\n");
2745 return NotImplemented
;
2748 GpStatus WINGDIPAPI
GdipSetPropertyItem(GpImage
*image
, GDIPCONST PropertyItem
* item
)
2752 TRACE("(%p,%p)\n", image
, item
);
2755 FIXME("not implemented\n");
2757 return NotImplemented
;
2760 GpStatus WINGDIPAPI
GdipSaveImageToFile(GpImage
*image
, GDIPCONST WCHAR
* filename
,
2761 GDIPCONST CLSID
*clsidEncoder
,
2762 GDIPCONST EncoderParameters
*encoderParams
)
2767 TRACE("%p (%s) %p %p\n", image
, debugstr_w(filename
), clsidEncoder
, encoderParams
);
2769 if (!image
|| !filename
|| !clsidEncoder
)
2770 return InvalidParameter
;
2772 stat
= GdipCreateStreamOnFile(filename
, GENERIC_WRITE
, &stream
);
2774 return GenericError
;
2776 stat
= GdipSaveImageToStream(image
, stream
, clsidEncoder
, encoderParams
);
2778 IStream_Release(stream
);
2782 /*************************************************************************
2783 * Encoding functions -
2784 * These functions encode an image in different image file formats.
2786 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
2787 #define BITMAP_FORMAT_JPEG 0xd8ff
2788 #define BITMAP_FORMAT_GIF 0x4947
2789 #define BITMAP_FORMAT_PNG 0x5089
2790 #define BITMAP_FORMAT_APM 0xcdd7
2792 static GpStatus
encode_image_WIC(GpImage
*image
, IStream
* stream
,
2793 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
2797 IWICBitmapEncoder
*encoder
;
2798 IWICBitmapFrameEncode
*frameencode
;
2799 IPropertyBag2
*encoderoptions
;
2802 PixelFormat gdipformat
=0;
2803 WICPixelFormatGUID wicformat
;
2805 BitmapData lockeddata
;
2809 if (image
->type
!= ImageTypeBitmap
)
2810 return GenericError
;
2812 bitmap
= (GpBitmap
*)image
;
2814 GdipGetImageWidth(image
, &width
);
2815 GdipGetImageHeight(image
, &height
);
2822 initresult
= CoInitialize(NULL
);
2824 hr
= CoCreateInstance(clsid
, NULL
, CLSCTX_INPROC_SERVER
,
2825 &IID_IWICBitmapEncoder
, (void**)&encoder
);
2828 if (SUCCEEDED(initresult
)) CoUninitialize();
2829 return hresult_to_status(hr
);
2832 hr
= IWICBitmapEncoder_Initialize(encoder
, stream
, WICBitmapEncoderNoCache
);
2836 hr
= IWICBitmapEncoder_CreateNewFrame(encoder
, &frameencode
, &encoderoptions
);
2839 if (SUCCEEDED(hr
)) /* created frame */
2841 hr
= IWICBitmapFrameEncode_Initialize(frameencode
, encoderoptions
);
2844 hr
= IWICBitmapFrameEncode_SetSize(frameencode
, width
, height
);
2847 /* FIXME: use the resolution from the image */
2848 hr
= IWICBitmapFrameEncode_SetResolution(frameencode
, 96.0, 96.0);
2852 for (i
=0; wic_pixel_formats
[i
]; i
++)
2854 if (wic_gdip_formats
[i
] == bitmap
->format
)
2857 if (wic_pixel_formats
[i
])
2858 memcpy(&wicformat
, wic_pixel_formats
[i
], sizeof(GUID
));
2860 memcpy(&wicformat
, &GUID_WICPixelFormat32bppBGRA
, sizeof(GUID
));
2862 hr
= IWICBitmapFrameEncode_SetPixelFormat(frameencode
, &wicformat
);
2864 for (i
=0; wic_pixel_formats
[i
]; i
++)
2866 if (IsEqualGUID(&wicformat
, wic_pixel_formats
[i
]))
2869 if (wic_pixel_formats
[i
])
2870 gdipformat
= wic_gdip_formats
[i
];
2873 ERR("cannot provide pixel format %s\n", debugstr_guid(&wicformat
));
2880 stat
= GdipBitmapLockBits(bitmap
, &rc
, ImageLockModeRead
, gdipformat
,
2885 UINT row_size
= (lockeddata
.Width
* PIXELFORMATBPP(gdipformat
) + 7)/8;
2888 /* write one row at a time in case stride is negative */
2889 row
= lockeddata
.Scan0
;
2890 for (i
=0; i
<lockeddata
.Height
; i
++)
2892 hr
= IWICBitmapFrameEncode_WritePixels(frameencode
, 1, row_size
, row_size
, row
);
2893 if (FAILED(hr
)) break;
2894 row
+= lockeddata
.Stride
;
2897 GdipBitmapUnlockBits(bitmap
, &lockeddata
);
2904 hr
= IWICBitmapFrameEncode_Commit(frameencode
);
2906 IWICBitmapFrameEncode_Release(frameencode
);
2907 IPropertyBag2_Release(encoderoptions
);
2911 hr
= IWICBitmapEncoder_Commit(encoder
);
2913 IWICBitmapEncoder_Release(encoder
);
2915 if (SUCCEEDED(initresult
)) CoUninitialize();
2917 return hresult_to_status(hr
);
2920 static GpStatus
encode_image_BMP(GpImage
*image
, IStream
* stream
,
2921 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
2923 return encode_image_WIC(image
, stream
, &CLSID_WICBmpEncoder
, params
);
2926 static GpStatus
encode_image_png(GpImage
*image
, IStream
* stream
,
2927 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
2929 return encode_image_WIC(image
, stream
, &CLSID_WICPngEncoder
, params
);
2932 /*****************************************************************************
2933 * GdipSaveImageToStream [GDIPLUS.@]
2935 GpStatus WINGDIPAPI
GdipSaveImageToStream(GpImage
*image
, IStream
* stream
,
2936 GDIPCONST CLSID
* clsid
, GDIPCONST EncoderParameters
* params
)
2939 encode_image_func encode_image
;
2942 TRACE("%p %p %p %p\n", image
, stream
, clsid
, params
);
2944 if(!image
|| !stream
)
2945 return InvalidParameter
;
2947 /* select correct encoder */
2948 encode_image
= NULL
;
2949 for (i
= 0; i
< NUM_CODECS
; i
++) {
2950 if ((codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
) &&
2951 IsEqualCLSID(clsid
, &codecs
[i
].info
.Clsid
))
2952 encode_image
= codecs
[i
].encode_func
;
2954 if (encode_image
== NULL
)
2955 return UnknownImageFormat
;
2957 stat
= encode_image(image
, stream
, clsid
, params
);
2962 /*****************************************************************************
2963 * GdipGetImagePalette [GDIPLUS.@]
2965 GpStatus WINGDIPAPI
GdipGetImagePalette(GpImage
*image
, ColorPalette
*palette
, INT size
)
2967 TRACE("(%p,%p,%i)\n", image
, palette
, size
);
2969 if (!image
|| !palette
)
2970 return InvalidParameter
;
2972 if (size
< (sizeof(UINT
)*2+sizeof(ARGB
)*image
->palette_count
))
2974 TRACE("<-- InsufficientBuffer\n");
2975 return InsufficientBuffer
;
2978 palette
->Flags
= image
->palette_flags
;
2979 palette
->Count
= image
->palette_count
;
2980 memcpy(palette
->Entries
, image
->palette_entries
, sizeof(ARGB
)*image
->palette_count
);
2985 /*****************************************************************************
2986 * GdipSetImagePalette [GDIPLUS.@]
2988 GpStatus WINGDIPAPI
GdipSetImagePalette(GpImage
*image
,
2989 GDIPCONST ColorPalette
*palette
)
2991 TRACE("(%p,%p)\n", image
, palette
);
2993 if(!image
|| !palette
|| palette
->Count
> 256)
2994 return InvalidParameter
;
2996 if (palette
->Count
> image
->palette_size
)
3000 new_palette
= GdipAlloc(sizeof(ARGB
) * palette
->Count
);
3001 if (!new_palette
) return OutOfMemory
;
3003 GdipFree(image
->palette_entries
);
3004 image
->palette_entries
= new_palette
;
3005 image
->palette_size
= palette
->Count
;
3008 image
->palette_flags
= palette
->Flags
;
3009 image
->palette_count
= palette
->Count
;
3010 memcpy(image
->palette_entries
, palette
->Entries
, sizeof(ARGB
)*palette
->Count
);
3015 /*************************************************************************
3017 * Structures that represent which formats we support for encoding.
3020 /* ImageCodecInfo creation routines taken from libgdiplus */
3021 static const WCHAR bmp_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
3022 static const WCHAR bmp_extension
[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
3023 static const WCHAR bmp_mimetype
[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
3024 static const WCHAR bmp_format
[] = {'B', 'M', 'P', 0}; /* BMP */
3025 static const BYTE bmp_sig_pattern
[] = { 0x42, 0x4D };
3026 static const BYTE bmp_sig_mask
[] = { 0xFF, 0xFF };
3028 static const WCHAR jpeg_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'J','P','E','G', 0};
3029 static const WCHAR jpeg_extension
[] = {'*','.','J','P','G',';', '*','.','J','P','E','G',';', '*','.','J','P','E',';', '*','.','J','F','I','F',0};
3030 static const WCHAR jpeg_mimetype
[] = {'i','m','a','g','e','/','j','p','e','g', 0};
3031 static const WCHAR jpeg_format
[] = {'J','P','E','G',0};
3032 static const BYTE jpeg_sig_pattern
[] = { 0xFF, 0xD8 };
3033 static const BYTE jpeg_sig_mask
[] = { 0xFF, 0xFF };
3035 static const WCHAR gif_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'G','I','F', 0};
3036 static const WCHAR gif_extension
[] = {'*','.','G','I','F',0};
3037 static const WCHAR gif_mimetype
[] = {'i','m','a','g','e','/','g','i','f', 0};
3038 static const WCHAR gif_format
[] = {'G','I','F',0};
3039 static const BYTE gif_sig_pattern
[4] = "GIF8";
3040 static const BYTE gif_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
3042 static const WCHAR tiff_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'T','I','F','F', 0};
3043 static const WCHAR tiff_extension
[] = {'*','.','T','I','F','F',';','*','.','T','I','F',0};
3044 static const WCHAR tiff_mimetype
[] = {'i','m','a','g','e','/','t','i','f','f', 0};
3045 static const WCHAR tiff_format
[] = {'T','I','F','F',0};
3046 static const BYTE tiff_sig_pattern
[] = {0x49,0x49,42,0,0x4d,0x4d,0,42};
3047 static const BYTE tiff_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
3049 static const WCHAR emf_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'E','M','F', 0};
3050 static const WCHAR emf_extension
[] = {'*','.','E','M','F',0};
3051 static const WCHAR emf_mimetype
[] = {'i','m','a','g','e','/','x','-','e','m','f', 0};
3052 static const WCHAR emf_format
[] = {'E','M','F',0};
3053 static const BYTE emf_sig_pattern
[] = { 0x01, 0x00, 0x00, 0x00 };
3054 static const BYTE emf_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
3056 static const WCHAR wmf_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'W','M','F', 0};
3057 static const WCHAR wmf_extension
[] = {'*','.','W','M','F',0};
3058 static const WCHAR wmf_mimetype
[] = {'i','m','a','g','e','/','x','-','w','m','f', 0};
3059 static const WCHAR wmf_format
[] = {'W','M','F',0};
3060 static const BYTE wmf_sig_pattern
[] = { 0xd7, 0xcd };
3061 static const BYTE wmf_sig_mask
[] = { 0xFF, 0xFF };
3063 static const WCHAR png_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'P','N','G', 0};
3064 static const WCHAR png_extension
[] = {'*','.','P','N','G',0};
3065 static const WCHAR png_mimetype
[] = {'i','m','a','g','e','/','p','n','g', 0};
3066 static const WCHAR png_format
[] = {'P','N','G',0};
3067 static const BYTE png_sig_pattern
[] = { 137, 80, 78, 71, 13, 10, 26, 10, };
3068 static const BYTE png_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
3070 static const WCHAR ico_codecname
[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'I','C','O', 0};
3071 static const WCHAR ico_extension
[] = {'*','.','I','C','O',0};
3072 static const WCHAR ico_mimetype
[] = {'i','m','a','g','e','/','x','-','i','c','o','n', 0};
3073 static const WCHAR ico_format
[] = {'I','C','O',0};
3074 static const BYTE ico_sig_pattern
[] = { 0x00, 0x00, 0x01, 0x00 };
3075 static const BYTE ico_sig_mask
[] = { 0xFF, 0xFF, 0xFF, 0xFF };
3077 static const struct image_codec codecs
[NUM_CODECS
] = {
3080 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
3081 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
3082 /* CodecName */ bmp_codecname
,
3084 /* FormatDescription */ bmp_format
,
3085 /* FilenameExtension */ bmp_extension
,
3086 /* MimeType */ bmp_mimetype
,
3087 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
3091 /* SigPattern */ bmp_sig_pattern
,
3092 /* SigMask */ bmp_sig_mask
,
3099 /* Clsid */ { 0x557cf401, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
3100 /* FormatID */ { 0xb96b3caeU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
3101 /* CodecName */ jpeg_codecname
,
3103 /* FormatDescription */ jpeg_format
,
3104 /* FilenameExtension */ jpeg_extension
,
3105 /* MimeType */ jpeg_mimetype
,
3106 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
3110 /* SigPattern */ jpeg_sig_pattern
,
3111 /* SigMask */ jpeg_sig_mask
,
3118 /* Clsid */ { 0x557cf402, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
3119 /* FormatID */ { 0xb96b3cb0U
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
3120 /* CodecName */ gif_codecname
,
3122 /* FormatDescription */ gif_format
,
3123 /* FilenameExtension */ gif_extension
,
3124 /* MimeType */ gif_mimetype
,
3125 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
3129 /* SigPattern */ gif_sig_pattern
,
3130 /* SigMask */ gif_sig_mask
,
3137 /* Clsid */ { 0x557cf405, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
3138 /* FormatID */ { 0xb96b3cb1U
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
3139 /* CodecName */ tiff_codecname
,
3141 /* FormatDescription */ tiff_format
,
3142 /* FilenameExtension */ tiff_extension
,
3143 /* MimeType */ tiff_mimetype
,
3144 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
3148 /* SigPattern */ tiff_sig_pattern
,
3149 /* SigMask */ tiff_sig_mask
,
3156 /* Clsid */ { 0x557cf403, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
3157 /* FormatID */ { 0xb96b3cacU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
3158 /* CodecName */ emf_codecname
,
3160 /* FormatDescription */ emf_format
,
3161 /* FilenameExtension */ emf_extension
,
3162 /* MimeType */ emf_mimetype
,
3163 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
3167 /* SigPattern */ emf_sig_pattern
,
3168 /* SigMask */ emf_sig_mask
,
3171 decode_image_olepicture_metafile
3175 /* Clsid */ { 0x557cf404, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
3176 /* FormatID */ { 0xb96b3cadU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
3177 /* CodecName */ wmf_codecname
,
3179 /* FormatDescription */ wmf_format
,
3180 /* FilenameExtension */ wmf_extension
,
3181 /* MimeType */ wmf_mimetype
,
3182 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportVector
| ImageCodecFlagsBuiltin
,
3186 /* SigPattern */ wmf_sig_pattern
,
3187 /* SigMask */ wmf_sig_mask
,
3190 decode_image_olepicture_metafile
3194 /* Clsid */ { 0x557cf406, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
3195 /* FormatID */ { 0xb96b3cafU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
3196 /* CodecName */ png_codecname
,
3198 /* FormatDescription */ png_format
,
3199 /* FilenameExtension */ png_extension
,
3200 /* MimeType */ png_mimetype
,
3201 /* Flags */ ImageCodecFlagsEncoder
| ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
3205 /* SigPattern */ png_sig_pattern
,
3206 /* SigMask */ png_sig_mask
,
3213 /* Clsid */ { 0x557cf407, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
3214 /* FormatID */ { 0xb96b3cabU
, 0x0728U
, 0x11d3U
, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
3215 /* CodecName */ ico_codecname
,
3217 /* FormatDescription */ ico_format
,
3218 /* FilenameExtension */ ico_extension
,
3219 /* MimeType */ ico_mimetype
,
3220 /* Flags */ ImageCodecFlagsDecoder
| ImageCodecFlagsSupportBitmap
| ImageCodecFlagsBuiltin
,
3224 /* SigPattern */ ico_sig_pattern
,
3225 /* SigMask */ ico_sig_mask
,
3232 /*****************************************************************************
3233 * GdipGetImageDecodersSize [GDIPLUS.@]
3235 GpStatus WINGDIPAPI
GdipGetImageDecodersSize(UINT
*numDecoders
, UINT
*size
)
3237 int decoder_count
=0;
3239 TRACE("%p %p\n", numDecoders
, size
);
3241 if (!numDecoders
|| !size
)
3242 return InvalidParameter
;
3244 for (i
=0; i
<NUM_CODECS
; i
++)
3246 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
3250 *numDecoders
= decoder_count
;
3251 *size
= decoder_count
* sizeof(ImageCodecInfo
);
3256 /*****************************************************************************
3257 * GdipGetImageDecoders [GDIPLUS.@]
3259 GpStatus WINGDIPAPI
GdipGetImageDecoders(UINT numDecoders
, UINT size
, ImageCodecInfo
*decoders
)
3261 int i
, decoder_count
=0;
3262 TRACE("%u %u %p\n", numDecoders
, size
, decoders
);
3265 size
!= numDecoders
* sizeof(ImageCodecInfo
))
3266 return GenericError
;
3268 for (i
=0; i
<NUM_CODECS
; i
++)
3270 if (codecs
[i
].info
.Flags
& ImageCodecFlagsDecoder
)
3272 if (decoder_count
== numDecoders
) return GenericError
;
3273 memcpy(&decoders
[decoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
3278 if (decoder_count
< numDecoders
) return GenericError
;
3283 /*****************************************************************************
3284 * GdipGetImageEncodersSize [GDIPLUS.@]
3286 GpStatus WINGDIPAPI
GdipGetImageEncodersSize(UINT
*numEncoders
, UINT
*size
)
3288 int encoder_count
=0;
3290 TRACE("%p %p\n", numEncoders
, size
);
3292 if (!numEncoders
|| !size
)
3293 return InvalidParameter
;
3295 for (i
=0; i
<NUM_CODECS
; i
++)
3297 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
3301 *numEncoders
= encoder_count
;
3302 *size
= encoder_count
* sizeof(ImageCodecInfo
);
3307 /*****************************************************************************
3308 * GdipGetImageEncoders [GDIPLUS.@]
3310 GpStatus WINGDIPAPI
GdipGetImageEncoders(UINT numEncoders
, UINT size
, ImageCodecInfo
*encoders
)
3312 int i
, encoder_count
=0;
3313 TRACE("%u %u %p\n", numEncoders
, size
, encoders
);
3316 size
!= numEncoders
* sizeof(ImageCodecInfo
))
3317 return GenericError
;
3319 for (i
=0; i
<NUM_CODECS
; i
++)
3321 if (codecs
[i
].info
.Flags
& ImageCodecFlagsEncoder
)
3323 if (encoder_count
== numEncoders
) return GenericError
;
3324 memcpy(&encoders
[encoder_count
], &codecs
[i
].info
, sizeof(ImageCodecInfo
));
3329 if (encoder_count
< numEncoders
) return GenericError
;
3334 GpStatus WINGDIPAPI
GdipGetEncoderParameterListSize(GpImage
*image
,
3335 GDIPCONST CLSID
* clsidEncoder
, UINT
*size
)
3339 TRACE("(%p,%s,%p)\n", image
, debugstr_guid(clsidEncoder
), size
);
3342 FIXME("not implemented\n");
3346 return NotImplemented
;
3349 /*****************************************************************************
3350 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
3352 GpStatus WINGDIPAPI
GdipCreateBitmapFromHBITMAP(HBITMAP hbm
, HPALETTE hpal
, GpBitmap
** bitmap
)
3357 BitmapData lockeddata
;
3360 TRACE("%p %p %p\n", hbm
, hpal
, bitmap
);
3363 return InvalidParameter
;
3365 /* TODO: Support for device-dependent bitmaps */
3367 FIXME("no support for device-dependent bitmaps\n");
3368 return NotImplemented
;
3371 if (GetObjectA(hbm
, sizeof(bm
), &bm
) != sizeof(bm
))
3372 return InvalidParameter
;
3374 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
3375 switch(bm
.bmBitsPixel
) {
3377 format
= PixelFormat1bppIndexed
;
3380 format
= PixelFormat4bppIndexed
;
3383 format
= PixelFormat8bppIndexed
;
3386 format
= PixelFormat24bppRGB
;
3389 format
= PixelFormat32bppRGB
;
3392 format
= PixelFormat48bppRGB
;
3395 FIXME("don't know how to handle %d bpp\n", bm
.bmBitsPixel
);
3396 return InvalidParameter
;
3399 retval
= GdipCreateBitmapFromScan0(bm
.bmWidth
, bm
.bmHeight
, 0,
3400 format
, NULL
, bitmap
);
3404 retval
= GdipBitmapLockBits(*bitmap
, NULL
, ImageLockModeWrite
,
3405 format
, &lockeddata
);
3410 for (y
=0; y
<bm
.bmHeight
; y
++)
3412 memcpy((BYTE
*)lockeddata
.Scan0
+lockeddata
.Stride
*y
,
3413 (BYTE
*)bm
.bmBits
+bm
.bmWidthBytes
*(bm
.bmHeight
-1-y
),
3422 INT src_height
, dst_stride
;
3425 hdc
= CreateCompatibleDC(NULL
);
3426 oldhbm
= SelectObject(hdc
, hbm
);
3428 pbmi
= GdipAlloc(sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
3432 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
3433 pbmi
->bmiHeader
.biBitCount
= 0;
3435 GetDIBits(hdc
, hbm
, 0, 0, NULL
, pbmi
, DIB_RGB_COLORS
);
3437 src_height
= abs(pbmi
->bmiHeader
.biHeight
);
3439 if (pbmi
->bmiHeader
.biHeight
> 0)
3441 dst_bits
= (BYTE
*)lockeddata
.Scan0
+lockeddata
.Stride
*(src_height
-1);
3442 dst_stride
= -lockeddata
.Stride
;
3446 dst_bits
= lockeddata
.Scan0
;
3447 dst_stride
= lockeddata
.Stride
;
3450 for (y
=0; y
<src_height
; y
++)
3452 GetDIBits(hdc
, hbm
, y
, 1, dst_bits
+dst_stride
*y
,
3453 pbmi
, DIB_RGB_COLORS
);
3459 retval
= OutOfMemory
;
3461 SelectObject(hdc
, oldhbm
);
3465 GdipBitmapUnlockBits(*bitmap
, &lockeddata
);
3472 GpStatus WINGDIPAPI
GdipDeleteEffect(CGpEffect
*effect
)
3474 FIXME("(%p): stub\n", effect
);
3475 /* note: According to Jose Roca's GDI+ Docs, this is not implemented
3476 * in Windows's gdiplus */
3477 return NotImplemented
;
3480 /*****************************************************************************
3481 * GdipSetEffectParameters [GDIPLUS.@]
3483 GpStatus WINGDIPAPI
GdipSetEffectParameters(CGpEffect
*effect
,
3484 const VOID
*params
, const UINT size
)
3488 TRACE("(%p,%p,%u)\n", effect
, params
, size
);
3491 FIXME("not implemented\n");
3493 return NotImplemented
;
3496 /*****************************************************************************
3497 * GdipGetImageFlags [GDIPLUS.@]
3499 GpStatus WINGDIPAPI
GdipGetImageFlags(GpImage
*image
, UINT
*flags
)
3501 TRACE("%p %p\n", image
, flags
);
3503 if(!image
|| !flags
)
3504 return InvalidParameter
;
3506 *flags
= image
->flags
;
3511 GpStatus WINGDIPAPI
GdipTestControl(GpTestControlEnum control
, void *param
)
3513 TRACE("(%d, %p)\n", control
, param
);
3516 case TestControlForceBilinear
:
3518 FIXME("TestControlForceBilinear not handled\n");
3520 case TestControlNoICM
:
3522 FIXME("TestControlNoICM not handled\n");
3524 case TestControlGetBuildNumber
:
3525 *((DWORD
*)param
) = 3102;
3532 GpStatus WINGDIPAPI
GdipRecordMetafileFileName(GDIPCONST WCHAR
* fileName
,
3533 HDC hdc
, EmfType type
, GDIPCONST GpRectF
*pFrameRect
,
3534 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
,
3535 GpMetafile
**metafile
)
3537 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName
), hdc
, type
, pFrameRect
,
3538 frameUnit
, debugstr_w(desc
), metafile
);
3540 return NotImplemented
;
3543 GpStatus WINGDIPAPI
GdipRecordMetafileFileNameI(GDIPCONST WCHAR
* fileName
, HDC hdc
, EmfType type
,
3544 GDIPCONST GpRect
*pFrameRect
, MetafileFrameUnit frameUnit
,
3545 GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
3547 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName
), hdc
, type
, pFrameRect
,
3548 frameUnit
, debugstr_w(desc
), metafile
);
3550 return NotImplemented
;
3553 GpStatus WINGDIPAPI
GdipImageForceValidation(GpImage
*image
)
3555 TRACE("%p\n", image
);
3560 /*****************************************************************************
3561 * GdipGetImageThumbnail [GDIPLUS.@]
3563 GpStatus WINGDIPAPI
GdipGetImageThumbnail(GpImage
*image
, UINT width
, UINT height
,
3564 GpImage
**ret_image
, GetThumbnailImageAbort cb
,
3568 GpGraphics
*graphics
;
3569 UINT srcwidth
, srcheight
;
3571 TRACE("(%p %u %u %p %p %p)\n",
3572 image
, width
, height
, ret_image
, cb
, cb_data
);
3574 if (!image
|| !ret_image
)
3575 return InvalidParameter
;
3577 if (!width
) width
= 120;
3578 if (!height
) height
= 120;
3580 GdipGetImageWidth(image
, &srcwidth
);
3581 GdipGetImageHeight(image
, &srcheight
);
3583 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, PixelFormat32bppARGB
,
3584 NULL
, (GpBitmap
**)ret_image
);
3588 stat
= GdipGetImageGraphicsContext(*ret_image
, &graphics
);
3592 stat
= GdipDrawImageRectRectI(graphics
, image
,
3593 0, 0, width
, height
, 0, 0, srcwidth
, srcheight
, UnitPixel
,
3596 GdipDeleteGraphics(graphics
);
3601 GdipDisposeImage(*ret_image
);
3609 /*****************************************************************************
3610 * GdipImageRotateFlip [GDIPLUS.@]
3612 GpStatus WINGDIPAPI
GdipImageRotateFlip(GpImage
*image
, RotateFlipType type
)
3614 GpBitmap
*new_bitmap
;
3616 int bpp
, bytesperpixel
;
3617 int rotate_90
, flip_x
, flip_y
;
3618 int src_x_offset
, src_y_offset
;
3620 UINT x
, y
, width
, height
;
3621 BitmapData src_lock
, dst_lock
;
3624 TRACE("(%p, %u)\n", image
, type
);
3627 flip_x
= (type
&6) == 2 || (type
&6) == 4;
3628 flip_y
= (type
&3) == 1 || (type
&3) == 2;
3630 if (image
->type
!= ImageTypeBitmap
)
3632 FIXME("Not implemented for type %i\n", image
->type
);
3633 return NotImplemented
;
3636 bitmap
= (GpBitmap
*)image
;
3637 bpp
= PIXELFORMATBPP(bitmap
->format
);
3641 FIXME("Not implemented for %i bit images\n", bpp
);
3642 return NotImplemented
;
3647 width
= bitmap
->height
;
3648 height
= bitmap
->width
;
3652 width
= bitmap
->width
;
3653 height
= bitmap
->height
;
3656 bytesperpixel
= bpp
/8;
3658 stat
= GdipCreateBitmapFromScan0(width
, height
, 0, bitmap
->format
, NULL
, &new_bitmap
);
3663 stat
= GdipBitmapLockBits(bitmap
, NULL
, ImageLockModeRead
, bitmap
->format
, &src_lock
);
3667 stat
= GdipBitmapLockBits(new_bitmap
, NULL
, ImageLockModeWrite
, bitmap
->format
, &dst_lock
);
3671 LPBYTE src_row
, src_pixel
;
3672 LPBYTE dst_row
, dst_pixel
;
3674 src_origin
= src_lock
.Scan0
;
3675 if (flip_x
) src_origin
+= bytesperpixel
* (bitmap
->width
- 1);
3676 if (flip_y
) src_origin
+= src_lock
.Stride
* (bitmap
->height
- 1);
3680 if (flip_y
) src_x_offset
= -src_lock
.Stride
;
3681 else src_x_offset
= src_lock
.Stride
;
3682 if (flip_x
) src_y_offset
= -bytesperpixel
;
3683 else src_y_offset
= bytesperpixel
;
3687 if (flip_x
) src_x_offset
= -bytesperpixel
;
3688 else src_x_offset
= bytesperpixel
;
3689 if (flip_y
) src_y_offset
= -src_lock
.Stride
;
3690 else src_y_offset
= src_lock
.Stride
;
3693 src_row
= src_origin
;
3694 dst_row
= dst_lock
.Scan0
;
3695 for (y
=0; y
<height
; y
++)
3697 src_pixel
= src_row
;
3698 dst_pixel
= dst_row
;
3699 for (x
=0; x
<width
; x
++)
3701 /* FIXME: This could probably be faster without memcpy. */
3702 memcpy(dst_pixel
, src_pixel
, bytesperpixel
);
3703 dst_pixel
+= bytesperpixel
;
3704 src_pixel
+= src_x_offset
;
3706 src_row
+= src_y_offset
;
3707 dst_row
+= dst_lock
.Stride
;
3710 GdipBitmapUnlockBits(new_bitmap
, &dst_lock
);
3713 GdipBitmapUnlockBits(bitmap
, &src_lock
);
3717 move_bitmap(bitmap
, new_bitmap
, FALSE
);
3719 GdipDisposeImage((GpImage
*)new_bitmap
);