See ISO 18004:2006, 6.4.1, Tables 2 and 3. This enum encapsulates the various modes in which data can be encoded to bits in the QR code standard.

Exemplo n.º 1
0
 public QRCode()
 {
     mode = null;
     ecLevel = null;
     version = - 1;
     matrixWidth = - 1;
     maskPattern = - 1;
     numTotalBytes = - 1;
     numDataBytes = - 1;
     numECBytes = - 1;
     numRSBlocks = - 1;
     matrix = null;
 }
Exemplo n.º 2
0
 /// <summary> Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".</summary>
 internal static void appendBytes(String content, Mode mode, BitVector bits, 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);
     }
 }
Exemplo n.º 3
0
 /// <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);
 }
Exemplo n.º 4
0
 /// <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);
 }
Exemplo n.º 5
0
        /// <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?)");
        }