Skip to content

Commit

Permalink
NpcNameFinder: use Pararell.For instead of raw for loop to speed up t…
Browse files Browse the repository at this point in the history
…he image processing.
  • Loading branch information
Xian55 committed Feb 12, 2022
1 parent 1914e4f commit 2667e64
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions SharedLib/NpcFinder/NpcNameFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Linq;
using System.Drawing.Imaging;
using System.Threading;
using System.Diagnostics;
using System.Threading.Tasks;

namespace SharedLib.NpcFinder
{
Expand Down Expand Up @@ -336,7 +338,8 @@ private void PopulateLinesOfNpcNames()
BitmapData bitmapData = bitmapProvider.Bitmap.LockBits(new Rectangle(0, 0, bitmapProvider.Bitmap.Width, bitmapProvider.Bitmap.Height), ImageLockMode.ReadOnly, bitmapProvider.Bitmap.PixelFormat);
int bytesPerPixel = Bitmap.GetPixelFormatSize(bitmapProvider.Bitmap.PixelFormat) / 8;

for (int y = Area.Top; y < Area.Height; y += incY)
//for (int y = Area.Top; y < Area.Height; y += incY)
Parallel.For(Area.Top, Area.Height, y =>
{
bool isEndOfSection;
var lengthStart = -1;
Expand Down Expand Up @@ -373,7 +376,7 @@ private void PopulateLinesOfNpcNames()
{
npcNameLine.Add(new LineOfNpcName(lengthStart, lengthEnd, y));
}
}
});

bitmapProvider.Bitmap.UnlockBits(bitmapData);
}
Expand Down

0 comments on commit 2667e64

Please sign in to comment.