Ziqing Hui : windowscodecs: Implement DdsDecoder_Wine_Initialize().

Alexandre Julliard julliard at winehq.org
Fri Jul 17 16:30:45 CDT 2020


Module: wine
Branch: master
Commit: 9ac21b7e1e10fad8ef4f2f7e87cc4bf7912eec7f
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=9ac21b7e1e10fad8ef4f2f7e87cc4bf7912eec7f

Author: Ziqing Hui <zhui at codeweavers.com>
Date:   Wed Jul 15 22:00:21 2020 +0800

windowscodecs: Implement DdsDecoder_Wine_Initialize().

Code in DdsDecoder_Initialize() are moved to DdsDecoder_Wine_Initialize().
And DdsDecoder_Initialize() are implemented on top of DdsDecoder_Wine_Initialize().

Signed-off-by: Ziqing Hui <zhui at codeweavers.com>
Signed-off-by: Esme Povirk <esme at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/windowscodecs/ddsformat.c | 126 +++++++++++++++++++++--------------------
 1 file changed, 66 insertions(+), 60 deletions(-)

diff --git a/dlls/windowscodecs/ddsformat.c b/dlls/windowscodecs/ddsformat.c
index 295b935a26..f7b5201321 100644
--- a/dlls/windowscodecs/ddsformat.c
+++ b/dlls/windowscodecs/ddsformat.c
@@ -104,6 +104,7 @@ typedef struct dds_info {
     UINT array_size;
     UINT frame_count;
     UINT data_offset;
+    BOOL compressed;
     DXGI_FORMAT format;
     WICDdsDimension dimension;
     WICDdsAlphaMode alpha_mode;
@@ -213,6 +214,8 @@ static void get_dds_info(dds_info* info, DDS_HEADER *header, DDS_HEADER_DXT10 *h
     int i;
     UINT depth;
 
+    info->compressed = !(header->ddspf.flags & (DDPF_RGB | DDPF_LUMINANCE));
+
     info->width = header->width;
     info->height = header->height;
     info->depth = 1;
@@ -623,67 +626,10 @@ static HRESULT WINAPI DdsDecoder_Initialize(IWICBitmapDecoder *iface, IStream *p
                                             WICDecodeOptions cacheOptions)
 {
     DdsDecoder *This = impl_from_IWICBitmapDecoder(iface);
-    DDS_HEADER_DXT10 header_dxt10;
-    DDS_HEADER header;
-    HRESULT hr;
-    LARGE_INTEGER seek;
-    DWORD magic;
-    ULONG bytesread;
 
     TRACE("(%p,%p,%x)\n", iface, pIStream, cacheOptions);
 
-    EnterCriticalSection(&This->lock);
-
-    if (This->initialized) {
-        hr = WINCODEC_ERR_WRONGSTATE;
-        goto end;
-    }
-
-    seek.QuadPart = 0;
-    hr = IStream_Seek(pIStream, seek, SEEK_SET, NULL);
-    if (FAILED(hr)) goto end;
-
-    hr = IStream_Read(pIStream, &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(pIStream, &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(pIStream, &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 = pIStream;
-    IStream_AddRef(pIStream);
-
-end:
-    LeaveCriticalSection(&This->lock);
-
-    return hr;
+    return IWICWineDecoder_Initialize(&This->IWICWineDecoder_iface, pIStream, cacheOptions);
 }
 
 static HRESULT WINAPI DdsDecoder_GetContainerFormat(IWICBitmapDecoder *iface,
@@ -987,8 +933,68 @@ static ULONG WINAPI DdsDecoder_Wine_Release(IWICWineDecoder *iface)
 
 static HRESULT WINAPI DdsDecoder_Wine_Initialize(IWICWineDecoder *iface, IStream *stream, WICDecodeOptions options)
 {
-    FIXME("(This %p, stream %p, options %#x)\n", iface, stream, options);
-    return E_NOTIMPL;
+    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, 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 = {




More information about the wine-cvs mailing list