]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/BrotliCustomDecompressLib/common/transform.h
MdeModulePkg: Update Brotli DecompressLib to the latest v1.0.6
[mirror_edk2.git] / MdeModulePkg / Library / BrotliCustomDecompressLib / common / transform.h
1 /* transforms is a part of ABI, but not API.
2
3 It means that there are some functions that are supposed to be in "common"
4 library, but header itself is not placed into include/brotli. This way,
5 aforementioned functions will be available only to brotli internals.
6 */
7
8 #ifndef BROTLI_COMMON_TRANSFORM_H_
9 #define BROTLI_COMMON_TRANSFORM_H_
10
11 #include <brotli/port.h>
12 #include <brotli/types.h>
13
14 #if defined(__cplusplus) || defined(c_plusplus)
15 extern "C" {
16 #endif
17
18 enum BrotliWordTransformType {
19 BROTLI_TRANSFORM_IDENTITY = 0,
20 BROTLI_TRANSFORM_OMIT_LAST_1 = 1,
21 BROTLI_TRANSFORM_OMIT_LAST_2 = 2,
22 BROTLI_TRANSFORM_OMIT_LAST_3 = 3,
23 BROTLI_TRANSFORM_OMIT_LAST_4 = 4,
24 BROTLI_TRANSFORM_OMIT_LAST_5 = 5,
25 BROTLI_TRANSFORM_OMIT_LAST_6 = 6,
26 BROTLI_TRANSFORM_OMIT_LAST_7 = 7,
27 BROTLI_TRANSFORM_OMIT_LAST_8 = 8,
28 BROTLI_TRANSFORM_OMIT_LAST_9 = 9,
29 BROTLI_TRANSFORM_UPPERCASE_FIRST = 10,
30 BROTLI_TRANSFORM_UPPERCASE_ALL = 11,
31 BROTLI_TRANSFORM_OMIT_FIRST_1 = 12,
32 BROTLI_TRANSFORM_OMIT_FIRST_2 = 13,
33 BROTLI_TRANSFORM_OMIT_FIRST_3 = 14,
34 BROTLI_TRANSFORM_OMIT_FIRST_4 = 15,
35 BROTLI_TRANSFORM_OMIT_FIRST_5 = 16,
36 BROTLI_TRANSFORM_OMIT_FIRST_6 = 17,
37 BROTLI_TRANSFORM_OMIT_FIRST_7 = 18,
38 BROTLI_TRANSFORM_OMIT_FIRST_8 = 19,
39 BROTLI_TRANSFORM_OMIT_FIRST_9 = 20,
40 BROTLI_NUM_TRANSFORM_TYPES /* Counts transforms, not a transform itself. */
41 };
42
43 #define BROTLI_TRANSFORMS_MAX_CUT_OFF BROTLI_TRANSFORM_OMIT_LAST_9
44
45 typedef struct BrotliTransforms {
46 uint16_t prefix_suffix_size;
47 /* Last character must be null, so prefix_suffix_size must be at least 1. */
48 const uint8_t* prefix_suffix;
49 const uint16_t* prefix_suffix_map;
50 uint32_t num_transforms;
51 /* Each entry is a [prefix_id, transform, suffix_id] triplet. */
52 const uint8_t* transforms;
53 /* Indices of transforms like ["", BROTLI_TRANSFORM_OMIT_LAST_#, ""].
54 0-th element corresponds to ["", BROTLI_TRANSFORM_IDENTITY, ""].
55 -1, if cut-off transform does not exist. */
56 int16_t cutOffTransforms[BROTLI_TRANSFORMS_MAX_CUT_OFF + 1];
57 } BrotliTransforms;
58
59 /* T is BrotliTransforms*; result is uint8_t. */
60 #define BROTLI_TRANSFORM_PREFIX_ID(T, I) ((T)->transforms[((I) * 3) + 0])
61 #define BROTLI_TRANSFORM_TYPE(T, I) ((T)->transforms[((I) * 3) + 1])
62 #define BROTLI_TRANSFORM_SUFFIX_ID(T, I) ((T)->transforms[((I) * 3) + 2])
63
64 /* T is BrotliTransforms*; result is const uint8_t*. */
65 #define BROTLI_TRANSFORM_PREFIX(T, I) (&(T)->prefix_suffix[ \
66 (T)->prefix_suffix_map[BROTLI_TRANSFORM_PREFIX_ID(T, I)]])
67 #define BROTLI_TRANSFORM_SUFFIX(T, I) (&(T)->prefix_suffix[ \
68 (T)->prefix_suffix_map[BROTLI_TRANSFORM_SUFFIX_ID(T, I)]])
69
70 BROTLI_COMMON_API const BrotliTransforms* BrotliGetTransforms(void);
71
72 BROTLI_COMMON_API int BrotliTransformDictionaryWord(
73 uint8_t* dst, const uint8_t* word, int len,
74 const BrotliTransforms* transforms, int transform_idx);
75
76 #if defined(__cplusplus) || defined(c_plusplus)
77 } /* extern "C" */
78 #endif
79
80 #endif /* BROTLI_COMMON_TRANSFORM_H_ */