chore : replaced var with explicit types

This commit is contained in:
gelaws-hub 2025-07-31 20:41:48 +07:00
parent b344b6a03f
commit 64841332e0
4 changed files with 34 additions and 33 deletions

View file

@ -16,36 +16,36 @@ internal class ImageProcessor
public async Task<byte[]> StitchAndCropAsync(StitchRequest stitchRequest)
{
using var finalImage = new Image<Rgba32>(stitchRequest.CropW, stitchRequest.CropH);
using Image<Rgba32> finalImage = new(stitchRequest.CropW, stitchRequest.CropH);
for (var r = stitchRequest.StartTileRow; r <= stitchRequest.EndTileRow; r++)
for (int r = stitchRequest.StartTileRow; r <= stitchRequest.EndTileRow; r++)
{
for (var c = stitchRequest.StartTileCol; c <= stitchRequest.EndTileCol; c++)
for (int c = stitchRequest.StartTileCol; c <= stitchRequest.EndTileCol; c++)
{
var tileFileName = TileHelper.GetTileFileName(r, c);
var tileFilePath = Path.Combine(_assetPath, tileFileName);
string tileFileName = TileHelper.GetTileFileName(r, c);
string tileFilePath = Path.Combine(_assetPath, tileFileName);
if (!File.Exists(tileFilePath))
{
throw new FileNotFoundException($"Asset not found: {tileFileName}");
}
using var tileImage = await Image.LoadAsync(tileFilePath);
using Image tileImage = await Image.LoadAsync(tileFilePath);
var tileOriginX = (c - stitchRequest.MinCol) * TILE_SIZE;
var tileOriginY = (r - stitchRequest.MinRow) * TILE_SIZE;
int tileOriginX = (c - stitchRequest.MinCol) * TILE_SIZE;
int tileOriginY = (r - stitchRequest.MinRow) * TILE_SIZE;
var srcX = Math.Max(0, stitchRequest.CropX - tileOriginX);
var srcY = Math.Max(0, stitchRequest.CropY - tileOriginY);
var destX = Math.Max(0, tileOriginX - stitchRequest.CropX);
var destY = Math.Max(0, tileOriginY - stitchRequest.CropY);
int srcX = Math.Max(0, stitchRequest.CropX - tileOriginX);
int srcY = Math.Max(0, stitchRequest.CropY - tileOriginY);
int destX = Math.Max(0, tileOriginX - stitchRequest.CropX);
int destY = Math.Max(0, tileOriginY - stitchRequest.CropY);
var overlapW = Math.Max(
int overlapW = Math.Max(
0,
Math.Min(stitchRequest.CropX + stitchRequest.CropW, tileOriginX + TILE_SIZE)
- Math.Max(stitchRequest.CropX, tileOriginX)
);
var overlapH = Math.Max(
int overlapH = Math.Max(
0,
Math.Min(stitchRequest.CropY + stitchRequest.CropH, tileOriginY + TILE_SIZE)
- Math.Max(stitchRequest.CropY, tileOriginY)
@ -53,7 +53,7 @@ internal class ImageProcessor
if (overlapW > 0 && overlapH > 0)
{
var sourceRect = new Rectangle(srcX, srcY, overlapW, overlapH);
Rectangle sourceRect = new Rectangle(srcX, srcY, overlapW, overlapH);
finalImage.Mutate(ctx =>
ctx.DrawImage(
tileImage,
@ -68,12 +68,12 @@ internal class ImageProcessor
if (stitchRequest.OutputScale > 0 && stitchRequest.OutputScale < 1.0)
{
var newWidth = (int)(stitchRequest.CropW * stitchRequest.OutputScale);
var newHeight = (int)(stitchRequest.CropH * stitchRequest.OutputScale);
int newWidth = (int)(stitchRequest.CropW * stitchRequest.OutputScale);
int newHeight = (int)(stitchRequest.CropH * stitchRequest.OutputScale);
finalImage.Mutate(x => x.Resize(newWidth, newHeight, KnownResamplers.Bicubic));
}
using var memoryStream = new MemoryStream();
using MemoryStream memoryStream = new MemoryStream();
await finalImage.SaveAsPngAsync(memoryStream);
return memoryStream.ToArray();
}