Browse Source

I was going to fix a bug, I was going to...

Equbuxu 4 years ago
parent
commit
0b5717b5eb

+ 6 - 0
PixiEditor/Helpers/LayerBitmapContext.cs

@@ -7,6 +7,12 @@ namespace PixiEditor.Helpers
 {
     class LayerBitmapContext : IDisposable
     {
+        public static Color Premultiply(Color c)
+        {
+            float fraction = c.A / 255f;
+            return Color.FromArgb(c.A, (byte)Math.Round(c.R * fraction), (byte)Math.Round(c.G * fraction), (byte)Math.Round(c.B * fraction));
+        }
+
         private Layer layer;
         private BitmapContext ctx;
         public LayerBitmapContext(Layer layer)

+ 1 - 3
PixiEditor/Models/Tools/Tools/FloodFill.cs

@@ -49,11 +49,9 @@ namespace PixiEditor.Models.Tools.Tools
 
             using (LayerBitmapContext ctx = new LayerBitmapContext(layer))
             {
-                float fraction = newColor.A / 255f;
-                Color premult = Color.FromArgb(colorToReplace.A, (byte)(colorToReplace.R * fraction), (byte)(colorToReplace.G * fraction), (byte)(colorToReplace.B * fraction));
+                Color premult = LayerBitmapContext.Premultiply(colorToReplace);
                 PerformLinearFill(ctx, changedCoords, floodFillQueue, startingCoords, width, ref premult, visited);
                 PerformFloodFIll(ctx, changedCoords, floodFillQueue, ref premult, width, height, visited);
-
             }
 
             return BitmapPixelChanges.FromSingleColoredArray(changedCoords, newColor);