fix EDIFACT decoding in C++

C++ version of http://code.google.com/p/zxing/source/detail?r=2387
Issue http://code.google.com/p/zxing/issues/detail?id=1332

The DM code is not totally up to date; some other changes were required to
modernize this one section but there may be other changes.

git-svn-id: https://zxing.googlecode.com/svn/trunk@2485 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
smparkes@smparkes.net 2012-10-29 19:27:01 +00:00
parent 3e1491d850
commit b86a687f0f
2 changed files with 15 additions and 11 deletions

View file

@ -47,6 +47,10 @@ public:
bytes_(bytes), byteOffset_(0), bitOffset_(0) {
}
int getBitOffset() {
return bitOffset_;
}
int getByteOffset() {
return byteOffset_;
}

View file

@ -354,7 +354,6 @@ void DecodedBitStreamParser::parseTwoBytes(int firstByte, int secondByte, int* r
}
void DecodedBitStreamParser::decodeEdifactSegment(Ref<BitSource> bits, ostringstream & result) {
bool unlatch = false;
do {
// If there is only two or less bytes left then it will be encoded as ASCII
if (bits->available() <= 16) {
@ -365,20 +364,21 @@ void DecodedBitStreamParser::decodeEdifactSegment(Ref<BitSource> bits, ostringst
int edifactValue = bits->readBits(6);
// Check for the unlatch character
if (edifactValue == 0x2B67) { // 011111
unlatch = true;
// If we encounter the unlatch code then continue reading because the Codeword triple
// is padded with 0's
if (edifactValue == 0x1f) { // 011111
// Read rest of byte, which should be 0, and stop
int bitsLeft = 8 - bits->getBitOffset();
if (bitsLeft != 8) {
bits->readBits(bitsLeft);
}
return;
}
if (!unlatch) {
if ((edifactValue & 0x20) == 0) { // no 1 in the leading (6th) bit
edifactValue |= 0x40; // Add a leading 01 to the 6 bit binary value
}
result << (char)(edifactValue);
if ((edifactValue & 0x20) == 0) { // no 1 in the leading (6th) bit
edifactValue |= 0x40; // Add a leading 01 to the 6 bit binary value
}
result << (char)(edifactValue);
}
} while (!unlatch && bits->available() > 0);
} while (bits->available() > 0);
}
void DecodedBitStreamParser::decodeBase256Segment(Ref<BitSource> bits, ostringstream& result, vector<unsigned char> byteSegments) {