summaryrefslogtreecommitdiffstats
path: root/third_party/jpeg-xl/lib/jxl/enc_toc.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/jpeg-xl/lib/jxl/enc_toc.cc
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/jpeg-xl/lib/jxl/enc_toc.cc')
-rw-r--r--third_party/jpeg-xl/lib/jxl/enc_toc.cc45
1 files changed, 45 insertions, 0 deletions
diff --git a/third_party/jpeg-xl/lib/jxl/enc_toc.cc b/third_party/jpeg-xl/lib/jxl/enc_toc.cc
new file mode 100644
index 0000000000..dc75fdd9ba
--- /dev/null
+++ b/third_party/jpeg-xl/lib/jxl/enc_toc.cc
@@ -0,0 +1,45 @@
+// Copyright (c) the JPEG XL Project Authors. All rights reserved.
+//
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include "lib/jxl/enc_toc.h"
+
+#include <stdint.h>
+
+#include "lib/jxl/coeff_order.h"
+#include "lib/jxl/common.h"
+#include "lib/jxl/enc_aux_out.h"
+#include "lib/jxl/enc_coeff_order.h"
+#include "lib/jxl/field_encodings.h"
+#include "lib/jxl/fields.h"
+#include "lib/jxl/toc.h"
+
+namespace jxl {
+Status WriteGroupOffsets(const std::vector<BitWriter>& group_codes,
+ const std::vector<coeff_order_t>* permutation,
+ BitWriter* JXL_RESTRICT writer, AuxOut* aux_out) {
+ BitWriter::Allotment allotment(writer, MaxBits(group_codes.size()));
+ if (permutation && !group_codes.empty()) {
+ // Don't write a permutation at all for an empty group_codes.
+ writer->Write(1, 1); // permutation
+ JXL_DASSERT(permutation->size() == group_codes.size());
+ EncodePermutation(permutation->data(), /*skip=*/0, permutation->size(),
+ writer, /* layer= */ 0, aux_out);
+
+ } else {
+ writer->Write(1, 0); // no permutation
+ }
+ writer->ZeroPadToByte(); // before TOC entries
+
+ for (size_t i = 0; i < group_codes.size(); i++) {
+ JXL_ASSERT(group_codes[i].BitsWritten() % kBitsPerByte == 0);
+ const size_t group_size = group_codes[i].BitsWritten() / kBitsPerByte;
+ JXL_RETURN_IF_ERROR(U32Coder::Write(kTocDist, group_size, writer));
+ }
+ writer->ZeroPadToByte(); // before first group
+ allotment.ReclaimAndCharge(writer, kLayerTOC, aux_out);
+ return true;
+}
+
+} // namespace jxl