/// <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 static BitList GetFormatInfoBits(ErrorCorrectionLevel errorlevel, Pattern pattern)
        {
            int formatInfo = (int)pattern.MaskPatternType;
            //Pattern bits length = 3
            formatInfo |= GetErrorCorrectionIndicatorBits(errorlevel) << 3;

            int bchCode = BCHCalculator.CalculateBCH(formatInfo, s_FormatInfoPoly);
            //bchCode length = 10
            formatInfo = (formatInfo << 10) | bchCode;

            //xor maskPattern
            formatInfo ^= s_FormatInfoMaskPattern;

            BitList resultBits = new BitList();
            resultBits.Add(formatInfo, 15);

            if(resultBits.Count != 15)
                throw new Exception("FormatInfoBits length is not 15");
            else
                return resultBits;
        }
 public static TriStateMatrix Xor(this TriStateMatrix first, Pattern second, ErrorCorrectionLevel errorlevel)
 {
 	TriStateMatrix result = XorMatrix(first, second);
 	result.EmbedFormatInformation(errorlevel, second);
 	return result;
 }
 public static TriStateMatrix Apply(this TriStateMatrix matrix, Pattern pattern, ErrorCorrectionLevel errorlevel)
 {
     return matrix.Xor(pattern, errorlevel);
 }
Exemple #5
0
 public static TriStateMatrix Apply(this Pattern pattern, TriStateMatrix matrix, ErrorCorrectionLevel errorLevel) => matrix.Xor(pattern, errorLevel);