Here works thread
int i - row where he works
if i == 0 , then other thread is working
private void Work() {
for (int i = 0; i < _workPool.Length; i++) {
if (_workPool[i] == 0) {
_workPool[i] = 1;
#region Work
int x = i * 40;
#endregion
int miss = 0;
for (int y = 0; (y + 40) < 240; y += 40) {
try {
Bitmap bCur = image.Clone(new Rectangle(x, y, 40, 40), PixelFormat.Format24bppRgb);
Bitmap bOld = old.Clone(new Rectangle(x, y, 40, 40), PixelFormat.Format24bppRgb);
miss = Check(bCur, bOld);
} catch{
miss = 0;
}
if (miss > 50) {
while (true) {
try {
g.FillRectangle(this.brush, new Rectangle(x, y, x + 40, y + 40));
break;
} catch {}
}
}
}
//Console.WriteLine("Working on:{0}\tMiss:{1}%", x,miss);
_workDone += 1;
}
}
//Console.WriteLine("Thread:{0} has finished work", Thread.CurrentThread.Name);
}
lets continue, comparing, and getting %
public int Check(Bitmap n, Bitmap o) {
int miss = 0;
int w = n.Width;
int h = n.Height;
int all = ((w - 1) * (h - 1));
//vertical
for (int x = 0; x < w; x += 1) {
//horizontal
for (int y = 0; y < h; y += 1) {
Color c1 = n.GetPixel(x, y);
Color c2 = o.GetPixel(x, y);
if (Look((int)c1.R, (int)c1.B, (int)c1.G, (int)c2.R, (int)c2.B, (int)c2.G)) {
miss += 1;
}
}
}
double a = miss;
double b = all;
double c = ((a / b) * 100);
miss = (int)c;
return miss;
}
and checking two pixels
public bool Look(int r1, int b1, int g1, int r2, int b2, int g2) {
int s1 = skirt(r1,r2);
int s2 = skirt(g1, g2);
int s3 = skirt(b1, b2);
int s = s1 + s2 + s3;
if (s > 50) {
return true;
} else {
return false;
}
}
and checking pixels value diff
public int skirt(int n1, int n2) {
int k = n1 - n2;
if (k < 0) {
k = k * -1;
}
return k;
}