Package com.google.zxing.oned
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
public abstract class UPCEANReader extends OneDReader
Encapsulates functionality and implementation that is common to UPC and EAN families of one-dimensional barcodes.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringBuilderdecodeRowStringBufferprivate EANManufacturerOrgSupporteanManSupport(package private) static int[]END_PATTERNend guard pattern.private UPCEANExtensionSupportextensionReader(package private) static int[][]L_AND_G_PATTERNSAs above but also including the "even", or "G" patterns used to encode UPC/EAN digits.(package private) static int[][]L_PATTERNS"Odd", or "L" patterns used to encode UPC/EAN digits.private static floatMAX_AVG_VARIANCEprivate static floatMAX_INDIVIDUAL_VARIANCE(package private) static int[]MIDDLE_PATTERNPattern marking the middle of a UPC/EAN pattern, separating the two halves.(package private) static int[]START_END_PATTERNStart/end guard pattern.
-
Constructor Summary
Constructors Modifier Constructor Description protectedUPCEANReader()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) booleancheckChecksum(java.lang.String s)(package private) static booleancheckStandardUPCEANChecksum(java.lang.CharSequence s)Computes 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[]decodeEnd(BitArray row, int endStart)protected abstract intdecodeMiddle(BitArray row, int[] startRange, java.lang.StringBuilder resultString)Subclasses override this to decode the portion of a barcode between the start and end guard patterns.ResultdecodeRow(int rowNumber, BitArray row, int[] startGuardRange, java.util.Map<DecodeHintType,?> hints)LikedecodeRow(int, BitArray, Map), but allows caller to inform method about where the UPC/EAN start pattern is found.ResultdecodeRow(int rowNumber, BitArray row, java.util.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[]findStartGuardPattern(BitArray row)(package private) abstract BarcodeFormatgetBarcodeFormat()Get the format of this decoder.(package private) static intgetStandardUPCEANChecksum(java.lang.CharSequence s)-
Methods inherited from class com.google.zxing.oned.OneDReader
decode, decode, patternMatchVariance, recordPattern, recordPatternInReverse, reset
-
-
-
-
Field Detail
-
MAX_AVG_VARIANCE
private static final float MAX_AVG_VARIANCE
- See Also:
- Constant Field Values
-
MAX_INDIVIDUAL_VARIANCE
private static final float MAX_INDIVIDUAL_VARIANCE
- See Also:
- Constant Field Values
-
START_END_PATTERN
static final int[] START_END_PATTERN
Start/end guard pattern.
-
MIDDLE_PATTERN
static final int[] MIDDLE_PATTERN
Pattern marking the middle of a UPC/EAN pattern, separating the two halves.
-
END_PATTERN
static final int[] END_PATTERN
end 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_PATTERNS
As above but also including the "even", or "G" patterns used to encode UPC/EAN digits.
-
decodeRowStringBuffer
private final java.lang.StringBuilder decodeRowStringBuffer
-
extensionReader
private final UPCEANExtensionSupport extensionReader
-
eanManSupport
private final EANManufacturerOrgSupport eanManSupport
-
-
Method Detail
-
findStartGuardPattern
static int[] findStartGuardPattern(BitArray row) throws NotFoundException
- Throws:
NotFoundException
-
decodeRow
public Result decodeRow(int rowNumber, BitArray row, java.util.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, java.util.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
boolean checkChecksum(java.lang.String s) throws FormatException- Parameters:
s- string of digits to check- Returns:
checkStandardUPCEANChecksum(CharSequence)- Throws:
FormatException- if the string does not contain only digits
-
checkStandardUPCEANChecksum
static boolean checkStandardUPCEANChecksum(java.lang.CharSequence s) throws FormatExceptionComputes 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
static int getStandardUPCEANChecksum(java.lang.CharSequence s) throws FormatException- Throws:
FormatException
-
decodeEnd
int[] decodeEnd(BitArray row, int endStart) throws NotFoundException
- 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
abstract BarcodeFormat getBarcodeFormat()
Get the format of this decoder.- Returns:
- The 1D format.
-
decodeMiddle
protected abstract int decodeMiddle(BitArray row, int[] startRange, java.lang.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
-
-