move forward to aligning the ECBlocks in the QR Version with the implemenation of Java. Also, used Ref where appropriate to avoid data copying.

This commit is contained in:
favoritas37 2015-06-18 23:52:52 +03:00
parent 84d3f773ba
commit 4ccc725f0b
2 changed files with 27 additions and 20 deletions

View File

@ -43,17 +43,23 @@ int ECB::getDataCodewords() {
return dataCodewords_; return dataCodewords_;
} }
ECBlocks::ECBlocks(int ecCodewords, ECB *ecBlocks) : ECBlocks::ECBlocks(int ecCodewordsPerBloc, ECB *ecBlocks) :
ecCodewords_(ecCodewords), ecBlocks_(1, ecBlocks) { ecCodewordsPerBloc_(ecCodewordsPerBloc), ecBlocks_(1, ecBlocks) {
} }
ECBlocks::ECBlocks(int ecCodewords, ECB *ecBlocks1, ECB *ecBlocks2) : ECBlocks::ECBlocks(int ecCodewordsPerBloc, ECB *ecBlocks1, ECB *ecBlocks2) :
ecCodewords_(ecCodewords), ecBlocks_(1, ecBlocks1) { ecCodewordsPerBloc_(ecCodewordsPerBloc), ecBlocks_(1, ecBlocks1) {
ecBlocks_.push_back(ecBlocks2); ecBlocks_.push_back(ecBlocks2);
} }
int ECBlocks::getECCodewords() { int ECBlocks::getECCodewordsPerBloc()
return ecCodewords_; {
return ecCodewordsPerBloc_;
}
int ECBlocks::getTotalECCodewords()
{
return ecBlocks_.size();
} }
std::vector<ECB*>& ECBlocks::getECBlocks() { std::vector<ECB*>& ECBlocks::getECBlocks() {
@ -91,11 +97,11 @@ int Version::getDimensionForVersion() {
return 17 + 4 * versionNumber_; return 17 + 4 * versionNumber_;
} }
ECBlocks& Version::getECBlocksForLevel(ErrorCorrectionLevel &ecLevel) { ECBlocks& Version::getECBlocksForLevel(const ErrorCorrectionLevel &ecLevel) const {
return *ecBlocks_[ecLevel.ordinal()]; return *ecBlocks_[ecLevel.ordinal()];
} }
Version *Version::getProvisionalVersionForDimension(int dimension) { Ref<Version> Version::getProvisionalVersionForDimension(int dimension) {
if (dimension % 4 != 1) { if (dimension % 4 != 1) {
throw FormatException(); throw FormatException();
} }
@ -107,7 +113,7 @@ Version *Version::getProvisionalVersionForDimension(int dimension) {
} }
} }
Version *Version::getVersionForNumber(int versionNumber) { Ref<Version> Version::getVersionForNumber(int versionNumber) {
if (versionNumber < 1 || versionNumber > N_VERSIONS) { if (versionNumber < 1 || versionNumber > N_VERSIONS) {
throw ReaderException("versionNumber must be between 1 and 40"); throw ReaderException("versionNumber must be between 1 and 40");
} }
@ -124,7 +130,7 @@ Version::Version(int versionNumber, vector<int> *alignmentPatternCenters, ECBloc
ecBlocks_[3] = ecBlocks4; ecBlocks_[3] = ecBlocks4;
int total = 0; int total = 0;
int ecCodewords = ecBlocks1->getECCodewords(); int ecCodewords = ecBlocks1->getECCodewordsPerBloc();
vector<ECB*> &ecbArray = ecBlocks1->getECBlocks(); vector<ECB*> &ecbArray = ecBlocks1->getECBlocks();
for (size_t i = 0; i < ecbArray.size(); i++) { for (size_t i = 0; i < ecbArray.size(); i++) {
ECB *ecBlock = ecbArray[i]; ECB *ecBlock = ecbArray[i];
@ -140,7 +146,7 @@ Version::~Version() {
} }
} }
Version *Version::decodeVersionInformation(unsigned int versionBits) { Ref<Version> Version::decodeVersionInformation(unsigned int versionBits) {
int bestDifference = numeric_limits<int>::max(); int bestDifference = numeric_limits<int>::max();
size_t bestVersion = 0; size_t bestVersion = 0;
for (int i = 0; i < N_VERSION_DECODE_INFOS; i++) { for (int i = 0; i < N_VERSION_DECODE_INFOS; i++) {
@ -163,7 +169,7 @@ Version *Version::decodeVersionInformation(unsigned int versionBits) {
return getVersionForNumber(bestVersion); return getVersionForNumber(bestVersion);
} }
// If we didn't find a close enough match, fail // If we didn't find a close enough match, fail
return 0; return Ref<Version>(NULL);
} }
Ref<BitMatrix> Version::buildFunctionPattern() { Ref<BitMatrix> Version::buildFunctionPattern() {

View File

@ -42,12 +42,13 @@ public:
class ECBlocks { class ECBlocks {
private: private:
int ecCodewords_; int ecCodewordsPerBloc_;
std::vector<ECB*> ecBlocks_; std::vector<ECB*> ecBlocks_;
public: public:
ECBlocks(int ecCodewords, ECB *ecBlocks); ECBlocks(int ecCodewordsPerBloc, ECB *ecBlocks);
ECBlocks(int ecCodewords, ECB *ecBlocks1, ECB *ecBlocks2); ECBlocks(int ecCodewordsPerBloc, ECB *ecBlocks1, ECB *ecBlocks2);
int getECCodewords(); int getECCodewordsPerBloc();
int getTotalECCodewords();
std::vector<ECB*>& getECBlocks(); std::vector<ECB*>& getECBlocks();
~ECBlocks(); ~ECBlocks();
}; };
@ -72,10 +73,10 @@ public:
std::vector<int> &getAlignmentPatternCenters(); std::vector<int> &getAlignmentPatternCenters();
int getTotalCodewords(); int getTotalCodewords();
int getDimensionForVersion(); int getDimensionForVersion();
ECBlocks &getECBlocksForLevel(ErrorCorrectionLevel &ecLevel); ECBlocks &getECBlocksForLevel(const ErrorCorrectionLevel &ecLevel) const;
static Version *getProvisionalVersionForDimension(int dimension); static Ref<Version> getProvisionalVersionForDimension(int dimension);
static Version *getVersionForNumber(int versionNumber); static Ref<Version> getVersionForNumber(int versionNumber);
static Version *decodeVersionInformation(unsigned int versionBits); static Ref<Version> decodeVersionInformation(unsigned int versionBits);
Ref<BitMatrix> buildFunctionPattern(); Ref<BitMatrix> buildFunctionPattern();
static int buildVersions(); static int buildVersions();
}; };