11 #include "itk/itkpix/geo/geometry.hpp"
14 #include "bintree.hpp"
15 #include "bitstream.hpp"
16 #include "print_utils.hpp"
20 namespace itk::itkpix::endec::codec {
22 [[maybe_unused]]
static inline print<false> logger;
38 template <itk::itkpix::endec::concepts::EventCallback OutPut,
bool EnableLogging = false>
45 : data(data_, opt.en_chip_id ? 3 : 1), out(proc), options(opt) {}
67 uint64_t ccol = 999999;
70 bool is_neighbor =
false;
73 auto fetch_ccol = [&]()
mutable ->
bool {
75 std::tie(result, ccol) = data.fetch(6);
77 if ((ccol >> 3) == 0b111) {
78 auto [result1, intTag] = data.fetch(5);
79 intTag |= ((ccol & 0b111) << 5);
81 std::tie(result2, ccol) = data.fetch(6);
82 logger.internal_tag(intTag);
85 if (ccol == 0)
return false;
89 auto fetch_ctrl = [&]()
mutable ->
bool {
90 auto [result, ctrl] = data.fetch(2);
91 is_last = (ctrl & 2) == 2;
92 is_neighbor = (ctrl & 1) == 1;
97 auto fetch_hitmap = [&]() ->
bool {
98 auto [result, hit_map] = data.prefetch(30);
100 auto len = BinaryTreeLUT::decode(hit_map, decoded);
102 logger.hitmap(hit_map >> (30 - len), len, decoded);
105 auto hits = BinaryTreeLUT::hit_lut_length[decoded];
106 auto [result1, tots] = data.fetch(hits * 4);
107 logger.tot(tots, hits);
110 int hit_count = hits;
111 auto h = BinaryTreeLUT::hit_lut[decoded];
113 uint16_t col_base = (ccol - 1) * itk::itkpix::geo::NumQColPix;
114 uint16_t row_base = qrow * itk::itkpix::geo::NumQRowPix;
115 for (
int i = 0; i < hits; ++i) {
116 uint16_t col = col_base + uint16_t(h[i].first);
117 uint16_t row = row_base + uint16_t(h[i].second);
119 uint16_t tot = ((tots >> (hit_count * 4)) & 0xf);
122 out.add_hit(col, row, tot);
129 std::tie(result, tag) = data.fetch(8);
132 while (data.left() > 6 && ccol != 0) {
134 auto success = fetch_ccol();
140 std::tie(result, qrow) = data.fetch(8);
149 std::size_t bits_processed()
const {
return data.index(); }
152 static inline constexpr uint64_t bit_mask(std::size_t n) {
return (uint64_t(1) << n) - 1; }
154 BitStreamReader<const std::span<uint64_t>> data;
156 const Options options;
163 namespace itk::itkpix::endec::codec {
167 template<
typename Callback,
int cb_type = 0>
173 : opt(opt), cb_evt(cb_evt) {
174 log.
trace(
"slac.DecCore(opt, evt)");
177 inline void initialize() {
178 log.
trace(
"slac.initialize");
180 inline void finalize() {
181 log.
trace(
"slac.finalize");
183 inline void decode(uint64_t data64) {
184 log.
warn(
"not implemented | slac.decode(data64: 0x{:016x})", data64);
186 inline void decode(
const uint8_t *buff,
size_t size) {
187 auto data = std::span<const uint8_t>{buff,
size};
190 inline void decode(
const uint64_t *buff64,
size_t size64) {
191 auto data64 = std::span<const uint64_t>{buff64, size64};
195 inline void decode(
const std::span<const uint8_t> buff) {
196 log.
trace(
"slac.decode(buff) | size64: {}", buff.size());
197 for (
auto data : buff) {
198 log.
trace(
" 0x{:02x}", data);
201 inline void decode(
const std::span<const uint64_t> buff64) {
Definition: test_enc_dec.cpp:117
Definition: decoder.hpp:168
Decode a ITK pixel data stream.
Definition: decoder.hpp:39
void decode()
Decode the ITK pixel data stream.
Definition: decoder.hpp:66
Logger class definition, wrapper around CoreLogger, adds templated methods for different logging leve...
Definition: logger.hpp:108
void trace(fmt::format_string< Args... > fmt, Args &&...args)
Logs a message with trace level.
Definition: logger.hpp:132
void warn(fmt::format_string< Args... > fmt, Args &&...args)
Logs a message with warning level.
Definition: logger.hpp:156
Templates for ITkPix Decoder Core.
Common encoder/decoder options.
Definition: options.hpp:10
Definition: print_utils.hpp:10