1 | /****************************************************************************** |
2 | |
3 | gif_hash.h - magfic constants and declarations for GIF LZW |
4 | |
5 | SPDX-License-Identifier: MIT |
6 | |
7 | ******************************************************************************/ |
8 | |
9 | #ifndef _GIF_HASH_H_ |
10 | #define _GIF_HASH_H_ |
11 | |
12 | #include <stdint.h> |
13 | |
14 | #define HT_SIZE 8192 /* 12bits = 4096 or twice as big! */ |
15 | #define HT_KEY_MASK 0x1FFF /* 13bits keys */ |
16 | #define HT_KEY_NUM_BITS 13 /* 13bits keys */ |
17 | #define HT_MAX_KEY 8191 /* 13bits - 1, maximal code possible */ |
18 | #define HT_MAX_CODE 4095 /* Biggest code possible in 12 bits. */ |
19 | |
20 | /* The 32 bits of the long are divided into two parts for the key & code: */ |
21 | /* 1. The code is 12 bits as our compression algorithm is limited to 12bits */ |
22 | /* 2. The key is 12 bits Prefix code + 8 bit new char or 20 bits. */ |
23 | /* The key is the upper 20 bits. The code is the lower 12. */ |
24 | #define HT_GET_KEY(l) (l >> 12) |
25 | #define HT_GET_CODE(l) (l & 0x0FFF) |
26 | #define HT_PUT_KEY(l) (l << 12) |
27 | #define HT_PUT_CODE(l) (l & 0x0FFF) |
28 | |
29 | typedef struct GifHashTableType { |
30 | uint32_t HTable[HT_SIZE]; |
31 | } GifHashTableType; |
32 | |
33 | GifHashTableType *_InitHashTable(void); |
34 | void _ClearHashTable(GifHashTableType *HashTable); |
35 | void _InsertHashTable(GifHashTableType *HashTable, uint32_t Key, int Code); |
36 | int _ExistsHashTable(GifHashTableType *HashTable, uint32_t Key); |
37 | |
38 | #endif /* _GIF_HASH_H_ */ |
39 | |
40 | /* end */ |
41 | |