* Given data and error-correction codewords received, possibly corrupted by errors, attempts to * correct the errors in-place using Reed-Solomon error correction. * * @param codewordBytes data and error correction codewords * @param numDataCodewords number of codewords that are data bytes * @return false if error correction fails */
| 37 | * @return false if error correction fails |
| 38 | */ |
| 39 | static bool CorrectErrors(ByteArray& codewordBytes, int numDataCodewords) |
| 40 | { |
| 41 | // First read into an array of ints |
| 42 | std::vector<int> codewordsInts(codewordBytes.begin(), codewordBytes.end()); |
| 43 | |
| 44 | int numECCodewords = Size(codewordBytes) - numDataCodewords; |
| 45 | if (!ReedSolomonDecode(GenericGF::QRCodeField256(), codewordsInts, numECCodewords)) |
| 46 | return false; |
| 47 | |
| 48 | // Copy back into array of bytes -- only need to worry about the bytes that were data |
| 49 | // We don't care about errors in the error-correction codewords |
| 50 | std::copy_n(codewordsInts.begin(), numDataCodewords, codewordBytes.begin()); |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | |
| 55 | /** |
no test coverage detected