Example #1
0
        /// <summary>
        /// Determine which version to use
        /// </summary>
        /// <param name="dataBitsLength">Number of bits for encoded content</param>
        /// <param name="encodingName">Encoding name for EightBitByte</param>
        /// <returns>VersionDetail and ECI</returns>
        internal static VersionControlStruct InitialSetup(int dataBitsLength, Mode mode, ErrorCorrectionLevel level, string encodingName)
        {
            int totalDataBits = dataBitsLength;

            bool containECI = false;

            BitList eciHeader = new BitList();


            //Check ECI header
            if (mode == Mode.EightBitByte)
            {
                if (encodingName != DEFAULT_ENCODING && encodingName != QRCodeConstantVariable.UTF8Encoding)
                {
                    ECISet eciSet   = new ECISet(ECISet.AppendOption.NameToValue);
                    int    eciValue = eciSet.GetECIValueByName(encodingName);

                    totalDataBits += ECISet.NumOfECIHeaderBits(eciValue);
                    eciHeader      = eciSet.GetECIHeader(encodingName);
                    containECI     = true;
                }
            }
            //Determine which version group it belong to
            int searchGroup = DynamicSearchIndicator(totalDataBits, level, mode);

            int[] charCountIndicator = CharCountIndicatorTable.GetCharCountIndicatorSet(mode);

            totalDataBits += (NUM_BITS_MODE_INDICATOR + charCountIndicator[searchGroup]);

            int lowerSearchBoundary  = searchGroup == 0 ? 1 : (VERSION_GROUP[searchGroup - 1] + 1);
            int higherSearchBoundary = VERSION_GROUP[searchGroup];

            //Binary search to find proper version
            int versionNum = BinarySearch(totalDataBits, level, lowerSearchBoundary, higherSearchBoundary);

            VersionControlStruct vcStruct = FillVCStruct(versionNum, level, encodingName);

            vcStruct.isContainECI = containECI;

            vcStruct.ECIHeader = eciHeader;

            return(vcStruct);
        }
Example #2
0
        /// <summary>
        /// Determine which version to use
        /// </summary>
        /// <param name="dataBitsLength">Number of bits for encoded content</param>
        /// <param name="encodingName">Encoding name for EightBitByte</param>
        /// <returns>VersionDetail and ECI</returns>
        internal static VersionControlStruct InitialSetup(int dataBitsLength, ErrorCorrectionLevel level, string encodingName)
        {
            int totalDataBits = dataBitsLength;

            bool containECI = false;

            BitList eciHeader = new BitList();

            if (encodingName is not DefaultEncoding and not QRCodeConstantVariable.UTF8Encoding)
            {
                ECISet eciSet   = new ECISet(ECISet.AppendOption.NameToValue);
                int    eciValue = eciSet.GetECIValueByName(encodingName);

                totalDataBits += ECISet.NumOfECIHeaderBits(eciValue);
                eciHeader      = eciSet.GetECIHeader(encodingName);
                containECI     = true;
            }

            // Determine which version group it belong to
            int searchGroup = DynamicSearchIndicator(totalDataBits, level);

            int[] charCountIndicator = CharCountIndicatorTable.GetCharCountIndicatorSet();

            totalDataBits += (NumBitsModeIndicator + charCountIndicator[searchGroup]);

            int lowerSearchBoundary  = searchGroup == 0 ? 1 : (VERSION_GROUP[searchGroup - 1] + 1);
            int higherSearchBoundary = VERSION_GROUP[searchGroup];

            // Binary search to find proper version
            int versionNum = BinarySearch(totalDataBits, level, lowerSearchBoundary, higherSearchBoundary);

            VersionControlStruct vcStruct = FillVCStruct(versionNum, level);

            vcStruct.IsContainECI = containECI;

            vcStruct.ECIHeader = eciHeader;

            return(vcStruct);
        }
Example #3
0
        private static VersionControlStruct FillVCStruct(int versionNum, ErrorCorrectionLevel level)
        {
            if (versionNum < 1 || versionNum > 40)
            {
                throw new InvalidOperationException($"Unexpected version number: {versionNum}");
            }

            VersionControlStruct vcStruct = new VersionControlStruct();

            int version = versionNum;

            QRCodeVersion versionData = VersionTable.GetVersionByNum(versionNum);

            int numTotalBytes = versionData.TotalCodewords;

            ErrorCorrectionBlocks ecBlocks = versionData.GetECBlocksByLevel(level);
            int numDataBytes = numTotalBytes - ecBlocks.NumErrorCorrectionCodewards;
            int numECBlocks  = ecBlocks.NumBlocks;

            VersionDetail vcDetail = new VersionDetail(version, numTotalBytes, numDataBytes, numECBlocks);

            vcStruct.VersionDetail = vcDetail;
            return(vcStruct);
        }
Example #4
0
		private static VersionControlStruct FillVCStruct(int versionNum, ErrorCorrectionLevel level, string encodingName)
		{
			if(versionNum < 1 || versionNum > 40)
			{
				throw new InvalidOperationException(string.Format("Unexpected version number: {0}", versionNum));
			}
			
			VersionControlStruct vcStruct = new VersionControlStruct();
			
			int version = versionNum;
			
			QRCodeVersion versionData = VersionTable.GetVersionByNum(versionNum);
			
			int numTotalBytes = versionData.TotalCodewords;
			
			ErrorCorrectionBlocks ecBlocks = versionData.GetECBlocksByLevel(level);
			int numDataBytes = numTotalBytes - ecBlocks.NumErrorCorrectionCodewards;
			int numECBlocks = ecBlocks.NumBlocks;
			
			VersionDetail vcDetail = new VersionDetail(version, numTotalBytes, numDataBytes, numECBlocks);
			
			vcStruct.VersionDetail = vcDetail;
			return vcStruct;
		}
 internal EncodationStruct(VersionControlStruct vcStruct)
     : this()
 {
     this.VersionDetail = vcStruct.VersionDetail;
 }