First time that all written tests for Qr Encoding are succeeding. #10

Still the Qr code that is generated is not recognizable
This commit is contained in:
favoritas37 2017-04-19 20:27:58 +03:00
parent ae144f213d
commit 94de33f4f5
4 changed files with 8 additions and 20 deletions

View File

@ -38,7 +38,7 @@ void ReedSolomonEncoder::encode(std::vector<byte> &toEncode, int ecBytes)
if (ecBytes == 0) {
throw Exception("No error correction bytes");
}
//int dataBytes = toEncode.size() - ecBytes;
int dataBytes = toEncode.size();// - ecBytes;
toEncode.resize(toEncode.size()+ecBytes);
if (dataBytes <= 0) {
@ -46,7 +46,7 @@ void ReedSolomonEncoder::encode(std::vector<byte> &toEncode, int ecBytes)
}
Ref<GenericGFPoly> generator = buildGenerator(ecBytes);
ArrayRef<int> infoCoefficients(dataBytes);
//memcpy(infoCoefficients.operator ->(), toEncode.data(), dataBytes);
//to-do optimize the following loop
for(int i=0; i< dataBytes; i++)
infoCoefficients[i] = toEncode[i];
@ -60,15 +60,6 @@ void ReedSolomonEncoder::encode(std::vector<byte> &toEncode, int ecBytes)
toEncode[dataBytes + i] = 0;
}
//original kept for future checks
//System.arraycopy(coefficients, 0, toEncode, dataBytes + numZeroCoefficients, coefficients.length);
//toEncode.insert(toEncode.begin() + (dataBytes-1) + numZeroCoefficients,
// coefficients.array_->values().begin(),
// coefficients.array_->values().end());
//toEncode.resize(toEncode.size() + numZeroCoefficients + coefficients->size());
for (size_t i = 0; i < coefficients->size(); i++)
toEncode[dataBytes + numZeroCoefficients + i] = coefficients[i];
}

View File

@ -77,7 +77,7 @@ protected:
int numDataBytes,
int numRSBlocks);
static ArrayRef<byte> generateECBytes(std::vector<byte> &dataBytes, int numEcBytesInBlock);
static ArrayRef<byte> generateECBytes(const std::vector<byte> &dataBytes, int numEcBytesInBlock);
static void appendNumericBytes(const QString& content, BitArray& bits);

View File

@ -423,20 +423,17 @@ BitArray* Encoder::interleaveWithECBytes(const BitArray& bits,
return result;
}
ArrayRef<byte> Encoder::generateECBytes(std::vector<byte>& dataBytes, int numEcBytesInBlock)
ArrayRef<byte> Encoder::generateECBytes(const std::vector<byte>& dataBytes, int numEcBytesInBlock)
{
int numDataBytes = dataBytes.size();
// std::vector<int> toEncode(numDataBytes);
//toEncode.resize(numDataBytes + numEcBytesInBlock);
// for (int i = 0; i < numDataBytes; i++)
// toEncode[i] = dataBytes[i];
std::vector<byte> dataBytesCopy(dataBytes);
zxing::ReedSolomonEncoder encoder(GenericGF::QR_CODE_FIELD_256);
encoder.encode(dataBytes, numEcBytesInBlock);
encoder.encode(dataBytesCopy, numEcBytesInBlock);
ArrayRef<byte> ecBytes(numEcBytesInBlock);
for (int i = 0; i < numEcBytesInBlock; i++) {
ecBytes[i] = dataBytes[numDataBytes + i];
ecBytes[i] = dataBytesCopy[numDataBytes + i];
}
return ecBytes;
}

View File

@ -364,7 +364,7 @@ void EncoderTests::testGenerateECBytes()
const byte expected[] = {
42, 159, 74, 221, 244, 169, 239, 150, 138, 70, 237, 85, 224, 96, 74, 219, 61
};
assertEquals( getArrayLength(expected), ecBytes.count());
assertEquals( getArrayLength(expected), ecBytes->size());
for (int x = 0; x < getArrayLength(expected); x++) {
assertEquals(expected[x], ecBytes[x]);
}