Skip to content

Instantly share code, notes, and snippets.

@TheVeryStarlk
Last active May 7, 2024 19:07
Show Gist options
  • Save TheVeryStarlk/388cbc4fbfd603ffe4d29156da68de2d to your computer and use it in GitHub Desktop.
Save TheVeryStarlk/388cbc4fbfd603ffe4d29156da68de2d to your computer and use it in GitHub Desktop.
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
var bytes = File.ReadAllBytes("r.0.0.mca")[8192..];
var colors = new List<Rgba32>();
for (var index = 0; index < bytes.Length;)
{
if (index + 15 > bytes.Length)
{
break;
}
var slice = bytes[index..(index += 15)];
colors
.AddRange(slice
.Chunk(3)
.Select(chunk => new Rgba32(chunk[0], chunk[1], chunk[2])));
}
var chunks = colors.Chunk(256);
var count = 0;
foreach (var chunk in chunks)
{
using var image = new Image<Rgba32>(16, 16, Rgba32.ParseHex("#000000"));
var horizontal = 0;
var vertical = 0;
foreach (var color in chunk)
{
if (horizontal == 16)
{
horizontal = 0;
vertical++;
}
image[horizontal++, vertical] = color;
}
image.SaveAsPng($"Frames/{count++}.png");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment