public class ScreenXYBTComparator
extends java.lang.Object
implements java.lang.Runnable
Normal usage is to use an ExecutorService to handle multiple instances of this class searching multiple X,Y coordinates simultaneously.
Sample usage:
ExecutorService pool = Executors.newFixedThreadPool(threads); ScreenXYBTComparator[] compare = new ScreenXYBTComparator[threads]; ... if (useBitsTolerance){ if(compare[i]==null) { compare[i] = new ScreenXYBTComparator(screenBuffer, screenModel, imageBuffer, imageModel, screenx, screeny, maxPixelErrors); pool.execute(compare[tindex++]); ...Once an instance has been created and run to completion, it can be reused. It is important, though, that the thread running the instance did, indeed, run to completion. This can be checked by calling the isDone() as needed.
Sample reuse:
if(next_screenx < maxScreenX && compare[i].isDone()){ compare[i].prepare(next_screenx, screeny); pool.execute(compare[tindex++]); ...
The overhead of parallel thread maintenance with each of these instances testing only 1 X,Y location per invocation probably makes this class a poor candidate when testing large areas of the screen. Initial testing suggests that when large areas of the screen are searched by a large number of Threads starting and stopping-- potentially thousands or hundreds of thousands of times--actually makes the search take longer.
ImageUtils
,
Executors
,
ExecutorService
Constructor and Description |
---|
ScreenXYBTComparator(java.awt.image.DataBuffer screenshotBuffer,
java.awt.image.SampleModel screenshot,
java.awt.image.DataBuffer targetBuffer,
java.awt.image.SampleModel target,
int startScreenX,
int startScreenY,
int maxBTerrors)
Initial instance and use of this class must be done through this constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
getPercentErrors()
This is normally only called if
the instance isDone() and getResult() signals a match and the calling thread wants to find out
what percentage of pixel errors occurred during that match.
|
int |
getPixelErrors()
Normally only called if the instance isDone() and getResult() signals a match and the
calling thread wants to find out how many pixel errors occurred during that match.
|
boolean |
getResult()
true if a completed search yielded a match.
|
int |
getScreenX()
Normally only called if the instance isDone() and getResult() signals a match and the
calling thread wants to find out what screen x,y coordinate has that match.
|
int |
getScreenY()
Normally only called if the instance isDone() and getResult() signals a match and the
calling thread wants to find out what screen x,y coordinate has that match.
|
boolean |
isDone()
true when a single thread execution has completed.
|
void |
prepare(int screenX,
int screenY)
Used to prepare the instance for reuse on another screen X,Y location AFTER its initial search has completed.
|
void |
run()
Evaluate if the target image matches at the specified screen x,y coordinate.
|
public ScreenXYBTComparator(java.awt.image.DataBuffer screenshotBuffer, java.awt.image.SampleModel screenshot, java.awt.image.DataBuffer targetBuffer, java.awt.image.SampleModel target, int startScreenX, int startScreenY, int maxBTerrors)
screenshotBuffer
- screenshot
- targetBuffer
- target
- startScreenX
- -- the screen X coordinate to anchor this search.startScreenY
- -- the screen Y coordinate to anchor this search.maxBTerrors
- -- maximum number of "Bit Tolerance" pixel mismatches allowed before a
search failure is reported.Thread
,
Executors
public boolean getResult()
isDone()
public int getScreenX()
public int getScreenY()
public int getPixelErrors()
public int getPercentErrors()
public void prepare(int screenX, int screenY)
screenX
- -- the new screen X coordinate to anchor the next search.screenY
- -- the new screen Y coordinate to anchor the next search.run()
public boolean isDone()
run()
,
getResult()
public void run()
run
in interface java.lang.Runnable
screenshotBuffer
- screenshot
- targetBuffer
- target
- startScreenX
- startScreenY
- maxBTerrors
- - max number of pixel mismatches allowed (bit tolerance)isDone()
,
getResult()
Copyright © SAS Institute. All Rights Reserved.