瀏覽代碼

Merge pull request #1230 from PixiEditor/fix/flood-fill-infinite-loop

Trasnform color using actual surfaces
Krzysztof Krysiński 2 周之前
父節點
當前提交
943f181b16
共有 1 個文件被更改,包括 8 次插入2 次删除
  1. 8 2
      src/PixiEditor.ChangeableDocument/Changes/Drawing/FloodFill/FloodFillHelper.cs

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

@@ -71,9 +71,15 @@ public static class FloodFillHelper
         ColorF colorSpaceCorrectedColor = drawingColor;
         ColorF colorSpaceCorrectedColor = drawingColor;
         if (!document.ProcessingColorSpace.IsSrgb)
         if (!document.ProcessingColorSpace.IsSrgb)
         {
         {
-            var srgbTransform = ColorSpace.CreateSrgb().GetTransformFunction();
+            // Mixing using actual surfaces is more accurate than using ColorTransformFn
+            // mismatch between actual surface color and transformed color here can lead to infinite loops
+            using Surface srgbSurface = Surface.ForProcessing(new VecI(1), ColorSpace.CreateSrgb());
+            using Paint srgbPaint = new Paint(){ Color = drawingColor };
+            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 = drawingColor.TransformColor(srgbTransform);
             uLongColor = fixedColor.ToULong();
             uLongColor = fixedColor.ToULong();
             colorSpaceCorrectedColor = fixedColor;
             colorSpaceCorrectedColor = fixedColor;
         }
         }