QR encoder day 3

Code still at https://github.com/grimley517/QREncoder

Okay - this is working well - doing a little chunk everyday is paying off.  Yesterday I decided to implement a single list of the maximum size for a message from the specification rather than try to work it out programatically.  Today I can implement that.

I am going to start with purely numerical data - 3 digits takes 10 Characters, Section 8.4.2 of the ISO reference (http://raidenii.net/files/datasheets/misc/qr_code.pdf) gives the formula for the length of the bit stream as:

B = 4 + C + 10(D/3) +R

Where b is the length of the bit stream.
 C is the number of bits in the Character Count Indication ( 10 for v1-9, 12 for v 10 - 26, and 14 for v27-40)

D = Number of input characters

R = 0 if D % 3 == 0; 4 if D%3 == 1; 7 if D%3 ==2

This may seem a little circular since we need to know the Version number to be able to calculate the version number we need. But we can rearrange for V-C

B-C = 4 + 10(D/3)+R

or even for B - C - 4 since this leaves us with a constant

B-C-4 = 10(D/3) +R

We can adjust our codeword limits list in char to compensate for the changing in C, by converting into bits (*8) then removing the Bits in C and 4

B-C-4 we will call bitsRequired.

Testing for this was quite simple;


Although this will need more tests - especially on edge cases to ensure correctness.



 The init function was fairly simple since this is only handling a size of a numeric input.
This looks unwieldy, and possibly should be broken down, But essentially it creates a list of bit sizes for each version, then calculates the bits required to store the number.  Then works out the version number by counting all the versions it wont fit into.

Next steps.

  • This should reject a message that is too big.  
  • This also needs some extra testing - in particular corner cases, cases where the version number trips over, and where the message is too long.
 





Comments

Popular Posts