| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
#include <errno.h> |
|---|
| 28 |
|
|---|
| 29 |
#include <aalib.h> |
|---|
| 30 |
|
|---|
| 31 |
#ifdef HAVE_CONFIG_H |
|---|
| 32 |
# include "config.h" |
|---|
| 33 |
#endif |
|---|
| 34 |
|
|---|
| 35 |
#include <vlc_common.h> |
|---|
| 36 |
#include <vlc_plugin.h> |
|---|
| 37 |
#include <vlc_vout.h> |
|---|
| 38 |
#include <vlc_interface.h> |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
static int Create ( vlc_object_t * ); |
|---|
| 44 |
static void Destroy ( vlc_object_t * ); |
|---|
| 45 |
|
|---|
| 46 |
static int Init ( vout_thread_t * ); |
|---|
| 47 |
static void End ( vout_thread_t * ); |
|---|
| 48 |
static int Manage ( vout_thread_t * ); |
|---|
| 49 |
static void Render ( vout_thread_t *, picture_t * ); |
|---|
| 50 |
static void Display ( vout_thread_t *, picture_t * ); |
|---|
| 51 |
|
|---|
| 52 |
static void SetPalette ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * ); |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
vlc_module_begin(); |
|---|
| 58 |
set_shortname( N_("ASCII Art")); |
|---|
| 59 |
set_category( CAT_VIDEO ); |
|---|
| 60 |
set_subcategory( SUBCAT_VIDEO_VOUT ); |
|---|
| 61 |
set_description( N_("ASCII-art video output") ); |
|---|
| 62 |
set_capability( "video output", 10 ); |
|---|
| 63 |
add_shortcut( "aalib" ); |
|---|
| 64 |
set_callbacks( Create, Destroy ); |
|---|
| 65 |
vlc_module_end(); |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
struct vout_sys_t |
|---|
| 74 |
{ |
|---|
| 75 |
struct aa_context* aa_context; |
|---|
| 76 |
aa_palette palette; |
|---|
| 77 |
int i_width; |
|---|
| 78 |
int i_height; |
|---|
| 79 |
}; |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
static int Create( vlc_object_t *p_this ) |
|---|
| 87 |
{ |
|---|
| 88 |
vout_thread_t *p_vout = (vout_thread_t *)p_this; |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); |
|---|
| 92 |
if( p_vout->p_sys == NULL ) |
|---|
| 93 |
return( 1 ); |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
aa_parseoptions( NULL, NULL, NULL, NULL ); |
|---|
| 97 |
|
|---|
| 98 |
if (!(p_vout->p_sys->aa_context = aa_autoinit(&aa_defparams))) |
|---|
| 99 |
{ |
|---|
| 100 |
msg_Err( p_vout, "cannot initialize aalib" ); |
|---|
| 101 |
return( 1 ); |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 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; |
|---|
| 109 |
|
|---|
| 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 ); |
|---|
| 115 |
return( 0 ); |
|---|
| 116 |
} |
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
static int Init( vout_thread_t *p_vout ) |
|---|
| 122 |
{ |
|---|
| 123 |
int i_index; |
|---|
| 124 |
picture_t *p_pic = NULL; |
|---|
| 125 |
|
|---|
| 126 |
I_OUTPUTPICTURES = 0; |
|---|
| 127 |
|
|---|
| 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; |
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ ) |
|---|
| 137 |
{ |
|---|
| 138 |
if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE ) |
|---|
| 139 |
{ |
|---|
| 140 |
p_pic = p_vout->p_picture + i_index; |
|---|
| 141 |
break; |
|---|
| 142 |
} |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
if( p_pic == NULL ) |
|---|
| 146 |
{ |
|---|
| 147 |
return -1; |
|---|
| 148 |
} |
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 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; |
|---|
| 157 |
p_pic->i_planes = 1; |
|---|
| 158 |
|
|---|
| 159 |
p_pic->i_status = DESTROYED_PICTURE; |
|---|
| 160 |
p_pic->i_type = DIRECT_PICTURE; |
|---|
| 161 |
|
|---|
| 162 |
PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic; |
|---|
| 163 |
I_OUTPUTPICTURES++; |
|---|
| 164 |
|
|---|
| 165 |
return 0; |
|---|
| 166 |
} |
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
static void End( vout_thread_t *p_vout ) |
|---|
| 172 |
{ |
|---|
| 173 |
; |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
static void Destroy( vlc_object_t *p_this ) |
|---|
| 182 |
{ |
|---|
| 183 |
vout_thread_t *p_vout = (vout_thread_t *)p_this; |
|---|
| 184 |
|
|---|
| 185 |
aa_close( p_vout->p_sys->aa_context ); |
|---|
| 186 |
free( p_vout->p_sys ); |
|---|
| 187 |
} |
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
static int Manage( vout_thread_t *p_vout ) |
|---|
| 196 |
{ |
|---|
| 197 |
int event, x, y, b; |
|---|
| 198 |
event = aa_getevent( p_vout->p_sys->aa_context, 0 ); |
|---|
| 199 |
switch ( event ) |
|---|
| 200 |
{ |
|---|
| 201 |
case AA_MOUSE: |
|---|
| 202 |
aa_getmouse( p_vout->p_sys->aa_context, &x, &y, &b ); |
|---|
| 203 |
if ( b & AA_BUTTON3 ) |
|---|
| 204 |
{ |
|---|
| 205 |
intf_thread_t *p_intf; |
|---|
| 206 |
p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE ); |
|---|
| 207 |
if( p_intf ) |
|---|
| 208 |
{ |
|---|
| 209 |
p_intf->b_menu_change = 1; |
|---|
| 210 |
vlc_object_release( p_intf ); |
|---|
| 211 |
} |
|---|
| 212 |
} |
|---|
| 213 |
break; |
|---|
| 214 |
case AA_RESIZE: |
|---|
| 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 ); |
|---|
| 219 |
break; |
|---|
| 220 |
default: |
|---|
| 221 |
break; |
|---|
| 222 |
} |
|---|
| 223 |
return( 0 ); |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
static void Render( vout_thread_t *p_vout, picture_t *p_pic ) |
|---|
| 230 |
{ |
|---|
| 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 ) ); |
|---|
| 234 |
} |
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
static void Display( vout_thread_t *p_vout, picture_t *p_pic ) |
|---|
| 240 |
{ |
|---|
| 241 |
|
|---|
| 242 |
int i_width, i_height, i_x, i_y; |
|---|
| 243 |
|
|---|
| 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 ); |
|---|
| 246 |
|
|---|
| 247 |
aa_flush(p_vout->p_sys->aa_context); |
|---|
| 248 |
} |
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
static void SetPalette( vout_thread_t *p_vout, |
|---|
| 254 |
uint16_t *red, uint16_t *green, uint16_t *blue ) |
|---|
| 255 |
{ |
|---|
| 256 |
int i; |
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
for( i = 0; i < 256; i++ ) |
|---|
| 260 |
{ |
|---|
| 261 |
aa_setpalette( p_vout->p_sys->palette, 256 -i, |
|---|
| 262 |
red[ i ], green[ i ], blue[ i ] ); |
|---|
| 263 |
} |
|---|
| 264 |
} |
|---|
| 265 |
|
|---|