summaryrefslogtreecommitdiffstats
path: root/video/out/vo_sixel.c
Commit message (Collapse)AuthorAgeFilesLines
* vo_sixel: don't divide by zero on small terminalAvi Halachmi (:avih)2020-12-021-10/+16
| | | | | | | | | | Our canvas size calculation is affected by few factors, and rounded down more than once - which can result in 0 width or (more typically) height - e.g. when terminal height is one row. If the width or height are 0 then all bets are off, so simply skip the setups and rendering on this case. We can still recover automatically if the terminal is resized to become bigger.
* vo_sixel: re-fit image on terminal resizeShreesh Adiga2020-12-021-1/+20
| | | | | | | | The obvious approach would be SIGWINCH, however, integrating it would be tricky, so instead we simply poll the size on draw_frame. This means the image won't resize automatically when still - e.g. cover art or when paused, though it would re-fit on OSD changes.
* vo_sixel: refactor of resize, reconfig (no-op)Shreesh Adiga2020-12-021-27/+34
| | | | More granular functionality - will be used by the the next commit.
* vo_sixel: Update description string of vo driverShreesh Adiga2020-12-021-1/+1
|
* vo_sixel: don't leak the frame referenceAvi Halachmi (:avih)2020-11-291-4/+9
| | | | | | The reference is allocated at reconfig and happens at least once (and leaked at least once), but can also be called more, e.g. on zoom or pan-and-scan changes.
* vo_sixel: use draw_frame instead of draw_imageShreesh Adiga2020-11-271-13/+36
| | | | | | draw_image is deprecated, and draw_frame allows better behavior, like rendering the osd without image. e.g. `mpv --vo=sixel --idle --force-window`.
* vo_sixel: skip testdither init in fixed paletteShreesh Adiga2020-11-271-11/+18
| | | | | | | testdither was being created irrespective of whether opt_fixedpal is set or not. In case of opt_fixedpal=1, testdither is not used in the `prepare_static_palette` code. Hence only initialize it when opt_fixedpal is 0.
* vo_sixel: Update libsixel constant valuesShreesh Adiga2020-11-271-3/+3
| | | | | | | | In sixel_dither_initialize, replace 3 with the libsixel SIXEL_PIXELFORMAT_RGB888. Also in sixel_encode, the 4th parameter is supposed to be depth, which also happens to be the value of PIXELFORMAT_RGB888, so replacing that constant with the depth value.
* vo_sixel: change default dither to "auto"Avi Halachmi (:avih)2020-11-271-1/+1
| | | | | | | | | | | | | | For two reasons: 1. It was counter intuitive that there's an "auto" value (which is actually a libsixel value and not an mpv one), but it's not the default value - our default was Atkinson. 2. "auto" provides better dithering than Atkinson with libsixel, which is especially noticeable with smooth gradients - where Atkinson has visible banding. In libsixel 1.8.2 the "auto" value maps to Atkinson if the output palette has up to 16 colors, or to Floyd-Steinberg otherwise (e.g. using fixed palette with 256 colors chooses Floyd-Steinberg).
* vo_sixel: fix the image corruption with mltermAvi Halachmi (:avih)2020-11-271-6/+5
| | | | | | | | | | | | | | | | | | | | | | | | The issue was that we only uploaded the palette to the terminal when it changed (once on init with fixed palette, every frame with dynamic palette with trheshold=-1, only on scene change with threshold >= 0). Now we upload it on every frame, and it seems to fix the mlterm image corruption both with fixed palette and also with dynamic palette with threshold (i.e. at frames which did not upload a palette). It's not entirely clear why it's required with mlterm. It would seem that the palette which libsixel uses with fixed palette matches the built in default palette in xterm, but not in mlterm. With dynamic palette we can guess that mlterm resets the palette after a sixel image, but that's not confirmed. Uploading the palette on every frame doesn't seem to slow down xterm when using fixed palette - not clear yet why uploading a different palette (when using fixedpalette=no) slows it down while same palette on every frame doesn't. In mlterm there's no slowdown either way - and now also no corruption.
* vo_sixel: support --vo-sixel-exit-clear[=yes]Avi Halachmi (:avih)2020-11-271-2/+7
| | | | | | | | By default we still clear the screen, but now it's possible to leave the last sixel image on screen. Allows mpv to be used as img2sixel of sorts, but with our auto-fit and various mpv scaling/filters etc.
* vo_sixel: draw osd on the output frameShreesh Adiga2020-11-221-0/+5
|
* vo_sixel: return -1 instead of SIXELSTATUS on failureShreesh Adiga2020-11-221-10/+36
| | | | | | | | Currently in mpv functions sixel failures return the value status which is of type SIXELSTATUS. So changing it to -1 which is explicit and compatible with mpv. Also log the errors using MP_ERR/MP_LOG with the error string returned by libsixel to have more info.
* vo_sixel: set --vo-sixel-fixedpalette=yes by defaultShreesh Adiga2020-11-221-1/+1
| | | | | | | fixedpalette seems to be slightly faster than dynamic palette, and also in mlterm it avoids corruption of too bright values overflowing to black. Hence setting it to be default choice instead of dynamic palette.
* vo_sixel: Add aspect ratio based output centeringShreesh Adiga2020-11-221-158/+156
| | | | | | | | | | | | | | | | | | | | | | | | | | Resize the image based on the dimensions reported by vo_get_src_dst_rects to correctly handle aspect ratio that might be set/ignored. Added pad-x and pad-y options for padding. These options will be used to remove the extra padding. Some terminals report the padding of 2px in the ioctl dimensions which can't be used for displaying sixel output. These options can be used for fine tuning the output video resolution. Now all the terminal size detection and calculation logic is done in a single function at resize. Also top and left values are computed from the dst_rect parameters to simplify the logic for the aspect ratio based centering. Additionally vo-sixel-rows and vo-sixel-cols options have been added to enable the user to override the values in case of failures with get_terminal_size2. This commit also adds ability to handle video zoom correctly. Whenever video-zoom is triggered, the src and dst rects will be updated. Scaling seems to work well now.
* vo_sixel: rename all user options with opt_ prefixShreesh Adiga2020-11-221-36/+50
| | | | | | | This has no changes to mpv sixel playback behaviour. This is required because currently the offset values and the resolutions are being overwritten and not remembered.
* vo_sixel: set output resolution based on terminal_get_size2Shreesh Adiga2020-11-221-2/+37
|
* vo_sixel: Add fallback terminal width and heightShreesh Adiga2020-11-091-2/+5
| | | | | In case terminal_get_size function fails, the default height of 25 rows and 80 columns will be assumed
* vo_sixel: Add checks to prevent null pointer dereferencing.Shreesh Adiga2020-11-091-1/+8
|
* video/out/vo_sixel.c: Implement sixel as a output deviceShreesh Adiga2020-11-071-0/+421
Based on the implementation of ffmpeg's sixel backend output written by Hayaki Saito https://github.com/saitoha/FFmpeg-SIXEL/blob/sixel/libavdevice/sixel.c Sixel is a protocol to display graphics in a terminal. This commit adds support to play videos on a sixel enabled terminal using libsixel. With --vo=sixel, the output will be in sixel format. The input frame will be scaled to the user specified resolution (--vo-sixel-width and --vo-sixel-height) using swscaler and then encoded using libsixel and output to the terminal. This method requires high cpu and there are high frame drops for 720p and higher resolution videos and might require using lesser colors and have drop in quality. Docs have all the supported options listed to fine tune the output quality. TODO: A few parameters of libsixel such as the sixel_encode_policy and the SIXEL_XTERM16 variables are hardcoded, might want to expose them as command line options. Also the initialization resolution is not automatic and if the user doesn't specify the dimensions, it picks 320x240 as the default resolution which is not optimal. So need to automatically pick the best fit resolution for the current open terminal window size.