package qrc

  1. Overview
  2. Docs

QR code properties.

Except for Prop.mode_capacity, not for the casual user.

Version

val version_of_w : int -> (version, string) result

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.

val data_bytes : version -> ec_level -> int

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.

val ec_bytes : version -> ec_level -> int

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.

val ec_blocks : version -> ec_level -> int

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.

val mode_capacity : version -> ec_level -> mode -> int

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.

val align_pat_center : pat_count:int -> pat_last:int -> pat_delta:int -> int -> int

align_pat_center ~pat_count ~pat_last ~pat_delta i is the center of the ith 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

val field : Gf_256.t Lazy.t

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 - g0)·(x - g1)·…·(x - gec) with g the generator of f and ec the number of error correcting bytes .

OCaml

Innovation. Community. Security.