1 struct subpicture_updater_sys_t {
8 int i_font_height_percent;
16 static int SubpictureTextValidate(subpicture_t *subpic,
17 bool has_src_changed, const video_format_t *fmt_src,
18 bool has_dst_changed, const video_format_t *fmt_dst,
21 subpicture_updater_sys_t *sys = subpic->updater.p_sys;
22 VLC_UNUSED(fmt_src); VLC_UNUSED(fmt_dst); VLC_UNUSED(ts);
24 if (!has_src_changed && !has_dst_changed)
26 if (!sys->is_fixed && subpic->b_absolute && subpic->p_region &&
27 subpic->i_original_picture_width > 0 &&
28 subpic->i_original_picture_height > 0) {
31 sys->x = subpic->p_region->i_x;
32 sys->y = subpic->p_region->i_y;
33 sys->fixed_width = subpic->i_original_picture_width;
34 sys->fixed_height = subpic->i_original_picture_height;
38 static void SubpictureTextUpdate(subpicture_t *subpic,
39 const video_format_t *fmt_src,
40 const video_format_t *fmt_dst,
43 subpicture_updater_sys_t *sys = subpic->updater.p_sys;
44 VLC_UNUSED(fmt_src); VLC_UNUSED(ts);
46 if (fmt_dst->i_sar_num <= 0 || fmt_dst->i_sar_den <= 0)
49 subpic->i_original_picture_width = fmt_dst->i_width * fmt_dst->i_sar_num / fmt_dst->i_sar_den;
50 subpic->i_original_picture_height = fmt_dst->i_height;
53 video_format_Init(&fmt, VLC_CODEC_TEXT);
57 subpicture_region_t *r = subpic->p_region = subpicture_region_New(&fmt);
61 r->psz_text = sys->text ? strdup(sys->text) : NULL;
62 r->psz_html = sys->html ? strdup(sys->html) : NULL;
63 r->i_align = sys->align;
64 r->b_renderbg = sys->renderbg;
66 const float margin_ratio = 0.04;
67 const int margin_h = margin_ratio * fmt_dst->i_visible_width;
68 const int margin_v = margin_ratio * fmt_dst->i_visible_height;
71 if (r->i_align & SUBPICTURE_ALIGN_LEFT)
72 r->i_x += margin_h + fmt_dst->i_x_offset;
73 else if (r->i_align & SUBPICTURE_ALIGN_RIGHT)
74 r->i_x += margin_h + fmt_dst->i_width - (fmt_dst->i_visible_width + fmt_dst->i_x_offset);
77 if (r->i_align & SUBPICTURE_ALIGN_TOP )
78 r->i_y += margin_v + fmt_dst->i_y_offset;
79 else if (r->i_align & SUBPICTURE_ALIGN_BOTTOM )
80 r->i_y += margin_v + fmt_dst->i_height - (fmt_dst->i_visible_height + fmt_dst->i_y_offset);
82 /* FIXME it doesn't adapt on crop settings changes */
83 r->i_x = sys->x * fmt_dst->i_width / sys->fixed_width;
84 r->i_y = sys->y * fmt_dst->i_height / sys->fixed_height;
87 if (sys->i_font_height_percent != 0)
89 r->p_style = text_style_New();
92 r->p_style->i_font_size = sys->i_font_height_percent *
93 subpic->i_original_picture_height / 100;
94 r->p_style->i_font_color = 0xffffff;
95 r->p_style->i_font_alpha = 0xff;
99 static void SubpictureTextDestroy(subpicture_t *subpic)
101 subpicture_updater_sys_t *sys = subpic->updater.p_sys;
108 static inline subpicture_t *decoder_NewSubpictureText(decoder_t *decoder)
110 subpicture_updater_sys_t *sys = calloc(1, sizeof(*sys));
111 subpicture_updater_t updater = {
112 .pf_validate = SubpictureTextValidate,
113 .pf_update = SubpictureTextUpdate,
114 .pf_destroy = SubpictureTextDestroy,
117 subpicture_t *subpic = decoder_NewSubpicture(decoder, &updater);