2002-04-17 21:51:18 +00:00
|
|
|
#define OSD_SUPPORT
|
2002-04-16 00:34:04 +00:00
|
|
|
|
2002-04-06 22:05:01 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "../config.h"
|
|
|
|
#include "../mp_msg.h"
|
|
|
|
|
2002-04-16 00:34:04 +00:00
|
|
|
#include "img_format.h"
|
2002-04-13 19:14:34 +00:00
|
|
|
#include "mp_image.h"
|
2002-04-06 22:05:01 +00:00
|
|
|
#include "vf.h"
|
|
|
|
|
|
|
|
#include "../libvo/fastmemcpy.h"
|
|
|
|
|
2002-04-16 00:34:04 +00:00
|
|
|
#ifdef OSD_SUPPORT
|
|
|
|
#include "../libvo/sub.h"
|
|
|
|
#include "../libvo/osd.h"
|
|
|
|
#endif
|
|
|
|
|
2002-04-06 22:05:01 +00:00
|
|
|
struct vf_priv_s {
|
|
|
|
int exp_w,exp_h;
|
|
|
|
int exp_x,exp_y;
|
|
|
|
mp_image_t *dmpi;
|
2002-04-16 00:34:04 +00:00
|
|
|
int osd;
|
2002-04-17 21:51:18 +00:00
|
|
|
unsigned char* fb_ptr;
|
2002-04-06 22:05:01 +00:00
|
|
|
};
|
|
|
|
|
2002-05-12 19:06:15 +00:00
|
|
|
extern int opt_screen_size_x;
|
|
|
|
extern int opt_screen_size_y;
|
|
|
|
|
2002-04-16 00:34:04 +00:00
|
|
|
//===========================================================================//
|
|
|
|
#ifdef OSD_SUPPORT
|
|
|
|
|
|
|
|
static 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
|
2002-04-17 21:51:18 +00:00
|
|
|
//printf("OSD clear: %d;%d %dx%d \n",x0,y0,w,h);
|
|
|
|
vf_mpi_clear(vf->priv->dmpi,x0,y0,w,h);
|
2002-04-16 00:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 || x0+w<=vf->priv->exp_x+orig_w) return;
|
|
|
|
// TODO clear left and right side of the image if needed
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_func(int x0,int y0, int w,int h,unsigned char* src, unsigned char *srca, int stride){
|
2002-04-17 21:51:18 +00:00
|
|
|
unsigned char* dst;
|
|
|
|
if(!vo_osd_changed_flag && vf->priv->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->priv->dmpi->planes[0]+
|
2002-04-16 00:34:04 +00:00
|
|
|
vf->priv->dmpi->stride[0]*y0+
|
|
|
|
(vf->priv->dmpi->bpp>>3)*x0;
|
|
|
|
switch(vf->priv->dmpi->imgfmt){
|
|
|
|
case IMGFMT_BGR15:
|
|
|
|
case IMGFMT_RGB15:
|
|
|
|
vo_draw_alpha_rgb15(w,h,src,srca,stride,dst,vf->priv->dmpi->stride[0]);
|
|
|
|
break;
|
|
|
|
case IMGFMT_BGR16:
|
|
|
|
case IMGFMT_RGB16:
|
|
|
|
vo_draw_alpha_rgb16(w,h,src,srca,stride,dst,vf->priv->dmpi->stride[0]);
|
|
|
|
break;
|
|
|
|
case IMGFMT_BGR24:
|
|
|
|
case IMGFMT_RGB24:
|
|
|
|
vo_draw_alpha_rgb24(w,h,src,srca,stride,dst,vf->priv->dmpi->stride[0]);
|
|
|
|
break;
|
|
|
|
case IMGFMT_BGR32:
|
|
|
|
case IMGFMT_RGB32:
|
|
|
|
vo_draw_alpha_rgb32(w,h,src,srca,stride,dst,vf->priv->dmpi->stride[0]);
|
|
|
|
break;
|
|
|
|
case IMGFMT_YV12:
|
|
|
|
case IMGFMT_I420:
|
|
|
|
case IMGFMT_IYUV:
|
2002-06-23 19:33:55 +00:00
|
|
|
case IMGFMT_YVU9:
|
|
|
|
case IMGFMT_IF09:
|
|
|
|
case IMGFMT_Y800:
|
|
|
|
case IMGFMT_Y8:
|
2002-04-16 00:34:04 +00:00
|
|
|
vo_draw_alpha_yv12(w,h,src,srca,stride,dst,vf->priv->dmpi->stride[0]);
|
|
|
|
break;
|
|
|
|
case IMGFMT_YUY2:
|
|
|
|
vo_draw_alpha_yuy2(w,h,src,srca,stride,dst,vf->priv->dmpi->stride[0]);
|
|
|
|
break;
|
|
|
|
case IMGFMT_UYVY:
|
|
|
|
vo_draw_alpha_yuy2(w,h,src,srca,stride,dst+1,vf->priv->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;
|
2002-04-17 21:51:18 +00:00
|
|
|
// printf("======================================\n");
|
2002-04-16 00:34:04 +00:00
|
|
|
if(vf->priv->exp_w!=w || vf->priv->exp_h!=h ||
|
2002-04-17 21:51:18 +00:00
|
|
|
vf->priv->exp_x || vf->priv->exp_y){
|
|
|
|
// yep, we're expanding image, not just copy.
|
|
|
|
if(vf->priv->dmpi->planes[0]!=vf->priv->fb_ptr){
|
|
|
|
// double buffering, so we need full clear :(
|
|
|
|
remove_func(0,0,vf->priv->exp_w,vf->priv->exp_h);
|
|
|
|
} else {
|
|
|
|
// partial clear:
|
|
|
|
vo_remove_text(vf->priv->exp_w,vf->priv->exp_h,remove_func);
|
|
|
|
}
|
2002-04-16 00:34:04 +00:00
|
|
|
}
|
|
|
|
vo_draw_text(vf->priv->exp_w,vf->priv->exp_h,draw_func);
|
2002-04-17 21:51:18 +00:00
|
|
|
// save buffer pointer for double buffering detection - yes, i know it's
|
|
|
|
// ugly method, but note that codecs with DR support does the same...
|
|
|
|
vf->priv->fb_ptr=vf->priv->dmpi->planes[0];
|
2002-04-16 00:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2002-04-06 22:05:01 +00:00
|
|
|
//===========================================================================//
|
|
|
|
|
|
|
|
static int config(struct vf_instance_s* vf,
|
|
|
|
int width, int height, int d_width, int d_height,
|
|
|
|
unsigned int flags, unsigned int outfmt){
|
2002-06-23 15:15:31 +00:00
|
|
|
if (outfmt == IMGFMT_IF09) return 0;
|
2002-04-06 22:05:01 +00:00
|
|
|
// calculate the missing parameters:
|
2002-05-01 14:15:05 +00:00
|
|
|
#if 0
|
2002-04-06 22:05:01 +00:00
|
|
|
if(vf->priv->exp_w<width) vf->priv->exp_w=width;
|
|
|
|
if(vf->priv->exp_h<height) vf->priv->exp_h=height;
|
2002-05-01 14:15:05 +00:00
|
|
|
#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
|
2002-04-18 17:59:32 +00:00
|
|
|
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;
|
2002-04-17 21:51:18 +00:00
|
|
|
vf->priv->fb_ptr=NULL;
|
2002-05-12 19:06:15 +00:00
|
|
|
|
|
|
|
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);
|
2002-04-06 22:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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){
|
2002-04-17 22:19:14 +00:00
|
|
|
if(mpi->type==MP_IMGTYPE_IPB) return; // not yet working
|
2002-04-16 00:34:04 +00:00
|
|
|
#ifdef OSD_SUPPORT
|
|
|
|
if(vf->priv->osd && (mpi->flags&MP_IMGFLAG_PRESERVE)){
|
|
|
|
// check if we have to render osd!
|
|
|
|
vo_update_osd(vf->priv->exp_w, vf->priv->exp_h);
|
|
|
|
if(vo_osd_check_range_update(vf->priv->exp_x,vf->priv->exp_y,
|
|
|
|
vf->priv->exp_x+mpi->w,vf->priv->exp_y+mpi->h)) return;
|
|
|
|
}
|
|
|
|
#endif
|
2002-04-06 22:05:01 +00:00
|
|
|
if(vf->priv->exp_w==mpi->width ||
|
|
|
|
(mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH)) ){
|
|
|
|
// try full DR !
|
|
|
|
vf->priv->dmpi=vf_get_image(vf->next,mpi->imgfmt,
|
|
|
|
mpi->type, mpi->flags, vf->priv->exp_w, vf->priv->exp_h);
|
|
|
|
// set up mpi as a cropped-down image of dmpi:
|
|
|
|
if(mpi->flags&MP_IMGFLAG_PLANAR){
|
|
|
|
mpi->planes[0]=vf->priv->dmpi->planes[0]+
|
|
|
|
vf->priv->exp_y*vf->priv->dmpi->stride[0]+vf->priv->exp_x;
|
2002-06-23 15:15:31 +00:00
|
|
|
mpi->planes[1]=vf->priv->dmpi->planes[1]+
|
2002-06-23 21:08:31 +00:00
|
|
|
(vf->priv->exp_y>>mpi->chroma_y_shift)*vf->priv->dmpi->stride[1]+(vf->priv->exp_x>>mpi->chroma_x_shift);
|
2002-06-23 15:15:31 +00:00
|
|
|
mpi->planes[2]=vf->priv->dmpi->planes[2]+
|
2002-06-23 21:08:31 +00:00
|
|
|
(vf->priv->exp_y>>mpi->chroma_y_shift)*vf->priv->dmpi->stride[2]+(vf->priv->exp_x>>mpi->chroma_x_shift);
|
2002-04-06 22:05:01 +00:00
|
|
|
mpi->stride[1]=vf->priv->dmpi->stride[1];
|
|
|
|
mpi->stride[2]=vf->priv->dmpi->stride[2];
|
|
|
|
} else {
|
|
|
|
mpi->planes[0]=vf->priv->dmpi->planes[0]+
|
|
|
|
vf->priv->exp_y*vf->priv->dmpi->stride[0]+
|
|
|
|
vf->priv->exp_x*(vf->priv->dmpi->bpp/8);
|
|
|
|
}
|
2002-04-08 01:36:21 +00:00
|
|
|
mpi->stride[0]=vf->priv->dmpi->stride[0];
|
|
|
|
mpi->width=vf->priv->dmpi->width;
|
2002-04-06 22:05:01 +00:00
|
|
|
mpi->flags|=MP_IMGFLAG_DIRECT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){
|
|
|
|
if(mpi->flags&MP_IMGFLAG_DIRECT){
|
2002-04-16 00:34:04 +00:00
|
|
|
#ifdef OSD_SUPPORT
|
|
|
|
if(vf->priv->osd) draw_osd(vf,mpi->w,mpi->h);
|
|
|
|
#endif
|
2002-04-28 01:02:02 +00:00
|
|
|
vf_next_put_image(vf,vf->priv->dmpi);
|
2002-04-06 22:05:01 +00:00
|
|
|
return; // we've used DR, so we're ready...
|
|
|
|
}
|
|
|
|
|
|
|
|
// hope we'll get DR buffer:
|
|
|
|
vf->priv->dmpi=vf_get_image(vf->next,mpi->imgfmt,
|
|
|
|
MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
|
|
|
|
vf->priv->exp_w, vf->priv->exp_h);
|
|
|
|
|
|
|
|
// copy mpi->dmpi...
|
|
|
|
if(mpi->flags&MP_IMGFLAG_PLANAR){
|
|
|
|
memcpy_pic(vf->priv->dmpi->planes[0]+
|
|
|
|
vf->priv->exp_y*vf->priv->dmpi->stride[0]+vf->priv->exp_x,
|
|
|
|
mpi->planes[0], mpi->w, mpi->h,
|
|
|
|
vf->priv->dmpi->stride[0],mpi->stride[0]);
|
|
|
|
memcpy_pic(vf->priv->dmpi->planes[1]+
|
2002-06-23 21:08:31 +00:00
|
|
|
(vf->priv->exp_y>>mpi->chroma_y_shift)*vf->priv->dmpi->stride[1]+(vf->priv->exp_x>>mpi->chroma_x_shift),
|
|
|
|
mpi->planes[1], mpi->chroma_width, mpi->chroma_height,
|
2002-04-06 22:05:01 +00:00
|
|
|
vf->priv->dmpi->stride[1],mpi->stride[1]);
|
|
|
|
memcpy_pic(vf->priv->dmpi->planes[2]+
|
2002-06-23 21:08:31 +00:00
|
|
|
(vf->priv->exp_y>>mpi->chroma_y_shift)*vf->priv->dmpi->stride[2]+(vf->priv->exp_x>>mpi->chroma_x_shift),
|
|
|
|
mpi->planes[2], mpi->chroma_width, mpi->chroma_height,
|
2002-04-06 22:05:01 +00:00
|
|
|
vf->priv->dmpi->stride[2],mpi->stride[2]);
|
|
|
|
} else {
|
|
|
|
memcpy_pic(vf->priv->dmpi->planes[0]+
|
|
|
|
vf->priv->exp_y*vf->priv->dmpi->stride[0]+vf->priv->exp_x*(vf->priv->dmpi->bpp/8),
|
|
|
|
mpi->planes[0], mpi->w*(vf->priv->dmpi->bpp/8), mpi->h,
|
|
|
|
vf->priv->dmpi->stride[0],mpi->stride[0]);
|
|
|
|
}
|
2002-04-16 00:34:04 +00:00
|
|
|
#ifdef OSD_SUPPORT
|
|
|
|
if(vf->priv->osd) draw_osd(vf,mpi->w,mpi->h);
|
|
|
|
#endif
|
2002-04-06 22:05:01 +00:00
|
|
|
vf_next_put_image(vf,vf->priv->dmpi);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================//
|
|
|
|
|
2002-04-16 00:34:04 +00:00
|
|
|
static int control(struct vf_instance_s* vf, int request, void* data){
|
|
|
|
#ifdef OSD_SUPPORT
|
|
|
|
switch(request){
|
|
|
|
case VFCTRL_DRAW_OSD:
|
|
|
|
if(vf->priv->osd) return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return vf_next_control(vf,request,data);
|
|
|
|
}
|
|
|
|
|
2002-04-06 22:05:01 +00:00
|
|
|
static int open(vf_instance_t *vf, char* args){
|
|
|
|
vf->config=config;
|
2002-04-16 00:34:04 +00:00
|
|
|
vf->control=control;
|
2002-04-06 22:05:01 +00:00
|
|
|
vf->get_image=get_image;
|
|
|
|
vf->put_image=put_image;
|
|
|
|
vf->priv=malloc(sizeof(struct vf_priv_s));
|
|
|
|
// TODO: parse args ->
|
|
|
|
vf->priv->exp_x=
|
|
|
|
vf->priv->exp_y=
|
|
|
|
vf->priv->exp_w=
|
|
|
|
vf->priv->exp_h=-1;
|
2002-04-16 00:34:04 +00:00
|
|
|
if(args) sscanf(args, "%d:%d:%d:%d:%d",
|
2002-04-06 22:05:01 +00:00
|
|
|
&vf->priv->exp_w,
|
|
|
|
&vf->priv->exp_h,
|
|
|
|
&vf->priv->exp_x,
|
2002-04-16 00:34:04 +00:00
|
|
|
&vf->priv->exp_y,
|
|
|
|
&vf->priv->osd);
|
|
|
|
printf("Expand: %d x %d, %d ; %d (-1=autodetect) osd: %d\n",
|
2002-04-06 22:05:01 +00:00
|
|
|
vf->priv->exp_w,
|
|
|
|
vf->priv->exp_h,
|
|
|
|
vf->priv->exp_x,
|
2002-04-16 00:34:04 +00:00
|
|
|
vf->priv->exp_y,
|
|
|
|
vf->priv->osd);
|
2002-04-06 22:05:01 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vf_info_t vf_info_expand = {
|
2002-04-16 00:34:04 +00:00
|
|
|
#ifdef OSD_SUPPORT
|
|
|
|
"expanding & osd",
|
|
|
|
#else
|
2002-04-06 22:05:01 +00:00
|
|
|
"expanding",
|
2002-04-16 00:34:04 +00:00
|
|
|
#endif
|
2002-04-06 22:05:01 +00:00
|
|
|
"expand",
|
|
|
|
"A'rpi",
|
|
|
|
"",
|
|
|
|
open
|
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================//
|