diff --git a/cpp/core/src/zxing/LuminanceSource.cpp b/cpp/core/src/zxing/LuminanceSource.cpp index 834dba28a..99d54dffa 100644 --- a/cpp/core/src/zxing/LuminanceSource.cpp +++ b/cpp/core/src/zxing/LuminanceSource.cpp @@ -1,3 +1,4 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * LuminanceSource.cpp * zxing @@ -17,6 +18,7 @@ * limitations under the License. */ +#include #include #include @@ -44,4 +46,31 @@ Ref LuminanceSource::rotateCounterClockwise() { 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(); +} + + + } diff --git a/cpp/core/src/zxing/LuminanceSource.h b/cpp/core/src/zxing/LuminanceSource.h index 68a6e3514..7130808f5 100644 --- a/cpp/core/src/zxing/LuminanceSource.h +++ b/cpp/core/src/zxing/LuminanceSource.h @@ -1,3 +1,4 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- #ifndef __LUMINANCESOURCE_H__ #define __LUMINANCESOURCE_H__ /* @@ -42,6 +43,8 @@ public: virtual bool isRotateSupported() const; virtual Ref rotateCounterClockwise(); + operator std::string (); // should be const but don't want to make sure a + // large breaking change right now }; } diff --git a/cpp/core/src/zxing/common/BitArray.cpp b/cpp/core/src/zxing/common/BitArray.cpp index 02a2a19c3..ee3d1726d 100644 --- a/cpp/core/src/zxing/common/BitArray.cpp +++ b/cpp/core/src/zxing/common/BitArray.cpp @@ -1,3 +1,4 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * BitArray.cpp * zxing @@ -70,6 +71,32 @@ void BitArray::setBulk(size_t i, unsigned int 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() { size_t max = bits_.size(); for (size_t i = 0; i < max; i++) { diff --git a/cpp/core/src/zxing/common/BitArray.h b/cpp/core/src/zxing/common/BitArray.h index b0b23245f..d8a041b84 100644 --- a/cpp/core/src/zxing/common/BitArray.h +++ b/cpp/core/src/zxing/common/BitArray.h @@ -1,3 +1,4 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- #ifndef __BIT_ARRAY_H__ #define __BIT_ARRAY_H__ @@ -44,6 +45,7 @@ public: bool get(size_t i); void set(size_t i); void setBulk(size_t i, unsigned int newBits); + void setRange(int start, int end); void clear(); bool isRange(size_t start, size_t end, bool value); std::vector& getBitArray();