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.
*
@ -18,20 +19,20 @@
#include <zxing/ReaderException.h>
#include <zxing/ResultPoint.h>
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<Ref<Result> > GenericMultipleBarcodeReader::decodeMultiple(
Ref<BinaryBitmap> image, DecodeHints hints)
{
std::vector<Ref<Result> > results;
doDecodeMultiple(image, hints, results, 0, 0);
vector<Ref<Result> > GenericMultipleBarcodeReader::decodeMultiple(Ref<BinaryBitmap> image,
DecodeHints hints) {
vector<Ref<Result> > results;
doDecodeMultiple(image, hints, results, 0, 0, 0);
if (results.empty()){
throw ReaderException("No code detected");
}
@ -39,8 +40,14 @@ std::vector<Ref<Result> > GenericMultipleBarcodeReader::decodeMultiple(
}
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;
try {
result = delegate_.decode(image, hints);
@ -91,22 +98,22 @@ void GenericMultipleBarcodeReader::doDecodeMultiple(Ref<BinaryBitmap> 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<Result> GenericMultipleBarcodeReader::translateResultPoints(Ref<Result> resu
}
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__
#define __GENERIC_MULTIPLE_BARCODE_READER_H__
@ -22,26 +23,29 @@
namespace zxing {
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:
GenericMultipleBarcodeReader(Reader& delegate);
virtual ~GenericMultipleBarcodeReader();
virtual std::vector<Ref<Result> > decodeMultiple(Ref<BinaryBitmap> image,
DecodeHints hints);
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,
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__