summaryrefslogtreecommitdiffstats
path: root/sub/osd.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-05-09 18:01:07 +0200
committerwm4 <wm4@nowhere>2020-05-09 18:02:57 +0200
commitc1a961ad78b6d1da339e622c723d753a80687824 (patch)
tree4d3331052d5054603dfe780d291919dae09caedb /sub/osd.c
parent9190b3c4694d9fbbe23429a0402a3a236d16e4fb (diff)
downloadmpv-c1a961ad78b6d1da339e622c723d753a80687824.tar.bz2
mpv-c1a961ad78b6d1da339e622c723d753a80687824.tar.xz
draw_bmp: rewrite
draw_bmp.c is the software blender for subtitles and OSD. It's used by encoding mode (burning subtitles), and some VOs, like vo_drm, vo_x11, vo_xv, and possibly more. This changes the algorithm from upsampling the video to 4:4:4 and then blending to downsampling the OSD and then blending directly to video. This has far-reaching consequences for its internals, and results in an effective rewrite. Since I wanted to avoid un-premultiplying, all blending is done with premultiplied alpha. That's actually the sane thing to do. The old code just didn't do it, because it's very weird in YUV fixed point. Essentially, you'd have to compensate for the chroma centering constant by subtracting src_alpha/255*128. This seemed so hairy (especially with correct rounding and high bit depths involved) that I went for using float. I think it turned out mostly OK, although it's more complex and less maintainable than before. reinit() is certainly a bit too long. While it should be possible to optimize the RGB path more (for example by blending directly instead of doing the stupid float conversion), this is probably slower. vo_xv users probably lose in this, because it takes the slowest path (due to subsampling requirements and using YUV). Why this rewrite? Nobody knows. I simply forgot the reason. But you'll have it anyway. Whether or not this would have required a full rewrite, at least it supports target alpha now (you can for example hard sub transparent PNGs, if you ever wanted to use mpv for this). Remove the check in vf_sub. The new draw_bmp.c is not as reliant on libswscale anymore (mostly uses repack.c now), and osd.c shows an error message on missing support instead now. Formats with chroma subsampling of 4 are not supported, because FFmpeg doesn't provide pixfmt definitions for alpha variants. We could provide those ourselves (relatively trivial), but why bother.
Diffstat (limited to 'sub/osd.c')
-rw-r--r--sub/osd.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/sub/osd.c b/sub/osd.c
index 15ad5d20d7..52b69461ff 100644
--- a/sub/osd.c
+++ b/sub/osd.c
@@ -427,7 +427,8 @@ void osd_draw_on_image_p(struct osd_state *osd, struct mp_osd_res res,
stats_time_start(osd->stats, "draw-bmp");
- mp_draw_sub_bitmaps(&osd->draw_cache, dest, list);
+ if (!mp_draw_sub_bitmaps(&osd->draw_cache, dest, list))
+ MP_WARN(osd, "Failed rendering OSD.\n");
talloc_steal(osd, osd->draw_cache);
stats_time_end(osd->stats, "draw-bmp");