resolved bug in ReedSolomon encoder. Now the encoding tests are successfull but still the images produced can not be decoded. One step closer to #10

This commit is contained in:
favoritas37 2017-04-18 10:21:30 +03:00
parent e3152c2e3e
commit e5770ffaca
4 changed files with 27 additions and 20 deletions

View File

@ -49,8 +49,8 @@ GenericGF::GenericGF(int primitive_, int size_, int b)
} }
void GenericGF::initialize() { void GenericGF::initialize() {
expTable.resize(size); expTable = std::vector<int>(size);
logTable.resize(size); logTable = std::vector<int>(size);
int x = 1; int x = 1;
@ -66,12 +66,14 @@ void GenericGF::initialize() {
logTable[expTable[i]] = i; logTable[expTable[i]] = i;
} }
//logTable[0] == 0 but this should never be used //logTable[0] == 0 but this should never be used
zero = ArrayRef<int> coefficients_zero(1);
Ref<GenericGFPoly>(new GenericGFPoly(Ref<GenericGF>(this), ArrayRef<int>(new Array<int>(1)))); ArrayRef<int> coefficients_one(1);
zero->getCoefficients()[0] = 0;
one = coefficients_zero[0] = 0;
Ref<GenericGFPoly>(new GenericGFPoly(Ref<GenericGF>(this), ArrayRef<int>(new Array<int>(1)))); coefficients_one[0] = 1;
one->getCoefficients()[0] = 1;
zero = Ref<GenericGFPoly>(new GenericGFPoly(this, coefficients_zero));
one = Ref<GenericGFPoly>(new GenericGFPoly(this, coefficients_one));
initialized = true; initialized = true;
} }
@ -100,10 +102,10 @@ Ref<GenericGFPoly> GenericGF::buildMonomial(int degree, int coefficient) {
if (coefficient == 0) { if (coefficient == 0) {
return zero; return zero;
} }
ArrayRef<int> coefficients(new Array<int>(degree + 1)); ArrayRef<int> coefficients(degree + 1);
coefficients[0] = coefficient; coefficients[0] = coefficient;
return Ref<GenericGFPoly>(new GenericGFPoly(Ref<GenericGF>(this), coefficients)); return Ref<GenericGFPoly>(new GenericGFPoly(this, coefficients));
} }
int GenericGF::addOrSubtract(int a, int b) { int GenericGF::addOrSubtract(int a, int b) {

View File

@ -31,7 +31,7 @@ using zxing::Ref;
// VC++ // VC++
using zxing::GenericGF; using zxing::GenericGF;
GenericGFPoly::GenericGFPoly(Ref<GenericGF> field, GenericGFPoly::GenericGFPoly(GenericGF *field,
ArrayRef<int> coefficients) ArrayRef<int> coefficients)
: field_(field) { : field_(field) {
if (coefficients->size() == 0) { if (coefficients->size() == 0) {
@ -96,7 +96,7 @@ int GenericGFPoly::evaluateAt(int a) {
} }
Ref<GenericGFPoly> GenericGFPoly::addOrSubtract(Ref<zxing::GenericGFPoly> other) { Ref<GenericGFPoly> GenericGFPoly::addOrSubtract(Ref<zxing::GenericGFPoly> other) {
if (!(field_.object_ == other->field_.object_)) { if (!(field_ == other->field_)) {
throw IllegalArgumentException("GenericGFPolys do not have same GenericGF field"); throw IllegalArgumentException("GenericGFPolys do not have same GenericGF field");
} }
if (isZero()) { if (isZero()) {
@ -130,7 +130,7 @@ Ref<GenericGFPoly> GenericGFPoly::addOrSubtract(Ref<zxing::GenericGFPoly> other)
} }
Ref<GenericGFPoly> GenericGFPoly::multiply(Ref<zxing::GenericGFPoly> other) { Ref<GenericGFPoly> GenericGFPoly::multiply(Ref<zxing::GenericGFPoly> other) {
if (!(field_.object_ == other->field_.object_)) { if (!(field_ == other->field_)) {
throw IllegalArgumentException("GenericGFPolys do not have same GenericGF field"); throw IllegalArgumentException("GenericGFPolys do not have same GenericGF field");
} }
@ -186,8 +186,8 @@ Ref<GenericGFPoly> GenericGFPoly::multiplyByMonomial(int degree, int coefficient
return Ref<GenericGFPoly>(new GenericGFPoly(field_, product)); return Ref<GenericGFPoly>(new GenericGFPoly(field_, product));
} }
std::vector<Ref<GenericGFPoly> > GenericGFPoly::divide(Ref<GenericGFPoly> other) { std::vector<Ref<GenericGFPoly>> GenericGFPoly::divide(Ref<GenericGFPoly> other) {
if (!(field_.object_ == other->field_.object_)) { if (!(field_ == other->field_)) {
throw IllegalArgumentException("GenericGFPolys do not have same GenericGF field"); throw IllegalArgumentException("GenericGFPolys do not have same GenericGF field");
} }
if (other->isZero()) { if (other->isZero()) {

View File

@ -32,11 +32,11 @@ class GenericGF;
class GenericGFPoly : public Counted { class GenericGFPoly : public Counted {
private: private:
Ref<GenericGF> field_; GenericGF *field_;
ArrayRef<int> coefficients_; ArrayRef<int> coefficients_;
public: public:
GenericGFPoly(Ref<GenericGF> field, ArrayRef<int> coefficients); GenericGFPoly(GenericGF *field, ArrayRef<int> coefficients);
ArrayRef<int> getCoefficients(); ArrayRef<int> getCoefficients();
int getDegree(); int getDegree();
bool isZero(); bool isZero();
@ -46,7 +46,7 @@ public:
Ref<GenericGFPoly> multiply(Ref<GenericGFPoly> other); Ref<GenericGFPoly> multiply(Ref<GenericGFPoly> other);
Ref<GenericGFPoly> multiply(int scalar); Ref<GenericGFPoly> multiply(int scalar);
Ref<GenericGFPoly> multiplyByMonomial(int degree, int coefficient); Ref<GenericGFPoly> multiplyByMonomial(int degree, int coefficient);
std::vector<Ref<GenericGFPoly> > divide(Ref<GenericGFPoly> other); std::vector<Ref<GenericGFPoly>> divide(Ref<GenericGFPoly> other);
}; };

View File

@ -38,7 +38,9 @@ void ReedSolomonEncoder::encode(std::vector<int> &toEncode, int ecBytes)
if (ecBytes == 0) { if (ecBytes == 0) {
throw Exception("No error correction bytes"); throw Exception("No error correction bytes");
} }
int dataBytes = toEncode.size() - ecBytes; //int dataBytes = toEncode.size() - ecBytes;
int dataBytes = toEncode.size();// - ecBytes;
toEncode.resize(toEncode.size()+ecBytes);
if (dataBytes <= 0) { if (dataBytes <= 0) {
throw Exception("No data bytes provided"); throw Exception("No data bytes provided");
} }
@ -64,8 +66,11 @@ void ReedSolomonEncoder::encode(std::vector<int> &toEncode, int ecBytes)
//toEncode.insert(toEncode.begin() + (dataBytes-1) + numZeroCoefficients, //toEncode.insert(toEncode.begin() + (dataBytes-1) + numZeroCoefficients,
// coefficients.array_->values().begin(), // coefficients.array_->values().begin(),
// coefficients.array_->values().end()); // coefficients.array_->values().end());
//toEncode.resize(toEncode.size() + numZeroCoefficients + coefficients->size());
for (size_t i = 0; i < coefficients->size(); i++) for (size_t i = 0; i < coefficients->size(); i++)
toEncode[dataBytes + numZeroCoefficients + i] = coefficients[i]; toEncode[dataBytes + numZeroCoefficients + i] = coefficients[i];
} }
} }