Coverage Report

Created: 2026-09-14 07:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjxl/lib/jxl/enc_toc.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/enc_toc.h"
7
8
#include <cstddef>
9
#include <vector>
10
11
#include "lib/jxl/base/common.h"
12
#include "lib/jxl/base/compiler_specific.h"
13
#include "lib/jxl/base/status.h"
14
#include "lib/jxl/coeff_order_fwd.h"
15
#include "lib/jxl/enc_aux_out.h"
16
#include "lib/jxl/enc_coeff_order.h"
17
#include "lib/jxl/field_encodings.h"
18
#include "lib/jxl/fields.h"
19
#include "lib/jxl/toc.h"
20
21
namespace jxl {
22
23
Status WriteTocPermutation(const std::vector<coeff_order_t>& permutation,
24
7.64k
                           BitWriter* JXL_RESTRICT writer, AuxOut* aux_out) {
25
7.64k
  return writer->WithMaxBits(
26
7.64k
      MaxBits(0), LayerType::Toc, aux_out, [&]() -> Status {
27
7.64k
        if (!permutation.empty()) {
28
0
          writer->Write(1, 1);  // permutation present
29
0
          JXL_RETURN_IF_ERROR(EncodePermutation(
30
0
              permutation.data(), /*skip=*/0, permutation.size(), writer,
31
0
              LayerType::Header, aux_out));
32
7.64k
        } else {
33
7.64k
          writer->Write(1, 0);  // no permutation
34
7.64k
        }
35
7.64k
        writer->ZeroPadToByte();  // before TOC entries
36
7.64k
        return true;
37
7.64k
      });
38
7.64k
}
39
40
Status WriteTocSizes(const std::vector<size_t>& group_sizes,
41
7.57k
                     BitWriter* JXL_RESTRICT writer, AuxOut* aux_out) {
42
7.57k
  return writer->WithMaxBits(
43
7.57k
      MaxBits(group_sizes.size()), LayerType::Toc, aux_out, [&]() -> Status {
44
25.3k
        for (size_t group_size : group_sizes) {
45
25.3k
          JXL_RETURN_IF_ERROR(U32Coder::Write(kTocDist, group_size, writer));
46
25.3k
        }
47
7.57k
        writer->ZeroPadToByte();  // before first group
48
7.57k
        return true;
49
7.57k
      });
50
7.57k
}
51
52
}  // namespace jxl