MultiFormatUPCEANReader.cpp Example File
appdemos/qtws/QZXing/zxing/zxing/oned/MultiFormatUPCEANReader.cpp
#include <zxing/ZXing.h>
#include <zxing/oned/MultiFormatUPCEANReader.h>
#include <zxing/oned/EAN13Reader.h>
#include <zxing/oned/EAN8Reader.h>
#include <zxing/oned/UPCEReader.h>
#include <zxing/oned/UPCAReader.h>
#include <zxing/oned/OneDResultPoint.h>
#include <zxing/common/Array.h>
#include <zxing/ReaderException.h>
#include <zxing/NotFoundException.h>
#include <math.h>
using zxing::NotFoundException;
using zxing::Ref;
using zxing::Result;
using zxing::oned::MultiFormatUPCEANReader;
using zxing::DecodeHints;
using zxing::BitArray;
MultiFormatUPCEANReader::MultiFormatUPCEANReader(DecodeHints hints) : readers() {
if (hints.containsFormat(BarcodeFormat::EAN_13)) {
readers.push_back(Ref<UPCEANReader>(new EAN13Reader()));
} else if (hints.containsFormat(BarcodeFormat::UPC_A)) {
readers.push_back(Ref<UPCEANReader>(new UPCAReader()));
}
if (hints.containsFormat(BarcodeFormat::EAN_8)) {
readers.push_back(Ref<UPCEANReader>(new EAN8Reader()));
}
if (hints.containsFormat(BarcodeFormat::UPC_E)) {
readers.push_back(Ref<UPCEANReader>(new UPCEReader()));
}
if (readers.size() == 0) {
readers.push_back(Ref<UPCEANReader>(new EAN13Reader()));
readers.push_back(Ref<UPCEANReader>(new EAN8Reader()));
readers.push_back(Ref<UPCEANReader>(new UPCEReader()));
}
}
#include <typeinfo>
Ref<Result> MultiFormatUPCEANReader::decodeRow(int rowNumber, Ref<BitArray> row, zxing::DecodeHints ) {
UPCEANReader::Range startGuardPattern = UPCEANReader::findStartGuardPattern(row);
for (int i = 0, e = readers.size(); i < e; i++) {
Ref<UPCEANReader> reader = readers[i];
Ref<Result> result;
try {
result = reader->decodeRow(rowNumber, row, startGuardPattern);
} catch (ReaderException const& ignored) {
(void)ignored;
continue;
}
if(result.empty())
continue;
bool ean13MayBeUPCA =
result->getBarcodeFormat() == BarcodeFormat::EAN_13 &&
result->getText()->charAt(0) == '0';
bool canReturnUPCA = true;
if (ean13MayBeUPCA && canReturnUPCA) {
Ref<Result> resultUPCA (new Result(result->getText()->substring(1),
result->getRawBytes(),
result->getResultPoints(),
BarcodeFormat::UPC_A));
return resultUPCA;
}
return result;
}
throw NotFoundException();
}