From 5cdde6e4026a3e2f210e1ba4b008693ace047de0 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 25 Oct 2019 17:30:07 +0200 Subject: [PATCH] To test, scaled down rendering to 25% --- .../Extensions/RgbRectangleExtensions.cs | 9 +++++++-- src/Artemis.Core/RGB.NET/GraphicsDecorator.cs | 16 ++++++++++------ src/Artemis.Core/Services/RgbService.cs | 2 +- .../GeneralModule.cs | 2 +- .../ViewModels/Screens/DebugViewModel.cs | 5 ++++- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/Artemis.Core/Extensions/RgbRectangleExtensions.cs b/src/Artemis.Core/Extensions/RgbRectangleExtensions.cs index c3b54251a..2e94514bd 100644 --- a/src/Artemis.Core/Extensions/RgbRectangleExtensions.cs +++ b/src/Artemis.Core/Extensions/RgbRectangleExtensions.cs @@ -4,9 +4,14 @@ namespace Artemis.Core.Extensions { public static class RgbRectangleExtensions { - public static Rectangle ToDrawingRectangle(this global::RGB.NET.Core.Rectangle rectangle) + public static Rectangle ToDrawingRectangle(this global::RGB.NET.Core.Rectangle rectangle, double scale) { - return new Rectangle((int) rectangle.X, (int) rectangle.Y, (int) rectangle.Width, (int) rectangle.Height); + return new Rectangle( + (int) (rectangle.X * scale), + (int) (rectangle.Y * scale), + (int) (rectangle.Width * scale), + (int) (rectangle.Height * scale) + ); } } } \ No newline at end of file diff --git a/src/Artemis.Core/RGB.NET/GraphicsDecorator.cs b/src/Artemis.Core/RGB.NET/GraphicsDecorator.cs index f1f3187a6..5326910ed 100644 --- a/src/Artemis.Core/RGB.NET/GraphicsDecorator.cs +++ b/src/Artemis.Core/RGB.NET/GraphicsDecorator.cs @@ -9,17 +9,20 @@ namespace Artemis.Core.RGB.NET { public class GraphicsDecorator : AbstractDecorator, IBrushDecorator, IDisposable { + private readonly double _scale; private DirectBitmap _bitmap; - public GraphicsDecorator(ILedGroup ledGroup) + public GraphicsDecorator(ILedGroup ledGroup, double scale) { + _scale = scale; + var leds = ledGroup.GetLeds().ToList(); if (!leds.Any()) _bitmap = null; else { - var width = Math.Min(leds.Max(l => l.AbsoluteLedRectangle.X + l.AbsoluteLedRectangle.Width), 2000); - var height = Math.Min(leds.Max(l => l.AbsoluteLedRectangle.Y + l.AbsoluteLedRectangle.Height), 2000); + var width = Math.Min(leds.Max(l => l.AbsoluteLedRectangle.X + l.AbsoluteLedRectangle.Width) * scale, 4096); + var height = Math.Min(leds.Max(l => l.AbsoluteLedRectangle.Y + l.AbsoluteLedRectangle.Height) * scale, 4096); _bitmap = new DirectBitmap((int) width, (int) height); } @@ -27,10 +30,11 @@ namespace Artemis.Core.RGB.NET public Color ManipulateColor(Rectangle rectangle, BrushRenderTarget renderTarget, Color color) { - var point = renderTarget.Led.AbsoluteLedRectangle.Center; - if (_bitmap != null && _bitmap.Width - 1 >= point.X && _bitmap.Height - 1 >= point.Y) + 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) point.X, (int) point.Y); + var pixel = _bitmap.GetPixel((int) x, (int) y); return new Color(pixel.A, pixel.R, pixel.G, pixel.B); } diff --git a/src/Artemis.Core/Services/RgbService.cs b/src/Artemis.Core/Services/RgbService.cs index 8544aaea1..510c10394 100644 --- a/src/Artemis.Core/Services/RgbService.cs +++ b/src/Artemis.Core/Services/RgbService.cs @@ -108,7 +108,7 @@ namespace Artemis.Core.Services // Apply the application wide brush and decorator _background = new ListLedGroup(Surface.Leds) {Brush = new SolidColorBrush(new Color(255, 255, 255, 255))}; - GraphicsDecorator = new GraphicsDecorator(_background); + GraphicsDecorator = new GraphicsDecorator(_background, 0.25); _background.Brush.RemoveAllDecorators(); _background.Brush.AddDecorator(GraphicsDecorator); diff --git a/src/Artemis.Plugins.Modules.General/GeneralModule.cs b/src/Artemis.Plugins.Modules.General/GeneralModule.cs index a9293a0c4..92c373c4a 100644 --- a/src/Artemis.Plugins.Modules.General/GeneralModule.cs +++ b/src/Artemis.Plugins.Modules.General/GeneralModule.cs @@ -87,7 +87,7 @@ namespace Artemis.Plugins.Modules.General Colors[index] = color; } - var rectangle = led.AbsoluteLedRectangle.ToDrawingRectangle(); + var rectangle = led.AbsoluteLedRectangle.ToDrawingRectangle(0.25); graphics.FillRectangle(new SolidBrush(color), rectangle); index++; } diff --git a/src/Artemis.UI/ViewModels/Screens/DebugViewModel.cs b/src/Artemis.UI/ViewModels/Screens/DebugViewModel.cs index 5e07755b0..a14e71a72 100644 --- a/src/Artemis.UI/ViewModels/Screens/DebugViewModel.cs +++ b/src/Artemis.UI/ViewModels/Screens/DebugViewModel.cs @@ -38,7 +38,10 @@ namespace Artemis.UI.ViewModels.Screens var imageSource = ImageSourceFromBitmap(e.Bitmap); imageSource.Freeze(); CurrentFps = Math.Round(1.0 / e.DeltaTime, 2); - Execute.OnUIThread(() => CurrentFrame = imageSource); + Execute.OnUIThread(() => + { + CurrentFrame = imageSource; + }); } protected override void OnClose()