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

Skip to content

Conversation

@sz3
Copy link
Owner

@sz3 sz3 commented Oct 11, 2025

to quote myself from sz3/libcimbar#146

A long-running theme in the development of this "file transfer via the camera" idea is that there's a non-negotiable tradeoff between transfer speed and compatibility. In striving for fast transfers, we must sacrifice some low end devices, and for a 1024x1024 format that means any of device with a 720p camera.

At the same time, for a while I've thought it would be nice to have a smaller format for broader compatibility, even if performance suffers as a result. Some fine folks have even tried to do it themselves: #72

Finally, to put this idea over the edge from "nice to have": the introduction of the web decoder (re.cimbar.org) and the unpredictability of webcam performance means a more robust (even if slower) format will be helpful.

So: for 0.6.3, we'll add an experimental config mode Bm (I think of it as "B mini", or maybe "B minor" if you're music-theory inclined) that should work on a broader variety of cameras. It's a 1024x720 image (vs mode B and 4C's 1024x1024), so it has a fighting chance of working with 720p. It's also the first non-square configuration, which helps make up for some of the resolution loss in overall performance.

As far as usage goes, all you have to do is select "Bm" when using the web encoder (or pass --mode Bm to the cimbar_send cli), and the autodetect logic on the decoder should figure it out.


Code changes:

  • big subtree merge from libcimbar. Most notable/relevant is Config system update for proper runtime configuration libcimbar#143 (config system rewrite), but also includes ... well, everything else. (C api changes aren't currently relevant to this app -- we use the underlying C++ here)
  • added a custom android ToggleButton subclass (ModeSelToggle) for our mode button. Previously I was using a pretty ludicrous hack, repurposing the (seemingly) unused state_activated and hoping for the best. Now things are done the correct way (afaik), with custom state passed to represent our "3 different states of 'on'" on/off button. The result is the same as before: "off" represents autodetect, while "on" shows whatever the current autodetected mode is.
    • or maybe it's the opposite: "on" could mean autodetect is enabled, and "off" means it's not enabled 🤔 🤔 🤔
  • version bump for the upcoming 0.6.3 release

sz3 added 6 commits September 22, 2025 16:56
Autodetect will work for B, 4C, and the new experimental mode Bm.

(using the old 8c icon as a placeholder, but will get that sorted out
shortly)
7561ff0a Update other cli tools to work with new config paradigm
8983eff9 Update cli tools (send/recv) to support new config system
baaa4581 Add a rotate_window (enc) c api call and remove the js-side rotation hack
26b0dc29 weird hacks dept: fix issue where nav button is on top of canvas
736daf64 Shrink mode selection UI to one nav line
905c6390 Add "mode Bm" option to cimbar_send page
98fca1cf Merge pull request #145 from sz3/improve-encode-capi
4086d16f Add a test for the no-op/flush cimbare_encode() usage + ...
7793a330 JS encoder: split file encode into multiple calls, and loop over the file
00a7f472 Reorganizing the encoder c api to (hopefully) lessen OOM errors
a10cbde4 Merge pull request #144 from sz3/simplify-decode-capi
b8b90e1a Actually delete the dead code :)
9b9d523d Fix race condition in test, and add test timeout
e3a3fe5a Fix the js test; fix a bug
d7f669b2 Just use resize event listener, what are we doing man
41bfb600 Switch web decoder to use new C api pattern
55abfdbb The simplified capi for decodes.
cab0eaab I don't think we actually want to store more than one of these at a time.
8d624091 Merge pull request #143 from sz3/config-system-update
f0b16a55 Fix configuration for web encoder/decoder
30d14477 Push more config methods into GridConf so we can query a non-loaded config
4f1be773 Update other grid configs in the new config syntax
73a246cf Lazy eval the config inside the Decoder::decode() functions
49fd1227 Fix tests, fix refactor
92f02cd3 WIP: rewrite of config checks to use static threadlocal
a6a45cd2 fix build warnings

git-subtree-dir: app/src/cpp/libcimbar
git-subtree-split: 7561ff0a3fa8a45d7a753ca9db1137817201f636
Mergin sz3/libcimbar#146, a.k.a
libcimbar:7561ff0a3fa8a45d7a753ca9db1137817201f636. Will be equivalent
to the 0.6.3 libcimbar release.

Includes mode Bm and the new config system
(sz3/libcimbar#143)
int color_correction = legacy_mode? 1 : 2;
unsigned color_mode = legacy_mode? 0 : 1;
unsigned decodeRes = _dec.decode_fountain(img, _writer, color_mode, should_preprocess, color_correction);
int color_correction = modeVal==4? 1 : 2;
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 is a bit of a (minor) footgun that libcimbar probably needs to handle better: color_correction==2 should be (and is) the default, but it doesn't work for the original version of the format (mode 4C). In fact, that's the whole reason mode B exists to begin with...

unsigned modeVal = _modeVal;
if (modeVal == 0)
{
switch (count%3) {
Copy link
Owner Author

@sz3 sz3 Oct 11, 2025

Choose a reason for hiding this comment

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

Instead of mod 2, now we mod 3.

At some number of distinct configs this will fall over, but for now it's still ok to cycle through all configs.

unsigned MultiThreadedDecoder::fountain_chunk_size(int mode_val)
{
return cimbar::Config::fountain_chunk_size(cimbar::Config::ecc_bytes(), cimbar::Config::symbol_bits() + cimbar::Config::color_bits(), mode_val==4);
return cimbar::Config::temp_conf(mode_val).fountain_chunk_size();
Copy link
Owner Author

Choose a reason for hiding this comment

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

Much nicer.

@Override
public void run() {
mModeSwitch.setChecked(true);
mModeSwitch.setModeVal(detectedMode);
Copy link
Owner Author

Choose a reason for hiding this comment

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

Getting rid of the hack.

super(context, attrs);
}

public ModeSelToggle(Context context, AttributeSet attrs, int defStyleAttr) {
Copy link
Owner Author

Choose a reason for hiding this comment

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

Used some LLM-generated code to get the boilerplate right here. My current method is to generate something, take it apart, search the docs/internet, generate it a couple more times (in a fresh context) to see what's different, then manually distill all that into something that doesn't seem like a copypasted stackoverflow answer (not that there's anything wrong with that...)

@Override
protected int[] onCreateDrawableState(int extraSpace) {
// 1. Get the current standard drawable states (includes state_checked)
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
Copy link
Owner Author

Choose a reason for hiding this comment

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

I think +1 should be ok here, but I'm not 100% sure. +2 would be safer but seems (hopefully?) unnecessary.

app:state_modebm="true"
android:drawable="@drawable/ic_modebm"/>

<item android:state_checked="true"
Copy link
Owner Author

@sz3 sz3 Oct 11, 2025

Choose a reason for hiding this comment

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

These are evaluated top to bottom, so the default (as long as it's at the bottom) doesn't need any state_* check.

@sz3 sz3 merged commit 8b714bd into master Oct 17, 2025
@sz3 sz3 deleted the new-config-system branch October 17, 2025 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants