]> git.sesse.net Git - vlc/blob - modules/video_output/aa.c
vout modules: remove uneeded includes.
[vlc] / modules / video_output / aa.c
1 /*****************************************************************************
2  * vout_aa.c: Aa video output display method for testing purposes
3  *****************************************************************************
4  * Copyright (C) 2002-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <aalib.h>
32
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_vout.h>
36
37 /*****************************************************************************
38  * Local prototypes
39  *****************************************************************************/
40 static int  Create    ( vlc_object_t * );
41 static void Destroy   ( vlc_object_t * );
42
43 static int  Init      ( vout_thread_t * );
44 static void End       ( vout_thread_t * );
45 static int  Manage    ( vout_thread_t * );
46 static void Render    ( vout_thread_t *, picture_t * );
47 static void Display   ( vout_thread_t *, picture_t * );
48
49 static void SetPalette     ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
50
51 /*****************************************************************************
52  * Module descriptor
53  *****************************************************************************/
54 vlc_module_begin ()
55     set_shortname( N_("ASCII Art"))
56     set_category( CAT_VIDEO )
57     set_subcategory( SUBCAT_VIDEO_VOUT )
58     set_description( N_("ASCII-art video output") )
59     set_capability( "video output", 10 )
60     add_shortcut( "aalib" )
61     set_callbacks( Create, Destroy )
62 vlc_module_end ()
63
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  *****************************************************************************/
70 struct vout_sys_t
71 {
72     struct aa_context*  aa_context;
73     aa_palette          palette;
74     int                 i_width;                     /* width of main window */
75     int                 i_height;                   /* height of main window */
76 };
77
78 /*****************************************************************************
79  * Create: allocates aa video thread output method
80  *****************************************************************************
81  * This function allocates and initializes a aa vout method.
82  *****************************************************************************/
83 static int Create( vlc_object_t *p_this )
84 {
85     vout_thread_t *p_vout = (vout_thread_t *)p_this;
86
87     /* Allocate structure */
88     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
89     if( p_vout->p_sys == NULL )
90         return VLC_ENOMEM;
91
92     /* Don't parse any options, but take $AAOPTS into account */
93     aa_parseoptions( NULL, NULL, NULL, NULL );
94
95     if (!(p_vout->p_sys->aa_context = aa_autoinit(&aa_defparams)))
96     {
97         msg_Err( p_vout, "cannot initialize aalib" );
98         free( p_vout->p_sys );
99         return VLC_EGENERIC;
100     }
101
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;
107
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 );
113
114     return VLC_SUCCESS;
115 }
116
117 /*****************************************************************************
118  * Init: initialize aa video thread output method
119  *****************************************************************************/
120 static int Init( vout_thread_t *p_vout )
121 {
122     int i_index;
123     picture_t *p_pic = NULL;
124
125     I_OUTPUTPICTURES = 0;
126
127     p_vout->output.i_chroma = VLC_CODEC_RGB8;
128     p_vout->output.i_width = p_vout->p_sys->i_width;
129     p_vout->output.i_height = p_vout->p_sys->i_height;
130     p_vout->output.i_aspect = p_vout->p_sys->i_width
131                                * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
132     p_vout->output.pf_setpalette = SetPalette;
133
134     /* Find an empty picture slot */
135     for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
136     {
137         if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
138         {
139             p_pic = p_vout->p_picture + i_index;
140             break;
141         }
142     }
143
144     if( p_pic == NULL )
145         return VLC_EGENERIC;
146
147     /* Allocate the picture */
148     p_pic->p->p_pixels = aa_image( p_vout->p_sys->aa_context );
149     p_pic->p->i_lines = p_vout->p_sys->i_height;
150     p_pic->p->i_visible_lines = p_vout->p_sys->i_height;
151     p_pic->p->i_pitch = p_vout->p_sys->i_width;
152     p_pic->p->i_pixel_pitch = 1;
153     p_pic->p->i_visible_pitch = p_vout->p_sys->i_width;
154     p_pic->i_planes = 1;
155
156     p_pic->i_status = DESTROYED_PICTURE;
157     p_pic->i_type   = DIRECT_PICTURE;
158
159     PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
160     I_OUTPUTPICTURES++;
161
162     return VLC_SUCCESS;
163 }
164
165 /*****************************************************************************
166  * End: terminate aa video thread output method
167  *****************************************************************************/
168 static void End( vout_thread_t *p_vout )
169 {
170     ;
171 }
172
173 /*****************************************************************************
174  * Destroy: destroy aa video thread output method
175  *****************************************************************************
176  * Terminate an output method created by AaCreateOutputMethod
177  *****************************************************************************/
178 static void Destroy( vlc_object_t *p_this )
179 {
180     vout_thread_t *p_vout = (vout_thread_t *)p_this;
181
182     aa_close( p_vout->p_sys->aa_context );
183     free( p_vout->p_sys );
184 }
185
186 /*****************************************************************************
187  * Manage: handle aa events
188  *****************************************************************************
189  * This function should be called regularly by video output thread. It manages
190  * console events. It returns a non null value on error.
191  *****************************************************************************/
192 static int Manage( vout_thread_t *p_vout )
193 {
194     int event, x, y, b;
195     event = aa_getevent( p_vout->p_sys->aa_context, 0 );
196     switch ( event )
197     {
198     case AA_MOUSE:
199         aa_getmouse( p_vout->p_sys->aa_context, &x, &y, &b );
200         if ( b & AA_BUTTON3 )
201             var_SetBool( p_vout->p_libvlc, "intf-popupmenu", true );
202         break;
203     case AA_RESIZE:
204         p_vout->i_changes |= VOUT_SIZE_CHANGE;
205         aa_resize( p_vout->p_sys->aa_context );
206         p_vout->p_sys->i_width = aa_imgwidth( p_vout->p_sys->aa_context );
207         p_vout->p_sys->i_height = aa_imgheight( p_vout->p_sys->aa_context );
208         break;
209     default:
210         break;
211     }
212     return VLC_SUCCESS;
213 }
214
215 /*****************************************************************************
216  * Render: render previously calculated output
217  *****************************************************************************/
218 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
219 {
220   aa_fastrender( p_vout->p_sys->aa_context, 0, 0,
221                  aa_imgwidth( p_vout->p_sys->aa_context ),
222                  aa_imgheight( p_vout->p_sys->aa_context ) );
223 }
224
225 /*****************************************************************************
226  * Display: displays previously rendered output
227  *****************************************************************************/
228 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
229 {
230     /* No need to do anything, the fake direct buffers stay as they are */
231     unsigned int i_width, i_height, i_x, i_y;
232
233     vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
234                        &i_x, &i_y, &i_width, &i_height );
235
236     aa_flush(p_vout->p_sys->aa_context);
237 }
238
239 /*****************************************************************************
240  * SetPalette: set the 8bpp palette
241  *****************************************************************************/
242 static void SetPalette( vout_thread_t *p_vout,
243                         uint16_t *red, uint16_t *green, uint16_t *blue )
244 {
245     int i;
246
247     /* Fill colors with color information */
248     for( i = 0; i < 256; i++ )
249     {
250         aa_setpalette( p_vout->p_sys->palette, 256 -i,
251                        red[ i ], green[ i ], blue[ i ] );
252     }
253 }
254