Issue 1142 fix binary shift in Aztec decoding

git-svn-id: https://zxing.googlecode.com/svn/trunk@2159 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2012-02-04 14:58:09 +00:00
parent 2c84200f64
commit faf139e2e8
6 changed files with 91 additions and 63 deletions

View file

@ -106,9 +106,7 @@ public final class Decoder {
return new DecoderResult(null, result, null, null); return new DecoderResult(null, result, null, null);
} }
/** /**
*
* Gets the string encoded in the aztec code bits * Gets the string encoded in the aztec code bits
* *
* @return the decoded string * @return the decoded string
@ -128,6 +126,7 @@ public final class Decoder {
boolean end = false; boolean end = false;
boolean shift = false; boolean shift = false;
boolean switchShift = false; boolean switchShift = false;
boolean binaryShift = false;
while (!end) { while (!end) {
@ -140,8 +139,34 @@ public final class Decoder {
} }
int code; int code;
switch (table) { if (binaryShift) {
case BINARY: if (endIndex - startIndex < 5) {
break;
}
int length = readCode(correctedBits, startIndex, 5);
startIndex += 5;
if (length == 0) {
if (endIndex - startIndex < 11) {
break;
}
length = readCode(correctedBits, startIndex, 11) + 31;
startIndex += 11;
}
for (int charCount = 0; charCount < length; charCount++) {
if (endIndex - startIndex < 8) {
end = true;
break;
}
code = readCode(correctedBits, startIndex, 8);
result.append((char) code);
startIndex += 8;
}
binaryShift = false;
} else {
if (table == Table.BINARY) {
if (endIndex - startIndex < 8) { if (endIndex - startIndex < 8) {
end = true; end = true;
break; break;
@ -150,9 +175,8 @@ public final class Decoder {
startIndex += 8; startIndex += 8;
result.append((char) code); result.append((char) code);
break;
default: } else {
int size = 5; int size = 5;
if (table == Table.DIGIT) { if (table == Table.DIGIT) {
@ -174,12 +198,16 @@ public final class Decoder {
if (str.charAt(6) == 'S') { if (str.charAt(6) == 'S') {
shift = true; shift = true;
if (str.charAt(5) == 'B') {
binaryShift = true;
}
} }
} else { } else {
result.append(str); result.append(str);
} }
break;
}
} }
if (switchShift) { if (switchShift) {
@ -215,7 +243,6 @@ public final class Decoder {
} }
/** /**
*
* Gets the character (or string) corresponding to the passed code in the given table * Gets the character (or string) corresponding to the passed code in the given table
* *
* @param table the table used * @param table the table used
@ -239,8 +266,7 @@ public final class Decoder {
} }
/** /**
* * <p>Performs RS error correction on an array of bits.</p>
* <p> performs RS error correction on an array of bits </p>
* *
* @return the corrected array * @return the corrected array
* @throws FormatException if the input contains too many errors * @throws FormatException if the input contains too many errors
@ -342,7 +368,6 @@ public final class Decoder {
} }
/** /**
*
* Gets the array of bits from an Aztec Code matrix * Gets the array of bits from an Aztec Code matrix
* *
* @return the array of bits * @return the array of bits
@ -381,8 +406,10 @@ public final class Decoder {
flip = 0; flip = 0;
for (int i = 2 * size + 1; i > 5; i--) { for (int i = 2 * size + 1; i > 5; i--) {
rawbits[rawbitsOffset+4*size - 8 + (2*size-i) + 1] = matrix.get(matrixOffset + size-1-flip, matrixOffset + i/2 - 1); rawbits[rawbitsOffset + 4 * size - 8 + (2 * size - i) + 1] =
rawbits[rawbitsOffset+6*size - 12 + (2*size-i) + 1] = matrix.get(matrixOffset + i/2 - 1, matrixOffset + flip); matrix.get(matrixOffset + size - 1 - flip, matrixOffset + i / 2 - 1);
rawbits[rawbitsOffset + 6 * size - 12 + (2 * size - i) + 1] =
matrix.get(matrixOffset + i / 2 - 1, matrixOffset + flip);
flip = (flip + 1) % 2; flip = (flip + 1) % 2;
} }
@ -395,7 +422,6 @@ public final class Decoder {
return rawbits; return rawbits;
} }
/** /**
* Transforms an Aztec code matrix by removing the control dashed lines * Transforms an Aztec code matrix by removing the control dashed lines
*/ */

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -0,0 +1 @@
Histórico

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View file

@ -0,0 +1 @@
Históóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóóórico

View file

@ -26,10 +26,10 @@ public final class AztecBlackBox1TestCase extends AbstractBlackBoxTestCase {
public AztecBlackBox1TestCase() { public AztecBlackBox1TestCase() {
super("test/data/blackbox/aztec-1", new AztecReader(), BarcodeFormat.AZTEC); super("test/data/blackbox/aztec-1", new AztecReader(), BarcodeFormat.AZTEC);
addTest(7, 7, 0.0f); addTest(9, 9, 0.0f);
addTest(7, 7, 90.0f); addTest(9, 9, 90.0f);
addTest(7, 7, 180.0f); addTest(9, 9, 180.0f);
addTest(7, 7, 270.0f); addTest(9, 9, 270.0f);
} }
} }