Exemplo n.º 1
0
 private QREncoderMatrix(int dimension, string content, QRCorrectionLevel correctionLevel, QRMode mode, QRVersion version)
     : base(dimension, dimension)
 {
     Content         = content;
     CorrectionLevel = correctionLevel;
     Mode            = mode;
     Version         = version;
 }
Exemplo n.º 2
0
 private QREncoderMatrix(int dimension, string content, QRCorrectionLevel correctionLevel, QRMode mode, QRVersion version)
     : base(dimension, dimension)
 {
     Content = content;
     CorrectionLevel = correctionLevel;
     Mode = mode;
     Version = version;
 }
Exemplo n.º 3
0
        public static void AppendLengthInfo(int numLetters, QRVersion version, QRMode mode, BitList bits)
        {
            int numBits = mode.GetVersionCharacterCount(version);

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

            bits.AppendBits(numLetters, numBits);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
 public static void AppendBytes(String content, QRMode mode, BitList bits)
 {
     if (mode.Equals(QRMode.NUMERIC))
     {
         AppendNumericBytes(content, bits);
     }
     else if (mode.Equals(QRMode.ALPHANUMERIC))
     {
         AppendAlphanumericBytes(content, bits);
     }
     else if (mode.Equals(QRMode.BYTE))
     {
         Append8BitBytes(content, bits);
     }
     else
     {
         throw new NFXException(StringConsts.ARGUMENT_ERROR + typeof(QREncoderMatrix).Name + ".appendBytes(mode=NUMERIC|ALPHANUMERIC|BYTE)");
     }
 }
Exemplo n.º 6
0
 public static void AppendBytes(String content, QRMode mode, BitList bits)
 {
   if (mode.Equals(QRMode.NUMERIC))
     AppendNumericBytes(content, bits);
   else if (mode.Equals(QRMode.ALPHANUMERIC))
     AppendAlphanumericBytes(content, bits);
   else if (mode.Equals(QRMode.BYTE))
     Append8BitBytes(content, bits);
   else
     throw new NFXException(StringConsts.ARGUMENT_ERROR + typeof(QREncoderMatrix).Name + ".appendBytes(mode=NUMERIC|ALPHANUMERIC|BYTE)");
 }
Exemplo n.º 7
0
      public static void AppendLengthInfo(int numLetters, QRVersion version, QRMode mode, BitList bits)
      {
         int numBits = mode.GetVersionCharacterCount(version);
         if (numLetters >= (1 << numBits))
           throw new NFXException(StringConsts.CODE_LOGIC_ERROR + typeof(QREncoderMatrix).Name + ".appendLengthInfo(numLetters >= (1 << numBits))");

         bits.AppendBits(numLetters, numBits);
      }