diff options
author | wm4 <wm4@nowhere> | 2015-12-24 16:42:21 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-12-24 16:42:21 +0100 |
commit | 3973a953df7516afbb21f4b95dde2161a67e5d84 (patch) | |
tree | f854e2be2f7e2bad0aced53a2b1c2f37fe17284d /sub/draw_bmp.c | |
parent | 082c23515f6e83381ff5220128fa4e3aecbb43d3 (diff) | |
download | mpv-3973a953df7516afbb21f4b95dde2161a67e5d84.tar.bz2 mpv-3973a953df7516afbb21f4b95dde2161a67e5d84.tar.xz |
sub: find GBRP format automatically when rendering to RGB
This removes the need to define IMGFMT_GBRAP, which fixes compilation
with the current Libav release.
This also makes it automatically pick up a GBRP format with the same bit
width. (Unfortunately, it seems libswscale does not support conversion
to AV_PIX_FMT_GBRAP16, so our code falls back to 8 bit, removing
precision for video covered by subtitles in cases this code is used.)
Also, when the source video is e.g. 10 bit YUV, upsample to 16 bit.
Whether this is good or bad, it fixes behavior with alpha. Although I'm
not sure if the alpha range is really correct ([0,2^16-1] vs.
[0,255*256]). Keep in mind that libswscale doesn't even agree with the
way we do it.
Diffstat (limited to 'sub/draw_bmp.c')
-rw-r--r-- | sub/draw_bmp.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/sub/draw_bmp.c b/sub/draw_bmp.c index ba5c6271e4..8ea426a768 100644 --- a/sub/draw_bmp.c +++ b/sub/draw_bmp.c @@ -407,21 +407,20 @@ static bool align_bbox_for_swscale(struct mp_image *img, struct mp_rect *rc) static void get_closest_y444_format(int imgfmt, int *out_format, int *out_bits) { struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(imgfmt); + int planes = desc.flags & MP_IMGFLAG_ALPHA ? 4 : 3; + int bits = desc.component_bits > 8 ? 16 : 8; if (desc.flags & MP_IMGFLAG_RGB) { - *out_format = desc.flags & MP_IMGFLAG_ALPHA ? IMGFMT_GBRAP : IMGFMT_GBRP; - *out_bits = 8; - return; + *out_format = mp_imgfmt_find(0, 0, planes, bits, MP_IMGFLAG_RGB_P); + if (!mp_sws_supported_format(*out_format)) + *out_format = mp_imgfmt_find(0, 0, planes, 8, MP_IMGFLAG_RGB_P); } else if (desc.flags & MP_IMGFLAG_YUV_P) { - *out_format = mp_imgfmt_find_yuv_planar(0, 0, desc.num_planes, - desc.plane_bits); - if (*out_format && mp_sws_supported_format(*out_format)) { - *out_bits = mp_imgfmt_get_desc(*out_format).plane_bits; - return; - } + *out_format = mp_imgfmt_find(0, 0, planes, bits, MP_IMGFLAG_YUV_P); + } else { + *out_format = 0; } - // fallback - *out_format = IMGFMT_444P; - *out_bits = 8; + if (!mp_sws_supported_format(*out_format)) + *out_format = IMGFMT_444P; // generic fallback + *out_bits = mp_imgfmt_get_desc(*out_format).component_bits; } static struct part *get_cache(struct mp_draw_sub_cache *cache, |