+++ /dev/null
-/*\r
-* Copyright 2007 ZXing authors\r
-*\r
-* Licensed under the Apache License, Version 2.0 (the "License");\r
-* you may not use this file except in compliance with the License.\r
-* You may obtain a copy of the License at\r
-*\r
-* http://www.apache.org/licenses/LICENSE-2.0\r
-*\r
-* Unless required by applicable law or agreed to in writing, software\r
-* distributed under the License is distributed on an "AS IS" BASIS,\r
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-* See the License for the specific language governing permissions and\r
-* limitations under the License.\r
-*/\r
-using System;\r
-using System.Text;\r
-using com.google.zxing;\r
-using com.google.zxing.common;\r
-using com.google.zxing.qrcode.decoder;\r
-using com.google.zxing.qrcode;\r
-\r
-namespace com.google.zxing.qrcode.encoder\r
-{\r
-\r
- public sealed class QRCode \r
- { \r
- \r
- public static int NUM_MASK_PATTERNS = 8;\r
-\r
- private Mode mode;\r
- private ErrorCorrectionLevel ecLevel;\r
- private int version;\r
- private int matrixWidth;\r
- private int maskPattern;\r
- private int numTotalBytes;\r
- private int numDataBytes;\r
- private int numECBytes;\r
- private int numRSBlocks;\r
- private ByteMatrix matrix;\r
-\r
- public QRCode() {\r
- mode = null;\r
- ecLevel = null;\r
- version = -1;\r
- matrixWidth = -1;\r
- maskPattern = -1;\r
- numTotalBytes = -1;\r
- numDataBytes = -1;\r
- numECBytes = -1;\r
- numRSBlocks = -1;\r
- matrix = null;\r
- }\r
-\r
- // Mode of the QR Code.\r
- public Mode getMode() {\r
- return mode;\r
- }\r
-\r
- // Error correction level of the QR Code.\r
- public ErrorCorrectionLevel getECLevel() {\r
- return ecLevel;\r
- }\r
-\r
- // Version of the QR Code. The bigger size, the bigger version.\r
- public int getVersion() {\r
- return version;\r
- }\r
-\r
- // ByteMatrix width of the QR Code.\r
- public int getMatrixWidth() {\r
- return matrixWidth;\r
- }\r
-\r
- // Mask pattern of the QR Code.\r
- public int getMaskPattern() {\r
- return maskPattern;\r
- }\r
-\r
- // Number of total bytes in the QR Code.\r
- public int getNumTotalBytes() {\r
- return numTotalBytes;\r
- }\r
-\r
- // Number of data bytes in the QR Code.\r
- public int getNumDataBytes() {\r
- return numDataBytes;\r
- }\r
-\r
- // Number of error correction bytes in the QR Code.\r
- public int getNumECBytes() {\r
- return numECBytes;\r
- }\r
-\r
- // Number of Reedsolomon blocks in the QR Code.\r
- public int getNumRSBlocks() {\r
- return numRSBlocks;\r
- }\r
-\r
- // ByteMatrix data of the QR Code.\r
- public ByteMatrix getMatrix() {\r
- return matrix;\r
- }\r
- \r
-\r
- // Return the value of the module (cell) pointed by "x" and "y" in the matrix of the QR Code. They\r
- // call cells in the matrix "modules". 1 represents a black cell, and 0 represents a white cell.\r
- public int at(int x, int y) {\r
- // The value must be zero or one.\r
- int value = matrix.get(y, x);\r
- if (!(value == 0 || value == 1)) {\r
- // this is really like an assert... not sure what better exception to use?\r
- throw new Exception("Bad value");\r
- }\r
- return value;\r
- }\r
-\r
- // Checks all the member variables are set properly. Returns true on success. Otherwise, returns\r
- // false.\r
- public bool isValid() {\r
- return\r
- // First check if all version are not uninitialized.\r
- mode != null &&\r
- ecLevel != null &&\r
- version != -1 &&\r
- matrixWidth != -1 &&\r
- maskPattern != -1 &&\r
- numTotalBytes != -1 &&\r
- numDataBytes != -1 &&\r
- numECBytes != -1 &&\r
- numRSBlocks != -1 &&\r
- // Then check them in other ways..\r
- isValidMaskPattern(maskPattern) &&\r
- numTotalBytes == numDataBytes + numECBytes &&\r
- // ByteMatrix stuff.\r
- matrix != null &&\r
- matrixWidth == matrix.width() &&\r
- // See 7.3.1 of JISX0510:2004 (p.5).\r
- matrix.width() == matrix.height(); // Must be square.\r
- }\r
-\r
- // Return debug String.\r
- public String toString() {\r
- StringBuilder result = new StringBuilder(200);\r
- result.Append("<<\n");\r
- result.Append(" mode: ");\r
- result.Append(mode);\r
- result.Append("\n ecLevel: ");\r
- result.Append(ecLevel);\r
- result.Append("\n version: ");\r
- result.Append(version);\r
- result.Append("\n matrixWidth: ");\r
- result.Append(matrixWidth);\r
- result.Append("\n maskPattern: ");\r
- result.Append(maskPattern);\r
- result.Append("\n numTotalBytes: ");\r
- result.Append(numTotalBytes);\r
- result.Append("\n numDataBytes: ");\r
- result.Append(numDataBytes);\r
- result.Append("\n numECBytes: ");\r
- result.Append(numECBytes);\r
- result.Append("\n numRSBlocks: ");\r
- result.Append(numRSBlocks);\r
- if (matrix == null) {\r
- result.Append("\n matrix: null\n");\r
- } else {\r
- result.Append("\n matrix:\n");\r
- result.Append(matrix.toString());\r
- }\r
- result.Append(">>\n");\r
- return result.ToString();\r
- }\r
-\r
- public void setMode(Mode value) {\r
- mode = value;\r
- }\r
-\r
- public void setECLevel(ErrorCorrectionLevel value) {\r
- ecLevel = value;\r
- }\r
-\r
- public void setVersion(int value) {\r
- version = value;\r
- }\r
-\r
- public void setMatrixWidth(int value) {\r
- matrixWidth = value;\r
- }\r
-\r
- public void setMaskPattern(int value) {\r
- maskPattern = value;\r
- }\r
-\r
- public void setNumTotalBytes(int value) {\r
- numTotalBytes = value;\r
- }\r
-\r
- public void setNumDataBytes(int value) {\r
- numDataBytes = value;\r
- }\r
-\r
- public void setNumECBytes(int value) {\r
- numECBytes = value;\r
- }\r
-\r
- public void setNumRSBlocks(int value) {\r
- numRSBlocks = value;\r
- }\r
-\r
- // This takes ownership of the 2D array.\r
- public void setMatrix(ByteMatrix value) {\r
- matrix = value;\r
- }\r
-\r
- // Check if "mask_pattern" is valid.\r
- public static bool isValidMaskPattern(int maskPattern) {\r
- return maskPattern >= 0 && maskPattern < NUM_MASK_PATTERNS;\r
- }\r
-\r
- // Return true if the all values in the matrix are binary numbers.\r
- //\r
- // JAVAPORT: This is going to be super expensive and unnecessary, we should not call this in\r
- // production. I'm leaving it because it may be useful for testing. It should be removed entirely\r
- // if ByteMatrix is changed never to contain a -1.\r
- /*\r
- private static boolean EverythingIsBinary(final ByteMatrix matrix) {\r
- for (int y = 0; y < matrix.height(); ++y) {\r
- for (int x = 0; x < matrix.width(); ++x) {\r
- int value = matrix.get(y, x);\r
- if (!(value == 0 || value == 1)) {\r
- // Found non zero/one value.\r
- return false;\r
- }\r
- }\r
- }\r
- return true;\r
- }\r
- */\r
- \r
- }\r
-\r
-}
\ No newline at end of file