added bgr support and support for forcing output format

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@7161 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
alex 2002-08-30 11:18:20 +00:00
parent 17749b3397
commit c134b4ffff
1 changed files with 62 additions and 19 deletions

View File

@ -41,8 +41,8 @@ static unsigned int find_best(struct vf_instance_s* vf, unsigned int fmt){
while(*p){
ret=vf->next->query_format(vf->next,*p);
mp_msg(MSGT_VFILTER,MSGL_V,"[%s] query(%s) -> %d\n",vf->info->name,vo_format_name(*p),ret&3);
if(ret&2){ best=*p; break;} // no conversion -> bingo!
if(ret&1 && !best) best=*p; // best with conversion
if(ret&VFCAP_CSP_SUPPORTED_BY_HW){ best=*p; break;} // no conversion -> bingo!
if(ret&VFCAP_CSP_SUPPORTED && !best) best=*p; // best with conversion
++p;
}
return best;
@ -57,7 +57,8 @@ struct vf_priv_s {
static int config(struct vf_instance_s* vf,
int width, int height, int d_width, int d_height,
unsigned int flags, unsigned int outfmt){
vf->priv->fmt=find_best(vf,outfmt);
if (!vf->priv->fmt)
vf->priv->fmt=find_best(vf,outfmt);
if(!vf->priv->fmt){
// no matching fmt, so force one...
if(outfmt==IMGFMT_RGB8) vf->priv->fmt=IMGFMT_RGB32;
@ -70,33 +71,43 @@ static int config(struct vf_instance_s* vf,
static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){
mp_image_t *dmpi;
if (!mpi->planes[1])
{
mp_msg(MSGT_VFILTER,MSGL_V,"[%s] no palette given\n",vf->info->name);
return;
}
// hope we'll get DR buffer:
dmpi=vf_get_image(vf->next,vf->priv->fmt,
MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
mpi->w, mpi->h);
if(!mpi->planes[1]) mpi->planes[1]=(unsigned char*)gray_pal;
if (!mpi->planes[1])
{
mp_msg(MSGT_VFILTER,MSGL_V,"[%s] no palette given, assuming builtin grayscale one\n",vf->info->name);
mpi->planes[1] = (unsigned char*)gray_pal;
}
if(mpi->w==mpi->stride[0] && dmpi->w*(dmpi->bpp>>3)==dmpi->stride[0]){
// no stride conversion needed
switch(dmpi->imgfmt&255){
case 15:
palette8torgb15(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
if (mpi->flags & MP_IMGFLAG_SWAPPED)
palette8tobgr15(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
else
palette8torgb15(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
break;
case 16:
palette8torgb16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
if (mpi->flags & MP_IMGFLAG_SWAPPED)
palette8tobgr16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
else
palette8torgb16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
break;
case 24:
palette8torgb24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
if (mpi->flags & MP_IMGFLAG_SWAPPED)
palette8tobgr24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
else
palette8torgb24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
break;
case 32:
palette8torgb32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
if (mpi->flags & MP_IMGFLAG_SWAPPED)
palette8tobgr32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
else
palette8torgb32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
break;
}
} else {
@ -106,13 +117,29 @@ static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){
unsigned char* dst=dmpi->planes[0]+y*dmpi->stride[0];
switch(dmpi->imgfmt&255){
case 15:
palette8torgb15(src,dst,mpi->w,mpi->planes[1]);break;
if (mpi->flags & MP_IMGFLAG_SWAPPED)
palette8tobgr15(src,dst,mpi->w,mpi->planes[1]);
else
palette8torgb15(src,dst,mpi->w,mpi->planes[1]);
break;
case 16:
palette8torgb16(src,dst,mpi->w,mpi->planes[1]);break;
if (mpi->flags & MP_IMGFLAG_SWAPPED)
palette8tobgr16(src,dst,mpi->w,mpi->planes[1]);
else
palette8torgb16(src,dst,mpi->w,mpi->planes[1]);
break;
case 24:
palette8torgb24(src,dst,mpi->w,mpi->planes[1]);break;
if (mpi->flags & MP_IMGFLAG_SWAPPED)
palette8tobgr24(src,dst,mpi->w,mpi->planes[1]);
else
palette8torgb24(src,dst,mpi->w,mpi->planes[1]);
break;
case 32:
palette8torgb32(src,dst,mpi->w,mpi->planes[1]);break;
if (mpi->flags & MP_IMGFLAG_SWAPPED)
palette8tobgr32(src,dst,mpi->w,mpi->planes[1]);
else
palette8torgb32(src,dst,mpi->w,mpi->planes[1]);
break;
}
}
}
@ -134,14 +161,30 @@ static int open(vf_instance_t *vf, char* args){
vf->put_image=put_image;
vf->query_format=query_format;
vf->priv=malloc(sizeof(struct vf_priv_s));
memset(vf->priv, 0, sizeof(struct vf_priv_s));
for(i=0;i<256;i++) gray_pal[i]=0x01010101*i;
if (args)
{
if (!strcasecmp(args,"rgb15")) vf->priv->fmt=IMGFMT_RGB15; else
if (!strcasecmp(args,"rgb16")) vf->priv->fmt=IMGFMT_RGB16; else
if (!strcasecmp(args,"rgb24")) vf->priv->fmt=IMGFMT_RGB24; else
if (!strcasecmp(args,"rgb32")) vf->priv->fmt=IMGFMT_RGB32; else
if (!strcasecmp(args,"bgr15")) vf->priv->fmt=IMGFMT_BGR15; else
if (!strcasecmp(args,"bgr16")) vf->priv->fmt=IMGFMT_BGR16; else
if (!strcasecmp(args,"bgr24")) vf->priv->fmt=IMGFMT_BGR24; else
if (!strcasecmp(args,"bgr32")) vf->priv->fmt=IMGFMT_BGR32; else
{
printf("Unknown forced format name: '%s'\n", args);
return(0);
}
}
return 1;
}
vf_info_t vf_info_palette = {
"8bpp indexed (using palette) -> BGR 15/16/24/32 conversion",
"palette",
"A'rpi",
"A'rpi & Alex",
"",
open
};