summaryrefslogtreecommitdiffstats
path: root/sub
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 /sub
parent689a25003fc8098e5fdfbb2faefc0e18365d3acb (diff)
downloadmpv-c7da4ba74469bc6c404c396340ffadc748535f6e.tar.bz2
mpv-c7da4ba74469bc6c404c396340ffadc748535f6e.tar.xz
img_convert: add function to scale RGBA OSD images
Diffstat (limited to 'sub')
-rw-r--r--sub/img_convert.c45
-rw-r--r--sub/img_convert.h2
2 files changed, 46 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.