Coverage Report

Created: 2025-07-16 07:53

/src/libjxl/lib/jxl/enc_toc.cc
Line
Count
Source (jump to first uncovered line)
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 <memory>
9
10
#include "lib/jxl/base/common.h"
11
#include "lib/jxl/base/status.h"
12
#include "lib/jxl/enc_aux_out.h"
13
#include "lib/jxl/enc_coeff_order.h"
14
#include "lib/jxl/field_encodings.h"
15
#include "lib/jxl/fields.h"
16
#include "lib/jxl/toc.h"
17
18
namespace jxl {
19
Status WriteGroupOffsets(
20
    const std::vector<std::unique_ptr<BitWriter>>& group_codes,
21
    const std::vector<coeff_order_t>& permutation,
22
0
    BitWriter* JXL_RESTRICT writer, AuxOut* aux_out) {
23
0
  return writer->WithMaxBits(
24
0
      MaxBits(group_codes.size()), LayerType::Toc, aux_out, [&]() -> Status {
25
0
        if (!permutation.empty() && !group_codes.empty()) {
26
          // Don't write a permutation at all for an empty group_codes.
27
0
          writer->Write(1, 1);  // permutation
28
0
          JXL_ENSURE(permutation.size() == group_codes.size());
29
0
          JXL_RETURN_IF_ERROR(EncodePermutation(permutation.data(), /*skip=*/0,
30
0
                                                permutation.size(), writer,
31
0
                                                LayerType::Header, aux_out));
32
33
0
        } else {
34
0
          writer->Write(1, 0);  // no permutation
35
0
        }
36
0
        writer->ZeroPadToByte();  // before TOC entries
37
38
0
        for (const auto& bw : group_codes) {
39
0
          JXL_ENSURE(bw->BitsWritten() % kBitsPerByte == 0);
40
0
          const size_t group_size = bw->BitsWritten() / kBitsPerByte;
41
0
          JXL_RETURN_IF_ERROR(U32Coder::Write(kTocDist, group_size, writer));
42
0
        }
43
0
        writer->ZeroPadToByte();  // before first group
44
0
        return true;
45
0
      });
46
0
}
47
48
}  // namespace jxl