public void Test_against_reference_implementation(int version, TriStateMatrix expected) { TriStateMatrix target = new TriStateMatrix(expected.Width); PositioninngPatternBuilder.EmbedBasicPatterns(version, target); expected.AssertEquals(target); }
internal static void EmbedBasicPatterns(int version, TriStateMatrix matrix) { new PositionDetectionPattern(version).ApplyTo(matrix); new DarkDotAtLeftBottom(version).ApplyTo(matrix); new AlignmentPattern(version).ApplyTo(matrix); new TimingPattern(version).ApplyTo(matrix); }
private static TriStateMatrix XorMatrix(TriStateMatrix first, BitMatrix second) { int width = first.Width; TriStateMatrix maskedMatrix = new TriStateMatrix(width); for (int x = 0; x < width; x++) { for (int y = 0; y < width; y++) { MatrixStatus states = first.MStatus(x, y); switch (states) { case MatrixStatus.NoMask: maskedMatrix[x, y, MatrixStatus.NoMask] = first[x, y]; break; case MatrixStatus.Data: maskedMatrix[x, y, MatrixStatus.Data] = first[x, y] ^ second[x, y]; break; default: throw new ArgumentException("TristateMatrix has None value cell.", "first"); } } } return(maskedMatrix); }
public static void AssertEquals(this TriStateMatrix expected, TriStateMatrix actual) { if (expected == null) throw new ArgumentNullException("expected"); if (actual == null) throw new ArgumentNullException("actual"); if (expected.Width != actual.Width) { Assert.Fail("Mtrix must have same size. Expected {0}, Actual {1}", expected.Width, actual.Width); } for (int i = 0; i < expected.Width; i++) for (int j = 0; j < expected.Width; j++) { if (expected.MStatus(i, j) != MatrixStatus.None && actual.MStatus(i, j) != MatrixStatus.None && expected[i, j] != actual[i, j]) { Assert.Fail("Matrces are different.\nExpected:{0}Actual:{1}.", TriStateMatrixToGraphicExtensions.ToGraphicString(expected), TriStateMatrixToGraphicExtensions.ToGraphicString(actual)); } if (expected.MStatus(i, j) == MatrixStatus.None && actual.MStatus(i, j) != MatrixStatus.None) { Assert.Fail("Matrces are different.\nExpected:{0}Actual:{1}.", TriStateMatrixToGraphicExtensions.ToGraphicString(expected), TriStateMatrixToGraphicExtensions.ToGraphicString(actual)); } if (expected.MStatus(i, j) != MatrixStatus.None && actual.MStatus(i, j) == MatrixStatus.None) { Assert.Fail("Matrces are different.\nExpected:{0}Actual:{1}.", TriStateMatrixToGraphicExtensions.ToGraphicString(expected), TriStateMatrixToGraphicExtensions.ToGraphicString(actual)); } } }
public void Test_against_DataSet(int version, TriStateMatrix expected) { TriStateMatrix target = new TriStateMatrix(expected.Width); PositioninngPatternBuilder.EmbedBasicPatterns(version, target); expected.AssertEquals(target); }
public static TriStateMatrix FromBase64(string base64String) { byte[] bytes = Convert.FromBase64String(base64String); TriStateMatrix matrix = FromBytes(bytes); return(matrix); }
public static TriStateMatrix Xor(this TriStateMatrix first, Pattern second, ErrorCorrectionLevel errorlevel) { TriStateMatrix result = XorMatrix(first, second); result.EmbedFormatInformation(errorlevel, second); return(result); }
public override void ApplyTo(TriStateMatrix matrix) { foreach (MatrixPoint coordinatePair in GetNonColidingCoordinatePairs(matrix)) { this.CopyTo(matrix, coordinatePair, MatrixStatus.NoMask); } }
/// <summary> /// Embed version information to Matrix /// Only for version greater than or equal to 7 /// </summary> /// <param name="tsMatrix">Matrix</param> /// <param name="version">version number</param> internal static void EmbedVersionInformation(this TriStateMatrix tsMatrix, int version) { if (version < 7) { return; } BitList versionInfo = VersionInfoBitList(version); int matrixWidth = tsMatrix.Width; // 1 cell between version info and position stencil int shiftLength = QRCodeConstantVariable.PositionStencilWidth + VIRectangleHeight + 1; // Reverse order input int viIndex = LengthDataBits + LengthECBits - 1; for (int viWidth = 0; viWidth < VIRectangleWidth; viWidth++) { for (int viHeight = 0; viHeight < VIRectangleHeight; viHeight++) { bool bit = versionInfo[viIndex]; viIndex--; // Bottom left tsMatrix[viWidth, (matrixWidth - shiftLength + viHeight), MatrixStatus.NoMask] = bit; // Top right tsMatrix[(matrixWidth - shiftLength + viHeight), viWidth, MatrixStatus.NoMask] = bit; } } }
public override void ApplyTo(TriStateMatrix matrix) { foreach (MatrixPoint coordinatePair in GetNonColidingCoordinatePairs(matrix)) { CopyTo(matrix, coordinatePair, MatrixStatus.NoMask); } }
private static TriStateMatrix FromBytes(byte[] bytes) { int length = BitConverter.ToInt32(bytes, 0); byte[] data = new byte[(bytes.Length - sizeof(int)) * sizeof(byte)]; Array.Copy(bytes, sizeof(int), data, 0, data.Length); int width = (int)Math.Sqrt(length); if (width * width != length) { throw new ArgumentException(string.Format("The header containsinvalid length value. Length must be a square of width.{0}", length), "bytes"); } BitArray bitArray = new BitArray(data); TriStateMatrix matrix = new TriStateMatrix(width); for (int index = 0; index < length; index++) { int i = index % width; int j = index / width; matrix[i, j, MatrixStatus.Data] = bitArray[index]; } return(matrix); }
/// <summary> /// Xors the matrix. /// </summary> /// <param name="first">The first.</param> /// <param name="second">The second.</param> /// <returns></returns> /// <remarks></remarks> private static TriStateMatrix XorMatrix(TriStateMatrix first, BitMatrix second) { int width = first.Width; var maskedMatrix = new TriStateMatrix(width); for (int x = 0; x < width; x++) { for (int y = 0; y < width; y++) { MatrixStatus states = first.MStatus(x, y); switch (states) { case MatrixStatus.NoMask: maskedMatrix[x, y, MatrixStatus.NoMask] = first[x, y]; break; case MatrixStatus.Data: maskedMatrix[x, y, MatrixStatus.Data] = first[x, y] ^ second[x, y]; break; default: throw new ArgumentException("TristateMatrix has None value cell.", "first"); } } } return maskedMatrix; }
internal static TriStateMatrix Embed(this TriStateMatrix matrix, BitMatrix stencil, IEnumerable <MatrixPoint> locations) { foreach (MatrixPoint location in locations) { Embed(matrix, stencil, location); } return(matrix); }
public void Test_against_DataSet(TriStateMatrix input, MaskPatternType patternType, BitMatrix expected) { Pattern pattern = new PatternFactory().CreateByType(patternType); BitMatrix result = input.Apply(pattern, ErrorCorrectionLevel.H); expected.AssertEquals(result); }
private void Test_One_Case(int version, TriStateMatrix expected) { TriStateMatrix target = new TriStateMatrix(expected.Width); PositioninngPatternBuilder.EmbedBasicPatterns(version, target); target.EmbedVersionInformation(version); expected.AssertEquals(target); }
internal static void TryEmbedCodewords(this TriStateMatrix tsMatrix, BitList codewords) { int sWidth = tsMatrix.Width; int codewordsSize = codewords.Count; int bitIndex = 0; int directionUp = -1; int x = sWidth - 1; int y = sWidth - 1; while (x > 0) { //Skip vertical timing pattern if (x == 6) { x -= 1; } while (y >= 0 && y < sWidth) { for (int xOffset = 0; xOffset < 2; xOffset++) { int xPos = x - xOffset; if (tsMatrix.MStatus(xPos, y) != MatrixStatus.None) { continue; } else { bool bit; if (bitIndex < codewordsSize) { bit = codewords[bitIndex]; bitIndex++; } else { bit = false; } tsMatrix[xPos, y, MatrixStatus.Data] = bit; } } y = NextY(y, directionUp); } directionUp = ChangeDirection(directionUp); y = NextY(y, directionUp); x -= 2; } if (bitIndex != codewordsSize) { throw new Exception($"Not all bits from codewords consumed by matrix: {bitIndex} / {codewordsSize}"); } }
private void Test_One_Case(int version, MaskPatternType patternType, TriStateMatrix expected) { TriStateMatrix target = new TriStateMatrix(expected.Width); PositioninngPatternBuilder.EmbedBasicPatterns(version, target); PatternFactory pf = new PatternFactory(); Pattern pt = pf.CreateByType(patternType); target.EmbedFormatInformation(ErrorCorrectionLevel.H, pt); expected.AssertEquals(target); }
private TestCaseData GenerateRandomTestCaseData(int matrixSize, Random randomizer, int pattern) { ByteMatrix matrix; TriStateMatrix input = GetOriginal(matrixSize, randomizer, out matrix); ApplyPattern(matrix, pattern); BitMatrix expected = matrix.ToBitMatrix(); return(new TestCaseData(input, pattern, expected)); }
internal static string ToGraphicString(this TriStateMatrix matrix) { StringBuilder result = new StringBuilder(matrix.Width * matrix.Width + matrix.Width + 5); using (StringWriter writer = new StringWriter(result)) { matrix.ToGraphic(writer); } return(result.ToString()); }
private void Test_One_Case(int version, TriStateMatrix expected, IEnumerable<bool> codewords) { BitList dcList = new BitList(); dcList.Add(codewords); TriStateMatrix target = new TriStateMatrix(expected.Width); PositioninngPatternBuilder.EmbedBasicPatterns(version, target); target.TryEmbedCodewords(dcList); expected.AssertEquals(target); }
internal void CopyTo(TriStateMatrix target, MatrixRectangle sourceArea, MatrixPoint targetPoint, MatrixStatus mstatus) { for (int j = 0; j < sourceArea.Size.Height; j++) { for (int i = 0; i < sourceArea.Size.Width; i++) { bool value = this[sourceArea.Location.X + i, sourceArea.Location.Y + j]; target[targetPoint.X + i, targetPoint.Y + j, mstatus] = value; } } }
private static BitMatrix FromGraphics(string[] lines) { var matrix = new TriStateMatrix(lines.Length); for (int j = 0; j < matrix.Width; j++) { for (int i = 0; i < matrix.Width; i++) { matrix[i, j, MatrixStatus.Data] = lines[j][i] == s_1Char; } } return matrix; }
/// <summary> /// Copies to. /// </summary> /// <param name="target">The target.</param> /// <param name="sourceArea">The source area.</param> /// <param name="targetPoint">The target point.</param> /// <param name="mstatus">The mstatus.</param> /// <remarks></remarks> internal void CopyTo(TriStateMatrix target, MatrixRectangle sourceArea, MatrixPoint targetPoint, MatrixStatus mstatus) { for (int j = 0; j < sourceArea.Size.Height; j++) { for (int i = 0; i < sourceArea.Size.Width; i++) { bool value = this[sourceArea.Location.X + i, sourceArea.Location.Y + j]; target[targetPoint.X + i, targetPoint.Y + j, mstatus] = value; } } }
public override void ApplyTo(TriStateMatrix matrix) { MatrixSize size = GetSizeOfSquareWithSeparators(); MatrixPoint leftTopCorner = new MatrixPoint(0, 0); this.CopyTo(matrix, new MatrixRectangle(new MatrixPoint(1, 1), size), leftTopCorner, MatrixStatus.NoMask); MatrixPoint rightTopCorner = new MatrixPoint(matrix.Width - this.Width + 1, 0); this.CopyTo(matrix, new MatrixRectangle(new MatrixPoint(0, 1), size), rightTopCorner, MatrixStatus.NoMask); MatrixPoint leftBottomCorner = new MatrixPoint(0, matrix.Width - this.Width + 1); this.CopyTo(matrix, new MatrixRectangle(new MatrixPoint(1, 0), size), leftBottomCorner, MatrixStatus.NoMask); }
private void Test_One_Case(int version, TriStateMatrix expected, IEnumerable <bool> codewords) { BitList dcList = new BitList(); dcList.Add(codewords); TriStateMatrix target = new TriStateMatrix(expected.Width); PositioninngPatternBuilder.EmbedBasicPatterns(version, target); target.TryEmbedCodewords(dcList); expected.AssertEquals(target); }
public static TriStateMatrix ToTriStateMatrix(this BitMatrix input) { int width = input.Width; TriStateMatrix result = new TriStateMatrix(width); for(int x = 0; x < width; x++) { for(int y = 0; y < width; y++) { result[x, y, MatrixStatus.Data] = input[x, y]; } } return result; }
private static BitMatrix FromGraphics(string[] lines) { var matrix = new TriStateMatrix(lines.Length); for (int j = 0; j < matrix.Width; j++) { for (int i = 0; i < matrix.Width; i++) { matrix[i, j, MatrixStatus.Data] = lines[j][i] == s_1Char; } } return(matrix); }
public static TriStateMatrix ToTriStateMatrix(this BitMatrix input) { int width = input.Width; TriStateMatrix result = new TriStateMatrix(width); for (int x = 0; x < width; x++) { for (int y = 0; y < width; y++) { result[x, y, MatrixStatus.Data] = input[x, y]; } } return(result); }
internal static TriStateMatrix ToBitMatrix(this Common.ByteMatrix byteMatrix) { TriStateMatrix matrix = new TriStateMatrix(byteMatrix.Width); for (int i = 0; i < byteMatrix.Width; i++) { for (int j = 0; j < byteMatrix.Height; j++) { if (byteMatrix[j, i] != -1) { matrix[i, j, MatrixStatus.NoMask] = byteMatrix[j, i] != 0; } } } return matrix; }
/// <summary> /// Toes the pattern bit matrix. /// </summary> /// <param name="byteMatrix">The byte matrix.</param> /// <returns></returns> /// <remarks></remarks> internal static TriStateMatrix ToPatternBitMatrix(this ByteMatrix byteMatrix) { var matrix = new TriStateMatrix(byteMatrix.Width); for (int i = 0; i < byteMatrix.Width; i++) { for (int j = 0; j < byteMatrix.Height; j++) { if (byteMatrix[j, i] != -1) { matrix[i, j, MatrixStatus.Data] = byteMatrix[j, i] != 0; } } } return matrix; }
public override void ApplyTo(TriStateMatrix matrix) { MatrixSize size = GetSizeOfSquareWithSeparators(); MatrixPoint leftTopCorner = new MatrixPoint(0, 0); CopyTo(matrix, new MatrixRectangle(new MatrixPoint(1, 1), size), leftTopCorner, MatrixStatus.NoMask); MatrixPoint rightTopCorner = new MatrixPoint(matrix.Width - Width + 1, 0); CopyTo(matrix, new MatrixRectangle(new MatrixPoint(0, 1), size), rightTopCorner, MatrixStatus.NoMask); MatrixPoint leftBottomCorner = new MatrixPoint(0, matrix.Width - Width + 1); CopyTo(matrix, new MatrixRectangle(new MatrixPoint(1, 0), size), leftBottomCorner, MatrixStatus.NoMask); }
/// <summary> /// Toes the pattern bit matrix. /// </summary> /// <param name="byteMatrix">The byte matrix.</param> /// <returns></returns> /// <remarks></remarks> internal static TriStateMatrix ToPatternBitMatrix(this ByteMatrix byteMatrix) { var matrix = new TriStateMatrix(byteMatrix.Width); for (int i = 0; i < byteMatrix.Width; i++) { for (int j = 0; j < byteMatrix.Height; j++) { if (byteMatrix[j, i] != -1) { matrix[i, j, MatrixStatus.Data] = byteMatrix[j, i] != 0; } } } return(matrix); }
internal static TriStateMatrix ToBitMatrix(this Common.ByteMatrix byteMatrix) { TriStateMatrix matrix = new TriStateMatrix(byteMatrix.Width); for (int i = 0; i < byteMatrix.Width; i++) { for (int j = 0; j < byteMatrix.Height; j++) { if (byteMatrix[j, i] != -1) { matrix[i, j, MatrixStatus.NoMask] = byteMatrix[j, i] != 0; } } } return(matrix); }
private static TriStateMatrix FromGraphic(string[] lines) { var matrix = new TriStateMatrix(lines.Length); for (int j = 0; j < matrix.Width; j++) { for (int i = 0; i < matrix.Width; i++) { if (lines[j][i]==s_0Char) { matrix[i, j, MatrixStatus.NoMask] = false; } else if (lines[j][i]==s_1Char) { matrix[i, j, MatrixStatus.NoMask] = true; } } } return matrix; }
private static TriStateMatrix FromGraphic(string[] lines) { var matrix = new TriStateMatrix(lines.Length); for (int j = 0; j < matrix.Width; j++) { for (int i = 0; i < matrix.Width; i++) { if (lines[j][i] == s_0Char) { matrix[i, j, MatrixStatus.NoMask] = false; } else if (lines[j][i] == s_1Char) { matrix[i, j, MatrixStatus.NoMask] = true; } } } return(matrix); }
internal static BitMatrix GetLowestPenaltyMatrix(this TriStateMatrix matrix, ErrorCorrectionLevel errorlevel) { PatternFactory patternFactory = new PatternFactory(); int score = int.MaxValue; int tempScore; TriStateMatrix result = new TriStateMatrix(matrix.Width); TriStateMatrix triMatrix; foreach(Pattern pattern in patternFactory.AllPatterns()) { triMatrix = matrix.Apply(pattern, errorlevel); tempScore = triMatrix.PenaltyScore(); if(tempScore < score) { score = tempScore; result = triMatrix; } } return result; }
/// <summary> /// Get Qr BitMatrix as two dimentional bool array. /// </summary> /// <returns>null if matrix is null, else full matrix</returns> public BitMatrix GetQrMatrix() { if (m_QrCode.Matrix == null) { return(null); } else { BitMatrix matrix = m_QrCode.Matrix; TriStateMatrix clone = new TriStateMatrix(matrix.Width); for (int x = 0; x < matrix.Width; x++) { for (int y = 0; y < matrix.Width; y++) { clone[x, y, MatrixStatus.NoMask] = matrix[x, y]; } } return(clone); } }
internal static BitMatrix GetLowestPenaltyMatrix(this TriStateMatrix matrix, ErrorCorrectionLevel errorLevel) { PatternFactory patternFactory = new(); int score = int.MaxValue; int tempScore; TriStateMatrix result = new(matrix.Width); TriStateMatrix triMatrix; foreach (Pattern pattern in patternFactory.AllPatterns()) { triMatrix = matrix.Apply(pattern, errorLevel); tempScore = triMatrix.PenaltyScore(); if (tempScore < score) { score = tempScore; result = triMatrix; } } return(result); }
public static void ToGraphic(this TriStateMatrix matrix, TextWriter output) { output.WriteLine(matrix.Width.ToString()); for (int j = 0; j < matrix.Width; j++) { for (int i = 0; i < matrix.Width; i++) { char charToPrint; if (matrix.MStatus(i, j) == MatrixStatus.None) { charToPrint = s_EmptyChar; } else { charToPrint = matrix[i, j] ? s_1Char : s_0Char; } output.Write(charToPrint); } output.WriteLine(); } }
public override void ApplyTo(TriStateMatrix matrix) { // -8 is for skipping position detection patterns (size 7), and two horizontal/vertical // separation patterns (size 1). Thus, 8 = 7 + 1. for (int i = 8; i < matrix.Width - 8; ++i) { bool value = (sbyte)((i + 1) % 2) == 1; // Horizontal line. if (matrix.MStatus(6, i) == MatrixStatus.None) { matrix[6, i, MatrixStatus.NoMask] = value; } // Vertical line. if (matrix.MStatus(i, 6) == MatrixStatus.None) { matrix[i, 6, MatrixStatus.NoMask] = value; } } }
/// <summary> /// Embed format information to tristatematrix. /// Process combination of create info bits, BCH error correction bits calculation, embed towards matrix. /// </summary> /// <remarks>ISO/IEC 18004:2000 Chapter 8.9 Page 53</remarks> internal static void EmbedFormatInformation(this TriStateMatrix triMatrix, ErrorCorrectionLevel errorLevel, Pattern pattern) { BitList formatInfo = GetFormatInfoBits(errorLevel, pattern); int width = triMatrix.Width; for (int index = 0; index < 15; index++) { MatrixPoint point = PointForInfo1(index); bool bit = formatInfo[index]; triMatrix[point.X, point.Y, MatrixStatus.NoMask] = bit; if (index < 7) { triMatrix[8, width - 1 - index, MatrixStatus.NoMask] = bit; } else { triMatrix[width - 8 + (index - 7), 8, MatrixStatus.NoMask] = bit; } } }
private void Encode(string content, int option) { ErrorCorrectionLevel errorLevel = ErrorCorrectionLevel.H; EncodationStruct encodeStruct = DataEncode.Encode(content, errorLevel); BitList codewords = ECGenerator.FillECCodewords(encodeStruct.DataCodewords, encodeStruct.VersionDetail); if (option == 3) { return; } TriStateMatrix triMatrix = new TriStateMatrix(encodeStruct.VersionDetail.MatrixWidth); PositioninngPatternBuilder.EmbedBasicPatterns(encodeStruct.VersionDetail.Version, triMatrix); triMatrix.EmbedVersionInformation(encodeStruct.VersionDetail.Version); triMatrix.EmbedFormatInformation(errorLevel, new Pattern0()); triMatrix.TryEmbedCodewords(codewords); triMatrix.GetLowestPenaltyMatrix(errorLevel); }
private static TriStateMatrix FromBytes(byte[] bytes) { int length = BitConverter.ToInt32(bytes, 0); byte[] data = new byte[(bytes.Length - sizeof(int)) * sizeof(byte)]; Array.Copy(bytes, sizeof(int), data, 0, data.Length); int width = (int)Math.Sqrt(length); if (width * width != length) { throw new ArgumentException(string.Format("The header containsinvalid length value. Length must be a square of width.{0}", length), "bytes"); } BitArray bitArray = new BitArray(data); TriStateMatrix matrix = new TriStateMatrix(width); for (int index = 0; index < length; index++) { int i = index % width; int j = index / width; matrix[i, j, MatrixStatus.Data] = bitArray[index]; } return matrix; }
public static void AssertEquals(this TriStateMatrix expected, TriStateMatrix actual) { if (expected == null) { throw new ArgumentNullException("expected"); } if (actual == null) { throw new ArgumentNullException("actual"); } if (expected.Width != actual.Width) { Assert.Fail("Mtrix must have same size. Expected {0}, Actual {1}", expected.Width, actual.Width); } for (int i = 0; i < expected.Width; i++) { for (int j = 0; j < expected.Width; j++) { if (expected.MStatus(i, j) != MatrixStatus.None && actual.MStatus(i, j) != MatrixStatus.None && expected[i, j] != actual[i, j]) { Assert.Fail("Matrces are different.\nExpected:{0}Actual:{1}.", TriStateMatrixToGraphicExtensions.ToGraphicString(expected), TriStateMatrixToGraphicExtensions.ToGraphicString(actual)); } if (expected.MStatus(i, j) == MatrixStatus.None && actual.MStatus(i, j) != MatrixStatus.None) { Assert.Fail("Matrces are different.\nExpected:{0}Actual:{1}.", TriStateMatrixToGraphicExtensions.ToGraphicString(expected), TriStateMatrixToGraphicExtensions.ToGraphicString(actual)); } if (expected.MStatus(i, j) != MatrixStatus.None && actual.MStatus(i, j) == MatrixStatus.None) { Assert.Fail("Matrces are different.\nExpected:{0}Actual:{1}.", TriStateMatrixToGraphicExtensions.ToGraphicString(expected), TriStateMatrixToGraphicExtensions.ToGraphicString(actual)); } } } }
public void Test_against_reference_implementation(int version, MaskPatternType patternType, TriStateMatrix expected) { Test_One_Case(version, patternType, expected); }
public void Test_against_DataSet(int version, MaskPatternType patternType, TriStateMatrix expected) { Test_One_Case(version, patternType, expected); }
/// <summary> /// Copies to. /// </summary> /// <param name="target">The target.</param> /// <param name="targetPoint">The target point.</param> /// <param name="mstatus">The mstatus.</param> /// <remarks></remarks> internal void CopyTo(TriStateMatrix target, MatrixPoint targetPoint, MatrixStatus mstatus) { CopyTo(target, new MatrixRectangle(new MatrixPoint(0, 0), new MatrixSize(Width, Height)), targetPoint, mstatus); }
public override void ApplyTo(TriStateMatrix matrix) { matrix[8, matrix.Width - 8, MatrixStatus.NoMask] = true; }
public void Test_against_DataSet(int version, TriStateMatrix expected, IEnumerable<bool> codewords) { Test_One_Case(version, expected, codewords); }
public void Test_against_reference_implementation(int version, TriStateMatrix expected, IEnumerable<bool> codewords) { Test_One_Case(version, expected, codewords); }
/// <summary> /// Applies the specified pattern. /// </summary> /// <param name="pattern">The pattern.</param> /// <param name="matrix">The matrix.</param> /// <param name="errorlevel">The errorlevel.</param> /// <returns></returns> /// <remarks></remarks> public static TriStateMatrix Apply(this Pattern pattern, TriStateMatrix matrix, ErrorCorrectionLevel errorlevel) { return matrix.Xor(pattern, errorlevel); }
private void Encode(string content, int option) { ErrorCorrectionLevel errorLevel = ErrorCorrectionLevel.H; EncodationStruct encodeStruct = DataEncode.Encode(content, errorLevel); BitList codewords = ECGenerator.FillECCodewords(encodeStruct.DataCodewords, encodeStruct.VersionDetail); if(option == 3) return; TriStateMatrix triMatrix = new TriStateMatrix(encodeStruct.VersionDetail.MatrixWidth); PositioninngPatternBuilder.EmbedBasicPatterns(encodeStruct.VersionDetail.Version, triMatrix); triMatrix.EmbedVersionInformation(encodeStruct.VersionDetail.Version); triMatrix.EmbedFormatInformation(errorLevel, new Pattern0()); triMatrix.TryEmbedCodewords(codewords); triMatrix.GetLowestPenaltyMatrix(errorLevel); }
public abstract void ApplyTo(TriStateMatrix matrix);
/// <summary> /// Get Qr BitMatrix as two dimentional bool array. /// </summary> /// <returns>null if matrix is null, else full matrix</returns> public BitMatrix GetQrMatrix() { if (m_QrCode.Matrix == null) return null; else { BitMatrix matrix = m_QrCode.Matrix; TriStateMatrix clone = new TriStateMatrix(matrix.Width); for (int x = 0; x < matrix.Width; x++) { for (int y = 0; y < matrix.Width; y++) { clone[x, y, MatrixStatus.NoMask] = matrix[x, y]; } } return clone; } }
public IEnumerable<MatrixPoint> GetNonColidingCoordinatePairs(TriStateMatrix matrix) { return GetAllCoordinatePairs() .Where(point => matrix.MStatus(point.Offset(2, 2)) == MatrixStatus.None); }