- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.py
More file actions
Latest commit
77 lines (52 loc) · 3.03 KB
/
Copy pathCore.py
File metadata and controls
77 lines (52 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
fromjsonimportload
fromPILimportImage
fromFunctionsimportverify_data, digit_encoding, alphadigit_encoding, UTF8_encoding, determine_version, fill_data, split_into_blocks, RS_encoding, draw_info_codes, apply_data, choose_mask
fromMasksimportMASKS
CORRECTION_LEVELS= ['L', 'M', 'Q', 'H']
ENCODING_TYPES= {'digit': '0001', 'alphadigit': '0010', 'UTF8': '0100'}
withopen('lengthes of service fields.json', 'r') asinput_file:
SERVICE_FIELDS_LENGTHES=load(input_file)
defmain(raw_input, encoding_type, choice):
ifnotverify_data(raw_input, encoding_type):
return (0, None)
else:
ifencoding_type=='digit':
bit_input=digit_encoding(raw_input)
elifencoding_type=='alphadigit':
bit_input=alphadigit_encoding(raw_input.upper())
ifencoding_type=='UTF8':
bit_input=UTF8_encoding(raw_input)
correction_level=CORRECTION_LEVELS[int(choice)]
flag, version, index=determine_version(correction_level, encoding_type, len(bit_input))
ifnotflag:
return (1, None)
else:
ifencoding_type=='UTF8':
bit_input=ENCODING_TYPES[encoding_type] +bin(len(bit_input) //8)[2:].zfill(SERVICE_FIELDS_LENGTHES[encoding_type][index]) +bit_input+'0000'
else:
bit_input=ENCODING_TYPES[encoding_type] +bin(len(raw_input))[2:].zfill(SERVICE_FIELDS_LENGTHES[encoding_type][index]) +bit_input+'0000'
byte_input=fill_data(correction_level, version, bit_input)
blocks=split_into_blocks(correction_level, version, byte_input)
RS_encoded_blocks= []
forblockinblocks:
RS_encoded_blocks.append(RS_encoding(correction_level, version, block))
bin_output=''
foriinrange(len(blocks[-1])):
forjinrange(len(blocks)):
ifi!=len(blocks[j]):
bin_output+=blocks[j][i]
foriinrange(len(RS_encoded_blocks[-1])):
forjinrange(len(RS_encoded_blocks)):
ifi!=len(RS_encoded_blocks[j]):
bin_output+=RS_encoded_blocks[j][i]
white= (255, 255, 255, 255)
black= (0, 0, 0, 255)
path='frames/frame_'+str(version) +'.png'
image=Image.open(path)
size=image.size
pixels=image.load()
choose_mask(image, correction_level, size, pixels, bin_output, white, black)
background=Image.new('RGBA', (image.width+8, image.width+8), color='white')
background.paste(image, (4, 4, image.width+4, image.width+4))
image=background.resize((800, 800), Image.NEAREST)
return (2, image)