Crate datamatrix

Source
Expand description

Data Matrix (ECC 200) decoding and encoding library with an optimizing encoder.

§Usage example

let code = DataMatrix::encode(
    b"Hello, World!",
    SymbolList::default(),
)?;
print!("{}", code.bitmap().unicode());

This toy example will print a Data Matrix using Unicode block characters. For guidance on how to generate other output formats see the helper functions defined for the Bitmap struct, or the examples/ directory of this project.

You can specify other symbol sizes, see SymbolList for details.

§Character encoding notes for Data Matrix

TL;DR Data should be printable ASCII because many decoders lack a proper charset handling. Latin 1 is the next best choice, otherwise you rely on auto detection hacks of decoders. This does not apply if you have control over decoding or if you are not overly paranoidal.

This full section also applies to QR codes.

Be careful when encoding strings which contain non printable ASCII characters. While indicating for example UTF-8 encoding is possible through ECI, we doubt that many decoders around the world implement this. Also notice that some decoders are used as a keyboard source (e.g., handheld scanners) which may be constrained by platform/locale specific keyboard layouts with limited Unicode input capabilities. We therefore recommend to stay within the printable ASCII characters unless you have control over the full encoding and decoding process.

The Data Matrix specification defines ISO 8859-1 (Latin-1) as the standard charset. Our tests indicate that some decoders (smartphone scanner apps) are reluctant to follow this and return binary output if there are characters in the upper range, which is a safe choice. Unfortunately, some decoders try to guess the charset or just always assume UTF-8.

The full 8bit range can be encoded and the decoder will also return this exact input. So the problems mentioned above are related to the interpretation of the data and possible input limitations in the case of handheld scanners.

§Decoding

Assuming you have detected a Data Matrix you may decode the message like this:

// let pixels: Vec<bool> = …
let width = 16;
let data = DataMatrix::decode(&pixels, width)?;
assert_eq!(&data, b"Hello, World!");

§Current limitations

No visual detection is currently implemented, but the decoding backend is done and exposed in the API. All that is missing is a detector to extract a matrix of true and false values from an image. A general purpose detector is planned for the future, though.

Other limitations: Currently there is only limited support for GS1/FNC1 character encoding, limited ECI encoding, no structured append, and no reader programming. The decoding output format specified in ISO/IEC 15424 is also not implemented (metadata, ECI, etc.), if you have a use case for this please open an issue.

Modules§

data
Data part de- and encoding.
errorcode
Reed-Solomon error correction codes.
placement
Arrangement of bits in a Data Matrix symbol.

Structs§

DataMatrix
Encoded Data Matrix.
DataMatrixBuilder
Builder for encoding a Data Matrix with more control.
SymbolList
Set of symbol sizes the encoder is allowed to use.

Enums§

DecodingError
Errors when decoding a Data Matrix.
EncodationType
List of data encodation types
SymbolSize
The symbol sizes supported by Data Matrix.