mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
port r1899 java changes to C++
git-svn-id: https://zxing.googlecode.com/svn/trunk@1960 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
b72031d6e8
commit
c7e2f62050
|
@ -1,3 +1,4 @@
|
||||||
|
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||||
/*
|
/*
|
||||||
* LuminanceSource.cpp
|
* LuminanceSource.cpp
|
||||||
* zxing
|
* zxing
|
||||||
|
@ -17,6 +18,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
#include <zxing/LuminanceSource.h>
|
#include <zxing/LuminanceSource.h>
|
||||||
#include <zxing/common/IllegalArgumentException.h>
|
#include <zxing/common/IllegalArgumentException.h>
|
||||||
|
|
||||||
|
@ -44,4 +46,31 @@ Ref<LuminanceSource> LuminanceSource::rotateCounterClockwise() {
|
||||||
throw IllegalArgumentException("This luminance source does not support rotation.");
|
throw IllegalArgumentException("This luminance source does not support rotation.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LuminanceSource::operator std::string() {
|
||||||
|
unsigned char* row = 0;
|
||||||
|
std::ostringstream oss;
|
||||||
|
for (int y = 0; y < getHeight(); y++) {
|
||||||
|
row = getRow(y, row);
|
||||||
|
for (int x = 0; x < getWidth(); x++) {
|
||||||
|
int luminance = row[x] & 0xFF;
|
||||||
|
char c;
|
||||||
|
if (luminance < 0x40) {
|
||||||
|
c = '#';
|
||||||
|
} else if (luminance < 0x80) {
|
||||||
|
c = '+';
|
||||||
|
} else if (luminance < 0xC0) {
|
||||||
|
c = '.';
|
||||||
|
} else {
|
||||||
|
c = ' ';
|
||||||
|
}
|
||||||
|
oss << c;
|
||||||
|
}
|
||||||
|
oss << '\n';
|
||||||
|
}
|
||||||
|
delete [] row;
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||||
#ifndef __LUMINANCESOURCE_H__
|
#ifndef __LUMINANCESOURCE_H__
|
||||||
#define __LUMINANCESOURCE_H__
|
#define __LUMINANCESOURCE_H__
|
||||||
/*
|
/*
|
||||||
|
@ -42,6 +43,8 @@ public:
|
||||||
virtual bool isRotateSupported() const;
|
virtual bool isRotateSupported() const;
|
||||||
virtual Ref<LuminanceSource> rotateCounterClockwise();
|
virtual Ref<LuminanceSource> rotateCounterClockwise();
|
||||||
|
|
||||||
|
operator std::string (); // should be const but don't want to make sure a
|
||||||
|
// large breaking change right now
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||||
/*
|
/*
|
||||||
* BitArray.cpp
|
* BitArray.cpp
|
||||||
* zxing
|
* zxing
|
||||||
|
@ -70,6 +71,32 @@ void BitArray::setBulk(size_t i, unsigned int newBits) {
|
||||||
bits_[i >> logBits_] = newBits;
|
bits_[i >> logBits_] = newBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BitArray::setRange(int start, int end) {
|
||||||
|
if (end < start) {
|
||||||
|
throw new IllegalArgumentException("invalid call to BitArray::setRange");
|
||||||
|
}
|
||||||
|
if (end == start) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
end--; // will be easier to treat this as the last actually set bit -- inclusive
|
||||||
|
int firstInt = start >> 5;
|
||||||
|
int lastInt = end >> 5;
|
||||||
|
for (int i = firstInt; i <= lastInt; i++) {
|
||||||
|
int firstBit = i > firstInt ? 0 : start & 0x1F;
|
||||||
|
int lastBit = i < lastInt ? 31 : end & 0x1F;
|
||||||
|
int mask;
|
||||||
|
if (firstBit == 0 && lastBit == 31) {
|
||||||
|
mask = -1;
|
||||||
|
} else {
|
||||||
|
mask = 0;
|
||||||
|
for (int j = firstBit; j <= lastBit; j++) {
|
||||||
|
mask |= 1 << j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bits_[i] |= mask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BitArray::clear() {
|
void BitArray::clear() {
|
||||||
size_t max = bits_.size();
|
size_t max = bits_.size();
|
||||||
for (size_t i = 0; i < max; i++) {
|
for (size_t i = 0; i < max; i++) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||||
#ifndef __BIT_ARRAY_H__
|
#ifndef __BIT_ARRAY_H__
|
||||||
#define __BIT_ARRAY_H__
|
#define __BIT_ARRAY_H__
|
||||||
|
|
||||||
|
@ -44,6 +45,7 @@ public:
|
||||||
bool get(size_t i);
|
bool get(size_t i);
|
||||||
void set(size_t i);
|
void set(size_t i);
|
||||||
void setBulk(size_t i, unsigned int newBits);
|
void setBulk(size_t i, unsigned int newBits);
|
||||||
|
void setRange(int start, int end);
|
||||||
void clear();
|
void clear();
|
||||||
bool isRange(size_t start, size_t end, bool value);
|
bool isRange(size_t start, size_t end, bool value);
|
||||||
std::vector<unsigned int>& getBitArray();
|
std::vector<unsigned int>& getBitArray();
|
||||||
|
|
Loading…
Reference in a new issue