Ejemplo n.º 1
0
        public static QREncoderMatrix Encode(string content, QRCorrectionLevel correctionLevel)
        {
            string encoding = DEFAULT_ENCODING;

            QRMode mode = chooseMode(content, encoding);

            BitList header = new BitList();

            header.AppendBits(mode.ModeSignature, 4);

            BitList data = new BitList();

            AppendBytes(content, mode, data);

            int       provisionalBitsNeeded = header.Size + mode.GetVersionCharacterCount(QRVersion.GetVersionByNumber(1)) + data.Size;
            QRVersion provisionalVersion    = chooseVersion(provisionalBitsNeeded, correctionLevel);

            int       bitsNeeded = header.Size + mode.GetVersionCharacterCount(provisionalVersion) + data.Size;
            QRVersion version    = chooseVersion(bitsNeeded, correctionLevel);

            BitList headerNData = new BitList();

            headerNData.AppendBitList(header);

            int numLetters = mode == QRMode.BYTE ? data.ByteSize : content.Length;

            AppendLengthInfo(numLetters, version, mode, headerNData);

            headerNData.AppendBitList(data);

            QRVersion.CorrectionBlockSet correctionBlockSet = version.GetBlockSetByLevel(correctionLevel);
            int dataBytesQty = version.TotalCodewords - correctionBlockSet.TotalCodewords;

            WriteTerminationSection(dataBytesQty, headerNData);

            BitList finalBits = MixWithCorrectionBytes(headerNData, version.TotalCodewords, dataBytesQty, correctionBlockSet.TotalQty);

            int             dimension = version.Dimension;
            QREncoderMatrix matrix    = new QREncoderMatrix(dimension, content, correctionLevel, mode, version);

            int maskPattern = chooseMaskPattern(finalBits, correctionLevel, version, matrix);

            matrix.MaskPattern = maskPattern;

            matrix.FormMatrix(finalBits, correctionLevel, version, maskPattern);

            return(matrix);
        }
Ejemplo n.º 2
0
        public static void AppendLengthInfo(int numLetters, QRVersion version, QRMode mode, BitList bits)
        {
            int numBits = mode.GetVersionCharacterCount(version);

            if (numLetters >= (1 << numBits))
            {
                throw new AzosException(StringConsts.CODE_LOGIC_ERROR + typeof(QREncoderMatrix).Name + ".appendLengthInfo(numLetters >= (1 << numBits))");
            }

            bits.AppendBits(numLetters, numBits);
        }