CptSpike 0 Posted October 16, 2012 Title may not be particularly clear, sorry I'm struggling to put my problem in to words. But here goes. I'm writing a program that takes pixel colour info from the mouse pointer, and looks it up in an INI file to see the corresponding Pantone colour. Snippet of the INI looks like this: 16702208=108C 16765184=109C 14396928=110C (Pantone colour on the right) This is great if the pixel colour matches exactly, but if not, the user gets nothing. I want them to get the nearest match. Is it possible for AutoIt to select the nearest listed decimal number? I tried adding 1 to the pixel decimal number until it hits a matching a Pantone colour but this is far too slow. Sorry if I'm not articulating this very well. Many thanks. -CptSpike Share this post Link to post Share on other sites
water 2,359 Posted October 16, 2012 How many entries do you have in your INI file? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
FireFox 260 Posted October 16, 2012 Hi, I think you will need to get the section keys with IniReadSection and then comparing the data to get the nearest pantone color. Br, FireFox. OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDFMy Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme makerMy Examples : Capture tool | IP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewerMy Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control Share this post Link to post Share on other sites
CptSpike 0 Posted October 16, 2012 Exactly 907 entries, only one section name Firefox. Share this post Link to post Share on other sites
FireFox 260 Posted October 16, 2012 Exactly 907 entries, only one section name Firefox.I haven't asked how many section do you have OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDFMy Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme makerMy Examples : Capture tool | IP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewerMy Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control Share this post Link to post Share on other sites
CptSpike 0 Posted October 16, 2012 No I mean there are no section names to compare - only one section name. [Decimal] to be precise. Share this post Link to post Share on other sites
FireFox 260 Posted October 16, 2012 No I mean there are no section names to compare - only one section name. [Decimal] to be precise. oh, I meant compare pantone colors in the array (which contains all pantone colors). OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDFMy Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme makerMy Examples : Capture tool | IP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewerMy Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control Share this post Link to post Share on other sites
water 2,359 Posted October 16, 2012 The solution Firefox suggests should do what you need. InIReadSections returns a 2D array. If the entries are already sorted then search until you find a value which is higher than the value you want to comapre. Then take this or the previous value. You need to handle the situation where the first or last entry of the array is returned so you don't get out of bounds. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
CptSpike 0 Posted October 16, 2012 Oh I see. Hadn't thought about that. Still not sure where to go from there - most of the decimal values the program looks up won't be listed in the ini file, how would I get it to pick the closest match instead? Share this post Link to post Share on other sites
water 2,359 Posted October 16, 2012 This example will return the next highest value if the search value is not found in the ini file. It returns -1 if the search value is higher then the highest value in the ini file. Example works for this ini file: [section1] 16702208=108C 16765184=109C 14396928=110C #include <array.au3> Global $aValues = IniReadSection("C:temppantone.ini", "Section1") _Arraysort($aValues, 0, 1, 0, 0) _ArrayDisplay($aValues) Global $iReturn, $iSearchFor = 1670000 $iReturn = Search($iSearchFor) MsgBox(0, "", "Value searched: " & $iSearchFor & @CRLF & "Value returned: " & $iReturn) Func Search($iSearch) For $i = 1 To $aValues[0][0] If $aValues[$i][0] > $iSearch Then Return $aValues[$i][1] ConsoleWrite($i & @LF) Next Return -1 ; Value not found in table Endfunc My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
Melba23 3,398 Posted October 16, 2012 CptSpike,Ii fear there is a fundamental flaw in your +1 theory. The colour is made up of 3 elements (RGB) and each of them can vary slightly. So you need to add to each element of the colour and not just the final total. This code gives you the idea:expandcollapse popup$iPantone = "FEDB00" ; Hex of 16702208 ; Simulate PixelGetColor converted to Hex $iColor = "FDDA00" $iRed = StringMid($iColor, 1, 2) $iGrn = StringMid($iColor, 3, 2) $iBlu = StringMid($iColor, 5, 2) ; Start by adding to R $iTest_Color = Hex(Dec($iRed) + 1, 2) & $iGrn & $iBlu If $iTest_Color = $iPantone Then ConsoleWrite("Found!" & @CRLF) EndIf ; Now G $iTest_Color = $iRed & Hex(Dec($iGrn) + 1, 2) & $iBlu If $iTest_Color = $iPantone Then ConsoleWrite("Found!" & @CRLF) Else ConsoleWrite($iTest_Color & " - " & $iPantone & @CRLF) EndIf ; Now B $iTest_Color = $iRed & $iGrn & Hex(Dec($iBlu) + 1, 2) If $iTest_Color = $iPantone Then ConsoleWrite("Found!" & @CRLF) Else ConsoleWrite($iTest_Color & " - " & $iPantone & @CRLF) EndIf ; Now RG $iTest_Color = Hex(Dec($iRed) + 1, 2) & Hex(Dec($iGrn) + 1, 2) & $iBlu If $iTest_Color = $iPantone Then ConsoleWrite("Found!" & @CRLF) Else ConsoleWrite($iTest_Color & " - " & $iPantone & @CRLF) EndIf ; Now RB $iTest_Color = Hex(Dec($iRed) + 1, 2) & $iGrn & Hex(Dec($iBlu) + 1, 2) If $iTest_Color = $iPantone Then ConsoleWrite("Found!" & @CRLF) Else ConsoleWrite($iTest_Color & " - " & $iPantone & @CRLF) EndIf ; Now GB $iTest_Color = $iRed & Hex(Dec($iGrn) + 1, 2) & Hex(Dec($iBlu) + 1, 2) If $iTest_Color = $iPantone Then ConsoleWrite("Found!" & @CRLF) Else ConsoleWrite($iTest_Color & " - " & $iPantone & @CRLF) EndIf ; Now RGB $iTest_Color = Hex(Dec($iRed) + 1, 2) & Hex(Dec($iGrn) + 1, 2) & Hex(Dec($iBlu) + 1, 2) If $iTest_Color = $iPantone Then ConsoleWrite("Found!" & @CRLF) Else ConsoleWrite($iTest_Color & " - " & $iPantone & @CRLF) EndIfYou can see that you need to vary the colour elements separately to match the Pantone value. Of course in the real case you would need to subtract as well as add and the number of combinations you need to test becomes quite large. There should be a way of doing it faster using the Bit* functions rather then the cumbersome proof-of-concept code I used above - I will have a think about it. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Share this post Link to post Share on other sites
jdelaney 313 Posted October 16, 2012 Using Water's array #include <array.au3> #include <Color.au3> Global $aValues = IniReadSection("C:temppantone.ini", "Section1") _Arraysort($aValues, 0, 1, 0, 0) ;_ArrayDisplay($aValues) $iColor = 16702209 $iGreen = _ColorGetGreen ( $iColor ) $iRed = _ColorGetRed ( $iColor ) $iBlue = _ColorGetBlue ( $iColor ) ConsoleWrite ( $iGreen & " " & $iRed & " " & $iBlue & @CRLF ) Dim $aDiff[1][2] $iCounter = 0 For $i = 1 To UBound ( $aValues ) - 1 $iCurrentDiff = Abs ( _ColorGetGreen ( $aValues[$i][0] ) - $iGreen ) + Abs ( _ColorGetRed ( $aValues[$i][0] ) - $iRed ) + Abs ( _ColorGetBlue ( $aValues[$i][0] ) - $iBlue ) ReDim $aDiff[$iCounter+1][2] $aDiff[$iCounter][0] = $iCurrentDiff $aDiff[$iCounter][1] = $i $iCounter += 1 Next _ArraySort ( $aDiff, 0,0,0,0 ) $iLowestDiff = $aDiff[0][1] ConsoleWrite ( "Value searched: " & $iColor & @CRLF & "Value returned: " & $aValues[$iLowestDiff][0] & @CRLF ) 1 CptSpike reacted to this IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Share this post Link to post Share on other sites
CptSpike 0 Posted October 16, 2012 (OffTopic) I love this forum. So helpful. (OnTopic) Will play around with my code more tomorrow, looks like the array method is the way to go. Thanks for pointing out the mathemathical flaw Melba - I assumed the colours would follow a linear decimal pattern. But life is never simple jdelaney, may I shamelessly steal your code? Share this post Link to post Share on other sites
kylomas 415 Posted October 16, 2012 CptSpike, Posted code is posted code...do yourself a favor and take time to understand the code. Good Luck, kylomas 1 CptSpike reacted to this Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Share this post Link to post Share on other sites
CptSpike 0 Posted October 16, 2012 Thought it would be nice to ask anyways thanks everyone for the help. -CptSpike Share this post Link to post Share on other sites