Coverage Report

Created: 2025-06-16 07:00

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