On Fri Nov 18 07:27:22 2022 +0000, Zhiyi Zhang wrote:
Are premultiplied and straight supported for all formats, and "ignore"
is unsupported for all? No. D2D1_ALPHA_MODE_STRAIGHT is supported only for GUID_WICPixelFormat8bppAlpha. And then D2D1_ALPHA_MODE_PREMULTIPLIED is supported for all supported WIC bitmap formats with an alpha channel. D2D1_ALPHA_MODE_IGNORE is supported for all supported WIC bitmap formats without an alpha channel. If DXGI_FORMAT_UNKNOWN is used. The DXGI format is derived from the WIC bitmap format. For example, the DXGI format could be DXGI_FORMAT_B8G8R8A8_UNORM or DXGI_FORMAT_B8G8R8A8_UNORM_SRGB for GUID_WICPixelFormat32bppBGR.
I see. Can we maybe do it in several steps then:
- if format is not specified, get it from WIC bitmap, convert to DXGI format value; - resolve alpha mode; - check against some list of {format,aplhamode} pairs, similar to d2d_bitmap_create_from_wic_bitmap(). Maybe even reusing the list. This step is only to check if format/alphamode is acceptable; - check that d3d device supports resulting dxgi format;
These could be in a bit different order. For first step I think it's good to use a list that DirectXTK code is using, with a clear error for unrecognized WIC formats.
What happens when format is specified? Presumably it has to closely match the one from bitmap? Or maybe it does SW conversion on every transfer, using WIC facilities.