Coverage Report

Created: 2025-06-16 07:00

/src/libjxl/third_party/brotli/c/enc/prefix.h
Line
Count
Source (jump to first uncovered line)
1
/* Copyright 2013 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
/* Functions for encoding of integers into prefix codes the amount of extra
8
   bits, and the actual values of the extra bits. */
9
10
#ifndef BROTLI_ENC_PREFIX_H_
11
#define BROTLI_ENC_PREFIX_H_
12
13
#include <brotli/types.h>
14
15
#include "../common/constants.h"
16
#include "../common/platform.h"
17
#include "fast_log.h"
18
19
#if defined(__cplusplus) || defined(c_plusplus)
20
extern "C" {
21
#endif
22
23
/* Here distance_code is an intermediate code, i.e. one of the special codes or
24
   the actual distance increased by BROTLI_NUM_DISTANCE_SHORT_CODES - 1. */
25
static BROTLI_INLINE void PrefixEncodeCopyDistance(size_t distance_code,
26
                                                   size_t num_direct_codes,
27
                                                   size_t postfix_bits,
28
                                                   uint16_t* code,
29
0
                                                   uint32_t* extra_bits) {
30
0
  if (distance_code < BROTLI_NUM_DISTANCE_SHORT_CODES + num_direct_codes) {
31
0
    *code = (uint16_t)distance_code;
32
0
    *extra_bits = 0;
33
0
    return;
34
0
  } else {
35
0
    size_t dist = ((size_t)1 << (postfix_bits + 2u)) +
36
0
        (distance_code - BROTLI_NUM_DISTANCE_SHORT_CODES - num_direct_codes);
37
0
    size_t bucket = Log2FloorNonZero(dist) - 1;
38
0
    size_t postfix_mask = (1u << postfix_bits) - 1;
39
0
    size_t postfix = dist & postfix_mask;
40
0
    size_t prefix = (dist >> bucket) & 1;
41
0
    size_t offset = (2 + prefix) << bucket;
42
0
    size_t nbits = bucket - postfix_bits;
43
0
    *code = (uint16_t)((nbits << 10) |
44
0
        (BROTLI_NUM_DISTANCE_SHORT_CODES + num_direct_codes +
45
0
         ((2 * (nbits - 1) + prefix) << postfix_bits) + postfix));
46
0
    *extra_bits = (uint32_t)((dist - offset) >> postfix_bits);
47
0
  }
48
0
}
Unexecuted instantiation: encode.c:PrefixEncodeCopyDistance
Unexecuted instantiation: metablock.c:PrefixEncodeCopyDistance
Unexecuted instantiation: block_splitter.c:PrefixEncodeCopyDistance
Unexecuted instantiation: bit_cost.c:PrefixEncodeCopyDistance
Unexecuted instantiation: cluster.c:PrefixEncodeCopyDistance
Unexecuted instantiation: histogram.c:PrefixEncodeCopyDistance
Unexecuted instantiation: compress_fragment_two_pass.c:PrefixEncodeCopyDistance
Unexecuted instantiation: brotli_bit_stream.c:PrefixEncodeCopyDistance
Unexecuted instantiation: command.c:PrefixEncodeCopyDistance
Unexecuted instantiation: compress_fragment.c:PrefixEncodeCopyDistance
Unexecuted instantiation: backward_references_hq.c:PrefixEncodeCopyDistance
Unexecuted instantiation: backward_references.c:PrefixEncodeCopyDistance
49
50
#if defined(__cplusplus) || defined(c_plusplus)
51
}  /* extern "C" */
52
#endif
53
54
#endif  /* BROTLI_ENC_PREFIX_H_ */