upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/src/bcpack.h
blob: 9c34a074ba9468bc8690423384cf1611315ad3ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// C++ BCPack decoder. Publish the caller's staged output only on success.
#pragma once
#include <array>
#include <cstdint>
#include <span>

namespace leonida::bcpack {
enum class Quality { failed, confirmed, fitted };

// Fixed-size little-endian sidecar produced by
// tools/gen_bcpack_runtime_tables.py --profile. All fields are bytes: BC6H's 12
// endpoint quantities are stored as little-endian uint16 pairs.
struct Calibration {
  struct BC6 {
    std::array<std::uint8_t, 24> ep;
    std::array<std::uint8_t, 16> ix;
    std::array<std::uint8_t, 12> ep_confirmed;
    std::array<std::uint8_t, 16> ix_confirmed;
    std::uint8_t ep_class, ix_class;
  };
  struct BC7 {
    std::array<std::uint8_t, 24> ep, ep_bits, ep_confirmed;
    std::array<std::uint8_t, 32> ix, ix_bits, ix_confirmed;
  };
  std::array<BC6, 256> bc6;
  std::array<BC7, 256> bc7;
};
static_assert(sizeof(Calibration) == 256 * (70 + 168));
Quality decode(unsigned codec, std::span<const std::uint8_t> source,
               std::span<std::uint8_t> output, bool allow_fitted = false,
               const Calibration *history = nullptr, const char** failure = nullptr,
               bool fast_entropy = true);
} // namespace leonida::bcpack