コード例 #1
0
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: private static int[] findStartPattern(com.google.zxing.common.BitArray row) throws com.google.zxing.NotFoundException
        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.get(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;
                }
              }
              // Look for whitespace before start pattern, >= 50% of width of start pattern
              if (bestMatch >= 0 && 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;
              }
            }
            throw NotFoundException.NotFoundInstance;
        }
コード例 #2
0
        /// <summary>
        /// Skip all whitespace until we get to the first black line.
        /// </summary>
        /// <param name="row"> row of black/white values to search </param>
        /// <returns> index of the first black line. </returns>
        /// <exception cref="NotFoundException"> Throws exception if no black lines are found in the row </exception>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: private static int skipWhiteSpace(com.google.zxing.common.BitArray row) throws com.google.zxing.NotFoundException
        private static int skipWhiteSpace(BitArray row)
        {
            int width = row.Size;
            int endStart = row.getNextSet(0);
            if (endStart == width)
            {
              throw NotFoundException.NotFoundInstance;
            }

            return endStart;
        }