この記事では、マイクロ QR コードは考慮してません。
生成方法
表 9 にある値の幾つかは次の方法で求めることが出来ます。
# 大きさからデータのモジュール数を得る
# size^2 からデータを配置できない(決まったパターン)部分を除く
def data_modules(size):
nalign = (size >= 25) and int((size + 40) / 28) or 0
amods = (nalign >= 2) and ((nalign * nalign - 3) * 25) or 0
cmods = (nalign >= 3) and ((nalign - 2) * 10) or 0
fmods = 192 + ((size - 16) * 2) + amods - cmods
tmods = 31 + ((size >= 45) and 36 or 0)
return ((size * size) - fmods - tmods)
# 総コード語数を得る
def total_code_words(qrtype):
return data_modules(17 + 4 * qrtype) >> 3
# 総ブロック数を得る
BLOCK_TABLE = [
[[50, 450, 3522], [1, 4, 84, 80, 64, 0, 5, 80, 5, 80], []],
[[100, 919, 2076], [65, 88, 129, 22, 148, 66, 84, 81, 5, 85], []],
[[135, 1353, 1712], [17, 102, 70, 198, 53, 2, 28, 85, 89, 170], [14]],
[[158, 1785, -2009], [214, 86, 118, 13, 137, 28, 85, 149, 90, 238], [13, 15, 19, 22]]
]
def total_blocks(qrtype, correct):
iqrtype = qrtype - 1
table = BLOCK_TABLE[correct]
curv = table[0]
return (((curv[0] * qrtype * qrtype + curv[1] * qrtype + curv[2]) >> 12)
+ ((table[1][iqrtype >> 2] >> ((iqrtype & 3) << 1)) & 3)
+ (((qrtype in table[2]) and 4 or 0)))
# ブロックあたりの誤り訂正コード語を得る
CORRECT_TABLE = [
[205, [100, 107, 169, 248, 195], [1, 2]],
[382, [1, 175, 243, 255, 255], [20]],
[565, [96, 239, 255, 255, 255], [1, 2, 3, 4]],
[672, [80, 253, 71, 253, 253], []],
]
def correct_size(qrtype, correct, size):
iqrtype = qrtype - 1
table = CORRECT_TABLE[correct]
return (((table[0] * size) >> 10)
+ ((table[1][iqrtype >> 3] >> (iqrtype & 7)) & 1)
+ ((qrtype in table[2])
and ((correct != 2)
and 2
or ((qrtype != 2)
and -1
or -2))
or 0))
# 型ごとのデータ
def qrtype_data(qrtype):
correct = []
cw = total_code_words(qrtype)
for level in range(4):
tb = total_blocks(qrtype, level)
b2 = cw % tb
s1 = int((cw - b2) / tb)
b1 = tb - b2
s2 = s1 + 1
cs = correct_size(qrtype, level, s1)
bl = [[b1, s1, s1-cs]]
if b2 != 0:
bl.append([b2, s2, s2-cs])
correct.append([cw, tb, bl])
return [qrtype, correct]
# 表の出力
def dump():
for q in range(1, 40+1):
data = qrtype_data(q)
qrtype = str(data[0])
correct = data[1]
for level in range(4):
ctype = 'LMQH'[level]
code, total, block = correct[level]
code = str(code)
total = str(total)
nblk = len(block)
for i in range(nblk):
b, c, k = block[i]
b = str(b)
c = str(c)
k = str(k)
t = total
if nblk == 2:
if i != (nblk - 1):
t = b + ' +'
else:
ctype = ''
t = b + ' = ' + total
print('| ' + ' | '.join([qrtype, code, ctype, b, c, k, t]) + ' |')
dump()
出力結果から作成
表は以下のとおり
CODE: 総コード語数
訂正: 誤り訂正レベル
BLK: 誤り訂正ブロック数
c: ブロックあたりの総コード語数
k: ブロックあたりのデータ コード語数
総BLK: 誤り訂正ブロック数を累積します
型 | CODE | 訂正 | BLK | c | k | 総BLK |
---|---|---|---|---|---|---|
1 | 26 | L | 1 | 26 | 19 | 1 |
1 | 26 | M | 1 | 26 | 16 | 1 |
1 | 26 | Q | 1 | 26 | 13 | 1 |
1 | 26 | H | 1 | 26 | 9 | 1 |
2 | 44 | L | 1 | 44 | 34 | 1 |
2 | 44 | M | 1 | 44 | 28 | 1 |
2 | 44 | Q | 1 | 44 | 22 | 1 |
2 | 44 | H | 1 | 44 | 16 | 1 |
3 | 70 | L | 1 | 70 | 55 | 1 |
3 | 70 | M | 1 | 70 | 44 | 1 |
3 | 70 | Q | 2 | 35 | 17 | 2 |
3 | 70 | H | 2 | 35 | 13 | 2 |
4 | 100 | L | 1 | 100 | 80 | 1 |
4 | 100 | M | 2 | 50 | 32 | 2 |
4 | 100 | Q | 2 | 50 | 24 | 2 |
4 | 100 | H | 4 | 25 | 9 | 4 |
5 | 134 | L | 1 | 134 | 108 | 1 |
5 | 134 | M | 2 | 67 | 43 | 2 |
5 | 134 | Q | 2 | 33 | 15 | 2 + |
5 | 134 | 2 | 34 | 16 | 2 = 4 | |
5 | 134 | H | 2 | 33 | 11 | 2 + |
5 | 134 | 2 | 34 | 12 | 2 = 4 | |
6 | 172 | L | 2 | 86 | 68 | 2 |
6 | 172 | M | 4 | 43 | 27 | 4 |
6 | 172 | Q | 4 | 43 | 19 | 4 |
6 | 172 | H | 4 | 43 | 15 | 4 |
7 | 196 | L | 2 | 98 | 78 | 2 |
7 | 196 | M | 4 | 49 | 31 | 4 |
7 | 196 | Q | 2 | 32 | 14 | 2 + |
7 | 196 | 4 | 33 | 15 | 4 = 6 | |
7 | 196 | H | 4 | 39 | 13 | 4 + |
7 | 196 | 1 | 40 | 14 | 1 = 5 | |
8 | 242 | L | 2 | 121 | 97 | 2 |
8 | 242 | M | 2 | 60 | 38 | 2 + |
8 | 242 | 2 | 61 | 39 | 2 = 4 | |
8 | 242 | Q | 4 | 40 | 18 | 4 + |
8 | 242 | 2 | 41 | 19 | 2 = 6 | |
8 | 242 | H | 4 | 40 | 14 | 4 + |
8 | 242 | 2 | 41 | 15 | 2 = 6 | |
9 | 292 | L | 2 | 146 | 116 | 2 |
9 | 292 | M | 3 | 58 | 36 | 3 + |
9 | 292 | 2 | 59 | 37 | 2 = 5 | |
9 | 292 | Q | 4 | 36 | 16 | 4 + |
9 | 292 | 4 | 37 | 17 | 4 = 8 | |
9 | 292 | H | 4 | 36 | 12 | 4 + |
9 | 292 | 4 | 37 | 13 | 4 = 8 | |
10 | 346 | L | 2 | 86 | 68 | 2 + |
10 | 346 | 2 | 87 | 69 | 2 = 4 | |
10 | 346 | M | 4 | 69 | 43 | 4 + |
10 | 346 | 1 | 70 | 44 | 1 = 5 | |
10 | 346 | Q | 6 | 43 | 19 | 6 + |
10 | 346 | 2 | 44 | 20 | 2 = 8 | |
10 | 346 | H | 6 | 43 | 15 | 6 + |
10 | 346 | 2 | 44 | 16 | 2 = 8 | |
11 | 404 | L | 4 | 101 | 81 | 4 |
11 | 404 | M | 1 | 80 | 50 | 1 + |
11 | 404 | 4 | 81 | 51 | 4 = 5 | |
11 | 404 | Q | 4 | 50 | 22 | 4 + |
11 | 404 | 4 | 51 | 23 | 4 = 8 | |
11 | 404 | H | 3 | 36 | 12 | 3 + |
11 | 404 | 8 | 37 | 13 | 8 = 11 | |
12 | 466 | L | 2 | 116 | 92 | 2 + |
12 | 466 | 2 | 117 | 93 | 2 = 4 | |
12 | 466 | M | 6 | 58 | 36 | 6 + |
12 | 466 | 2 | 59 | 37 | 2 = 8 | |
12 | 466 | Q | 4 | 46 | 20 | 4 + |
12 | 466 | 6 | 47 | 21 | 6 = 10 | |
12 | 466 | H | 7 | 42 | 14 | 7 + |
12 | 466 | 4 | 43 | 15 | 4 = 11 | |
13 | 532 | L | 4 | 133 | 107 | 4 |
13 | 532 | M | 8 | 59 | 37 | 8 + |
13 | 532 | 1 | 60 | 38 | 1 = 9 | |
13 | 532 | Q | 8 | 44 | 20 | 8 + |
13 | 532 | 4 | 45 | 21 | 4 = 12 | |
13 | 532 | H | 12 | 33 | 11 | 12 + |
13 | 532 | 4 | 34 | 12 | 4 = 16 | |
14 | 581 | L | 3 | 145 | 115 | 3 + |
14 | 581 | 1 | 146 | 116 | 1 = 4 | |
14 | 581 | M | 4 | 64 | 40 | 4 + |
14 | 581 | 5 | 65 | 41 | 5 = 9 | |
14 | 581 | Q | 11 | 36 | 16 | 11 + |
14 | 581 | 5 | 37 | 17 | 5 = 16 | |
14 | 581 | H | 11 | 36 | 12 | 11 + |
14 | 581 | 5 | 37 | 13 | 5 = 16 | |
15 | 655 | L | 5 | 109 | 87 | 5 + |
15 | 655 | 1 | 110 | 88 | 1 = 6 | |
15 | 655 | M | 5 | 65 | 41 | 5 + |
15 | 655 | 5 | 66 | 42 | 5 = 10 | |
15 | 655 | Q | 5 | 54 | 24 | 5 + |
15 | 655 | 7 | 55 | 25 | 7 = 12 | |
15 | 655 | H | 11 | 36 | 12 | 11 + |
15 | 655 | 7 | 37 | 13 | 7 = 18 | |
16 | 733 | L | 5 | 122 | 98 | 5 + |
16 | 733 | 1 | 123 | 99 | 1 = 6 | |
16 | 733 | M | 7 | 73 | 45 | 7 + |
16 | 733 | 3 | 74 | 46 | 3 = 10 | |
16 | 733 | Q | 15 | 43 | 19 | 15 + |
16 | 733 | 2 | 44 | 20 | 2 = 17 | |
16 | 733 | H | 3 | 45 | 15 | 3 + |
16 | 733 | 13 | 46 | 16 | 13 = 16 | |
17 | 815 | L | 1 | 135 | 107 | 1 + |
17 | 815 | 5 | 136 | 108 | 5 = 6 | |
17 | 815 | M | 10 | 74 | 46 | 10 + |
17 | 815 | 1 | 75 | 47 | 1 = 11 | |
17 | 815 | Q | 1 | 50 | 22 | 1 + |
17 | 815 | 15 | 51 | 23 | 15 = 16 | |
17 | 815 | H | 2 | 42 | 14 | 2 + |
17 | 815 | 17 | 43 | 15 | 17 = 19 | |
18 | 901 | L | 5 | 150 | 120 | 5 + |
18 | 901 | 1 | 151 | 121 | 1 = 6 | |
18 | 901 | M | 9 | 69 | 43 | 9 + |
18 | 901 | 4 | 70 | 44 | 4 = 13 | |
18 | 901 | Q | 17 | 50 | 22 | 17 + |
18 | 901 | 1 | 51 | 23 | 1 = 18 | |
18 | 901 | H | 2 | 42 | 14 | 2 + |
18 | 901 | 19 | 43 | 15 | 19 = 21 | |
19 | 991 | L | 3 | 141 | 113 | 3 + |
19 | 991 | 4 | 142 | 114 | 4 = 7 | |
19 | 991 | M | 3 | 70 | 44 | 3 + |
19 | 991 | 11 | 71 | 45 | 11 = 14 | |
19 | 991 | Q | 17 | 47 | 21 | 17 + |
19 | 991 | 4 | 48 | 22 | 4 = 21 | |
19 | 991 | H | 9 | 39 | 13 | 9 + |
19 | 991 | 16 | 40 | 14 | 16 = 25 | |
20 | 1085 | L | 3 | 135 | 107 | 3 + |
20 | 1085 | 5 | 136 | 108 | 5 = 8 | |
20 | 1085 | M | 3 | 67 | 41 | 3 + |
20 | 1085 | 13 | 68 | 42 | 13 = 16 | |
20 | 1085 | Q | 15 | 54 | 24 | 15 + |
20 | 1085 | 5 | 55 | 25 | 5 = 20 | |
20 | 1085 | H | 15 | 43 | 15 | 15 + |
20 | 1085 | 10 | 44 | 16 | 10 = 25 | |
21 | 1156 | L | 4 | 144 | 116 | 4 + |
21 | 1156 | 4 | 145 | 117 | 4 = 8 | |
21 | 1156 | M | 17 | 68 | 42 | 17 |
21 | 1156 | Q | 17 | 50 | 22 | 17 + |
21 | 1156 | 6 | 51 | 23 | 6 = 23 | |
21 | 1156 | H | 19 | 46 | 16 | 19 + |
21 | 1156 | 6 | 47 | 17 | 6 = 25 | |
22 | 1258 | L | 2 | 139 | 111 | 2 + |
22 | 1258 | 7 | 140 | 112 | 7 = 9 | |
22 | 1258 | M | 17 | 74 | 46 | 17 |
22 | 1258 | Q | 7 | 54 | 24 | 7 + |
22 | 1258 | 16 | 55 | 25 | 16 = 23 | |
22 | 1258 | H | 34 | 37 | 13 | 34 |
23 | 1364 | L | 4 | 151 | 121 | 4 + |
23 | 1364 | 5 | 152 | 122 | 5 = 9 | |
23 | 1364 | M | 4 | 75 | 47 | 4 + |
23 | 1364 | 14 | 76 | 48 | 14 = 18 | |
23 | 1364 | Q | 11 | 54 | 24 | 11 + |
23 | 1364 | 14 | 55 | 25 | 14 = 25 | |
23 | 1364 | H | 16 | 45 | 15 | 16 + |
23 | 1364 | 14 | 46 | 16 | 14 = 30 | |
24 | 1474 | L | 6 | 147 | 117 | 6 + |
24 | 1474 | 4 | 148 | 118 | 4 = 10 | |
24 | 1474 | M | 6 | 73 | 45 | 6 + |
24 | 1474 | 14 | 74 | 46 | 14 = 20 | |
24 | 1474 | Q | 11 | 54 | 24 | 11 + |
24 | 1474 | 16 | 55 | 25 | 16 = 27 | |
24 | 1474 | H | 30 | 46 | 16 | 30 + |
24 | 1474 | 2 | 47 | 17 | 2 = 32 | |
25 | 1588 | L | 8 | 132 | 106 | 8 + |
25 | 1588 | 4 | 133 | 107 | 4 = 12 | |
25 | 1588 | M | 8 | 75 | 47 | 8 + |
25 | 1588 | 13 | 76 | 48 | 13 = 21 | |
25 | 1588 | Q | 7 | 54 | 24 | 7 + |
25 | 1588 | 22 | 55 | 25 | 22 = 29 | |
25 | 1588 | H | 22 | 45 | 15 | 22 + |
25 | 1588 | 13 | 46 | 16 | 13 = 35 | |
26 | 1706 | L | 10 | 142 | 114 | 10 + |
26 | 1706 | 2 | 143 | 115 | 2 = 12 | |
26 | 1706 | M | 19 | 74 | 46 | 19 + |
26 | 1706 | 4 | 75 | 47 | 4 = 23 | |
26 | 1706 | Q | 28 | 50 | 22 | 28 + |
26 | 1706 | 6 | 51 | 23 | 6 = 34 | |
26 | 1706 | H | 33 | 46 | 16 | 33 + |
26 | 1706 | 4 | 47 | 17 | 4 = 37 | |
27 | 1828 | L | 8 | 152 | 122 | 8 + |
27 | 1828 | 4 | 153 | 123 | 4 = 12 | |
27 | 1828 | M | 22 | 73 | 45 | 22 + |
27 | 1828 | 3 | 74 | 46 | 3 = 25 | |
27 | 1828 | Q | 8 | 53 | 23 | 8 + |
27 | 1828 | 26 | 54 | 24 | 26 = 34 | |
27 | 1828 | H | 12 | 45 | 15 | 12 + |
27 | 1828 | 28 | 46 | 16 | 28 = 40 | |
28 | 1921 | L | 3 | 147 | 117 | 3 + |
28 | 1921 | 10 | 148 | 118 | 10 = 13 | |
28 | 1921 | M | 3 | 73 | 45 | 3 + |
28 | 1921 | 23 | 74 | 46 | 23 = 26 | |
28 | 1921 | Q | 4 | 54 | 24 | 4 + |
28 | 1921 | 31 | 55 | 25 | 31 = 35 | |
28 | 1921 | H | 11 | 45 | 15 | 11 + |
28 | 1921 | 31 | 46 | 16 | 31 = 42 | |
29 | 2051 | L | 7 | 146 | 116 | 7 + |
29 | 2051 | 7 | 147 | 117 | 7 = 14 | |
29 | 2051 | M | 21 | 73 | 45 | 21 + |
29 | 2051 | 7 | 74 | 46 | 7 = 28 | |
29 | 2051 | Q | 1 | 53 | 23 | 1 + |
29 | 2051 | 37 | 54 | 24 | 37 = 38 | |
29 | 2051 | H | 19 | 45 | 15 | 19 + |
29 | 2051 | 26 | 46 | 16 | 26 = 45 | |
30 | 2185 | L | 5 | 145 | 115 | 5 + |
30 | 2185 | 10 | 146 | 116 | 10 = 15 | |
30 | 2185 | M | 19 | 75 | 47 | 19 + |
30 | 2185 | 10 | 76 | 48 | 10 = 29 | |
30 | 2185 | Q | 15 | 54 | 24 | 15 + |
30 | 2185 | 25 | 55 | 25 | 25 = 40 | |
30 | 2185 | H | 23 | 45 | 15 | 23 + |
30 | 2185 | 25 | 46 | 16 | 25 = 48 | |
31 | 2323 | L | 13 | 145 | 115 | 13 + |
31 | 2323 | 3 | 146 | 116 | 3 = 16 | |
31 | 2323 | M | 2 | 74 | 46 | 2 + |
31 | 2323 | 29 | 75 | 47 | 29 = 31 | |
31 | 2323 | Q | 42 | 54 | 24 | 42 + |
31 | 2323 | 1 | 55 | 25 | 1 = 43 | |
31 | 2323 | H | 23 | 45 | 15 | 23 + |
31 | 2323 | 28 | 46 | 16 | 28 = 51 | |
32 | 2465 | L | 17 | 145 | 115 | 17 |
32 | 2465 | M | 10 | 74 | 46 | 10 + |
32 | 2465 | 23 | 75 | 47 | 23 = 33 | |
32 | 2465 | Q | 10 | 54 | 24 | 10 + |
32 | 2465 | 35 | 55 | 25 | 35 = 45 | |
32 | 2465 | H | 19 | 45 | 15 | 19 + |
32 | 2465 | 35 | 46 | 16 | 35 = 54 | |
33 | 2611 | L | 17 | 145 | 115 | 17 + |
33 | 2611 | 1 | 146 | 116 | 1 = 18 | |
33 | 2611 | M | 14 | 74 | 46 | 14 + |
33 | 2611 | 21 | 75 | 47 | 21 = 35 | |
33 | 2611 | Q | 29 | 54 | 24 | 29 + |
33 | 2611 | 19 | 55 | 25 | 19 = 48 | |
33 | 2611 | H | 11 | 45 | 15 | 11 + |
33 | 2611 | 46 | 46 | 16 | 46 = 57 | |
34 | 2761 | L | 13 | 145 | 115 | 13 + |
34 | 2761 | 6 | 146 | 116 | 6 = 19 | |
34 | 2761 | M | 14 | 74 | 46 | 14 + |
34 | 2761 | 23 | 75 | 47 | 23 = 37 | |
34 | 2761 | Q | 44 | 54 | 24 | 44 + |
34 | 2761 | 7 | 55 | 25 | 7 = 51 | |
34 | 2761 | H | 59 | 46 | 16 | 59 + |
34 | 2761 | 1 | 47 | 17 | 1 = 60 | |
35 | 2876 | L | 12 | 151 | 121 | 12 + |
35 | 2876 | 7 | 152 | 122 | 7 = 19 | |
35 | 2876 | M | 12 | 75 | 47 | 12 + |
35 | 2876 | 26 | 76 | 48 | 26 = 38 | |
35 | 2876 | Q | 39 | 54 | 24 | 39 + |
35 | 2876 | 14 | 55 | 25 | 14 = 53 | |
35 | 2876 | H | 22 | 45 | 15 | 22 + |
35 | 2876 | 41 | 46 | 16 | 41 = 63 | |
36 | 3034 | L | 6 | 151 | 121 | 6 + |
36 | 3034 | 14 | 152 | 122 | 14 = 20 | |
36 | 3034 | M | 6 | 75 | 47 | 6 + |
36 | 3034 | 34 | 76 | 48 | 34 = 40 | |
36 | 3034 | Q | 46 | 54 | 24 | 46 + |
36 | 3034 | 10 | 55 | 25 | 10 = 56 | |
36 | 3034 | H | 2 | 45 | 15 | 2 + |
36 | 3034 | 64 | 46 | 16 | 64 = 66 | |
37 | 3196 | L | 17 | 152 | 122 | 17 + |
37 | 3196 | 4 | 153 | 123 | 4 = 21 | |
37 | 3196 | M | 29 | 74 | 46 | 29 + |
37 | 3196 | 14 | 75 | 47 | 14 = 43 | |
37 | 3196 | Q | 49 | 54 | 24 | 49 + |
37 | 3196 | 10 | 55 | 25 | 10 = 59 | |
37 | 3196 | H | 24 | 45 | 15 | 24 + |
37 | 3196 | 46 | 46 | 16 | 46 = 70 | |
38 | 3362 | L | 4 | 152 | 122 | 4 + |
38 | 3362 | 18 | 153 | 123 | 18 = 22 | |
38 | 3362 | M | 13 | 74 | 46 | 13 + |
38 | 3362 | 32 | 75 | 47 | 32 = 45 | |
38 | 3362 | Q | 48 | 54 | 24 | 48 + |
38 | 3362 | 14 | 55 | 25 | 14 = 62 | |
38 | 3362 | H | 42 | 45 | 15 | 42 + |
38 | 3362 | 32 | 46 | 16 | 32 = 74 | |
39 | 3532 | L | 20 | 147 | 117 | 20 + |
39 | 3532 | 4 | 148 | 118 | 4 = 24 | |
39 | 3532 | M | 40 | 75 | 47 | 40 + |
39 | 3532 | 7 | 76 | 48 | 7 = 47 | |
39 | 3532 | Q | 43 | 54 | 24 | 43 + |
39 | 3532 | 22 | 55 | 25 | 22 = 65 | |
39 | 3532 | H | 10 | 45 | 15 | 10 + |
39 | 3532 | 67 | 46 | 16 | 67 = 77 | |
40 | 3706 | L | 19 | 148 | 118 | 19 + |
40 | 3706 | 6 | 149 | 119 | 6 = 25 | |
40 | 3706 | M | 18 | 75 | 47 | 18 + |
40 | 3706 | 31 | 76 | 48 | 31 = 49 | |
40 | 3706 | Q | 34 | 54 | 24 | 34 + |
40 | 3706 | 34 | 55 | 25 | 34 = 68 | |
40 | 3706 | H | 20 | 45 | 15 | 20 + |
40 | 3706 | 61 | 46 | 16 | 61 = 81 |
表の規則性(?)
「誤り訂正ブロック数」および「ブロックあたりの総コード語数(表9のc)」
まず、各型番の誤り訂正レベルごとに、総誤り訂正ブロック数(表9にはない)を調べると
L:
1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8,
8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25,
M:
1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16,
17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49,
Q:
1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20,
23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68,
H:
1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25,
25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81,
となっています。(40-Q が 64 だったら…)
QR コードは正方形なので、型番から二次式
f \left( x \right) = a x^2 + b x + c
を考えればよさそうなです。
各誤り訂正レベルの $a,b,c$ の 4096 倍を求めたところ
$a$ | $b$ | $c$ | |
---|---|---|---|
L | 50 | 450 | 3522 |
M | 100 | 919 | 2076 |
Q | 135 | 1353 | 1712 |
H | 158 | 1785 | -2009 |
を得ました。(Mathematica の NonlinearModelFit で求めて少し弄った)
これで、総誤り訂正ブロック数を求めると
L:
0, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7,
8, 9, 9, 10, 11, 11, 12, 13, 14, 15, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
M:
0, 1, 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 17, 18, 19, 21, 22, 24, 25, 27, 29, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48,
Q:
0, 1, 1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 17, 18, 20,
21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 42, 44, 47, 49, 52, 55, 57, 60, 63, 66,
H:
-1, 0, 1, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 13, 14, 16, 18, 19, 21, 23,
25, 27, 29, 32, 34, 36, 39, 41, 44, 47, 50, 52, 55, 58, 62, 65, 68, 71, 75, 78,
となって、差分は
L:
1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1,
0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1,
M:
1, 0, 0, 1, 0, 2, 1, 1, 1, 0, 0, 2, 2, 1, 1, 0, 0, 1, 1, 2,
2, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1,
Q:
1, 0, 1, 0, 2, 1, 2, 1, 2, 1, 0, 1, 2, 5, 0, 3, 1, 1, 3, 0,
2, 0, 0, 0, 0, 3, 1, 0, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 2, 2,
H:
2, 1, 1, 3, 2, 1, 1, 1, 2, 1, 3, 1, 5, 3, 4, 0, 1, 2, 4, 2,
0, 7, 1, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 3, 2, 3,
だから、ほとんどが 2 ビットで収まります。
BLOCK_TABLE[n][1] は 2 ビット単位に詰めた差分テーブルです。
例外が BLOCK_TABLE[n][2] の型番一覧で、+4 が必要なものです。
誤り訂正ブロック数は、一つの誤り訂正レベルに二つある場合があるので、総誤り訂正ブロック数を $\left( t = b_1 + b_2 \right)$ とします。総誤り訂正ブロック数 $t$ と総コード語数( $Q$ とします)が分かると、ブロックあたりの総コード語数(表9の $c$) の二つの値は、$N$ と $(N+1)$ になっているので
\begin{eqnarray}
Q & = & b_1 N + b_2 \left( N + 1 \right) \\
& = & N \left( b_1 + b_2 \right) + b_2 \\
& = & N t + b
\end{eqnarray}
と表せて
\begin{eqnarray}
b_2 & \equiv & Q \pmod{ t } \\
N & = & \frac{ Q - b_2 }{ t } \\
b_1 & = & t - b_2 = \left( b_1 + b_2 \right) - b_2 \\
\end{eqnarray}
が得られます。
「総コード語数」と「総誤り訂正ブロック数」があれば、二段になっている「誤り訂正ブロック数」および「ブロックあたりの総コード語数(表9の$c$)」を求められます。
ブロックあたりのデータ コード語数(表9のk)
ブロックあたりのデータ コード語数(表9の$k$) は直接求めず、「ブロックあたりの総コード語数(表9の$c$)」から「ブロックあたりのデータ コード語数(表9の$k$)」を引いた、「ブロックあたりの訂正コード語数($c-k$)」を求めます。
各型番の誤り訂正レベルごとの「ブロックあたりの訂正コード語数($c-k$)」を左半分に、「ブロックあたりの総コード語数(表9の$c$)」を右半分に配置すると
L:
7, 10, 15, 20, 26, 18, 20, 24, 30, 18 | 26, 44, 70, 100, 134, 86, 98, 121, 146, 86,
20, 24, 26, 30, 22, 24, 28, 30, 28, 28 | 101, 116, 133, 145, 109, 122, 135, 150, 141, 135,
28, 28, 30, 30, 26, 28, 30, 30, 30, 30 | 144, 139, 151, 147, 132, 142, 152, 147, 146, 145,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30 | 145, 145, 145, 145, 151, 151, 152, 152, 147, 148,
M:
10, 16, 26, 18, 24, 16, 18, 22, 22, 26 | 26, 44, 70, 50, 67, 43, 49, 60, 58, 69,
30, 22, 22, 24, 24, 28, 28, 26, 26, 26 | 80, 58, 59, 64, 65, 73, 74, 69, 70, 67,
26, 28, 28, 28, 28, 28, 28, 28, 28, 28 | 68, 74, 75, 73, 75, 74, 73, 73, 73, 75,
28, 28, 28, 28, 28, 28, 28, 28, 28, 28 | 74, 74, 74, 74, 75, 75, 74, 74, 75, 75,
Q:
13, 22, 18, 26, 18, 24, 18, 22, 20, 24 | 26, 44, 35, 50, 33, 43, 32, 40, 36, 43,
28, 26, 24, 20, 30, 24, 28, 28, 26, 30 | 50, 46, 44, 36, 54, 43, 50, 50, 47, 54,
28, 30, 30, 30, 30, 28, 30, 30, 30, 30 | 50, 54, 54, 54, 54, 50, 53, 54, 53, 54,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30 | 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,
H:
17, 28, 22, 16, 22, 28, 26, 26, 24, 28 | 26, 44, 35, 25, 33, 43, 39, 40, 36, 43,
24, 28, 22, 24, 24, 30, 28, 28, 26, 28 | 36, 42, 33, 36, 36, 45, 42, 42, 39, 43,
30, 24, 30, 30, 30, 30, 30, 30, 30, 30 | 46, 37, 45, 46, 45, 46, 45, 45, 45, 45,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30 | 45, 45, 45, 46, 45, 45, 45, 45, 45, 45,
誤り訂正レベルごとに、概ね一定割合(左=右×定数)に見えるので試行錯誤して
L | M | Q | H |
---|---|---|---|
$\frac{205}{1024}$ | $\frac{382}{1024}$ | $\frac{565}{1024}$ | $\frac{672}{1024}$ |
としました。「ブロックあたりの総コード語数(表9の$c$)」は別途求められるので、定数倍してから「ブロックあたりの訂正コード語数」との差分をとると
L:
2, 2, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1,
M:
1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 2,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
Q:
-1,-2,-1,-1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
H:
0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
となって、ほとんどが 1 ビットで収まります。例外処理は異なりますが、あとは「総誤り訂正ブロック数」のとき同様です。
これで「ブロックあたりの訂正コード語数($c-k$)」が出てくるので「ブロックあたりのデータ コード語数(表9のk)」は求まります。
「QRコード」はデンソーウェーブの登録商標です。