Class OneDReader
Encapsulates functionality and implementation that is common to all families
of one-dimensional barcodes.
public abstract class OneDReader : Reader
- Inheritance
-
OneDReader
- Implements
- Derived
- Inherited Members
Constructors
OneDReader()
protected OneDReader()
Fields
INTEGER_MATH_SHIFT
protected static int INTEGER_MATH_SHIFT
Field Value
PATTERN_MATCH_RESULT_SCALE_FACTOR
protected static int PATTERN_MATCH_RESULT_SCALE_FACTOR
Field Value
Methods
decode(BinaryBitmap)
Locates and decodes a barcode in some format within an image.
public Result decode(BinaryBitmap image)
Parameters
image
BinaryBitmapimage of barcode to decode
Returns
- Result
String which the barcode encodes
decode(BinaryBitmap, IDictionary<DecodeHintType, object>)
Locates 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. Note that we don't try rotation without the try harder flag, even if rotation was supported.
public virtual Result decode(BinaryBitmap image, IDictionary<DecodeHintType, object> hints)
Parameters
image
BinaryBitmapimage of barcode to decode
hints
IDictionary<DecodeHintType, object>passed as a IDictionary<TKey, TValue> from DecodeHintType to arbitrary data. The meaning of the data depends upon the hint type. The implementation may or may not do anything with these hints.
Returns
- Result
String which the barcode encodes
decodeRow(int, BitArray, IDictionary<DecodeHintType, object>)
Attempts to decode a one-dimensional barcode format given a single row of an image.
public abstract Result decodeRow(int rowNumber, BitArray row, IDictionary<DecodeHintType, object> hints)
Parameters
rowNumber
introw number from top of the row
row
BitArraythe black/white pixel data of the row
hints
IDictionary<DecodeHintType, object>decode hints
Returns
doDecode(BinaryBitmap, IDictionary<DecodeHintType, object>)
We're going to examine rows from the middle outward, searching alternately above and below the middle, and farther out each time. rowStep is the number of rows between each successive attempt above and below the middle. So we'd scan row middle, then middle - rowStep, then middle + rowStep, then middle - (2 * rowStep), etc. rowStep is bigger as the image is taller, but is always at least 1. We've somewhat arbitrarily decided that moving up and down by about 1/16 of the image is pretty good; we try more of the image if "trying harder".
protected virtual Result doDecode(BinaryBitmap image, IDictionary<DecodeHintType, object> hints)
Parameters
image
BinaryBitmapThe image to decode
hints
IDictionary<DecodeHintType, object>Any hints that were requested
Returns
- Result
The contents of the decoded barcode
patternMatchVariance(int[], int[], int)
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.
protected static int patternMatchVariance(int[] counters, int[] pattern, int maxIndividualVariance)
Parameters
counters
int[]observed counters
pattern
int[]expected pattern
maxIndividualVariance
intThe most any counter can differ before we give up
Returns
- int
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
recordPattern(BitArray, int, int[])
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.
protected static bool recordPattern(BitArray row, int start, int[] counters)
Parameters
row
BitArrayrow to count from
start
intoffset into row to start at
counters
int[]array into which to record counts
Returns
recordPattern(BitArray, int, int[], int)
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.
protected static bool recordPattern(BitArray row, int start, int[] counters, int numCounters)
Parameters
row
BitArrayrow to count from
start
intoffset into row to start at
counters
int[]array into which to record counts
numCounters
int
Returns
recordPatternInReverse(BitArray, int, int[])
Records the pattern in reverse.
protected static bool recordPatternInReverse(BitArray row, int start, int[] counters)
Parameters
Returns
reset()
Resets any internal state the implementation has after a decode, to prepare it for reuse.
public virtual void reset()