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