Browse Source

Minor performance boost

flabbet 5 years ago
parent
commit
24e6f28e87

+ 1 - 1
PixiEditorDotNetCore3/Models/Images/BitmapConverter.cs

@@ -17,6 +17,6 @@ namespace PixiEditorDotNetCore3.Models.Images
             WriteableBitmap bitmap = BitmapFactory.New(currentBitmapWidth, currentBitmapHeight);
             WriteableBitmap bitmap = BitmapFactory.New(currentBitmapWidth, currentBitmapHeight);
             bitmap.FromByteArray(byteArray);
             bitmap.FromByteArray(byteArray);
             return bitmap;
             return bitmap;
-        }
+        }      
     }
     }
 }
 }

+ 2 - 0
PixiEditorDotNetCore3/Models/Layers/Layer.cs

@@ -46,10 +46,12 @@ namespace PixiEditorDotNetCore3.Models.Layers
 
 
         public void ApplyPixels(BitmapPixelChanges pixels, Color color)
         public void ApplyPixels(BitmapPixelChanges pixels, Color color)
         {
         {
+            LayerBitmap.Lock();
             foreach (var coords in pixels.ChangedCoordinates)
             foreach (var coords in pixels.ChangedCoordinates)
             {
             {
                 LayerBitmap.SetPixel(Math.Clamp(coords.X, 0, Width - 1), Math.Clamp(coords.Y, 0, Height - 1), color);
                 LayerBitmap.SetPixel(Math.Clamp(coords.X, 0, Width - 1), Math.Clamp(coords.Y, 0, Height - 1), color);
             }
             }
+            LayerBitmap.Unlock();
         }
         }
     }
     }
 }
 }

+ 0 - 29
PixiEditorDotNetCore3/Models/Tools/ToolManager.cs

@@ -1,29 +0,0 @@
-using PixiEditor.Helpers;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace PixiEditorDotNetCore3.Models.Tools
-{
-    class ToolManager : NotifyableObject
-    {
-
-        private ToolType _activeTool;
-
-        public ToolType ActiveTool
-        {
-            get { return _activeTool; }
-            set
-            {
-                if (_activeTool != value)
-                {
-                    _activeTool = value;
-                    RaisePropertyChanged("ActiveTool");
-                }
-            }
-        }
-    }
-}

+ 1 - 1
PixiEditorDotNetCore3/Views/MainWindow.xaml

@@ -11,7 +11,7 @@
         xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
         xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
         xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
         xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
         mc:Ignorable="d"
         mc:Ignorable="d"
-        Title="Pixi" Height="1000" Width="1600" Background="#FF252424" WindowStartupLocation="CenterScreen"  WindowState="Maximized" DataContext="{DynamicResource ViewModelMain}">
+        Title="PixiEditor" Height="1000" Width="1600" Background="#FF252424" WindowStartupLocation="CenterScreen"  WindowState="Maximized" DataContext="{DynamicResource ViewModelMain}">
     <Window.Resources>
     <Window.Resources>
         <vm:ViewModelMain x:Key="ViewModelMain"/>
         <vm:ViewModelMain x:Key="ViewModelMain"/>
         <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
         <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter"/>

+ 28 - 0
PixiEditorTests/PerformanceTests/BitmapOperationsTests.cs

@@ -0,0 +1,28 @@
+using NUnit.Framework;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Windows.Media.Imaging;
+
+namespace PixiEditorTests.PerformanceTests
+{
+    [TestFixture]
+    public class BitmapOperationsTests
+    {
+        [TestCase(16,16)]
+        [TestCase(128, 128)]
+        [TestCase(512, 512)]
+        [TestCase(1024, 1024)]
+        [TestCase(2046, 2046)]
+        [TestCase(4096, 4096)]
+        public void FillBitmapWithPixelsTest(int width, int height)
+        {
+            WriteableBitmap bitmap = BitmapFactory.New(width, height);
+            for (int i = 0; i < width * height; i++)
+            {
+                bitmap.SetPixeli(i, 0xFFFFF);
+            }
+            Assert.Pass();
+        }
+    }
+}