Skip to content

Commit 2e3705c

Browse files
committed
qrcode: Optimise masking and data layout hot loops
Build the masklayers row by row with a six-entry view of the extruded function pattern layer and the column kept on the stack, walking positions sequentially. Merge each bitstream bit into the layers without an intermediate definition or a repeated address lookup. Keep the module index on the stack in the per-mask extraction loop and hoist the negated mask bit position out of the loop.
1 parent cb014c3 commit 2e3705c

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

src/qrcode.ps.src

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,19 +1606,24 @@ begin
16061606

16071607
%
16081608
% Build masklayers from the extruded funcpatlayers, with function cell
1609-
% values included (as 0 or 255)
1609+
% values included (as 0 or 255), walking positions sequentially with
1610+
% the column kept on the stack
16101611
%
16111612
/masklayers rows cols mul array def
16121613
0 1 rows 1 sub {
16131614
/j exch def
1614-
0 1 cols 1 sub {
1615-
/i exch def
1616-
/pos i j qmv def
1617-
masklayers pos pixs pos get dup -1 eq {
1618-
pop funcpatlayers j 6 mul 72 mod i 6 mod add get
1615+
/jc j cols mul def
1616+
/fprow funcpatlayers j 6 mul 72 mod 6 getinterval def
1617+
0 1 cols 1 sub { % i
1618+
jc 1 index add % i pos
1619+
pixs 1 index get % i pos v
1620+
dup -1 eq {
1621+
pop fprow 2 index 6 mod get
16191622
} {
16201623
255 mul
1621-
} ifelse put
1624+
} ifelse % i pos val
1625+
masklayers 3 1 roll put
1626+
pop
16221627
} for
16231628
} for
16241629

@@ -1634,8 +1639,9 @@ begin
16341639
posx 0 lt {exit} if
16351640
/pos posx posy qmv def
16361641
pixs pos get -1 eq {
1637-
/bit cws num 8 idiv get 7 num 8 mod sub neg bitshift 1 and def
1638-
masklayers pos masklayers pos get bit 255 mul xor put
1642+
masklayers pos 2 copy get
1643+
cws num 8 idiv get 7 num 8 mod sub neg bitshift 1 and 255 mul
1644+
xor put
16391645
/num num 1 add def
16401646
} if
16411647
col 1 eq {
@@ -1783,11 +1789,10 @@ begin
17831789
/bestscore 999999999 def
17841790
0 1 nmasks 1 sub {
17851791
/m exch def
1786-
/maskbit maskbits m get def
1792+
/mbneg maskbits m get neg def
17871793
/masksym rows cols mul array def
17881794
0 1 rows cols mul 1 sub {
1789-
/i exch def
1790-
masksym i masklayers i get maskbit neg bitshift 1 and put
1795+
masksym exch dup masklayers exch get mbneg bitshift 1 and put
17911796
} for
17921797
nmasks 1 ne { % Not rMQR nor user-specified mask
17931798
/score masksym format (full) eq {evalfull} {evalmicro} ifelse def

0 commit comments

Comments
 (0)