diff options
author | wm4 <wm4@nowhere> | 2020-05-09 18:01:07 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-05-09 18:02:57 +0200 |
commit | c1a961ad78b6d1da339e622c723d753a80687824 (patch) | |
tree | 4d3331052d5054603dfe780d291919dae09caedb /test/repack.c | |
parent | 9190b3c4694d9fbbe23429a0402a3a236d16e4fb (diff) | |
download | mpv-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 'test/repack.c')
-rw-r--r-- | test/repack.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/repack.c b/test/repack.c index 4489bd1ea1..aa9c804308 100644 --- a/test/repack.c +++ b/test/repack.c @@ -1,6 +1,8 @@ #include <libavutil/pixfmt.h> #include "common/common.h" +#include "sub/draw_bmp.h" +#include "sub/osd.h" #include "tests.h" #include "video/fmt-conversion.h" #include "video/img_format.h" @@ -331,6 +333,55 @@ static void check_float_repack(int imgfmt, enum mp_csp csp, talloc_free(from_f); } +static bool try_draw_bmp(FILE *f, int imgfmt) +{ + bool ok = false; + + struct mp_image *dst = mp_image_alloc(imgfmt, 64, 64); + if (!dst) + goto done; + + struct sub_bitmap sb = { + .bitmap = &(uint8_t[]){123}, + .stride = 1, + .x = 1, + .y = 1, + .w = 1, .dw = 1, + .h = 1, .dh = 1, + + .libass = { .color = 0xDEDEDEDE }, + }; + struct sub_bitmaps sbs = { + .format = SUBBITMAP_LIBASS, + .parts = &sb, + .num_parts = 1, + .change_id = 1, + }; + struct sub_bitmap_list sbs_list = { + .change_id = 1, + .w = dst->w, + .h = dst->h, + .items = (struct sub_bitmaps *[]){&sbs}, + .num_items = 1, + }; + + struct mp_draw_sub_cache *c = NULL; + if (mp_draw_sub_bitmaps(&c, dst, &sbs_list)) { + char *info = mp_draw_sub_get_dbg_info(c); + fprintf(f, "%s\n", info); + talloc_free(info); + ok = true; + } + + talloc_free(c); + talloc_free(dst); + +done: + if (!ok) + fprintf(f, "no\n"); + return ok; +} + static void run(struct test_ctx *ctx) { FILE *f = test_open_out(ctx, "repack.txt"); @@ -359,6 +410,22 @@ static void run(struct test_ctx *ctx) check_float_repack(-AV_PIX_FMT_YUVA444P10, MP_CSP_BT_709, MP_CSP_LEVELS_TV); check_float_repack(-AV_PIX_FMT_YUVA444P16, MP_CSP_BT_709, MP_CSP_LEVELS_PC); check_float_repack(-AV_PIX_FMT_YUVA444P16, MP_CSP_BT_709, MP_CSP_LEVELS_TV); + + // Determine the list of possible draw_bmp input formats. Do this here + // because it mostly depends on repack and imgformat stuff. + f = test_open_out(ctx, "draw_bmp.txt"); + + for (int n = 0; n < num_imgfmts; n++) { + int imgfmt = imgfmts[n]; + + fprintf(f, "%-12s= ", mp_imgfmt_to_name(imgfmt)); + try_draw_bmp(f, imgfmt); + } + + fclose(f); + + assert_text_files_equal(ctx, "draw_bmp.txt", "draw_bmp.txt", + "This can fail if FFmpeg/libswscale adds or removes pixfmts."); } const struct unittest test_repack = { |