From: Nikolay Sivov Subject: [PATCH] wincodecs: Remove some of error handling duplication in InitializePredefined() Message-Id: <20161208111520.16574-1-nsivov@codeweavers.com> Date: Thu, 8 Dec 2016 14:15:20 +0300 Signed-off-by: Nikolay Sivov --- dlls/windowscodecs/palette.c | 56 +++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/dlls/windowscodecs/palette.c b/dlls/windowscodecs/palette.c index 89ec9ea..43f78ff 100644 --- a/dlls/windowscodecs/palette.c +++ b/dlls/windowscodecs/palette.c @@ -98,6 +98,36 @@ static ULONG WINAPI PaletteImpl_Release(IWICPalette *iface) return ref; } +static WICColor *generate_bw_palette(UINT *count) +{ + WICColor *entries; + + *count = 2; + entries = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(WICColor)); + if (!entries) return NULL; + + entries[0] = 0xff000000; + entries[1] = 0xffffffff; + + return entries; +} + +static WICColor *generate_gray4_palette(UINT *count) +{ + WICColor *entries; + + *count = 4; + entries = HeapAlloc(GetProcessHeap(), 0, 4 * sizeof(WICColor)); + if (!entries) return NULL; + + entries[0] = 0xff000000; + entries[1] = 0xff555555; + entries[2] = 0xffaaaaaa; + entries[3] = 0xffffffff; + + return entries; +} + static WICColor *generate_gray16_palette(UINT *count) { WICColor *entries; @@ -339,66 +369,47 @@ static HRESULT WINAPI PaletteImpl_InitializePredefined(IWICPalette *iface, switch (type) { case WICBitmapPaletteTypeFixedBW: - count = 2; - colors = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WICColor)); - if (!colors) return E_OUTOFMEMORY; - colors[0] = 0xff000000; - colors[1] = 0xffffffff; + colors = generate_bw_palette(&count); break; case WICBitmapPaletteTypeFixedGray4: - count = 4; - colors = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WICColor)); - if (!colors) return E_OUTOFMEMORY; - colors[0] = 0xff000000; - colors[1] = 0xff555555; - colors[2] = 0xffaaaaaa; - colors[3] = 0xffffffff; + colors = generate_gray4_palette(&count); break; case WICBitmapPaletteTypeFixedGray16: colors = generate_gray16_palette(&count); - if (!colors) return E_OUTOFMEMORY; break; case WICBitmapPaletteTypeFixedGray256: colors = generate_gray256_palette(&count); - if (!colors) return E_OUTOFMEMORY; break; case WICBitmapPaletteTypeFixedHalftone8: colors = generate_halftone8_palette(&count, add_transparent); - if (!colors) return E_OUTOFMEMORY; break; case WICBitmapPaletteTypeFixedHalftone27: colors = generate_halftone27_palette(&count, add_transparent); - if (!colors) return E_OUTOFMEMORY; break; case WICBitmapPaletteTypeFixedHalftone64: colors = generate_halftone64_palette(&count, add_transparent); - if (!colors) return E_OUTOFMEMORY; break; case WICBitmapPaletteTypeFixedHalftone125: colors = generate_halftone125_palette(&count, add_transparent); - if (!colors) return E_OUTOFMEMORY; break; case WICBitmapPaletteTypeFixedHalftone216: colors = generate_halftone216_palette(&count, add_transparent); - if (!colors) return E_OUTOFMEMORY; break; case WICBitmapPaletteTypeFixedHalftone252: colors = generate_halftone252_palette(&count, add_transparent); - if (!colors) return E_OUTOFMEMORY; break; case WICBitmapPaletteTypeFixedHalftone256: colors = generate_halftone256_palette(&count, add_transparent); - if (!colors) return E_OUTOFMEMORY; break; default: @@ -406,6 +417,9 @@ static HRESULT WINAPI PaletteImpl_InitializePredefined(IWICPalette *iface, return E_INVALIDARG; } + if (!colors) + return E_OUTOFMEMORY; + EnterCriticalSection(&This->lock); HeapFree(GetProcessHeap(), 0, This->colors); This->colors = colors; -- 2.10.2