Browse Source

Fixed post-merge issues

CPKreuz 1 year ago
parent
commit
d95f426330

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

@@ -1,6 +1,7 @@
 using PixiEditor.ChangeableDocument.Changeables.Animations;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
+using PixiEditor.DrawingApi.Core.Surface.ImageData;
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 
@@ -36,7 +37,7 @@ public class CombineColorNode : Node
         return new Color((byte)r, (byte)g, (byte)b, (byte)a);
     }
     
-    protected override ChunkyImage? OnExecute(KeyFrameTime frameTime)
+    protected override Image? OnExecute(KeyFrameTime frameTime)
     {
         return null;
     }

+ 4 - 3
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/EmptyImageNode.cs

@@ -1,4 +1,5 @@
 using PixiEditor.ChangeableDocument.Changeables.Animations;
+using PixiEditor.DrawingApi.Core.Surface.ImageData;
 using PixiEditor.Numerics;
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
@@ -15,11 +16,11 @@ public class EmptyImageNode : Node
         Size = CreateInput(nameof(Size), "SIZE", new VecI(32, 32));
     }
     
-    protected override ChunkyImage? OnExecute(KeyFrameTime frameTime)
+    protected override Image? OnExecute(KeyFrameTime frameTime)
     {
-        Output.Value = new ChunkyImage(Size.Value);
+        using var surface = new Surface(Size.Value);
 
-        return Output.Value;
+        return surface.DrawingSurface.Snapshot();
     }
 
     public override bool Validate() => Size.Value is { X: > 0, Y: > 0 };

+ 5 - 4
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ImageSizeNode.cs

@@ -1,23 +1,24 @@
 using PixiEditor.ChangeableDocument.Changeables.Animations;
+using PixiEditor.DrawingApi.Core.Surface.ImageData;
 using PixiEditor.Numerics;
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 
 public class ImageSizeNode : Node
 {
-    public InputProperty<ChunkyImage?> Image { get; }
+    public InputProperty<Image?> Image { get; }
     
     public OutputProperty<VecI> Size { get; }
     
     public ImageSizeNode()
     {
-        Image = CreateInput<ChunkyImage>(nameof(Image), "IMAGE", null);
+        Image = CreateInput<Image>(nameof(Image), "IMAGE", null);
         Size = CreateOutput(nameof(Size), "SIZE", new VecI());
     }
     
-    protected override ChunkyImage? OnExecute(KeyFrameTime frameTime)
+    protected override Image? OnExecute(KeyFrameTime frameTime)
     {
-        Size.Value = Image.Value?.CommittedSize ?? new VecI();
+        Size.Value = Image.Value?.Size ?? new VecI();
 
         return null;
     }

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

@@ -1,5 +1,6 @@
 using PixiEditor.ChangeableDocument.Changeables.Animations;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
+using PixiEditor.DrawingApi.Core.Surface.ImageData;
 using PixiEditor.Numerics;
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
@@ -16,7 +17,7 @@ public class ImageSpaceNode : Node
         Size = CreateFieldOutput(nameof(Size), "SIZE", ctx => ctx.Size);
     }
     
-    protected override ChunkyImage? OnExecute(KeyFrameTime frameTime)
+    protected override Image? OnExecute(KeyFrameTime frameTime)
     {
         return null;
     }

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

@@ -1,13 +1,17 @@
 using PixiEditor.ChangeableDocument.Changeables.Animations;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
+using PixiEditor.DrawingApi.Core.Surface;
+using PixiEditor.DrawingApi.Core.Surface.ImageData;
 using PixiEditor.Numerics;
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 
 public class ModifyImageLeftNode : Node
 {
-    public InputProperty<ChunkyImage?> Image { get; }
+    private Pixmap? pixmap;
+    
+    public InputProperty<Image?> Image { get; }
     
     public FieldOutputProperty<VecD> Coordinate { get; }
     
@@ -15,26 +19,28 @@ public class ModifyImageLeftNode : Node
     
     public ModifyImageLeftNode()
     {
-        Image = CreateInput<ChunkyImage>(nameof(Image), "IMAGE", null);
+        Image = CreateInput<Image>(nameof(Image), "IMAGE", null);
         Coordinate = CreateFieldOutput(nameof(Coordinate), "COORDINATE", ctx => ctx.Position);
         Color = CreateFieldOutput(nameof(Color), "COLOR", GetColor);
     }
 
     private Color GetColor(FieldContext context)
     {
-        if (Image.Value is not { } image)
-        {
+        if (pixmap == null)
             return new Color();
-        }
         
-        var pos = new VecI(
-            (int)(context.Position.X * context.Size.X),
-            (int)(context.Position.Y * context.Size.Y));
+        var x = context.Position.X * context.Size.X;
+        var y = context.Position.Y * context.Size.Y;
         
-        return image.GetCommittedPixel(pos);
+        return pixmap.GetPixelColor((int)x, (int)y);
+    }
+
+    internal void PreparePixmap()
+    {
+        pixmap = Image.Value?.PeekPixels();
     }
 
-    protected override ChunkyImage? OnExecute(KeyFrameTime frameTime)
+    protected override Image? OnExecute(KeyFrameTime frameTime)
     {
         return Image.Value;
     }

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

@@ -2,6 +2,7 @@
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.DrawingApi.Core.Surface;
+using PixiEditor.DrawingApi.Core.Surface.ImageData;
 using PixiEditor.DrawingApi.Core.Surface.PaintImpl;
 using PixiEditor.Numerics;
 
@@ -15,26 +16,27 @@ public class ModifyImageRightNode : Node
     
     public FieldInputProperty<Color> Color { get; }
     
-    public OutputProperty<ChunkyImage> Output { get; }
+    public OutputProperty<Image> Output { get; }
     
     public ModifyImageRightNode(ModifyImageLeftNode startNode)
     {
         this.startNode = startNode;
         Color = CreateFieldInput(nameof(Color), "COLOR", _ => new Color(0, 0, 0, 255));
-        Output = CreateOutput<ChunkyImage>(nameof(Output), "OUTPUT", null);
+        Output = CreateOutput<Image>(nameof(Output), "OUTPUT", null);
     }
 
-    protected override ChunkyImage? OnExecute(KeyFrameTime frameTime)
+    protected override Image? OnExecute(KeyFrameTime frameTime)
     {
-        if (startNode.Image.Value is not { CommittedSize: var size })
+        if (startNode.Image.Value is not { Size: var size })
         {
             return null;
         }
         
+        startNode.PreparePixmap();
+        
         var width = size.X;
         var height = size.Y;
 
-        Output.Value = new ChunkyImage(size);
         using var surface = new Surface(size);
 
         for (int y = 0; y < width; y++)
@@ -49,8 +51,7 @@ public class ModifyImageRightNode : Node
             }
         }
 
-        Output.Value.EnqueueDrawImage(VecI.Zero, surface);
-        Output.Value.CommitChanges();
+        Output.Value = surface.DrawingSurface.Snapshot();
 
         return Output.Value;
     }

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

@@ -1,6 +1,7 @@
 using PixiEditor.ChangeableDocument.Changeables.Animations;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
+using PixiEditor.DrawingApi.Core.Surface.ImageData;
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 
@@ -25,7 +26,7 @@ public class SeparateColorNode : Node
         A = CreateFieldOutput(nameof(A), "A", ctx => Color.Value(ctx).A / 255d);
     }
 
-    protected override ChunkyImage? OnExecute(KeyFrameTime frameTime)
+    protected override Image? OnExecute(KeyFrameTime frameTime)
     {
         return null;
     }

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

@@ -1,5 +1,6 @@
 using PixiEditor.ChangeableDocument.Changeables.Animations;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
+using PixiEditor.DrawingApi.Core.Surface.ImageData;
 using PixiEditor.Numerics;
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
@@ -19,7 +20,7 @@ public class SeparateVecDNode : Node
         Vector = CreateFieldInput("Vector", "VECTOR", _ => new VecD(0, 0));
     }
 
-    protected override ChunkyImage? OnExecute(KeyFrameTime frameTime)
+    protected override Image? OnExecute(KeyFrameTime frameTime)
     {
         return null;
     }

+ 4 - 0
src/PixiEditor.DrawingApi.Core/Bridge/NativeObjectsImpl/IPixmapImplementation.cs

@@ -1,6 +1,8 @@
 using System;
+using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.DrawingApi.Core.Surface;
 using PixiEditor.DrawingApi.Core.Surface.ImageData;
+using PixiEditor.Numerics;
 
 namespace PixiEditor.DrawingApi.Core.Bridge.NativeObjectsImpl;
 
@@ -8,6 +10,8 @@ public interface IPixmapImplementation
 {
     public void Dispose(IntPtr objectPointer);
 
+    public Color GetPixelColor(IntPtr objectPointer, VecI position);
+    
     public IntPtr GetPixels(IntPtr objectPointer);
 
     public Span<T> GetPixelSpan<T>(Pixmap pixmap)

+ 2 - 0
src/PixiEditor.DrawingApi.Core/Bridge/Operations/IImageImplementation.cs

@@ -1,4 +1,5 @@
 using System;
+using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.DrawingApi.Core.Numerics;
 using PixiEditor.DrawingApi.Core.Surface;
 using PixiEditor.DrawingApi.Core.Surface.ImageData;
@@ -21,5 +22,6 @@ namespace PixiEditor.DrawingApi.Core.Bridge.Operations
         public int GetHeight(IntPtr objectPointer);
         public object GetNativeImage(IntPtr objectPointer);
         public Image Clone(Image image);
+        public Pixmap PeekPixels(IntPtr objectPointer);
     }
 }

+ 5 - 0
src/PixiEditor.DrawingApi.Core/Surface/ImageData/Image.cs

@@ -56,6 +56,11 @@ namespace PixiEditor.DrawingApi.Core.Surface.ImageData
             return DrawingBackendApi.Current.ImageImplementation.Encode(this, format, quality);
         }
 
+        public Pixmap PeekPixels()
+        {
+            return DrawingBackendApi.Current.ImageImplementation.PeekPixels(ObjectPointer);
+        }
+
         public object Clone()
         {
             return DrawingBackendApi.Current.ImageImplementation.Clone(this);

+ 9 - 0
src/PixiEditor.DrawingApi.Core/Surface/Pixmap.cs

@@ -1,6 +1,8 @@
 using System;
 using PixiEditor.DrawingApi.Core.Bridge;
+using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.DrawingApi.Core.Surface.ImageData;
+using PixiEditor.Numerics;
 
 namespace PixiEditor.DrawingApi.Core.Surface;
 
@@ -39,6 +41,13 @@ public class Pixmap : NativeObject
         DrawingBackendApi.Current.PixmapImplementation.Dispose(ObjectPointer);
     }
 
+    public Color GetPixelColor(int x, int y) => GetPixelColor(new VecI(x, y));
+    
+    public Color GetPixelColor(VecI position)
+    {
+        return DrawingBackendApi.Current.PixmapImplementation.GetPixelColor(ObjectPointer, position);
+    }
+
     public IntPtr GetPixels()
     {
         return DrawingBackendApi.Current.PixmapImplementation.GetPixels(ObjectPointer);

+ 10 - 1
src/PixiEditor.DrawingApi.Skia/Implementations/SkiaImageImplementation.cs

@@ -12,11 +12,13 @@ namespace PixiEditor.DrawingApi.Skia.Implementations
     public class SkiaImageImplementation : SkObjectImplementation<SKImage>, IImageImplementation
     {
         private readonly SkObjectImplementation<SKData> _imgImplementation;
+        private readonly SkiaPixmapImplementation _pixmapImplementation;
         private SkObjectImplementation<SKSurface>? _surfaceImplementation;
         
-        public SkiaImageImplementation(SkObjectImplementation<SKData> imgDataImplementation)
+        public SkiaImageImplementation(SkObjectImplementation<SKData> imgDataImplementation, SkiaPixmapImplementation pixmapImplementation)
         {
             _imgImplementation = imgDataImplementation;
+            _pixmapImplementation = pixmapImplementation;
         }
         
         public void SetSurfaceImplementation(SkObjectImplementation<SKSurface> surfaceImplementation)
@@ -120,6 +122,13 @@ namespace PixiEditor.DrawingApi.Skia.Implementations
             return new Image(clone.Handle);
         }
 
+        public Pixmap PeekPixels(IntPtr objectPointer)
+        {
+            var nativePixmap = ManagedInstances[objectPointer].PeekPixels();
+
+            return _pixmapImplementation.CreateFrom(nativePixmap);
+        }
+
         public object GetNativeImage(IntPtr objectPointer)
         {
             return ManagedInstances[objectPointer];

+ 7 - 0
src/PixiEditor.DrawingApi.Skia/Implementations/SkiaPixmapImplementation.cs

@@ -1,7 +1,9 @@
 using System;
 using PixiEditor.DrawingApi.Core.Bridge.NativeObjectsImpl;
+using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.DrawingApi.Core.Surface;
 using PixiEditor.DrawingApi.Core.Surface.ImageData;
+using PixiEditor.Numerics;
 using SkiaSharp;
 
 namespace PixiEditor.DrawingApi.Skia.Implementations
@@ -21,6 +23,11 @@ namespace PixiEditor.DrawingApi.Skia.Implementations
             ManagedInstances.TryRemove(objectPointer, out _);
         }
 
+        public Color GetPixelColor(IntPtr objectPointer, VecI position)
+        {
+            return ManagedInstances[objectPointer].GetPixelColor(position.X, position.Y).ToBackendColor();
+        }
+
         public IntPtr GetPixels(IntPtr objectPointer)
         {
             return ManagedInstances[objectPointer].GetPixels();

+ 3 - 3
src/PixiEditor.DrawingApi.Skia/SkiaDrawingBackend.cs

@@ -28,9 +28,6 @@ namespace PixiEditor.DrawingApi.Skia
             SkiaImgDataImplementation dataImpl = new SkiaImgDataImplementation();
             ImgDataImplementation = dataImpl;
             
-            SkiaImageImplementation imgImpl = new SkiaImageImplementation(dataImpl);
-            ImageImplementation = imgImpl;
-            
             SkiaColorFilterImplementation colorFilterImpl = new SkiaColorFilterImplementation();
             ColorFilterImplementation = colorFilterImpl;
             
@@ -51,6 +48,9 @@ namespace PixiEditor.DrawingApi.Skia
             SkiaPixmapImplementation pixmapImpl = new SkiaPixmapImplementation(colorSpaceImpl);
             PixmapImplementation = pixmapImpl;
             
+            SkiaImageImplementation imgImpl = new SkiaImageImplementation(dataImpl, pixmapImpl);
+            ImageImplementation = imgImpl;
+
             SkiaBitmapImplementation bitmapImpl = new SkiaBitmapImplementation(imgImpl);
             BitmapImplementation = bitmapImpl;