Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

aa.c

00001 /*****************************************************************************
00002  * vout_aa.c: Aa video output display method for testing purposes
00003  *****************************************************************************
00004  * Copyright (C) 2002 the VideoLAN team
00005  * $Id: aa.c 12836 2005-10-15 13:23:08Z sigmunau $
00006  *
00007  * Authors: Sigmund Augdal Helberg <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <errno.h>                                                 /* ENOMEM */
00028 #include <stdlib.h>                                                /* free() */
00029 #include <string.h>                                            /* strerror() */
00030 
00031 #include <aalib.h>
00032 
00033 #include <vlc/vlc.h>
00034 #include <vlc/vout.h>
00035 #include <vlc/intf.h>
00036 
00037 /*****************************************************************************
00038  * Local prototypes
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  * Module descriptor
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  * vout_sys_t: aa video output method descriptor
00066  *****************************************************************************
00067  * This structure is part of the video output thread descriptor.
00068  * It describes the aa specific properties of an output thread.
00069  *****************************************************************************/
00070 struct vout_sys_t
00071 {
00072     struct aa_context*  aa_context;
00073     aa_palette          palette;
00074     int                 i_width;                     /* width of main window */
00075     int                 i_height;                   /* height of main window */
00076 };
00077 
00078 /*****************************************************************************
00079  * Create: allocates aa video thread output method
00080  *****************************************************************************
00081  * This function allocates and initializes a aa vout method.
00082  *****************************************************************************/
00083 static int Create( vlc_object_t *p_this )
00084 {
00085     vout_thread_t *p_vout = (vout_thread_t *)p_this;
00086 
00087     /* Allocate structure */
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     /* Don't parse any options, but take $AAOPTS into account */
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  * Init: initialize aa video thread output method
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     /* Find an empty picture slot */
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     /* Allocate the picture */
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  * End: terminate aa video thread output method
00170  *****************************************************************************/
00171 static void End( vout_thread_t *p_vout )
00172 {
00173     ;
00174 }
00175 
00176 /*****************************************************************************
00177  * Destroy: destroy aa video thread output method
00178  *****************************************************************************
00179  * Terminate an output method created by AaCreateOutputMethod
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  * Manage: handle aa events
00191  *****************************************************************************
00192  * This function should be called regularly by video output thread. It manages
00193  * console events. It returns a non null value on error.
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  * Render: render previously calculated output
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  * Display: displays previously rendered output
00238  *****************************************************************************/
00239 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
00240 {
00241     /* No need to do anything, the fake direct buffers stay as they are */
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  * SetPalette: set the 8bpp palette
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     /* Fill colors with color information */
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 

Generated on Tue Dec 20 10:14:55 2005 for vlc-0.8.4a by  doxygen 1.4.2