Renamed QrCode.appendErrorCorrection() to addEccAndInterleave() in all language versions.

pull/39/merge
Project Nayuki 7 years ago
parent 206618d71c
commit 0ee6c41c9c

@ -52,7 +52,7 @@ static int numTestCases = 0;
extern const int8_t ECC_CODEWORDS_PER_BLOCK[4][41]; extern const int8_t ECC_CODEWORDS_PER_BLOCK[4][41];
extern const int8_t NUM_ERROR_CORRECTION_BLOCKS[4][41]; extern const int8_t NUM_ERROR_CORRECTION_BLOCKS[4][41];
void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int *bitLen); void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int *bitLen);
void appendErrorCorrection(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]); void addEccAndInterleave(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]);
int getNumDataCodewords(int version, enum qrcodegen_Ecc ecl); int getNumDataCodewords(int version, enum qrcodegen_Ecc ecl);
int getNumRawDataModules(int version); int getNumRawDataModules(int version);
void calcReedSolomonGenerator(int degree, uint8_t result[]); void calcReedSolomonGenerator(int degree, uint8_t result[]);
@ -111,7 +111,7 @@ static void testAppendBitsToBuffer(void) {
// Ported from the Java version of the code. // Ported from the Java version of the code.
static uint8_t *appendErrorCorrectionReference(const uint8_t *data, int version, enum qrcodegen_Ecc ecl) { static uint8_t *addEccAndInterleaveReference(const uint8_t *data, int version, enum qrcodegen_Ecc ecl) {
// Calculate parameter numbers // Calculate parameter numbers
int numBlocks = NUM_ERROR_CORRECTION_BLOCKS[(int)ecl][version]; int numBlocks = NUM_ERROR_CORRECTION_BLOCKS[(int)ecl][version];
int blockEccLen = ECC_CODEWORDS_PER_BLOCK[(int)ecl][version]; int blockEccLen = ECC_CODEWORDS_PER_BLOCK[(int)ecl][version];
@ -151,20 +151,20 @@ static uint8_t *appendErrorCorrectionReference(const uint8_t *data, int version,
} }
static void testAppendErrorCorrection(void) { static void testAddEccAndInterleave(void) {
for (int version = 1; version <= 40; version++) { for (int version = 1; version <= 40; version++) {
for (int ecl = 0; ecl < 4; ecl++) { for (int ecl = 0; ecl < 4; ecl++) {
int dataLen = getNumDataCodewords(version, (enum qrcodegen_Ecc)ecl); int dataLen = getNumDataCodewords(version, (enum qrcodegen_Ecc)ecl);
uint8_t *pureData = MALLOC(dataLen, uint8_t); uint8_t *pureData = MALLOC(dataLen, uint8_t);
for (int i = 0; i < dataLen; i++) for (int i = 0; i < dataLen; i++)
pureData[i] = rand() % 256; pureData[i] = rand() % 256;
uint8_t *expectOutput = appendErrorCorrectionReference(pureData, version, (enum qrcodegen_Ecc)ecl); uint8_t *expectOutput = addEccAndInterleaveReference(pureData, version, (enum qrcodegen_Ecc)ecl);
int dataAndEccLen = getNumRawDataModules(version) / 8; int dataAndEccLen = getNumRawDataModules(version) / 8;
uint8_t *paddedData = MALLOC(dataAndEccLen, uint8_t); uint8_t *paddedData = MALLOC(dataAndEccLen, uint8_t);
memcpy(paddedData, pureData, dataLen * sizeof(uint8_t)); memcpy(paddedData, pureData, dataLen * sizeof(uint8_t));
uint8_t *actualOutput = MALLOC(dataAndEccLen, uint8_t); uint8_t *actualOutput = MALLOC(dataAndEccLen, uint8_t);
appendErrorCorrection(paddedData, version, (enum qrcodegen_Ecc)ecl, actualOutput); addEccAndInterleave(paddedData, version, (enum qrcodegen_Ecc)ecl, actualOutput);
assert(memcmp(actualOutput, expectOutput, dataAndEccLen * sizeof(uint8_t)) == 0); assert(memcmp(actualOutput, expectOutput, dataAndEccLen * sizeof(uint8_t)) == 0);
free(pureData); free(pureData);
@ -1057,7 +1057,7 @@ static void testGetTotalBits(void) {
int main(void) { int main(void) {
srand(time(NULL)); srand(time(NULL));
testAppendBitsToBuffer(); testAppendBitsToBuffer();
testAppendErrorCorrection(); testAddEccAndInterleave();
testGetNumDataCodewords(); testGetNumDataCodewords();
testGetNumRawDataModules(); testGetNumRawDataModules();
testCalcReedSolomonGenerator(); testCalcReedSolomonGenerator();

@ -60,7 +60,7 @@
testable void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int *bitLen); testable void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int *bitLen);
testable void appendErrorCorrection(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]); testable void addEccAndInterleave(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]);
testable int getNumDataCodewords(int version, enum qrcodegen_Ecc ecl); testable int getNumDataCodewords(int version, enum qrcodegen_Ecc ecl);
testable int getNumRawDataModules(int version); testable int getNumRawDataModules(int version);
@ -195,7 +195,7 @@ testable void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[]
// from the blocks and stores them in the result array. data[0 : rawCodewords - totalEcc] contains // from the blocks and stores them in the result array. data[0 : rawCodewords - totalEcc] contains
// the input data. data[rawCodewords - totalEcc : rawCodewords] is used as a temporary work area // the input data. data[rawCodewords - totalEcc : rawCodewords] is used as a temporary work area
// and will be clobbered by this function. The final answer is stored in result[0 : rawCodewords]. // and will be clobbered by this function. The final answer is stored in result[0 : rawCodewords].
testable void appendErrorCorrection(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]) { testable void addEccAndInterleave(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]) {
// Calculate parameter numbers // Calculate parameter numbers
assert(0 <= (int)ecl && (int)ecl < 4 && qrcodegen_VERSION_MIN <= version && version <= qrcodegen_VERSION_MAX); assert(0 <= (int)ecl && (int)ecl < 4 && qrcodegen_VERSION_MIN <= version && version <= qrcodegen_VERSION_MAX);
int numBlocks = NUM_ERROR_CORRECTION_BLOCKS[(int)ecl][version]; int numBlocks = NUM_ERROR_CORRECTION_BLOCKS[(int)ecl][version];
@ -948,7 +948,7 @@ bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], siz
assert(bitLen % 8 == 0); assert(bitLen % 8 == 0);
// Draw function and data codeword modules // Draw function and data codeword modules
appendErrorCorrection(qrcode, version, ecl, tempBuffer); addEccAndInterleave(qrcode, version, ecl, tempBuffer);
initializeFunctionModules(version, qrcode); initializeFunctionModules(version, qrcode);
drawCodewords(tempBuffer, getNumRawDataModules(version) / 8, qrcode); drawCodewords(tempBuffer, getNumRawDataModules(version) / 8, qrcode);
drawWhiteFunctionModules(qrcode, version); drawWhiteFunctionModules(qrcode, version);

@ -124,7 +124,7 @@ QrCode::QrCode(int ver, Ecc ecl, const vector<uint8_t> &dataCodewords, int mask)
// Draw function patterns, draw all codewords, do masking // Draw function patterns, draw all codewords, do masking
drawFunctionPatterns(); drawFunctionPatterns();
const vector<uint8_t> allCodewords = appendErrorCorrection(dataCodewords); const vector<uint8_t> allCodewords = addEccAndInterleave(dataCodewords);
drawCodewords(allCodewords); drawCodewords(allCodewords);
this->mask = handleConstructorMasking(mask); this->mask = handleConstructorMasking(mask);
} }
@ -298,7 +298,7 @@ bool QrCode::module(int x, int y) const {
} }
vector<uint8_t> QrCode::appendErrorCorrection(const vector<uint8_t> &data) const { vector<uint8_t> QrCode::addEccAndInterleave(const vector<uint8_t> &data) const {
if (data.size() != static_cast<unsigned int>(getNumDataCodewords(version, errorCorrectionLevel))) if (data.size() != static_cast<unsigned int>(getNumDataCodewords(version, errorCorrectionLevel)))
throw std::invalid_argument("Invalid argument"); throw std::invalid_argument("Invalid argument");

@ -201,7 +201,7 @@ class QrCode final {
// Returns a new byte string representing the given data with the appropriate error correction // Returns a new byte string representing the given data with the appropriate error correction
// codewords appended to it, based on this object's version and error correction level. // codewords appended to it, based on this object's version and error correction level.
private: std::vector<std::uint8_t> appendErrorCorrection(const std::vector<std::uint8_t> &data) const; private: std::vector<std::uint8_t> addEccAndInterleave(const std::vector<std::uint8_t> &data) const;
// Draws the given sequence of 8-bit codewords (data and error correction) onto the entire // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire

@ -226,7 +226,7 @@ public final class QrCode {
// Draw function patterns, draw all codewords, do masking // Draw function patterns, draw all codewords, do masking
drawFunctionPatterns(); drawFunctionPatterns();
byte[] allCodewords = appendErrorCorrection(dataCodewords); byte[] allCodewords = addEccAndInterleave(dataCodewords);
drawCodewords(allCodewords); drawCodewords(allCodewords);
this.mask = handleConstructorMasking(mask); this.mask = handleConstructorMasking(mask);
} }
@ -437,7 +437,7 @@ public final class QrCode {
// Returns a new byte string representing the given data with the appropriate error correction // Returns a new byte string representing the given data with the appropriate error correction
// codewords appended to it, based on this object's version and error correction level. // codewords appended to it, based on this object's version and error correction level.
private byte[] appendErrorCorrection(byte[] data) { private byte[] addEccAndInterleave(byte[] data) {
if (data.length != getNumDataCodewords(version, errorCorrectionLevel)) if (data.length != getNumDataCodewords(version, errorCorrectionLevel))
throw new IllegalArgumentException(); throw new IllegalArgumentException();

@ -92,7 +92,7 @@ var qrcodegen = new function() {
// Handle grid fields, draw function patterns, draw all codewords // Handle grid fields, draw function patterns, draw all codewords
drawFunctionPatterns(); drawFunctionPatterns();
var allCodewords = appendErrorCorrection(datacodewords); var allCodewords = addEccAndInterleave(datacodewords);
drawCodewords(allCodewords); drawCodewords(allCodewords);
// Handle masking // Handle masking
@ -310,7 +310,7 @@ var qrcodegen = new function() {
// Returns a new byte string representing the given data with the appropriate error correction // Returns a new byte string representing the given data with the appropriate error correction
// codewords appended to it, based on this object's version and error correction level. // codewords appended to it, based on this object's version and error correction level.
function appendErrorCorrection(data) { function addEccAndInterleave(data) {
if (data.length != QrCode.getNumDataCodewords(version, errCorLvl)) if (data.length != QrCode.getNumDataCodewords(version, errCorLvl))
throw "Invalid argument"; throw "Invalid argument";

@ -169,7 +169,7 @@ class QrCode(object):
self._isfunction = [[False] * self._size for _ in range(self._size)] # Indicates function modules that are not subjected to masking self._isfunction = [[False] * self._size for _ in range(self._size)] # Indicates function modules that are not subjected to masking
# Draw function patterns, draw all codewords # Draw function patterns, draw all codewords
self._draw_function_patterns() self._draw_function_patterns()
allcodewords = self._append_error_correction(datacodewords) allcodewords = self._add_ecc_and_interleave(datacodewords)
self._draw_codewords(allcodewords) self._draw_codewords(allcodewords)
# Handle masking # Handle masking
@ -345,7 +345,7 @@ class QrCode(object):
# ---- Private helper methods for constructor: Codewords and masking ---- # ---- Private helper methods for constructor: Codewords and masking ----
def _append_error_correction(self, data): def _add_ecc_and_interleave(self, data):
"""Returns a new byte string representing the given data with the appropriate error correction """Returns a new byte string representing the given data with the appropriate error correction
codewords appended to it, based on this object's version and error correction level.""" codewords appended to it, based on this object's version and error correction level."""
version = self._version version = self._version

@ -182,7 +182,7 @@ impl QrCode {
// Draw function patterns, draw all codewords, do masking // Draw function patterns, draw all codewords, do masking
result.draw_function_patterns(); result.draw_function_patterns();
let allcodewords: Vec<u8> = result.append_error_correction(datacodewords); let allcodewords: Vec<u8> = result.add_ecc_and_interleave(datacodewords);
result.draw_codewords(&allcodewords); result.draw_codewords(&allcodewords);
result.handle_constructor_masking(mask); result.handle_constructor_masking(mask);
result result
@ -403,7 +403,7 @@ impl QrCode {
// Returns a new byte string representing the given data with the appropriate error correction // Returns a new byte string representing the given data with the appropriate error correction
// codewords appended to it, based on this object's version and error correction level. // codewords appended to it, based on this object's version and error correction level.
fn append_error_correction(&self, data: &[u8]) -> Vec<u8> { fn add_ecc_and_interleave(&self, data: &[u8]) -> Vec<u8> {
let ver = self.version; let ver = self.version;
let ecl = self.errorcorrectionlevel; let ecl = self.errorcorrectionlevel;
assert_eq!(data.len(), QrCode::get_num_data_codewords(ver, ecl), "Illegal argument"); assert_eq!(data.len(), QrCode::get_num_data_codewords(ver, ecl), "Illegal argument");

@ -170,7 +170,7 @@ namespace qrcodegen {
// Handle grid fields, draw function patterns, draw all codewords // Handle grid fields, draw function patterns, draw all codewords
this.drawFunctionPatterns(); this.drawFunctionPatterns();
let allCodewords: Array<byte> = this.appendErrorCorrection(datacodewords); let allCodewords: Array<byte> = this.addEccAndInterleave(datacodewords);
this.drawCodewords(allCodewords); this.drawCodewords(allCodewords);
// Handle masking // Handle masking
@ -374,7 +374,7 @@ namespace qrcodegen {
// Returns a new byte string representing the given data with the appropriate error correction // Returns a new byte string representing the given data with the appropriate error correction
// codewords appended to it, based on this object's version and error correction level. // codewords appended to it, based on this object's version and error correction level.
private appendErrorCorrection(data: Array<byte>): Array<byte> { private addEccAndInterleave(data: Array<byte>): Array<byte> {
const ver: int = this.version; const ver: int = this.version;
const ecl: QrCode_Ecc = this.errorCorrectionLevel; const ecl: QrCode_Ecc = this.errorCorrectionLevel;
if (data.length != QrCode.getNumDataCodewords(ver, ecl)) if (data.length != QrCode.getNumDataCodewords(ver, ecl))

Loading…
Cancel
Save