Esempio n. 1
0
        static public uint ReadBitsAt(byte[] Data, int Offset, int Count)
        {
            var BitReader = new BitReader(Data);

            BitReader.Position = Offset;
            return(BitReader.ReadBits(Count));
        }
Esempio n. 2
0
        static public IEnumerable <KeyValuePair <uint, uint> > FixedBitReader(byte[] Data, int BitCount = 0, int Offset = 0)
        {
            using (var BitReader = new BitReader(Data))
            {
                BitReader.Position = Offset;

                uint Index = 0;
                while (BitReader.BitsLeft >= BitCount)
                {
                    yield return(new KeyValuePair <uint, uint>(Index++, BitReader.ReadBits(BitCount)));
                }
            }
        }
Esempio n. 3
0
        public static IEnumerable<KeyValuePair<uint, uint>> FixedBitReader(byte[] Data, int BitCount = 0, int Offset = 0)
        {
            using (var BitReader = new BitReader(Data))
            {
                BitReader.Position = Offset;

                uint Index = 0;
                while (BitReader.BitsLeft >= BitCount)
                {
                    yield return new KeyValuePair<uint, uint>(Index++, BitReader.ReadBits(BitCount));
                }
            }
        }
Esempio n. 4
0
            public GlyphSymbol Read(PGF PGF, int GlyphIndex)
            {
                var br = new BitReader(PGF.charData);

                br.Position = PGF.charPointer[GlyphIndex] * 4 * 8;

                this.GlyphIndex  = GlyphIndex;
                this.UnicodeChar = (char)PGF.reverseCharMap[GlyphIndex];

                //int NextOffset = br.Position;

                //br.Position = NextOffset;
                int ShadowOffset = (int)br.Position + (int)br.ReadBits(14) * 8;

                if (GlyphType == GlyphFlags.FONT_PGF_SHADOWGLYPH)
                {
                    br.Position = ShadowOffset;
                    br.SkipBits(14);
                }

                this.Width  = br.ReadBits(7);
                this.Height = br.ReadBits(7);
                this.Left   = br.ReadBitsSigned(7);
                this.Top    = br.ReadBitsSigned(7);
                this.Flags  = (GlyphFlags)br.ReadBits(6);

                if (Flags.HasFlag(GlyphFlags.FONT_PGF_CHARGLYPH))
                {
                    br.SkipBits(7);
                    var shadowId = br.ReadBits(9);
                    br.SkipBits(24);
                    if (!Flags.HasFlag(GlyphFlags.FONT_PGF_METRIC_FLAG1))
                    {
                        br.SkipBits(56);
                    }
                    if (!Flags.HasFlag(GlyphFlags.FONT_PGF_METRIC_FLAG2))
                    {
                        br.SkipBits(56);
                    }
                    if (!Flags.HasFlag(GlyphFlags.FONT_PGF_METRIC_FLAG3))
                    {
                        br.SkipBits(56);
                    }
                    this.AdvanceIndex = br.ReadBits(8);
                }

                this.DataByteOffset = (uint)(br.Position / 8);

                uint PixelIndex           = 0;
                uint NumberOfPixels       = Width * Height;
                bool BitmapHorizontalRows = (Flags & GlyphFlags.FONT_PGF_BMP_OVERLAY) == GlyphFlags.FONT_PGF_BMP_H_ROWS;

                this.Data = new byte[NumberOfPixels];
                int  Count;
                uint Value = 0;
                uint x, y;

                //Console.WriteLine(br.BitsLeft);

                while (PixelIndex < NumberOfPixels)
                {
                    uint Code = br.ReadBits(4);

                    if (Code < 8)
                    {
                        Value = br.ReadBits(4);
                        Count = (int)Code + 1;
                    }
                    else
                    {
                        Count = 16 - (int)Code;
                    }

                    for (int n = 0; (n < Count) && (PixelIndex < NumberOfPixels); n++)
                    {
                        if (Code >= 8)
                        {
                            Value = br.ReadBits(4);
                        }

                        if (BitmapHorizontalRows)
                        {
                            x = PixelIndex % Width;
                            y = PixelIndex / Width;
                        }
                        else
                        {
                            x = PixelIndex / Height;
                            y = PixelIndex % Height;
                        }

                        this.Data[x + y * Width] = (byte)((Value << 0) | (Value << 4));
                        PixelIndex++;
                    }
                }

                /*
                 * for (int y = 0, n = 0; y < Height; y++)
                 * {
                 *      for (int x = 0; x < Width; x++, n++)
                 *      {
                 *              Console.Write("{0:X1}", this.Data[n] & 0xF);
                 *              //String.Format
                 *      }
                 *      Console.WriteLine("");
                 * }
                 *
                 */
                //Console.WriteLine(this);

                return(this);
            }
Esempio n. 5
0
 public static uint ReadBitsAt(byte[] Data, int Offset, int Count)
 {
     var BitReader = new BitReader(Data);
     BitReader.Position = Offset;
     return BitReader.ReadBits(Count);
 }