|
@@ -1,7 +1,5 @@
|
|
-using System;
|
|
|
|
-using System.Collections.Generic;
|
|
|
|
|
|
+using System.Collections.Generic;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media;
|
|
-using System.Windows.Media.Imaging;
|
|
|
|
using PixiEditor.Models.DataHolders;
|
|
using PixiEditor.Models.DataHolders;
|
|
using PixiEditor.Models.Layers;
|
|
using PixiEditor.Models.Layers;
|
|
using PixiEditor.Models.Position;
|
|
using PixiEditor.Models.Position;
|
|
@@ -23,43 +21,42 @@ namespace PixiEditor.Models.Tools.Tools
|
|
return Only(ForestFire(layer, coordinates[0], color), layer);
|
|
return Only(ForestFire(layer, coordinates[0], color), layer);
|
|
}
|
|
}
|
|
|
|
|
|
- public BitmapPixelChanges ForestFire(Layer layer, Coordinates startingCoords, Color newColor)
|
|
|
|
|
|
+ private BitmapPixelChanges ForestFire(Layer layer, Coordinates startingCoords, Color newColor)
|
|
{
|
|
{
|
|
List<Coordinates> changedCoords = new List<Coordinates>();
|
|
List<Coordinates> changedCoords = new List<Coordinates>();
|
|
|
|
|
|
- Layer clone = layer.Clone();
|
|
|
|
int width = ViewModelMain.Current.BitmapManager.ActiveDocument.Width;
|
|
int width = ViewModelMain.Current.BitmapManager.ActiveDocument.Width;
|
|
int height = ViewModelMain.Current.BitmapManager.ActiveDocument.Height;
|
|
int height = ViewModelMain.Current.BitmapManager.ActiveDocument.Height;
|
|
|
|
|
|
|
|
+ var visited = new bool[width, height];
|
|
|
|
+
|
|
Color colorToReplace = layer.GetPixelWithOffset(startingCoords.X, startingCoords.Y);
|
|
Color colorToReplace = layer.GetPixelWithOffset(startingCoords.X, startingCoords.Y);
|
|
|
|
|
|
var stack = new Stack<Coordinates>();
|
|
var stack = new Stack<Coordinates>();
|
|
stack.Push(new Coordinates(startingCoords.X, startingCoords.Y));
|
|
stack.Push(new Coordinates(startingCoords.X, startingCoords.Y));
|
|
-
|
|
|
|
- using(clone.LayerBitmap.GetBitmapContext(ReadWriteMode.ReadWrite))
|
|
|
|
|
|
+
|
|
|
|
+ while (stack.Count > 0)
|
|
{
|
|
{
|
|
- while (stack.Count > 0)
|
|
|
|
- {
|
|
|
|
- var cords = stack.Pop();
|
|
|
|
- var relativeCords = clone.GetRelativePosition(cords);
|
|
|
|
|
|
+ var cords = stack.Pop();
|
|
|
|
+ var relativeCords = layer.GetRelativePosition(cords);
|
|
|
|
|
|
- if (cords.X < 0 || cords.X > width - 1) continue;
|
|
|
|
- if (cords.Y < 0 || cords.Y > height - 1) continue;
|
|
|
|
- if (clone.GetPixel(relativeCords.X, relativeCords.Y) == newColor) continue;
|
|
|
|
|
|
+ if (cords.X < 0 || cords.X > width - 1) continue;
|
|
|
|
+ if (cords.Y < 0 || cords.Y > height - 1) continue;
|
|
|
|
+ if (visited[cords.X, cords.Y]) continue;
|
|
|
|
+ if (layer.GetPixel(relativeCords.X, relativeCords.Y) == newColor) continue;
|
|
|
|
|
|
- if (clone.GetPixel(relativeCords.X, relativeCords.Y) == colorToReplace)
|
|
|
|
- {
|
|
|
|
- changedCoords.Add(new Coordinates(cords.X, cords.Y));
|
|
|
|
- clone.SetPixel(new Coordinates(cords.X, cords.Y), newColor);
|
|
|
|
- stack.Push(new Coordinates(cords.X, cords.Y - 1));
|
|
|
|
- stack.Push(new Coordinates(cords.X + 1, cords.Y));
|
|
|
|
- stack.Push(new Coordinates(cords.X, cords.Y + 1));
|
|
|
|
- stack.Push(new Coordinates(cords.X - 1, cords.Y));
|
|
|
|
- }
|
|
|
|
|
|
+ if (layer.GetPixel(relativeCords.X, relativeCords.Y) == colorToReplace)
|
|
|
|
+ {
|
|
|
|
+ changedCoords.Add(new Coordinates(cords.X, cords.Y));
|
|
|
|
+ visited[cords.X, cords.Y] = true;
|
|
|
|
+ stack.Push(new Coordinates(cords.X, cords.Y - 1));
|
|
|
|
+ stack.Push(new Coordinates(cords.X, cords.Y + 1));
|
|
|
|
+ stack.Push(new Coordinates(cords.X - 1, cords.Y));
|
|
|
|
+ stack.Push(new Coordinates(cords.X + 1, cords.Y));
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
return BitmapPixelChanges.FromSingleColoredArray(changedCoords, newColor);
|
|
return BitmapPixelChanges.FromSingleColoredArray(changedCoords, newColor);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|