Skip to content

Commit 50fb1b3

Browse files
committed
Add toggle for old "4c" mode in the cimbar_js and the cli tools
Somewhat of a misnomer as an option -- might call it just "c" mode eventually (the 4 would be the default number of colors per tile, which can still be overriden to 8)
1 parent 079046b commit 50fb1b3

File tree

6 files changed

+42
-10
lines changed

6 files changed

+42
-10
lines changed

src/exe/cimbar/cimbar.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ namespace {
101101
}
102102

103103
template <typename FilenameIterable>
104-
int encode(const FilenameIterable& infiles, const std::string& outpath, int ecc, int color_bits, int compression_level, bool no_fountain)
104+
int encode(const FilenameIterable& infiles, const std::string& outpath, int ecc, int color_bits, int compression_level, bool legacy_mode, bool no_fountain)
105105
{
106106
Encoder en(ecc, cimbar::Config::symbol_bits(), color_bits);
107107
for (const string& f : infiles)
@@ -179,6 +179,7 @@ int main(int argc, char** argv)
179179
("o,out", "Output file prefix (encoding) or directory (decoding).", cxxopts::value<string>())
180180
("c,color-bits", "Color bits. [0-3]", cxxopts::value<int>()->default_value(turbo::str::str(colorBits)))
181181
("e,ecc", "ECC level", cxxopts::value<unsigned>()->default_value(turbo::str::str(ecc)))
182+
("m,mode", "Select a cimbar mode. B (the default) is new to 0.6.x. 4C is the 0.5.x config. [B,4C]", cxxopts::value<string>()->default_value("B"))
182183
("z,compression", "Compression level. 0 == no compression.", cxxopts::value<int>()->default_value(turbo::str::str(compressionLevel)))
183184
("color-correct", "Toggle decoding color correction. 2 == full (fountain mode only). 1 == simple. 0 == off.", cxxopts::value<int>()->default_value("2"))
184185
("color-correction-file", "Debug -- save color correction matrix generated during fountain decode, or use it for non-fountain decodes", cxxopts::value<string>())
@@ -219,12 +220,19 @@ int main(int argc, char** argv)
219220
compressionLevel = result["compression"].as<int>();
220221
ecc = result["ecc"].as<unsigned>();
221222

223+
bool legacy_mode = false;
224+
if (result.count("mode")
225+
{
226+
string mode = result["mode"].as<string>();
227+
legacy_mode = (mode == "4c") or (mode == "4C");
228+
}
229+
222230
if (encodeFlag)
223231
{
224232
if (useStdin)
225-
return encode(StdinLineReader(), outpath, ecc, colorBits, compressionLevel, no_fountain);
233+
return encode(StdinLineReader(), outpath, ecc, colorBits, compressionLevel, legacy_mode, no_fountain);
226234
else
227-
return encode(infiles, outpath, ecc, colorBits, compressionLevel, no_fountain);
235+
return encode(infiles, outpath, ecc, colorBits, compressionLevel, legacy_mode, no_fountain);
228236
}
229237

230238
// else, decode
@@ -236,7 +244,9 @@ int main(int argc, char** argv)
236244
color_correction_file = result["color-correction-file"].as<string>();
237245
int preprocess = result["preprocess"].as<int>();
238246

239-
Decoder d(ecc, colorBits);
247+
unsigned color_mode = legacy_mode? 0 : 1;
248+
bool coupled = legacy_mode;
249+
Decoder d(ecc, colorBits, color_mode, coupled);
240250

241251
if (no_fountain)
242252
{

src/exe/cimbar_recv/recv.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ int main(int argc, char** argv)
4444
("c,colorbits", "Color bits. [0-3]", cxxopts::value<int>()->default_value(turbo::str::str(colorBits)))
4545
("e,ecc", "ECC level", cxxopts::value<unsigned>()->default_value(turbo::str::str(ecc)))
4646
("f,fps", "Target decode FPS", cxxopts::value<unsigned>()->default_value(turbo::str::str(defaultFps)))
47+
("m,mode", "Select a cimbar mode. B (the default) is new to 0.6.x. 4C is the 0.5.x config. [B,4C]", cxxopts::value<string>()->default_value("B"))
4748
("h,help", "Print usage")
4849
;
4950
options.show_positional_help();
@@ -62,6 +63,14 @@ int main(int argc, char** argv)
6263

6364
colorBits = std::min(3, result["colorbits"].as<int>());
6465
ecc = result["ecc"].as<unsigned>();
66+
67+
bool legacy_mode = false;
68+
if (result.count("mode")
69+
{
70+
string mode = result["mode"].as<string>();
71+
legacy_mode = (mode == "4c") or (mode == "4C");
72+
}
73+
6574
unsigned fps = result["fps"].as<unsigned>();
6675
if (fps == 0)
6776
fps = defaultFps;
@@ -95,7 +104,8 @@ int main(int argc, char** argv)
95104
window.auto_scale_to_window();
96105

97106
Extractor ext;
98-
Decoder dec;
107+
unsigned color_mode = legacy_mode? 0 : 1;
108+
Decoder dec(-1, -1, color_mode, legacy_mode);
99109

100110
unsigned chunkSize = cimbar::Config::fountain_chunk_size(ecc, colorBits+cimbar::Config::symbol_bits());
101111
fountain_decoder_sink<cimbar::zstd_decompressor<std::ofstream>> sink(outpath, chunkSize);

src/exe/cimbar_send/send.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ int main(int argc, char** argv)
4242
("c,colorbits", "Color bits. [0-3]", cxxopts::value<int>()->default_value(turbo::str::str(colorBits)))
4343
("e,ecc", "ECC level", cxxopts::value<unsigned>()->default_value(turbo::str::str(ecc)))
4444
("f,fps", "Target FPS", cxxopts::value<unsigned>()->default_value(turbo::str::str(defaultFps)))
45+
("m,mode", "Select a cimbar mode. B (the default) is new to 0.6.x. 4C is the 0.5.x config. [B,4C]", cxxopts::value<string>()->default_value("B"))
4546
("z,compression", "Compression level. 0 == no compression.", cxxopts::value<int>()->default_value(turbo::str::str(compressionLevel)))
4647
("h,help", "Print usage")
4748
;
@@ -61,6 +62,14 @@ int main(int argc, char** argv)
6162
colorBits = std::min(3, result["colorbits"].as<int>());
6263
compressionLevel = result["compression"].as<int>();
6364
ecc = result["ecc"].as<unsigned>();
65+
66+
bool legacy_mode = false;
67+
if (result.count("mode")
68+
{
69+
string mode = result["mode"].as<string>();
70+
legacy_mode = (mode == "4c") or (mode == "4C");
71+
}
72+
6473
unsigned fps = result["fps"].as<unsigned>();
6574
if (fps == 0)
6675
fps = defaultFps;
@@ -73,7 +82,7 @@ int main(int argc, char** argv)
7382
return 70;
7483
}
7584

76-
configure(colorBits, ecc, compressionLevel);
85+
configure(colorBits, ecc, compressionLevel, legacy_mode);
7786

7887
std::chrono::time_point start = std::chrono::high_resolution_clock::now();
7988
while (true)

src/lib/cimbar_js/cimbar_js.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace {
2222
unsigned _ecc = cimbar::Config::ecc_bytes();
2323
unsigned _colorBits = cimbar::Config::color_bits();
2424
int _compressionLevel = cimbar::Config::compression_level();
25+
bool _legacyMode = false;
2526
}
2627

2728
extern "C" {
@@ -109,16 +110,18 @@ int encode(unsigned char* buffer, unsigned size, int encode_id)
109110
return 1;
110111
}
111112

112-
int configure(unsigned color_bits, unsigned ecc, int compression)
113+
int configure(unsigned color_bits, unsigned ecc, int compression, bool legacy_mode)
113114
{
114115
// defaults
115116
if (color_bits > 3)
116117
color_bits = cimbar::Config::color_bits();
117-
if (ecc < 0 or ecc >= 150)
118+
if (ecc >= 150)
118119
ecc = cimbar::Config::ecc_bytes();
119120
if (compression < 0 or compression > 22)
120121
compression = cimbar::Config::compression_level();
121122

123+
_legacyMode = legacy_mode; // legacy mode shouldn't need a refresh, so just change it
124+
122125
// check if we need to refresh the stream
123126
bool refresh = (color_bits != _colorBits or ecc != _ecc or compression != _compressionLevel);
124127
if (refresh)

src/lib/cimbar_js/cimbar_js.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int initialize_GL(int width, int height);
1010
int render();
1111
int next_frame();
1212
int encode(unsigned char* buffer, unsigned size, int encode_id); // encode_id == -1 -> auto-increment
13-
int configure(unsigned color_bits, unsigned ecc, int compression);
13+
int configure(unsigned color_bits, unsigned ecc, int compression, bool legacy_mode);
1414

1515
#ifdef __cplusplus
1616
}

web/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ return {
156156

157157
setColorBits : function(color_bits)
158158
{
159-
Module._configure(color_bits, 255, 255);
159+
Module._configure(color_bits, 255, 255, true);
160160

161161
var nav = document.getElementById("nav-container");
162162
if (color_bits == 2) {

0 commit comments

Comments
 (0)