Jump to content

PixelSearch.au3 include library

Recommended Posts

See also:



In the interim I plan to develop a library of functions that achieve certain results that I feel I need for a script that I am working on. The library of functions I develop will not be optimized for execution time or code size. The targeted functionality is my only priority.

My required enhancements of the baseline PixelSearch functionality are:

  • a vertical column of pixels as the search mask (rather than just one pixel)
  • a horizontal row of pixels as the search mask (rather than just one pixel)
  • logical OR condition on match criteria (i.e. any one pixel in search mask needs to match target colour for search to terminate successfully)
  • logical NOR condition on match criteria (i.e. no pixels in search mask must match target colour for search to terminate successfully)
  • specify search direction to be LR, RL, TB, BT (rather than just LRTB single pixel search)
(LRTB = Left-to-Right, Top-to-Bottom, etc.)

The obvious application of the above is the scanning and interpreting of vertical and horizontal bar-gauges within some running application that has not use a query-friendly progress bar style control for each gauge.

The purpose of this post is to invite your input either to:

  • guide me to already existing functions and/or code snippets that deliver the stated functionality
  • suggest other building block functions that might be included in this PixelSearch.au3 include file
I do not promise to include your suggested additions however it makes sense that while I am in that frame of mind to at least consider other functionality in case it proves to be a natural extension of what I already plan to develop.

First a recap of the existing PixelSearch function parameters and behaviour:

; PixelSearch ( left, top, right, bottom, color [, shade-var [, step [, hwnd]]] )
; Required Parameters
;   left        left coordinate of rectangle. 
;   top         top coordinate of rectangle. 
;   right       right coordinate of rectangle. 
;   bottom      bottom coordinate of rectangle. 
;   colour      Colour value of pixel to find (in decimal or hex). 
; Optional Parameters
;   shade-var   [0..255] the tolerated shade variation in RGB component colours. Default is 0 (exact match).
;   step        Number of pixels advanced at each step of the search. Default is 1 (advance one pixel at a time - slow!).
;   hwnd        Window handle to be used. 
; Return Value
;   Success:    Returns a two-element array of pixel's coordinates. (Array[0] = x, Array[1] = y) 
;   Failure:    Sets @error to 1 if color is not found. 
; Remarks
;   The search is performed left-to-right, top-to-bottom and the first match is returned.

So here is what I plan to develop. Two functions that

  • set @error to 1 if no match
  • return a single integer (X or Y coordinate only - not a pair) if a match is found

; Parameters    (accepted values)
;   mask-logic  (OR)    - Terminate upon match for target color in ANY pixel. 
;               (NOR)   - Terminate upon match for target color in NO pixels. 
;   direction   (LR)    - Search direction is left to right. (only for _PixelSearchVmask)
;               (RL)    - Search driection is right to left. (only for _PixelSearchVmask)
;               (TB)    - Search direction is top to bottom. (only for _PixelSearchHmask)
;               (BT)    - Search driection is bottom to top. (only for _PixelSearchHmask)

Ideally the above would be integrated into just one function modeled after the existing PixelSearch however expedience is my mantra so I fully expect that the two functions described above is how it will turn out.

The final library will be posted here.

If you wish to test early versions (probably bugged) then post a response here.

Link to post
Share on other sites

I think you can get all you need in


At least it gives you a full indication on getting the bytes of an image in a large array and by calculating the offsets its quitte easy to search in any direction you want

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...