[2/3] d3dx9: Add partial DDS support implementation for D3DXGetImageInfo functions. (try 2)
Józef Kucia
joseph.kucia at gmail.com
Fri Apr 27 02:55:59 CDT 2012
Try 2: Do not use LPCVOID.
---
dlls/d3dx9_36/surface.c | 67 ++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 64 insertions(+), 3 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c
index f1bddb7..4cb5d27 100644
--- a/dlls/d3dx9_36/surface.c
+++ b/dlls/d3dx9_36/surface.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2009-2010 Tony Wasserka
+ * Copyright (C) 2012 Józef Kucia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -94,6 +95,65 @@ struct dds_header
DWORD reserved2;
};
+static D3DFORMAT dds_pixel_format_to_d3dformat(const struct dds_pixel_format *pixel_format)
+{
+ FIXME("Pixel format conversion not implemented.\n");
+ return D3DFMT_UNKNOWN;
+}
+
+/************************************************************
+* get_image_info_from_dds
+*
+* Fills a D3DXIMAGE_INFO structure with information
+* about a DDS file stored in the memory.
+*
+* PARAMS
+* buffer [I] pointer to DDS data
+* length [I] size of DDS data
+* info [O] pointer to D3DXIMAGE_INFO structure
+*
+* RETURNS
+* Success: D3D_OK
+* Failure: D3DXERR_INVALIDDATA
+*
+*/
+static HRESULT get_image_info_from_dds(const void *buffer, DWORD length, D3DXIMAGE_INFO *info)
+{
+ const struct dds_header *header = buffer;
+
+ if (length < sizeof(*header) || !info)
+ return D3DXERR_INVALIDDATA;
+
+ if (header->pixel_format.size != sizeof(header->pixel_format))
+ return D3DXERR_INVALIDDATA;
+
+ info->Width = header->width;
+ info->Height = header->height;
+ info->Depth = 1;
+ info->MipLevels = (header->flags & DDS_MIPMAPCOUNT) ? header->miplevels : 1;
+
+ info->Format = dds_pixel_format_to_d3dformat(&header->pixel_format);
+ if (info->Format == D3DFMT_UNKNOWN)
+ return D3DXERR_INVALIDDATA;
+
+ if (header->caps2 & DDS_CAPS2_VOLUME)
+ {
+ info->Depth = header->depth;
+ info->ResourceType = D3DRTYPE_VOLUMETEXTURE;
+ }
+ else if (header->caps2 & DDS_CAPS2_CUBEMAP)
+ {
+ info->ResourceType = D3DRTYPE_CUBETEXTURE;
+ }
+ else
+ {
+ info->ResourceType = D3DRTYPE_TEXTURE;
+ }
+
+ info->ImageFileFormat = D3DXIFF_DDS;
+
+ return D3D_OK;
+}
/************************************************************
* D3DXGetImageInfoFromFileInMemory
@@ -132,6 +192,9 @@ HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(LPCVOID data, UINT datasize, D3D
if (!info)
return D3D_OK;
+ if ((datasize >= 4) && !strncmp(data, "DDS ", 4))
+ return get_image_info_from_dds(data, datasize, info);
+
initresult = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&factory);
@@ -145,9 +208,7 @@ HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(LPCVOID data, UINT datasize, D3D
}
if (FAILED(hr)) {
- if ((datasize >= 4) && !strncmp(data, "DDS ", 4))
- FIXME("File type DDS is not supported yet\n");
- else if ((datasize >= 2) && (!strncmp(data, "P3", 2) || !strncmp(data, "P6", 2)))
+ if ((datasize >= 2) && (!strncmp(data, "P3", 2) || !strncmp(data, "P6", 2)))
FIXME("File type PPM is not supported yet\n");
else if ((datasize >= 2) && !strncmp(data, "BM", 2))
FIXME("File type DIB is not supported yet\n");
--
1.7.8.5
More information about the wine-patches
mailing list