コード例 #1
0
ファイル: Encoder.cs プロジェクト: hankhongyi/zxing_for_wp8
        /// <summary> Initialize "qrCode" according to "numInputBytes", "ecLevel", and "mode". On success,
        /// modify "qrCode".
        /// </summary>
        private static void initQRCode(int numInputBytes, ErrorCorrectionLevel ecLevel, Mode mode, QRCode qrCode)
        {
            qrCode.ECLevel = ecLevel;
            qrCode.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(ecLevel);
                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!
                    qrCode.Version = versionNum;
                    qrCode.NumTotalBytes = numBytes;
                    qrCode.NumDataBytes = numDataBytes;
                    qrCode.NumRSBlocks = numRSBlocks;
                    // getNumECBytes = 196 - 66 = 130
                    qrCode.NumECBytes = numEcBytes;
                    // matrix width = 21 + 6 * 4 = 45
                    qrCode.MatrixWidth = version.DimensionForVersion;
                    return ;
                }
            }
            throw new WriterException("Cannot find proper rs block info (input data too big?)");
        }
コード例 #2
0
ファイル: Encoder.cs プロジェクト: hankhongyi/zxing_for_wp8
 /// <summary> Append length info. On success, store the result in "bits".</summary>
 internal static void appendLengthInfo(int numLetters, int version, Mode mode, BitVector bits)
 {
     int numBits = mode.getCharacterCountBits(Version.getVersionForNumber(version));
     if (numLetters > ((1 << numBits) - 1))
     {
         throw new WriterException(numLetters + "is bigger than" + ((1 << numBits) - 1));
     }
     bits.appendBits(numLetters, numBits);
 }
コード例 #3
0
ファイル: Encoder.cs プロジェクト: hankhongyi/zxing_for_wp8
 /// <summary> Append mode info. On success, store the result in "bits".</summary>
 internal static void appendModeInfo(Mode mode, BitVector bits)
 {
     bits.appendBits(mode.Bits, 4);
 }
コード例 #4
0
ファイル: Encoder.cs プロジェクト: hankhongyi/zxing_for_wp8
 /// <summary> Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".</summary>
 internal static void appendBytes(System.String content, Mode mode, BitVector bits, System.String encoding)
 {
     if (mode.Equals(Mode.NUMERIC))
     {
         appendNumericBytes(content, bits);
     }
     else if (mode.Equals(Mode.ALPHANUMERIC))
     {
         appendAlphanumericBytes(content, bits);
     }
     else if (mode.Equals(Mode.BYTE))
     {
         append8BitBytes(content, bits, encoding);
     }
     else if (mode.Equals(Mode.KANJI))
     {
         appendKanjiBytes(content, bits);
     }
     else
     {
         throw new WriterException("Invalid mode: " + mode);
     }
 }