refactor into using ImageSharp
This commit is contained in:
parent
efaaee3b17
commit
db3c833c4c
5 changed files with 125 additions and 111 deletions
46
Program.cs
46
Program.cs
|
|
@ -1,27 +1,31 @@
|
|||
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
namespace LiloStitcher;
|
||||
public static class Program
|
||||
{
|
||||
public static async Task<int> Main( string[] args )
|
||||
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";
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
var begin = sw.ElapsedMilliseconds;
|
||||
var opt = new Options
|
||||
{
|
||||
CanvasRect = "A1:AE55",
|
||||
CropOffset = [0.0, 0.0],
|
||||
CropSize = [1.0, 1.0],
|
||||
OutputScale = 1.0,
|
||||
OutputPath = "stitched.png"
|
||||
};
|
||||
|
||||
string tileFilePath = "../stitch-a-ton/tiles1705";
|
||||
string assetDir = Path.GetFullPath( Path.Combine( Directory.GetCurrentDirectory(), tileFilePath ) );
|
||||
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));
|
||||
|
||||
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 );
|
||||
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!,
|
||||
|
|
@ -30,16 +34,18 @@ public static class Program
|
|||
opt.OutputScale
|
||||
);
|
||||
|
||||
Console.WriteLine( "Stitching..." );
|
||||
var png = await stitcher.CreateImageAsync( req, CancellationToken.None );
|
||||
Console.WriteLine("Stitching...");
|
||||
var pngBytes = await stitcher.CreateImageAsync(req, CancellationToken.None);
|
||||
|
||||
File.WriteAllBytes( opt.OutputPath!, png );
|
||||
Console.WriteLine( $"Done. Wrote {opt.OutputPath} ({png.Length / 1024.0:F1} KB)" );
|
||||
File.WriteAllBytes(opt.OutputPath!, pngBytes);
|
||||
Console.WriteLine($"Done. Wrote {opt.OutputPath} ({pngBytes.Length / 1024.0:F1} KB)");
|
||||
|
||||
Console.WriteLine(begin - sw.ElapsedMilliseconds);
|
||||
return 0;
|
||||
}
|
||||
catch( Exception ex )
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine( "ERROR: " + ex.Message );
|
||||
Console.Error.WriteLine("ERROR: " + ex.Message);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue