90 lines
3.1 KiB
C#
90 lines
3.1 KiB
C#
using Domain.Interfaces;
|
|
using SkiaSharp;
|
|
|
|
namespace Domain.RenderPart;
|
|
|
|
public class BigFrameRender : RenderPartBase
|
|
{
|
|
private readonly uint _bigFrameWidth;
|
|
private readonly uint _bigFrameHeight;
|
|
public BigFrameRender(IEnumerable<ILayer> layers, uint row, uint col, uint bigFrameWidth, uint bigFrameHeight, Guid renderId) :
|
|
base(layers, row, col, renderId)
|
|
{
|
|
_bigFrameWidth = bigFrameWidth;
|
|
_bigFrameHeight = bigFrameHeight;
|
|
}
|
|
|
|
public override async Task<IEnumerable<ExpIniFileGenerator.FrameExpInfo>> Execute(CancellationToken cancellationToken)
|
|
{
|
|
var frameExpInfos = new List<ExpIniFileGenerator.FrameExpInfo>();
|
|
BigFrameLayerRenderResult? previousLayerResult = null;
|
|
// _drawer.SetBackgroundColor((int)y, (int)x, (int)currentFrameHeight, (int)currentFrameWidth, ConsoleColor.DarkBlue);
|
|
|
|
foreach (var layer in _layers.OrderBy(q => q.Order))
|
|
{
|
|
previousLayerResult = await RenderBigFrame(layer, _col, _row, _bigFrameWidth, _bigFrameHeight, previousLayerResult);
|
|
}
|
|
|
|
if (previousLayerResult != null)
|
|
{
|
|
//split bigFrame
|
|
for (uint row = 0; row < _bigFrameHeight; row++)
|
|
{
|
|
for (uint col = 0; col < _bigFrameWidth; col++)
|
|
{
|
|
try
|
|
{
|
|
// Task.Delay(20).Wait();
|
|
var frameInfo = new ExpIniFileGenerator.FrameExpInfo{ Row = row, Column = col };
|
|
// if (!IsImageEmpty(previousLayerResult.Frame[col,row]))
|
|
// {
|
|
// frameInfo.IsContainAnything = true;
|
|
// await SaveImage(previousLayerResult.Frame[col, row], "");
|
|
// }
|
|
frameExpInfos.Add(frameInfo);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return frameExpInfos;
|
|
}
|
|
|
|
private async Task<BigFrameLayerRenderResult> RenderBigFrame(ILayer layer, uint x, uint y, uint bigFrameWidth, uint bigFrameHeight, BigFrameLayerRenderResult? previousLayerResult)
|
|
{
|
|
var automask = previousLayerResult?.Frame ?? new SKBitmap(Convert.ToInt32(bigFrameWidth), Convert.ToInt32(bigFrameHeight));
|
|
var result = new BigFrameLayerRenderResult()
|
|
{
|
|
Frame = new SKBitmap(Convert.ToInt32(bigFrameWidth), Convert.ToInt32(bigFrameHeight)),
|
|
};
|
|
result.Frame = await layer.Render(x, y, bigFrameWidth, bigFrameHeight, automask);
|
|
return result;
|
|
}
|
|
|
|
private bool IsImageEmpty(char image)
|
|
{
|
|
return image is '\0' or ' ';
|
|
}
|
|
|
|
private async Task SaveImage(char image, string destination)
|
|
{
|
|
//destinationn is object
|
|
//
|
|
await Task.Delay(200);
|
|
}
|
|
|
|
protected override Task RenderImage()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
|
|
public override long EstimateMemoryUsage()
|
|
{
|
|
return 10;
|
|
}
|
|
} |