Esempio n. 1
0
            public DrSprFrame(Stream s, SprHeader sph, SprFrameInfo info)
            {
                Type = SpriteFrameType.Indexed;
                var picindex = info.A * sph.Nrots + info.R;
                var readInt  = new Func <int, int>((off) =>
                {
                    s.Position = off;
                    return(s.ReadInt32());
                });

                var picnr = readInt(HeaderSize + picindex * 4);

                if (picnr >= sph.Npics)
                {
                    throw new Exception("Pic number was greater or equal to number of pics.");
                }

                var picoff     = readInt(sph.OffPicoffs + 8 * picnr);
                var nextpicoff = readInt(sph.OffPicoffs + 8 * (picnr + 1));
                var start      = s.Position;

                s.Position = sph.OffBits + picoff;
                var tempData = s.ReadBytes(nextpicoff - picoff);

                Data = new byte[(sph.Szx + 2) * sph.Szy];

                var pixindex = new Func <int, int, int>((x, y) =>
                {
                    int vr = (y * sph.Szx) + x;
                    return(vr);
                });

                var curr = 0;

                for (var l = 0; l < sph.Szy; ++l)
                {
                    int step = 0, currx = 0, cnt, i;
                    while (currx < sph.Szx)
                    {
                        cnt = tempData[curr++];
                        if ((step & 1) != 0)
                        {
                            cnt &= 0x7f;
                        }
                        if ((step & 1) != 0)
                        {
                            if (!sph.IsShadow)
                            {
                                for (i = 0; i < cnt; ++i, ++curr)
                                {
                                    int newIndex = pixindex(currx + i, l);
                                    Data[newIndex] = tempData[curr];
                                }
                            }
                            else
                            {
                                for (i = 0; i < cnt; ++i)
                                {
                                    int newIndex = pixindex(currx + i, l);
                                    Data[newIndex] = 47;
                                }
                            }
                        }

                        currx += cnt;
                        ++step;
                    }

                    if (currx != sph.Szx)
                    {
                        throw new Exception("Current x was not equal to the line size.");
                    }
                }

                Offset    = new float2(0, 0);
                FrameSize = new Size(sph.Szx, sph.Szy);
                Size      = FrameSize;

                s.Position = start;
            }
Esempio n. 2
0
        DrSprFrame[] ParseFrames(Stream s, out TypeDictionary metadata)
        {
            var start = s.Position;

            metadata = new TypeDictionary();
            var frames = new List <DrSprFrame>();

            for (int sect = 0; sect < header.Nsects; ++sect)
            {
                s.Position = header.OffSections + 16 * sect;
                var firstanim = s.ReadInt32();
                var lastanim  = s.ReadInt32();
                s.ReadInt32();                 // Framerate
                var numhotspots = s.ReadInt32();

                var bmp_szx = header.Szx * header.Nrots;
                var bmp_szy = header.Szy * (lastanim - firstanim + 1);

                var rotOffset = 0;
                if (header.Nrots >= 4)
                {
                    rotOffset = header.Nrots / 4;
                }

                for (var r = 0; r < header.Nrots; ++r)
                {
                    var newR = r + rotOffset;
                    if (newR >= header.Nrots)
                    {
                        newR -= header.Nrots;
                    }

                    for (var a = firstanim; a <= lastanim; ++a)
                    {
                        var sfi = new SprFrameInfo()
                        {
                            A        = a,
                            R        = newR,
                            S        = sect,
                            BmpSzx   = bmp_szx,
                            BmpSzy   = bmp_szy,
                            Lastanim = lastanim
                        };
                        var frame = new DrSprFrame(s, header, sfi);
                        frames.Add(frame);
                    }
                }

                if (numhotspots > 0)
                {
                    int off_hotspots, h;
                    s.Seek(header.OffPicoffs + 8 * header.Npics, SeekOrigin.Begin);
                    off_hotspots = header.OffBits;
                    for (h = 0; h < numhotspots; ++h)
                    {
                        int frameindex = 0;
                        for (int r = 0; r < header.Nrots; ++r)
                        {
                            for (int a = firstanim; a <= lastanim; ++a)
                            {
                                int picindex = a * header.Nrots + r;
                                var read_int = new Func <int, int>((off) =>
                                {
                                    s.Position = off;
                                    return(s.ReadInt32());
                                });

                                int headersize = 32;
                                int picnr      = read_int(headersize + picindex * 4);
                                int hotoff     = read_int(header.OffPicoffs + 8 * picnr + 4);
                                s.Position = off_hotspots + 4 + 3 * (hotoff + h);
                                byte hx = s.ReadUInt8();
                                byte hy = s.ReadUInt8();

                                metadata.Add(new DrFrameMetadata()
                                {
                                    Hotspot    = new int2(hx, hy),
                                    FrameIndex = frameindex
                                });

                                frameindex++;
                            }
                        }
                    }
                }
            }

            s.Position = start;
            return(frames.ToArray());
        }