public override Result decodeRow(int rowNumber, BitArray row, Dictionary<DecodeHintType, Object> hints)
{
int[] start = findAsteriskPattern(row);
int nextStart = start[1];
int end = row.Size;
// Read off white space
while (nextStart < end && !row.get_Renamed(nextStart))
{
nextStart++;
}
var result = new StringBuilder(20);
var counters = new int[9];
char decodedChar;
int lastStart;
do
{
recordPattern(row, nextStart, counters);
int pattern = toNarrowWidePattern(counters);
if (pattern < 0)
{
throw ReaderException.Instance;
}
decodedChar = patternToChar(pattern);
result.Append(decodedChar);
lastStart = nextStart;
for (int i = 0; i < counters.Length; i++)
{
nextStart += counters[i];
}
// Read off white space
while (nextStart < end && !row.get_Renamed(nextStart))
{
nextStart++;
}
} while (decodedChar != '*');
result.Remove(result.Length - 1, 1); // remove asterisk
// Look for whitespace after pattern:
int lastPatternSize = 0;
for (int i = 0; i < counters.Length; i++)
{
lastPatternSize += counters[i];
}
int whiteSpaceAfterEnd = nextStart - lastStart - lastPatternSize;
// If 50% of last pattern size, following last pattern, is not whitespace, fail
// (but if it's whitespace to the very end of the image, that's OK)
if (nextStart != end && whiteSpaceAfterEnd/2 < lastPatternSize)
{
throw ReaderException.Instance;
}
if (usingCheckDigit)
{
int max = result.Length - 1;
int total = 0;
for (int i = 0; i < max; i++)
{
total += ALPHABET_STRING.IndexOf((Char) result[i]);
}
if (total%43 != ALPHABET_STRING.IndexOf((Char) result[max]))
{
throw ReaderException.Instance;
}
result.Remove(max, 1);
}
String resultString = result.ToString();
if (extendedMode)
{
resultString = decodeExtended(resultString);
}
if (resultString.Length == 0)
{
// Almost surely a false positive
throw ReaderException.Instance;
}
float left = (start[1] + start[0])/2.0f;
float right = (nextStart + lastStart)/2.0f;
return new Result(resultString, null,
new[] {new ResultPoint(left, rowNumber), new ResultPoint(right, rowNumber)},
BarcodeFormat.CODE_39);
}