mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Node editor - Add SKBitmap preview to cables
This commit is contained in:
parent
c597d62c77
commit
567f6098d3
@ -83,6 +83,9 @@
|
|||||||
<DataTemplate DataType="core:Numeric">
|
<DataTemplate DataType="core:Numeric">
|
||||||
<TextBlock Text="{Binding}" FontFamily="Consolas"/>
|
<TextBlock Text="{Binding}" FontFamily="Consolas"/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
<DataTemplate DataType="skiaSharp:SKBitmap">
|
||||||
|
<SKBitmapControl Bitmap="{Binding}"></SKBitmapControl>
|
||||||
|
</DataTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<TextBlock Text="{Binding}" FontFamily="Consolas"/>
|
<TextBlock Text="{Binding}" FontFamily="Consolas"/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|||||||
@ -5,7 +5,7 @@ using SkiaSharp;
|
|||||||
|
|
||||||
namespace Artemis.VisualScripting.Nodes.Image;
|
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<object, CaptureScreenNodeCustomViewModel>
|
public class CaptureScreenNode : Node<object, CaptureScreenNodeCustomViewModel>
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
@ -30,7 +30,7 @@ public class CaptureScreenNode : Node<object, CaptureScreenNodeCustomViewModel>
|
|||||||
|
|
||||||
private CaptureZone _captureZone;
|
private CaptureZone _captureZone;
|
||||||
|
|
||||||
public OutputPin<SKImage> Output { get; set; }
|
public OutputPin<SKBitmap> Output { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -39,9 +39,9 @@ public class CaptureScreenNode : Node<object, CaptureScreenNodeCustomViewModel>
|
|||||||
public CaptureScreenNode()
|
public CaptureScreenNode()
|
||||||
: base("Capture Screen", "Captures a region of the screen")
|
: base("Capture Screen", "Captures a region of the screen")
|
||||||
{
|
{
|
||||||
Output = CreateOutputPin<SKImage>("Image");
|
Output = CreateOutputPin<SKBitmap>("Image");
|
||||||
|
|
||||||
_captureZone = _screenCapture.RegisterCaptureZone(4500, 700, 256, 256, 1);
|
_captureZone = _screenCapture.RegisterCaptureZone(20, 20, 256, 256, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -56,7 +56,7 @@ public class CaptureScreenNode : Node<object, CaptureScreenNodeCustomViewModel>
|
|||||||
if (capture.IsEmpty) return;
|
if (capture.IsEmpty) return;
|
||||||
|
|
||||||
fixed (byte* ptr = capture)
|
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
|
//TODO DarthAffe 18.08.2022: Dispose Output or better reuse it
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,12 +6,12 @@ using SkiaSharp;
|
|||||||
|
|
||||||
namespace Artemis.VisualScripting.Nodes.Image;
|
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
|
public class QuantizeNode : Node
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
public InputPin<SKImage> Image { get; set; }
|
public InputPin<SKBitmap> Image { get; set; }
|
||||||
|
|
||||||
public OutputPin<SKColor> Vibrant { get; set; }
|
public OutputPin<SKColor> Vibrant { get; set; }
|
||||||
public OutputPin<SKColor> Muted { get; set; }
|
public OutputPin<SKColor> Muted { get; set; }
|
||||||
@ -27,7 +27,7 @@ public class QuantizeNode : Node
|
|||||||
public QuantizeNode()
|
public QuantizeNode()
|
||||||
: base("Quantize", "Quantizes the image into key-colors")
|
: base("Quantize", "Quantizes the image into key-colors")
|
||||||
{
|
{
|
||||||
Image = CreateInputPin<SKImage>("Image");
|
Image = CreateInputPin<SKBitmap>("Image");
|
||||||
|
|
||||||
Vibrant = CreateOutputPin<SKColor>("Vibrant");
|
Vibrant = CreateOutputPin<SKColor>("Vibrant");
|
||||||
Muted = CreateOutputPin<SKColor>("Muted");
|
Muted = CreateOutputPin<SKColor>("Muted");
|
||||||
@ -45,8 +45,7 @@ public class QuantizeNode : Node
|
|||||||
{
|
{
|
||||||
if (Image.Value == null) return;
|
if (Image.Value == null) return;
|
||||||
|
|
||||||
using SKBitmap bitmap = SKBitmap.FromImage(Image.Value);
|
SKColor[] colorPalette = ColorQuantizer.Quantize(Image.Value.Pixels, 32); //TODO DarthAffe 18.08.2022: Palette-Size as input
|
||||||
SKColor[] colorPalette = ColorQuantizer.Quantize(bitmap.Pixels, 32); //TODO DarthAffe 18.08.2022: Palette-Size as input
|
|
||||||
ColorSwatch swatch = ColorQuantizer.FindAllColorVariations(colorPalette, true);
|
ColorSwatch swatch = ColorQuantizer.FindAllColorVariations(colorPalette, true);
|
||||||
|
|
||||||
Vibrant.Value = swatch.Vibrant;
|
Vibrant.Value = swatch.Vibrant;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user