mirror of
https://github.com/status-im/qzxing.git
synced 2025-01-11 19:44:36 +00:00
bug fixing in QR encoder. Still not functional
This commit is contained in:
parent
95a2e44571
commit
45aa03fdca
@ -291,10 +291,10 @@ QImage QZXing::encodeData(const QString& data)
|
||||
Ref<qrcode::QRCode> barcode = qrcode::Encoder::encode(data, qrcode::ErrorCorrectionLevel::L );
|
||||
Ref<qrcode::ByteMatrix> bytesRef = barcode->getMatrix();
|
||||
const std::vector< std::vector <char> >& bytes = bytesRef->getArray();
|
||||
QImage image;
|
||||
for(int i=0; i<bytesRef->getWidth(); ++i)
|
||||
for(int j=0; j<bytesRef->getHeight(); ++i)
|
||||
image.setPixel(i,j,bytes[i][j]);
|
||||
QImage image(bytesRef->getWidth(), bytesRef->getHeight(), QImage::Format_ARGB32);
|
||||
for(int i=0; i<bytesRef->getWidth(); i++)
|
||||
for(int j=0; j<bytesRef->getHeight(); j++)
|
||||
image.setPixel(i,j,bytes[i][j] ? 0 : 255);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,12 @@ BitArray::~BitArray() {
|
||||
}
|
||||
|
||||
int BitArray::getSize() const {
|
||||
return bits->size();
|
||||
return size;
|
||||
}
|
||||
|
||||
int BitArray::getSizeInBytes() const
|
||||
{
|
||||
return (size + 7)/8;\
|
||||
}
|
||||
|
||||
void BitArray::setBulk(int i, int newBits) {
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
BitArray(int size);
|
||||
~BitArray();
|
||||
int getSize() const;
|
||||
int getSizeInBytes() const;
|
||||
|
||||
bool get(int i) const {
|
||||
return (bits[i >> logBits] & (1 << (i & bitsMask))) != 0;
|
||||
|
@ -212,7 +212,7 @@ std::vector<Ref<GenericGFPoly> > GenericGFPoly::divide(Ref<GenericGFPoly> other)
|
||||
}
|
||||
|
||||
std::vector<Ref<GenericGFPoly> > returnValue;
|
||||
returnValue[0] = quotient;
|
||||
returnValue[1] = remainder;
|
||||
returnValue.push_back(quotient);
|
||||
returnValue.push_back(remainder);
|
||||
return returnValue;
|
||||
}
|
||||
|
@ -44,7 +44,11 @@ void ReedSolomonEncoder::encode(std::vector<int> &toEncode, int ecBytes)
|
||||
}
|
||||
Ref<GenericGFPoly> generator = buildGenerator(ecBytes);
|
||||
ArrayRef<int> infoCoefficients(dataBytes);
|
||||
memcpy(infoCoefficients.operator ->(), toEncode.data(), dataBytes);
|
||||
//memcpy(infoCoefficients.operator ->(), toEncode.data(), dataBytes);
|
||||
//to-do optimize the following loop
|
||||
for(int i=0; i< dataBytes; ++i)
|
||||
infoCoefficients[i] = toEncode[i];
|
||||
|
||||
Ref<GenericGFPoly> info(new GenericGFPoly(field_, infoCoefficients));
|
||||
info = info->multiplyByMonomial(ecBytes, 1);
|
||||
Ref<GenericGFPoly> remainder = info->divide(generator)[1];
|
||||
|
@ -8,7 +8,7 @@ ByteMatrix::ByteMatrix(size_t width, size_t height) :
|
||||
width_(width), height_(height)
|
||||
{
|
||||
bytes_.resize(height_);
|
||||
for(size_t i=0; i<height; ++i)
|
||||
for(size_t i=0; i<height; i++)
|
||||
bytes_[i].resize(width);
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ Ref<QRCode> Encoder::encode(const QString& content, ErrorCorrectionLevel &ecLeve
|
||||
BitArray headerAndDataBits;
|
||||
headerAndDataBits.appendBitArray(headerBits);
|
||||
// Find "length" of main segment and write it
|
||||
int numLetters = (*mode == Mode::BYTE) ? dataBits.getSize() : content.length();
|
||||
int numLetters = (*mode == Mode::BYTE) ? dataBits.getSizeInBytes() : content.length();
|
||||
appendLengthInfo(numLetters, *version, *mode, headerAndDataBits);
|
||||
// Put data together into the overall payload
|
||||
headerAndDataBits.appendBitArray(dataBits);
|
||||
@ -256,14 +256,15 @@ void Encoder::terminateBits(int numDataBytes, BitArray& bits)
|
||||
}
|
||||
// Append termination bits. See 8.4.8 of JISX0510:2004 (p.24) for details.
|
||||
// If the last byte isn't 8-bit aligned, we'll add padding bits.
|
||||
int numBitsInLastByte = bits.getSize() & 0x07;
|
||||
int numBitsInLastByte = bits.getSize() % 8;
|
||||
if (numBitsInLastByte > 0) {
|
||||
for (int i = numBitsInLastByte; i < 8; i++) {
|
||||
bits.appendBit(false);
|
||||
}
|
||||
}
|
||||
// If we have more space, we'll fill the space with padding patterns defined in 8.4.9 (p.24).
|
||||
int numPaddingBytes = numDataBytes - bits.getSize();//bits.getSizeInBytes();
|
||||
int bitSizeInBytes = bits.getSizeInBytes();
|
||||
int numPaddingBytes = numDataBytes - bitSizeInBytes;
|
||||
for (int i = 0; i < numPaddingBytes; ++i) {
|
||||
bits.appendBits((i & 0x01) == 0 ? 0xEC : 0x11, 8);
|
||||
}
|
||||
@ -347,7 +348,7 @@ BitArray* Encoder::interleaveWithECBytes(const BitArray& bits,
|
||||
{
|
||||
|
||||
// "bits" must have "getNumDataBytes" bytes of data.
|
||||
if (bits.getSize() != numDataBytes)
|
||||
if (bits.getSizeInBytes() != numDataBytes)
|
||||
throw new WriterException("Number of bits and data bytes does not match");
|
||||
|
||||
// Step 1. Divide data bytes into blocks and generate error correction bytes for them. We'll
|
||||
@ -401,11 +402,11 @@ BitArray* Encoder::interleaveWithECBytes(const BitArray& bits,
|
||||
}
|
||||
}
|
||||
}
|
||||
if (numTotalBytes != result->getSize()) { // Should be same.
|
||||
if (numTotalBytes != result->getSizeInBytes()) { // Should be same.
|
||||
QString message("Interleaving error: ");
|
||||
message += QString::number(numTotalBytes);
|
||||
message += " and ";
|
||||
message += QString(result->getSize());
|
||||
message += QString(result->getSizeInBytes());
|
||||
message += " differ.";
|
||||
throw new WriterException(message.toStdString().c_str());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user