/// <summary> /// /// </summary> /// <param name="xStart"></param> /// <param name="yStart"></param> /// <param name="matrix"></param> private static void embedPositionDetectionPattern(int xStart, int yStart, ByteMatrix matrix) { // We know the width and height. if (POSITION_DETECTION_PATTERN[0].Length != 7 || POSITION_DETECTION_PATTERN.Length != 7) { throw new WriterException("Bad position detection pattern"); } for (int y = 0; y < 7; ++y) { for (int x = 0; x < 7; ++x) { if (!isEmpty(matrix.get_Renamed(xStart + x, yStart + y))) { throw new WriterException(); } matrix.set_Renamed(xStart + x, yStart + y, POSITION_DETECTION_PATTERN[y][x]); } } }
// Embed position detection patterns and surrounding vertical/horizontal separators. private static void embedPositionDetectionPatternsAndSeparators(ByteMatrix matrix) { // Embed three big squares at corners. int pdpWidth = POSITION_DETECTION_PATTERN[0].Length; // Left top corner. embedPositionDetectionPattern(0, 0, matrix); // Embed horizontal separation patterns around the squares. int hspWidth = HORIZONTAL_SEPARATION_PATTERN[0].Length; // Left top corner. embedHorizontalSeparationPattern(0, hspWidth - 1, matrix); // Embed vertical separation patterns around the squares. int vspSize = VERTICAL_SEPARATION_PATTERN.Length; // Left top corner. embedVerticalSeparationPattern(vspSize, 0, matrix); }
// Build 2D matrix of QR Code from "dataBits" with "ecLevel", "version" and "getMaskPattern". On // success, store the result in "matrix" and return true. public static void buildMatrix(BitVector dataBits, ErrorCorrectionLevel ecLevel, int version, int maskPattern, ByteMatrix matrix) { clearMatrix(matrix); embedBasicPatterns(version, matrix); // Type information appear with any version. embedTypeInfo(ecLevel, version, maskPattern, matrix); // Data should be embedded at end. embedDataBits(dataBits, maskPattern, matrix); }
private const int TYPE_INFO_MASK_PATTERN = 0x4445; //100010001000101 // Set all cells to -1. -1 means that the cell is empty (not set yet). // // JAVAPORT: We shouldn't need to do this at all. The code should be rewritten to begin encoding // with the ByteMatrix initialized all to zero. public static void clearMatrix(ByteMatrix matrix) { matrix.clear((sbyte)(-1)); }
// Embed type information. On success, modify the matrix. public static void embedTypeInfo(ErrorCorrectionLevel ecLevel, int version, int maskPattern, ByteMatrix matrix) { BitVector typeInfoBits = new BitVector(); makeTypeInfoBits(ecLevel, version, maskPattern, typeInfoBits); for (int i = 0; i < typeInfoBits.size(); ++i) { // Place bits in LSB to MSB order. LSB (least significant bit) is the last value in // "typeInfoBits". int bit = typeInfoBits.at(typeInfoBits.size() - 1 - i); // Type info bits at the left top corner. See 8.9 of JISX0510:2004 (p.46). int x1 = TYPE_INFO_COORDINATES[i][0]; int y1 = TYPE_INFO_COORDINATES[i][1]; matrix.set_Renamed(x1, y1, bit); } }