vo_aa.c

来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 759 行 · 第 1/2 页

C
759
字号
/* * MPlayer *  * Video driver for AAlib - 1.0 *  * by Folke Ashberg <folke@ashberg.de> *  * Code started: Sun Aug 12 2001 * Version 1.0 : Thu Aug 16 2001 * */#include <mplaylib.h>#include <mplaylib.h>#include <sys/stat.h>#include <mplaylib.h>#include <math.h>#include <stdarg.h>#include <time.h>#include <mplaylib.h>#include <errno.h>#include "config.h"#include "video_out.h"#include "video_out_internal.h"#include "aspect.h"#include "libswscale/swscale.h"#include "libmpcodecs/vf_scale.h"#include "font_load.h"#include "sub.h"#include "osdep/keycodes.h"#include <aalib.h>#include "subopt-helper.h"#include "help_mp.h"#include "mp_msg.h"#include "mp_fifo.h"#define MESSAGE_DURATION 3#define MESSAGE_SIZE 512#define MESSAGE_DEKO " +++ %s +++ "#undef memcpy#define memcpy uc_memcpy	static vo_info_t info = {	    "AAlib",	    "aa",	    "Alban Bedel <albeu@free.fr> and Folke Ashberg <folke@ashberg.de>",	    ""	};LIBVO_EXTERN(aa)/* aa's main context we use */aa_context *c;aa_renderparams *p;static int fast =0;/* used for the sws */static uint8_t * image[3];static int image_stride[3];/* image infos */static int image_format;static int image_width;static int image_height;static int image_x, image_y;static int screen_x, screen_y;static int screen_w, screen_h;static int src_width;static int src_height;/* osd stuff */time_t stoposd = 0;static int showosdmessage = 0;char osdmessagetext[MESSAGE_SIZE];char posbar[MESSAGE_SIZE];static int osdx, osdy;static int osd_text_length = 0;int aaconfigmode=1;font_desc_t* vo_font_save = NULL;static struct SwsContext *sws=NULL;/* configuration */int aaopt_osdcolor = AA_SPECIAL;int aaopt_subcolor = AA_SPECIAL;voidresize(void){    /*      * this function is called by aa lib if windows resizes     * further during init, because here we have to calculate     * a little bit     */    aa_resize(c);    aspect_save_screenres(aa_imgwidth(c),aa_imgheight(c));    image_height =  aa_imgheight(c); //src_height;    image_width = aa_imgwidth(c); //src_width;    aspect(&image_width,&image_height,A_ZOOM);    image_x = (aa_imgwidth(c) - image_width) / 2;    image_y = (aa_imgheight(c) - image_height) / 2;    screen_w = image_width * aa_scrwidth(c) / aa_imgwidth(c);    screen_h = image_height * aa_scrheight(c) / aa_imgheight(c);    screen_x = (aa_scrwidth(c) - screen_w) / 2;    screen_y = (aa_scrheight(c) - screen_h) / 2;        if(sws) sws_freeContext(sws);    sws = sws_getContextFromCmdLine(src_width,src_height,image_format,				   image_width,image_height,IMGFMT_Y8);    image[0] = aa_image(c) + image_y * aa_imgwidth(c) + image_x;    image[1] = NULL;    image[2] = NULL;    image_stride[0] = aa_imgwidth(c);    image_stride[1] = 0;     image_stride[2] = 0;    showosdmessage=0;}static voidosdmessage(int duration, int deko, const char *fmt, ...){    /*     * for outputting a centered string at the bottom     * of our window for a while     */    va_list ar;    char m[MESSAGE_SIZE];    unsigned int old_len = strlen(osdmessagetext);    va_start(ar, fmt);    vsprintf(m, fmt, ar);    va_end(ar);    if (deko==1) sprintf(osdmessagetext, MESSAGE_DEKO , m);    else strcpy(osdmessagetext, m);    if(old_len > strlen(osdmessagetext)) {      memset(c->textbuffer + osdy * aa_scrwidth(c) + osdx,' ',old_len);      memset(c->attrbuffer + osdy * aa_scrwidth(c) + osdx,0,old_len);    }    showosdmessage=1;    stoposd = time(NULL) + duration;    osdx=(aa_scrwidth(c) / 2) - (strlen(osdmessagetext) / 2 ) ;    posbar[0]='\0';}static voidosdpercent(int duration, int deko, int min, int max, int val, const char * desc, const char * unit){    /*     * prints a bar for setting values     */    float step;    int where;    int i;        step=(float)aa_scrwidth(c) /(float)(max-min);    where=(val-min)*step;    osdmessage(duration,deko,"%s: %i%s",desc, val, unit);    posbar[0]='|';    posbar[aa_scrwidth(c)-1]='|';    for (i=0;i<aa_scrwidth(c);i++){	if (i==where) posbar[i]='#';	else posbar[i]='-';    }    if (where!=0) posbar[0]='|';    if (where!=(aa_scrwidth(c)-1) ) posbar[aa_scrwidth(c)-1]='|';    posbar[aa_scrwidth(c)]='\0'; }static voidprintosdtext(void){  if(osd_text_length > 0 && !vo_osd_text) {    memset(c->textbuffer,' ',osd_text_length);    memset(c->attrbuffer,0,osd_text_length);    osd_text_length = 0;  }    /*      * places the mplayer status osd     */  if (vo_osd_text && vo_osd_text[0] != 0) {    int len;    if(vo_osd_text[0] < 32) {      len = strlen(sub_osd_names_short[vo_osd_text[0]]) + strlen(vo_osd_text+1) + 2;      aa_printf(c, 0, 0 , aaopt_osdcolor, "%s %s ", sub_osd_names_short[vo_osd_text[0]], vo_osd_text+1);    } else {      len = strlen(vo_osd_text) + 1;      aa_printf(c, 0, 0 , aaopt_osdcolor, "%s ",vo_osd_text);    }    if(len < osd_text_length) {      memset(c->textbuffer + len,' ',osd_text_length - len);      memset(c->attrbuffer + len,0,osd_text_length - len);    }    osd_text_length = len;      }}static voidprintosdprogbar(void){    /* print mplayer osd-progbar */    if (vo_osd_progbar_type!=-1){        osdpercent(1,1,0,255,vo_osd_progbar_value, sub_osd_names[vo_osd_progbar_type], "");    }}static intconfig(uint32_t width, uint32_t height, uint32_t d_width,	    uint32_t d_height, uint32_t flags, char *title, 	    uint32_t format) {    /*     * main init     * called by mplayer     */    int i;    aspect_save_orig(width,height);    aspect_save_prescale(d_width,d_height);    src_height = height;    src_width = width;    image_format = format;    /* nothing will change its size, be we need some values initialized */    resize();    /* now init out own 'font' (to use vo_draw_text_sub without edit them) */    if(!vo_font_save) vo_font_save = vo_font;    if(vo_font == vo_font_save) {      vo_font=malloc(sizeof(font_desc_t));//if(!desc) return NULL;      memset(vo_font,0,sizeof(font_desc_t));      vo_font->pic_a[0]=malloc(sizeof(raw_file));      memset(vo_font->pic_a[0],0,sizeof(raw_file));      vo_font->pic_b[0]=malloc(sizeof(raw_file));      memset(vo_font->pic_b[0],0,sizeof(raw_file));#ifdef HAVE_FREETYPE      vo_font->dynamic = 0;#endif      vo_font->spacewidth=1;      vo_font->charspace=0;      vo_font->height=1;      vo_font->pic_a[0]->bmp=malloc(255);      vo_font->pic_a[0]->pal=NULL;      vo_font->pic_b[0]->bmp=malloc(255);      vo_font->pic_b[0]->pal=NULL;      vo_font->pic_a[0]->w=1;      vo_font->pic_a[0]->h=1;      for (i=0; i<255; i++){	vo_font->width[i]=1;	vo_font->font[i]=0;	vo_font->start[i]=i;	vo_font->pic_a[0]->bmp[i]=i;	vo_font->pic_b[0]->bmp[i]=i;      }    }    /* say hello */    osdmessage(5, 1, "Welcome to ASCII ART MPlayer");      mp_msg(MSGT_VO,MSGL_V,"VO: [aa] screendriver:   %s\n", c->driver->name);    mp_msg(MSGT_VO,MSGL_V,"VO: [aa] keyboarddriver: %s\n", c->kbddriver->name);    mp_msg(MSGT_VO,MSGL_INFO,		"\n"		"Important suboptions\n"		"\textended  use use all 256 characters\n"		"\teight     use eight bit ascii\n"		"\tdriver    set recommended aalib driver (X11,curses,linux)\n"		"\thelp      to see all options provided by aalib\n"		"\n"		"AA-MPlayer Keys\n"		"\t1 : contrast -\n"		"\t2 : contrast +\n"		"\t3 : brightness -\n"		"\t4 : brightness +\n"		"\t5 : fast rendering\n"		"\t6 : dithering\n"		"\t7 : invert image\n"	        "\ta : toggles between aa and mplayer control\n"		"\n"		"All other keys are MPlayer defaults.\n"	  );    return 0;}static int query_format(uint32_t format) {    /*     * ...are we able to... ?     * called by mplayer     * All input format supported by the sws     */    switch(format){	case IMGFMT_YV12:	case IMGFMT_I420:	case IMGFMT_IYUV:	case IMGFMT_IYU2:	case IMGFMT_BGR32:	case IMGFMT_BGR24:	case IMGFMT_BGR16:	case IMGFMT_BGR15:	case IMGFMT_RGB32:	case IMGFMT_RGB24:	case IMGFMT_Y8:	case IMGFMT_Y800:	    return VFCAP_CSP_SUPPORTED | VFCAP_SWSCALE | VFCAP_OSD;    }    return 0;}static int draw_frame(uint8_t *src[]) {  int stride[3] = { 0 , 0 , 0 };  switch(image_format) {  case IMGFMT_BGR15:  case IMGFMT_BGR16:    stride[0] = src_width*2;    break;  case IMGFMT_IYU2:  case IMGFMT_BGR24:    stride[0] = src_width*3;    break;  case IMGFMT_BGR32:    stride[0] = src_width*4;    break;  }  sws_scale_ordered(sws,src,stride,0,src_height,image,image_stride);   /* Now 'ASCIInate' the image */   if (fast)    aa_fastrender(c, screen_x, screen_y, screen_w + screen_x, screen_h + screen_y );  else    aa_render(c, p,screen_x, screen_y, screen_w + screen_x, screen_h + screen_y );  return 0;}static int draw_slice(uint8_t *src[], int stride[], 	    int w, int h, int x, int y) {  int dx1 = screen_x + (x * screen_w / src_width);  int dy1 = screen_y + (y * screen_h / src_height);  int dx2 = screen_x + ((x+w) * screen_w / src_width);  int dy2 = screen_y + ((y+h) * screen_h / src_height);  sws_scale_ordered(sws,src,stride,y,h,image,image_stride);  /* Now 'ASCIInate' the image */   if (fast)    aa_fastrender(c, dx1, dy1, dx2, dy2 );  else    aa_render(c, p,dx1, dy1, dx2, dy2 );    return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?