2025-07-31 06:19:32 +07:00
|
|
|
using System.IO.Pipelines;
|
2025-07-30 07:30:00 +07:00
|
|
|
using StitchATon2.App.Models;
|
|
|
|
|
using StitchATon2.Domain;
|
|
|
|
|
using StitchATon2.Domain.ImageCreators;
|
|
|
|
|
|
|
|
|
|
namespace StitchATon2.App;
|
|
|
|
|
|
|
|
|
|
public static class Utils
|
|
|
|
|
{
|
|
|
|
|
public static GridSection CreateSection(this TileManager manager, GenerateImageDto dto)
|
|
|
|
|
=> manager.CreateSection(
|
|
|
|
|
dto.CanvasRect!,
|
|
|
|
|
dto.CropOffset![0],
|
|
|
|
|
dto.CropOffset![1],
|
|
|
|
|
dto.CropSize![0],
|
|
|
|
|
dto.CropSize![1]);
|
|
|
|
|
|
|
|
|
|
public static async Task WriteToStream(this GridSection section, Stream stream, float? scale)
|
|
|
|
|
{
|
|
|
|
|
var imageCreator = new ImageCreator(section);
|
|
|
|
|
await imageCreator.WriteToStream(stream, scale!.Value);
|
|
|
|
|
}
|
2025-07-31 06:19:32 +07:00
|
|
|
|
2025-07-31 07:40:28 +07:00
|
|
|
public static async Task DangerousWriteToPipe(
|
|
|
|
|
this GridSection section,
|
|
|
|
|
PipeWriter pipeWriter,
|
|
|
|
|
float? scale,
|
|
|
|
|
CancellationToken cancellationToken = default)
|
2025-07-31 06:19:32 +07:00
|
|
|
{
|
|
|
|
|
var imageCreator = new DangerousImageCreator(section);
|
2025-07-31 07:40:28 +07:00
|
|
|
await imageCreator.WriteToPipe(pipeWriter, scale!.Value, cancellationToken);
|
2025-07-31 06:19:32 +07:00
|
|
|
}
|
2025-07-30 07:30:00 +07:00
|
|
|
}
|