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

            bool containECI = false;

            var eciHeader = new BitList();


            //Check ECI header
            if (mode == Mode.EightBitByte)
            {
                if (encodingName != DEFAULT_ENCODING && encodingName != QRCodeConstantVariable.UTF8Encoding)
                {
                    var 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>
        /// Fills the VC struct.
        /// </summary>
        /// <param name="versionNum">The version num.</param>
        /// <param name="level">The level.</param>
        /// <param name="encodingName">Name of the encoding.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        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));
            }

            var 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;

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

            vcStruct.VersionDetail = vcDetail;
            return(vcStruct);
        }
Example #3
0
        /// <summary>
        /// Fills the VC struct.
        /// </summary>
        /// <param name="versionNum">The version num.</param>
        /// <param name="level">The level.</param>
        /// <param name="encodingName">Name of the encoding.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        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));
            }

            var 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;

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

            vcStruct.VersionDetail = vcDetail;
            return vcStruct;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="EncodationStruct"/> struct.
 /// </summary>
 /// <param name="vcStruct">The vc struct.</param>
 /// <remarks></remarks>
 internal EncodationStruct(VersionControlStruct vcStruct)
     : this()
 {
     VersionDetail = vcStruct.VersionDetail;
 }