Jump to content

color-specific checksum


monji
 Share

Recommended Posts

hi,

i need this function in this game i'm playing to check the monster name. the monster name's color is #FFFFFF, written against a semi-transparent black background in a specific position in the screen. i cannot use a simple checksum because there is no way to set the background to pure black. i thought i could get a checksum of the white pixels in the region because there'd be no white pixels in the background because of the black overlay. i now have this:

Func colorCheckSum( $color, $left, $top, $right, $bottom )
    Local $x, $y, $ret = 0, $r = 55445, $c1 = 4285, $c2 = 8719, $cyp
    For $x = $left to $right
        For $y = $top to $bottom
            If PixelGetColor( $x, $y ) = $color Then 
                $cyp = BitOR($c1*$x + $c2*$r, 2^$y*$c2 ); i'm not really sure if this'd
                $r = ($cyp+$r)*$c1+$c2              ; generate truly unique checksums
                $ret = $ret + $cyp                  ; but it's good enough for my purposes
            EndIf
        Next
    Next
    return $ret
EndFunc

$start = TimerInit()
$c = colorCheckSum( 16777215, 490, 55, 540, 65 )
;~ $c = PixelCheckSum( 0, 490, 55, 540, 65 )
ConsoleWrite( "checksum:" & $c & @CR )
ConsoleWrite( "time:" & TimerDiff($start) & @CR )

Exit

but it takes too much time (~100ms vs. ~0.4ms with PixelChecksum). is there a better way of doing this, maybe a better algo or a windows api call of some sort?

thanks,

-mon.

Edited by monji
Link to comment
Share on other sites

Func colorCheckSum( $color, $left, $top, $right, $bottom )
    Local $x, $y, $ret = 0, $r = 55445, $c1 = 4285, $c2 = 8719, $cyp
    For $x = $left to $right Step 10;Increase the step so it doesn't have to check each pixel
        For $y = $top to $bottom Step 5
            If PixelGetColor( $x, $y ) = $color Then 
                $cyp = BitOR($c1*$x + $c2*$r, 2^$y*$c2 ); i'm not really sure if this'd
                $r = ($cyp+$r)*$c1+$c2             ; generate truly unique checksums
                $ret = $ret + $cyp                 ; but it's good enough for my purposes
            EndIf
        Next
    Next
    return $ret
EndFunc

$start = TimerInit()
$c = colorCheckSum( 16777215, 490, 55, 540, 65 )
;~ $c = PixelCheckSum( 0, 490, 55, 540, 65 )
ConsoleWrite( "checksum:" & $c & @CR )
ConsoleWrite( "time:" & TimerDiff($start) & @CR )

Exit

I'm sure this could provide a good enough checksum for textual purposes and if the timer is accurate, it should drop the execution to 1/50, or 2ms, dunno if that's good enough.

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

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...