private void WriteFrameInfo(List <WrittenImageInfo> imageInfos, GafFrameInfo info) { var header = new Structures.GafFrameInfo { Unknown2 = 0, Unknown3 = (uint)info.Unknown3, // Cavedog gafs sometimes have a value here but we don't know what it does. }; if (info.ImageIndex.HasValue) { var imageInfo = imageInfos[info.ImageIndex.Value]; header.LayerCount = 0; header.OriginX = (short)info.OriginX; header.OriginY = (short)info.OriginY; header.Width = (ushort)imageInfo.Width; header.Height = (ushort)imageInfo.Height; header.Compressed = true; header.TransparencyIndex = (byte)imageInfo.TransparencyIndex; header.PtrFrameData = (uint)imageInfo.Pointer; } else { var rect = info.Layers.Select(layer => new Rect { X = -layer.OriginX, Y = -layer.OriginY, Width = imageInfos[layer.ImageIndex].Width, Height = imageInfos[layer.ImageIndex].Height }).Aggregate(Rect.Merge); header.LayerCount = (ushort)info.Layers.Count; header.OriginX = (short)(-rect.X); header.OriginY = (short)(-rect.Y); header.Width = (ushort)rect.Width; header.Height = (ushort)rect.Height; header.Compressed = false; header.TransparencyIndex = 9; header.PtrFrameData = (uint)(writer.BaseStream.Position + 24); } header.Write(writer); if (!info.ImageIndex.HasValue) { var startPos = writer.BaseStream.Position + (4 * info.Layers.Count); for (var i = 0; i < info.Layers.Count; ++i) { writer.Write((uint)(startPos + (24 * i))); } var layerPointers = new List <long>(); foreach (var layer in info.Layers) { WriteLayerInfo(imageInfos, layer); } } }
public static void Read(BinaryReader b, ref GafFrameInfo e) { e.Width = b.ReadUInt16(); e.Height = b.ReadUInt16(); e.OriginX = b.ReadInt16(); e.OriginY = b.ReadInt16(); e.TransparencyIndex = b.ReadByte(); e.Compressed = b.ReadBoolean(); e.LayerCount = b.ReadUInt16(); e.Unknown2 = b.ReadUInt32(); e.PtrFrameData = b.ReadUInt32(); e.Unknown3 = b.ReadUInt32(); }
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(); }
private void WriteLayerInfo(List <WrittenImageInfo> imageInfos, GafLayerInfo info) { var imageInfo = imageInfos[info.ImageIndex]; var header = new Structures.GafFrameInfo { OriginX = (short)info.OriginX, OriginY = (short)info.OriginY, Unknown2 = 0, Unknown3 = (uint)info.Unknown3, // Cavedog gafs sometimes have a value here but we don't know what it does. LayerCount = 0, Width = (ushort)imageInfo.Width, Height = (ushort)imageInfo.Height, Compressed = true, TransparencyIndex = (byte)imageInfo.TransparencyIndex, PtrFrameData = (uint)imageInfo.Pointer, }; header.Write(writer); }
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; }