Sign in to follow this  
Followers 0
evilertoaster

adler checksum in autoit

4 posts in this topic

Hi,

I'm trying to port the pixel checksum fuction from autoit over to autoit itself for use in my own program. I looked at the C++ source for the pixel checksum function and found they use an 'alder' method, but when i tried coverting it (i havn't done any C++ for so long :D ) i found it didn't give the same checksum for the same group of pixels. Can anyone find a typo or some error i made in the conversion?

Func _BMPGetChecksum(ByRef $BMPHandle,$step=0)
    Local $q,$r,$col,$relrect,$adler,$s1,$s2,$nStep,$ptOrigin
    For $q=0 to _BMPGetWidth($BMPHandle)
        For $r=0 to _BMPGetHeight($BMPHandle)
            $col= _PixelRead($BMPHandle, $q, $r)  ;returns a string "RRGGBB"
            $s1 = BitAND($adler, 0xffff)
            $s2 = BitAND(BitRotate($adler,16), 0xffff)
            $s1 = Mod(($s1 + Dec(StringLeft($col,2))), 65521)
            $s2 = Mod(($s2 + $s1),65521)
            $adler = BitShift($s2,16) + $s1
            $s1 = BitAND($adler, 0xffff)
            $s2 = BitAND(BitRotate($adler,16), 0xffff)
            $s1 = Mod(($s1 + Dec(StringMid($col,3,2))),65521)
            $s2 = Mod(($s2+$s1),65521)
            $adler = BitShift($s2,16) + $s1
            $s1 = BitAND($adler, 0xffff)
            $s2 = BitAND(BitRotate($adler,16), 0xffff)
            $s1 = Mod(($s1 + Dec(StringRight($col,2))), 65521)
            $s2 = Mod(($s2 + $s1),65521)
            $adler = BitShift($s2,16) + $s1
        Next
    Next
    Return $adler
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Aren't bitmaps stored differently than they are displayed? The first pixel stored on disk is different than the first pixel stored on screen, I believe.

Edit: I'm, of course, assuming you're comparing the bitmap as displayed on screen to the bitmap stored in a file and are getting different results. You can use the code posted on Wikipedia to make sure you implement the algorithm correctly. Then you can adapt it from there to read a bitmap.

Edited by Valik

Share this post


Link to post
Share on other sites

Yes they are stored differntly but when working with my BMP library (which i am) the pixel read function corrects that for you. I guess i can start looking though if there's some reading discrepency anyways....the algorithm i copied form AutoIt source directly becuase i wanted it to be the same (it's slightly different i think than the one posted on wikipedia)...do we know who wrote that function in autoit?

Share this post


Link to post
Share on other sites

Jon wrote the function. The code on Wikipedia does the same thing, it just does it more efficiently (I think that is the case). I intend to update the one in AutoIt someday to use a more efficient version, too, but the actual output will be the same.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0