FreeRDP/scripts/LOMHash.c

78 lines
1.6 KiB
C
Raw Normal View History

2019-11-06 17:24:51 +03:00
#include <stdio.h>
typedef unsigned short UINT16;
typedef unsigned char BYTE;
2019-11-06 17:24:51 +03:00
static UINT16 HuffCodeLOM[] = { 0x0001, 0x0000, 0x0002, 0x0009, 0x0006, 0x0005, 0x000d, 0x000b,
0x0003, 0x001b, 0x0007, 0x0017, 0x0037, 0x000f, 0x004f, 0x006f,
0x002f, 0x00ef, 0x001f, 0x005f, 0x015f, 0x009f, 0x00df, 0x01df,
0x003f, 0x013f, 0x00bf, 0x01bf, 0x007f, 0x017f, 0x00ff, 0x01ff };
2012-03-21 21:32:38 +04:00
UINT16 HashTable[32] = { [0 ... 31] = 0xffff };
2012-03-21 21:32:38 +04:00
BYTE tab[4] = { 0, 4, 10, 19 };
2012-03-21 21:32:38 +04:00
UINT16 hash(UINT16 key)
2012-03-21 21:32:38 +04:00
{
2019-11-06 17:24:51 +03:00
return ((key & 0x1f) ^ (key >> 5) ^ (key >> 9));
2012-03-21 21:32:38 +04:00
}
BYTE minihash(UINT16 key)
2012-03-21 21:32:38 +04:00
{
BYTE h;
h = (key >> 4) & 0xf;
return ((h ^ (h >> 2) ^ (h >> 3)) & 0x3);
2012-03-21 21:32:38 +04:00
}
void buildhashtable(void)
{
for (int i = 0; i < 32; i++)
{
UINT16 h = hash(HuffCodeLOM[i]);
if (HashTable[h] != 0xffff)
{
HashTable[h] ^= (HuffCodeLOM[i] & 0xfe0) ^ 0xfe0;
HashTable[tab[minihash(HuffCodeLOM[i])]] = i;
}
else
{
HashTable[h] = i;
HashTable[h] ^= 0xfe0;
}
2019-11-06 17:24:51 +03:00
printf("at %d %" PRIu16 "=0x%" PRIx16 "\n", i, h, HashTable[h]);
}
2012-03-21 21:32:38 +04:00
}
BYTE getvalue(UINT16 huff)
2012-03-21 21:32:38 +04:00
{
UINT16 h = HashTable[hash(huff)];
if ((h ^ huff) >> 5)
{
return h & 0x1f;
}
else
return HashTable[tab[minihash(huff)]];
2012-03-21 21:32:38 +04:00
}
main()
{
buildhashtable();
printf("static UINT16 HuffIndexLOM[32] = {\n");
for (int i = 0; i < 32; i++)
{
if (i == 31)
2019-11-06 17:24:51 +03:00
printf("0x%" PRIx16 " };\n", HashTable[i]);
else
2019-11-06 17:24:51 +03:00
printf("0x%" PRIx16 ", ", HashTable[i]);
}
for (int i = 0; i < 32; i++)
if (i != getvalue(HuffCodeLOM[i]))
2019-11-06 17:24:51 +03:00
printf("Fail :( at %d : 0x%04" PRIx16 " got %" PRIu8 "\n", i, HuffCodeLOM[i],
getvalue(HuffCodeLOM[i]));
return 0;
2012-03-21 21:32:38 +04:00
}