junkew Posted January 12, 2009 Posted January 12, 2009 I am trying to find a way with stringregexpreplace to select triplets of bytes and replace with either 0 or 1I understand the concept of regular expressionsPost http://www.autoitscript.com/forum/index.php?showtopic=86773 shows nicely how to select certain colors.I would like to do something like ($sBitmap is the binary representation of a 24 bits image); Selects all pixels below/less than 0x202020 to become white$pixelsWhite = StringRegExpReplace($sBitmap, "([01][0-9A-F][01][0-9A-F][01][0-9A-F])","0"); Selects all pixels above 0x202020 to become black$pixelsBlack = StringRegExpReplace($sBitmap, "([2-9A-F][0-9A-F][2-9A-F][0-9A-F][2-9A-F][0-9A-F])","1")Unfortunately above should check at triplets (3 bytes) and should be more or less in 1 passSo I would like to do something like (watch the or | sign )$pixels = StringRegExpReplace($sBitmap, "([01][0-9A-F][01][0-9A-F][01][0-9A-F])|([2-9A-F][0-9A-F][2-9A-F][0-9A-F][2-9A-F][0-9A-F])","0|1")All I can do now is something like below$pixelsWhite = StringRegExpReplace($sBitmap, "([01][0-9A-F][01][0-9A-F][01][0-9A-F])","000")$pixelsBlack = StringRegExpReplace($sBitmap, "([2-9A-F][0-9A-F][2-9A-F][0-9A-F][2-9A-F][0-9A-F])","111")$pixelsWhite = StringRegExpReplace($sBitmap, "000","0")$pixelsBlack = StringRegExpReplace($sBitmap, "111","1")any suggestions (besides making a for/next loop in triplets) FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
Malkey Posted January 13, 2009 Posted January 13, 2009 I am trying to find a way with stringregexpreplace to select triplets of bytes and replace with either 0 or 1 I understand the concept of regular expressions Post http://www.autoitscript.com/forum/index.php?showtopic=86773 shows nicely how to select certain colors. I would like to do something like ($sBitmap is the binary representation of a 24 bits image) ; Selects all pixels below/less than 0x202020 to become white $pixelsWhite = StringRegExpReplace($sBitmap, "([01][0-9A-F][01][0-9A-F][01][0-9A-F])","0") ; Selects all pixels above 0x202020 to become black $pixelsBlack = StringRegExpReplace($sBitmap, "([2-9A-F][0-9A-F][2-9A-F][0-9A-F][2-9A-F][0-9A-F])","1") Unfortunately above should check at triplets (3 bytes) and should be more or less in 1 pass So I would like to do something like (watch the or | sign ) $pixels = StringRegExpReplace($sBitmap, "([01][0-9A-F][01][0-9A-F][01][0-9A-F])|([2-9A-F][0-9A-F][2-9A-F][0-9A-F][2-9A-F][0-9A-F])","0|1") All I can do now is something like below $pixelsWhite = StringRegExpReplace($sBitmap, "([01][0-9A-F][01][0-9A-F][01][0-9A-F])","000") $pixelsBlack = StringRegExpReplace($sBitmap, "([2-9A-F][0-9A-F][2-9A-F][0-9A-F][2-9A-F][0-9A-F])","111") $pixelsWhite = StringRegExpReplace($sBitmap, "000","0") $pixelsBlack = StringRegExpReplace($sBitmap, "111","1") any suggestions (besides making a for/next loop in triplets)White in 24 bit, 0xRRGGBB hex format is all the colours 0xFFFFFF. Black is no colours 0x000000 This appears to work for any 24 bit colour below 0x202020 changes to black 0x000000. Any colour equal to or greater than 0x202020 changes to white 0xFFFFFF. Local $sBitmap = "8DC7D30A050492CDDC9ED5E216110181C0C47ABEBD79C6BF84CDCB8FC7D28CBECA060C04A5D6CE" $pixels = StringRegExpReplace(StringRegExpReplace($sBitmap, "([01][0-9A-F][01][0-9A-F][01][0-9A-F])", "000000"), _ "([2-9A-F][0-9A-F][2-9A-F][0-9A-F][2-9A-F][0-9A-F])", "FFFFFF") MsgBox(0, "", $pixels)
junkew Posted January 13, 2009 Author Posted January 13, 2009 (edited) Looks good but somehow it fails on added 11 in front and 1111 at end Local $sBitmap = "118DC7D30A050492CDDC9ED5E216110181C0C47ABEBD79C6BF84CDCB8FC7D28CBECA060C04A5D6CE1111" Edited January 13, 2009 by junkew FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
junkew Posted January 13, 2009 Author Posted January 13, 2009 After playing around I found myself the following solution. Any suggestions? Local $sBitmap = "118DC7110011031A150492CDDC9ED5E216110181C0C47ABEBD79C6BF84CDCB8FC7D28CBECA060C04A5D6CE1111" ;First sample $pixels = StringRegExpReplace(StringRegExpReplace($sBitmap, "([01][0-9A-F][01][0-9A-F][01][0-9A-F])", "000000"), _ "([2-9A-F][0-9A-F][2-9A-F][0-9A-F][2-9A-F][0-9A-F])", "FFFFFF") consolewrite($pixels & @crlf & @crlf) ;Explanation / Debugging $pixels = StringRegExpReplace($sBitmap, ".{6}", "$0 ") consolewrite($pixels & @crlf) $pixels = StringRegExpReplace($pixels, "([01][0-9A-F][01][0-9A-F][01][0-9A-F]) ", "GGGGGG") consolewrite($pixels & @crlf) $pixels = StringRegExpReplace($pixels, "([0-9A-F]{6}) ", "FFFFFF") consolewrite($pixels & @crlf) $pixels = StringRegExpReplace($pixels, "G", "0") consolewrite($pixels & @crlf & @crlf) ;Fully working $pixels = StringRegExpReplace($sBitmap, ".{6}", "$0 ") ;~ consolewrite($pixels & @crlf) $pixels = StringRegExpReplace($pixels, "([01][0-9A-F][01][0-9A-F][01][0-9A-F]) ", "G") ;~ consolewrite($pixels & @crlf) $pixels = StringRegExpReplace($pixels, "([0-9A-F]{6}) ", "1") ;~ consolewrite($pixels & @crlf) $pixels = StringRegExpReplace($pixels, "G", "0") consolewrite($pixels & @crlf & @crlf) FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
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