This commit is contained in:
Robert committed 2019-12-02 20:14:28 +01:00
1 parent 9148323ad5
commit b8a678c97f
16 files changed
+172 -166

No files matched your search

+6 -2
View File
@@ -110,6 +110,9 @@
<Reference Include="Serilog.Sinks.File, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.Sinks.File.4.0.0\lib\net45\Serilog.Sinks.File.dll</HintPath>
</Reference>
<Reference Include="SkiaSharp, Version=1.68.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\SkiaSharp.1.68.1\lib\net45\SkiaSharp.dll</HintPath>
</Reference>
<Reference Include="Stylet, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Stylet.1.2.0\lib\net45\Stylet.dll</HintPath>
</Reference>
@@ -125,7 +128,6 @@
<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.3.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.4.5.1\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath>
</Reference>
@@ -156,6 +158,7 @@
<Compile Include="Events\FrameRenderingEventArgs.cs" />
<Compile Include="Exceptions\ArtemisCoreException.cs" />
<Compile Include="Extensions\DirectoryInfoExtensions.cs" />
<Compile Include="Extensions\DoubleExtensions.cs" />
<Compile Include="Extensions\RgbColorExtensions.cs" />
<Compile Include="Extensions\RgbDeviceExtensions.cs" />
<Compile Include="Extensions\RgbRectangleExtensions.cs" />
@@ -189,7 +192,6 @@
<Compile Include="Models\Profile\Profile.cs" />
<Compile Include="Ninject\CoreModule.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RGB.NET\DirectBitmap.cs" />
<Compile Include="RGB.NET\GraphicsDecorator.cs" />
<Compile Include="Services\DeviceService.cs" />
<Compile Include="Services\Interfaces\ILayerService.cs" />
@@ -230,5 +232,7 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\Fody.6.0.5\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.6.0.5\build\Fody.targets'))" />
<Error Condition="!Exists('..\packages\PropertyChanged.Fody.3.1.3\build\PropertyChanged.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\PropertyChanged.Fody.3.1.3\build\PropertyChanged.Fody.props'))" />
<Error Condition="!Exists('..\packages\SkiaSharp.1.68.1\build\net45\SkiaSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SkiaSharp.1.68.1\build\net45\SkiaSharp.targets'))" />
</Target>
<Import Project="..\packages\SkiaSharp.1.68.1\build\net45\SkiaSharp.targets" Condition="Exists('..\packages\SkiaSharp.1.68.1\build\net45\SkiaSharp.targets')" />
</Project>
@@ -1,23 +1,23 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.RGB.NET;
using RGB.NET.Core;
namespace Artemis.Core.Events
{
public class FrameRenderingEventArgs : EventArgs
{
public FrameRenderingEventArgs(List<Module> modules, Bitmap bitmap, double deltaTime, RGBSurface rgbSurface)
public FrameRenderingEventArgs(List<Module> modules, GraphicsDecorator graphicsDecorator, double deltaTime, RGBSurface rgbSurface)
{
Modules = modules;
Bitmap = bitmap;
GraphicsDecorator = graphicsDecorator;
DeltaTime = deltaTime;
RgbSurface = rgbSurface;
}
public List<Module> Modules { get; }
public Bitmap Bitmap { get; }
public GraphicsDecorator GraphicsDecorator { get; }
public double DeltaTime { get; }
public RGBSurface RgbSurface { get; }
}
@@ -0,0 +1,12 @@
using System;
namespace Artemis.Core.Extensions
{
public static class DoubleExtensions
{
public static int RoundToInt(this double number)
{
return (int) Math.Round(number, MidpointRounding.AwayFromZero);
}
}
}
@@ -6,6 +6,7 @@ using Artemis.Core.Extensions;
using Artemis.Core.Plugins.Abstract;
using Artemis.Storage.Entities.Surface;
using RGB.NET.Core;
using SkiaSharp;
using Stylet;
using Rectangle = System.Drawing.Rectangle;
@@ -38,8 +39,8 @@ namespace Artemis.Core.Models.Surface
Leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
}
public Rectangle RenderRectangle { get; private set; }
public GraphicsPath RenderPath { get; private set; }
public SKRect RenderRectangle { get; private set; }
public SKPath RenderPath { get; private set; }
public IRGBDevice RgbDevice { get; }
public Plugin Plugin { get; }
@@ -95,6 +96,12 @@ namespace Artemis.Core.Models.Surface
internal void CalculateRenderProperties()
{
RenderRectangle = SKRect.Create(
(RgbDevice.Location.X * Surface.Scale).RoundToInt(),
(RgbDevice.Location.Y * Surface.Scale).RoundToInt(),
(RgbDevice.Location.X * Surface.Scale).RoundToInt(),
(RgbDevice.Location.X * Surface.Scale).RoundToInt()
);
RenderRectangle = new Rectangle(
(int) Math.Round(RgbDevice.Location.X * Surface.Scale, MidpointRounding.AwayFromZero),
(int) Math.Round(RgbDevice.Location.Y * Surface.Scale, MidpointRounding.AwayFromZero),
+3 -2
View File
@@ -2,6 +2,7 @@
using System.Drawing;
using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Models;
using SkiaSharp;
namespace Artemis.Core.Plugins.Abstract
{
@@ -37,8 +38,8 @@ namespace Artemis.Core.Plugins.Abstract
/// </summary>
/// <param name="deltaTime">Time since the last render</param>
/// <param name="surface">The RGB Surface to render to</param>
/// <param name="graphics"></param>
public abstract void Render(double deltaTime, ArtemisSurface surface, Graphics graphics);
/// <param name="canvas"></param>
public abstract void Render(double deltaTime, ArtemisSurface surface, SKCanvas canvas);
/// <summary>
/// Called when the module's view model is being show, return view models here to create tabs for them
-57
View File
@@ -1,57 +0,0 @@
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
namespace Artemis.Core.RGB.NET
{
public class DirectBitmap : IDisposable
{
public DirectBitmap(int width, int height)
{
Width = width;
Height = height;
Bits = new int[width * height];
BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned);
Bitmap = new Bitmap(width, height, width * 4, PixelFormat.Format32bppPArgb, BitsHandle.AddrOfPinnedObject());
}
public Bitmap Bitmap { get; }
public int[] Bits { get; }
public bool Disposed { get; private set; }
public int Height { get; }
public int Width { get; }
protected GCHandle BitsHandle { get; }
public void Dispose()
{
if (Disposed) return;
Disposed = true;
Bitmap.Dispose();
BitsHandle.Free();
}
public void SetPixel(int x, int y, Color colour)
{
var index = x + y * Width;
var col = colour.ToArgb();
Bits[index] = col;
}
public Color GetPixel(int x, int y)
{
var index = x + y * Width;
if (index >= 0 && index - 1 <= Bits.Length)
{
var col = Bits[index];
var result = Color.FromArgb(col);
return result;
}
return Color.Black;
}
}
}
+20 -35
View File
@@ -1,16 +1,13 @@
using System;
using System.Drawing;
using System.Linq;
using RGB.NET.Core;
using Color = RGB.NET.Core.Color;
using Rectangle = RGB.NET.Core.Rectangle;
using SkiaSharp;
namespace Artemis.Core.RGB.NET
{
public class GraphicsDecorator : AbstractDecorator, IBrushDecorator, IDisposable
{
private readonly double _scale;
private DirectBitmap _bitmap;
public GraphicsDecorator(ILedGroup ledGroup, double scale)
{
@@ -18,27 +15,27 @@ namespace Artemis.Core.RGB.NET
var leds = ledGroup.GetLeds().ToList();
if (!leds.Any())
_bitmap = null;
else
{
var width = Math.Min(leds.Max(l => l.AbsoluteLedRectangle.Location.X + l.AbsoluteLedRectangle.Size.Width) * scale, 4096);
var height = Math.Min(leds.Max(l => l.AbsoluteLedRectangle.Location.Y + l.AbsoluteLedRectangle.Size.Height) * scale, 4096);
return;
_bitmap = new DirectBitmap((int) width, (int) height);
}
var width = Math.Min(leds.Max(l => l.AbsoluteLedRectangle.Location.X + l.AbsoluteLedRectangle.Size.Width) * scale, 4096);
var height = Math.Min(leds.Max(l => l.AbsoluteLedRectangle.Location.Y + l.AbsoluteLedRectangle.Size.Height) * scale, 4096);
Bitmap = new SKBitmap(new SKImageInfo(RoundToInt(width), RoundToInt(height)));
Canvas = new SKCanvas(Bitmap);
}
public SKBitmap Bitmap { get; private set; }
public SKCanvas Canvas { get; private set; }
public Color ManipulateColor(Rectangle rectangle, BrushRenderTarget renderTarget, Color color)
{
if (Bitmap == null)
return new Color(0, 0, 0);
var x = renderTarget.Led.AbsoluteLedRectangle.Center.X * _scale;
var y = renderTarget.Led.AbsoluteLedRectangle.Center.Y * _scale;
if (_bitmap != null && _bitmap.Width - 1 >= x && _bitmap.Height - 1 >= y)
{
var pixel = _bitmap.GetPixel((int) x, (int) y);
return new Color(pixel.A, pixel.R, pixel.G, pixel.B);
}
return new Color(0, 0, 0);
var pixel = Bitmap.GetPixel(RoundToInt(x), RoundToInt(y));
return new Color(pixel.Alpha, pixel.Red, pixel.Green, pixel.Blue);
}
public override void OnDetached(IDecoratable decoratable)
@@ -48,27 +45,15 @@ namespace Artemis.Core.RGB.NET
public void Dispose()
{
_bitmap?.Dispose();
_bitmap = null;
Bitmap?.Dispose();
Canvas?.Dispose();
Bitmap = null;
Canvas = null;
}
public Graphics GetGraphics()
private int RoundToInt(double number)
{
try
{
return _bitmap == null ? null : Graphics.FromImage(_bitmap.Bitmap);
}
catch (AccessViolationException)
{
// ignored
}
return null;
}
public Bitmap GetBitmap()
{
return _bitmap?.Bitmap;
return (int) Math.Round(number, MidpointRounding.AwayFromZero);
}
}
}
+9 -16
View File
@@ -8,7 +8,6 @@ using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Storage.Interfaces;
using RGB.NET.Core;
using Serilog;
using Color = System.Drawing.Color;
namespace Artemis.Core.Services
{
@@ -78,26 +77,20 @@ namespace Artemis.Core.Services
module.Update(args.DeltaTime);
}
// If there is no graphics decorator, skip the frame
if (_rgbService.GraphicsDecorator == null)
// If there is no ready graphics decorator, skip the frame
if (_rgbService.GraphicsDecorator?.Canvas == null)
return;
// Render all active modules
using (var g = _rgbService.GraphicsDecorator.GetGraphics())
_rgbService.GraphicsDecorator.Canvas.Clear();
lock (_modules)
{
// If there are no graphics, skip the frame
if (g == null)
return;
g.Clear(Color.Black);
lock (_modules)
{
foreach (var module in _modules)
module.Render(args.DeltaTime, _surfaceService.ActiveSurface, g);
}
foreach (var module in _modules)
module.Render(args.DeltaTime, _surfaceService.ActiveSurface, _rgbService.GraphicsDecorator.Canvas);
}
OnFrameRendering(new FrameRenderingEventArgs(_modules, _rgbService.GraphicsDecorator.GetBitmap(), args.DeltaTime, _rgbService.Surface));
OnFrameRendering(new FrameRenderingEventArgs(_modules, _rgbService.GraphicsDecorator, args.DeltaTime, _rgbService.Surface));
}
catch (Exception e)
{
@@ -107,7 +100,7 @@ namespace Artemis.Core.Services
private void SurfaceOnUpdated(UpdatedEventArgs args)
{
OnFrameRendered(new FrameRenderedEventArgs(_rgbService.GraphicsDecorator.GetBitmap(), _rgbService.Surface));
OnFrameRendered(new FrameRenderedEventArgs(_rgbService.GraphicsDecorator, _rgbService.Surface));
}
protected virtual void OnFrameRendering(FrameRenderingEventArgs e)
+1 -1
View File
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AppDomainToolkit" version="1.0.4.3" targetFramework="net461" />
<package id="Ben.Demystifier" version="0.1.4" targetFramework="net472" />
@@ -15,6 +14,7 @@
<package id="Serilog" version="2.8.0" targetFramework="net472" />
<package id="Serilog.Enrichers.Demystify" version="1.0.0-dev-00019" targetFramework="net472" />
<package id="Serilog.Sinks.File" version="4.0.0" targetFramework="net472" />
<package id="SkiaSharp" version="1.68.1" targetFramework="net472" />
<package id="Stylet" version="1.2.0" targetFramework="net472" />
<package id="System.Buffers" version="4.5.0" targetFramework="net472" />
<package id="System.Collections.Immutable" version="1.6.0-preview8.19405.3" targetFramework="net472" />