public void Animate(IEnumerable<Frame> frames) { var palette = new Palette(frames); var encodedFrames = frames.Select(f => new { Data = f.Encode(palette), Duration = f.Duration }); int size = palette.Data.Length + encodedFrames.Sum(f => f.Data.Length); Console.WriteLine("Uploading animation of {0} frame(s) ({1} bytes)", frames.Count(), size); WriteNewAnimation(); WritePalette(palette); foreach (var frame in encodedFrames) { WriteNewFrame(frame.Duration); WriteFrameData(frame.Data); } WriteStartAnimation(); }
public byte[] Encode(Palette palette) { return RLE(palette.EncodeFrame(this)); }
private void WritePalette(Palette palette) { int offset = 0; while (offset < palette.Data.Length) { byte todo = (byte)Math.Min(30, palette.Data.Length - offset); byte[] buffer = new byte[todo + 1]; buffer[0] = CMD_APPEND_PALETTE; Array.Copy(palette.Data, offset, buffer, 1, todo); offset += todo; Write (buffer); } }