From 567f6098d35b0ffd86bfeb172532d106c29934ed Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 18 Aug 2022 21:19:27 +0200 Subject: [PATCH] Node editor - Add SKBitmap preview to cables --- src/Artemis.UI/Screens/VisualScripting/CableView.axaml | 3 +++ .../Nodes/Image/CaptureScreenNode.cs | 10 +++++----- .../Nodes/Image/QuantizeNode.cs | 9 ++++----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Artemis.UI/Screens/VisualScripting/CableView.axaml b/src/Artemis.UI/Screens/VisualScripting/CableView.axaml index 257dbf803..de22a5923 100644 --- a/src/Artemis.UI/Screens/VisualScripting/CableView.axaml +++ b/src/Artemis.UI/Screens/VisualScripting/CableView.axaml @@ -83,6 +83,9 @@ + + + diff --git a/src/Artemis.VisualScripting/Nodes/Image/CaptureScreenNode.cs b/src/Artemis.VisualScripting/Nodes/Image/CaptureScreenNode.cs index dd2b641dd..c91ed8cda 100644 --- a/src/Artemis.VisualScripting/Nodes/Image/CaptureScreenNode.cs +++ b/src/Artemis.VisualScripting/Nodes/Image/CaptureScreenNode.cs @@ -5,7 +5,7 @@ using SkiaSharp; namespace Artemis.VisualScripting.Nodes.Image; -[Node("Capture Screen", "Captures a region of the screen", "Image", OutputType = typeof(SKImage))] +[Node("Capture Screen", "Captures a region of the screen", "Image", OutputType = typeof(SKBitmap))] public class CaptureScreenNode : Node { #region Properties & Fields @@ -30,7 +30,7 @@ public class CaptureScreenNode : Node private CaptureZone _captureZone; - public OutputPin Output { get; set; } + public OutputPin Output { get; set; } #endregion @@ -39,9 +39,9 @@ public class CaptureScreenNode : Node public CaptureScreenNode() : base("Capture Screen", "Captures a region of the screen") { - Output = CreateOutputPin("Image"); + Output = CreateOutputPin("Image"); - _captureZone = _screenCapture.RegisterCaptureZone(4500, 700, 256, 256, 1); + _captureZone = _screenCapture.RegisterCaptureZone(20, 20, 256, 256, 1); } #endregion @@ -56,7 +56,7 @@ public class CaptureScreenNode : Node if (capture.IsEmpty) return; fixed (byte* ptr = capture) - Output.Value = SKImage.FromPixels(new SKImageInfo(_captureZone.Width, _captureZone.Height, SKColorType.Bgra8888, SKAlphaType.Opaque), new IntPtr(ptr), _captureZone.Stride); + Output.Value = SKBitmap.FromImage(SKImage.FromPixels(new SKImageInfo(_captureZone.Width, _captureZone.Height, SKColorType.Bgra8888, SKAlphaType.Opaque), new IntPtr(ptr), _captureZone.Stride)); //TODO DarthAffe 18.08.2022: Dispose Output or better reuse it } diff --git a/src/Artemis.VisualScripting/Nodes/Image/QuantizeNode.cs b/src/Artemis.VisualScripting/Nodes/Image/QuantizeNode.cs index 05ff6af5b..38fbd27b5 100644 --- a/src/Artemis.VisualScripting/Nodes/Image/QuantizeNode.cs +++ b/src/Artemis.VisualScripting/Nodes/Image/QuantizeNode.cs @@ -6,12 +6,12 @@ using SkiaSharp; namespace Artemis.VisualScripting.Nodes.Image; -[Node("Quantize", "Quantizes the image into key-colors", "Image", InputType = typeof(SKImage), OutputType = typeof(SKColor))] +[Node("Quantize", "Quantizes the image into key-colors", "Image", InputType = typeof(SKBitmap), OutputType = typeof(SKColor))] public class QuantizeNode : Node { #region Properties & Fields - public InputPin Image { get; set; } + public InputPin Image { get; set; } public OutputPin Vibrant { get; set; } public OutputPin Muted { get; set; } @@ -27,7 +27,7 @@ public class QuantizeNode : Node public QuantizeNode() : base("Quantize", "Quantizes the image into key-colors") { - Image = CreateInputPin("Image"); + Image = CreateInputPin("Image"); Vibrant = CreateOutputPin("Vibrant"); Muted = CreateOutputPin("Muted"); @@ -45,8 +45,7 @@ public class QuantizeNode : Node { if (Image.Value == null) return; - using SKBitmap bitmap = SKBitmap.FromImage(Image.Value); - SKColor[] colorPalette = ColorQuantizer.Quantize(bitmap.Pixels, 32); //TODO DarthAffe 18.08.2022: Palette-Size as input + SKColor[] colorPalette = ColorQuantizer.Quantize(Image.Value.Pixels, 32); //TODO DarthAffe 18.08.2022: Palette-Size as input ColorSwatch swatch = ColorQuantizer.FindAllColorVariations(colorPalette, true); Vibrant.Value = swatch.Vibrant;