Package com.google.zxing.oned
Class ITFReader
java.lang.Object
com.google.zxing.oned.OneDReader
com.google.zxing.oned.ITFReader
- All Implemented Interfaces:
Reader
Implements decoding of the ITF format, or Interleaved Two of Five.
This Reader will scan ITF barcodes of certain lengths only. At the moment it reads length 6, 8, 10, 12, 14, 16, 18, 20, 24, and 44 as these have appeared "in the wild". Not all lengths are scanned, especially shorter ones, to avoid false positives. This in turn is due to a lack of required checksum function.
The checksum is optional and is not applied by this Reader. The consumer of the decoded value will have to apply a checksum if required.
http://en.wikipedia.org/wiki/Interleaved_2_of_5 is a great reference for Interleaved 2 of 5 information.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int[]
Valid ITF lengths.private static final int[][]
private static final float
private static final float
private static final int
private int
private static final int[][]
Patterns of Wide / Narrow lines to indicate each digitprivate static final int[]
Start/end guard pattern.private static final int
private static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static int
decodeDigit
(int[] counters) Attempts to decode a sequence of ITF black/white lines into single digit.private int[]
Identify where the end of the middle / payload section ends.private static void
decodeMiddle
(BitArray row, int payloadStart, int payloadEnd, StringBuilder resultString) decodeRow
(int rowNumber, BitArray row, Map<DecodeHintType, ?> hints) Attempts to decode a one-dimensional barcode format given a single row of an image.private int[]
decodeStart
(BitArray row) Identify where the start of the middle / payload section starts.private static int[]
findGuardPattern
(BitArray row, int rowOffset, int[] pattern) private static int
skipWhiteSpace
(BitArray row) Skip all whitespace until we get to the first black line.private void
validateQuietZone
(BitArray row, int startPattern) The start invalid input: '&' end patterns must be pre/post fixed by a quiet zone.Methods inherited from class com.google.zxing.oned.OneDReader
decode, decode, patternMatchVariance, recordPattern, recordPatternInReverse, reset
-
Field Details
-
MAX_AVG_VARIANCE
private static final float MAX_AVG_VARIANCE- See Also:
-
MAX_INDIVIDUAL_VARIANCE
private static final float MAX_INDIVIDUAL_VARIANCE- See Also:
-
W
private static final int W- See Also:
-
w
private static final int w- See Also:
-
N
private static final int N- See Also:
-
DEFAULT_ALLOWED_LENGTHS
private static final int[] DEFAULT_ALLOWED_LENGTHSValid ITF lengths. Anything longer than the largest value is also allowed. -
narrowLineWidth
private int narrowLineWidth -
START_PATTERN
private static final int[] START_PATTERNStart/end guard pattern. Note: The end pattern is reversed because the row is reversed before searching for the END_PATTERN -
END_PATTERN_REVERSED
private static final int[][] END_PATTERN_REVERSED -
PATTERNS
private static final int[][] PATTERNSPatterns of Wide / Narrow lines to indicate each digit
-
-
Constructor Details
-
ITFReader
public ITFReader()
-
-
Method Details
-
decodeRow
public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType, ?> hints) throws FormatException, NotFoundExceptionDescription copied from class:OneDReader
Attempts to decode a one-dimensional barcode format given a single row of an image.
- Specified by:
decodeRow
in classOneDReader
- Parameters:
rowNumber
- row number from top of the rowrow
- the black/white pixel data of the rowhints
- decode hints- Returns:
Result
containing encoded string and start/end of barcode- Throws:
FormatException
- if a potential barcode is found but format is invalidNotFoundException
- if no potential barcode is found
-
decodeMiddle
private static void decodeMiddle(BitArray row, int payloadStart, int payloadEnd, StringBuilder resultString) throws NotFoundException - Parameters:
row
- row of black/white values to searchpayloadStart
- offset of start patternresultString
-StringBuilder
to append decoded chars to- Throws:
NotFoundException
- if decoding could not complete successfully
-
decodeStart
Identify where the start of the middle / payload section starts.- Parameters:
row
- row of black/white values to search- Returns:
- Array, containing index of start of 'start block' and end of 'start block'
- Throws:
NotFoundException
-
validateQuietZone
The start invalid input: '&' 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- Parameters:
row
- bit array representing the scanned barcode.startPattern
- index into row of the start or end pattern.- Throws:
NotFoundException
- if the quiet zone cannot be found
-
skipWhiteSpace
Skip all whitespace until we get to the first black line.- Parameters:
row
- row of black/white values to search- Returns:
- index of the first black line.
- Throws:
NotFoundException
- Throws exception if no black lines are found in the row
-
decodeEnd
Identify where the end of the middle / payload section ends.- Parameters:
row
- row of black/white values to search- Returns:
- Array, containing index of start of 'end block' and end of 'end block'
- Throws:
NotFoundException
-
findGuardPattern
private static int[] findGuardPattern(BitArray row, int rowOffset, int[] pattern) throws NotFoundException - Parameters:
row
- row of black/white values to searchrowOffset
- position to start searchpattern
- pattern of counts of number of black and white pixels that are being searched for as a pattern- Returns:
- start/end horizontal offset of guard pattern, as an array of two ints
- Throws:
NotFoundException
- if pattern is not found
-
decodeDigit
Attempts to decode a sequence of ITF black/white lines into single digit.- Parameters:
counters
- the counts of runs of observed black/white/black/... values- Returns:
- The decoded digit
- Throws:
NotFoundException
- if digit cannot be decoded
-