mirror of
https://github.com/Merricx/qrazybox.git
synced 2025-02-19 16:12:56 +01:00
refoctoring - reuse table.js infomration arrays
This commit is contained in:
parent
3181e2bc6f
commit
aeccf3f471
1 changed files with 6 additions and 86 deletions
92
js/qr.js
92
js/qr.js
|
@ -72,50 +72,6 @@ for(let i=0;i<40;i++){
|
|||
)
|
||||
}
|
||||
|
||||
let alignment_lookup = [
|
||||
[],
|
||||
[6, 18],
|
||||
[6, 22],
|
||||
[6, 26],
|
||||
[6, 30],
|
||||
[6, 34],
|
||||
[6, 22, 38],
|
||||
[6, 24, 42],
|
||||
[6, 26, 46],
|
||||
[6, 28, 50],
|
||||
[6, 30, 54],
|
||||
[6, 32, 58],
|
||||
[6, 34, 62],
|
||||
[6, 26, 46, 66],
|
||||
[6, 26, 48, 70],
|
||||
[6, 26, 50, 74],
|
||||
[6, 30, 54, 78],
|
||||
[6, 30, 56, 82],
|
||||
[6, 30, 58, 86],
|
||||
[6, 34, 62, 90],
|
||||
[6, 28, 50, 72, 94],
|
||||
[6, 26, 50, 74, 98],
|
||||
[6, 30, 54, 78, 102],
|
||||
[6, 28, 54, 80, 106],
|
||||
[6, 32, 58, 84, 110],
|
||||
[6, 30, 58, 86, 114],
|
||||
[6, 34, 62, 90, 118],
|
||||
[6, 26, 50, 74, 98, 122],
|
||||
[6, 30, 54, 78, 102, 126],
|
||||
[6, 26, 52, 78, 104, 130],
|
||||
[6, 30, 56, 82, 108, 134],
|
||||
[6, 34, 60, 86, 112, 138],
|
||||
[6, 30, 58, 86, 114, 142],
|
||||
[6, 34, 62, 90, 118, 146],
|
||||
[6, 30, 54, 78, 102, 126, 150],
|
||||
[6, 24, 50, 76, 102, 128, 154],
|
||||
[6, 28, 54, 80, 106, 132, 158],
|
||||
[6, 32, 58, 84, 110, 136, 162],
|
||||
[6, 26, 54, 82, 110, 138, 166],
|
||||
[6, 30, 58, 86, 114, 142, 170]
|
||||
];
|
||||
|
||||
|
||||
/*
|
||||
Alignment patterns are boxes sized 5x5 that are
|
||||
formed as follows:
|
||||
|
@ -124,12 +80,12 @@ let alignment_lookup = [
|
|||
- Inner 3x3 white square
|
||||
- Inner-most 1x1 black square
|
||||
|
||||
The coordinates from alignment_lookup refer to the center
|
||||
The coordinates from alignment_pattern_array (file: table.js) refer to the center
|
||||
of the alignment pattern (the 1x1 square).
|
||||
*/
|
||||
|
||||
function add_alignment_patterns(t, index){
|
||||
let alignment = alignment_lookup[index];
|
||||
let alignment = alignment_pattern_array[index];
|
||||
if(alignment.length == 0){
|
||||
return;
|
||||
}
|
||||
|
@ -169,53 +125,17 @@ function add_alignment_patterns(t, index){
|
|||
console.log(alignment_locs);
|
||||
}
|
||||
|
||||
// from table.js version_information_table ( left most bit is still position 17 )
|
||||
var version_information_table_bit = [
|
||||
[0,0,0,1,1,1,1,1,0,0,1,0,0,1,0,1,0,0], //7
|
||||
[0,0,1,0,0,0,0,1,0,1,1,0,1,1,1,1,0,0], //8
|
||||
[0,0,1,0,0,1,1,0,1,0,1,0,0,1,1,0,0,1], //9
|
||||
[0,0,1,0,1,0,0,1,0,0,1,1,0,1,0,0,1,1], //10
|
||||
[0,0,1,0,1,1,1,0,1,1,1,1,1,1,0,1,1,0], //11
|
||||
[0,0,1,1,0,0,0,1,1,1,0,1,1,0,0,0,1,0], //12
|
||||
[0,0,1,1,0,1,1,0,0,0,0,1,0,0,0,1,1,1], //13
|
||||
[0,0,1,1,1,0,0,1,1,0,0,0,0,0,1,1,0,1], //14
|
||||
[0,0,1,1,1,1,1,0,0,1,0,0,1,0,1,0,0,0], //15
|
||||
[0,1,0,0,0,0,1,0,1,1,0,1,1,1,1,0,0,0], //16
|
||||
[0,1,0,0,0,1,0,1,0,0,0,1,0,1,1,1,0,1], //17
|
||||
[0,1,0,0,1,0,1,0,1,0,0,0,0,1,0,1,1,1], //18
|
||||
[0,1,0,0,1,1,0,1,0,1,0,0,1,1,0,0,1,0], //19
|
||||
[0,1,0,1,0,0,1,0,0,1,1,0,1,0,0,1,1,0], //20
|
||||
[0,1,0,1,0,1,0,1,1,0,1,0,0,0,0,0,1,1], //21
|
||||
[0,1,0,1,1,0,1,0,0,0,1,1,0,0,1,0,0,1], //22
|
||||
[0,1,0,1,1,1,0,1,1,1,1,1,1,0,1,1,0,0], //23
|
||||
[0,1,1,0,0,0,1,1,1,0,1,1,0,0,0,1,0,0], //24
|
||||
[0,1,1,0,0,1,0,0,0,1,1,1,1,0,0,0,0,1], //25
|
||||
[0,1,1,0,1,0,1,1,1,1,1,0,1,0,1,0,1,1], //26
|
||||
[0,1,1,0,1,1,0,0,0,0,1,0,0,0,1,1,1,0], //27
|
||||
[0,1,1,1,0,0,1,1,0,0,0,0,0,1,1,0,1,0], //28
|
||||
[0,1,1,1,0,1,0,0,1,1,0,0,1,1,1,1,1,1], //29
|
||||
[0,1,1,1,1,0,1,1,0,1,0,1,1,1,0,1,0,1], //30
|
||||
[0,1,1,1,1,1,0,0,1,0,0,1,0,1,0,0,0,0], //31
|
||||
[1,0,0,0,0,0,1,0,0,1,1,1,0,1,0,1,0,1], //32
|
||||
[1,0,0,0,0,1,0,1,1,0,1,1,1,1,0,0,0,0], //33
|
||||
[1,0,0,0,1,0,1,0,0,0,1,0,1,1,1,0,1,0], //34
|
||||
[1,0,0,0,1,1,0,1,1,1,1,0,0,1,1,1,1,1], //35
|
||||
[1,0,0,1,0,0,1,0,1,1,0,0,0,0,1,0,1,1], //36
|
||||
[1,0,0,1,0,1,0,1,0,0,0,0,1,0,1,1,1,0], //37
|
||||
[1,0,0,1,1,0,1,0,1,0,0,1,1,0,0,1,0,0], //38
|
||||
[1,0,0,1,1,1,0,1,0,1,0,1,0,0,0,0,0,1], //39
|
||||
[1,0,1,0,0,0,1,1,0,0,0,1,1,0,1,0,0,1] //40
|
||||
];
|
||||
|
||||
// use table.js Array version_information_table ( left most bit is still position 17 )
|
||||
function add_version_info(t, version){
|
||||
if (version >= 7) {
|
||||
for (step=0 ; step < 3 ; step++ ){
|
||||
x=0;
|
||||
for(let i = 17 - step; i>=0 ; i -= 3){
|
||||
// Bottom Left
|
||||
draw_square(t, 4*version + 6 + step, x ,1, version_information_table_bit[version - 7][i]);
|
||||
draw_square(t, 4*version + 6 + step, x ,1, version_information_table[version - 7].toString().split("")[i]);
|
||||
// Top Right
|
||||
draw_square(t, x, 4*version + 6 + step ,1, version_information_table_bit[version - 7][i]);
|
||||
draw_square(t, x, 4*version + 6 + step ,1, version_information_table[version - 7].toString().split("")[i]);
|
||||
|
||||
x++;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue