예제 #1
0
 internal static int[] findStartGuardPattern(BitArray row)
 {
     bool foundStart = false;
     int[] startRange = null;
     int nextStart = 0;
     while (!foundStart)
     {
         startRange = findGuardPattern(row, nextStart, false, START_END_PATTERN);
         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;
 }
예제 #2
0
        private static int[] findAsteriskPattern(BitArray row)
        {
            int width = row.Size;
            int rowOffset = 0;
            while (rowOffset < width)
            {
                if (row.get_Renamed(rowOffset))
                {
                    break;
                }
                rowOffset++;
            }

            int counterPosition = 0;
            int[] counters = new int[9];
            int patternStart = rowOffset;
            bool isWhite = false;
            int patternLength = counters.Length;

            for (int i = rowOffset; i < width; i++)
            {
                bool pixel = row.get_Renamed(i);
                if (pixel ^ 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(System.Math.Max(0, patternStart - (i - patternStart) / 2), patternStart, false))
                            {
                                return new int[]{patternStart, i};
                            }
                        }
                        patternStart += counters[0] + counters[1];
                        for (int y = 2; y < patternLength; y++)
                        {
                            counters[y - 2] = counters[y];
                        }
                        counters[patternLength - 2] = 0;
                        counters[patternLength - 1] = 0;
                        counterPosition--;
                    }
                    else
                    {
                        counterPosition++;
                    }
                    counters[counterPosition] = 1;
                    isWhite = !isWhite;
                }
            }
            throw ReaderException.Instance;
        }
예제 #3
0
        /// <summary> <p>Like {@link #decodeRow(int, BitArray, java.util.Hashtable)}, 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>
        public virtual Result decodeRow(int rowNumber, BitArray row, int[] startGuardRange, System.Collections.Hashtable hints)
        {
            ResultPointCallback resultPointCallback = hints == null?null:(ResultPointCallback) hints[DecodeHintType.NEED_RESULT_POINT_CALLBACK];

            if (resultPointCallback != null)
            {
                resultPointCallback.foundPossibleResultPoint(new ResultPoint((startGuardRange[0] + startGuardRange[1]) / 2.0f, rowNumber));
            }

            System.Text.StringBuilder result = decodeRowStringBuffer;
            result.Length = 0;
            int endStart = decodeMiddle(row, startGuardRange, result);

            if (resultPointCallback != null)
            {
                resultPointCallback.foundPossibleResultPoint(new ResultPoint(endStart, rowNumber));
            }

            int[] endRange = decodeEnd(row, endStart);

            if (resultPointCallback != null)
            {
                resultPointCallback.foundPossibleResultPoint(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))
            {
                throw ReaderException.Instance;
            }

            System.String resultString = result.ToString();
            if (!checkChecksum(resultString))
            {
                throw ReaderException.Instance;
            }

            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            float left = (float) (startGuardRange[1] + startGuardRange[0]) / 2.0f;
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            float right = (float) (endRange[1] + endRange[0]) / 2.0f;
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            return new Result(resultString, null, new ResultPoint[]{new ResultPoint(left, (float) rowNumber), new ResultPoint(right, (float) rowNumber)}, BarcodeFormat);
        }