crashdemons Posted April 7, 2008 Share Posted April 7, 2008 (edited) This script is able to translate window pixel data into an ascii image using a script-defined "grayscale"It also has color support if you save the output as an HTML Self-Screenshots:Changelog:1.5 - Grayscale palette now extended on load for faster matching; Pixel color conversions are cached; Ascii mode for HTML removed (ugly); Screenshot now loaded before conversions to reduce errors from changes over time.; Timers added to output to reduce GUI processing cost.1.4 - Blank title now matches the entire desktop; Added vert/horiz step settings (I wouldn't change these unless the image is going to be resized smaller)1.3 - Fixed: if $ShowHTMLInColor is false, and the output is saved as HTML, a grayscale HTML image is made where it originally didn't. Added Optional Switch Between Natural/Mathematical Color-to-GrayScale Conversion ($ColorMode)1.21 - Better $gs grayscale - added another decimal place JUST for $gs changes (If you use .txt format or $ShowHTMLDefinit, $gs changes effect how good the picture looks)1.2 - Better window Matching + Inexistant window catching. (thanks SxyfrG)1.1 - Quick Fix (before posting even)Notes:-HTML output looks best in Internet Explorer ... :| +Text output from this program looks best in Terminal font (Stand back from your monitor )+The bottom box is the (partial match) title of the window to screenshot+To use HTML support, save as a .htm or .html-HTML support doesn't look good with the grayscale characters, so $ShowHTMLDefinit is off by default-Yes I know it needs a better set of Grayscale characters - if you have a better one, or one that works for a different font than "Terminal" please post your edited $gs.expandcollapse popup;Ascii Screenshot 1.5 ;By Crash Daemonicus #include <Array.au3> Opt("WinTitleMatchMode",2) ;---------SETTINGS---------- Global $gs='#H@R&$X81>l!;+:,. ' ;$gs is the Grayscale Ascii spectrum from black to white Global $ShowHTMLInColor=True ;Switches whether the "pixels" are colored in HTML output Global $ColorMode=True ;Sets the mode for grayscale conversion, True is mathematically, False is Naturally (Mathematically, grayscale is R+G+B; Naturally, the darkness isn't the same between R,G and cool.gif Global $black=0 ;Sets the black color value - should be 0 Global $white=RGB_To_BW(16777215,$ColorMode) ;Sets the white color value - should be FF Global $HSteps=1 ;Sets the steps to take when capturing a row (setting this higher decreases horiz. quality/size but increases speed) Global $VSteps=1 ;Sets the steps to take when capturing all rows (setting this higher decreases vertic. quality/size but increases speed) ;--------------------------- Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Ascii Screenshot", 279, 106, 193, 115) GUISetOnEvent(-3,"_exit") $outfile = GUICtrlCreateInput("output.txt", 61, 2, 130, 21) $getscreen = GUICtrlCreateButton("Get Screen", 192, 27, 78, 20, 0) $Label1 = GUICtrlCreateLabel("Output File", 3, 4, 55, 17) $pointbox = GUICtrlCreateLabel("0%", 0, 27, 40, 20, -1, $WS_EX_CLIENTEDGE) $windowbox=GUICtrlCreateInput("[ACTIVE]", 61, 27, 130, 20) $status=GUICtrlCreateLabel('Starting...',0,27+20,279,60,-1,$WS_EX_CLIENTEDGE) $browse = GUICtrlCreateButton("Browse...", 193, 3, 78, 20, 0) GUICtrlSetState($getscreen,128) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetOnEvent($getscreen,"GetScreen") GUICtrlSetOnEvent($browse,"Browse") Global $pps=0 Global $pixels=0 Global $seconds=0 Global $cacher=0 Global $cachew=0 Global $cachewh=0 Global $_ScreenTimer Global $gsl=StringLen($gs) _Status('Please Wait: Extending Grayscale palette...') $gs2='' $gsa=StringSplit($gs,'') $max=$white-$black $l_color=-1 $l_bufa='' $gsa2=$gsa $xmax=Int($max/$gsl) $remainder=$max-($xmax*$gsl) $i=1 For $i=0 To $black $gs2&=$gsa[1] Next $imin=$black+1 $imax=$xmax For $i=1 To $gsl $rmax=Ceiling($remainder/$gsl) $imax+=$rmax $remainder-=$rmax $c=$gsa[$i] For $ii=$imin To $imax $gs2&=$c Next _ProgressTimer($i,1,$gsl,200) $imin=$imax+1 $imax=$imin+($xmax-1) Next $gs=$gs2 $_ProgTimer=-1 _ProgressTimer(1,0,1,200) _Status('Ready...') GUICtrlSetState($getscreen,64) While 1 sleep(300) WEnd Func Browse() $fsd=FileSaveDialog("Save Ascii Image",@WorkingDir,'Text files (*.txt)|HTML files (*.htm;*.html)|All (*.*)') If @error Or $fsd=='' then Return 0 GUICtrlSetData($outfile,$fsd) EndFunc Func GetScreen() Global $pps=0 Global $pixels=0 Global $seconds=0 Global $cacher=0 Global $_ScreenTimer GUICtrlSetState($getscreen,$GUI_DISABLE) _Status('Preparing Settings...') $window=GUICtrlRead($windowbox) If $window=="" Then Local $wgp[4] $wgp[0]=0 $wgp[1]=0 $wgp[2]=@DesktopWidth $wgp[3]=@DesktopHeight Else If WinExists($window)==0 Then MsgBox(0,'Error Finding Window',"I'm Sorry, but I could not find that window.") GUICtrlSetState($getscreen,$GUI_ENABLE) Return 0 Else $wgp=WinGetPos($window) EndIf EndIf $fn=GUICtrlRead($outfile) $html=False $gsl=StringLen($gs) If StringInStr($fn,'.htm') Then $html=True $gsa=StringSplit('#','') $gsl=1 Else $gsa=StringSplit($gs,'') EndIf $x1=$wgp[0] $y1=$wgp[1] $x2=$wgp[0]+$wgp[2] $y2=$wgp[1]+$wgp[3] $buf='' If $html Then $buf&='<HTML><BODY><style type="text/css">'&@CRLF $buf&='<!-- '&@CRLF $buf&='font,body,br,pre,div {margin:0; padding:0; font-family:Terminal; font-size:4px; line-height:4px; letter-spacing:0px;}'&@CRLF $buf&=' -->'&@CRLF $buf&='</style><div NOWRAP>'&@CRLF Else $buf&='Please View in "TERMINAL" font.'&@CRLF EndIf _Status('Loading Screenshot...') Local $ColorArrayY[$wgp[3]+1] For $y=$y1 To $y2 step $VSteps Local $ColorArrayX[$wgp[2]+1] $x=0 For $x=$x1 To $x2 step $HSteps $ColorArrayX[$x-$x1]=PixelGetColor($x,$y) Next $ColorArrayY[$y-$y1]=$ColorArrayX $delay=200 If $y=$y2 Then $delay=0 _ProgressTimer($y,$y1,$y2,$delay) Next _Status('Converting Screenshot...') $_ScreenTimer=TimerInit() For $y=$y1 To $y2 step $VSteps $x=0 $ColorY=$ColorArrayY[$y-$y1] For $x=$x1 To $x2 step $HSteps $color=$ColorY[$x-$x1];PixelGetColor($x,$y) $bufa=_Pixel_GetCache($color,$html) If $bufa=='' Then _StatusT('Converting...',$html) $bw=RGB_To_BW($color,$ColorMode) If $html Then $chosencolor=$color If $ShowHTMLInColor==False Then $chosencolor=BW_To_RGB($bw) $bufa='<font color="#'&Hex($chosencolor,6)&'">#</font>' Else If $bw>$gsl Then $bw=$gsl $bufa=$gsa[$bw+1] EndIf _Pixel_SetCache($color,$bufa,$html) EndIf $pixels+=1 $buf&=$bufa Next If $html Then $buf&='<br>' $buf&=@CRLF $delay=300 If $y=$y2 Then $delay=0 _ProgressTimer($y,$y1,$y2,$delay) Next If $html Then $buf&=@CRLF&'</div></font></BODY></HTML>' _Status('Saving Screenshot...') FileOverwrite($fn,$buf) _Status('Ready...') GUICtrlSetState($getscreen,$GUI_ENABLE) EndFunc Func _Pixel_GetCache($color,$html) $vn='pxc_'&String($color) If $html Then $vn&='h' If IsDeclared($vn)=0 Then Return '' $cacher+=1 _StatusT('Reading Cache...',$html) Return Eval($vn) EndFunc Func _Pixel_SetCache($color,$bufa,$html) $vn='pxc_'&String($color) If $html Then $vn&='h' $cachewh+=1 Else $cachew+=1 EndIf _StatusT('Writing Caching...',$html) ;ConsoleWrite($vn&'='&$bufa&@CRLF) Assign($vn,$bufa,2) EndFunc Func _StatusT($t,$html) Global $_StatusTimer, $max If TimerDiff($_StatusTimer)>400 Then $seconds=TimerDiff($_ScreenTimer)/1000 $pps=Round(($pixels/$seconds),2) If $html Then $cwt=$cachewh Else $cwt=$cachew&' / '&$white EndIf _Status('Converting: '&$t&@CRLF&'Pixels Per Second: '&$pps&@CRLF&'Colors Cached: '&$cwt&@CRLF&'Cache Reads: '&$cacher) $_StatusTimer=TimerInit() EndIf EndFunc Func _Status($t) GUICtrlSetData($status,$t) EndFunc Func _ProgressTimer($i,$n,$x,$delay=100) ;I only do this so that updating the GUI doesnt slow the program down. Global $_ProgTimer If TimerDiff($_ProgTimer)>$delay Then GUICtrlSetData($pointbox,Round(_ConvertRange($i, $n,$x, 0, 100),0)&'%') $_ProgTimer=TimerInit() EndIf EndFunc Func _exit() Exit EndFunc Func RGB_To_BW($color,$Mathematical=False) ; $hexcol=Hex($color,6) $red=_Bit_Mid($color,1,8) $grn=_Bit_Mid($color,9,16) $blu=_Bit_Mid($color,16,23) If $Mathematical Then Return Int($red+$grn+$blu) Else ;RGB -> Grayscale ;Mathematically, grayscale=_ConvertRange($color, 0, 0xFFFFFF, 0, 255) is correct ;BUT visually, grayscale=(30% red+59% green+11% blue) is more correct Return Int((0.30*$red)+(0.59*$grn)+(0.11*$blu)) EndIf EndFunc Func BW_To_RGB($color) ;This will not convert grayscale to colors, but rather Grayscale values to RGB values Return $color*65536+$color*256+$color EndFunc Func _Bit_Mid($int,$start,$count=-1) $len=_Bit_Len($int) $int=_Bit_TrimLeft($int,$start-1) $len=$len-($start-1) If $count>-1 And $count<$len Then ;$count $int=BitShift($int,$len-$count) EndIf Return $int EndFunc Func _Bit_TrimLeft($int,$bits) ;BitShift($int,+) is technically _Bit_TrimRight ;BitShift($int,-) is technically _Bit_PadRight0 $len=_Bit_Len($int) $bits=$len-$bits $leftbits=BitShift($int,$bits) Return $int-BitShift($leftbits,0-$bits) EndFunc Func _Bit_Len($int) If $int=0 Then Return 0 If $int<0 Then $int=BitNot($int) Return Floor(Log($int)/Log(2))+1 EndFunc Func _ConvertRange($i, $n, $x, $nb, $xb) Return ((($i - $n) / ($x - $n)) * ($xb - $nb)) + $nb EndFunc Func FileOverwrite($file, $data) $fh = FileOpen($file, 2 + 16) $d = FileWrite($fh, StringToBinary($data)) FileClose($fh) Return $d EndFunc ;==>FileOverwrite5-5-13 edit: Fixed post images Edited May 6, 2013 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
crashdemons Posted April 7, 2008 Author Share Posted April 7, 2008 (edited) Can it only capture its own window?No - the bottom box defines WHICH window to capture (matching a window title or advanced window matching code). Since it is defaulted to "[ACTIVE]" it will capture it's own window if you do not change the text before hitting the "Get Screen" button. Edited April 7, 2008 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
SxyfrG Posted April 7, 2008 Share Posted April 7, 2008 This is great! A few problems though, you seem to have minimal error checking I entered in a non-existent window title and it errored out (including If WinExists ( GUICtrlRead ( $WindowBox ) ) = 1 Then would be better ) And to make title matching easier ... Opt("WinTitleMatchMode",2) ;Match any substring in a title My scripts:AppLauncherTRAY - Awesome app launcher that runs from the system tray NEW VERSION! | Run Length Encoding - VERY simple compression in pure autoit | Simple Minesweeper Game - Fun little game :)My website Link to comment Share on other sites More sharing options...
crashdemons Posted April 7, 2008 Author Share Posted April 7, 2008 This is great!A few problems though, you seem to have minimal error checking I entered in a non-existent window title and it errored out (including If WinExists ( GUICtrlRead ( $WindowBox ) ) = 1 Then would be better )And to make title matching easier ...Opt("WinTitleMatchMode",2) ;Match any substring in a titleThanks, I updated the code in the main post to fix that. My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
sensalim Posted April 7, 2008 Share Posted April 7, 2008 Looks cool! Link to comment Share on other sites More sharing options...
NeoFoX Posted April 7, 2008 Share Posted April 7, 2008 Nice idea but the 'get-only-a-window-option' would be nice.. Or the option which I have in my Pixel-to-data-program, to chose an image would be nice! Great work igg. Grtz, Neo [center][font="Arial"]--- The Neo and Only --- [/font][font="Arial"]--Projects---[/font]Image to Text converterText to ASCII converter[/center] Link to comment Share on other sites More sharing options...
LIMITER Posted April 7, 2008 Share Posted April 7, 2008 Cool script !! Link to comment Share on other sites More sharing options...
thomaatje Posted April 7, 2008 Share Posted April 7, 2008 Great script! Link to comment Share on other sites More sharing options...
crashdemons Posted April 8, 2008 Author Share Posted April 8, 2008 Nice idea but the 'get-only-a-window-option' would be nice..Or the option which I have in my Pixel-to-data-program, to chose an image would be nice!Great work igg.Grtz,NeoThanks, I didn't know you made something similar - it wasn't my intention to recreate something that had already been made .Also, I'm not quite sure on the best way to retrieve pixel colors from an image using autoit. My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
crashdemons Posted June 12, 2008 Author Share Posted June 12, 2008 Update 1.5 Grayscale palette now extended on load for faster matching Pixel color conversions are cached Ascii mode for HTML removed (ugly) Screenshot now loaded before conversions to reduce errors from changes over time. Timers added to GUI updating to reduce processing cost over time. My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
EvAsion Posted June 12, 2008 Share Posted June 12, 2008 one of these has been made in autoit before. |-- Periodic Table --||-- Dynamic Class Timetable --||-- Navigation in Counter-Strike --| Link to comment Share on other sites More sharing options...
crashdemons Posted June 12, 2008 Author Share Posted June 12, 2008 (edited) one of these has been made in autoit before.Didn't see it when I did a search the first time - so I made it.Although it doesn't really matter, does it?Since, there can be more than program available for something. Edited June 12, 2008 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
EvAsion Posted June 12, 2008 Share Posted June 12, 2008 Didn't see it when I did a search the first time - so I made it.Although it doesn't really matter, does it?Since, there can be more than program available for something.I'm not saying yours is bad, infact yours seems to be much faster than the original, athough the original had a lot more features including only using user defined sets of characters, only certain shades of colours.. etc. etc. (this was 1+years ago btw) |-- Periodic Table --||-- Dynamic Class Timetable --||-- Navigation in Counter-Strike --| 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