qrkit/decode
Decode a QR module matrix back into text.
from_rows reads a Standard QR, Micro QR or rMQR symbol given as rows of
modules (True is dark), the shape qrkit.rows returns. A light quiet
zone around the symbol is removed first, and the symbol may be rotated or
mirrored. Damaged codewords are repaired with Reed-Solomon error
correction up to the level’s capacity.
This reads a grid of modules, not a photo: locating a symbol in a camera image, perspective correction and thresholding are out of scope.
import qrkit
import qrkit/decode
pub fn round_trip() -> Result(String, Nil) {
let assert Ok(qr) = qrkit.encode("https://example.com")
case decode.from_rows(qrkit.rows(qr)) {
Ok(decoded) -> Ok(decode.text(decoded))
Error(_) -> Error(Nil)
}
}
Types
The Structured Append header of a symbol that is one part of a split
message: its 0-based position, the total number of symbols, and the
parity byte of the whole message.
pub type StructuredAppend {
StructuredAppend(position: Int, total: Int, parity: Int)
}
Constructors
-
StructuredAppend(position: Int, total: Int, parity: Int)
Values
pub fn eci(decoded: Decoded) -> option.Option(Int)
The last ECI designator in the data, if any.
pub fn error_correction(
decoded: Decoded,
) -> types.ErrorCorrection
The error correction level from the format information.
pub fn errors_corrected(decoded: Decoded) -> Int
How many codewords Reed-Solomon error correction repaired.
pub fn from_rows(
rows: List(List(Bool)),
) -> Result(Decoded, error.DecodeError)
Decode a symbol given as rows of modules, True for dark.
pub fn mask(decoded: Decoded) -> Int
The data mask from the format information (always 4 for rMQR, whose mask is fixed).
pub fn structured_append(
decoded: Decoded,
) -> option.Option(StructuredAppend)
The Structured Append header, if the symbol is part of a split message.