I've always been intrigued by the QRCodes. It fascinating how fast you can read a QRCode using your phone. Reading a QRCode is way more complex than creating one. You have to take into account rotation, skew or even missing parts, on a portable device.
Reading a QRCode being way harder, I invested time into creating QRCode. I have put around six month on cargo fast_qr
and npm fast_qr
. Getting to fast execution time, it recently became 9x faster than the most used crate
in the Rust community. I'm happy.
I have learned a lot about QRCodes, and I want to share my knowledge. This is a very good portfolio projet, so I will make a blog post about it.
A QRCode is a representation of data allowing a camera to pickup it's content. We could use an OCR
to read an URL. However, this method is way more sensitive to case, image distortions or text font. Also, QRCodes can contain various type of data. We could store pretty much any data a decoder can understand.
QRCodes have multiple versions (sizes), multiple encoding levels (quality), and multiple data encodings (content types).
Each will have a great inpact in the resulting QRCode. Versions are ranging from 1 to 40 (both included). ECL (encoding levels) are Low, Medium, Quartile and High, respectively 7%, 15%, 25%, 30% of damage can be recovered. Knowing that, we know how many byte we can store
Data encodings are Numerical, AlphaNumerical, Byte and Kanji, respectively a string representation of a number, uppercase-alphabet and number, byte (any data) and kanji characters.
You can find a table including how many characters can be encoded
in each variant.
If you are here to create your own QRCode generator, your journey begins here.
We will make a QRCode of version 5
and ECL H
and mode Byte
(working for any data). But in the end, any combinaison will work, as long as you know how to encode it. (Which can be found in the standard, part 8.3)
QRCode has a specification as you might have imagined. I will be refering to this one
for the remaining time.