55 lines
No EOL
1.8 KiB
C#
55 lines
No EOL
1.8 KiB
C#
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
|
|
namespace LiloStitcher;
|
|
public static class Program
|
|
{
|
|
public static async Task<int> Main( string[] args )
|
|
{
|
|
try
|
|
{
|
|
var opt = new Options();
|
|
opt.CanvasRect = "A1:H12";
|
|
opt.CropOffset = [0.25, 0.25];
|
|
opt.CropSize = [0.75, 0.75];
|
|
opt.OutputScale = 0.5;
|
|
opt.OutputPath = "stitched.png";
|
|
|
|
string tileFilePath = "../stitch-a-ton/tiles1705";
|
|
string assetDir = Path.GetFullPath( Path.Combine( Directory.GetCurrentDirectory(), tileFilePath ) );
|
|
|
|
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
|
|
);
|
|
|
|
Console.WriteLine( "Stitching..." );
|
|
var png = await stitcher.CreateImageAsync( req, CancellationToken.None );
|
|
|
|
File.WriteAllBytes( opt.OutputPath!, png );
|
|
Console.WriteLine( $"Done. Wrote {opt.OutputPath} ({png.Length / 1024.0:F1} KB)" );
|
|
return 0;
|
|
}
|
|
catch( Exception ex )
|
|
{
|
|
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; }
|
|
}
|
|
} |