X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=core%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fdatamatrix%2Fdecoder%2FBitMatrixParser.java;h=fe4830226fb21900bb9c14fe3c747a38149173cd;hb=a96a22b731c6402277a70ca54ccec32088adbfbb;hp=f54e9c1489c61ff2c7e99fe9285168854b48f725;hpb=93dc44adb7dbf108975ec09d061229b80f8cc834;p=zxing.git diff --git a/core/src/com/google/zxing/datamatrix/decoder/BitMatrixParser.java b/core/src/com/google/zxing/datamatrix/decoder/BitMatrixParser.java index f54e9c14..fe483022 100644 --- a/core/src/com/google/zxing/datamatrix/decoder/BitMatrixParser.java +++ b/core/src/com/google/zxing/datamatrix/decoder/BitMatrixParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2007 Google Inc. + * Copyright 2007 ZXing authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,7 @@ final class BitMatrixParser { private final BitMatrix mappingBitMatrix; private final BitMatrix readMappingMatrix; - private Version version; -// private FormatInformation parsedFormatInfo; + private final Version version; /** * @param bitMatrix {@link BitMatrix} to parse @@ -36,7 +35,7 @@ final class BitMatrixParser { BitMatrixParser(BitMatrix bitMatrix) throws ReaderException { int dimension = bitMatrix.getDimension(); if (dimension < 10 || dimension > 144 || (dimension & 0x01) != 0) { - throw new ReaderException("Invalid dimension (" + dimension + ") Must be 0 mod 2 and >= 10 and <= 144"); + throw ReaderException.getInstance(); } version = readVersion(bitMatrix); @@ -98,19 +97,23 @@ final class BitMatrixParser { // Check the four corner cases if ((row == numRows) && (column == 0) && !corner1Read) { result[resultOffset++] = (byte) readCorner1(numRows, numColumns); - row -= 2; column +=2; + row -= 2; + column +=2; corner1Read = true; } else if ((row == numRows-2) && (column == 0) && ((numColumns & 0x03) != 0) && !corner2Read) { result[resultOffset++] = (byte) readCorner2(numRows, numColumns); - row -= 2; column +=2; + row -= 2; + column +=2; corner2Read = true; } else if ((row == numRows+4) && (column == 2) && ((numColumns & 0x07) == 0) && !corner3Read) { result[resultOffset++] = (byte) readCorner3(numRows, numColumns); - row -= 2; column +=2; + row -= 2; + column +=2; corner3Read = true; } else if ((row == numRows-2) && (column == 0) && ((numColumns & 0x07) == 4) && !corner4Read) { result[resultOffset++] = (byte) readCorner4(numRows, numColumns); - row -= 2; column +=2; + row -= 2; + column +=2; corner4Read = true; } else { // Sweep upward diagonally to the right @@ -118,29 +121,33 @@ final class BitMatrixParser { if ((row < numRows) && (column >= 0) && !readMappingMatrix.get(row, column)) { result[resultOffset++] = (byte) readUtah(row, column, numRows, numColumns); } - row -= 2; column +=2; + row -= 2; + column +=2; } while ((row >= 0) && (column < numColumns)); - row += 1; column +=3; + row += 1; + column +=3; - // Sweep downward giagonally to the left + // Sweep downward diagonally to the left do { if ((row >= 0) && (column < numColumns) && !readMappingMatrix.get(row, column)) { result[resultOffset++] = (byte) readUtah(row, column, numRows, numColumns); } - row += 2; column -=2; + row += 2; + column -=2; } while ((row < numRows) && (column >= 0)); - row += 3; column +=1; + row += 3; + column +=1; } } while ((row < numRows) || (column < numColumns)); if (resultOffset != version.getTotalCodewords()) { - throw new ReaderException("Did not read all codewords"); + throw ReaderException.getInstance(); } return result; } /** - *

Reads a bit of the mapping matrix accounting for boundry wrapping.

+ *

Reads a bit of the mapping matrix accounting for boundary wrapping.

* * @param row Row to read in the mapping matrix * @param column Column to read in the mapping matrix @@ -149,7 +156,7 @@ final class BitMatrixParser { * @return value of the given bit in the mapping matrix */ boolean readModule(int row, int column, int numRows, int numColumns) { - // Adjust the row and column indicies based on boundry wrapping + // Adjust the row and column indices based on boundary wrapping if (row < 0) { row += numRows; column += 4 - ((numRows + 4) & 0x07); @@ -417,22 +424,22 @@ final class BitMatrixParser { // TODO(bbrown): Make this work with rectangular codes BitMatrix bitMatrixWithoutAlignment = new BitMatrix(sizeDataRegionRow); for (int dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow) { + int dataRegionRowOffset = dataRegionRow * dataRegionSizeRows; for (int dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn; ++dataRegionColumn) { + int dataRegionColumnOffset = dataRegionColumn * dataRegionSizeColumns; for (int i = 0; i < dataRegionSizeRows; ++i) { + int readRowOffset = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i; + int writeRowOffset = dataRegionRowOffset + i; for (int j = 0; j < dataRegionSizeColumns; ++j) { - int readRowOffset = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i; int readColumnOffset = dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j; - int writeRowOffset = dataRegionRow * dataRegionSizeRows + i; - int writeColumnOffset = dataRegionColumn * dataRegionSizeColumns + j; - if (bitMatrix.get(readRowOffset, readColumnOffset)) { + int writeColumnOffset = dataRegionColumnOffset + j; bitMatrixWithoutAlignment.set(writeRowOffset, writeColumnOffset); } } } } } - return bitMatrixWithoutAlignment; }