public void Pattern_01() { const int WIDTH = 21, HEIGHT = 21; QRMatrix matrix = new QRMatrix(WIDTH, HEIGHT); matrix.Fill(2); matrix.AddBasicPatterns(QRVersion.GetVersionByNumber(1)); string expected = "1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1\r\n" + "1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1\r\n" + "1 0 1 1 1 0 1 0 0 1 0 1 1 1 0 1\r\n" + "1 0 1 1 1 0 1 0 0 1 0 1 1 1 0 1\r\n" + "1 0 1 1 1 0 1 0 0 1 0 1 1 1 0 1\r\n" + "1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1\r\n" + "1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\r\n" + "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n" + " 1 \r\n" + " 0 \r\n" + " 1 \r\n" + " 0 \r\n" + " 1 \r\n" + "0 0 0 0 0 0 0 0 1 \r\n" + "1 1 1 1 1 1 1 0 \r\n" + "1 0 0 0 0 0 1 0 \r\n" + "1 0 1 1 1 0 1 0 \r\n" + "1 0 1 1 1 0 1 0 \r\n" + "1 0 1 1 1 0 1 0 \r\n" + "1 0 0 0 0 0 1 0 \r\n" + "1 1 1 1 1 1 1 0 "; Assert.AreEqual(expected, matrix.ToString()); }
public void VersionInfo() { const int WIDTH = 21, HEIGHT = 21; // Version info bits = 000111 110010 010100 // Actually, version 7 QR Code has 45x45 matrix but we use 21x21 here // since 45x45 matrix is too big to depict. QRMatrix matrix = new QRMatrix(WIDTH, HEIGHT); matrix.AddVersionInfoIfRequired(QRVersion.GetVersionByNumber(7)); string expected = " 0 0 1 \r\n" + " 0 1 0 \r\n" + " 0 1 0 \r\n" + " 0 1 1 \r\n" + " 1 1 1 \r\n" + " 0 0 0 \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + "0 0 0 0 1 0 \r\n" + "0 1 1 1 1 0 \r\n" + "1 0 0 1 1 0 \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " "; Assert.AreEqual(expected, matrix.ToString()); }
public void MakeVersionInfoBits() { // From Appendix D in JISX0510:2004 (p 68) BitList bits = new BitList(); QRMatrix.GenerateVersionInfoBits(bits, QRVersion.GetVersionByNumber(7)); Assert.AreEqual("00011111 00100101 00", bits.ToString()); }
public void BuildMatrix() { const int WIDTH = 21, HEIGHT = 21; // From http://www.swetake.com/qr/qr7.html int[] ints = { 32, 65, 205, 69, 41, 220, 46, 128, 236, 42, 159, 74, 221, 244, 169, 239, 150, 138, 70, 237, 85, 224, 96, 74, 219, 61 }; BitList bits = new BitList(); foreach (int i in ints) { bits.AppendBits(i, 8); } QRMatrix matrix = new QRMatrix(WIDTH, HEIGHT); matrix.FormMatrix(bits, QRCorrectionLevel.H, QRVersion.GetVersionByNumber(1), 3); string expected = "1 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1\r\n" + "1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1\r\n" + "1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 0 1\r\n" + "1 0 1 1 1 0 1 0 0 1 1 0 0 0 1 0 1 1 1 0 1\r\n" + "1 0 1 1 1 0 1 0 1 1 0 0 1 0 1 0 1 1 1 0 1\r\n" + "1 0 0 0 0 0 1 0 0 0 1 1 1 0 1 0 0 0 0 0 1\r\n" + "1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\r\n" + "0 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0\r\n" + "0 0 1 1 0 0 1 1 1 0 0 1 1 1 1 0 1 0 0 0 0\r\n" + "1 0 1 0 1 0 0 0 0 0 1 1 1 0 0 1 0 1 1 1 0\r\n" + "1 1 1 1 0 1 1 0 1 0 1 1 1 0 0 1 1 1 0 1 0\r\n" + "1 0 1 0 1 1 0 1 1 1 0 0 1 1 1 0 0 1 0 1 0\r\n" + "0 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 1 1 1 1\r\n" + "0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 1 1\r\n" + "1 1 1 1 1 1 1 0 1 1 1 1 0 0 0 0 1 0 1 1 0\r\n" + "1 0 0 0 0 0 1 0 0 0 0 1 0 1 1 1 0 0 0 0 0\r\n" + "1 0 1 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1\r\n" + "1 0 1 1 1 0 1 0 1 1 0 1 0 0 0 0 0 1 1 1 0\r\n" + "1 0 1 1 1 0 1 0 1 1 1 1 0 0 0 0 1 1 1 0 0\r\n" + "1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0\r\n" + "1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 0 0 1 0"; Assert.AreEqual(expected, matrix.ToString()); }
public void AppendLengthInfo() { BitList bits = new BitList(); QREncoderMatrix.AppendLengthInfo(1, /* 1 letter (1/1).*/ QRVersion.GetVersionByNumber(1), QRMode.NUMERIC, bits); Assert.AreEqual("00000000 01", bits.ToString()); // 10 bits. bits = new BitList(); QREncoderMatrix.AppendLengthInfo(2, /* 2 letters (2/1).*/ QRVersion.GetVersionByNumber(10), QRMode.ALPHANUMERIC, bits); Assert.AreEqual("00000000 010", bits.ToString()); // 11 bits. bits = new BitList(); QREncoderMatrix.AppendLengthInfo(255, /* 255 letter (255/1).*/ QRVersion.GetVersionByNumber(27), QRMode.BYTE, bits); Assert.AreEqual("00000000 11111111", bits.ToString()); // 16 bits. bits = new BitList(); QREncoderMatrix.AppendLengthInfo(512, /* 512 letters (1024/2).*/ QRVersion.GetVersionByNumber(40), QRMode.KANJI, bits); Assert.AreEqual("00100000 0000", bits.ToString()); // 12 bits. }
public int GetVersionCharacterCount(QRVersion version) { if (VersionCharacterCount == null) throw new NFXException(StringConsts.ARGUMENT_ERROR + GetType().Name + ".appendBytes(version=>VersionCharacterCount!=null)"); int number = version.Number; int offset; if (number <= 9) { offset = 0; } else if (number <= 26) { offset = 1; } else { offset = 2; } return VersionCharacterCount[offset]; }
public void DataBits() { const int WIDTH = 21, HEIGHT = 21; //System.Diagnostics.Debugger.Launch(); // Cells other than basic patterns should be filled with zero. QRMatrix matrix = new QRMatrix(WIDTH, HEIGHT); matrix.AddBasicPatterns(QRVersion.GetVersionByNumber(1)); BitList bits = new BitList(); matrix.InsertDataBits(bits, -1); string expected = "1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1\r\n" + "1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1\r\n" + "1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1\r\n" + "1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1\r\n" + "1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1\r\n" + "1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1\r\n" + "1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\r\n" + "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n" + "0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n" + "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n" + "0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n" + "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n" + "0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n" + "0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0\r\n" + "1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n" + "1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n" + "1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n" + "1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n" + "1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n" + "1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\r\n" + "1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0"; Assert.AreEqual(expected, matrix.ToString()); }
public int GetVersionCharacterCount(QRVersion version) { if (VersionCharacterCount == null) { throw new NFXException(StringConsts.ARGUMENT_ERROR + GetType().Name + ".appendBytes(version=>VersionCharacterCount!=null)"); } int number = version.Number; int offset; if (number <= 9) { offset = 0; } else if (number <= 26) { offset = 1; } else { offset = 2; } return(VersionCharacterCount[offset]); }