Пример #1
0
        static internal GIFTag ExtractGifTag(byte[] data, GSTransferPath path)
        {
            GIFTag t = new GIFTag();
            t.size = data.Length;
            t.path = path;
            t.TAG = BitConverter.ToUInt64(data, 0);
            t.REGS = BitConverter.ToUInt64(data, 8);

            t.Q = 1f;
            t.nloop = (uint)GetBit(t.TAG, 0, 15);
            t.eop = (uint)GetBit(t.TAG, 15, 1);
            t.pre = (uint)GetBit(t.TAG, 46, 1);
            t.prim = GIFPrim.ExtractGIFPrim((uint)GetBit(t.TAG, 47, 11));
            t.flg = (GIFFLG)GetBit(t.TAG, 58, 2);
            t.nreg = (uint)GetBit(t.TAG, 60, 4);
            if (t.nreg == 0)
                t.nreg = 16;

            byte[] registers = new byte[t.nreg];
            Unpack[] regsunpack = new Unpack[t.nreg];

            t.regs = new List<IGifData>();
            for (byte i = 0; i < t.nreg; i++)
            {
                byte reg = (byte)GetBit(t.REGS, i * 4, 4);
                registers[i] = reg;
                regsunpack[i] = GetUnpack(reg);
            }

            int p = 16;
            switch (t.flg)
            {
                case GIFFLG.GIF_FLG_PACKED:
                    for (int j = 0; j < t.nloop; j++)
                        for (int i = 0; i < t.nreg; i++)
                        {
                            UInt64 LowData = BitConverter.ToUInt64(data, p);
                            UInt64 HighData = BitConverter.ToUInt64(data, p + 8);
                            t.regs.Add(regsunpack[i](t, registers[i], LowData, HighData, true));
                            p += 16;
                        }
                    break;
                case GIFFLG.GIF_FLG_REGLIST:
                    for (int j = 0; j < t.nloop; j++)
                        for (int i = 0; i < t.nreg; i++)
                        {
                            UInt64 Data = BitConverter.ToUInt64(data, p);
                            t.regs.Add(regsunpack[i](t, registers[i], Data, 0, false));
                            p += 8;
                        }
                    break;
                case GIFFLG.GIF_FLG_IMAGE:
                case GIFFLG.GIF_FLG_IMAGE2:
                    GifImage image = new GifImage();
                    image.Data = new byte[t.nloop * 16];
                    try
                    {
                        Array.Copy(data, 16, image.Data, 0, t.nloop * 16);
                    }
                    catch (ArgumentException) { }
                    t.regs.Add(image);
                    break;
                default:
                    break;
            }
            return t;
        }
Пример #2
0
        static internal GIFTag ExtractGifTag(byte[] data,GSTransferPath path)
        {
            GIFTag t = new GIFTag();

            t.size = data.Length;
            t.path = path;
            t.TAG  = BitConverter.ToUInt64(data,0);
            t.REGS = BitConverter.ToUInt64(data,8);

            t.Q     = 1f;
            t.nloop = (uint)GetBit(t.TAG,0,15);
            t.eop   = (uint)GetBit(t.TAG,15,1);
            t.pre   = (uint)GetBit(t.TAG,46,1);
            t.prim  = GIFPrim.ExtractGIFPrim((uint)GetBit(t.TAG,47,11));
            t.flg   = (GIFFLG)GetBit(t.TAG,58,2);
            t.nreg  = (uint)GetBit(t.TAG,60,4);
            if (t.nreg == 0)
            {
                t.nreg = 16;
            }

            byte[]   registers  = new byte[t.nreg];
            Unpack[] regsunpack = new Unpack[t.nreg];

            t.regs = new List <IGifData>();
            for (byte i = 0; i < t.nreg; i++)
            {
                byte reg = (byte)GetBit(t.REGS,i * 4,4);
                registers[i]  = reg;
                regsunpack[i] = GetUnpack(reg);
            }

            int p = 16;

            switch (t.flg)
            {
            case GIFFLG.GIF_FLG_PACKED:
                for (int j = 0; j < t.nloop; j++)
                {
                    for (int i = 0; i < t.nreg; i++)
                    {
                        UInt64 LowData  = BitConverter.ToUInt64(data,p);
                        UInt64 HighData = BitConverter.ToUInt64(data,p + 8);
                        t.regs.Add(regsunpack[i](t,registers[i],LowData,HighData,true));
                        p += 16;
                    }
                }
                break;

            case GIFFLG.GIF_FLG_REGLIST:
                for (int j = 0; j < t.nloop; j++)
                {
                    for (int i = 0; i < t.nreg; i++)
                    {
                        UInt64 Data = BitConverter.ToUInt64(data,p);
                        t.regs.Add(regsunpack[i](t,registers[i],Data,0,false));
                        p += 8;
                    }
                }
                break;

            case GIFFLG.GIF_FLG_IMAGE:
            case GIFFLG.GIF_FLG_IMAGE2:
                GifImage image = new GifImage();
                image.Data = new byte[t.nloop * 16];
                try
                {
                    Array.Copy(data,16,image.Data,0,t.nloop * 16);
                }
                catch (ArgumentException) { }
                t.regs.Add(image);
                break;

            default:
                break;
            }
            return(t);
        }