00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <errno.h>
00028 #include <stdlib.h>
00029 #include <string.h>
00030
00031 #include <aalib.h>
00032
00033 #include <vlc/vlc.h>
00034 #include <vlc/vout.h>
00035 #include <vlc/intf.h>
00036
00037
00038
00039
00040 static int Create ( vlc_object_t * );
00041 static void Destroy ( vlc_object_t * );
00042
00043 static int Init ( vout_thread_t * );
00044 static void End ( vout_thread_t * );
00045 static int Manage ( vout_thread_t * );
00046 static void Render ( vout_thread_t *, picture_t * );
00047 static void Display ( vout_thread_t *, picture_t * );
00048
00049 static void SetPalette ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
00050
00051
00052
00053
00054 vlc_module_begin();
00055 set_shortname( _("Ascii Art"));
00056 set_category( CAT_VIDEO );
00057 set_subcategory( SUBCAT_VIDEO_VOUT );
00058 set_description( _("ASCII-art video output") );
00059 set_capability( "video output", 10 );
00060 add_shortcut( "aalib" );
00061 set_callbacks( Create, Destroy );
00062 vlc_module_end();
00063
00064
00065
00066
00067
00068
00069
00070 struct vout_sys_t
00071 {
00072 struct aa_context* aa_context;
00073 aa_palette palette;
00074 int i_width;
00075 int i_height;
00076 };
00077
00078
00079
00080
00081
00082
00083 static int Create( vlc_object_t *p_this )
00084 {
00085 vout_thread_t *p_vout = (vout_thread_t *)p_this;
00086
00087
00088 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
00089 if( p_vout->p_sys == NULL )
00090 {
00091 msg_Err( p_vout, "out of memory" );
00092 return( 1 );
00093 }
00094
00095
00096 aa_parseoptions( NULL, NULL, NULL, NULL );
00097
00098 if (!(p_vout->p_sys->aa_context = aa_autoinit(&aa_defparams)))
00099 {
00100 msg_Err( p_vout, "cannot initialize aalib" );
00101 return( 1 );
00102 }
00103
00104 p_vout->pf_init = Init;
00105 p_vout->pf_end = End;
00106 p_vout->pf_manage = Manage;
00107 p_vout->pf_render = Render;
00108 p_vout->pf_display = Display;
00109
00110 p_vout->p_sys->i_width = aa_imgwidth(p_vout->p_sys->aa_context);
00111 p_vout->p_sys->i_height = aa_imgheight(p_vout->p_sys->aa_context);
00112 aa_autoinitkbd( p_vout->p_sys->aa_context, 0 );
00113 aa_autoinitmouse( p_vout->p_sys->aa_context, AA_MOUSEPRESSMASK );
00114 aa_hidemouse( p_vout->p_sys->aa_context );
00115 return( 0 );
00116 }
00117
00118
00119
00120
00121 static int Init( vout_thread_t *p_vout )
00122 {
00123 int i_index;
00124 picture_t *p_pic = NULL;
00125
00126 I_OUTPUTPICTURES = 0;
00127
00128 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
00129 p_vout->output.i_width = p_vout->p_sys->i_width;
00130 p_vout->output.i_height = p_vout->p_sys->i_height;
00131 p_vout->output.i_aspect = p_vout->p_sys->i_width
00132 * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
00133 p_vout->output.pf_setpalette = SetPalette;
00134
00135
00136 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
00137 {
00138 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
00139 {
00140 p_pic = p_vout->p_picture + i_index;
00141 break;
00142 }
00143 }
00144
00145 if( p_pic == NULL )
00146 {
00147 return -1;
00148 }
00149
00150
00151 p_pic->p->p_pixels = aa_image( p_vout->p_sys->aa_context );
00152 p_pic->p->i_lines = p_vout->p_sys->i_height;
00153 p_pic->p->i_visible_lines = p_vout->p_sys->i_height;
00154 p_pic->p->i_pitch = p_vout->p_sys->i_width;
00155 p_pic->p->i_pixel_pitch = 1;
00156 p_pic->p->i_visible_pitch = p_vout->p_sys->i_width;
00157 p_pic->i_planes = 1;
00158
00159 p_pic->i_status = DESTROYED_PICTURE;
00160 p_pic->i_type = DIRECT_PICTURE;
00161
00162 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
00163 I_OUTPUTPICTURES++;
00164
00165 return 0;
00166 }
00167
00168
00169
00170
00171 static void End( vout_thread_t *p_vout )
00172 {
00173 ;
00174 }
00175
00176
00177
00178
00179
00180
00181 static void Destroy( vlc_object_t *p_this )
00182 {
00183 vout_thread_t *p_vout = (vout_thread_t *)p_this;
00184
00185 aa_close( p_vout->p_sys->aa_context );
00186 free( p_vout->p_sys );
00187 }
00188
00189
00190
00191
00192
00193
00194
00195 static int Manage( vout_thread_t *p_vout )
00196 {
00197 int event, x, y, b;
00198 event = aa_getevent( p_vout->p_sys->aa_context, 0 );
00199 switch ( event )
00200 {
00201 case AA_MOUSE:
00202 aa_getmouse( p_vout->p_sys->aa_context, &x, &y, &b );
00203 if ( b & AA_BUTTON3 )
00204 {
00205 intf_thread_t *p_intf;
00206 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
00207 if( p_intf )
00208 {
00209 p_intf->b_menu_change = 1;
00210 vlc_object_release( p_intf );
00211 }
00212 }
00213 break;
00214 case AA_RESIZE:
00215 p_vout->i_changes |= VOUT_SIZE_CHANGE;
00216 aa_resize( p_vout->p_sys->aa_context );
00217 p_vout->p_sys->i_width = aa_imgwidth( p_vout->p_sys->aa_context );
00218 p_vout->p_sys->i_height = aa_imgheight( p_vout->p_sys->aa_context );
00219 break;
00220 default:
00221 break;
00222 }
00223 return( 0 );
00224 }
00225
00226
00227
00228
00229 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
00230 {
00231 aa_fastrender( p_vout->p_sys->aa_context, 0, 0,
00232 aa_imgwidth( p_vout->p_sys->aa_context ),
00233 aa_imgheight( p_vout->p_sys->aa_context ) );
00234 }
00235
00236
00237
00238
00239 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
00240 {
00241
00242 int i_width, i_height, i_x, i_y;
00243
00244 vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
00245 &i_x, &i_y, &i_width, &i_height );
00246
00247 aa_flush(p_vout->p_sys->aa_context);
00248 }
00249
00250
00251
00252
00253 static void SetPalette( vout_thread_t *p_vout,
00254 uint16_t *red, uint16_t *green, uint16_t *blue )
00255 {
00256 int i;
00257
00258
00259 for( i = 0; i < 256; i++ )
00260 {
00261 aa_setpalette( p_vout->p_sys->palette, 256 -i,
00262 red[ i ], green[ i ], blue[ i ] );
00263 }
00264 }
00265