3232% IN THE SOFTWARE.
3333
3434% --BEGIN ENCODER dotcode--
35- % --REQUIRES preamble raiseerror processoptions parseinput setanycolor rendertext renmatrix--
35+ % --REQUIRES preamble raiseerror processoptions parseinput setanycolor fifocache rendertext renmatrix--
3636% --DESC: DotCode
3737% --EXAM: This is DotCode
3838% --EXOP: inkspread=0.16
@@ -44,6 +44,7 @@ true setglobal
4444dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
4545dup /processoptions dup /uk.co.terryburton.bwipp findresource put
4646dup /parseinput dup /uk.co.terryburton.bwipp findresource put
47+ dup /fifocache dup /uk.co.terryburton.bwipp findresource put
4748dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
4849begin
4950
@@ -188,6 +189,44 @@ begin
188189 exch get /preload known {//dotcode.latevars /init get exec} if
189190} {pop} ifelse
190191
192+ %
193+ % Generate Reed-Solomon coefficients for given NC (uses rsalog from currentdict)
194+ %
195+ /dotcode.gencoeffs {
196+ /coeffs [ 1 NC {0} repeat ] def
197+ 1 1 NC {
198+ /i exch def
199+ NC -1 1 {
200+ /j exch def
201+ coeffs j coeffs j get 113 add rsalog i get coeffs j 1 sub get mul 113 mod sub 113 mod put
202+ } for
203+ } for
204+ coeffs
205+ } bind def
206+
207+ %
208+ % FIFO cache for ECC polynomials
209+ %
210+ % 79 unique keys: NC=1-79 continuous range from symbol interleaving
211+ %
212+ /dotcode.coeffscachemax 79 def % Override with global_ctx.dotcode.coeffscachemax
213+ /dotcode.coeffscachelimit 3160 def % Override with global_ctx.dotcode.coeffscachelimit
214+ /uk.co.terryburton.bwipp.global_ctx dup where {
215+ exch get
216+ dup /dotcode.coeffscachemax 2 copy known {get /dotcode.coeffscachemax exch def} {pop pop} ifelse
217+ /dotcode.coeffscachelimit 2 copy known {get /dotcode.coeffscachelimit exch def} {pop pop} ifelse
218+ } {pop} ifelse
219+
220+ /dotcode.coeffscache dotcode.coeffscachemax dotcode.coeffscachelimit //fifocache exec def
221+
222+ /dotcode.coeffscachefetch {
223+ /NC exch def
224+ NC
225+ { //dotcode.gencoeffs exec }
226+ { length }
227+ //dotcode.coeffscache /fetch get exec
228+ } bind def
229+
191230/dotcode {
192231
193232 128 dict begin
@@ -1067,14 +1106,7 @@ begin
10671106 /ND nd 1 add start sub step add 1 sub step idiv def
10681107 /NW nw 1 add start sub step add 1 sub step idiv def
10691108 /NC NW ND sub def
1070- /coeffs [ 1 NC {0} repeat ] def
1071- 1 1 NC {
1072- /i exch def
1073- NC -1 1 {
1074- /j exch def
1075- coeffs j coeffs j get 113 add rsalog i get coeffs j 1 sub get mul 113 mod sub 113 mod put
1076- } for
1077- } for
1109+ /coeffs NC //dotcode.coeffscachefetch exec def
10781110 0 1 ND 1 sub {
10791111 /t exch rscws exch offset get rscws ND offset get add 113 mod def
10801112 0 1 NC 2 sub {
0 commit comments