Skip to content

Commit

Permalink
Working towards proper color correction
Browse files Browse the repository at this point in the history
  • Loading branch information
sz3 committed Dec 31, 2023
1 parent 47a221d commit 1786a1d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
24 changes: 24 additions & 0 deletions src/lib/cimb_translator/CimbReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,30 @@ bool CimbReader::done() const
return !_good or _positions.done();
}

void CimbReader::init_ccm()
{
// if no fountain header, we use a simplified von kries matrix?
// or maybe don't bother? Might be easier if we treat it as authoritative (but old),
// rather than having a "good" CCM saved sometimes, but not always.
if (_fountainColorHeader.id() == 0) // & decoder CCM isn't set?
{
//updateColorCorrection(_image, decoder);
return;
}

// should most of this logic go into CimbDecoder?

// full ccm, using header values as known color index
// 1. get positions
// 2. put fountain header into a bitbuffer so we can read decoder.color_bits() bits at a time
// 3. using expected fountain headers, decode color for each position
// 4. sample corners
// 5. group results from #3 and #4 by expected color index, compute avgs
// 6. generate ccm from avgs in #5
// 7. save ccm in decoder. Success! We hope

}

void CimbReader::update_metadata(char* buff, unsigned len)
{
if (len == 0 and _fountainColorHeader.id() == 0)
Expand Down
1 change: 1 addition & 0 deletions src/lib/cimb_translator/CimbReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class CimbReader
unsigned read_color(const PositionData& pos);
bool done() const;

void init_ccm();
void update_metadata(char* buff, unsigned len);

unsigned num_reads() const;
Expand Down
7 changes: 3 additions & 4 deletions src/lib/encoder/Decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,11 @@ inline unsigned Decoder::do_decode(CimbReader& reader, STREAM& ostream)
// flush symbols
reed_solomon_stream rss(ostream, _eccBytes, _eccBlockSize);
symbolBits.flush(rss);

// TODO: get fountain headers out of ostream somehow.
// after we call symbolBits.flush(), the underlying aligned stream (ostream) may have knowledge about
// the fountain headers -- one per chunk (see chunk_size()) -- which we can use to help us with the color decode...
}

// do color correction init, now that we (hopefully) have some fountain headers from the symbol decode
reader.init_ccm();

bitbuffer colorBits(cimbar::Config::capacity(_colorBits));
// then decode colors.
for (const PositionData& p : colorPositions)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/fountain/FountainMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class FountainMetadata

uint32_t id() const
{
uint32_t shortid;
uint32_t shortid = 0;
std::copy(data(), data()+4, reinterpret_cast<uint8_t*>(&shortid));
return shortid;
}
Expand Down

0 comments on commit 1786a1d

Please sign in to comment.