French version

Le QR code.



This code is part of the family of 2-dimensional codes, it can encode up to 7089 characters on a very small surface. The encoding is done in two steps : first the datas are converted into a bit stream cut into codewords. (High level encoding) then these are converted into small black and white squares. In addition, an error correction system makes it possible to reconstruct badly printed, erased, fuzzy or torn off datas. In the remainder of this presentation, the term "codeword" will be abbreviated to CW and Reed-Solomon code in RS. There are also micro QR codes not studied here.

The general structure.

Low level encoding.
There are 40 versions (Sizes) of symbol. A set of parameters is attached to each version : From these parameters we can calculate other values, this is done using a spreadsheet :
We will find the calculation of the size of the symbol, the number and location of alignment patterns, the areas occupied by the various elements, etc ...

To build a QRcode you need :

High level encoding.
We will use the following operators : + -> addition, x -> multiplication, \ -> integer division, MOD -> rest of the whole division
There are 4 encoding modes (Compression) that can be mixed :
Compression mode Data to be encoded Compression rate Mode indicator Numeric ASCII digits 3 digits in 10 bits 0001 Alphanumeric Digits + capital letters + 9 symbols 2 characters in 11 bits 0010 Byte Byte 1 byte in 8 bits 0100 Kanji Asian characters / 1000
There are other indicators not studied here: 0111 = ECI, 0011 = Multi codes, 0101 et 1001 = FNC1
0000 indicate the end of datas.
Each segment begins with a 4-bit mode indicator followed by the number of characters encoded on a variable bit number (see table), followed by the datas.
Detection and correction of errors.
Bar code making.
Since we can create the bar code pattern it remains us to draw it on the screen and to print it on a paper sheet. Two approaches are possibles : It seems there is no free fontfor datamatrix barcode on the net. I've decided consequently to draw this font and to propose it for download. Since each symbol have an even row number and an even column number, I put in each character of the font 4 modules (2 rows and 2 columns). In this manner we have 16 combinations assigned to the 16 first capital letters.
If we give a value at each dot of this 2 x 2 matrix like this :
1 2 4 8
The ASCII value of the character associated to a given matrix is the sum each dot value + 65 (65 = A = no dot, all white !)

The " datamatrix.ttf " font (Suitable for QRcodes)
This font contains the 16 character A (ASCII : 65) to P (ASCII : 80)

Copy this file in the font directory, often named : \Windows\Fonts

Encoding a QRcode

The program will have to take place in several stages : Because of the interaction between the different modes of compression it is difficult to make a 100% optimization. However, the standard gives in Appendix J a method of optimization ...
The evaluation of the results of the different masks will be done "by eye" and by testing the codes obtained.

A little program to test all that.

Here is a small program written with Visual Basic 6.
The setup file copy the program, Visual Basic
dependencies, source files and the font.

Setup file :

ZIP file without setup :

The function QRcode$ is about 900 lines, so I do not reproduce it here, just get it in the file "form1.frm" which is with the program above ; with the self-installation program the file "form1.frm" is located in the program directory, subdirectory "sources"

The function is called as follows : resultat$ = QRcode$(Chaine$, Level%, Mask%, Version%, CodeErr%)
These last two parameters are optional and are passed by references. CodeErr% values at the return of the function : Now simply display or print the resultat$ string with the datamatrix font for example in a word processor. Office users will be able to even integrate the Datamatrix$ function into a macro in order to automate the processing. To be able to carry out all the processing in a single function, I had to use "Gosub" instead of functions with parameters; I can already hear the programming aesthetes screaming sacrilege.


Do you like this page ?

Is it useful for you ?
Click here !