|
@@ -8,7 +8,12 @@ using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
|
+using System.Runtime.CompilerServices;
|
|
|
|
+using System.Runtime.InteropServices;
|
|
|
|
+using System.Threading;
|
|
|
|
+using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows;
|
|
|
|
+using System.Windows.Media;
|
|
|
|
|
|
namespace PixiEditor.Models.Layers
|
|
namespace PixiEditor.Models.Layers
|
|
{
|
|
{
|
|
@@ -31,6 +36,7 @@ namespace PixiEditor.Models.Layers
|
|
|
|
|
|
private string layerHighlightColor = "#666666";
|
|
private string layerHighlightColor = "#666666";
|
|
|
|
|
|
|
|
+
|
|
public Layer(string name, int maxWidth, int maxHeight)
|
|
public Layer(string name, int maxWidth, int maxHeight)
|
|
{
|
|
{
|
|
Name = name;
|
|
Name = name;
|
|
@@ -693,5 +699,58 @@ namespace PixiEditor.Models.Layers
|
|
Width = newWidth;
|
|
Width = newWidth;
|
|
Height = newHeight;
|
|
Height = newHeight;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public void ReplaceColor(SKColor oldColor, SKColor newColor)
|
|
|
|
+ {
|
|
|
|
+ if (LayerBitmap == null)
|
|
|
|
+ {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Stopwatch sw = new Stopwatch();
|
|
|
|
+
|
|
|
|
+ sw.Start();
|
|
|
|
+
|
|
|
|
+ int maxThreads = Environment.ProcessorCount;
|
|
|
|
+ int rowsPerThread = Height / maxThreads;
|
|
|
|
+
|
|
|
|
+ Thread[] threads = new Thread[maxThreads];
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < maxThreads; i++)
|
|
|
|
+ {
|
|
|
|
+ var i1 = i;
|
|
|
|
+ threads[i] = new Thread(() =>
|
|
|
|
+ {
|
|
|
|
+ int startRow = i1 * rowsPerThread;
|
|
|
|
+ int endRow = (i1 + 1) * rowsPerThread;
|
|
|
|
+ if (i1 == maxThreads - 1)
|
|
|
|
+ {
|
|
|
|
+ endRow = Height;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (int y = startRow; y < endRow; y++)
|
|
|
|
+ {
|
|
|
|
+ for (int x = 0; x < Width; x++)
|
|
|
|
+ {
|
|
|
|
+ if (LayerBitmap.GetSRGBPixel(x, y) == oldColor)
|
|
|
|
+ {
|
|
|
|
+ LayerBitmap.SetSRGBPixelUnmanaged(x, y, newColor);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ threads[i].Start();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ threads.ToList().ForEach(x => x.Join());
|
|
|
|
+
|
|
|
|
+ sw.Stop();
|
|
|
|
+
|
|
|
|
+ layerBitmap.SkiaSurface.Canvas.DrawSurface(layerBitmap.SkiaSurface, 0, 0, new SKPaint { BlendMode = SKBlendMode.Dst });
|
|
|
|
+
|
|
|
|
+ InvokeLayerBitmapChange();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|