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