Module Qrc.Matrix
QR 2D matrices.
type bits
= (int, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t
The type for sequence of bits.
type t
The type for 2D square matrices of modules (binary pixels).
For a matrix of width
w
, the module at position (0,0
) is the top-left corner, and (w-1,w-1)
is the bottom-right corner. The quiet zone (surrounding frame of four zero modules) is not included. We store the bits in row-major order.
val zero : w:int -> t
zero ~w
is a matrix of zeros of sizew
.
val of_bits : w:int -> bits -> t
of_bits ~w bits
is a matrix from the sequence of bitsbits
interpreted in row-major order. Exceeding final bits are ignored.- raises Invalid_argument
if less than
w
2 bits are provided.
val w : t -> int
w m
is the matrix width.
val bits : t -> bits
bits m
are the matrix's bits (modules) in row-major order. If there are more bits than(w m) * (w m)
, exceeding final bits should be ignored.
val get : t -> x:int -> y:int -> bool
get m ~x ~y
is the(x,y)
module ofm
.
val set : t -> x:int -> y:int -> unit
set m ~x ~y v
sets the(x,y)
module ofm
totrue
.
val clear : t -> x:int -> y:int -> unit
clear m ~x ~y
sets the(x,y)
module ofm
tofalse
.
val fold : (int -> int -> bool -> 'a -> 'a) -> t -> 'a -> 'a
fold f m acc
foldsf
over all the modules(x,y)
ofm
asf x y (get m ~x ~y) acc'
in row-major order and starting withacc
.
val to_svg : ?w_mm:int -> ?invert:bool -> ?quiet_zone:bool -> t -> string
to_svg ~w_mm ~invert ~quiet_zone m
is an SVG image form
in a coordinate system using one (slightly larger) unit black square per set module. The image, including the quiet zone, has a width and height ofw_mm
millimeters (defaults to50
). Ifinvert
istrue
(defaults tofalse
) black modules are white and vice-versa. Ifquiet_zone
istrue
(default) the surrounding frame of four zero modules is included.