Browse Source

Fixed premultiplication in flood fill

Krzysztof Krysiński 1 week ago
parent
commit
60b9885be4

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