23#define NONAMELESSUNION
45#define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
46#define WMF_PLACEABLE_KEY 0x9ac6cdd7
84 hr = IWICImagingFactory_CreatePalette(
factory, &wic_palette);
89 hr = IWICBitmapFrameDecode_CopyPalette(frame, wic_palette);
101 IWICPalette_GetColorCount(wic_palette, &
count);
105 IWICPalette_GetType(wic_palette, &
type);
124 IWICPalette_HasAlpha(wic_palette, &
alpha);
128 IWICPalette_Release(wic_palette);
130 IWICImagingFactory_Release(
factory);
137 FIXME(
"(%p %p %p %d %p %p): stub\n",
bitmap, effect, roi, useAuxData, auxData, auxDataSize);
149 FIXME(
"(%p %d %p %p %p %p %d %p %p): stub\n", inputBitmaps, numInputs, effect, roi, outputRect, outputBitmap, useAuxData, auxData, auxDataSize);
186 *
r = (pixel>>7&0xf8)|(pixel>>12&0x7);
187 *
g = (pixel>>2&0xf8)|(pixel>>6&0x7);
188 *
b = (pixel<<3&0xf8)|(pixel>>2&0x7);
196 *
r = (pixel>>8&0xf8)|(pixel>>13&0x7);
197 *
g = (pixel>>3&0xfc)|(pixel>>9&0x3);
198 *
b = (pixel<<3&0xf8)|(pixel>>2&0x7);
206 *
r = (pixel>>7&0xf8)|(pixel>>12&0x7);
207 *
g = (pixel>>2&0xf8)|(pixel>>6&0x7);
208 *
b = (pixel<<3&0xf8)|(pixel>>2&0x7);
209 if ((pixel&0x8000) == 0x8000)
250 *
r =
row[
x*4+2] * 255 / *
a;
251 *
g =
row[
x*4+1] * 255 / *
a;
282 *
r =
row[
x*8+5] * 255 / *
a;
283 *
g =
row[
x*8+3] * 255 / *
a;
284 *
b =
row[
x*8+1] * 255 / *
a;
346 FIXME(
"not implemented for format 0x%x\n",
bitmap->format);
361 int best_distance = 0x7fff;
480 *((
UINT64*)(
row)+
x) = (a64<<56)|(a64<<48)|(r64<<40)|(r64<<32)|(g64<<24)|(g64<<16)|(
b64<<8)|
b64;
555 FIXME(
"not implemented for format 0x%x\n",
bitmap->format);
574 memcpy(dst_bits+dst_stride*
y, src_bits+src_stride*
y, widthbytes);
578#define convert_indexed_to_rgb(getpixel_function, setpixel_function) do { \
579 for (y=0; y<height; y++) \
580 for (x=0; x<width; x++) { \
583 BYTE *color = (BYTE *)&argb; \
584 getpixel_function(&index, src_bits+src_stride*y, x); \
585 argb = (palette && index < palette->Count) ? palette->Entries[index] : 0; \
586 setpixel_function(color[2], color[1], color[0], color[3], dst_bits+dst_stride*y, x); \
591#define convert_rgb_to_rgb(getpixel_function, setpixel_function) do { \
592 for (y=0; y<height; y++) \
593 for (x=0; x<width; x++) { \
595 getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
596 setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x); \
601#define convert_rgb_to_indexed(getpixel_function, setpixel_function) do { \
602 for (y=0; y<height; y++) \
603 for (x=0; x<width; x++) { \
605 getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
606 setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x, palette); \
1018#undef convert_indexed_to_rgb
1019#undef convert_rgb_to_rgb
1040 if(!lockeddata || !
bitmap)
1056 act_rect.
X = act_rect.
Y = 0;
1063 WARN(
"bitmap is already locked and cannot be locked again\n");
1076 lockeddata->
Scan0 =
bitmap->bits + (bitspp / 8) * act_rect.
X +
1117 lockeddata->
Stride = (((act_rect.
Width * bitspp + 7) / 8) + 3) & ~3;
1136 FIXME(
"Cannot copy rows that don't start at a whole byte.\n");
1167 if (!
bitmap || xdpi == 0.0 || ydpi == 0.0)
1170 bitmap->image.xres = xdpi;
1171 bitmap->image.yres = ydpi;
1185 if(!
bitmap || !lockeddata)
1214 FIXME(
"Cannot copy rows that don't start at a whole byte.\n");
1226 ERR(
"failed to convert pixels; this should never happen\n");
1243 TRACE(
"(%f,%f,%f,%f,0x%x,%p,%p)\n",
x,
y,
width,
height,
format, srcBitmap, dstBitmap);
1249 TRACE(
"<-- InvalidParameter\n");
1275 dst_palette = heap_alloc_zero(
sizeof(
UINT) * 2 +
sizeof(
ARGB) * src_palette->
Count);
1284 (*dstBitmap)->image.palette = dst_palette;
1303 TRACE(
"(%i,%i,%i,%i,0x%x,%p,%p)\n",
x,
y,
width,
height,
format, srcBitmap, dstBitmap);
1312 if (!
image || !cloneImage)
1335 result->image.frame_count = 1;
1350 *cloneImage = &
result->image;
1355 WARN(
"GpImage with no image data (metafile in wrong state?)\n");
1397 stride = ((
info->bmiHeader.biWidth *
info->bmiHeader.biBitCount + 31) >> 3) & ~3;
1399 if(
info->bmiHeader.biHeight > 0)
1405 switch(
info->bmiHeader.biBitCount) {
1425 FIXME(
"don't know how to handle %d bpp\n",
info->bmiHeader.biBitCount);
1452 if(!lpBitmapName || !
bitmap)
1473 return ((
b + ((
BYTE)bkgnd * (255 -
alpha) + 127) / 255) |
1474 (
g + ((
BYTE)(bkgnd >> 8) * (255 -
alpha) + 127) / 255) << 8 |
1475 (
r + ((
BYTE)(bkgnd >> 16) * (255 -
alpha) + 127) / 255) << 16 |
1489 TRACE(
"(%p,%p,%x)\n",
bitmap, hbmReturn, background);
1497 bih.
biSize =
sizeof(bih);
1526 if (background & 0xffffff)
1532 if ((*
ptr & 0xff000000) == 0xff000000)
continue;
1618 bih.
biSize =
sizeof(bih);
1635 if (bm.bmBitsPixel == 32)
1643 if ((*
src++ & 0xff000000) != 0)
1646 else has_alpha =
FALSE;
1667 dst_row = lockeddata.
Scan0;
1677 *
dst++ |= 0xff000000;
1679 dst_row += lockeddata.
Stride;
1687 dst_row = lockeddata.
Scan0;
1692 *
dst++ |= 0xff000000;
1693 dst_row += lockeddata.
Stride;
1710 static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
1715 entries[
i] = 0xff000000;
1716 if (
i&1) entries[
i] |= 0x800000;
1717 if (
i&2) entries[
i] |= 0x8000;
1718 if (
i&4) entries[
i] |= 0x80;
1722 entries[
i] = 0xffc0c0c0;
1726 entries[
i] = 0xff000000;
1727 if (
i&1) entries[
i] |= 0xff0000;
1728 if (
i&2) entries[
i] |= 0xff00;
1729 if (
i&4) entries[
i] |= 0xff;
1739 entries[
i] = 0xff000000;
1740 entries[
i] |= halftone_values[(
i-40)%6];
1741 entries[
i] |= halftone_values[((
i-40)/6)%6] << 8;
1742 entries[
i] |= halftone_values[((
i-40)/36)%6] << 16;
1764 INT row_size, dib_stride;
1785 dib_stride = (row_size + 3) & ~3;
1823 own_bits =
bits = heap_alloc_zero(
size);
1840 memcpy(&(*bitmap)->image.format, &ImageFormatMemoryBMP,
sizeof(
GUID));
1842 (*bitmap)->image.frame_count = 1;
1843 (*bitmap)->image.current_frame = 0;
1844 (*bitmap)->image.palette =
NULL;
1845 (*bitmap)->image.xres = xres;
1846 (*bitmap)->image.yres = yres;
1847 (*bitmap)->width =
width;
1848 (*bitmap)->height =
height;
1849 (*bitmap)->format =
format;
1850 (*bitmap)->image.decoder =
NULL;
1852 (*bitmap)->hdc =
NULL;
1853 (*bitmap)->bits =
bits;
1854 (*bitmap)->stride =
stride;
1855 (*bitmap)->own_bits = own_bits;
1856 (*bitmap)->metadata_reader =
NULL;
1857 (*bitmap)->prop_count = 0;
1858 (*bitmap)->prop_item =
NULL;
1870 if (!(*bitmap)->image.palette)
1882 (*bitmap)->image.palette->Entries[0] = 0xff000000;
1883 (*bitmap)->image.palette->Entries[1] = 0xffffffff;
1891 (*bitmap)->image.palette->Count);
1901static HBITMAP hbitmap_from_emf(HENHMETAFILE hemf)
1985 if(!
bitmap || !graphics || !cachedbmp)
2005 ULONG andstride, xorstride, bitssize;
2006 LPBYTE andbits, xorbits, androw, xorrow, srcrow;
2018 andstride = ((lockeddata.
Width+31)/32)*4;
2019 xorstride = lockeddata.
Width*4;
2020 bitssize = (andstride + xorstride) * lockeddata.
Height;
2022 andbits = heap_alloc_zero(bitssize);
2026 xorbits = andbits + andstride * lockeddata.
Height;
2032 androw = andbits + andstride *
y;
2034 if (srcrow[3+4*
x] >= 128)
2035 androw[
x/8] |= 1 << (7-
x%8);
2037 xorrow = xorbits + xorstride *
y;
2038 memcpy(xorrow, srcrow, xorstride);
2057 TRACE(
"%p\n", cachedbmp);
2071 TRACE(
"%p %p %d %d\n", graphics, cachedbmp,
x,
y);
2073 if(!graphics || !cachedbmp)
2091 if (clobber_palette)
2094 dst->image.palette =
src->image.palette;
2099 dst->image.xres =
src->image.xres;
2100 dst->image.yres =
src->image.yres;
2102 dst->height =
src->height;
2103 dst->format =
src->format;
2104 dst->hbitmap =
src->hbitmap;
2107 dst->stride =
src->stride;
2108 dst->own_bits =
src->own_bits;
2109 if (
dst->metadata_reader)
2110 IWICMetadataReader_Release(
dst->metadata_reader);
2111 dst->metadata_reader =
src->metadata_reader;
2113 dst->prop_item =
src->prop_item;
2114 dst->prop_count =
src->prop_count;
2115 if (
dst->image.decoder)
2116 IWICBitmapDecoder_Release(
dst->image.decoder);
2117 dst->image.decoder =
src->image.decoder;
2118 dst->image.frame_count =
src->image.frame_count;
2119 dst->image.current_frame =
src->image.current_frame;
2120 dst->image.format =
src->image.format;
2122 src->image.type = ~0;
2138 IWICMetadataReader_Release(((
GpBitmap*)
image)->metadata_reader);
2149 IWICBitmapDecoder_Release(
image->decoder);
2179 FIXME(
"not implemented\n");
2191 FIXME(
"not implemented\n");
2199 TRACE(
"%p %p %p\n",
image, srcRect, srcUnit);
2201 if(!
image || !srcRect || !srcUnit)
2208 srcRect->
X = srcRect->
Y = 0.0;
2214 WARN(
"GpImage with no image data\n");
2218 TRACE(
"returning (%f, %f) (%f, %f) unit type %d\n", srcRect->
X, srcRect->
Y,
2241 WARN(
"GpImage with no image data\n");
2257 if(!
image || !graphics)
2274 (*graphics)->image =
image;
2275 (*graphics)->xres =
image->xres;
2276 (*graphics)->yres =
image->yres;
2300 WARN(
"GpImage with no image data\n");
2328 if (!
image->palette ||
image->palette->Count == 0)
2403 WARN(
"GpImage with no image data\n");
2440 UINT prop_count,
i, items_returned;
2448 FIXME(
"Not implemented for type %d\n",
image->type);
2456 for (
i = 0;
i <
num;
i++)
2471 hr = IWICMetadataReader_GetCount(
reader, &prop_count);
2476 hr = IWICMetadataReader_GetEnumerator(
reader, &enumerator);
2479 IWICEnumMetadataItem_Reset(enumerator);
2481 for (
i = 0;
i <
num;
i++)
2485 hr = IWICEnumMetadataItem_Next(enumerator, 1,
NULL, &
id,
NULL, &items_returned);
2490 FIXME(
"not supported propvariant type for id: %u\n",
id.
vt);
2494 list[
i] =
id.u.uiVal;
2497 IWICEnumMetadataItem_Release(enumerator);
2511 return value->u.caub.cElems;
2515 return value->u.caui.cElems * 2;
2520 return value->u.caul.cElems * 4;
2525 return value->u.cauh.cElems * 8;
2529 return value->u.blob.cbSize;
2531 FIXME(
"not supported variant type %d\n",
value->vt);
2548 FIXME(
"Not implemented for type %d\n",
image->type);
2572 id.u.uiVal = propid;
2583#ifndef PropertyTagTypeSByte
2584#define PropertyTagTypeSByte 6
2585#define PropertyTagTypeSShort 8
2586#define PropertyTagTypeFloat 11
2587#define PropertyTagTypeDouble 12
2613 if (vt2type[
i].
vt ==
vt)
return vt2type[
i].type;
2615 FIXME(
"not supported variant type %u\n",
vt);
2622 UINT item_size, item_type;
2671 FIXME(
"not supported variant type %d\n",
value->vt);
2675 item->length = item_size;
2676 item->type = item_type;
2696 FIXME(
"Not implemented for type %d\n",
image->type);
2725 id.u.uiVal = propid;
2740 UINT prop_count, prop_size,
i;
2749 FIXME(
"Not implemented for type %d\n",
image->type);
2769 hr = IWICMetadataReader_GetCount(
reader, &prop_count);
2772 hr = IWICMetadataReader_GetEnumerator(
reader, &enumerator);
2775 IWICEnumMetadataItem_Reset(enumerator);
2779 PropVariantInit(&
id);
2780 PropVariantInit(&
value);
2782 for (
i = 0;
i < prop_count;
i++)
2784 UINT items_returned, item_size;
2786 hr = IWICEnumMetadataItem_Next(enumerator, 1,
NULL, &
id, &
value, &items_returned);
2790 if (item_size) prop_size +=
sizeof(
PropertyItem) + item_size;
2796 IWICEnumMetadataItem_Release(enumerator);
2800 *
count = prop_count;
2812 UINT prop_count, prop_size,
i;
2822 FIXME(
"Not implemented for type %d\n",
image->type);
2835 item_value = (
char *)(
buf + prop_count);
2837 for (
i = 0;
i < prop_count;
i++)
2839 buf[
i].value = item_value;
2840 item_value +=
buf[
i].length;
2849 hr = IWICMetadataReader_GetEnumerator(
reader, &enumerator);
2852 IWICEnumMetadataItem_Reset(enumerator);
2854 item_value = (
char *)(
buf + prop_count);
2856 PropVariantInit(&
id);
2857 PropVariantInit(&
value);
2859 for (
i = 0;
i < prop_count;
i++)
2862 UINT items_returned, item_size;
2864 hr = IWICEnumMetadataItem_Next(enumerator, 1,
NULL, &
id, &
value, &items_returned);
2869 FIXME(
"not supported propvariant type for id: %u\n",
id.
vt);
2881 buf[
i].length = item_size;
2882 buf[
i].value = item_value;
2884 item_value += item_size;
2893 IWICEnumMetadataItem_Release(enumerator);
2908 {&ImageFormatGIF, &FrameDimensionTime},
2909 {&ImageFormatIcon, &FrameDimensionResolution},
2969 result = &FrameDimensionPage;
3011 UINT prop_size, prop_count;
3016 prop_size = prop_count = 0;
3018 if (!prop_item)
return;
3027 prop_item = heap_alloc_zero(prop_size +
item->length +
sizeof(
PropertyItem));
3028 if (!prop_item)
return;
3031 memcpy(prop_item + prop_count + 1,
bitmap->prop_item + prop_count, prop_size);
3033 item_value = (
char *)(prop_item + prop_count + 1);
3035 for (
i = 0;
i < prop_count;
i++)
3037 prop_item[
i].
value = item_value;
3038 item_value += prop_item[
i].
length;
3042 prop_item[prop_count].
id =
item->id;
3043 prop_item[prop_count].
type =
item->type;
3045 prop_item[prop_count].
value = (
char *)(prop_item + prop_count + 1) + prop_size;
3049 bitmap->prop_item = prop_item;
3063 PropVariantInit(&
id);
3064 PropVariantInit(&
value);
3068 if (!
id.
u.pwszVal)
return FALSE;
3090 PropVariantInit(&
id);
3091 PropVariantInit(&
value);
3095 if (!
id.
u.pwszVal)
return NULL;
3103 item_size +=
sizeof(*item);
3104 item = heap_alloc_zero(item_size);
3121 static const WCHAR textentryW[] = {
'T',
'e',
'x',
't',
'E',
'n',
't',
'r',
'y',0 };
3133 static const WCHAR applicationW[] = {
'A',
'p',
'p',
'l',
'i',
'c',
'a',
't',
'i',
'o',
'n',0 };
3134 static const WCHAR dataW[] = {
'D',
'a',
't',
'a',0 };
3151 loop = heap_alloc_zero(
sizeof(*loop) +
sizeof(
SHORT));
3156 loop->length =
sizeof(
SHORT);
3157 loop->
value = loop + 1;
3174 static const WCHAR backgroundW[] = {
'B',
'a',
'c',
'k',
'g',
'r',
'o',
'u',
'n',
'd',
'C',
'o',
'l',
'o',
'r',
'I',
'n',
'd',
'e',
'x',0 };
3186 static const WCHAR global_flagW[] = {
'G',
'l',
'o',
'b',
'a',
'l',
'C',
'o',
'l',
'o',
'r',
'T',
'a',
'b',
'l',
'e',
'F',
'l',
'a',
'g',0 };
3202 hr = IWICBitmapDecoder_CopyPalette(decoder,
palette);
3209 IWICImagingFactory_Release(
factory);
3217 pal = heap_alloc_zero(
sizeof(*pal) +
count * 3);
3218 if (!pal)
return NULL;
3221 pal->
value = pal + 1;
3228 rgb[
i*3] = (colors[
i] >> 16) & 0xff;
3229 rgb[
i*3 + 1] = (colors[
i] >> 8) & 0xff;
3230 rgb[
i*3 + 2] = colors[
i] & 0xff;
3241 static const WCHAR transparency_flagW[] = {
'T',
'r',
'a',
'n',
's',
'p',
'a',
'r',
'e',
'n',
'c',
'y',
'F',
'l',
'a',
'g',0 };
3242 static const WCHAR colorW[] = {
'T',
'r',
'a',
'n',
's',
'p',
'a',
'r',
'e',
'n',
't',
'C',
'o',
'l',
'o',
'r',
'I',
'n',
'd',
'e',
'x',0 };
3259 UINT block_count,
i;
3263 hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICMetadataBlockReader, (
void **)&block_reader);
3266 hr = IWICMetadataBlockReader_GetCount(block_reader, &block_count);
3269 for (
i = 0;
i < block_count;
i++)
3271 hr = IWICMetadataBlockReader_GetReaderByIndex(block_reader,
i, &
reader);
3284 IWICMetadataReader_Release(
reader);
3288 IWICMetadataBlockReader_Release(block_reader);
3296 static const WCHAR delayW[] = {
'D',
'e',
'l',
'a',
'y',0 };
3301 UINT frame_count, block_count,
i;
3305 IWICBitmapDecoder_GetFrameCount(decoder, &frame_count);
3306 if (frame_count > 1)
3308 delay = heap_alloc_zero(
sizeof(*delay) + frame_count *
sizeof(
LONG));
3316 delay->
value = delay + 1;
3320 for (
i = 0;
i < frame_count;
i++)
3322 hr = IWICBitmapDecoder_GetFrame(decoder,
i, &frame);
3326 IWICBitmapFrameDecode_Release(frame);
3333 hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICMetadataBlockReader, (
void **)&block_reader);
3336 hr = IWICMetadataBlockReader_GetCount(block_reader, &block_count);
3339 for (
i = 0;
i < block_count;
i++)
3341 hr = IWICMetadataBlockReader_GetReaderByIndex(block_reader,
i, &
reader);
3347 if (frame_count > 1 && !loop)
3356 IWICMetadataReader_Release(
reader);
3360 IWICMetadataBlockReader_Release(block_reader);
3363 if (frame_count > 1 && !loop)
3365 loop = heap_alloc_zero(
sizeof(*loop) +
sizeof(
SHORT));
3370 loop->length =
sizeof(
SHORT);
3371 loop->
value = loop + 1;
3372 *(
SHORT *)loop->value = 1;
3389 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
3392 hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICMetadataBlockReader, (
void **)&block_reader);
3395 hr = IWICMetadataBlockReader_GetCount(block_reader, &block_count);
3398 for (
i = 0;
i < block_count;
i++)
3400 hr = IWICMetadataBlockReader_GetReaderByIndex(block_reader,
i, &
reader);
3403 if (!transparent_idx)
3406 IWICMetadataReader_Release(
reader);
3410 IWICMetadataBlockReader_Release(block_reader);
3416 IWICBitmapFrameDecode_Release(frame);
3426 item_size +=
sizeof(*item);
3427 item = heap_alloc_zero(item_size);
3453 ERR(
"unhandled case %u\n",
value.vt);
3468 struct keyword_info {
3483 hr = IWICBitmapDecoder_GetFrame(decoder, active_frame, &frame);
3486 hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICMetadataBlockReader, (
void **)&block_reader);
3489 hr = IWICMetadataBlockReader_GetCount(block_reader, &block_count);
3492 for (
i = 0;
i < block_count;
i++)
3494 hr = IWICMetadataBlockReader_GetReaderByIndex(block_reader,
i, &
reader);
3542 rational[0] = 100000;
3554 if (!seen_whitepoint)
3565 rational[1] = 100000;
3567 rational[3] = 100000;
3569 seen_whitepoint =
TRUE;
3584 rational[1] = 100000;