Esempio n. 1
0
        public void Write()
        {
            var entries = source.EnumerateSequences().ToList();

            var header = new Structures.GafHeader
            {
                IdVersion     = 0x00010100,
                SequenceCount = (uint)entries.Count,
                Unknown1      = 0
            };

            header.Write(writer);

            // reserve space for the entry pointers
            var entryPointersPos = writer.BaseStream.Position;

            for (int i = 0; i < entries.Count; ++i)
            {
                writer.Write(0);
            }

            // write all the images
            var writtenImageInfos = new List <WrittenImageInfo>();

            foreach (var imageInfo in source.EnumerateImageInfos())
            {
                var pos = writer.BaseStream.Position;
                CompressedFrameWriter.WriteCompressedImage(new MemoryStream(imageInfo.Data), this.writer, imageInfo.Width, (byte)imageInfo.TransparencyIndex);
                writtenImageInfos.Add(new WrittenImageInfo
                {
                    Width             = imageInfo.Width,
                    Height            = imageInfo.Height,
                    TransparencyIndex = imageInfo.TransparencyIndex,
                    Pointer           = pos
                });
            }


            // write all the sequences
            var entryPointers = new List <long>();

            foreach (var entry in entries)
            {
                entryPointers.Add(writer.BaseStream.Position);
                this.WriteGafEntry(writtenImageInfos, entry);
            }

            // go back and fill in the entry pointers
            var currPos = writer.BaseStream.Position;

            writer.BaseStream.Seek(entryPointersPos, SeekOrigin.Begin);
            foreach (var p in entryPointers)
            {
                writer.Write((uint)p);
            }

            // reset seek pos forward to after the last byte we wrote
            writer.BaseStream.Seek(currPos, SeekOrigin.Begin);
        }
Esempio n. 2
0
        /// <summary>
        /// Reads the GAF data from the input stream.
        /// </summary>
        public void Read()
        {
            // read in header
            Structures.GafHeader header = new Structures.GafHeader();
            Structures.GafHeader.Read(this.reader, ref header);

            this.adapter.BeginRead(header.SequenceCount);

            // read in pointers to entries
            int[] pointers = new int[header.SequenceCount];
            for (int i = 0; i < header.SequenceCount; i++)
            {
                pointers[i] = this.reader.ReadInt32();
            }

            // read in the actual entries themselves
            for (int i = 0; i < header.SequenceCount; i++)
            {
                this.reader.BaseStream.Seek(pointers[i], SeekOrigin.Begin);
                this.ReadGafEntry();
            }

            this.adapter.EndRead();
        }
Esempio n. 3
0
 public static void Read(BinaryReader b, ref GafHeader header)
 {
     header.IdVersion     = b.ReadUInt32();
     header.SequenceCount = b.ReadUInt32();
     header.Unknown1      = b.ReadUInt32();
 }