Skip to content

Commit

Permalink
finished qr code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
barrettotte committed Sep 6, 2021
1 parent d9d9d8c commit 148decb
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 47 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ I constrained the QR code generation a lot. I just wanted to encode a url, not b

- Byte mode encoding only
- QR version 4 and below (up to 80 characters with v4-L)
- Mask evaluation not implemented, hardcoded to TODO: ?
- Mask evaluation not implemented, hardcoded to mask 0 (I think masks only effect scan efficiency)

## Running Locally

Expand Down
Binary file added docs/asm_qrcode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 5 additions & 8 deletions main.s
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
.equ MAX_DWB, 80 // max data words per block (v4-L)
.equ MAX_ECWB, 28 // max error correction words per block (v2-H)
.equ MAX_PAYLOAD, 255 // max size of payload to transform into QR code
.equ MAX_QR_SIZE, 1096 // max modules in QR matrix; ((V*4)+21)^2, round next byte
.equ MAX_QR_SIZE, 1696 // max modules in QR matrix; ((V*4)+21+8)^2, to next word

.data

Expand Down Expand Up @@ -83,7 +83,7 @@ g1bw_cap: .space 1 // data words in each group 1 block
count_ind: .space 1 // character count indicator byte

pyld_size: .space 1 // calculated size of payload
pyld_bits: .space 2 // payload size in bits TODO: needed?
pyld_bits: .space 2 // payload size in bits
qr_width: .space 1 // width of QR matrix
bin_str: .space 8+1 // temp for byte to binary ASCII string convert

Expand Down Expand Up @@ -403,14 +403,11 @@ qr_fill:
bl qr_fmtbits // add format bits to QR matrix

bl qr_mask0 // apply mask 0 to QR matrix
bl qr_quiet // add quiet zone to QR matrix
add r2, r2, #8 // add quiet zone width

ldr r0, =qr_mat // pointer to QR matrix
ldr r1, =out_file // pointer to PBM file name
mov r2, r11 // pass qr_width
bl qr_normalize // normalize QR matrix to ['0','1']

qr_output:
mov r2, r11 // pass qr_width
ldr r1, =out_file // pointer to PBM file name
mov r3, r2 // use width for PBM width + length (square)
bl pbm_write // create new PBM file from QR matrix

Expand Down
68 changes: 38 additions & 30 deletions qrcode.pbm
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
P1
29 29
1 1 1 1 1 1 1 0 1 1 0 0 0 0 0 1 1 0 0 1 0 0 1 1 1 1 1 1 1
1 0 0 0 0 0 1 0 1 0 1 1 1 1 0 0 0 1 1 1 1 0 1 0 0 0 0 0 1
1 0 1 1 1 0 1 0 1 1 1 1 0 0 0 1 0 0 1 1 0 0 1 0 1 1 1 0 1
1 0 1 1 1 0 1 0 1 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 1 1 0 1
1 0 1 1 1 0 1 0 1 1 0 1 0 0 0 1 1 0 1 1 0 0 1 0 1 1 1 0 1
1 0 0 0 0 0 1 0 0 1 0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 0 0 0 1
1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0
0 1 1 0 1 0 1 1 0 1 1 1 0 1 0 0 0 1 0 1 1 0 1 0 1 1 1 1 1
1 1 0 1 1 0 0 0 1 1 1 0 1 0 0 1 0 0 1 0 1 0 1 0 0 0 1 0 1
1 1 0 0 1 0 1 1 1 0 1 1 1 1 1 1 1 0 1 0 1 0 0 0 0 1 1 1 1
1 1 0 0 0 1 0 1 1 0 1 1 0 0 0 1 0 1 0 1 1 1 1 1 0 1 0 1 0
0 0 0 0 0 0 1 0 0 1 1 0 1 0 1 0 0 1 0 0 1 0 1 1 0 0 0 0 0
0 1 1 1 1 0 0 0 0 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 0 0 1 1
0 0 1 1 1 0 1 0 1 0 1 1 1 1 0 1 0 0 0 0 0 0 1 1 0 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0 1 1 1 1 1 1 1 1 1 0 0 0 1 1 0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 0 1 0 1 1 1 0 1 0 0 0 1 1 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
56 changes: 48 additions & 8 deletions qrcode.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
.global qr_zigzag // "zigzag" payload into QR matrix
.global qr_fmtbits // add format bits to QR matrix
.global qr_mask0 // apply mask 0 to QR matrix

@ TODO: .global qr_quiet // add quiet zone to QR matrix
.global qr_quiet // add quiet zone to QR matrix

// internal subroutines
// add_square - add a square to QR matrix
Expand Down Expand Up @@ -318,12 +317,12 @@ _qrn_x_loop:
_qrn_y_loop:
ldrb r6, [r0, r9] // qr_mat[qr_idx]

cmp r6, #MOD_EMP // check if reserved empty
beq _qrn_ltmod // normalize to light
cmp r6, #MOD_RLT // check if reserved light
beq _qrn_ltmod // normalize to light
cmp r6, #MOD_RDK // check if reserved dark
beq _qrn_dkmod // normalize to dark
cmp r6, #MOD_EMP // check if empty module
beq _qrn_ltmod // normalize to data light module
cmp r6, #MOD_RLT // check if reserved light module
beq _qrn_ltmod // normalize to data light module
cmp r6, #MOD_RDK // check if reserved dark module
beq _qrn_dkmod // normalize to data dark module

b _qrn_y_next // already normalized; iterate
_qrn_dkmod:
Expand Down Expand Up @@ -564,4 +563,45 @@ _qrm0_y_next:
pop {r4-r11, lr} // restore caller's vars + return address
bx lr // return from subroutine

qr_quiet: // ***** Add quiet zone to QR matrix *****
// r0 - pointer to QR matrix
// r1 - unused
// r2 - QR width
// r3 - unused
push {r4-r11, lr} // save caller's vars + return address

mov r4, r2 // y = qr_width
sub r4, r4, #1
_qrq_y_loop:
mov r5, r2 // x = qr_width
sub r5, r5, #1
_qrq_x_loop:
umull r6, r7, r4, r2 // q = y * qr_width
add r6, r6, r5 // q += x
ldrb r10, [r0, r6] // mod = qr_mat[q]
_qrq_transform:
push {r10} // save original module
add r7, r2, #8 // qr_width + 8
add r8, r4, #4 // y + (8/2)
umull r10, r11, r8, r7 // t = (y + (8/2)) * (qr_width + 8)
add r11, r10, r5 // t += x
add r11, r11, #4 // t += (8/2)
pop {r10} // restore original module
strb r10, [r0, r11] // qr_mat[t] = qr_mat[q]
_qrq_reset:
mov r10, #MOD_DLT // light module '0'
strb r10, [r0, r6] // reset moved module

_qrq_x_next:
sub r5, r5, #1 // x--
cmp r5, #0 // check loop condition
bge _qrq_x_loop // while (x > 0)
_qrq_y_next:
sub r4, r4, #1 // y--
cmp r4, #0 // check loop condition
bge _qrq_y_loop // while (y > 0)

pop {r4-r11, lr} // restore caller's vars + return address
bx lr // return from subroutine

.end // end of source

0 comments on commit 148decb

Please sign in to comment.