[3/5] windowscodecs: Register pixel formats.

Vincent Povirk madewokherd at gmail.com
Wed Jun 13 13:22:29 CDT 2012


-------------- next part --------------
From 681d7f77e04981049bb40f081dbb7def04ff3ec5 Mon Sep 17 00:00:00 2001
From: Vincent Povirk <vincent at codeweavers.com>
Date: Mon, 16 Apr 2012 14:31:09 -0500
Subject: [PATCH 03/27] windowscodecs: Register pixel formats.

---
 dlls/windowscodecs/regsvr.c |  461 +++++++++++++++++++++++++++++++++++++++++++
 include/wincodec.idl        |    2 +
 2 files changed, 463 insertions(+)

diff --git a/dlls/windowscodecs/regsvr.c b/dlls/windowscodecs/regsvr.c
index 85ebc6f..b73b645 100644
--- a/dlls/windowscodecs/regsvr.c
+++ b/dlls/windowscodecs/regsvr.c
@@ -132,6 +132,23 @@ struct regsvr_metadatareader
 static HRESULT register_metadatareaders(struct regsvr_metadatareader const *list);
 static HRESULT unregister_metadatareaders(struct regsvr_metadatareader const *list);
 
+struct regsvr_pixelformat
+{
+    CLSID const *clsid;         /* NULL for end of list */
+    LPCSTR author;
+    LPCSTR friendlyname;
+    LPCSTR version;
+    GUID const *vendor;
+    UINT bitsperpixel;
+    UINT channelcount;
+    BYTE const * const *channelmasks;
+    WICPixelFormatNumericRepresentation numericrepresentation;
+    UINT supportsalpha;
+};
+
+static HRESULT register_pixelformats(struct regsvr_pixelformat const *list);
+static HRESULT unregister_pixelformats(struct regsvr_pixelformat const *list);
+
 /***********************************************************************
  *		static string constants
  */
@@ -176,6 +193,11 @@ static const char supportspadding_valuename[] = "SupportsPadding";
 static const char requiresfixedsize_valuename[] = "FixedSize";
 static const WCHAR containers_keyname[] = {'C','o','n','t','a','i','n','e','r','s',0};
 static const char dataoffset_valuename[] = "DataOffset";
+static const char bitsperpixel_valuename[] = "BitLength";
+static const char channelcount_valuename[] = "ChannelCount";
+static const char numericrepresentation_valuename[] = "NumericRepresentation";
+static const char supportstransparency_valuename[] = "SupportsTransparency";
+static const WCHAR channelmasks_keyname[] = {'C','h','a','n','n','e','l','M','a','s','k','s',0};
 
 /***********************************************************************
  *		register_decoders
@@ -938,6 +960,181 @@ error_return:
 }
 
 /***********************************************************************
+ *                register_pixelformats
+ */
+static HRESULT register_pixelformats(struct regsvr_pixelformat const *list)
+{
+    LONG res = ERROR_SUCCESS;
+    HKEY coclass_key;
+    WCHAR buf[39];
+    HKEY formats_key;
+    HKEY instance_key;
+
+    res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
+                          KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
+    if (res == ERROR_SUCCESS)  {
+        StringFromGUID2(&CATID_WICPixelFormats, buf, 39);
+        res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
+                              KEY_READ | KEY_WRITE, NULL, &formats_key, NULL);
+        if (res == ERROR_SUCCESS)
+        {
+            res = RegCreateKeyExW(formats_key, instance_keyname, 0, NULL, 0,
+                              KEY_READ | KEY_WRITE, NULL, &instance_key, NULL);
+            if (res != ERROR_SUCCESS) goto error_close_coclass_key;
+        }
+        if (res != ERROR_SUCCESS)
+            RegCloseKey(coclass_key);
+    }
+    if (res != ERROR_SUCCESS) goto error_return;
+
+    for (; res == ERROR_SUCCESS && list->clsid; ++list) {
+        HKEY clsid_key;
+        HKEY instance_clsid_key;
+
+        StringFromGUID2(list->clsid, buf, 39);
+        res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
+                              KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
+        if (res != ERROR_SUCCESS) goto error_close_coclass_key;
+
+        StringFromGUID2(list->clsid, buf, 39);
+        res = RegCreateKeyExW(instance_key, buf, 0, NULL, 0,
+                              KEY_READ | KEY_WRITE, NULL, &instance_clsid_key, NULL);
+        if (res == ERROR_SUCCESS) {
+            res = RegSetValueExW(instance_clsid_key, clsid_valuename, 0, REG_SZ,
+                                 (CONST BYTE*)(buf), 78);
+            RegCloseKey(instance_clsid_key);
+        }
+        if (res != ERROR_SUCCESS) goto error_close_clsid_key;
+
+        if (list->author) {
+            res = RegSetValueExA(clsid_key, author_valuename, 0, REG_SZ,
+                                 (CONST BYTE*)(list->author),
+                                 strlen(list->author) + 1);
+            if (res != ERROR_SUCCESS) goto error_close_clsid_key;
+        }
+
+        if (list->friendlyname) {
+            res = RegSetValueExA(clsid_key, friendlyname_valuename, 0, REG_SZ,
+                                 (CONST BYTE*)(list->friendlyname),
+                                 strlen(list->friendlyname) + 1);
+            if (res != ERROR_SUCCESS) goto error_close_clsid_key;
+        }
+
+        if (list->vendor) {
+            StringFromGUID2(list->vendor, buf, 39);
+            res = RegSetValueExW(clsid_key, vendor_valuename, 0, REG_SZ,
+                                 (CONST BYTE*)(buf), 78);
+            if (res != ERROR_SUCCESS) goto error_close_clsid_key;
+        }
+
+        if (list->version) {
+            res = RegSetValueExA(clsid_key, version_valuename, 0, REG_SZ,
+                                 (CONST BYTE*)(list->version),
+                                 strlen(list->version) + 1);
+            if (res != ERROR_SUCCESS) goto error_close_clsid_key;
+        }
+
+        res = RegSetValueExA(clsid_key, bitsperpixel_valuename, 0, REG_DWORD,
+                             (CONST BYTE*)(&list->bitsperpixel), 4);
+        if (res != ERROR_SUCCESS) goto error_close_clsid_key;
+
+        res = RegSetValueExA(clsid_key, channelcount_valuename, 0, REG_DWORD,
+                             (CONST BYTE*)(&list->channelcount), 4);
+        if (res != ERROR_SUCCESS) goto error_close_clsid_key;
+
+        res = RegSetValueExA(clsid_key, numericrepresentation_valuename, 0, REG_DWORD,
+                             (CONST BYTE*)(&list->numericrepresentation), 4);
+        if (res != ERROR_SUCCESS) goto error_close_clsid_key;
+
+        res = RegSetValueExA(clsid_key, supportstransparency_valuename, 0, REG_DWORD,
+                             (CONST BYTE*)(&list->supportsalpha), 4);
+        if (res != ERROR_SUCCESS) goto error_close_clsid_key;
+
+        if (list->channelmasks) {
+            HKEY masks_key;
+            UINT i, mask_size;
+            WCHAR mask_valuename[11];
+            const WCHAR valuename_format[] = {'%','d',0};
+
+            mask_size = (list->bitsperpixel + 7)/8;
+
+            res = RegCreateKeyExW(clsid_key, channelmasks_keyname, 0, NULL, 0,
+                                  KEY_READ | KEY_WRITE, NULL, &masks_key, NULL);
+            if (res != ERROR_SUCCESS) goto error_close_clsid_key;
+            for (i=0; i < list->channelcount; i++)
+            {
+                sprintfW(mask_valuename, valuename_format, i);
+                res = RegSetValueExW(masks_key, mask_valuename, 0, REG_BINARY,
+                                     list->channelmasks[i], mask_size);
+                if (res != ERROR_SUCCESS) break;
+            }
+            RegCloseKey(masks_key);
+            if (res != ERROR_SUCCESS) goto error_close_clsid_key;
+        }
+
+    error_close_clsid_key:
+        RegCloseKey(clsid_key);
+    }
+
+error_close_coclass_key:
+    RegCloseKey(instance_key);
+    RegCloseKey(formats_key);
+    RegCloseKey(coclass_key);
+error_return:
+    return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
+}
+
+/***********************************************************************
+ *                unregister_pixelformats
+ */
+static HRESULT unregister_pixelformats(struct regsvr_pixelformat const *list)
+{
+    LONG res = ERROR_SUCCESS;
+    HKEY coclass_key;
+    WCHAR buf[39];
+    HKEY formats_key;
+    HKEY instance_key;
+
+    res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
+                        KEY_READ | KEY_WRITE, &coclass_key);
+    if (res == ERROR_FILE_NOT_FOUND) return S_OK;
+
+    if (res == ERROR_SUCCESS)  {
+        StringFromGUID2(&CATID_WICPixelFormats, buf, 39);
+        res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
+                              KEY_READ | KEY_WRITE, NULL, &formats_key, NULL);
+        if (res == ERROR_SUCCESS)
+        {
+            res = RegCreateKeyExW(formats_key, instance_keyname, 0, NULL, 0,
+                              KEY_READ | KEY_WRITE, NULL, &instance_key, NULL);
+            if (res != ERROR_SUCCESS) goto error_close_coclass_key;
+        }
+        if (res != ERROR_SUCCESS)
+            RegCloseKey(coclass_key);
+    }
+    if (res != ERROR_SUCCESS) goto error_return;
+
+    for (; res == ERROR_SUCCESS && list->clsid; ++list) {
+        StringFromGUID2(list->clsid, buf, 39);
+
+        res = RegDeleteTreeW(coclass_key, buf);
+        if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
+        if (res != ERROR_SUCCESS) goto error_close_coclass_key;
+
+        res = RegDeleteTreeW(instance_key, buf);
+        if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
+        if (res != ERROR_SUCCESS) goto error_close_coclass_key;
+    }
+
+error_close_coclass_key:
+    RegCloseKey(instance_key);
+    RegCloseKey(formats_key);
+    RegCloseKey(coclass_key);
+error_return:
+    return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
+}
+
+/***********************************************************************
  *		decoder list
  */
 static const BYTE mask_all[] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
@@ -1331,6 +1528,266 @@ static struct regsvr_metadatareader const metadatareader_list[] = {
     { NULL }			/* list terminator */
 };
 
+static BYTE const channel_mask_1bit[] = { 0x01 };
+static BYTE const channel_mask_2bit[] = { 0x03 };
+static BYTE const channel_mask_4bit[] = { 0x0f };
+
+static BYTE const channel_mask_8bit[] = { 0xff, 0x00, 0x00, 0x00 };
+static BYTE const channel_mask_8bit2[] = { 0x00, 0xff, 0x00, 0x00 };
+static BYTE const channel_mask_8bit3[] = { 0x00, 0x00, 0xff, 0x00 };
+static BYTE const channel_mask_8bit4[] = { 0x00, 0x00, 0x00, 0xff };
+
+static BYTE const channel_mask_16bit[] = { 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+static BYTE const channel_mask_16bit2[] = { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 };
+static BYTE const channel_mask_16bit3[] = { 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 };
+static BYTE const channel_mask_16bit4[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff };
+
+static BYTE const channel_mask_5bit[] = { 0x1f, 0x00 };
+static BYTE const channel_mask_5bit2[] = { 0xe0, 0x03 };
+static BYTE const channel_mask_5bit3[] = { 0x00, 0x7c };
+static BYTE const channel_mask_5bit4[] = { 0x00, 0x80 };
+
+static BYTE const channel_mask_BGR565_2[] = { 0xe0, 0x07 };
+static BYTE const channel_mask_BGR565_3[] = { 0x00, 0xf8 };
+
+static BYTE const * const channel_masks_1bit[] = { channel_mask_1bit };
+static BYTE const * const channel_masks_2bit[] = { channel_mask_2bit };
+static BYTE const * const channel_masks_4bit[] = { channel_mask_4bit };
+static BYTE const * const channel_masks_8bit[] = { channel_mask_8bit,
+    channel_mask_8bit2, channel_mask_8bit3, channel_mask_8bit4 };
+static BYTE const * const channel_masks_16bit[] = { channel_mask_16bit,
+    channel_mask_16bit2, channel_mask_16bit3, channel_mask_16bit4};
+
+static BYTE const * const channel_masks_BGRA5551[] = { channel_mask_5bit,
+    channel_mask_5bit2, channel_mask_5bit3, channel_mask_5bit4 };
+
+static BYTE const * const channel_masks_BGR565[] = { channel_mask_5bit,
+    channel_mask_BGR565_2, channel_mask_BGR565_3 };
+
+static struct regsvr_pixelformat const pixelformat_list[] = {
+    {   &GUID_WICPixelFormat1bppIndexed,
+        "The Wine Project",
+        "1bpp Indexed",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        1, /* bitsperpixel */
+        1, /* channel count */
+        channel_masks_1bit,
+        WICPixelFormatNumericRepresentationIndexed,
+        1
+    },
+    {   &GUID_WICPixelFormat2bppIndexed,
+        "The Wine Project",
+        "2bpp Indexed",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        2, /* bitsperpixel */
+        1, /* channel count */
+        channel_masks_2bit,
+        WICPixelFormatNumericRepresentationIndexed,
+        1
+    },
+    {   &GUID_WICPixelFormat4bppIndexed,
+        "The Wine Project",
+        "4bpp Indexed",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        4, /* bitsperpixel */
+        1, /* channel count */
+        channel_masks_4bit,
+        WICPixelFormatNumericRepresentationIndexed,
+        1
+    },
+    {   &GUID_WICPixelFormat8bppIndexed,
+        "The Wine Project",
+        "8bpp Indexed",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        8, /* bitsperpixel */
+        1, /* channel count */
+        channel_masks_8bit,
+        WICPixelFormatNumericRepresentationIndexed,
+        1
+    },
+    {   &GUID_WICPixelFormatBlackWhite,
+        "The Wine Project",
+        "Black and White",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        1, /* bitsperpixel */
+        1, /* channel count */
+        channel_masks_1bit,
+        WICPixelFormatNumericRepresentationUnsignedInteger,
+        0
+    },
+    {   &GUID_WICPixelFormat2bppGray,
+        "The Wine Project",
+        "2bpp Grayscale",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        2, /* bitsperpixel */
+        1, /* channel count */
+        channel_masks_2bit,
+        WICPixelFormatNumericRepresentationUnsignedInteger,
+        0
+    },
+    {   &GUID_WICPixelFormat4bppGray,
+        "The Wine Project",
+        "4bpp Grayscale",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        4, /* bitsperpixel */
+        1, /* channel count */
+        channel_masks_4bit,
+        WICPixelFormatNumericRepresentationUnsignedInteger,
+        0
+    },
+    {   &GUID_WICPixelFormat8bppGray,
+        "The Wine Project",
+        "8bpp Grayscale",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        8, /* bitsperpixel */
+        1, /* channel count */
+        channel_masks_8bit,
+        WICPixelFormatNumericRepresentationUnsignedInteger,
+        0
+    },
+    {   &GUID_WICPixelFormat16bppGray,
+        "The Wine Project",
+        "16bpp Grayscale",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        16, /* bitsperpixel */
+        1, /* channel count */
+        channel_masks_16bit,
+        WICPixelFormatNumericRepresentationUnsignedInteger,
+        0
+    },
+    {   &GUID_WICPixelFormat16bppBGR555,
+        "The Wine Project",
+        "16bpp BGR555",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        16, /* bitsperpixel */
+        3, /* channel count */
+        channel_masks_BGRA5551,
+        WICPixelFormatNumericRepresentationUnsignedInteger,
+        0
+    },
+    {   &GUID_WICPixelFormat16bppBGR565,
+        "The Wine Project",
+        "16bpp BGR565",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        16, /* bitsperpixel */
+        3, /* channel count */
+        channel_masks_BGR565,
+        WICPixelFormatNumericRepresentationUnsignedInteger,
+        0
+    },
+    {   &GUID_WICPixelFormat16bppBGRA5551,
+        "The Wine Project",
+        "16bpp BGRA5551",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        16, /* bitsperpixel */
+        4, /* channel count */
+        channel_masks_BGRA5551,
+        WICPixelFormatNumericRepresentationUnsignedInteger,
+        1
+    },
+    {   &GUID_WICPixelFormat24bppBGR,
+        "The Wine Project",
+        "24bpp BGR",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        24, /* bitsperpixel */
+        3, /* channel count */
+        channel_masks_8bit,
+        WICPixelFormatNumericRepresentationUnsignedInteger,
+        0
+    },
+    {   &GUID_WICPixelFormat32bppBGR,
+        "The Wine Project",
+        "32bpp BGR",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        32, /* bitsperpixel */
+        3, /* channel count */
+        channel_masks_8bit,
+        WICPixelFormatNumericRepresentationUnsignedInteger,
+        0
+    },
+    {   &GUID_WICPixelFormat32bppBGRA,
+        "The Wine Project",
+        "32bpp BGRA",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        32, /* bitsperpixel */
+        4, /* channel count */
+        channel_masks_8bit,
+        WICPixelFormatNumericRepresentationUnsignedInteger,
+        1
+    },
+    {   &GUID_WICPixelFormat32bppPBGRA,
+        "The Wine Project",
+        "32bpp PBGRA",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        32, /* bitsperpixel */
+        4, /* channel count */
+        channel_masks_8bit,
+        WICPixelFormatNumericRepresentationUnsignedInteger,
+        1
+    },
+    {   &GUID_WICPixelFormat48bppRGB,
+        "The Wine Project",
+        "48bpp RGB",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        48, /* bitsperpixel */
+        3, /* channel count */
+        channel_masks_16bit,
+        WICPixelFormatNumericRepresentationUnsignedInteger,
+        0
+    },
+    {   &GUID_WICPixelFormat64bppRGBA,
+        "The Wine Project",
+        "64bpp RGBA",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        64, /* bitsperpixel */
+        4, /* channel count */
+        channel_masks_16bit,
+        WICPixelFormatNumericRepresentationUnsignedInteger,
+        1
+    },
+    {   &GUID_WICPixelFormat64bppPRGBA,
+        "The Wine Project",
+        "64bpp PRGBA",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        64, /* bitsperpixel */
+        4, /* channel count */
+        channel_masks_16bit,
+        WICPixelFormatNumericRepresentationUnsignedInteger,
+        1
+    },
+    {   &GUID_WICPixelFormat32bppCMYK,
+        "The Wine Project",
+        "32bpp CMYK",
+        NULL, /* no version */
+        &GUID_VendorMicrosoft,
+        32, /* bitsperpixel */
+        4, /* channel count */
+        channel_masks_8bit,
+        WICPixelFormatNumericRepresentationUnsignedInteger,
+        0
+    },
+    { NULL }			/* list terminator */
+};
+
 extern HRESULT WINAPI WIC_DllRegisterServer(void) DECLSPEC_HIDDEN;
 extern HRESULT WINAPI WIC_DllUnregisterServer(void) DECLSPEC_HIDDEN;
 
@@ -1349,6 +1806,8 @@ HRESULT WINAPI DllRegisterServer(void)
         hr = register_converters(converter_list);
     if (SUCCEEDED(hr))
         hr = register_metadatareaders(metadatareader_list);
+    if (SUCCEEDED(hr))
+        hr = register_pixelformats(pixelformat_list);
     return hr;
 }
 
@@ -1367,5 +1826,7 @@ HRESULT WINAPI DllUnregisterServer(void)
         hr = unregister_converters(converter_list);
     if (SUCCEEDED(hr))
         hr = unregister_metadatareaders(metadatareader_list);
+    if (SUCCEEDED(hr))
+        hr = unregister_pixelformats(pixelformat_list);
     return hr;
 }
diff --git a/include/wincodec.idl b/include/wincodec.idl
index afb0207..a479ea7 100644
--- a/include/wincodec.idl
+++ b/include/wincodec.idl
@@ -1004,3 +1004,5 @@ cpp_quote("DEFINE_GUID(CATID_WICBitmapDecoders, 0x7ed96837,0x96f0,0x4812,0xb2,0x
 cpp_quote("DEFINE_GUID(CATID_WICBitmapEncoders, 0xac757296,0x3522,0x4e11,0x98,0x62,0xc1,0x7b,0xe5,0xa1,0x76,0x7e);")
 cpp_quote("DEFINE_GUID(CATID_WICFormatConverters, 0x7835eae8,0xbf14,0x49d1,0x93,0xce,0x53,0x3a,0x40,0x7b,0x22,0x48);")
 cpp_quote("DEFINE_GUID(CATID_WICMetadataReader, 0x05af94d8,0x7174,0x4cd2,0xbe,0x4a,0x41,0x24,0xb8,0x0e,0xe4,0xb8);")
+cpp_quote("DEFINE_GUID(CATID_WICPixelFormats, 0x2b46e70f,0xcda7,0x473e,0x89,0xf6,0xdc,0x96,0x30,0xa2,0x39,0x0b);")
+
-- 
1.7.9.5


More information about the wine-patches mailing list