Documentation
¶
Overview ¶
Package tables holds the JAB Code static lookup tables (encoding, alignment-pattern, and palette/finder geometry) shared by the encoder and decoder.
Index ¶
- Constants
- Variables
- func APNCoreColorIndex(nc int, variant wire.Variant) int
- func APXCoreColorIndex(nc int, variant wire.Variant) int
- func EncodingValue(char, mode int, variant wire.Variant) int
- func FPCoreColorIndex(fp, nc int, variant wire.Variant) int
- func MixedISOSequence(input []byte) (value, size int, ok bool)
- func NcMetadataColorIndex(value, nc int) int
- func NcMetadataColorIndexVariant(value, nc int, variant wire.Variant) int
- func PrimaryPalettePlacementIndex(c, i int) int
- func PrimaryPalettePlacementIndexVariant(c, i, colorNumber int, variant wire.Variant) int
- func SecondaryPaletteFits(firstColor, paletteCount int) bool
- func SecondaryPaletteModules(i, firstColor, paletteCount, width, height int) (pts [4]image.Point, n int)
- func SecondaryPalettePlacementIndex(i int) int
- func SecondaryPalettePlacementIndexVariant(i, colorNumber int, variant wire.Variant) int
Constants ¶
const EncMax = 1000000 // ENC_MAX
EncMax marks an impossible/unbounded mode transition.
const MixedISOFirstMultiByte = 23
MixedISOFirstMultiByte is the first mixed-mode value ISO transmits as more than one byte.
Variables ¶
var APNCoreColor = [8]int{0, 3, 3, 3, 7, 15, 15, 31}
var APNum = [32]int{2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9}
APNum is the number of finder/alignment patterns per row/column for side-versions 1..32.
var APPos = [32][9]int{
{4, 18, 0, 0, 0, 0, 0, 0, 0},
{4, 22, 0, 0, 0, 0, 0, 0, 0},
{4, 26, 0, 0, 0, 0, 0, 0, 0},
{4, 30, 0, 0, 0, 0, 0, 0, 0},
{4, 34, 0, 0, 0, 0, 0, 0, 0},
{4, 17, 38, 0, 0, 0, 0, 0, 0},
{4, 20, 42, 0, 0, 0, 0, 0, 0},
{4, 23, 46, 0, 0, 0, 0, 0, 0},
{4, 26, 50, 0, 0, 0, 0, 0, 0},
{4, 14, 32, 54, 0, 0, 0, 0, 0},
{4, 17, 39, 58, 0, 0, 0, 0, 0},
{4, 20, 46, 62, 0, 0, 0, 0, 0},
{4, 23, 44, 66, 0, 0, 0, 0, 0},
{4, 26, 37, 51, 70, 0, 0, 0, 0},
{4, 14, 36, 58, 74, 0, 0, 0, 0},
{4, 17, 39, 56, 78, 0, 0, 0, 0},
{4, 20, 42, 63, 82, 0, 0, 0, 0},
{4, 23, 38, 54, 70, 86, 0, 0, 0},
{4, 26, 38, 56, 77, 90, 0, 0, 0},
{4, 14, 33, 53, 72, 94, 0, 0, 0},
{4, 17, 38, 59, 79, 98, 0, 0, 0},
{4, 20, 36, 53, 70, 86, 102, 0, 0},
{4, 23, 36, 55, 74, 93, 106, 0, 0},
{4, 26, 36, 58, 79, 100, 110, 0, 0},
{4, 14, 36, 58, 80, 92, 114, 0, 0},
{4, 17, 34, 52, 70, 88, 99, 118, 0},
{4, 20, 37, 54, 72, 89, 106, 122, 0},
{4, 23, 38, 56, 74, 92, 113, 126, 0},
{4, 26, 36, 58, 78, 98, 120, 130, 0},
{4, 14, 32, 49, 67, 84, 102, 112, 134},
{4, 17, 35, 53, 71, 89, 107, 119, 138},
{4, 20, 38, 55, 73, 91, 108, 126, 142},
}
APPos holds the finder/alignment pattern coordinates for side-versions 1..32.
var APXCoreColor = [8]int{0, 2, 6, 14, 30, 60, 124, 252}
var CharacterSize = [7]int{5, 5, 4, 4, 5, 6, 8}
CharacterSize is the per-character bit size of each base mode.
var EncodingTable = [256][6]int{}/* 256 elements not displayed */
EncodingTable maps a byte value and encoding mode (upper, lower, numeric, punct, mixed, alphanumeric) to its code, or a negative sentinel.
var FPCoreColor = [4][8]int{
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 2, 6, 14, 30, 60, 124, 252},
{0, 3, 3, 3, 7, 15, 15, 31},
}
FPCoreColor[fp][Nc] and APNCoreColor/APXCoreColor[Nc] are the finder and alignment pattern core color indices per color mode Nc.
var LatchShiftTo = [14][14]int{
{0, 5, 5, 1000000, 1000000, 5, 1000000, 1000000, 1000000, 1000000, 5, 7, 1000000, 11},
{7, 0, 5, 1000000, 1000000, 5, 1000000, 5, 1000000, 1000000, 5, 7, 1000000, 11},
{4, 6, 0, 1000000, 1000000, 9, 1000000, 6, 1000000, 1000000, 4, 6, 1000000, 10},
{1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 0, 0, 0, 1000000, 1000000, 0, 1000000},
{1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 0, 0, 0, 1000000, 1000000, 0, 1000000},
{8, 13, 13, 1000000, 1000000, 0, 1000000, 1000000, 1000000, 1000000, 8, 8, 1000000, 12},
{1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 0, 0, 0, 0, 1000000, 1000000, 0, 0},
{0, 5, 5, 1000000, 1000000, 5, 1000000, 1000000, 1000000, 1000000, 5, 7, 1000000, 11},
{7, 0, 5, 1000000, 1000000, 5, 1000000, 5, 1000000, 1000000, 5, 7, 1000000, 11},
{4, 6, 0, 1000000, 1000000, 9, 1000000, 6, 1000000, 1000000, 4, 6, 1000000, 10},
{1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 0, 0, 0, 1000000, 1000000, 0, 1000000},
{1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 0, 0, 0, 1000000, 1000000, 0, 1000000},
{8, 13, 13, 1000000, 1000000, 0, 1000000, 1000000, 1000000, 1000000, 8, 8, 1000000, 12},
{1000000, 1000000, 1000000, 1000000, 1000000, 1000000, 0, 0, 0, 0, 1000000, 1000000, 0, 0},
}
LatchShiftTo[k][j] is the bit cost of switching from mode k to mode j (first latch, then shift); modes 0-6 are latch, 7-13 shift.
var MixedISOTransmitted = [9][]byte{
{226, 130, 172},
{194, 167},
{195, 132},
{195, 150},
{195, 156},
{195, 159},
{195, 164},
{195, 182},
{195, 188},
}
MixedISOTransmitted holds what mixed-mode values 23 to 31 transmit under ISO/IEC 23634:2022 Table 13, whose ISO column spells those nine entries as UTF-8 byte sequences (5.3.1 makes UTF-8 the default interpretation). The C-family and BSI variants transmit the ISO-8859-15 single bytes instead: the same nine characters, in the character set BSI TR-03137 specifies.
The value's index is its mixed-mode value minus MixedISOFirstMultiByte.
var ModeSwitch = [7][16]int{
{-1, 28, 29, -1, -1, 30, -1, -1, -1, -1, 27, 125, -1, 124, 126, -1},
{126, -1, 29, -1, -1, 30, -1, 28, -1, 127, 27, 125, -1, 124, -1, 127},
{14, 63, -1, -1, -1, 478, -1, 62, -1, -1, 13, 61, -1, 60, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{255, 8188, 8189, -1, -1, -1, -1, -1, -1, -1, 254, 253, -1, 252, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
}
ModeSwitch[from][to] is the bit code written for a mode switch; the last two columns are ECI and FNC1.
var NcColorEncode = [8][2]int{
{0, 0},
{0, 3},
{0, 6},
{3, 0},
{3, 3},
{3, 6},
{6, 0},
{6, 3},
}
NcColorEncode maps each 3-bit metadata value to two module color indices.
var PrimaryPalettePlacement = [4][8]int{
{0, 3, 5, 6, 1, 2, 4, 7},
{0, 6, 5, 3, 1, 2, 4, 7},
{6, 0, 5, 3, 1, 2, 4, 7},
{3, 0, 5, 6, 1, 2, 4, 7},
}
PrimaryPalettePlacement / SecondaryPalettePlacement give the module order of the embedded color palette. They cover only the eight indices of a 4- or 8-color symbol; PrimaryPalettePlacementIndex / SecondaryPalettePlacementIndex extend them for higher color counts.
var SecondaryPalettePlacement = [8]int{3, 6, 5, 0, 1, 2, 4, 7}
var SecondaryPalettePosition = [32]image.Point{
{4, 5},
{4, 6},
{4, 7},
{4, 8},
{4, 9},
{4, 10},
{4, 11},
{4, 12},
{5, 12},
{5, 11},
{5, 10},
{5, 9},
{5, 8},
{5, 7},
{5, 6},
{5, 5},
{6, 5},
{6, 6},
{6, 7},
{6, 8},
{6, 9},
{6, 10},
{6, 11},
{6, 12},
{7, 12},
{7, 11},
{7, 10},
{7, 9},
{7, 8},
{7, 7},
{7, 6},
{7, 5},
}
SecondaryPalettePosition gives the placement order inside one of a secondary symbol's four 32-module palette regions. Its 32 coordinates are the serpentine walk of the upper-left region in ISO/IEC 23634:2022 Figure G.2 (column x=4 downwards, x=5 upwards, x=6 down, x=7 up); the other three regions are its rotations. The length is the region size, not a colour ceiling.
var SymbolPos = [61]image.Point{
{0, 0},
{0, -1},
{0, 1},
{-1, 0},
{1, 0},
{0, -2},
{-1, -1},
{1, -1},
{0, 2},
{-1, 1},
{1, 1},
{-2, 0},
{2, 0},
{0, -3},
{-1, -2},
{1, -2},
{-2, -1},
{2, -1},
{0, 3},
{-1, 2},
{1, 2},
{-2, 1},
{2, 1},
{-3, 0},
{3, 0},
{0, -4},
{-1, -3},
{1, -3},
{-2, -2},
{2, -2},
{-3, -1},
{3, -1},
{0, 4},
{-1, 3},
{1, 3},
{-2, 2},
{2, 2},
{-3, 1},
{3, 1},
{-4, 0},
{4, 0},
{0, -5},
{-1, -4},
{1, -4},
{-2, -3},
{2, -3},
{-3, -2},
{3, -2},
{-4, -1},
{4, -1},
{0, 5},
{-1, 4},
{1, 4},
{-2, 3},
{2, 3},
{-3, 2},
{3, 2},
{-4, 1},
{4, 1},
{-5, 0},
{5, 0},
}
SymbolPos gives the grid position of each cascaded symbol slot.
Functions ¶
func APNCoreColorIndex ¶
APNCoreColorIndex returns the U/L alignment-pattern core color index under the selected wire-format variant.
func APXCoreColorIndex ¶
APXCoreColorIndex returns the X0/X1 alignment-pattern core color index under the selected wire-format variant.
func EncodingValue ¶
EncodingValue is EncodingTable[char][mode] for the given wire variant.
The ISO route cannot reach the mixed-mode entries at or above MixedISOFirstMultiByte from a single input byte, because ISO transmits those nine values as multi-byte UTF-8 rather than as the ISO-8859-15 byte the table is indexed by. A lone 0xC4 is not "A with diaeresis" there, so it takes the byte mode; the UTF-8 spelling reaches the mixed mode through MixedISOSequence.
func FPCoreColorIndex ¶
FPCoreColorIndex returns one finder-pattern core color index under the selected wire-format variant.
func MixedISOSequence ¶
MixedISOSequence matches one of the nine UTF-8 sequences ISO/IEC 23634 Table 13 gives for mixed-mode values 23 to 31 at the start of input, returning the mixed-mode value and how many bytes it spans.
It is how the ISO encoder reaches those values: EncodingValue cannot, because the table is indexed by a single byte and ISO spends two or three on each of these characters.
func NcMetadataColorIndex ¶
NcMetadataColorIndex maps an NcColorEncode value - black (0), cyan (3) or yellow (6) in the 8-color palette - to the palette index carrying that color in color mode nc. Part I is read before the palette, by module color pattern alone, so it must be placed in colors DecodeModuleNC recognizes: black, cyan, yellow. In the 4- and 8-color palettes those sit at indices 0/3/6 and this is the identity, but the higher modes place them elsewhere on the RGB grid, where the fixed index would render as an unrelated color. The finder cyan (FP3) and yellow (FP2) core columns already hold those per-mode indices.
func NcMetadataColorIndexVariant ¶
NcMetadataColorIndexVariant is NcMetadataColorIndex under the selected wire-format variant.
func PrimaryPalettePlacementIndex ¶
PrimaryPalettePlacementIndex returns which palette color index copy c places at palette slot i. For the eight low indices it is the reference-defined shuffle (kept byte-identical for 4- and 8-color symbols); above 7 neither the reference nor ISO defines an order, so the extension is the identity - every copy carries slot i as color i. Encoder and decoder both route through this function, so higher-color palettes round-trip regardless of the choice.
func PrimaryPalettePlacementIndexVariant ¶
PrimaryPalettePlacementIndexVariant is PrimaryPalettePlacementIndex under the selected wire-format variant.
func SecondaryPaletteFits ¶
SecondaryPaletteFits reports whether a secondary symbol's embedded palette addresses only positions the regions actually have.
func SecondaryPaletteModules ¶
func SecondaryPaletteModules(i, firstColor, paletteCount, width, height int) (pts [4]image.Point, n int)
SecondaryPaletteModules returns the modules carrying secondary palette colour i, one per embedded copy, and how many of them there are.
The four regions of Figure G.2 hold 128 modules for two palettes of up to 64 colours (ISO/IEC 23634:2022 G.3), so each colour is embedded twice. BSI TR-03137 Part 2 3.4.4 states the pairing normatively for the same layout: the two copies go in diagonally opposite regions, the palette's first half in one diagonal pair and its second half in the other. The 4- and 8-colour modes instead embed four copies, one per region, at the placement ISO fixes for the modes it defines; they are identified by firstColor, since only they carry palette colours 0 and 1 in the alignment patterns.
func SecondaryPalettePlacementIndex ¶
SecondaryPalettePlacementIndex is the secondary-symbol counterpart of PrimaryPalettePlacementIndex.
Types ¶
This section is empty.