1 /*****************************************************************************
2 * vout_aa.c: Aa video output display method for testing purposes
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: aa.c,v 1.6 2002/06/02 09:03:53 sam Exp $
7 * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <errno.h> /* ENOMEM */
28 #include <stdlib.h> /* free() */
29 #include <string.h> /* strerror() */
37 /*****************************************************************************
38 * Capabilities defined in the other files.
39 *****************************************************************************/
40 static void vout_getfunctions ( function_list_t * p_function_list );
42 /*****************************************************************************
43 * Build configuration tree.
44 *****************************************************************************/
50 SET_DESCRIPTION( _("ASCII-art video output module") )
51 ADD_CAPABILITY( VOUT, 10 )
52 ADD_SHORTCUT( "aalib" )
57 vout_getfunctions( &p_module->p_functions->vout );
61 MODULE_DEACTIVATE_START
62 MODULE_DEACTIVATE_STOP
64 /*****************************************************************************
65 * vout_sys_t: aa video output method descriptor
66 *****************************************************************************
67 * This structure is part of the video output thread descriptor.
68 * It describes the aa specific properties of an output thread.
69 *****************************************************************************/
72 struct aa_context* aa_context;
74 int i_width; /* width of main window */
75 int i_height; /* height of main window */
78 /*****************************************************************************
80 *****************************************************************************/
81 static int vout_Create ( vout_thread_t * );
82 static int vout_Init ( vout_thread_t * );
83 static void vout_End ( vout_thread_t * );
84 static void vout_Destroy ( vout_thread_t * );
85 static int vout_Manage ( vout_thread_t * );
86 static void vout_Render ( vout_thread_t *, picture_t * );
87 static void vout_Display ( vout_thread_t *, picture_t * );
89 static void SetPalette ( vout_thread_t *, u16 *, u16 *, u16 * );
91 /*****************************************************************************
92 * Functions exported as capabilities. They are declared as static so that
93 * we don't pollute the namespace too much.
94 *****************************************************************************/
95 static void vout_getfunctions( function_list_t * p_function_list )
97 p_function_list->functions.vout.pf_create = vout_Create;
98 p_function_list->functions.vout.pf_init = vout_Init;
99 p_function_list->functions.vout.pf_end = vout_End;
100 p_function_list->functions.vout.pf_destroy = vout_Destroy;
101 p_function_list->functions.vout.pf_manage = vout_Manage;
102 p_function_list->functions.vout.pf_render = vout_Render;
103 p_function_list->functions.vout.pf_display = vout_Display;
106 /*****************************************************************************
107 * vout_Create: allocates aa video thread output method
108 *****************************************************************************
109 * This function allocates and initializes a aa vout method.
110 *****************************************************************************/
111 static int vout_Create( vout_thread_t *p_vout )
113 /* Allocate structure */
114 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
115 if( p_vout->p_sys == NULL )
117 msg_Err( p_vout, "out of memory" );
121 /* Don't parse any options, but take $AAOPTS into account */
122 aa_parseoptions( NULL, NULL, NULL, NULL );
124 if (!(p_vout->p_sys->aa_context = aa_autoinit(&aa_defparams)))
126 msg_Err( p_vout, "cannot initialize aalib" );
130 p_vout->p_sys->i_width = aa_imgwidth(p_vout->p_sys->aa_context);
131 p_vout->p_sys->i_height = aa_imgheight(p_vout->p_sys->aa_context);
132 aa_autoinitkbd( p_vout->p_sys->aa_context, 0 );
133 aa_autoinitmouse( p_vout->p_sys->aa_context, AA_MOUSEPRESSMASK );
134 aa_hidemouse( p_vout->p_sys->aa_context );
138 /*****************************************************************************
139 * vout_Init: initialize aa video thread output method
140 *****************************************************************************/
141 static int vout_Init( vout_thread_t *p_vout )
144 picture_t *p_pic = NULL;
146 I_OUTPUTPICTURES = 0;
148 p_vout->output.i_chroma = FOURCC_RGB2;
149 p_vout->output.i_width = p_vout->p_sys->i_width;
150 p_vout->output.i_height = p_vout->p_sys->i_height;
151 p_vout->output.i_aspect = p_vout->p_sys->i_width
152 * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
153 p_vout->output.pf_setpalette = SetPalette;
155 /* Find an empty picture slot */
156 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
158 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
160 p_pic = p_vout->p_picture + i_index;
170 /* Allocate the picture */
171 p_pic->p->p_pixels = aa_image( p_vout->p_sys->aa_context );
172 p_pic->p->i_pixel_bytes = 1;
173 p_pic->p->i_lines = p_vout->p_sys->i_height;
174 p_pic->p->i_pitch = p_vout->p_sys->i_width;
175 p_pic->p->b_margin = 0;
178 p_pic->i_status = DESTROYED_PICTURE;
179 p_pic->i_type = DIRECT_PICTURE;
181 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
187 /*****************************************************************************
188 * vout_End: terminate aa video thread output method
189 *****************************************************************************/
190 static void vout_End( vout_thread_t *p_vout )
195 /*****************************************************************************
196 * vout_Destroy: destroy aa video thread output method
197 *****************************************************************************
198 * Terminate an output method created by AaCreateOutputMethod
199 *****************************************************************************/
200 static void vout_Destroy( vout_thread_t *p_vout )
202 aa_close( p_vout->p_sys->aa_context );
203 free( p_vout->p_sys );
206 /*****************************************************************************
207 * vout_Manage: handle aa events
208 *****************************************************************************
209 * This function should be called regularly by video output thread. It manages
210 * console events. It returns a non null value on error.
211 *****************************************************************************/
212 static int vout_Manage( vout_thread_t *p_vout )
215 event = aa_getevent( p_vout->p_sys->aa_context, 0 );
219 aa_getmouse( p_vout->p_sys->aa_context, &x, &y, &b );
220 if ( b & AA_BUTTON3 )
222 intf_thread_t *p_intf;
223 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
226 p_intf->b_menu_change = 1;
227 vlc_object_release( p_intf );
232 p_vout->i_changes |= VOUT_SIZE_CHANGE;
233 aa_resize( p_vout->p_sys->aa_context );
234 p_vout->p_sys->i_width = aa_imgwidth( p_vout->p_sys->aa_context );
235 p_vout->p_sys->i_height = aa_imgheight( p_vout->p_sys->aa_context );
243 /*****************************************************************************
244 * vout_Render: render previously calculated output
245 *****************************************************************************/
246 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
248 aa_fastrender( p_vout->p_sys->aa_context, 0, 0,
249 aa_imgwidth( p_vout->p_sys->aa_context ),
250 aa_imgheight( p_vout->p_sys->aa_context ) );
253 /*****************************************************************************
254 * vout_Display: displays previously rendered output
255 *****************************************************************************/
256 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
258 /* No need to do anything, the fake direct buffers stay as they are */
259 int i_width, i_height, i_x, i_y;
261 vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
262 &i_x, &i_y, &i_width, &i_height );
264 aa_flush(p_vout->p_sys->aa_context);
267 /*****************************************************************************
268 * SetPalette: set the 8bpp palette
269 *****************************************************************************/
270 static void SetPalette( vout_thread_t *p_vout, u16 *red, u16 *green, u16 *blue )
274 /* Fill colors with color information */
275 for( i = 0; i < 256; i++ )
277 aa_setpalette( p_vout->p_sys->palette, 256 -i,
278 red[ i ], green[ i ], blue[ i ] );