c++ port of r2585

git-svn-id: https://zxing.googlecode.com/svn/trunk@2625 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
smparkes@smparkes.net 2013-04-06 20:19:19 +00:00
parent 7640573424
commit 8e609df96e
2 changed files with 47 additions and 39 deletions

View file

@ -1,3 +1,4 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
/* /*
* Copyright 2011 ZXing authors All rights reserved. * Copyright 2011 ZXing authors All rights reserved.
* *
@ -18,20 +19,20 @@
#include <zxing/ReaderException.h> #include <zxing/ReaderException.h>
#include <zxing/ResultPoint.h> #include <zxing/ResultPoint.h>
namespace zxing { using std::vector;
namespace multi { using zxing::Ref;
GenericMultipleBarcodeReader::GenericMultipleBarcodeReader(Reader& delegate) : using zxing::Result;
delegate_(delegate) using zxing::multi::GenericMultipleBarcodeReader;
{
} GenericMultipleBarcodeReader::GenericMultipleBarcodeReader(Reader& delegate)
: delegate_(delegate) {}
GenericMultipleBarcodeReader::~GenericMultipleBarcodeReader(){} GenericMultipleBarcodeReader::~GenericMultipleBarcodeReader(){}
std::vector<Ref<Result> > GenericMultipleBarcodeReader::decodeMultiple( vector<Ref<Result> > GenericMultipleBarcodeReader::decodeMultiple(Ref<BinaryBitmap> image,
Ref<BinaryBitmap> image, DecodeHints hints) DecodeHints hints) {
{ vector<Ref<Result> > results;
std::vector<Ref<Result> > results; doDecodeMultiple(image, hints, results, 0, 0, 0);
doDecodeMultiple(image, hints, results, 0, 0);
if (results.empty()){ if (results.empty()){
throw ReaderException("No code detected"); throw ReaderException("No code detected");
} }
@ -39,8 +40,14 @@ std::vector<Ref<Result> > GenericMultipleBarcodeReader::decodeMultiple(
} }
void GenericMultipleBarcodeReader::doDecodeMultiple(Ref<BinaryBitmap> image, void GenericMultipleBarcodeReader::doDecodeMultiple(Ref<BinaryBitmap> image,
DecodeHints hints, std::vector<Ref<Result> >& results, int xOffset, int yOffset) DecodeHints hints,
{ vector<Ref<Result> >& results,
int xOffset,
int yOffset,
int currentDepth) {
if (currentDepth > MAX_DEPTH) {
return;
}
Ref<Result> result; Ref<Result> result;
try { try {
result = delegate_.decode(image, hints); result = delegate_.decode(image, hints);
@ -91,22 +98,22 @@ void GenericMultipleBarcodeReader::doDecodeMultiple(Ref<BinaryBitmap> image,
// Decode left of barcode // Decode left of barcode
if (minX > MIN_DIMENSION_TO_RECUR) { if (minX > MIN_DIMENSION_TO_RECUR) {
doDecodeMultiple(image->crop(0, 0, (int) minX, height), doDecodeMultiple(image->crop(0, 0, (int) minX, height),
hints, results, xOffset, yOffset); hints, results, xOffset, yOffset, currentDepth+1);
} }
// Decode above barcode // Decode above barcode
if (minY > MIN_DIMENSION_TO_RECUR) { if (minY > MIN_DIMENSION_TO_RECUR) {
doDecodeMultiple(image->crop(0, 0, width, (int) minY), doDecodeMultiple(image->crop(0, 0, width, (int) minY),
hints, results, xOffset, yOffset); hints, results, xOffset, yOffset, currentDepth+1);
} }
// Decode right of barcode // Decode right of barcode
if (maxX < width - MIN_DIMENSION_TO_RECUR) { if (maxX < width - MIN_DIMENSION_TO_RECUR) {
doDecodeMultiple(image->crop((int) maxX, 0, width - (int) maxX, height), 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 // Decode below barcode
if (maxY < height - MIN_DIMENSION_TO_RECUR) { if (maxY < height - MIN_DIMENSION_TO_RECUR) {
doDecodeMultiple(image->crop(0, (int) maxY, width, height - (int) maxY), 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<Result> GenericMultipleBarcodeReader::translateResultPoints(Ref<Result> resu
} }
return Ref<Result>(new Result(result->getText(), result->getRawBytes(), newResultPoints, result->getBarcodeFormat())); return Ref<Result>(new Result(result->getText(), result->getRawBytes(), newResultPoints, result->getBarcodeFormat()));
} }
} // End zxing::multi namespace
} // End zxing namespace

View file

@ -1,3 +1,4 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
#ifndef __GENERIC_MULTIPLE_BARCODE_READER_H__ #ifndef __GENERIC_MULTIPLE_BARCODE_READER_H__
#define __GENERIC_MULTIPLE_BARCODE_READER_H__ #define __GENERIC_MULTIPLE_BARCODE_READER_H__
@ -22,26 +23,29 @@
namespace zxing { namespace zxing {
namespace multi { namespace multi {
class GenericMultipleBarcodeReader : public MultipleBarcodeReader {
private:
static Ref<Result> translateResultPoints(Ref<Result> result,
int xOffset,
int yOffset);
void doDecodeMultiple(Ref<BinaryBitmap> image,
DecodeHints hints,
std::vector<Ref<Result> >& results,
int xOffset,
int yOffset);
Reader& delegate_;
static const int MIN_DIMENSION_TO_RECUR = 100;
public: class GenericMultipleBarcodeReader : public MultipleBarcodeReader {
GenericMultipleBarcodeReader(Reader& delegate); private:
virtual ~GenericMultipleBarcodeReader(); static Ref<Result> translateResultPoints(Ref<Result> result,
virtual std::vector<Ref<Result> > decodeMultiple(Ref<BinaryBitmap> image, int xOffset,
DecodeHints hints); int yOffset);
void doDecodeMultiple(Ref<BinaryBitmap> image,
DecodeHints hints,
std::vector<Ref<Result> >& 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<Ref<Result> > decodeMultiple(Ref<BinaryBitmap> image, DecodeHints hints);
}; };
} // End zxing::multi namespace
} // End zxing namespace }
}
#endif // __GENERIC_MULTIPLE_BARCODE_READER_H__ #endif // __GENERIC_MULTIPLE_BARCODE_READER_H__