Thomas 2 лет назад
Родитель
Сommit
0e84090c31
1 измененных файлов с 14 добавлено и 5 удалено
  1. 14 5
      UICatalog/Scenarios/Animation.cs

+ 14 - 5
UICatalog/Scenarios/Animation.cs

@@ -56,6 +56,7 @@ namespace UICatalog.Scenarios {
 			Task.Run(()=>{
 			Task.Run(()=>{
 				while(!isDisposed)
 				while(!isDisposed)
 				{
 				{
+					// When updating from a Thread/Task always use Invoke
 					Application.MainLoop.Invoke(()=>
 					Application.MainLoop.Invoke(()=>
 					{
 					{
 						imageView.NextFrame();
 						imageView.NextFrame();
@@ -140,6 +141,7 @@ namespace UICatalog.Scenarios {
 
 
 			private Image<Rgba32>[] fullResImages;
 			private Image<Rgba32>[] fullResImages;
 			private Image<Rgba32>[] matchSizes;
 			private Image<Rgba32>[] matchSizes;
+			private string[] brailleCache;
 
 
 			Rect oldSize = Rect.Empty;
 			Rect oldSize = Rect.Empty;
 
 
@@ -150,6 +152,7 @@ namespace UICatalog.Scenarios {
 
 
 				fullResImages = new Image<Rgba32>[frameCount];
 				fullResImages = new Image<Rgba32>[frameCount];
 				matchSizes = new Image<Rgba32>[frameCount];
 				matchSizes = new Image<Rgba32>[frameCount];
+				brailleCache = new string[frameCount];
 
 
 				for(int i=0;i<frameCount-1;i++)
 				for(int i=0;i<frameCount-1;i++)
 				{
 				{
@@ -172,10 +175,12 @@ namespace UICatalog.Scenarios {
 				{
 				{
 					// Invalidate cached images now size has changed
 					// Invalidate cached images now size has changed
 					matchSizes = new Image<Rgba32>[frameCount];
 					matchSizes = new Image<Rgba32>[frameCount];
+					brailleCache = new string[frameCount];
 					oldSize = bounds;
 					oldSize = bounds;
 				}
 				}
 
 
 				var imgScaled = matchSizes[currentFrame];
 				var imgScaled = matchSizes[currentFrame];
+				var braille = brailleCache[currentFrame];
 
 
 				if(imgScaled == null)
 				if(imgScaled == null)
 				{
 				{
@@ -185,14 +190,19 @@ namespace UICatalog.Scenarios {
 					var newSize = Math.Min(bounds.Width,bounds.Height);
 					var newSize = Math.Min(bounds.Width,bounds.Height);
 
 
 					// generate one
 					// generate one
-					matchSizes[currentFrame] = imgFull.Clone (
+					matchSizes[currentFrame] = imgScaled = imgFull.Clone (
 						x => x.Resize (
 						x => x.Resize (
 							 newSize * BitmapToBraille.CHAR_HEIGHT,
 							 newSize * BitmapToBraille.CHAR_HEIGHT,
 							 newSize * BitmapToBraille.CHAR_HEIGHT));
 							 newSize * BitmapToBraille.CHAR_HEIGHT));
+				}
 
 
+				if(braille == null)
+				{
+					brailleCache[currentFrame] = braille = GetBraille(matchSizes[currentFrame]);
 				}
 				}
 
 
-				var lines = GetBraille(matchSizes[currentFrame]);
+
+				var lines = braille.Split('\n');
 
 
 				for(int y = 0; y < lines.Length;y++)
 				for(int y = 0; y < lines.Length;y++)
 				{
 				{
@@ -204,15 +214,14 @@ namespace UICatalog.Scenarios {
 				}
 				}
 			}
 			}
 
 
-			private string[] GetBraille (Image<Rgba32> img)
+			private string GetBraille (Image<Rgba32> img)
 			{
 			{
 				var braille = new BitmapToBraille(
 				var braille = new BitmapToBraille(
 					img.Width,
 					img.Width,
 					img.Height,
 					img.Height,
 					(x,y)=>IsLit(img,x,y));
 					(x,y)=>IsLit(img,x,y));
 
 
-				var pix = braille.GenerateImage();
-				return pix.Split('\n');
+				return braille.GenerateImage();
 			}
 			}
 
 
 			private bool IsLit (Image<Rgba32> img, int x, int y)
 			private bool IsLit (Image<Rgba32> img, int x, int y)