spec

package
v0.0.0-...-b4425be Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package spec holds JAB Code symbol geometry, metadata layout, masking and finder core-color constants shared by the encoder and decoder.

Index

Constants

View Source
const (
	ModeUpper = iota
	ModeLower
	ModeNumeric
	ModePunct
	ModeMixed
	ModeAlphanumeric
	ModeByte
)

Encoding modes shared by the encoder's mode optimizer and the decoder; they index the per-character cost and decoding tables (encoder.h, decoder.h).

View Source
const (
	ColorPaletteNumber = 4
	DistanceToBorder   = 4

	PrimaryMetadataX                 = 6
	PrimaryMetadataY                 = 1
	PrimaryMetadataPart1Length       = 6
	PrimaryMetadataPart2Length       = 38
	PrimaryMetadataPart1ModuleNumber = 4
)

Symbol layout constants (jabcode.h, decoder.h).

View Source
const (
	FP0CoreColor = 0 // black
	FP1CoreColor = 0 // black
	FP2CoreColor = 6 // yellow
	FP3CoreColor = 3 // cyan
)

Finder-pattern core color indices in the 8-color default palette, used as fixed scalars during detection and masking (the Nc=2 column of tables.FPCoreColor).

View Source
const DefaultECCLevel = 3

DefaultECCLevel is the error-correction level of a default-mode primary symbol.

View Source
const DefaultMaskingReference = 7

DefaultMaskingReference is the fixed mask pattern used in default mode.

View Source
const DefaultModuleColorMode = 2

DefaultModuleColorMode is the Nc of a default-mode primary symbol, so its color count is 2^(Nc+1) = 8.

View Source
const PalettePlacementSlots = 64

PalettePlacementSlots is how many palette colors a symbol embeds at most. The 128- and 256-color modes embed 64 representatives and interpolate the rest, so no mode ever walks more slots than this.

Variables

View Source
var ECCWeights = [11][2]int{
	{4, 9}, {3, 8}, {3, 7}, {4, 9}, {3, 6}, {4, 7}, {4, 6}, {3, 4}, {4, 5}, {5, 6}, {6, 7},
}

ECCWeights maps an error-correction level to its LDPC (wc, wr) weights.

Functions

func BSIErrorCorrectionBitLength

func BSIErrorCorrectionBitLength(sideVersion image.Point) int

BSIErrorCorrectionBitLength returns the width of the BSI E metadata field for a symbol with the given side versions.

func Log2Int

func Log2Int(n int) int

Log2Int returns log2(n) for a power-of-two n (the bits-per-module count).

func MaskValue

func MaskValue(maskType, x, y int) int

MaskValue returns the mask offset for module (x, y) under the given pattern.

func NextMetadataModuleInPrimary

func NextMetadataModuleInPrimary(height, width, count int, x, y *int)

NextMetadataModuleInPrimary advances (x, y) to the next metadata/palette module position in a primary symbol. count is the running module index.

func NextMetadataModuleInSecondary

func NextMetadataModuleInSecondary(count int, x, y *int)

NextMetadataModuleInSecondary advances (x, y) along the metadata strip of a BSI-era secondary symbol. count is the running module index.

func PaletteCopies

func PaletteCopies(colorNumber int) int

PaletteCopies returns how many redundant copies of the colour palette a symbol embeds. The 4- and 8-colour modes embed four, which ISO/IEC 23634 4.3.9 requires outright. The higher modes embed two: ISO covers them only in informative Annex G, whose budget is 128 modules for two palettes, while BSI TR-03137 Part 2 3.3.8 says normatively that two shall be placed. With two copies the up-to-64 embedded colours fit the primary symbol's fixed metadata region, which four copies overflow. The count is the same on encode and decode, so the palette round-trips.

func PaletteFinderColors

func PaletteFinderColors(colorNumber int) int

PaletteFinderColors returns how many of a symbol's palette colors are carried by the finder (primary) or alignment (secondary) patterns rather than embedded in the metadata region. ISO/IEC 23634 4.3.9 has each embedded palette carry every colour "except the two colours used by the nearest finder pattern or alignment pattern U or L", so the 4- and 8-colour modes carry two there. The higher modes carry none, because their finder cores are not palette colors 0 and 1 (ISO/IEC 23634 Annex G embeds every color in the palettes).

func SizeToVersion

func SizeToVersion(s int) int

SizeToVersion returns the side version of a symbol with the given module side length.

func ValidSideSize

func ValidSideSize(s int) bool

ValidSideSize reports whether s is a legal module side length, the size of some side version 1..32 (4v+17).

func VersionToSize

func VersionToSize(v int) int

VersionToSize returns the module side length of a symbol of the given side version.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL