Skip to content

Commit 55a24b9

Browse files
committed
Rework RSEC into shared helpers
1 parent a789b30 commit 55a24b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+521
-310
lines changed

CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
XXXX-XX-XX
2+
3+
* Reed-Solomon encoding was factored into shared rsecbinary and rsecprime helpers.
4+
* Wrappers for encoders using the rsec helpers now list them in REQUIRES so standalone builds include them.
5+
6+
17
2026-04-16
28

39
* The renderer was changed to gridfit in the same direction when fitting independent axes.

src/azteccode.ps.src

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
% IN THE SOFTWARE.
3333

3434
% --BEGIN ENCODER azteccode--
35-
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput setanycolor fifocache render renmatrix--
35+
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput setanycolor fifocache rsecbinary render renmatrix--
3636
% --DESC: Aztec Code
3737
% --EXAM: This is Aztec Code
3838
% --EXOP: format=full
@@ -46,6 +46,7 @@ dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
4646
dup /processoptions dup /uk.co.terryburton.bwipp findresource put
4747
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
4848
dup /fifocache dup /uk.co.terryburton.bwipp findresource put
49+
dup /rsecbinary dup /uk.co.terryburton.bwipp findresource put
4950
dup /setuphooks dup /uk.co.terryburton.bwipp findresource put
5051
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
5152
dup /render dup /uk.co.terryburton.bwipp findresource put
@@ -895,7 +896,8 @@ begin
895896
(input.encoding) //azteccode.after exec
896897

897898
%
898-
% Reed-Solomon algorithm
899+
% Reed-Solomon algorithm. Returns rsnc ECC codewords. The GF parameters
900+
% (and hence rsprod) vary with rsbt, so both are bound per call.
899901
%
900902
/rscodes {
901903

@@ -924,27 +926,9 @@ begin
924926
/coeffs rsnc rsbt //azteccode.coeffscachefetch exec def
925927
(ecc.coeffs) //azteccode.after exec
926928

927-
%
928-
% Extend the input with the error correction values
929-
%
930-
/nd rscws length def
931-
/rscws [ rscws aload pop rsnc {0} repeat 0 ] def
932-
0 1 nd 1 sub { % i
933-
rscws exch get rscws nd get xor % k = rscws[i] ^ rscw[nd]
934-
0 1 rsnc 1 sub { % j
935-
dup
936-
rscws exch nd add 2 copy 1 add get % ... rscws nd+j rscws[nd+j+1]
937-
coeffs rsnc 6 -1 roll sub 1 sub get % ... coeffs[rsnc-1-j]
938-
4 index % ... k
939-
rsprod xor put % rscws[nd+j] = rscws[nd+j+1] ^ (coeffs[rsnc-1-j] * k)
940-
} for
941-
pop % k
942-
} for
943-
944-
%
945-
% Return all but the last codeword
946-
%
947-
rscws 0 rscws length 1 sub getinterval
929+
/lfsr rsnc array def
930+
{rscws exch get} rscws length coeffs rsnc lfsr /rsprod load //rsecbinary exec
931+
lfsr
948932

949933
(ecc.cws) //azteccode.after exec
950934

@@ -962,7 +946,7 @@ begin
962946
mode 2#0000000011110000 and -4 bitshift
963947
mode 2#0000000000001111 and
964948
] def
965-
/mode mode 6 4 rscodes def
949+
/mode [ mode aload pop mode 6 4 rscodes aload pop ] def
966950
} if
967951
format (compact) eq {
968952
/mode layers 1 sub 6 bitshift cws length 1 sub add def
@@ -971,15 +955,15 @@ begin
971955
mode 2#11110000 and -4 bitshift
972956
mode 2#00001111 and
973957
] def
974-
/mode mode 5 4 rscodes def
958+
/mode [ mode aload pop mode 5 4 rscodes aload pop ] def
975959
} if
976960
format (rune) eq {
977961
/mode barcode cvi def
978962
/mode [
979963
mode 2#11110000 and -4 bitshift
980964
mode 2#00001111 and
981965
] def
982-
/mode mode 5 4 rscodes def
966+
/mode [ mode aload pop mode 5 4 rscodes aload pop ] def
983967
/mode [mode {2#1010 xor} forall] def % Invert alternate bits
984968
} if
985969
/modebits mode length 4 mul string def
@@ -996,9 +980,9 @@ begin
996980

997981
options /debugecc known
998982
/uk.co.terryburton.bwipp.global_ctx dup where {exch get /enabledebug known} {pop false} ifelse
999-
and { /bwipp.debugecc ecws cws length ecws length cws length sub getinterval //raiseerror exec } if
983+
and { /bwipp.debugecc ecws //raiseerror exec } if
1000984

1001-
/cws ecws def
985+
/cws [ cws aload pop ecws aload pop ] def
1002986
format (full) eq {
1003987
/databits layers layers mul 16 mul layers 112 mul add string def
1004988
} {

src/azteccodecompact.ps.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
% IN THE SOFTWARE.
3333

3434
% --BEGIN ENCODER azteccodecompact--
35-
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput setanycolor fifocache render renmatrix azteccode--
35+
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput setanycolor fifocache rsecbinary render renmatrix azteccode--
3636
% --DESC: Compact Aztec Code
3737
% --EXAM: 1234
3838
% --EXOP:

src/aztecrune.ps.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
% IN THE SOFTWARE.
3333

3434
% --BEGIN ENCODER aztecrune--
35-
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput setanycolor fifocache render renmatrix azteccode--
35+
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput setanycolor fifocache rsecbinary render renmatrix azteccode--
3636
% --DESC: Aztec Runes
3737
% --EXAM: 1
3838
% --EXOP:

src/codeone.ps.src

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
% IN THE SOFTWARE.
3333

3434
% --BEGIN ENCODER codeone--
35-
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput setanycolor fifocache render renmatrix--
35+
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput setanycolor fifocache rsecbinary render renmatrix--
3636
% --DESC: Code One
3737
% --EXAM: Code One
3838
% --EXOP:
@@ -46,6 +46,7 @@ dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
4646
dup /processoptions dup /uk.co.terryburton.bwipp findresource put
4747
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
4848
dup /fifocache dup /uk.co.terryburton.bwipp findresource put
49+
dup /rsecbinary dup /uk.co.terryburton.bwipp findresource put
4950
dup /setuphooks dup /uk.co.terryburton.bwipp findresource put
5051
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
5152
dup /render dup /uk.co.terryburton.bwipp findresource put
@@ -1092,39 +1093,17 @@ begin
10921093
(ecc.cws) //codeone.before exec
10931094

10941095
%
1095-
% De-interleave the codewords into blocks
1096+
% Reed-Solomon algorithm. Each block's data is read directly from cws via
1097+
% interleaved indexing.
10961098
%
1097-
/cwbs rsbl array def % Array of data codeword blocks
1098-
/ecbs rsbl array def % Array of error correction blocks
1099+
/ecbs rsbl array def
10991100
0 1 rsbl 1 sub {
1100-
/i exch def
1101-
/cwb dcpb array def
1102-
0 1 dcpb 1 sub {
1103-
/j exch def
1104-
cwb j cws j rsbl mul i add get put
1105-
} for
1106-
cwbs i cwb put
1107-
} for
1108-
1109-
%
1110-
% Reed-Solomon algorithm to derive the error correction codewords
1111-
%
1112-
0 1 cwbs length 1 sub {
1113-
/i exch def
1114-
/rscws [ cwbs i get aload pop ecpb {0} repeat ] def
1115-
0 1 dcpb 1 sub { % m
1116-
rscws 1 index get % k = rscws[m]
1117-
0 1 ecpb 1 sub { % j
1118-
rscws 3 index 2 index add 1 add 2 copy get % ... rscws m+j+1 rscws[m+j+1]
1119-
coeffs ecpb 6 -1 roll sub 1 sub get % ... coeffs[ecpb-j-1]
1120-
4 index % ... k
1121-
//codeone.rsprod exec % p = coeffs[ecpb-j-1] * k
1122-
xor put % rscws[m+j+1] = rscws[m+j+1] ^ p
1123-
} for
1124-
pop % k
1125-
pop % m
1126-
} for
1127-
ecbs i rscws dcpb ecpb getinterval put
1101+
/blk exch def
1102+
ecbs blk
1103+
/lfsr ecpb array def
1104+
{cws exch rsbl mul blk add get} dcpb coeffs ecpb lfsr //codeone.rsprod //rsecbinary exec
1105+
lfsr
1106+
put
11281107
} for
11291108

11301109
options /debugecc known
@@ -1134,7 +1113,7 @@ begin
11341113
%
11351114
% Extend codewords with the interleaved error correction codes
11361115
%
1137-
/cws [ cws aload pop rscw {0} repeat ] def
1116+
/cws cws length rscw add array dup 0 cws putinterval def
11381117
0 1 rscw 1 sub {
11391118
/i exch def
11401119
cws dcws i add ecbs i rsbl mod get i rsbl idiv get put

src/databarexpandedcomposite.ps.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
% IN THE SOFTWARE.
3333

3434
% --BEGIN ENCODER databarexpandedcomposite--
35-
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput gs1process setanycolor fifocache render renlinear renmatrix databarexpanded micropdf417 pdf417 gs1-cc--
35+
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput gs1process setanycolor fifocache rsecprime render renlinear renmatrix databarexpanded micropdf417 pdf417 gs1-cc--
3636
% --DESC: GS1 DataBar Expanded Composite
3737
% --EXAM: (01)09521234543213(3103)001234|(91)1A2B3C4D5E
3838
% --EXOP:

src/databarexpandedstackedcomposite.ps.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
% IN THE SOFTWARE.
3333

3434
% --BEGIN ENCODER databarexpandedstackedcomposite--
35-
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput gs1process setanycolor fifocache render renlinear renmatrix databarexpanded databarexpandedstacked micropdf417 pdf417 gs1-cc--
35+
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput gs1process setanycolor fifocache rsecprime render renlinear renmatrix databarexpanded databarexpandedstacked micropdf417 pdf417 gs1-cc--
3636
% --DESC: GS1 DataBar Expanded Stacked Composite
3737
% --EXAM: (01)09521234543213(10)ABCDEF|(21)12345678
3838
% --EXOP: segments=4

src/databarlimitedcomposite.ps.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
% IN THE SOFTWARE.
3333

3434
% --BEGIN ENCODER databarlimitedcomposite--
35-
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput gs1process setanycolor fifocache render renlinear renmatrix databarlimited micropdf417 pdf417 gs1-cc--
35+
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput gs1process setanycolor fifocache rsecprime render renlinear renmatrix databarlimited micropdf417 pdf417 gs1-cc--
3636
% --DESC: GS1 DataBar Limited Composite
3737
% --EXAM: (01)09521234543213|(21)abcdefghijklmnopqrst
3838
% --EXOP:

src/databaromnicomposite.ps.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
% IN THE SOFTWARE.
3333

3434
% --BEGIN ENCODER databaromnicomposite--
35-
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput gs1process setanycolor fifocache render renlinear renmatrix databaromni micropdf417 pdf417 gs1-cc--
35+
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput gs1process setanycolor fifocache rsecprime render renlinear renmatrix databaromni micropdf417 pdf417 gs1-cc--
3636
% --DESC: GS1 DataBar Omnidirectional Composite
3737
% --EXAM: (01)09521234543213|(11)990102
3838
% --EXOP:

src/databarstackedcomposite.ps.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
% IN THE SOFTWARE.
3333

3434
% --BEGIN ENCODER databarstackedcomposite--
35-
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput gs1process setanycolor fifocache render renlinear renmatrix databaromni databarstacked micropdf417 pdf417 gs1-cc--
35+
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput gs1process setanycolor fifocache rsecprime render renlinear renmatrix databaromni databarstacked micropdf417 pdf417 gs1-cc--
3636
% --DESC: GS1 DataBar Stacked Composite
3737
% --EXAM: (01)09521234543213|(17)010200
3838
% --EXOP:

0 commit comments

Comments
 (0)