Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/brotli/dec/prefix.c
14730 views
1
/* Copyright 2025 Google Inc. All Rights Reserved.
2
3
Distributed under MIT license.
4
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
*/
6
7
#include "prefix.h"
8
9
#include "../common/platform.h" /* IWYU pragma: keep */
10
#include "../common/static_init.h"
11
12
#if (BROTLI_STATIC_INIT != BROTLI_STATIC_INIT_NONE)
13
#include "../common/constants.h"
14
#endif
15
16
#if defined(__cplusplus) || defined(c_plusplus)
17
extern "C" {
18
#endif
19
20
#if (BROTLI_STATIC_INIT == BROTLI_STATIC_INIT_NONE)
21
/* Embed kCmdLut. */
22
#include "prefix_inc.h"
23
#else
24
BROTLI_COLD BROTLI_BOOL BrotliDecoderInitCmdLut(CmdLutElement* items) {
25
static const uint8_t kInsertLengthExtraBits[24] = {
26
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03,
27
0x04, 0x04, 0x05, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0C, 0x0E, 0x18};
28
static const uint8_t kCopyLengthExtraBits[24] = {
29
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02,
30
0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x18};
31
static const uint8_t kCellPos[11] = {0, 1, 0, 1, 8, 9, 2, 16, 10, 17, 18};
32
33
uint16_t insert_length_offsets[24];
34
uint16_t copy_length_offsets[24];
35
insert_length_offsets[0] = 0;
36
copy_length_offsets[0] = 2;
37
for (size_t i = 0; i < 23; ++i) {
38
insert_length_offsets[i + 1] =
39
insert_length_offsets[i] + (uint16_t)(1u << kInsertLengthExtraBits[i]);
40
copy_length_offsets[i + 1] =
41
copy_length_offsets[i] + (uint16_t)(1u << kCopyLengthExtraBits[i]);
42
}
43
44
for (size_t symbol = 0; symbol < BROTLI_NUM_COMMAND_SYMBOLS; ++symbol) {
45
CmdLutElement* item = items + symbol;
46
const size_t cell_idx = symbol >> 6;
47
const size_t cell_pos = kCellPos[cell_idx];
48
const size_t copy_code = ((cell_pos << 3) & 0x18) + (symbol & 0x7);
49
const uint16_t copy_len_offset = copy_length_offsets[copy_code];
50
const size_t insert_code = (cell_pos & 0x18) + ((symbol >> 3) & 0x7);
51
item->copy_len_extra_bits = kCopyLengthExtraBits[copy_code];
52
item->context = (copy_len_offset > 4) ? 3 : ((uint8_t)copy_len_offset - 2);
53
item->copy_len_offset = copy_len_offset;
54
item->distance_code = (cell_idx >= 2) ? -1 : 0;
55
item->insert_len_extra_bits = kInsertLengthExtraBits[insert_code];
56
item->insert_len_offset = insert_length_offsets[insert_code];
57
}
58
return BROTLI_TRUE;
59
}
60
61
BROTLI_MODEL("small")
62
CmdLutElement kCmdLut[BROTLI_NUM_COMMAND_SYMBOLS];
63
#endif /* BROTLI_STATIC_INIT */
64
65
#if defined(__cplusplus) || defined(c_plusplus)
66
} /* extern "C" */
67
#endif
68
69