#include <zxing/common/IllegalArgumentException.h>
namespace zxing {
+const DecodeHints DecodeHints::PRODUCT_HINT(
+ BARCODEFORMAT_UPC_E_HINT |
+ BARCODEFORMAT_UPC_A_HINT |
+ BARCODEFORMAT_EAN_8_HINT |
+ BARCODEFORMAT_EAN_13_HINT);
+
+const DecodeHints DecodeHints::ONED_HINT(
+ BARCODEFORMAT_UPC_E_HINT |
+ BARCODEFORMAT_UPC_A_HINT |
+ BARCODEFORMAT_EAN_8_HINT |
+ BARCODEFORMAT_EAN_13_HINT |
+ BARCODEFORMAT_CODE_128_HINT |
+ BARCODEFORMAT_CODE_39_HINT |
+ BARCODEFORMAT_ITF_HINT);
+
+const DecodeHints DecodeHints::DEFAULT_HINT(
+ BARCODEFORMAT_UPC_E_HINT |
+ BARCODEFORMAT_UPC_A_HINT |
+ BARCODEFORMAT_EAN_8_HINT |
+ BARCODEFORMAT_EAN_13_HINT |
+ BARCODEFORMAT_CODE_128_HINT |
+ BARCODEFORMAT_CODE_39_HINT |
+ BARCODEFORMAT_ITF_HINT |
+ // TODO: uncomment once this passes QA
+ // BARCODEFORMAT_DATA_MATRIX_HINT |
+ BARCODEFORMAT_QR_CODE_HINT);
+
DecodeHints::DecodeHints() {
hints = 0;
}
hints = init;
}
-DecodeHints::~DecodeHints() {
- // if DecodeHintType requires a destructor in the future, call it here
-}
-
void DecodeHints::addFormat(BarcodeFormat toadd) {
switch (toadd) {
case BarcodeFormat_QR_CODE: hints |= BARCODEFORMAT_QR_CODE_HINT; break;
+#ifndef __DECODEHINTS_H_
+#define __DECODEHINTS_H_
/*
* DecodeHintType.h
* zxing
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef DECODEHINTS_H_
-#define DECODEHINTS_H_
#include <zxing/BarcodeFormat.h>
public:
- static const DecodeHintType BARCODEFORMAT_PRODUCT_HINT =
- BARCODEFORMAT_UPC_E_HINT |
- BARCODEFORMAT_UPC_A_HINT |
- BARCODEFORMAT_EAN_8_HINT |
- BARCODEFORMAT_EAN_13_HINT;
-
- static const DecodeHintType BARCODEFORMAT_ONED_HINT =
- BARCODEFORMAT_PRODUCT_HINT |
- BARCODEFORMAT_CODE_128_HINT |
- BARCODEFORMAT_CODE_39_HINT |
- BARCODEFORMAT_ITF_HINT;
-
- static const DecodeHintType BARCODEFORMAT_ANY_HINT =
- BARCODEFORMAT_ONED_HINT |
-// TODO: uncomment once this passes QA
-// BARCODEFORMAT_DATA_MATRIX_HINT |
- BARCODEFORMAT_QR_CODE_HINT;
-
- static const DecodeHintType DEFAULT_HINTS = BARCODEFORMAT_ANY_HINT;
+ static const DecodeHints PRODUCT_HINT;
+ static const DecodeHints ONED_HINT;
+ static const DecodeHints DEFAULT_HINT;
DecodeHints();
DecodeHints(DecodeHintType init);
- ~DecodeHints();
+
void addFormat(BarcodeFormat toadd);
bool containsFormat(BarcodeFormat tocheck) const;
void setTryHarder(bool toset);
namespace zxing {
MultiFormatReader::MultiFormatReader() {
- readers.push_back(new zxing::qrcode::QRCodeReader());
- readers.push_back(new zxing::datamatrix::DataMatrixReader());
- readers.push_back(new zxing::oned::MultiFormatUPCEANReader());
- readers.push_back(new zxing::oned::MultiFormatOneDReader());
+
}
- Ref<Result> MultiFormatReader::decode(Ref<BinaryBitmap> image, DecodeHints hints){
- for (unsigned int i = 0; i < readers.size(); i++) {
+ Ref<Result> MultiFormatReader::decode(Ref<BinaryBitmap> image) {
+ setHints(DecodeHints::DEFAULT_HINT);
+ return decodeInternal(image);
+ }
+
+ Ref<Result> MultiFormatReader::decode(Ref<BinaryBitmap> image, DecodeHints hints) {
+ setHints(hints);
+ return decodeInternal(image);
+ }
+
+ Ref<Result> MultiFormatReader::decodeWithState(Ref<BinaryBitmap> image) {
+ // Make sure to set up the default state so we don't crash
+ if (readers_.size() == 0) {
+ setHints(DecodeHints::DEFAULT_HINT);
+ }
+ return decodeInternal(image);
+ }
+
+ void MultiFormatReader::setHints(DecodeHints hints) {
+ hints_ = hints;
+ readers_.clear();
+ bool tryHarder = hints.getTryHarder();
+
+ bool addOneDReader = hints.containsFormat(BarcodeFormat_UPC_E) ||
+ hints.containsFormat(BarcodeFormat_UPC_A) ||
+ hints.containsFormat(BarcodeFormat_EAN_8) ||
+ hints.containsFormat(BarcodeFormat_EAN_13) ||
+ hints.containsFormat(BarcodeFormat_CODE_128) ||
+ hints.containsFormat(BarcodeFormat_CODE_39) ||
+ hints.containsFormat(BarcodeFormat_ITF);
+ if (addOneDReader && !tryHarder) {
+ readers_.push_back(new zxing::oned::MultiFormatOneDReader(hints));
+ }
+ if (hints.containsFormat(BarcodeFormat_QR_CODE)) {
+ readers_.push_back(new zxing::qrcode::QRCodeReader());
+ }
+ if (hints.containsFormat(BarcodeFormat_DATA_MATRIX)) {
+ readers_.push_back(new zxing::datamatrix::DataMatrixReader());
+ }
+ //TODO: add PDF417 here once PDF417 reader is implemented
+ if (addOneDReader && tryHarder) {
+ readers_.push_back(new zxing::oned::MultiFormatOneDReader(hints));
+ }
+ if (readers_.size() == 0) {
+ if (!tryHarder) {
+ readers_.push_back(new zxing::oned::MultiFormatOneDReader(hints));
+ }
+ readers_.push_back(new zxing::qrcode::QRCodeReader());
+ if (tryHarder) {
+ readers_.push_back(new zxing::oned::MultiFormatOneDReader(hints));
+ }
+ }
+ }
+
+ Ref<Result> MultiFormatReader::decodeInternal(Ref<BinaryBitmap> image) {
+ for (unsigned int i = 0; i < readers_.size(); i++) {
try {
- return readers[i]->decode(image, hints);
+ return readers_[i]->decode(image, hints_);
} catch (ReaderException re) {
// continue
}
}
MultiFormatReader::~MultiFormatReader(){
- for (unsigned int i = 0; i < readers.size(); i++) {
- delete readers[i];
+ for (unsigned int i = 0; i < readers_.size(); i++) {
+ delete readers_[i];
}
}
}
+#ifndef __MULTI_FORMAT_READER_H__
+#define __MULTI_FORMAT_READER_H__
+
/*
* MultiFormatBarcodeReader.h
* ZXing
*
- * Created by Lukasz Warchol on 10-01-26.
- * Modified by Luiz Silva on 09/02/2010.
* Copyright 2010 ZXing authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
class MultiFormatReader : public Reader {
private:
- std::vector<Reader*>readers;
+ Ref<Result> decodeInternal(Ref<BinaryBitmap> image);
+
+ std::vector<Reader*> readers_;
+ DecodeHints hints_;
+
public:
MultiFormatReader();
+ Ref<Result> decode(Ref<BinaryBitmap> image);
Ref<Result> decode(Ref<BinaryBitmap> image, DecodeHints hints);
-
+ Ref<Result> decodeWithState(Ref<BinaryBitmap> image);
+ void setHints(DecodeHints hints);
~MultiFormatReader();
};
}
+
+#endif
Reader::~Reader() { }
Ref<Result> Reader::decode(Ref<BinaryBitmap> image) {
- DecodeHints hints(hints.DEFAULT_HINTS);
- return decode(image, hints);
+ return decode(image, DecodeHints::DEFAULT_HINT);
}
}
* Reader.h
* zxing
*
- * Created by Christian Brunschen on 13/05/2008.
- * Copyright 2008 ZXing authors All rights reserved.
+ * Copyright 2010 ZXing authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
protected:
Reader() {}
public:
- Ref<Result> decode(Ref<BinaryBitmap> image);
+ virtual Ref<Result> decode(Ref<BinaryBitmap> image);
virtual Ref<Result> decode(Ref<BinaryBitmap> image, DecodeHints hints) = 0;
virtual ~Reader();
};
endPattern[0] = row->getSize() - endPattern[1];
endPattern[1] = row->getSize() - temp;
+ row->reverse();
return endPattern;
} catch (ReaderException re) {
row->reverse();
namespace zxing {
namespace oned {
- MultiFormatOneDReader::MultiFormatOneDReader() : readers() {
- readers.push_back(Ref<OneDReader>(new MultiFormatUPCEANReader()));
- readers.push_back(Ref<OneDReader>(new Code39Reader()));
- readers.push_back(Ref<OneDReader>(new Code128Reader()));
- readers.push_back(Ref<OneDReader>(new ITFReader()));
+ MultiFormatOneDReader::MultiFormatOneDReader(DecodeHints hints) : readers() {
+ if (hints.containsFormat(BarcodeFormat_EAN_13) ||
+ hints.containsFormat(BarcodeFormat_EAN_8) ||
+ hints.containsFormat(BarcodeFormat_UPC_A) ||
+ hints.containsFormat(BarcodeFormat_UPC_E)) {
+ readers.push_back(Ref<OneDReader>(new MultiFormatUPCEANReader(hints)));
+ }
+ if (hints.containsFormat(BarcodeFormat_CODE_39)) {
+ readers.push_back(Ref<OneDReader>(new Code39Reader()));
+ }
+ if (hints.containsFormat(BarcodeFormat_CODE_128)) {
+ readers.push_back(Ref<OneDReader>(new Code128Reader()));
+ }
+ if (hints.containsFormat(BarcodeFormat_ITF)) {
+ readers.push_back(Ref<OneDReader>(new ITFReader()));
+ }
+ if (readers.size() == 0) {
+ readers.push_back(Ref<OneDReader>(new MultiFormatUPCEANReader(hints)));
+ readers.push_back(Ref<OneDReader>(new Code39Reader()));
+ readers.push_back(Ref<OneDReader>(new Code128Reader()));
+ readers.push_back(Ref<OneDReader>(new ITFReader()));
+ }
}
Ref<Result> MultiFormatOneDReader::decodeRow(int rowNumber, Ref<BitArray> row){
+#ifndef __MULTI_FORMAT_ONED_READER_H__
+#define __MULTI_FORMAT_ONED_READER_H__
/*
* MultiFormatOneDReader.h
* ZXing
*
- * Created by Lukasz Warchol on 10-01-25.
- * Copyright 2010 ZXing authors All rights reserved.
+ * Copyright 2010 ZXing authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
#include <zxing/oned/OneDReader.h>
-#include <zxing/common/BitArray.h>
-#include <zxing/Result.h>
namespace zxing {
namespace oned {
private:
std::vector<Ref<OneDReader> > readers;
public:
- MultiFormatOneDReader();
+ MultiFormatOneDReader(DecodeHints hints);
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
};
}
}
+
+#endif
#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>
namespace zxing {
namespace oned {
- MultiFormatUPCEANReader::MultiFormatUPCEANReader() : readers() {
- readers.push_back(Ref<OneDReader>(new EAN13Reader()));
- // UPC-A is covered by EAN-13
- readers.push_back(Ref<OneDReader>(new EAN8Reader()));
- readers.push_back(Ref<OneDReader>(new UPCEReader()));
+ MultiFormatUPCEANReader::MultiFormatUPCEANReader(DecodeHints hints) : readers() {
+ if (hints.containsFormat(BarcodeFormat_EAN_13)) {
+ readers.push_back(Ref<OneDReader>(new EAN13Reader()));
+ } else if (hints.containsFormat(BarcodeFormat_UPC_A)) {
+ readers.push_back(Ref<OneDReader>(new UPCAReader()));
+ }
+ if (hints.containsFormat(BarcodeFormat_EAN_8)) {
+ readers.push_back(Ref<OneDReader>(new EAN8Reader()));
+ }
+ if (hints.containsFormat(BarcodeFormat_UPC_E)) {
+ readers.push_back(Ref<OneDReader>(new UPCEReader()));
+ }
+ if (readers.size() == 0) {
+ readers.push_back(Ref<OneDReader>(new EAN13Reader()));
+ // UPC-A is covered by EAN-13
+ readers.push_back(Ref<OneDReader>(new EAN8Reader()));
+ readers.push_back(Ref<OneDReader>(new UPCEReader()));
+ }
}
-
+
Ref<Result> MultiFormatUPCEANReader::decodeRow(int rowNumber, Ref<BitArray> row){
// Compute this location once and reuse it on multiple implementations
int size = readers.size();
+#ifndef __MULTI_FORMAT_UPC_EAN_READER_H__
+#define __MULTI_FORMAT_UPC_EAN_READER_H__
/*
* MultiFormatUPCEANReader.h
* ZXing
*
- * Created by Lukasz Warchol on 10-01-25.
* Copyright 2010 ZXing authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* limitations under the License.
*/
-
-
#include <zxing/oned/OneDReader.h>
-#include <zxing/common/BitArray.h>
-#include <zxing/Result.h>
namespace zxing {
namespace oned {
private:
std::vector<Ref<OneDReader> > readers;
public:
- MultiFormatUPCEANReader();
+ MultiFormatUPCEANReader(DecodeHints hints);
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
};
}
}
+
+#endif
binarizer = new GlobalHistogramBinarizer(source);
}
- DecodeHints hints(hints.DEFAULT_HINTS);
+ DecodeHints hints(DecodeHints::DEFAULT_HINT);
hints.setTryHarder(tryHarder);
Ref<BinaryBitmap> binary(new BinaryBitmap(binarizer));
Ref<Result> result(decode(binary, hints));
textfilename.replace(dotpos+1, textfilename.length() - dotpos - 1, "txt");
char data[MAX_EXPECTED];
FILE *fp = fopen(textfilename.data(), "rb");
-
+
+ if (!fp) {
+ // could not open file
+ return "";
+ }
// get file size
fseek(fp, 0, SEEK_END);
int toread = ftell(fp);