google / gif-for-cli

https://opensource.googleblog.com/2018/06/tenor-gif-for-cli.html
Apache License 2.0
2.93k stars 161 forks source link

Make better image accuracy by improving the algorithm #27

Open strear opened 2 years ago

strear commented 2 years ago

Now, gif-for-cli still uses a predefined constant . ,\'-:;!" ^/+? *&8#$@% to match the brightness and generate the image, like all similar tools do. This approach does not make effective use of all the visible characters in the ASCII character set, and some uneven symbols like ^ and , would give the output image a "broken" feel.

Perhaps we can introduce a kind of "oversampling" method: since the input is a bitmap, we could also divide the glyph of each character into 𝑛² pieces (say 4 or 9 pieces), and compare in the scaled original image for an equally sized area. By using an optimized π‘˜-d tree (π‘˜ = 𝑛²), the single most accurate character can be found instantly for each 𝑛² pixels. This would be a major improvement for gif-for-cli.

Screenshot 2022-01-03 123405 Screenshot 2022-01-03 125115

Original: http://9front.org/img/9iknowthis01.png

I have written an example implementing this idea for reference (strear/saam), but its code is in C++. Do the maintainers and the pull request people have any good ideas on how to merge this implementation in?