Пример #1
0
        private void WriteSegments(BitSequence bs)
        {
            foreach (QRCodeEncoder segment in _segments)
            {
                bs.Append(segment.ModeIndicator, ModeIndicator.LENGTH);
                bs.Append(segment.CharCount,
                          CharCountIndicator.GetLength(
                              _currVersion, segment.EncodingMode)
                          );

                byte[] data = segment.GetBytes();

                for (int i = 0; i < data.Length - 1; ++i)
                {
                    bs.Append(data[i], 8);
                }

                int codewordBitLength = segment.BitCount % 8;

                if (codewordBitLength == 0)
                {
                    codewordBitLength = 8;
                }

                bs.Append(data[data.Length - 1] >> (8 - codewordBitLength),
                          codewordBitLength);
            }
        }
Пример #2
0
        /// <summary>
        /// エンコードされたデータのバイト配列を返します。
        /// </summary>
        public override byte[] GetBytes()
        {
            var bs        = new BitSequence();
            int bitLength = 10;

            for (int i = 0; i <= (_codeWords.Count - 1) - 1; ++i)
            {
                bs.Append(_codeWords[i], bitLength);
            }

            switch (_charCounter % 3)
            {
            case 1:
                bitLength = 4;
                break;

            case 2:
                bitLength = 7;
                break;

            default:
                bitLength = 10;
                break;
            }

            bs.Append(_codeWords[_codeWords.Count - 1], bitLength);

            return(bs.GetBytes());
        }
Пример #3
0
        /// <summary>
        /// 1bppビットマップファイルのバイトデータを返します。
        /// </summary>
        /// <param name="moduleSize">モジュールサイズ(px)</param>
        /// <param name="foreRgb">前景色</param>
        /// <param name="backRgb">背景色</param>
        private byte[] GetBitmap1bpp(int moduleSize, string foreRgb, string backRgb)
        {
            Color foreColor = ColorTranslator.FromHtml(foreRgb);
            Color backColor = ColorTranslator.FromHtml(backRgb);

            int[][] moduleMatrix = QuietZone.Place(GetModuleMatrix());

            int width, height;

            width = height = moduleSize * moduleMatrix.Length;

            int rowBytesLen = (width + 7) / 8;

            int pack8bit = 0;

            if (width % 8 > 0)
            {
                pack8bit = 8 - (width % 8);
            }

            int pack32bit = 0;

            if (rowBytesLen % 4 > 0)
            {
                pack32bit = 8 * (4 - (rowBytesLen % 4));
            }

            int rowSize = (width + pack8bit + pack32bit) / 8;

            byte[] bitmapData = new byte[rowSize * height];
            int    offset     = 0;

            for (int r = moduleMatrix.Length - 1; r >= 0; --r)
            {
                var bs = new BitSequence();

                foreach (int v in moduleMatrix[r])
                {
                    int color = Values.IsDark(v) ? 0 : 1;

                    for (int i = 1; i <= moduleSize; ++i)
                    {
                        bs.Append(color, 1);
                    }
                }
                bs.Append(0, pack8bit);
                bs.Append(0, pack32bit);

                byte[] bitmapRow = bs.GetBytes();

                for (int i = 1; i <= moduleSize; ++i)
                {
                    Array.Copy(bitmapRow, 0, bitmapData, offset, rowSize);
                    offset += rowSize;
                }
            }

            return(DIB.Build1bppDIB(bitmapData, width, height, foreColor, backColor));
        }
Пример #4
0
 private void WriteStructuredAppendHeader(BitSequence bs)
 {
     bs.Append(ModeIndicator.STRUCTURED_APPEND_VALUE,
               ModeIndicator.LENGTH);
     bs.Append(_position,
               SymbolSequenceIndicator.POSITION_LENGTH);
     bs.Append(_parent.Count - 1,
               SymbolSequenceIndicator.TOTAL_NUMBER_LENGTH);
     bs.Append(_parent.Parity,
               StructuredAppend.PARITY_DATA_LENGTH);
 }
Пример #5
0
 private void WritePaddingBits(BitSequence bs)
 {
     if (bs.Length % 8 > 0)
     {
         bs.Append(0x0, 8 - (bs.Length % 8));
     }
 }
Пример #6
0
        private void WriteTerminator(BitSequence bs)
        {
            int terminatorLength = Math.Min(
                ModeIndicator.LENGTH, _dataBitCapacity - _dataBitCounter);

            bs.Append(ModeIndicator.TERMINATOR_VALUE, terminatorLength);
        }
Пример #7
0
        /// <summary>
        /// エンコードされたデータのバイト配列を返します。
        /// </summary>
        public override byte[] GetBytes()
        {
            var bs = new BitSequence();

            foreach (int wd in _codeWords)
            {
                bs.Append(wd, 13);
            }

            return(bs.GetBytes());
        }
Пример #8
0
        private void WritePadCodewords(BitSequence bs)
        {
            int numDataCodewords = DataCodeword.GetTotalNumber(
                _parent.ErrorCorrectionLevel, _currVersion);

            bool flag = true;

            while (bs.Length < 8 * numDataCodewords)
            {
                bs.Append(flag ? 236 : 17, 8);
                flag = !flag;
            }
        }
Пример #9
0
        /// <summary>
        /// エンコードされたデータのバイト配列を返します。
        /// </summary>
        public override byte[] GetBytes()
        {
            var bs        = new BitSequence();
            int bitLength = 11;

            for (int i = 0; i <= (_codeWords.Count - 1) - 1; ++i)
            {
                bs.Append(_codeWords[i], bitLength);
            }

            if (_charCounter % 2 == 0)
            {
                bitLength = 11;
            }
            else
            {
                bitLength = 6;
            }

            bs.Append(_codeWords[_codeWords.Count - 1], bitLength);

            return(bs.GetBytes());
        }