Przeglądaj źródła

Fix kernel resizing losing values and use identity kernel as default

CPKreuz 1 rok temu
rodzic
commit
671654c45e

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

@@ -28,7 +28,7 @@ public class KernelFilterNode : Node
     {
         Transformed = CreateOutput<Surface>(nameof(Transformed), "TRANSFORMED", null);
         Image = CreateInput<Surface>(nameof(Image), "IMAGE", null);
-        Kernel = CreateInput(nameof(Kernel), "KERNEL", new Kernel(3, 3));
+        Kernel = CreateInput(nameof(Kernel), "KERNEL", Numerics.Kernel.Identity(3, 3));
         Gain = CreateInput(nameof(Gain), "GAIN", 1d);
         Bias = CreateInput(nameof(Bias), "BIAS", 0d);
         Tile = CreateInput(nameof(Tile), "TILE_MODE", TileMode.Clamp);

+ 4 - 1
src/PixiEditor.Numerics/Kernel.cs

@@ -30,6 +30,9 @@ public class Kernel
         _buffer = new KernelArray(width, height);
     }
 
+    public static Kernel Identity(int width, int height) =>
+        new(width, height) { [0, 0] = 1 };
+
     public void Resize(int width, int height)
     {
         var old = _buffer;
@@ -46,7 +49,7 @@ public class Kernel
         {
             for (int x = -newRadiusX; x <= newRadiusX; x++)
             {
-                if (x < oldRadiusX || x > oldRadiusX || y < oldRadiusY || y > oldRadiusY)
+                if (x < -oldRadiusX || x > oldRadiusX || y < -oldRadiusY || y > oldRadiusY)
                     continue;
 
                 _buffer[x, y] = old[x, y];