Skip to content

Commit 8d5fa95

Browse files
authored
Merge pull request #11 from OUDON/develop
v0.1.3
2 parents 7826473 + 722351c commit 8d5fa95

File tree

7 files changed

+44
-42
lines changed

7 files changed

+44
-42
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ This is an rMQR Code image generator implemented in Python. This is implemented
66

77

88
## 📌 Important Notice
9-
Please verify an image generated by this software whether it can decode correctly before use.
10-
9+
- Please verify an image generated by this software whether it can decode correctly before use.
10+
- Because this is in early stage, QR Code readers may have not been supported rMQR Code yet.
1111

1212
## 🚀 Installation
1313
```

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = rmqrcode
3-
version = 0.1.2
3+
version = 0.1.3
44
author = Takahiro Tomita
55
author_email = [email protected]
66
description = An rMQR Code Generetor

src/rmqrcode/console.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,18 @@ def main():
5353
elif args.fit_strategy == 'min_height':
5454
fit_strategy = FitStrategy.MINIMIZE_HEIGHT
5555

56-
qr = _make_qr(
57-
args.DATA,
58-
ecc=ecc,
59-
version=args.version,
60-
fit_strategy=fit_strategy
61-
)
56+
try:
57+
qr = _make_qr(
58+
args.DATA,
59+
ecc=ecc,
60+
version=args.version,
61+
fit_strategy=fit_strategy
62+
)
63+
except DataTooLongError:
64+
_show_error_and_exit("Error: The data is too long.")
6265

6366
_save_image(qr, args.OUTPUT)
6467

65-
print(f"{qr}")
66-
6768

6869
def _init_argparser():
6970
parser = argparse.ArgumentParser()

src/rmqrcode/format/data_capacities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
# ISO/IEC 23941:2022 Table 6
5-
data_capacities = {
5+
DataCapacities = {
66
'R7x43': {
77
'height': 7,
88
'width': 43,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from .error_correction_level import ErrorCorrectionLevel
22

33

4-
qr_versions = {
4+
rMQRVersions = {
55
'R7x43': {
66
'version_indicator': 0b00000,
77
'height': 7,

src/rmqrcode/rmqrcode.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .format.error_correction_level import ErrorCorrectionLevel
2-
from .format.qr_versions import qr_versions
3-
from .format.data_capacities import data_capacities
2+
from .format.rmqr_versions import rMQRVersions
3+
from .format.data_capacities import DataCapacities
44
from .format.alignment_pattern_coordinates import AlignmentPatternCoordinates
55
from .format.generator_polynomials import GeneratorPolynomials
66
from .format.mask import mask
@@ -33,7 +33,7 @@ def fit(data,ecc=ErrorCorrectionLevel.M, fit_strategy=FitStrategy.BALANCED):
3333
determined_height = set()
3434

3535
logger.debug("Select rMQR Code version")
36-
for version_name, qr_version in data_capacities.items():
36+
for version_name, qr_version in DataCapacities.items():
3737
if data_length <= qr_version['capacity']['Byte'][ecc]:
3838
width, height = qr_version['width'], qr_version['height']
3939
if not width in determined_width and not height in determined_height:
@@ -69,7 +69,7 @@ def __init__(self, version, ecc, logger=None):
6969
if not rMQR.validate_version(version):
7070
raise IllegalVersionError("The rMQR version is illegal.")
7171

72-
qr_version = qr_versions[version]
72+
qr_version = rMQRVersions[version]
7373
self._version = version
7474
self._height = qr_version['height']
7575
self._width = qr_version['width']
@@ -134,15 +134,15 @@ def __str__(self):
134134

135135
def _put_finder_pattern(self):
136136
# Finder pattern
137-
# 周囲
137+
# Outer square
138138
for i in range(7):
139139
for j in range(7):
140140
if i == 0 or i == 6 or j == 0 or j == 6:
141141
self._qr[i][j] = Color.BLACK
142142
else:
143143
self._qr[i][j] = Color.WHITE
144144

145-
# 真ん中
145+
# Inner square
146146
for i in range(3):
147147
for j in range(3):
148148
self._qr[2+i][2+j] = Color.BLACK
@@ -156,19 +156,19 @@ def _put_finder_pattern(self):
156156
self._qr[7][n] = Color.WHITE
157157

158158
# Finder sub pattern
159-
# 周囲
159+
# Outer square
160160
for i in range(5):
161161
for j in range(5):
162162
color = Color.BLACK if i == 0 or i == 4 or j == 0 or j == 4 else Color.WHITE
163163
self._qr[self._height-i-1][self._width-j-1] = color
164164

165-
# 真ん中
165+
# Inner square
166166
self._qr[self._height-1-2][self._width-1-2] = Color.BLACK
167167

168168

169169
def _put_corner_finder_pattern(self):
170170
# Corner finder pattern
171-
# 左下
171+
# Bottom left
172172
self._qr[self._height-1][0] = Color.BLACK
173173
self._qr[self._height-1][1] = Color.BLACK
174174
self._qr[self._height-1][2] = Color.BLACK
@@ -177,7 +177,7 @@ def _put_corner_finder_pattern(self):
177177
self._qr[self._height-2][0] = Color.BLACK
178178
self._qr[self._height-2][1] = Color.WHITE
179179

180-
# 右上
180+
# Top right
181181
self._qr[0][self._width-1] = Color.BLACK
182182
self._qr[0][self._width-2] = Color.BLACK
183183
self._qr[1][self._width-1] = Color.BLACK
@@ -191,22 +191,22 @@ def _put_alignment_pattern(self):
191191
for i in range(3):
192192
for j in range(3):
193193
color = Color.BLACK if i == 0 or i == 2 or j == 0 or j == 2 else Color.WHITE
194-
# 上側
194+
# Top side
195195
self._qr[i][center_x + j - 1] = color
196-
# 下側
196+
# Bottom side
197197
self._qr[self._height-1-i][center_x + j - 1] = color
198198

199199

200200
def _put_timing_pattern(self):
201201
# Timing pattern
202-
#
202+
# Horizontal
203203
for j in range(self._width):
204204
color = Color.BLACK if (j + 1) % 2 else Color.WHITE
205205
for i in [0, self._height - 1]:
206206
if self._qr[i][j] == Color.UNDEFINED:
207207
self._qr[i][j] = color
208208

209-
#
209+
# Vertical
210210
center_xs = [0, self._width - 1]
211211
center_xs.extend(AlignmentPatternCoordinates[self._width])
212212
for i in range(self._height):
@@ -248,7 +248,7 @@ def _put_version_information_finder_sub_pattern_side(self, version_information):
248248

249249

250250
def _compute_version_info(self):
251-
qr_version = qr_versions[self.version_name()]
251+
qr_version = rMQRVersions[self.version_name()]
252252
version_information_data = qr_version['version_indicator']
253253
if self._error_correction_level == ErrorCorrectionLevel.H:
254254
version_information_data |= 1<<6
@@ -258,14 +258,17 @@ def _compute_version_info(self):
258258

259259

260260
def _put_data(self, data):
261-
qr_version = qr_versions[self.version_name()]
261+
qr_version = rMQRVersions[self.version_name()]
262262

263263
character_count_length = qr_version['character_count_length']
264264
codewords_total = qr_version['codewords_total']
265265
encoded_data = self._convert_to_bites_data(data, character_count_length, codewords_total)
266266
codewords = split_into_8bits(encoded_data)
267267

268-
# codeword数に満たない場合は規定の文字列を付与する
268+
if len(codewords) > codewords_total:
269+
raise DataTooLongError("The data is too long.")
270+
271+
# Add the remainder codewords
269272
while True:
270273
if len(codewords) >= codewords_total:
271274
break
@@ -279,7 +282,7 @@ def _put_data(self, data):
279282
qr_version['blocks'][self._error_correction_level]
280283
)
281284

282-
# データの並び替え
285+
# Construct the final message codeword sequence
283286
# Data codewords
284287
final_codewords = []
285288
for i in range(len(data_codewords_per_block[-1])):
@@ -297,8 +300,8 @@ def _put_data(self, data):
297300
final_codewords.append(rs_codewords[i])
298301
self._logger.debug(f"Put RS data codewords {i} : {rs_codewords[i]}")
299302

300-
# 配置
301-
dy = -1 # 最初は上方向
303+
# Codeword placement
304+
dy = -1 # Up
302305
current_codeword_idx = 0
303306
current_bit_idx = 0
304307
cx, cy = self._width - 2, self._height - 6
@@ -308,30 +311,28 @@ def _put_data(self, data):
308311
while True:
309312
for x in [cx, cx-1]:
310313
if self._qr[cy][x] == Color.UNDEFINED:
311-
# 空白のセルのみ処理する
314+
# Process only empty cell
312315
if current_codeword_idx == len(final_codewords):
313-
# codewordsを配置しきった場合はremainder_bitsがあれば配置する
316+
# Remainder bits
314317
self._qr[cy][x] = Color.WHITE
315318
mask_area[cy][x] = True
316319
remainder_bits -= 1
317320
else:
318-
# codewordsを配置する
321+
# Codewords
319322
self._qr[cy][x] = Color.BLACK if final_codewords[current_codeword_idx][current_bit_idx] == '1' else Color.WHITE
320323
mask_area[cy][x] = True
321324
current_bit_idx += 1
322325
if current_bit_idx == 8:
323326
current_bit_idx = 0
324327
current_codeword_idx += 1
325328

326-
# codewordsの配置が終わりremainder_bitsも残っていなければ終了
327329
if current_codeword_idx == len(final_codewords) and remainder_bits == 0:
328330
break
329331

330-
# codewordsの配置が終わりremainder_bitsも残っていなければ終了
331332
if current_codeword_idx == len(final_codewords) and remainder_bits == 0:
332333
break
333334

334-
# 座標の更新
335+
# Update current coordinates
335336
if dy < 0 and cy == 1:
336337
cx -= 2
337338
dy = 1
@@ -369,7 +370,7 @@ def _split_into_blocks(self, codewords, blocks_definition):
369370
def _convert_to_bites_data(self, data, character_count_length, codewords_total):
370371
encoded_data = ByteEncoder.encode(data, character_count_length)
371372

372-
# 付加できるなら終端文字を付け加える
373+
# Terminator (may be truncated)
373374
if len(encoded_data) + 3 <= codewords_total * 8:
374375
encoded_data += "000"
375376

@@ -390,7 +391,7 @@ def _apply_mask(self, mask_area):
390391

391392
@staticmethod
392393
def validate_version(version_name):
393-
return version_name in qr_versions
394+
return version_name in rMQRVersions
394395

395396

396397
class DataTooLongError(ValueError):

src/rmqrcode/util/galois_fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class GaloisFields:
44
i2e = {}
55

66
def __init__(self):
7-
# GF(2^8)の既約多項式
7+
# Irreducible polynomial in GF(2^8)
88
p = (1<<8)|(1<<4)|(1<<3)|(1<<2)|1
99

1010
self.e2i[0] = 1

0 commit comments

Comments
 (0)