Issue 357
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Mon, 19 Apr 2010 20:49:54 +0000 (20:49 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Mon, 19 Apr 2010 20:49:54 +0000 (20:49 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1313 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/pdf417/decoder/DecodedBitStreamParser.java

index 0638843..8b801f3 100644 (file)
@@ -347,19 +347,18 @@ final class DecodedBitStreamParser {
           byteCompactedCodewords[count] = code;\r
           count++;\r
           // Base 900\r
-          value *= 900;\r
-          value += code;\r
+          value = 900 * value + code;\r
         } else {\r
-          if ((code == TEXT_COMPACTION_MODE_LATCH) ||\r
-              (code == BYTE_COMPACTION_MODE_LATCH) ||\r
-              (code == NUMERIC_COMPACTION_MODE_LATCH) ||\r
-              (code == BYTE_COMPACTION_MODE_LATCH_6) ||\r
-              (code == BEGIN_MACRO_PDF417_CONTROL_BLOCK) ||\r
-              (code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) ||\r
-              (code == MACRO_PDF417_TERMINATOR)) {\r
+          if (code == TEXT_COMPACTION_MODE_LATCH ||\r
+              code == BYTE_COMPACTION_MODE_LATCH ||\r
+              code == NUMERIC_COMPACTION_MODE_LATCH ||\r
+              code == BYTE_COMPACTION_MODE_LATCH_6 ||\r
+              code == BEGIN_MACRO_PDF417_CONTROL_BLOCK ||\r
+              code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD ||\r
+              code == MACRO_PDF417_TERMINATOR) {\r
+            codeIndex--;\r
+            end = true;\r
           }\r
-          codeIndex--;\r
-          end = true;\r
         }\r
         if ((count % 5 == 0) && (count > 0)) {\r
           // Decode every 5 codewords\r
@@ -385,31 +384,30 @@ final class DecodedBitStreamParser {
       int count = 0;\r
       long value = 0;\r
       boolean end = false;\r
-      while ((codeIndex < codewords[0]) && !end) {\r
+      while (codeIndex < codewords[0] && !end) {\r
         int code = codewords[codeIndex++];\r
         if (code < TEXT_COMPACTION_MODE_LATCH) {\r
-          count += 1;\r
+          count++;\r
           // Base 900\r
-          value *= 900;\r
-          value += code;\r
+          value = 900 * value + code;\r
         } else {\r
-          if ((code == TEXT_COMPACTION_MODE_LATCH) ||\r
-              (code == BYTE_COMPACTION_MODE_LATCH) ||\r
-              (code == NUMERIC_COMPACTION_MODE_LATCH) ||\r
-              (code == BYTE_COMPACTION_MODE_LATCH_6) ||\r
-              (code == BEGIN_MACRO_PDF417_CONTROL_BLOCK) ||\r
-              (code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) ||\r
-              (code == MACRO_PDF417_TERMINATOR)) {\r
+          if (code == TEXT_COMPACTION_MODE_LATCH ||\r
+              code == BYTE_COMPACTION_MODE_LATCH ||\r
+              code == NUMERIC_COMPACTION_MODE_LATCH ||\r
+              code == BYTE_COMPACTION_MODE_LATCH_6 ||\r
+              code == BEGIN_MACRO_PDF417_CONTROL_BLOCK ||\r
+              code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD ||\r
+              code == MACRO_PDF417_TERMINATOR) {\r
+            codeIndex--;\r
+            end = true;\r
           }\r
-          codeIndex--;\r
-          end = true;\r
         }\r
         if ((count % 5 == 0) && (count > 0)) {\r
           // Decode every 5 codewords\r
           // Convert to Base 256\r
           char[] decodedData = new char[6];\r
           for (int j = 0; j < 6; ++j) {\r
-            decodedData[5 - j] = (char) (value % 256);\r
+            decodedData[5 - j] = (char) (value & 0xFF);\r
             value >>= 8;\r
           }\r
           result.append(decodedData);\r
@@ -433,24 +431,28 @@ final class DecodedBitStreamParser {
 \r
     int[] numericCodewords = new int[MAX_NUMERIC_CODEWORDS];\r
 \r
-    while ((codeIndex < codewords.length) && !end) {\r
+    while (codeIndex < codewords[0] && !end) {\r
       int code = codewords[codeIndex++];\r
+      if (codeIndex == codewords[0]) {\r
+        end = true;\r
+      }\r
       if (code < TEXT_COMPACTION_MODE_LATCH) {\r
         numericCodewords[count] = code;\r
         count++;\r
       } else {\r
-        if ((code == TEXT_COMPACTION_MODE_LATCH) ||\r
-            (code == BYTE_COMPACTION_MODE_LATCH) ||\r
-            (code == BYTE_COMPACTION_MODE_LATCH_6) ||\r
-            (code == BEGIN_MACRO_PDF417_CONTROL_BLOCK) ||\r
-            (code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) ||\r
-            (code == MACRO_PDF417_TERMINATOR)) {\r
+        if (code == TEXT_COMPACTION_MODE_LATCH ||\r
+            code == BYTE_COMPACTION_MODE_LATCH ||\r
+            code == BYTE_COMPACTION_MODE_LATCH_6 ||\r
+            code == BEGIN_MACRO_PDF417_CONTROL_BLOCK ||\r
+            code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD ||\r
+            code == MACRO_PDF417_TERMINATOR) {\r
+               codeIndex--;\r
+          end = true;          \r
         }\r
-        codeIndex--;\r
-        end = true;\r
       }\r
-      if ((count % MAX_NUMERIC_CODEWORDS) == 0 ||\r
-          code == NUMERIC_COMPACTION_MODE_LATCH) {\r
+      if (count % MAX_NUMERIC_CODEWORDS == 0 ||\r
+          code == NUMERIC_COMPACTION_MODE_LATCH ||\r
+          end) {\r
         // Re-invoking Numeric Compaction mode (by using codeword 902\r
         // while in Numeric Compaction mode) serves  to terminate the\r
         // current Numeric Compaction mode grouping as described in 5.4.4.2,\r