From 8e609df96ee1f646f6cafb8a105eab1ee8c79fb4 Mon Sep 17 00:00:00 2001 From: "smparkes@smparkes.net" Date: Sat, 6 Apr 2013 20:19:19 +0000 Subject: [PATCH] c++ port of r2585 git-svn-id: https://zxing.googlecode.com/svn/trunk@2625 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../multi/GenericMultipleBarcodeReader.cpp | 44 ++++++++++--------- .../multi/GenericMultipleBarcodeReader.h | 42 ++++++++++-------- 2 files changed, 47 insertions(+), 39 deletions(-) diff --git a/cpp/core/src/zxing/multi/GenericMultipleBarcodeReader.cpp b/cpp/core/src/zxing/multi/GenericMultipleBarcodeReader.cpp index 5a24aaabf..2ce3c3a60 100644 --- a/cpp/core/src/zxing/multi/GenericMultipleBarcodeReader.cpp +++ b/cpp/core/src/zxing/multi/GenericMultipleBarcodeReader.cpp @@ -1,3 +1,4 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Copyright 2011 ZXing authors All rights reserved. * @@ -18,20 +19,20 @@ #include #include -namespace zxing { -namespace multi { -GenericMultipleBarcodeReader::GenericMultipleBarcodeReader(Reader& delegate) : - delegate_(delegate) -{ -} +using std::vector; +using zxing::Ref; +using zxing::Result; +using zxing::multi::GenericMultipleBarcodeReader; + +GenericMultipleBarcodeReader::GenericMultipleBarcodeReader(Reader& delegate) + : delegate_(delegate) {} GenericMultipleBarcodeReader::~GenericMultipleBarcodeReader(){} -std::vector > GenericMultipleBarcodeReader::decodeMultiple( - Ref image, DecodeHints hints) -{ - std::vector > results; - doDecodeMultiple(image, hints, results, 0, 0); +vector > GenericMultipleBarcodeReader::decodeMultiple(Ref image, + DecodeHints hints) { + vector > results; + doDecodeMultiple(image, hints, results, 0, 0, 0); if (results.empty()){ throw ReaderException("No code detected"); } @@ -39,8 +40,14 @@ std::vector > GenericMultipleBarcodeReader::decodeMultiple( } void GenericMultipleBarcodeReader::doDecodeMultiple(Ref image, - DecodeHints hints, std::vector >& results, int xOffset, int yOffset) -{ + DecodeHints hints, + vector >& results, + int xOffset, + int yOffset, + int currentDepth) { + if (currentDepth > MAX_DEPTH) { + return; + } Ref result; try { result = delegate_.decode(image, hints); @@ -91,22 +98,22 @@ void GenericMultipleBarcodeReader::doDecodeMultiple(Ref image, // Decode left of barcode if (minX > MIN_DIMENSION_TO_RECUR) { doDecodeMultiple(image->crop(0, 0, (int) minX, height), - hints, results, xOffset, yOffset); + hints, results, xOffset, yOffset, currentDepth+1); } // Decode above barcode if (minY > MIN_DIMENSION_TO_RECUR) { doDecodeMultiple(image->crop(0, 0, width, (int) minY), - hints, results, xOffset, yOffset); + hints, results, xOffset, yOffset, currentDepth+1); } // Decode right of barcode if (maxX < width - MIN_DIMENSION_TO_RECUR) { doDecodeMultiple(image->crop((int) maxX, 0, width - (int) maxX, height), - hints, results, xOffset + (int) maxX, yOffset); + hints, results, xOffset + (int) maxX, yOffset, currentDepth+1); } // Decode below barcode if (maxY < height - MIN_DIMENSION_TO_RECUR) { doDecodeMultiple(image->crop(0, (int) maxY, width, height - (int) maxY), - hints, results, xOffset, yOffset + (int) maxY); + hints, results, xOffset, yOffset + (int) maxY, currentDepth+1); } } @@ -122,6 +129,3 @@ Ref GenericMultipleBarcodeReader::translateResultPoints(Ref resu } return Ref(new Result(result->getText(), result->getRawBytes(), newResultPoints, result->getBarcodeFormat())); } - -} // End zxing::multi namespace -} // End zxing namespace diff --git a/cpp/core/src/zxing/multi/GenericMultipleBarcodeReader.h b/cpp/core/src/zxing/multi/GenericMultipleBarcodeReader.h index 87d46b335..ff96ab8a2 100644 --- a/cpp/core/src/zxing/multi/GenericMultipleBarcodeReader.h +++ b/cpp/core/src/zxing/multi/GenericMultipleBarcodeReader.h @@ -1,3 +1,4 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- #ifndef __GENERIC_MULTIPLE_BARCODE_READER_H__ #define __GENERIC_MULTIPLE_BARCODE_READER_H__ @@ -22,26 +23,29 @@ namespace zxing { namespace multi { -class GenericMultipleBarcodeReader : public MultipleBarcodeReader { - private: - static Ref translateResultPoints(Ref result, - int xOffset, - int yOffset); - void doDecodeMultiple(Ref image, - DecodeHints hints, - std::vector >& results, - int xOffset, - int yOffset); - Reader& delegate_; - static const int MIN_DIMENSION_TO_RECUR = 100; - public: - GenericMultipleBarcodeReader(Reader& delegate); - virtual ~GenericMultipleBarcodeReader(); - virtual std::vector > decodeMultiple(Ref image, - DecodeHints hints); +class GenericMultipleBarcodeReader : public MultipleBarcodeReader { + private: + static Ref translateResultPoints(Ref result, + int xOffset, + int yOffset); + void doDecodeMultiple(Ref image, + DecodeHints hints, + std::vector >& results, + int xOffset, + int yOffset, + int currentDepth); + Reader& delegate_; + static const int MIN_DIMENSION_TO_RECUR = 100; + static const int MAX_DEPTH = 4; + + public: + GenericMultipleBarcodeReader(Reader& delegate); + virtual ~GenericMultipleBarcodeReader(); + virtual std::vector > decodeMultiple(Ref image, DecodeHints hints); }; -} // End zxing::multi namespace -} // End zxing namespace + +} +} #endif // __GENERIC_MULTIPLE_BARCODE_READER_H__