DotCode

DotCode is two-dimensional (2D) matrix barcode invented in 2008 by Hand Held Products company to replace outdated Code 128. At this time, it is issued by Association for Automatic Identification and Mobility (AIM) as “ISS DotCode Symbology Specification 4.0”. DotCode consists of sparse black round dots and white spaces on white background. In case of black background round dots, creating barcode, can be white. DotCode was developed to use with high-speed industrial printers where printing accuracy can be low. Because DotCode by the standard does not require complicated elements like continuous lines or special shapes it can be applied with laser engraving or industrial drills.

DotCode can be represented as rectangular array with minimal size of each side 5X dots. Maximal size of DotCode is not limited by the standard (as Code 128 is not limited) but practical limit is recommended as 100x99 which can encode around 730 digits, 366 alphanumeric characters or 304 bytes.

As an extension of Code 128 barcode, DotCode allows more compact encoding of 8-bit data array and Unicode support with Extended Channel Interpretation feature. Additionally, DotCode provides much more data density and Reed–Solomon error correction which allows to restore partially damaged barcode. However, the main DotCode implementation, the same as Code 128, is effective encoding of GS1 data which is used in worldwide shipping and packaging industry.

History and standards
DotCode barcode was invented in 2008 by Dr. Andrew Longacre from Hand Held Products company and standardized in 2009 by AIM as “Bar code symbology specification - DotCode”. In 2019 DotCode was reviewed as “ISS DotCode Symbology Specification 4.0”.

Set of patents is registered, which are related with DotCode encoding and decoding:
 * United States Patent US20090200386A1 by Hand Held Products Inc "Machine readable 2D symbology printable on demand"
 * United States Patent US20090200386A1 by Datalogic IP Tech SRL "System and method for extracting bitstream data in two-dimensional optical codes"
 * Chinese Patent CN113297872A by Fuzhou Symbol Information Technology Co ltd "Dotcode identification method and equipment"

Application
DotCode barcode can be used in the same way as Code 128 or any (2D) matrix barcode. At this time, it is used mostly to encode GS1 data in tobacco, alcoholic and non-alcoholic beverage, pharmaceutical and grocery industries. The main implementation at this time is in tobacco industry.

Main advantages of DotCode are:
 * Full support and replacement of Code 128 codeset;
 * Compact encoding of 8-bit data array;
 * Unicode support with Extended Channel Interpretation feature;
 * Effective encoding of GS1 data;
 * Reed–Solomon error correction
 * Ability to apply the barcode by high-speed industrial printers and other methods like laser engraving.

Barcode design
DotCode represents data in rectangular structure which consists from black round dots and white spaces on white background or white round dots on black background. DotCode does not have finder pattern, like other 2D barcodes and it must be detected with slow blob detection algorithms like Gabor filter or Circle Hough Transform. All data, metadata and error correction codewords are encoded in the same dots array which does not have any visual difference.

Here are some samples of DotCode:

DotCode symbol is constructed from the following elements:
 * Two mask bits which are represented on diagram as two green points;
 * Data bits (data and error correction bits) which must be read from up to down (even barcode side) and from left to right (odd barcode side);
 * Corner points, marked as red on diagram, which can be used as data bits or padding bits (black dots);
 * Quiet zone at least 3X size of the dots.

The DotCode bits array is represented as: (Two mask bits: M2, M1)(Data bits)(Corner bits, can be data or padding bits: C1 – C6)

The data codewords in 0 – 112 range are encoded in 5-of-9 binary dot patterns which are encoded from 9 dots where 5 black dots and 4 white spaces. The rest of barcode matrix (rest from division on 9) is padded with black padding bits. The padding bits can be from 0 to 8. The logically DotCode bits array is represented as: (2 mask bits)(Data codewords 9 bits each)(Padding bits 0 – 8 bits)

DotCode size has the following requirements:
 * Sum of DotCode width and height must be odd: $$(W + H)\pmod{2} = 1$$;
 * Minimal size of each side must be 5, maximal is not limited;
 * It is recommended to use width and height to have at least 6 padding black bits where data bits capacity rest from division on 9 more or equal 6: $$6 <= (((W * H) / 2) - 2)\pmod{9}$$

Data masking
To minimize DotCode problematic symbols, the data codewords are masked to create others visual sequences. The mask pattern is applied only to data sequence and does not affect error correction codewords. DotCode standard has 4 mask pattern which are codded into 2 bits and placed as the first 2 bits of symbol bits array.

Error correction
DotCode uses Reed–Solomon error correction with prime power of 3 and finite field $$\mathbb{F}_{113}$$ or $GF(113)$. The data codewords is represented with values from 0 to 112 and mask value is counted as leading data codeword from 0 to 3. In this way the data protected array length is (1 + ND). But amount of error correction codewords is calculated only from ND: $$NC = 3 + (ND / 2)$$, where ND is data codewords and NC - error correction codewords.

The resulting codewords NW with error correction codewords is: $$NW = (1 + ND) + NC$$, where NW is all encoding codewords: 1 mask codeword + data codewords(ND) + error correction codewords(NC).

Because Reed–Solomon error correction cannot correct amount of codewords which are more than polynomial, if NW happens to exceed 112, the data is split into error correction blocks: $$B = (NW + 111) / 112$$, where B is block counts.

The data can be split into block in the following way, for each block ‘’’n’’’, for n equals 1 to B:
 * 1) $$ND(block) = ((1+ND) - (n-1) + (B-1)) / B$$
 * 2) $$NW(block) = (NW - (n-1) + (B-1)) / B$$
 * 3) $$NC(block) = NW(block) - ND(block)$$

The error correction data $$NC$$ is written after single data block $$ND$$ in scrambled mode: (ND)(NC1_1)(NC2_1)(NC3_1)...(NC1_n)(NC2_m)(NC3_k)

Encoding
DotCode encoding size is not limited by standard, but practical encoding size in 100x99 version which includes 4950 dots can encode 366 raw data codewords, 730 digits, 365 alphanumeric characters, or 304 bytes. The data message in DotCode is represented with data codewords from 0 to 112 which are encoded with 5-of-9 binary dot patterns.

DotCode supports the following features:
 * Natively encodes digits or ASCII charset (between 0 and 127) with A, B and C code sets and extended ASCII values (128 to 255) with Upper Shift;
 * Effectively encodes bytes (5 bytes into 6 codewords) with Binary Latch;
 * Encodes GS1 data;
 * Encodes Unicode symbols with Extended Channel Interpretation feature;
 * Supports Structured append encoding (logically using multiple barcode symbols as single data stream);
 * Supports “Macro” encoding.

There three main rules at message encoding start:
 * The default starting encoding is Code Set C;
 * In case of two digits in Code Set C (0 – 100 value) are encoded in the position of the first codeword, the message is decoded as GS1 message;
 * If FNC1 (opposite effect to Code 128) or other non-digit codeword (101 - 112) is encoded in the position of the first codeword, the message is decoded as NON GS1 message.

Binary byte encoding
DotCode can encode full 8-bit charset in two ways:
 * With Upper Shift, which requires 2 codewords on one (128 to 255) symbol;
 * With Binary Latch, which requires 1 Binary Latch symbol and 6 codewords on every 5 bytes.

Upper Shift modes can encode (128 to 255) extended ASCII characters in two codewords with returning to previous mode:

Binary Latch mode can encode 8-bit charset and ECI sequences from 1 to 5 symbols. It uses the following rules:
 * The data is split into block of 5 symbols (byte or ECI mode identifier) or 6 codewords;
 * 0 – 258 values are radix converted from five base 259 into six base 103 values;
 * 0 – 255 values are byte values;
 * 256, 257 or 258 values marks to encode ECI sequence in next 1, 2 or 3 bytes respectively;
 * Any DotCode codewords in the encoded sequence above 102 (from 103 to 112) interrupt or change mode.

As we see in the following table, Binary Latch encodes data more effectively, starting from 3 bytes.

ECI encoding
DotCode can encode ECI indicator int two ways:
 * In Binary Latch mode (reviewed upper);
 * With FNC2 character.

FNC2 in any position except at the end of data signals the insertion of an ECI sequence – "\nnnnnn", which represents values between 000000 and 811799. The values can be encoded in 1 or 3 codewords:
 * In case of next codeword < 40 directly encodes ECI value 000000 to 000039;
 * Otherwise, the next three codewords valued A, B, & C encode an ECI value of $$(A - 40) * 12769 + B * 113 + C + 40$$.

GS1 encoding
Any two digits in the position of the first codeword identify a symbol as GS1 encoded (opposite to Code 128). In case of symbol with two digits in the position of the first codeword must be decoded as ordinary data, the FNC1 (omitted in decoded message) must be inserted at the place of the first codeword. FNC1 in the other than the first position works as GS1 Application Identifier splitter and decoded as GS (ASCII value 29) character.

Codeword 100 in Code Set C encodes application GS1 AI (17) the next 3 codewords is an expiration date and inserts GS1 AI (10) before decoding other codewords: (100)(24)(12)(30)(56)(64) -> 17241230105664

Macros mode
Some data codewords 97 – 100 in the lead data position in Code Set B can encode “Macros”. In any other position it encodes ASCII symbol: (Latch B)(HT) -> [)>RS05GS … RSEoT (Shift B)(HT) -> [)>RS05GS … RSEoT

Structured append
DotCode can create composite symbol, where data from multiple DotCode symbols can be logically united. This can be made with FNC2 symbol in last data position. When FNC2 is in the final data position, then the preceding two message characters, digits and uppercase letters in order 1 to 9 then A to Z (for values 10 to 35) shall as "m" and "n" designate where this message belongs in a "m out of n" sequence. As an example, a symbol whose message ends "4 B FNC2" shall be the 4th symbol out of 11 that comprise the entire message.

Special modes encoding
FNC3 in the first codeword position indicates that the message is the instructions for initialization or reprogramming of the bar code reader.

FNC3 in any other position than first indicates that encoded message must be logically separated into two distinct messages (before and after it);

Data padding
DotCode symbol codewords capacity is: $$NW = ((H * W) / 2 - 2) \pmod{9})$$

DotCode symbol data codewords capacity is: $$ND = (NW - 3) - (NW - 3) / 3$$

In this way we need to pad data codewords in case with have free space. There are two rules:
 * Binary mode must be terminated with Latch to Code Set A (codeword 109);
 * In other modes codeword 106 (Latch to Code Set C / Latch to Code Set B) must be used.