mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
WIP - Added a BitmapBrush to replace the GraphicsDecorator
This commit is contained in:
1 parent
146c545f02
commit
5dbd35208b
15 files changed
+399
-116
No files matched your search
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Artemis.Core.Extensions;
|
||||
using RGB.NET.Core;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.RGB.NET
|
||||
{
|
||||
public class BitmapBrush : AbstractDecoratable<IBrushDecorator>, IBrush, IDisposable
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
public BitmapBrush(Scale scale)
|
||||
{
|
||||
Scale = scale;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsEnabled { get; set; } = true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public BrushCalculationMode BrushCalculationMode { get; set; } = BrushCalculationMode.Absolute;
|
||||
|
||||
/// <inheritdoc />
|
||||
public double Brightness { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public double Opacity { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IList<IColorCorrection> ColorCorrections { get; } = new List<IColorCorrection>();
|
||||
|
||||
/// <inheritdoc />
|
||||
public Rectangle RenderedRectangle { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public Dictionary<BrushRenderTarget, Color> RenderedTargets { get; } = new Dictionary<BrushRenderTarget, Color>();
|
||||
|
||||
public Scale Scale { get; set; }
|
||||
public SKBitmap Bitmap { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void PerformRender(Rectangle rectangle, IEnumerable<BrushRenderTarget> renderTargets)
|
||||
{
|
||||
if (RenderedRectangle != rectangle || RenderedScale != Scale)
|
||||
Bitmap = null;
|
||||
|
||||
if (renderTargets.Any())
|
||||
{
|
||||
var test = RGBSurface.Instance.SurfaceRectangle;
|
||||
var width = renderTargets.Max(l => l.Led.AbsoluteLedRectangle.Location.X + l.Led.AbsoluteLedRectangle.Size.Width);
|
||||
var height = renderTargets.Max(l => l.Led.AbsoluteLedRectangle.Location.Y + l.Led.AbsoluteLedRectangle.Size.Height);
|
||||
}
|
||||
|
||||
RenderedRectangle = rectangle;
|
||||
RenderedScale = Scale;
|
||||
RenderedTargets.Clear();
|
||||
|
||||
if (Bitmap == null)
|
||||
CreateBitmap(RenderedRectangle);
|
||||
|
||||
foreach (var renderTarget in renderTargets)
|
||||
{
|
||||
var scaledLocation = renderTarget.Point * Scale;
|
||||
if (scaledLocation.X < Bitmap.Width && scaledLocation.Y < Bitmap.Height)
|
||||
{
|
||||
RenderedTargets[renderTarget] = Bitmap.GetPixel(RoundToInt(scaledLocation.X), RoundToInt(scaledLocation.Y)).ToRgbColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Scale RenderedScale { get; private set; }
|
||||
|
||||
private void CreateBitmap(Rectangle rectangle)
|
||||
{
|
||||
var width = Math.Min((rectangle.Location.X + rectangle.Size.Width) * Scale.Horizontal, 4096);
|
||||
var height = Math.Min((rectangle.Location.Y + rectangle.Size.Height) * Scale.Vertical, 4096);
|
||||
Bitmap = new SKBitmap(new SKImageInfo(width.RoundToInt(), height.RoundToInt()));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private int RoundToInt(double number)
|
||||
{
|
||||
return (int) Math.Round(number, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void PerformFinalize()
|
||||
{
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Bitmap?.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ namespace Artemis.Core.RGB.NET
|
||||
var height = Math.Min(leds.Max(l => l.AbsoluteLedRectangle.Location.Y + l.AbsoluteLedRectangle.Size.Height) * scale, 4096);
|
||||
Bitmap = new SKBitmap(new SKImageInfo(width.RoundToInt(), height.RoundToInt()));
|
||||
}
|
||||
|
||||
|
||||
public SKBitmap Bitmap { get; private set; }
|
||||
|
||||
public Color ManipulateColor(Rectangle rectangle, BrushRenderTarget renderTarget, Color color)
|
||||
|
||||
Reference in new issue
Block a user