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 */
33 #include <vlc_interface.h>
35 /*****************************************************************************
37 *****************************************************************************/
38 static int Create ( vlc_object_t * );
39 static void Destroy ( vlc_object_t * );
41 static int Init ( vout_thread_t * );
42 static void End ( vout_thread_t * );
43 static int Manage ( vout_thread_t * );
44 static void Render ( vout_thread_t *, picture_t * );
45 static void Display ( vout_thread_t *, picture_t * );
47 static void SetPalette ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
49 /*****************************************************************************
51 *****************************************************************************/
53 set_shortname( _("ASCII Art"));
54 set_category( CAT_VIDEO );
55 set_subcategory( SUBCAT_VIDEO_VOUT );
56 set_description( _("ASCII-art video output") );
57 set_capability( "video output", 10 );
58 add_shortcut( "aalib" );
59 set_callbacks( Create, Destroy );
62 /*****************************************************************************
63 * vout_sys_t: aa video output method descriptor
64 *****************************************************************************
65 * This structure is part of the video output thread descriptor.
66 * It describes the aa specific properties of an output thread.
67 *****************************************************************************/
70 struct aa_context* aa_context;
72 int i_width; /* width of main window */
73 int i_height; /* height of main window */
76 /*****************************************************************************
77 * Create: allocates aa video thread output method
78 *****************************************************************************
79 * This function allocates and initializes a aa vout method.
80 *****************************************************************************/
81 static int Create( vlc_object_t *p_this )
83 vout_thread_t *p_vout = (vout_thread_t *)p_this;
85 /* Allocate structure */
86 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
87 if( p_vout->p_sys == NULL )
89 msg_Err( p_vout, "out of memory" );
93 /* Don't parse any options, but take $AAOPTS into account */
94 aa_parseoptions( NULL, NULL, NULL, NULL );
96 if (!(p_vout->p_sys->aa_context = aa_autoinit(&aa_defparams)))
98 msg_Err( p_vout, "cannot initialize aalib" );
102 p_vout->pf_init = Init;
103 p_vout->pf_end = End;
104 p_vout->pf_manage = Manage;
105 p_vout->pf_render = Render;
106 p_vout->pf_display = Display;
108 p_vout->p_sys->i_width = aa_imgwidth(p_vout->p_sys->aa_context);
109 p_vout->p_sys->i_height = aa_imgheight(p_vout->p_sys->aa_context);
110 aa_autoinitkbd( p_vout->p_sys->aa_context, 0 );
111 aa_autoinitmouse( p_vout->p_sys->aa_context, AA_MOUSEPRESSMASK );
112 aa_hidemouse( p_vout->p_sys->aa_context );
116 /*****************************************************************************
117 * Init: initialize aa video thread output method
118 *****************************************************************************/
119 static int Init( vout_thread_t *p_vout )
122 picture_t *p_pic = NULL;
124 I_OUTPUTPICTURES = 0;
126 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
127 p_vout->output.i_width = p_vout->p_sys->i_width;
128 p_vout->output.i_height = p_vout->p_sys->i_height;
129 p_vout->output.i_aspect = p_vout->p_sys->i_width
130 * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
131 p_vout->output.pf_setpalette = SetPalette;
133 /* Find an empty picture slot */
134 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
136 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
138 p_pic = p_vout->p_picture + i_index;
148 /* Allocate the picture */
149 p_pic->p->p_pixels = aa_image( p_vout->p_sys->aa_context );
150 p_pic->p->i_lines = p_vout->p_sys->i_height;
151 p_pic->p->i_visible_lines = p_vout->p_sys->i_height;
152 p_pic->p->i_pitch = p_vout->p_sys->i_width;
153 p_pic->p->i_pixel_pitch = 1;
154 p_pic->p->i_visible_pitch = p_vout->p_sys->i_width;
157 p_pic->i_status = DESTROYED_PICTURE;
158 p_pic->i_type = DIRECT_PICTURE;
160 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
166 /*****************************************************************************
167 * End: terminate aa video thread output method
168 *****************************************************************************/
169 static void End( vout_thread_t *p_vout )
174 /*****************************************************************************
175 * Destroy: destroy aa video thread output method
176 *****************************************************************************
177 * Terminate an output method created by AaCreateOutputMethod
178 *****************************************************************************/
179 static void Destroy( vlc_object_t *p_this )
181 vout_thread_t *p_vout = (vout_thread_t *)p_this;
183 aa_close( p_vout->p_sys->aa_context );
184 free( p_vout->p_sys );
187 /*****************************************************************************
188 * Manage: handle aa events
189 *****************************************************************************
190 * This function should be called regularly by video output thread. It manages
191 * console events. It returns a non null value on error.
192 *****************************************************************************/
193 static int Manage( vout_thread_t *p_vout )
196 event = aa_getevent( p_vout->p_sys->aa_context, 0 );
200 aa_getmouse( p_vout->p_sys->aa_context, &x, &y, &b );
201 if ( b & AA_BUTTON3 )
203 intf_thread_t *p_intf;
204 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
207 p_intf->b_menu_change = 1;
208 vlc_object_release( p_intf );
213 p_vout->i_changes |= VOUT_SIZE_CHANGE;
214 aa_resize( p_vout->p_sys->aa_context );
215 p_vout->p_sys->i_width = aa_imgwidth( p_vout->p_sys->aa_context );
216 p_vout->p_sys->i_height = aa_imgheight( p_vout->p_sys->aa_context );
224 /*****************************************************************************
225 * Render: render previously calculated output
226 *****************************************************************************/
227 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
229 aa_fastrender( p_vout->p_sys->aa_context, 0, 0,
230 aa_imgwidth( p_vout->p_sys->aa_context ),
231 aa_imgheight( p_vout->p_sys->aa_context ) );
234 /*****************************************************************************
235 * Display: displays previously rendered output
236 *****************************************************************************/
237 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
239 /* No need to do anything, the fake direct buffers stay as they are */
240 int i_width, i_height, i_x, i_y;
242 vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
243 &i_x, &i_y, &i_width, &i_height );
245 aa_flush(p_vout->p_sys->aa_context);
248 /*****************************************************************************
249 * SetPalette: set the 8bpp palette
250 *****************************************************************************/
251 static void SetPalette( vout_thread_t *p_vout,
252 uint16_t *red, uint16_t *green, uint16_t *blue )
256 /* Fill colors with color information */
257 for( i = 0; i < 256; i++ )
259 aa_setpalette( p_vout->p_sys->palette, 256 -i,
260 red[ i ], green[ i ], blue[ i ] );