1 /*****************************************************************************
2 * vout_aa.c: Aa video output display method for testing purposes
3 *****************************************************************************
4 * Copyright (C) 2002 the VideoLAN team
7 * Authors: 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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <errno.h> /* ENOMEM */
37 #include <vlc_interface.h>
39 /*****************************************************************************
41 *****************************************************************************/
42 static int Create ( vlc_object_t * );
43 static void Destroy ( vlc_object_t * );
45 static int Init ( vout_thread_t * );
46 static void End ( vout_thread_t * );
47 static int Manage ( vout_thread_t * );
48 static void Render ( vout_thread_t *, picture_t * );
49 static void Display ( vout_thread_t *, picture_t * );
51 static void SetPalette ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
53 /*****************************************************************************
55 *****************************************************************************/
57 set_shortname( _("ASCII Art"));
58 set_category( CAT_VIDEO );
59 set_subcategory( SUBCAT_VIDEO_VOUT );
60 set_description( _("ASCII-art video output") );
61 set_capability( "video output", 10 );
62 add_shortcut( "aalib" );
63 set_callbacks( Create, Destroy );
66 /*****************************************************************************
67 * vout_sys_t: aa video output method descriptor
68 *****************************************************************************
69 * This structure is part of the video output thread descriptor.
70 * It describes the aa specific properties of an output thread.
71 *****************************************************************************/
74 struct aa_context* aa_context;
76 int i_width; /* width of main window */
77 int i_height; /* height of main window */
80 /*****************************************************************************
81 * Create: allocates aa video thread output method
82 *****************************************************************************
83 * This function allocates and initializes a aa vout method.
84 *****************************************************************************/
85 static int Create( vlc_object_t *p_this )
87 vout_thread_t *p_vout = (vout_thread_t *)p_this;
89 /* Allocate structure */
90 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
91 if( p_vout->p_sys == NULL )
93 msg_Err( p_vout, "out of memory" );
97 /* Don't parse any options, but take $AAOPTS into account */
98 aa_parseoptions( NULL, NULL, NULL, NULL );
100 if (!(p_vout->p_sys->aa_context = aa_autoinit(&aa_defparams)))
102 msg_Err( p_vout, "cannot initialize aalib" );
106 p_vout->pf_init = Init;
107 p_vout->pf_end = End;
108 p_vout->pf_manage = Manage;
109 p_vout->pf_render = Render;
110 p_vout->pf_display = Display;
112 p_vout->p_sys->i_width = aa_imgwidth(p_vout->p_sys->aa_context);
113 p_vout->p_sys->i_height = aa_imgheight(p_vout->p_sys->aa_context);
114 aa_autoinitkbd( p_vout->p_sys->aa_context, 0 );
115 aa_autoinitmouse( p_vout->p_sys->aa_context, AA_MOUSEPRESSMASK );
116 aa_hidemouse( p_vout->p_sys->aa_context );
120 /*****************************************************************************
121 * Init: initialize aa video thread output method
122 *****************************************************************************/
123 static int Init( vout_thread_t *p_vout )
126 picture_t *p_pic = NULL;
128 I_OUTPUTPICTURES = 0;
130 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
131 p_vout->output.i_width = p_vout->p_sys->i_width;
132 p_vout->output.i_height = p_vout->p_sys->i_height;
133 p_vout->output.i_aspect = p_vout->p_sys->i_width
134 * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
135 p_vout->output.pf_setpalette = SetPalette;
137 /* Find an empty picture slot */
138 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
140 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
142 p_pic = p_vout->p_picture + i_index;
152 /* Allocate the picture */
153 p_pic->p->p_pixels = aa_image( p_vout->p_sys->aa_context );
154 p_pic->p->i_lines = p_vout->p_sys->i_height;
155 p_pic->p->i_visible_lines = p_vout->p_sys->i_height;
156 p_pic->p->i_pitch = p_vout->p_sys->i_width;
157 p_pic->p->i_pixel_pitch = 1;
158 p_pic->p->i_visible_pitch = p_vout->p_sys->i_width;
161 p_pic->i_status = DESTROYED_PICTURE;
162 p_pic->i_type = DIRECT_PICTURE;
164 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
170 /*****************************************************************************
171 * End: terminate aa video thread output method
172 *****************************************************************************/
173 static void End( vout_thread_t *p_vout )
178 /*****************************************************************************
179 * Destroy: destroy aa video thread output method
180 *****************************************************************************
181 * Terminate an output method created by AaCreateOutputMethod
182 *****************************************************************************/
183 static void Destroy( vlc_object_t *p_this )
185 vout_thread_t *p_vout = (vout_thread_t *)p_this;
187 aa_close( p_vout->p_sys->aa_context );
188 free( p_vout->p_sys );
191 /*****************************************************************************
192 * Manage: handle aa events
193 *****************************************************************************
194 * This function should be called regularly by video output thread. It manages
195 * console events. It returns a non null value on error.
196 *****************************************************************************/
197 static int Manage( vout_thread_t *p_vout )
200 event = aa_getevent( p_vout->p_sys->aa_context, 0 );
204 aa_getmouse( p_vout->p_sys->aa_context, &x, &y, &b );
205 if ( b & AA_BUTTON3 )
207 intf_thread_t *p_intf;
208 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
211 p_intf->b_menu_change = 1;
212 vlc_object_release( p_intf );
217 p_vout->i_changes |= VOUT_SIZE_CHANGE;
218 aa_resize( p_vout->p_sys->aa_context );
219 p_vout->p_sys->i_width = aa_imgwidth( p_vout->p_sys->aa_context );
220 p_vout->p_sys->i_height = aa_imgheight( p_vout->p_sys->aa_context );
228 /*****************************************************************************
229 * Render: render previously calculated output
230 *****************************************************************************/
231 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
233 aa_fastrender( p_vout->p_sys->aa_context, 0, 0,
234 aa_imgwidth( p_vout->p_sys->aa_context ),
235 aa_imgheight( p_vout->p_sys->aa_context ) );
238 /*****************************************************************************
239 * Display: displays previously rendered output
240 *****************************************************************************/
241 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
243 /* No need to do anything, the fake direct buffers stay as they are */
244 int i_width, i_height, i_x, i_y;
246 vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
247 &i_x, &i_y, &i_width, &i_height );
249 aa_flush(p_vout->p_sys->aa_context);
252 /*****************************************************************************
253 * SetPalette: set the 8bpp palette
254 *****************************************************************************/
255 static void SetPalette( vout_thread_t *p_vout,
256 uint16_t *red, uint16_t *green, uint16_t *blue )
260 /* Fill colors with color information */
261 for( i = 0; i < 256; i++ )
263 aa_setpalette( p_vout->p_sys->palette, 256 -i,
264 red[ i ], green[ i ], blue[ i ] );