Package com.google.zxing.oned
Class OneDReader
- java.lang.Object
-
- com.google.zxing.oned.OneDReader
-
- All Implemented Interfaces:
Reader
- Direct Known Subclasses:
AbstractRSSReader,CodaBarReader,Code128Reader,Code39Reader,Code93Reader,ITFReader,MultiFormatOneDReader,MultiFormatUPCEANReader,UPCEANReader
public abstract class OneDReader extends java.lang.Object implements Reader
Encapsulates functionality and implementation that is common to all families of one-dimensional barcodes.
-
-
Field Summary
Fields Modifier and Type Field Description protected static intINTEGER_MATH_SHIFTprotected static intPATTERN_MATCH_RESULT_SCALE_FACTOR
-
Constructor Summary
Constructors Constructor Description OneDReader()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Resultdecode(BinaryBitmap image)Locates and decodes a barcode in some format within an image.Resultdecode(BinaryBitmap image, java.util.Map<DecodeHintType,?> hints)Locates and decodes a barcode in some format within an image.abstract 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.protected static intpatternMatchVariance(int[] counters, int[] pattern, int maxIndividualVariance)Determines how closely a set of observed counts of runs of black/white values matches a given target pattern.protected static voidrecordPattern(BitArray row, int start, int[] counters)Records the size of successive runs of white and black pixels in a row, starting at a given point.protected static voidrecordPatternInReverse(BitArray row, int start, int[] counters)voidreset()Resets any internal state the implementation has after a decode, to prepare it for reuse.
-
-
-
Field Detail
-
INTEGER_MATH_SHIFT
protected static final int INTEGER_MATH_SHIFT
- See Also:
- Constant Field Values
-
PATTERN_MATCH_RESULT_SCALE_FACTOR
protected static final int PATTERN_MATCH_RESULT_SCALE_FACTOR
- See Also:
- Constant Field Values
-
-
Method Detail
-
decode
public Result decode(BinaryBitmap image) throws NotFoundException, FormatException
Description copied from interface:ReaderLocates and decodes a barcode in some format within an image.- Specified by:
decodein interfaceReader- Parameters:
image- image of barcode to decode- Returns:
- String which the barcode encodes
- Throws:
NotFoundException- if no potential barcode is foundFormatException- if a potential barcode is found but format is invalid
-
decode
public Result decode(BinaryBitmap image, java.util.Map<DecodeHintType,?> hints) throws NotFoundException, FormatException
Description copied from interface:ReaderLocates and decodes a barcode in some format within an image. This method also accepts hints, each possibly associated to some data, which may help the implementation decode.- Specified by:
decodein interfaceReader- Parameters:
image- image of barcode to decodehints- passed as aMapfromDecodeHintTypeto arbitrary data. The meaning of the data depends upon the hint type. The implementation may or may not do anything with these hints.- Returns:
- String which the barcode encodes
- Throws:
NotFoundException- if no potential barcode is foundFormatException- if a potential barcode is found but format is invalid
-
reset
public void reset()
Description copied from interface:ReaderResets any internal state the implementation has after a decode, to prepare it for reuse.
-
recordPattern
protected static void recordPattern(BitArray row, int start, int[] counters) throws NotFoundException
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.- Parameters:
row- row to count fromstart- offset into row to start atcounters- array into which to record counts- Throws:
NotFoundException- if counters cannot be filled entirely from row before running out of pixels
-
recordPatternInReverse
protected static void recordPatternInReverse(BitArray row, int start, int[] counters) throws NotFoundException
- Throws:
NotFoundException
-
patternMatchVariance
protected static int patternMatchVariance(int[] counters, int[] pattern, int maxIndividualVariance)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- observed counterspattern- expected patternmaxIndividualVariance- The most any counter can differ before we give up- Returns:
- ratio of total variance between counters and pattern compared to total pattern size, where the ratio has been multiplied by 256. So, 0 means no variance (perfect match); 256 means the total variance between counters and patterns equals the pattern length, higher values mean even more variance
-
decodeRow
public abstract Result decodeRow(int rowNumber, BitArray row, java.util.Map<DecodeHintType,?> hints) throws NotFoundException, ChecksumException, FormatException
Attempts to decode a one-dimensional barcode format given a single row of an image.
- 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
-
-