-
Notifications
You must be signed in to change notification settings - Fork 107
-
Hello, i have this image that i want to render on my terminal:
So i download and try to render it:
curl -sL 'https://veekun.com/dex/media/pokemon/icons/492-sky.png' > shaymin-sky.png chafa --symbols vhalf shaymin-sky.png
But the result seem blurry:
Screenshot from 2021年12月05日 21-46-23
I want the output to be pixel-perfect, am i missing something? you guy have any suggestion?
Beta Was this translation helpful? Give feedback.
All reactions
I spent some time trying to tackle this issue as I think I got a reasonable solution:
I found that -filter did some blurring so I wanted to avoid that option and just use -scale for exact pixel replication.
For the following image:
Running just chafa:
Running:
convert in.png -scale 800% out.png
chafa --scale 1 out.png
We get the pixel perfect:
Note for some small images this doesn't work so well, but for most sprites the above will serve you well.
Here is an example of another image with the prescaling done for chafa and comparing it with timg's output:
Chafa w/ prescaling:
Timg's output with original file:
I would love if there was a mode for pixel perfect display in chafa that so...
Replies: 3 comments 6 replies
-
Which terminal are you running? Try one with sixel support, or Kitty, which is supported through its own protocol. Chafa should detect your terminal and use the correct mode automatically, but if it doesn't, there's always the -f flag (the parameter can be sixel, kitty, iterm, or symbol.
There may still be some blurriness due to scaling. Currently, the only was around that is to prescale the image using nearest-neighbor interpolation. I.e. make the pixels 16x bigger or 32x bigger. Then run chafa on that.
You can do the prescaling using something like convert in.png -filter point -resize 800% out.png.
Beta Was this translation helpful? Give feedback.
All reactions
-
I spent some time trying to tackle this issue as I think I got a reasonable solution:
I found that -filter did some blurring so I wanted to avoid that option and just use -scale for exact pixel replication.
For the following image:
not-shiny:shaymin-sky+male-small
Running just chafa:
chafa-og-shaymin-sky
Running:
convert in.png -scale 800% out.png
chafa --scale 1 out.png
We get the pixel perfect:
chafa-scale-shaymin-sky
Note for some small images this doesn't work so well, but for most sprites the above will serve you well.
Here is an example of another image with the prescaling done for chafa and comparing it with timg's output:
not-shiny:pichu+female-small
Chafa w/ prescaling:
chafa-scale-pichu
Timg's output with original file:
timg-pichu
I would love if there was a mode for pixel perfect display in chafa that somehow bypasses the scaling of the dimension into cells. Note looking at the pipeline end to end, the prescaling does cause that pipeline to be slower than timg's pipeline, while also not being as accurate.
Beta Was this translation helpful? Give feedback.
All reactions
-
🎉 1 -
🚀 1
-
@hpjansson trying to get back into some terminal shenanigans and I remember this was a small lingering nit I had.
I was wondering if half-cell support has been added to Chafa or if there is a plan to add pixel-perfect/half cell support? If there is a plan should an issue be made?
Beta Was this translation helpful? Give feedback.
All reactions
-
There is pixel perfect processing since version 1.14, but only for pixel-based protocols like sixels and iterm2. I still need to make a few adjustments for it to work effortlessly with symbols. You should get the best possible half-cell output this way now:
chafa --scale 8 --symbols vhalf -w 1
The --scale option was added in version 1.12. This respects the view size, so if you want results that can be bigger than the terminal, you should use --view-size 9999x9999 or some other suitably large extent (1.14 onwards).
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 1
-
@hpjansson I want to follow up with this as --symbols vhalf makes the pixel perfect output worse. See the below image for a comparison of chafa (with and without --symbols vhalf) and timg (which still has better output):
Is there a better symbols group I can use, one that has the same group as timg's default (quarter)? See Half block and quarter block rendering on timg's readme for more info.
Edit: we do have --symbols quad, but that doesn't fare better (I tried with all -w options, and -w 9 ends up pretty blurry)
Beta Was this translation helpful? Give feedback.
All reactions
-
👀 1
-
If you want all the quad permutations, you have to explicitly include half-blocks too: --symbols half+quad. You may also get sharper pixels using --color-extractor median. But in order to do this perfectly, we need to implement the following:
- Decouple nearest-neighbor resampling from the
-wswitch (or always do upsampling with nearest-neighbor). - Align image to half-block or quad-block grid. The first example looks like an alignment issue.
Beta Was this translation helpful? Give feedback.
All reactions
-
I feel like decoupling the nearest-neighbor resampling would do the trick.
I didn't even think about the alignment tbh.
Posting output of some various combinations for posterity's sake:
Based on all this as of now (1.14.2) the best way to render a pixel perfect pixelart image is simply chafa --scale 8 --symbols all -w 1.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2
-
Match input and output scale.
Then convert with --symbols vhalf (and no other).
The vertical-half symbol will be invariant, represent two square (vertically stacked) pixels, controlled via fg and bg color.
Limiting the valid character to just 'upper half' maximally aids compression
Beta Was this translation helpful? Give feedback.