Exemplo n.º 1
0
        public static List <QRRSBlock> GetRSBlocks(int typeNumber, QRErrorCorrectLevel errorCorrectLevel)
        {
            int[] rsBlock = GetRsBlockTable(typeNumber, errorCorrectLevel);

            if (rsBlock == null)
            {
                throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel);
            }

            int length = (int)rsBlock.Length / 3;

            var list = new List <QRRSBlock>();

            for (int i = 0; i < length; i++)
            {
                int count      = rsBlock[i * 3 + 0];
                int totalCount = rsBlock[i * 3 + 1];
                int dataCount  = rsBlock[i * 3 + 2];

                for (int j = 0; j < count; j++)
                {
                    list.Add(new QRRSBlock(totalCount, dataCount));
                }
            }

            return(list);
        }
Exemplo n.º 2
0
        public static List <QRRSBlock> GetRSBlocks(int typeNumber, QRErrorCorrectLevel errorCorrectLevel)
        {
            var rsBlock = GetRsBlockTable(typeNumber, errorCorrectLevel);

            if (rsBlock == null)
            {
                throw new ErrorException(string.Format("Bad rs block @ typeNumber: {0} and /errorCorrectLevel: {1}", typeNumber, errorCorrectLevel), ErrorCode.BadBlock);
            }

            var length = rsBlock.Length / 3;
            var list   = new List <QRRSBlock>();

            for (var i = 0; i < length; i++)
            {
                var count      = rsBlock[i * 3 + 0];
                var totalCount = rsBlock[i * 3 + 1];
                var dataCount  = rsBlock[i * 3 + 2];

                for (var j = 0; j < count; j++)
                {
                    list.Add(new QRRSBlock(totalCount, dataCount));
                }
            }

            return(list);
        }
Exemplo n.º 3
0
        private static int[] GetRsBlockTable(int typeNumber, QRErrorCorrectLevel errorCorrectLevel)
        {
            int[] result;
            switch (errorCorrectLevel)
            {
            case QRErrorCorrectLevel.M:
                result = QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
                break;

            case QRErrorCorrectLevel.L:
                result = QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4];
                break;

            case QRErrorCorrectLevel.H:
                result = QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
                break;

            case QRErrorCorrectLevel.Q:
                result = QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
                break;

            default:
                result = null;
                break;
            }
            return(result);
        }
Exemplo n.º 4
0
        public static List <QRRSBlock> GetRSBlocks(int typeNumber, QRErrorCorrectLevel errorCorrectLevel)
        {
            int[] rsBlockTable = QRRSBlock.GetRsBlockTable(typeNumber, errorCorrectLevel);
            bool  flag         = rsBlockTable == null;

            if (flag)
            {
                throw new Error(string.Concat(new object[]
                {
                    "bad rs block @ typeNumber:",
                    typeNumber,
                    "/errorCorrectLevel:",
                    errorCorrectLevel
                }));
            }
            int num = rsBlockTable.Length / 3;
            List <QRRSBlock> list = new List <QRRSBlock>();

            for (int index = 0; index < num; index++)
            {
                int num2       = rsBlockTable[index * 3];
                int totalCount = rsBlockTable[index * 3 + 1];
                int dataCount  = rsBlockTable[index * 3 + 2];
                for (int index2 = 0; index2 < num2; index2++)
                {
                    list.Add(new QRRSBlock(totalCount, dataCount));
                }
            }
            return(list);
        }
Exemplo n.º 5
0
        private DataCache CreateData(int typeNumber, QRErrorCorrectLevel errorCorrectLevel, List <QR8bitByte> dataList)
        {
            List <QRRSBlock> rsBlocks = QRRSBlock.GetRSBlocks(typeNumber, errorCorrectLevel);
            QRBitBuffer      buffer   = new QRBitBuffer();

            for (int index = 0; index < dataList.Count; index++)
            {
                QR8bitByte qr8bitByte = dataList[index];
                buffer.Put((int)qr8bitByte.Mode, 4);
                buffer.Put(qr8bitByte.Length, QRUtil.GetLengthInBits(qr8bitByte.Mode, typeNumber));
                qr8bitByte.Write(buffer);
            }
            int num = 0;

            for (int index2 = 0; index2 < rsBlocks.Count; index2++)
            {
                num += rsBlocks[index2].DataCount;
            }
            bool flag = buffer.GetLengthInBits() > num * 8;

            if (flag)
            {
                throw new Error(string.Concat(new object[]
                {
                    "code length overflow. (",
                    buffer.GetLengthInBits(),
                    ">",
                    num * 8,
                    ")"
                }));
            }
            bool flag2 = buffer.GetLengthInBits() + 4 <= num * 8;

            if (flag2)
            {
                buffer.Put(0, 4);
            }
            while (buffer.GetLengthInBits() % 8 != 0)
            {
                buffer.PutBit(false);
            }
            while (true)
            {
                bool flag3 = buffer.GetLengthInBits() < num * 8;
                if (!flag3)
                {
                    break;
                }
                buffer.Put(236, 8);
                bool flag4 = buffer.GetLengthInBits() < num * 8;
                if (!flag4)
                {
                    break;
                }
                buffer.Put(17, 8);
            }
            return(this.CreateBytes(buffer, rsBlocks));
        }
Exemplo n.º 6
0
        private static int[] GetRsBlockTable(int typeNumber, QRErrorCorrectLevel errorCorrectLevel)
        {
            switch (errorCorrectLevel)
            {
            case QRErrorCorrectLevel.L:
                return(QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0]);

            case QRErrorCorrectLevel.M:
                return(QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1]);

            case QRErrorCorrectLevel.Q:
                return(QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2]);

            case QRErrorCorrectLevel.H:
                return(QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3]);

            default:
                return(null);
            }
        }
Exemplo n.º 7
0
 public QRCode(int typeNumber, QRErrorCorrectLevel level)
 {
     m_typeNumber        = typeNumber;
     m_errorCorrectLevel = level;
     m_dataCache         = null;
 }
Exemplo n.º 8
0
        private DataCache CreateData(int typeNumber, QRErrorCorrectLevel errorCorrectLevel, List <QR8bitByte> dataList)
        {
            List <QRRSBlock> rsBlocks = QRRSBlock.GetRSBlocks(typeNumber, errorCorrectLevel);

            var buffer = new QRBitBuffer();

            for (int i = 0; i < dataList.Count; i++)
            {
                QR8bitByte data = dataList[i];

                buffer.Put((int)data.Mode, 4);
                buffer.Put(data.Length, QRUtil.GetLengthInBits(data.Mode, typeNumber));
                data.Write(buffer);
            }

            // calc num max data.
            int totalDataCount = 0;

            for (var i = 0; i < rsBlocks.Count; i++)
            {
                totalDataCount += rsBlocks[i].DataCount;
            }

            if (buffer.GetLengthInBits() > totalDataCount * 8)
            {
                throw new Error("code length overflow. ("
                                + buffer.GetLengthInBits()
                                + ">"
                                + totalDataCount * 8
                                + ")");
            }

            // end code
            if (buffer.GetLengthInBits() + 4 <= totalDataCount * 8)
            {
                buffer.Put(0, 4);
            }

            // padding
            while (buffer.GetLengthInBits() % 8 != 0)
            {
                buffer.PutBit(false);
            }

            // padding
            while (true)
            {
                if (buffer.GetLengthInBits() >= totalDataCount * 8)
                {
                    break;
                }
                buffer.Put(QRCode.PAD0, 8);

                if (buffer.GetLengthInBits() >= totalDataCount * 8)
                {
                    break;
                }
                buffer.Put(QRCode.PAD1, 8);
            }

            return(CreateBytes(buffer, rsBlocks));
        }