コード例 #1
0
ファイル: Decoder.cs プロジェクト: tofilagman/z.Barcode
        /// <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));
        }
コード例 #2
0
ファイル: Decoder.cs プロジェクト: smart-make/zxing
        /// <summary>
        /// <p>Decodes a PDF417 Code represented as a <seealso cref="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>
        /// <exception cref="FormatException"> if the PDF417 Code cannot be decoded </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public com.google.zxing.common.DecoderResult decode(com.google.zxing.common.BitMatrix bits) throws com.google.zxing.FormatException, com.google.zxing.ChecksumException
        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.Length == 0)
            {
                throw FormatException.FormatInstance;
            }

            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));
        }
コード例 #3
0
ファイル: Decoder.cs プロジェクト: henningms/zxing2.0-wp7
        /// <summary> <p>Decodes a Data Matrix 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 Data Matrix Code modules
        /// </param>
        /// <returns> text and bytes encoded within the Data Matrix Code
        /// </returns>
        /// <throws>  ReaderException if the Data Matrix Code cannot be decoded </throws>
        public DecoderResult decode(BitMatrix bits)
        {
            // Construct a parser and read version, error-correction level
            var parser = new BitMatrixParser(bits);
            Version version = parser.readVersion(bits);

            // Read codewords
            sbyte[] codewords = parser.readCodewords();
            // Separate into data blocks
            DataBlock[] dataBlocks = DataBlock.getDataBlocks(codewords, version);

            // Count total number of data bytes
            int totalBytes = 0;
            for (int i = 0; i < dataBlocks.Length; i++)
            {
                totalBytes += dataBlocks[i].NumDataCodewords;
            }
            var resultBytes = new sbyte[totalBytes];
            int resultOffset = 0;

            // Error-correct and copy data blocks together into a stream of bytes
            for (int j = 0; j < dataBlocks.Length; j++)
            {
                DataBlock dataBlock = dataBlocks[j];
                sbyte[] codewordBytes = dataBlock.Codewords;
                int numDataCodewords = dataBlock.NumDataCodewords;
                correctErrors(codewordBytes, numDataCodewords);
                for (int i = 0; i < numDataCodewords; i++)
                {
                    resultBytes[resultOffset++] = codewordBytes[i];
                }
            }

            // Decode the contents of that stream of bytes
            return DecodedBitStreamParser.decode(resultBytes);
        }