Hey,
I am trying to checksum an image, but it takes too long to give a result, tried add values, and Adler-32 but both finishes in a long time (approximately 2 seconds).
Adding values:
Function Checksum_CountryFlag(Img : TPicture):Integer;
var j, k, Checksum : Integer;
begin
Checksum := 0;
For j := 0 to Img.Width do
For k := 0 to Img.Height do
If (((Img.Bitmap.Canvas.Pixels[j,k]) <> 15577344) And ((Img.Bitmap.Canvas.Pixels[j,k]) <> 15311104) And ((Img.Bitmap.Canvas.Pixels[j,k]) <> 3816255) And ((Img.Bitmap.Canvas.Pixels[j,k]) <> 10526623) And ((Img.Bitmap.Canvas.Pixels[j,k]) <> 12303034) And ((Img.Bitmap.Canvas.Pixels[j,k]) <> 9013641)) Then
begin
Checksum := Checksum + Img.Bitmap.Canvas.Pixels[j,k];
end;
Result := Abs(Checksum);
end;
Adler-32:
Function Checksum_Adler32(Img : TPicture):Integer;
var i,a,b,j,k : Integer;
begin
a := 1; b := 0;
For j := 0 to Img.Width do
For k := 0 to Img.Height do
If (((Img.Bitmap.Canvas.Pixels[j,k]) <> 15577344) And ((Img.Bitmap.Canvas.Pixels[j,k]) <> 15311104) And ((Img.Bitmap.Canvas.Pixels[j,k]) <> 3816255) And ((Img.Bitmap.Canvas.Pixels[j,k]) <> 10526623) And ((Img.Bitmap.Canvas.Pixels[j,k]) <> 12303034) And ((Img.Bitmap.Canvas.Pixels[j,k]) <> 9013641)) Then
begin
a := a + Img.Bitmap.Canvas.Pixels[j,k];
b := b + a;
end;
Result := Abs(a) + Abs(b);
end;
As you see, i am trying to avoid some values (technical reasons). Maybe this what makes it takes too long, i don't know, any ideas for improving this algorithm ?