From 24bfa82a91a49b0e2a120b719a6b89ac2b1b415b Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 25 Nov 2012 00:06:16 +0100 Subject: sub: reimplement -spugauss as --sub-gauss Apparently the -spugauss option was popular. The code originally implementing this is gone (scaler stuff in spudec.c). Reimplement it using libswscale to scale and blur image subtitles if the --sub-gauss option is set. The code does some rather lazy padding to allow the blur to spread pixels past the original image bounding box. (This problem exists with normal bilinear scaling too, but is barely noticable.) Technically, this doesn't just blur subtitles, but anything RGBA (or indexed) that enters the OSD rendering path. But only image subtitles produce these OSD formats currently, so no explicit check is done to prevent blurring in other cases. --- sub/img_convert.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'sub/img_convert.c') diff --git a/sub/img_convert.c b/sub/img_convert.c index e2eded24c3..274a83d833 100644 --- a/sub/img_convert.c +++ b/sub/img_convert.c @@ -28,6 +28,7 @@ #include "video/img_format.h" #include "video/mp_image.h" #include "video/sws_utils.h" +#include "video/memcpy_pic.h" struct osd_conv_cache { struct sub_bitmap part; @@ -86,3 +87,44 @@ bool osd_conv_idx_to_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs) } return true; } + +bool osd_conv_blur_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs, + double gblur) +{ + struct sub_bitmaps src = *imgs; + if (src.format != SUBBITMAP_RGBA) + return false; + + talloc_free(c->parts); + imgs->parts = c->parts = talloc_array(c, struct sub_bitmap, src.num_parts); + + for (int n = 0; n < src.num_parts; n++) { + struct sub_bitmap *d = &imgs->parts[n]; + struct sub_bitmap *s = &src.parts[n]; + + // add a transparent padding border to reduce artifacts + int pad = 5; + struct mp_image *temp = alloc_mpi(s->w + pad * 2, s->h + pad * 2, + IMGFMT_BGRA); + memset_pic(temp->planes[0], 0, temp->w * 4, temp->h, temp->stride[0]); + uint8_t *p0 = temp->planes[0] + pad * 4 + pad * temp->stride[0]; + memcpy_pic(p0, s->bitmap, s->w * 4, s->h, temp->stride[0], s->stride); + + double sx = (double)s->dw / s->w; + double sy = (double)s->dh / s->h; + + d->x = s->x - pad * sx; + d->y = s->y - pad * sy; + d->w = d->dw = s->dw + pad * 2 * sx; + d->h = d->dh = s->dh + pad * 2 * sy; + struct mp_image *image = alloc_mpi(d->w, d->h, IMGFMT_BGRA); + talloc_steal(c->parts, image); + d->stride = image->stride[0]; + d->bitmap = image->planes[0]; + + mp_image_sw_blur_scale(image, temp, gblur); + + talloc_free(temp); + } + return true; +} -- cgit v1.2.3