port r1875 to C++

git-svn-id: https://zxing.googlecode.com/svn/trunk@1959 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
smparkes@smparkes.net 2011-10-12 16:41:57 +00:00
parent d2ed7976ef
commit b72031d6e8
6 changed files with 51 additions and 9 deletions

View file

@ -1,3 +1,4 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
/*
* AlignmentPattern.cpp
* zxing
@ -38,8 +39,20 @@ float AlignmentPattern::getY() const {
}
bool AlignmentPattern::aboutEquals(float moduleSize, float i, float j) const {
return abs(i - posY_) <= moduleSize && abs(j - posX_) <= moduleSize && (abs(moduleSize - estimatedModuleSize_)
<= 1.0f || abs(moduleSize - estimatedModuleSize_) / estimatedModuleSize_ <= 0.1f);
if (abs(i - getY()) <= moduleSize && abs(j - getX()) <= moduleSize) {
float moduleSizeDiff = abs(moduleSize - estimatedModuleSize_);
return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize_;
}
return false;
}
Ref<AlignmentPattern> AlignmentPattern::combineEstimate(float i, float j, float newModuleSize) const {
float combinedX = (getX() + j) / 2.0f;
float combinedY = (getY() + i) / 2.0f;
float combinedModuleSize = (estimatedModuleSize_ + newModuleSize) / 2.0f;
Ref<AlignmentPattern> result
(new AlignmentPattern(combinedX, combinedY, combinedModuleSize));
return result;
}
}

View file

@ -1,3 +1,5 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
#ifndef __ALIGNMENT_PATTERN_H__
#define __ALIGNMENT_PATTERN_H__
@ -37,6 +39,8 @@ namespace zxing {
float getX() const;
float getY() const;
bool aboutEquals(float moduleSize, float i, float j) const;
Ref<AlignmentPattern> combineEstimate(float i, float j,
float newModuleSize) const;
};
}

View file

@ -1,3 +1,4 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
/*
* AlignmentPatternFinder.cpp
* zxing
@ -104,8 +105,7 @@ Ref<AlignmentPattern> AlignmentPatternFinder::handlePossibleCenter(vector<int> &
Ref<AlignmentPattern> center((*possibleCenters_)[index]);
// Look for about the same center and module size:
if (center->aboutEquals(estimatedModuleSize, centerI, centerJ)) {
Ref<AlignmentPattern> result(new AlignmentPattern(centerJ, centerI, estimatedModuleSize));
return result;
return center->combineEstimate(centerI, centerJ, estimatedModuleSize);
}
}
AlignmentPattern *tmp = new AlignmentPattern(centerJ, centerI, estimatedModuleSize);

View file

@ -1,3 +1,4 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
/*
* FinderPattern.cpp
* zxing
@ -26,7 +27,11 @@ namespace zxing {
using namespace std;
FinderPattern::FinderPattern(float posX, float posY, float estimatedModuleSize) :
posX_(posX), posY_(posY), estimatedModuleSize_(estimatedModuleSize), counter_(1) {
posX_(posX), posY_(posY), estimatedModuleSize_(estimatedModuleSize), count_(1) {
}
FinderPattern::FinderPattern(float posX, float posY, float estimatedModuleSize, int count) :
posX_(posX), posY_(posY), estimatedModuleSize_(estimatedModuleSize), count_(count) {
}
float FinderPattern::getX() const {
@ -38,7 +43,7 @@ namespace zxing {
}
int FinderPattern::getCount() const {
return counter_;
return count_;
}
float FinderPattern::getEstimatedModuleSize() const {
@ -46,13 +51,29 @@ namespace zxing {
}
void FinderPattern::incrementCount() {
counter_++;
count_++;
}
/*
bool FinderPattern::aboutEquals(float moduleSize, float i, float j) const {
return abs(i - posY_) <= moduleSize && abs(j - posX_) <= moduleSize && (abs(moduleSize - estimatedModuleSize_)
<= 1.0f || abs(moduleSize - estimatedModuleSize_) / estimatedModuleSize_ <= 0.1f);
}
*/
bool FinderPattern::aboutEquals(float moduleSize, float i, float j) const {
if (abs(i - getY()) <= moduleSize && abs(j - getX()) <= moduleSize) {
float moduleSizeDiff = abs(moduleSize - estimatedModuleSize_);
return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize_;
}
return false;
}
Ref<FinderPattern> FinderPattern::combineEstimate(float i, float j, float newModuleSize) const {
int combinedCount = count_ + 1;
float combinedX = (count_ * getX() + j) / combinedCount;
float combinedY = (count_ * getY() + i) / combinedCount;
float combinedModuleSize = (count_ * getEstimatedModuleSize() + newModuleSize) / combinedCount;
return Ref<FinderPattern>(new FinderPattern(combinedX, combinedY, combinedModuleSize, combinedCount));
}
}
}

View file

@ -1,3 +1,4 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
#ifndef __FINDER_PATTERN_H__
#define __FINDER_PATTERN_H__
@ -31,16 +32,18 @@ namespace zxing {
float posX_;
float posY_;
float estimatedModuleSize_;
int counter_;
int count_;
public:
FinderPattern(float posX, float posY, float estimatedModuleSize);
FinderPattern(float posX, float posY, float estimatedModuleSize, int count);
float getX() const;
float getY() const;
int getCount() const;
float getEstimatedModuleSize() const;
void incrementCount();
bool aboutEquals(float moduleSize, float i, float j) const;
Ref<FinderPattern> combineEstimate(float i, float j, float newModuleSize) const;
};
}
}

View file

@ -1,3 +1,4 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
/*
* FinderPatternFinder.cpp
* zxing
@ -236,7 +237,7 @@ bool FinderPatternFinder::handlePossibleCenter(int* stateCount, size_t i, size_t
Ref<FinderPattern> center = possibleCenters_[index];
// Look for about the same center and module size:
if (center->aboutEquals(estimatedModuleSize, centerI, centerJ)) {
center->incrementCount();
possibleCenters_[index] = center->combineEstimate(centerI, centerJ, estimatedModuleSize);
found = true;
break;
}