예제 #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 GifApplicationExtension Read(Stream s)
        {
            GifApplicationExtension ret = new GifApplicationExtension();

            byte[] bb = new byte[20];
            s.Read(bb, 0, 3 + 8 + 3);

            byte b = (byte)s.ReadByte();

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