Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ITFReader

Decodes ITF barcodes.

author

Tjieco

Hierarchy

Implements

Index

Properties

Private narrowLineWidth

narrowLineWidth: number = -1

Static Private DEFAULT_ALLOWED_LENGTHS

DEFAULT_ALLOWED_LENGTHS: number[] = [6, 8, 10, 12, 14]

Static Private END_PATTERN_REVERSED

END_PATTERN_REVERSED: Int32Array[] = [Int32Array.from([1, 1, 2]), // 2xInt32Array.from([1, 1, 3]) // 3x]

Static Private MAX_AVG_VARIANCE

MAX_AVG_VARIANCE: number = 0.38

Static Private MAX_INDIVIDUAL_VARIANCE

MAX_INDIVIDUAL_VARIANCE: number = 0.5

Static Private PATTERNS

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

Static Private START_PATTERN

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

Start/end guard pattern.

Note: The end pattern is reversed because the row is reversed before searching for the END_PATTERN

Methods

decode

Private decodeEnd

  • Identify where the end of the middle / payload section ends.

    Parameters

    • row: BitArray

      row of black/white values to search

    Returns number[]

    Array, containing index of start of 'end block' and end of 'end block'

decodeRow

Private decodeStart

  • Identify where the start of the middle / payload section starts.

    Parameters

    • row: BitArray

      row of black/white values to search

    Returns number[]

    Array, containing index of start of 'start block' and end of 'start block'

reset

  • reset(): void

Private validateQuietZone

  • validateQuietZone(row: BitArray, startPattern: number): void
  • The start & end patterns must be pre/post fixed by a quiet zone. This zone must be at least 10 times the width of a narrow line. Scan back until we either get to the start of the barcode or match the necessary number of quiet zone pixels.

    Note: Its assumed the row is reversed when using this method to find quiet zone after the end pattern.

    ref: http://www.barcode-1.net/i25code.html

    throws

    NotFoundException if the quiet zone cannot be found

    Parameters

    • row: BitArray

      bit array representing the scanned barcode.

    • startPattern: number

      index into row of the start or end pattern.

    Returns void

Static Private decodeDigit

  • decodeDigit(counters: Int32Array): number
  • Attempts to decode a sequence of ITF black/white lines into single digit.

    throws

    NotFoundException if digit cannot be decoded

    Parameters

    • counters: Int32Array

      the counts of runs of observed black/white/black/... values

    Returns number

    The decoded digit

Static Private decodeMiddle

  • decodeMiddle(row: BitArray, payloadStart: number, payloadEnd: number, resultString: StringBuilder): void

Static Private findGuardPattern

  • findGuardPattern(row: BitArray, rowOffset: number, pattern: Int32Array): number[]
  • throws

    NotFoundException if pattern is not found

    Parameters

    • row: BitArray

      row of black/white values to search

    • rowOffset: number

      position to start search

    • pattern: Int32Array

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

    Returns number[]

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

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

Static Private skipWhiteSpace

  • Skip all whitespace until we get to the first black line.

    throws

    NotFoundException Throws exception if no black lines are found in the row

    Parameters

    • row: BitArray

      row of black/white values to search

    Returns number

    index of the first black line.

Generated using TypeDoc