diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2020-01-01 22:50:08 +0100 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2020-01-01 22:50:08 +0100 |
| commit | 2481d1857b08879a3d15e679a302667c7d8976f7 (patch) | |
| tree | c8ae66b72a3469e65239c94d1d52795fb75700b2 /Models/ImageModel.cs | |
| parent | fbe866f7b26c10bb54d72c029f8c628988a90be2 (diff) | |
| download | avalar-2481d1857b08879a3d15e679a302667c7d8976f7.tar.gz avalar-2481d1857b08879a3d15e679a302667c7d8976f7.tar.bz2 avalar-2481d1857b08879a3d15e679a302667c7d8976f7.zip | |
Adds a working but slightly buggy pipeline implementation.
Diffstat (limited to 'Models/ImageModel.cs')
| -rw-r--r-- | Models/ImageModel.cs | 69 |
1 files changed, 59 insertions, 10 deletions
diff --git a/Models/ImageModel.cs b/Models/ImageModel.cs index e0bb1af..047d2e0 100644 --- a/Models/ImageModel.cs +++ b/Models/ImageModel.cs @@ -1,28 +1,61 @@ using Avalar.Models.Interfaces; +using Avalar.Utils; +using Avalar.Services.Interfaces; using Avalonia.Media.Imaging; using ReactiveUI; using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; namespace Avalar.Models { public class ImageModel : ReactiveObject, IImageModel, ISettingsModel, IDisposable { - + private readonly IResizer m_Resizer; + private readonly IBrightness m_Brightness; + private CancellationTokenSource m_CancellationTokenSource; + private AvalarPipeline m_pipeline; private IBitmap m_OriginalBitmap; - private IBitmap m_LatestResult; + public ImageModel(IServiceProvider serviceProvider) + { + m_Resizer = serviceProvider.GetService<IResizer>(); + m_Brightness = serviceProvider.GetService<IBrightness>(); - private double m_Width; - public double Width { - get => m_Width; - set => this.RaiseAndSetIfChanged(ref m_Width, value); + m_pipeline = new AvalarPipeline(new List<IPipelineStep> + { + m_Resizer.AsPipelineStep(), + m_Brightness.AsPipelineStep() + }); + + m_pipeline.PipelineChanged += OnPipelineChanged; } - private double m_Height; - public double Height + public async Task RunPipeline() { - get => m_Height; - set => this.RaiseAndSetIfChanged(ref m_Height, value); + try + { + LatestResult = await m_pipeline.Run(m_OriginalBitmap, m_CancellationTokenSource.Token).ConfigureAwait(false); + } catch (OperationCanceledException) + { + + } + } + + private async void OnPipelineChanged(object sender, EventArgs e) + { + m_CancellationTokenSource?.Cancel(); + m_CancellationTokenSource = new CancellationTokenSource(); + + await RunPipeline().ConfigureAwait(false); + } + + private IBitmap m_LatestResult; + public IBitmap LatestResult + { + get => m_LatestResult; + set => this.RaiseAndSetIfChanged(ref m_LatestResult, value); } public IBitmap LoadImage(string imagePath) @@ -48,9 +81,25 @@ namespace Avalar.Models { m_OriginalBitmap.Dispose(); m_LatestResult.Dispose(); + m_CancellationTokenSource.Dispose(); } disposed = true; } + + public void SetWidth(uint width) + { + m_Resizer.Width = width; + } + + public void SetHeight(uint height) + { + m_Resizer.Height = height; + } + + public void SetBrightnessDelta(int brightnessDelta) + { + m_Brightness.Brightness = brightnessDelta; + } } } |
