-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support new cimbar format "mode B", minor UI change = version 0.6.0f #31
Changes from all commits
e2d01f6
1dcef31
dbc0869
a513177
78a46cc
333b718
818439b
c34d5ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
class MultiThreadedDecoder | ||
{ | ||
public: | ||
MultiThreadedDecoder(std::string data_path, int color_bits); | ||
MultiThreadedDecoder(std::string data_path, bool legacy_mode); | ||
|
||
inline static clock_t bytes = 0; | ||
inline static clock_t perfect = 0; | ||
|
@@ -26,11 +26,10 @@ class MultiThreadedDecoder | |
inline static clock_t extractTicks = 0; | ||
|
||
bool add(cv::Mat mat); | ||
bool decode(const cv::Mat& img, bool should_preprocess); | ||
|
||
void stop(); | ||
|
||
int color_bits() const; | ||
bool legacy_mode() const; | ||
unsigned num_threads() const; | ||
unsigned backlog() const; | ||
unsigned files_in_flight() const; | ||
|
@@ -43,20 +42,20 @@ class MultiThreadedDecoder | |
void save(const cv::Mat& img); | ||
|
||
protected: | ||
int _colorBits; | ||
bool _legacyMode; | ||
Decoder _dec; | ||
unsigned _numThreads; | ||
turbo::thread_pool _pool; | ||
concurrent_fountain_decoder_sink<cimbar::zstd_decompressor<std::ofstream>> _writer; | ||
std::string _dataPath; | ||
}; | ||
|
||
inline MultiThreadedDecoder::MultiThreadedDecoder(std::string data_path, int color_bits) | ||
: _colorBits(color_bits) | ||
, _dec(cimbar::Config::ecc_bytes(), _colorBits) | ||
inline MultiThreadedDecoder::MultiThreadedDecoder(std::string data_path, bool legacy_mode) | ||
: _legacyMode(legacy_mode) | ||
, _dec(cimbar::Config::ecc_bytes(), cimbar::Config::color_bits(), legacy_mode? 0 : 1, legacy_mode) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These ternarys (ternaries?) are kinda gross, but fine for now? |
||
, _numThreads(std::max<int>(((int)std::thread::hardware_concurrency()/2), 1)) | ||
, _pool(_numThreads, 1) | ||
, _writer(data_path, cimbar::Config::fountain_chunk_size(cimbar::Config::ecc_bytes(), cimbar::Config::symbol_bits() + _colorBits)) | ||
, _writer(data_path, cimbar::Config::fountain_chunk_size(cimbar::Config::ecc_bytes(), cimbar::Config::symbol_bits() + cimbar::Config::color_bits(), legacy_mode)) | ||
, _dataPath(data_path) | ||
{ | ||
FountainInit::init(); | ||
|
@@ -97,7 +96,8 @@ inline bool MultiThreadedDecoder::add(cv::Mat mat) | |
// if extracted image is small, we'll need to run some filters on it | ||
clock_t begin = clock(); | ||
bool should_preprocess = (res == Extractor::NEEDS_SHARPEN); | ||
unsigned decodeRes = _dec.decode_fountain(img, _writer, should_preprocess); | ||
int color_correction = _legacyMode? 1 : 2; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notably, this means that mode 4C will not benefit from the color correction matrix generated by mode B. I went back and forth on this, and probably will remove it once mode B is the default (if not sooner 🤔 ). Mode B's CCM will pretty much always be better, if it exists. |
||
unsigned decodeRes = _dec.decode_fountain(img, _writer, should_preprocess, color_correction); | ||
bytes += decodeRes; | ||
++decoded; | ||
decodeTicks += clock() - begin; | ||
|
@@ -107,16 +107,6 @@ inline bool MultiThreadedDecoder::add(cv::Mat mat) | |
} ); | ||
} | ||
|
||
inline bool MultiThreadedDecoder::decode(const cv::Mat& img, bool should_preprocess) | ||
{ | ||
return _pool.try_execute( [&, img, should_preprocess] () { | ||
clock_t begin = clock(); | ||
bytes += _dec.decode_fountain(img, _writer, should_preprocess); | ||
++decoded; | ||
decodeTicks += clock() - begin; | ||
} ); | ||
} | ||
|
||
inline void MultiThreadedDecoder::save(const cv::Mat& mat) | ||
{ | ||
std::stringstream fname; | ||
|
@@ -131,9 +121,9 @@ inline void MultiThreadedDecoder::stop() | |
_pool.stop(); | ||
} | ||
|
||
inline int MultiThreadedDecoder::color_bits() const | ||
inline bool MultiThreadedDecoder::legacy_mode() const | ||
{ | ||
return _colorBits; | ||
return _legacyMode; | ||
} | ||
|
||
inline unsigned MultiThreadedDecoder::num_threads() const | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ namespace { | |
|
||
cv::Scalar color = cv::Scalar(255,255,255); | ||
if (in_progress == 1) | ||
color = cv::Scalar(255,100,100); | ||
color = cv::Scalar(255,244,94); // 0,191,255 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you can see, blue is also an option. I decided to throw our colorblind friends a bone and not use red vs green. |
||
else if (in_progress == 2) | ||
color = cv::Scalar(0,255,0); | ||
cv::Scalar outline = cv::Scalar(0,0,0); | ||
|
@@ -123,8 +123,8 @@ namespace { | |
void drawDebugInfo(cv::Mat& mat, MultiThreadedDecoder& proc) | ||
{ | ||
std::stringstream sstop; | ||
sstop << "cfc using " << proc.num_threads() << " thread(s). " << proc.color_bits() << "..." << proc.backlog() << "? "; | ||
sstop << (MultiThreadedDecoder::bytes / std::max<double>(1, MultiThreadedDecoder::decoded)) << "b v0.5.15"; | ||
sstop << "cfc using " << proc.num_threads() << " thread(s). " << proc.legacy_mode() << "..." << proc.backlog() << "? "; | ||
sstop << (MultiThreadedDecoder::bytes / std::max<double>(1, MultiThreadedDecoder::decoded)) << "b v0.6.0f"; | ||
std::stringstream ssmid; | ||
ssmid << "#: " << MultiThreadedDecoder::perfect << " / " << MultiThreadedDecoder::decoded << " / " << MultiThreadedDecoder::scanned << " / " << _calls; | ||
std::stringstream ssperf; | ||
|
@@ -162,20 +162,21 @@ namespace { | |
|
||
extern "C" { | ||
jstring JNICALL | ||
Java_org_cimbar_camerafilecopy_MainActivity_processImageJNI(JNIEnv *env, jobject instance, jlong matAddr, jstring dataPathObj, jint colorBitsJ) | ||
Java_org_cimbar_camerafilecopy_MainActivity_processImageJNI(JNIEnv *env, jobject instance, jlong matAddr, jstring dataPathObj, jint modeInt) | ||
{ | ||
++_calls; | ||
|
||
// get params from raw address | ||
Mat &mat = *(Mat *) matAddr; | ||
string dataPath = jstring_to_cppstr(env, dataPathObj); | ||
int colorBits = (int)colorBitsJ; | ||
int modeVal = (int)modeInt; | ||
bool legacyMode = modeVal <= 8; // current scheme: old 4c = 4, old 8c = 8, new = bigger number | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These "modeVal" numbers (4, 8, 68) are CFC only at the moment, and might change in the future. libcimbar currently has no such concept, but if we adopt one there we'll probably mirror it here. |
||
|
||
std::shared_ptr<MultiThreadedDecoder> proc; | ||
{ | ||
std::lock_guard<std::mutex> lock(_mutex); | ||
if (!_proc or _proc->color_bits() != colorBits) | ||
_proc = std::make_shared<MultiThreadedDecoder>(dataPath, colorBits); | ||
if (!_proc or _proc->legacy_mode() != legacyMode) | ||
_proc = std::make_shared<MultiThreadedDecoder>(dataPath, legacyMode); | ||
proc = _proc; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't talk about what happened to version 12...
(ok, it's just that the default was
mode B
, and I concluded that might be a problem)