diff options
Diffstat (limited to 'Source/Core/VideoCommon/Src/TextureDecoder.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/Src/TextureDecoder.cpp | 89 |
1 files changed, 45 insertions, 44 deletions
diff --git a/Source/Core/VideoCommon/Src/TextureDecoder.cpp b/Source/Core/VideoCommon/Src/TextureDecoder.cpp index c6db5582bb..1cf39c17ea 100644 --- a/Source/Core/VideoCommon/Src/TextureDecoder.cpp +++ b/Source/Core/VideoCommon/Src/TextureDecoder.cpp @@ -88,57 +88,58 @@ int TexDecoder_GetTextureSizeInBytes(int width, int height, int format) return (width * height * TexDecoder_GetTexelSizeInNibbles(format)) / 2; } -/*u64 TexDecoder_GetTlutHash(const u8* src, int len) +u64 TexDecoder_GetFullHash(const u8 *key, int len, u64 seed) { - //char str[40000], st[20]; str[0]='\0';for (int i=0;i<len;i++){sprintf(st,"%02x ",src[i]);strcat(str,st);} - u64 hash = 0xbeefbabe1337c0de; - int step = len / 29 / 8; - if (!step) step = 1; - for (int i = 0; i < len/8; i += step) { - hash = _rotl64(hash, 17) ^ ((u64 *)(src + i))[0]; + const u64 m = 0xc6a4a7935bd1e995; + const int r = 47; + + u64 h = seed ^ (len * m); + + const u64 * data = (const u64 *)key; + const u64 * end = data + (len/8); + + while(data != end) + { + u64 k = *data++; + + k *= m; + k ^= k >> r; + k *= m; + + h ^= k; + h *= m; } - return hash; -} -u64 TexDecoder_GetSafeTextureHash(const u8 *src, int width, int height, int texformat, u32 seed) + const u8 * data2 = (const u8*)data; + + switch(len & 7) + { + case 7: h ^= u64(data2[6]) << 48; + case 6: h ^= u64(data2[5]) << 40; + case 5: h ^= u64(data2[4]) << 32; + case 4: h ^= u64(data2[3]) << 24; + case 3: h ^= u64(data2[2]) << 16; + case 2: h ^= u64(data2[1]) << 8; + case 1: h ^= u64(data2[0]); + h *= m; + }; + + h ^= h >> r; + h *= m; + h ^= h >> r; + + return h; +} + +u64 TexDecoder_GetFastHash(const u8 *src, int len, u64 seed) { - int len = TexDecoder_GetTextureSizeInBytes(width, height, texformat); - u64 hash = seed ? seed : 0xbeefbabe1337c0de; - int step = len / 29 / 8; + u64 hash = seed ? seed : 0x1337c0debeefbabe; + int step = (len / 8) / 37; if (!step) step = 1; for (int i = 0; i < len / 8; i += step) { - hash = _rotl(hash, 17) ^ ((u64 *)src)[i]; - } - return hash; -} -*/ - -u32 TexDecoder_GetTlutHash(const u8* src, int len) -{ - //char str[40000], st[20]; str[0]='\0';for (int i=0;i<len;i++){sprintf(st,"%02x ",src[i]);strcat(str,st);} - u32 hash = 0xbeefbabe; - for (int i = 0; i < len / 4; i ++) { - hash = _rotl(hash, 7) ^ ((u32 *)src)[i]; + hash = _rotl64(hash, 19) ^ ((u64 *)src)[i]; hash += 7; // to add a bit more entropy/mess in here - } - return hash; -} - -u32 TexDecoder_GetSafeTextureHash(const u8 *src, int width, int height, int texformat, u32 seed) -{ - int sz = TexDecoder_GetTextureSizeInBytes(width, height, texformat); - u32 hash = seed ? seed : 0x1337c0de; - if (sz < 2048) { - for (int i = 0; i < sz / 4; i += 13) { - hash = _rotl(hash, 19) ^ ((u32 *)src)[i]; - } - return hash; - } else { - int step = sz / 23 / 4; - for (int i = 0; i < sz / 4; i += step) { - hash = _rotl(hash, 19) ^ ((u32 *)src)[i]; - } - } + } return hash; } |
