Explorar el Código

Performance improvement

flabbet hace 5 años
padre
commit
bf9bff6338

+ 1 - 0
PixiEditor/Models/Controllers/BitmapOperationsUtility.cs

@@ -58,6 +58,7 @@ namespace PixiEditor.Models.Controllers
 
         public void StopAction()
         {
+            if (_lastModifiedLayers == null) return;
             for (int i = 0; i < _lastModifiedLayers.Length; i++)
             {
                 BitmapPixelChanges oldValues = GetOldPixelsValues(_lastModifiedLayers[i].PixelChanges.ChangedPixels.Keys.ToArray());

+ 9 - 9
PixiEditor/Models/Layers/Layer.cs

@@ -88,16 +88,16 @@ namespace PixiEditor.Models.Layers
         public void ApplyPixels(BitmapPixelChanges pixels)
         {
             if (pixels.ChangedPixels == null) return;
-            LayerBitmap.Lock();
-
-            foreach (var coords in pixels.ChangedPixels)
-            {
-                if (coords.Key.X > Width - 1 || coords.Key.X < 0 || coords.Key.Y < 0 || coords.Key.Y > Height - 1) continue;
-                LayerBitmap.SetPixel(Math.Clamp(coords.Key.X, 0, Width - 1), Math.Clamp(coords.Key.Y, 0, Height - 1),
-                    coords.Value);
+            using (LayerBitmap.GetBitmapContext())
+            {
+
+                foreach (var coords in pixels.ChangedPixels)
+                {
+                    if (coords.Key.X > Width - 1 || coords.Key.X < 0 || coords.Key.Y < 0 || coords.Key.Y > Height - 1) continue;
+                    LayerBitmap.SetPixel(Math.Clamp(coords.Key.X, 0, Width - 1), Math.Clamp(coords.Key.Y, 0, Height - 1),
+                        coords.Value);
+                }
             }
-
-            LayerBitmap.Unlock();
         }
 
         public void Clear()