本文整理汇总了C#中ZXing.Common.BitArray.isRange方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.isRange方法的具体用法?C# BitArray.isRange怎么用?C# BitArray.isRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZXing.Common.BitArray
的用法示例。
在下文中一共展示了BitArray.isRange方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: decodeRow
/// <summary>
/// <p>Like decodeRow(int, BitArray, java.util.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.</p>
/// </summary>
/// <param name="rowNumber">row index into the image</param>
/// <param name="row">encoding of the row of the barcode image</param>
/// <param name="startGuardRange">start/end column where the opening start pattern was found</param>
/// <param name="hints">optional hints that influence decoding</param>
/// <returns><see cref="Result"/> encapsulating the result of decoding a barcode in the row</returns>
virtual public Result decodeRow(int rowNumber,
BitArray row,
int[] startGuardRange,
IDictionary<DecodeHintType, object> hints)
{
var resultPointCallback = hints == null || !hints.ContainsKey(DecodeHintType.NEED_RESULT_POINT_CALLBACK) ? null :
(ResultPointCallback)hints[DecodeHintType.NEED_RESULT_POINT_CALLBACK];
if (resultPointCallback != null)
{
resultPointCallback(new ResultPoint(
(startGuardRange[0] + startGuardRange[1]) / 2.0f, rowNumber
));
}
var result = decodeRowStringBuffer;
result.Length = 0;
var endStart = decodeMiddle(row, startGuardRange, result);
if (endStart < 0)
return null;
if (resultPointCallback != null)
{
resultPointCallback(new ResultPoint(
endStart, rowNumber
));
}
var endRange = decodeEnd(row, endStart);
if (endRange == null)
return null;
if (resultPointCallback != null)
{
resultPointCallback(new ResultPoint(
(endRange[0] + endRange[1]) / 2.0f, rowNumber
));
}
// Make sure there is a quiet zone at least as big as the end pattern after the barcode. The
// spec might want more whitespace, but in practice this is the maximum we can count on.
var end = endRange[1];
var quietEnd = end + (end - endRange[0]);
if (quietEnd >= row.Size || !row.isRange(end, quietEnd, false))
{
return null;
}
var resultString = result.ToString();
// UPC/EAN should never be less than 8 chars anyway
if (resultString.Length < 8)
{
return null;
}
if (!checkChecksum(resultString))
{
return null;
}
var left = (startGuardRange[1] + startGuardRange[0]) / 2.0f;
var right = (endRange[1] + endRange[0]) / 2.0f;
var format = BarcodeFormat;
var decodeResult = new Result(resultString,
null, // no natural byte representation for these barcodes
new ResultPoint[]
{
new ResultPoint(left, rowNumber),
new ResultPoint(right, rowNumber)
},
format);
var extensionResult = extensionReader.decodeRow(rowNumber, row, endRange[1]);
if (extensionResult != null)
{
decodeResult.putMetadata(ResultMetadataType.UPC_EAN_EXTENSION, extensionResult.Text);
decodeResult.putAllMetadata(extensionResult.ResultMetadata);
decodeResult.addResultPoints(extensionResult.ResultPoints);
int extensionLength = extensionResult.Text.Length;
int[] allowedExtensions = hints != null && hints.ContainsKey(DecodeHintType.ALLOWED_EAN_EXTENSIONS) ?
(int[]) hints[DecodeHintType.ALLOWED_EAN_EXTENSIONS] : null;
if (allowedExtensions != null)
{
bool valid = false;
foreach (int length in allowedExtensions)
{
if (extensionLength == length)
{
valid = true;
break;
//.........这里部分代码省略.........
示例2: findEndPattern
private int[] findEndPattern(BitArray row, int rowOffset, int[] counters)
{
const int patternLength = 3;
int width = row.Size;
int counterPosition = 0;
int patternStart = rowOffset;
bool isWhite = false;
counters[0] = 0;
counters[1] = 0;
counters[2] = 0;
for (int i = rowOffset; i < width; i++)
{
if (row[i] ^ isWhite)
{
counters[counterPosition]++;
}
else
{
if (counterPosition == patternLength - 1)
{
var factorNarrowToWide = ((float)counters[1]) / ((float)counters[0]);
if (factorNarrowToWide >= 1.5 && factorNarrowToWide <= 5)
{
if (toPattern(counters, patternLength) == END_ENCODING)
{
// Look for whitespace after end pattern, >= 50% of width of end pattern
var minEndOfWhite = Math.Min(row.Size - 1, i + ((i - patternStart) >> 1));
if (row.isRange(i, minEndOfWhite, false))
{
return new int[] {patternStart, i};
}
}
}
return null;
}
counterPosition++;
counters[counterPosition] = 1;
isWhite = !isWhite;
}
}
return null;
}
示例3: findStartGuardPattern
internal static int[] findStartGuardPattern(BitArray row)
{
bool foundStart = false;
int[] startRange = null;
int nextStart = 0;
int[] counters = new int[START_END_PATTERN.Length];
while (!foundStart)
{
for (int idx = 0; idx < START_END_PATTERN.Length; idx++)
counters[idx] = 0;
startRange = findGuardPattern(row, nextStart, false, START_END_PATTERN, counters);
if (startRange == null)
return null;
int start = startRange[0];
nextStart = startRange[1];
// Make sure there is a quiet zone at least as big as the start pattern before the barcode.
// If this check would run off the left edge of the image, do not accept this barcode,
// as it is very likely to be a false positive.
int quietStart = start - (nextStart - start);
if (quietStart >= 0)
{
foundStart = row.isRange(quietStart, start, false);
}
}
return startRange;
}
示例4: findStartPattern
private int[] findStartPattern(BitArray row, int[] counters)
{
const int patternLength = 2;
int width = row.Size;
int rowOffset = row.getNextSet(0);
int counterPosition = 0;
int patternStart = rowOffset;
bool isWhite = false;
counters[0] = 0;
counters[1] = 0;
for (int i = rowOffset; i < width; i++)
{
if (row[i] ^ isWhite)
{
counters[counterPosition]++;
}
else
{
if (counterPosition == patternLength - 1)
{
// narrow and wide areas should be as near as possible to factor 2
// lets say we will check 1.5 <= factor <= 5
var factorNarrowToWide = ((float)counters[0]) / ((float)counters[1]);
if (factorNarrowToWide >= 1.5 && factorNarrowToWide <= 5)
{
calculateAverageCounterWidth(counters, patternLength);
if (toPattern(counters, patternLength) == START_ENCODING)
{
// Look for whitespace before start pattern, >= 50% of width of start pattern
if (row.isRange(Math.Max(0, patternStart - ((i - patternStart) >> 1)), patternStart, false))
{
return new int[] {patternStart, i};
}
}
}
patternStart += counters[0] + counters[1];
Array.Copy(counters, 2, counters, 0, patternLength - 2);
counters[patternLength - 2] = 0;
counters[patternLength - 1] = 0;
counterPosition--;
}
else
{
counterPosition++;
}
counters[counterPosition] = 1;
isWhite = !isWhite;
}
}
return null;
}
示例5: findAsteriskPattern
private static int[] findAsteriskPattern(BitArray row, int[] counters)
{
int width = row.Size;
int rowOffset = row.getNextSet(0);
int counterPosition = 0;
int patternStart = rowOffset;
bool isWhite = false;
int patternLength = counters.Length;
for (int i = rowOffset; i < width; i++)
{
if (row[i] ^ isWhite)
{
counters[counterPosition]++;
}
else
{
if (counterPosition == patternLength - 1)
{
if (toNarrowWidePattern(counters) == ASTERISK_ENCODING)
{
// Look for whitespace before start pattern, >= 50% of width of start pattern
if (row.isRange(Math.Max(0, patternStart - ((i - patternStart) >> 1)), patternStart, false))
{
return new int[] { patternStart, i };
}
}
patternStart += counters[0] + counters[1];
Array.Copy(counters, 2, counters, 0, patternLength - 2);
counters[patternLength - 2] = 0;
counters[patternLength - 1] = 0;
counterPosition--;
}
else
{
counterPosition++;
}
counters[counterPosition] = 1;
isWhite = !isWhite;
}
}
return null;
}
示例6: decodeRow
//.........这里部分代码省略.........
{
lastCharacterWasPrintable = false;
}
switch (code)
{
case CODE_FNC_1:
// do nothing?
break;
case CODE_CODE_A:
codeSet = CODE_CODE_A;
break;
case CODE_CODE_B:
codeSet = CODE_CODE_B;
break;
case CODE_STOP:
done = true;
break;
}
}
break;
}
// Unshift back to another code set if we were shifted
if (unshift)
{
codeSet = codeSet == CODE_CODE_A ? CODE_CODE_B : CODE_CODE_A;
}
}
// Check for ample whitespace following pattern, but, to do this we first need to remember that
// we fudged decoding CODE_STOP since it actually has 7 bars, not 6. There is a black bar left
// to read off. Would be slightly better to properly read. Here we just skip it:
nextStart = row.getNextUnset(nextStart);
if (!row.isRange(nextStart,
Math.Min(row.Size, nextStart + (nextStart - lastStart) / 2),
false))
{
return null;
}
// Pull out from sum the value of the penultimate check code
checksumTotal -= multiplier * lastCode;
// lastCode is the checksum then:
if (checksumTotal % 103 != lastCode)
{
return null;
}
// Need to pull out the check digits from string
int resultLength = result.Length;
if (resultLength == 0)
{
// false positive
return null;
}
// Only bother if the result had at least one character, and if the checksum digit happened to
// be a printable character. If it was just interpreted as a control code, nothing to remove.
if (resultLength > 0 && lastCharacterWasPrintable)
{
if (codeSet == CODE_CODE_C)
{
result.Remove(resultLength - 2, 2);
}
else
{
result.Remove(resultLength - 1, 1);
}
}
float left = (startPatternInfo[1] + startPatternInfo[0]) / 2.0f;
float right = (nextStart + lastStart) / 2.0f;
var resultPointCallback = hints == null || !hints.ContainsKey(DecodeHintType.NEED_RESULT_POINT_CALLBACK)
? null
: (ResultPointCallback)hints[DecodeHintType.NEED_RESULT_POINT_CALLBACK];
if (resultPointCallback != null)
{
resultPointCallback(new ResultPoint(left, rowNumber));
resultPointCallback(new ResultPoint(right, rowNumber));
}
int rawCodesSize = rawCodes.Count;
var rawBytes = new byte[rawCodesSize];
for (int i = 0; i < rawCodesSize; i++)
{
rawBytes[i] = rawCodes[i];
}
return new Result(
result.ToString(),
rawBytes,
new []
{
new ResultPoint(left, rowNumber),
new ResultPoint(right, rowNumber)
},
BarcodeFormat.CODE_128);
}
示例7: findStartPattern
private static int[] findStartPattern(BitArray row)
{
int width = row.Size;
int rowOffset = row.getNextSet(0);
int counterPosition = 0;
int[] counters = new int[6];
int patternStart = rowOffset;
bool isWhite = false;
int patternLength = counters.Length;
for (int i = rowOffset; i < width; i++)
{
if (row[i] ^ isWhite)
{
counters[counterPosition]++;
}
else
{
if (counterPosition == patternLength - 1)
{
int bestVariance = MAX_AVG_VARIANCE;
int bestMatch = -1;
for (int startCode = CODE_START_A; startCode <= CODE_START_C; startCode++)
{
int variance = patternMatchVariance(counters, CODE_PATTERNS[startCode],
MAX_INDIVIDUAL_VARIANCE);
if (variance < bestVariance)
{
bestVariance = variance;
bestMatch = startCode;
}
}
if (bestMatch >= 0)
{
// Look for whitespace before start pattern, >= 50% of width of start pattern
if (row.isRange(Math.Max(0, patternStart - (i - patternStart) / 2), patternStart,
false))
{
return new int[] { patternStart, i, bestMatch };
}
}
patternStart += counters[0] + counters[1];
Array.Copy(counters, 2, counters, 0, patternLength - 2);
counters[patternLength - 2] = 0;
counters[patternLength - 1] = 0;
counterPosition--;
}
else
{
counterPosition++;
}
counters[counterPosition] = 1;
isWhite = !isWhite;
}
}
return null;
}
示例8: decodeRow
/// <summary>
/// <p>Like decodeRow(int, BitArray, java.util.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.</p>
/// </summary>
virtual public Result decodeRow(int rowNumber,
BitArray row,
int[] startGuardRange,
IDictionary<DecodeHintType, object> hints)
{
ResultPointCallback resultPointCallback = hints == null || !hints.ContainsKey(DecodeHintType.NEED_RESULT_POINT_CALLBACK) ? null :
(ResultPointCallback)hints[DecodeHintType.NEED_RESULT_POINT_CALLBACK];
if (resultPointCallback != null)
{
resultPointCallback(new ResultPoint(
(startGuardRange[0] + startGuardRange[1]) / 2.0f, rowNumber
));
}
StringBuilder result = decodeRowStringBuffer;
result.Length = 0;
int endStart = decodeMiddle(row, startGuardRange, result);
if (endStart < 0)
return null;
if (resultPointCallback != null)
{
resultPointCallback(new ResultPoint(
endStart, rowNumber
));
}
int[] endRange = decodeEnd(row, endStart);
if (endRange == null)
return null;
if (resultPointCallback != null)
{
resultPointCallback(new ResultPoint(
(endRange[0] + endRange[1]) / 2.0f, rowNumber
));
}
// Make sure there is a quiet zone at least as big as the end pattern after the barcode. The
// spec might want more whitespace, but in practice this is the maximum we can count on.
int end = endRange[1];
int quietEnd = end + (end - endRange[0]);
if (quietEnd >= row.Size || !row.isRange(end, quietEnd, false))
{
return null;
}
String resultString = result.ToString();
if (!checkChecksum(resultString))
{
return null;
}
float left = (startGuardRange[1] + startGuardRange[0]) / 2.0f;
float right = (endRange[1] + endRange[0]) / 2.0f;
BarcodeFormat format = BarcodeFormat;
Result decodeResult = new Result(resultString,
null, // no natural byte representation for these barcodes
new ResultPoint[]
{
new ResultPoint(left, rowNumber),
new ResultPoint(right, rowNumber)
},
format);
Result extensionResult = extensionReader.decodeRow(rowNumber, row, endRange[1]);
if (extensionResult != null)
{
decodeResult.putMetadata(ResultMetadataType.UPC_EAN_EXTENSION, extensionResult.Text);
decodeResult.putAllMetadata(extensionResult.ResultMetadata);
decodeResult.addResultPoints(extensionResult.ResultPoints);
}
if (format == BarcodeFormat.EAN_13 || format == BarcodeFormat.UPC_A)
{
String countryID = eanManSupport.lookupCountryIdentifier(resultString);
if (countryID != null)
{
decodeResult.putMetadata(ResultMetadataType.POSSIBLE_COUNTRY, countryID);
}
}
return decodeResult;
}