vf_expand.c

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

C
481
字号
#define OSD_SUPPORT#include <uclib.h>#include <uclib.h>#include <uclib.h>#include "config.h"#include "mp_msg.h"#include "help_mp.h"#include "img_format.h"#include "mp_image.h"#include "vf.h"#include "libvo/fastmemcpy.h"#ifdef OSD_SUPPORT#include "libvo/sub.h"#include "libvo/osd.h"#endif#include "m_option.h"#include "m_struct.h"#define MAX(a,b) ((a) > (b) ? (a) : (b))static struct vf_priv_s {    int exp_w,exp_h;    int exp_x,exp_y;    int osd;    double aspect;    int round;    unsigned char* fb_ptr;    int passthrough;    int first_slice;} const vf_priv_dflt = {  -1,-1,  -1,-1,  0,  0.,  1,  NULL,  0,  0};extern int opt_screen_size_x;extern int opt_screen_size_y;//===========================================================================//#ifdef OSD_SUPPORTstatic struct vf_instance_s* vf=NULL; // fixme (needs sub.c changes)static int orig_w,orig_h;static void remove_func_2(int x0,int y0, int w,int h){    // TODO: let's cleanup the place    //printf("OSD clear: %d;%d %dx%d  \n",x0,y0,w,h);    vf_mpi_clear(vf->dmpi,x0,y0,w,h);}static void remove_func(int x0,int y0, int w,int h){    if(!vo_osd_changed_flag) return;    // split it to 4 parts:    if(y0<vf->priv->exp_y){	// it has parts above the image:	int y=y0+h;	if(y>vf->priv->exp_y) y=vf->priv->exp_y;	remove_func_2(x0,y0,w,y-y0);	if(y0+h<=vf->priv->exp_y) return;	h-=y-y0;y0=y;    }    if(y0+h>vf->priv->exp_y+orig_h){	// it has parts under the image:	int y=y0;	if(y<vf->priv->exp_y+orig_h) y=vf->priv->exp_y+orig_h;	remove_func_2(x0,y,w,y0+h-y);	if(y0>=vf->priv->exp_y+orig_h) return;	h=y-y0;    }    if(x0<vf->priv->exp_x){	// it has parts on the left side of the image:	int x=x0+w;	if(x>vf->priv->exp_x) x=vf->priv->exp_x;	remove_func_2(x0,y0,x-x0,h);	if(x0+w<=vf->priv->exp_x) return;	w-=x-x0;x0=x;    }    if(x0+w>vf->priv->exp_x+orig_w){	// it has parts on the right side of the image:	int x=x0;	if(x<vf->priv->exp_x+orig_w) x=vf->priv->exp_x+orig_w;	remove_func_2(x,y0,x0+w-x,h);	if(x0>=vf->priv->exp_x+orig_w) return;	w=x-x0;    }}static void draw_func(int x0,int y0, int w,int h,unsigned char* src, unsigned char *srca, int stride){    unsigned char* dst;    if(!vo_osd_changed_flag && vf->dmpi->planes[0]==vf->priv->fb_ptr){	// ok, enough to update the area inside the video, leave the black bands	// untouched!	if(x0<vf->priv->exp_x){	    int tmp=vf->priv->exp_x-x0;	    w-=tmp; src+=tmp; srca+=tmp; x0+=tmp;	}	if(y0<vf->priv->exp_y){	    int tmp=vf->priv->exp_y-y0;	    h-=tmp; src+=tmp*stride; srca+=tmp*stride; y0+=tmp;	}	if(x0+w>vf->priv->exp_x+orig_w){	    w=vf->priv->exp_x+orig_w-x0;	}	if(y0+h>vf->priv->exp_y+orig_h){	    h=vf->priv->exp_y+orig_h-y0;	}    }    if(w<=0 || h<=0) return; // nothing to do...//    printf("OSD redraw: %d;%d %dx%d  \n",x0,y0,w,h);    dst=vf->dmpi->planes[0]+			vf->dmpi->stride[0]*y0+			(vf->dmpi->bpp>>3)*x0;    switch(vf->dmpi->imgfmt){    case IMGFMT_BGR15:    case IMGFMT_RGB15:	vo_draw_alpha_rgb15(w,h,src,srca,stride,dst,vf->dmpi->stride[0]);	break;    case IMGFMT_BGR16:    case IMGFMT_RGB16:	vo_draw_alpha_rgb16(w,h,src,srca,stride,dst,vf->dmpi->stride[0]);	break;    case IMGFMT_BGR24:    case IMGFMT_RGB24:	vo_draw_alpha_rgb24(w,h,src,srca,stride,dst,vf->dmpi->stride[0]);	break;    case IMGFMT_BGR32:    case IMGFMT_RGB32:	vo_draw_alpha_rgb32(w,h,src,srca,stride,dst,vf->dmpi->stride[0]);	break;    case IMGFMT_YV12:    case IMGFMT_I420:    case IMGFMT_IYUV:    case IMGFMT_YVU9:    case IMGFMT_IF09:    case IMGFMT_Y800:    case IMGFMT_Y8:	vo_draw_alpha_yv12(w,h,src,srca,stride,dst,vf->dmpi->stride[0]);	break;    case IMGFMT_YUY2:	vo_draw_alpha_yuy2(w,h,src,srca,stride,dst,vf->dmpi->stride[0]);	break;    case IMGFMT_UYVY:	vo_draw_alpha_yuy2(w,h,src,srca,stride,dst+1,vf->dmpi->stride[0]);	break;    }}static void draw_osd(struct vf_instance_s* vf_,int w,int h){    vf=vf_;orig_w=w;orig_h=h;//    printf("======================================\n");    if(vf->priv->exp_w!=w || vf->priv->exp_h!=h ||	vf->priv->exp_x || vf->priv->exp_y){	// yep, we're expanding image, not just copy.	if(vf->dmpi->planes[0]!=vf->priv->fb_ptr){	    // double buffering, so we need full clear :(	    if (vf->priv->exp_y > 0)		remove_func_2(0,0,vf->priv->exp_w,vf->priv->exp_y);	    if (vf->priv->exp_y+h < vf->priv->exp_h)		remove_func_2(0,vf->priv->exp_y+h,vf->priv->exp_w,vf->priv->exp_h-h-vf->priv->exp_y);	    if (vf->priv->exp_x > 0)		remove_func_2(0,vf->priv->exp_y,vf->priv->exp_x,h);	    if (vf->priv->exp_x+w < vf->priv->exp_w)		remove_func_2(vf->priv->exp_x+w,vf->priv->exp_y,vf->priv->exp_w-w-vf->priv->exp_x,h);	} else {	    // partial clear:	    vo_remove_text(vf->priv->exp_w,vf->priv->exp_h,remove_func);	}    }    vo_draw_text(vf->priv->exp_w,vf->priv->exp_h,draw_func);    // save buffer pointer for double buffering detection - yes, i know it's    // ugly method, but note that codecs with DR support does the same...    if(vf->dmpi)      vf->priv->fb_ptr=vf->dmpi->planes[0];}#endif//===========================================================================//static int config(struct vf_instance_s* vf,        int width, int height, int d_width, int d_height,	unsigned int flags, unsigned int outfmt){    if(outfmt == IMGFMT_MPEGPES) {      vf->priv->passthrough = 1;      return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);    }    if (outfmt == IMGFMT_IF09) return 0;    // calculate the missing parameters:#if 0    if(vf->priv->exp_w<width) vf->priv->exp_w=width;    if(vf->priv->exp_h<height) vf->priv->exp_h=height;#else    if ( vf->priv->exp_w == -1 ) vf->priv->exp_w=width;      else if (vf->priv->exp_w < -1 ) vf->priv->exp_w=width - vf->priv->exp_w;        else if ( vf->priv->exp_w<width ) vf->priv->exp_w=width;    if ( vf->priv->exp_h == -1 ) vf->priv->exp_h=height;      else if ( vf->priv->exp_h < -1 ) vf->priv->exp_h=height - vf->priv->exp_h;        else if( vf->priv->exp_h<height ) vf->priv->exp_h=height;#endif    if (vf->priv->aspect) {        float adjusted_aspect = vf->priv->aspect;        adjusted_aspect *= ((double)width/height) / ((double)d_width/d_height);        if (vf->priv->exp_h < vf->priv->exp_w / adjusted_aspect) {            vf->priv->exp_h = vf->priv->exp_w / adjusted_aspect + 0.5;        } else {            vf->priv->exp_w = vf->priv->exp_h * adjusted_aspect + 0.5;        }    }    if (vf->priv->round > 1) { // round up.        vf->priv->exp_w = (1 + (vf->priv->exp_w - 1) / vf->priv->round) * vf->priv->round;        vf->priv->exp_h = (1 + (vf->priv->exp_h - 1) / vf->priv->round) * vf->priv->round;    }    if(vf->priv->exp_x<0 || vf->priv->exp_x+width>vf->priv->exp_w) vf->priv->exp_x=(vf->priv->exp_w-width)/2;    if(vf->priv->exp_y<0 || vf->priv->exp_y+height>vf->priv->exp_h) vf->priv->exp_y=(vf->priv->exp_h-height)/2;    vf->priv->fb_ptr=NULL;    if(!opt_screen_size_x && !opt_screen_size_y){	d_width=d_width*vf->priv->exp_w/width;	d_height=d_height*vf->priv->exp_h/height;    }    return vf_next_config(vf,vf->priv->exp_w,vf->priv->exp_h,d_width,d_height,flags,outfmt);}// there are 4 cases:// codec --DR--> expand --DR--> vo// codec --DR--> expand -copy-> vo// codec -copy-> expand --DR--> vo// codec -copy-> expand -copy-> vo (worst case)static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){

⌨️ 快捷键说明

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