1 /*****************************************************************************
2 * parser.c : OSD import module
3 *****************************************************************************
4 * Copyright (C) 2007 M2X
7 * Authors: Jean-Paul Saman
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>
34 #include <vlc_config.h>
37 #include <vlc_image.h>
39 #include <vlc_charset.h>
45 /*****************************************************************************
47 *****************************************************************************/
49 /*****************************************************************************
50 * Create a new Menu structure
51 *****************************************************************************/
52 osd_menu_t *osd_MenuNew( osd_menu_t *p_menu, const char *psz_path,
55 if( !p_menu ) return NULL;
57 p_menu->p_state = (osd_menu_state_t *) malloc( sizeof( osd_menu_state_t ) );
58 if( !p_menu->p_state )
60 msg_Err( p_menu, "Memory allocation for OSD Menu state failed" );
64 memset(p_menu->p_state, 0, sizeof(osd_menu_state_t));
65 if( psz_path != NULL )
66 p_menu->psz_path = strdup( psz_path );
68 p_menu->psz_path = NULL;
72 p_menu->i_style = OSD_MENU_STYLE_SIMPLE;
77 /*****************************************************************************
79 *****************************************************************************/
80 void osd_MenuFree( osd_menu_t *p_menu )
82 msg_Dbg( p_menu, "freeing menu" );
83 osd_ButtonFree( p_menu, p_menu->p_button );
85 free( p_menu->psz_path );
86 free( p_menu->p_state );
88 p_menu->p_button = NULL;
89 p_menu->p_last_button = NULL;
90 p_menu->psz_path = NULL;
91 p_menu->p_state = NULL;
94 /*****************************************************************************
96 *****************************************************************************/
97 osd_button_t *osd_ButtonNew( const char *psz_action, int i_x, int i_y )
99 osd_button_t *p_button = NULL;
100 p_button = (osd_button_t*) malloc( sizeof(osd_button_t) );
104 memset( p_button, 0, sizeof(osd_button_t) );
105 p_button->psz_action = strdup(psz_action);
106 p_button->psz_action_down = NULL;
107 p_button->p_feedback = NULL;
114 /*****************************************************************************
116 *****************************************************************************/
117 void osd_ButtonFree( osd_menu_t *p_menu, osd_button_t *p_button )
119 osd_button_t *p_current = p_button;
120 osd_button_t *p_next = NULL;
121 osd_button_t *p_prev = NULL;
123 /* First walk to the end. */
124 while( p_current->p_next )
126 p_next = p_current->p_next;
129 /* Then free end first and walk to the start. */
130 while( p_current->p_prev )
132 msg_Dbg( p_menu, "+ freeing button %s [%p]",
133 p_current->psz_action, p_current );
134 p_prev = p_current->p_prev;
136 if( p_current->p_next )
138 free( p_current->p_next->psz_name );
139 free( p_current->p_next->psz_action );
140 free( p_current->p_next->psz_action_down );
141 if( p_current->p_feedback )
143 free( p_current->p_feedback->p_data_orig );
144 free( p_current->p_feedback );
145 p_current->p_feedback = NULL;
148 /* Free all states first */
149 if( p_current->p_next->p_states )
150 osd_StatesFree( p_menu, p_current->p_next->p_states );
152 free( p_current->p_next );
153 p_current->p_next = NULL;
156 if( p_current->p_up )
158 free( p_current->p_up->psz_name );
159 free( p_current->p_up->psz_action );
160 free( p_current->p_up->psz_action_down );
161 if( p_current->p_feedback )
163 free( p_current->p_feedback->p_data_orig );
164 free( p_current->p_feedback );
167 p_current->p_feedback = NULL;
169 /* Free all states first */
170 if( p_current->p_up->p_states )
171 osd_StatesFree( p_menu, p_current->p_up->p_states );
172 free( p_current->p_up );
173 p_current->p_up = NULL;
176 /* Free the last one. */
179 msg_Dbg( p_menu, "+ freeing button %s [%p]",
180 p_button->psz_action, p_button );
181 free( p_button->psz_name );
182 free( p_button->psz_action );
183 free( p_button->psz_action_down );
184 if( p_current->p_feedback )
186 free( p_current->p_feedback->p_data_orig );
187 free( p_current->p_feedback );
188 p_current->p_feedback = NULL;
191 if( p_button->p_states )
192 osd_StatesFree( p_menu, p_button->p_states );
199 /*****************************************************************************
200 * Create a new state image
201 *****************************************************************************/
202 osd_state_t *osd_StateNew( osd_menu_t *p_menu, const char *psz_file,
203 const char *psz_state )
205 osd_state_t *p_state = NULL;
206 video_format_t fmt_in, fmt_out;
208 p_state = (osd_state_t*) malloc( sizeof(osd_state_t) );
212 memset( p_state, 0, sizeof(osd_state_t) );
213 memset( &fmt_in, 0, sizeof(video_format_t) );
214 memset( &fmt_out, 0, sizeof(video_format_t) );
216 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
217 if( p_menu->p_image )
219 p_state->p_pic = image_ReadUrl( p_menu->p_image, psz_file,
222 p_state->i_width = p_state->p_pic->p[Y_PLANE].i_visible_pitch;
223 p_state->i_height = p_state->p_pic->p[Y_PLANE].i_visible_lines;
228 p_state->psz_state = strdup( psz_state );
229 if( strncmp( ppsz_button_states[0], psz_state,
230 strlen(ppsz_button_states[0]) ) == 0 )
231 p_state->i_state = OSD_BUTTON_UNSELECT;
232 else if( strncmp( ppsz_button_states[1], psz_state,
233 strlen(ppsz_button_states[1]) ) == 0 )
234 p_state->i_state = OSD_BUTTON_SELECT;
235 else if( strncmp( ppsz_button_states[2], psz_state,
236 strlen(ppsz_button_states[2]) ) == 0 )
237 p_state->i_state = OSD_BUTTON_PRESSED;
242 /*****************************************************************************
244 *****************************************************************************/
245 void osd_StatesFree( osd_menu_t *p_menu, osd_state_t *p_states )
247 osd_state_t *p_state = p_states;
248 osd_state_t *p_next = NULL;
249 osd_state_t *p_prev = NULL;
251 while( p_state->p_next )
253 p_next = p_state->p_next;
256 /* Then free end first and walk to the start. */
257 while( p_state->p_prev )
259 msg_Dbg( p_menu, " |- freeing state %s [%p]",
260 p_state->psz_state, p_state );
261 p_prev = p_state->p_prev;
263 if( p_state->p_next )
265 if( p_state->p_next->p_pic )
267 free( p_state->p_next->p_pic->p_data_orig );
268 free( p_state->p_next->p_pic );
270 free( p_state->p_next->psz_state );
271 free( p_state->p_next );
272 p_state->p_next = NULL;
275 /* Free the last one. */
278 msg_Dbg( p_menu, " |- freeing state %s [%p]",
279 p_state->psz_state, p_states );
280 if( p_states->p_pic )
282 free( p_states->p_pic->p_data_orig );
283 free( p_states->p_pic );
285 free( p_state->psz_state );