Commit ccc34703 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

d2d1: Also infer the alpha mode in d2d_d3d_render_target_CreateBitmapFromWicBitmap().

parent e9e21ab4
...@@ -300,14 +300,28 @@ static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateBitmap(ID2D1RenderT ...@@ -300,14 +300,28 @@ static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateBitmap(ID2D1RenderT
static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateBitmapFromWicBitmap(ID2D1RenderTarget *iface, static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateBitmapFromWicBitmap(ID2D1RenderTarget *iface,
IWICBitmapSource *bitmap_source, const D2D1_BITMAP_PROPERTIES *desc, ID2D1Bitmap **bitmap) IWICBitmapSource *bitmap_source, const D2D1_BITMAP_PROPERTIES *desc, ID2D1Bitmap **bitmap)
{ {
const D2D1_PIXEL_FORMAT *d2d_format;
D2D1_BITMAP_PROPERTIES bitmap_desc; D2D1_BITMAP_PROPERTIES bitmap_desc;
WICPixelFormatGUID wic_format;
unsigned int bpp, data_size; unsigned int bpp, data_size;
D2D1_SIZE_U size; D2D1_SIZE_U size;
unsigned int i;
WICRect rect; WICRect rect;
UINT32 pitch; UINT32 pitch;
HRESULT hr; HRESULT hr;
void *data; void *data;
static const struct
{
const WICPixelFormatGUID *wic;
D2D1_PIXEL_FORMAT d2d;
}
format_lookup[] =
{
{&GUID_WICPixelFormat32bppPBGRA, {DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED}},
{&GUID_WICPixelFormat32bppBGR, {DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE}},
};
TRACE("iface %p, bitmap_source %p, desc %p, bitmap %p.\n", TRACE("iface %p, bitmap_source %p, desc %p, bitmap %p.\n",
iface, bitmap_source, desc, bitmap); iface, bitmap_source, desc, bitmap);
...@@ -329,28 +343,32 @@ static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateBitmapFromWicBitmap ...@@ -329,28 +343,32 @@ static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateBitmapFromWicBitmap
bitmap_desc = *desc; bitmap_desc = *desc;
} }
if (bitmap_desc.pixelFormat.format == DXGI_FORMAT_UNKNOWN) if (FAILED(hr = IWICBitmapSource_GetPixelFormat(bitmap_source, &wic_format)))
{ {
WICPixelFormatGUID wic_format; WARN("Failed to get bitmap format, hr %#x.\n", hr);
return hr;
}
if (FAILED(hr = IWICBitmapSource_GetPixelFormat(bitmap_source, &wic_format))) for (i = 0, d2d_format = NULL; i < sizeof(format_lookup) / sizeof(*format_lookup); ++i)
{
if (IsEqualGUID(&wic_format, format_lookup[i].wic))
{ {
WARN("Failed to get bitmap format, hr %#x.\n", hr); d2d_format = &format_lookup[i].d2d;
return hr; break;
} }
}
if (IsEqualGUID(&wic_format, &GUID_WICPixelFormat32bppPBGRA) if (!d2d_format)
|| IsEqualGUID(&wic_format, &GUID_WICPixelFormat32bppBGR)) {
{ WARN("Unsupported WIC bitmap format %s.\n", debugstr_guid(&wic_format));
bitmap_desc.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM; return D2DERR_UNSUPPORTED_PIXEL_FORMAT;
}
else
{
WARN("Unsupported WIC bitmap format %s.\n", debugstr_guid(&wic_format));
return D2DERR_UNSUPPORTED_PIXEL_FORMAT;
}
} }
if (bitmap_desc.pixelFormat.format == DXGI_FORMAT_UNKNOWN)
bitmap_desc.pixelFormat.format = d2d_format->format;
if (bitmap_desc.pixelFormat.alphaMode == D2D1_ALPHA_MODE_UNKNOWN)
bitmap_desc.pixelFormat.alphaMode = d2d_format->alphaMode;
switch (bitmap_desc.pixelFormat.format) switch (bitmap_desc.pixelFormat.format)
{ {
case DXGI_FORMAT_B8G8R8A8_UNORM: case DXGI_FORMAT_B8G8R8A8_UNORM:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment