\r
package com.google.zxing.qrcode.decoder;\r
\r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.FormatException;\r
import com.google.zxing.common.BitMatrix;\r
\r
/**\r
\r
/**\r
* @param bitMatrix {@link BitMatrix} to parse\r
- * @throws ReaderException if dimension is not >= 21 and 1 mod 4\r
+ * @throws FormatException if dimension is not >= 21 and 1 mod 4\r
*/\r
- BitMatrixParser(BitMatrix bitMatrix) throws ReaderException {\r
- int dimension = bitMatrix.getDimension();\r
+ BitMatrixParser(BitMatrix bitMatrix) throws FormatException {\r
+ int dimension = bitMatrix.getHeight();\r
if (dimension < 21 || (dimension & 0x03) != 1) {\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
this.bitMatrix = bitMatrix;\r
}\r
* <p>Reads format information from one of its two locations within the QR Code.</p>\r
*\r
* @return {@link FormatInformation} encapsulating the QR Code's format info\r
- * @throws ReaderException if both format information locations cannot be parsed as\r
+ * @throws FormatException if both format information locations cannot be parsed as\r
* the valid encoding of format information\r
*/\r
- FormatInformation readFormatInformation() throws ReaderException {\r
+ FormatInformation readFormatInformation() throws FormatException {\r
\r
if (parsedFormatInfo != null) {\r
return parsedFormatInfo;\r
}\r
\r
// Read top-left format info bits\r
- int formatInfoBits = 0;\r
+ int formatInfoBits1 = 0;\r
for (int i = 0; i < 6; i++) {\r
- formatInfoBits = copyBit(i, 8, formatInfoBits);\r
+ formatInfoBits1 = copyBit(i, 8, formatInfoBits1);\r
}\r
// .. and skip a bit in the timing pattern ...\r
- formatInfoBits = copyBit(7, 8, formatInfoBits);\r
- formatInfoBits = copyBit(8, 8, formatInfoBits);\r
- formatInfoBits = copyBit(8, 7, formatInfoBits);\r
+ formatInfoBits1 = copyBit(7, 8, formatInfoBits1);\r
+ formatInfoBits1 = copyBit(8, 8, formatInfoBits1);\r
+ formatInfoBits1 = copyBit(8, 7, formatInfoBits1);\r
// .. and skip a bit in the timing pattern ...\r
for (int j = 5; j >= 0; j--) {\r
- formatInfoBits = copyBit(8, j, formatInfoBits);\r
+ formatInfoBits1 = copyBit(8, j, formatInfoBits1);\r
}\r
\r
- parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits);\r
- if (parsedFormatInfo != null) {\r
- return parsedFormatInfo;\r
- }\r
-\r
- // Hmm, failed. Try the top-right/bottom-left pattern\r
- int dimension = bitMatrix.getDimension();\r
- formatInfoBits = 0;\r
+ // Read the top-right/bottom-left pattern too\r
+ int dimension = bitMatrix.getHeight();\r
+ int formatInfoBits2 = 0;\r
int iMin = dimension - 8;\r
for (int i = dimension - 1; i >= iMin; i--) {\r
- formatInfoBits = copyBit(i, 8, formatInfoBits);\r
+ formatInfoBits2 = copyBit(i, 8, formatInfoBits2);\r
}\r
for (int j = dimension - 7; j < dimension; j++) {\r
- formatInfoBits = copyBit(8, j, formatInfoBits);\r
+ formatInfoBits2 = copyBit(8, j, formatInfoBits2);\r
}\r
\r
- parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits);\r
+ parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits1, formatInfoBits2);\r
if (parsedFormatInfo != null) {\r
return parsedFormatInfo;\r
}\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
\r
/**\r
* <p>Reads version information from one of its two locations within the QR Code.</p>\r
*\r
* @return {@link Version} encapsulating the QR Code's version\r
- * @throws ReaderException if both version information locations cannot be parsed as\r
+ * @throws FormatException if both version information locations cannot be parsed as\r
* the valid encoding of version information\r
*/\r
- Version readVersion() throws ReaderException {\r
+ Version readVersion() throws FormatException {\r
\r
if (parsedVersion != null) {\r
return parsedVersion;\r
}\r
\r
- int dimension = bitMatrix.getDimension();\r
+ int dimension = bitMatrix.getHeight();\r
\r
int provisionalVersion = (dimension - 17) >> 2;\r
if (provisionalVersion <= 6) {\r
if (parsedVersion != null && parsedVersion.getDimensionForVersion() == dimension) {\r
return parsedVersion;\r
}\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
\r
private int copyBit(int i, int j, int versionBits) {\r
* QR Code.</p>\r
*\r
* @return bytes encoded within the QR Code\r
- * @throws ReaderException if the exact number of bytes expected is not read\r
+ * @throws FormatException if the exact number of bytes expected is not read\r
*/\r
- byte[] readCodewords() throws ReaderException {\r
+ byte[] readCodewords() throws FormatException {\r
\r
FormatInformation formatInfo = readFormatInformation();\r
Version version = readVersion();\r
// Get the data mask for the format used in this QR Code. This will exclude\r
// some bits from reading as we wind through the bit matrix.\r
DataMask dataMask = DataMask.forReference((int) formatInfo.getDataMask());\r
- int dimension = bitMatrix.getDimension();\r
+ int dimension = bitMatrix.getHeight();\r
dataMask.unmaskBitMatrix(bitMatrix, dimension);\r
\r
BitMatrix functionPattern = version.buildFunctionPattern();\r
readingUp ^= true; // readingUp = !readingUp; // switch directions\r
}\r
if (resultOffset != version.getTotalCodewords()) {\r
- throw ReaderException.getInstance();\r
+ throw FormatException.getFormatInstance();\r
}\r
return result;\r
}\r