Coverage Report

Created: 2026-07-25 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjxl/lib/jxl/entropy_coder.cc
Line
Count
Source
1
// Copyright (c) the JPEG XL Project Authors. All rights reserved.
2
//
3
// Use of this source code is governed by a BSD-style
4
// license that can be found in the LICENSE file.
5
6
#include "lib/jxl/entropy_coder.h"
7
8
#include <jxl/memory_manager.h>
9
10
#include <cstdint>
11
#include <vector>
12
13
#include "lib/jxl/ac_context.h"
14
#include "lib/jxl/base/compiler_specific.h"
15
#include "lib/jxl/base/status.h"
16
#include "lib/jxl/coeff_order.h"
17
#include "lib/jxl/coeff_order_fwd.h"
18
#include "lib/jxl/dec_bit_reader.h"
19
#include "lib/jxl/dec_context_map.h"
20
#include "lib/jxl/fields.h"
21
#include "lib/jxl/pack_signed.h"
22
23
namespace jxl {
24
25
Status DecodeBlockCtxMap(JxlMemoryManager* memory_manager, BitReader* br,
26
4.89k
                         BlockCtxMap* block_ctx_map) {
27
4.89k
  auto& dct = block_ctx_map->dc_thresholds;
28
4.89k
  auto& qft = block_ctx_map->qf_thresholds;
29
4.89k
  auto& ctx_map = block_ctx_map->ctx_map;
30
4.89k
  bool is_default = static_cast<bool>(br->ReadFixedBits<1>());
31
4.89k
  if (is_default) {
32
4.73k
    *block_ctx_map = BlockCtxMap();
33
4.73k
    return true;
34
4.73k
  }
35
160
  block_ctx_map->num_dc_ctxs = 1;
36
480
  for (int j : {0, 1, 2}) {
37
480
    dct[j].resize(br->ReadFixedBits<4>());
38
480
    block_ctx_map->num_dc_ctxs *= dct[j].size() + 1;
39
480
    for (int& i : dct[j]) {
40
229
      i = UnpackSigned(U32Coder::Read(kDCThresholdDist, br));
41
229
    }
42
480
  }
43
160
  qft.resize(br->ReadFixedBits<4>());
44
413
  for (uint32_t& i : qft) {
45
413
    i = U32Coder::Read(kQFThresholdDist, br) + 1;
46
413
  }
47
48
160
  if (block_ctx_map->num_dc_ctxs * (qft.size() + 1) > 64) {
49
3
    return JXL_FAILURE("Invalid block context map: too big");
50
3
  }
51
52
157
  ctx_map.resize(3 * kNumOrders * block_ctx_map->num_dc_ctxs *
53
157
                 (qft.size() + 1));
54
157
  JXL_RETURN_IF_ERROR(
55
157
      DecodeContextMap(memory_manager, &ctx_map, &block_ctx_map->num_ctxs, br));
56
157
  if (block_ctx_map->num_ctxs > 16) {
57
0
    return JXL_FAILURE("Invalid block context map: too many distinct contexts");
58
0
  }
59
157
  return true;
60
157
}
61
62
#if JXL_CXX_LANG < JXL_CXX_17
63
constexpr uint8_t BlockCtxMap::kDefaultCtxMap[];  // from ac_context.h
64
#endif
65
66
}  // namespace jxl