summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-11-22 13:30:16 +0100
committerwm4 <wm4@nowhere>2012-11-22 15:26:38 +0100
commit86ad77d0db3bb4ab4b3995408d9e0f8ccbdf6a6d (patch)
tree466bea46f053f0ec597d48fdc063ee6497a38a44 /sub
parent6c1e21e2239ec524358f819114ed9f271ffb7dc7 (diff)
downloadmpv-86ad77d0db3bb4ab4b3995408d9e0f8ccbdf6a6d.tar.bz2
mpv-86ad77d0db3bb4ab4b3995408d9e0f8ccbdf6a6d.tar.xz
draw_bmp: add RGB rendering to fix image quality issues
As pointed out in commit ed01df, the quality loss due to frequent conversion between RGB and YUV is too much when drawing OSD and subtitles. Fix this by staying in the same colorspace when drawing subtitles. Render directly to RGB, without converting to YUV first. The bad thing about packed RGB is that there are many pixel formats, which would all require special code for blending. It's also completely incompatible to planar YUV. Use planar RGB instead, which allows us to reuse all code originally written for planar YUV. The only thing that needs to be changed is the color conversion in the libass case. (In exchange for simpler code, the image has to be copied, but this is still much better than converting to YUV.) Unfortunately, libswscale doesn't support planar RGB output. Add a hack to sws_utils.c to handle conversion to planar RGB. In the common case, when converting 32 bit per pixel RGB, calling swscale can be avoided entirely. The change in mp_image.c is needed to allocate GBRP images correctly. (The issue with vo_x11 could be easily solved by always backing up the same bounding box as the bitmap drawing RGB<->YUV conversion does, but this commit is probably the better fix.)
Diffstat (limited to 'sub')
-rw-r--r--sub/draw_bmp.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/sub/draw_bmp.c b/sub/draw_bmp.c
index 96d87eec0c..a0c58324da 100644
--- a/sub/draw_bmp.c
+++ b/sub/draw_bmp.c
@@ -307,7 +307,14 @@ static void draw_ass(struct mp_draw_sub_cache **cache, struct mp_rect bb,
int b = (sb->libass.color >> 8) & 0xFF;
int a = 255 - (sb->libass.color & 0xFF);
int color_yuv[3] = {r, g, b};
- mp_map_int_color(rgb2yuv, bits, color_yuv);
+ if (dst.flags & MP_IMGFLAG_YUV) {
+ mp_map_int_color(rgb2yuv, bits, color_yuv);
+ } else {
+ assert(dst.imgfmt == IMGFMT_GBRP);
+ color_yuv[0] = g;
+ color_yuv[1] = b;
+ color_yuv[2] = r;
+ }
int bytes = (bits + 7) / 8;
uint8_t *alpha_p = (uint8_t *)sb->bitmap + src_y * sb->stride + src_x;
@@ -411,6 +418,10 @@ static void get_closest_y444_format(int imgfmt, int *out_format, int *out_bits)
return;
}
}
+ } else {
+ *out_format = IMGFMT_GBRP;
+ *out_bits = 8;
+ return;
}
*out_format = IMGFMT_444P16;
*out_bits = 16;