Browse Source

Fixed flood fill losing precision

Krzysztof Krysiński 1 month ago
parent
commit
0fd4ac2649

+ 11 - 0
src/ChunkyImageLib/ColorEx.cs

@@ -14,4 +14,15 @@ public static class ColorEx
         ptr[3] = (Half)(normalizedAlpha);
         return result;
     }
+
+    public static unsafe ulong ToULong(this ColorF colorF)
+    {
+        ulong result = 0;
+        Half* ptr = (Half*)&result;
+        ptr[0] = (Half)colorF.R;
+        ptr[1] = (Half)colorF.G;
+        ptr[2] = (Half)colorF.B;
+        ptr[3] = (Half)colorF.A;
+        return result;
+    }
 }

+ 1 - 1
src/ChunkyImageLib/Operations/ReplaceColorOperation.cs

@@ -35,7 +35,7 @@ internal class ReplaceColorOperation : IDrawOperation
             targetColorBits = newColor.TransformColor(transform).ToULong();
 
             var transformOld = targetChunk.Surface.ImageInfo.ColorSpace.GetTransformFunction();
-            colorBounds = new ColorBounds(oldColor.TransformColor(transform));
+            colorBounds = new ColorBounds((Color)oldColor.TransformColor(transform));
         }
 
         ReplaceColor(colorBounds, targetColorBits, targetChunk);

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit 896dd056b0b37774fe22bb615aecdc19fbc83763
+Subproject commit 38fe5456e1e82664ece3eb9f742a29ee60744ed5

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

@@ -71,7 +71,7 @@ public static class FloodFillHelper
 
             var fixedColor = drawingColor.TransformColor(srgbTransform);
             uLongColor = fixedColor.ToULong();
-            colorSpaceCorrectedColor = fixedColor;
+            colorSpaceCorrectedColor = (Color)fixedColor;
         }
 
         if ((colorSpaceCorrectedColor.A == 0) || colorToReplace == colorSpaceCorrectedColor)