Issue 505

git-svn-id: https://zxing.googlecode.com/svn/trunk@1524 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2010-08-12 20:51:09 +00:00
parent 0a6cac9820
commit 00322f3873
12 changed files with 111 additions and 9 deletions

View file

@ -100,4 +100,12 @@ bool DecodeHints::getTryHarder() const {
return (hints & TRYHARDER_HINT); return (hints & TRYHARDER_HINT);
} }
void DecodeHints::setResultPointCallback(Ref<ResultPointCallback> const& _callback) {
callback = _callback;
}
Ref<ResultPointCallback> DecodeHints::getResultPointCallback() const {
return callback;
}
} /* namespace */ } /* namespace */

View file

@ -20,6 +20,7 @@
*/ */
#include <zxing/BarcodeFormat.h> #include <zxing/BarcodeFormat.h>
#include <zxing/ResultPointCallback.h>
namespace zxing { namespace zxing {
@ -42,6 +43,8 @@ class DecodeHints {
DecodeHintType hints; DecodeHintType hints;
Ref<ResultPointCallback> callback;
public: public:
static const DecodeHints PRODUCT_HINT; static const DecodeHints PRODUCT_HINT;
@ -56,6 +59,9 @@ class DecodeHints {
void setTryHarder(bool toset); void setTryHarder(bool toset);
bool getTryHarder() const; bool getTryHarder() const;
void setResultPointCallback(Ref<ResultPointCallback> const&);
Ref<ResultPointCallback> getResultPointCallback() const;
}; };
} }

View file

@ -20,3 +20,8 @@
#include <zxing/ResultPoint.h> #include <zxing/ResultPoint.h>
namespace zxing {
ResultPoint::~ResultPoint() {}
}

View file

@ -28,6 +28,8 @@ class ResultPoint : public Counted {
protected: protected:
ResultPoint() {} ResultPoint() {}
public: public:
virtual ~ResultPoint();
virtual float getX() const = 0; virtual float getX() const = 0;
virtual float getY() const = 0; virtual float getY() const = 0;
}; };

View file

@ -0,0 +1,27 @@
/*
* ResultPointCallback.cpp
* zxing
*
* Created by Christian Brunschen on 13/05/2008.
* Copyright 2008 ZXing authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <zxing/ResultPointCallback.h>
namespace zxing {
ResultPointCallback::~ResultPointCallback() {}
}

View file

@ -0,0 +1,39 @@
#ifndef __RESULT_POINT_CALLBACK_H__
#define __RESULT_POINT_CALLBACK_H__
/*
* ResultPointCallback.h
* zxing
*
* Copyright 2010 ZXing authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <zxing/common/Counted.h>
namespace zxing {
class ResultPoint;
class ResultPointCallback : public Counted {
protected:
ResultPointCallback() {}
public:
virtual void foundPossibleResultPoint(ResultPoint const& point) = 0;
virtual ~ResultPointCallback();
};
}
#endif // __RESULT_POINT_CALLBACK_H__

View file

@ -112,15 +112,19 @@ Ref<AlignmentPattern> AlignmentPatternFinder::handlePossibleCenter(vector<int> &
// Hadn't found this before; save it // Hadn't found this before; save it
tmp->retain(); tmp->retain();
possibleCenters_->push_back(tmp); possibleCenters_->push_back(tmp);
if (callback_ != 0) {
callback_->foundPossibleResultPoint(*tmp);
}
} }
Ref<AlignmentPattern> result; Ref<AlignmentPattern> result;
return result; return result;
} }
AlignmentPatternFinder::AlignmentPatternFinder(Ref<BitMatrix> image, size_t startX, size_t startY, size_t width, AlignmentPatternFinder::AlignmentPatternFinder(Ref<BitMatrix> image, size_t startX, size_t startY, size_t width,
size_t height, float moduleSize) : size_t height, float moduleSize,
Ref<ResultPointCallback>const& callback) :
image_(image), possibleCenters_(new vector<AlignmentPattern *> ()), startX_(startX), startY_(startY), image_(image), possibleCenters_(new vector<AlignmentPattern *> ()), startX_(startX), startY_(startY),
width_(width), height_(height), moduleSize_(moduleSize) { width_(width), height_(height), moduleSize_(moduleSize), callback_(callback) {
} }
AlignmentPatternFinder::~AlignmentPatternFinder() { AlignmentPatternFinder::~AlignmentPatternFinder() {

View file

@ -23,6 +23,7 @@
#include "AlignmentPattern.h" #include "AlignmentPattern.h"
#include <zxing/common/Counted.h> #include <zxing/common/Counted.h>
#include <zxing/common/BitMatrix.h> #include <zxing/common/BitMatrix.h>
#include <zxing/ResultPointCallback.h>
#include <vector> #include <vector>
namespace zxing { namespace zxing {
@ -51,7 +52,7 @@ private:
public: public:
AlignmentPatternFinder(Ref<BitMatrix> image, size_t startX, size_t startY, size_t width, size_t height, AlignmentPatternFinder(Ref<BitMatrix> image, size_t startX, size_t startY, size_t width, size_t height,
float moduleSize); float moduleSize, Ref<ResultPointCallback>const& callback);
~AlignmentPatternFinder(); ~AlignmentPatternFinder();
Ref<AlignmentPattern> find(); Ref<AlignmentPattern> find();
@ -59,6 +60,7 @@ private:
AlignmentPatternFinder(const AlignmentPatternFinder&); AlignmentPatternFinder(const AlignmentPatternFinder&);
AlignmentPatternFinder& operator =(const AlignmentPatternFinder&); AlignmentPatternFinder& operator =(const AlignmentPatternFinder&);
Ref<ResultPointCallback> callback_;
}; };
} }
} }

View file

@ -44,7 +44,8 @@ Ref<BitMatrix> Detector::getImage() {
} }
Ref<DetectorResult> Detector::detect(DecodeHints const& hints) { Ref<DetectorResult> Detector::detect(DecodeHints const& hints) {
FinderPatternFinder finder(image_); callback_ = hints.getResultPointCallback();
FinderPatternFinder finder(image_, hints.getResultPointCallback());
Ref<FinderPatternInfo> info(finder.find(hints)); Ref<FinderPatternInfo> info(finder.find(hints));
Ref<FinderPattern> topLeft(info->getTopLeft()); Ref<FinderPattern> topLeft(info->getTopLeft());
@ -271,7 +272,7 @@ Ref<AlignmentPattern> Detector::findAlignmentInRegion(float overallEstModuleSize
int alignmentAreaBottomY = min((int)(image_->getHeight() - 1), estAlignmentY + allowance); int alignmentAreaBottomY = min((int)(image_->getHeight() - 1), estAlignmentY + allowance);
AlignmentPatternFinder alignmentFinder(image_, alignmentAreaLeftX, alignmentAreaTopY, alignmentAreaRightX AlignmentPatternFinder alignmentFinder(image_, alignmentAreaLeftX, alignmentAreaTopY, alignmentAreaRightX
- alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize); - alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize, callback_);
return alignmentFinder.find(); return alignmentFinder.find();
} }

View file

@ -25,6 +25,7 @@
#include <zxing/common/BitMatrix.h> #include <zxing/common/BitMatrix.h>
#include <zxing/qrcode/detector/AlignmentPattern.h> #include <zxing/qrcode/detector/AlignmentPattern.h>
#include <zxing/common/PerspectiveTransform.h> #include <zxing/common/PerspectiveTransform.h>
#include <zxing/ResultPointCallback.h>
namespace zxing { namespace zxing {
@ -35,6 +36,7 @@ namespace qrcode {
class Detector : public Counted { class Detector : public Counted {
private: private:
Ref<BitMatrix> image_; Ref<BitMatrix> image_;
Ref<ResultPointCallback> callback_;
protected: protected:
Ref<BitMatrix> getImage(); Ref<BitMatrix> getImage();

View file

@ -236,6 +236,9 @@ bool FinderPatternFinder::handlePossibleCenter(int* stateCount, size_t i, size_t
if (!found) { if (!found) {
Ref<FinderPattern> newPattern(new FinderPattern(centerJ, centerI, estimatedModuleSize)); Ref<FinderPattern> newPattern(new FinderPattern(centerJ, centerI, estimatedModuleSize));
possibleCenters_.push_back(newPattern); possibleCenters_.push_back(newPattern);
if (callback_ != 0) {
callback_->foundPossibleResultPoint(*newPattern);
}
} }
return true; return true;
} }
@ -384,8 +387,9 @@ float FinderPatternFinder::distance(Ref<ResultPoint> p1, Ref<ResultPoint> p2) {
return (float)sqrt(dx * dx + dy * dy); return (float)sqrt(dx * dx + dy * dy);
} }
FinderPatternFinder::FinderPatternFinder(Ref<BitMatrix> image) : FinderPatternFinder::FinderPatternFinder(Ref<BitMatrix> image,
image_(image), possibleCenters_(), hasSkipped_(false) { Ref<ResultPointCallback>const& callback) :
image_(image), possibleCenters_(), hasSkipped_(false), callback_(callback) {
} }
Ref<FinderPatternInfo> FinderPatternFinder::find(DecodeHints const& hints) { Ref<FinderPatternInfo> FinderPatternFinder::find(DecodeHints const& hints) {

View file

@ -24,6 +24,7 @@
#include <zxing/qrcode/detector/FinderPatternInfo.h> #include <zxing/qrcode/detector/FinderPatternInfo.h>
#include <zxing/common/Counted.h> #include <zxing/common/Counted.h>
#include <zxing/common/BitMatrix.h> #include <zxing/common/BitMatrix.h>
#include <zxing/ResultPointCallback.h>
#include <vector> #include <vector>
namespace zxing { namespace zxing {
@ -42,6 +43,8 @@ private:
std::vector<Ref<FinderPattern> > possibleCenters_; std::vector<Ref<FinderPattern> > possibleCenters_;
bool hasSkipped_; bool hasSkipped_;
Ref<ResultPointCallback> callback_;
/** stateCount must be int[5] */ /** stateCount must be int[5] */
static float centerFromEnd(int* stateCount, int end); static float centerFromEnd(int* stateCount, int end);
static bool foundPatternCross(int* stateCount); static bool foundPatternCross(int* stateCount);
@ -55,10 +58,9 @@ private:
bool haveMultiplyConfirmedCenters(); bool haveMultiplyConfirmedCenters();
std::vector<Ref<FinderPattern> > selectBestPatterns(); std::vector<Ref<FinderPattern> > selectBestPatterns();
static std::vector<Ref<FinderPattern> > orderBestPatterns(std::vector<Ref<FinderPattern> > patterns); static std::vector<Ref<FinderPattern> > orderBestPatterns(std::vector<Ref<FinderPattern> > patterns);
public: public:
static float distance(Ref<ResultPoint> p1, Ref<ResultPoint> p2); static float distance(Ref<ResultPoint> p1, Ref<ResultPoint> p2);
FinderPatternFinder(Ref<BitMatrix> image); FinderPatternFinder(Ref<BitMatrix> image, Ref<ResultPointCallback>const&);
Ref<FinderPatternInfo> find(DecodeHints const& hints); Ref<FinderPatternInfo> find(DecodeHints const& hints);
}; };
} }