/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 | 6.74k | BitWriter* JXL_RESTRICT writer, AuxOut* aux_out) { |
25 | 6.74k | return writer->WithMaxBits( |
26 | 6.74k | MaxBits(0), LayerType::Toc, aux_out, [&]() -> Status { |
27 | 6.74k | 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 | 6.74k | } else { |
33 | 6.74k | writer->Write(1, 0); // no permutation |
34 | 6.74k | } |
35 | 6.74k | writer->ZeroPadToByte(); // before TOC entries |
36 | 6.74k | return true; |
37 | 6.74k | }); |
38 | 6.74k | } |
39 | | |
40 | | Status WriteTocSizes(const std::vector<size_t>& group_sizes, |
41 | 6.68k | BitWriter* JXL_RESTRICT writer, AuxOut* aux_out) { |
42 | 6.68k | return writer->WithMaxBits( |
43 | 6.68k | MaxBits(group_sizes.size()), LayerType::Toc, aux_out, [&]() -> Status { |
44 | 22.4k | for (size_t group_size : group_sizes) { |
45 | 22.4k | JXL_RETURN_IF_ERROR(U32Coder::Write(kTocDist, group_size, writer)); |
46 | 22.4k | } |
47 | 6.68k | writer->ZeroPadToByte(); // before first group |
48 | 6.68k | return true; |
49 | 6.68k | }); |
50 | 6.68k | } |
51 | | |
52 | | } // namespace jxl |