upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/bcpack.h
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/src/bcpack.h')
-rw-r--r--runtime/src/bcpack.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/runtime/src/bcpack.h b/runtime/src/bcpack.h
new file mode 100644
index 000000000..9c34a074b
--- /dev/null
+++ b/runtime/src/bcpack.h
@@ -0,0 +1,33 @@
1// C++ BCPack decoder. Publish the caller's staged output only on success.
2#pragma once
3#include <array>
4#include <cstdint>
5#include <span>
6
7namespace leonida::bcpack {
8enum class Quality { failed, confirmed, fitted };
9
10// Fixed-size little-endian sidecar produced by
11// tools/gen_bcpack_runtime_tables.py --profile. All fields are bytes: BC6H's 12
12// endpoint quantities are stored as little-endian uint16 pairs.
13struct Calibration {
14 struct BC6 {
15 std::array<std::uint8_t, 24> ep;
16 std::array<std::uint8_t, 16> ix;
17 std::array<std::uint8_t, 12> ep_confirmed;
18 std::array<std::uint8_t, 16> ix_confirmed;
19 std::uint8_t ep_class, ix_class;
20 };
21 struct BC7 {
22 std::array<std::uint8_t, 24> ep, ep_bits, ep_confirmed;
23 std::array<std::uint8_t, 32> ix, ix_bits, ix_confirmed;
24 };
25 std::array<BC6, 256> bc6;
26 std::array<BC7, 256> bc7;
27};
28static_assert(sizeof(Calibration) == 256 * (70 + 168));
29Quality decode(unsigned codec, std::span<const std::uint8_t> source,
30 std::span<std::uint8_t> output, bool allow_fitted = false,
31 const Calibration *history = nullptr, const char** failure = nullptr,
32 bool fast_entropy = true);
33} // namespace leonida::bcpack