mirror of https://github.com/status-im/qzxing.git
fixing compilation errors
This commit is contained in:
parent
7eb571c2ae
commit
4af0dd58f1
|
@ -34,14 +34,14 @@ int BitArray::makeArraySize(int size) {
|
|||
return (size + 31) / 32;
|
||||
}
|
||||
|
||||
BitArray::BitArray(): size(0), bits(1) {}
|
||||
BitArray::BitArray(): size(0), bits(new std::vector<int>(1)) {}
|
||||
|
||||
BitArray::BitArray(int size_)
|
||||
: size(size_), bits(makeArraySize(size)) {}
|
||||
: size(size_), bits(new std::vector<int>(makeArraySize(size))) {}
|
||||
|
||||
//this could be wrong. TODO: check size value
|
||||
BitArray::BitArray(std::vector<int> other)
|
||||
: size(int(other.size())), bits(int(other.size()))
|
||||
: size(int(other.size())), bits(new std::vector<int>(int(other.size())))
|
||||
{
|
||||
for(size_t i=0; i<other.size(); i++)
|
||||
{
|
||||
|
@ -63,13 +63,13 @@ int BitArray::getSizeInBytes() const
|
|||
}
|
||||
|
||||
void BitArray::setBulk(int i, int newBits) {
|
||||
bits[i / 32] = newBits;
|
||||
(*bits)[i / 32] = newBits;
|
||||
}
|
||||
|
||||
void BitArray::clear() {
|
||||
int max = bits->size();
|
||||
for (int i = 0; i < max; i++) {
|
||||
bits[i] = 0;
|
||||
(*bits)[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ bool BitArray::isRange(int start, int end, bool value) {
|
|||
|
||||
// Return false if we're looking for 1s and the masked bits[i] isn't all 1s (that is,
|
||||
// equals the mask, or we're looking for 0s and the masked portion is not all 0s
|
||||
if ((bits[i] & mask) != (value ? mask : 0)) {
|
||||
if (((*bits)[i] & mask) != (value ? mask : 0)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -108,23 +108,23 @@ bool BitArray::isRange(int start, int end, bool value) {
|
|||
}
|
||||
|
||||
vector<int>& BitArray::getBitArray() {
|
||||
return bits->values();
|
||||
return (*bits);
|
||||
}
|
||||
|
||||
void BitArray::reverse()
|
||||
{
|
||||
QSharedPointer<std::vector<int>> newBits(bits->size());
|
||||
QSharedPointer<std::vector<int>> newBits(new std::vector<int>(bits->size()));
|
||||
// reverse all int's first
|
||||
int len = ((this->size-1) / 32);
|
||||
int oldBitsLen = len + 1;
|
||||
for (int i = 0; i < oldBitsLen; i++) {
|
||||
long x = long(bits[i]);
|
||||
long x = long((*bits)[i]);
|
||||
x = ((x >> 1) & 0x55555555L) | ((x & 0x55555555L) << 1);
|
||||
x = ((x >> 2) & 0x33333333L) | ((x & 0x33333333L) << 2);
|
||||
x = ((x >> 4) & 0x0f0f0f0fL) | ((x & 0x0f0f0f0fL) << 4);
|
||||
x = ((x >> 8) & 0x00ff00ffL) | ((x & 0x00ff00ffL) << 8);
|
||||
x = ((x >> 16) & 0x0000ffffL) | ((x & 0x0000ffffL) << 16);
|
||||
newBits[len - i] = int(x);
|
||||
(*newBits)[len - i] = int(x);
|
||||
}
|
||||
// now correct the int's if the bit size isn't a multiple of 32
|
||||
if (size != oldBitsLen * 32) {
|
||||
|
@ -133,14 +133,14 @@ void BitArray::reverse()
|
|||
for (int i = 0; i < 31 - leftOffset; i++) {
|
||||
mask = (mask << 1) | 1;
|
||||
}
|
||||
int currentInt = (newBits[0] >> leftOffset) & mask;
|
||||
int currentInt = ((*newBits)[0] >> leftOffset) & mask;
|
||||
for (int i = 1; i < oldBitsLen; i++) {
|
||||
int nextInt = newBits[i];
|
||||
int nextInt = (*newBits)[i];
|
||||
currentInt |= nextInt << (32 - leftOffset);
|
||||
newBits[i - 1] = currentInt;
|
||||
(*newBits)[i - 1] = currentInt;
|
||||
currentInt = (nextInt >> leftOffset) & mask;
|
||||
}
|
||||
newBits[oldBitsLen - 1] = currentInt;
|
||||
(*newBits)[oldBitsLen - 1] = currentInt;
|
||||
}
|
||||
bits = newBits;
|
||||
}
|
||||
|
@ -177,14 +177,14 @@ int BitArray::getNextSet(int from) {
|
|||
return size;
|
||||
}
|
||||
int bitsOffset = from >> logBits;
|
||||
int currentBits = bits[bitsOffset];
|
||||
int currentBits = (*bits)[bitsOffset];
|
||||
// mask off lesser bits first
|
||||
currentBits &= ~((1 << (from & bitsMask)) - 1);
|
||||
while (currentBits == 0) {
|
||||
if (++bitsOffset == bits->size()) {
|
||||
return size;
|
||||
}
|
||||
currentBits = bits[bitsOffset];
|
||||
currentBits = (*bits)[bitsOffset];
|
||||
}
|
||||
int result = (bitsOffset << logBits) + numberOfTrailingZeros(currentBits);
|
||||
return result > size ? size : result;
|
||||
|
@ -195,14 +195,14 @@ int BitArray::getNextUnset(int from) {
|
|||
return size;
|
||||
}
|
||||
int bitsOffset = from >> logBits;
|
||||
int currentBits = ~bits[bitsOffset];
|
||||
int currentBits = ~(*bits)[bitsOffset];
|
||||
// mask off lesser bits first
|
||||
currentBits &= ~((1 << (from & bitsMask)) - 1);
|
||||
while (currentBits == 0) {
|
||||
if (++bitsOffset == bits->size()) {
|
||||
return size;
|
||||
}
|
||||
currentBits = ~bits[bitsOffset];
|
||||
currentBits = ~(*bits)[bitsOffset];
|
||||
}
|
||||
int result = (bitsOffset << logBits) + numberOfTrailingZeros(currentBits);
|
||||
return result > size ? size : result;
|
||||
|
@ -212,7 +212,7 @@ void BitArray::appendBit(bool bit)
|
|||
{
|
||||
ensureCapacity(size + 1);
|
||||
if (bit) {
|
||||
bits[size / 32] |= 1 << (size & 0x1F);
|
||||
(*bits)[size / 32] |= 1 << (size & 0x1F);
|
||||
}
|
||||
size++;
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ void BitArray::ensureCapacity(int size)
|
|||
QSharedPointer<std::vector<int>> newBits = makeArray(size);
|
||||
//memcpy(bits, newBits->, bits->size());
|
||||
for (int i=0; i<bits->size(); ++i) {
|
||||
newBits[i] = bits[i];
|
||||
(*newBits)[i] = (*bits)[i];
|
||||
}
|
||||
bits = newBits;
|
||||
|
||||
|
@ -259,7 +259,7 @@ void BitArray::xor_(const BitArray& other)
|
|||
for (int i = 0; i < bits->size(); i++) {
|
||||
// The last byte could be incomplete (i.e. not have 8 bits in
|
||||
// it) but there is no problem since 0 XOR 0 == 0.
|
||||
bits[i] ^= other.bits[i];
|
||||
(*bits)[i] ^= (*(other.bits))[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ void BitMatrix::init(int width, int height) {
|
|||
this->width = width;
|
||||
this->height = height;
|
||||
this->rowSize = (width + 31) >> 5;
|
||||
bits = QSharedPointer<std::vector<int>>(rowSize * height);
|
||||
bits.reset(new std::vector<int>(rowSize * height));
|
||||
}
|
||||
|
||||
BitMatrix::BitMatrix(int dimension) {
|
||||
|
@ -52,7 +52,7 @@ BitMatrix::~BitMatrix() {}
|
|||
|
||||
void BitMatrix::flip(int x, int y) {
|
||||
int offset = y * rowSize + (x >> 5);
|
||||
bits[offset] ^= 1 << (x & 0x1f);
|
||||
(*bits)[offset] ^= 1 << (x & 0x1f);
|
||||
}
|
||||
|
||||
void BitMatrix::rotate180()
|
||||
|
@ -86,18 +86,18 @@ void BitMatrix::setRegion(int left, int top, int width, int height) {
|
|||
for (int y = top; y < bottom; y++) {
|
||||
int offset = y * rowSize;
|
||||
for (int x = left; x < right; x++) {
|
||||
bits[offset + (x >> 5)] |= 1 << (x & 0x1f);
|
||||
(*bits)[offset + (x >> 5)] |= 1 << (x & 0x1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QSharedPointer<BitArray> BitMatrix::getRow(int y, QSharedPointer<BitArray> row) {
|
||||
if (row.empty() || row->getSize() < width) {
|
||||
row = new BitArray(width);
|
||||
if (row.isNull() || row->getSize() < width) {
|
||||
row.reset(new BitArray(width));
|
||||
}
|
||||
int offset = y * rowSize;
|
||||
for (int x = 0; x < rowSize; x++) {
|
||||
row->setBulk(x << 5, bits[offset + x]);
|
||||
row->setBulk(x << 5, (*bits)[offset + x]);
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ void BitMatrix::setRow(int y, QSharedPointer<zxing::BitArray> row)
|
|||
|
||||
//change with memcopy
|
||||
for(int i=0; i<width; i++)
|
||||
bits[y * rowSize + i] = row->get(i);
|
||||
(*bits)[y * rowSize + i] = row->get(i);
|
||||
}
|
||||
|
||||
int BitMatrix::getWidth() const {
|
||||
|
@ -125,7 +125,7 @@ int BitMatrix::getHeight() const {
|
|||
|
||||
QSharedPointer<std::vector<int>> BitMatrix::getTopLeftOnBit() const {
|
||||
int bitsOffset = 0;
|
||||
while (bitsOffset < bits->size() && bits[bitsOffset] == 0) {
|
||||
while (bitsOffset < bits->size() && (*bits)[bitsOffset] == 0) {
|
||||
bitsOffset++;
|
||||
}
|
||||
if (bitsOffset == bits->size()) {
|
||||
|
@ -134,21 +134,21 @@ QSharedPointer<std::vector<int>> BitMatrix::getTopLeftOnBit() const {
|
|||
int y = bitsOffset / rowSize;
|
||||
int x = (bitsOffset % rowSize) << 5;
|
||||
|
||||
int theBits = bits[bitsOffset];
|
||||
int theBits = (*bits)[bitsOffset];
|
||||
int bit = 0;
|
||||
while ((theBits << (31-bit)) == 0) {
|
||||
bit++;
|
||||
}
|
||||
x += bit;
|
||||
QSharedPointer<std::vector<int>> res (2);
|
||||
res[0]=x;
|
||||
res[1]=y;
|
||||
QSharedPointer<std::vector<int>> res (new std::vector<int>(2));
|
||||
(*res)[0]=x;
|
||||
(*res)[1]=y;
|
||||
return res;
|
||||
}
|
||||
|
||||
QSharedPointer<std::vector<int>> BitMatrix::getBottomRightOnBit() const {
|
||||
int bitsOffset = bits->size() - 1;
|
||||
while (bitsOffset >= 0 && bits[bitsOffset] == 0) {
|
||||
while (bitsOffset >= 0 && (*bits)[bitsOffset] == 0) {
|
||||
bitsOffset--;
|
||||
}
|
||||
if (bitsOffset < 0) {
|
||||
|
@ -158,16 +158,16 @@ QSharedPointer<std::vector<int>> BitMatrix::getBottomRightOnBit() const {
|
|||
int y = bitsOffset / rowSize;
|
||||
int x = (bitsOffset % rowSize) << 5;
|
||||
|
||||
int theBits = bits[bitsOffset];
|
||||
int theBits = (*bits)[bitsOffset];
|
||||
int bit = 31;
|
||||
while ((theBits >> bit) == 0) {
|
||||
bit--;
|
||||
}
|
||||
x += bit;
|
||||
|
||||
QSharedPointer<std::vector<int>> res (2);
|
||||
res[0]=x;
|
||||
res[1]=y;
|
||||
QSharedPointer<std::vector<int>> res (new std::vector<int>(2));
|
||||
(*res)[0]=x;
|
||||
(*res)[1]=y;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -180,7 +180,7 @@ QSharedPointer<std::vector<int>> BitMatrix::getEnclosingRectangle() const
|
|||
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x32 = 0; x32 < rowSize; x32++) {
|
||||
int theBits = bits[y * rowSize + x32];
|
||||
int theBits = (*bits)[y * rowSize + x32];
|
||||
if (theBits != 0) {
|
||||
if (y < top) {
|
||||
top = y;
|
||||
|
@ -217,11 +217,11 @@ QSharedPointer<std::vector<int>> BitMatrix::getEnclosingRectangle() const
|
|||
return QSharedPointer<std::vector<int>>();
|
||||
}
|
||||
|
||||
QSharedPointer<std::vector<int>> res(4);
|
||||
res[0] = left;
|
||||
res[1] = top;
|
||||
res[2] = width;
|
||||
res[3] = height;
|
||||
QSharedPointer<std::vector<int>> res(new std::vector<int>(4));
|
||||
(*res)[0] = left;
|
||||
(*res)[1] = top;
|
||||
(*res)[2] = width;
|
||||
(*res)[3] = height;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ int BitSource::readBits(int numBits) {
|
|||
int toRead = numBits < bitsLeft ? numBits : bitsLeft;
|
||||
int bitsToNotRead = bitsLeft - toRead;
|
||||
int mask = (0xFF >> (8 - toRead)) << bitsToNotRead;
|
||||
result = (bytes_[byteOffset_] & mask) >> bitsToNotRead;
|
||||
result = ((*bytes_)[byteOffset_] & mask) >> bitsToNotRead;
|
||||
numBits -= toRead;
|
||||
bitOffset_ += toRead;
|
||||
if (bitOffset_ == 8) {
|
||||
|
@ -52,7 +52,7 @@ int BitSource::readBits(int numBits) {
|
|||
// Next read whole bytes
|
||||
if (numBits > 0) {
|
||||
while (numBits >= 8) {
|
||||
result = (result << 8) | (bytes_[byteOffset_] & 0xFF);
|
||||
result = (result << 8) | ((*bytes_)[byteOffset_] & 0xFF);
|
||||
byteOffset_++;
|
||||
numBits -= 8;
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ int BitSource::readBits(int numBits) {
|
|||
if (numBits > 0) {
|
||||
int bitsToNotRead = 8 - numBits;
|
||||
int mask = (0xFF >> bitsToNotRead) << bitsToNotRead;
|
||||
result = (result << numBits) | ((bytes_[byteOffset_] & mask) >> bitsToNotRead);
|
||||
result = (result << numBits) | (((*bytes_)[byteOffset_] & mask) >> bitsToNotRead);
|
||||
bitOffset_ += numBits;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ bool CharacterSetECI::init_tables() {
|
|||
}
|
||||
|
||||
CharacterSetECI::CharacterSetECI(const std::vector<int> values, const std::vector<const char*> names)
|
||||
: Counted(), values_(values)
|
||||
: values_(values)
|
||||
{
|
||||
for(size_t i=0; i<names.size(); i++)
|
||||
names_.push_back(std::string(names[i]));
|
||||
|
|
|
@ -39,18 +39,18 @@ const int LUMINANCE_BUCKETS = 1 << LUMINANCE_BITS;
|
|||
const QSharedPointer<std::vector<zxing::byte>> EMPTY (0);
|
||||
|
||||
GlobalHistogramBinarizer::GlobalHistogramBinarizer(QSharedPointer<LuminanceSource> source)
|
||||
: Binarizer(source), luminances(EMPTY), buckets(LUMINANCE_BUCKETS) {}
|
||||
: Binarizer(source), luminances(EMPTY), buckets(new std::vector<int>(LUMINANCE_BUCKETS)) {}
|
||||
|
||||
GlobalHistogramBinarizer::~GlobalHistogramBinarizer() {}
|
||||
|
||||
void GlobalHistogramBinarizer::initArrays(int luminanceSize) {
|
||||
if (luminances->size() < luminanceSize) {
|
||||
luminances = QSharedPointer<std::vector<zxing::byte>>(luminanceSize);
|
||||
luminances.reset(new std::vector<zxing::byte>(luminanceSize));
|
||||
}
|
||||
// for (int x = 0; x < LUMINANCE_BUCKETS; x++) {
|
||||
// buckets[x] = 0;
|
||||
// }
|
||||
memset(&buckets[0], 0, sizeof(int) * LUMINANCE_BUCKETS);
|
||||
memset(&(*buckets)[0], 0, sizeof(int) * LUMINANCE_BUCKETS);
|
||||
}
|
||||
|
||||
QSharedPointer<BitArray> GlobalHistogramBinarizer::getBlackRow(int y, QSharedPointer<BitArray> row) {
|
||||
|
@ -58,7 +58,7 @@ QSharedPointer<BitArray> GlobalHistogramBinarizer::getBlackRow(int y, QSharedPoi
|
|||
LuminanceSource& source = *getLuminanceSource();
|
||||
int width = source.getWidth();
|
||||
if (row == NULL || static_cast<int>(row->getSize()) < width) {
|
||||
row = new BitArray(width);
|
||||
row.reset(new BitArray(width));
|
||||
} else {
|
||||
row->clear();
|
||||
}
|
||||
|
@ -68,22 +68,22 @@ QSharedPointer<BitArray> GlobalHistogramBinarizer::getBlackRow(int y, QSharedPoi
|
|||
if (false) {
|
||||
std::cerr << "gbr " << y << " r ";
|
||||
for(int i=0, e=localLuminances->size(); i < e; ++i) {
|
||||
std::cerr << 0+localLuminances[i] << " ";
|
||||
std::cerr << 0+(*localLuminances)[i] << " ";
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
QSharedPointer<std::vector<int>> localBuckets = buckets;
|
||||
for (int x = 0; x < width; x++) {
|
||||
int pixel = localLuminances[x] & 0xff;
|
||||
localBuckets[pixel >> LUMINANCE_SHIFT]++;
|
||||
int pixel = (*localLuminances)[x] & 0xff;
|
||||
(*localBuckets)[pixel >> LUMINANCE_SHIFT]++;
|
||||
}
|
||||
int blackPoint = estimateBlackPoint(localBuckets);
|
||||
// std::cerr << "gbr bp " << y << " " << blackPoint << std::endl;
|
||||
|
||||
int left = localLuminances[0] & 0xff;
|
||||
int center = localLuminances[1] & 0xff;
|
||||
int left = (*localLuminances)[0] & 0xff;
|
||||
int center = (*localLuminances)[1] & 0xff;
|
||||
for (int x = 1; x < width - 1; x++) {
|
||||
int right = localLuminances[x + 1] & 0xff;
|
||||
int right = (*localLuminances)[x + 1] & 0xff;
|
||||
// A simple -1 4 -1 box filter with a weight of 2.
|
||||
int luminance = ((center << 2) - left - right) >> 1;
|
||||
if (luminance < blackPoint) {
|
||||
|
@ -111,8 +111,8 @@ QSharedPointer<BitMatrix> GlobalHistogramBinarizer::getBlackMatrix() {
|
|||
QSharedPointer<std::vector<zxing::byte>> localLuminances = source.getRow(row, luminances);
|
||||
int right = (width << 2) / 5;
|
||||
for (int x = width / 5; x < right; x++) {
|
||||
int pixel = localLuminances[x] & 0xff;
|
||||
localBuckets[pixel >> LUMINANCE_SHIFT]++;
|
||||
int pixel = (*localLuminances)[x] & 0xff;
|
||||
(*localBuckets)[pixel >> LUMINANCE_SHIFT]++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ QSharedPointer<BitMatrix> GlobalHistogramBinarizer::getBlackMatrix() {
|
|||
for (int y = 0; y < height; y++) {
|
||||
int offset = y * width;
|
||||
for (int x = 0; x < width; x++) {
|
||||
int pixel = localLuminances[offset + x] & 0xff;
|
||||
int pixel = (*localLuminances)[offset + x] & 0xff;
|
||||
if (pixel < blackPoint) {
|
||||
matrix->set(x, y);
|
||||
}
|
||||
|
@ -142,17 +142,17 @@ int GlobalHistogramBinarizer::estimateBlackPoint(QSharedPointer<std::vector<int>
|
|||
int firstPeakSize = 0;
|
||||
if (false) {
|
||||
for (int x = 0; x < numBuckets; x++) {
|
||||
cerr << buckets[x] << " ";
|
||||
cerr << (*buckets)[x] << " ";
|
||||
}
|
||||
cerr << endl;
|
||||
}
|
||||
for (int x = 0; x < numBuckets; x++) {
|
||||
if (buckets[x] > firstPeakSize) {
|
||||
if ((*buckets)[x] > firstPeakSize) {
|
||||
firstPeak = x;
|
||||
firstPeakSize = buckets[x];
|
||||
firstPeakSize = (*buckets)[x];
|
||||
}
|
||||
if (buckets[x] > maxBucketCount) {
|
||||
maxBucketCount = buckets[x];
|
||||
if ((*buckets)[x] > maxBucketCount) {
|
||||
maxBucketCount = (*buckets)[x];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ int GlobalHistogramBinarizer::estimateBlackPoint(QSharedPointer<std::vector<int>
|
|||
for (int x = 0; x < numBuckets; x++) {
|
||||
int distanceToBiggest = x - firstPeak;
|
||||
// Encourage more distant second peaks by multiplying by square of distance
|
||||
int score = buckets[x] * distanceToBiggest * distanceToBiggest;
|
||||
int score = (*buckets)[x] * distanceToBiggest * distanceToBiggest;
|
||||
if (score > secondPeakScore) {
|
||||
secondPeak = x;
|
||||
secondPeakScore = score;
|
||||
|
@ -196,7 +196,7 @@ int GlobalHistogramBinarizer::estimateBlackPoint(QSharedPointer<std::vector<int>
|
|||
// Favor a "valley" that is not too close to either peak -- especially not
|
||||
// the black peak -- and that has a low value of course
|
||||
int score = fromFirst * fromFirst * (secondPeak - x) *
|
||||
(maxBucketCount - buckets[x]);
|
||||
(maxBucketCount - (*buckets)[x]);
|
||||
if (score > bestValleyScore) {
|
||||
bestValley = x;
|
||||
bestValleyScore = score;
|
||||
|
|
|
@ -49,11 +49,11 @@ QSharedPointer<std::vector<zxing::byte>> GreyscaleLuminanceSource::getRow(int y,
|
|||
}
|
||||
int width = getWidth();
|
||||
if (!row || row->size() < width) {
|
||||
QSharedPointer<std::vector<zxing::byte>> temp (width);
|
||||
QSharedPointer<std::vector<zxing::byte>> temp (new std::vector<zxing::byte>(width));
|
||||
row = temp;
|
||||
}
|
||||
int offset = (y + top_) * dataWidth_ + left_;
|
||||
memcpy(&row[0], &greyData_[offset], width);
|
||||
memcpy(&(*row)[0], &(*greyData_)[offset], width);
|
||||
return row;
|
||||
}
|
||||
|
||||
|
@ -62,9 +62,9 @@ QSharedPointer<std::vector<zxing::byte>> GreyscaleLuminanceSource::getMatrix() c
|
|||
return greyData_;
|
||||
|
||||
int size = getWidth() * getHeight();
|
||||
QSharedPointer<std::vector<zxing::byte>> result (size);
|
||||
QSharedPointer<std::vector<zxing::byte>> result (new std::vector<zxing::byte>(size));
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -56,14 +56,14 @@ vector<QSharedPointer<ResultPoint> > MonochromeRectangleDetector::detect() {
|
|||
bottom = (int) pointD->getY() + 1;
|
||||
|
||||
// Go try to find point A again with better information -- might have been off at first.
|
||||
pointA.reset(findCornerFromCenter(halfWidth, 0, left, right,
|
||||
halfHeight, -deltaY, top, bottom, halfWidth >> 2));
|
||||
pointA = findCornerFromCenter(halfWidth, 0, left, right,
|
||||
halfHeight, -deltaY, top, bottom, halfWidth >> 2);
|
||||
|
||||
vector<QSharedPointer<ResultPoint> > corners(4);
|
||||
corners[0].reset(pointA);
|
||||
corners[1].reset(pointB);
|
||||
corners[2].reset(pointC);
|
||||
corners[3].reset(pointD);
|
||||
corners[0] = pointA;
|
||||
corners[1] = pointB;
|
||||
corners[2] = pointC;
|
||||
corners[3] = pointD;
|
||||
return corners;
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ QSharedPointer<TwoInts> MonochromeRectangleDetector::blackWhiteRange(int fixedDi
|
|||
end--;
|
||||
QSharedPointer<TwoInts> result(NULL);
|
||||
if (end > start) {
|
||||
result = new TwoInts;
|
||||
result.reset(new TwoInts);
|
||||
result->start = start;
|
||||
result->end = end;
|
||||
}
|
||||
|
|
|
@ -276,19 +276,19 @@ vector<QSharedPointer<ResultPoint> > WhiteRectangleDetector::centerEdges(QShared
|
|||
QSharedPointer<ResultPoint> pointB(new ResultPoint(zi + CORR, zj + CORR));
|
||||
QSharedPointer<ResultPoint> pointC(new ResultPoint(xi - CORR, xj - CORR));
|
||||
QSharedPointer<ResultPoint> pointD(new ResultPoint(yi + CORR, yj - CORR));
|
||||
corners[0].reset(pointA);
|
||||
corners[1].reset(pointB);
|
||||
corners[2].reset(pointC);
|
||||
corners[3].reset(pointD);
|
||||
corners[0] = pointA;
|
||||
corners[1] = pointB;
|
||||
corners[2] = pointC;
|
||||
corners[3] = pointD;
|
||||
} else {
|
||||
QSharedPointer<ResultPoint> pointA(new ResultPoint(ti + CORR, tj + CORR));
|
||||
QSharedPointer<ResultPoint> pointB(new ResultPoint(zi + CORR, zj - CORR));
|
||||
QSharedPointer<ResultPoint> pointC(new ResultPoint(xi - CORR, xj + CORR));
|
||||
QSharedPointer<ResultPoint> pointD(new ResultPoint(yi - CORR, yj - CORR));
|
||||
corners[0].reset(pointA);
|
||||
corners[1].reset(pointB);
|
||||
corners[2].reset(pointC);
|
||||
corners[3].reset(pointD);
|
||||
corners[0] = pointA;
|
||||
corners[1] = pointB;
|
||||
corners[2] = pointC;
|
||||
corners[3] = pointD;
|
||||
}
|
||||
return corners;
|
||||
}
|
||||
|
|
|
@ -71,11 +71,11 @@ void GenericGF::initialize() {
|
|||
logTable.at(expTable.at(i)) = i;
|
||||
}
|
||||
//logTable[0] == 0 but this should never be used
|
||||
QSharedPointer<std::vector<int>> coefficients_zero(1);
|
||||
QSharedPointer<std::vector<int>> coefficients_one(1);
|
||||
QSharedPointer<std::vector<int>> coefficients_zero(new std::vector<int>(1));
|
||||
QSharedPointer<std::vector<int>> coefficients_one(new std::vector<int>(1));
|
||||
|
||||
coefficients_zero[0] = 0;
|
||||
coefficients_one[0] = 1;
|
||||
(*coefficients_zero)[0] = 0;
|
||||
(*coefficients_one)[0] = 1;
|
||||
|
||||
zero = QSharedPointer<GenericGFPoly>(new GenericGFPoly(this, coefficients_zero));
|
||||
one = QSharedPointer<GenericGFPoly>(new GenericGFPoly(this, coefficients_one));
|
||||
|
@ -107,8 +107,8 @@ QSharedPointer<GenericGFPoly> GenericGF::buildMonomial(int degree, int coefficie
|
|||
if (coefficient == 0) {
|
||||
return zero;
|
||||
}
|
||||
QSharedPointer<std::vector<int>> coefficients(degree + 1);
|
||||
coefficients[0] = coefficient;
|
||||
QSharedPointer<std::vector<int>> coefficients(new std::vector<int>(degree + 1));
|
||||
(*coefficients)[0] = coefficient;
|
||||
|
||||
return QSharedPointer<GenericGFPoly>(new GenericGFPoly(this, coefficients));
|
||||
}
|
||||
|
|
|
@ -31,25 +31,25 @@ using zxing::GenericGFPoly;
|
|||
// VC++
|
||||
using zxing::GenericGF;
|
||||
|
||||
GenericGFPoly::GenericGFPoly(GenericGF *field,
|
||||
GenericGFPoly::GenericGFPoly(zxing::GenericGF *field,
|
||||
QSharedPointer<std::vector<int>> coefficients)
|
||||
: field_(field) {
|
||||
if (coefficients->size() == 0) {
|
||||
throw IllegalArgumentException("need coefficients");
|
||||
}
|
||||
int coefficientsLength = coefficients->size();
|
||||
if (coefficientsLength > 1 && coefficients[0] == 0) {
|
||||
if (coefficientsLength > 1 && (*coefficients)[0] == 0) {
|
||||
// Leading term must be non-zero for anything except the constant polynomial "0"
|
||||
int firstNonZero = 1;
|
||||
while (firstNonZero < coefficientsLength && coefficients[firstNonZero] == 0) {
|
||||
while (firstNonZero < coefficientsLength && (*coefficients)[firstNonZero] == 0) {
|
||||
firstNonZero++;
|
||||
}
|
||||
if (firstNonZero == coefficientsLength) {
|
||||
coefficients_ = field->getZero()->getCoefficients();
|
||||
} else {
|
||||
coefficients_ = QSharedPointer<std::vector<int>>(coefficientsLength-firstNonZero);
|
||||
coefficients_.reset(new std::vector<int>(coefficientsLength-firstNonZero));
|
||||
for (int i = 0; i < (int)coefficients_->size(); i++) {
|
||||
coefficients_[i] = coefficients[i + firstNonZero];
|
||||
(*coefficients_)[i] = (*coefficients)[i + firstNonZero];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -66,11 +66,11 @@ int GenericGFPoly::getDegree() {
|
|||
}
|
||||
|
||||
bool GenericGFPoly::isZero() {
|
||||
return coefficients_[0] == 0;
|
||||
return (*coefficients_)[0] == 0;
|
||||
}
|
||||
|
||||
int GenericGFPoly::getCoefficient(int degree) {
|
||||
return coefficients_[coefficients_->size() - 1 - degree];
|
||||
return (*coefficients_)[coefficients_->size() - 1 - degree];
|
||||
}
|
||||
|
||||
int GenericGFPoly::evaluateAt(int a) {
|
||||
|
@ -84,13 +84,13 @@ int GenericGFPoly::evaluateAt(int a) {
|
|||
// Just the sum of the coefficients
|
||||
int result = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
result = GenericGF::addOrSubtract(result, coefficients_[i]);
|
||||
result = GenericGF::addOrSubtract(result, (*coefficients_)[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
int result = coefficients_[0];
|
||||
int result = (*coefficients_)[0];
|
||||
for (int i = 1; i < size; i++) {
|
||||
result = GenericGF::addOrSubtract(field_->multiply(a, result), coefficients_[i]);
|
||||
result = GenericGF::addOrSubtract(field_->multiply(a, result), (*coefficients_)[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -114,16 +114,16 @@ QSharedPointer<GenericGFPoly> GenericGFPoly::addOrSubtract(QSharedPointer<zxing:
|
|||
largerCoefficients = temp;
|
||||
}
|
||||
|
||||
QSharedPointer<std::vector<int>> sumDiff(largerCoefficients->size());
|
||||
QSharedPointer<std::vector<int>> sumDiff(new std::vector<int>(largerCoefficients->size()));
|
||||
int lengthDiff = largerCoefficients->size() - smallerCoefficients->size();
|
||||
// Copy high-order terms only found in higher-degree polynomial's coefficients
|
||||
for (int i = 0; i < lengthDiff; i++) {
|
||||
sumDiff[i] = largerCoefficients[i];
|
||||
(*sumDiff)[i] = (*largerCoefficients)[i];
|
||||
}
|
||||
|
||||
for (int i = lengthDiff; i < (int)largerCoefficients->size(); i++) {
|
||||
sumDiff[i] = GenericGF::addOrSubtract(smallerCoefficients[i-lengthDiff],
|
||||
largerCoefficients[i]);
|
||||
(*sumDiff)[i] = GenericGF::addOrSubtract((*smallerCoefficients)[i-lengthDiff],
|
||||
(*largerCoefficients)[i]);
|
||||
}
|
||||
|
||||
return QSharedPointer<GenericGFPoly>(new GenericGFPoly(field_, sumDiff));
|
||||
|
@ -144,12 +144,12 @@ QSharedPointer<GenericGFPoly> GenericGFPoly::multiply(QSharedPointer<zxing::Gene
|
|||
QSharedPointer<std::vector<int>> bCoefficients = other->getCoefficients();
|
||||
int bLength = bCoefficients->size();
|
||||
|
||||
QSharedPointer<std::vector<int>> product(aLength + bLength - 1);
|
||||
QSharedPointer<std::vector<int>> product(new std::vector<int>(aLength + bLength - 1));
|
||||
for (int i = 0; i < aLength; i++) {
|
||||
int aCoeff = aCoefficients[i];
|
||||
int aCoeff = (*aCoefficients)[i];
|
||||
for (int j = 0; j < bLength; j++) {
|
||||
product[i+j] = GenericGF::addOrSubtract(product[i+j],
|
||||
field_->multiply(aCoeff, bCoefficients[j]));
|
||||
(*product)[i+j] = GenericGF::addOrSubtract((*product)[i+j],
|
||||
field_->multiply(aCoeff, (*bCoefficients)[j]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,9 +164,9 @@ QSharedPointer<GenericGFPoly> GenericGFPoly::multiply(int scalar) {
|
|||
return QSharedPointer<GenericGFPoly>(this);
|
||||
}
|
||||
int size = coefficients_->size();
|
||||
QSharedPointer<std::vector<int>> product(size);
|
||||
QSharedPointer<std::vector<int>> product(new std::vector<int>(size));
|
||||
for (int i = 0; i < size; i++) {
|
||||
product[i] = field_->multiply(coefficients_[i], scalar);
|
||||
(*product)[i] = field_->multiply((*coefficients_)[i], scalar);
|
||||
}
|
||||
return QSharedPointer<GenericGFPoly>(new GenericGFPoly(field_, product));
|
||||
}
|
||||
|
@ -179,9 +179,9 @@ QSharedPointer<GenericGFPoly> GenericGFPoly::multiplyByMonomial(int degree, int
|
|||
return field_->getZero();
|
||||
}
|
||||
int size = coefficients_->size();
|
||||
QSharedPointer<std::vector<int>> product(size+degree);
|
||||
QSharedPointer<std::vector<int>> product(new std::vector<int>(size+degree));
|
||||
for (int i = 0; i < size; i++) {
|
||||
product[i] = field_->multiply(coefficients_[i], coefficient);
|
||||
(*product)[i] = field_->multiply((*coefficients_)[i], coefficient);
|
||||
}
|
||||
return QSharedPointer<GenericGFPoly>(new GenericGFPoly(field_, product));
|
||||
}
|
||||
|
|
|
@ -40,12 +40,12 @@ ReedSolomonDecoder::~ReedSolomonDecoder() {
|
|||
}
|
||||
|
||||
void ReedSolomonDecoder::decode(QSharedPointer<std::vector<int>> received, int twoS) {
|
||||
QSharedPointer<GenericGFPoly> poly(new GenericGFPoly(field, received));
|
||||
QSharedPointer<std::vector<int>> syndromeCoefficients(twoS);
|
||||
QSharedPointer<GenericGFPoly> poly(new GenericGFPoly(field.data(), received));
|
||||
QSharedPointer<std::vector<int>> syndromeCoefficients(new std::vector<int>(twoS));
|
||||
bool noError = true;
|
||||
for (int i = 0; i < twoS; i++) {
|
||||
int eval = poly->evaluateAt(field->exp(i + field->getGeneratorBase()));
|
||||
syndromeCoefficients[syndromeCoefficients->size() - 1 - i] = eval;
|
||||
(*syndromeCoefficients)[syndromeCoefficients->size() - 1 - i] = eval;
|
||||
if (eval != 0) {
|
||||
noError = false;
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ void ReedSolomonDecoder::decode(QSharedPointer<std::vector<int>> received, int t
|
|||
if (noError) {
|
||||
return;
|
||||
}
|
||||
QSharedPointer<GenericGFPoly> syndrome(new GenericGFPoly(field, syndromeCoefficients));
|
||||
QSharedPointer<GenericGFPoly> syndrome(new GenericGFPoly(field.data(), syndromeCoefficients));
|
||||
vector<QSharedPointer<GenericGFPoly> > sigmaOmega =
|
||||
runEuclideanAlgorithm(field->buildMonomial(twoS, 1), syndrome, twoS);
|
||||
QSharedPointer<GenericGFPoly> sigma = sigmaOmega[0];
|
||||
|
@ -61,11 +61,11 @@ void ReedSolomonDecoder::decode(QSharedPointer<std::vector<int>> received, int t
|
|||
QSharedPointer<std::vector<int>> errorLocations = findErrorLocations(sigma);
|
||||
QSharedPointer<std::vector<int>> errorMagitudes = findErrorMagnitudes(omega, errorLocations);
|
||||
for (int i = 0; i < errorLocations->size(); i++) {
|
||||
int position = received->size() - 1 - field->log(errorLocations[i]);
|
||||
int position = received->size() - 1 - field->log((*errorLocations)[i]);
|
||||
if (position < 0) {
|
||||
throw ReedSolomonException("Bad error location");
|
||||
}
|
||||
received[position] = GenericGF::addOrSubtract(received[position], errorMagitudes[i]);
|
||||
(*received)[position] = GenericGF::addOrSubtract((*received)[position], (*errorMagitudes)[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,14 +133,14 @@ QSharedPointer<std::vector<int>> ReedSolomonDecoder::findErrorLocations(QSharedP
|
|||
int numErrors = errorLocator->getDegree();
|
||||
if (numErrors == 1) { // shortcut
|
||||
QSharedPointer<std::vector<int>> result(new std::vector<int>(1));
|
||||
result[0] = errorLocator->getCoefficient(1);
|
||||
(*result)[0] = errorLocator->getCoefficient(1);
|
||||
return result;
|
||||
}
|
||||
QSharedPointer<std::vector<int>> result(new std::vector<int>(numErrors));
|
||||
int e = 0;
|
||||
for (size_t i = 1; i < field->getSize() && e < numErrors; i++) {
|
||||
if (errorLocator->evaluateAt(i) == 0) {
|
||||
result[e] = field->inverse(i);
|
||||
(*result)[e] = field->inverse(i);
|
||||
e++;
|
||||
}
|
||||
}
|
||||
|
@ -155,19 +155,19 @@ QSharedPointer<std::vector<int>> ReedSolomonDecoder::findErrorMagnitudes(QShared
|
|||
int s = errorLocations->size();
|
||||
QSharedPointer<std::vector<int>> result(new std::vector<int>(s));
|
||||
for (int i = 0; i < s; i++) {
|
||||
int xiInverse = field->inverse(errorLocations[i]);
|
||||
int xiInverse = field->inverse((*errorLocations)[i]);
|
||||
int denominator = 1;
|
||||
for (int j = 0; j < s; j++) {
|
||||
if (i != j) {
|
||||
int term = 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),
|
||||
(*result)[i] = field->multiply(errorEvaluator->evaluateAt(xiInverse),
|
||||
field->inverse(denominator));
|
||||
if (field->getGeneratorBase() != 0) {
|
||||
result[i] = field->multiply(result[i], xiInverse);
|
||||
(*result)[i] = field->multiply((*result)[i], xiInverse);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue