wpanther93 Posted April 9, 2010 Share Posted April 9, 2010 Hey, I'm new to the forums, but I've been using autoit to automate windows task for a while. I had a few questions about pixel search: How efficient is it? (how long would it take to scan the entire screen for a specific color?) I also would like to know about restraining it to a window. I know the nousecoordmode option is used, but do I have to set it to 0 and also use the hwnd parameter? Any clarification would be most helpful. Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted April 9, 2010 Share Posted April 9, 2010 Hi and Welcome to the forums! If Aero (and thus DWM) is enabled you'll have to disable it to get max speed. I whipped up a quick example: If _DwmIsEnabled() = True Then $Text = "By turning off DWM this script will be much much faster." & @CRLF & "Would you like me to turn off DWM for you??" & @CRLF & "(will be activated again when script end)" If MsgBox(4+32+262144, "It seems like you have DWM running.", $Text) = 6 Then _DwmEnable(False) EndIf $iTimer = TimerInit() PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 0x123456) ConsoleWrite("Pixelsearch took: " & Round(TimerDiff($iTimer)) & " ms" & @CRLF) Func _DwmIsEnabled() If FileExists(@SystemDir & "\dwmapi.dll") Then $Receiver = DllStructCreate("int") $aTemp = DllCall("dwmapi.dll", "uint", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($Receiver, 1)) $Receiver2 = DllStructCreate("int", $aTemp[1]) If DllStructGetData($Receiver2, 1) = True Then Return 1 Else Return SetError(1, 0, 0) EndIf Else Return SetError(2, 0, 0) EndIf EndFunc Func _DwmEnable($WhatToDo) DllCall("dwmapi.dll", "uint", "DwmEnableComposition", "int", $WhatToDo) EndFunc My result are around 60-80ms with DWM on and around 30ms with it off. My screen is 1600x1200. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Yoriz Posted April 9, 2010 Share Posted April 9, 2010 Run on your own pc to see what times you get #include <WindowsConstants.au3> GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP) GUISetBkColor("0xFFFFFF") GUICtrlCreateGraphic(@DesktopWidth-2, @DesktopHeight-2, 2, 2) GUICtrlSetBkColor(-1,"0x000000") GUISetState() $timer = TimerInit() $aPixelfound = PixelSearch(1, 1, @DesktopWidth-1, @DesktopHeight-1, "0x000000") $timer = TimerDiff($timer) ConsoleWrite("PixelSearch took " & $timer/1000 & " Seconds To find pixel at" & @CR & "X = " & $aPixelfound[0] & @CR & "Y = " & $aPixelfound[1] & @CR) MsgBox(0,"PixelSearch took " & $timer/1000 & " Seconds","To find pixel at" & @CR & "X = " & $aPixelfound[0] & @CR & "Y = " & $aPixelfound[1]) $hSearchInWindow = GUICreate("", 100, 100, 100, 100, $WS_POPUP) GUISetBkColor("0x000000") GUICtrlCreateGraphic(90, 90, 2, 2) GUICtrlSetBkColor(-1,"0xFFFFFF") GUISetState() Opt("PixelCoordMode", 0) $timer = TimerInit() $aPixelfound = PixelSearch(0, 0, 99, 99, "0xFFFFFF", 0, 1, $hSearchInWindow) $timer = TimerDiff($timer) ConsoleWrite("PixelSearch in window took " & $timer/1000 & " Seconds To find pixel at" & @CR & "X = " & $aPixelfound[0] & @CR & "Y = " & $aPixelfound[1] & @CR) MsgBox(0,"PixelSearch in window took " & $timer/1000 & " Seconds","To find pixel at" & @CR & "X = " & $aPixelfound[0] & @CR & "Y = " & $aPixelfound[1]) #cs PixelSearch took 0.0692593611757919 Seconds To find pixel at X = 1678 Y = 1048 PixelSearch in window took 0.000674108022108955 Seconds To find pixel at X = 90 Y = 90 #ce GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. Link to comment Share on other sites More sharing options...
wpanther93 Posted April 10, 2010 Author Share Posted April 10, 2010 Thanks guys. That clears that up for me completely. I was afraid it would be more along the line of seconds than milliseconds. How about restraining it to a window with pixel search? Link to comment Share on other sites More sharing options...
somdcomputerguy Posted April 10, 2010 Share Posted April 10, 2010 WinGetPos - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
wpanther93 Posted April 10, 2010 Author Share Posted April 10, 2010 Perfect! I was stuck thinking I would have to use the window handle or mousecoordmode, but this is much easier. Thanks everyone. Link to comment Share on other sites More sharing options...
ahha Posted April 11, 2010 Share Posted April 11, 2010 (edited) Question. On win7 x64 (4GHz) PixelGetColor takes about 33ms/pixel. Even with DWM off it takes 10ms/pixel, so it's about 3 times faster but switching DWM off/on really tears up the screen. However, PixelSearch is blindingly fast in comparison searching a 1680x1050 screen (almost 2 million pixels) in about 150ms? What routine is PixelSearch using to get pixel color? Edited April 11, 2010 by ahha Link to comment Share on other sites More sharing options...
Ascend4nt Posted April 11, 2010 Share Posted April 11, 2010 It'd be my guess that PixelSearch() is grabbing the bitmap into memory using GetDIBits (see MSDN) for searching. This is what I use for reading pixels from memory (there's multiple examples of this on the web). Only issue is that you have to mask off the top 8 bits when you read it in RGB mode. The PixelGetColor() function probably directly uses GetPixel (see MSDN for this too). My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
ahha Posted April 11, 2010 Share Posted April 11, 2010 (edited) Thanks. For others searching GetDIBits is here: http://msdn.microsoft.com/en-us/library/dd144879%28VS.85%29.aspx and GetPixel is here: http://msdn.microsoft.com/en-us/library/dd144909%28VS.85%29.aspx Here's a really good explanation of why GetPixel is dog SLOW. http://social.msdn.microsoft.com/Forums/en-US/windowsuidevelopment/thread/4db649d2-4747-4773-8f9a-9b74dacc5a7d Also found a post here subject: http://www.autoitscript.com/forum/index.php?showtopic=106407 PixelGetColor vs. _GDIPlus_BitmapLockBits posted by QED Posted 05 December 2009 - 02:43 PM which talks about speed. Edited April 11, 2010 by ahha Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now