typo fixes
[mplayer/greg.git] / libvo / vo_aa.c
blob4e23247bdfda6561c9afaf65730b1f537826a804
1 /*
2 * MPlayer
3 *
4 * Video driver for AAlib - 1.0
5 *
6 * by Folke Ashberg <folke@ashberg.de>
7 *
8 * Code started: Sun Aug 12 2001
9 * Version 1.0 : Thu Aug 16 2001
13 #include <stdio.h>
14 #include <stdlib.h>
16 #include <sys/stat.h>
17 #include <unistd.h>
19 #include <limits.h>
20 #include <math.h>
21 #include <stdarg.h>
22 #include <time.h>
23 #include <string.h>
24 #include <errno.h>
26 #include "config.h"
27 #include "video_out.h"
28 #include "video_out_internal.h"
29 #include "aspect.h"
30 #include "postproc/swscale.h"
31 #include "libmpcodecs/vf_scale.h"
32 #include "font_load.h"
33 #include "sub.h"
35 #include "osdep/keycodes.h"
36 #include <aalib.h>
37 #include "subopt-helper.h"
38 #include "help_mp.h"
39 #include "mp_msg.h"
42 #define MESSAGE_DURATION 3
43 #define MESSAGE_SIZE 512
44 #define MESSAGE_DEKO " +++ %s +++ "
46 static vo_info_t info = {
47 "AAlib",
48 "aa",
49 "Alban Bedel <albeu@free.fr> and Folke Ashberg <folke@ashberg.de>",
53 LIBVO_EXTERN(aa)
55 /* aa's main context we use */
56 aa_context *c;
57 aa_renderparams *p;
58 static int fast =0;
59 /* used for the sws */
60 static uint8_t * image[3];
61 static int image_stride[3];
63 /* image infos */
64 static int image_format;
65 static int image_width;
66 static int image_height;
67 static int image_x, image_y;
68 static int screen_x, screen_y;
69 static int screen_w, screen_h;
70 static int src_width;
71 static int src_height;
73 /* osd stuff */
74 time_t stoposd = 0;
75 static int showosdmessage = 0;
76 char osdmessagetext[MESSAGE_SIZE];
77 char posbar[MESSAGE_SIZE];
78 static int osdx, osdy;
79 static int osd_text_length = 0;
80 int aaconfigmode=1;
81 #ifdef USE_OSD
82 font_desc_t* vo_font_save = NULL;
83 #endif
84 static struct SwsContext *sws=NULL;
86 /* our version of the playmodes :) */
88 extern void mplayer_put_key(int code);
90 /* to disable stdout outputs when curses/linux mode */
91 extern int quiet;
93 /* configuration */
94 int aaopt_osdcolor = AA_SPECIAL;
95 int aaopt_subcolor = AA_SPECIAL;
97 extern struct aa_hardware_params aa_defparams;
98 extern struct aa_renderparams aa_defrenderparams;
100 void
101 resize(void){
103 * this function is called by aa lib if windows resizes
104 * further during init, because here we have to calculate
105 * a little bit
108 aa_resize(c);
110 aspect_save_screenres(aa_imgwidth(c),aa_imgheight(c));
111 image_height = aa_imgheight(c); //src_height;
112 image_width = aa_imgwidth(c); //src_width;
114 aspect(&image_width,&image_height,A_ZOOM);
116 image_x = (aa_imgwidth(c) - image_width) / 2;
117 image_y = (aa_imgheight(c) - image_height) / 2;
118 screen_w = image_width * aa_scrwidth(c) / aa_imgwidth(c);
119 screen_h = image_height * aa_scrheight(c) / aa_imgheight(c);
120 screen_x = (aa_scrwidth(c) - screen_w) / 2;
121 screen_y = (aa_scrheight(c) - screen_h) / 2;
123 if(sws) sws_freeContext(sws);
124 sws = sws_getContextFromCmdLine(src_width,src_height,image_format,
125 image_width,image_height,IMGFMT_Y8);
127 image[0] = aa_image(c) + image_y * aa_imgwidth(c) + image_x;
128 image[1] = NULL;
129 image[2] = NULL;
131 image_stride[0] = aa_imgwidth(c);
132 image_stride[1] = 0;
133 image_stride[2] = 0;
135 showosdmessage=0;
139 void
140 osdmessage(int duration, int deko, char *fmt, ...)
143 * for outputting a centered string at the bottom
144 * of our window for a while
146 va_list ar;
147 char m[MESSAGE_SIZE];
148 unsigned int old_len = strlen(osdmessagetext);
150 va_start(ar, fmt);
151 vsprintf(m, fmt, ar);
152 va_end(ar);
153 if (deko==1) sprintf(osdmessagetext, MESSAGE_DEKO , m);
154 else strcpy(osdmessagetext, m);
156 if(old_len > strlen(osdmessagetext)) {
157 memset(c->textbuffer + osdy * aa_scrwidth(c) + osdx,' ',old_len);
158 memset(c->attrbuffer + osdy * aa_scrwidth(c) + osdx,0,old_len);
160 showosdmessage=1;
161 stoposd = time(NULL) + duration;
162 osdx=(aa_scrwidth(c) / 2) - (strlen(osdmessagetext) / 2 ) ;
163 posbar[0]='\0';
166 void
167 osdpercent(int duration, int deko, int min, int max, int val, char * desc, char * unit)
170 * prints a bar for setting values
172 float step;
173 int where;
174 int i;
177 step=(float)aa_scrwidth(c) /(float)(max-min);
178 where=(val-min)*step;
179 osdmessage(duration,deko,"%s: %i%s",desc, val, unit);
180 posbar[0]='|';
181 posbar[aa_scrwidth(c)-1]='|';
182 for (i=0;i<aa_scrwidth(c);i++){
183 if (i==where) posbar[i]='#';
184 else posbar[i]='-';
186 if (where!=0) posbar[0]='|';
187 if (where!=(aa_scrwidth(c)-1) ) posbar[aa_scrwidth(c)-1]='|';
189 posbar[aa_scrwidth(c)]='\0';
193 void
194 printosdtext(void)
196 if(osd_text_length > 0 && !vo_osd_text) {
197 memset(c->textbuffer,' ',osd_text_length);
198 memset(c->attrbuffer,0,osd_text_length);
199 osd_text_length = 0;
202 * places the mplayer status osd
204 if (vo_osd_text && vo_osd_text[0] != 0) {
205 int len;
206 if(vo_osd_text[0] < 32) {
207 len = strlen(__sub_osd_names_short[vo_osd_text[0]]) + strlen(vo_osd_text+1) + 2;
208 aa_printf(c, 0, 0 , aaopt_osdcolor, "%s %s ", __sub_osd_names_short[vo_osd_text[0]], vo_osd_text+1);
209 } else {
210 len = strlen(vo_osd_text) + 1;
211 aa_printf(c, 0, 0 , aaopt_osdcolor, "%s ",vo_osd_text);
214 if(len < osd_text_length) {
215 memset(c->textbuffer + len,' ',osd_text_length - len);
216 memset(c->attrbuffer + len,0,osd_text_length - len);
218 osd_text_length = len;
223 void
224 printosdprogbar(void){
225 /* print mplayer osd-progbar */
226 if (vo_osd_progbar_type!=-1){
227 osdpercent(1,1,0,255,vo_osd_progbar_value, __sub_osd_names[vo_osd_progbar_type], "");
230 static int
231 config(uint32_t width, uint32_t height, uint32_t d_width,
232 uint32_t d_height, uint32_t flags, char *title,
233 uint32_t format) {
235 * main init
236 * called by mplayer
239 int i;
241 aspect_save_orig(width,height);
242 aspect_save_prescale(d_width,d_height);
244 src_height = height;
245 src_width = width;
246 image_format = format;
248 /* nothing will change its size, be we need some values initialized */
249 resize();
251 #ifdef USE_OSD
252 /* now init out own 'font' (to use vo_draw_text_sub without edit them) */
253 if(!vo_font_save) vo_font_save = vo_font;
254 if(vo_font == vo_font_save) {
255 vo_font=malloc(sizeof(font_desc_t));//if(!desc) return NULL;
256 memset(vo_font,0,sizeof(font_desc_t));
257 vo_font->pic_a[0]=malloc(sizeof(raw_file));
258 memset(vo_font->pic_a[0],0,sizeof(raw_file));
259 vo_font->pic_b[0]=malloc(sizeof(raw_file));
260 memset(vo_font->pic_b[0],0,sizeof(raw_file));
262 #ifdef HAVE_FREETYPE
263 vo_font->dynamic = 0;
264 #endif
266 vo_font->spacewidth=1;
267 vo_font->charspace=0;
268 vo_font->height=1;
269 vo_font->pic_a[0]->bmp=malloc(255);
270 vo_font->pic_a[0]->pal=NULL;
271 vo_font->pic_b[0]->bmp=malloc(255);
272 vo_font->pic_b[0]->pal=NULL;
273 vo_font->pic_a[0]->w=1;
274 vo_font->pic_a[0]->h=1;
275 for (i=0; i<255; i++){
276 vo_font->width[i]=1;
277 vo_font->font[i]=0;
278 vo_font->start[i]=i;
279 vo_font->pic_a[0]->bmp[i]=i;
280 vo_font->pic_b[0]->bmp[i]=i;
283 #endif
284 /* say hello */
285 osdmessage(5, 1, "Welcome to ASCII ART MPlayer");
287 mp_msg(MSGT_VO,MSGL_V,"VO: [aa] screendriver: %s\n", c->driver->name);
288 mp_msg(MSGT_VO,MSGL_V,"VO: [aa] keyboarddriver: %s\n", c->kbddriver->name);
290 mp_msg(MSGT_VO,MSGL_INFO,
291 "\n"
292 "Important suboptions\n"
293 "\textended use use all 256 characters\n"
294 "\teight use eight bit ascii\n"
295 "\tdriver set recommended aalib driver (X11,curses,linux)\n"
296 "\thelp to see all options provided by aalib\n"
297 "\n"
298 "AA-MPlayer Keys\n"
299 "\t1 : contrast -\n"
300 "\t2 : contrast +\n"
301 "\t3 : brightness -\n"
302 "\t4 : brightness +\n"
303 "\t5 : fast rendering\n"
304 "\t6 : dithering\n"
305 "\t7 : invert image\n"
306 "\ta : toggles between aa and mplayer control\n"
308 "\n"
309 "All other keys are MPlayer defaults.\n"
314 return 0;
317 static int
318 query_format(uint32_t format) {
320 * ...are we able to... ?
321 * called by mplayer
322 * All input format supported by the sws
324 switch(format){
325 case IMGFMT_YV12:
326 case IMGFMT_I420:
327 case IMGFMT_IYUV:
328 case IMGFMT_IYU2:
329 case IMGFMT_BGR32:
330 case IMGFMT_BGR24:
331 case IMGFMT_BGR16:
332 case IMGFMT_BGR15:
333 case IMGFMT_RGB32:
334 case IMGFMT_RGB24:
335 case IMGFMT_Y8:
336 case IMGFMT_Y800:
337 return VFCAP_CSP_SUPPORTED|VFCAP_SWSCALE
338 #ifdef USE_OSD
339 | VFCAP_OSD
340 #endif
343 return 0;
346 static int
347 draw_frame(uint8_t *src[]) {
348 int stride[3] = { 0 , 0 , 0 };
350 switch(image_format) {
351 case IMGFMT_BGR15:
352 case IMGFMT_BGR16:
353 stride[0] = src_width*2;
354 break;
355 case IMGFMT_IYU2:
356 case IMGFMT_BGR24:
357 stride[0] = src_width*3;
358 break;
359 case IMGFMT_BGR32:
360 stride[0] = src_width*4;
361 break;
364 sws_scale_ordered(sws,src,stride,0,src_height,image,image_stride);
366 /* Now 'ASCIInate' the image */
367 if (fast)
368 aa_fastrender(c, screen_x, screen_y, screen_w + screen_x, screen_h + screen_y );
369 else
370 aa_render(c, p,screen_x, screen_y, screen_w + screen_x, screen_h + screen_y );
372 return 0;
375 static int
376 draw_slice(uint8_t *src[], int stride[],
377 int w, int h, int x, int y) {
379 int dx1 = screen_x + (x * screen_w / src_width);
380 int dy1 = screen_y + (y * screen_h / src_height);
381 int dx2 = screen_x + ((x+w) * screen_w / src_width);
382 int dy2 = screen_y + ((y+h) * screen_h / src_height);
384 sws_scale_ordered(sws,src,stride,y,h,image,image_stride);
386 /* Now 'ASCIInate' the image */
387 if (fast)
388 aa_fastrender(c, dx1, dy1, dx2, dy2 );
389 else
390 aa_render(c, p,dx1, dy1, dx2, dy2 );
393 return 0;
396 static void
397 flip_page(void) {
399 /* do we have to put *our* (messages, progbar) osd to aa's txtbuf ? */
400 if (showosdmessage)
402 if (time(NULL)>=stoposd ) {
403 showosdmessage=0;
404 if(osdmessagetext) {
405 memset(c->textbuffer + osdy * aa_scrwidth(c) + osdx,' ',strlen(osdmessagetext));
406 memset(c->attrbuffer + osdy * aa_scrwidth(c) + osdx ,0,strlen(osdmessagetext));
407 osdmessagetext[0] = '\0';
409 if(posbar) {
410 memset(c->textbuffer + (osdy+1) * aa_scrwidth(c),' ',strlen(posbar));
411 memset(c->attrbuffer + (osdy+1) * aa_scrwidth(c),0,strlen(posbar));
413 } else {
414 /* update osd */
415 aa_puts(c, osdx, osdy, AA_SPECIAL, osdmessagetext);
416 /* posbar? */
417 if (posbar[0]!='\0')
418 aa_puts(c, 0, osdy + 1, AA_SPECIAL, posbar);
421 /* OSD time & playmode , subtitles */
422 #ifdef USE_OSD
423 printosdtext();
424 #endif
427 /* print out */
428 aa_flush(c);
431 static void
432 check_events(void) {
434 * any events?
435 * called by show_image and mplayer
437 int key;
438 while ((key=aa_getevent(c,0))!=AA_NONE ){
439 if (key>255){
440 /* some conversations */
441 switch (key) {
442 case AA_UP:
443 mplayer_put_key(KEY_UP);
444 break;
445 case AA_DOWN:
446 mplayer_put_key(KEY_DOWN);
447 break;
448 case AA_LEFT:
449 mplayer_put_key(KEY_LEFT);
450 break;
451 case AA_RIGHT:
452 mplayer_put_key(KEY_RIGHT);
453 break;
454 case AA_ESC:
455 mplayer_put_key(KEY_ESC);
456 break;
457 case 65765:
458 mplayer_put_key(KEY_PAGE_UP);
459 break;
460 case 65766:
461 mplayer_put_key(KEY_PAGE_DOWN);
462 break;
463 default:
464 continue; /* aa lib special key */
465 break;
468 if (key=='a' || key=='A'){
469 aaconfigmode=!aaconfigmode;
470 osdmessage(MESSAGE_DURATION, 1, "aa config mode is now %s",
471 aaconfigmode==1 ? "on. use keys 5-7" : "off");
473 if (aaconfigmode==1) {
474 switch (key) {
475 /* AA image controls */
476 case '5':
477 fast=!fast;
478 osdmessage(MESSAGE_DURATION, 1, "Fast mode is now %s", fast==1 ? "on" : "off");
479 break;
480 case '6':
481 if (p->dither==AA_FLOYD_S){
482 p->dither=AA_NONE;
483 osdmessage(MESSAGE_DURATION, 1, "Dithering: Off");
484 }else if (p->dither==AA_NONE){
485 p->dither=AA_ERRORDISTRIB;
486 osdmessage(MESSAGE_DURATION, 1, "Dithering: Error Distribution");
487 }else if (p->dither==AA_ERRORDISTRIB){
488 p->dither=AA_FLOYD_S;
489 osdmessage(MESSAGE_DURATION, 1, "Dithering: Floyd Steinberg");
491 break;
492 case '7':
493 p->inversion=!p->inversion;
494 osdmessage(MESSAGE_DURATION, 1, "Invert mode is now %s",
495 p->inversion==1 ? "on" : "off");
496 break;
498 default :
499 /* nothing if we're interested in?
500 * the mplayer should handle it!
502 mplayer_put_key(key);
503 break;
505 }// aaconfigmode
506 else mplayer_put_key(key);
510 static void
511 uninit(void) {
513 * THE END
516 if (strstr(c->driver->name,"Curses") || strstr(c->driver->name,"Linux")){
517 freopen("/dev/tty", "w", stderr);
519 #ifdef USE_OSD
520 if(vo_font_save) {
521 free(vo_font->pic_a[0]->bmp);
522 free(vo_font->pic_a[0]);
523 free(vo_font->pic_b[0]->bmp);
524 free(vo_font->pic_b[0]);
525 free(vo_font);
526 vo_font = vo_font_save;
527 vo_font_save = NULL;
529 #endif
530 aa_close(c);
533 #ifdef USE_OSD
534 static void draw_alpha(int x,int y, int w,int h, unsigned char* src, unsigned char *srca, int stride){
535 int i,j;
536 for (i = 0; i < h; i++) {
537 for (j = 0; j < w; j++) {
538 if (src[i*stride+j] > 0) {
539 c->textbuffer[x + j + (y+i)*aa_scrwidth(c)] = src[i*stride+j];
540 c->attrbuffer[x + j + (y+i)*aa_scrwidth(c)] = aaopt_subcolor;
546 static void clear_alpha(int x0,int y0, int w,int h) {
547 int l;
549 for(l = 0 ; l < h ; l++) {
550 memset(c->textbuffer + (y0 + l) * aa_scrwidth(c) + x0,' ',w);
551 memset(c->attrbuffer + (y0 + l) * aa_scrwidth(c) + x0,0,w);
556 #endif
558 static void
559 draw_osd(void){
560 #ifdef USE_OSD
561 char * vo_osd_text_save;
562 int vo_osd_progbar_type_save;
564 printosdprogbar();
565 /* let vo_draw_text only write subtitle */
566 vo_osd_text_save=vo_osd_text; /* we have to save the osd_text */
567 vo_osd_text=NULL;
568 vo_osd_progbar_type_save=vo_osd_progbar_type;
569 vo_osd_progbar_type=-1;
570 vo_remove_text(aa_scrwidth(c), aa_scrheight(c),clear_alpha);
571 vo_draw_text(aa_scrwidth(c), aa_scrheight(c), draw_alpha);
572 vo_osd_text=vo_osd_text_save;
573 vo_osd_progbar_type=vo_osd_progbar_type_save;
574 #endif
578 getcolor(char * s){
579 int i;
580 char * rest;
581 if (s==NULL) return -1;
582 i=strtol(s, &rest, 10);
583 if ((rest==NULL || strlen(rest)==0) && i>=0 && i<=5) return i;
584 if (!strcasecmp(s, "normal")) return AA_NORMAL;
585 else if (!strcasecmp(s, "dim")) return AA_DIM;
586 else if (!strcasecmp(s, "bold")) return AA_BOLD;
587 else if (!strcasecmp(s, "boldfont")) return AA_BOLDFONT;
588 else if (!strcasecmp(s, "special")) return AA_SPECIAL;
589 else return -1;
592 static int parse_suboptions(const char *arg) {
593 char *pseudoargv[4], *osdcolor = NULL, *subcolor = NULL, **strings,
594 *helpmsg = NULL;
595 int pseudoargc, displayhelp = 0, *booleans;
596 opt_t extra_opts[] = {
597 {"osdcolor", OPT_ARG_MSTRZ, &osdcolor, NULL, 0},
598 {"subcolor", OPT_ARG_MSTRZ, &subcolor, NULL, 0},
599 {"help", OPT_ARG_BOOL, &displayhelp, NULL, 0} };
600 opt_t *subopts = NULL, *p;
601 char *strings_list[] = {"-driver", "-kbddriver", "-mousedriver", "-font",
602 "-width", "-height", "-minwidth", "-minheight", "-maxwidth",
603 "-maxheight", "-recwidth", "-recheight", "-bright", "-contrast",
604 "-gamma", "-dimmul", "-boldmul", "-random" };
605 char *booleans_list[] = {"-dim", "-bold", "-reverse", "-normal",
606 "-boldfont", "-inverse", "-extended", "-eight", "-dither",
607 "-floyd_steinberg", "-error_distribution"};
608 char *nobooleans_list[] = {"-nodim", "-nobold", "-noreverse", "-nonormal",
609 "-noboldfont", "-noinverse", "-noextended", "-noeight", "-nodither",
610 "-nofloyd_steinberg", "-noerror_distribution"};
611 const int nstrings = sizeof(strings_list) / sizeof(char*);
612 const int nbooleans = sizeof(booleans_list) / sizeof(int);
613 const int nextra_opts = sizeof(extra_opts) / sizeof(opt_t);
614 const int nsubopts = nstrings + nbooleans + nextra_opts;
615 int i, retval = 0;
617 subopts = calloc(nsubopts + 1, sizeof(opt_t));
618 strings = calloc(nstrings, sizeof(char*));
619 booleans = calloc(nbooleans, sizeof(int));
621 p = subopts;
622 for (i=0; i<nstrings; i++, p++) {
623 p->name = strings_list[i] + 1; // skip '-'
624 p->type = OPT_ARG_MSTRZ;
625 p->valp = &strings[i];
627 for (i=0; i<nbooleans; i++, p++) {
628 p->name = booleans_list[i] + 1;
629 p->type = OPT_ARG_BOOL;
630 p->valp = &booleans[i];
632 memcpy(p, extra_opts, sizeof(extra_opts));
634 retval = subopt_parse(arg, subopts);
636 if (retval == 0 && displayhelp) {
637 helpmsg = strdup(aa_help);
638 for (i=0; i<(signed)strlen(helpmsg); i++)
639 if (helpmsg[i] == '-') helpmsg[i] = ' ';
640 mp_msg(MSGT_VO, MSGL_INFO, MSGTR_VO_AA_HelpHeader);
641 mp_msg(MSGT_VO, MSGL_INFO, "%s\n\n", helpmsg);
642 mp_msg(MSGT_VO, MSGL_INFO, MSGTR_VO_AA_AdditionalOptions);
643 retval = -1;
645 if (retval == 0) {
646 pseudoargv[3] = NULL;
647 for (i=0; i<nstrings; i++) {
648 pseudoargc = 3; // inside loop because aalib changes it
649 if (strings[i] != NULL) {
650 pseudoargv[1] = strings_list[i];
651 pseudoargv[2] = strings[i];
652 aa_parseoptions(&aa_defparams, &aa_defrenderparams,
653 &pseudoargc, pseudoargv) != 1;
656 pseudoargv[2] = NULL;
657 for (i=0; i<nbooleans; i++) {
658 pseudoargc = 2;
659 if (booleans[i]) pseudoargv[1] = booleans_list[i];
660 else pseudoargv[1] = nobooleans_list[i];
661 aa_parseoptions(&aa_defparams, &aa_defrenderparams,
662 &pseudoargc, pseudoargv) != 1;
664 if (osdcolor) aaopt_osdcolor = getcolor(osdcolor);
665 if (subcolor) aaopt_subcolor = getcolor(subcolor);
668 if (subopts) free(subopts);
669 if (booleans) free(booleans);
670 if (strings) {
671 for (i=0; i<nstrings; i++)
672 if (strings[i])
673 free(strings[i]);
674 free(strings);
676 if (osdcolor) free(osdcolor);
677 if (subcolor) free(subcolor);
678 if (helpmsg) free(helpmsg);
679 return retval;
682 static int preinit(const char *arg)
684 char * hidis = NULL;
685 struct stat sbuf;
686 int fd, vt, major, minor;
687 FILE * fp;
688 char fname[12];
689 extern aa_linkedlist *aa_displayrecommended;
691 if(arg)
693 if (parse_suboptions(arg) != 0)
694 return ENOSYS;
697 /* initializing of aalib */
699 hidis=aa_getfirst(&aa_displayrecommended);
700 if ( hidis==NULL ){
701 /* check /dev/vcsa<vt> */
702 /* check only, if no driver is explicit set */
703 fd = dup (fileno (stderr));
704 fstat (fd, &sbuf);
705 major = sbuf.st_rdev >> 8;
706 vt = minor = sbuf.st_rdev & 0xff;
707 close (fd);
708 sprintf (fname, "/dev/vcsa%2.2i", vt);
709 fp = fopen (fname, "w+");
710 if (fp==NULL){
711 fprintf(stderr,"VO: [aa] cannot open %s for writing,"
712 "so we'll not use linux driver\n", fname);
713 aa_recommendlowdisplay("linux");
714 aa_recommendhidisplay("curses");
715 aa_recommendhidisplay("X11");
716 }else fclose(fp);
717 } else aa_recommendhidisplay(hidis);
718 c = aa_autoinit(&aa_defparams);
720 if (c == NULL) {
721 mp_msg(MSGT_VO,MSGL_ERR,"Cannot initialize aalib\n");
722 return VO_ERROR;
724 if (!aa_autoinitkbd(c,0)) {
725 mp_msg(MSGT_VO,MSGL_ERR,"Cannot initialize keyboard\n");
726 aa_close(c);
727 return VO_ERROR;
730 aa_resizehandler(c, (void *)resize);
731 aa_hidecursor(c);
732 p = aa_getrenderparams();
734 if ((strstr(c->driver->name,"Curses")) || (strstr(c->driver->name,"Linux"))){
735 freopen("/dev/null", "w", stderr);
736 /* disable console blanking */
737 printf("\033[9;0]");
740 memset(image,0,3*sizeof(uint8_t));
741 osdmessagetext[0] = '\0';
742 osdx = osdy = 0;
744 return 0;
747 static int control(uint32_t request, void *data, ...)
749 switch (request) {
750 case VOCTRL_QUERY_FORMAT:
751 return query_format(*((uint32_t*)data));
752 case VOCTRL_SET_EQUALIZER: {
753 va_list ap;
754 int val;
756 va_start(ap, data);
757 val = va_arg(ap, int);
758 va_end(ap);
760 if(strcmp((char*)data,"contrast") == 0)
761 p->contrast = ( val + 100 ) * 64 / 100;
762 else if(strcmp((char*)data,"brightness") == 0)
763 p->bright = ( val + 100) * 128 / 100;
764 return VO_TRUE;
766 case VOCTRL_GET_EQUALIZER: {
767 va_list ap;
768 int* val;
770 va_start(ap, data);
771 val = va_arg(ap, int*);
772 va_end(ap);
774 if(strcmp((char*)data,"contrast") == 0)
775 *val = (p->contrast - 64) * 100 / 64;
776 else if(strcmp((char*)data,"brightness") == 0)
777 *val = (p->bright - 128) * 100 / 128;
779 return VO_TRUE;
782 return VO_NOTIMPL;