|
@@ -1,11 +1,10 @@
|
|
|
-using PixiEditor.Helpers;
|
|
|
-using PixiEditor.Models.Controllers;
|
|
|
+using PixiEditor.Models.Controllers;
|
|
|
using PixiEditor.Models.DataHolders;
|
|
|
using PixiEditor.Models.Layers;
|
|
|
using PixiEditor.Models.Position;
|
|
|
+using SkiaSharp;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
|
-using System.Windows.Media;
|
|
|
|
|
|
namespace PixiEditor.Models.Tools.Tools
|
|
|
{
|
|
@@ -22,7 +21,7 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
|
|
|
public override string Tooltip => "Fills area with color. (G)";
|
|
|
|
|
|
- public override LayerChange[] Use(Layer layer, List<Coordinates> coordinates, Color color)
|
|
|
+ public override LayerChange[] Use(Layer layer, List<Coordinates> coordinates, SKColor color)
|
|
|
{
|
|
|
Stopwatch sw = new Stopwatch();
|
|
|
sw.Start();
|
|
@@ -32,12 +31,12 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- public BitmapPixelChanges LinearFill(Layer layer, Coordinates startingCoords, Color newColor)
|
|
|
+ public BitmapPixelChanges LinearFill(Layer layer, Coordinates startingCoords, SKColor newColor)
|
|
|
{
|
|
|
List<Coordinates> changedCoords = new List<Coordinates>();
|
|
|
Queue<FloodFillRange> floodFillQueue = new Queue<FloodFillRange>();
|
|
|
- Color colorToReplace = layer.GetPixelWithOffset(startingCoords.X, startingCoords.Y);
|
|
|
- if ((colorToReplace.A == 0 && newColor.A == 0) ||
|
|
|
+ SKColor colorToReplace = layer.GetPixelWithOffset(startingCoords.X, startingCoords.Y);
|
|
|
+ if ((colorToReplace.Alpha == 0 && newColor.Alpha == 0) ||
|
|
|
colorToReplace == newColor)
|
|
|
return BitmapPixelChanges.Empty;
|
|
|
|
|
@@ -47,20 +46,16 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
return BitmapPixelChanges.Empty;
|
|
|
var visited = new bool[width * height];
|
|
|
|
|
|
- using (LayerBitmapContext ctx = new LayerBitmapContext(layer))
|
|
|
- {
|
|
|
- Color premult = LayerBitmapContext.Premultiply(colorToReplace);
|
|
|
- PerformLinearFill(ctx, changedCoords, floodFillQueue, startingCoords, width, ref premult, visited);
|
|
|
- PerformFloodFIll(ctx, changedCoords, floodFillQueue, ref premult, width, height, visited);
|
|
|
- }
|
|
|
+ PerformLinearFill(layer, changedCoords, floodFillQueue, startingCoords, width, colorToReplace, visited);
|
|
|
+ PerformFloodFIll(layer, changedCoords, floodFillQueue, colorToReplace, width, height, visited);
|
|
|
|
|
|
return BitmapPixelChanges.FromSingleColoredArray(changedCoords, newColor);
|
|
|
}
|
|
|
|
|
|
private void PerformLinearFill(
|
|
|
- LayerBitmapContext layer,
|
|
|
+ Layer layer,
|
|
|
List<Coordinates> changedCoords, Queue<FloodFillRange> floodFillQueue,
|
|
|
- Coordinates coords, int width, ref Color colorToReplace, bool[] visited)
|
|
|
+ Coordinates coords, int width, SKColor colorToReplace, bool[] visited)
|
|
|
{
|
|
|
// Find the Left Edge of the Color Area
|
|
|
int fillXLeft = coords.X;
|
|
@@ -76,7 +71,7 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
// Move one pixel to the left
|
|
|
fillXLeft--;
|
|
|
// Exit the loop if we're at edge of the bitmap or the color area
|
|
|
- if (fillXLeft < 0 || visited[pixelIndex - 1] || !layer.IsPixelMatching(fillXLeft, coords.Y, colorToReplace))
|
|
|
+ if (fillXLeft < 0 || visited[pixelIndex - 1] || layer.GetPixelWithOffset(fillXLeft, coords.Y) != colorToReplace)
|
|
|
break;
|
|
|
}
|
|
|
int lastFilledPixelLeft = fillXLeft + 1;
|
|
@@ -92,7 +87,7 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
visited[pixelIndex] = true;
|
|
|
|
|
|
fillXRight++;
|
|
|
- if (fillXRight >= width || visited[pixelIndex + 1] || !layer.IsPixelMatching(fillXRight, coords.Y, colorToReplace))
|
|
|
+ if (fillXRight >= width || visited[pixelIndex + 1] || layer.GetPixelWithOffset(fillXRight, coords.Y) != colorToReplace)
|
|
|
break;
|
|
|
}
|
|
|
int lastFilledPixelRight = fillXRight - 1;
|
|
@@ -103,9 +98,9 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
}
|
|
|
|
|
|
private void PerformFloodFIll(
|
|
|
- LayerBitmapContext layer,
|
|
|
+ Layer layer,
|
|
|
List<Coordinates> changedCords, Queue<FloodFillRange> floodFillQueue,
|
|
|
- ref Color colorToReplace, int width, int height, bool[] pixelsVisited)
|
|
|
+ SKColor colorToReplace, int width, int height, bool[] pixelsVisited)
|
|
|
{
|
|
|
while (floodFillQueue.Count > 0)
|
|
|
{
|
|
@@ -120,11 +115,11 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
{
|
|
|
//START LOOP UPWARDS
|
|
|
//if we're not above the top of the bitmap and the pixel above this one is within the color tolerance
|
|
|
- if (range.Y > 0 && (!pixelsVisited[upPixelIndex]) && layer.IsPixelMatching(i, upY, colorToReplace))
|
|
|
- PerformLinearFill(layer, changedCords, floodFillQueue, new Coordinates(i, upY), width, ref colorToReplace, pixelsVisited);
|
|
|
+ if (range.Y > 0 && (!pixelsVisited[upPixelIndex]) && layer.GetPixelWithOffset(i, upY) == colorToReplace)
|
|
|
+ PerformLinearFill(layer, changedCords, floodFillQueue, new Coordinates(i, upY), width, colorToReplace, pixelsVisited);
|
|
|
//START LOOP DOWNWARDS
|
|
|
- if (range.Y < (height - 1) && (!pixelsVisited[downPixelxIndex]) && layer.IsPixelMatching(i, downY, colorToReplace))
|
|
|
- PerformLinearFill(layer, changedCords, floodFillQueue, new Coordinates(i, downY), width, ref colorToReplace, pixelsVisited);
|
|
|
+ if (range.Y < (height - 1) && (!pixelsVisited[downPixelxIndex]) && layer.GetPixel(i, downY) == colorToReplace)
|
|
|
+ PerformLinearFill(layer, changedCords, floodFillQueue, new Coordinates(i, downY), width, colorToReplace, pixelsVisited);
|
|
|
downPixelxIndex++;
|
|
|
upPixelIndex++;
|
|
|
}
|