change using NetVips to reduce memory load
This commit is contained in:
parent
661c4b955c
commit
49b6f3810d
5 changed files with 210 additions and 220 deletions
99
Program.cs
99
Program.cs
|
|
@ -1,61 +1,68 @@
|
|||
using System.Diagnostics;
|
||||
using lilo_stitcher_console;
|
||||
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
|
||||
{
|
||||
try
|
||||
{
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
var begin = sw.ElapsedMilliseconds;
|
||||
var opt = new Options
|
||||
{
|
||||
CanvasRect = "A1:AE55",
|
||||
CropOffset = [0.4, 0.4],
|
||||
CropSize = [0.8, 0.8],
|
||||
OutputScale = 0.5,
|
||||
OutputPath = "stitched.png"
|
||||
};
|
||||
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"
|
||||
};
|
||||
|
||||
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));
|
||||
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 = 128L * 1024 * 1024 });
|
||||
var tileCache = new TileCache(memCache);
|
||||
var loader = new TileLoader(tileCache, assetDir);
|
||||
var stitcher = new lilo_stitcher_console.LiloStitcher(loader);
|
||||
|
||||
var req = new GenerateRequest(
|
||||
opt.CanvasRect!,
|
||||
opt.CropOffset!,
|
||||
opt.CropSize!,
|
||||
opt.OutputScale
|
||||
);
|
||||
var req = new GenerateRequest(
|
||||
opt.CanvasRect!,
|
||||
opt.CropOffset!,
|
||||
opt.CropSize!,
|
||||
opt.OutputScale
|
||||
);
|
||||
|
||||
Console.WriteLine("Stitching...");
|
||||
var pngBytes = await stitcher.CreateImageAsync(req, CancellationToken.None);
|
||||
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)");
|
||||
|
||||
File.WriteAllBytes(opt.OutputPath!, pngBytes);
|
||||
Console.WriteLine($"Done. Wrote {opt.OutputPath} ({pngBytes.Length / 1024.0:F1} KB)");
|
||||
|
||||
Console.WriteLine(sw.ElapsedMilliseconds - begin);
|
||||
return 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine("ERROR: " + ex.Message);
|
||||
return 1;
|
||||
}
|
||||
Console.WriteLine(sw.ElapsedMilliseconds - begin);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private struct Options
|
||||
catch( Exception ex )
|
||||
{
|
||||
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; }
|
||||
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; }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue