/// <summary> /// Encodes the specified content. /// </summary> /// <param name="content">The content.</param> /// <param name="ecLevel">The ec level.</param> /// <returns></returns> /// <remarks></remarks> internal static EncodationStruct Encode(string content, ErrorCorrectionLevel ecLevel) { RecognitionStruct recognitionResult = InputRecognise.Recognise(content); EncoderBase encoderBase = CreateEncoder(recognitionResult.Mode, recognitionResult.EncodingName); BitList encodeContent = encoderBase.GetDataBits(content); int encodeContentLength = encodeContent.Count; VersionControlStruct vcStruct = VersionControl.InitialSetup(encodeContentLength, recognitionResult.Mode, ecLevel, recognitionResult.EncodingName); var dataCodewords = new BitList(); //Eci header if (vcStruct.isContainECI && vcStruct.ECIHeader != null) { dataCodewords.Add(vcStruct.ECIHeader); } //Header dataCodewords.Add(encoderBase.GetModeIndicator()); int numLetter = recognitionResult.Mode == Mode.EightBitByte ? encodeContentLength >> 3 : content.Length; dataCodewords.Add(encoderBase.GetCharCountIndicator(numLetter, vcStruct.VersionDetail.Version)); //Data dataCodewords.Add(encodeContent); //Terminator Padding dataCodewords.TerminateBites(dataCodewords.Count, vcStruct.VersionDetail.NumDataBytes); int dataCodewordsCount = dataCodewords.Count; if ((dataCodewordsCount & 0x7) != 0) { throw new ArgumentException("data codewords is not byte sized."); } else if (dataCodewordsCount >> 3 != vcStruct.VersionDetail.NumDataBytes) { throw new ArgumentException("datacodewords num of bytes not equal to NumDataBytes for current version"); } var encStruct = new EncodationStruct(vcStruct); encStruct.Mode = recognitionResult.Mode; encStruct.DataCodewords = dataCodewords; return(encStruct); }
/// <summary> /// Encodes the specified content. /// </summary> /// <param name="content">The content.</param> /// <param name="ecLevel">The ec level.</param> /// <returns></returns> /// <remarks></remarks> internal static EncodationStruct Encode(string content, ErrorCorrectionLevel ecLevel) { RecognitionStruct recognitionResult = InputRecognise.Recognise(content); EncoderBase encoderBase = CreateEncoder(recognitionResult.Mode, recognitionResult.EncodingName); BitList encodeContent = encoderBase.GetDataBits(content); int encodeContentLength = encodeContent.Count; VersionControlStruct vcStruct = VersionControl.InitialSetup(encodeContentLength, recognitionResult.Mode, ecLevel, recognitionResult.EncodingName); var dataCodewords = new BitList(); //Eci header if (vcStruct.isContainECI && vcStruct.ECIHeader != null) dataCodewords.Add(vcStruct.ECIHeader); //Header dataCodewords.Add(encoderBase.GetModeIndicator()); int numLetter = recognitionResult.Mode == Mode.EightBitByte ? encodeContentLength >> 3 : content.Length; dataCodewords.Add(encoderBase.GetCharCountIndicator(numLetter, vcStruct.VersionDetail.Version)); //Data dataCodewords.Add(encodeContent); //Terminator Padding dataCodewords.TerminateBites(dataCodewords.Count, vcStruct.VersionDetail.NumDataBytes); int dataCodewordsCount = dataCodewords.Count; if ((dataCodewordsCount & 0x7) != 0) throw new ArgumentException("data codewords is not byte sized."); else if (dataCodewordsCount >> 3 != vcStruct.VersionDetail.NumDataBytes) { throw new ArgumentException("datacodewords num of bytes not equal to NumDataBytes for current version"); } var encStruct = new EncodationStruct(vcStruct); encStruct.Mode = recognitionResult.Mode; encStruct.DataCodewords = dataCodewords; return encStruct; }