summaryrefslogtreecommitdiffstats
path: root/sub/img_convert.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-11-25 00:06:16 +0100
committerwm4 <wm4@nowhere>2012-11-25 23:40:07 +0100
commit24bfa82a91a49b0e2a120b719a6b89ac2b1b415b (patch)
tree1413d73435d6a6dfe174a214da8943a8bd040aef /sub/img_convert.c
parent2bd7f980ac5b692b62b0765c4411129f953b0593 (diff)
downloadmpv-24bfa82a91a49b0e2a120b719a6b89ac2b1b415b.tar.bz2
mpv-24bfa82a91a49b0e2a120b719a6b89ac2b1b415b.tar.xz
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.
Diffstat (limited to 'sub/img_convert.c')
-rw-r--r--sub/img_convert.c42
1 files changed, 42 insertions, 0 deletions
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;
+}