瀏覽代碼

Merge branch 'master' of https://github.com/PixiEditor/PixiEditor

Krzysztof Krysiński 1 周之前
父節點
當前提交
0a0fbeedc8

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit b7cc8bd1ee26e2d35e820a0b2a4a8dfdcb8b93ea
+Subproject commit ecaab29256ad9ebbcf8ba3a0c19d763f64e9d0e1

+ 3 - 3
src/PixiEditor.ChangeableDocument/Changes/Drawing/FloodFill/FloodFillHelper.cs

@@ -80,7 +80,7 @@ public static class FloodFillHelper
             srgbSurface.DrawingSurface.Canvas.DrawPixel(0, 0, srgbPaint);
             using var processingSurface = Surface.ForProcessing(VecI.One, document.ProcessingColorSpace);
             processingSurface.DrawingSurface.Canvas.DrawSurface(srgbSurface.DrawingSurface, 0, 0);
-            var fixedColor = processingSurface.GetRawPixelPrecise(VecI.Zero);
+            var fixedColor = processingSurface.GetRawPixelPrecise(VecI.Zero).Premultiplied();
 
             uLongColor = fixedColor.ToULong();
             colorSpaceCorrectedColor = fixedColor;
@@ -226,7 +226,7 @@ public static class FloodFillHelper
     {
         var rawPixelRef = referenceChunk.Surface.GetRawPixelPrecise(pos);
         // color should be a fixed color
-        if ((Color)rawPixelRef == (Color)color || (Color)drawingChunk.Surface.GetRawPixelPrecise(pos) == (Color)color)
+        if ((Color)rawPixelRef == (Color)color || (Color)drawingChunk.Surface.GetRawPixelPrecise(pos).Premultiplied() == (Color)color)
             return null;
         if (checkFirstPixel && !bounds.IsWithinBounds(rawPixelRef))
             return null;
@@ -240,7 +240,7 @@ public static class FloodFillHelper
         using var refPixmap = referenceChunk.Surface.PeekPixels();
         Half* refArray = (Half*)refPixmap.GetPixels();
 
-        Surface cpuSurface = Surface.ForProcessing(new VecI(chunkSize), referenceChunk.Surface.ColorSpace);
+        using Surface cpuSurface = Surface.ForProcessing(new VecI(chunkSize), referenceChunk.Surface.ColorSpace);
         cpuSurface.DrawingSurface.Canvas.DrawSurface(drawingChunk.Surface.DrawingSurface, 0, 0);
         using var drawPixmap = cpuSurface.PeekPixels();
         Half* drawArray = (Half*)drawPixmap.GetPixels();

+ 88 - 0
tests/PixiEditor.Tests/FloodFillTests.cs

@@ -0,0 +1,88 @@
+using Avalonia.Headless.XUnit;
+using Drawie.Backend.Core.ColorsImpl;
+using Drawie.Backend.Core.Surfaces.ImageData;
+using Drawie.Numerics;
+using PixiEditor.ChangeableDocument.Changes.Drawing.FloodFill;
+using PixiEditor.ChangeableDocument.Enums;
+using PixiEditor.Tests;
+using PixiEditor.ViewModels.Document;
+
+namespace PixiEditor.Backend.Tests;
+
+public class FloodFillTests : FullPixiEditorTest
+{
+    [AvaloniaTheory]
+    [InlineData(0, 64)]
+    [InlineData(130, 64)]
+    [InlineData(255, 64)]
+    [InlineData(0, 512)]
+    [InlineData(130, 512)]
+    [InlineData(255, 512)]
+    [InlineData(0, 2048)]
+    [InlineData(130, 2048)]
+    [InlineData(255, 2048)]
+    public void TestThatFloodFillHelperFinishesLinearCs(byte alpha, int imgSize)
+    {
+        var doc = DocumentViewModel.Build(b => b.WithSize(imgSize, imgSize)
+            .WithGraph(g =>
+                g.WithImageLayerNode(
+                        "layer", new VecI(imgSize), ColorSpace.CreateSrgbLinear(), out var id)
+                    .WithOutputNode(id, "Output")));
+
+        var color = Color.FromHsv(0f, 59.3f, 82.6f, alpha);
+
+        var dict = FloodFillHelper.FloodFill([doc.NodeGraph.StructureTree.Members[0].Id],
+            doc.AccessInternalReadOnlyDocument(),
+            null, VecI.Zero, color, 0, 0, false, FloodFillMode.Replace);
+
+        Assert.NotNull(dict);
+        foreach (var kvp in dict)
+        {
+            Assert.NotNull(kvp.Value);
+            var srgbPixel = kvp.Value.Surface.GetSrgbPixel(VecI.Zero);
+            if (alpha == 0)
+                Assert.Equal(Color.FromRgba(0, 0, 0, 0), srgbPixel);
+            else
+                Assert.Equal(color, srgbPixel);
+        }
+    }
+
+    [AvaloniaTheory]
+    [InlineData(0, 64)]
+    [InlineData(130, 64)]
+    [InlineData(255, 64)]
+    [InlineData(0, 512)]
+    [InlineData(130, 512)]
+    [InlineData(255, 512)]
+    [InlineData(0, 2048)]
+    [InlineData(130, 2048)]
+    [InlineData(255, 2048)]
+    public void TestThatFloodFillHelperFinishesSrgbCs(byte alpha, int imgSize)
+    {
+        var doc = DocumentViewModel.Build(b => b.WithSize(imgSize, imgSize)
+            .WithGraph(g =>
+                g.WithImageLayerNode(
+                    "layer", new VecI(imgSize), ColorSpace.CreateSrgb(), out var id).WithOutputNode(id, "Output")));
+
+        FloodFillHelper.FloodFill([doc.NodeGraph.StructureTree.Members[0].Id], doc.AccessInternalReadOnlyDocument(),
+            null, VecI.Zero,
+            Color.FromHsv(0f, 59.3f, 82.6f, alpha), 0, 0, false, FloodFillMode.Replace);
+
+        var color = Color.FromHsv(0f, 59.3f, 82.6f, alpha);
+
+        var dict = FloodFillHelper.FloodFill([doc.NodeGraph.StructureTree.Members[0].Id],
+            doc.AccessInternalReadOnlyDocument(),
+            null, VecI.Zero, color, 0, 0, false, FloodFillMode.Replace);
+
+        Assert.NotNull(dict);
+        foreach (var kvp in dict)
+        {
+            Assert.NotNull(kvp.Value);
+            var srgbPixel = kvp.Value.Surface.GetSrgbPixel(VecI.Zero);
+            if (alpha == 0)
+                Assert.Equal(Color.FromRgba(0, 0, 0, 0), srgbPixel);
+            else
+                Assert.Equal(color, srgbPixel);
+        }
+    }
+}

+ 0 - 2
tests/PixiEditor.Tests/PixiEditorTest.cs

@@ -1,6 +1,5 @@
 using Drawie.Backend.Core;
 using Drawie.Backend.Core.Bridge;
-using Drawie.Interop.Avalonia.Core;
 using Drawie.Numerics;
 using Drawie.RenderApi;
 using Drawie.RenderApi.OpenGL;
@@ -9,7 +8,6 @@ using Drawie.Silk;
 using Drawie.Skia;
 using Drawie.Windowing;
 using DrawiEngine;
-using DrawiEngine.Desktop;
 using Microsoft.Extensions.DependencyInjection;
 using PixiEditor.Extensions.Runtime;
 using PixiEditor.Helpers;