Exemplo n.º 1
0
        /// <summary> <p>Decodes a PDF417 Code represented as a {@link BitMatrix}.
        /// A 1 or "true" is taken to mean a black module.</p>
        ///
        /// </summary>
        /// <param name="bits">booleans representing white/black PDF417 Code modules
        /// </param>
        /// <returns> text and bytes encoded within the PDF417 Code
        /// </returns>
        /// <throws>  ReaderException if the PDF417 Code cannot be decoded </throws>
        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.ECLevel;
            int numECCodewords = 1 << (ecLevel + 1);

            int[] erasures = parser.Erasures;

            int?ceResult = correctErrors(codewords, erasures, numECCodewords);

            if (ceResult.IsBlank())
            {
                return(null);
            }

            bool success = verifyCodewordCount(codewords, numECCodewords);

            if (!success)
            {
                return(null);
            }

            // Decode the codewords
            return(DecodedBitStreamParser.decode(codewords));
        }
Exemplo n.º 2
0
        /// <summary> <p>Decodes a PDF417 Code represented as a {@link BitMatrix}.
        /// A 1 or "true" is taken to mean a black module.</p>
        ///
        /// </summary>
        /// <param name="bits">booleans representing white/black PDF417 Code modules
        /// </param>
        /// <returns> text and bytes encoded within the PDF417 Code
        /// </returns>
        /// <throws>  ReaderException if the PDF417 Code cannot be decoded </throws>
        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)
            {
                throw ReaderException.Instance;
            }

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

            int[] erasures = parser.Erasures;

            correctErrors(codewords, erasures, numECCodewords);
            verifyCodewordCount(codewords, numECCodewords);

            // Decode the codewords
            return(DecodedBitStreamParser.decode(codewords));
        }