]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/C/BrotliCompress/enc/prefix.h
BaseTools: resolve initialization order errors in VfrFormPkg.h
[mirror_edk2.git] / BaseTools / Source / C / BrotliCompress / enc / prefix.h
CommitLineData
11b7501a
SB
1/* Copyright 2013 Google Inc. All Rights Reserved.\r
2\r
3 Distributed under MIT license.\r
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT\r
5*/\r
6\r
7/* Functions for encoding of integers into prefix codes the amount of extra\r
8 bits, and the actual values of the extra bits. */\r
9\r
10#ifndef BROTLI_ENC_PREFIX_H_\r
11#define BROTLI_ENC_PREFIX_H_\r
12\r
13#include "../common/constants.h"\r
14#include "../common/port.h"\r
15#include "../common/types.h"\r
16#include "./fast_log.h"\r
17\r
18#if defined(__cplusplus) || defined(c_plusplus)\r
19extern "C" {\r
20#endif\r
21\r
22static BROTLI_INLINE void PrefixEncodeCopyDistance(size_t distance_code,\r
23 size_t num_direct_codes,\r
24 size_t postfix_bits,\r
25 uint16_t* code,\r
26 uint32_t* extra_bits) {\r
27 if (distance_code < BROTLI_NUM_DISTANCE_SHORT_CODES + num_direct_codes) {\r
28 *code = (uint16_t)distance_code;\r
29 *extra_bits = 0;\r
30 return;\r
31 } else {\r
32 size_t dist = ((size_t)1 << (postfix_bits + 2u)) +\r
33 (distance_code - BROTLI_NUM_DISTANCE_SHORT_CODES - num_direct_codes);\r
34 size_t bucket = Log2FloorNonZero(dist) - 1;\r
35 size_t postfix_mask = (1u << postfix_bits) - 1;\r
36 size_t postfix = dist & postfix_mask;\r
37 size_t prefix = (dist >> bucket) & 1;\r
38 size_t offset = (2 + prefix) << bucket;\r
39 size_t nbits = bucket - postfix_bits;\r
40 *code = (uint16_t)(\r
41 (BROTLI_NUM_DISTANCE_SHORT_CODES + num_direct_codes +\r
42 ((2 * (nbits - 1) + prefix) << postfix_bits) + postfix));\r
43 *extra_bits = (uint32_t)(\r
44 (nbits << 24) | ((dist - offset) >> postfix_bits));\r
45 }\r
46}\r
47\r
48#if defined(__cplusplus) || defined(c_plusplus)\r
49} /* extern "C" */\r
50#endif\r
51\r
52#endif /* BROTLI_ENC_PREFIX_H_ */\r