feat : put back the original logic, the streaming mechanism didn't produce a result as expected

This commit is contained in:
gelaws-hub 2025-08-01 21:11:23 +07:00
parent 8b033d0725
commit dd9f0d9cbe
3 changed files with 9 additions and 164 deletions

View file

@ -1,6 +1,4 @@
using StitcherApi.Models;
using StitcherApi.Services.Fast;
using StitcherApi.Services.Streaming;
using StitcherApi.Services.Utilities;
namespace StitcherApi.Services;
@ -8,56 +6,29 @@ namespace StitcherApi.Services;
public class ImageService : IImageService
{
private readonly ILogger<ImageService> _logger;
private readonly FastProcessor _fastProcessor;
private readonly StreamingProcessor _streamingProcessor;
private const double ASPECT_RATIO_THRESHOLD_TALL = 0.25;
private const double ASPECT_RATIO_THRESHOLD_WIDE = 8.0;
private const int TILE_COUNT_THRESHOLD = 30;
private readonly StitchProcessor _stitchProcessor;
public ImageService(IConfiguration config, ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<ImageService>();
string assetPath =
config["AssetPath"] ?? throw new InvalidOperationException("AssetPath not configured.");
_fastProcessor = new FastProcessor(assetPath, loggerFactory.CreateLogger<FastProcessor>());
_streamingProcessor = new StreamingProcessor(
_stitchProcessor = new StitchProcessor(
assetPath,
loggerFactory.CreateLogger<StreamingProcessor>()
loggerFactory.CreateLogger<StitchProcessor>()
);
}
public async Task<byte[]> GenerateImageAsync(GenerateImageRequest request)
{
_logger.LogInformation("Processing request with the fast processor...");
(int minRow, int minCol, int maxRow, int maxCol) = CoordinateParser.ParseCanvasRect(
request.CanvasRect
);
int tileGridWidth = maxCol - minCol + 1;
int tileGridHeight = maxRow - minRow + 1;
int totalTiles = tileGridWidth * tileGridHeight;
StitchRequest stitchRequest = CreateStitchRequest(request, minRow, minCol, maxRow, maxCol);
double aspectRatio = (tileGridHeight > 0) ? (double)tileGridWidth / tileGridHeight : 0;
if (
totalTiles > TILE_COUNT_THRESHOLD
|| aspectRatio > ASPECT_RATIO_THRESHOLD_WIDE
|| (aspectRatio > 0 && aspectRatio < ASPECT_RATIO_THRESHOLD_TALL)
)
{
_logger.LogInformation("Large, Tall, or Wide canvas detected. Using fast processor.");
return await _fastProcessor.ProcessAsync(stitchRequest);
}
else
{
_logger.LogInformation(
"Small, block-shaped canvas detected. Using robust streaming processor."
);
return await _streamingProcessor.ProcessAsync(stitchRequest);
}
return await _stitchProcessor.ProcessAsync(stitchRequest);
}
private StitchRequest CreateStitchRequest(