mirror of
https://github.com/zxing/zxing.git
synced 2025-01-13 04:07:27 -08:00
c++ port of the relevant parts of r2581
git-svn-id: https://zxing.googlecode.com/svn/trunk@2624 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
44e85392eb
commit
7640573424
|
@ -21,21 +21,8 @@
|
||||||
|
|
||||||
#include <zxing/ChecksumException.h>
|
#include <zxing/ChecksumException.h>
|
||||||
|
|
||||||
namespace zxing {
|
using zxing::ChecksumException;
|
||||||
|
|
||||||
ChecksumException::ChecksumException() {}
|
ChecksumException::ChecksumException() throw() {}
|
||||||
|
ChecksumException::ChecksumException(const char *msg) throw() : ReaderException(msg) {}
|
||||||
ChecksumException::ChecksumException(const char *msg) :
|
ChecksumException::~ChecksumException() throw() {}
|
||||||
ReaderException(msg) {
|
|
||||||
}
|
|
||||||
|
|
||||||
ChecksumException::~ChecksumException() throw() {
|
|
||||||
}
|
|
||||||
|
|
||||||
ChecksumException const&
|
|
||||||
ChecksumException::getChecksumInstance() {
|
|
||||||
static ChecksumException instance;
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -25,10 +25,9 @@ namespace zxing {
|
||||||
class ChecksumException : public ReaderException {
|
class ChecksumException : public ReaderException {
|
||||||
typedef ReaderException Base;
|
typedef ReaderException Base;
|
||||||
public:
|
public:
|
||||||
ChecksumException();
|
ChecksumException() throw();
|
||||||
ChecksumException(const char *msg);
|
ChecksumException(const char *msg) throw();
|
||||||
~ChecksumException() throw();
|
~ChecksumException() throw();
|
||||||
static ChecksumException const& getChecksumInstance();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,17 +24,14 @@
|
||||||
#include <zxing/datamatrix/decoder/DecodedBitStreamParser.h>
|
#include <zxing/datamatrix/decoder/DecodedBitStreamParser.h>
|
||||||
#include <zxing/datamatrix/Version.h>
|
#include <zxing/datamatrix/Version.h>
|
||||||
#include <zxing/ReaderException.h>
|
#include <zxing/ReaderException.h>
|
||||||
|
#include <zxing/ChecksumException.h>
|
||||||
#include <zxing/common/reedsolomon/ReedSolomonException.h>
|
#include <zxing/common/reedsolomon/ReedSolomonException.h>
|
||||||
|
|
||||||
namespace zxing {
|
using zxing::Ref;
|
||||||
namespace datamatrix {
|
using zxing::DecoderResult;
|
||||||
|
using zxing::datamatrix::Decoder;
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
Decoder::Decoder() :
|
|
||||||
rsDecoder_(GenericGF::DATA_MATRIX_FIELD_256) {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Decoder::Decoder() : rsDecoder_(GenericGF::DATA_MATRIX_FIELD_256) {}
|
||||||
|
|
||||||
void Decoder::correctErrors(ArrayRef<char> codewordBytes, int numDataCodewords) {
|
void Decoder::correctErrors(ArrayRef<char> codewordBytes, int numDataCodewords) {
|
||||||
int numCodewords = codewordBytes->size();
|
int numCodewords = codewordBytes->size();
|
||||||
|
@ -45,9 +42,8 @@ void Decoder::correctErrors(ArrayRef<char> codewordBytes, int numDataCodewords)
|
||||||
int numECCodewords = numCodewords - numDataCodewords;
|
int numECCodewords = numCodewords - numDataCodewords;
|
||||||
try {
|
try {
|
||||||
rsDecoder_.decode(codewordInts, numECCodewords);
|
rsDecoder_.decode(codewordInts, numECCodewords);
|
||||||
} catch (ReedSolomonException const& ex) {
|
} catch (ReedSolomonException const& ignored) {
|
||||||
ReaderException rex(ex.what());
|
throw ChecksumException();
|
||||||
throw rex;
|
|
||||||
}
|
}
|
||||||
// Copy back into array of bytes -- only need to worry about the bytes that were data
|
// Copy back into array of bytes -- only need to worry about the bytes that were data
|
||||||
// We don't care about errors in the error-correction codewords
|
// We don't care about errors in the error-correction codewords
|
||||||
|
@ -90,5 +86,3 @@ Ref<DecoderResult> Decoder::decode(Ref<BitMatrix> bits) {
|
||||||
DecodedBitStreamParser decodedBSParser;
|
DecodedBitStreamParser decodedBSParser;
|
||||||
return Ref<DecoderResult> (decodedBSParser.decode(resultBytes));
|
return Ref<DecoderResult> (decodedBSParser.decode(resultBytes));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ void GenericMultipleBarcodeReader::doDecodeMultiple(Ref<BinaryBitmap> image,
|
||||||
Ref<Result> result;
|
Ref<Result> result;
|
||||||
try {
|
try {
|
||||||
result = delegate_.decode(image, hints);
|
result = delegate_.decode(image, hints);
|
||||||
} catch (ReaderException const& re) {
|
} catch (ReaderException const& ignored) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool alreadyFound = false;
|
bool alreadyFound = false;
|
||||||
|
|
|
@ -279,6 +279,6 @@ void Code93Reader::checkOneChecksum(string const& result,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result[checkPosition] != ALPHABET[total % 47]) {
|
if (result[checkPosition] != ALPHABET[total % 47]) {
|
||||||
throw ChecksumException::getChecksumInstance();
|
throw ChecksumException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ Ref<Result> MultiFormatUPCEANReader::decodeRow(int rowNumber, Ref<BitArray> row)
|
||||||
Ref<Result> result;
|
Ref<Result> result;
|
||||||
try {
|
try {
|
||||||
result = reader->decodeRow(rowNumber, row, startGuardPattern);
|
result = reader->decodeRow(rowNumber, row, startGuardPattern);
|
||||||
} catch (ReaderException const& re) {
|
} catch (ReaderException const& ignored) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ Ref<Result> OneDReader::doDecode(Ref<BinaryBitmap> image, DecodeHints hints) {
|
||||||
// Estimate black point for this row and load it:
|
// Estimate black point for this row and load it:
|
||||||
try {
|
try {
|
||||||
row = image->getBlackRow(rowNumber, row);
|
row = image->getBlackRow(rowNumber, row);
|
||||||
} catch (NotFoundException const& nfe) {
|
} catch (NotFoundException const& ignored) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,22 +26,23 @@
|
||||||
#include <zxing/DecodeHints.h>
|
#include <zxing/DecodeHints.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace qrcode {
|
namespace qrcode {
|
||||||
|
|
||||||
class QRCodeReader : public Reader {
|
class QRCodeReader : public Reader {
|
||||||
private:
|
private:
|
||||||
Decoder decoder_;
|
Decoder decoder_;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Decoder& getDecoder();
|
Decoder& getDecoder();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QRCodeReader();
|
QRCodeReader();
|
||||||
virtual Ref<Result> decode(Ref<BinaryBitmap> image, DecodeHints hints);
|
virtual ~QRCodeReader();
|
||||||
virtual ~QRCodeReader();
|
|
||||||
|
|
||||||
};
|
Ref<Result> decode(Ref<BinaryBitmap> image, DecodeHints hints);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __QR_CODE_READER_H__
|
#endif // __QR_CODE_READER_H__
|
||||||
|
|
|
@ -20,13 +20,16 @@
|
||||||
|
|
||||||
#include <zxing/qrcode/Version.h>
|
#include <zxing/qrcode/Version.h>
|
||||||
#include <zxing/qrcode/FormatInformation.h>
|
#include <zxing/qrcode/FormatInformation.h>
|
||||||
|
#include <zxing/FormatException.h>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
|
|
||||||
|
using std::vector;
|
||||||
|
using std::numeric_limits;
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace qrcode {
|
namespace qrcode {
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
ECB::ECB(int count, int dataCodewords) :
|
ECB::ECB(int count, int dataCodewords) :
|
||||||
count_(count), dataCodewords_(dataCodewords) {
|
count_(count), dataCodewords_(dataCodewords) {
|
||||||
|
@ -94,9 +97,13 @@ ECBlocks& Version::getECBlocksForLevel(ErrorCorrectionLevel &ecLevel) {
|
||||||
|
|
||||||
Version *Version::getProvisionalVersionForDimension(int dimension) {
|
Version *Version::getProvisionalVersionForDimension(int dimension) {
|
||||||
if (dimension % 4 != 1) {
|
if (dimension % 4 != 1) {
|
||||||
throw ReaderException("Dimension must be 1 mod 4");
|
throw FormatException();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return Version::getVersionForNumber((dimension - 17) >> 2);
|
||||||
|
} catch (IllegalArgumentException const& ignored) {
|
||||||
|
throw FormatException();
|
||||||
}
|
}
|
||||||
return Version::getVersionForNumber((dimension - 17) >> 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Version *Version::getVersionForNumber(int versionNumber) {
|
Version *Version::getVersionForNumber(int versionNumber) {
|
||||||
|
@ -547,5 +554,6 @@ int Version::buildVersions() {
|
||||||
new ECB(61, 16)))));
|
new ECB(61, 16)))));
|
||||||
return VERSIONS.size();
|
return VERSIONS.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ void DecodedBitStreamParser::decodeHanziSegment(Ref<BitSource> bits_,
|
||||||
|
|
||||||
try {
|
try {
|
||||||
append(result, buffer, nBytes, StringUtils::GB2312);
|
append(result, buffer, nBytes, StringUtils::GB2312);
|
||||||
} catch (ReaderException const& re) {
|
} catch (ReaderException const& ignored) {
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
throw FormatException();
|
throw FormatException();
|
||||||
}
|
}
|
||||||
|
@ -164,8 +164,12 @@ void DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, std::string
|
||||||
offset += 2;
|
offset += 2;
|
||||||
count--;
|
count--;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
append(result, buffer, nBytes, StringUtils::SHIFT_JIS);
|
append(result, buffer, nBytes, StringUtils::SHIFT_JIS);
|
||||||
|
} catch (ReaderException const& ignored) {
|
||||||
|
delete [] buffer;
|
||||||
|
throw FormatException();
|
||||||
|
}
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +204,7 @@ void DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits_,
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
append(result, readBytes, nBytes, encoding.c_str());
|
append(result, readBytes, nBytes, encoding.c_str());
|
||||||
} catch (ReaderException const& re) {
|
} catch (ReaderException const& ignored) {
|
||||||
throw FormatException();
|
throw FormatException();
|
||||||
}
|
}
|
||||||
byteSegments->values().push_back(bytes_);
|
byteSegments->values().push_back(bytes_);
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <zxing/qrcode/decoder/DataBlock.h>
|
#include <zxing/qrcode/decoder/DataBlock.h>
|
||||||
#include <zxing/qrcode/decoder/DecodedBitStreamParser.h>
|
#include <zxing/qrcode/decoder/DecodedBitStreamParser.h>
|
||||||
#include <zxing/ReaderException.h>
|
#include <zxing/ReaderException.h>
|
||||||
|
#include <zxing/ChecksumException.h>
|
||||||
#include <zxing/common/reedsolomon/ReedSolomonException.h>
|
#include <zxing/common/reedsolomon/ReedSolomonException.h>
|
||||||
|
|
||||||
using zxing::qrcode::Decoder;
|
using zxing::qrcode::Decoder;
|
||||||
|
@ -46,9 +47,8 @@ void Decoder::correctErrors(ArrayRef<char> codewordBytes, int numDataCodewords)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
rsDecoder_.decode(codewordInts, numECCodewords);
|
rsDecoder_.decode(codewordInts, numECCodewords);
|
||||||
} catch (ReedSolomonException const& ex) {
|
} catch (ReedSolomonException const& ignored) {
|
||||||
ReaderException rex(ex.what());
|
throw ChecksumException();
|
||||||
throw rex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < numDataCodewords; i++) {
|
for (int i = 0; i < numDataCodewords; i++) {
|
||||||
|
|
Loading…
Reference in a new issue