Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support writing screenshots to animated GIFs #18

Merged
merged 1 commit into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion CommandLine/Commands/ScreenshotCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ static bool WriteScreenToDisk(string fileName, ArraySegment<byte> memory, Screen
bitmap.Save(newFileName, ImageFormat.Png);
}

if (settings.Scr || !settings.Png)
if (settings.Gif)
{
var newFileName = Path.Combine(settings.OutputFolder, Path.ChangeExtension(Path.GetFileName(fileName), "gif"));
Out.Write($" Dumping {fileName} @ {address} to {newFileName}");
using var animatedGif = AnimatedGif.AnimatedGif.Create(newFileName, 320); // 25 fps
using var frameOne = SpectrumDisplay.GetBitmap(memory.ToArray(), address, false);
animatedGif.AddFrame(frameOne, quality: AnimatedGif.GifQuality.Bit8);
using var frameTwo = SpectrumDisplay.GetBitmap(memory.ToArray(), address, true);
animatedGif.AddFrame(frameTwo, quality: AnimatedGif.GifQuality.Bit8);
}

// Write SCR if specified OR if nothing specified (so it is the default)
if (settings.Scr |(!settings.Png && !settings.Gif))
{
var newFileName = Path.Combine(settings.OutputFolder, Path.ChangeExtension(Path.GetFileName(fileName), "scr"));
Out.Write($" Dumping {fileName} @ {address} to {newFileName}");
Expand Down
4 changes: 4 additions & 0 deletions CommandLine/Commands/Settings/ScreenshotSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public class ScreenshotSettings : RequiredSettings
[Description("Write a .scr version of the screenshot (default).")]
public bool Scr { get; set; }

[CommandOption("--gif")]
[Description("Write an animated .gif of the screenshot.")]
public bool Gif { get; set; }

[CommandOption("--flashed")]
[Description("Write png with the alternate flashed attribute state.")]
public bool Flashed { get; set; }
Expand Down
1 change: 1 addition & 0 deletions Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AnimatedGif" Version="1.0.5" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="5.0.0" />
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
Expand Down