release
This commit is contained in:
parent
49b6f3810d
commit
52e830b459
23 changed files with 923 additions and 171 deletions
73
Program.cs
73
Program.cs
|
|
@ -1,68 +1,19 @@
|
|||
using lilo_stitcher_console;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
namespace LiloStitcher;
|
||||
// Add services to the container.
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
// builder.Services.AddOpenApi();
|
||||
|
||||
public static class Program
|
||||
{
|
||||
public static async Task<int> Main( string[] args )
|
||||
{
|
||||
try
|
||||
{
|
||||
NetVips.NetVips.Init();
|
||||
NetVips.NetVips.Concurrency = 3;
|
||||
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
var begin = sw.ElapsedMilliseconds;
|
||||
var opt = new Options
|
||||
{
|
||||
CanvasRect = "A1:AE55",
|
||||
CropOffset = new[] { 0.4, 0.4 },
|
||||
CropSize = new[] { 0.8, 0.8 },
|
||||
OutputScale = 0.5,
|
||||
OutputPath = "stitched.png"
|
||||
};
|
||||
builder.Services.AddControllers().AddJsonOptions(options => options.JsonSerializerOptions.PropertyNameCaseInsensitive = true);
|
||||
|
||||
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));
|
||||
builder.Services.AddMemoryCache(o => o.SizeLimit = 256 * 1024 * 1024);
|
||||
|
||||
using var memCache = new MemoryCache(new MemoryCacheOptions { SizeLimit = 128L * 1024 * 1024 });
|
||||
var tileCache = new TileCache(memCache);
|
||||
var loader = new TileLoader(tileCache, assetDir);
|
||||
var stitcher = new lilo_stitcher_console.LiloStitcher(loader);
|
||||
builder.Services.AddSingleton<LiloStitcher.TileCache>();
|
||||
builder.Services.AddSingleton<LiloStitcher.TileLoader>();
|
||||
builder.Services.AddSingleton<LiloStitcher.LiloStitcher>();
|
||||
|
||||
var req = new GenerateRequest(
|
||||
opt.CanvasRect!,
|
||||
opt.CropOffset!,
|
||||
opt.CropSize!,
|
||||
opt.OutputScale
|
||||
);
|
||||
var app = builder.Build();
|
||||
|
||||
Console.WriteLine("Stitching...");
|
||||
var png = await stitcher.CreateImageAsync(req, CancellationToken.None);
|
||||
File.Move( png, opt.OutputPath!, overwrite: true );
|
||||
|
||||
long bytes = new FileInfo( opt.OutputPath! ).Length;
|
||||
Console.WriteLine($"Done. Wrote {opt.OutputPath} ({bytes / 1024.0:F1} KB)");
|
||||
app.MapControllers();
|
||||
|
||||
Console.WriteLine(sw.ElapsedMilliseconds - begin);
|
||||
|
||||
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; }
|
||||
}
|
||||
}
|
||||
app.Run();
|
||||
Loading…
Add table
Add a link
Reference in a new issue