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 <sigmunau@idi.ntnu.no>
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <errno.h> /* ENOMEM */
28 #include <stdlib.h> /* free() */
29 #include <string.h> /* strerror() */
37 /*****************************************************************************
39 *****************************************************************************/
40 static int Create ( vlc_object_t * );
41 static void Destroy ( vlc_object_t * );
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 * );
49 static void SetPalette ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
51 /*****************************************************************************
53 *****************************************************************************/
55 set_shortname( _("Ascii Art"));
56 set_category( CAT_VIDEO );
57 set_subcategory( SUBCAT_VIDEO_VOUT );
58 set_description( _("ASCII-art video output") );
59 set_capability( "video output", 10 );
60 add_shortcut( "aalib" );
61 set_callbacks( Create, Destroy );
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 *****************************************************************************/
72 struct aa_context* aa_context;
74 int i_width; /* width of main window */
75 int i_height; /* height of main window */
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 )
85 vout_thread_t *p_vout = (vout_thread_t *)p_this;
87 /* Allocate structure */
88 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
89 if( p_vout->p_sys == NULL )
91 msg_Err( p_vout, "out of memory" );
95 /* Don't parse any options, but take $AAOPTS into account */
96 aa_parseoptions( NULL, NULL, NULL, NULL );
98 if (!(p_vout->p_sys->aa_context = aa_autoinit(&aa_defparams)))
100 msg_Err( p_vout, "cannot initialize aalib" );
104 p_vout->pf_init = Init;
105 p_vout->pf_end = End;
106 p_vout->pf_manage = Manage;
107 p_vout->pf_render = Render;
108 p_vout->pf_display = Display;
110 p_vout->p_sys->i_width = aa_imgwidth(p_vout->p_sys->aa_context);
111 p_vout->p_sys->i_height = aa_imgheight(p_vout->p_sys->aa_context);
112 aa_autoinitkbd( p_vout->p_sys->aa_context, 0 );
113 aa_autoinitmouse( p_vout->p_sys->aa_context, AA_MOUSEPRESSMASK );
114 aa_hidemouse( p_vout->p_sys->aa_context );
118 /*****************************************************************************
119 * Init: initialize aa video thread output method
120 *****************************************************************************/
121 static int Init( vout_thread_t *p_vout )
124 picture_t *p_pic = NULL;
126 I_OUTPUTPICTURES = 0;
128 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
129 p_vout->output.i_width = p_vout->p_sys->i_width;
130 p_vout->output.i_height = p_vout->p_sys->i_height;
131 p_vout->output.i_aspect = p_vout->p_sys->i_width
132 * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
133 p_vout->output.pf_setpalette = SetPalette;
135 /* Find an empty picture slot */
136 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
138 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
140 p_pic = p_vout->p_picture + i_index;
150 /* Allocate the picture */
151 p_pic->p->p_pixels = aa_image( p_vout->p_sys->aa_context );
152 p_pic->p->i_lines = p_vout->p_sys->i_height;
153 p_pic->p->i_visible_lines = p_vout->p_sys->i_height;
154 p_pic->p->i_pitch = p_vout->p_sys->i_width;
155 p_pic->p->i_pixel_pitch = 1;
156 p_pic->p->i_visible_pitch = p_vout->p_sys->i_width;
159 p_pic->i_status = DESTROYED_PICTURE;
160 p_pic->i_type = DIRECT_PICTURE;
162 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
168 /*****************************************************************************
169 * End: terminate aa video thread output method
170 *****************************************************************************/
171 static void End( vout_thread_t *p_vout )
176 /*****************************************************************************
177 * Destroy: destroy aa video thread output method
178 *****************************************************************************
179 * Terminate an output method created by AaCreateOutputMethod
180 *****************************************************************************/
181 static void Destroy( vlc_object_t *p_this )
183 vout_thread_t *p_vout = (vout_thread_t *)p_this;
185 aa_close( p_vout->p_sys->aa_context );
186 free( p_vout->p_sys );
189 /*****************************************************************************
190 * Manage: handle aa events
191 *****************************************************************************
192 * This function should be called regularly by video output thread. It manages
193 * console events. It returns a non null value on error.
194 *****************************************************************************/
195 static int Manage( vout_thread_t *p_vout )
198 event = aa_getevent( p_vout->p_sys->aa_context, 0 );
202 aa_getmouse( p_vout->p_sys->aa_context, &x, &y, &b );
203 if ( b & AA_BUTTON3 )
205 intf_thread_t *p_intf;
206 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
209 p_intf->b_menu_change = 1;
210 vlc_object_release( p_intf );
215 p_vout->i_changes |= VOUT_SIZE_CHANGE;
216 aa_resize( p_vout->p_sys->aa_context );
217 p_vout->p_sys->i_width = aa_imgwidth( p_vout->p_sys->aa_context );
218 p_vout->p_sys->i_height = aa_imgheight( p_vout->p_sys->aa_context );
226 /*****************************************************************************
227 * Render: render previously calculated output
228 *****************************************************************************/
229 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
231 aa_fastrender( p_vout->p_sys->aa_context, 0, 0,
232 aa_imgwidth( p_vout->p_sys->aa_context ),
233 aa_imgheight( p_vout->p_sys->aa_context ) );
236 /*****************************************************************************
237 * Display: displays previously rendered output
238 *****************************************************************************/
239 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
241 /* No need to do anything, the fake direct buffers stay as they are */
242 int i_width, i_height, i_x, i_y;
244 vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
245 &i_x, &i_y, &i_width, &i_height );
247 aa_flush(p_vout->p_sys->aa_context);
250 /*****************************************************************************
251 * SetPalette: set the 8bpp palette
252 *****************************************************************************/
253 static void SetPalette( vout_thread_t *p_vout,
254 uint16_t *red, uint16_t *green, uint16_t *blue )
258 /* Fill colors with color information */
259 for( i = 0; i < 256; i++ )
261 aa_setpalette( p_vout->p_sys->palette, 256 -i,
262 red[ i ], green[ i ], blue[ i ] );