ClassLibraryWeiBao/QR二维码/EncodingRegion/Codeword.cs

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using Gma.QrCodeNet.Encoding.Positioning;

namespace Gma.QrCodeNet.Encoding.EncodingRegion
{
	/// <remarks>ISO/IEC 18004:2000 Chapter 8.7.3 Page 46</remarks>
	internal static class Codeword
	{
		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(string.Format("Not all bits from codewords consumed by matrix: {0} / {1}", bitIndex, codewordsSize));
		}
		
后面还有 12 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。