1d support for most C++ decoders; n.b. not pdf417 and rss

git-svn-id: https://zxing.googlecode.com/svn/trunk@2608 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
smparkes@smparkes.net 2013-04-01 06:00:29 +00:00
parent b323e601b7
commit af53906502
45 changed files with 378 additions and 321 deletions

View file

@ -34,7 +34,8 @@
debug="true"
deprecation="true"
fork="true"
includeantruntime="false">
includeantruntime="false"
encoding="UTF-8">
</javac>
<jar jarfile="core.jar" basedir="build"/>
</target>
@ -51,7 +52,8 @@
destdir="build-test"
debug="true"
deprecation="true"
includeantruntime="false">
includeantruntime="false"
encoding="UTF-8">
<classpath>
<pathelement location="core.jar"/>
<pathelement location="lib/junit-4.11.jar"/>

View file

@ -31,7 +31,7 @@ public final class AztecBlackBox2TestCase extends AbstractBlackBoxTestCase {
addTest(2, 2, 0.0f);
addTest(2, 2, 90.0f);
addTest(3, 3, 180.0f);
addTest(1, 1, 270.0f);
addTest(2, 2, 270.0f);
}
}

1
cpp/.gitignore vendored
View file

@ -4,3 +4,4 @@ xcuserdata
callgrind.out.*
contents.xcworkspacedata
*.pyc
/.rbenv-version

View file

@ -35,3 +35,46 @@
...
fun:map_images
}
{
c++
Memcheck:Leak
...
fun:__cxa_get_globals
}
{
stdio
Memcheck:Leak
...
fun:sprintf
}
{
objc
Memcheck:Leak
...
fun:prepareForMethodLookup
fun:lookUpMethod
}
{
os
Memcheck:Leak
...
fun:dlopen
}
{
osx
Memcheck:Leak
...
fun:map_images
}
{
at_exit
Memcheck:Leak
...
fun:atexit_register
}

View file

@ -22,8 +22,7 @@ if env['PIC']:
flags.append("-fPIC")
flags.append("-Wextra -Werror")
# Can't enable unless we get rid of the dynamic variable length arrays
# flags.append("-pedantic")
flags.append("-pedantic")
compile_options['CXXFLAGS'] = ' '.join(flags)
compile_options['LINKFLAGS'] = "-ldl -L/usr/lib -L/opt/local/lib -L/usr/local/lib"

View file

@ -44,7 +44,7 @@ public:
RSS_EXPANDED,
UPC_A,
UPC_E,
UPC_EAN_EXTENSION,
UPC_EAN_EXTENSION
};
BarcodeFormat(Value v) : value(v) {}

View file

@ -20,21 +20,24 @@
*/
#include <zxing/ZXing.h>
#include <zxing/Exception.h>
#include <string.h>
namespace zxing {
using zxing::Exception;
Exception::Exception() {}
Exception::Exception(const char *msg) :
message(msg) {
void Exception::deleteMessage() {
delete [] message;
}
const char* Exception::what() const throw() {
return message.c_str();
char const* Exception::copy(char const* msg) {
char* message = 0;
if (msg) {
int l = strlen(msg)+1;
if (l) {
message = new char[l];
strcpy(message, msg);
}
Exception::~Exception() throw() {
}
return message;
}

View file

@ -1,3 +1,4 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
#ifndef __EXCEPTION_H__
#define __EXCEPTION_H__
@ -24,17 +25,27 @@
#include <exception>
namespace zxing {
class Exception;
}
class Exception : public std::exception {
class zxing::Exception : public std::exception {
private:
std::string message;
char const* const message;
public:
Exception();
Exception(const char *msg);
virtual const char* what() const throw();
virtual ~Exception() throw();
Exception() throw() : message(0) {}
Exception(const char* msg) throw() : message(copy(msg)) {}
Exception(Exception const& that) throw() : std::exception(that), message(copy(that.message)) {}
~Exception() throw() {
if(message) {
deleteMessage();
}
}
char const* what() const throw() {return message ? message : "";}
private:
static char const* copy(char const*);
void deleteMessage();
};
}
#endif // __EXCEPTION_H__

View file

@ -20,6 +20,7 @@
* limitations under the License.
*/
#include <zxing/ZXing.h>
#include <zxing/MultiFormatReader.h>
#include <zxing/qrcode/QRCodeReader.h>
#include <zxing/datamatrix/DataMatrixReader.h>
@ -111,7 +112,6 @@ void MultiFormatReader::setHints(DecodeHints hints) {
Ref<Result> MultiFormatReader::decodeInternal(Ref<BinaryBitmap> image) {
for (unsigned int i = 0; i < readers_.size(); i++) {
try {
// std::cerr << "0 " << typeid(readers_[i]).name() << std::endl;
return readers_[i]->decode(image, hints_);
} catch (ReaderException const& re) {
// continue

View file

@ -1,34 +0,0 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
/*
* Copyright 20011 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <zxing/NotFoundException.h>
using zxing::NotFoundException;
NotFoundException::NotFoundException() {}
NotFoundException::NotFoundException(const char *msg)
: ReaderException(msg) {}
NotFoundException::~NotFoundException() throw() {}
NotFoundException const&
NotFoundException::getNotFoundInstance() {
static NotFoundException instance;
return instance;
}

View file

@ -22,15 +22,14 @@
#include <zxing/ReaderException.h>
namespace zxing {
class NotFoundException;
}
class NotFoundException : public ReaderException {
class zxing::NotFoundException : public ReaderException {
public:
NotFoundException();
NotFoundException(const char *msg);
~NotFoundException() throw();
static NotFoundException const& getNotFoundInstance();
NotFoundException() throw() {}
NotFoundException(const char *msg) throw() : ReaderException(msg) {}
~NotFoundException() throw() {}
};
}
#endif // __NOT_FOUND_EXCEPTION_H__

View file

@ -1,35 +0,0 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
/*
* ReaderException.cpp
* zxing
*
* Created by Christian Brunschen on 13/05/2008.
* Copyright 2008-2011 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <zxing/ReaderException.h>
namespace zxing {
ReaderException::ReaderException() {}
ReaderException::ReaderException(const char *msg) :
Exception(msg) {
}
ReaderException::~ReaderException() throw() {
}
}

View file

@ -23,13 +23,14 @@
#include <zxing/Exception.h>
namespace zxing {
class ReaderException;
}
class ReaderException : public Exception {
class zxing::ReaderException : public Exception {
public:
ReaderException();
ReaderException(const char *msg);
~ReaderException() throw();
ReaderException() throw() {}
ReaderException(char const* msg) throw() : Exception(msg) {}
~ReaderException() throw() {}
};
}
#endif // __READER_EXCEPTION_H__

View file

@ -0,0 +1,97 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
/*
* Copyright 2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __ZXING_H_
#define __ZXING_H_
#define ZXING_ARRAY_LEN(v) ((int)(sizeof(v)/sizeof(v[0])))
#ifndef ZXING_DEBUG
#define ZXING_DEBUG 0
#endif
#if ZXING_DEBUG
#include <iostream>
#include <string>
using std::cout;
using std::cerr;
using std::endl;
using std::flush;
using std::string;
using std::ostream;
#if ZXING_DEBUG_TIMER
#include <sys/time.h>
namespace zxing {
class DebugTimer;
}
class zxing::DebugTimer {
public:
DebugTimer(char const* string_) : chars(string_) {
gettimeofday(&start, 0);
}
DebugTimer(std::string const& string_) : chars(0), string(string_) {
gettimeofday(&start, 0);
}
void mark(char const* string) {
struct timeval end;
gettimeofday(&end, 0);
int diff =
(end.tv_sec - start.tv_sec)*1000*1000+(end.tv_usec - start.tv_usec);
cerr << diff << " " << string << '\n';
}
void mark(std::string string) {
mark(string.c_str());
}
~DebugTimer() {
if (chars) {
mark(chars);
} else {
mark(string.c_str());
}
}
private:
char const* const chars;
std::string string;
struct timeval start;
};
#define ZXING_TIME(string) DebugTimer __timer__ (string)
#define ZXING_TIME_MARK(string) __timer__.mark(string)
#endif
#endif // ZXING_DEBUG
#ifndef ZXING_TIME
#define ZXING_TIME(string) (void)0
#endif
#ifndef ZXING_TIME_MARK
#define ZXING_TIME_MARK(string) (void)0
#endif
#endif

View file

@ -32,7 +32,7 @@ AztecDetectorResult::AztecDetectorResult(Ref<BitMatrix> bits,
compact_(compact),
nbDatablocks_(nbDatablocks),
nbLayers_(nbLayers) {
};
}
bool AztecDetectorResult::isCompact() {
return compact_;

View file

@ -30,7 +30,7 @@ using zxing::aztec::AztecReader;
AztecReader::AztecReader() : decoder_() {
// nothing
};
}
Ref<Result> AztecReader::decode(Ref<zxing::BinaryBitmap> image) {
Detector detector(image->getBlackMatrix());

View file

@ -328,13 +328,12 @@ Ref<BitArray> Decoder::correctBits(Ref<zxing::BitArray> rawbits) {
}
try {
// std::printf("trying reed solomon, numECCodewords:%d\n", numECCodewords);
ReedSolomonDecoder rsDecoder(gf);
rsDecoder.decode(dataWords, numECCodewords);
} catch (ReedSolomonException rse) {
} catch (ReedSolomonException const& ignored) {
// std::printf("got reed solomon exception:%s, throwing formatexception\n", rse.what());
throw FormatException("rs decoding failed");
} catch (IllegalArgumentException iae) {
} catch (IllegalArgumentException const& iae) {
// std::printf("illegal argument exception: %s", iae.what());
}

View file

@ -205,7 +205,7 @@ void Detector::correctParameterData(Ref<zxing::BitArray> parameterData, bool com
// std::printf("parameter data reed solomon\n");
ReedSolomonDecoder rsDecoder(GenericGF::AZTEC_PARAM);
rsDecoder.decode(parameterWords, numECCodewords);
} catch (ReedSolomonException e) {
} catch (ReedSolomonException const& ignored) {
// std::printf("reed solomon decoding failed\n");
throw ReaderException("failed to decode parameter data");
}
@ -308,7 +308,7 @@ Ref<Point> Detector::getMatrixCenter() {
pointC = cornerPoints[2];
pointD = cornerPoints[3];
} catch (NotFoundException e) {
} catch (NotFoundException const& e) {
int cx = image_->getWidth() / 2;
int cy = image_->getHeight() / 2;
@ -331,7 +331,7 @@ Ref<Point> Detector::getMatrixCenter() {
pointC = cornerPoints[2];
pointD = cornerPoints[3];
} catch (NotFoundException e) {
} catch (NotFoundException const& e) {
pointA = getFirstDifferent(Ref<Point>(new Point(cx+15/2, cy-15/2)), false, 1, -1)->toResultPoint();
pointB = getFirstDifferent(Ref<Point>(new Point(cx+15/2, cy+15/2)), false, 1, 1)->toResultPoint();

View file

@ -30,7 +30,6 @@
#include <zxing/common/Counted.h>
namespace zxing {
template<typename T> class Array : public Counted {

View file

@ -106,11 +106,11 @@ bool BitArray::isRange(int start, int end, bool value) {
}
vector<int>& BitArray::getBitArray() {
return bits;
return bits->values();
}
void BitArray::reverse() {
vector<int> newBits(bits.size());
ArrayRef<int> newBits(bits.size());
int size = this->size;
for (int i = 0; i < size; i++) {
if (get(size - i - 1)) {

View file

@ -20,6 +20,7 @@
#include <zxing/common/Counted.h>
#include <zxing/common/IllegalArgumentException.h>
#include <zxing/common/Array.h>
#include <vector>
#include <limits>
#include <iostream>
@ -43,7 +44,7 @@ public:
private:
int size;
std::vector<int> bits;
ArrayRef<int> bits;
static const int logBits = ZX_LOG_DIGITS(bitsPerWord);
static const int bitsMask = (1 << logBits) - 1;

View file

@ -71,7 +71,7 @@ void BitMatrix::setRegion(int left, int top, int width, int height) {
int right = left + width;
int bottom = top + height;
if (bottom > this->height || right > this->width) {
throw new IllegalArgumentException("The region must fit inside the matrix");
throw IllegalArgumentException("The region must fit inside the matrix");
}
for (int y = top; y < bottom; y++) {
int offset = y * rowSize;

View file

@ -28,67 +28,67 @@ using zxing::GenericGF;
using zxing::GenericGFPoly;
using zxing::Ref;
Ref<GenericGF> GenericGF::QR_CODE_FIELD_256(new GenericGF(0x011D, 256));
Ref<GenericGF> GenericGF::DATA_MATRIX_FIELD_256(new GenericGF(0x012D, 256));
Ref<GenericGF> GenericGF::AZTEC_PARAM(new GenericGF(0x13, 16));
Ref<GenericGF> GenericGF::AZTEC_DATA_6(new GenericGF(0x43, 64));
Ref<GenericGF> GenericGF::AZTEC_DATA_8(GenericGF::DATA_MATRIX_FIELD_256);
Ref<GenericGF> GenericGF::AZTEC_DATA_10(new GenericGF(0x409, 1024));
Ref<GenericGF> GenericGF::AZTEC_DATA_12(new GenericGF(0x1069, 4096));
Ref<GenericGF> GenericGF::AZTEC_DATA_12(new GenericGF(0x1069, 4096, 1));
Ref<GenericGF> GenericGF::AZTEC_DATA_10(new GenericGF(0x409, 1024, 1));
Ref<GenericGF> GenericGF::AZTEC_DATA_6(new GenericGF(0x43, 64, 1));
Ref<GenericGF> GenericGF::AZTEC_PARAM(new GenericGF(0x13, 16, 1));
Ref<GenericGF> GenericGF::QR_CODE_FIELD_256(new GenericGF(0x011D, 256, 0));
Ref<GenericGF> GenericGF::DATA_MATRIX_FIELD_256(new GenericGF(0x012D, 256, 1));
Ref<GenericGF> GenericGF::AZTEC_DATA_8 = DATA_MATRIX_FIELD_256;
Ref<GenericGF> GenericGF::MAXICODE_FIELD_64 = AZTEC_DATA_6;
namespace {
int INITIALIZATION_THRESHOLD = 0;
}
static int INITIALIZATION_THRESHOLD = 0;
GenericGF::GenericGF(int primitive, int size)
: size_(size), primitive_(primitive), initialized_(false) {
GenericGF::GenericGF(int primitive_, int size_, int b)
: size(size_), primitive(primitive_), generatorBase(b), initialized(false) {
if (size <= INITIALIZATION_THRESHOLD) {
initialize();
}
}
void GenericGF::initialize() {
//expTable_ = std::vector<int>(size_, (const int) 0);
//logTable_ = std::vector<int>(size_, (const int) 0);
expTable_.resize(size_);
logTable_.resize(size_);
expTable.resize(size);
logTable.resize(size);
int x = 1;
for (int i = 0; i < size_; i++) {
expTable_[i] = x;
for (int i = 0; i < size; i++) {
expTable[i] = x;
x <<= 1; // x = x * 2; we're assuming the generator alpha is 2
if (x >= size_) {
x ^= primitive_;
x &= size_-1;
if (x >= size) {
x ^= primitive;
x &= size-1;
}
}
for (int i = 0; i < size_-1; i++) {
logTable_[expTable_[i]] = i;
for (int i = 0; i < size-1; i++) {
logTable[expTable[i]] = i;
}
//logTable_[0] == 0 but this should never be used
zero_ = Ref<GenericGFPoly>(new GenericGFPoly(Ref<GenericGF>(this), ArrayRef<int>(new Array<int>(1))));
zero_->getCoefficients()[0] = 0;
one_ = Ref<GenericGFPoly>(new GenericGFPoly(Ref<GenericGF>(this), ArrayRef<int>(new Array<int>(1))));
one_->getCoefficients()[0] = 1;
initialized_ = true;
//logTable[0] == 0 but this should never be used
zero =
Ref<GenericGFPoly>(new GenericGFPoly(Ref<GenericGF>(this), ArrayRef<int>(new Array<int>(1))));
zero->getCoefficients()[0] = 0;
one =
Ref<GenericGFPoly>(new GenericGFPoly(Ref<GenericGF>(this), ArrayRef<int>(new Array<int>(1))));
one->getCoefficients()[0] = 1;
initialized = true;
}
void GenericGF::checkInit() {
if (!initialized_) {
if (!initialized) {
initialize();
}
}
Ref<GenericGFPoly> GenericGF::getZero() {
checkInit();
return zero_;
return zero;
}
Ref<GenericGFPoly> GenericGF::getOne() {
checkInit();
return one_;
return one;
}
Ref<GenericGFPoly> GenericGF::buildMonomial(int degree, int coefficient) {
@ -98,12 +98,11 @@ Ref<GenericGFPoly> GenericGF::buildMonomial(int degree, int coefficient) {
throw IllegalArgumentException("Degree must be non-negative");
}
if (coefficient == 0) {
return zero_;
return zero;
}
ArrayRef<int> coefficients(new Array<int>(degree + 1));
coefficients[0] = coefficient;
//return new GenericGFPoly(this, coefficients);
return Ref<GenericGFPoly>(new GenericGFPoly(Ref<GenericGF>(this), coefficients));
}
@ -113,7 +112,7 @@ int GenericGF::addOrSubtract(int a, int b) {
int GenericGF::exp(int a) {
checkInit();
return expTable_[a];
return expTable[a];
}
int GenericGF::log(int a) {
@ -121,7 +120,7 @@ int GenericGF::log(int a) {
if (a == 0) {
throw IllegalArgumentException("cannot give log(0)");
}
return logTable_[a];
return logTable[a];
}
int GenericGF::inverse(int a) {
@ -129,7 +128,7 @@ int GenericGF::inverse(int a) {
if (a == 0) {
throw IllegalArgumentException("Cannot calculate the inverse of 0");
}
return expTable_[size_ - logTable_[a] - 1];
return expTable[size - logTable[a] - 1];
}
int GenericGF::multiply(int a, int b) {
@ -139,9 +138,13 @@ int GenericGF::multiply(int a, int b) {
return 0;
}
return expTable_[(logTable_[a] + logTable_[b]) % (size_ - 1)];
return expTable[(logTable[a] + logTable[b]) % (size - 1)];
}
int GenericGF::getSize() {
return size_;
return size;
}
int GenericGF::getGeneratorBase() {
return generatorBase;
}

View file

@ -31,13 +31,14 @@ namespace zxing {
class GenericGF : public Counted {
private:
std::vector<int> expTable_;
std::vector<int> logTable_;
Ref<GenericGFPoly> zero_;
Ref<GenericGFPoly> one_;
int size_;
int primitive_;
bool initialized_;
std::vector<int> expTable;
std::vector<int> logTable;
Ref<GenericGFPoly> zero;
Ref<GenericGFPoly> one;
int size;
int primitive;
int generatorBase;
bool initialized;
void initialize();
void checkInit();
@ -50,12 +51,14 @@ namespace zxing {
static Ref<GenericGF> AZTEC_PARAM;
static Ref<GenericGF> QR_CODE_FIELD_256;
static Ref<GenericGF> DATA_MATRIX_FIELD_256;
static Ref<GenericGF> MAXICODE_FIELD_64;
GenericGF(int primitive, int size);
GenericGF(int primitive, int size, int b);
Ref<GenericGFPoly> getZero();
Ref<GenericGFPoly> getOne();
int getSize();
int getGeneratorBase();
Ref<GenericGFPoly> buildMonomial(int degree, int coefficient);
static int addOrSubtract(int a, int b);
@ -63,14 +66,6 @@ namespace zxing {
int log(int a);
int inverse(int a);
int multiply(int a, int b);
bool operator==(GenericGF other) {
return (other.getSize() == this->size_ &&
other.primitive_ == this->primitive_);
}
//#warning todo: add print method
};
}

View file

@ -33,9 +33,7 @@ using zxing::ArrayRef;
using zxing::ReedSolomonDecoder;
using zxing::GenericGFPoly;
ReedSolomonDecoder::ReedSolomonDecoder(Ref<GenericGF> fld) :
field(fld) {
}
ReedSolomonDecoder::ReedSolomonDecoder(Ref<GenericGF> field_) : field(field_) {}
ReedSolomonDecoder::~ReedSolomonDecoder() {
}
@ -43,10 +41,9 @@ ReedSolomonDecoder::~ReedSolomonDecoder() {
void ReedSolomonDecoder::decode(ArrayRef<int> received, int twoS) {
Ref<GenericGFPoly> poly(new GenericGFPoly(field, received));
ArrayRef<int> syndromeCoefficients(twoS);
bool dataMatrix = (field.object_ == GenericGF::DATA_MATRIX_FIELD_256.object_);
bool noError = true;
for (int i = 0; i < twoS; i++) {
int eval = poly->evaluateAt(field->exp(dataMatrix ? i + 1 : i));
int eval = poly->evaluateAt(field->exp(i + field->getGeneratorBase()));
syndromeCoefficients[syndromeCoefficients->size() - 1 - i] = eval;
if (eval != 0) {
noError = false;
@ -61,7 +58,7 @@ void ReedSolomonDecoder::decode(ArrayRef<int> received, int twoS) {
Ref<GenericGFPoly> sigma = sigmaOmega[0];
Ref<GenericGFPoly> omega = sigmaOmega[1];
ArrayRef<int> errorLocations = findErrorLocations(sigma);
ArrayRef<int> errorMagitudes = findErrorMagnitudes(omega, errorLocations, dataMatrix);
ArrayRef<int> errorMagitudes = findErrorMagnitudes(omega, errorLocations);
for (int i = 0; i < errorLocations->size(); i++) {
int position = received->size() - 1 - field->log(errorLocations[i]);
if (position < 0) {
@ -86,7 +83,6 @@ vector<Ref<GenericGFPoly> > ReedSolomonDecoder::runEuclideanAlgorithm(Ref<Generi
Ref<GenericGFPoly> tLast(field->getZero());
Ref<GenericGFPoly> t(field->getOne());
// Run Euclidean algorithm until r's degree is less than R/2
while (r->getDegree() >= R / 2) {
Ref<GenericGFPoly> rLastLast(rLast);
@ -94,14 +90,13 @@ vector<Ref<GenericGFPoly> > ReedSolomonDecoder::runEuclideanAlgorithm(Ref<Generi
rLast = r;
tLast = t;
// Divide rLastLast by rLast, with quotient q and remainder r
if (rLast->isZero()) {
// Oops, Euclidean algorithm already terminated?
throw ReedSolomonException("r_{i-1} was zero");
}
r = rLastLast;
Ref<GenericGFPoly> q(field->getZero());
Ref<GenericGFPoly> q = field->getZero();
int denominatorLeadingTerm = rLast->getCoefficient(rLast->getDegree());
int dltInverse = field->inverse(denominatorLeadingTerm);
while (r->getDegree() >= rLast->getDegree() && !r->isZero()) {
@ -112,7 +107,6 @@ vector<Ref<GenericGFPoly> > ReedSolomonDecoder::runEuclideanAlgorithm(Ref<Generi
}
t = q->multiply(tLast)->addOrSubtract(tLastLast);
}
int sigmaTildeAtZero = t->getCoefficient(0);
@ -123,17 +117,6 @@ vector<Ref<GenericGFPoly> > ReedSolomonDecoder::runEuclideanAlgorithm(Ref<Generi
int inverse = field->inverse(sigmaTildeAtZero);
Ref<GenericGFPoly> sigma(t->multiply(inverse));
Ref<GenericGFPoly> omega(r->multiply(inverse));
/*
#ifdef DEBUG
cout << "t = " << *t << endl;
cout << "r = " << *r << "\n";
cout << "sigma = " << *sigma << endl;
cout << "omega = " << *omega << endl;
#endif
*/
vector<Ref<GenericGFPoly> > result(2);
result[0] = sigma;
result[1] = omega;
@ -151,7 +134,6 @@ ArrayRef<int> ReedSolomonDecoder::findErrorLocations(Ref<GenericGFPoly> errorLoc
ArrayRef<int> result(new Array<int>(numErrors));
int e = 0;
for (int i = 1; i < field->getSize() && e < numErrors; i++) {
// cout << "errorLocator(" << i << ") == " << errorLocator->evaluateAt(i) << endl;
if (errorLocator->evaluateAt(i) == 0) {
result[e] = field->inverse(i);
e++;
@ -163,7 +145,7 @@ ArrayRef<int> ReedSolomonDecoder::findErrorLocations(Ref<GenericGFPoly> errorLoc
return result;
}
ArrayRef<int> ReedSolomonDecoder::findErrorMagnitudes(Ref<GenericGFPoly> errorEvaluator, ArrayRef<int> errorLocations, bool dataMatrix) {
ArrayRef<int> ReedSolomonDecoder::findErrorMagnitudes(Ref<GenericGFPoly> errorEvaluator, ArrayRef<int> errorLocations) {
// This is directly applying Forney's Formula
int s = errorLocations.size();
ArrayRef<int> result(new Array<int>(s));
@ -172,13 +154,14 @@ ArrayRef<int> ReedSolomonDecoder::findErrorMagnitudes(Ref<GenericGFPoly> errorEv
int denominator = 1;
for (int j = 0; j < s; j++) {
if (i != j) {
denominator = field->multiply(denominator, GenericGF::addOrSubtract(1, field->multiply(errorLocations[j],
xiInverse)));
int term = field->multiply(errorLocations[j], xiInverse);
int termPlus1 = (term & 0x1) == 0 ? term | 1 : term & ~1;
denominator = field->multiply(denominator, termPlus1);
}
}
result[i] = field->multiply(errorEvaluator->evaluateAt(xiInverse), field->inverse(denominator));
if (dataMatrix) {
result[i] = field->multiply(errorEvaluator->evaluateAt(xiInverse),
field->inverse(denominator));
if (field->getGeneratorBase() != 0) {
result[i] = field->multiply(result[i], xiInverse);
}
}

View file

@ -41,7 +41,7 @@ public:
private:
std::vector<Ref<GenericGFPoly> > runEuclideanAlgorithm(Ref<GenericGFPoly> a, Ref<GenericGFPoly> b, int R);
ArrayRef<int> findErrorLocations(Ref<GenericGFPoly> errorLocator);
ArrayRef<int> findErrorMagnitudes(Ref<GenericGFPoly> errorEvaluator, ArrayRef<int> errorLocations, bool dataMatrix);
ArrayRef<int> findErrorMagnitudes(Ref<GenericGFPoly> errorEvaluator, ArrayRef<int> errorLocations);
};
}

View file

@ -36,28 +36,28 @@ Ref<Result> ByQuadrantReader::decode(Ref<BinaryBitmap> image, DecodeHints hints)
Ref<BinaryBitmap> topLeft = image->crop(0, 0, halfWidth, halfHeight);
try {
return delegate_.decode(topLeft, hints);
} catch (ReaderException re) {
} catch (ReaderException const& re) {
// continue
}
Ref<BinaryBitmap> topRight = image->crop(halfWidth, 0, halfWidth, halfHeight);
try {
return delegate_.decode(topRight, hints);
} catch (ReaderException re) {
} catch (ReaderException const& re) {
// continue
}
Ref<BinaryBitmap> bottomLeft = image->crop(0, halfHeight, halfWidth, halfHeight);
try {
return delegate_.decode(bottomLeft, hints);
} catch (ReaderException re) {
} catch (ReaderException const& re) {
// continue
}
Ref<BinaryBitmap> bottomRight = image->crop(halfWidth, halfHeight, halfWidth, halfHeight);
try {
return delegate_.decode(bottomRight, hints);
} catch (ReaderException re) {
} catch (ReaderException const& re) {
// continue
}

View file

@ -44,7 +44,7 @@ void GenericMultipleBarcodeReader::doDecodeMultiple(Ref<BinaryBitmap> image,
Ref<Result> result;
try {
result = delegate_.decode(image, hints);
} catch (ReaderException re) {
} catch (ReaderException const& re) {
return;
}
bool alreadyFound = false;

View file

@ -43,7 +43,7 @@ std::vector<Ref<Result> > QRCodeMultiReader::decodeMultiple(Ref<BinaryBitmap> im
// result->putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult->getByteSegments());
// result->putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult->getECLevel().toString());
results.push_back(result);
} catch (ReaderException re) {
} catch (ReaderException const& re) {
// ignore and continue
}
}

View file

@ -34,7 +34,7 @@ std::vector<Ref<DetectorResult> > MultiDetector::detectMulti(DecodeHints hints){
for(unsigned int i = 0; i < info.size(); i++){
try{
result.push_back(processFinderPatternInfo(info[i]));
} catch (ReaderException e){
} catch (ReaderException const& e){
// ignore
}
}

View file

@ -15,7 +15,8 @@
* limitations under the License.
*/
#include "CodaBarReader.h"
#include <zxing/ZXing.h>
#include <zxing/oned/CodaBarReader.h>
#include <zxing/oned/OneDResultPoint.h>
#include <zxing/common/Array.h>
#include <zxing/ReaderException.h>
@ -77,6 +78,7 @@ using namespace std;
Ref<Result> CodaBarReader::decodeRow(int rowNumber,
Ref<BitArray> row) {
// cerr << "cbr " << rowNumber << " " << *row << endl;
setCounters(row);
int startOffset = findStartPattern();
@ -86,7 +88,7 @@ Ref<Result> CodaBarReader::decodeRow(int rowNumber,
do {
int charOffset = toNarrowWidePattern(nextStart);
if (charOffset == -1) {
throw NotFoundException::getNotFoundInstance();
throw NotFoundException();
}
// Hack: We store the position in the alphabet table into a
// StringBuilder, so that we can access the decoded patterns in
@ -111,7 +113,7 @@ Ref<Result> CodaBarReader::decodeRow(int rowNumber,
// otherwise this is probably a false positive. The exception is if we are
// at the end of the row. (I.e. the barcode barely fits.)
if (nextStart < counterLength && trailingWhitespace < lastPatternSize / 2) {
throw NotFoundException::getNotFoundInstance();
throw NotFoundException();
}
validatePattern(startOffset);
@ -123,17 +125,17 @@ Ref<Result> CodaBarReader::decodeRow(int rowNumber,
// Ensure a valid start and end character
char startchar = decodeRowResult[0];
if (!arrayContains(STARTEND_ENCODING, startchar)) {
throw NotFoundException::getNotFoundInstance();
throw NotFoundException();
}
char endchar = decodeRowResult[decodeRowResult.length() - 1];
if (!arrayContains(STARTEND_ENCODING, endchar)) {
throw NotFoundException::getNotFoundInstance();
throw NotFoundException();
}
// remove stop/start characters character and check if a long enough string is contained
if ((int)decodeRowResult.length() <= MIN_CHARACTER_LENGTH) {
// Almost surely a false positive ( start + stop + at least 1 character)
throw NotFoundException::getNotFoundInstance();
throw NotFoundException();
}
decodeRowResult.erase(decodeRowResult.length() - 1, 1);
@ -155,13 +157,10 @@ decodeRowResult.erase(0, 1);
resultPoints[1] =
Ref<OneDResultPoint>(new OneDResultPoint(right, (float) rowNumber));
return Ref<Result>(
new Result(
Ref<String>(new String(decodeRowResult)),
return Ref<Result>(new Result(Ref<String>(new String(decodeRowResult)),
ArrayRef<char>(),
resultPoints,
BarcodeFormat::CODABAR)
);
BarcodeFormat::CODABAR));
}
void CodaBarReader::validatePattern(int start) {
@ -214,7 +213,7 @@ void CodaBarReader::validatePattern(int start) {
int category = (j & 1) + (pattern & 1) * 2;
int size = counters[pos + j] << INTEGER_MATH_SHIFT;
if (size < mins[category] || size > maxes[category]) {
throw NotFoundException::getNotFoundInstance();
throw NotFoundException();
}
pattern >>= 1;
}
@ -237,7 +236,7 @@ void CodaBarReader::setCounters(Ref<BitArray> row) {
int i = row->getNextUnset(0);
int end = row->getSize();
if (i >= end) {
throw NotFoundException::getNotFoundInstance();
throw NotFoundException();
}
bool isWhite = true;
int count = 0;
@ -277,49 +276,59 @@ int CodaBarReader::findStartPattern() {
}
}
}
throw NotFoundException::getNotFoundInstance();
throw NotFoundException();
}
bool CodaBarReader::arrayContains(char const array[], char key) {
return index(array, key) != 0;
}
// Assumes that counters[position] is a bar.
int CodaBarReader::toNarrowWidePattern(int position) {
int end = position + 7;
if (end >= counterLength) {
return -1;
}
// First element is for bars, second is for spaces.
vector<int> maxes (2, 0);
vector<int> mins (2, std::numeric_limits<int>::max());
vector<int> thresholds (2, 0);
for (int i = 0; i < 2; i++) {
for (int j = position + i; j < end; j += 2) {
if (counters[j] < mins[i]) {
mins[i] = counters[j];
vector<int>& theCounters = counters;
int maxBar = 0;
int minBar = std::numeric_limits<int>::max();
for (int j = position; j < end; j += 2) {
int currentCounter = theCounters[j];
if (currentCounter < minBar) {
minBar = currentCounter;
}
if (counters[j] > maxes[i]) {
maxes[i] = counters[j];
if (currentCounter > maxBar) {
maxBar = currentCounter;
}
}
thresholds[i] = (mins[i] + maxes[i]) / 2;
int thresholdBar = (minBar + maxBar) / 2;
int maxSpace = 0;
int minSpace = std::numeric_limits<int>::max();
for (int j = position + 1; j < end; j += 2) {
int currentCounter = theCounters[j];
if (currentCounter < minSpace) {
minSpace = currentCounter;
}
if (currentCounter > maxSpace) {
maxSpace = currentCounter;
}
}
int thresholdSpace = (minSpace + maxSpace) / 2;
int bitmask = 1 << 7;
int pattern = 0;
for (int i = 0; i < 7; i++) {
int barOrSpace = i & 1;
int threshold = (i & 1) == 0 ? thresholdBar : thresholdSpace;
bitmask >>= 1;
if (counters[position + i] > thresholds[barOrSpace]) {
if (theCounters[position + i] > threshold) {
pattern |= bitmask;
}
}
for (int i = 0;
i < (int)(sizeof(CHARACTER_ENCODINGS)/sizeof(CHARACTER_ENCODINGS[0]));
i++) {
for (int i = 0; i < ZXING_ARRAY_LEN(CHARACTER_ENCODINGS); i++) {
if (CHARACTER_ENCODINGS[i] == pattern) {
return i;
}

View file

@ -70,7 +70,7 @@ Ref<Result> Code93Reader::decodeRow(int rowNumber, Ref<BitArray> row) {
recordPattern(row, nextStart, counters);
int pattern = toPattern(counters);
if (pattern < 0) {
throw NotFoundException::getNotFoundInstance();
throw NotFoundException();
}
decodedChar = patternToChar(pattern);
result.append(1, decodedChar);
@ -85,12 +85,12 @@ Ref<Result> Code93Reader::decodeRow(int rowNumber, Ref<BitArray> row) {
// Should be at least one more black module
if (nextStart == end || !row->get(nextStart)) {
throw NotFoundException::getNotFoundInstance();
throw NotFoundException();
}
if (result.length() < 2) {
// false positive -- need at least 2 checksum digits
throw NotFoundException::getNotFoundInstance();
throw NotFoundException();
}
checkChecksums(result);
@ -147,7 +147,7 @@ Code93Reader::Range Code93Reader::findAsteriskPattern(Ref<BitArray> row) {
isWhite = !isWhite;
}
}
throw NotFoundException::getNotFoundInstance();
throw NotFoundException();
}
int Code93Reader::toPattern(vector<int>& counters) {
@ -183,7 +183,7 @@ char Code93Reader::patternToChar(int pattern) {
return ALPHABET[i];
}
}
throw NotFoundException::getNotFoundInstance();
throw NotFoundException();
}
Ref<String> Code93Reader::decodeExtended(string const& encoded) {

View file

@ -34,12 +34,6 @@ EAN13Reader::EAN13Reader() : decodeMiddleCounters(4, 0) { }
int EAN13Reader::decodeMiddle(Ref<BitArray> row,
Range const& startRange,
std::string& resultString) {
if (false) {
std::cerr << "ba "
<< startRange[0] << " "
<< startRange[1] << " "
<< *row << std::endl;
}
vector<int>& counters (decodeMiddleCounters);
counters.clear();
counters.resize(4);
@ -83,7 +77,7 @@ void EAN13Reader::determineFirstDigit(std::string& resultString, int lgPatternFo
return;
}
}
throw NotFoundException::getNotFoundInstance();
throw NotFoundException();
}
zxing::BarcodeFormat EAN13Reader::getBarcodeFormat(){

View file

@ -15,7 +15,8 @@
* limitations under the License.
*/
#include "ITFReader.h"
#include <zxing/ZXing.h>
#include <zxing/oned/ITFReader.h>
#include <zxing/oned/OneDResultPoint.h>
#include <zxing/common/Array.h>
#include <zxing/ReaderException.h>
@ -107,6 +108,7 @@ Ref<Result> ITFReader::decodeRow(int rowNumber, Ref<BitArray> row) {
break;
}
}
if (!lengthOK) {
throw FormatException();
}
@ -114,6 +116,7 @@ Ref<Result> ITFReader::decodeRow(int rowNumber, Ref<BitArray> row) {
ArrayRef< Ref<ResultPoint> > resultPoints(2);
resultPoints[0] = Ref<OneDResultPoint>(new OneDResultPoint(startRange[1], (float) rowNumber));
resultPoints[1] = Ref<OneDResultPoint>(new OneDResultPoint(endRange[0], (float) rowNumber));
return Ref<Result>(new Result(resultString, ArrayRef<char>(), resultPoints, BarcodeFormat::ITF));
}
@ -227,21 +230,18 @@ ITFReader::Range ITFReader::decodeEnd(Ref<BitArray> row) {
* @throws ReaderException if the quiet zone cannot be found, a ReaderException is thrown.
*/
void ITFReader::validateQuietZone(Ref<BitArray> row, int startPattern) {
(void)row;
(void)startPattern;
//#pragma mark needs some corrections
// int quietCount = narrowLineWidth * 10; // expect to find this many pixels of quiet zone
//
// for (int i = startPattern - 1; quietCount > 0 && i >= 0; i--) {
// if (row->get(i)) {
// break;
// }
// quietCount--;
// }
// if (quietCount != 0) {
// // Unable to find the necessary number of quiet zone pixels.
// throw ReaderException("Unable to find the necessary number of quiet zone pixels");
// }
int quietCount = this->narrowLineWidth * 10; // expect to find this many pixels of quiet zone
for (int i = startPattern - 1; quietCount > 0 && i >= 0; i--) {
if (row->get(i)) {
break;
}
quietCount--;
}
if (quietCount != 0) {
// Unable to find the necessary number of quiet zone pixels.
throw NotFoundException();
}
}
/**
@ -253,15 +253,9 @@ void ITFReader::validateQuietZone(Ref<BitArray> row, int startPattern) {
*/
int ITFReader::skipWhiteSpace(Ref<BitArray> row) {
int width = row->getSize();
int endStart = 0;
while (endStart < width) {
if (row->get(endStart)) {
break;
}
endStart++;
}
int endStart = row->getNextSet(0);
if (endStart == width) {
throw ReaderException("");
throw NotFoundException();
}
return endStart;
}
@ -281,7 +275,7 @@ ITFReader::Range ITFReader::findGuardPattern(Ref<BitArray> row,
// TODO: This is very similar to implementation in UPCEANReader. Consider if they can be
// merged to a single method.
int patternLength = pattern.size();
vector<int> counters(patternLength, 0);
vector<int> counters(patternLength);
int width = row->getSize();
bool isWhite = false;

View file

@ -18,8 +18,8 @@
* limitations under the License.
*/
#include "MultiFormatOneDReader.h"
#include <zxing/ZXing.h>
#include <zxing/oned/MultiFormatOneDReader.h>
#include <zxing/oned/MultiFormatUPCEANReader.h>
#include <zxing/oned/Code39Reader.h>
#include <zxing/oned/Code128Reader.h>
@ -84,15 +84,11 @@ Ref<Result> MultiFormatOneDReader::decodeRow(int rowNumber, Ref<BitArray> row) {
for (int i = 0; i < size; i++) {
OneDReader* reader = readers[i];
try {
// std::cerr << "v 1 " << typeid(*reader).name() << " " << rowNumber << std::endl;
Ref<Result> result = reader->decodeRow(rowNumber, row);
// std::cerr << "^ 1 " << typeid(*reader).name() << " " << rowNumber << std::endl;
return result;
} catch (ReaderException const& re) {
// std::cerr << "^ * " << typeid(*reader).name() << " " << rowNumber << std::endl;
// continue
}
}
// std::cerr << "throwing nfe" << std::endl;
throw NotFoundException();
}

View file

@ -17,8 +17,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "MultiFormatUPCEANReader.h"
#include <zxing/ZXing.h>
#include <zxing/oned/MultiFormatUPCEANReader.h>
#include <zxing/oned/EAN13Reader.h>
#include <zxing/oned/EAN8Reader.h>
#include <zxing/oned/UPCEReader.h>
@ -59,12 +60,10 @@ MultiFormatUPCEANReader::MultiFormatUPCEANReader(DecodeHints hints) : readers()
Ref<Result> MultiFormatUPCEANReader::decodeRow(int rowNumber, Ref<BitArray> row) {
// Compute this location once and reuse it on multiple implementations
UPCEANReader::Range startGuardPattern = UPCEANReader::findStartGuardPattern(row);
// std::cerr << "sgp " << startGuardPattern[0] << " " << startGuardPattern[1] << std::endl;
for (int i = 0, e = readers.size(); i < e; i++) {
Ref<UPCEANReader> reader = readers[i];
Ref<Result> result;
try {
// std::cerr << typeid(*reader).name() << " " << rowNumber << std::endl;
result = reader->decodeRow(rowNumber, row, startGuardPattern);
} catch (ReaderException const& re) {
continue;

View file

@ -18,7 +18,8 @@
* limitations under the License.
*/
#include "OneDReader.h"
#include <zxing/ZXing.h>
#include <zxing/oned/OneDReader.h>
#include <zxing/ReaderException.h>
#include <zxing/oned/OneDResultPoint.h>
#include <zxing/NotFoundException.h>

View file

@ -18,7 +18,8 @@
* limitations under the License.
*/
#include "UPCEANReader.h"
#include <zxing/ZXing.h>
#include <zxing/oned/UPCEANReader.h>
#include <zxing/oned/OneDResultPoint.h>
#include <zxing/ReaderException.h>
#include <zxing/NotFoundException.h>
@ -116,13 +117,8 @@ Ref<Result> UPCEANReader::decodeRow(int rowNumber, Ref<BitArray> row) {
Ref<Result> UPCEANReader::decodeRow(int rowNumber,
Ref<BitArray> row,
Range const& startGuardRange) {
if (false) {
std::cerr << "dR " << rowNumber << " " << *row << " "
<< startGuardRange[0] << " " << startGuardRange[1] << std::endl;
}
string& result = decodeRowStringBuffer;
result.clear();
// cerr << "drx " << rowNumber << endl;
int endStart = decodeMiddle(row, startGuardRange, result);
Range endRange = decodeEnd(row, endStart);

View file

@ -15,7 +15,8 @@
* limitations under the License.
*/
#include "UPCEReader.h"
#include <zxing/ZXing.h>
#include <zxing/oned/UPCEReader.h>
#include <zxing/ReaderException.h>
using std::string;

View file

@ -365,7 +365,7 @@ DecodedBitStreamParser::decode(ArrayRef<char> bytes,
fc1InEffect = true;
} else if (mode == &Mode::STRUCTURED_APPEND) {
if (bits.available() < 16) {
throw new FormatException();
throw FormatException();
}
// not really supported; all we do is ignore it
// Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue

View file

@ -96,7 +96,7 @@ void ReedSolomonTest::testTooManyErrors() {
checkQRRSDecode(received);
cout << "expected exception!\n";
CPPUNIT_FAIL("should not happen!");
} catch (ReedSolomonException e) {
} catch (ReedSolomonException const& e) {
// expected
} catch (...) {
CPPUNIT_FAIL("unexpected exception!");

View file

@ -39,7 +39,7 @@ void ErrorCorrectionLevelTest::testForBits() {
try {
ErrorCorrectionLevel::forBits(4);
CPPUNIT_FAIL("should have thrown an exception");
} catch (zxing::ReaderException ex) {
} catch (zxing::ReaderException const& ex) {
// expected
}
}

View file

@ -56,7 +56,7 @@ void VersionTest::testVersionForNumber() {
try {
Version::getVersionForNumber(0);
CPPUNIT_FAIL("Should have thrown an exception");
} catch (zxing::ReaderException re) {
} catch (zxing::ReaderException const& re) {
// good
}
for (int i = 1; i <= 40; i++) {

View file

@ -35,7 +35,7 @@ void ModeTest::testForBits() {
try {
Mode::forBits(0x10);
CPPUNIT_FAIL("should have thrown an exception");
} catch (zxing::ReaderException ex) {
} catch (zxing::ReaderException const& ex) {
// expected
}
}

View file

@ -98,16 +98,16 @@ int test_image(Image& image, bool hybrid, string expected = "") {
cell_result = result->getText()->getText();
result_format = BarcodeFormat::barcodeFormatNames[result->getBarcodeFormat()];
res = 0;
} catch (ReaderException e) {
} catch (ReaderException const& e) {
cell_result = "zxing::ReaderException: " + string(e.what());
res = -2;
} catch (zxing::IllegalArgumentException& e) {
} catch (zxing::IllegalArgumentException const& e) {
cell_result = "zxing::IllegalArgumentException: " + string(e.what());
res = -3;
} catch (zxing::Exception& e) {
} catch (zxing::Exception const& e) {
cell_result = "zxing::Exception: " + string(e.what());
res = -4;
} catch (std::exception& e) {
} catch (std::exception const& e) {
cell_result = "std::exception: " + string(e.what());
res = -5;
}
@ -162,16 +162,16 @@ int test_image_multi(Image& image, bool hybrid){
Ref<BinaryBitmap> binary(new BinaryBitmap(binarizer));
results = decodeMultiple(binary, hints);
res = 0;
} catch (ReaderException e) {
} catch (ReaderException const& e) {
cell_result = "zxing::ReaderException: " + string(e.what());
res = -2;
} catch (zxing::IllegalArgumentException& e) {
} catch (zxing::IllegalArgumentException const& e) {
cell_result = "zxing::IllegalArgumentException: " + string(e.what());
res = -3;
} catch (zxing::Exception& e) {
} catch (zxing::Exception const& e) {
cell_result = "zxing::Exception: " + string(e.what());
res = -4;
} catch (std::exception& e) {
} catch (std::exception const& e) {
cell_result = "std::exception: " + string(e.what());
res = -5;
}