Jump to content

adler checksum in autoit


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
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?

Link to comment
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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...