vo_chafa: add a chafa VO#17725
Conversation
video/out/vo_chafa.c
Outdated
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
|
|
||
| #include <libswscale/swscale.h> |
There was a problem hiding this comment.
I don't think we should be including swscale directly, we use our wrappers anyway.
There was a problem hiding this comment.
You're right, that header seems to be unused
DOCS/man/vo.rst
Outdated
|
|
||
| ``chafa`` | ||
| Graphical output for the terminal, using chafa. Tested with ``ghostty`` and | ||
| ``foot``. |
There was a problem hiding this comment.
While it's good to note where it was tested in PR, I don't think this information is necessary in the documentation that may outlive any of those claims.
There was a problem hiding this comment.
These claims are also present in the docs for the sixel VO. Still removed those from the chafa docs though.
DOCS/man/vo.rst
Outdated
| size both in cells and in pixels. By default it tries to use values which | ||
| the terminal reports, however, due to differences between terminals this is | ||
| an error-prone process which cannot be automated with certainty - some | ||
| terminals report the size in pixels including the padding - e.g. ``xterm``, |
There was a problem hiding this comment.
e.g.
xterm
I don't think xterm, supports chafa. The documentation should be accurate. Is this "terminal size issue" actually a problem on supported terminals, or just copied from sixel documentation?
Please make sure the new added code/docs is accurate and not copy-pasted information.
There was a problem hiding this comment.
Should be fixed.
| Additionally, they may behave differently when maximized or in fullscreen, | ||
| and mpv cannot detect this state using standard methods. | ||
|
|
||
| Sixel size and alignment options: |
There was a problem hiding this comment.
Not Sixel... But you get the point, this docs needs fixes. I won't point every error, please read through it and fix.
There was a problem hiding this comment.
Oops, totally my fault. The docs should be fixed now
video/out/vo_chafa.c
Outdated
| #include "video/sws_utils.h" | ||
| #include "video/mp_image.h" | ||
|
|
||
| #define IMGFMT IMGFMT_RGB24 |
There was a problem hiding this comment.
Is this the only format supported by the protocol?
There was a problem hiding this comment.
Nope, it isn't. Just fixed that
There was a problem hiding this comment.
I'm pretty sure the formats with an alpha component are unmultiplied (straight). I could be wrong on that though
video/out/vo_chafa.c
Outdated
| }; | ||
|
|
||
| struct priv { | ||
| // User specified options |
There was a problem hiding this comment.
Remove dummy comments, we know that opts are options. I know LLMs likes to spit more tokens that they should have.
There was a problem hiding this comment.
Oops, sorry about that. Those have been removed
| } | ||
|
|
||
| if (priv->frame) { | ||
| talloc_free(priv->frame); |
There was a problem hiding this comment.
I get an error when I try to use that in place of talloc_free
assigning to 'struct mp_image' from incompatible type 'void *'
There was a problem hiding this comment.
The error is telling you what needs to change. You need one more layer of indirection, TA_FREEP accepts pointer-to-pointer, not the same as regular talloc_free.
| if (priv->opts.width > 0) { | ||
| // option - set by the user, hard truth | ||
| total_px_width = priv->opts.width; | ||
| } else { | ||
| if (total_px_width <= 0) { | ||
| // ioctl failed to read terminal width | ||
| total_px_width = TERMINAL_FALLBACK_PX_WIDTH; | ||
| } else { | ||
| if (priv->opts.pad_x >= 0 && priv->opts.pad_x < total_px_width / 2) { | ||
| // explicit padding set by the user | ||
| total_px_width -= (2 * priv->opts.pad_x); | ||
| } else { | ||
| // rounded "auto padding" | ||
| total_px_width = total_px_width / num_cols * num_cols; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Is all this needed? Can't you use chafa_canvas_config_get_cell_geometry?
There was a problem hiding this comment.
This should be needed. This is where the pad_x and pad_y options are applied
| priv->height, | ||
| priv->frame->stride[0]); | ||
|
|
||
| if (mpi) |
There was a problem hiding this comment.
This check is also in the sixel VO on line 458. In the case that frame->current is NULL (when OSD should be redrawn in --force-window --idle mode). mpi is not initialized and remains NULL, and thus can't be freed
video/out/vo_chafa.c
Outdated
| { | ||
| // Go to the offset row and column | ||
| gchar pos_buf[64]; | ||
| g_snprintf(pos_buf, sizeof(pos_buf), TERM_ESC_GOTO_YX, priv->top + i , priv->left); |
There was a problem hiding this comment.
You should use mpv's primitives, like bstr_xappend_asprintf or mp_tprintf if small on stack.
|
Thanks for the review kasper97, lmk if you need any more changes |
…ells of chafa canvas
…ly selected by default
…e_chafa_canvas` function
First off, amazing project. I think MPV has been my default video player for at least 5 years, and it's still definitely the best I've used.
This PR adds a VO that uses the
chafalibrary to render to the terminal.chafauses a much wider array of symbols than just halfblocks to render graphics, significantly improving the fidelity of it's output over thetctbackend. This is meant to be a higher quality alternative to thetctVO for terminals without support for any of the already implemented image protocols (kitty, sixel, etc.).chafaalso supports theiTerm2image protocol, which isn't currently implemented in any VO, which is a nice bonus.I initially pointed GLM 4.7 at the sixel VO and told it to replace libsixel with chafa, but I've made sure to throughly review and fix it's output.