Jacek Caban : winex11: Use a simple sdbm hash implementation in X11DRV_GetICMProfile.
Alexandre Julliard
julliard at winehq.org
Fri Apr 22 14:46:05 CDT 2022
Module: wine
Branch: master
Commit: f1fb42ac4d4924beba3e5d48cf76132a2bbbaecc
URL: https://source.winehq.org/git/wine.git/?a=commit;h=f1fb42ac4d4924beba3e5d48cf76132a2bbbaecc
Author: Jacek Caban <jacek at codeweavers.com>
Date: Fri Apr 22 14:46:31 2022 +0200
winex11: Use a simple sdbm hash implementation in X11DRV_GetICMProfile.
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/winex11.drv/graphics.c | 39 +++++++++++++++++++--------------------
1 file changed, 19 insertions(+), 20 deletions(-)
diff --git a/dlls/winex11.drv/graphics.c b/dlls/winex11.drv/graphics.c
index 4dafb5a339b..dadedf2d9cf 100644
--- a/dlls/winex11.drv/graphics.c
+++ b/dlls/winex11.drv/graphics.c
@@ -1621,12 +1621,13 @@ fallback:
return dev->funcs->pGradientFill( dev, vert_array, nvert, grad_array, ngrad, mode );
}
-static unsigned char *get_icm_profile( unsigned long *size )
+static char *get_icm_profile( unsigned long *size )
{
Atom type;
int format;
unsigned long count, remaining;
- unsigned char *profile, *ret = NULL;
+ unsigned char *profile;
+ char *ret = NULL;
XGetWindowProperty( gdi_display, DefaultRootWindow(gdi_display),
x11drv_atom(_ICC_PROFILE), 0, ~0UL, False, AnyPropertyType,
@@ -1674,15 +1675,15 @@ BOOL CDECL X11DRV_GetICMProfile( PHYSDEV dev, BOOL allow_default, LPDWORD size,
DWORD required;
char buf[4096];
KEY_VALUE_FULL_INFORMATION *info = (void *)buf;
- unsigned char *buffer;
- unsigned long buflen;
+ char *buffer;
+ unsigned long buflen, i;
ULONG full_size;
- WCHAR profile[MAX_PATH], fullname[MAX_PATH + ARRAY_SIZE( color_path )];
+ WCHAR fullname[MAX_PATH + ARRAY_SIZE( color_path )], *p;
if (!size) return FALSE;
memcpy( fullname, color_path, sizeof(color_path) );
- fullname[ARRAYSIZE(color_path)] = 0;
+ p = fullname + ARRAYSIZE(color_path);
hkey = reg_open_key( NULL, mntr_key, sizeof(mntr_key) );
@@ -1690,27 +1691,25 @@ BOOL CDECL X11DRV_GetICMProfile( PHYSDEV dev, BOOL allow_default, LPDWORD size,
info, sizeof(buf), &full_size ))
{
/* FIXME handle multiple values */
- memcpy( fullname + ARRAYSIZE(color_path), info->Name, info->NameLength );
- fullname[ARRAYSIZE(color_path) + info->NameLength / sizeof(WCHAR)] = 0;
+ memcpy( p, info->Name, info->NameLength );
+ p[info->NameLength / sizeof(WCHAR)] = 0;
}
else if ((buffer = get_icm_profile( &buflen )))
{
- static const WCHAR fmt[] = {'%','0','2','x',0};
static const WCHAR icm[] = {'.','i','c','m',0};
-
- unsigned char sha1sum[20];
- unsigned int i;
- sha_ctx ctx;
+ UINT64 hash = 0;
HANDLE file;
- A_SHAInit( &ctx );
- A_SHAUpdate( &ctx, buffer, buflen );
- A_SHAFinal( &ctx, sha1sum );
+ for (i = 0; i < buflen; i++) hash = (hash << 16) - hash + buffer[i];
+ for (i = 0; i < sizeof(hash) * 2; i++)
+ {
+ int digit = hash & 0xf;
+ p[i] = digit < 10 ? '0' + digit : 'a' - 10 + digit;
+ hash >>= 4;
+ }
- for (i = 0; i < sizeof(sha1sum); i++) sprintfW( &profile[i * 2], fmt, sha1sum[i] );
- memcpy( &profile[i * 2], icm, sizeof(icm) );
+ memcpy( p + i, icm, sizeof(icm) );
- strcatW( fullname, profile );
file = CreateFileW( fullname, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0 );
if (file != INVALID_HANDLE_VALUE)
{
@@ -1723,7 +1722,7 @@ BOOL CDECL X11DRV_GetICMProfile( PHYSDEV dev, BOOL allow_default, LPDWORD size,
HeapFree( GetProcessHeap(), 0, buffer );
}
else if (!allow_default) return FALSE;
- else strcatW( fullname, srgb );
+ else lstrcpyW( p, srgb );
NtClose( hkey );
required = strlenW( fullname ) + 1;
More information about the wine-cvs
mailing list