Browse Source

Performance Improvements

CPKreuz 1 year ago
parent
commit
65d9407eba

+ 2 - 2
src/PixiEditor.ChangeableDocument/Changeables/Graph/FieldInputProperty.cs

@@ -3,9 +3,9 @@ using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph;
 
-public class FieldInputProperty<T> : InputProperty<Func<IFieldContext, T>>
+public class FieldInputProperty<T> : InputProperty<Func<FieldContext, T>>
 {
-    internal FieldInputProperty(Node node, string internalName, string displayName, Func<IFieldContext, T> defaultValue) : base(node, internalName, displayName, defaultValue)
+    internal FieldInputProperty(Node node, string internalName, string displayName, Func<FieldContext, T> defaultValue) : base(node, internalName, displayName, defaultValue)
     {
     }
 }

+ 2 - 2
src/PixiEditor.ChangeableDocument/Changeables/Graph/FieldOutputProperty.cs

@@ -3,9 +3,9 @@ using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph;
 
-public class FieldOutputProperty<T> : OutputProperty<Func<IFieldContext, T>>
+public class FieldOutputProperty<T> : OutputProperty<Func<FieldContext, T>>
 {
-    internal FieldOutputProperty(Node node, string internalName, string displayName, Func<IFieldContext, T> defaultValue) : base(node, internalName, displayName, defaultValue)
+    internal FieldOutputProperty(Node node, string internalName, string displayName, Func<FieldContext, T> defaultValue) : base(node, internalName, displayName, defaultValue)
     {
     }
 }

+ 5 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Interfaces/FieldContext.cs

@@ -0,0 +1,5 @@
+using PixiEditor.Numerics;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
+
+public record struct FieldContext(VecD Position, VecI Size);

+ 0 - 10
src/PixiEditor.ChangeableDocument/Changeables/Graph/Interfaces/IFieldContext.cs

@@ -1,10 +0,0 @@
-using PixiEditor.Numerics;
-
-namespace PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
-
-public interface IFieldContext
-{
-    public VecD Position { get; }
-    
-    public VecI Size { get; }
-}

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/CombineColor.cs

@@ -26,7 +26,7 @@ public class CombineColor : Node
         A = CreateFieldInput("A", "A", _ => 1d);
     }
 
-    private Color GetColor(IFieldContext ctx)
+    private Color GetColor(FieldContext ctx)
     {
         var r = R.Value(ctx) * 255;
         var g = G.Value(ctx) * 255;

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ModifyImageLeftNode.cs

@@ -20,7 +20,7 @@ public class ModifyImageLeftNode : Node
         Color = CreateFieldOutput(nameof(Color), "COLOR", GetColor);
     }
 
-    private Color GetColor(IFieldContext context)
+    private Color GetColor(FieldContext context)
     {
         if (Image.Value is not { } image)
         {

+ 8 - 6
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ModifyImageRightNode.cs

@@ -2,12 +2,15 @@
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.DrawingApi.Core.Surface;
+using PixiEditor.DrawingApi.Core.Surface.PaintImpl;
 using PixiEditor.Numerics;
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 
 public class ModifyImageRightNode : Node
 {
+    private Paint drawingPaint = new Paint() { BlendMode = BlendMode.Src };
+    
     public InputProperty<ChunkyImage?> _InternalImage { get; }
     
     public FieldInputProperty<Color> Color { get; }
@@ -33,18 +36,21 @@ public class ModifyImageRightNode : Node
         var height = size.Y;
 
         Output.Value = new ChunkyImage(size);
+        using var surface = new Surface(size);
 
         for (int y = 0; y < width; y++)
         {
             for (int x = 0; x < height; x++)
             {
-                var context = new CreateImageContext(new VecD((double)x / width, (double)y / width), new VecI(width, height));
+                var context = new FieldContext(new VecD((double)x / width, (double)y / width), new VecI(width, height));
                 var color = Color.Value(context);
 
-                Output.Value.EnqueueDrawPixel(new VecI(x, y), color, BlendMode.Src);
+                drawingPaint.Color = color;
+                surface.DrawingSurface.Canvas.DrawPixel(x, y, drawingPaint);
             }
         }
 
+        Output.Value.EnqueueDrawImage(VecI.Zero, surface);
         Output.Value.CommitChanges();
 
         return Output.Value;
@@ -53,8 +59,4 @@ public class ModifyImageRightNode : Node
     public override bool Validate() => true;
 
     public override Node CreateCopy() => new ModifyImageRightNode();
-
-    record CreateImageContext(VecD Position, VecI Size) : IFieldContext
-    {
-    }
 }

+ 2 - 2
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Node.cs

@@ -109,7 +109,7 @@ public abstract class Node : IReadOnlyNode, IDisposable
     }
 
     protected FieldInputProperty<T> CreateFieldInput<T>(string propName, string displayName,
-        Func<IFieldContext, T> defaultFunc)
+        Func<FieldContext, T> defaultFunc)
     {
         var property = new FieldInputProperty<T>(this, propName, displayName, defaultFunc);
         if (InputProperties.Any(x => x.InternalPropertyName == propName))
@@ -134,7 +134,7 @@ public abstract class Node : IReadOnlyNode, IDisposable
     }
 
     protected FieldOutputProperty<T> CreateFieldOutput<T>(string propName, string displayName,
-        Func<IFieldContext, T> defaultFunc)
+        Func<FieldContext, T> defaultFunc)
     {
         var property = new FieldOutputProperty<T>(this, propName, displayName, defaultFunc);
         outputs.Add(property);