Minor refactorings / code cleanups executed after static code analysis.

This commit is contained in:
Nikos Ftylitakis 2019-11-06 15:02:07 +02:00
parent 3c0d206581
commit 21fd399a78
29 changed files with 71 additions and 59 deletions

View File

@ -179,7 +179,7 @@ ArrayRef<zxing::byte> CameraImageWrapper::getMatrixP() const
return imageBytes; return imageBytes;
} }
zxing::byte CameraImageWrapper::gray(unsigned int r, unsigned int g, unsigned int b) zxing::byte CameraImageWrapper::gray(const unsigned int r, const unsigned int g, const unsigned int b)
{ {
//the values are not masked with (x & 0xFF) because functions qRed, qGreen, qBlue already do it //the values are not masked with (x & 0xFF) because functions qRed, qGreen, qBlue already do it
return R_TO_GREYSCALE[r] + G_TO_GREYSCALE[g] + B_TO_GREYSCALE[b]; return R_TO_GREYSCALE[r] + G_TO_GREYSCALE[g] + B_TO_GREYSCALE[b];

View File

@ -45,7 +45,7 @@ public:
Ref<LuminanceSource> invert() const; Ref<LuminanceSource> invert() const;
Ref<LuminanceSource> rotateCounterClockwise() const; Ref<LuminanceSource> rotateCounterClockwise() const;
inline zxing::byte gray(unsigned int r, unsigned int g, unsigned int b); inline zxing::byte gray(const unsigned int r, const unsigned int g, const unsigned int b);
private: private:
ArrayRef<zxing::byte> getRowP(int y, ArrayRef<zxing::byte> row) const; ArrayRef<zxing::byte> getRowP(int y, ArrayRef<zxing::byte> row) const;

View File

@ -81,7 +81,7 @@ QImage ImageHandler::extractQImage(QObject *imageObj, int offsetX, int offsetY,
if (offsetX || offsetY || width || height) if (offsetX || offsetY || width || height)
return img.copy(offsetX, offsetY, width, height); return img.copy(offsetX, offsetY, width, height);
else
return img; return img;
} }

View File

@ -35,7 +35,7 @@ public:
int width = 0, int height = 0); int width = 0, int height = 0);
public slots: public slots:
void save(QObject *item, const QString &path, void save(QObject *imageObj, const QString &path,
const int offsetX = 0, const int offsetY = 0, const int offsetX = 0, const int offsetY = 0,
const int width = 0, const int height = 0); const int width = 0, const int height = 0);
private: private:

View File

@ -340,7 +340,7 @@ QRectF getTagRect(const ArrayRef<Ref<ResultPoint> > &resultPoints, const Ref<Bit
qreal yMin = qreal(resultRectPoints[0]->getY()); qreal yMin = qreal(resultRectPoints[0]->getY());
qreal yMax = yMin; qreal yMax = yMin;
for (unsigned int i = 1; i < resultRectPoints.size(); ++i) { for (size_t i = 1; i < resultRectPoints.size(); ++i) {
qreal y = qreal(resultRectPoints[i]->getY()); qreal y = qreal(resultRectPoints[i]->getY());
if (y < yMin) if (y < yMin)
yMin = y; yMin = y;
@ -549,7 +549,7 @@ QString QZXing::decodeSubImageQML(const QUrl &imageUrl,
if (imagePath.startsWith("/")) if (imagePath.startsWith("/"))
imagePath = imagePath.right(imagePath.length() - 1); imagePath = imagePath.right(imagePath.length() - 1);
QQmlEngine *engine = QQmlEngine::contextForObject(this)->engine(); QQmlEngine *engine = QQmlEngine::contextForObject(this)->engine();
QQuickImageProvider *imageProvider = static_cast<QQuickImageProvider *>(engine->imageProvider(imageUrl.host())); QQuickImageProvider *imageProvider = dynamic_cast<QQuickImageProvider *>(engine->imageProvider(imageUrl.host()));
QSize imgSize; QSize imgSize;
img = imageProvider->requestImage(imagePath, &imgSize, QSize()); img = imageProvider->requestImage(imagePath, &imgSize, QSize());
} else { } else {

View File

@ -114,7 +114,7 @@ public:
#endif //QT_VERSION >= Qt 4.7 #endif //QT_VERSION >= Qt 4.7
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
static void registerQMLImageProvider(QQmlEngine& view); static void registerQMLImageProvider(QQmlEngine& engine);
#endif //QT_VERSION >= Qt 5.0 #endif //QT_VERSION >= Qt 5.0
#endif //QZXING_QML #endif //QZXING_QML

View File

@ -33,7 +33,7 @@ private:
public: public:
EncodeHint(); EncodeHint();
const std::string getCharacterSet() const { return characterSet_; } std::string getCharacterSet() const { return characterSet_; }
const zxing::qrcode::ErrorCorrectionLevel* getErrorCorrectionLevel() { return errorCorrectionLevel_; } const zxing::qrcode::ErrorCorrectionLevel* getErrorCorrectionLevel() { return errorCorrectionLevel_; }
void setCharacterSet(const std::string& characterSet) { characterSet_ = characterSet; } void setCharacterSet(const std::string& characterSet) { characterSet_ = characterSet; }

View File

@ -31,7 +31,7 @@ ArrayRef<zxing::byte> InvertedLuminanceSource::getRow(int y, ArrayRef<zxing::byt
row = delegate->getRow(y, row); row = delegate->getRow(y, row);
int width = getWidth(); int width = getWidth();
for (int i = 0; i < width; i++) { for (int i = 0; i < width; i++) {
row[i] = (zxing::byte) (255 - (row[i] & 0xFF)); row[i] = 0xFF - row[i];
} }
return row; return row;
} }
@ -41,7 +41,7 @@ ArrayRef<zxing::byte> InvertedLuminanceSource::getMatrix() const {
int length = getWidth() * getHeight(); int length = getWidth() * getHeight();
ArrayRef<zxing::byte> invertedMatrix(length); ArrayRef<zxing::byte> invertedMatrix(length);
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
invertedMatrix[i] = (zxing::byte) (255 - (matrix[i] & 0xFF)); invertedMatrix[i] = 0xFF - matrix[i];
} }
return invertedMatrix; return invertedMatrix;
} }

View File

@ -57,7 +57,7 @@ LuminanceSource::operator std::string() const {
for (int y = 0; y < getHeight(); y++) { for (int y = 0; y < getHeight(); y++) {
row = getRow(y, row); row = getRow(y, row);
for (int x = 0; x < getWidth(); x++) { for (int x = 0; x < getWidth(); x++) {
int luminance = row[x] & 0xFF; int luminance = row[x];// & 0xFF;
char c; char c;
if (luminance < 0x40) { if (luminance < 0x40) {
c = '#'; c = '#';

View File

@ -63,7 +63,7 @@ Ref<Result> MultiFormatReader::decode(Ref<BinaryBitmap> image, DecodeHints hints
Ref<Result> MultiFormatReader::decodeWithState(Ref<BinaryBitmap> image) { Ref<Result> MultiFormatReader::decodeWithState(Ref<BinaryBitmap> image) {
// Make sure to set up the default state so we don't crash // Make sure to set up the default state so we don't crash
if (readers_.size() == 0) { if (readers_.empty()) {
setHints(DecodeHints::DEFAULT_HINT); setHints(DecodeHints::DEFAULT_HINT);
} }
return decodeInternal(image); return decodeInternal(image);
@ -75,7 +75,7 @@ void MultiFormatReader::setHints(DecodeHints hints) {
enableReaders(hints, false); enableReaders(hints, false);
if (readers_.size() == 0) if (readers_.empty())
enableReaders(hints, true); enableReaders(hints, true);
} }
@ -138,7 +138,7 @@ void MultiFormatReader::enableReaders(zxing::DecodeHints hints, bool allowAll)
} }
Ref<Result> MultiFormatReader::decodeInternal(Ref<BinaryBitmap> image) { Ref<Result> MultiFormatReader::decodeInternal(Ref<BinaryBitmap> image) {
for (unsigned int i = 0; i < readers_.size(); i++) { for (size_t i = 0; i < readers_.size(); i++) {
try { try {
return readers_[i]->decode(image, hints_); return readers_[i]->decode(image, hints_);
} catch (ReaderException const& re) { } catch (ReaderException const& re) {

View File

@ -35,7 +35,7 @@ namespace zxing {
Result::Result(Ref<String> text, Result::Result(Ref<String> text,
ArrayRef<zxing::byte> rawBytes, ArrayRef<zxing::byte> rawBytes,
ArrayRef< Ref<ResultPoint> > resultPoints, ArrayRef< Ref<ResultPoint> > resultPoints,
BarcodeFormat format, std::string charSet, BarcodeFormat format, const std::string &charSet,
ResultMetadata metadata) : ResultMetadata metadata) :
text_(text), rawBytes_(rawBytes), resultPoints_(resultPoints), format_(format), charSet_(charSet), metadata_(metadata) { text_(text), rawBytes_(rawBytes), resultPoints_(resultPoints), format_(format), charSet_(charSet), metadata_(metadata) {
} }

View File

@ -44,7 +44,7 @@ public:
Result(Ref<String> text, Result(Ref<String> text,
ArrayRef<zxing::byte> rawBytes, ArrayRef<zxing::byte> rawBytes,
ArrayRef< Ref<ResultPoint> > resultPoints, ArrayRef< Ref<ResultPoint> > resultPoints,
BarcodeFormat format, std::string charSet = "", BarcodeFormat format, const std::string &charSet = "",
ResultMetadata metadata = ResultMetadata()); ResultMetadata metadata = ResultMetadata());
~Result(); ~Result();
Ref<String> getText(); Ref<String> getText();

View File

@ -42,7 +42,7 @@ float ResultPoint::getY() const {
return posY_; return posY_;
} }
bool ResultPoint::equals(Ref<ResultPoint> other) { bool ResultPoint::equals(const Ref<ResultPoint> &other) {
return posX_ == other->getX() && posY_ == other->getY(); return posX_ == other->getX() && posY_ == other->getY();
} }

View File

@ -40,7 +40,7 @@ public:
virtual float getX() const; virtual float getX() const;
virtual float getY() const; virtual float getY() const;
bool equals(Ref<ResultPoint> other); bool equals(const Ref<ResultPoint> &other);
static void orderBestPatterns(std::vector<Ref<ResultPoint> > &patterns); static void orderBestPatterns(std::vector<Ref<ResultPoint> > &patterns);
static float distance(Ref<ResultPoint> point1, Ref<ResultPoint> point2); static float distance(Ref<ResultPoint> point1, Ref<ResultPoint> point2);

View File

@ -280,7 +280,7 @@ void BitArray::toBytes(int bitOffset, std::vector<zxing::byte>& array, int offse
} }
} }
const std::string BitArray::toString() const std::string BitArray::toString() const
{ {
std::stringstream result;// = new StringBuilder(2 * width * height + 2); std::stringstream result;// = new StringBuilder(2 * width * height + 2);

View File

@ -76,7 +76,7 @@ public:
void toBytes(int bitOffset, std::vector<zxing::byte>& array, int offset, int numBytes) const; void toBytes(int bitOffset, std::vector<zxing::byte>& array, int offset, int numBytes) const;
const std::string toString() const; std::string toString() const;
static ArrayRef<int> makeArray(int size) { static ArrayRef<int> makeArray(int size) {
return ArrayRef<int>((size + 31) / 32); return ArrayRef<int>((size + 31) / 32);

View File

@ -27,15 +27,15 @@ namespace zxing {
/** /**
* ByteArray is an extension of std::vector<unsigned char>. * ByteArray is an extension of std::vector<unsigned char>.
*/ */
class ByteArray : public std::vector<uint8_t> class ByteArray : public std::vector<zxing::byte>
{ {
public: public:
ByteArray() {} ByteArray() {}
ByteArray(std::initializer_list<uint8_t> list) : std::vector<uint8_t>(list) {} ByteArray(std::initializer_list<zxing::byte> list) : std::vector<zxing::byte>(list) {}
explicit ByteArray(int len) : std::vector<uint8_t>(len, 0) {} explicit ByteArray(int len) : std::vector<zxing::byte>(len, 0) {}
int length() const { return static_cast<int>(size()); } int length() const { return static_cast<int>(size()); }
const zxing::byte* bytePtr() const { return reinterpret_cast<const zxing::byte*>(data()); } const zxing::byte* bytePtr() const { return data(); }
zxing::byte* bytePtr() { return reinterpret_cast<zxing::byte*>(data()); } zxing::byte* bytePtr() { return data(); }
}; };
} }

View File

@ -16,12 +16,10 @@
*/ */
#include <zxing/common/CharacterSetECI.h> #include <zxing/common/CharacterSetECI.h>
#include <zxing/common/IllegalArgumentException.h>
#include <zxing/FormatException.h> #include <zxing/FormatException.h>
#include <cstdlib> #include <cstdlib>
using std::string; using std::string;
using zxing::IllegalArgumentException;
namespace zxing { namespace zxing {
namespace common { namespace common {
@ -89,7 +87,7 @@ int CharacterSetECI::getValue() const {
return values_[0]; return values_[0];
} }
void CharacterSetECI::addCharacterSet(const std::vector<int> values, const std::vector<const char*> names) { void CharacterSetECI::addCharacterSet(const std::vector<int> &values, const std::vector<const char *> &names) {
CharacterSetECI* charSet = new CharacterSetECI(values, names); CharacterSetECI* charSet = new CharacterSetECI(values, names);
for(size_t i=0; i<values.size(); i++) { for(size_t i=0; i<values.size(); i++) {
VALUE_TO_ECI[values[i]] = charSet; VALUE_TO_ECI[values[i]] = charSet;

View File

@ -40,7 +40,7 @@ private:
CharacterSetECI(const std::vector<int> values, const std::vector<const char*> names); CharacterSetECI(const std::vector<int> values, const std::vector<const char*> names);
static void addCharacterSet(const std::vector<int> value, const std::vector<const char*> encodingNames); static void addCharacterSet(const std::vector<int> &value, const std::vector<const char*> &encodingNames);
public: public:
char const* name() const; char const* name() const;

View File

@ -26,7 +26,7 @@ void Counted::release()
} }
} }
int Counted::count() const size_t Counted::count() const
{ {
return count_; return count_;
} }

View File

@ -25,7 +25,7 @@ namespace zxing {
/* base class for reference-counted objects */ /* base class for reference-counted objects */
class Counted { class Counted {
private: private:
unsigned int count_; size_t count_;
public: public:
Counted(); Counted();
@ -36,7 +36,7 @@ public:
void release(); void release();
/* return the current count for denugging purposes or similar */ /* return the current count for denugging purposes or similar */
int count() const; size_t count() const;
}; };
/* counting reference to reference-counted objects */ /* counting reference to reference-counted objects */

View File

@ -58,16 +58,15 @@ ArrayRef<zxing::byte> GreyscaleLuminanceSource::getRow(int y, ArrayRef<zxing::by
} }
ArrayRef<zxing::byte> GreyscaleLuminanceSource::getMatrix() const { ArrayRef<zxing::byte> GreyscaleLuminanceSource::getMatrix() const {
if (left_ == 0 && top_ == 0 && dataWidth_ == getWidth() && dataHeight_ == getHeight()) { if (left_ == 0 && top_ == 0 && dataWidth_ == getWidth() && dataHeight_ == getHeight())
return greyData_; return greyData_;
} else {
int size = getWidth() * getHeight(); int size = getWidth() * getHeight();
ArrayRef<zxing::byte> result (size); ArrayRef<zxing::byte> result (size);
for (int row = 0; row < getHeight(); row++) { for (int row = 0; row < getHeight(); row++) {
memcpy(&result[row * getWidth()], &greyData_[(top_ + row) * dataWidth_ + left_], getWidth()); memcpy(&result[row * getWidth()], &greyData_[(top_ + row) * dataWidth_ + left_], getWidth());
} }
return result; return result;
}
} }
Ref<LuminanceSource> GreyscaleLuminanceSource::rotateCounterClockwise() const { Ref<LuminanceSource> GreyscaleLuminanceSource::rotateCounterClockwise() const {
@ -81,3 +80,4 @@ Ref<LuminanceSource> GreyscaleLuminanceSource::rotateCounterClockwise() const {
} }
} }

View File

@ -44,11 +44,13 @@ Ref<PerspectiveTransform> PerspectiveTransform::squareToQuadrilateral(float x0,
float y2, float x3, float y3) { float y2, float x3, float y3) {
float dx3 = x0 - x1 + x2 - x3; float dx3 = x0 - x1 + x2 - x3;
float dy3 = y0 - y1 + y2 - y3; float dy3 = y0 - y1 + y2 - y3;
Ref<PerspectiveTransform> result;
if (dx3 == 0.0f && dy3 == 0.0f) { if (dx3 == 0.0f && dy3 == 0.0f) {
Ref<PerspectiveTransform> result(new PerspectiveTransform(x1 - x0, x2 - x1, x0, y1 - y0, y2 - y1, y0, 0.0f, result = new PerspectiveTransform(x1 - x0, x2 - x1, x0, y1 - y0, y2 - y1, y0, 0.0f,
0.0f, 1.0f)); 0.0f, 1.0f);
return result; }
} else { else
{
float dx1 = x1 - x2; float dx1 = x1 - x2;
float dx2 = x3 - x2; float dx2 = x3 - x2;
float dy1 = y1 - y2; float dy1 = y1 - y2;
@ -56,10 +58,11 @@ Ref<PerspectiveTransform> PerspectiveTransform::squareToQuadrilateral(float x0,
float denominator = dx1 * dy2 - dx2 * dy1; float denominator = dx1 * dy2 - dx2 * dy1;
float a13 = (dx3 * dy2 - dx2 * dy3) / denominator; float a13 = (dx3 * dy2 - dx2 * dy3) / denominator;
float a23 = (dx1 * dy3 - dx3 * dy1) / denominator; float a23 = (dx1 * dy3 - dx3 * dy1) / denominator;
Ref<PerspectiveTransform> result(new PerspectiveTransform(x1 - x0 + a13 * x1, x3 - x0 + a23 * x3, x0, y1 - y0 result = new PerspectiveTransform(x1 - x0 + a13 * x1, x3 - x0 + a23 * x3, x0, y1 - y0
+ a13 * y1, y3 - y0 + a23 * y3, y0, a13, a23, 1.0f)); + a13 * y1, y3 - y0 + a23 * y3, y0, a13, a23, 1.0f);
return result;
} }
return result;
} }
Ref<PerspectiveTransform> PerspectiveTransform::quadrilateralToSquare(float x0, float y0, float x1, float y1, float x2, Ref<PerspectiveTransform> PerspectiveTransform::quadrilateralToSquare(float x0, float y0, float x1, float y1, float x2,

View File

@ -8,7 +8,7 @@
namespace zxing { namespace zxing {
typedef unsigned char byte; typedef uint8_t byte;
typedef bool boolean; typedef bool boolean;
} }

View File

@ -59,7 +59,7 @@ void GenericGF::initialize() {
int x = 1; int x = 1;
for (int i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
expTable[i] = x; expTable[i] = x;
x <<= 1; // x = x * 2; we're assuming the generator alpha is 2 x <<= 1; // x = x * 2; we're assuming the generator alpha is 2
if (x >= size) { if (x >= size) {
@ -67,8 +67,8 @@ void GenericGF::initialize() {
x &= size-1; x &= size-1;
} }
} }
for (int i = 0; i < size-1; i++) { for (size_t i = 0; i < size-1; i++) {
logTable[expTable[i]] = i; logTable.at(expTable.at(i)) = i;
} }
//logTable[0] == 0 but this should never be used //logTable[0] == 0 but this should never be used
ArrayRef<int> coefficients_zero(1); ArrayRef<int> coefficients_zero(1);
@ -148,7 +148,7 @@ int GenericGF::multiply(int a, int b) {
return expTable[(logTable[a] + logTable[b]) % (size - 1)]; return expTable[(logTable[a] + logTable[b]) % (size - 1)];
} }
int GenericGF::getSize() { size_t GenericGF::getSize() {
return size; return size;
} }

View File

@ -58,7 +58,7 @@ namespace zxing {
Ref<GenericGFPoly> getZero(); Ref<GenericGFPoly> getZero();
Ref<GenericGFPoly> getOne(); Ref<GenericGFPoly> getOne();
int getSize(); size_t getSize();
int getGeneratorBase(); int getGeneratorBase();
Ref<GenericGFPoly> buildMonomial(int degree, int coefficient); Ref<GenericGFPoly> buildMonomial(int degree, int coefficient);

View File

@ -51,7 +51,7 @@ void ReedSolomonEncoder::encode(std::vector<zxing::byte> &toEncode, int ecBytes)
ArrayRef<int> infoCoefficients(dataBytes); ArrayRef<int> infoCoefficients(dataBytes);
//to-do optimize the following loop //to-do optimize the following loop
for(int i=0; i< dataBytes; i++) for(size_t i=0; i< dataBytes; i++)
infoCoefficients[i] = toEncode[size_t(i)]; infoCoefficients[i] = toEncode[size_t(i)];
Ref<GenericGFPoly> info(new GenericGFPoly(field_, infoCoefficients)); Ref<GenericGFPoly> info(new GenericGFPoly(field_, infoCoefficients));
@ -64,7 +64,7 @@ void ReedSolomonEncoder::encode(std::vector<zxing::byte> &toEncode, int ecBytes)
} }
for (int i = 0; i < coefficients->size(); i++) for (int i = 0; i < coefficients->size(); i++)
toEncode[size_t(dataBytes + numZeroCoefficients + i)] = zxing::byte(coefficients[int(i)]); toEncode[size_t(dataBytes + numZeroCoefficients + i)] = zxing::byte(coefficients[i]);
} }
} }

View File

@ -44,14 +44,24 @@ int ECB::getDataCodewords() {
} }
ECBlocks::ECBlocks(int ecCodewordsPerBloc, ECB *ecBlocks) : ECBlocks::ECBlocks(int ecCodewordsPerBloc, ECB *ecBlocks) :
ecCodewordsPerBloc_(ecCodewordsPerBloc), ecBlocks_(1, ecBlocks) { ecCodewordsPerBloc_(ecCodewordsPerBloc), ecBlocks_() {
ecBlocks_.push_back(ecBlocks);
} }
ECBlocks::ECBlocks(int ecCodewordsPerBloc, ECB *ecBlocks1, ECB *ecBlocks2) : ECBlocks::ECBlocks(int ecCodewordsPerBloc, ECB *ecBlocks1, ECB *ecBlocks2) :
ecCodewordsPerBloc_(ecCodewordsPerBloc), ecBlocks_(1, ecBlocks1) { ecCodewordsPerBloc_(ecCodewordsPerBloc), ecBlocks_() {
ecBlocks_.push_back(ecBlocks1);
ecBlocks_.push_back(ecBlocks2); ecBlocks_.push_back(ecBlocks2);
} }
int ECBlocks::numBlocks() const
{
int sumSizeOfBlocks = 0;
for (size_t i=0; i<ecBlocks_.size(); ++i)
sumSizeOfBlocks += ecBlocks_[i]->getCount();
return sumSizeOfBlocks;
}
int ECBlocks::getECCodewordsPerBloc() int ECBlocks::getECCodewordsPerBloc()
{ {
return ecCodewordsPerBloc_; return ecCodewordsPerBloc_;
@ -59,7 +69,7 @@ int ECBlocks::getECCodewordsPerBloc()
int ECBlocks::getTotalECCodewords() int ECBlocks::getTotalECCodewords()
{ {
return ecCodewordsPerBloc_ * int(ecBlocks_.size()); return ecCodewordsPerBloc_ * numBlocks();//int(ecBlocks_.size());
} }
std::vector<ECB*>& ECBlocks::getECBlocks() { std::vector<ECB*>& ECBlocks::getECBlocks() {

View File

@ -47,6 +47,7 @@ private:
public: public:
ECBlocks(int ecCodewordsPerBloc, ECB *ecBlocks); ECBlocks(int ecCodewordsPerBloc, ECB *ecBlocks);
ECBlocks(int ecCodewordsPerBloc, ECB *ecBlocks1, ECB *ecBlocks2); ECBlocks(int ecCodewordsPerBloc, ECB *ecBlocks1, ECB *ecBlocks2);
int numBlocks() const;
int getECCodewordsPerBloc(); int getECCodewordsPerBloc();
int getTotalECCodewords(); int getTotalECCodewords();
std::vector<ECB*>& getECBlocks(); std::vector<ECB*>& getECBlocks();