2009-07-25 04:24:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
|
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2009-07-25 04:24:39 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
2009-07-25 04:24:39 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2009-07-25 04:24:39 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2015-04-13 07:36:54 +00:00
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2009-07-25 04:24:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
2011-01-19 16:00:22 +00:00
|
|
|
#include <stdbool.h>
|
2009-07-25 04:24:39 +00:00
|
|
|
|
|
|
|
#include <ass/ass.h>
|
|
|
|
#include <ass/ass_types.h>
|
|
|
|
|
2014-06-14 17:17:31 +00:00
|
|
|
#include "common/common.h"
|
2013-12-21 18:06:37 +00:00
|
|
|
#include "common/global.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/path.h"
|
2009-07-25 04:24:39 +00:00
|
|
|
#include "ass_mp.h"
|
2013-11-24 11:58:06 +00:00
|
|
|
#include "osd.h"
|
2010-03-09 20:35:53 +00:00
|
|
|
#include "stream/stream.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/options.h"
|
2009-07-25 04:24:39 +00:00
|
|
|
|
2013-06-03 20:14:56 +00:00
|
|
|
// res_y should be track->PlayResY
|
|
|
|
// It determines scaling of font sizes and more.
|
2013-12-10 18:58:57 +00:00
|
|
|
void mp_ass_set_style(ASS_Style *style, double res_y,
|
2013-09-26 15:49:54 +00:00
|
|
|
const struct osd_style_opts *opts)
|
2012-11-17 19:56:45 +00:00
|
|
|
{
|
2015-11-29 12:50:51 +00:00
|
|
|
if (!style)
|
|
|
|
return;
|
|
|
|
|
2012-11-17 19:56:45 +00:00
|
|
|
if (opts->font) {
|
2013-12-15 16:38:48 +00:00
|
|
|
if (!style->FontName || strcmp(style->FontName, opts->font) != 0) {
|
|
|
|
free(style->FontName);
|
|
|
|
style->FontName = strdup(opts->font);
|
|
|
|
}
|
2012-11-17 19:56:45 +00:00
|
|
|
}
|
|
|
|
|
2013-06-03 20:14:56 +00:00
|
|
|
// libass_font_size = FontSize * (window_height / res_y)
|
|
|
|
// scale translates parameters from PlayResY=720 to res_y
|
|
|
|
double scale = res_y / 720.0;
|
2012-11-17 19:56:45 +00:00
|
|
|
|
|
|
|
style->FontSize = opts->font_size * scale;
|
|
|
|
style->PrimaryColour = MP_ASS_COLOR(opts->color);
|
|
|
|
style->SecondaryColour = style->PrimaryColour;
|
2014-06-01 21:53:24 +00:00
|
|
|
style->OutlineColour = MP_ASS_COLOR(opts->border_color);
|
|
|
|
if (opts->back_color.a) {
|
|
|
|
style->BackColour = MP_ASS_COLOR(opts->back_color);
|
|
|
|
style->BorderStyle = 4; // opaque box
|
|
|
|
} else {
|
|
|
|
style->BackColour = MP_ASS_COLOR(opts->shadow_color);
|
|
|
|
style->BorderStyle = 1; // outline
|
|
|
|
}
|
2012-11-17 19:56:45 +00:00
|
|
|
style->Outline = opts->border_size * scale;
|
|
|
|
style->Shadow = opts->shadow_offset * scale;
|
|
|
|
style->Spacing = opts->spacing * scale;
|
|
|
|
style->MarginL = opts->margin_x * scale;
|
|
|
|
style->MarginR = style->MarginL;
|
|
|
|
style->MarginV = opts->margin_y * scale;
|
|
|
|
style->ScaleX = 1.;
|
|
|
|
style->ScaleY = 1.;
|
2015-02-16 19:04:02 +00:00
|
|
|
style->Alignment = 1 + (opts->align_x + 1) + (opts->align_y + 2) % 3 * 4;
|
2013-04-13 16:53:03 +00:00
|
|
|
style->Blur = opts->blur;
|
2015-04-01 20:58:12 +00:00
|
|
|
style->Bold = opts->bold;
|
2012-11-17 19:56:45 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 18:06:37 +00:00
|
|
|
void mp_ass_configure_fonts(ASS_Renderer *priv, struct osd_style_opts *opts,
|
|
|
|
struct mpv_global *global, struct mp_log *log)
|
2009-07-25 04:24:39 +00:00
|
|
|
{
|
2013-12-21 19:45:19 +00:00
|
|
|
void *tmp = talloc_new(NULL);
|
2014-06-18 23:55:40 +00:00
|
|
|
char *default_font = mp_find_config_file(tmp, global, "subfont.ttf");
|
2013-12-21 19:45:19 +00:00
|
|
|
char *config = mp_find_config_file(tmp, global, "fonts.conf");
|
2012-12-09 11:45:05 +00:00
|
|
|
|
2013-12-21 19:45:19 +00:00
|
|
|
if (default_font && !mp_path_exists(default_font))
|
2012-12-09 11:45:05 +00:00
|
|
|
default_font = NULL;
|
|
|
|
|
2013-12-21 19:45:19 +00:00
|
|
|
mp_verbose(log, "Setting up fonts...\n");
|
2012-12-09 11:45:05 +00:00
|
|
|
ass_set_fonts(priv, default_font, opts->font, 1, config, 1);
|
2013-12-21 19:45:19 +00:00
|
|
|
mp_verbose(log, "Done.\n");
|
2009-07-25 04:24:39 +00:00
|
|
|
|
2013-12-21 19:45:19 +00:00
|
|
|
talloc_free(tmp);
|
2009-07-25 04:24:39 +00:00
|
|
|
}
|
|
|
|
|
2012-09-28 19:38:52 +00:00
|
|
|
void mp_ass_render_frame(ASS_Renderer *renderer, ASS_Track *track, double time,
|
|
|
|
struct sub_bitmap **parts, struct sub_bitmaps *res)
|
|
|
|
{
|
|
|
|
int changed;
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
ASS_Image *imgs = ass_render_frame(renderer, track, time, &changed);
|
2015-03-18 11:33:14 +00:00
|
|
|
if (changed)
|
|
|
|
res->change_id++;
|
2012-09-28 19:38:52 +00:00
|
|
|
res->format = SUBBITMAP_LIBASS;
|
|
|
|
|
|
|
|
res->parts = *parts;
|
|
|
|
res->num_parts = 0;
|
2015-01-26 18:16:27 +00:00
|
|
|
int num_parts_alloc = MP_TALLOC_AVAIL(res->parts);
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
for (struct ass_image *img = imgs; img; img = img->next) {
|
2012-09-28 19:38:52 +00:00
|
|
|
if (img->w == 0 || img->h == 0)
|
|
|
|
continue;
|
|
|
|
if (res->num_parts >= num_parts_alloc) {
|
2014-06-14 17:17:31 +00:00
|
|
|
num_parts_alloc = MPMAX(num_parts_alloc * 2, 32);
|
2012-09-28 19:38:52 +00:00
|
|
|
res->parts = talloc_realloc(NULL, res->parts, struct sub_bitmap,
|
|
|
|
num_parts_alloc);
|
|
|
|
}
|
|
|
|
struct sub_bitmap *p = &res->parts[res->num_parts];
|
|
|
|
p->bitmap = img->bitmap;
|
|
|
|
p->stride = img->stride;
|
|
|
|
p->libass.color = img->color;
|
|
|
|
p->dw = p->w = img->w;
|
|
|
|
p->dh = p->h = img->h;
|
|
|
|
p->x = img->dst_x;
|
|
|
|
p->y = img->dst_y;
|
|
|
|
res->num_parts++;
|
|
|
|
}
|
|
|
|
*parts = res->parts;
|
|
|
|
}
|
|
|
|
|
2014-06-10 21:56:05 +00:00
|
|
|
static const int map_ass_level[] = {
|
2012-07-29 21:57:46 +00:00
|
|
|
MSGL_ERR, // 0 "FATAL errors"
|
|
|
|
MSGL_WARN,
|
|
|
|
MSGL_INFO,
|
|
|
|
MSGL_V,
|
|
|
|
MSGL_V,
|
|
|
|
MSGL_V, // 5 application recommended level
|
2013-12-21 20:41:18 +00:00
|
|
|
MSGL_DEBUG,
|
|
|
|
MSGL_TRACE, // 7 "verbose DEBUG"
|
2012-07-29 21:57:46 +00:00
|
|
|
};
|
|
|
|
|
2009-07-25 04:24:39 +00:00
|
|
|
static void message_callback(int level, const char *format, va_list va, void *ctx)
|
|
|
|
{
|
2013-12-21 18:06:37 +00:00
|
|
|
struct mp_log *log = ctx;
|
|
|
|
if (!log)
|
|
|
|
return;
|
2012-07-29 21:57:46 +00:00
|
|
|
level = map_ass_level[level];
|
2013-12-21 20:49:13 +00:00
|
|
|
mp_msg_va(log, level, format, va);
|
2009-07-25 04:24:39 +00:00
|
|
|
// libass messages lack trailing \n
|
2013-12-21 20:49:13 +00:00
|
|
|
mp_msg(log, level, "\n");
|
2009-07-25 04:24:39 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 18:06:37 +00:00
|
|
|
ASS_Library *mp_ass_init(struct mpv_global *global, struct mp_log *log)
|
2009-07-25 04:24:39 +00:00
|
|
|
{
|
2014-06-18 23:55:40 +00:00
|
|
|
char *path = mp_find_config_file(NULL, global, "fonts");
|
2013-12-15 14:04:49 +00:00
|
|
|
ASS_Library *priv = ass_library_init();
|
|
|
|
if (!priv)
|
|
|
|
abort();
|
2013-12-21 18:06:37 +00:00
|
|
|
ass_set_message_cb(priv, message_callback, log);
|
2013-02-08 22:50:21 +00:00
|
|
|
if (path)
|
|
|
|
ass_set_fonts_dir(priv, path);
|
2013-12-21 18:06:37 +00:00
|
|
|
ass_set_extract_fonts(priv, global->opts->use_embedded_fonts);
|
2012-12-09 14:05:21 +00:00
|
|
|
talloc_free(path);
|
2009-07-25 04:24:39 +00:00
|
|
|
return priv;
|
|
|
|
}
|