# package qrc

Library

Module

Module type

Parameter

Class

Class type

QR code properties.

Except for `mode_capacity`

, not for the casual user.

## Version

`version_of_w w`

is the version associated to a matrix width of `w`

(without the quiet zone).

`val version_to_w : version -> int`

`version_to_w v`

is the matrix width (without the quiet zone) for a QR code of version `v`

. The result is between 21 to 177, increasing by 4 with each version.

## Capacity

`val total_bytes : version -> int`

`total_bytes v`

is the number of bytes available to encode data in a QR code of version `v`

. This includes the bytes used for error correction. For all `ec_level`

this is equal to `data_bytes`

```
v ec_level
```

+ `ec_bytes`

` v ec_level`

.

This is ‘Total number of codewords’ in table 9 of ISO/IEC 18004:2015.

`data_bytes v ec_level`

is the number of bytes that can be used for data in a QR code of version `v`

with error correction level `ec_level`

This is the ‘Number of data codewords’ in table 7 of ISO/IEC 18004:2015.

**Warning.** Encoding the data into the actual `mode`

uses a few additional bytes from these bytes. Use `mode_capacity`

to determine the actual number of letters of the given mode you can encode in a QR code.

`ec_bytes v ec_level`

is the number of bytes used for error correction in a QR code of version `v`

with error correction level `ec_level`

.

This is the ‘Number of error correction codewords’ in table 9 of ISO/IEC 18004:2015.

`ec_blocks v ec_level`

is the number of blocks by which the data bytes to encode have to be divided and on which Reed-Solomon error correction is performed.

This is the ‘Number of error correction blocks’ in table 9 of ISO/IEC 18004:2015.

`mode_capacity v ec_level mode`

is the number of `mode`

*letters* (that is bytes for ``Byte`

) that can be encoded in a QR code of version `v`

and error correction `ec_level`

.

This is the ‘Data capacity’ columns in table 7 of ISO/IEC 18004:2015.

## Alignment patterns

**Note.** The result of the functions below for ``V 1`

is undefined.

`val align_pat_count : version -> int`

`align_pat_count v`

is the (maximal) number of alignement patterns along one dimension; square that and retract 3 to get the total.

`val align_pat_last : version -> int`

`align_pat_last v`

is the `x`

coordinate of the center of the last (rightmost) alignement pattern in version `v`

.

`val align_pat_delta : version -> int`

`align_pat_delta v`

is the distance between the centers of alignement patterns from right to left, or bottom to top; except for the last hop to column 6 or row 6 which absorbs the unevenness.

`align_pat_center ~pat_count ~pat_last ~pat_delta i`

is the center of the `i`

th alignement pattern starting from `0`

and counting from left to right or top to bottom.

This computes the values ‘Row/Columns coordinates of center module’ in table E.1 of ISO/IEC 18004:2015.

## Galois field

`field`

is the Galois field used for error correction in QR codes, the polynomial is 0b100011101 and the generator is `2`

.

`val gen : Gf_256.t -> ec:int -> Gf_256.byte array`

`gen f ec`

is are the coefficients of the generator polynomial (x - `g`

^{0})·(x - `g`

^{1})·…·(x - `g`

^{ec}) with `g`

the generator of `f`

and `ec`

the number of error correcting bytes .