Skip to content

Commit 7abd516

Browse files
committed
rsecprime: Require caller-reversed coefficients
Callers deliver the generator coefficients reversed from their cached gencoeffs procedures, matching the rsecbinary interface; the ECC codeword count is the length of the coefficient array.
1 parent e6ed27e commit 7abd516

5 files changed

Lines changed: 34 additions & 30 deletions

File tree

src/dotcode.ps.src

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ begin
218218
} for
219219
pop % i
220220
} for
221-
% Flip to standard g(x) form: drop the leading 1 and reverse coeffs[1..NC]
222-
% so the constant term ends up at index 0.
223-
NC -1 1 { coeffs exch get } for
221+
% Drop the leading 1, delivering the coefficients reversed as rsecprime
222+
% requires
223+
1 1 NC { coeffs exch get } for
224224
NC array astore
225225
} bind def
226226

@@ -1184,7 +1184,7 @@ begin
11841184
% spec's negated form in lfsr[0..NC), so no post-pass is needed.
11851185
%
11861186
/lfsr NC array def
1187-
{step mul start add rscws exch get} ND coeffs NC lfsr 113 //rsecprime exec
1187+
{step mul start add rscws exch get} ND coeffs lfsr 113 //rsecprime exec
11881188
0 1 NC 1 sub {
11891189
/j exch def
11901190
rscws ND j add offset lfsr j get put

src/micropdf417.ps.src

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,11 @@ begin
564564
} for
565565
/coeffs coeffs 0 coeffs length 1 sub getinterval def
566566
coeffs length 1 sub -2 0 { coeffs exch 2 copy get 929 exch sub put } for
567-
coeffs
567+
568+
%
569+
% Deliver the coefficients reversed, as rsecprime requires
570+
%
571+
[ k 1 sub -1 0 { coeffs exch get } for ]
568572
} bind def
569573

570574
%
@@ -1273,7 +1277,7 @@ begin
12731277
%
12741278
% Derive the error codewords directly into cws[n..n+k)
12751279
%
1276-
{cws exch get} n coeffs k cws n k getinterval 929 //rsecprime exec
1280+
{cws exch get} n coeffs cws n k getinterval 929 //rsecprime exec
12771281

12781282
options /debugecc known
12791283
/uk.co.terryburton.bwipp.global_ctx dup where {exch get /enabledebug known} {pop false} ifelse

src/pdf417.ps.src

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,11 @@ begin
433433
} for
434434
/coeffs coeffs 0 k getinterval def
435435
k 1 sub -2 0 { coeffs exch 2 copy get 929 exch sub put } for
436-
coeffs
436+
437+
%
438+
% Deliver the coefficients reversed, as rsecprime requires
439+
%
440+
[ k 1 sub -1 0 { coeffs exch get } for ]
437441
} bind def
438442

439443
%
@@ -1167,7 +1171,7 @@ begin
11671171
%
11681172
% Derive the error codewords directly into cws[n..n+k)
11691173
%
1170-
{cws exch get} n coeffs k cws n k getinterval 929 //rsecprime exec
1174+
{cws exch get} n coeffs cws n k getinterval 929 //rsecprime exec
11711175

11721176
options /debugecc known
11731177
/uk.co.terryburton.bwipp.global_ctx dup where {exch get /enabledebug known} {pop false} ifelse

src/rsecprime.ps.src

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,25 @@ begin
4242
%
4343
% Reed-Solomon encoder for prime-field GF(p).
4444
%
45-
% Runs a streaming LFSR over nd data codewords using the generator polynomial
46-
% coeffs. The caller-owned lfsr is the shift register; on return, its first
47-
% nc cells are the ECC codewords in the negated form expected by callers
48-
% (pdf417, micropdf417, ultracode): this fuses what used to be a separate
49-
% post-pass of (p - cws[i]) mod p into the inner update.
45+
% Runs a streaming LFSR over nd data codewords using the generator
46+
% polynomial. The caller-owned lfsr is the shift register; on return, its
47+
% first nc cells are the ECC codewords, where nc is the length of
48+
% coeffsrev, negated ((p - c) mod p) as the callers expect. The caller
49+
% must supply the generator coefficients reversed.
5050
%
5151
/rsecprime {
5252

5353
8 dict begin
5454

55-
/p exch def % Prime modulus
56-
/lfsr exch def % Workspace of length at least nc
57-
/nc exch def % Number of ECC codewords to produce
58-
/coeffs exch def % Generator polynomial coefficients
59-
/nd exch def % Number of data codewords
60-
/getdata exch def % Implements fetching nth codeword
55+
/p exch def % Prime modulus
56+
/lfsr exch def % Workspace of length at least nc
57+
/coeffsrev exch def % Reversed generator polynomial coefficients
58+
/nd exch def % Number of data codewords
59+
/getdata exch def % Implements fetching nth codeword
6160

62-
0 1 nc 1 sub {lfsr exch 0 put} for % Zero LFSR
61+
/nc coeffsrev length def % Number of ECC codewords to produce
6362

64-
%
65-
% Reverse coeffs to simplify the inner loop
66-
%
67-
/coeffsrev nc array def
68-
0 1 nc 1 sub {
69-
/j exch def
70-
coeffsrev j coeffs nc 1 sub j sub get put
71-
} for
63+
0 1 nc 1 sub {lfsr exch 0 put} for % Zero LFSR
7264

7365
0 1 nd 1 sub { % m
7466
getdata exec lfsr 0 get sub p add p mod % fb = (data[m] - S[0]) mod p

src/ultracode.ps.src

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,11 @@ begin
196196
} for
197197
/coeffs coeffs 0 coeffs length 1 sub getinterval def
198198
coeffs length 1 sub -2 0 { coeffs exch 2 copy get 283 exch sub put } for
199-
coeffs
199+
200+
%
201+
% Deliver the coefficients reversed, as rsecprime requires
202+
%
203+
[ k 1 sub -1 0 { coeffs exch get } for ]
200204
} bind def
201205

202206
%
@@ -430,7 +434,7 @@ begin
430434
%
431435
/rsdata [ start mcc acc dcws aload pop ] def
432436
/ecws k array def
433-
{rsdata exch get} n coeffs k ecws 283 //rsecprime exec
437+
{rsdata exch get} n coeffs ecws 283 //rsecprime exec
434438

435439
options /debugecc known
436440
/uk.co.terryburton.bwipp.global_ctx dup where {exch get /enabledebug known} {pop false} ifelse

0 commit comments

Comments
 (0)