summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-08-10 00:27:41 +0200
committerwm4 <wm4@nowhere>2013-08-12 00:51:31 +0200
commitc7da4ba74469bc6c404c396340ffadc748535f6e (patch)
treebb6530195bf4ac92a69a4e369ec8ecc620a72234
parent689a25003fc8098e5fdfbb2faefc0e18365d3acb (diff)
downloadmpv-c7da4ba74469bc6c404c396340ffadc748535f6e.tar.bz2
mpv-c7da4ba74469bc6c404c396340ffadc748535f6e.tar.xz
img_convert: add function to scale RGBA OSD images
-rw-r--r--sub/img_convert.c45
-rw-r--r--sub/img_convert.h2
-rw-r--r--video/sws_utils.c3
-rw-r--r--video/sws_utils.h1
4 files changed, 50 insertions, 1 deletions
diff --git a/sub/img_convert.c b/sub/img_convert.c
index 3196340c7a..35215a7522 100644
--- a/sub/img_convert.c
+++ b/sub/img_convert.c
@@ -142,6 +142,51 @@ bool osd_conv_blur_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs,
return true;
}
+// If RGBA parts need scaling, scale them.
+bool osd_scale_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs)
+{
+ struct sub_bitmaps src = *imgs;
+ if (src.format != SUBBITMAP_RGBA && src.format != SUBBITMAP_RGBA_STR)
+ return false;
+
+ bool need_scale = false;
+ for (int n = 0; n < src.num_parts; n++) {
+ struct sub_bitmap *sb = &src.parts[n];
+ if (sb->w != sb->dw || sb->h != sb->dh)
+ need_scale = true;
+ }
+ if (!need_scale)
+ return false;
+
+ talloc_free(c->parts);
+ imgs->parts = c->parts = talloc_array(c, struct sub_bitmap, src.num_parts);
+
+ // Note: we scale all parts, since most likely all need scaling anyway, and
+ // to get a proper copy of all data in the imgs list.
+ for (int n = 0; n < src.num_parts; n++) {
+ struct sub_bitmap *d = &imgs->parts[n];
+ struct sub_bitmap *s = &src.parts[n];
+
+ struct mp_image src_image = {0};
+ mp_image_setfmt(&src_image, IMGFMT_BGRA);
+ mp_image_set_size(&src_image, s->w, s->h);
+ src_image.planes[0] = s->bitmap;
+ src_image.stride[0] = s->stride;
+
+ d->x = s->x;
+ d->y = s->y;
+ d->w = d->dw = s->dw;
+ d->h = d->dh = s->dh;
+ struct mp_image *image = mp_image_alloc(IMGFMT_BGRA, d->w, d->h);
+ talloc_steal(c->parts, image);
+ d->stride = image->stride[0];
+ d->bitmap = image->planes[0];
+
+ mp_image_swscale(image, &src_image, mp_sws_fast_flags);
+ }
+ return true;
+}
+
static void rgba_to_gray(uint32_t *colors, size_t count)
{
for (int n = 0; n < count; n++) {
diff --git a/sub/img_convert.h b/sub/img_convert.h
index 3b739a4a38..5dc7fc2e90 100644
--- a/sub/img_convert.h
+++ b/sub/img_convert.h
@@ -18,9 +18,9 @@ bool osd_conv_ass_to_rgba_str(struct osd_conv_cache *c, struct sub_bitmaps *imgs
// Sub postprocessing
bool osd_conv_blur_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs,
double gblur);
+bool osd_scale_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs);
bool osd_conv_idx_to_gray(struct osd_conv_cache *c, struct sub_bitmaps *imgs);
-
bool mp_sub_bitmaps_bb(struct sub_bitmaps *imgs, struct mp_rect *out_bb);
// Intentionally limit the maximum number of bounding rects to something low.
diff --git a/video/sws_utils.c b/video/sws_utils.c
index 2c2ac9a9b4..db91434553 100644
--- a/video/sws_utils.c
+++ b/video/sws_utils.c
@@ -45,6 +45,9 @@ const int mp_sws_hq_flags = SWS_LANCZOS | SWS_FULL_CHR_H_INT |
SWS_FULL_CHR_H_INP | SWS_ACCURATE_RND |
SWS_BITEXACT;
+// Fast, lossy.
+const int mp_sws_fast_flags = SWS_BILINEAR;
+
// Set ctx parameters to global command line flags.
void mp_sws_set_from_cmdline(struct mp_sws_context *ctx)
{
diff --git a/video/sws_utils.h b/video/sws_utils.h
index a3c1d59be3..647cae2281 100644
--- a/video/sws_utils.h
+++ b/video/sws_utils.h
@@ -14,6 +14,7 @@ struct mp_csp_details;
#define SWS_MIN_BYTE_ALIGN 16
extern const int mp_sws_hq_flags;
+extern const int mp_sws_fast_flags;
bool mp_sws_supported_format(int imgfmt);