Merge svn changes up to r30165
[mplayer/glamo.git] / libvo / vo_aa.c
blob5e9dfbae10de79b1696d2690f9afb4c269e433fc
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[MP_MAX_PLANES];
72 static int image_stride[MP_MAX_PLANES];
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 static unsigned char vo_osd_text[64];
101 static void
102 resize(void){
104 * this function is called by aa lib if windows resizes
105 * further during init, because here we have to calculate
106 * a little bit
109 aa_resize(c);
111 aspect_save_screenres(aa_imgwidth(c),aa_imgheight(c));
112 image_height = aa_imgheight(c); //src_height;
113 image_width = aa_imgwidth(c); //src_width;
115 aspect(&image_width,&image_height,A_ZOOM);
117 image_x = (aa_imgwidth(c) - image_width) / 2;
118 image_y = (aa_imgheight(c) - image_height) / 2;
119 screen_w = image_width * aa_scrwidth(c) / aa_imgwidth(c);
120 screen_h = image_height * aa_scrheight(c) / aa_imgheight(c);
121 screen_x = (aa_scrwidth(c) - screen_w) / 2;
122 screen_y = (aa_scrheight(c) - screen_h) / 2;
124 if(sws) sws_freeContext(sws);
125 sws = sws_getContextFromCmdLine(src_width,src_height,image_format,
126 image_width,image_height,IMGFMT_Y8);
128 memset(image, 0, sizeof(image));
129 image[0] = aa_image(c) + image_y * aa_imgwidth(c) + image_x;
131 memset(image_stride, 0, sizeof(image_stride));
132 image_stride[0] = aa_imgwidth(c);
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)
196 * places the mplayer status osd
198 if (vo_osd_text[0] != 0) {
199 int len;
200 if(vo_osd_text[0] < 32) {
201 len = strlen(sub_osd_names_short[vo_osd_text[0]]) + strlen(vo_osd_text+1) + 2;
202 aa_printf(c, 0, 0 , aaopt_osdcolor, "%s %s ", sub_osd_names_short[vo_osd_text[0]], vo_osd_text+1);
203 } else {
204 len = strlen(vo_osd_text) + 1;
205 aa_printf(c, 0, 0 , aaopt_osdcolor, "%s ",vo_osd_text);
208 if(len < osd_text_length) {
209 memset(c->textbuffer + len,' ',osd_text_length - len);
210 memset(c->attrbuffer + len,0,osd_text_length - len);
212 osd_text_length = len;
217 static void
218 printosdprogbar(void){
219 /* print mplayer osd-progbar */
220 if (vo_osd_progbar_type!=-1){
221 osdpercent(1,1,0,255,vo_osd_progbar_value, sub_osd_names[vo_osd_progbar_type], "");
224 static int
225 config(uint32_t width, uint32_t height, uint32_t d_width,
226 uint32_t d_height, uint32_t flags, char *title,
227 uint32_t format) {
229 * main init
230 * called by mplayer
233 int i;
235 aspect_save_orig(width,height);
236 aspect_save_prescale(d_width,d_height);
238 src_height = height;
239 src_width = width;
240 image_format = format;
242 /* nothing will change its size, be we need some values initialized */
243 resize();
245 /* now init our own 'font' */
246 if(!vo_font_save) vo_font_save = vo_font;
247 if(vo_font == vo_font_save) {
248 vo_font=malloc(sizeof(font_desc_t));//if(!desc) return NULL;
249 memset(vo_font,0,sizeof(font_desc_t));
250 vo_font->pic_a[0]=malloc(sizeof(raw_file));
251 memset(vo_font->pic_a[0],0,sizeof(raw_file));
252 vo_font->pic_b[0]=malloc(sizeof(raw_file));
253 memset(vo_font->pic_b[0],0,sizeof(raw_file));
255 #ifdef CONFIG_FREETYPE
256 vo_font->dynamic = 0;
257 #endif
259 vo_font->spacewidth=1;
260 vo_font->charspace=0;
261 vo_font->height=1;
262 vo_font->pic_a[0]->bmp=malloc(255);
263 vo_font->pic_a[0]->pal=NULL;
264 vo_font->pic_b[0]->bmp=malloc(255);
265 vo_font->pic_b[0]->pal=NULL;
266 vo_font->pic_a[0]->w=1;
267 vo_font->pic_a[0]->h=1;
268 for (i=0; i<255; i++){
269 vo_font->width[i]=1;
270 vo_font->font[i]=0;
271 vo_font->start[i]=i;
272 vo_font->pic_a[0]->bmp[i]=i;
273 vo_font->pic_b[0]->bmp[i]=i;
277 /* say hello */
278 osdmessage(5, 1, "Welcome to ASCII ART MPlayer");
280 mp_msg(MSGT_VO,MSGL_V,"VO: [aa] screendriver: %s\n", c->driver->name);
281 mp_msg(MSGT_VO,MSGL_V,"VO: [aa] keyboarddriver: %s\n", c->kbddriver->name);
283 mp_msg(MSGT_VO,MSGL_INFO,
284 "\n"
285 "Important suboptions\n"
286 "\textended use use all 256 characters\n"
287 "\teight use eight bit ascii\n"
288 "\tdriver set recommended aalib driver (X11,curses,linux)\n"
289 "\thelp to see all options provided by aalib\n"
290 "\n"
291 "AA-MPlayer Keys\n"
292 "\t1 : contrast -\n"
293 "\t2 : contrast +\n"
294 "\t3 : brightness -\n"
295 "\t4 : brightness +\n"
296 "\t5 : fast rendering\n"
297 "\t6 : dithering\n"
298 "\t7 : invert image\n"
299 "\ta : toggles between aa and mplayer control\n"
301 "\n"
302 "All other keys are MPlayer defaults.\n"
307 return 0;
310 static int
311 query_format(uint32_t format) {
313 * ...are we able to... ?
314 * called by mplayer
315 * All input format supported by the sws
317 switch(format){
318 case IMGFMT_YV12:
319 case IMGFMT_I420:
320 case IMGFMT_IYUV:
321 case IMGFMT_IYU2:
322 case IMGFMT_BGR32:
323 case IMGFMT_BGR24:
324 case IMGFMT_BGR16:
325 case IMGFMT_BGR15:
326 case IMGFMT_RGB32:
327 case IMGFMT_RGB24:
328 case IMGFMT_Y8:
329 case IMGFMT_Y800:
330 return VFCAP_CSP_SUPPORTED | VFCAP_SWSCALE | VFCAP_OSD;
332 return 0;
335 static int
336 draw_frame(uint8_t *src[]) {
337 int stride[MP_MAX_PLANES] = {0};
339 switch(image_format) {
340 case IMGFMT_BGR15:
341 case IMGFMT_BGR16:
342 stride[0] = src_width*2;
343 break;
344 case IMGFMT_IYU2:
345 case IMGFMT_BGR24:
346 stride[0] = src_width*3;
347 break;
348 case IMGFMT_BGR32:
349 stride[0] = src_width*4;
350 break;
353 sws_scale_ordered(sws,src,stride,0,src_height,image,image_stride);
355 /* Now 'ASCIInate' the image */
356 if (fast)
357 aa_fastrender(c, screen_x, screen_y, screen_w + screen_x, screen_h + screen_y );
358 else
359 aa_render(c, p,screen_x, screen_y, screen_w + screen_x, screen_h + screen_y );
361 return 0;
364 static int
365 draw_slice(uint8_t *src[], int stride[],
366 int w, int h, int x, int y) {
368 int dx1 = screen_x + (x * screen_w / src_width);
369 int dy1 = screen_y + (y * screen_h / src_height);
370 int dx2 = screen_x + ((x+w) * screen_w / src_width);
371 int dy2 = screen_y + ((y+h) * screen_h / src_height);
373 sws_scale_ordered(sws,src,stride,y,h,image,image_stride);
375 /* Now 'ASCIInate' the image */
376 if (fast)
377 aa_fastrender(c, dx1, dy1, dx2, dy2 );
378 else
379 aa_render(c, p,dx1, dy1, dx2, dy2 );
382 return 0;
385 static void
386 flip_page(void) {
388 /* do we have to put *our* (messages, progbar) osd to aa's txtbuf ? */
389 if (showosdmessage)
391 if (time(NULL)>=stoposd ) {
392 showosdmessage=0;
393 if(*osdmessagetext) {
394 memset(c->textbuffer + osdy * aa_scrwidth(c) + osdx,' ',strlen(osdmessagetext));
395 memset(c->attrbuffer + osdy * aa_scrwidth(c) + osdx ,0,strlen(osdmessagetext));
396 osdmessagetext[0] = '\0';
398 if(*posbar) {
399 memset(c->textbuffer + (osdy+1) * aa_scrwidth(c),' ',strlen(posbar));
400 memset(c->attrbuffer + (osdy+1) * aa_scrwidth(c),0,strlen(posbar));
402 } else {
403 /* update osd */
404 aa_puts(c, osdx, osdy, AA_SPECIAL, osdmessagetext);
405 /* posbar? */
406 if (posbar[0]!='\0')
407 aa_puts(c, 0, osdy + 1, AA_SPECIAL, posbar);
410 /* OSD time & playmode , subtitles */
411 printosdtext();
414 /* print out */
415 aa_flush(c);
418 static void
419 check_events(void) {
421 * any events?
422 * called by show_image and mplayer
424 int key;
425 while ((key=aa_getevent(c,0))!=AA_NONE ){
426 if (key>255){
427 /* some conversations */
428 switch (key) {
429 case AA_UP:
430 mplayer_put_key(KEY_UP);
431 break;
432 case AA_DOWN:
433 mplayer_put_key(KEY_DOWN);
434 break;
435 case AA_LEFT:
436 mplayer_put_key(KEY_LEFT);
437 break;
438 case AA_RIGHT:
439 mplayer_put_key(KEY_RIGHT);
440 break;
441 case AA_ESC:
442 mplayer_put_key(KEY_ESC);
443 break;
444 case 65765:
445 mplayer_put_key(KEY_PAGE_UP);
446 break;
447 case 65766:
448 mplayer_put_key(KEY_PAGE_DOWN);
449 break;
450 default:
451 continue; /* aa lib special key */
452 break;
455 if (key=='a' || key=='A'){
456 aaconfigmode=!aaconfigmode;
457 osdmessage(MESSAGE_DURATION, 1, "aa config mode is now %s",
458 aaconfigmode==1 ? "on. use keys 5-7" : "off");
460 if (aaconfigmode==1) {
461 switch (key) {
462 /* AA image controls */
463 case '5':
464 fast=!fast;
465 osdmessage(MESSAGE_DURATION, 1, "Fast mode is now %s", fast==1 ? "on" : "off");
466 break;
467 case '6':
468 if (p->dither==AA_FLOYD_S){
469 p->dither=AA_NONE;
470 osdmessage(MESSAGE_DURATION, 1, "Dithering: Off");
471 }else if (p->dither==AA_NONE){
472 p->dither=AA_ERRORDISTRIB;
473 osdmessage(MESSAGE_DURATION, 1, "Dithering: Error Distribution");
474 }else if (p->dither==AA_ERRORDISTRIB){
475 p->dither=AA_FLOYD_S;
476 osdmessage(MESSAGE_DURATION, 1, "Dithering: Floyd Steinberg");
478 break;
479 case '7':
480 p->inversion=!p->inversion;
481 osdmessage(MESSAGE_DURATION, 1, "Invert mode is now %s",
482 p->inversion==1 ? "on" : "off");
483 break;
485 default :
486 /* nothing if we're interested in?
487 * the mplayer should handle it!
489 mplayer_put_key(key);
490 break;
492 }// aaconfigmode
493 else mplayer_put_key(key);
497 static void
498 uninit(void) {
500 * THE END
503 if (strstr(c->driver->name,"Curses") || strstr(c->driver->name,"Linux")){
504 freopen("/dev/tty", "w", stderr);
506 if(vo_font_save) {
507 free(vo_font->pic_a[0]->bmp);
508 free(vo_font->pic_a[0]);
509 free(vo_font->pic_b[0]->bmp);
510 free(vo_font->pic_b[0]);
511 free(vo_font);
512 vo_font = vo_font_save;
513 vo_font_save = NULL;
515 aa_close(c);
518 static void draw_alpha(int x,int y, int w,int h, unsigned char* src, unsigned char *srca, int stride){
519 int i,j;
520 for (i = 0; i < h; i++) {
521 for (j = 0; j < w; j++) {
522 if (src[i*stride+j] > 0) {
523 c->textbuffer[x + j + (y+i)*aa_scrwidth(c)] = src[i*stride+j];
524 c->attrbuffer[x + j + (y+i)*aa_scrwidth(c)] = aaopt_subcolor;
530 static void clear_alpha(int x0,int y0, int w,int h) {
531 int l;
533 for(l = 0 ; l < h ; l++) {
534 memset(c->textbuffer + (y0 + l) * aa_scrwidth(c) + x0,' ',w);
535 memset(c->attrbuffer + (y0 + l) * aa_scrwidth(c) + x0,0,w);
540 static void
541 draw_osd(void){
542 char vo_osd_text_save;
543 int vo_osd_progbar_type_save;
545 printosdprogbar();
546 /* let vo_draw_text only write subtitle */
547 vo_osd_text_save = global_osd->osd_text[0];
548 global_osd->osd_text[0] = 0;
549 vo_osd_progbar_type_save=vo_osd_progbar_type;
550 vo_osd_progbar_type=-1;
551 vo_remove_text(aa_scrwidth(c), aa_scrheight(c),clear_alpha);
552 vo_draw_text(aa_scrwidth(c), aa_scrheight(c), draw_alpha);
553 global_osd->osd_text[0] = vo_osd_text_save;
554 vo_osd_progbar_type=vo_osd_progbar_type_save;
557 static int
558 getcolor(char * s){
559 int i;
560 char * rest;
561 if (s==NULL) return -1;
562 i=strtol(s, &rest, 10);
563 if ((rest==NULL || strlen(rest)==0) && i>=0 && i<=5) return i;
564 if (!strcasecmp(s, "normal")) return AA_NORMAL;
565 else if (!strcasecmp(s, "dim")) return AA_DIM;
566 else if (!strcasecmp(s, "bold")) return AA_BOLD;
567 else if (!strcasecmp(s, "boldfont")) return AA_BOLDFONT;
568 else if (!strcasecmp(s, "special")) return AA_SPECIAL;
569 else return -1;
572 static int parse_suboptions(const char *arg) {
573 char *pseudoargv[4], *osdcolor = NULL, *subcolor = NULL, **strings,
574 *helpmsg = NULL;
575 int pseudoargc, displayhelp = 0, *booleans;
576 const opt_t extra_opts[] = {
577 {"osdcolor", OPT_ARG_MSTRZ, &osdcolor, NULL},
578 {"subcolor", OPT_ARG_MSTRZ, &subcolor, NULL},
579 {"help", OPT_ARG_BOOL, &displayhelp, NULL} };
580 opt_t *subopts = NULL, *p;
581 char * const strings_list[] = {"-driver", "-kbddriver", "-mousedriver", "-font",
582 "-width", "-height", "-minwidth", "-minheight", "-maxwidth",
583 "-maxheight", "-recwidth", "-recheight", "-bright", "-contrast",
584 "-gamma", "-dimmul", "-boldmul", "-random" };
585 char * const booleans_list[] = {"-dim", "-bold", "-reverse", "-normal",
586 "-boldfont", "-inverse", "-extended", "-eight", "-dither",
587 "-floyd_steinberg", "-error_distribution"};
588 char * const nobooleans_list[] = {"-nodim", "-nobold", "-noreverse", "-nonormal",
589 "-noboldfont", "-noinverse", "-noextended", "-noeight", "-nodither",
590 "-nofloyd_steinberg", "-noerror_distribution"};
591 const int nstrings = sizeof(strings_list) / sizeof(char*);
592 const int nbooleans = sizeof(booleans_list) / sizeof(char*);
593 const int nextra_opts = sizeof(extra_opts) / sizeof(opt_t);
594 const int nsubopts = nstrings + nbooleans + nextra_opts;
595 int i, retval = 0;
597 subopts = calloc(nsubopts + 1, sizeof(opt_t));
598 strings = calloc(nstrings, sizeof(char*));
599 booleans = calloc(nbooleans, sizeof(int));
601 p = subopts;
602 for (i=0; i<nstrings; i++, p++) {
603 p->name = strings_list[i] + 1; // skip '-'
604 p->type = OPT_ARG_MSTRZ;
605 p->valp = &strings[i];
607 for (i=0; i<nbooleans; i++, p++) {
608 p->name = booleans_list[i] + 1;
609 p->type = OPT_ARG_BOOL;
610 p->valp = &booleans[i];
612 memcpy(p, extra_opts, sizeof(extra_opts));
614 retval = subopt_parse(arg, subopts);
616 if (retval == 0 && displayhelp) {
617 helpmsg = strdup(aa_help);
618 for (i=0; i<(signed)strlen(helpmsg); i++)
619 if (helpmsg[i] == '-') helpmsg[i] = ' ';
620 mp_tmsg(MSGT_VO, MSGL_INFO, "\n\nHere are the aalib vo_aa suboptions:\n");
621 mp_msg(MSGT_VO, MSGL_INFO, "%s\n\n", helpmsg);
622 #define VO_AA_AdditionalOptions _("Additional options vo_aa provides:\n" \
623 " help print this help message\n" \
624 " osdcolor set OSD color\n subcolor set subtitle color\n" \
625 " the color parameters are:\n 0 : normal\n" \
626 " 1 : dim\n 2 : bold\n 3 : boldfont\n" \
627 " 4 : reverse\n 5 : special\n\n\n")
629 mp_tmsg(MSGT_VO, MSGL_INFO, VO_AA_AdditionalOptions);
630 retval = -1;
632 if (retval == 0) {
633 pseudoargv[3] = NULL;
634 for (i=0; i<nstrings; i++) {
635 pseudoargc = 3; // inside loop because aalib changes it
636 if (strings[i] != NULL) {
637 pseudoargv[1] = strings_list[i];
638 pseudoargv[2] = strings[i];
639 aa_parseoptions(&aa_defparams, &aa_defrenderparams,
640 &pseudoargc, pseudoargv);
643 pseudoargv[2] = NULL;
644 for (i=0; i<nbooleans; i++) {
645 pseudoargc = 2;
646 if (booleans[i]) pseudoargv[1] = booleans_list[i];
647 else pseudoargv[1] = nobooleans_list[i];
648 aa_parseoptions(&aa_defparams, &aa_defrenderparams,
649 &pseudoargc, pseudoargv);
651 if (osdcolor) aaopt_osdcolor = getcolor(osdcolor);
652 if (subcolor) aaopt_subcolor = getcolor(subcolor);
655 if (subopts) free(subopts);
656 if (booleans) free(booleans);
657 if (strings) {
658 for (i=0; i<nstrings; i++)
659 if (strings[i])
660 free(strings[i]);
661 free(strings);
663 if (osdcolor) free(osdcolor);
664 if (subcolor) free(subcolor);
665 if (helpmsg) free(helpmsg);
666 return retval;
669 static int preinit(const char *arg)
671 char * hidis = NULL;
672 struct stat sbuf;
673 int fd, vt, major, minor;
674 FILE * fp;
675 char fname[12];
677 if(arg)
679 if (parse_suboptions(arg) != 0)
680 return ENOSYS;
683 /* initializing of aalib */
685 hidis=aa_getfirst(&aa_displayrecommended);
686 if ( hidis==NULL ){
687 /* check /dev/vcsa<vt> */
688 /* check only, if no driver is explicit set */
689 fd = dup (fileno (stderr));
690 fstat (fd, &sbuf);
691 major = sbuf.st_rdev >> 8;
692 vt = minor = sbuf.st_rdev & 0xff;
693 close (fd);
694 sprintf (fname, "/dev/vcsa%2.2i", vt);
695 fp = fopen (fname, "w+");
696 if (fp==NULL){
697 fprintf(stderr,"VO: [aa] cannot open %s for writing,"
698 "so we'll not use linux driver\n", fname);
699 aa_recommendlowdisplay("linux");
700 aa_recommendhidisplay("curses");
701 aa_recommendhidisplay("X11");
702 }else fclose(fp);
703 } else aa_recommendhidisplay(hidis);
704 c = aa_autoinit(&aa_defparams);
706 if (c == NULL) {
707 mp_msg(MSGT_VO,MSGL_ERR,"Cannot initialize aalib\n");
708 return VO_ERROR;
710 if (!aa_autoinitkbd(c,0)) {
711 mp_msg(MSGT_VO,MSGL_ERR,"Cannot initialize keyboard\n");
712 aa_close(c);
713 return VO_ERROR;
716 aa_resizehandler(c, (void *)resize);
717 aa_hidecursor(c);
718 p = aa_getrenderparams();
720 if ((strstr(c->driver->name,"Curses")) || (strstr(c->driver->name,"Linux"))){
721 freopen("/dev/null", "w", stderr);
722 /* disable console blanking */
723 printf("\033[9;0]");
726 memset(image,0,3*sizeof(uint8_t));
727 osdmessagetext[0] = '\0';
728 osdx = osdy = 0;
730 return 0;
733 static int control(uint32_t request, void *data)
735 switch (request) {
736 case VOCTRL_QUERY_FORMAT:
737 return query_format(*((uint32_t*)data));
738 case VOCTRL_SET_EQUALIZER: {
739 struct voctrl_set_equalizer_args *args = data;
740 if (strcmp(args->name, "contrast") == 0)
741 p->contrast = (args->value + 100) * 64 / 100;
742 else if (strcmp(args->name, "brightness") == 0)
743 p->bright = (args->value + 100) * 128 / 100;
744 return VO_TRUE;
746 case VOCTRL_GET_EQUALIZER: {
747 struct voctrl_get_equalizer_args *args = data;
749 if (strcmp(args->name, "contrast") == 0)
750 *args->valueptr = (p->contrast - 64) * 100 / 64;
751 else if (strcmp(args->name, "brightness") == 0)
752 *args->valueptr = (p->bright - 128) * 100 / 128;
754 return VO_TRUE;
757 return VO_NOTIMPL;