-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFastFind.au3
667 lines (587 loc) · 30.6 KB
/
FastFind.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
#cs ----------------------------------------------------------------------------
FastFind Version: 2.2
Author: FastFrench
Some Wrappers: frank10
AutoIt Version: 3.3.8.1
Script Function:
All FastFind.dll wrapper functions.
This dll provides optimized screen processing. All actions implies at least 2 dll calls : one to copy the screen data into memory, and a second to make specific action.
This way, you can make several actions even faster when they apply to the same screen data.
Functions exported in FastFind.dll 1.8 are :
SnapShot (Makes captures of the screen, a Window - partial or full - into memory, required before using any of the following.)
ColorPixelSearch (Search the closest pixel with a given color)
ColorCount (Count how many pixels with a given color exist in the SnapShot.)
HasChanged (Says if two snapshots are exactly the same or not. Usefull to check if some changes occured in a given area. )
LocalizeChanges (Same has HasChanged, but returns precisely the smallest rectangle that includes all the changes, and the number of pixels that are different).
GetPixel (Gives the color of a pixel in the SnapShot. Much faster than PixelGetColor if you use this a lot.)
AddColor
RemoveColor (Those 3 functions allow management of a list of colors, instead of using only one)
ResetColors (Tou can have up to 1024 colors active in the list)
AddExcludedArea (Those functions add exceptions in the processing of screen areas, with rectangles that are ignored)
ResetExcludedAreas (You can have up to 1024 areas in the list)
IsExcluded
ColorsSearch (Close to ColorSearch, except that instead of a single color, all colors of the current list are in use)
ColorsPixelSearch (Similar to ColorPixelSearch, except that instead of a single color, all colors of the current list are in use)
ColorSearch (it's the most versatile and powerful function (in 1.3) : you can, at the same time, check for as many colors as you want,
with possibly a "ShadeVariation", multiple subareas to ignore... will Find the closest spot with a all specified criteria.
The spot is a square area of NxN pixels with at least P pixels that are as close as allowed by ShadeVariation
from any of the colors in the list).
ProgressiveSearch (new with 1.4 : similar to ColorSearch, except that if the "ideal" spot can't be found, can still search for the best spot available).
GetLastErrorMsg
FFVersion
-- New in version 1.6
SaveBMP
SaveJPG
GetLastFileSuffix
KeepChanges
KeepColor
-- New in version 1.7
DrawSnapShot
FFSetPixel
DuplicateSnapShot
GetRawData
-- New in version 2.0
Function with an additionnal parameter (ShadeVariation) :
KeepChanges
LocalizeChanges
HasChanged
New functions :
DrawSnapShotXY (same as DrawSnapShot, with specific top-left position for drawing).
ComputeMeanValues (Gives mean Red, Green and Blue values)
ApplyFilterOnSnapShot (apply a AND filter on each pixels in the SnapShot)
FFGetRawData (gets direct access to all pixel data of a ScreenShot)
Bug fix :
FFColorCount with ShadeVariation
-- 2.2
Detects more error patterns (wrong coordinates)
#ce ----------------------------------------------------------------------------
; User global variables (can be changes by user)
global $FFDefaultSnapShot = 0 ; Default SnapShot Nb
global $FFDefautDebugMode = 0xE7 ; Si below to the meaning of this value. To remove all debug features (file traces, graphical feedback..., use 0 here)
; System global variables ** do not change them **
global $FFDllHandle = -1
global $FFLastSnap = 0
global const $FFNbSnapMax = 1024
global $FFLastSnapStatus[$FFNbSnapMax] ; array used to automatically make a SnapShot when needed
global const $FFCurrentVersion="2.2"
InitFFDll()
; Loading the the dll and initialisation of the wrapper
; -----------------------------------------------------
Func InitFFDll()
for $i = 0 To $FFNbSnapMax-1
$FFLastSnapStatus[$i] = 0
Next
If @AutoItX64 Then
Global $DllName = "FastFind64.dll"
Else
Global $DllName = "FastFind.dll"
Endif
$FFDllHandle = DllOpen($DllName)
If $FFDllHandle=-1 Then
$FFDllHandle=$DllName
MsgBox(0,"Error","Failed to load "&$DllName&", application probably won't properly work. "&@LF&"Check if the file "&$DllName&"is installed near this script")
Exit(100)
Return
EndIf
if ($FFCurrentVersion<>FFGetVersion()) Then
MsgBox(0, "Error", "Wrong version of "&$DllName&". The dll is version "&FFGetVersion()&" while version "&$FFCurrentVersion&" is required.");
Exit(101)
EndIf
FFSetDebugMode($FFDefautDebugMode)
EndFunc
Func CloseFFDll()
If $FFDllHandle<>-1 Then DllClose($FFDllHandle)
EndFunc
; Determines the debugging mode.
; ------------------------------------------------- --------------------
; The 4 bits determine the channel debugging enabled, they have the following meanings:
; 0x00 = no debug
; 0x01 = Information sent to the console (RequireAdmin)
; 0x02 = debug information sent to a file (trace.txt)
; 0x04 = Graphic display of points / areas identified
; 0x08 = Display MessageBox (blocking)
; Note that in case of error, a MessageBox is displayed in the DLL if DebugMode> 0
; The following 4 bits are used to filter based on the origin of the debug message
; 0x0010 / / Excludes internal traces of the DLL
; 0x0020 / / Excludes detailed internal traces of the DLL
; 0x0040 / / Excludes external traces (those of the application)
; 0x0080 / / Error message (priority)
;
; Errors (serious) are displayed on all available channels (file, console and MessageBox) if $ DebugMode> 0
;
; Proto C function: void SetDebugMode (int NewMode)
Func FFSetDebugMode($DebugMode)
DllCall($FFDllHandle, "none", "SetDebugMode", "int", $DebugMode)
EndFunc
; The DLL also exposes its debugging functions, allowing the AutoIt application share same traces
Func FFTrace($DebugString)
DllCall($FFDllHandle, "none", "DebugTrace", "str", $DebugString)
EndFunc
; This function allows you to handle errors (the text appears in the logfile, the console and a MessageBox if $ DebugMode> 0)
Func FFTraceError($DebugString)
DllCall($FFDllHandle, "none", "DebugError", "str", $DebugString)
EndFunc
; Sets the current window to use
; -----------------------------------
; By default, the entire screen is used. You can select a particular window. By default, we will always use the last Window set.
; If $WindowsHandle = 0, the entire screen : GetDesktopWindow ()
; If ClientOnly = True, then only the client part of the Window will be capturable, and coordinates will be relative to top-left
; corner of the client area (client area is the full Window except title bar, possibly menu area, borders...)
; If ClientOnly = False, then the full Window will be used.
;
; Proto C function: void SetHWnd(HWND NewWindowHandle, bool bClientArea);
Func FFSetWnd($WindowHandle, $ClientOnly=True)
DllCall($FFDllHandle, "none", "SetHWnd", "HWND", $WindowHandle, "BOOLEAN", $ClientOnly)
EndFunc
; Choose the Default SnapShot that will by used in the next operations. This avoid to specify the number of the SnapShot every time when you always work on the same
Func FFSetDefaultSnapShot($NewSnapShot)
$FFDefaultSnapShot = $NewSnapShot
EndFunc
; Managing the list of colors
; ================================
; When a parameter is proposed Dane Color function, the value -1 means that all colors in the list are taken into account
; Add one or more colors in the list maintained by FastFind
; Proto C function: int addColor (int newColor)
Func FFAddColor(const $NewColor)
local $res
if (IsArray($NewColor)) Then
For $Color In $NewColor
$res = DllCall($FFDllHandle, "int", "AddColor", "int", $Color)
Next
Else
$res = DllCall($FFDllHandle, "int", "AddColor", "int", $NewColor)
EndIf
if IsArray($res) Then return $res[0]
return $res
EndFunc
; Remove a color (if any) from the list of colors
;
; Proto C function: int RemoveColor (int newColor)
Func FFRemoveColor(const $OldColor)
local $res = DllCall($FFDllHandle, "int", "RemoveColor", "int", $OldColor)
if IsArray($res) Then return $res[0]
return $res
EndFunc
; Totally Empty the list of colors
;
; Proto C function: int ResetColors ()
Func FFResetColors()
DllCall($FFDllHandle, "none", "ResetColors")
EndFunc
; Exclusion areas management
; ==========================
; Exclusion zones can restrict searches with all functions
; Search
; It is possible to have up to 1024 rectangles of exclusion, thereby removing precisely
; Any search area. For example, with flash, the mouse cursor will usually appears on the snapshots
; (unlike cursors managed by Windows API). You can use an Exclusion rectangle established according to the position
; of the mouse so the cursor does not affect the Search results.
;
; Adds an exclusion zone
;
; Proto C function: void WINAPI AddExcludedArea (int x1, int y1, int x2, int y2)
Func FFAddExcludedArea(const $x1, const $y1, const $x2, const $y2)
local $Res = DllCall($FFDllHandle, "int", "AddExcludedArea", "int", $x1, "int", $y1, "int", $x2, "int", $y2)
if IsArray($res) Then return $res[0]
return $res
EndFunc
; Clears the list of all zones
;
; Proto C function: void WINAPI ResetExcludedAreas()
Func FFResetExcludedAreas()
DllCall($FFDllHandle, "none", "ResetExcludedAreas")
EndFunc
; Through the list of exclusion zones to determine if the point passed as a parameter is excluded or not.
;
; Proto C function: bool WINAPI IsExcluded(int x, int y, HWND hWnd)
Func FFIsExcluded(const $x, const $y, const $hWnd)
local $Res = DllCall($FFDllHandle, "BOOLEAN", "IsExcluded", "int", $x, "int", $y, "HWND", $hWnd)
if IsArray($res) Then return $res[0]
return $res
EndFunc
; FFSnapShot Function - This function allows you to make a copy of the screen, window or only a part in memory
; - All other functions of FF running from memory, it should first run FFSnapShot (either explicitly or implicitly as designed within this wrapper)
; It is possible to perform several different catches and work on any thereafter.
;
; Input:
; The area to capture (in coordinates relative to the boundaries of the window if a window handle nonzero indicated) [optional, the entire screen by default]
; If the area indicated is 0,0,0,0 then this is the entire window (or screen) to be captured
; The ID to use SnapShot (optional, default to the last used, 0 initially)
; And a window handle [optional, the same screen as the previous time by default. Initially, the entire screen.]
;
; Warning: Graphic data is stored in memory, the use of this feature consumes memory. It takes about 1.8 MB of RAM to capture 800x600.
; Therefore it should preferably always reuse the same No. SnapShot. Nevertheless, it is possible to store up to 1024 screens.
;
; Return Values: If unsuccessful, returns 0 and sets @Error.
; If successful, returns 1
; Proto C function: int WINAPI SnapShot(int aLeft, int aTop, int aRight, int aBottom, int NoSnapShot)
Func FFSnapShot(const $Left=0, const $Top=0, const $Right=0, const $Bottom=0, const $NoSnapShot=$FFDefaultSnapShot, const $WindowHandle=-1)
if ($WindowHandle <> -1) Then FFSetWnd($WindowHandle)
$FFDefaultSnapShot = $NoSnapShot ; On mémorise le no du SnapShot utilisé, cela restera le SnapShop par défaut pour les prochains appels
local $Res = DllCall($FFDllHandle, "int", "SnapShot", "int", $Left, "int", $Top, "int", $Right, "int", $Bottom, "int", $NoSnapShot)
If ( ((Not IsArray($Res)) AND ($Res=0)) OR $Res[0]=0) Then
MsgBox(0, "FFSnapShot", "SnapShot ("&$Left&","&$Top&","&$Right&","&$Bottom&","&$NoSnapShot&","&Hex($WindowHandle,8)&") failed ")
if (IsArray($Res)) Then
MsgBox(0, "FFSnapShot Error", "IsArray($Res):"&IsArray($Res)&" - Ubound($Res):"&UBound($Res)&" - $Res[0]:"&$Res[0])
else
MsgBox(0, "FFSnapShot Error", "IsArray($Res):"&IsArray($Res)&" - $Res:"&$Res)
EndIf
$FFLastSnapStatus[$NoSnapShot] = -1
SetError(2)
Return False
EndIf
$FFLastSnapStatus[$NoSnapShot] = 1
$FFLastSnap = $NoSnapShot
Return True
EndFunc
; Internal Function, don't use it directly
Func SnapShotPreProcessor($Left, $Top, $Right, $Bottom, $ForceNewSnap, $NoSnapShot, $WindowHandle)
; Si on impose une nouvelle capture ou si aucun SnapShot valide n'a déjà été effectué pour ce N°
if ($ForceNewSnap OR $FFLastSnapStatus[$NoSnapShot] <> 1) Then return FFSnapShot($Left, $Top, $Right, $Bottom, $NoSnapShot, $WindowHandle)
Return True
EndFunc
; FFNearestPixel Function - This function works like PixelSearch, except that instead of returning the first pixel found,
; it returns the closest from a given position ($PosX,$PosY)
; Return Values: If unsuccessful, returns 0 and sets @Error.
; If successful, an array of 2 elements:
; [0] : X coordinate of the pixel found the nearest
; [1] : Y coordinate of the pixel
; Example: To find the pixel with color 0x00AB0C45 as close as possible from 500, 500 in full screen
; $Res = FFNearestPixel(500, 500, 0x00AB0C45)
; If Not @Error Then MsgBox (0, "Resource", "Found in" & $PosX & "," & $PosY)
;
; Proto C function: int WINAPI ColorPixelSearch(int &XRef, int &YRef, int ColorToFind, int NoSnapShot)
Func FFNearestPixel($PosX, $PosY, $Color, $ForceNewSnap=true, $Left=0, $Top=0, $Right=0, $Bottom=0, $NoSnapShot=$FFLastSnap, $WindowHandle=-1)
;local $NoSnapShot = 2 ; Slot utilisé pour les captures d'écran (entre 0 et 3), choisi arbitrairement
if Not SnapShotPreProcessor($Left, $Top, $Right, $Bottom, $ForceNewSnap, $NoSnapShot, $WindowHandle) Then
SetError(2)
Return False
EndIf
local $Result = DllCall($FFDllHandle, "int", "ColorPixelSearch", "int*", $PosX, "int*",$PosY, "int", $Color, "int", $NoSnapShot)
If ( Not IsArray($Result) OR $Result[0]<>1) Then
SetError(1)
Return False
EndIf
local $CoordResult[2] = [$Result[1], $Result[2]] ; PosX, PosY
return $CoordResult
EndFunc
; FFNearestSpot Function - This feature allows you to find, among all the area (or "spots") containing a minimum number of pixels
; a given color, the one that is closest to a reference point.
; Return Values: If unsuccessful, returns 0 and sets @Error.
; If successful, an array of 3 elements: [0] : X coordinate of the nearest spot [1] : Y coordinate of the nearest spot [2] : Number of pixels found in the nearest spot
; For example, suppose you want to detect a blue circle (Color = 0x000000FF) partially obscured, diameter 32 pixels (say with at least 45 pixels having the right color)
; and the closest possible to the position x = 198 and y = 543, in a full screen, so the function is called as follows:
; FFNearestSpot $Res = (32, 45, 198, 543, 0x000000FF)
; If Not @Error Then MsgBox (0, "Blue Circle", "The blue circle closest to the position 198, 543 is at "&$PosX&","&$PosY&@LF&" and contains "&$NbPixel&" blue pixels")
;
; Proto C function: int WINAPI GenericColorSearch(int SizeSearch, int &NbMatchMin, int &XRef, int &YRef, int ColorToFind, int ShadeVariation, int NoSnapShot)
Func FFNearestSpot($SizeSearch, $NbPixel, $PosX, $PosY, $Color, $ShadeVariation=0, $ForceNewSnap=true, $Left=0, $Top=0, $Right=0, $Bottom=0, $NoSnapShot=$FFLastSnap, $WindowHandle=-1)
if Not SnapShotPreProcessor($Left, $Top, $Right, $Bottom, $ForceNewSnap, $NoSnapShot, $WindowHandle) Then
SetError(2)
Return False
EndIf
local $Result = DllCall($FFDllHandle, "int", "GenericColorSearch", "int", $SizeSearch, "int*", $NbPixel, "int*", $PosX, "int*",$PosY, "int", $Color, "int", $ShadeVariation, "int", $NoSnapShot)
If ((Not IsArray($Result)) OR $Result[0]<>1) Then
SetError(1)
Return False
EndIF
local $CoordResult[3] = [$Result[3], $Result[4], $Result[2]] ; PosX, PoxY, Nombre de pixels
return $CoordResult
EndFunc
; FFBestSpot Function - This feature is similar to FFNearestSpot, but even more powerful.
; Suppose for instance that you want to find a spot with ideally 200 blue pixels in a 50x50 area, but some of those pixels may be covered, and also for transparency reasons, the color may be a bit different.
; So, if it can't find a spot with 200 pure blue pixels, you could accept "lower" results, like only 120 blue pixels minimum, and - if enough pure blue pixels can't be found - try to find something close enough
; with ShadeVariation.
; FFBestSpot will do that all for you.
; Here is how it works :
; Only one additionnal parameters compared to FFNearestSpot : you give the minimum acceptable number of pixels to find, and then the "optimal" number. All other parameters are the same, with same meaning.
; First, FFBestSpot will try to find if any spot exist with at least the optimal number of pixels and pure color (or colors). If yes, then it return the one that as the shorter distance with $PoxX/$PosY
; Otherwise, it will try to find the spots that has the better number of pixels in the pure Color (or colors). If it can find a spot with at least the minimum acceptable number of pixels, then it returns this spot.
; Otherwise, it will try again the two same searches, but now with ShadeVariation as set in the parameter (if this parameter is not 0)
; If no proper spot can be found, returns 0 in the first element of the array and set @Error=1.
;
; Proto C function: int WINAPI ProgressiveSearch(int SizeSearch, int &NbMatchMin, int NbMatchMax, int &XRef, int &YRef, int ColorToFind/*-1 if several colors*/, int ShadeVariation, int NoSnapShot)
Func FFBestSpot($SizeSearch, $MinNbPixel, $OptNbPixel, $PosX, $PosY, $Color, $ShadeVariation=0, $ForceNewSnap=true, $Left=0, $Top=0, $Right=0, $Bottom=0, $NoSnapShot=$FFLastSnap, $WindowHandle=-1)
if Not SnapShotPreProcessor($Left, $Top, $Right, $Bottom, $ForceNewSnap, $NoSnapShot, $WindowHandle) Then
SetError(2)
Return False
EndIf
local $Result = DllCall($FFDllHandle, "int", "ProgressiveSearch", "int", $SizeSearch, "int*", $MinNbPixel, "int", $OptNbPixel, "int*", $PosX, "int*",$PosY, "int", $Color, "int", $ShadeVariation, "int", $NoSnapShot)
If ((Not IsArray($Result)) OR $Result[0]<>1) Then
SetError(1)
Return False
EndIf
local $CoordResult[3] = [$Result[4], $Result[5], $Result[2]] ; PosX, PoxY, Nombre de pixels
return $CoordResult
EndFunc
; FFColorCount Function - This function counts the number of pixels with the specified color, exact or approximate (ShadeVariation).
;
; Proto C : int WINAPI ColorCount(int ColorToFind, int NoSnapShot, int ShadeVariation)
Func FFColorCount($ColorToCount, $ShadeVariation=0, $ForceNewSnap=true, $Left=0, $Top=0, $Right=0, $Bottom=0, $NoSnapShot=$FFLastSnap, $WindowHandle=-1)
if Not SnapShotPreProcessor($Left, $Top, $Right, $Bottom, $ForceNewSnap, $NoSnapShot, $WindowHandle) Then
SetError(2)
Return False
EndIf
$Result = DllCall($FFDllHandle, "int", "ColorCount", "int", $ColorToCount, "int", $NoSnapShot, "int", $ShadeVariation)
If (Not IsArray($Result)) Then Return False
Return $Result[0]
EndFunc
; FFIsDifferent Function - This function compares two SnapShots of the same window and return whether they have different or not .
; modified by frank10
; Proto C : int WINAPI HasChanged(int NoSnapShot, int NoSnapShot2, int ShadeVariation); // ** Changed in version 2.0 : ShadeVariation added **
Func FFIsDifferent($NoSnapShot1, $NoSnapShot2, $ShadeVariation=0)
$Result = DllCall($FFDllHandle, "int", "HasChanged", "int", $NoSnapShot1, "int", $NoSnapShot2, "int", $ShadeVariation)
If (Not IsArray($Result)) Then Return False
Return $Result[0]
EndFunc
; FFLocalizeChanges Function - This function compares two SnapShots and specifies the number of different pixels and the smallest rectangle containing all changes.
; modified by frank10
; If unsuccessful, @Error = 1 and returns 0
; In case of differences, returns an array of 5 elements thus formed:
; [0]: left edge of the rectangle
; [1]: upper edge of the rectangle
; [2]: right edge of the rectangle
; [3]: lower edge of the rectangle
; [4]: Number of pixels that changed
; Proto C : int WINAPI LocalizeChanges(int NoSnapShot, int NoSnapShot2, int &xMin, int &yMin, int &xMax, int &yMax, int &nbFound, int ShadeVariation); // ** Changed in version 2.0 : ShadeVariation added **
Func FFLocalizeChanges($NoSnapShot1, $NoSnapShot2, $ShadeVariation=0)
$Result = DllCall($FFDllHandle, "int", "LocalizeChanges", "int", $NoSnapShot1, "int", $NoSnapShot2, "int*", 0, "int*", 0, "int*", 0, "int*", 0, "int*", 0, "int" , $ShadeVariation )
If ((Not IsArray($Result)) OR $Result[0]<>1) Then
SetError(1)
Return False
EndIF
local $TabRes[5] = [$Result[3], $Result[4], $Result[5], $Result[6], $Result[7]];
Return $TabRes
EndFunc
; FFGetPixel Function - Cette fonction est close to PixelGetColor, except it works on a SnapShot.
; In order to make this function as fast as possible, you should explicitely make the snapshot before using it (cf benchmark.au3)
;
; Proto C : int WINAPI FFgetPixel(int X, int Y, int NoSnapShot)
Func FFGetPixel($x, $y, $NoSnapShot=$FFLastSnap)
$Result = DllCall($FFDllHandle, "int", "FFGetPixel", "int", $x, "int", $y, "int", $NoSnapShot)
If ( (Not IsArray($Result)) or ($Result[0]=-1) ) Then
SetError(2)
Return -1
EndIf
Return $Result[0]
EndFunc
; FFGetVersion Function - This function returns the version Nb of FastFind DLL
;
; Proto C : LPCTSTR WINAPI FFVersion(void)
Func FFGetVersion()
$Result = DllCall($FFDllHandle, "str", "FFVersion")
If ( (Not IsArray($Result)) ) Then
SetError(2)
Return "???"
EndIf
Return $Result[0]
EndFunc
; FFGetLastError function - This function will return the last error message, if any (won't work if all debug are disabled, as error strings won't be initialized).
;
; Proto C : LPCTSTR WINAPI GetLastErrorMsg(void)
Func FFGetLastError()
$Result = DllCall($FFDllHandle, "str", "GetLastErrorMsg")
If ( (Not IsArray($Result)) ) Then
SetError(2)
Return ""
EndIf
Return $Result[0]
EndFunc
global $LastFileNameParam=""
; New in version 1.6 => Save a SnapShot in a .BMP file.
; Exemple of usage: FFSaveBMP("TOTO")
Func FFSaveBMP($FileNameWithNoExtension, $ForceNewSnap=false, $Left=0, $Top=0, $Right=0, $Bottom=0, $NoSnapShot=$FFLastSnap, $WindowHandle=-1)
if Not SnapShotPreProcessor($Left, $Top, $Right, $Bottom, $ForceNewSnap, $NoSnapShot, $WindowHandle) Then
SetError(2)
Return False
EndIf
local $Result = DllCall($FFDllHandle, "BOOLEAN", "SaveBMP", "int", $NoSnapShot, "str", $FileNameWithNoExtension)
If ((Not IsArray($Result)) OR $Result[0]<>1) Then
SetError(1)
Return False
EndIf
local $Suffixe = DllCall($FFDllHandle, "int", "GetLastFileSuffix")
If (IsArray($Result)) Then
If ($Result[0]>0) Then
$LastFileNameParam = $FileNameWithNoExtension+".BMP"
Else
$LastFileNameParam = $FileNameWithNoExtension+"_"+$Result[0]+".BMP"
EndIf
EndIf
return true
EndFunc
; New in version 1.6 => Save a SnapShot in a JPEG file.
; Exemple of usage: FFSaveJPG("TOTO")
Func FFSaveJPG($FileNameWithNoExtension, $QualityFactor=85, $ForceNewSnap=true, $Left=0, $Top=0, $Right=0, $Bottom=0, $NoSnapShot=$FFLastSnap, $WindowHandle=-1)
if Not SnapShotPreProcessor($Left, $Top, $Right, $Bottom, $ForceNewSnap, $NoSnapShot, $WindowHandle) Then
SetError(2)
Return False
EndIf
local $Result = DllCall($FFDllHandle, "BOOLEAN", "SaveJPG", "int", $NoSnapShot, "str", $FileNameWithNoExtension, "ULONG", $QualityFactor)
If ((Not IsArray($Result)) OR $Result[0]<>1) Then
SetError(1)
Return False
EndIf
local $Suffixe = DllCall($FFDllHandle, "int", "GetLastFileSuffix")
If (IsArray($Result)) Then
If ($Result[0]>0) Then
$LastFileNameParam = $FileNameWithNoExtension+".JPG"
Else
$LastFileNameParam = $FileNameWithNoExtension+"_"+$Result[0]+".JPG"
EndIf
EndIf
return true
EndFunc
; Gives the FileName of the last file written with FFSaveJPG of FFSaveBMP
Func FFGetLastFileName()
return $LastFileNameParam
EndFunc
; Change a SnapShot so that it keeps only the pixels that are different from another SnapShot.
; modified by frank10
; Exemple :
; FFSnapShot(0, 0, 0, 0, 1) ; Takes FullScreen SnapShot N°1
; Sleep(1000) ; Wait 1 second
; FFSnapShot(0, 0, 0, 0, 2) ; Takes another SnapShot (N°2)
; FFKeepChanges(1, 2, 8) ; SnapShot N°1 will have all pixels black, except those that have changed between the 2 SnapShots with a shadevariation of 8. SnapShot N°2 is kept unchanged.
; FFSaveBMP("snapshot", false, 0,0,0,0, 1) ; Saves the result into snapshot.bmp
;
;Prototype : int WINAPI KeepChanges(int NoSnapShot, int NoSnapShot2, int ShadeVariation); // ** Changed in version 2.0 : ShadeVariation added **
Func FFKeepChanges($NoSnapShot1, $NoSnapShot2, $ShadeVariation=0)
$Result = DllCall($FFDllHandle, "int", "KeepChanges", "int", $NoSnapShot1, "int", $NoSnapShot2, "int", $ShadeVariation)
If ((Not IsArray($Result)) OR $Result[0]<>1) Then
SetError(1)
Return False
EndIF
Return true
EndFunc
; Change a SnapShot so that it keeps only the color (or colors if a list is used) asked. All other pixels will be black.
; Exemple :
; FFSnapShot(0, 0, 0, 0, 1) ; Takes FullScreen SnapShot N°1
; Sleep(1000) ; Wait 1 second
; FFSnapShot(0, 0, 0, 0, 2) ; Takes another SnapShot (N°2)
; FFKeepChanges(1, 2) ; SnapShot N°1 will have all pixels black, except those that have changed between the 2 SnapShots. SnapShot N°2 is kept unchanged.
; FFResetColors() ; Rest of the list of colors
; local $Couleurs[2]=[0x00FF0000, 0x000000FF] ; Pure blue and pure red
; FFAddColor($Couleurs)
; FFKeepColor(-1, 60, false, 0,0,0,0, 1, -1) ; As the SnapShot N°1 now has only very few pixels (only changes), we can now make de detection with very high ShadeVariation value
; ; After this step, the SnapShot N°1 will only have blue and red pixels left.
;Prototype : int WINAPI KeepColor(int NoSnapShot, int ColorToFind, int ShadeVariation);
Func FFKeepColor($ColorToFind, $ShadeVariation=0, $ForceNewSnap=true, $Left=0, $Top=0, $Right=0, $Bottom=0, $NoSnapShot=$FFLastSnap, $WindowHandle=-1)
if Not SnapShotPreProcessor($Left, $Top, $Right, $Bottom, $ForceNewSnap, $NoSnapShot, $WindowHandle) Then
SetError(2)
Return False
EndIf
$Result = DllCall($FFDllHandle, "int", "KeepColor", "int", $NoSnapShot, "int", $ColorToFind, "int", $ShadeVariation)
If ((Not IsArray($Result)) OR $Result[0]<>1) Then
SetError(1)
Return False
EndIF
Return true
EndFunc
; FFDrawSnapShot will draw the SnapShot back on screen (using the same Window and same position).
; Can also be used on modified SnapShots (after use of FFsetPixel, FFKeepChanges or FFKeepColor)
; Proto C: bool WINAPI DrawSnapShot(int NoSnapShot);
Func FFDrawSnapShot($NoSnapShot=$FFLastSnap)
if $FFLastSnapStatus[$NoSnapShot] <> 1 Then
SetError(2)
Return False
EndIf
$Result = DllCall($FFDllHandle, "BOOLEAN", "DrawSnapShot", "int", $NoSnapShot)
If ((Not IsArray($Result)) OR $Result[0]<>1) Then
SetError(1)
Return False
EndIF
Return true
EndFunc
; FFSetPixel will change the color of a pixel in a given SnapShot
;bool WINAPI FFSetPixel(int x, int y, int Color, int NoSnapShot);
Func FFSetPixel($x, $y, $Color, $NoSnapShot=$FFLastSnap)
if $FFLastSnapStatus[$NoSnapShot] <> 1 Then
SetError(2)
Return False
EndIf
$Result = DllCall($FFDllHandle, "BOOLEAN", "FFSetPixel", "int", $x, "int", $y, "int", $Color, "int", $NoSnapShot)
If ((Not IsArray($Result)) OR $Result[0]<>1) Then
SetError(1)
Return False
EndIF
Return true
EndFunc
;bool WINAPI DuplicateSnapShot(int Src, int Dst);
Func FFDuplicateSnapShot($NoSnapShotSrc, $NoSnapShotDst)
; If $NoSnapShotSrc do not exist, then make the capture
if Not SnapShotPreProcessor(0, 0, 0, 0, false, $NoSnapShotSrc, -1) Then
SetError(2)
Return False
EndIf
$Result = DllCall($FFDllHandle, "BOOLEAN", "DuplicateSnapShot", "int", $NoSnapShotSrc, "int", $NoSnapShotDst)
If ((Not IsArray($Result)) OR $Result[0]<>1) Then
SetError(1)
Return False
EndIF
Return true
EndFunc
; GetRawData Function - Gives RawBytes of the SnapShot
; Wrapper made by frank10
; If unsuccessful, @Error = 1 and returns 0
; Success: it returns a string stride with the Raw bytes of the SnapShot in 8 Hex digits (BGRA) of pixels from left to right, top to bottom
; every pixel can be accessed like this: StringMid($sStride, $pixelNo *8 +1 ,8) and you get 685E5B00 68blue 5Egreen 5Bred 00alpha
;Proto C: int * WINAPI GetRawData(int NoSnapShot, int &NbBytes);
Func FFGetRawData($NoSnapShot=$FFLastSnap)
$aResult = DllCall($FFDllHandle, "ptr", "GetRawData", "int", $NoSnapShot, "int*", 0)
If ( Not IsArray($aResult) ) Then
SetError(1)
Return False
EndIf
Local $t_Raw = DllStructCreate('ubyte['& $aResult[2] & ']',$aResult[0])
Local $sStride = DllStructGetData($t_Raw, 1)
$sStride = StringRight($sStride,StringLen($sStride)-2)
Return $sStride
EndFunc
; FFComputeMeanValues Function - Gives mean Red, Green and Blue values, useful for detecting changed areas
; Wrapper made by frank10
; If unsuccessful, @Error = 1 and returns 0
; It returns an array with:
; [0]: MeanRed
; [1]: MeanGreen
; [2]: MeanBlue
; Proto C : int WINAPI ComputeMeanValues(int NoSnapShot, int &MeanRed, int &MeanGreen, int &MeanBlue);
Func FFComputeMeanValues($NoSnapShot=$FFLastSnap)
$aResult = DllCall($FFDllHandle, "int", "ComputeMeanValues", "int", $NoSnapShot, "int*", 0, "int*", 0, "int*", 0)
If ( Not IsArray($aResult) OR $aResult[0]<>1) Then
SetError(1)
Return False
EndIf
local $MeanResult[3] = [$aResult[2], $aResult[3], $aResult[4]] ; MeanRed, MeanGreen, MeanBlue
return $MeanResult
EndFunc
; FFApplyFilterOnSnapshot Function - apply an AND filter on each pixels in the SnapShot
; Wrapper made by frank10
; If unsuccessful, @Error = 1 and returns 0
; Success: It returns 1
;Proto C : int WINAPI ApplyFilterOnSnapShot(int NoSnapShot, int Red, int Green, int Blue); // ** New in version 2.0 **
Func FFApplyFilterOnSnapShot($Red, $Green, $Blue, $NoSnapShot=$FFLastSnap)
$aResult = DllCall($FFDllHandle, "int", "ApplyFilterOnSnapShot", "int", $NoSnapShot, "int", $Red, "int", $Green, "int", $Blue)
If ( Not IsArray($aResult) OR $aResult[0]<>1) Then
SetError(1)
Return False
EndIf
return true
EndFunc
; FFDrawSnapShotXY Function - same as DrawSnapShot, with specific top-left position for drawing
; Wrapper made by frank10
; If unsuccessful, @Error = 1 and returns 0
; Success: returns 1
;Proto C : bool WINAPI DrawSnapShotXY(int NoSnapShot, int X, int Y); // ** New in version 2.0 **
Func FFDrawSnapShotXY($iX, $iY, $NoSnapShot = $FFLastSnap)
if $FFLastSnapStatus[$NoSnapShot] <> 1 Then
SetError(2)
Return False
EndIf
$Result = DllCall($FFDllHandle, "BOOLEAN", "DrawSnapShotXY", "int", $NoSnapShot, "int", $iX, "int", $iY)
If ((Not IsArray($Result)) OR $Result[0]<>1) Then
SetError(1)
Return False
EndIF
Return true
EndFunc