Note that there are some explanatory texts on larger screens.

plurals
  1. POChecksum an image in Delphi
    text
    copied!<p>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).</p> <p>Adding values:</p> <pre><code>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]) &lt;&gt; 15577344) And ((Img.Bitmap.Canvas.Pixels[j,k]) &lt;&gt; 15311104) And ((Img.Bitmap.Canvas.Pixels[j,k]) &lt;&gt; 3816255) And ((Img.Bitmap.Canvas.Pixels[j,k]) &lt;&gt; 10526623) And ((Img.Bitmap.Canvas.Pixels[j,k]) &lt;&gt; 12303034) And ((Img.Bitmap.Canvas.Pixels[j,k]) &lt;&gt; 9013641)) Then begin Checksum := Checksum + Img.Bitmap.Canvas.Pixels[j,k]; end; Result := Abs(Checksum); end; </code></pre> <p>Adler-32:</p> <pre><code>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]) &lt;&gt; 15577344) And ((Img.Bitmap.Canvas.Pixels[j,k]) &lt;&gt; 15311104) And ((Img.Bitmap.Canvas.Pixels[j,k]) &lt;&gt; 3816255) And ((Img.Bitmap.Canvas.Pixels[j,k]) &lt;&gt; 10526623) And ((Img.Bitmap.Canvas.Pixels[j,k]) &lt;&gt; 12303034) And ((Img.Bitmap.Canvas.Pixels[j,k]) &lt;&gt; 9013641)) Then begin a := a + Img.Bitmap.Canvas.Pixels[j,k]; b := b + a; end; Result := Abs(a) + Abs(b); end; </code></pre> <p>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 ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload