#codec #no-std #codematrix #semacode

no-std datamatrix

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

10 releases

0.3.0 Feb 13, 2022
0.2.1 Jul 11, 2021
0.1.1 May 24, 2021
0.1.0-beta.2 Feb 8, 2021
0.1.0-alpha.2 Jan 31, 2021

#1207 in Encoding

Download history 67/week @ 2023-12-14 10/week @ 2023-12-21 4/week @ 2023-12-28 51/week @ 2024-01-04 99/week @ 2024-01-11 127/week @ 2024-01-18 140/week @ 2024-01-25 71/week @ 2024-02-01 97/week @ 2024-02-08 64/week @ 2024-02-15 67/week @ 2024-02-22 68/week @ 2024-02-29 110/week @ 2024-03-07 75/week @ 2024-03-14 88/week @ 2024-03-21 52/week @ 2024-03-28

335 downloads per month

Apache-2.0 OR MIT

290KB
7K SLoC

datamatrix-rs

crates.io Documentation License Lines of Code

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

Data Matrix encoding 'datamatrix-rs'

This library features an optimzing, and linear time encoder which achieves the smallest possible encoding size.

The Data Matrix standard (ISO/IEC 16022:2006) contains a heuristic to decide which encoding modes to use, and in most cases that works. A straightforward implementation will not have linear runtime, though. This library uses an idea similar to the A* algorithm.

The optimizer is special about this implementation, most implementations use the heuristic. See the list of related projects below for credits and references to other open source Data Matrix libraries.

Example

let code = DataMatrix::encode(
    b"Hello, World!",
    SymbolList::default(),
).unwrap();

// print an "ASCII art" version
print!("{}", code.bitmap().unicode());

The library contains helpers for generating other output formats. Example code can be found in examples/. The extra effort for this last rendering step is usually low and this approach allows high flexibility.

Status

  • Encodation modes ASCII, Base256, C40, Text, X12, EDIFACT implemented.
  • Optimizer for switching between encodation modes to find a minimal encodation size.
  • Data part decoding.
  • Fuzzed data de- and encoding (no issues after 48h)
  • Check the open bug reports in other implementations.
  • Reed Solomon de-/encoder.
  • Tile placement encoding.
  • Helpers for rendering
  • Implement Extended Rectangular Data Matrix (DMRE) defined in ISO 21471 which adds more rectangular symbol sizes
  • Tile placement decoding.
  • Visual detection in images.
  • More detailed decoder output.
  • ECI support. This has progressed as far as I could get without buying the standards for this (several hundred dollars).

Things in consideration for after that:

  • "Structured Append"
  • "Reader Programming"

Disclaimer

Since the encoded data is padded to fill up the remaining space in a Data Matrix symbol, the symbol generated by this library will in many cases not be smaller compared to an optimizer based on the heuristic defined in the specification. What it achieves however in any case is a linear encoding time, and it avoids some of the bugs which can be attributed to using the heuristic (see open bugs in zxing and OkapiBarcode). And, of course, there are cases where it will return a smaller symbol altough admittedly no thorough study of this has been done.

The following projects were invaluable for learning from their implementation and stealing some of their test cases and bug reports.

  • zxing is a Google library to encode and decode multiple 1D and 2D codes including Data Matrix. The core part is written in Java. It uses the heuristic from the specification.
  • barcode4j is a predecessor (?) of zxing, the Data Matrix code was forked into zxing.
  • libdmtx is the most prominent open source C library for encoding and decoding Data Matrix. It has a more limited optimizer compared to the specification, but it can also decode Data Matric codes from images.
  • zxing-cpp is a C++ port of zxing, it also contains some improvements.
  • OkapiBarcode is a Java library with Data Matrix encoding support, among dozens of other codes! The implementation seems to follow the standard.
  • OkapiBarcode is ported from (?) the zint C library. Ports to Pascal and C# are referenced on their website. Off topic: There are encoders for some nice vintage codes and discontinued commercial codes, see "Extras" on the website.
  • postscriptbarcode implements encoding of several 1D and 2D codes using only PostScript. It is also available as a LaTeX package. Port to JavaScript.
  • A perl module for encoding.
  • iec16022 is a Data Matrix encoder originally written by Andrews & Arnold Ltd. but is now maintained by Reimar Döffinger. It has a similar optimizing encoder.

Dependencies

~0.1–0.9MB
~31K SLoC