예제 #1
0
파일: Encoder.cs 프로젝트: CareyGit/jx
		/// <summary> Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".</summary>
		internal static void  appendBytes(System.String content, Mode mode, BitVector bits, System.String encoding)
		{
			if (mode.Equals(Mode.NUMERIC))
			{
				appendNumericBytes(content, bits);
			}
			else if (mode.Equals(Mode.ALPHANUMERIC))
			{
				appendAlphanumericBytes(content, bits);
			}
			else if (mode.Equals(Mode.BYTE))
			{
				append8BitBytes(content, bits, encoding);
			}
			else if (mode.Equals(Mode.KANJI))
			{
				appendKanjiBytes(content, bits);
			}
			else
			{
				throw new WriterException("Invalid mode: " + mode);
			}
		}
예제 #2
0
파일: Encoder.cs 프로젝트: CareyGit/jx
		/// <summary> Append length info. On success, store the result in "bits".</summary>
		internal static void  appendLengthInfo(int numLetters, int version, Mode mode, BitVector bits)
		{
			int numBits = mode.getCharacterCountBits(Version.getVersionForNumber(version));
			if (numLetters > ((1 << numBits) - 1))
			{
				throw new WriterException(numLetters + "is bigger than" + ((1 << numBits) - 1));
			}
			bits.appendBits(numLetters, numBits);
		}
예제 #3
0
파일: Encoder.cs 프로젝트: CareyGit/jx
		/// <summary> Initialize "qrCode" according to "numInputBytes", "ecLevel", and "mode". On success,
		/// modify "qrCode".
		/// </summary>
		private static void  initQRCode(int numInputBytes, ErrorCorrectionLevel ecLevel, Mode mode, QRCode qrCode)
		{
			qrCode.ECLevel = ecLevel;
			qrCode.Mode = mode;
			
			// In the following comments, we use numbers of Version 7-H.
			for (int versionNum = 1; versionNum <= 40; versionNum++)
			{
				Version version = Version.getVersionForNumber(versionNum);
				// numBytes = 196
				int numBytes = version.TotalCodewords;
				// getNumECBytes = 130
				Version.ECBlocks ecBlocks = version.getECBlocksForLevel(ecLevel);
				int numEcBytes = ecBlocks.TotalECCodewords;
				// getNumRSBlocks = 5
				int numRSBlocks = ecBlocks.NumBlocks;
				// getNumDataBytes = 196 - 130 = 66
				int numDataBytes = numBytes - numEcBytes;
				// We want to choose the smallest version which can contain data of "numInputBytes" + some
				// extra bits for the header (mode info and length info). The header can be three bytes
				// (precisely 4 + 16 bits) at most. Hence we do +3 here.
				if (numDataBytes >= numInputBytes + 3)
				{
					// Yay, we found the proper rs block info!
					qrCode.Version = versionNum;
					qrCode.NumTotalBytes = numBytes;
					qrCode.NumDataBytes = numDataBytes;
					qrCode.NumRSBlocks = numRSBlocks;
					// getNumECBytes = 196 - 66 = 130
					qrCode.NumECBytes = numEcBytes;
					// matrix width = 21 + 6 * 4 = 45
					qrCode.MatrixWidth = version.DimensionForVersion;
					return ;
				}
			}
			throw new WriterException("Cannot find proper rs block info (input data too big?)");
		}
예제 #4
0
파일: Encoder.cs 프로젝트: CareyGit/jx
		/// <summary> Append mode info. On success, store the result in "bits".</summary>
		internal static void  appendModeInfo(Mode mode, BitVector bits)
		{
			bits.appendBits(mode.Bits, 4);
		}
예제 #5
0
파일: QRCode.cs 프로젝트: CareyGit/jx
		public QRCode()
		{
			mode = null;
			ecLevel = null;
			version = - 1;
			matrixWidth = - 1;
			maskPattern = - 1;
			numTotalBytes = - 1;
			numDataBytes = - 1;
			numECBytes = - 1;
			numRSBlocks = - 1;
			matrix = null;
		}