diff --git a/core/build.xml b/core/build.xml
index 064fc6676..4e3846d69 100644
--- a/core/build.xml
+++ b/core/build.xml
@@ -34,7 +34,8 @@
debug="true"
deprecation="true"
fork="true"
- includeantruntime="false">
+ includeantruntime="false"
+ encoding="UTF-8">
@@ -51,7 +52,8 @@
destdir="build-test"
debug="true"
deprecation="true"
- includeantruntime="false">
+ includeantruntime="false"
+ encoding="UTF-8">
diff --git a/core/test/src/com/google/zxing/aztec/AztecBlackBox2TestCase.java b/core/test/src/com/google/zxing/aztec/AztecBlackBox2TestCase.java
index fc1d9b92e..82cf64a1f 100644
--- a/core/test/src/com/google/zxing/aztec/AztecBlackBox2TestCase.java
+++ b/core/test/src/com/google/zxing/aztec/AztecBlackBox2TestCase.java
@@ -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);
}
}
diff --git a/cpp/.gitignore b/cpp/.gitignore
index ad5eebcd7..9d49746ce 100644
--- a/cpp/.gitignore
+++ b/cpp/.gitignore
@@ -3,4 +3,5 @@
xcuserdata
callgrind.out.*
contents.xcworkspacedata
-*.pyc
\ No newline at end of file
+*.pyc
+/.rbenv-version
\ No newline at end of file
diff --git a/cpp/.valgrind.supp b/cpp/.valgrind.supp
index 7884f7f5d..2c9ba11e6 100644
--- a/cpp/.valgrind.supp
+++ b/cpp/.valgrind.supp
@@ -34,4 +34,47 @@
fun:malloc_zone_calloc
...
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
}
\ No newline at end of file
diff --git a/cpp/SConscript b/cpp/SConscript
index 40976da12..9db8f15e6 100644
--- a/cpp/SConscript
+++ b/cpp/SConscript
@@ -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"
diff --git a/cpp/core/src/zxing/BarcodeFormat.h b/cpp/core/src/zxing/BarcodeFormat.h
index cb2bffb05..5c5a00f48 100644
--- a/cpp/core/src/zxing/BarcodeFormat.h
+++ b/cpp/core/src/zxing/BarcodeFormat.h
@@ -44,7 +44,7 @@ public:
RSS_EXPANDED,
UPC_A,
UPC_E,
- UPC_EAN_EXTENSION,
+ UPC_EAN_EXTENSION
};
BarcodeFormat(Value v) : value(v) {}
diff --git a/cpp/core/src/zxing/Exception.cpp b/cpp/core/src/zxing/Exception.cpp
index ca8c21d05..2d912a2cf 100644
--- a/cpp/core/src/zxing/Exception.cpp
+++ b/cpp/core/src/zxing/Exception.cpp
@@ -20,21 +20,24 @@
*/
+#include
#include
+#include
-namespace zxing {
+using zxing::Exception;
-Exception::Exception() {}
-
-Exception::Exception(const char *msg) :
- message(msg) {
-}
-
-const char* Exception::what() const throw() {
- return message.c_str();
-}
-
-Exception::~Exception() throw() {
+void Exception::deleteMessage() {
+ delete [] message;
}
+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);
+ }
+ }
+ return message;
}
diff --git a/cpp/core/src/zxing/Exception.h b/cpp/core/src/zxing/Exception.h
index 67dd97abe..c7aa1b3de 100644
--- a/cpp/core/src/zxing/Exception.h
+++ b/cpp/core/src/zxing/Exception.h
@@ -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
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__
diff --git a/cpp/core/src/zxing/MultiFormatReader.cpp b/cpp/core/src/zxing/MultiFormatReader.cpp
index d60c38ec6..54127a15f 100644
--- a/cpp/core/src/zxing/MultiFormatReader.cpp
+++ b/cpp/core/src/zxing/MultiFormatReader.cpp
@@ -20,6 +20,7 @@
* limitations under the License.
*/
+#include
#include
#include
#include
@@ -111,7 +112,6 @@ void MultiFormatReader::setHints(DecodeHints hints) {
Ref MultiFormatReader::decodeInternal(Ref 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
diff --git a/cpp/core/src/zxing/NotFoundException.cpp b/cpp/core/src/zxing/NotFoundException.cpp
deleted file mode 100644
index b35d6e040..000000000
--- a/cpp/core/src/zxing/NotFoundException.cpp
+++ /dev/null
@@ -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
-
-using zxing::NotFoundException;
-
-NotFoundException::NotFoundException() {}
-
-NotFoundException::NotFoundException(const char *msg)
- : ReaderException(msg) {}
-
-NotFoundException::~NotFoundException() throw() {}
-
-
-NotFoundException const&
-NotFoundException::getNotFoundInstance() {
- static NotFoundException instance;
- return instance;
-}
diff --git a/cpp/core/src/zxing/NotFoundException.h b/cpp/core/src/zxing/NotFoundException.h
index 4bdccdfeb..4fd97677e 100644
--- a/cpp/core/src/zxing/NotFoundException.h
+++ b/cpp/core/src/zxing/NotFoundException.h
@@ -22,15 +22,14 @@
#include
namespace zxing {
-
- class NotFoundException : public ReaderException {
- public:
- NotFoundException();
- NotFoundException(const char *msg);
- ~NotFoundException() throw();
-
- static NotFoundException const& getNotFoundInstance();
- };
-
+ class NotFoundException;
}
+
+class zxing::NotFoundException : public ReaderException {
+public:
+ NotFoundException() throw() {}
+ NotFoundException(const char *msg) throw() : ReaderException(msg) {}
+ ~NotFoundException() throw() {}
+};
+
#endif // __NOT_FOUND_EXCEPTION_H__
diff --git a/cpp/core/src/zxing/ReaderException.cpp b/cpp/core/src/zxing/ReaderException.cpp
deleted file mode 100644
index 07d4bb697..000000000
--- a/cpp/core/src/zxing/ReaderException.cpp
+++ /dev/null
@@ -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
-
-namespace zxing {
-
-ReaderException::ReaderException() {}
-
-ReaderException::ReaderException(const char *msg) :
- Exception(msg) {
-}
-
-ReaderException::~ReaderException() throw() {
-}
-
-}
diff --git a/cpp/core/src/zxing/ReaderException.h b/cpp/core/src/zxing/ReaderException.h
index d54ae62b4..cf726f895 100644
--- a/cpp/core/src/zxing/ReaderException.h
+++ b/cpp/core/src/zxing/ReaderException.h
@@ -23,13 +23,14 @@
#include
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__
diff --git a/cpp/core/src/zxing/ZXing.h b/cpp/core/src/zxing/ZXing.h
new file mode 100644
index 000000000..a8fbfb925
--- /dev/null
+++ b/cpp/core/src/zxing/ZXing.h
@@ -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
+#include
+
+using std::cout;
+using std::cerr;
+using std::endl;
+using std::flush;
+using std::string;
+using std::ostream;
+
+#if ZXING_DEBUG_TIMER
+
+#include
+
+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
diff --git a/cpp/core/src/zxing/aztec/AztecDetectorResult.cpp b/cpp/core/src/zxing/aztec/AztecDetectorResult.cpp
index 5f29cfb92..53c1b3572 100644
--- a/cpp/core/src/zxing/aztec/AztecDetectorResult.cpp
+++ b/cpp/core/src/zxing/aztec/AztecDetectorResult.cpp
@@ -32,7 +32,7 @@ AztecDetectorResult::AztecDetectorResult(Ref bits,
compact_(compact),
nbDatablocks_(nbDatablocks),
nbLayers_(nbLayers) {
- };
+ }
bool AztecDetectorResult::isCompact() {
return compact_;
diff --git a/cpp/core/src/zxing/aztec/AztecReader.cpp b/cpp/core/src/zxing/aztec/AztecReader.cpp
index 96aa2d62e..8620e5ce1 100644
--- a/cpp/core/src/zxing/aztec/AztecReader.cpp
+++ b/cpp/core/src/zxing/aztec/AztecReader.cpp
@@ -30,7 +30,7 @@ using zxing::aztec::AztecReader;
AztecReader::AztecReader() : decoder_() {
// nothing
-};
+}
Ref AztecReader::decode(Ref image) {
Detector detector(image->getBlackMatrix());
diff --git a/cpp/core/src/zxing/aztec/decoder/Decoder.cpp b/cpp/core/src/zxing/aztec/decoder/Decoder.cpp
index 44ee40227..b1d2e280f 100644
--- a/cpp/core/src/zxing/aztec/decoder/Decoder.cpp
+++ b/cpp/core/src/zxing/aztec/decoder/Decoder.cpp
@@ -328,13 +328,12 @@ Ref Decoder::correctBits(Ref 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());
}
diff --git a/cpp/core/src/zxing/aztec/detector/Detector.cpp b/cpp/core/src/zxing/aztec/detector/Detector.cpp
index dfca21ec3..ba1a23385 100644
--- a/cpp/core/src/zxing/aztec/detector/Detector.cpp
+++ b/cpp/core/src/zxing/aztec/detector/Detector.cpp
@@ -205,7 +205,7 @@ void Detector::correctParameterData(Ref 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 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 Detector::getMatrixCenter() {
pointC = cornerPoints[2];
pointD = cornerPoints[3];
- } catch (NotFoundException e) {
+ } catch (NotFoundException const& e) {
pointA = getFirstDifferent(Ref(new Point(cx+15/2, cy-15/2)), false, 1, -1)->toResultPoint();
pointB = getFirstDifferent(Ref(new Point(cx+15/2, cy+15/2)), false, 1, 1)->toResultPoint();
diff --git a/cpp/core/src/zxing/common/Array.h b/cpp/core/src/zxing/common/Array.h
index 3f879a946..57a63f405 100644
--- a/cpp/core/src/zxing/common/Array.h
+++ b/cpp/core/src/zxing/common/Array.h
@@ -30,7 +30,6 @@
#include
-
namespace zxing {
template class Array : public Counted {
diff --git a/cpp/core/src/zxing/common/BitArray.cpp b/cpp/core/src/zxing/common/BitArray.cpp
index 478de7b5f..e4bb85a40 100644
--- a/cpp/core/src/zxing/common/BitArray.cpp
+++ b/cpp/core/src/zxing/common/BitArray.cpp
@@ -106,11 +106,11 @@ bool BitArray::isRange(int start, int end, bool value) {
}
vector& BitArray::getBitArray() {
- return bits;
+ return bits->values();
}
void BitArray::reverse() {
- vector newBits(bits.size());
+ ArrayRef newBits(bits.size());
int size = this->size;
for (int i = 0; i < size; i++) {
if (get(size - i - 1)) {
diff --git a/cpp/core/src/zxing/common/BitArray.h b/cpp/core/src/zxing/common/BitArray.h
index 2832647a6..a728d5496 100644
--- a/cpp/core/src/zxing/common/BitArray.h
+++ b/cpp/core/src/zxing/common/BitArray.h
@@ -20,6 +20,7 @@
#include
#include
+#include
#include
#include
#include
@@ -43,7 +44,7 @@ public:
private:
int size;
- std::vector bits;
+ ArrayRef bits;
static const int logBits = ZX_LOG_DIGITS(bitsPerWord);
static const int bitsMask = (1 << logBits) - 1;
diff --git a/cpp/core/src/zxing/common/BitMatrix.cpp b/cpp/core/src/zxing/common/BitMatrix.cpp
index 2360d9d43..a03eb42fb 100644
--- a/cpp/core/src/zxing/common/BitMatrix.cpp
+++ b/cpp/core/src/zxing/common/BitMatrix.cpp
@@ -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;
diff --git a/cpp/core/src/zxing/common/reedsolomon/GenericGF.cpp b/cpp/core/src/zxing/common/reedsolomon/GenericGF.cpp
index 22a81f0b9..f7b779d1a 100644
--- a/cpp/core/src/zxing/common/reedsolomon/GenericGF.cpp
+++ b/cpp/core/src/zxing/common/reedsolomon/GenericGF.cpp
@@ -28,67 +28,67 @@ using zxing::GenericGF;
using zxing::GenericGFPoly;
using zxing::Ref;
-Ref GenericGF::QR_CODE_FIELD_256(new GenericGF(0x011D, 256));
-Ref GenericGF::DATA_MATRIX_FIELD_256(new GenericGF(0x012D, 256));
-Ref GenericGF::AZTEC_PARAM(new GenericGF(0x13, 16));
-Ref GenericGF::AZTEC_DATA_6(new GenericGF(0x43, 64));
-Ref GenericGF::AZTEC_DATA_8(GenericGF::DATA_MATRIX_FIELD_256);
-Ref GenericGF::AZTEC_DATA_10(new GenericGF(0x409, 1024));
-Ref GenericGF::AZTEC_DATA_12(new GenericGF(0x1069, 4096));
+Ref GenericGF::AZTEC_DATA_12(new GenericGF(0x1069, 4096, 1));
+Ref GenericGF::AZTEC_DATA_10(new GenericGF(0x409, 1024, 1));
+Ref GenericGF::AZTEC_DATA_6(new GenericGF(0x43, 64, 1));
+Ref GenericGF::AZTEC_PARAM(new GenericGF(0x13, 16, 1));
+Ref GenericGF::QR_CODE_FIELD_256(new GenericGF(0x011D, 256, 0));
+Ref GenericGF::DATA_MATRIX_FIELD_256(new GenericGF(0x012D, 256, 1));
+Ref GenericGF::AZTEC_DATA_8 = DATA_MATRIX_FIELD_256;
+Ref 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(size_, (const int) 0);
- //logTable_ = std::vector(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(new GenericGFPoly(Ref(this), ArrayRef(new Array(1))));
- zero_->getCoefficients()[0] = 0;
- one_ = Ref(new GenericGFPoly(Ref(this), ArrayRef(new Array(1))));
- one_->getCoefficients()[0] = 1;
-
- initialized_ = true;
+ //logTable[0] == 0 but this should never be used
+ zero =
+ Ref(new GenericGFPoly(Ref(this), ArrayRef(new Array(1))));
+ zero->getCoefficients()[0] = 0;
+ one =
+ Ref(new GenericGFPoly(Ref(this), ArrayRef(new Array(1))));
+ one->getCoefficients()[0] = 1;
+ initialized = true;
}
void GenericGF::checkInit() {
- if (!initialized_) {
+ if (!initialized) {
initialize();
}
}
Ref GenericGF::getZero() {
checkInit();
- return zero_;
+ return zero;
}
Ref GenericGF::getOne() {
checkInit();
- return one_;
+ return one;
}
Ref GenericGF::buildMonomial(int degree, int coefficient) {
@@ -98,12 +98,11 @@ Ref GenericGF::buildMonomial(int degree, int coefficient) {
throw IllegalArgumentException("Degree must be non-negative");
}
if (coefficient == 0) {
- return zero_;
+ return zero;
}
ArrayRef coefficients(new Array(degree + 1));
coefficients[0] = coefficient;
- //return new GenericGFPoly(this, coefficients);
return Ref(new GenericGFPoly(Ref(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;
}
diff --git a/cpp/core/src/zxing/common/reedsolomon/GenericGF.h b/cpp/core/src/zxing/common/reedsolomon/GenericGF.h
index 6f76a5865..3a068f863 100644
--- a/cpp/core/src/zxing/common/reedsolomon/GenericGF.h
+++ b/cpp/core/src/zxing/common/reedsolomon/GenericGF.h
@@ -31,13 +31,14 @@ namespace zxing {
class GenericGF : public Counted {
private:
- std::vector expTable_;
- std::vector logTable_;
- Ref zero_;
- Ref one_;
- int size_;
- int primitive_;
- bool initialized_;
+ std::vector expTable;
+ std::vector logTable;
+ Ref zero;
+ Ref one;
+ int size;
+ int primitive;
+ int generatorBase;
+ bool initialized;
void initialize();
void checkInit();
@@ -50,12 +51,14 @@ namespace zxing {
static Ref AZTEC_PARAM;
static Ref QR_CODE_FIELD_256;
static Ref DATA_MATRIX_FIELD_256;
+ static Ref MAXICODE_FIELD_64;
- GenericGF(int primitive, int size);
+ GenericGF(int primitive, int size, int b);
Ref getZero();
Ref getOne();
int getSize();
+ int getGeneratorBase();
Ref 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
-
};
}
diff --git a/cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.cpp b/cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.cpp
index 3f36c6288..a3959b2ad 100644
--- a/cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.cpp
+++ b/cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.cpp
@@ -33,9 +33,7 @@ using zxing::ArrayRef;
using zxing::ReedSolomonDecoder;
using zxing::GenericGFPoly;
-ReedSolomonDecoder::ReedSolomonDecoder(Ref fld) :
- field(fld) {
-}
+ReedSolomonDecoder::ReedSolomonDecoder(Ref field_) : field(field_) {}
ReedSolomonDecoder::~ReedSolomonDecoder() {
}
@@ -43,10 +41,9 @@ ReedSolomonDecoder::~ReedSolomonDecoder() {
void ReedSolomonDecoder::decode(ArrayRef received, int twoS) {
Ref poly(new GenericGFPoly(field, received));
ArrayRef 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 received, int twoS) {
Ref sigma = sigmaOmega[0];
Ref omega = sigmaOmega[1];
ArrayRef errorLocations = findErrorLocations(sigma);
- ArrayRef errorMagitudes = findErrorMagnitudes(omega, errorLocations, dataMatrix);
+ ArrayRef 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[ > ReedSolomonDecoder::runEuclideanAlgorithm(Ref tLast(field->getZero());
Ref t(field->getOne());
-
// Run Euclidean algorithm until r's degree is less than R/2
while (r->getDegree() >= R / 2) {
Ref rLastLast(rLast);
@@ -94,14 +90,13 @@ vector][ > ReedSolomonDecoder::runEuclideanAlgorithm(RefisZero()) {
// Oops, Euclidean algorithm already terminated?
throw ReedSolomonException("r_{i-1} was zero");
}
r = rLastLast;
- Ref q(field->getZero());
+ Ref 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][ > ReedSolomonDecoder::runEuclideanAlgorithm(Refmultiply(tLast)->addOrSubtract(tLastLast);
-
}
int sigmaTildeAtZero = t->getCoefficient(0);
@@ -123,17 +117,6 @@ vector][ > ReedSolomonDecoder::runEuclideanAlgorithm(Refinverse(sigmaTildeAtZero);
Ref sigma(t->multiply(inverse));
Ref omega(r->multiply(inverse));
-
-
-/*
- #ifdef DEBUG
- cout << "t = " << *t << endl;
- cout << "r = " << *r << "\n";
- cout << "sigma = " << *sigma << endl;
- cout << "omega = " << *omega << endl;
- #endif
-*/
-
vector][ > result(2);
result[0] = sigma;
result[1] = omega;
@@ -151,7 +134,6 @@ ArrayRef ReedSolomonDecoder::findErrorLocations(Ref errorLoc
ArrayRef result(new Array(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 ReedSolomonDecoder::findErrorLocations(Ref errorLoc
return result;
}
-ArrayRef ReedSolomonDecoder::findErrorMagnitudes(Ref errorEvaluator, ArrayRef errorLocations, bool dataMatrix) {
+ArrayRef ReedSolomonDecoder::findErrorMagnitudes(Ref errorEvaluator, ArrayRef errorLocations) {
// This is directly applying Forney's Formula
int s = errorLocations.size();
ArrayRef result(new Array(s));
@@ -172,13 +154,14 @@ ArrayRef ReedSolomonDecoder::findErrorMagnitudes(Ref 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);
}
}
diff --git a/cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.h b/cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.h
index 20a417ea3..dc1037750 100644
--- a/cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.h
+++ b/cpp/core/src/zxing/common/reedsolomon/ReedSolomonDecoder.h
@@ -41,7 +41,7 @@ public:
private:
std::vector][ > runEuclideanAlgorithm(Ref a, Ref b, int R);
ArrayRef findErrorLocations(Ref errorLocator);
- ArrayRef findErrorMagnitudes(Ref errorEvaluator, ArrayRef errorLocations, bool dataMatrix);
+ ArrayRef findErrorMagnitudes(Ref errorEvaluator, ArrayRef errorLocations);
};
}
diff --git a/cpp/core/src/zxing/multi/ByQuadrantReader.cpp b/cpp/core/src/zxing/multi/ByQuadrantReader.cpp
index 427278907..d8cf76ede 100644
--- a/cpp/core/src/zxing/multi/ByQuadrantReader.cpp
+++ b/cpp/core/src/zxing/multi/ByQuadrantReader.cpp
@@ -36,28 +36,28 @@ Ref ByQuadrantReader::decode(Ref image, DecodeHints hints)
Ref topLeft = image->crop(0, 0, halfWidth, halfHeight);
try {
return delegate_.decode(topLeft, hints);
- } catch (ReaderException re) {
+ } catch (ReaderException const& re) {
// continue
}
Ref topRight = image->crop(halfWidth, 0, halfWidth, halfHeight);
try {
return delegate_.decode(topRight, hints);
- } catch (ReaderException re) {
+ } catch (ReaderException const& re) {
// continue
}
Ref bottomLeft = image->crop(0, halfHeight, halfWidth, halfHeight);
try {
return delegate_.decode(bottomLeft, hints);
- } catch (ReaderException re) {
+ } catch (ReaderException const& re) {
// continue
}
Ref bottomRight = image->crop(halfWidth, halfHeight, halfWidth, halfHeight);
try {
return delegate_.decode(bottomRight, hints);
- } catch (ReaderException re) {
+ } catch (ReaderException const& re) {
// continue
}
diff --git a/cpp/core/src/zxing/multi/GenericMultipleBarcodeReader.cpp b/cpp/core/src/zxing/multi/GenericMultipleBarcodeReader.cpp
index c80263ed3..e4b42130b 100644
--- a/cpp/core/src/zxing/multi/GenericMultipleBarcodeReader.cpp
+++ b/cpp/core/src/zxing/multi/GenericMultipleBarcodeReader.cpp
@@ -44,7 +44,7 @@ void GenericMultipleBarcodeReader::doDecodeMultiple(Ref image,
Ref result;
try {
result = delegate_.decode(image, hints);
- } catch (ReaderException re) {
+ } catch (ReaderException const& re) {
return;
}
bool alreadyFound = false;
diff --git a/cpp/core/src/zxing/multi/qrcode/QRCodeMultiReader.cpp b/cpp/core/src/zxing/multi/qrcode/QRCodeMultiReader.cpp
index 90cfb0274..bebe6e161 100644
--- a/cpp/core/src/zxing/multi/qrcode/QRCodeMultiReader.cpp
+++ b/cpp/core/src/zxing/multi/qrcode/QRCodeMultiReader.cpp
@@ -43,7 +43,7 @@ std::vector][ > QRCodeMultiReader::decodeMultiple(Ref 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
}
}
diff --git a/cpp/core/src/zxing/multi/qrcode/detector/MultiDetector.cpp b/cpp/core/src/zxing/multi/qrcode/detector/MultiDetector.cpp
index 53f64a24c..ed2bc638b 100644
--- a/cpp/core/src/zxing/multi/qrcode/detector/MultiDetector.cpp
+++ b/cpp/core/src/zxing/multi/qrcode/detector/MultiDetector.cpp
@@ -34,7 +34,7 @@ std::vector][ > 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
}
}
diff --git a/cpp/core/src/zxing/oned/CodaBarReader.cpp b/cpp/core/src/zxing/oned/CodaBarReader.cpp
index a8e0320f5..8fe73c112 100644
--- a/cpp/core/src/zxing/oned/CodaBarReader.cpp
+++ b/cpp/core/src/zxing/oned/CodaBarReader.cpp
@@ -15,7 +15,8 @@
* limitations under the License.
*/
-#include "CodaBarReader.h"
+#include
+#include
#include
#include
#include
@@ -77,6 +78,7 @@ using namespace std;
Ref CodaBarReader::decodeRow(int rowNumber,
Ref row) {
+
// cerr << "cbr " << rowNumber << " " << *row << endl;
setCounters(row);
int startOffset = findStartPattern();
@@ -86,7 +88,7 @@ Ref 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 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,21 +125,21 @@ Ref 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);
-decodeRowResult.erase(0, 1);
+ decodeRowResult.erase(decodeRowResult.length() - 1, 1);
+ decodeRowResult.erase(0, 1);
int runningCount = 0;
for (int i = 0; i < startOffset; i++) {
@@ -155,13 +157,10 @@ decodeRowResult.erase(0, 1);
resultPoints[1] =
Ref(new OneDResultPoint(right, (float) rowNumber));
- return Ref(
- new Result(
- Ref(new String(decodeRowResult)),
- ArrayRef(),
- resultPoints,
- BarcodeFormat::CODABAR)
- );
+ return Ref(new Result(Ref(new String(decodeRowResult)),
+ ArrayRef(),
+ resultPoints,
+ 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 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 maxes (2, 0);
- vector mins (2, std::numeric_limits::max());
- vector 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];
- }
- if (counters[j] > maxes[i]) {
- maxes[i] = counters[j];
- }
+ vector& theCounters = counters;
+
+ int maxBar = 0;
+ int minBar = std::numeric_limits::max();
+ for (int j = position; j < end; j += 2) {
+ int currentCounter = theCounters[j];
+ if (currentCounter < minBar) {
+ minBar = currentCounter;
+ }
+ 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::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;
}
diff --git a/cpp/core/src/zxing/oned/Code93Reader.cpp b/cpp/core/src/zxing/oned/Code93Reader.cpp
index abbc3b50f..d174c32ec 100644
--- a/cpp/core/src/zxing/oned/Code93Reader.cpp
+++ b/cpp/core/src/zxing/oned/Code93Reader.cpp
@@ -70,7 +70,7 @@ Ref Code93Reader::decodeRow(int rowNumber, Ref 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 Code93Reader::decodeRow(int rowNumber, Ref 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 row) {
isWhite = !isWhite;
}
}
- throw NotFoundException::getNotFoundInstance();
+ throw NotFoundException();
}
int Code93Reader::toPattern(vector& counters) {
@@ -183,7 +183,7 @@ char Code93Reader::patternToChar(int pattern) {
return ALPHABET[i];
}
}
- throw NotFoundException::getNotFoundInstance();
+ throw NotFoundException();
}
Ref Code93Reader::decodeExtended(string const& encoded) {
diff --git a/cpp/core/src/zxing/oned/EAN13Reader.cpp b/cpp/core/src/zxing/oned/EAN13Reader.cpp
index 9907f46d3..fbec476aa 100644
--- a/cpp/core/src/zxing/oned/EAN13Reader.cpp
+++ b/cpp/core/src/zxing/oned/EAN13Reader.cpp
@@ -34,12 +34,6 @@ EAN13Reader::EAN13Reader() : decodeMiddleCounters(4, 0) { }
int EAN13Reader::decodeMiddle(Ref row,
Range const& startRange,
std::string& resultString) {
- if (false) {
- std::cerr << "ba "
- << startRange[0] << " "
- << startRange[1] << " "
- << *row << std::endl;
- }
vector& 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(){
diff --git a/cpp/core/src/zxing/oned/ITFReader.cpp b/cpp/core/src/zxing/oned/ITFReader.cpp
index d8a5abe9e..7c529002c 100644
--- a/cpp/core/src/zxing/oned/ITFReader.cpp
+++ b/cpp/core/src/zxing/oned/ITFReader.cpp
@@ -15,7 +15,8 @@
* limitations under the License.
*/
-#include "ITFReader.h"
+#include
+#include
#include
#include
#include
@@ -107,6 +108,7 @@ Ref ITFReader::decodeRow(int rowNumber, Ref row) {
break;
}
}
+
if (!lengthOK) {
throw FormatException();
}
@@ -114,6 +116,7 @@ Ref ITFReader::decodeRow(int rowNumber, Ref row) {
ArrayRef< Ref > resultPoints(2);
resultPoints[0] = Ref(new OneDResultPoint(startRange[1], (float) rowNumber));
resultPoints[1] = Ref(new OneDResultPoint(endRange[0], (float) rowNumber));
+
return Ref(new Result(resultString, ArrayRef(), resultPoints, BarcodeFormat::ITF));
}
@@ -227,21 +230,18 @@ ITFReader::Range ITFReader::decodeEnd(Ref row) {
* @throws ReaderException if the quiet zone cannot be found, a ReaderException is thrown.
*/
void ITFReader::validateQuietZone(Ref 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 row, int startPattern) {
*/
int ITFReader::skipWhiteSpace(Ref 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 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 counters(patternLength, 0);
+ vector counters(patternLength);
int width = row->getSize();
bool isWhite = false;
diff --git a/cpp/core/src/zxing/oned/MultiFormatOneDReader.cpp b/cpp/core/src/zxing/oned/MultiFormatOneDReader.cpp
index a608dd1b0..334106d6a 100644
--- a/cpp/core/src/zxing/oned/MultiFormatOneDReader.cpp
+++ b/cpp/core/src/zxing/oned/MultiFormatOneDReader.cpp
@@ -18,8 +18,8 @@
* limitations under the License.
*/
-#include "MultiFormatOneDReader.h"
-
+#include
+#include
#include
#include
#include
@@ -84,15 +84,11 @@ Ref MultiFormatOneDReader::decodeRow(int rowNumber, Ref 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 = 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();
}
diff --git a/cpp/core/src/zxing/oned/MultiFormatUPCEANReader.cpp b/cpp/core/src/zxing/oned/MultiFormatUPCEANReader.cpp
index c7dce1eff..84b655aa5 100644
--- a/cpp/core/src/zxing/oned/MultiFormatUPCEANReader.cpp
+++ b/cpp/core/src/zxing/oned/MultiFormatUPCEANReader.cpp
@@ -17,8 +17,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "MultiFormatUPCEANReader.h"
+#include
+#include
#include
#include
#include
@@ -59,12 +60,10 @@ MultiFormatUPCEANReader::MultiFormatUPCEANReader(DecodeHints hints) : readers()
Ref MultiFormatUPCEANReader::decodeRow(int rowNumber, Ref 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 reader = readers[i];
Ref result;
try {
- // std::cerr << typeid(*reader).name() << " " << rowNumber << std::endl;
result = reader->decodeRow(rowNumber, row, startGuardPattern);
} catch (ReaderException const& re) {
continue;
diff --git a/cpp/core/src/zxing/oned/OneDReader.cpp b/cpp/core/src/zxing/oned/OneDReader.cpp
index 8e42c7e1d..318ee59a7 100644
--- a/cpp/core/src/zxing/oned/OneDReader.cpp
+++ b/cpp/core/src/zxing/oned/OneDReader.cpp
@@ -18,7 +18,8 @@
* limitations under the License.
*/
-#include "OneDReader.h"
+#include
+#include
#include
#include
#include
diff --git a/cpp/core/src/zxing/oned/UPCEANReader.cpp b/cpp/core/src/zxing/oned/UPCEANReader.cpp
index 923950458..48eab64dd 100644
--- a/cpp/core/src/zxing/oned/UPCEANReader.cpp
+++ b/cpp/core/src/zxing/oned/UPCEANReader.cpp
@@ -18,7 +18,8 @@
* limitations under the License.
*/
-#include "UPCEANReader.h"
+#include
+#include
#include
#include
#include
@@ -116,13 +117,8 @@ Ref UPCEANReader::decodeRow(int rowNumber, Ref row) {
Ref UPCEANReader::decodeRow(int rowNumber,
Ref 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);
@@ -135,7 +131,7 @@ Ref UPCEANReader::decodeRow(int rowNumber,
if (quietEnd >= row->getSize() || !row->isRange(end, quietEnd, false)) {
throw NotFoundException();
}
-
+
Ref resultString (new String(result));
if (!checkChecksum(resultString)) {
throw ChecksumException();
diff --git a/cpp/core/src/zxing/oned/UPCEReader.cpp b/cpp/core/src/zxing/oned/UPCEReader.cpp
index 6a6b963f8..49c515565 100644
--- a/cpp/core/src/zxing/oned/UPCEReader.cpp
+++ b/cpp/core/src/zxing/oned/UPCEReader.cpp
@@ -15,7 +15,8 @@
* limitations under the License.
*/
-#include "UPCEReader.h"
+#include
+#include
#include
using std::string;
diff --git a/cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp b/cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp
index 10ad1f4df..e939a5512 100644
--- a/cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp
+++ b/cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp
@@ -365,7 +365,7 @@ DecodedBitStreamParser::decode(ArrayRef 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
diff --git a/cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.cpp b/cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.cpp
index bd0dcfb24..0828b5917 100644
--- a/cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.cpp
+++ b/cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.cpp
@@ -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!");
diff --git a/cpp/core/tests/src/qrcode/ErrorCorrectionLevelTest.cpp b/cpp/core/tests/src/qrcode/ErrorCorrectionLevelTest.cpp
index 8164de31b..9507ff431 100644
--- a/cpp/core/tests/src/qrcode/ErrorCorrectionLevelTest.cpp
+++ b/cpp/core/tests/src/qrcode/ErrorCorrectionLevelTest.cpp
@@ -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
}
}
diff --git a/cpp/core/tests/src/qrcode/VersionTest.cpp b/cpp/core/tests/src/qrcode/VersionTest.cpp
index 3fcc11ed0..150d251d2 100644
--- a/cpp/core/tests/src/qrcode/VersionTest.cpp
+++ b/cpp/core/tests/src/qrcode/VersionTest.cpp
@@ -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++) {
diff --git a/cpp/core/tests/src/qrcode/decoder/ModeTest.cpp b/cpp/core/tests/src/qrcode/decoder/ModeTest.cpp
index 36a61d2c9..83498951d 100644
--- a/cpp/core/tests/src/qrcode/decoder/ModeTest.cpp
+++ b/cpp/core/tests/src/qrcode/decoder/ModeTest.cpp
@@ -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
}
}
diff --git a/cpp/magick/src/main.cpp b/cpp/magick/src/main.cpp
index 14bdf2087..855573935 100644
--- a/cpp/magick/src/main.cpp
+++ b/cpp/magick/src/main.cpp
@@ -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 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;
}
]