Signed-off-by: Nikolay Sivov nsivov@codeweavers.com ---
No changes in 1/2.
dlls/windowscodecs/jpegformat.c | 31 ++++++++++--------------------- dlls/windowscodecs/pngformat.c | 13 +++++-------- dlls/windowscodecs/propertybag.c | 4 ++-- dlls/windowscodecs/tiffformat.c | 20 +++++++------------- dlls/windowscodecs/wincodecs_private.h | 2 +- 5 files changed, 25 insertions(+), 45 deletions(-)
diff --git a/dlls/windowscodecs/jpegformat.c b/dlls/windowscodecs/jpegformat.c index ef050ba688..6617ec7b8e 100644 --- a/dlls/windowscodecs/jpegformat.c +++ b/dlls/windowscodecs/jpegformat.c @@ -1440,7 +1440,15 @@ static HRESULT WINAPI JpegEncoder_CreateNewFrame(IWICBitmapEncoder *iface, { JpegEncoder *This = impl_from_IWICBitmapEncoder(iface); HRESULT hr; - PROPBAG2 opts[6] = {{0}}; + static const PROPBAG2 opts[6] = + { + { PROPBAG2_TYPE_DATA, VT_R4, 0, 0, (LPOLESTR)wszImageQuality }, + { PROPBAG2_TYPE_DATA, VT_UI1, 0, 0, (LPOLESTR)wszBitmapTransform }, + { PROPBAG2_TYPE_DATA, VT_I4 | VT_ARRAY, 0, 0, (LPOLESTR)wszLuminance }, + { PROPBAG2_TYPE_DATA, VT_I4 | VT_ARRAY, 0, 0, (LPOLESTR)wszChrominance }, + { PROPBAG2_TYPE_DATA, VT_UI1, 0, 0, (LPOLESTR)wszJpegYCrCbSubsampling }, + { PROPBAG2_TYPE_DATA, VT_BOOL, 0, 0, (LPOLESTR)wszSuppressApp0 }, + };
TRACE("(%p,%p,%p)\n", iface, ppIFrameEncode, ppIEncoderOptions);
@@ -1458,26 +1466,7 @@ static HRESULT WINAPI JpegEncoder_CreateNewFrame(IWICBitmapEncoder *iface, return WINCODEC_ERR_NOTINITIALIZED; }
- opts[0].pstrName = (LPOLESTR)wszImageQuality; - opts[0].vt = VT_R4; - opts[0].dwType = PROPBAG2_TYPE_DATA; - opts[1].pstrName = (LPOLESTR)wszBitmapTransform; - opts[1].vt = VT_UI1; - opts[1].dwType = PROPBAG2_TYPE_DATA; - opts[2].pstrName = (LPOLESTR)wszLuminance; - opts[2].vt = VT_I4|VT_ARRAY; - opts[2].dwType = PROPBAG2_TYPE_DATA; - opts[3].pstrName = (LPOLESTR)wszChrominance; - opts[3].vt = VT_I4|VT_ARRAY; - opts[3].dwType = PROPBAG2_TYPE_DATA; - opts[4].pstrName = (LPOLESTR)wszJpegYCrCbSubsampling; - opts[4].vt = VT_UI1; - opts[4].dwType = PROPBAG2_TYPE_DATA; - opts[5].pstrName = (LPOLESTR)wszSuppressApp0; - opts[5].vt = VT_BOOL; - opts[5].dwType = PROPBAG2_TYPE_DATA; - - hr = CreatePropertyBag2(opts, 6, ppIEncoderOptions); + hr = CreatePropertyBag2(opts, sizeof(opts)/sizeof(opts[0]), ppIEncoderOptions); if (FAILED(hr)) { LeaveCriticalSection(&This->lock); diff --git a/dlls/windowscodecs/pngformat.c b/dlls/windowscodecs/pngformat.c index 1ab2c8573b..117761c335 100644 --- a/dlls/windowscodecs/pngformat.c +++ b/dlls/windowscodecs/pngformat.c @@ -2033,7 +2033,11 @@ static HRESULT WINAPI PngEncoder_CreateNewFrame(IWICBitmapEncoder *iface, { PngEncoder *This = impl_from_IWICBitmapEncoder(iface); HRESULT hr; - PROPBAG2 opts[2]= {{0}}; + static const PROPBAG2 opts[2] = + { + { PROPBAG2_TYPE_DATA, VT_BOOL, 0, 0, (LPOLESTR)wszPngInterlaceOption }, + { PROPBAG2_TYPE_DATA, VT_UI1, 0, 0, (LPOLESTR)wszPngFilterOption }, + };
TRACE("(%p,%p,%p)\n", iface, ppIFrameEncode, ppIEncoderOptions);
@@ -2051,13 +2055,6 @@ static HRESULT WINAPI PngEncoder_CreateNewFrame(IWICBitmapEncoder *iface, return WINCODEC_ERR_NOTINITIALIZED; }
- opts[0].pstrName = (LPOLESTR)wszPngInterlaceOption; - opts[0].vt = VT_BOOL; - opts[0].dwType = PROPBAG2_TYPE_DATA; - opts[1].pstrName = (LPOLESTR)wszPngFilterOption; - opts[1].vt = VT_UI1; - opts[1].dwType = PROPBAG2_TYPE_DATA; - hr = CreatePropertyBag2(opts, sizeof(opts)/sizeof(opts[0]), ppIEncoderOptions); if (FAILED(hr)) { diff --git a/dlls/windowscodecs/propertybag.c b/dlls/windowscodecs/propertybag.c index 2f3015ca6d..e9d1af9670 100644 --- a/dlls/windowscodecs/propertybag.c +++ b/dlls/windowscodecs/propertybag.c @@ -213,7 +213,7 @@ static HRESULT WINAPI PropertyBag_CountProperties(IPropertyBag2 *iface, ULONG *p return S_OK; }
-static HRESULT copy_propbag2(PROPBAG2 *dest, PROPBAG2 *src) +static HRESULT copy_propbag2(PROPBAG2 *dest, const PROPBAG2 *src) { dest->cfType = src->cfType; dest->clsid = src->clsid; @@ -278,7 +278,7 @@ static const IPropertyBag2Vtbl PropertyBag_Vtbl = { PropertyBag_LoadObject };
-HRESULT CreatePropertyBag2(PROPBAG2 *options, UINT count, +HRESULT CreatePropertyBag2(const PROPBAG2 *options, UINT count, IPropertyBag2 **ppPropertyBag2) { UINT i; diff --git a/dlls/windowscodecs/tiffformat.c b/dlls/windowscodecs/tiffformat.c index a0eec53f5f..f165e18934 100644 --- a/dlls/windowscodecs/tiffformat.c +++ b/dlls/windowscodecs/tiffformat.c @@ -1936,7 +1936,11 @@ static HRESULT WINAPI TiffEncoder_CreateNewFrame(IWICBitmapEncoder *iface, { TiffEncoder *This = impl_from_IWICBitmapEncoder(iface); TiffFrameEncode *result; - + static const PROPBAG2 opts[2] = + { + { PROPBAG2_TYPE_DATA, VT_UI1, 0, 0, (LPOLESTR)wszTiffCompressionMethod }, + { PROPBAG2_TYPE_DATA, VT_R4, 0, 0, (LPOLESTR)wszCompressionQuality }, + }; HRESULT hr=S_OK;
TRACE("(%p,%p,%p)\n", iface, ppIFrameEncode, ppIEncoderOptions); @@ -1955,24 +1959,14 @@ static HRESULT WINAPI TiffEncoder_CreateNewFrame(IWICBitmapEncoder *iface,
if (SUCCEEDED(hr)) { - PROPBAG2 opts[2]= {{0}}; - opts[0].pstrName = (LPOLESTR)wszTiffCompressionMethod; - opts[0].vt = VT_UI1; - opts[0].dwType = PROPBAG2_TYPE_DATA; - - opts[1].pstrName = (LPOLESTR)wszCompressionQuality; - opts[1].vt = VT_R4; - opts[1].dwType = PROPBAG2_TYPE_DATA; - - hr = CreatePropertyBag2(opts, 2, ppIEncoderOptions); - + hr = CreatePropertyBag2(opts, sizeof(opts)/sizeof(opts[0]), ppIEncoderOptions); if (SUCCEEDED(hr)) { VARIANT v; VariantInit(&v); V_VT(&v) = VT_UI1; V_UNION(&v, bVal) = WICTiffCompressionDontCare; - hr = IPropertyBag2_Write(*ppIEncoderOptions, 1, opts, &v); + hr = IPropertyBag2_Write(*ppIEncoderOptions, 1, (PROPBAG2 *)opts, &v); VariantClear(&v); if (FAILED(hr)) { diff --git a/dlls/windowscodecs/wincodecs_private.h b/dlls/windowscodecs/wincodecs_private.h index 2249c13843..8bba811250 100644 --- a/dlls/windowscodecs/wincodecs_private.h +++ b/dlls/windowscodecs/wincodecs_private.h @@ -120,7 +120,7 @@ extern void reverse_bgr8(UINT bytesperpixel, LPBYTE bits, UINT width, UINT heigh
extern HRESULT get_pixelformat_bpp(const GUID *pixelformat, UINT *bpp) DECLSPEC_HIDDEN;
-extern HRESULT CreatePropertyBag2(PROPBAG2 *options, UINT count, +extern HRESULT CreatePropertyBag2(const PROPBAG2 *options, UINT count, IPropertyBag2 **property) DECLSPEC_HIDDEN;
extern HRESULT CreateComponentInfo(REFCLSID clsid, IWICComponentInfo **ppIInfo) DECLSPEC_HIDDEN;
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))
Signed-off-by: Vincent Povirk vincent@codeweavers.com