Added local variable to appendErrorCorrection() in {Java, C++, JavaScript, Python} language versions to reduce code repetition and synchronize with C version.
This commit is contained in:
parent
a712ccc230
commit
17e0155500
|
@ -311,8 +311,9 @@ vector<uint8_t> QrCode::appendErrorCorrection(const vector<uint8_t> &data) const
|
|||
// Calculate parameter numbers
|
||||
int numBlocks = NUM_ERROR_CORRECTION_BLOCKS[errorCorrectionLevel.ordinal][version];
|
||||
int blockEccLen = ECC_CODEWORDS_PER_BLOCK[errorCorrectionLevel.ordinal][version];
|
||||
int numShortBlocks = numBlocks - getNumRawDataModules(version) / 8 % numBlocks;
|
||||
int shortBlockLen = getNumRawDataModules(version) / 8 / numBlocks;
|
||||
int rawCodewords = getNumRawDataModules(version) / 8;
|
||||
int numShortBlocks = numBlocks - rawCodewords % numBlocks;
|
||||
int shortBlockLen = rawCodewords / numBlocks;
|
||||
|
||||
// Split data into blocks and append ECC to each block
|
||||
vector<vector<uint8_t> > blocks;
|
||||
|
@ -337,7 +338,7 @@ vector<uint8_t> QrCode::appendErrorCorrection(const vector<uint8_t> &data) const
|
|||
result.push_back(blocks.at(j).at(i));
|
||||
}
|
||||
}
|
||||
if (result.size() != static_cast<unsigned int>(getNumRawDataModules(version) / 8))
|
||||
if (result.size() != static_cast<unsigned int>(rawCodewords))
|
||||
throw "Assertion error";
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -458,8 +458,9 @@ public final class QrCode {
|
|||
// Calculate parameter numbers
|
||||
int numBlocks = NUM_ERROR_CORRECTION_BLOCKS[errorCorrectionLevel.ordinal()][version];
|
||||
int blockEccLen = ECC_CODEWORDS_PER_BLOCK[errorCorrectionLevel.ordinal()][version];
|
||||
int numShortBlocks = numBlocks - getNumRawDataModules(version) / 8 % numBlocks;
|
||||
int shortBlockLen = getNumRawDataModules(version) / 8 / numBlocks;
|
||||
int rawCodewords = getNumRawDataModules(version) / 8;
|
||||
int numShortBlocks = numBlocks - rawCodewords % numBlocks;
|
||||
int shortBlockLen = rawCodewords / numBlocks;
|
||||
|
||||
// Split data into blocks and append ECC to each block
|
||||
byte[][] blocks = new byte[numBlocks][];
|
||||
|
@ -474,7 +475,7 @@ public final class QrCode {
|
|||
}
|
||||
|
||||
// Interleave (not concatenate) the bytes from every block into a single sequence
|
||||
byte[] result = new byte[getNumRawDataModules(version) / 8];
|
||||
byte[] result = new byte[rawCodewords];
|
||||
for (int i = 0, k = 0; i < blocks[0].length; i++) {
|
||||
for (int j = 0; j < blocks.length; j++) {
|
||||
// Skip the padding byte in short blocks
|
||||
|
|
|
@ -358,8 +358,9 @@ var qrcodegen = new function() {
|
|||
// Calculate parameter numbers
|
||||
var numBlocks = QrCode.NUM_ERROR_CORRECTION_BLOCKS[errCorLvl.ordinal][version];
|
||||
var blockEccLen = QrCode.ECC_CODEWORDS_PER_BLOCK[errCorLvl.ordinal][version];
|
||||
var numShortBlocks = numBlocks - Math.floor(QrCode.getNumRawDataModules(version) / 8) % numBlocks;
|
||||
var shortBlockLen = Math.floor(QrCode.getNumRawDataModules(version) / (numBlocks * 8));
|
||||
var rawCodewords = Math.floor(QrCode.getNumRawDataModules(version) / 8);
|
||||
var numShortBlocks = numBlocks - rawCodewords % numBlocks;
|
||||
var shortBlockLen = Math.floor(rawCodewords / numBlocks);
|
||||
|
||||
// Split data into blocks and append ECC to each block
|
||||
var blocks = [];
|
||||
|
@ -385,7 +386,7 @@ var qrcodegen = new function() {
|
|||
result.push(blocks[j][i]);
|
||||
}
|
||||
}
|
||||
if (result.length != Math.floor(QrCode.getNumRawDataModules(version) / 8))
|
||||
if (result.length != rawCodewords)
|
||||
throw "Assertion error";
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -362,8 +362,9 @@ class QrCode(object):
|
|||
# Calculate parameter numbers
|
||||
numblocks = QrCode._NUM_ERROR_CORRECTION_BLOCKS[self._errcorlvl.ordinal][version]
|
||||
blockecclen = QrCode._ECC_CODEWORDS_PER_BLOCK[self._errcorlvl.ordinal][version]
|
||||
numshortblocks = numblocks - QrCode._get_num_raw_data_modules(version) // 8 % numblocks
|
||||
shortblocklen = self._get_num_raw_data_modules(version) // 8 // numblocks
|
||||
rawcodewords = QrCode._get_num_raw_data_modules(version) // 8
|
||||
numshortblocks = numblocks - rawcodewords % numblocks
|
||||
shortblocklen = rawcodewords // numblocks
|
||||
|
||||
# Split data into blocks and append ECC to each block
|
||||
blocks = []
|
||||
|
@ -386,7 +387,7 @@ class QrCode(object):
|
|||
# Skip the padding byte in short blocks
|
||||
if i != shortblocklen - blockecclen or j >= numshortblocks:
|
||||
result.append(blk[i])
|
||||
assert len(result) == QrCode._get_num_raw_data_modules(version) // 8
|
||||
assert len(result) == rawcodewords
|
||||
return result
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue