windowscodecs: Register builtin encoders.

This commit is contained in:
Vincent Povirk 2010-09-05 21:24:53 -05:00 committed by Alexandre Julliard
parent d701e8fab3
commit ad2895d10b
2 changed files with 250 additions and 0 deletions

View File

@ -83,6 +83,21 @@ struct regsvr_decoder
static HRESULT register_decoders(struct regsvr_decoder const *list);
static HRESULT unregister_decoders(struct regsvr_decoder const *list);
struct regsvr_encoder
{
CLSID const *clsid; /* NULL for end of list */
LPCSTR author;
LPCSTR friendlyname;
LPCSTR version;
GUID const *vendor;
LPCSTR mimetypes;
LPCSTR extensions;
GUID const * const *formats;
};
static HRESULT register_encoders(struct regsvr_encoder const *list);
static HRESULT unregister_encoders(struct regsvr_encoder const *list);
struct regsvr_converter
{
CLSID const *clsid; /* NULL for end of list */
@ -474,6 +489,177 @@ error_return:
return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
}
/***********************************************************************
* register_encoders
*/
static HRESULT register_encoders(struct regsvr_encoder const *list)
{
LONG res = ERROR_SUCCESS;
HKEY coclass_key;
WCHAR buf[39];
HKEY encoders_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_WICBitmapEncoders, buf, 39);
res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &encoders_key, NULL);
if (res == ERROR_SUCCESS)
{
res = RegCreateKeyExW(encoders_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;
}
if (list->mimetypes) {
res = RegSetValueExA(clsid_key, mimetypes_valuename, 0, REG_SZ,
(CONST BYTE*)(list->mimetypes),
strlen(list->mimetypes) + 1);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
}
if (list->extensions) {
res = RegSetValueExA(clsid_key, extensions_valuename, 0, REG_SZ,
(CONST BYTE*)(list->extensions),
strlen(list->extensions) + 1);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
}
if (list->formats) {
HKEY formats_key;
GUID const * const *format;
res = RegCreateKeyExW(clsid_key, formats_keyname, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &formats_key, NULL);
if (res != ERROR_SUCCESS) goto error_close_clsid_key;
for (format=list->formats; *format; ++format)
{
HKEY format_key;
StringFromGUID2(*format, buf, 39);
res = RegCreateKeyExW(formats_key, buf, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &format_key, NULL);
if (res != ERROR_SUCCESS) break;
RegCloseKey(format_key);
}
RegCloseKey(formats_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(encoders_key);
RegCloseKey(coclass_key);
error_return:
return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
}
/***********************************************************************
* unregister_encoders
*/
static HRESULT unregister_encoders(struct regsvr_encoder const *list)
{
LONG res = ERROR_SUCCESS;
HKEY coclass_key;
WCHAR buf[39];
HKEY encoders_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_WICBitmapEncoders, buf, 39);
res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &encoders_key, NULL);
if (res == ERROR_SUCCESS)
{
res = RegCreateKeyExW(encoders_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(encoders_key);
RegCloseKey(coclass_key);
error_return:
return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
}
/***********************************************************************
* register_converters
*/
@ -969,6 +1155,64 @@ static struct regsvr_decoder const decoder_list[] = {
{ NULL } /* list terminator */
};
static GUID const * const bmp_encode_formats[] = {
&GUID_WICPixelFormat16bppBGR555,
&GUID_WICPixelFormat16bppBGR565,
&GUID_WICPixelFormat24bppBGR,
&GUID_WICPixelFormat32bppBGR,
NULL
};
static GUID const * const png_encode_formats[] = {
&GUID_WICPixelFormat24bppBGR,
&GUID_WICPixelFormatBlackWhite,
&GUID_WICPixelFormat2bppGray,
&GUID_WICPixelFormat4bppGray,
&GUID_WICPixelFormat8bppGray,
&GUID_WICPixelFormat16bppGray,
&GUID_WICPixelFormat32bppBGR,
&GUID_WICPixelFormat32bppBGRA,
&GUID_WICPixelFormat48bppRGB,
&GUID_WICPixelFormat64bppRGBA,
NULL
};
static GUID const * const icns_encode_formats[] = {
&GUID_WICPixelFormat32bppBGRA,
NULL
};
static struct regsvr_encoder const encoder_list[] = {
{ &CLSID_WICBmpEncoder,
"The Wine Project",
"BMP Encoder",
"1.0.0.0",
&GUID_VendorMicrosoft,
"image/bmp",
".bmp,.dib,.rle",
bmp_encode_formats
},
{ &CLSID_WICPngEncoder,
"The Wine Project",
"PNG Encoder",
"1.0.0.0",
&GUID_VendorMicrosoft,
"image/png",
".png",
png_encode_formats
},
{ &CLSID_WICIcnsEncoder,
"The Wine Project",
"ICNS Encoder",
"1.0.0.0",
&GUID_VendorWine,
"image/icns",
".icns",
icns_encode_formats
},
{ NULL } /* list terminator */
};
static GUID const * const converter_formats[] = {
&GUID_WICPixelFormat1bppIndexed,
&GUID_WICPixelFormat2bppIndexed,
@ -1009,6 +1253,8 @@ HRESULT WINAPI DllRegisterServer(void)
hr = register_coclasses(coclass_list);
if (SUCCEEDED(hr))
register_decoders(decoder_list);
if (SUCCEEDED(hr))
register_encoders(encoder_list);
if (SUCCEEDED(hr))
register_converters(converter_list);
return hr;
@ -1023,6 +1269,8 @@ HRESULT WINAPI DllUnregisterServer(void)
hr = unregister_coclasses(coclass_list);
if (SUCCEEDED(hr))
unregister_decoders(decoder_list);
if (SUCCEEDED(hr))
unregister_encoders(encoder_list);
if (SUCCEEDED(hr))
unregister_converters(converter_list);
return hr;

View File

@ -21,6 +21,8 @@
DEFINE_GUID(CLSID_WICIcnsEncoder, 0x312fb6f1,0xb767,0x409d,0x8a,0x6d,0x0f,0xc1,0x54,0xd4,0xf0,0x5c);
DEFINE_GUID(GUID_VendorWine, 0xddf46da1,0x7dc1,0x404e,0x98,0xf2,0xef,0xa4,0x8d,0xfc,0x95,0x0a);
extern HRESULT FormatConverter_CreateInstance(IUnknown *pUnkOuter, REFIID riid, void** ppv);
extern HRESULT ImagingFactory_CreateInstance(IUnknown *pUnkOuter, REFIID riid, void** ppv);
extern HRESULT BmpDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID riid, void** ppv);