summaryrefslogtreecommitdiffstats
path: root/sub/ass_mp.c
diff options
context:
space:
mode:
Diffstat (limited to 'sub/ass_mp.c')
-rw-r--r--sub/ass_mp.c48
1 files changed, 42 insertions, 6 deletions
diff --git a/sub/ass_mp.c b/sub/ass_mp.c
index d5d9e3e7d6..3e9f83313f 100644
--- a/sub/ass_mp.c
+++ b/sub/ass_mp.c
@@ -23,6 +23,7 @@
#include <stdarg.h>
#include <stdbool.h>
#include <assert.h>
+#include <math.h>
#include <ass/ass.h>
#include <ass/ass_types.h>
@@ -131,9 +132,14 @@ static void message_callback(int level, const char *format, va_list va, void *ct
mp_msg(log, level, "\n");
}
-ASS_Library *mp_ass_init(struct mpv_global *global, struct mp_log *log)
+ASS_Library *mp_ass_init(struct mpv_global *global,
+ struct osd_style_opts *opts, struct mp_log *log)
{
- char *path = mp_find_config_file(NULL, global, "fonts");
+ char *path = opts->fonts_dir && opts->fonts_dir[0] ?
+ mp_get_user_path(NULL, global, opts->fonts_dir) :
+ mp_find_config_file(NULL, global, "fonts");
+ mp_dbg(log, "ASS library version: 0x%x (runtime 0x%x)\n",
+ (unsigned)LIBASS_VERSION, ass_library_version());
ASS_Library *priv = ass_library_init();
if (!priv)
abort();
@@ -237,6 +243,11 @@ static bool pack(struct mp_ass_packer *p, struct sub_bitmaps *res, int imgfmt)
talloc_steal(p, p->cached_img);
}
+ if (!mp_image_make_writeable(p->cached_img)) {
+ packer_reset(p->packer);
+ return false;
+ }
+
res->packed = p->cached_img;
for (int n = 0; n < res->num_parts; n++) {
@@ -277,7 +288,7 @@ static bool pack_rgba(struct mp_ass_packer *p, struct sub_bitmaps *res)
struct sub_bitmaps imgs = {
.change_id = res->change_id,
- .format = SUBBITMAP_RGBA,
+ .format = SUBBITMAP_BGRA,
.parts = p->rgba_imgs,
.num_parts = num_bb,
};
@@ -330,10 +341,10 @@ static bool pack_rgba(struct mp_ass_packer *p, struct sub_bitmaps *res)
// repacks all images). preferred_osd_format can be set to a desired
// sub_bitmap_format. Currently, only SUBBITMAP_LIBASS is supported.
void mp_ass_packer_pack(struct mp_ass_packer *p, ASS_Image **image_lists,
- int num_image_lists, bool image_lists_changed,
+ int num_image_lists, bool image_lists_changed, bool video_color_space,
int preferred_osd_format, struct sub_bitmaps *out)
{
- int format = preferred_osd_format == SUBBITMAP_RGBA ? SUBBITMAP_RGBA
+ int format = preferred_osd_format == SUBBITMAP_BGRA ? SUBBITMAP_BGRA
: SUBBITMAP_LIBASS;
if (p->cached_subs_valid && !image_lists_changed &&
@@ -350,6 +361,7 @@ void mp_ass_packer_pack(struct mp_ass_packer *p, ASS_Image **image_lists,
.change_id = image_lists_changed,
.format = SUBBITMAP_LIBASS,
.parts = p->cached_parts,
+ .video_color_space = video_color_space,
};
for (int n = 0; n < num_image_lists; n++) {
@@ -371,7 +383,7 @@ void mp_ass_packer_pack(struct mp_ass_packer *p, ASS_Image **image_lists,
}
bool r = false;
- if (format == SUBBITMAP_RGBA) {
+ if (format == SUBBITMAP_BGRA) {
r = pack_rgba(p, &res);
} else {
r = pack_libass(p, &res);
@@ -385,3 +397,27 @@ void mp_ass_packer_pack(struct mp_ass_packer *p, ASS_Image **image_lists,
p->cached_subs.change_id = 0;
p->cached_subs_valid = true;
}
+
+// Set *out_rc to [x0, y0, x1, y1] of the graphical bounding box in script
+// coordinates.
+// Set it to [inf, inf, -inf, -inf] if empty.
+void mp_ass_get_bb(ASS_Image *image_list, ASS_Track *track,
+ struct mp_osd_res *res, double *out_rc)
+{
+ double rc[4] = {INFINITY, INFINITY, -INFINITY, -INFINITY};
+
+ for (ASS_Image *img = image_list; img; img = img->next) {
+ if (img->w == 0 || img->h == 0)
+ continue;
+ rc[0] = MPMIN(rc[0], img->dst_x);
+ rc[1] = MPMIN(rc[1], img->dst_y);
+ rc[2] = MPMAX(rc[2], img->dst_x + img->w);
+ rc[3] = MPMAX(rc[3], img->dst_y + img->h);
+ }
+
+ double scale = track->PlayResY / (double)MPMAX(res->h, 1);
+ if (scale > 0) {
+ for (int i = 0; i < 4; i++)
+ out_rc[i] = rc[i] * scale;
+ }
+}