示例#1
0
        private static string ECBlocksToString(VersionZX.ECBlocks ecBlocks)
        {
            VersionZX.ECB[] ecBlock     = ecBlocks.getECBlocks();
            string          returnValue = "";

            foreach (VersionZX.ECB ecb in ecBlock)
            {
                returnValue = string.Join(s_Separator, returnValue, ecb.Count, ecb.DataCodewords);
            }
            return(returnValue);
        }
示例#2
0
        /// <summary> Initialize "QRCodeInternal" according to "numInputBytes", "m_EcLevelInternal", and "mode". On success,
        /// modify "QRCodeInternal".
        /// </summary>
        internal static void initQRCode(int numInputBytes, ErrorCorrectionLevelInternal m_EcLevelInternal, Mode mode, QRCodeInternal qrCodeInternal)
        {
            qrCodeInternal.EcLevelInternal = m_EcLevelInternal;
            qrCodeInternal.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(m_EcLevelInternal);
                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!
                    qrCodeInternal.Version       = versionNum;
                    qrCodeInternal.NumTotalBytes = numBytes;
                    qrCodeInternal.NumDataBytes  = numDataBytes;
                    qrCodeInternal.NumRSBlocks   = numRSBlocks;
                    // getNumECBytes = 196 - 66 = 130
                    qrCodeInternal.NumECBytes = numEcBytes;
                    // matrix width = 21 + 6 * 4 = 45
                    qrCodeInternal.MatrixWidth = version.DimensionForVersion;
                    return;
                }
            }
            throw new WriterException("Cannot find proper rs block info (input data too big?)");
        }