Remove several useless casts from af_resample
[mplayer/glamo.git] / libvo / vo_aa.c
blob5046a8b9ecc3cfb20b35ecfcd6b1694c64bc741f
1 /*
2 * video output driver for AAlib
4 * copyright (c) 2001 Folke Ashberg <folke@ashberg.de>
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <stdio.h>
24 #include <stdlib.h>
26 #include <sys/stat.h>
27 #include <unistd.h>
29 #include <limits.h>
30 #include <math.h>
31 #include <stdarg.h>
32 #include <time.h>
33 #include <string.h>
34 #include <errno.h>
36 #include "config.h"
37 #include "video_out.h"
38 #include "video_out_internal.h"
39 #include "aspect.h"
40 #include "libswscale/swscale.h"
41 #include "libmpcodecs/vf_scale.h"
42 #include "font_load.h"
43 #include "sub.h"
45 #include "osdep/keycodes.h"
46 #include <aalib.h>
47 #include "subopt-helper.h"
48 #include "help_mp.h"
49 #include "mp_msg.h"
50 #include "mp_fifo.h"
53 #define MESSAGE_DURATION 3
54 #define MESSAGE_SIZE 512
55 #define MESSAGE_DEKO " +++ %s +++ "
57 static const vo_info_t info = {
58 "AAlib",
59 "aa",
60 "Alban Bedel <albeu@free.fr> and Folke Ashberg <folke@ashberg.de>",
64 const LIBVO_EXTERN(aa)
66 /* aa's main context we use */
67 aa_context *c;
68 aa_renderparams *p;
69 static int fast =0;
70 /* used for the sws */
71 static uint8_t * image[3];
72 static int image_stride[3];
74 /* image infos */
75 static int image_format;
76 static int image_width;
77 static int image_height;
78 static int image_x, image_y;
79 static int screen_x, screen_y;
80 static int screen_w, screen_h;
81 static int src_width;
82 static int src_height;
84 /* osd stuff */
85 time_t stoposd = 0;
86 static int showosdmessage = 0;
87 char osdmessagetext[MESSAGE_SIZE];
88 char posbar[MESSAGE_SIZE];
89 static int osdx, osdy;
90 static int osd_text_length = 0;
91 int aaconfigmode=1;
92 font_desc_t* vo_font_save = NULL;
93 static struct SwsContext *sws=NULL;
95 /* configuration */
96 int aaopt_osdcolor = AA_SPECIAL;
97 int aaopt_subcolor = AA_SPECIAL;
99 void
100 resize(void){
102 * this function is called by aa lib if windows resizes
103 * further during init, because here we have to calculate
104 * a little bit
107 aa_resize(c);
109 aspect_save_screenres(aa_imgwidth(c),aa_imgheight(c));
110 image_height = aa_imgheight(c); //src_height;
111 image_width = aa_imgwidth(c); //src_width;
113 aspect(&image_width,&image_height,A_ZOOM);
115 image_x = (aa_imgwidth(c) - image_width) / 2;
116 image_y = (aa_imgheight(c) - image_height) / 2;
117 screen_w = image_width * aa_scrwidth(c) / aa_imgwidth(c);
118 screen_h = image_height * aa_scrheight(c) / aa_imgheight(c);
119 screen_x = (aa_scrwidth(c) - screen_w) / 2;
120 screen_y = (aa_scrheight(c) - screen_h) / 2;
122 if(sws) sws_freeContext(sws);
123 sws = sws_getContextFromCmdLine(src_width,src_height,image_format,
124 image_width,image_height,IMGFMT_Y8);
126 image[0] = aa_image(c) + image_y * aa_imgwidth(c) + image_x;
127 image[1] = NULL;
128 image[2] = NULL;
130 image_stride[0] = aa_imgwidth(c);
131 image_stride[1] = 0;
132 image_stride[2] = 0;
134 showosdmessage=0;
138 static void
139 osdmessage(int duration, int deko, const char *fmt, ...)
142 * for outputting a centered string at the bottom
143 * of our window for a while
145 va_list ar;
146 char m[MESSAGE_SIZE];
147 unsigned int old_len = strlen(osdmessagetext);
149 va_start(ar, fmt);
150 vsprintf(m, fmt, ar);
151 va_end(ar);
152 if (deko==1) sprintf(osdmessagetext, MESSAGE_DEKO , m);
153 else strcpy(osdmessagetext, m);
155 if(old_len > strlen(osdmessagetext)) {
156 memset(c->textbuffer + osdy * aa_scrwidth(c) + osdx,' ',old_len);
157 memset(c->attrbuffer + osdy * aa_scrwidth(c) + osdx,0,old_len);
159 showosdmessage=1;
160 stoposd = time(NULL) + duration;
161 osdx=(aa_scrwidth(c) / 2) - (strlen(osdmessagetext) / 2 ) ;
162 posbar[0]='\0';
165 static void
166 osdpercent(int duration, int deko, int min, int max, int val, const char * desc, const char * unit)
169 * prints a bar for setting values
171 float step;
172 int where;
173 int i;
176 step=(float)aa_scrwidth(c) /(float)(max-min);
177 where=(val-min)*step;
178 osdmessage(duration,deko,"%s: %i%s",desc, val, unit);
179 posbar[0]='|';
180 posbar[aa_scrwidth(c)-1]='|';
181 for (i=0;i<aa_scrwidth(c);i++){
182 if (i==where) posbar[i]='#';
183 else posbar[i]='-';
185 if (where!=0) posbar[0]='|';
186 if (where!=(aa_scrwidth(c)-1) ) posbar[aa_scrwidth(c)-1]='|';
188 posbar[aa_scrwidth(c)]='\0';
192 static void
193 printosdtext(void)
195 if(osd_text_length > 0 && !vo_osd_text) {
196 memset(c->textbuffer,' ',osd_text_length);
197 memset(c->attrbuffer,0,osd_text_length);
198 osd_text_length = 0;
201 * places the mplayer status osd
203 if (vo_osd_text && vo_osd_text[0] != 0) {
204 int len;
205 if(vo_osd_text[0] < 32) {
206 len = strlen(sub_osd_names_short[vo_osd_text[0]]) + strlen(vo_osd_text+1) + 2;
207 aa_printf(c, 0, 0 , aaopt_osdcolor, "%s %s ", sub_osd_names_short[vo_osd_text[0]], vo_osd_text+1);
208 } else {
209 len = strlen(vo_osd_text) + 1;
210 aa_printf(c, 0, 0 , aaopt_osdcolor, "%s ",vo_osd_text);
213 if(len < osd_text_length) {
214 memset(c->textbuffer + len,' ',osd_text_length - len);
215 memset(c->attrbuffer + len,0,osd_text_length - len);
217 osd_text_length = len;
222 static void
223 printosdprogbar(void){
224 /* print mplayer osd-progbar */
225 if (vo_osd_progbar_type!=-1){
226 osdpercent(1,1,0,255,vo_osd_progbar_value, sub_osd_names[vo_osd_progbar_type], "");
229 static int
230 config(uint32_t width, uint32_t height, uint32_t d_width,
231 uint32_t d_height, uint32_t flags, char *title,
232 uint32_t format) {
234 * main init
235 * called by mplayer
238 int i;
240 aspect_save_orig(width,height);
241 aspect_save_prescale(d_width,d_height);
243 src_height = height;
244 src_width = width;
245 image_format = format;
247 /* nothing will change its size, be we need some values initialized */
248 resize();
250 /* now init our own 'font' */
251 if(!vo_font_save) vo_font_save = vo_font;
252 if(vo_font == vo_font_save) {
253 vo_font=malloc(sizeof(font_desc_t));//if(!desc) return NULL;
254 memset(vo_font,0,sizeof(font_desc_t));
255 vo_font->pic_a[0]=malloc(sizeof(raw_file));
256 memset(vo_font->pic_a[0],0,sizeof(raw_file));
257 vo_font->pic_b[0]=malloc(sizeof(raw_file));
258 memset(vo_font->pic_b[0],0,sizeof(raw_file));
260 #ifdef CONFIG_FREETYPE
261 vo_font->dynamic = 0;
262 #endif
264 vo_font->spacewidth=1;
265 vo_font->charspace=0;
266 vo_font->height=1;
267 vo_font->pic_a[0]->bmp=malloc(255);
268 vo_font->pic_a[0]->pal=NULL;
269 vo_font->pic_b[0]->bmp=malloc(255);
270 vo_font->pic_b[0]->pal=NULL;
271 vo_font->pic_a[0]->w=1;
272 vo_font->pic_a[0]->h=1;
273 for (i=0; i<255; i++){
274 vo_font->width[i]=1;
275 vo_font->font[i]=0;
276 vo_font->start[i]=i;
277 vo_font->pic_a[0]->bmp[i]=i;
278 vo_font->pic_b[0]->bmp[i]=i;
282 /* say hello */
283 osdmessage(5, 1, "Welcome to ASCII ART MPlayer");
285 mp_msg(MSGT_VO,MSGL_V,"VO: [aa] screendriver: %s\n", c->driver->name);
286 mp_msg(MSGT_VO,MSGL_V,"VO: [aa] keyboarddriver: %s\n", c->kbddriver->name);
288 mp_msg(MSGT_VO,MSGL_INFO,
289 "\n"
290 "Important suboptions\n"
291 "\textended use use all 256 characters\n"
292 "\teight use eight bit ascii\n"
293 "\tdriver set recommended aalib driver (X11,curses,linux)\n"
294 "\thelp to see all options provided by aalib\n"
295 "\n"
296 "AA-MPlayer Keys\n"
297 "\t1 : contrast -\n"
298 "\t2 : contrast +\n"
299 "\t3 : brightness -\n"
300 "\t4 : brightness +\n"
301 "\t5 : fast rendering\n"
302 "\t6 : dithering\n"
303 "\t7 : invert image\n"
304 "\ta : toggles between aa and mplayer control\n"
306 "\n"
307 "All other keys are MPlayer defaults.\n"
312 return 0;
315 static int
316 query_format(uint32_t format) {
318 * ...are we able to... ?
319 * called by mplayer
320 * All input format supported by the sws
322 switch(format){
323 case IMGFMT_YV12:
324 case IMGFMT_I420:
325 case IMGFMT_IYUV:
326 case IMGFMT_IYU2:
327 case IMGFMT_BGR32:
328 case IMGFMT_BGR24:
329 case IMGFMT_BGR16:
330 case IMGFMT_BGR15:
331 case IMGFMT_RGB32:
332 case IMGFMT_RGB24:
333 case IMGFMT_Y8:
334 case IMGFMT_Y800:
335 return VFCAP_CSP_SUPPORTED | VFCAP_SWSCALE | VFCAP_OSD;
337 return 0;
340 static int
341 draw_frame(uint8_t *src[]) {
342 int stride[3] = { 0 , 0 , 0 };
344 switch(image_format) {
345 case IMGFMT_BGR15:
346 case IMGFMT_BGR16:
347 stride[0] = src_width*2;
348 break;
349 case IMGFMT_IYU2:
350 case IMGFMT_BGR24:
351 stride[0] = src_width*3;
352 break;
353 case IMGFMT_BGR32:
354 stride[0] = src_width*4;
355 break;
358 sws_scale_ordered(sws,src,stride,0,src_height,image,image_stride);
360 /* Now 'ASCIInate' the image */
361 if (fast)
362 aa_fastrender(c, screen_x, screen_y, screen_w + screen_x, screen_h + screen_y );
363 else
364 aa_render(c, p,screen_x, screen_y, screen_w + screen_x, screen_h + screen_y );
366 return 0;
369 static int
370 draw_slice(uint8_t *src[], int stride[],
371 int w, int h, int x, int y) {
373 int dx1 = screen_x + (x * screen_w / src_width);
374 int dy1 = screen_y + (y * screen_h / src_height);
375 int dx2 = screen_x + ((x+w) * screen_w / src_width);
376 int dy2 = screen_y + ((y+h) * screen_h / src_height);
378 sws_scale_ordered(sws,src,stride,y,h,image,image_stride);
380 /* Now 'ASCIInate' the image */
381 if (fast)
382 aa_fastrender(c, dx1, dy1, dx2, dy2 );
383 else
384 aa_render(c, p,dx1, dy1, dx2, dy2 );
387 return 0;
390 static void
391 flip_page(void) {
393 /* do we have to put *our* (messages, progbar) osd to aa's txtbuf ? */
394 if (showosdmessage)
396 if (time(NULL)>=stoposd ) {
397 showosdmessage=0;
398 if(*osdmessagetext) {
399 memset(c->textbuffer + osdy * aa_scrwidth(c) + osdx,' ',strlen(osdmessagetext));
400 memset(c->attrbuffer + osdy * aa_scrwidth(c) + osdx ,0,strlen(osdmessagetext));
401 osdmessagetext[0] = '\0';
403 if(*posbar) {
404 memset(c->textbuffer + (osdy+1) * aa_scrwidth(c),' ',strlen(posbar));
405 memset(c->attrbuffer + (osdy+1) * aa_scrwidth(c),0,strlen(posbar));
407 } else {
408 /* update osd */
409 aa_puts(c, osdx, osdy, AA_SPECIAL, osdmessagetext);
410 /* posbar? */
411 if (posbar[0]!='\0')
412 aa_puts(c, 0, osdy + 1, AA_SPECIAL, posbar);
415 /* OSD time & playmode , subtitles */
416 printosdtext();
419 /* print out */
420 aa_flush(c);
423 static void
424 check_events(void) {
426 * any events?
427 * called by show_image and mplayer
429 int key;
430 while ((key=aa_getevent(c,0))!=AA_NONE ){
431 if (key>255){
432 /* some conversations */
433 switch (key) {
434 case AA_UP:
435 mplayer_put_key(KEY_UP);
436 break;
437 case AA_DOWN:
438 mplayer_put_key(KEY_DOWN);
439 break;
440 case AA_LEFT:
441 mplayer_put_key(KEY_LEFT);
442 break;
443 case AA_RIGHT:
444 mplayer_put_key(KEY_RIGHT);
445 break;
446 case AA_ESC:
447 mplayer_put_key(KEY_ESC);
448 break;
449 case 65765:
450 mplayer_put_key(KEY_PAGE_UP);
451 break;
452 case 65766:
453 mplayer_put_key(KEY_PAGE_DOWN);
454 break;
455 default:
456 continue; /* aa lib special key */
457 break;
460 if (key=='a' || key=='A'){
461 aaconfigmode=!aaconfigmode;
462 osdmessage(MESSAGE_DURATION, 1, "aa config mode is now %s",
463 aaconfigmode==1 ? "on. use keys 5-7" : "off");
465 if (aaconfigmode==1) {
466 switch (key) {
467 /* AA image controls */
468 case '5':
469 fast=!fast;
470 osdmessage(MESSAGE_DURATION, 1, "Fast mode is now %s", fast==1 ? "on" : "off");
471 break;
472 case '6':
473 if (p->dither==AA_FLOYD_S){
474 p->dither=AA_NONE;
475 osdmessage(MESSAGE_DURATION, 1, "Dithering: Off");
476 }else if (p->dither==AA_NONE){
477 p->dither=AA_ERRORDISTRIB;
478 osdmessage(MESSAGE_DURATION, 1, "Dithering: Error Distribution");
479 }else if (p->dither==AA_ERRORDISTRIB){
480 p->dither=AA_FLOYD_S;
481 osdmessage(MESSAGE_DURATION, 1, "Dithering: Floyd Steinberg");
483 break;
484 case '7':
485 p->inversion=!p->inversion;
486 osdmessage(MESSAGE_DURATION, 1, "Invert mode is now %s",
487 p->inversion==1 ? "on" : "off");
488 break;
490 default :
491 /* nothing if we're interested in?
492 * the mplayer should handle it!
494 mplayer_put_key(key);
495 break;
497 }// aaconfigmode
498 else mplayer_put_key(key);
502 static void
503 uninit(void) {
505 * THE END
508 if (strstr(c->driver->name,"Curses") || strstr(c->driver->name,"Linux")){
509 freopen("/dev/tty", "w", stderr);
511 if(vo_font_save) {
512 free(vo_font->pic_a[0]->bmp);
513 free(vo_font->pic_a[0]);
514 free(vo_font->pic_b[0]->bmp);
515 free(vo_font->pic_b[0]);
516 free(vo_font);
517 vo_font = vo_font_save;
518 vo_font_save = NULL;
520 aa_close(c);
523 static void draw_alpha(int x,int y, int w,int h, unsigned char* src, unsigned char *srca, int stride){
524 int i,j;
525 for (i = 0; i < h; i++) {
526 for (j = 0; j < w; j++) {
527 if (src[i*stride+j] > 0) {
528 c->textbuffer[x + j + (y+i)*aa_scrwidth(c)] = src[i*stride+j];
529 c->attrbuffer[x + j + (y+i)*aa_scrwidth(c)] = aaopt_subcolor;
535 static void clear_alpha(int x0,int y0, int w,int h) {
536 int l;
538 for(l = 0 ; l < h ; l++) {
539 memset(c->textbuffer + (y0 + l) * aa_scrwidth(c) + x0,' ',w);
540 memset(c->attrbuffer + (y0 + l) * aa_scrwidth(c) + x0,0,w);
545 static void
546 draw_osd(void){
547 char * vo_osd_text_save;
548 int vo_osd_progbar_type_save;
550 printosdprogbar();
551 /* let vo_draw_text only write subtitle */
552 vo_osd_text_save=vo_osd_text; /* we have to save the osd_text */
553 vo_osd_text=NULL;
554 vo_osd_progbar_type_save=vo_osd_progbar_type;
555 vo_osd_progbar_type=-1;
556 vo_remove_text(aa_scrwidth(c), aa_scrheight(c),clear_alpha);
557 vo_draw_text(aa_scrwidth(c), aa_scrheight(c), draw_alpha);
558 vo_osd_text=vo_osd_text_save;
559 vo_osd_progbar_type=vo_osd_progbar_type_save;
562 static int
563 getcolor(char * s){
564 int i;
565 char * rest;
566 if (s==NULL) return -1;
567 i=strtol(s, &rest, 10);
568 if ((rest==NULL || strlen(rest)==0) && i>=0 && i<=5) return i;
569 if (!strcasecmp(s, "normal")) return AA_NORMAL;
570 else if (!strcasecmp(s, "dim")) return AA_DIM;
571 else if (!strcasecmp(s, "bold")) return AA_BOLD;
572 else if (!strcasecmp(s, "boldfont")) return AA_BOLDFONT;
573 else if (!strcasecmp(s, "special")) return AA_SPECIAL;
574 else return -1;
577 static int parse_suboptions(const char *arg) {
578 char *pseudoargv[4], *osdcolor = NULL, *subcolor = NULL, **strings,
579 *helpmsg = NULL;
580 int pseudoargc, displayhelp = 0, *booleans;
581 opt_t extra_opts[] = {
582 {"osdcolor", OPT_ARG_MSTRZ, &osdcolor, NULL, 0},
583 {"subcolor", OPT_ARG_MSTRZ, &subcolor, NULL, 0},
584 {"help", OPT_ARG_BOOL, &displayhelp, NULL, 0} };
585 opt_t *subopts = NULL, *p;
586 char *strings_list[] = {"-driver", "-kbddriver", "-mousedriver", "-font",
587 "-width", "-height", "-minwidth", "-minheight", "-maxwidth",
588 "-maxheight", "-recwidth", "-recheight", "-bright", "-contrast",
589 "-gamma", "-dimmul", "-boldmul", "-random" };
590 char *booleans_list[] = {"-dim", "-bold", "-reverse", "-normal",
591 "-boldfont", "-inverse", "-extended", "-eight", "-dither",
592 "-floyd_steinberg", "-error_distribution"};
593 char *nobooleans_list[] = {"-nodim", "-nobold", "-noreverse", "-nonormal",
594 "-noboldfont", "-noinverse", "-noextended", "-noeight", "-nodither",
595 "-nofloyd_steinberg", "-noerror_distribution"};
596 const int nstrings = sizeof(strings_list) / sizeof(char*);
597 const int nbooleans = sizeof(booleans_list) / sizeof(char*);
598 const int nextra_opts = sizeof(extra_opts) / sizeof(opt_t);
599 const int nsubopts = nstrings + nbooleans + nextra_opts;
600 int i, retval = 0;
602 subopts = calloc(nsubopts + 1, sizeof(opt_t));
603 strings = calloc(nstrings, sizeof(char*));
604 booleans = calloc(nbooleans, sizeof(int));
606 p = subopts;
607 for (i=0; i<nstrings; i++, p++) {
608 p->name = strings_list[i] + 1; // skip '-'
609 p->type = OPT_ARG_MSTRZ;
610 p->valp = &strings[i];
612 for (i=0; i<nbooleans; i++, p++) {
613 p->name = booleans_list[i] + 1;
614 p->type = OPT_ARG_BOOL;
615 p->valp = &booleans[i];
617 memcpy(p, extra_opts, sizeof(extra_opts));
619 retval = subopt_parse(arg, subopts);
621 if (retval == 0 && displayhelp) {
622 helpmsg = strdup(aa_help);
623 for (i=0; i<(signed)strlen(helpmsg); i++)
624 if (helpmsg[i] == '-') helpmsg[i] = ' ';
625 mp_msg(MSGT_VO, MSGL_INFO, MSGTR_VO_AA_HelpHeader);
626 mp_msg(MSGT_VO, MSGL_INFO, "%s\n\n", helpmsg);
627 mp_msg(MSGT_VO, MSGL_INFO, MSGTR_VO_AA_AdditionalOptions);
628 retval = -1;
630 if (retval == 0) {
631 pseudoargv[3] = NULL;
632 for (i=0; i<nstrings; i++) {
633 pseudoargc = 3; // inside loop because aalib changes it
634 if (strings[i] != NULL) {
635 pseudoargv[1] = strings_list[i];
636 pseudoargv[2] = strings[i];
637 aa_parseoptions(&aa_defparams, &aa_defrenderparams,
638 &pseudoargc, pseudoargv);
641 pseudoargv[2] = NULL;
642 for (i=0; i<nbooleans; i++) {
643 pseudoargc = 2;
644 if (booleans[i]) pseudoargv[1] = booleans_list[i];
645 else pseudoargv[1] = nobooleans_list[i];
646 aa_parseoptions(&aa_defparams, &aa_defrenderparams,
647 &pseudoargc, pseudoargv);
649 if (osdcolor) aaopt_osdcolor = getcolor(osdcolor);
650 if (subcolor) aaopt_subcolor = getcolor(subcolor);
653 if (subopts) free(subopts);
654 if (booleans) free(booleans);
655 if (strings) {
656 for (i=0; i<nstrings; i++)
657 if (strings[i])
658 free(strings[i]);
659 free(strings);
661 if (osdcolor) free(osdcolor);
662 if (subcolor) free(subcolor);
663 if (helpmsg) free(helpmsg);
664 return retval;
667 static int preinit(const char *arg)
669 char * hidis = NULL;
670 struct stat sbuf;
671 int fd, vt, major, minor;
672 FILE * fp;
673 char fname[12];
675 if(arg)
677 if (parse_suboptions(arg) != 0)
678 return ENOSYS;
681 /* initializing of aalib */
683 hidis=aa_getfirst(&aa_displayrecommended);
684 if ( hidis==NULL ){
685 /* check /dev/vcsa<vt> */
686 /* check only, if no driver is explicit set */
687 fd = dup (fileno (stderr));
688 fstat (fd, &sbuf);
689 major = sbuf.st_rdev >> 8;
690 vt = minor = sbuf.st_rdev & 0xff;
691 close (fd);
692 sprintf (fname, "/dev/vcsa%2.2i", vt);
693 fp = fopen (fname, "w+");
694 if (fp==NULL){
695 fprintf(stderr,"VO: [aa] cannot open %s for writing,"
696 "so we'll not use linux driver\n", fname);
697 aa_recommendlowdisplay("linux");
698 aa_recommendhidisplay("curses");
699 aa_recommendhidisplay("X11");
700 }else fclose(fp);
701 } else aa_recommendhidisplay(hidis);
702 c = aa_autoinit(&aa_defparams);
704 if (c == NULL) {
705 mp_msg(MSGT_VO,MSGL_ERR,"Cannot initialize aalib\n");
706 return VO_ERROR;
708 if (!aa_autoinitkbd(c,0)) {
709 mp_msg(MSGT_VO,MSGL_ERR,"Cannot initialize keyboard\n");
710 aa_close(c);
711 return VO_ERROR;
714 aa_resizehandler(c, (void *)resize);
715 aa_hidecursor(c);
716 p = aa_getrenderparams();
718 if ((strstr(c->driver->name,"Curses")) || (strstr(c->driver->name,"Linux"))){
719 freopen("/dev/null", "w", stderr);
720 /* disable console blanking */
721 printf("\033[9;0]");
724 memset(image,0,3*sizeof(uint8_t));
725 osdmessagetext[0] = '\0';
726 osdx = osdy = 0;
728 return 0;
731 static int control(uint32_t request, void *data, ...)
733 switch (request) {
734 case VOCTRL_QUERY_FORMAT:
735 return query_format(*((uint32_t*)data));
736 case VOCTRL_SET_EQUALIZER: {
737 va_list ap;
738 int val;
740 va_start(ap, data);
741 val = va_arg(ap, int);
742 va_end(ap);
744 if(strcmp((char*)data,"contrast") == 0)
745 p->contrast = ( val + 100 ) * 64 / 100;
746 else if(strcmp((char*)data,"brightness") == 0)
747 p->bright = ( val + 100) * 128 / 100;
748 return VO_TRUE;
750 case VOCTRL_GET_EQUALIZER: {
751 va_list ap;
752 int* val;
754 va_start(ap, data);
755 val = va_arg(ap, int*);
756 va_end(ap);
758 if(strcmp((char*)data,"contrast") == 0)
759 *val = (p->contrast - 64) * 100 / 64;
760 else if(strcmp((char*)data,"brightness") == 0)
761 *val = (p->bright - 128) * 100 / 128;
763 return VO_TRUE;
766 return VO_NOTIMPL;