Class UPCEANReader
java.lang.Object
com.google.zxing.oned.OneDReader
com.google.zxing.oned.UPCEANReader
- All Implemented Interfaces:
Reader
- Direct Known Subclasses:
EAN13Reader, EAN8Reader, UPCAReader, UPCEReader
Encapsulates functionality and implementation that is common to UPC and EAN families of one-dimensional barcodes.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringBuilderprivate final EANManufacturerOrgSupport(package private) static final int[]end guard pattern.private final UPCEANExtensionSupport(package private) static final int[][]As above but also including the "even", or "G" patterns used to encode UPC/EAN digits.(package private) static final int[][]"Odd", or "L" patterns used to encode UPC/EAN digits.private static final floatprivate static final float(package private) static final int[]Pattern marking the middle of a UPC/EAN pattern, separating the two halves.(package private) static final int[]Start/end guard pattern. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) boolean(package private) static booleanComputes the UPC/EAN checksum on a string of digits, and reports whether the checksum is correct or not.(package private) static intdecodeDigit(BitArray row, int[] counters, int rowOffset, int[][] patterns) Attempts to decode a single UPC/EAN-encoded digit.(package private) int[]protected abstract intdecodeMiddle(BitArray row, int[] startRange, StringBuilder resultString) Subclasses override this to decode the portion of a barcode between the start and end guard patterns.decodeRow(int rowNumber, BitArray row, int[] startGuardRange, Map<DecodeHintType, ?> hints) LikedecodeRow(int, BitArray, Map), but allows caller to inform method about where the UPC/EAN start pattern is found.decodeRow(int rowNumber, BitArray row, Map<DecodeHintType, ?> hints) Attempts to decode a one-dimensional barcode format given a single row of an image.(package private) static int[]findGuardPattern(BitArray row, int rowOffset, boolean whiteFirst, int[] pattern) private static int[]findGuardPattern(BitArray row, int rowOffset, boolean whiteFirst, int[] pattern, int[] counters) (package private) static int[](package private) abstract BarcodeFormatGet the format of this decoder.(package private) static intMethods inherited from class 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:
-
START_END_PATTERN
static final int[] START_END_PATTERNStart/end guard pattern. -
MIDDLE_PATTERN
static final int[] MIDDLE_PATTERNPattern marking the middle of a UPC/EAN pattern, separating the two halves. -
END_PATTERN
static final int[] END_PATTERNend guard pattern. -
L_PATTERNS
static final int[][] L_PATTERNS"Odd", or "L" patterns used to encode UPC/EAN digits. -
L_AND_G_PATTERNS
static final int[][] L_AND_G_PATTERNSAs above but also including the "even", or "G" patterns used to encode UPC/EAN digits. -
decodeRowStringBuffer
-
extensionReader
-
eanManSupport
-
-
Constructor Details
-
UPCEANReader
protected UPCEANReader()
-
-
Method Details
-
findStartGuardPattern
- Throws:
NotFoundException
-
decodeRow
public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType, ?> hints) throws NotFoundException, ChecksumException, FormatException Description copied from class:OneDReaderAttempts to decode a one-dimensional barcode format given a single row of an image.
- Specified by:
decodeRowin classOneDReader- Parameters:
rowNumber- row number from top of the rowrow- the black/white pixel data of the rowhints- decode hints- Returns:
Resultcontaining encoded string and start/end of barcode- Throws:
NotFoundException- if no potential barcode is foundChecksumException- if a potential barcode is found but does not pass its checksumFormatException- if a potential barcode is found but format is invalid
-
decodeRow
public Result decodeRow(int rowNumber, BitArray row, int[] startGuardRange, Map<DecodeHintType, ?> hints) throws NotFoundException, ChecksumException, FormatException Like
decodeRow(int, BitArray, Map), but allows caller to inform method about where the UPC/EAN start pattern is found. This allows this to be computed once and reused across many implementations.- Parameters:
rowNumber- row index into the imagerow- encoding of the row of the barcode imagestartGuardRange- start/end column where the opening start pattern was foundhints- optional hints that influence decoding- Returns:
Resultencapsulating the result of decoding a barcode in the row- Throws:
NotFoundException- if no potential barcode is foundChecksumException- if a potential barcode is found but does not pass its checksumFormatException- if a potential barcode is found but format is invalid
-
checkChecksum
- Parameters:
s- string of digits to check- Returns:
checkStandardUPCEANChecksum(CharSequence)- Throws:
FormatException- if the string does not contain only digits
-
checkStandardUPCEANChecksum
Computes the UPC/EAN checksum on a string of digits, and reports whether the checksum is correct or not.- Parameters:
s- string of digits to check- Returns:
- true iff string of digits passes the UPC/EAN checksum algorithm
- Throws:
FormatException- if the string does not contain only digits
-
getStandardUPCEANChecksum
- Throws:
FormatException
-
decodeEnd
- Throws:
NotFoundException
-
findGuardPattern
static int[] findGuardPattern(BitArray row, int rowOffset, boolean whiteFirst, int[] pattern) throws NotFoundException - Throws:
NotFoundException
-
findGuardPattern
private static int[] findGuardPattern(BitArray row, int rowOffset, boolean whiteFirst, int[] pattern, int[] counters) throws NotFoundException - Parameters:
row- row of black/white values to searchrowOffset- position to start searchwhiteFirst- if true, indicates that the pattern specifies white/black/white/... pixel counts, otherwise, it is interpreted as black/white/black/...pattern- pattern of counts of number of black and white pixels that are being searched for as a patterncounters- array of counters, as long as pattern, to re-use- Returns:
- start/end horizontal offset of guard pattern, as an array of two ints
- Throws:
NotFoundException- if pattern is not found
-
decodeDigit
static int decodeDigit(BitArray row, int[] counters, int rowOffset, int[][] patterns) throws NotFoundException Attempts to decode a single UPC/EAN-encoded digit.- Parameters:
row- row of black/white values to decodecounters- the counts of runs of observed black/white/black/... valuesrowOffset- horizontal offset to start decoding frompatterns- the set of patterns to use to decode -- sometimes different encodings for the digits 0-9 are used, and this indicates the encodings for 0 to 9 that should be used- Returns:
- horizontal offset of first pixel beyond the decoded digit
- Throws:
NotFoundException- if digit cannot be decoded
-
getBarcodeFormat
-
decodeMiddle
protected abstract int decodeMiddle(BitArray row, int[] startRange, StringBuilder resultString) throws NotFoundException Subclasses override this to decode the portion of a barcode between the start and end guard patterns.- Parameters:
row- row of black/white values to searchstartRange- start/end offset of start guard patternresultString-StringBuilderto append decoded chars to- Returns:
- horizontal offset of first pixel after the "middle" that was decoded
- Throws:
NotFoundException- if decoding could not complete successfully
-