public static VersionCheckStatus VersionCheck(int versionNum, int numDataBits, Mode mode, ErrorCorrectionLevel level, string encodingName) { int TotalDataBits = numDataBits; ECISet eciSet = new ECISet(ECISet.AppendOption.NameToValue); if(mode == Mode.EightBitByte) { if(encodingName != DEFAULT_ENCODING) { int eciValue = eciSet.GetECIValueByName(encodingName); TotalDataBits += ECISet.NumOfECIHeaderBits(eciValue); } } int bitCharCountIndicator = CharCountIndicatorTable.GetBitCountInCharCountIndicator(mode, versionNum); TotalDataBits += (4 + bitCharCountIndicator); int expectContainer = DataBits(versionNum, level); int lowerContainer = versionNum == 1 ? 0 : DataBits(versionNum - 1, level); if(expectContainer < TotalDataBits) { return VersionCheckStatus.SmallerThanExpect; } else if(lowerContainer >= TotalDataBits) { return VersionCheckStatus.LargerThanExpect; } else { return VersionCheckStatus.Efficient; } }
/// <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; }