lilo-stitcher/Program.cs

61 lines
2.1 KiB
C#
Raw Permalink Normal View History

2025-07-21 00:08:32 +07:00
using System.Diagnostics;
using Microsoft.Extensions.Caching.Memory;
namespace LiloStitcher;
public static class Program
{
2025-07-21 00:08:32 +07:00
public static async Task<int> Main(string[] args)
{
try
{
2025-07-21 00:08:32 +07:00
Stopwatch sw = Stopwatch.StartNew();
var begin = sw.ElapsedMilliseconds;
var opt = new Options
{
CanvasRect = "A1:AE55",
2025-07-31 12:57:14 +07:00
CropOffset = [0.4, 0.4],
CropSize = [0.8, 0.8],
OutputScale = 0.5,
2025-07-21 00:08:32 +07:00
OutputPath = "stitched.png"
};
2025-07-21 00:08:32 +07:00
string tileFilePath = "../tiles1705"; // should later be directed to the read-only `ASSET_PATH_RO` environment variable
string assetDir = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), tileFilePath));
2025-07-21 00:08:32 +07:00
using var memCache = new MemoryCache(new MemoryCacheOptions { SizeLimit = 256L * 1024 * 1024 });
var tileCache = new TileCache(memCache);
var loader = new TileLoader(tileCache, assetDir);
var stitcher = new LiloStitcher(loader);
var req = new GenerateRequest(
opt.CanvasRect!,
opt.CropOffset!,
opt.CropSize!,
opt.OutputScale
);
2025-07-21 00:08:32 +07:00
Console.WriteLine("Stitching...");
var pngBytes = await stitcher.CreateImageAsync(req, CancellationToken.None);
2025-07-21 00:08:32 +07:00
File.WriteAllBytes(opt.OutputPath!, pngBytes);
Console.WriteLine($"Done. Wrote {opt.OutputPath} ({pngBytes.Length / 1024.0:F1} KB)");
2025-07-31 12:57:14 +07:00
Console.WriteLine(sw.ElapsedMilliseconds - begin);
return 0;
}
2025-07-21 00:08:32 +07:00
catch (Exception ex)
{
2025-07-21 00:08:32 +07:00
Console.Error.WriteLine("ERROR: " + ex.Message);
return 1;
}
}
private struct Options
{
public string? CanvasRect { get; set; }
public double[]? CropOffset { get; set; }
public double[]? CropSize { get; set; }
public double OutputScale { get; set; }
public string? OutputPath { get; set; }
}
}