예제 #1
0
        /// <summary>
        /// Decodes the codewords.
        /// </summary>
        /// <returns>The codewords.</returns>
        /// <param name="codewords">Codewords.</param>
        /// <param name="ecLevel">Ec level.</param>
        /// <param name="erasures">Erasures.</param>
        private static DecoderResult decodeCodewords(int[] codewords, int ecLevel, int[] erasures)
        {
            if (codewords.Length == 0)
            {
                return(null);
            }

            int numECCodewords = 1 << (ecLevel + 1);

            int correctedErrorsCount = correctErrors(codewords, erasures, numECCodewords);

            if (correctedErrorsCount < 0)
            {
                return(null);
            }
            if (!verifyCodewordCount(codewords, numECCodewords))
            {
                return(null);
            }

            // Decode the codewords
            DecoderResult decoderResult = DecodedBitStreamParser.decode(codewords, ecLevel.ToString());

            if (decoderResult != null)
            {
                decoderResult.ErrorsCorrected = correctedErrorsCount;
                decoderResult.Erasures        = erasures.Length;
            }
            return(decoderResult);
        }
예제 #2
0
        /// <summary>
        /// <p>Decodes a PDF417 Code represented as a <see cref="BitMatrix" />.
        /// A 1 or "true" is taken to mean a black module.</p>
        ///
        /// <param name="bits">booleans representing white/black PDF417 Code modules</param>
        /// <returns>text and bytes encoded within the PDF417 Code</returns>
        /// <exception cref="FormatException">if the PDF417 Code cannot be decoded</exception>
        /// </summary>
        public DecoderResult decode(BitMatrix bits)
        {
            // Construct a parser to read the data codewords and error-correction level
            BitMatrixParser parser = new BitMatrixParser(bits);

            int[] codewords = parser.readCodewords();
            if (codewords == null || codewords.Length == 0)
            {
                return(null);
            }

            int ecLevel        = parser.getECLevel();
            int numECCodewords = 1 << (ecLevel + 1);

            int[] erasures = parser.getErasures();

            if (!correctErrors(codewords, erasures, numECCodewords))
            {
                return(null);
            }
            if (!verifyCodewordCount(codewords, numECCodewords))
            {
                return(null);
            }

            // Decode the codewords
            return(DecodedBitStreamParser.decode(codewords));
        }
        /// <summary>
        /// Decodes the codewords.
        /// </summary>
        /// <returns>The codewords.</returns>
        /// <param name="codewords">Codewords.</param>
        /// <param name="ecLevel">Ec level.</param>
        /// <param name="erasures">Erasures.</param>
        private static DecoderResult DecodeCodewords(int[] codewords, int ecLevel, int[] erasures)
        {
            if (codewords.Length == 0)
            {
                throw ReaderException.Instance;
            }

            int numECCodewords = 1 << (ecLevel + 1);

            Log.WriteLine("EC level: " + ecLevel + ", ec codewords: " + numECCodewords);

            int correctedErrorsCount = CorrectErrors(codewords, erasures, numECCodewords);

            Log.WriteLine("Corrected errors: " + correctedErrorsCount);
            VerifyCodewordCount(codewords, numECCodewords);

            // Decode the codewords
            DecoderResult decoderResult = DecodedBitStreamParser.Decode(codewords);

            decoderResult.ErrorsCorrected = (correctedErrorsCount >= 0) ? correctedErrorsCount : 0;
            decoderResult.Erasures        = erasures.Length;
            return(decoderResult);
        }