windowscodecs: Fix the bug when the input palette hpal is NULL in ImagingFactory_CreateBitmapFromHBITMAP.
When the palette is given NULL and the format is 1/4/8bppIndexed, palette info is lost. It causes incorrect color calculation when the WIC interface is called later.
Signed-off-by: yangkun yangkun@uniontech.com Change-Id: I851373e9186dc815488235f0fc219d8fbdd91658
-- v2: windowscodecs: Fix the bug when the input palette hpal is NULL in ImagingFactory_CreateBitmapFromHBITMAP.
From: yangkun yangkun@uniontech.com
When the palette is given NULL and the format is 1/4/8bppIndexed, palette info is lost. It causes incorrect color calculation when the WIC interface is called later.
Signed-off-by: yangkun yangkun@uniontech.com Change-Id: I851373e9186dc815488235f0fc219d8fbdd91658 --- dlls/windowscodecs/imgfactory.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/dlls/windowscodecs/imgfactory.c b/dlls/windowscodecs/imgfactory.c index e2ffd6da3f4..9cb2a56c1d1 100644 --- a/dlls/windowscodecs/imgfactory.c +++ b/dlls/windowscodecs/imgfactory.c @@ -791,6 +791,21 @@ static HRESULT WINAPI ImagingFactory_CreateBitmapFromHBITMAP(IWICImagingFactory2 bmi->bmiHeader.biHeight = -bm.bmHeight; GetDIBits(hdc, hbm, 0, bm.bmHeight, buffer, bmi, DIB_RGB_COLORS);
+ if (!hpal && + (IsEqualGUID(&format, &GUID_WICPixelFormat1bppIndexed) || + IsEqualGUID(&format, &GUID_WICPixelFormat4bppIndexed) || + IsEqualGUID(&format, &GUID_WICPixelFormat8bppIndexed))) + { + num_palette_entries = bmi->bmiHeader.biClrUsed ? bmi->bmiHeader.biClrUsed : (UINT)(1 << bmi->bmiHeader.biBitCount); + for (UINT i = 0; i < num_palette_entries; i++) + { + entry[i].peRed = bmi->bmiColors[i].rgbRed; + entry[i].peGreen = bmi->bmiColors[i].rgbGreen; + entry[i].peBlue = bmi->bmiColors[i].rgbBlue; + entry[i].peFlags = 0; + } + } + DeleteDC(hdc); IWICBitmapLock_Release(lock);