From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/windowscodecs/ddsformat.c | 162 +++++++++------------------ dlls/windowscodecs/imgfactory.c | 24 +--- dlls/windowscodecs/tests/ddsformat.c | 46 +++----- include/wincodec.idl | 11 -- 4 files changed, 76 insertions(+), 167 deletions(-)
diff --git a/dlls/windowscodecs/ddsformat.c b/dlls/windowscodecs/ddsformat.c index eb8fc456266..a1ef19cd2ee 100644 --- a/dlls/windowscodecs/ddsformat.c +++ b/dlls/windowscodecs/ddsformat.c @@ -141,7 +141,6 @@ typedef struct dds_frame_info { typedef struct DdsDecoder { IWICBitmapDecoder IWICBitmapDecoder_iface; IWICDdsDecoder IWICDdsDecoder_iface; - IWICWineDecoder IWICWineDecoder_iface; LONG ref; BOOL initialized; IStream *stream; @@ -722,11 +721,6 @@ static inline DdsDecoder *impl_from_IWICDdsDecoder(IWICDdsDecoder *iface) return CONTAINING_RECORD(iface, DdsDecoder, IWICDdsDecoder_iface); }
-static inline DdsDecoder *impl_from_IWICWineDecoder(IWICWineDecoder *iface) -{ - return CONTAINING_RECORD(iface, DdsDecoder, IWICWineDecoder_iface); -} - static inline DdsFrameDecode *impl_from_IWICBitmapFrameDecode(IWICBitmapFrameDecode *iface) { return CONTAINING_RECORD(iface, DdsFrameDecode, IWICBitmapFrameDecode_iface); @@ -1071,8 +1065,6 @@ static HRESULT WINAPI DdsDecoder_QueryInterface(IWICBitmapDecoder *iface, REFIID *ppv = &This->IWICBitmapDecoder_iface; } else if (IsEqualIID(&IID_IWICDdsDecoder, iid)) { *ppv = &This->IWICDdsDecoder_iface; - } else if (IsEqualIID(&IID_IWICWineDecoder, iid)) { - *ppv = &This->IWICWineDecoder_iface; } else { *ppv = NULL; return E_NOINTERFACE; @@ -1118,28 +1110,76 @@ static HRESULT WINAPI DdsDecoder_QueryCapability(IWICBitmapDecoder *iface, IStre return E_NOTIMPL; }
-static HRESULT WINAPI DdsDecoder_Initialize(IWICBitmapDecoder *iface, IStream *pIStream, +static HRESULT WINAPI DdsDecoder_Initialize(IWICBitmapDecoder *iface, IStream *stream, WICDecodeOptions cacheOptions) { DdsDecoder *This = impl_from_IWICBitmapDecoder(iface); + DDS_HEADER_DXT10 header_dxt10; + LARGE_INTEGER seek; + DDS_HEADER header; + ULONG bytesread; + DWORD magic; HRESULT hr;
- TRACE("(%p,%p,%x)\n", iface, pIStream, cacheOptions); + TRACE("(%p,%p,%x)\n", iface, stream, cacheOptions);
EnterCriticalSection(&This->lock);
- hr = IWICWineDecoder_Initialize(&This->IWICWineDecoder_iface, pIStream, cacheOptions); + if (This->initialized) { + hr = WINCODEC_ERR_WRONGSTATE; + goto end; + } + + seek.QuadPart = 0; + hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL); if (FAILED(hr)) goto end;
+ hr = IStream_Read(stream, &magic, sizeof(magic), &bytesread); + if (FAILED(hr)) goto end; + if (bytesread != sizeof(magic)) { + hr = WINCODEC_ERR_STREAMREAD; + goto end; + } + if (magic != DDS_MAGIC) { + hr = WINCODEC_ERR_UNKNOWNIMAGEFORMAT; + goto end; + } + + hr = IStream_Read(stream, &header, sizeof(header), &bytesread); + if (FAILED(hr)) goto end; + if (bytesread != sizeof(header)) { + hr = WINCODEC_ERR_STREAMREAD; + goto end; + } + if (header.size != sizeof(header)) { + hr = WINCODEC_ERR_BADHEADER; + goto end; + } + + if (has_extended_header(&header)) { + hr = IStream_Read(stream, &header_dxt10, sizeof(header_dxt10), &bytesread); + if (FAILED(hr)) goto end; + if (bytesread != sizeof(header_dxt10)) { + hr = WINCODEC_ERR_STREAMREAD; + goto end; + } + } + + get_dds_info(&This->info, &header, &header_dxt10); + if (This->info.dimension == WICDdsTextureCube || (This->info.format != DXGI_FORMAT_BC1_UNORM && This->info.format != DXGI_FORMAT_BC2_UNORM && - This->info.format != DXGI_FORMAT_BC3_UNORM)) { - IStream_Release(pIStream); - This->stream = NULL; - This->initialized = FALSE; + This->info.format != DXGI_FORMAT_BC3_UNORM)) + { hr = WINCODEC_ERR_BADHEADER; } + else + { + This->initialized = TRUE; + This->stream = stream; + IStream_AddRef(stream); + }
end: LeaveCriticalSection(&This->lock); @@ -1432,97 +1472,6 @@ static const IWICDdsDecoderVtbl DdsDecoder_Dds_Vtbl = { DdsDecoder_Dds_GetFrame };
-static HRESULT WINAPI DdsDecoder_Wine_QueryInterface(IWICWineDecoder *iface, REFIID iid, void **ppv) -{ - DdsDecoder *This = impl_from_IWICWineDecoder(iface); - return DdsDecoder_QueryInterface(&This->IWICBitmapDecoder_iface, iid, ppv); -} - -static ULONG WINAPI DdsDecoder_Wine_AddRef(IWICWineDecoder *iface) -{ - DdsDecoder *This = impl_from_IWICWineDecoder(iface); - return DdsDecoder_AddRef(&This->IWICBitmapDecoder_iface); -} - -static ULONG WINAPI DdsDecoder_Wine_Release(IWICWineDecoder *iface) -{ - DdsDecoder *This = impl_from_IWICWineDecoder(iface); - return DdsDecoder_Release(&This->IWICBitmapDecoder_iface); -} - -static HRESULT WINAPI DdsDecoder_Wine_Initialize(IWICWineDecoder *iface, IStream *stream, WICDecodeOptions options) -{ - DdsDecoder *This = impl_from_IWICWineDecoder(iface); - DDS_HEADER_DXT10 header_dxt10; - LARGE_INTEGER seek; - DDS_HEADER header; - ULONG bytesread; - DWORD magic; - HRESULT hr; - - TRACE("(This %p, stream %p, options %#x)\n", iface, stream, options); - - EnterCriticalSection(&This->lock); - - if (This->initialized) { - hr = WINCODEC_ERR_WRONGSTATE; - goto end; - } - - seek.QuadPart = 0; - hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL); - if (FAILED(hr)) goto end; - - hr = IStream_Read(stream, &magic, sizeof(magic), &bytesread); - if (FAILED(hr)) goto end; - if (bytesread != sizeof(magic)) { - hr = WINCODEC_ERR_STREAMREAD; - goto end; - } - if (magic != DDS_MAGIC) { - hr = WINCODEC_ERR_UNKNOWNIMAGEFORMAT; - goto end; - } - - hr = IStream_Read(stream, &header, sizeof(header), &bytesread); - if (FAILED(hr)) goto end; - if (bytesread != sizeof(header)) { - hr = WINCODEC_ERR_STREAMREAD; - goto end; - } - if (header.size != sizeof(header)) { - hr = WINCODEC_ERR_BADHEADER; - goto end; - } - - if (has_extended_header(&header)) { - hr = IStream_Read(stream, &header_dxt10, sizeof(header_dxt10), &bytesread); - if (FAILED(hr)) goto end; - if (bytesread != sizeof(header_dxt10)) { - hr = WINCODEC_ERR_STREAMREAD; - goto end; - } - } - - get_dds_info(&This->info, &header, &header_dxt10); - - This->initialized = TRUE; - This->stream = stream; - IStream_AddRef(stream); - -end: - LeaveCriticalSection(&This->lock); - - return hr; -} - -static const IWICWineDecoderVtbl DdsDecoder_Wine_Vtbl = { - DdsDecoder_Wine_QueryInterface, - DdsDecoder_Wine_AddRef, - DdsDecoder_Wine_Release, - DdsDecoder_Wine_Initialize -}; - static HRESULT WINAPI DdsFrameEncode_QueryInterface(IWICBitmapFrameEncode *iface, REFIID iid, void **ppv) { DdsFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); @@ -1757,7 +1706,6 @@ HRESULT DdsDecoder_CreateInstance(REFIID iid, void** ppv)
This->IWICBitmapDecoder_iface.lpVtbl = &DdsDecoder_Vtbl; This->IWICDdsDecoder_iface.lpVtbl = &DdsDecoder_Dds_Vtbl; - This->IWICWineDecoder_iface.lpVtbl = &DdsDecoder_Wine_Vtbl; This->ref = 1; This->initialized = FALSE; This->stream = NULL; diff --git a/dlls/windowscodecs/imgfactory.c b/dlls/windowscodecs/imgfactory.c index b128a1ad13e..e2ffd6da3f4 100644 --- a/dlls/windowscodecs/imgfactory.c +++ b/dlls/windowscodecs/imgfactory.c @@ -135,7 +135,7 @@ static HRESULT find_decoder(IStream *pIStream, const GUID *pguidVendor, IEnumUnknown *enumdecoders = NULL; IUnknown *unkdecoderinfo = NULL; GUID vendor; - HRESULT res, res_wine; + HRESULT res; ULONG num_fetched; BOOL matches, found;
@@ -148,7 +148,6 @@ static HRESULT find_decoder(IStream *pIStream, const GUID *pguidVendor, while (IEnumUnknown_Next(enumdecoders, 1, &unkdecoderinfo, &num_fetched) == S_OK) { IWICBitmapDecoderInfo *decoderinfo = NULL; - IWICWineDecoder *wine_decoder = NULL;
res = IUnknown_QueryInterface(unkdecoderinfo, &IID_IWICBitmapDecoderInfo, (void**)&decoderinfo); if (FAILED(res)) goto next; @@ -171,27 +170,12 @@ static HRESULT find_decoder(IStream *pIStream, const GUID *pguidVendor, res = IWICBitmapDecoder_Initialize(*decoder, pIStream, metadataOptions); if (FAILED(res)) { - res_wine = IWICBitmapDecoder_QueryInterface(*decoder, &IID_IWICWineDecoder, (void **)&wine_decoder); - if (FAILED(res_wine)) - { - IWICBitmapDecoder_Release(*decoder); - *decoder = NULL; - goto next; - } - - res_wine = IWICWineDecoder_Initialize(wine_decoder, pIStream, metadataOptions); - if (FAILED(res_wine)) - { - IWICBitmapDecoder_Release(*decoder); - *decoder = NULL; - goto next; - } - - res = res_wine; + IWICBitmapDecoder_Release(*decoder); + *decoder = NULL; + goto next; }
next: - if (wine_decoder) IWICWineDecoder_Release(wine_decoder); if (decoderinfo) IWICBitmapDecoderInfo_Release(decoderinfo); IUnknown_Release(unkdecoderinfo); if (found) break; diff --git a/dlls/windowscodecs/tests/ddsformat.c b/dlls/windowscodecs/tests/ddsformat.c index a9965095d62..3ee66eca917 100644 --- a/dlls/windowscodecs/tests/ddsformat.c +++ b/dlls/windowscodecs/tests/ddsformat.c @@ -393,30 +393,29 @@ static struct test_data { UINT pixel_format_bpp; const GUID *expected_pixel_format; WICDdsParameters expected_parameters; - BOOL wine_init; } test_data[] = { { test_dds_alpha, sizeof(test_dds_alpha), WINCODEC_ERR_BADHEADER, 1, 1, 8, &GUID_WICPixelFormat8bppAlpha, - { 1, 1, 1, 1, 1, DXGI_FORMAT_A8_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE }, + { 1, 1, 1, 1, 1, DXGI_FORMAT_A8_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown } }, { test_dds_luminance, sizeof(test_dds_luminance), WINCODEC_ERR_BADHEADER, 1, 1, 8, &GUID_WICPixelFormat8bppGray, - { 1, 1, 1, 1, 1, DXGI_FORMAT_R8_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE }, + { 1, 1, 1, 1, 1, DXGI_FORMAT_R8_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown } }, { test_dds_rgb565, sizeof(test_dds_rgb565), WINCODEC_ERR_BADHEADER, 1, 2, 16, &GUID_WICPixelFormat16bppBGR565, - { 4, 4, 1, 1, 1, DXGI_FORMAT_B5G6R5_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE }, + { 4, 4, 1, 1, 1, DXGI_FORMAT_B5G6R5_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown } }, { test_dds_24bpp, sizeof(test_dds_24bpp), WINCODEC_ERR_BADHEADER, 1, 3, 24, &GUID_WICPixelFormat24bppBGR, - { 1, 1, 1, 1, 1, DXGI_FORMAT_UNKNOWN, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE }, + { 1, 1, 1, 1, 1, DXGI_FORMAT_UNKNOWN, WICDdsTexture2D, WICDdsAlphaModeUnknown } }, { test_dds_32bpp_xrgb, sizeof(test_dds_32bpp_xrgb), WINCODEC_ERR_BADHEADER, 1, 4, 32, &GUID_WICPixelFormat32bppBGR, - { 1, 1, 1, 1, 1, DXGI_FORMAT_B8G8R8X8_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE }, + { 1, 1, 1, 1, 1, DXGI_FORMAT_B8G8R8X8_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown } }, { test_dds_32bpp_argb, sizeof(test_dds_32bpp_argb), WINCODEC_ERR_BADHEADER, 1, 4, 32, &GUID_WICPixelFormat32bppBGRA, - { 1, 1, 1, 1, 1, DXGI_FORMAT_B8G8R8A8_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE }, + { 1, 1, 1, 1, 1, DXGI_FORMAT_B8G8R8A8_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown } }, { test_dds_64bpp, sizeof(test_dds_64bpp), WINCODEC_ERR_BADHEADER, 1, 8, 64, &GUID_WICPixelFormat64bppRGBA, - { 1, 1, 1, 1, 1, DXGI_FORMAT_R16G16B16A16_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE }, + { 1, 1, 1, 1, 1, DXGI_FORMAT_R16G16B16A16_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown } }, { test_dds_96bpp, sizeof(test_dds_96bpp), WINCODEC_ERR_BADHEADER, 1, 12, 96, &GUID_WICPixelFormat96bppRGBFloat, - { 1, 1, 1, 1, 1, DXGI_FORMAT_R32G32B32_FLOAT, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE }, + { 1, 1, 1, 1, 1, DXGI_FORMAT_R32G32B32_FLOAT, WICDdsTexture2D, WICDdsAlphaModeUnknown } }, { test_dds_128bpp, sizeof(test_dds_128bpp), WINCODEC_ERR_BADHEADER, 1, 16, 128, &GUID_WICPixelFormat128bppRGBAFloat, - { 1, 1, 1, 1, 1, DXGI_FORMAT_R32G32B32A32_FLOAT, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE }, + { 1, 1, 1, 1, 1, DXGI_FORMAT_R32G32B32A32_FLOAT, WICDdsTexture2D, WICDdsAlphaModeUnknown } }, { test_dds_cube, sizeof(test_dds_cube), WINCODEC_ERR_BADHEADER, 18, 8, 32, &GUID_WICPixelFormat32bppPBGRA, - { 4, 4, 1, 3, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTextureCube, WICDdsAlphaModePremultiplied }, TRUE }, + { 4, 4, 1, 3, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTextureCube, WICDdsAlphaModePremultiplied } }, { test_dds_cube_dx10, sizeof(test_dds_cube_dx10), WINCODEC_ERR_BADHEADER, 18, 8, 32, &GUID_WICPixelFormat32bppBGRA, - { 4, 4, 1, 3, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTextureCube, WICDdsAlphaModeUnknown }, TRUE }, + { 4, 4, 1, 3, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTextureCube, WICDdsAlphaModeUnknown } }, { test_dds_mipmaps, sizeof(test_dds_mipmaps), S_OK, 3, 8, 32, &GUID_WICPixelFormat32bppPBGRA, { 4, 4, 1, 3, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTexture2D, WICDdsAlphaModePremultiplied } }, { test_dds_volume, sizeof(test_dds_volume), S_OK, 7, 8, 32, &GUID_WICPixelFormat32bppPBGRA, @@ -525,24 +524,13 @@ static IWICBitmapEncoder *create_encoder(void) return encoder; }
-static HRESULT init_decoder(IWICBitmapDecoder *decoder, IWICStream *stream, HRESULT expected, BOOL wine_init) +static HRESULT init_decoder(IWICBitmapDecoder *decoder, IWICStream *stream, HRESULT expected) { HRESULT hr; - IWICWineDecoder *wine_decoder;
hr = IWICBitmapDecoder_Initialize(decoder, (IStream*)stream, WICDecodeMetadataCacheOnDemand); ok(hr == expected, "Expected hr %#lx, got %#lx\n", expected, hr);
- if (hr != S_OK && wine_init) { - hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICWineDecoder, (void **)&wine_decoder); - ok(hr == S_OK || broken(hr != S_OK), "QueryInterface failed, hr %#lx\n", hr); - - if (hr == S_OK) { - hr = IWICWineDecoder_Initialize(wine_decoder, (IStream*)stream, WICDecodeMetadataCacheOnDemand); - ok(hr == S_OK, "Initialize failed, hr %#lx\n", hr); - } - } - return hr; }
@@ -789,7 +777,7 @@ static void test_dds_decoder_initialize(void) decoder = create_decoder(); if (!decoder) goto next;
- init_decoder(decoder, stream, test_data[i].init_hr, test_data[i].wine_init); + init_decoder(decoder, stream, test_data[i].init_hr);
next: if (decoder) IWICBitmapDecoder_Release(decoder); @@ -878,9 +866,9 @@ static void test_dds_decoder_image_parameters(void) hr = IWICDdsDecoder_GetParameters(dds_decoder, NULL); ok(hr == E_INVALIDARG, "GetParameters got unexpected hr %#lx\n", hr);
- if (test_data[i].init_hr != S_OK && !test_data[i].wine_init) goto next; + if (test_data[i].init_hr != S_OK) goto next;
- hr = init_decoder(decoder, stream, test_data[i].init_hr, test_data[i].wine_init); + hr = init_decoder(decoder, stream, test_data[i].init_hr); if (hr != S_OK) { if (test_data[i].expected_parameters.Dimension == WICDdsTextureCube) { win_skip("Cube map is not supported\n"); @@ -1286,7 +1274,7 @@ static void test_dds_decoder(void) IWICStream *stream = NULL; IWICBitmapDecoder *decoder = NULL;
- if (test_data[i].init_hr != S_OK && !test_data[i].wine_init) continue; + if (test_data[i].init_hr != S_OK) continue;
winetest_push_context("Test %u", i);
@@ -1294,7 +1282,7 @@ static void test_dds_decoder(void) if (!stream) goto next; decoder = create_decoder(); if (!decoder) goto next; - hr = init_decoder(decoder, stream, test_data[i].init_hr, test_data[i].wine_init); + hr = init_decoder(decoder, stream, test_data[i].init_hr); if (hr != S_OK) { if (test_data[i].expected_parameters.Dimension == WICDdsTextureCube) { win_skip("Cube map is not supported\n"); diff --git a/include/wincodec.idl b/include/wincodec.idl index 6752341c02a..5ff13713867 100644 --- a/include/wincodec.idl +++ b/include/wincodec.idl @@ -1235,17 +1235,6 @@ interface IWICDdsFrameDecode : IUnknown [out, size_is(bufferSize)] BYTE *buffer); };
-[ - object, - uuid(b9bd430d-28a8-41d3-a1f5-f36ee02840bf) -] -interface IWICWineDecoder : IUnknown -{ - HRESULT Initialize( - [in] IStream *stream, - [in] WICDecodeOptions options); -}; - cpp_quote("HRESULT WINAPI WICConvertBitmapSource(REFWICPixelFormatGUID dstFormat, IWICBitmapSource *pISrc, IWICBitmapSource **ppIDst);") cpp_quote("HRESULT WINAPI WICCreateBitmapFromSection(UINT width, UINT height, REFWICPixelFormatGUID format, HANDLE section, UINT stride, UINT offset, IWICBitmap **bitmap);") cpp_quote("HRESULT WINAPI WICCreateBitmapFromSectionEx(UINT width, UINT height, REFWICPixelFormatGUID format, HANDLE section, UINT stride, UINT offset, WICSectionAccessLevel access, IWICBitmap **bitmap);")