mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Performance improvements
This commit is contained in:
parent
8dbcbe0758
commit
c1d57d5b7b
2 changed files with 28 additions and 26 deletions
|
@ -472,6 +472,9 @@ public static extern bool CreateProcess(string lpApplicationName, string lpComma
|
|||
|
||||
#region Other dll
|
||||
|
||||
[DllImport("msvcrt.dll")]
|
||||
public static extern int memcmp(IntPtr b1, IntPtr b2, long count);
|
||||
|
||||
/// <summary>
|
||||
/// Copy a block of memory.
|
||||
/// </summary>
|
||||
|
|
|
@ -858,42 +858,41 @@ private Bitmap CombineImagesV3(List<Bitmap> images)
|
|||
int matchIndex = 0;
|
||||
int matchLimit = currentImage.Height / 3;
|
||||
|
||||
using (UnsafeBitmap bmpResult = new UnsafeBitmap(result, true, ImageLockMode.ReadOnly))
|
||||
using (UnsafeBitmap bmpCurrentImage = new UnsafeBitmap(currentImage, true, ImageLockMode.ReadOnly))
|
||||
Rectangle rect = new Rectangle(0, result.Height - currentImage.Height,
|
||||
currentImage.Width - (currentImage.Width > ignoreRightOffset ? ignoreRightOffset : 0), currentImage.Height);
|
||||
|
||||
BitmapData bdResult = result.LockBits(new Rectangle(0, 0, result.Width, result.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
||||
BitmapData bdCurrentImage = currentImage.LockBits(new Rectangle(0, 0, currentImage.Width, currentImage.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
||||
int stride = bdResult.Stride;
|
||||
int strideCompare = stride / result.Width * rect.Width;
|
||||
int rectBottom = rect.Bottom - 1;
|
||||
|
||||
for (int currentImageY = currentImage.Height - 1; currentImageY >= 0 && matchCount < matchLimit; currentImageY--)
|
||||
{
|
||||
Rectangle rect = new Rectangle(0, result.Height - currentImage.Height,
|
||||
currentImage.Width - (currentImage.Width > ignoreRightOffset ? ignoreRightOffset : 0), currentImage.Height);
|
||||
int currentMatchCount = 0;
|
||||
|
||||
for (int currentImageY = currentImage.Height - 1; currentImageY >= 0 && matchCount < matchLimit; currentImageY--)
|
||||
for (int y = 0; currentImageY - y >= 0 && currentMatchCount < matchLimit; y++)
|
||||
{
|
||||
int currentMatchCount = 0;
|
||||
bool isMatch = true;
|
||||
|
||||
for (int y = 0; currentImageY - y >= 0 && isMatch && currentMatchCount < matchLimit; y++)
|
||||
if (NativeMethods.memcmp(bdResult.Scan0 + ((rectBottom - y) * stride), bdCurrentImage.Scan0 + ((currentImageY - y) * stride), strideCompare) == 0)
|
||||
{
|
||||
for (int x = rect.X; x < rect.Right; x++)
|
||||
{
|
||||
if (bmpResult.GetPixel(x, rect.Bottom - 1 - y) != bmpCurrentImage.GetPixel(x, currentImageY - y))
|
||||
{
|
||||
isMatch = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isMatch)
|
||||
{
|
||||
currentMatchCount++;
|
||||
}
|
||||
currentMatchCount++;
|
||||
}
|
||||
|
||||
if (currentMatchCount > matchCount)
|
||||
else
|
||||
{
|
||||
matchCount = currentMatchCount;
|
||||
matchIndex = currentImageY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentMatchCount > matchCount)
|
||||
{
|
||||
matchCount = currentMatchCount;
|
||||
matchIndex = currentImageY;
|
||||
}
|
||||
}
|
||||
|
||||
result.UnlockBits(bdResult);
|
||||
currentImage.UnlockBits(bdCurrentImage);
|
||||
|
||||
if (matchCount > 0)
|
||||
{
|
||||
Bitmap newResult = new Bitmap(result.Width, result.Height + currentImage.Height - matchIndex - 1);
|
||||
|
|
Loading…
Reference in a new issue