Skip to content

Commit

Permalink
Calculate total_cells() and frame capacity, and ...
Browse files Browse the repository at this point in the history
... use it in fountain_chunk_size(). The existing calculation was built
around the 8x8 grid size (9300 bytes).
  • Loading branch information
sz3 committed Jun 1, 2023
1 parent cdd2f5c commit c34ae88
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/lib/cimb_translator/CimbReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace {
CimbReader::CimbReader(const cv::Mat& img, CimbDecoder& decoder, bool needs_sharpen, bool color_correction)
: _image(img)
, _cellSize(Config::cell_size() + 2)
, _positions(Config::cell_spacing(), Config::num_cells(), Config::cell_offset(), Config::corner_padding())
, _positions(Config::cell_spacing(), Config::cells_per_col(), Config::cell_offset(), Config::corner_padding())
, _decoder(decoder)
, _good(_image.cols >= Config::image_size() and _image.rows >= Config::image_size())
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/cimb_translator/CimbWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace {
}

CimbWriter::CimbWriter(unsigned symbol_bits, unsigned color_bits, bool dark, int size)
: _positions(Config::cell_spacing(), Config::num_cells(), Config::cell_offset(), Config::corner_padding(), Config::interleave_blocks(), Config::interleave_partitions())
: _positions(Config::cell_spacing(), Config::cells_per_col(), Config::cell_offset(), Config::corner_padding(), Config::interleave_blocks(), Config::interleave_partitions())
, _encoder(symbol_bits, color_bits)
{
if (size > cimbar::Config::image_size())
Expand Down
27 changes: 18 additions & 9 deletions src/lib/cimb_translator/Config.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* This code is subject to the terms of the Mozilla Public License, v.2.0. http://mozilla.org/MPL/2.0/. */
#include "Config.h"
#include <cmath>

namespace cimbar {

Expand Down Expand Up @@ -53,11 +54,23 @@ unsigned Config::cell_offset()
return 9;
}

unsigned Config::num_cells()
unsigned Config::cells_per_col()
{
return 168;
}

unsigned Config::total_cells()
{
return std::pow(cells_per_col(), 2) - std::pow(corner_padding(), 2) * 4;
}

unsigned Config::capacity(unsigned bitspercell)
{
if (!bitspercell)
bitspercell = bits_per_cell();
return total_cells() * bitspercell / 8;
}

unsigned Config::corner_padding()
{
return 54 / cell_spacing();
Expand All @@ -75,15 +88,11 @@ unsigned Config::interleave_partitions()

unsigned Config::fountain_chunk_size(unsigned ecc, unsigned bitspercell)
{
// this calculation is based off the 112x112-6 grid.
// in that grid, we have 155 * bits_per_cell * 10 total bytes of data.
// so this neatly splits into 10 chunks per frame.
// ex: 690=6900/10 for ecc=40.
if (!bitspercell)
bitspercell = bits_per_cell();

// TODO: sanity checks?
// this should neatly split into fountain_chunks_per_frame() [ex: 10] chunks per frame.
// the other reasonable settings for fountain_chunks_per_frame are `2` and `5`
return (155-ecc) * bitspercell * 10 / fountain_chunks_per_frame();
const unsigned eccBlockSize = 155;
return capacity(bitspercell) * (eccBlockSize-ecc) / eccBlockSize / fountain_chunks_per_frame();
}

unsigned Config::fountain_chunks_per_frame()
Expand Down
5 changes: 4 additions & 1 deletion src/lib/cimb_translator/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ namespace cimbar
unsigned cell_size();
unsigned cell_spacing();
unsigned cell_offset();
unsigned num_cells();
unsigned cells_per_col();
unsigned total_cells();
unsigned capacity(unsigned bitspercell=0);

unsigned corner_padding();
unsigned interleave_blocks();
unsigned interleave_partitions();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/encoder/Decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ inline Decoder::Decoder(int ecc_bytes, int color_bits, bool interleave)
template <typename STREAM>
inline unsigned Decoder::do_decode(CimbReader& reader, STREAM& ostream)
{
bitbuffer bb(13950); // TODO: should vary by _bitsPerOp
bitbuffer bb(cimbar::Config::capacity(_bitsPerOp));
std::vector<unsigned> interleaveLookup = Interleave::interleave_reverse(reader.num_reads(), _interleaveBlocks, _interleavePartitions);
std::array<PositionData, 27900> colorPositions; // 27900 = the number of cells == reader.num_reads(). Can we calculate this at compile time?
std::array<PositionData, 27900> colorPositions; // 27900 = the number of cells == reader.num_reads(). Can we calculate this from config at compile time?

// read symbols first
while (!reader.done())
Expand Down

0 comments on commit c34ae88

Please sign in to comment.