Masking

We have placed our data on our QRCode. We will now apply masking to the QRCode.

The masking part (8.8) consists in patching the QRCode flaws:

- Too many consecutive modules of the same value

- Some sequence looking too much like the Finder Patterns

- Modules of the same value

- Module Dark / Light ratio

We will compute a score based on above criteria for each masks we will be using.

The masking part (8.8) consists in patching the QRCode flaws:

- Too many consecutive modules of the same value

- Some sequence looking too much like the Finder Patterns

- Modules of the same value

- Module Dark / Light ratio

We will compute a score based on above criteria for each masks we will be using.

After applying the masking, we will be very close to have a scannable QRCode

As mentionned before, there are masks to apply, 8 of them. I have made a simple vizualization each masks area of effect:

- Grey is untouched by the mask

- Black is flipped by the mask

- Orange is the occupied area

- Grey is untouched by the mask

- Black is flipped by the mask

- Orange is the occupied area

Mask 000 (CheckerBoard)

(i + j) % 2 == 0

Mask 001 (Horizontal)

i % 2 == 0

Mask 010 (Vertical)

j % 3 == 0

Mask 011 (Diagonal)

(i + j) % 2 == 0

Mask 100 (Large CheckerBoard)

((i / 2) + (j / 3)) % 2 == 0

Mask 101 (Fields)

((i * j) % 2 + (i * j) % 3) == 0

Mask 110 (Diamonds)

(((i * j) % 2 + (i * j) % 3)) % 2 == 0

Mask 111 (Meadow)

(((i * j) % 3 + (i + j) % 2)) % 2 == 0

We will apply each masks to our QRCode and compute a score based on the flaws we have seen before.

The remaining question is how to compute the four scores ?

The remaining question is how to compute the four scores ?

The flaw score will be computed as follow:

- Find**5 + N** consecutive modules of the same value and add **3 + N** to the score.

- Some sequence of module being**[D, L, D, D, D, L, D]** (D = Dark, L = Light) will add **40** to the score.

- Compute the ratio of Dark / Light modules in percentage and retrieve the absolute value of the difference with**50%**, divide by 5 and then multiply by 10. (integer division)

- Count the**2x2** modules of the same value and add **3 * N** to the score.

- Find

- Some sequence of module being

- Compute the ratio of Dark / Light modules in percentage and retrieve the absolute value of the difference with

- Count the

example.com without masking

example.com with Checkerboard masking

Every score is computed on non-occupied areas.

Black and white ratio score

2x2 Square score

5 + N consecutive modules score

Finder pattern score

We have find a black / white ratio of

We have found

We have found

We have found

We have placed the data on the QRCode. We applied the eight masks to find the one with the lowest score.

To make it readable we need to add the format information and the version information.