Skip to content

pdf417: fix left row indicator for rows using cluster 0 symbol characters - #102

Merged
danielwhite merged 1 commit into
boombuler:masterfrom
danielwhite:fix-pdf417-encoding
Oct 11, 2026
Merged

danielwhite merged 1 commit into
boombuler:masterfrom
danielwhite:fix-pdf417-encoding

Conversation

@danielwhite

Copy link
Copy Markdown
Collaborator

This fixes #93 so that rows using cluster 0 symbol characters are correctly calculated.

A regression test has been included with hand-computed values to ensure that we get the expected results across a range of inputs.

The major impact of this change to downstream consumers is that any golden tests against the output of this package will need to be updated.

Specification

The correction is sourced from the USS PDF417 specification:

Left row indicator:

$$ L_i = \begin{cases} 30x_i + y & \text{if } c_i = 0 \\ 30x_i + z & \text{if } c_i = 3 \\ 30x_i + v & \text{if } c_i = 6 \end{cases} $$

Right row indicator:

$$ R_i = \begin{cases} 30x_i + v & \text{if } c_i = 0 \\ 30x_i + y & \text{if } c_i = 3 \\ 30x_i + z & \text{if } c_i = 6 \end{cases} $$

Where:

  • $x_i = (\text{row number} - 1)\ \mathrm{div}\ 3$ for $i = 1$ to $90$
  • $y = (\text{number of rows} - 1)\ \mathrm{div}\ 3$
  • $z = (\text{error correction level}) \cdot 3 + (\text{number of rows} - 1)\ \mathrm{mod}\ 3$
  • $v = \text{number of columns in the data region} - 1$
  • $c_i = \text{cluster number of the } i\text{th row}$

div is the integer division operator, rounding down; mod is the remainder after division.

This correction is souced from the USS PDF417 specification:

> The symbol character value of the left row indicator (L_i) is given
> by:
>
> L_i = 30 * x_i + y if c_i = 0
> L_i = 30 * x_i + z if c_i = 3
> L_i = 30 * x_i + v if c_i = 6
>
> Where:
>
> x_i = (row number -1) div 3 for i = 1 to 90
> y = (number of rows - 1) div 3
> z = (error correction level) * 3 + (number of rows - 1) mod 3
> v = number of columns in the data region - 1
> c_i = cluster number of the i th row
>
> div is the integer division operator, rounding down
> mod is the remainder after division.

A regression test has been included with hand-computed values to
ensure that we get the expected results.

The major impact of this change to downstream consumers is that any
golden tests against the output of this package will need to be
updated.
@danielwhite
danielwhite merged commit 6e24082 into boombuler:master Oct 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] PDF417 Left Row Indicator for Cluster 0

1 participant