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
40 struct arib_text_region_s
*p_next
;
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
,
53 subpicture_updater_sys_t
*sys
= subpic
->updater
.p_sys
;
54 VLC_UNUSED(fmt_src
); VLC_UNUSED(fmt_dst
); VLC_UNUSED(ts
);
57 if (!has_src_changed
&& !has_dst_changed
)
63 static void SubpictureTextUpdate(subpicture_t
*subpic
,
64 const video_format_t
*fmt_src
,
65 const video_format_t
*fmt_dst
,
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)
77 video_format_Init(&fmt
, VLC_CODEC_TEXT
);
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
)
87 subpic
->p_region
= r
= subpicture_region_New(&fmt
);
91 r
->p_next
= subpicture_region_New(&fmt
);
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
;
132 sys
->p_region
= NULL
;
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
,
146 subpicture_t
*subpic
= decoder_NewSubpicture(decoder
, &updater
);