formatting cleanup before trying to make the last failing C++ qr blackbox test pass

git-svn-id: https://zxing.googlecode.com/svn/trunk@1964 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
smparkes@smparkes.net 2011-10-13 15:20:25 +00:00
parent 9558d83d71
commit beeef242b2
5 changed files with 329 additions and 321 deletions

View file

@ -1,3 +1,4 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
/* /*
* BitMatrix.cpp * BitMatrix.cpp
* zxing * zxing
@ -24,10 +25,16 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
namespace zxing { using std::numeric_limits;
using namespace std; using std::ostream;
using std::ostringstream;
unsigned int logDigits(unsigned digits) { using zxing::BitMatrix;
using zxing::BitArray;
using zxing::Ref;
namespace {
unsigned int logDigits(unsigned digits) {
unsigned log = 0; unsigned log = 0;
unsigned val = 1; unsigned val = 1;
while (val < digits) { while (val < digits) {
@ -35,19 +42,20 @@ unsigned int logDigits(unsigned digits) {
val <<= 1; val <<= 1;
} }
return log; return log;
} }
const unsigned int bitsPerWord = numeric_limits<unsigned int>::digits; const unsigned int bitsPerWord = numeric_limits<unsigned int>::digits;
const unsigned int logBits = logDigits(bitsPerWord); const unsigned int logBits = logDigits(bitsPerWord);
const unsigned int bitsMask = (1 << logBits) - 1; const unsigned int bitsMask = (1 << logBits) - 1;
static size_t wordsForSize(size_t width, size_t height) { size_t wordsForSize(size_t width, size_t height) {
size_t bits = width * height; size_t bits = width * height;
int arraySize = bits >> logBits; int arraySize = bits >> logBits;
if (bits - (arraySize << logBits) != 0) { if (bits - (arraySize << logBits) != 0) {
arraySize++; arraySize++;
} }
return arraySize; return arraySize;
}
} }
BitMatrix::BitMatrix(size_t dimension) : BitMatrix::BitMatrix(size_t dimension) :
@ -160,7 +168,8 @@ unsigned int* BitMatrix::getBits() const {
return bits_; return bits_;
} }
ostream& operator<<(ostream &out, const BitMatrix &bm) { namespace zxing {
ostream& operator<<(ostream &out, const BitMatrix &bm) {
for (size_t y = 0; y < bm.height_; y++) { for (size_t y = 0; y < bm.height_; y++) {
for (size_t x = 0; x < bm.width_; x++) { for (size_t x = 0; x < bm.width_; x++) {
out << (bm.get(x, y) ? "X " : " "); out << (bm.get(x, y) ? "X " : " ");
@ -168,11 +177,11 @@ ostream& operator<<(ostream &out, const BitMatrix &bm) {
out << "\n"; out << "\n";
} }
return out; return out;
}
} }
const char *BitMatrix::description() {
const char* BitMatrix::description() {
ostringstream out; ostringstream out;
out << *this; out << *this;
return out.str().c_str(); return out.str().c_str();
} }
}

View file

@ -1,3 +1,4 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
#ifndef __BIT_MATRIX_H__ #ifndef __BIT_MATRIX_H__
#define __BIT_MATRIX_H__ #define __BIT_MATRIX_H__

View file

@ -1,3 +1,4 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
/* /*
* QRCodeReader.cpp * QRCodeReader.cpp
* zxing * zxing

View file

@ -1,3 +1,4 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
#ifndef __QR_CODE_READER_H__ #ifndef __QR_CODE_READER_H__
#define __QR_CODE_READER_H__ #define __QR_CODE_READER_H__

View file

@ -1,5 +1,5 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
* /*
* DecodedBitStreamParser.cpp * DecodedBitStreamParser.cpp
* zxing * zxing
* *
@ -35,25 +35,24 @@
#define ICONV_CONST /**/ #define ICONV_CONST /**/
#endif #endif
using namespace std;
using namespace zxing; using namespace zxing;
using namespace zxing::qrcode;
namespace zxing { const char DecodedBitStreamParser::ALPHANUMERIC_CHARS[] =
namespace qrcode { { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
using namespace std; 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
const char DecodedBitStreamParser::ALPHANUMERIC_CHARS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', ' ', '$', '%', '*', '+', '-', '.', '/', ':' 'Y', 'Z', ' ', '$', '%', '*', '+', '-', '.', '/', ':'
}; };
const char *DecodedBitStreamParser::ASCII = "ASCII"; const char *DecodedBitStreamParser::ASCII = "ASCII";
const char *DecodedBitStreamParser::ISO88591 = "ISO-8859-1"; const char *DecodedBitStreamParser::ISO88591 = "ISO-8859-1";
const char *DecodedBitStreamParser::UTF8 = "UTF-8"; const char *DecodedBitStreamParser::UTF8 = "UTF-8";
const char *DecodedBitStreamParser::SHIFT_JIS = "SHIFT_JIS"; const char *DecodedBitStreamParser::SHIFT_JIS = "SHIFT_JIS";
const char *DecodedBitStreamParser::EUC_JP = "EUC-JP"; const char *DecodedBitStreamParser::EUC_JP = "EUC-JP";
void DecodedBitStreamParser::append(std::string &result, const unsigned char *bufIn, size_t nIn, const char *src) { void DecodedBitStreamParser::append(std::string &result, const unsigned char *bufIn, size_t nIn, const char *src) {
#ifndef NO_ICONV #ifndef NO_ICONV
if (nIn == 0) { if (nIn == 0) {
return; return;
@ -85,9 +84,9 @@ namespace zxing {
#else #else
result.append((const char *)bufIn, nIn); result.append((const char *)bufIn, nIn);
#endif #endif
} }
void DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, std::string &result, int count) { void DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, std::string &result, int count) {
// Each character will require 2 bytes. Read the characters as 2-byte pairs // Each character will require 2 bytes. Read the characters as 2-byte pairs
// and decode as Shift_JIS afterwards // and decode as Shift_JIS afterwards
size_t nBytes = 2 * count; size_t nBytes = 2 * count;
@ -113,9 +112,9 @@ namespace zxing {
append(result, buffer, nBytes, SHIFT_JIS); append(result, buffer, nBytes, SHIFT_JIS);
delete[] buffer; delete[] buffer;
} }
void DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits, std::string &result, int count) { void DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits, std::string &result, int count) {
int nBytes = count; int nBytes = count;
unsigned char* readBytes = new unsigned char[nBytes]; unsigned char* readBytes = new unsigned char[nBytes];
if (count << 3 > bits->available()) { if (count << 3 > bits->available()) {
@ -135,9 +134,9 @@ namespace zxing {
const char *encoding = guessEncoding(readBytes, nBytes); const char *encoding = guessEncoding(readBytes, nBytes);
append(result, readBytes, nBytes, encoding); append(result, readBytes, nBytes, encoding);
delete[] readBytes; delete[] readBytes;
} }
void DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> bits, std::string &result, int count) { void DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> bits, std::string &result, int count) {
int nBytes = count; int nBytes = count;
unsigned char* bytes = new unsigned char[nBytes]; unsigned char* bytes = new unsigned char[nBytes];
int i = 0; int i = 0;
@ -189,9 +188,9 @@ namespace zxing {
} }
append(result, bytes, nBytes, ASCII); append(result, bytes, nBytes, ASCII);
delete[] bytes; delete[] bytes;
} }
void DecodedBitStreamParser::decodeAlphanumericSegment(Ref<BitSource> bits, std::string &result, int count) { void DecodedBitStreamParser::decodeAlphanumericSegment(Ref<BitSource> bits, std::string &result, int count) {
int nBytes = count; int nBytes = count;
unsigned char* bytes = new unsigned char[nBytes]; unsigned char* bytes = new unsigned char[nBytes];
int i = 0; int i = 0;
@ -207,10 +206,10 @@ namespace zxing {
} }
append(result, bytes, nBytes, ASCII); append(result, bytes, nBytes, ASCII);
delete[] bytes; delete[] bytes;
} }
const char * const char *
DecodedBitStreamParser::guessEncoding(unsigned char *bytes, int length) { DecodedBitStreamParser::guessEncoding(unsigned char *bytes, int length) {
const bool ASSUME_SHIFT_JIS = false; const bool ASSUME_SHIFT_JIS = false;
char const* const PLATFORM_DEFAULT_ENCODING="UTF-8"; char const* const PLATFORM_DEFAULT_ENCODING="UTF-8";
@ -326,9 +325,9 @@ namespace zxing {
} }
// Otherwise, we take a wild guess with platform encoding // Otherwise, we take a wild guess with platform encoding
return PLATFORM_DEFAULT_ENCODING; return PLATFORM_DEFAULT_ENCODING;
} }
string DecodedBitStreamParser::decode(ArrayRef<unsigned char> bytes, Version *version) { string DecodedBitStreamParser::decode(ArrayRef<unsigned char> bytes, Version *version) {
string result; string result;
Ref<BitSource> bits(new BitSource(bytes)); Ref<BitSource> bits(new BitSource(bytes));
Mode *mode = &Mode::TERMINATOR; Mode *mode = &Mode::TERMINATOR;
@ -357,7 +356,4 @@ namespace zxing {
} }
} while (mode != &Mode::TERMINATOR); } while (mode != &Mode::TERMINATOR);
return result; return result;
}
}
} }