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(),
).unwrap();
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 charactes 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).unwrap();
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 no support for GS1/FCN1 character encoding, full ECI, structured append, and 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 part de- and encoding.

Reed-Solomon error correction codes.

Arrangement of bits in a Data Matrix symbol.

Structs

Encoded Data Matrix.

Builder for encoding a Data Matrix with more control.

Set of symbol sizes the encoder is allowed to use.

Enums

Errors when decoding a Data Matrix.

List of data encodation types

The symbol sizes supported by Data Matrix.