The old version of catimg
was slow, VERY slow.
Displaying sprites and tiny pictures was very cool as it was quite fast but larger images took years to render and I was so sad about that :(
By googling catimg
I found this nifty gist. It was quite funny because the script was published some days after mine but it was way faster (Even more if we take into account the very first version with grep
uugh). The point is that some lines of code made me see that I was a fool using such slow techniques to convert colors…
I’m refering to this lines
Well first of all the (( x = a + b, y = 3 ))
was new to me and I found it very nice (much better than using expr
all the time), but I realized that the color could be calculated. I didn’t see that colors code were used in a particular order and that I could exploit that, shame on me…
Then I realized that the script didn’t converted grayscale colors so I added it:
I also check for transparent colors and that’s why there is a "$R" = "NO"
but that’s not the point. Just by doing that the script speed TRIPLED.
After this I looked at another line:
Instead of saving the conversion to a new file just output it to teh stdout and parse it live. I used my own command line with my regexp and replaced the _
with f
because it gave some troubles and voila:
And there it is a super fast catimg script *0*. There is also somethign better about my script: I use the remap
option which gives MUCH better results.
The current version is very fast so I proposed it as a plugin for oh-my-zsh. You can check the pull request here
If you find any improovement to the script, please, send me a message!
You can find the Github repo here.