Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EAN13Reader

Implements decoding of the EAN-13 format.

author

dswitkin@google.com (Daniel Switkin)

author

Sean Owen

author

alasdair@google.com (Alasdair Mackintosh)

Hierarchy

Implements

Index

Constructors

constructor

Properties

Private decodeMiddleCounters

decodeMiddleCounters: Int32Array

Protected decodeRowStringBuffer

decodeRowStringBuffer: string = ""

Static END_PATTERN

END_PATTERN: Int32Array = Int32Array.from([1, 1, 1, 1, 1, 1])

end guard pattern.

Static Private FIRST_DIGIT_ENCODINGS

FIRST_DIGIT_ENCODINGS: number[] = [0x00, 0x0B, 0x0D, 0xE, 0x13, 0x19, 0x1C, 0x15, 0x16, 0x1A]

Static L_AND_G_PATTERNS

L_AND_G_PATTERNS: Int32Array[]

As above but also including the "even", or "G" patterns used to encode UPC/EAN digits.

Static L_PATTERNS

L_PATTERNS: Int32Array[] = [Int32Array.from([3, 2, 1, 1]), // 0Int32Array.from([2, 2, 2, 1]), // 1Int32Array.from([2, 1, 2, 2]), // 2Int32Array.from([1, 4, 1, 1]), // 3Int32Array.from([1, 1, 3, 2]), // 4Int32Array.from([1, 2, 3, 1]), // 5Int32Array.from([1, 1, 1, 4]), // 6Int32Array.from([1, 3, 1, 2]), // 7Int32Array.from([1, 2, 1, 3]), // 8Int32Array.from([3, 1, 1, 2]), // 9]

"Odd", or "L" patterns used to encode UPC/EAN digits.

Static MIDDLE_PATTERN

MIDDLE_PATTERN: Int32Array = Int32Array.from([1, 1, 1, 1, 1])

Pattern marking the middle of a UPC/EAN pattern, separating the two halves.

Static START_END_PATTERN

START_END_PATTERN: Int32Array = Int32Array.from([1, 1, 1])

Start/end guard pattern.

Methods

decode

decodeMiddle

  • decodeMiddle(row: BitArray, startRange: Int32Array, resultString: string): { resultString: string; rowOffset: number }

decodeRow

getBarcodeFormat

reset

  • reset(): void

Static checkChecksum

  • checkChecksum(s: string): boolean

Static checkStandardUPCEANChecksum

  • checkStandardUPCEANChecksum(s: string): boolean

Static decodeDigit

  • decodeDigit(row: BitArray, counters: Int32Array, rowOffset: int, patterns: Int32Array[]): number

Static decodeEnd

  • decodeEnd(row: BitArray, endStart: number): Int32Array

Static determineFirstDigit

  • determineFirstDigit(resultString: string, lgPatternFound: number): string

Static findGuardPattern

  • findGuardPattern(row: BitArray, rowOffset: number, whiteFirst: boolean, pattern: Int32Array, counters: Int32Array): Int32Array
  • throws

    NotFoundException if pattern is not found

    Parameters

    • row: BitArray

      row of black/white values to search

    • rowOffset: number

      position to start search

    • whiteFirst: boolean

      if true, indicates that the pattern specifies white/black/white/... pixel counts, otherwise, it is interpreted as black/white/black/...

    • pattern: Int32Array

      pattern of counts of number of black and white pixels that are being searched for as a pattern

    • counters: Int32Array

      array of counters, as long as pattern, to re-use

    Returns Int32Array

    start/end horizontal offset of guard pattern, as an array of two ints

Static findGuardPatternWithoutCounters

  • findGuardPatternWithoutCounters(row: BitArray, rowOffset: int, whiteFirst: boolean, pattern: Int32Array): Int32Array

Static findStartGuardPattern

  • findStartGuardPattern(row: BitArray): Int32Array

Static getStandardUPCEANChecksum

  • getStandardUPCEANChecksum(s: string): number

Static Protected patternMatchVariance

  • patternMatchVariance(counters: Int32Array, pattern: Int32Array, maxIndividualVariance: number): number
  • Determines how closely a set of observed counts of runs of black/white values matches a given target pattern. This is reported as the ratio of the total variance from the expected pattern proportions across all pattern elements, to the length of the pattern.

    Parameters

    • counters: Int32Array

      observed counters

    • pattern: Int32Array

      expected pattern

    • maxIndividualVariance: number

      The most any counter can differ before we give up

    Returns number

    ratio of total variance between counters and pattern compared to total pattern size

Static Protected recordPattern

  • recordPattern(row: BitArray, start: number, counters: Int32Array): void
  • Records the size of successive runs of white and black pixels in a row, starting at a given point. The values are recorded in the given array, and the number of runs recorded is equal to the size of the array. If the row starts on a white pixel at the given start point, then the first count recorded is the run of white pixels starting from that point; likewise it is the count of a run of black pixels if the row begin on a black pixels at that point.

    throws

    NotFoundException if counters cannot be filled entirely from row before running out of pixels

    Parameters

    • row: BitArray

      row to count from

    • start: number

      offset into row to start at

    • counters: Int32Array

      array into which to record counts

    Returns void

Static Protected recordPatternInReverse

  • recordPatternInReverse(row: BitArray, start: number, counters: Int32Array): void

Generated using TypeDoc