C++ Port:

- Fixed to be able to build for the Symbian emulator (variable-sized arrays cannot be created on the stack).
- Fixed bug only present on Symbian phones that prevented the alignment patterns from being found (the Symbian implementation of valarray does not initialize its values to 0, unless it is explicitly specified as the default value).
- Fixed an include.

git-svn-id: https://zxing.googlecode.com/svn/trunk@1100 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
ralf.kistner@gmail.com 2009-11-05 22:11:15 +00:00
parent d2fea027ec
commit 4c51e618e3
4 changed files with 274 additions and 259 deletions

View file

@ -13,7 +13,7 @@ compile_options['CXXFLAGS'] = ' '.join(flags)
def all_files(dir, ext='.cpp', level=5):
files = []
for i in range(level):
for i in range(1, level):
files += Glob(dir + ('/*' * i) + ext)
return files

View file

@ -29,7 +29,7 @@
#include <typeinfo>
#endif
#include "Counted.h"
#include <zxing/common/Counted.h>
namespace zxing {

View file

@ -23,6 +23,11 @@
#include <iconv.h>
// Required for compatibility. TODO: test on Symbian
#ifdef ZXING_ICONV_CONST
#undef ICONV_CONST
#define ICONV_CONST const
#endif
#ifndef ICONV_CONST
#define ICONV_CONST /**/
#endif
@ -51,8 +56,8 @@ void DecodedBitStreamParser::append(ostream &ost, const unsigned char *bufIn, si
}
iconv_t cd = iconv_open(UTF8, src);
int maxOut = 4 * nIn + 1;
unsigned char bufOut[maxOut];
const int maxOut = 4 * nIn + 1;
unsigned char* bufOut = new unsigned char[maxOut];
ICONV_CONST char *fromPtr = (ICONV_CONST char *)bufIn;
size_t nFrom = nIn;
@ -63,6 +68,7 @@ void DecodedBitStreamParser::append(ostream &ost, const unsigned char *bufIn, si
size_t oneway = iconv(cd, &fromPtr, &nFrom, &toPtr, &nTo);
if (oneway == (size_t)(-1)) {
iconv_close(cd);
delete[] bufOut;
throw ReaderException("error converting characters");
}
}
@ -72,13 +78,14 @@ void DecodedBitStreamParser::append(ostream &ost, const unsigned char *bufIn, si
bufOut[nResult] = '\0';
ost << bufOut;
delete[] bufOut;
}
void DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, ostringstream &result, int count) {
// Each character will require 2 bytes. Read the characters as 2-byte pairs
// and decode as Shift_JIS afterwards
size_t nBytes = 2 * count;
unsigned char buffer[nBytes];
unsigned char* buffer = new unsigned char[nBytes];
int offset = 0;
while (count > 0) {
// Each 13 bits encodes a 2-byte character
@ -99,14 +106,16 @@ void DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, ostringstre
}
append(result, buffer, nBytes, SHIFT_JIS);
delete[] buffer;
}
void DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits, ostringstream &result, int count) {
int nBytes = count;
unsigned char readBytes[nBytes];
unsigned char* readBytes = new unsigned char[nBytes];
if (count << 3 > bits->available()) {
ostringstream s;
s << "Count too large: " << count;
delete[] readBytes;
throw ReaderException(s.str().c_str());
}
for (int i = 0; i < count; i++) {
@ -119,11 +128,12 @@ void DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits, ostringstrea
// give a hint.
const char *encoding = guessEncoding(readBytes, nBytes);
append(result, readBytes, nBytes, encoding);
delete[] readBytes;
}
void DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> bits, ostringstream &result, int count) {
int nBytes = count;
unsigned char bytes[nBytes];
unsigned char* bytes = new unsigned char[nBytes];
int i = 0;
// Read three digits at a time
while (count >= 3) {
@ -132,6 +142,7 @@ void DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> bits, ostringst
if (threeDigitsBits >= 1000) {
ostringstream s;
s << "Illegal value for 3-digit unit: " << threeDigitsBits;
delete[] bytes;
throw ReaderException(s.str().c_str());
}
bytes[i++] = ALPHANUMERIC_CHARS[threeDigitsBits / 100];
@ -145,6 +156,7 @@ void DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> bits, ostringst
if (twoDigitsBits >= 100) {
ostringstream s;
s << "Illegal value for 2-digit unit: " << twoDigitsBits;
delete[] bytes;
throw ReaderException(s.str().c_str());
}
bytes[i++] = ALPHANUMERIC_CHARS[twoDigitsBits / 10];
@ -155,16 +167,18 @@ void DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> bits, ostringst
if (digitBits >= 10) {
ostringstream s;
s << "Illegal value for digit unit: " << digitBits;
delete[] bytes;
throw ReaderException(s.str().c_str());
}
bytes[i++] = ALPHANUMERIC_CHARS[digitBits];
}
append(result, bytes, nBytes, ASCII);
delete[] bytes;
}
void DecodedBitStreamParser::decodeAlphanumericSegment(Ref<BitSource> bits, ostringstream &result, int count) {
int nBytes = count;
unsigned char bytes[nBytes];
unsigned char* bytes = new unsigned char[nBytes];
int i = 0;
// Read two characters at a time
while (count > 1) {
@ -177,6 +191,7 @@ void DecodedBitStreamParser::decodeAlphanumericSegment(Ref<BitSource> bits, ostr
bytes[i++] = ALPHANUMERIC_CHARS[bits->readBits(6)];
}
append(result, bytes, nBytes, ASCII);
delete[] bytes;
}
const char *

View file

@ -46,7 +46,7 @@ bool AlignmentPatternFinder::foundPatternCross(valarray<int> &stateCount) {
float AlignmentPatternFinder::crossCheckVertical(size_t startI, size_t centerJ, int maxCount,
int originalStateCountTotal) {
int maxI = image_->getHeight();
valarray<int> stateCount(3);
valarray<int> stateCount(0, 3);
// Start counting up from center
@ -136,7 +136,7 @@ Ref<AlignmentPattern> AlignmentPatternFinder::find() {
// Ref<BitArray> luminanceRow(new BitArray(width_));
// We are looking for black/white/black modules in 1:1:1 ratio;
// this tracks the number of black/white/black modules seen so far
valarray<int> stateCount(3);
valarray<int> stateCount(0, 3);
for (size_t iGen = 0; iGen < height_; iGen++) {
// Search from middle outwards
size_t i = middleI + ((iGen & 0x01) == 0 ? ((iGen + 1) >> 1) : -((iGen + 1) >> 1));