Jump to content
Sign in to follow this  

extended pixelsearch

Recommended Posts


Hi all.

I needed to search some pixelcolor on the whole screen. The problem is, my color has different shades, but just in one color component , i.e. it changes from 0x0000CC to 0x0000FF.

So wenn im searching with Pixelsearch function with shades 32 i get a lot of fake hits. What i need is a Pixelsearch with ability to specify shades separately for each color component (RGB).

So I wrote this function, and it works, but much slower then original function :)

If you want to use it on big areas you should specify step > 1, im using 4 to check a screen and it takes ~10-15 sec

Maybe someone can optimize it or point me to usefull info, how can i make it.

; Function Name:    myPixelSearch()
; Description:      similar to PixelSearch, but you can specify shades for
;                   each color
; Parameter(s):     x1,$y1,$x2,$y2,$color, $shadered, $shadegreen, $shadeblue,$step
; Return Value(s):  The array with coordinates of the pixel
;                   or @error if nothing found
;author               : Detmyl
Func myPixelSearch($x1, $y1, $x2, $y2, $color, $shade_red, $shade_green, $shade_blue, $step = 1)
    Dim $ret[2]
    $colorRGB = getRGB($color)

    For $y = $y1 To $y2 Step $step
        For $x = $x1 To $x2 Step $step
            $pixel_color = PixelGetColor($x, $y)
            $pixel_colorRGB = getRGB($pixel_color)
            If Abs($colorRGB[0] - $pixel_colorRGB[0]) > $shade_red Then
            ElseIf Abs($colorRGB[1] - $pixel_colorRGB[1]) > $shade_green Then
            ElseIf Abs($colorRGB[2] - $pixel_colorRGB[2]) > $shade_blue Then
                $ret[0] = $x
                $ret[1] = $y
                Return $ret
    ;nothing found
    Return 0
EndFunc   ;==>myPixelSearch

; Function Name:    getRGB()
; Description:      returns R,G,B from the color
; Parameter(s):     $color RGB color 0x000000
; Return Value(s):  $arr[0] - Red
;           $arr[1] - Green
;           $arr[2] - Blue
Func getRGB($color)
    Dim $ret[3]
    $ret[0] = BitAND(BitShift($color, 16), 0xff)
    $ret[1] = BitAND(BitShift($color, 8), 0xff)
    $ret[2] = BitAND($color, 0xff)
    Return $ret
EndFunc   ;==>getRGB

Share this post

Link to post
Share on other sites

I was looking for more information about reporting individual shades as well, your script worked great! TY.

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