1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2026-01-01 10:13:30 +00:00

Blur effect - Some minor optimizations

Profile editor - Properly update effects on render
This commit is contained in:
SpoinkyNL 2020-06-16 20:28:05 +02:00
parent 8eed347de5
commit 34bcd22f8c
5 changed files with 33 additions and 9 deletions

View File

@ -287,6 +287,7 @@ namespace Artemis.Core.Models.Profile
using (var paint = new SKPaint()) using (var paint = new SKPaint())
{ {
paint.FilterQuality = SKFilterQuality.Low;
paint.BlendMode = General.BlendMode.CurrentValue; paint.BlendMode = General.BlendMode.CurrentValue;
paint.Color = new SKColor(0, 0, 0, (byte) (Transform.Opacity.CurrentValue * 2.55f)); paint.Color = new SKColor(0, 0, 0, (byte) (Transform.Opacity.CurrentValue * 2.55f));

View File

@ -102,6 +102,8 @@ namespace Artemis.UI.Shared.Services
{ {
layer.OverrideProgress(CurrentTime); layer.OverrideProgress(CurrentTime);
layer.LayerBrush?.Update(delta.TotalSeconds); layer.LayerBrush?.Update(delta.TotalSeconds);
foreach (var baseLayerEffect in layer.LayerEffects)
baseLayerEffect.Update(delta.TotalSeconds);
} }
_lastUpdateTime = CurrentTime; _lastUpdateTime = CurrentTime;

View File

@ -40,8 +40,8 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<materialDesign:PackIcon Kind="{Binding Icon}" Width="20" Height="20" VerticalAlignment="Center" /> <materialDesign:PackIcon Kind="{Binding Icon}" Width="20" Height="20" VerticalAlignment="Center" />
<StackPanel Margin="8 0 0 0" Grid.Column="1" VerticalAlignment="Stretch"> <StackPanel Margin="8 0 0 0" Grid.Column="1" VerticalAlignment="Stretch">
<TextBlock FontWeight="Bold" Text="{Binding DisplayName}" /> <TextBlock FontWeight="Bold" Text="{Binding DisplayName}" TextWrapping="Wrap" />
<TextBlock Text="{Binding Description}" /> <TextBlock Text="{Binding Description}" TextWrapping="Wrap" />
</StackPanel> </StackPanel>
</Grid> </Grid>
</Border> </Border>

View File

@ -1,10 +1,15 @@
using Artemis.Core.Plugins.LayerEffect.Abstract; using System;
using Artemis.Core.Plugins.LayerEffect.Abstract;
using SkiaSharp; using SkiaSharp;
namespace Artemis.Plugins.LayerEffects.Filter namespace Artemis.Plugins.LayerEffects.Filter
{ {
public class BlurEffect : LayerEffect<BlurEffectProperties> public class BlurEffect : LayerEffect<BlurEffectProperties>
{ {
private double _lastWidth;
private double _lastHeight;
private SKImageFilter _imageFilter;
public override void EnableLayerEffect() public override void EnableLayerEffect()
{ {
} }
@ -15,15 +20,27 @@ namespace Artemis.Plugins.LayerEffects.Filter
public override void Update(double deltaTime) public override void Update(double deltaTime)
{ {
if (Math.Abs(Properties.BlurAmount.CurrentValue.Width - _lastWidth) > 0.01 || Math.Abs(Properties.BlurAmount.CurrentValue.Height - _lastHeight) > 0.01)
{
if (Properties.BlurAmount.CurrentValue.Width <= 0 && Properties.BlurAmount.CurrentValue.Height <= 0)
_imageFilter = null;
else
{
_imageFilter = SKImageFilter.CreateBlur(
Properties.BlurAmount.CurrentValue.Width,
Properties.BlurAmount.CurrentValue.Height
);
}
_lastWidth = Properties.BlurAmount.CurrentValue.Width;
_lastHeight = Properties.BlurAmount.CurrentValue.Height;
}
} }
public override void PreProcess(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint) public override void PreProcess(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint)
{ {
paint.ImageFilter = SKImageFilter.CreateBlur( if (_imageFilter != null)
Properties.BlurAmount.CurrentValue.Width, paint.ImageFilter = SKImageFilter.CreateMerge(paint.ImageFilter, _imageFilter);
Properties.BlurAmount.CurrentValue.Height,
paint.ImageFilter
);
} }
public override void PostProcess(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint) public override void PostProcess(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint)

View File

@ -6,7 +6,11 @@ namespace Artemis.Plugins.LayerEffects.Filter
{ {
public override void EnablePlugin() public override void EnablePlugin()
{ {
AddLayerEffectDescriptor<BlurEffect>("Blur", "A layer effect providing a blur filter effect", "BlurOn"); AddLayerEffectDescriptor<BlurEffect>(
"Blur",
"A layer effect providing a blur filter effect. \r\nNote: CPU intensive, best to only use on small layers or for a short period of time.",
"BlurOn"
);
AddLayerEffectDescriptor<DilateEffect>("Dilate", "A layer effect providing a dilation filter effect", "EyePlus"); AddLayerEffectDescriptor<DilateEffect>("Dilate", "A layer effect providing a dilation filter effect", "EyePlus");
AddLayerEffectDescriptor<ErodeEffect>("Erode", "A layer effect providing an erode filter effect", "EyeMinus"); AddLayerEffectDescriptor<ErodeEffect>("Erode", "A layer effect providing an erode filter effect", "EyeMinus");
AddLayerEffectDescriptor<GlowEffect>("Glow", "A layer effect providing a glow filter effect", "BoxShadow"); AddLayerEffectDescriptor<GlowEffect>("Glow", "A layer effect providing a glow filter effect", "BoxShadow");