From: srowen Date: Thu, 12 Aug 2010 20:51:09 +0000 (+0000) Subject: Issue 505 X-Git-Url: http://git.rot13.org/?p=zxing.git;a=commitdiff_plain;h=d59aa5593ed5a911b1141be85d1888088c21e859 Issue 505 git-svn-id: http://zxing.googlecode.com/svn/trunk@1524 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- diff --git a/cpp/core/src/zxing/DecodeHints.cpp b/cpp/core/src/zxing/DecodeHints.cpp index 6947de55..8209f767 100644 --- a/cpp/core/src/zxing/DecodeHints.cpp +++ b/cpp/core/src/zxing/DecodeHints.cpp @@ -100,4 +100,12 @@ bool DecodeHints::getTryHarder() const { return (hints & TRYHARDER_HINT); } +void DecodeHints::setResultPointCallback(Ref const& _callback) { + callback = _callback; +} + +Ref DecodeHints::getResultPointCallback() const { + return callback; +} + } /* namespace */ diff --git a/cpp/core/src/zxing/DecodeHints.h b/cpp/core/src/zxing/DecodeHints.h index 897939dd..f5c27f52 100644 --- a/cpp/core/src/zxing/DecodeHints.h +++ b/cpp/core/src/zxing/DecodeHints.h @@ -20,6 +20,7 @@ */ #include +#include namespace zxing { @@ -42,6 +43,8 @@ class DecodeHints { DecodeHintType hints; + Ref callback; + public: static const DecodeHints PRODUCT_HINT; @@ -56,6 +59,9 @@ class DecodeHints { void setTryHarder(bool toset); bool getTryHarder() const; + void setResultPointCallback(Ref const&); + Ref getResultPointCallback() const; + }; } diff --git a/cpp/core/src/zxing/ResultPoint.cpp b/cpp/core/src/zxing/ResultPoint.cpp index 46495687..96706855 100755 --- a/cpp/core/src/zxing/ResultPoint.cpp +++ b/cpp/core/src/zxing/ResultPoint.cpp @@ -20,3 +20,8 @@ #include +namespace zxing { + +ResultPoint::~ResultPoint() {} + +} diff --git a/cpp/core/src/zxing/ResultPoint.h b/cpp/core/src/zxing/ResultPoint.h index 4ad24e2b..f3e6090c 100644 --- a/cpp/core/src/zxing/ResultPoint.h +++ b/cpp/core/src/zxing/ResultPoint.h @@ -28,6 +28,8 @@ class ResultPoint : public Counted { protected: ResultPoint() {} public: + virtual ~ResultPoint(); + virtual float getX() const = 0; virtual float getY() const = 0; }; diff --git a/cpp/core/src/zxing/ResultPointCallback.cpp b/cpp/core/src/zxing/ResultPointCallback.cpp new file mode 100644 index 00000000..72474c95 --- /dev/null +++ b/cpp/core/src/zxing/ResultPointCallback.cpp @@ -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 + +namespace zxing { + +ResultPointCallback::~ResultPointCallback() {} + +} diff --git a/cpp/core/src/zxing/ResultPointCallback.h b/cpp/core/src/zxing/ResultPointCallback.h new file mode 100644 index 00000000..26876563 --- /dev/null +++ b/cpp/core/src/zxing/ResultPointCallback.h @@ -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 + +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__ diff --git a/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.cpp b/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.cpp index 017e2ee6..1f764918 100644 --- a/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.cpp +++ b/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.cpp @@ -112,15 +112,19 @@ Ref AlignmentPatternFinder::handlePossibleCenter(vector & // Hadn't found this before; save it tmp->retain(); possibleCenters_->push_back(tmp); + if (callback_ != 0) { + callback_->foundPossibleResultPoint(*tmp); + } } Ref result; return result; } AlignmentPatternFinder::AlignmentPatternFinder(Ref image, size_t startX, size_t startY, size_t width, - size_t height, float moduleSize) : + size_t height, float moduleSize, + Refconst& callback) : image_(image), possibleCenters_(new vector ()), startX_(startX), startY_(startY), - width_(width), height_(height), moduleSize_(moduleSize) { + width_(width), height_(height), moduleSize_(moduleSize), callback_(callback) { } AlignmentPatternFinder::~AlignmentPatternFinder() { diff --git a/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.h b/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.h index bfcf1485..dbc7b0ae 100644 --- a/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.h +++ b/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.h @@ -23,6 +23,7 @@ #include "AlignmentPattern.h" #include #include +#include #include namespace zxing { @@ -51,7 +52,7 @@ private: public: AlignmentPatternFinder(Ref image, size_t startX, size_t startY, size_t width, size_t height, - float moduleSize); + float moduleSize, Refconst& callback); ~AlignmentPatternFinder(); Ref find(); @@ -59,6 +60,7 @@ private: AlignmentPatternFinder(const AlignmentPatternFinder&); AlignmentPatternFinder& operator =(const AlignmentPatternFinder&); + Ref callback_; }; } } diff --git a/cpp/core/src/zxing/qrcode/detector/Detector.cpp b/cpp/core/src/zxing/qrcode/detector/Detector.cpp index eef30954..bba077f9 100644 --- a/cpp/core/src/zxing/qrcode/detector/Detector.cpp +++ b/cpp/core/src/zxing/qrcode/detector/Detector.cpp @@ -44,7 +44,8 @@ Ref Detector::getImage() { } Ref Detector::detect(DecodeHints const& hints) { - FinderPatternFinder finder(image_); + callback_ = hints.getResultPointCallback(); + FinderPatternFinder finder(image_, hints.getResultPointCallback()); Ref info(finder.find(hints)); Ref topLeft(info->getTopLeft()); @@ -271,7 +272,7 @@ Ref Detector::findAlignmentInRegion(float overallEstModuleSize int alignmentAreaBottomY = min((int)(image_->getHeight() - 1), estAlignmentY + allowance); AlignmentPatternFinder alignmentFinder(image_, alignmentAreaLeftX, alignmentAreaTopY, alignmentAreaRightX - - alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize); + - alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize, callback_); return alignmentFinder.find(); } diff --git a/cpp/core/src/zxing/qrcode/detector/Detector.h b/cpp/core/src/zxing/qrcode/detector/Detector.h index e63aac19..6ec30527 100644 --- a/cpp/core/src/zxing/qrcode/detector/Detector.h +++ b/cpp/core/src/zxing/qrcode/detector/Detector.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace zxing { @@ -35,6 +36,7 @@ namespace qrcode { class Detector : public Counted { private: Ref image_; + Ref callback_; protected: Ref getImage(); diff --git a/cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.cpp b/cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.cpp index fa02af3c..52cd1cc1 100644 --- a/cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.cpp +++ b/cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.cpp @@ -236,6 +236,9 @@ bool FinderPatternFinder::handlePossibleCenter(int* stateCount, size_t i, size_t if (!found) { Ref newPattern(new FinderPattern(centerJ, centerI, estimatedModuleSize)); possibleCenters_.push_back(newPattern); + if (callback_ != 0) { + callback_->foundPossibleResultPoint(*newPattern); + } } return true; } @@ -384,8 +387,9 @@ float FinderPatternFinder::distance(Ref p1, Ref p2) { return (float)sqrt(dx * dx + dy * dy); } -FinderPatternFinder::FinderPatternFinder(Ref image) : - image_(image), possibleCenters_(), hasSkipped_(false) { +FinderPatternFinder::FinderPatternFinder(Ref image, + Refconst& callback) : + image_(image), possibleCenters_(), hasSkipped_(false), callback_(callback) { } Ref FinderPatternFinder::find(DecodeHints const& hints) { diff --git a/cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.h b/cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.h index ac8489ea..6c8684d5 100644 --- a/cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.h +++ b/cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.h @@ -24,6 +24,7 @@ #include #include #include +#include #include namespace zxing { @@ -42,6 +43,8 @@ private: std::vector > possibleCenters_; bool hasSkipped_; + Ref callback_; + /** stateCount must be int[5] */ static float centerFromEnd(int* stateCount, int end); static bool foundPatternCross(int* stateCount); @@ -55,10 +58,9 @@ private: bool haveMultiplyConfirmedCenters(); std::vector > selectBestPatterns(); static std::vector > orderBestPatterns(std::vector > patterns); - public: static float distance(Ref p1, Ref p2); - FinderPatternFinder(Ref image); + FinderPatternFinder(Ref image, Refconst&); Ref find(DecodeHints const& hints); }; }