示例#1
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));
        }
        /// <summary>
        /// <p>This is called when a horizontal scan finds a possible alignment pattern. It will
        /// cross check with a vertical scan, and if successful, will see if this pattern had been
        /// found on a previous horizontal scan. If so, we consider it confirmed and conclude we have
        /// found the alignment pattern.</p>
        /// </summary>
        /// <param name="stateCount"> reading state module counts from horizontal scan </param>
        /// <param name="i"> row where alignment pattern may be found </param>
        /// <param name="j"> end of possible alignment pattern in row </param>
        /// <returns> <seealso cref="AlignmentPattern"/> if we have found the same pattern twice, or null if not </returns>
        private AlignmentPattern handlePossibleCenter(int[] stateCount, int i, int j)
        {
            int   stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];
            float centerJ         = centerFromEnd(stateCount, j);
            float centerI         = crossCheckVertical(i, (int)centerJ, 2 * stateCount[1], stateCountTotal);

            if (!float.IsNaN(centerI))
            {
                float estimatedModuleSize = (float)(stateCount[0] + stateCount[1] + stateCount[2]) / 3.0f;
                foreach (AlignmentPattern center in possibleCenters)
                {
                    // Look for about the same center and module size:
                    if (center.aboutEquals(estimatedModuleSize, centerI, centerJ))
                    {
                        return(center.combineEstimate(centerI, centerJ, estimatedModuleSize));
                    }
                }
                // Hadn't found this before; save it
                AlignmentPattern point = new AlignmentPattern(centerJ, centerI, estimatedModuleSize);
                possibleCenters.Add(point);
                if (resultPointCallback != null)
                {
                    resultPointCallback.foundPossibleResultPoint(point);
                }
            }
            return(null);
        }
示例#3
0
        /// <summary>
        /// <p>Like <seealso cref="#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>
//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, int[] startGuardRange, java.util.Map<com.google.zxing.DecodeHintType,?> hints) throws com.google.zxing.NotFoundException, com.google.zxing.ChecksumException, com.google.zxing.FormatException
        public virtual Result decodeRow(int rowNumber, BitArray row, int[] startGuardRange, IDictionary <DecodeHintType, object> hints)
        {
            //ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints[DecodeHintType.NEED_RESULT_POINT_CALLBACK];
            ResultPointCallback resultPointCallback = null;

            if (hints != null && hints.ContainsKey(DecodeHintType.NEED_RESULT_POINT_CALLBACK))
            {
                resultPointCallback = (ResultPointCallback)hints[DecodeHintType.NEED_RESULT_POINT_CALLBACK];
            }

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

            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 NotFoundException.NotFoundInstance;
            }

            string resultString = result.ToString();

            if (!checkChecksum(resultString))
            {
                throw ChecksumException.ChecksumInstance;
            }

            float         left         = (float)(startGuardRange[1] + startGuardRange[0]) / 2.0f;
            float         right        = (float)(endRange[1] + endRange[0]) / 2.0f;
            BarcodeFormat format       = BarcodeFormat;
            Result        decodeResult = new Result(resultString, null, new ResultPoint[] { new ResultPoint(left, (float)rowNumber), new ResultPoint(right, (float)rowNumber) }, format); // no natural byte representation for these barcodes

            try
            {
                Result extensionResult = extensionReader.decodeRow(rowNumber, row, endRange[1]);
                decodeResult.putMetadata(ResultMetadataType.UPC_EAN_EXTENSION, extensionResult.Text);
                decodeResult.putAllMetadata(extensionResult.ResultMetadata);
                decodeResult.addResultPoints(extensionResult.ResultPoints);
            }
            catch (ReaderException re)
            {
                // continue
            }

            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);
        }