Signed-off-by: Nikolay Sivov nsivov@codeweavers.com ---
v2: fixed a leak in tests
dlls/windowscodecs/bmpencode.c | 7 +++++-- dlls/windowscodecs/icnsformat.c | 9 ++++++--- dlls/windowscodecs/jpegformat.c | 11 +++++++---- dlls/windowscodecs/pngformat.c | 11 +++++++---- dlls/windowscodecs/tests/converter.c | 18 ++++++++++++++++++ dlls/windowscodecs/tiffformat.c | 2 +- 6 files changed, 44 insertions(+), 14 deletions(-)
diff --git a/dlls/windowscodecs/bmpencode.c b/dlls/windowscodecs/bmpencode.c index 48a8e27d4b..047154e6cc 100644 --- a/dlls/windowscodecs/bmpencode.c +++ b/dlls/windowscodecs/bmpencode.c @@ -508,8 +508,11 @@ static HRESULT WINAPI BmpEncoder_CreateNewFrame(IWICBitmapEncoder *iface,
if (!This->stream) return WINCODEC_ERR_NOTINITIALIZED;
- hr = CreatePropertyBag2(NULL, 0, ppIEncoderOptions); - if (FAILED(hr)) return hr; + if (ppIEncoderOptions) + { + hr = CreatePropertyBag2(NULL, 0, ppIEncoderOptions); + if (FAILED(hr)) return hr; + }
encode = HeapAlloc(GetProcessHeap(), 0, sizeof(BmpFrameEncode)); if (!encode) diff --git a/dlls/windowscodecs/icnsformat.c b/dlls/windowscodecs/icnsformat.c index 14144f7e60..aa9640417f 100644 --- a/dlls/windowscodecs/icnsformat.c +++ b/dlls/windowscodecs/icnsformat.c @@ -617,9 +617,12 @@ static HRESULT WINAPI IcnsEncoder_CreateNewFrame(IWICBitmapEncoder *iface, goto end; }
- hr = CreatePropertyBag2(NULL, 0, ppIEncoderOptions); - if (FAILED(hr)) - goto end; + if (ppIEncoderOptions) + { + hr = CreatePropertyBag2(NULL, 0, ppIEncoderOptions); + if (FAILED(hr)) + goto end; + }
frameEncode = HeapAlloc(GetProcessHeap(), 0, sizeof(IcnsFrameEncode)); if (frameEncode == NULL) diff --git a/dlls/windowscodecs/jpegformat.c b/dlls/windowscodecs/jpegformat.c index 6617ec7b8e..433a0311db 100644 --- a/dlls/windowscodecs/jpegformat.c +++ b/dlls/windowscodecs/jpegformat.c @@ -1466,11 +1466,14 @@ static HRESULT WINAPI JpegEncoder_CreateNewFrame(IWICBitmapEncoder *iface, return WINCODEC_ERR_NOTINITIALIZED; }
- hr = CreatePropertyBag2(opts, sizeof(opts)/sizeof(opts[0]), ppIEncoderOptions); - if (FAILED(hr)) + if (ppIEncoderOptions) { - LeaveCriticalSection(&This->lock); - return hr; + hr = CreatePropertyBag2(opts, sizeof(opts)/sizeof(opts[0]), ppIEncoderOptions); + if (FAILED(hr)) + { + LeaveCriticalSection(&This->lock); + return hr; + } }
This->frame_count = 1; diff --git a/dlls/windowscodecs/pngformat.c b/dlls/windowscodecs/pngformat.c index 117761c335..26b5fd52bc 100644 --- a/dlls/windowscodecs/pngformat.c +++ b/dlls/windowscodecs/pngformat.c @@ -2055,11 +2055,14 @@ static HRESULT WINAPI PngEncoder_CreateNewFrame(IWICBitmapEncoder *iface, return WINCODEC_ERR_NOTINITIALIZED; }
- hr = CreatePropertyBag2(opts, sizeof(opts)/sizeof(opts[0]), ppIEncoderOptions); - if (FAILED(hr)) + if (ppIEncoderOptions) { - LeaveCriticalSection(&This->lock); - return hr; + hr = CreatePropertyBag2(opts, sizeof(opts)/sizeof(opts[0]), ppIEncoderOptions); + if (FAILED(hr)) + { + LeaveCriticalSection(&This->lock); + return hr; + } }
This->frame_count = 1; diff --git a/dlls/windowscodecs/tests/converter.c b/dlls/windowscodecs/tests/converter.c index 704ae5d0dd..80423dc54e 100644 --- a/dlls/windowscodecs/tests/converter.c +++ b/dlls/windowscodecs/tests/converter.c @@ -803,6 +803,24 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls WICPixelFormatGUID pixelformat; int i;
+ hr = CoCreateInstance(clsid_encoder, NULL, CLSCTX_INPROC_SERVER, + &IID_IWICBitmapEncoder, (void **)&encoder); + ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr); + + hr = CreateStreamOnHGlobal(NULL, TRUE, &stream); + ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr); + + hr = IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache); + ok(SUCCEEDED(hr), "Initialize failed, hr=%x\n", hr); + + /* Encoder options are optional. */ + hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frameencode, NULL); + ok(SUCCEEDED(hr), "Failed to create encode frame, hr %#x.\n", hr); + + IStream_Release(stream); + IWICBitmapEncoder_Release(encoder); + IWICBitmapFrameEncode_Release(frameencode); + hr = CoCreateInstance(clsid_encoder, NULL, CLSCTX_INPROC_SERVER, &IID_IWICBitmapEncoder, (void**)&encoder); ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr); diff --git a/dlls/windowscodecs/tiffformat.c b/dlls/windowscodecs/tiffformat.c index f165e18934..f125b07bed 100644 --- a/dlls/windowscodecs/tiffformat.c +++ b/dlls/windowscodecs/tiffformat.c @@ -1957,7 +1957,7 @@ static HRESULT WINAPI TiffEncoder_CreateNewFrame(IWICBitmapEncoder *iface, hr = E_FAIL; }
- if (SUCCEEDED(hr)) + if (ppIEncoderOptions && SUCCEEDED(hr)) { hr = CreatePropertyBag2(opts, sizeof(opts)/sizeof(opts[0]), ppIEncoderOptions); if (SUCCEEDED(hr))