//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public com.google.zxing.Result decodeRow(int rowNumber, com.google.zxing.common.BitArray row, java.util.Map<com.google.zxing.DecodeHintType,?> hints) throws com.google.zxing.NotFoundException, com.google.zxing.ChecksumException, com.google.zxing.FormatException public override Result decodeRow(int rowNumber, BitArray row, IDictionary<DecodeHintType, object> hints) { int[] theCounters = counters; theCounters.Fill(0); StringBuilder result = decodeRowResult; result.Length = 0; int[] start = findAsteriskPattern(row, theCounters); // Read off white space int nextStart = row.getNextSet(start[1]); int end = row.Size; char decodedChar; int lastStart; do { recordPattern(row, nextStart, theCounters); int pattern = toNarrowWidePattern(theCounters); if (pattern < 0) { throw NotFoundException.NotFoundInstance; } decodedChar = patternToChar(pattern); result.Append(decodedChar); lastStart = nextStart; foreach (int counter in theCounters) { nextStart += counter; } // Read off white space nextStart = row.getNextSet(nextStart); } while (decodedChar != '*'); result.Length = result.Length - 1; // remove asterisk // Look for whitespace after pattern: int lastPatternSize = 0; foreach (int counter in theCounters) { lastPatternSize += counter; } 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 >> 1) < lastPatternSize) { throw NotFoundException.NotFoundInstance; } if (usingCheckDigit) { int max = result.Length - 1; int total = 0; for (int i = 0; i < max; i++) { total += ALPHABET_STRING.IndexOf(decodeRowResult[i]); } if (result[max] != ALPHABET[total % 43]) { throw ChecksumException.ChecksumInstance; } result.Length = max; } if (result.Length == 0) { // false positive throw NotFoundException.NotFoundInstance; } string resultString; if (extendedMode) { resultString = decodeExtended(result.ToString()); } else { resultString = result.ToString(); } float left = (float)(start[1] + start[0]) / 2.0f; float right = (float)(nextStart + lastStart) / 2.0f; return new Result(resultString, null, new ResultPoint[]{new ResultPoint(left, (float) rowNumber), new ResultPoint(right, (float) rowNumber)}, BarcodeFormat.CODE_39); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static int[] findAsteriskPattern(com.google.zxing.common.BitArray row, int[] counters) throws com.google.zxing.NotFoundException 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.get(i) ^ isWhite) { counters[counterPosition]++; } else { if (counterPosition == patternLength - 1) { // Look for whitespace before start pattern, >= 50% of width of start pattern if (toNarrowWidePattern(counters) == ASTERISK_ENCODING && 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; } } throw NotFoundException.NotFoundInstance; }
/// <param name="row"> row of black/white values to search </param> /// <param name="rowOffset"> position to start search </param> /// <param name="whiteFirst"> if true, indicates that the pattern specifies white/black/white/... /// pixel counts, otherwise, it is interpreted as black/white/black/... </param> /// <param name="pattern"> pattern of counts of number of black and white pixels that are being /// searched for as a pattern </param> /// <param name="counters"> array of counters, as long as pattern, to re-use </param> /// <returns> start/end horizontal offset of guard pattern, as an array of two ints </returns> /// <exception cref="NotFoundException"> if pattern is not found </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static int[] findGuardPattern(com.google.zxing.common.BitArray row, int rowOffset, boolean whiteFirst, int[] pattern, int[] counters) throws com.google.zxing.NotFoundException private static int[] findGuardPattern(BitArray row, int rowOffset, bool whiteFirst, int[] pattern, int[] counters) { int patternLength = pattern.Length; int width = row.Size; bool isWhite = whiteFirst; rowOffset = whiteFirst ? row.getNextUnset(rowOffset) : row.getNextSet(rowOffset); int counterPosition = 0; int patternStart = rowOffset; for (int x = rowOffset; x < width; x++) { if (row.get(x) ^ isWhite) { counters[counterPosition]++; } else { if (counterPosition == patternLength - 1) { if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) { return new int[]{patternStart, x}; } 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; } } throw NotFoundException.NotFoundInstance; }