continued the transition of changing all byte references from char to unsinged char => Qr Encoder

This commit is contained in:
favoritas37 2016-06-12 14:19:58 +03:00
parent 9708a0ed23
commit 983390d465
6 changed files with 31 additions and 31 deletions

View File

@ -246,7 +246,7 @@ QString QZXing::decodeImageFromFile(const QString& imageFilePath, int maxWidth,
// used to have a check if this image exists
// but was removed because if the image file path doesn't point to a valid image
// then the QImage::isNull will return true and the decoding will fail eitherway.
QUrl imageUrl(imageFilePath);
QUrl imageUrl = QUrl::fromLocalFile(imageFilePath);
QImage tmpImage = QImage(imageUrl.toLocalFile());
return decodeImage(tmpImage, maxWidth, maxHeight, smoothTransformation);
}
@ -302,7 +302,7 @@ QImage QZXing::encodeData(const QString& data)
try {
Ref<qrcode::QRCode> barcode = qrcode::Encoder::encode(data, qrcode::ErrorCorrectionLevel::L );
Ref<qrcode::ByteMatrix> bytesRef = barcode->getMatrix();
const std::vector< std::vector <char> >& bytes = bytesRef->getArray();
const std::vector< std::vector <unsigned char> >& bytes = bytesRef->getArray();
image = QImage(bytesRef->getWidth(), bytesRef->getHeight(), QImage::Format_ARGB32);
for(int i=0; i<bytesRef->getWidth(); i++)
for(int j=0; j<bytesRef->getHeight(); j++)
@ -311,7 +311,7 @@ QImage QZXing::encodeData(const QString& data)
qRgb(255,255,255));
image = image.scaled(240, 240);
//bool success = image.save("tmp.bmp","BMP");
// bool success = image.save("tmp.bmp","BMP");
} catch (std::exception& e) {
std::cout << "Error: " << e.what() << std::endl;
}

View File

@ -22,32 +22,32 @@ size_t ByteMatrix::getWidth() const
return width_;
}
signed char ByteMatrix::get(size_t x, size_t y) const
unsigned char ByteMatrix::get(size_t x, size_t y) const
{
return bytes_[y][x];
}
std::vector< std::vector<char> > ByteMatrix::getArray() const
std::vector< std::vector<unsigned char> > ByteMatrix::getArray() const
{
return bytes_;
}
void ByteMatrix::set(size_t x, size_t y, const char value)
void ByteMatrix::set(size_t x, size_t y, const unsigned char value)
{
bytes_[y][x] = value;
}
void ByteMatrix::set(size_t x, size_t y, size_t value)
{
bytes_[y][x] = (char) value;
bytes_[y][x] = (unsigned char) value;
}
void ByteMatrix::set(size_t x, size_t y, bool value)
{
bytes_[y][x] = (char) (value ? 1 : 0);
bytes_[y][x] = (unsigned char) (value ? 1 : 0);
}
void ByteMatrix::clear(const char value)
void ByteMatrix::clear(const unsigned char value)
{
for (size_t y = 0; y < height_; y++) {
for (size_t x = 0; x < width_; x++) {

View File

@ -11,7 +11,7 @@ namespace qrcode {
class ByteMatrix : public Counted
{
private:
std::vector< std::vector<char> > bytes_;
std::vector< std::vector<unsigned char> > bytes_;
size_t width_;
size_t height_;
@ -21,13 +21,13 @@ public:
size_t getHeight() const;
size_t getWidth() const;
signed char get(size_t x, size_t y) const;
unsigned char get(size_t x, size_t y) const;
std::vector< std::vector<char> > getArray() const;
void set(size_t x, size_t y, const char value);
std::vector<std::vector<unsigned char> > getArray() const;
void set(size_t x, size_t y, const unsigned char value);
void set(size_t x, size_t y, size_t value);
void set(size_t x, size_t y, bool value);
void clear(const char value);
void clear(const unsigned char value);
const std::string toString() const;
};

View File

@ -28,7 +28,7 @@ int MaskUtil::applyMaskPenaltyRule1(const ByteMatrix& matrix)
int MaskUtil::applyMaskPenaltyRule2(const ByteMatrix& matrix)
{
int penalty = 0;
const std::vector<std::vector<char> >& array = matrix.getArray();
const std::vector<std::vector<unsigned char> >& array = matrix.getArray();
int width = matrix.getWidth();
int height = matrix.getHeight();
for (int y = 0; y < height - 1; y++) {
@ -50,12 +50,12 @@ int MaskUtil::applyMaskPenaltyRule2(const ByteMatrix& matrix)
int MaskUtil::applyMaskPenaltyRule3(const ByteMatrix& matrix)
{
int numPenalties = 0;
const std::vector<std::vector<char> >& array = matrix.getArray();
const std::vector<std::vector<unsigned char> >& array = matrix.getArray();
int width = matrix.getWidth();
int height = matrix.getHeight();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
const std::vector<char>& arrayY = array[y]; // We can at least optimize this access
const std::vector<unsigned char>& arrayY = array[y]; // We can at least optimize this access
if (x + 6 < width &&
arrayY[x] == 1 &&
arrayY[x + 1] == 0 &&
@ -83,7 +83,7 @@ int MaskUtil::applyMaskPenaltyRule3(const ByteMatrix& matrix)
return numPenalties * N3;
}
bool MaskUtil::isWhiteHorizontal(const std::vector<char>& rowArray, int from, int to)
bool MaskUtil::isWhiteHorizontal(const std::vector<unsigned char>& rowArray, int from, int to)
{
for (int i = from; i < to; i++) {
if (i >= 0 && i < rowArray.size() && rowArray[i] == 1) {
@ -93,7 +93,7 @@ bool MaskUtil::isWhiteHorizontal(const std::vector<char>& rowArray, int from, in
return true;
}
bool MaskUtil::isWhiteVertical(const std::vector<std::vector<char> >& array, int col, int from, int to)
bool MaskUtil::isWhiteVertical(const std::vector<std::vector<unsigned char> > &array, int col, int from, int to)
{
for (int i = from; i < to; i++) {
if (i >= 0 && i < array.size() && array[i][col] == 1) {
@ -110,11 +110,11 @@ bool MaskUtil::isWhiteVertical(const std::vector<std::vector<char> >& array, int
int MaskUtil::applyMaskPenaltyRule4(const ByteMatrix& matrix)
{
int numDarkCells = 0;
const std::vector<std::vector<char> >& array = matrix.getArray();
const std::vector<std::vector<unsigned char> >& array = matrix.getArray();
int width = matrix.getWidth();
int height = matrix.getHeight();
for (int y = 0; y < height; y++) {
const std::vector<char>& arrayY = array[y];
const std::vector<unsigned char>& arrayY = array[y];
for (size_t x = 0; x < width; x++) {
if (arrayY[x] == 1) {
numDarkCells++;
@ -177,7 +177,7 @@ int MaskUtil::applyMaskPenaltyRule1Internal(const ByteMatrix& matrix, bool isHor
int penalty = 0;
int iLimit = isHorizontal ? matrix.getHeight() : matrix.getWidth();
int jLimit = isHorizontal ? matrix.getWidth() : matrix.getHeight();
const std::vector<std::vector<char> >& array = matrix.getArray();
const std::vector<std::vector<unsigned char> >& array = matrix.getArray();
for (size_t i = 0; i < iLimit; i++) {
int numSameBitCells = 0;
int prevBit = -1;

View File

@ -15,9 +15,9 @@ private:
static const int N3;
static const int N4;
static bool isWhiteHorizontal(const std::vector<char>& rowArray, int from, int to);
static bool isWhiteHorizontal(const std::vector<unsigned char>& rowArray, int from, int to);
static bool isWhiteVertical(const std::vector<std::vector<char> >& array, int col, int from, int to);
static bool isWhiteVertical(const std::vector<std::vector<unsigned char> >& array, int col, int from, int to);
/**
* Helper function for applyMaskPenaltyRule1. We need this for doing this calculation in both

View File

@ -290,11 +290,11 @@ void MatrixUtil::embedTimingPatterns(ByteMatrix& matrix)
int bit = (i + 1) % 2;
// Horizontal line.
if (isEmpty(matrix.get(i, 6))) {
matrix.set(i, 6, (char)bit);
matrix.set(i, 6, (unsigned char)bit);
}
// Vertical line.
if (isEmpty(matrix.get(6, i))) {
matrix.set(6, i, (char)bit);
matrix.set(6, i, (unsigned char)bit);
}
}
}
@ -304,7 +304,7 @@ void MatrixUtil::embedDarkDotAtLeftBottomCorner(ByteMatrix& matrix)
if (matrix.get(8, matrix.getHeight() - 8) == 0) {
throw new WriterException();
}
matrix.set(8, matrix.getHeight() - 8, (char)1);
matrix.set(8, matrix.getHeight() - 8, (unsigned char)1);
}
void MatrixUtil::embedHorizontalSeparationPattern(int xStart,
@ -315,7 +315,7 @@ void MatrixUtil::embedHorizontalSeparationPattern(int xStart,
if (!isEmpty(matrix.get(xStart + x, yStart))) {
throw new WriterException();
}
matrix.set(xStart + x, yStart, (char)0);
matrix.set(xStart + x, yStart, (unsigned char)0);
}
}
@ -327,7 +327,7 @@ void MatrixUtil::embedVerticalSeparationPattern(int xStart,
if (!isEmpty(matrix.get(xStart, yStart + y))) {
throw new WriterException();
}
matrix.set(xStart, yStart + y, (char)0);
matrix.set(xStart, yStart + y, (unsigned char)0);
}
}
@ -335,7 +335,7 @@ void MatrixUtil::embedPositionAdjustmentPattern(int xStart, int yStart, ByteMatr
{
for (int y = 0; y < 5; ++y) {
for (int x = 0; x < 5; ++x) {
matrix.set(xStart + x, yStart + y, (char)POSITION_ADJUSTMENT_PATTERN[y][x]);
matrix.set(xStart + x, yStart + y, (unsigned char)POSITION_ADJUSTMENT_PATTERN[y][x]);
}
}
}
@ -344,7 +344,7 @@ void MatrixUtil::embedPositionDetectionPattern(int xStart, int yStart, ByteMatri
{
for (int y = 0; y < 7; ++y) {
for (int x = 0; x < 7; ++x) {
matrix.set(xStart + x, yStart + y, (char)POSITION_DETECTION_PATTERN[y][x]);
matrix.set(xStart + x, yStart + y, (unsigned char)POSITION_DETECTION_PATTERN[y][x]);
}
}
}