Genaration of a QR code
Due to the increased popularity of QR codes, many users often ask a question: why do we need a QR code and how to scan it? People, who want to understand all the nuances of QR technologies in details, are interested in the process of generation of a QR code.
Generation of a QR code goes by the strictly determined algorithm, which is in the simplified way can be divided into several key stages.
1. Coding of the data
It is possible to encode information to a QR code in several ways, and you can choose the one certain method in accordance to what symbols you use. If you use only numbers from 0 to 9 you may apply numeric encoding, if you need to encode Latin letters besides numbers, a space and symbols +-*/$%*.:, you will need to use alphanumeric encoding. There is also Kanji encoding, which is applied for encoding of Chinese and Japanese hieroglyphs and byte encoding. A null string of bits is created before each way of encoding mode, which then is filled.
2. Addition of service information
At this stage of generation of a QR code it is necessary to define the error correction level and the version of the code, and then goes the addition of service fields, where the encoding mode and the number of data is specified. It is possible to choose one of four levels of correction in accordance to the location of a QR code, presence or absence of an image there: L—when 7% of errors can be allowed, M—up to 15%, Q—25% and H—up to 30%. The higher the error correction level, the more probability that it will be possible to scan it even if it is partially removed, covered or damaged, but at the same time the less information which it is possible to encode to a QR code. It is necessary to consider the volume of data, which you need to encode when choosing the version. The higher is the number of the version, the more is the size of a QR code and the more information it is possible to encode there.
3. Separation of the data into blocks
The sequence of bytes that was received at the previous stages has to be separated into blocks, the number of which directly depends on the version and the error correction level. Initially the number of bytes (data) is defined in each of the blocks, and then goes the consecutive filling of blocks. It is important so that the data filled all the blocks.
4. Creation of error correction bytes
This process is based on the algorithm of Reed–Solomon. It should be applied to each block of information of a QR code. First of all it is necessary to define the number of error correction bytes, which it is required to create, and then, based on this data, you may create a generation polynomial.
5. Combination of blocks
It is necessary to unite all the data blocks and error correction blocks into one stream of bytes. You need to take one byte of information from each of the data blocks one by one, starting form the first one and finishing with the last one. This process repeats until all the blocks are empty. It is necessary to do all the same and in the following manner with error correction blocks also.
6. Arrangement of the information into a QR code
The sequence of bytes you have created you need to arrange in strict order. Besides, the structure of a QR code has basic modules and elements, which occupy their definite places. They include zones defining the encoding version, format information zone, timing lines, position patterns, alignment pattern and quiet zone. Then you may start adding data. Thus it is necessary to choose the optimal mask, which will be placed on each module. There are 8 masks in general. The process of filling of a QR code starts from the right bottom corner, from the bottom upwards, column by column, bite by bite.
This description of the algorithm of generation of a QR code is intended for guidance only. It is possible to find more detailed information on the generation of a QR code from the official documents of the Denso-Wave company.