[PATCH] d3dx9: Add a utility function for retrieving information about a pixel format

Tony Wasserka tony.wasserka at freenet.de
Wed Jul 15 09:45:35 CDT 2009


---
 dlls/d3dx9_36/d3dx9_36_private.h |   16 +++++++++++
 dlls/d3dx9_36/util.c             |   52 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/dlls/d3dx9_36/d3dx9_36_private.h b/dlls/d3dx9_36/d3dx9_36_private.h
index 8568366..6dff2a9 100644
--- a/dlls/d3dx9_36/d3dx9_36_private.h
+++ b/dlls/d3dx9_36/d3dx9_36_private.h
@@ -31,9 +31,25 @@
 #include "d3dx9.h"
 
 /* for internal use */
+typedef enum _StaticFormatType {
+    FORMAT_ARGB,
+    FORMAT_ABGR,
+    FORMAT_UNKNOWN
+} StaticFormatType;
+
+typedef struct _StaticPixelFormatDesc {
+    D3DFORMAT format;
+    BYTE abits, rbits, gbits, bbits;
+    UINT bpp;
+    StaticFormatType type;
+} StaticPixelFormatDesc;
+
 HRESULT map_view_of_file(LPCWSTR filename, LPVOID *buffer, DWORD *length);
 HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, LPVOID *buffer, DWORD *length);
 
+void get_format_info(D3DFORMAT format, StaticPixelFormatDesc *desc);
+
+
 extern const ID3DXBufferVtbl D3DXBuffer_Vtbl;
 
 /* ID3DXBUFFER */
diff --git a/dlls/d3dx9_36/util.c b/dlls/d3dx9_36/util.c
index ff41ee7..210d66f 100644
--- a/dlls/d3dx9_36/util.c
+++ b/dlls/d3dx9_36/util.c
@@ -20,6 +20,38 @@
 #include "wine/debug.h"
 #include "d3dx9_36_private.h"
 
+
+/************************************************************
+ * pixel format table providing info about number of bytes per pixel,
+ * number of bits per channel and format type.
+ *
+ * Call get_format_info to request information about a specific format.
+ */
+static const StaticPixelFormatDesc formats[] =
+{
+   /*    format             abits   rbits   gbits   bbits    bpp       type    */
+    { D3DFMT_R8G8B8,          0,      8,      8,      8,      3,    FORMAT_ARGB    },
+    { D3DFMT_A8R8G8B8,        8,      8,      8,      8,      4,    FORMAT_ARGB    },
+    { D3DFMT_X8R8G8B8,        0,      8,      8,      8,      4,    FORMAT_ARGB    },
+    { D3DFMT_R5G6B5,          0,      5,      6,      5,      2,    FORMAT_ARGB    },
+    { D3DFMT_X1R5G5B5,        0,      5,      5,      5,      2,    FORMAT_ARGB    },
+    { D3DFMT_A1R5G5B5,        1,      5,      5,      5,      2,    FORMAT_ARGB    },
+    { D3DFMT_A4R4G4B4,        4,      4,      4,      4,      2,    FORMAT_ARGB    },
+    { D3DFMT_R3G3B2,          0,      3,      3,      2,      1,    FORMAT_ARGB    },
+    { D3DFMT_A8,              8,      0,      0,      0,      1,    FORMAT_ARGB    },
+    { D3DFMT_A8R3G3B2,        8,      3,      3,      2,      2,    FORMAT_ARGB    },
+    { D3DFMT_X4R4G4B4,        0,      4,      4,      4,      2,    FORMAT_ARGB    },
+    { D3DFMT_A2B10G10R10,     2,     10,     10,     10,      4,    FORMAT_ABGR    },
+    { D3DFMT_A8B8G8R8,        8,      8,      8,      8,      4,    FORMAT_ABGR    },
+    { D3DFMT_X8B8G8R8,        0,      8,      8,      8,      4,    FORMAT_ABGR    },
+    { D3DFMT_G16R16,          0,     16,     16,      0,      4,    FORMAT_ABGR    },
+    { D3DFMT_A2R10G10B10,     2,     10,     10,     10,      4,    FORMAT_ARGB    },
+    { D3DFMT_A16B16G16R16,   16,     16,     16,     16,      8,    FORMAT_ABGR    },
+
+    { D3DFMT_UNKNOWN,         0,      0,      0,      0,      0,    FORMAT_UNKNOWN }, /* marks last element */
+};
+
+
 /************************************************************
  * map_view_of_file
  *
@@ -102,3 +134,23 @@ HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, LPVOID *buffer,
 
     return S_OK;
 }
+
+
+/************************************************************
+ * get_format_info
+ *
+ * Returns information about the specified format.
+ * If the format is unsupported, it's filled with the D3DFMT_UNKNOWN desc.
+ *
+ * PARAMS
+ *   format [I] format whose description is queried
+ *   desc   [O] pointer to a StaticPixelFormatDesc structure
+ *
+ */
+void get_format_info(D3DFORMAT format, StaticPixelFormatDesc *desc)
+{
+    int i = 0;
+    while(formats[i].format != format && formats[i].format != D3DFMT_UNKNOWN) i++;
+
+    memcpy(desc, &formats[i].format, sizeof(StaticPixelFormatDesc));
+}
-- 
1.6.0.2


--------------080703040307080704060401--



More information about the wine-patches mailing list