示例#1
0
        public static GifContainer Parse(Stream fs)
        {
            GifContainer ret = new GifContainer();

            {
                ret.Header.Read(fs);
                ret.LogicalScreen.Read(fs);
                int findex = 0;
                //lookahead
                while (true)
                {
                    var b = fs.ReadByte();
                    fs.Position--;
                    if (b == 0x3b)
                    {
                        break;
                    }

                    if (b == 0x21)
                    {
                        b = fs.ReadByte();
                        var b2 = fs.ReadByte();
                        fs.Position -= 2;;
                        if (b2 == 0xf9)
                        {
                            ret.Data.Add(GraphicControlExtension.Read(fs));
                        }
                        else
                        if (b2 == 0xff)
                        {
                            ret.Data.Add(GifApplicationExtension.Read(fs));
                        }
                        else
                        if (b2 == 0xfe)
                        {
                            ret.Data.Add(GifCommentBlock.Read(fs));
                        }
                        else
                        {
                            throw new GifParsingException("unknown header: " + b.ToString("X2") + b2.ToString("X2") + ", shift: " + fs.Position);
                        }
                    }
                    else
                    if (b == 0x2c)
                    {
                        var r = GifRenderBlock.Read(fs);
                        ret.Data.Add(r);
                        r.FrameIndex = findex++;
                    }
                    else
                    {
                        throw new GifParsingException("unknown header: " + b.ToString("X2") + ", shift: " + fs.Position);
                    }
                }
            }

            ret.UpdateInfo();
            return(ret);
        }
示例#2
0
        public static GifCommentBlock Read(Stream s)
        {
            GifCommentBlock ret = new GifCommentBlock();

            ret.Shift = s.Position;
            s.ReadByte();
            s.ReadByte();
            var b = s.ReadByte();

            while (b != 0)
            {
                var bb = new byte[b];
                s.Read(bb, 0, b);
                b = s.ReadByte();
            }
            return(ret);
        }