Skip to content

Commit 2667e64

Browse files
committed
NpcNameFinder: use Pararell.For instead of raw for loop to speed up the image processing.
1 parent 1914e4f commit 2667e64

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

SharedLib/NpcFinder/NpcNameFinder.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using System.Linq;
77
using System.Drawing.Imaging;
88
using System.Threading;
9+
using System.Diagnostics;
10+
using System.Threading.Tasks;
911

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

339-
for (int y = Area.Top; y < Area.Height; y += incY)
341+
//for (int y = Area.Top; y < Area.Height; y += incY)
342+
Parallel.For(Area.Top, Area.Height, y =>
340343
{
341344
bool isEndOfSection;
342345
var lengthStart = -1;
@@ -373,7 +376,7 @@ private void PopulateLinesOfNpcNames()
373376
{
374377
npcNameLine.Add(new LineOfNpcName(lengthStart, lengthEnd, y));
375378
}
376-
}
379+
});
377380

378381
bitmapProvider.Bitmap.UnlockBits(bitmapData);
379382
}

0 commit comments

Comments
 (0)