public abstract class UPCEANReader extends OneDReader
Encapsulates functionality and implementation that is common to UPC and EAN families of one-dimensional barcodes.
Modifier and Type | Field and Description |
---|---|
private java.lang.StringBuilder |
decodeRowStringBuffer |
private EANManufacturerOrgSupport |
eanManSupport |
(package private) static int[] |
END_PATTERN
end guard pattern.
|
private UPCEANExtensionSupport |
extensionReader |
(package private) static int[][] |
L_AND_G_PATTERNS
As 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 float |
MAX_AVG_VARIANCE |
private static float |
MAX_INDIVIDUAL_VARIANCE |
(package private) static int[] |
MIDDLE_PATTERN
Pattern marking the middle of a UPC/EAN pattern, separating the two halves.
|
(package private) static int[] |
START_END_PATTERN
Start/end guard pattern.
|
Modifier | Constructor and Description |
---|---|
protected |
UPCEANReader() |
Modifier and Type | Method and Description |
---|---|
(package private) boolean |
checkChecksum(java.lang.String s) |
(package private) static boolean |
checkStandardUPCEANChecksum(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 int |
decodeDigit(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 int |
decodeMiddle(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.
|
Result |
decodeRow(int rowNumber,
BitArray row,
int[] startGuardRange,
java.util.Map<DecodeHintType,?> hints)
Like
decodeRow(int, BitArray, Map) , but
allows caller to inform method about where the UPC/EAN start pattern is
found. |
Result |
decodeRow(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 BarcodeFormat |
getBarcodeFormat()
Get the format of this decoder.
|
(package private) static int |
getStandardUPCEANChecksum(java.lang.CharSequence s) |
decode, decode, patternMatchVariance, recordPattern, recordPatternInReverse, reset
private static final float MAX_AVG_VARIANCE
private static final float MAX_INDIVIDUAL_VARIANCE
static final int[] START_END_PATTERN
static final int[] MIDDLE_PATTERN
static final int[] END_PATTERN
static final int[][] L_PATTERNS
static final int[][] L_AND_G_PATTERNS
private final java.lang.StringBuilder decodeRowStringBuffer
private final UPCEANExtensionSupport extensionReader
private final EANManufacturerOrgSupport eanManSupport
static int[] findStartGuardPattern(BitArray row) throws NotFoundException
NotFoundException
public Result decodeRow(int rowNumber, BitArray row, java.util.Map<DecodeHintType,?> hints) throws NotFoundException, ChecksumException, FormatException
OneDReader
Attempts to decode a one-dimensional barcode format given a single row of an image.
decodeRow
in class OneDReader
rowNumber
- row number from top of the rowrow
- the black/white pixel data of the rowhints
- decode hintsResult
containing encoded string and start/end of barcodeNotFoundException
- 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 invalidpublic 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.
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 decodingResult
encapsulating the result of decoding a barcode in the rowNotFoundException
- 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 invalidboolean checkChecksum(java.lang.String s) throws FormatException
s
- string of digits to checkcheckStandardUPCEANChecksum(CharSequence)
FormatException
- if the string does not contain only digitsstatic boolean checkStandardUPCEANChecksum(java.lang.CharSequence s) throws FormatException
s
- string of digits to checkFormatException
- if the string does not contain only digitsstatic int getStandardUPCEANChecksum(java.lang.CharSequence s) throws FormatException
FormatException
int[] decodeEnd(BitArray row, int endStart) throws NotFoundException
NotFoundException
static int[] findGuardPattern(BitArray row, int rowOffset, boolean whiteFirst, int[] pattern) throws NotFoundException
NotFoundException
private static int[] findGuardPattern(BitArray row, int rowOffset, boolean whiteFirst, int[] pattern, int[] counters) throws NotFoundException
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-useNotFoundException
- if pattern is not foundstatic int decodeDigit(BitArray row, int[] counters, int rowOffset, int[][] patterns) throws NotFoundException
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 usedNotFoundException
- if digit cannot be decodedabstract BarcodeFormat getBarcodeFormat()
protected abstract int decodeMiddle(BitArray row, int[] startRange, java.lang.StringBuilder resultString) throws NotFoundException
row
- row of black/white values to searchstartRange
- start/end offset of start guard patternresultString
- StringBuilder
to append decoded chars toNotFoundException
- if decoding could not complete successfully