1 /*****************************************************************************
2 * video_text.c : text manipulation functions
3 *****************************************************************************
4 * Copyright (C) 1999-2007 the VideoLAN team
7 * Author: Sigmund Augdal Helberg <dnumgis@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
29 #include <vlc_common.h>
31 #include <vlc_block.h>
32 #include <vlc_filter.h>
35 /* TODO remove access to private vout data */
36 #include "vout_internal.h"
39 * \brief Show text on the video for some time
40 * \param p_vout pointer to the vout the text is to be showed on
41 * \param i_channel Subpicture channel
42 * \param psz_string The text to be shown
43 * \param p_style Pointer to a struct with text style info (it is duplicated if non NULL)
44 * \param i_flags flags for alignment and such
45 * \param i_hmargin horizontal margin in pixels
46 * \param i_vmargin vertical margin in pixels
47 * \param i_duration Amount of time the text is to be shown.
49 int vout_ShowTextRelative( vout_thread_t *p_vout, int i_channel,
50 char *psz_string, const text_style_t *p_style,
51 int i_flags, int i_hmargin, int i_vmargin,
54 mtime_t i_now = mdate();
56 return vout_ShowTextAbsolute( p_vout, i_channel, psz_string,
57 p_style, i_flags, i_hmargin, i_vmargin,
58 i_now, i_now + i_duration );
62 * \brief Show text on the video from a given start date to a given end date
63 * \param p_vout pointer to the vout the text is to be showed on
64 * \param i_channel Subpicture channel
65 * \param psz_string The text to be shown
66 * \param p_style Pointer to a struct with text style info (it is duplicated if non NULL)
67 * \param i_flags flags for alignment and such
68 * \param i_hmargin horizontal margin in pixels
69 * \param i_vmargin vertical margin in pixels
70 * \param i_start the time when this string is to appear on the video
71 * \param i_stop the time when this string should stop to be displayed
72 * if this is 0 the string will be shown untill the next string
73 * is about to be shown
75 int vout_ShowTextAbsolute( vout_thread_t *p_vout, int i_channel,
76 const char *psz_string, const text_style_t *p_style,
77 int i_flags, int i_hmargin, int i_vmargin,
78 mtime_t i_start, mtime_t i_stop )
83 if( !psz_string ) return VLC_EGENERIC;
85 p_spu = subpicture_New( NULL );
89 p_spu->i_channel = i_channel;
90 p_spu->i_start = i_start;
91 p_spu->i_stop = i_stop;
92 p_spu->b_ephemer = true;
93 p_spu->b_absolute = false;
97 /* Create a new subpicture region */
98 memset( &fmt, 0, sizeof(video_format_t) );
99 fmt.i_chroma = VLC_CODEC_TEXT;
100 fmt.i_width = fmt.i_height = 0;
101 fmt.i_x_offset = fmt.i_y_offset = 0;
102 p_spu->p_region = subpicture_region_New( &fmt );
103 if( !p_spu->p_region )
105 msg_Err( p_vout, "cannot allocate SPU region" );
106 subpicture_Delete( p_spu );
110 p_spu->p_region->psz_text = strdup( psz_string );
111 p_spu->p_region->i_align = i_flags & SUBPICTURE_ALIGN_MASK;
112 p_spu->p_region->i_x = i_hmargin;
113 p_spu->p_region->i_y = i_vmargin;
115 p_spu->p_region->p_style = text_style_Duplicate( p_style );
117 spu_DisplaySubpicture( vout_GetSpu( p_vout ), p_spu );
122 #undef vout_OSDMessage
124 * \brief Write an informative message at the default location,
125 * for the default duration and only if the OSD option is enabled.
126 * \param p_caller The object that called the function.
127 * \param i_channel Subpicture channel
128 * \param psz_format printf style formatting
130 void vout_OSDMessage( vlc_object_t *p_caller, int i_channel,
131 const char *psz_format, ... )
133 vout_thread_t *p_vout;
134 char *psz_string = NULL;
137 if( !var_InheritBool( p_caller, "osd" ) ) return;
139 p_vout = vlc_object_find( p_caller, VLC_OBJECT_VOUT, FIND_ANYWHERE );
142 va_start( args, psz_format );
143 if( vasprintf( &psz_string, psz_format, args ) != -1 )
145 vout_ShowTextRelative( p_vout, i_channel, psz_string, NULL,
146 SUBPICTURE_ALIGN_TOP|SUBPICTURE_ALIGN_RIGHT,
147 30 + p_vout->p->fmt_in.i_width
148 - p_vout->p->fmt_in.i_visible_width
149 - p_vout->p->fmt_in.i_x_offset,
150 20 + p_vout->p->fmt_in.i_y_offset, 1000000 );
153 vlc_object_release( p_vout );
159 text_style_t *text_style_New( void )
161 text_style_t *p_style = calloc( 1, sizeof(*p_style) );
165 /* initialize to default text style */
166 p_style->psz_fontname = NULL;
167 p_style->i_font_size = 22;
168 p_style->i_font_color = 0xffffff;
169 p_style->i_font_alpha = 0xff;
170 p_style->i_style_flags = STYLE_OUTLINE;
171 p_style->i_outline_color = 0x000000;
172 p_style->i_outline_alpha = 0xff;
173 p_style->i_shadow_color = 0x000000;
174 p_style->i_shadow_alpha = 0xff;
175 p_style->i_background_color = 0xffffff;
176 p_style->i_background_alpha = 0x80;
177 p_style->i_karaoke_background_color = 0xffffff;
178 p_style->i_karaoke_background_alpha = 0xff;
179 p_style->i_outline_width = 1;
180 p_style->i_shadow_width = 0;
181 p_style->i_spacing = -1;
186 text_style_t *text_style_Copy( text_style_t *p_dst, const text_style_t *p_src )
194 if( p_src->psz_fontname )
195 p_dst->psz_fontname = strdup( p_src->psz_fontname );
200 text_style_t *text_style_Duplicate( const text_style_t *p_src )
205 text_style_t *p_dst = calloc( 1, sizeof(*p_dst) );
207 text_style_Copy( p_dst, p_src );
211 void text_style_Delete( text_style_t *p_style )
214 free( p_style->psz_fontname );