private void WriteGafEntry(List <WrittenImageInfo> imageInfos, GafEntryInfo entryInfo) { var header = new Structures.GafSequenceHeader { FrameCount = (ushort)entryInfo.FrameInfos.Count, Unknown1 = 1, Unknown2 = 0, Name = entryInfo.Name }; header.Write(writer); // reserve space for frame pointers var framePointersPosition = writer.BaseStream.Position; foreach (var _ in entryInfo.FrameInfos) { var entry = new Structures.GaFrameListItem { PtrFrameInfo = 0, Duration = 0, }; entry.Write(writer); } // write frames var pointers = new List <long>(); foreach (var frameInfo in entryInfo.FrameInfos) { pointers.Add(writer.BaseStream.Position); WriteFrameInfo(imageInfos, frameInfo); } // go back and write frame pointers var currPos = writer.BaseStream.Position; writer.BaseStream.Seek(framePointersPosition, SeekOrigin.Begin); // write pointers for (var i = 0; i < entryInfo.FrameInfos.Count; ++i) { var entry = new Structures.GaFrameListItem { PtrFrameInfo = (uint)pointers[i], Duration = (uint)entryInfo.FrameInfos[i].Duration, }; entry.Write(writer); } // reset to end writer.BaseStream.Seek(currPos, SeekOrigin.Begin); }
private void LoadFrame(ref Structures.GaFrameListItem entry) { // read in the frame data table Structures.GafFrameInfo d = new Structures.GafFrameInfo(); Structures.GafFrameInfo.Read(this.reader, ref d); this.adapter.BeginFrame(ref entry, ref d); // read the actual frame image this.reader.BaseStream.Seek(d.PtrFrameData, SeekOrigin.Begin); if (d.LayerCount > 0) { // read in the pointers uint[] framePointers = new uint[d.LayerCount]; for (int i = 0; i < d.LayerCount; i++) { framePointers[i] = this.reader.ReadUInt32(); } // read in each frame for (int i = 0; i < d.LayerCount; i++) { this.reader.BaseStream.Seek(framePointers[i], SeekOrigin.Begin); var dummyEntry = new Structures.GaFrameListItem { PtrFrameInfo = 0, Duration = 0 }; this.LoadFrame(ref dummyEntry); } } else { byte[] data; if (d.Compressed) { data = CompressedFrameReader.ReadCompressedImage(this.reader, d.Width, d.Height, d.TransparencyIndex); } else { data = this.ReadUncompressedImage(d.Width, d.Height); } this.adapter.SetFrameData(data); } this.adapter.EndFrame(); }
public void BeginFrame(ref Gaf.Structures.GaFrameListItem entry, ref Gaf.Structures.GafFrameInfo data) { if (frameDepth > 0) { this.currentLayerInfo = data; var layerJson = new GafLayerJson { OriginX = data.OriginX, OriginY = data.OriginY, TransparencyIndex = data.TransparencyIndex, Unknown3 = data.Unknown3, }; entries.Last().Frames.Last().Layers.Add(layerJson); } else { this.currentFrameInfo = data; var frameJson = new GafFrameJson { Duration = entry.Duration, Unknown3 = data.Unknown3, }; if (data.LayerCount > 0) { frameJson.Layers = new List <GafLayerJson>(); } else { frameJson.OriginX = data.OriginX; frameJson.OriginY = data.OriginY; frameJson.TransparencyIndex = data.TransparencyIndex; } entries.Last().Frames.Add(frameJson); } frameDepth += 1; }
private void ReadGafEntry() { // read the entry header Structures.GafSequenceHeader entry = new Structures.GafSequenceHeader(); Structures.GafSequenceHeader.Read(this.reader, ref entry); this.adapter.BeginEntry(ref entry); // read in all the frame entry pointers Structures.GaFrameListItem[] frameEntries = new Structures.GaFrameListItem[entry.FrameCount]; for (int i = 0; i < entry.FrameCount; i++) { Structures.GaFrameListItem.Read(this.reader, ref frameEntries[i]); } // read in the corresponding frames for (int i = 0; i < entry.FrameCount; i++) { this.reader.BaseStream.Seek(frameEntries[i].PtrFrameInfo, SeekOrigin.Begin); this.LoadFrame(ref frameEntries[i]); } this.adapter.EndEntry(); }
public static void Read(BinaryReader b, ref GaFrameListItem e) { e.PtrFrameInfo = b.ReadUInt32(); e.Duration = b.ReadUInt32(); }