示例#1
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());
        }
示例#2
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));
        }
示例#3
0
        private static (byte[] encoded, int padding) Encode(string text, Dictionary <char, BitSequence> dictionary)
        {
            BitSequence sequence = new BitSequence(8 * text.Length);

            foreach (char c in text)          // pętla przez każdy znak tekstu
            {
                sequence.Push(dictionary[c]); // dodaje do sekwencji bitów kod odpowiadajacy znakowi
            }
            return(sequence.GetBytes());
        }
示例#4
0
        /// <summary>
        /// エンコードされたデータのバイト配列を返します。
        /// </summary>
        public override byte[] GetBytes()
        {
            var bs = new BitSequence();

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

            return(bs.GetBytes());
        }
示例#5
0
        /// <summary>
        /// コード語に変換するメッセージビット列を返します。
        /// </summary>
        private byte[] GetMessageBytes()
        {
            var bs = new BitSequence();

            if (_parent.Count > 1)
            {
                WriteStructuredAppendHeader(bs);
            }

            WriteSegments(bs);
            WriteTerminator(bs);
            WritePaddingBits(bs);
            WritePadCodewords(bs);

            return(bs.GetBytes());
        }
示例#6
0
        public void ToBytesTest()
        {
            var seq = new BitSequence(16);

            seq.Push();
            seq.Push(true);
            seq.Push(true);
            seq.Push(true);
            seq.Push(true);
            seq.Push(true);
            seq.Push(true);
            seq.Push(true);
            seq.Push(true);
            var(arr, pad) = seq.GetBytes();
            Assert.Equal(7, pad);
            Assert.Equal(2, arr.Length);
            Assert.Equal(new byte[] { 127, 128 }, arr);
        }
示例#7
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());
        }