Example #1
0
        private void MapData(byte[] data, int maskPattern)
        {
            int inc       = -1;
            int row       = moduleCount - 1;
            int bitIndex  = 7;
            int byteIndex = 0;

            for (int col = moduleCount - 1; col > 0; col -= 2)
            {
                if (col == 6)
                {
                    col--;
                }
                while (true)
                {
                    for (int c = 0; c < 2; c++)
                    {
                        if (modules[row][col - c] == null)
                        {
                            bool dark = false;

                            if (byteIndex < data.Length)
                            {
                                dark = (((int)(((uint)data[byteIndex]) >> bitIndex) & 1) == 1);
                            }

                            bool mask = QRUtil.GetMask(maskPattern, row, col - c);
                            if (mask)
                            {
                                dark = !dark;
                            }

                            modules[row][col - c] = dark;
                            bitIndex--;
                            if (bitIndex == -1)
                            {
                                byteIndex++;
                                bitIndex = 7;
                            }
                        }
                    }

                    row += inc;
                    if (row < 0 || moduleCount <= row)
                    {
                        row -= inc;
                        inc  = -inc;
                        break;
                    }
                }
            }
        }
Example #2
0
        private void MapData(byte[] data, int maskPattern)
        {
            int num  = -1;
            int num2 = this.moduleCount - 1;
            int num3 = 7;
            int num4 = 0;

            for (int i = this.moduleCount - 1; i > 0; i -= 2)
            {
                if (i == 6)
                {
                    i--;
                }
                do
                {
                    for (int j = 0; j < 2; j++)
                    {
                        if (!this.modules[num2][i - j].HasValue)
                        {
                            bool flag = false;
                            if (num4 < data.Length)
                            {
                                flag = (((uint)data[num4] >> num3 & 1u) == 1u);
                            }
                            bool mask = QRUtil.GetMask(maskPattern, num2, i - j);
                            if (mask)
                            {
                                flag = !flag;
                            }
                            this.modules[num2][i - j] = new bool?(flag);
                            num3--;
                            if (num3 == -1)
                            {
                                num4++;
                                num3 = 7;
                            }
                        }
                    }
                    num2 += num;
                }while (num2 >= 0 && this.moduleCount > num2);
                num2 -= num;
                num   = -num;
            }
        }