1 /*****************************************************************************
2 * video_widgets.c : OSD widgets manipulation functions
3 *****************************************************************************
4 * Copyright (C) 2004-2010 the VideoLAN team
7 * Author: Yoann Peronneau <yoann@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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
32 #include <vlc_common.h>
36 #include <vlc_filter.h>
38 /* TODO remove access to private vout data */
39 #include "vout_internal.h"
42 #define STYLE_FILLED 1
44 /*****************************************************************************
45 * Draws a rectangle at the given position in the subpic.
46 * It may be filled (fill == STYLE_FILLED) or empty (fill == STYLE_EMPTY).
47 *****************************************************************************/
48 static void DrawRect( subpicture_t *p_subpic, int i_x1, int i_y1,
49 int i_x2, int i_y2, short fill )
52 uint8_t *p_a = p_subpic->p_region->p_picture->A_PIXELS;
53 int i_pitch = p_subpic->p_region->p_picture->Y_PITCH;
55 if( fill == STYLE_FILLED )
57 for( y = i_y1; y <= i_y2; y++ )
59 for( x = i_x1; x <= i_x2; x++ )
61 p_a[ x + i_pitch * y ] = 0xff;
67 for( y = i_y1; y <= i_y2; y++ )
69 p_a[ i_x1 + i_pitch * y ] = 0xff;
70 p_a[ i_x2 + i_pitch * y ] = 0xff;
72 for( x = i_x1; x <= i_x2; x++ )
74 p_a[ x + i_pitch * i_y1 ] = 0xff;
75 p_a[ x + i_pitch * i_y2 ] = 0xff;
80 /*****************************************************************************
81 * Draws a triangle at the given position in the subpic.
82 * It may be filled (fill == STYLE_FILLED) or empty (fill == STYLE_EMPTY).
83 *****************************************************************************/
84 static void DrawTriangle( subpicture_t *p_subpic, int i_x1, int i_y1,
85 int i_x2, int i_y2, short fill )
88 uint8_t *p_a = p_subpic->p_region->p_picture->A_PIXELS;
89 int i_pitch = p_subpic->p_region->p_picture->Y_PITCH;
91 i_mid = i_y1 + ( ( i_y2 - i_y1 ) >> 1 );
95 if( fill == STYLE_FILLED )
97 for( y = i_y1; y <= i_mid; y++ )
100 for( x = i_x1; x <= i_x1 + h && x <= i_x2; x++ )
102 p_a[ x + i_pitch * y ] = 0xff;
103 p_a[ x + i_pitch * ( i_y2 - h ) ] = 0xff;
109 for( y = i_y1; y <= i_mid; y++ )
112 p_a[ i_x1 + i_pitch * y ] = 0xff;
113 p_a[ i_x1 + h + i_pitch * y ] = 0xff;
114 p_a[ i_x1 + i_pitch * ( i_y2 - h ) ] = 0xff;
115 p_a[ i_x1 + h + i_pitch * ( i_y2 - h ) ] = 0xff;
121 if( fill == STYLE_FILLED )
123 for( y = i_y1; y <= i_mid; y++ )
126 for( x = i_x1; x >= i_x1 - h && x >= i_x2; x-- )
128 p_a[ x + i_pitch * y ] = 0xff;
129 p_a[ x + i_pitch * ( i_y2 - h ) ] = 0xff;
135 for( y = i_y1; y <= i_mid; y++ )
138 p_a[ i_x1 + i_pitch * y ] = 0xff;
139 p_a[ i_x1 - h + i_pitch * y ] = 0xff;
140 p_a[ i_x1 + i_pitch * ( i_y2 - h ) ] = 0xff;
141 p_a[ i_x1 - h + i_pitch * ( i_y2 - h ) ] = 0xff;
147 /*****************************************************************************
148 * Create Picture: creates subpicture region and picture
149 *****************************************************************************/
150 static int CreatePicture( subpicture_t *p_subpic,
151 int i_x, int i_y, int i_width, int i_height )
153 uint8_t *p_y, *p_u, *p_v, *p_a;
157 /* Create a new subpicture region */
158 memset( &fmt, 0, sizeof(video_format_t) );
159 fmt.i_chroma = VLC_CODEC_YUVA;
160 fmt.i_width = fmt.i_visible_width = i_width;
161 fmt.i_height = fmt.i_visible_height = i_height;
162 fmt.i_x_offset = fmt.i_y_offset = 0;
163 p_subpic->p_region = subpicture_region_New( &fmt );
164 if( !p_subpic->p_region )
167 p_subpic->p_region->i_x = i_x;
168 p_subpic->p_region->i_y = i_y;
169 p_y = p_subpic->p_region->p_picture->Y_PIXELS;
170 p_u = p_subpic->p_region->p_picture->U_PIXELS;
171 p_v = p_subpic->p_region->p_picture->V_PIXELS;
172 p_a = p_subpic->p_region->p_picture->A_PIXELS;
173 i_pitch = p_subpic->p_region->p_picture->Y_PITCH;
175 /* Initialize the region pixels (only the alpha will be changed later) */
176 memset( p_y, 0xff, i_pitch * p_subpic->p_region->fmt.i_height );
177 memset( p_u, 0x80, i_pitch * p_subpic->p_region->fmt.i_height );
178 memset( p_v, 0x80, i_pitch * p_subpic->p_region->fmt.i_height );
179 memset( p_a, 0x00, i_pitch * p_subpic->p_region->fmt.i_height );
184 /*****************************************************************************
185 * Creates and initializes an OSD widget.
186 *****************************************************************************/
187 static subpicture_t *CreateWidget( int i_channel )
189 subpicture_t *p_subpic;
190 mtime_t i_now = mdate();
192 /* Create and initialize a subpicture */
193 p_subpic = subpicture_New( NULL );
194 if( p_subpic == NULL ) return NULL;
196 p_subpic->i_channel = i_channel;
197 p_subpic->i_start = i_now;
198 p_subpic->i_stop = i_now + 1200000;
199 p_subpic->b_ephemer = true;
200 p_subpic->b_fade = true;
205 /*****************************************************************************
206 * Displays an OSD slider.
207 * Types are: OSD_HOR_SLIDER and OSD_VERT_SLIDER.
208 *****************************************************************************/
209 static int OsdSlider( spu_t *p_spu,
210 int i_render_width, int i_render_height,
211 int i_margin_left, int i_margin_bottom,
212 int i_channel, int i_position, short i_type )
214 subpicture_t *p_subpic;
215 int i_x_margin, i_y_margin, i_x, i_y, i_width, i_height;
217 p_subpic = CreateWidget( i_channel );
218 if( p_subpic == NULL )
223 i_y_margin = i_render_height / 10;
224 i_x_margin = i_y_margin + i_margin_left;
225 i_y_margin += i_margin_bottom;
227 if( i_type == OSD_HOR_SLIDER )
229 i_width = i_render_width - 2 * i_x_margin;
230 i_height = i_render_height / 20;
232 i_y = i_render_height - i_y_margin - i_height;
236 i_width = i_render_width / 40;
237 i_height = i_render_height - 2 * i_y_margin;
238 i_x = i_render_width - i_x_margin - i_width;
242 /* Create subpicture region and picture */
243 CreatePicture( p_subpic, i_x, i_y, i_width, i_height );
245 if( i_type == OSD_HOR_SLIDER )
247 int i_x_pos = ( i_width - 2 ) * i_position / 100;
248 DrawRect( p_subpic, i_x_pos - 1, 2, i_x_pos + 1,
249 i_height - 3, STYLE_FILLED );
250 DrawRect( p_subpic, 0, 0, i_width - 1, i_height - 1, STYLE_EMPTY );
252 else if( i_type == OSD_VERT_SLIDER )
254 int i_y_pos = i_height / 2;
255 DrawRect( p_subpic, 2, i_height - ( i_height - 2 ) * i_position / 100,
256 i_width - 3, i_height - 3, STYLE_FILLED );
257 DrawRect( p_subpic, 1, i_y_pos, 1, i_y_pos, STYLE_FILLED );
258 DrawRect( p_subpic, i_width - 2, i_y_pos,
259 i_width - 2, i_y_pos, STYLE_FILLED );
260 DrawRect( p_subpic, 0, 0, i_width - 1, i_height - 1, STYLE_EMPTY );
263 spu_DisplaySubpicture( p_spu, p_subpic );
268 /*****************************************************************************
269 * Displays an OSD icon.
270 * Types are: OSD_PLAY_ICON, OSD_PAUSE_ICON, OSD_SPEAKER_ICON, OSD_MUTE_ICON
271 *****************************************************************************/
272 static int OsdIcon( spu_t *p_spu,
273 int i_render_width, int i_render_height, int i_margin_right,
274 int i_margin_top, int i_channel, short i_type )
276 subpicture_t *p_subpic;
277 int i_x_margin, i_y_margin, i_x, i_y, i_width, i_height;
279 p_subpic = CreateWidget( i_channel );
280 if( p_subpic == NULL )
285 i_y_margin = i_render_height / 15;
286 i_x_margin = i_y_margin + i_margin_right;
287 i_y_margin += i_margin_top;
288 i_width = i_render_width / 20;
290 i_x = i_render_width - i_x_margin - i_width;
293 /* Create subpicture region and picture */
294 CreatePicture( p_subpic, i_x, i_y, i_width, i_height );
296 if( i_type == OSD_PAUSE_ICON )
298 int i_bar_width = i_width / 3;
299 DrawRect( p_subpic, 0, 0, i_bar_width - 1, i_height -1, STYLE_FILLED );
300 DrawRect( p_subpic, i_width - i_bar_width, 0,
301 i_width - 1, i_height - 1, STYLE_FILLED );
303 else if( i_type == OSD_PLAY_ICON )
305 int i_mid = i_height >> 1;
306 int i_delta = ( i_width - i_mid ) >> 1;
307 int i_y2 = ( ( i_height - 1 ) >> 1 ) * 2;
308 DrawTriangle( p_subpic, i_delta, 0, i_width - i_delta, i_y2,
311 else if( i_type == OSD_SPEAKER_ICON || i_type == OSD_MUTE_ICON )
313 int i_mid = i_height >> 1;
314 int i_delta = ( i_width - i_mid ) >> 1;
315 int i_y2 = ( ( i_height - 1 ) >> 1 ) * 2;
316 DrawRect( p_subpic, i_delta, i_mid / 2, i_width - i_delta,
317 i_height - 1 - i_mid / 2, STYLE_FILLED );
318 DrawTriangle( p_subpic, i_width - i_delta, 0, i_delta, i_y2,
320 if( i_type == OSD_MUTE_ICON )
322 uint8_t *p_a = p_subpic->p_region->p_picture->A_PIXELS;
323 int i_pitch = p_subpic->p_region->p_picture->Y_PITCH;
325 for( i = 1; i < i_pitch; i++ )
327 int k = i + ( i_height - i - 1 ) * i_pitch;
328 p_a[ k ] = 0xff - p_a[ k ];
333 spu_DisplaySubpicture( p_spu, p_subpic );
337 /*****************************************************************************
338 * Displays an OSD slider.
339 * Types are: OSD_HOR_SLIDER and OSD_VERT_SLIDER.
340 *****************************************************************************/
341 void vout_OSDSlider( vout_thread_t *p_vout, int i_channel, int i_position,
344 if( !var_InheritBool( p_vout, "osd" ) || i_position < 0 )
347 OsdSlider( vout_GetSpu( p_vout ),
348 p_vout->p->fmt_render.i_width,
349 p_vout->p->fmt_render.i_height,
350 p_vout->p->fmt_in.i_x_offset,
351 p_vout->p->fmt_in.i_height - p_vout->p->fmt_in.i_visible_height
352 - p_vout->p->fmt_in.i_y_offset,
353 i_channel, i_position, i_type );
356 /*****************************************************************************
357 * Displays an OSD icon.
358 * Types are: OSD_PLAY_ICON, OSD_PAUSE_ICON, OSD_SPEAKER_ICON, OSD_MUTE_ICON
359 *****************************************************************************/
360 void vout_OSDIcon( vout_thread_t *p_vout, int i_channel, short i_type )
362 if( !var_InheritBool( p_vout, "osd" ) )
365 OsdIcon( vout_GetSpu( p_vout ),
366 p_vout->p->fmt_render.i_width,
367 p_vout->p->fmt_render.i_height,
368 p_vout->p->fmt_in.i_width - p_vout->p->fmt_in.i_visible_width
369 - p_vout->p->fmt_in.i_x_offset,
370 p_vout->p->fmt_in.i_y_offset,