Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/exe/cimbar/cimbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ int main(int argc, char** argv)
("n,encode", "Run the encoder!", cxxopts::value<bool>())
("i,in", "Encoded pngs/jpgs/etc (for decode), or file to encode", cxxopts::value<vector<string>>())
("o,out", "Output file prefix (encoding) or directory (decoding).", cxxopts::value<string>())
("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"))
("m,mode", "Select a cimbar mode. B (the default) is new to 0.6.x. 4C is the 0.5.x config. [B,Bm,4C]", cxxopts::value<string>()->default_value("B"))
("z,compression", "Compression level. 0 == no compression.", cxxopts::value<int>()->default_value(turbo::str::str(compressionLevel)))
("color-correct", "Toggle decoding color correction. 2 == full (fountain mode only). 1 == simple. 0 == off.", cxxopts::value<int>()->default_value("2"))
("color-correction-file", "Debug -- save color correction matrix generated during fountain decode, or use it for non-fountain decodes", cxxopts::value<string>())
Expand Down Expand Up @@ -224,15 +224,20 @@ int main(int argc, char** argv)
bool no_fountain = result.count("no-fountain");

compressionLevel = result["compression"].as<int>();

// set config
unsigned config_mode = 68;
if (result.count("mode"))
{
string mode = result["mode"].as<string>();
int modeVal = 68;
if (mode == "4" or mode == "4c" or mode == "4C")
modeVal = 4;
cimbar::Config::update(modeVal);
config_mode = 4;
else if (mode == "8c" or mode == "8C")
config_mode = 8;
else if (mode == "Bm" or mode == "BM")
config_mode = 67;
}
cimbar::Config::update(config_mode);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit of code is duplicated a few places. Probably time to split it out (realistically: next time I add a new config)


if (encodeFlag)
{
Expand Down
17 changes: 14 additions & 3 deletions src/exe/cimbar_extract/cimbar_extract.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* This code is subject to the terms of the Mozilla Public License, v.2.0. http://mozilla.org/MPL/2.0/. */
#include "cimb_translator/Config.h"
#include "extractor/ExtractorPlus.h"

#include "cxxopts/cxxopts.hpp"
Expand All @@ -13,7 +14,7 @@ int main(int argc, char** argv)
options.add_options()
("i,in", "Encoded png/jpg/etc", cxxopts::value<std::string>())
("o,out", "Output image", cxxopts::value<std::string>())
("d,dark", "Dark mode", cxxopts::value<bool>()->default_value("true"))
("m,mode", "Select a cimbar mode. B (the default) is new to 0.6.x. 4C is the 0.5.x config. [B,Bm,4C]", cxxopts::value<string>()->default_value("B"))
("h,help", "Print usage")
;
options.show_positional_help();
Expand All @@ -27,10 +28,20 @@ int main(int argc, char** argv)
exit(0);
}

// really, you only need to supply mode for non 1024x1024 configs
unsigned config_mode = 68;
if (result.count("mode"))
{
string mode = result["mode"].as<string>();
if (mode == "4c" or mode == "4C")
config_mode = 4;
else if (mode == "Bm" or mode == "BM")
config_mode = 67;
}
cimbar::Config::update(config_mode);

std::string infile = result["in"].as<std::string>();
std::string outfile = result["out"].as<std::string>();
bool dark = result["dark"].as<bool>();

ExtractorPlus ext;
if (!ext.extract(infile, outfile))
return 1;
Expand Down
13 changes: 8 additions & 5 deletions src/exe/cimbar_recv/recv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int main(int argc, char** argv)
("c,colorbits", "Color bits. [0-3]", cxxopts::value<int>()->default_value(turbo::str::str(colorBits)))
("e,ecc", "ECC level", cxxopts::value<unsigned>()->default_value(turbo::str::str(ecc)))
("f,fps", "Target decode FPS", cxxopts::value<unsigned>()->default_value(turbo::str::str(defaultFps)))
("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"))
("m,mode", "Select a cimbar mode. B (the default) is new to 0.6.x. 4C is the 0.5.x config. [B,Bm,4C]", cxxopts::value<string>()->default_value("B"))
("h,help", "Print usage")
;
options.show_positional_help();
Expand All @@ -65,13 +65,16 @@ int main(int argc, char** argv)
colorBits = std::min(3, result["colorbits"].as<int>());
ecc = result["ecc"].as<unsigned>();

bool legacy_mode = false;
unsigned config_mode = 68;
if (result.count("mode"))
{
string mode = result["mode"].as<string>();
legacy_mode = (mode == "4c") or (mode == "4C");
if (mode == "4c" or mode == "4C")
config_mode = 4;
else if (mode == "Bm" or mode == "BM")
config_mode = 67;
}
unsigned color_mode = legacy_mode? 0 : 1;
cimbar::Config::update(config_mode);

unsigned fps = result["fps"].as<unsigned>();
if (fps == 0)
Expand Down Expand Up @@ -148,7 +151,7 @@ int main(int argc, char** argv)
shouldPreprocess = true;

// decode
int bytes = dec.decode_fountain(img, sink, color_mode, shouldPreprocess);
int bytes = dec.decode_fountain(img, sink, shouldPreprocess);
if (bytes > 0)
std::cerr << "got some bytes " << bytes << std::endl;

Expand Down
6 changes: 4 additions & 2 deletions src/exe/cimbar_recv2/recv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main(int argc, char** argv)
("i,in", "Video source.", cxxopts::value<string>())
("o,out", "Output directory (decoding).", cxxopts::value<string>())
("f,fps", "Target decode FPS", cxxopts::value<unsigned>()->default_value(turbo::str::str(defaultFps)))
("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"))
("m,mode", "Select a cimbar mode. B (the default) is new to 0.6.x. 4C is the 0.5.x config. [B,Bm,4C]", cxxopts::value<string>()->default_value("B"))
("h,help", "Print usage")
;
options.show_positional_help();
Expand All @@ -65,8 +65,10 @@ int main(int argc, char** argv)
if (result.count("mode"))
{
string mode = result["mode"].as<string>();
if (mode == "4" or mode == "4c" or mode == "4C")
if (mode == "4c" or mode == "4C")
config_mode = 4;
else if (mode == "Bm" or mode == "BM")
config_mode = 67;
}

unsigned fps = result["fps"].as<unsigned>();
Expand Down
4 changes: 3 additions & 1 deletion src/exe/cimbar_send/send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int main(int argc, char** argv)
("c,colorbits", "Color bits. [0-3]", cxxopts::value<int>()->default_value(turbo::str::str(colorBits)))
("e,ecc", "ECC level", cxxopts::value<unsigned>()->default_value(turbo::str::str(ecc)))
("f,fps", "Target FPS", cxxopts::value<unsigned>()->default_value(turbo::str::str(defaultFps)))
("m,mode", "Select a cimbar mode. B is new to 0.6.x. 4C is the 0.5.x config. [B,4C]", cxxopts::value<string>()->default_value("4C"))
("m,mode", "Select a cimbar mode. B is new to 0.6.x. 4C is the 0.5.x config. [B,Bm,4C]", cxxopts::value<string>()->default_value("4C"))
("z,compression", "Compression level. 0 == no compression.", cxxopts::value<int>()->default_value(turbo::str::str(compressionLevel)))
("h,help", "Print usage")
;
Expand All @@ -69,6 +69,8 @@ int main(int argc, char** argv)
string mode = result["mode"].as<string>();
if (mode == "4c" or mode == "4C")
config_mode = 4;
else if (mode == "Bm" or mode == "BM")
config_mode = 67;
}

unsigned fps = result["fps"].as<unsigned>();
Expand Down
1 change: 1 addition & 0 deletions src/lib/cimbar_js/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ set (LINK_WASM_EXPORTED_FUNCTIONS
, "_cimbare_encode"
, "_cimbare_encode_bufsize"
, "_cimbare_configure"
, "_cimbare_rotate_window"
, "_cimbare_get_aspect_ratio"
)

Expand Down
18 changes: 15 additions & 3 deletions src/lib/cimbar_js/cimbar_js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ int cimbare_init_window(int width, int height)
return 0;
}

int cimbare_rotate_window(bool rotate)
{
if (!_window or !_window->is_good())
return -1;

_window->rotate(0);
if (rotate) // 90 degrees
{
_window->rotate();
_window->rotate();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing rotation implementation has a weird rotation order due to what I initially implemented it for (an alternative attempt at the "shakycam" jitter we use to fast-fail bad frames). So 90 degrees is 2 "rotations", even though that makes no sense. (will probably change it to act normal in a followup)

}
return 0;
}

bool cimbare_auto_scale_window()
{
if (!_window or !_window->is_good())
Expand Down Expand Up @@ -181,9 +195,7 @@ int cimbare_encode(const unsigned char* buffer, unsigned size)

int cimbare_configure(int mode_val, int compression)
{
// defaults
if (mode_val == 0)
mode_val = 68;
cimbar::Config::update(mode_val);
if (compression < 0 or compression > 22)
compression = cimbar::Config::compression_level();

Expand Down
1 change: 1 addition & 0 deletions src/lib/cimbar_js/cimbar_js.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "C" {
#endif

int cimbare_init_window(int width, int height);
int cimbare_rotate_window(bool rotate);
int cimbare_render();
int cimbare_next_frame();
int cimbare_init_encode(const char* filename, unsigned fnsize, int encode_id);
Expand Down
8 changes: 7 additions & 1 deletion src/lib/gui/window_glfw.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class window_glfw
glfwMakeContextCurrent(_w);
glfwSwapInterval(1);

_display = std::make_shared<cimbar::gl_2d_display>(std::min(width, height));
_display = std::make_shared<cimbar::gl_2d_display>(std::max(width, height));
glGenTextures(1, &_texid);
init_opengl(width, height);
}
Expand Down Expand Up @@ -72,7 +72,13 @@ class window_glfw
void resize(unsigned width, unsigned height)
{
if (_w)
{
_width = width;
_height = height;
glfwSetWindowAspectRatio(_w, width, height);
glfwSetWindowSize(_w, width, height);
init_opengl(width, height);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resize() has to be a bit smarter now...

}
}

void rotate(unsigned i=1)
Expand Down
32 changes: 18 additions & 14 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@
color: #F0F0F0;
outline: 6px solid black;
box-shadow: 0px 0px 12px black, 0px 0px 18px black;
transform-origin: 0;
transition: transform 0.3s;
}

.dragdrop::before {
Expand All @@ -73,15 +71,6 @@
left: 0;
text-align: center;
width: 100%;
transform-origin: center center;
transition: transform 0.3s;
}

.dragdrop.rotated::before {
width: 100vh;
left: 0;
top: 0;
transform: rotate(-90deg) translateX(-20%) translateY(-5em);
}

.dragdrop.error:before {
Expand All @@ -105,11 +94,13 @@

/* options */
#nav-container a.mode-b,
#nav-container a.mode-bm,
#nav-container a.mode-4c {
color: #555;
}

#nav-container.mode-b a.mode-b,
#nav-container.mode-bm a.mode-bm,
#nav-container.mode-4c a.mode-4c {
color: #9fa6b2;
}
Expand Down Expand Up @@ -293,6 +284,16 @@
font-size: 2em;
}

#nav-content h4 {
font-variant: small-caps;
padding-top: 1em;
}

#nav-content li.modesel a {
display: inline-block;
width: 2em;
}

#nav-content li:hover {
background-color: #2c323c;
}
Expand Down Expand Up @@ -343,11 +344,14 @@
<ul>
<li><a class="attention" id="nav-find-file-link" href="javascript:void(0)" onclick="Main.clickFileInput()">Find
File</a></li>
<li><a href="javascript:void(0)" onclick="Main.toggleFullscreen()">Fullscreen</a></li>
<hr>
<li><a class="mode-b" href="javascript:void(0)" onclick="Main.setMode('B')">Mode B</a></li>
<li><a class="mode-4c" href="javascript:void(0)" onclick="Main.setMode('4C')">4C <small>(old apps)</small></a>
<li class="modesel">
<h4>Mode</h4>
<a class="mode-b" href="javascript:void(0)" onclick="Main.setMode('B')">B</a>
<a class="mode-bm" href="javascript:void(0)" onclick="Main.setMode('Bm')">Bm</a>
<a class="mode-4c" href="javascript:void(0)" onclick="Main.setMode('4C')">4C</a>
</li>
<li class="small"><a href="javascript:void(0)" onclick="Main.toggleFullscreen()">Fullscreen</a></li>
<li class="small"><a href="https://github.com/sz3/libcimbar">github</a></li>
<li class="small"><a href="https://github.com/sz3/cfc/releases/latest">android app</a></li>
</ul>
Expand Down
43 changes: 25 additions & 18 deletions web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ var Main = function () {
return {
init: function (canvas) {
Main.setMode('B');
Main.resize();
Main.check_GL_enabled(canvas);
},

Expand Down Expand Up @@ -114,6 +113,8 @@ var Main = function () {
// using ratio from current config,
// determine optimal dimensions and rotation
var needRotate = _idealRatio > 1 && height > width;
Module._cimbare_rotate_window(needRotate);

var ourRatio = needRotate ? height / width : width / height;

var xdim = needRotate ? height : width;
Expand All @@ -126,22 +127,13 @@ var Main = function () {
}

console.log(xdim + "x" + ydim);
canvas.style.width = xdim + "px";
canvas.style.height = ydim + "px";
if (needRotate) {
// TODO: rotating #dragdrop around the center doesn't work for inane
// css reasons. So here's a hack to move it where it should be. css sucks.
// if at some point this is understood/fixed, we should define a static css rule
// to match against `.rotated`
var translate = -Math.floor(width / 2) - Math.floor(width / 96) + "px";
var dragdrop = document.getElementById('dragdrop');
dragdrop.style.transform = "rotate(90deg) translateX(-50%) translateY(" + translate + ")";
dragdrop.classList.add("rotated");
canvas.style.width = ydim + "px";
canvas.style.height = xdim + "px";
}
else {
var dragdrop = document.getElementById('dragdrop');
dragdrop.style.transform = "";
dragdrop.classList.remove("rotated");
canvas.style.width = xdim + "px";
canvas.style.height = ydim + "px";
}
},

Expand Down Expand Up @@ -221,8 +213,9 @@ var Main = function () {
fileInput: function (ev) {
console.log("file input: " + ev);
var file = document.getElementById('file_input').files[0];
if (file)
if (file) {
importFile(file);
}
Main.blurNav(false);
},

Expand Down Expand Up @@ -255,20 +248,34 @@ var Main = function () {
},

setMode: function (mode_str) {
const modeVal = (mode_str == "4C") ? 4 : 68;
Module._cimbare_configure(modeVal, 255);
let modeVal = 68;
if (mode_str == "4C") {
modeVal = 4;
}
else if (mode_str == "Bm") {
modeVal = 67;
}
Module._cimbare_configure(modeVal, -1);
_idealRatio = Module._cimbare_get_aspect_ratio();
Main.resize();

var nav = document.getElementById("nav-container");
if (modeVal == 4) {
nav.classList.remove("mode-b");
nav.classList.add("mode-4c");
} else if (mode_str == "B") {
nav.classList.remove("mode-b");
nav.classList.remove("mode-bm");
} else if (modeVal == 68) {
nav.classList.add("mode-b");
nav.classList.remove("mode-bm");
nav.classList.remove("mode-4c");
} else if (modeVal == 67) {
nav.classList.add("mode-bm");
nav.classList.remove("mode-b");
nav.classList.remove("mode-4c");
} else {
nav.classList.remove("mode-b");
nav.classList.remove("mode-bm");
nav.classList.remove("mode-4c");
}
},
Expand Down
Loading