configure: Improve detection of ibtool
[vlc.git] / modules / codec / arib / substext.h
bloba1bba0ca618fbd913033cdc908bfe8597df0c880
1 /*****************************************************************************
2 * substext.h : ARIB subtitles subpicture decoder
3 *****************************************************************************
4 * Copyright (C) 2012 Naohiro KORIYAMA
6 * Authors: Naohiro KORIYAMA <nkoriyama@gmail.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 typedef struct arib_text_region_s
25 char *psz_text;
27 char *psz_fontname;
28 int i_font_color;
29 int i_planewidth;
30 int i_planeheight;
31 int i_fontwidth;
32 int i_fontheight;
33 int i_verint;
34 int i_horint;
35 int i_charleft;
36 int i_charbottom;
37 int i_charleft_adj;
38 int i_charbottom_adj;
40 struct arib_text_region_s *p_next;
41 } arib_text_region_t;
43 struct subpicture_updater_sys_t
45 arib_text_region_t *p_region;
48 static int SubpictureTextValidate(subpicture_t *subpic,
49 bool has_src_changed, const video_format_t *fmt_src,
50 bool has_dst_changed, const video_format_t *fmt_dst,
51 mtime_t ts)
53 subpicture_updater_sys_t *sys = subpic->updater.p_sys;
54 VLC_UNUSED(fmt_src); VLC_UNUSED(fmt_dst); VLC_UNUSED(ts);
55 VLC_UNUSED(sys);
57 if (!has_src_changed && !has_dst_changed)
59 return VLC_SUCCESS;
61 return VLC_EGENERIC;
63 static void SubpictureTextUpdate(subpicture_t *subpic,
64 const video_format_t *fmt_src,
65 const video_format_t *fmt_dst,
66 mtime_t ts)
68 subpicture_updater_sys_t *sys = subpic->updater.p_sys;
69 VLC_UNUSED(fmt_src); VLC_UNUSED(ts);
71 if (fmt_dst->i_sar_num <= 0 || fmt_dst->i_sar_den <= 0)
73 return;
76 video_format_t fmt;
77 video_format_Init(&fmt, VLC_CODEC_TEXT);
78 fmt.i_sar_num = 1;
79 fmt.i_sar_den = 1;
81 subpicture_region_t *r = NULL;
82 arib_text_region_t *p_region;
83 for( p_region = sys->p_region; p_region; p_region = p_region->p_next )
85 if( !r )
87 subpic->p_region = r = subpicture_region_New(&fmt);
89 else
91 r->p_next = subpicture_region_New(&fmt);
92 r = r->p_next;
94 if( r == NULL )
96 return;
99 r->p_text = text_segment_New( p_region->psz_text );
100 r->i_align = SUBPICTURE_ALIGN_LEFT | SUBPICTURE_ALIGN_TOP;
102 subpic->i_original_picture_width = p_region->i_planewidth;
103 subpic->i_original_picture_height = p_region->i_planeheight;
105 r->i_x = p_region->i_charleft - (p_region->i_fontwidth + p_region->i_horint / 2) + p_region->i_charleft_adj;
106 r->i_y = p_region->i_charbottom - (p_region->i_fontheight + p_region->i_verint / 2) + p_region->i_charbottom_adj;
107 r->p_text->style = text_style_Create( STYLE_NO_DEFAULTS );
108 r->p_text->style->psz_fontname = p_region->psz_fontname ? strdup( p_region->psz_fontname ) : NULL;
109 r->p_text->style->i_font_size = p_region->i_fontheight;
110 r->p_text->style->i_font_color = p_region->i_font_color;
111 r->p_text->style->i_features |= STYLE_HAS_FONT_COLOR;
112 if( p_region->i_fontwidth < p_region->i_fontheight )
114 r->p_text->style->i_style_flags |= STYLE_HALFWIDTH;
115 r->p_text->style->i_features |= STYLE_HAS_FLAGS;
117 r->p_text->style->i_spacing = p_region->i_horint;
120 static void SubpictureTextDestroy(subpicture_t *subpic)
122 subpicture_updater_sys_t *sys = subpic->updater.p_sys;
124 arib_text_region_t *p_region, *p_region_next;
125 for( p_region = sys->p_region; p_region; p_region = p_region_next )
127 free( p_region->psz_text );
128 free( p_region->psz_fontname );
129 p_region_next = p_region->p_next;
130 free( p_region );
132 sys->p_region = NULL;
133 free( sys );
136 static inline subpicture_t *decoder_NewSubpictureText(decoder_t *decoder)
138 subpicture_updater_sys_t *sys = (subpicture_updater_sys_t*)
139 calloc( 1, sizeof(subpicture_updater_sys_t) );
140 subpicture_updater_t updater = {
141 .pf_validate = SubpictureTextValidate,
142 .pf_update = SubpictureTextUpdate,
143 .pf_destroy = SubpictureTextDestroy,
144 .p_sys = sys,
146 subpicture_t *subpic = decoder_NewSubpicture(decoder, &updater);
147 if( subpic == NULL )
149 free( sys );
151 return subpic;