mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Layers - Allow the clip render mode to stretch if really needed
Core - Include the canvas' SKImageInfo in render calls
This commit is contained in:
1 parent
1853f87c61
commit
1a0d5dafd1
13 files changed
+107
-64
No files matched your search
@@ -2,6 +2,7 @@
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Profile.LayerProperties;
|
||||
using Artemis.Core.Plugins.LayerBrush;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Plugins.LayerBrushes.Noise.Utilities;
|
||||
using SkiaSharp;
|
||||
|
||||
@@ -10,16 +11,23 @@ namespace Artemis.Plugins.LayerBrushes.Noise
|
||||
public class NoiseBrush : LayerBrush
|
||||
{
|
||||
private static readonly Random Rand = new Random();
|
||||
private readonly OpenSimplexNoise _noise;
|
||||
private readonly IRgbService _rgbService;
|
||||
private SKBitmap _bitmap;
|
||||
|
||||
private float _renderScale;
|
||||
private readonly OpenSimplexNoise _noise;
|
||||
private float _x;
|
||||
private float _y;
|
||||
private float _z;
|
||||
private SKBitmap _bitmap;
|
||||
|
||||
public NoiseBrush(Layer layer, LayerBrushDescriptor descriptor) : base(layer, descriptor)
|
||||
public NoiseBrush(Layer layer, LayerBrushDescriptor descriptor, IRgbService rgbService) : base(layer, descriptor)
|
||||
{
|
||||
_rgbService = rgbService;
|
||||
_x = Rand.Next(0, 4096);
|
||||
_y = Rand.Next(0, 4096);
|
||||
_z = Rand.Next(0, 4096);
|
||||
_noise = new OpenSimplexNoise(Rand.Next(0, 4096));
|
||||
|
||||
MainColorProperty = RegisterLayerProperty<SKColor>("Brush.MainColor", "Main color", "The main color of the noise.");
|
||||
SecondaryColorProperty = RegisterLayerProperty<SKColor>("Brush.SecondaryColor", "Secondary color", "The secondary color of the noise.");
|
||||
ScaleProperty = RegisterLayerProperty<SKSize>("Brush.Scale", "Scale", "The scale of the noise.");
|
||||
@@ -27,10 +35,7 @@ namespace Artemis.Plugins.LayerBrushes.Noise
|
||||
AnimationSpeedProperty = RegisterLayerProperty<float>("Brush.AnimationSpeed", "Animation speed", "The speed at which the noise moves.");
|
||||
ScaleProperty.InputAffix = "%";
|
||||
|
||||
_x = Rand.Next(0, 4096);
|
||||
_y = Rand.Next(0, 4096);
|
||||
_z = Rand.Next(0, 4096);
|
||||
_noise = new OpenSimplexNoise(Rand.Next(0, 4096));
|
||||
DetermineRenderScale();
|
||||
}
|
||||
|
||||
public LayerProperty<SKColor> MainColorProperty { get; set; }
|
||||
@@ -52,28 +57,35 @@ namespace Artemis.Plugins.LayerBrushes.Noise
|
||||
_y = 0;
|
||||
if (float.IsPositiveInfinity(_z) || float.IsNegativeInfinity(_z) || float.IsNaN(_z))
|
||||
_z = 0;
|
||||
|
||||
DetermineRenderScale();
|
||||
base.Update(deltaTime);
|
||||
}
|
||||
|
||||
public override void Render(SKCanvas canvas, SKPath path, SKPaint paint)
|
||||
public override void Render(SKCanvas canvas, SKImageInfo canvasInfo, SKPath path, SKPaint paint)
|
||||
{
|
||||
var mainColor = MainColorProperty.CurrentValue;
|
||||
var scale = ScaleProperty.CurrentValue;
|
||||
// Scale down the render path to avoid computing a value for every pixel
|
||||
var width = Math.Floor(path.Bounds.Width * RenderScale);
|
||||
var height = Math.Floor(path.Bounds.Height * RenderScale);
|
||||
|
||||
CreateBitmap((int) width, (int) height);
|
||||
var opacity = (float) Math.Round(mainColor.Alpha / 255.0, 2, MidpointRounding.AwayFromZero);
|
||||
|
||||
_bitmap.Erase(SKColor.Empty);
|
||||
// Scale down the render path to avoid computing a value for every pixel
|
||||
var width = Math.Floor(path.Bounds.Width * _renderScale);
|
||||
var height = Math.Floor(path.Bounds.Height * _renderScale);
|
||||
|
||||
CreateBitmap((int) width, (int) height);
|
||||
|
||||
for (var x = 0; x < width; x++)
|
||||
{
|
||||
var scrolledX = x + _x;
|
||||
for (var y = 0; y < height; y++)
|
||||
{
|
||||
var scrolledY = y + _y;
|
||||
var v = _noise.Evaluate(0.1f * scale.Width * scrolledX / width, 0.1f * scale.Height * scrolledY / height, _z);
|
||||
var evalX = 0.1 * scale.Width * scrolledX / width;
|
||||
var evalY = 0.1 * scale.Height * scrolledY / height;
|
||||
if (double.IsNaN(evalX) || double.IsNaN(evalY))
|
||||
continue;
|
||||
|
||||
var v = _noise.Evaluate(evalX, evalY, _z);
|
||||
var alpha = (byte) Math.Max(0, Math.Min(255, v * 1024));
|
||||
_bitmap.SetPixel(x, y, new SKColor(mainColor.Red, mainColor.Green, mainColor.Blue, (byte) (alpha * opacity)));
|
||||
}
|
||||
@@ -81,7 +93,7 @@ namespace Artemis.Plugins.LayerBrushes.Noise
|
||||
|
||||
var bitmapTransform = SKMatrix.Concat(
|
||||
SKMatrix.MakeTranslation(path.Bounds.Left, path.Bounds.Top),
|
||||
SKMatrix.MakeScale(1f / RenderScale, 1f / RenderScale)
|
||||
SKMatrix.MakeScale(1f / _renderScale, 1f / _renderScale)
|
||||
);
|
||||
using (var backgroundShader = SKShader.CreateColor(SecondaryColorProperty.CurrentValue))
|
||||
using (var foregroundShader = SKShader.CreateBitmap(_bitmap, SKShaderTileMode.Clamp, SKShaderTileMode.Clamp, bitmapTransform))
|
||||
@@ -94,12 +106,15 @@ namespace Artemis.Plugins.LayerBrushes.Noise
|
||||
}
|
||||
}
|
||||
|
||||
private void DetermineRenderScale()
|
||||
{
|
||||
_renderScale = (float) (0.125f / _rgbService.RenderScale);
|
||||
}
|
||||
|
||||
private void CreateBitmap(int width, int height)
|
||||
{
|
||||
if (_bitmap == null)
|
||||
{
|
||||
_bitmap = new SKBitmap(new SKImageInfo(width, height));
|
||||
}
|
||||
else if (_bitmap.Width != width || _bitmap.Height != height)
|
||||
{
|
||||
_bitmap.Dispose();
|
||||
|
||||
Reference in new issue
Block a user