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;
}
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
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> 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:
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)
return img.copy(offsetX, offsetY, width, height);
else
return img;
}

View File

@ -35,7 +35,7 @@ public:
int width = 0, int height = 0);
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 width = 0, const int height = 0);
private:

View File

@ -340,7 +340,7 @@ QRectF getTagRect(const ArrayRef<Ref<ResultPoint> > &resultPoints, const Ref<Bit
qreal yMin = qreal(resultRectPoints[0]->getY());
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());
if (y < yMin)
yMin = y;
@ -549,7 +549,7 @@ QString QZXing::decodeSubImageQML(const QUrl &imageUrl,
if (imagePath.startsWith("/"))
imagePath = imagePath.right(imagePath.length() - 1);
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;
img = imageProvider->requestImage(imagePath, &imgSize, QSize());
} else {

View File

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

View File

@ -33,7 +33,7 @@ private:
public:
EncodeHint();
const std::string getCharacterSet() const { return characterSet_; }
std::string getCharacterSet() const { return characterSet_; }
const zxing::qrcode::ErrorCorrectionLevel* getErrorCorrectionLevel() { return errorCorrectionLevel_; }
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);
int width = getWidth();
for (int i = 0; i < width; i++) {
row[i] = (zxing::byte) (255 - (row[i] & 0xFF));
row[i] = 0xFF - row[i];
}
return row;
}
@ -41,7 +41,7 @@ ArrayRef<zxing::byte> InvertedLuminanceSource::getMatrix() const {
int length = getWidth() * getHeight();
ArrayRef<zxing::byte> invertedMatrix(length);
for (int i = 0; i < length; i++) {
invertedMatrix[i] = (zxing::byte) (255 - (matrix[i] & 0xFF));
invertedMatrix[i] = 0xFF - matrix[i];
}
return invertedMatrix;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -40,7 +40,7 @@ public:
virtual float getX() 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 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);

View File

@ -76,7 +76,7 @@ public:
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) {
return ArrayRef<int>((size + 31) / 32);

View File

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

View File

@ -16,12 +16,10 @@
*/
#include <zxing/common/CharacterSetECI.h>
#include <zxing/common/IllegalArgumentException.h>
#include <zxing/FormatException.h>
#include <cstdlib>
using std::string;
using zxing::IllegalArgumentException;
namespace zxing {
namespace common {
@ -89,7 +87,7 @@ int CharacterSetECI::getValue() const {
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);
for(size_t i=0; i<values.size(); i++) {
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);
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:
char const* name() const;

View File

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

View File

@ -25,7 +25,7 @@ namespace zxing {
/* base class for reference-counted objects */
class Counted {
private:
unsigned int count_;
size_t count_;
public:
Counted();
@ -36,7 +36,7 @@ public:
void release();
/* return the current count for denugging purposes or similar */
int count() const;
size_t count() const;
};
/* 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 {
if (left_ == 0 && top_ == 0 && dataWidth_ == getWidth() && dataHeight_ == getHeight()) {
if (left_ == 0 && top_ == 0 && dataWidth_ == getWidth() && dataHeight_ == getHeight())
return greyData_;
} else {
int size = getWidth() * getHeight();
ArrayRef<zxing::byte> result (size);
for (int row = 0; row < getHeight(); row++) {
memcpy(&result[row * getWidth()], &greyData_[(top_ + row) * dataWidth_ + left_], getWidth());
}
return result;
}
}
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 dx3 = x0 - x1 + x2 - x3;
float dy3 = y0 - y1 + y2 - y3;
Ref<PerspectiveTransform> result;
if (dx3 == 0.0f && dy3 == 0.0f) {
Ref<PerspectiveTransform> result(new PerspectiveTransform(x1 - x0, x2 - x1, x0, y1 - y0, y2 - y1, y0, 0.0f,
0.0f, 1.0f));
return result;
} else {
result = new PerspectiveTransform(x1 - x0, x2 - x1, x0, y1 - y0, y2 - y1, y0, 0.0f,
0.0f, 1.0f);
}
else
{
float dx1 = x1 - x2;
float dx2 = x3 - x2;
float dy1 = y1 - y2;
@ -56,10 +58,11 @@ Ref<PerspectiveTransform> PerspectiveTransform::squareToQuadrilateral(float x0,
float denominator = dx1 * dy2 - dx2 * dy1;
float a13 = (dx3 * dy2 - dx2 * dy3) / denominator;
float a23 = (dx1 * dy3 - dx3 * dy1) / denominator;
Ref<PerspectiveTransform> 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));
return result;
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);
}
return result;
}
Ref<PerspectiveTransform> PerspectiveTransform::quadrilateralToSquare(float x0, float y0, float x1, float y1, float x2,

View File

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

View File

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

View File

@ -58,7 +58,7 @@ namespace zxing {
Ref<GenericGFPoly> getZero();
Ref<GenericGFPoly> getOne();
int getSize();
size_t getSize();
int getGeneratorBase();
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);
//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)];
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++)
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) :
ecCodewordsPerBloc_(ecCodewordsPerBloc), ecBlocks_(1, ecBlocks) {
ecCodewordsPerBloc_(ecCodewordsPerBloc), ecBlocks_() {
ecBlocks_.push_back(ecBlocks);
}
ECBlocks::ECBlocks(int ecCodewordsPerBloc, ECB *ecBlocks1, ECB *ecBlocks2) :
ecCodewordsPerBloc_(ecCodewordsPerBloc), ecBlocks_(1, ecBlocks1) {
ecCodewordsPerBloc_(ecCodewordsPerBloc), ecBlocks_() {
ecBlocks_.push_back(ecBlocks1);
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()
{
return ecCodewordsPerBloc_;
@ -59,7 +69,7 @@ int ECBlocks::getECCodewordsPerBloc()
int ECBlocks::getTotalECCodewords()
{
return ecCodewordsPerBloc_ * int(ecBlocks_.size());
return ecCodewordsPerBloc_ * numBlocks();//int(ecBlocks_.size());
}
std::vector<ECB*>& ECBlocks::getECBlocks() {

View File

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