2019-11-06 17:24:51 +03:00
|
|
|
#include <stdio.h>
|
2012-10-09 11:01:37 +04:00
|
|
|
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
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 HashTable[32] = { [0 ... 31] = 0xffff };
|
2012-03-21 21:32:38 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE tab[4] = { 0, 4, 10, 19 };
|
2012-03-21 21:32:38 +04:00
|
|
|
|
2012-10-09 11:01:37 +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
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE minihash(UINT16 key)
|
2012-03-21 21:32:38 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03: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)
|
|
|
|
{
|
2024-01-30 12:25:38 +03:00
|
|
|
for (int i = 0; i < 32; i++)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2024-01-30 12:25:38 +03:00
|
|
|
UINT16 h = hash(HuffCodeLOM[i]);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
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]);
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2012-03-21 21:32:38 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE getvalue(UINT16 huff)
|
2012-03-21 21:32:38 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03: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()
|
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
buildhashtable();
|
|
|
|
printf("static UINT16 HuffIndexLOM[32] = {\n");
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (int i = 0; i < 32; i++)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
|
|
|
if (i == 31)
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("0x%" PRIx16 " };\n", HashTable[i]);
|
2016-04-05 18:07:45 +03:00
|
|
|
else
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("0x%" PRIx16 ", ", HashTable[i]);
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (int i = 0; i < 32; i++)
|
2016-04-05 18:07:45 +03:00
|
|
|
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],
|
2016-04-05 18:07:45 +03:00
|
|
|
getvalue(HuffCodeLOM[i]));
|
|
|
|
|
|
|
|
return 0;
|
2012-03-21 21:32:38 +04:00
|
|
|
}
|