Skip to content
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

Enable binary decoding. #80

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Enable binary decoding. #80

wants to merge 4 commits into from

Conversation

kousu
Copy link
Contributor

@kousu kousu commented Mar 31, 2019

I want to be able to pass binary data through QR codes. qrencode will let me make QR codes like this, but zxing-cpp won't read them: it clips at the first embedded null, and, if iconv is enabled, chokes trying to interpret data as text in some format. There are a lot of fiddly details about transiting between different data encodings and the QR spec doesn't help by being vague on some parts. I've detailed the problems at the sister project
zxing-cpp/zxing-cpp#62

I've decided to patch this in a works-for-me kind of way: unmarked encodings are treated as binary and if that's not good enough the higher layers have the source material and can try decoding it themselves.

This adds a single lone test for this case, which also means it adds tests to the project CI config.

There are a lot of fiddly details about transiting between different
data encodings. And the QR spec is a bit vague on some parts.
I've detailed the problems at the sister project
zxing-cpp/zxing-cpp#62

I've decided to patch this in a works-for-me kind of way:
unmarked encodings are treated as bianry and if that's not
good enough the higher layers have the source material
and can try decoding it themselves.
@kousu
Copy link
Contributor Author

kousu commented Mar 31, 2019

It would be good to import https://github.com/nu-book/zxing-cpp/tree/master/test/blackbox to make sure this hasn't introduced any regressions!

jsQR has a huge corpus too https://github.com/cozmo/jsQR/tree/master/tests/end-to-end

@kousu
Copy link
Contributor Author

kousu commented Apr 2, 2019

For comparison, jsQR outputs both text and binary. You almost do this, returning DecoderResult with both ::getText() and ::getRawBytes(), but the latter is not the same as "binary" because it includes the pre-parsing chunk headers. What I am looking for is something that can give me the unmodified 8-bit payloads of the chunks; your current API gives me. I discovered that compiling with -DNO_ICONV would give me this behaviour, and nothing else would; try it on the test file attached in this PR: the usual zxing'll crop to the first couple bytes because it hits a null almost immediately.

An alternate patch would be to rename ::getRawBytes() with ::getBytes() which behaves the same as jsQR's. But I like having a single output better. I'd rather just be able to control/detect whether I have text or binary.

I think I'd generated my expected output from zxing itself.
This was generated from the source file with
curl https://sampleswap.org//samples-ghost/DRUM%20LOOPS%20and%20BREAKS/161%20to%20180%20bpm/128[kb]161_amenvar3.aif.mp3 | head -c 856 | tee ../tests/amen-01.bin
856 is the packet size qrencode decided to chunk this file into when I first split it up.
@gonce30
Copy link

gonce30 commented Aug 14, 2024

Wi-Fi_QR_code_BATD170521IEFZD (1)

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