Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dithering with ASCII characters #61

Open
adrhill opened this issue Dec 6, 2021 · 0 comments
Open

Support dithering with ASCII characters #61

adrhill opened this issue Dec 6, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@adrhill
Copy link
Collaborator

adrhill commented Dec 6, 2021

I've taken a brief look into how this is typically done. Usually people define a ramp of ASCII characters to approximate a gray-scale color ramp. In this sense, we can already dither with ASCII characters using the underlying IndirectArray:

using DitherPunk, TestImages, ImageCore, ImageTransformations

img = testimage("fabio_gray_256")
img = imresize(img, ratio=(1//6, 1//3))

ascii_ramp = split(" .:-=+*#%@", "")
cs = Gray.(range(0, 1, length=10)) # match length of ramp

d = dither(img, FloydSteinberg(), cs)
mat = ascii_ramp[d.index]

for r in eachrow(mat)
    println(join(r))
end

which prints the following (make sure your browser window is wide enough):

----::--------::-:-:-::-::-:--------:--=-=-=---:-----:::::-:-:--:-::::::.::.::.:::.::.
-=--::---------::::::::::::------------=--::-=-+=-----=--::-:-:-:-:::::.:.:.::.:.:.:.:
-=--::--------::::::::::::::----------=+++=+=+=-:---:-:-:--::--:-:::-:.:.:.:.:.:.:.:..
=---::-------:::::::::::::::-:-:--:=+==+=-=++++==+==+==--::::::-:-:::.:...:.:.:.:.:.:.
--=-::-:-------::::::::::::-:::--=====##*+======+=-----::-::.:::::::::..:.:.:.:.:.:.:.
-=--::--------:-::::::::-:-:-++=*+*%#*#*****++++++=-=-::-::.::.:-:::::.....:.:.:.:.:.:
-=--:::-----:--:-:-:--:::--=++***#*+++++++++*+=---=-:=:==:-:.:-:::.::.:.:.:.:.:.:.:.:.
=---::-:------:-::::::::-=+++*#*+=--:::-::::--=+==--=-:=-+:::-:::::.:::..:.:.:.:.:.:.:
----::::-:::.:::-:--:-:-=-***--:-:--=+====-::.-:++++-:.:::-:::--::.::::::.:.:.:.:.:..:
-=--::::::::::::::::::--=+=::::--+:.-----:-=-::.:::-::...::::::--=--:-:.:.:.::.:.:.:.:
--=::::::---:-::-:::-:=+=+=:=---::----::::=-:.+..::::.:::.:::::::=--:::::.::.:.:.:.:.:
-=---:::----:-::::-::=++=-=:::.:::==::----:-:-:::.::.::---------:..::::::::..:.:.:::.:
=-=-::::-:=--::-::::=+-=-::::.::-*#*#*+#**#*++**---:-=***+*++=+==:.:::-::::::.:.:..:..
-==-::::------:::---*++-::--:::-=*######%%##%%###########*+++=++=-::.::::::::.::.::.::
------::--=--:-:--=+*+=-=---:-:--+###%##%#%%#%%%%%##%#%#**+++=+=-:::::-:---::::.:.:.:.
-=---:::--==-----+*++-::-:::::::==*###%%#%##%##%#%%######***+++=-.:::-:-::::::-::.:.:.
=-----::--==--=+***+-:-=::.:-:-::=+*######%########%####***+++=+-:..:---==+--:::.:.:.:
--=:-:::---==*+#+#+=-++=:::-:...*+*########%%#%%#%#%%####***++===-.:.:---=----:.:.::..
=-----::--=++=#***-+++=:.:.....-+****#%%%%%#%#%#%#%##%#%#**++----=....:---=-::::::.::.
-=---:::-==+-*+**++*+=-::..:..:=**+++------==+=*#####+-::::::--===:.:..:..::-::::::.:.
-=---::---=+*****+*+*-:::.:....+****+=+#--:+-=-=*##*==++*:-*+--=+===+:..:::-::::-::.:.
=-=---::-=++*++*+**=+=-::::..::=*#%##%****#####+*##*++*+*#**+**+++-++=.:.:::--::-::..:
-=-:-:::-*+#+****#+*=+--::::..:=+*#%%%%%@%%%##*+*##+=++**###****+==#*+...:--:-==::::..
-----::---#*++****+++===-:--:..-+*##%%%%%#%#%#***##*==+**#*##**++=-**-..:::=--=+:-:::.
-=-:--::-=*++*****=++=++-=---:.:=+*##%#%%%#%##***##*+==******++++-=+:...::--+=+---::.:
----:::-=+*+**#**++=+*++-=-....:-=+**######%##***#**+==*****+++==-=...:.:.::=++--:::..
=----::===*+*****+=+*===+=-....::+=+**#*######***%%*+=+++*++++====-....:.:::==-==::::.
-=--:-:-=+#***#*++++-++=+=:.....-=++**#*###*%##=+**++=+*++*+++=====....::.::-----::::.
------:-*#*#*#+*++==*=++=::....::+++++**#**####**+==+++=+==++=====-......:::-:--:::.::
----===**+*+*#***++**+=:::::....-=*++*+*#*********=*+++==+=++==+==:......:::--:-::::.:
=----*+***++******++=---::::.....==*+*+*#*++=--=-=+----=++++==+==-=:.......::-:--:::-:
::=*++=*=++**#***+*==-=:-:::......=++*++***#*****++++++=+++=+===-===--......::-:-:::-:
-=*====++**##**#*+==-+-::::....... .=+++*#****++++==+==+==+===-++====++-=......::.:.::
--*==-=+**#**#**+=====-:-.:..........-=+=**########****+++===-+++====+++*++=..........
:=*+*+**%#####+=+=+++-:-::..:.........-=-=+***####%##**++==-++++==+++=+++++++=......:.
=+++**###*##++=#=+++-:---:.::.:.......:-+=+=+++**++++++=-=++++++++=++++++++++++....:..
**+*#%#***+**+*=*+=::.---.:.::.::......-==+====--------+==++++++++++++=+=++++=++:...::
+###***++*#**+*+---..:::..:::.::......::-+=++++==+****+++*++**+++++*++++++=+======:..:
#***+***##*+**==:-::::.::..:........:.---++++***#********+******++*+*+*++++=+++++++.:.
*****#***+**++-=-:-:::::...::.::.......--=+++++**********#####*+++*******+**+*+++===:.
*%*********+=*-::::::::.:.:.:......:..:::-+**+*+***#***#*#####*+=+#****+**+*++*+*++===
*=#**#***++---:::.:.:.:::....::.:....::.:+*****+*+***#*#*#*#*#++***+++++++*+**+*+*+**+
***#****++=--:=::::.:.:.::..:...:.....:--=********++*****######**+*+*++**+*++**+******

This might be worth adding to the docs.

However, when #60 is implemented, we can go one step further and use font rasterizers like FreeTypeAbstraction.jl to generate tiles from characters, average their color and return ASCII. This would also open up the possibility of supporting colored letters on colored background.

@adrhill adrhill added the enhancement New feature or request label Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant