mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
c++ port of r2585
git-svn-id: https://zxing.googlecode.com/svn/trunk@2625 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
7640573424
commit
8e609df96e
|
@ -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
|
|
||||||
|
|
|
@ -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,6 +23,7 @@
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace multi {
|
namespace multi {
|
||||||
|
|
||||||
class GenericMultipleBarcodeReader : public MultipleBarcodeReader {
|
class GenericMultipleBarcodeReader : public MultipleBarcodeReader {
|
||||||
private:
|
private:
|
||||||
static Ref<Result> translateResultPoints(Ref<Result> result,
|
static Ref<Result> translateResultPoints(Ref<Result> result,
|
||||||
|
@ -31,17 +33,19 @@ class GenericMultipleBarcodeReader : public MultipleBarcodeReader {
|
||||||
DecodeHints hints,
|
DecodeHints hints,
|
||||||
std::vector<Ref<Result> >& results,
|
std::vector<Ref<Result> >& results,
|
||||||
int xOffset,
|
int xOffset,
|
||||||
int yOffset);
|
int yOffset,
|
||||||
|
int currentDepth);
|
||||||
Reader& delegate_;
|
Reader& delegate_;
|
||||||
static const int MIN_DIMENSION_TO_RECUR = 100;
|
static const int MIN_DIMENSION_TO_RECUR = 100;
|
||||||
|
static const int MAX_DEPTH = 4;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GenericMultipleBarcodeReader(Reader& delegate);
|
GenericMultipleBarcodeReader(Reader& delegate);
|
||||||
virtual ~GenericMultipleBarcodeReader();
|
virtual ~GenericMultipleBarcodeReader();
|
||||||
virtual std::vector<Ref<Result> > decodeMultiple(Ref<BinaryBitmap> image,
|
virtual std::vector<Ref<Result> > decodeMultiple(Ref<BinaryBitmap> image, DecodeHints hints);
|
||||||
DecodeHints hints);
|
|
||||||
};
|
};
|
||||||
} // End zxing::multi namespace
|
|
||||||
} // End zxing namespace
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // __GENERIC_MULTIPLE_BARCODE_READER_H__
|
#endif // __GENERIC_MULTIPLE_BARCODE_READER_H__
|
||||||
|
|
Loading…
Reference in a new issue