2010-01-30 16:57:40 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2002-04-21 17:22:37 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "mp_msg.h"
|
2002-04-21 17:22:37 +00:00
|
|
|
|
|
|
|
#include "img_format.h"
|
|
|
|
#include "mp_image.h"
|
|
|
|
#include "vf.h"
|
|
|
|
|
2006-06-30 12:00:31 +00:00
|
|
|
#include "libswscale/rgb2rgb.h"
|
2002-04-21 17:22:37 +00:00
|
|
|
|
|
|
|
//===========================================================================//
|
|
|
|
|
2003-11-23 17:09:59 +00:00
|
|
|
// commented out 16 and 15 bit output support, because the conversion
|
|
|
|
// routines are incorrrect. they assume the palette to be of the same
|
|
|
|
// depth as the output, which is incorrect. --Joey
|
|
|
|
|
2008-04-26 13:35:40 +00:00
|
|
|
static const unsigned int bgr_list[]={
|
2002-04-21 17:22:37 +00:00
|
|
|
IMGFMT_BGR32,
|
|
|
|
IMGFMT_BGR24,
|
2003-11-23 17:09:59 +00:00
|
|
|
// IMGFMT_BGR16,
|
|
|
|
// IMGFMT_BGR15,
|
2002-05-25 13:22:28 +00:00
|
|
|
0
|
2002-04-21 17:22:37 +00:00
|
|
|
};
|
2008-04-26 13:35:40 +00:00
|
|
|
static const unsigned int rgb_list[]={
|
2002-04-21 17:22:37 +00:00
|
|
|
IMGFMT_RGB32,
|
|
|
|
IMGFMT_RGB24,
|
2003-11-23 17:09:59 +00:00
|
|
|
// IMGFMT_RGB16,
|
|
|
|
// IMGFMT_RGB15,
|
2002-05-25 13:22:28 +00:00
|
|
|
0
|
2002-04-21 17:22:37 +00:00
|
|
|
};
|
|
|
|
|
2002-05-30 00:26:23 +00:00
|
|
|
static unsigned int gray_pal[256];
|
|
|
|
|
2008-04-24 02:49:44 +00:00
|
|
|
static unsigned int find_best(struct vf_instance* vf, unsigned int fmt){
|
2002-04-21 17:22:37 +00:00
|
|
|
unsigned int best=0;
|
|
|
|
int ret;
|
2008-04-26 13:35:40 +00:00
|
|
|
const unsigned int* p;
|
2002-04-21 17:22:37 +00:00
|
|
|
if(fmt==IMGFMT_BGR8) p=bgr_list;
|
|
|
|
else if(fmt==IMGFMT_RGB8) p=rgb_list;
|
|
|
|
else return 0;
|
|
|
|
while(*p){
|
|
|
|
ret=vf->next->query_format(vf->next,*p);
|
2003-02-04 17:51:39 +00:00
|
|
|
mp_msg(MSGT_VFILTER,MSGL_DBG2,"[%s] query(%s) -> %d\n",vf->info->name,vo_format_name(*p),ret&3);
|
2002-08-30 11:18:20 +00:00
|
|
|
if(ret&VFCAP_CSP_SUPPORTED_BY_HW){ best=*p; break;} // no conversion -> bingo!
|
|
|
|
if(ret&VFCAP_CSP_SUPPORTED && !best) best=*p; // best with conversion
|
2002-04-21 17:22:37 +00:00
|
|
|
++p;
|
|
|
|
}
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================//
|
|
|
|
|
|
|
|
struct vf_priv_s {
|
|
|
|
unsigned int fmt;
|
2003-02-04 17:51:39 +00:00
|
|
|
int pal_msg;
|
2002-04-21 17:22:37 +00:00
|
|
|
};
|
|
|
|
|
2008-04-24 02:49:44 +00:00
|
|
|
static int config(struct vf_instance* vf,
|
2002-04-21 17:22:37 +00:00
|
|
|
int width, int height, int d_width, int d_height,
|
|
|
|
unsigned int flags, unsigned int outfmt){
|
2002-08-30 11:18:20 +00:00
|
|
|
if (!vf->priv->fmt)
|
|
|
|
vf->priv->fmt=find_best(vf,outfmt);
|
2002-04-21 17:22:37 +00:00
|
|
|
if(!vf->priv->fmt){
|
|
|
|
// no matching fmt, so force one...
|
|
|
|
if(outfmt==IMGFMT_RGB8) vf->priv->fmt=IMGFMT_RGB32;
|
|
|
|
else if(outfmt==IMGFMT_BGR8) vf->priv->fmt=IMGFMT_BGR32;
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt);
|
|
|
|
}
|
|
|
|
|
2008-04-24 02:49:44 +00:00
|
|
|
static int put_image(struct vf_instance* vf, mp_image_t *mpi, double pts){
|
2002-04-21 17:22:37 +00:00
|
|
|
mp_image_t *dmpi;
|
2009-12-26 11:11:41 +00:00
|
|
|
uint8_t *old_palette = mpi->planes[1];
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-04-21 17:22:37 +00:00
|
|
|
// 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);
|
|
|
|
|
2002-08-30 11:18:20 +00:00
|
|
|
if (!mpi->planes[1])
|
|
|
|
{
|
2003-02-04 17:51:39 +00:00
|
|
|
if(!vf->priv->pal_msg){
|
|
|
|
mp_msg(MSGT_VFILTER,MSGL_V,"[%s] no palette given, assuming builtin grayscale one\n",vf->info->name);
|
|
|
|
vf->priv->pal_msg=1;
|
|
|
|
}
|
2002-08-30 11:18:20 +00:00
|
|
|
mpi->planes[1] = (unsigned char*)gray_pal;
|
|
|
|
}
|
2002-05-30 00:26:23 +00:00
|
|
|
|
2002-04-21 17:22:37 +00:00
|
|
|
if(mpi->w==mpi->stride[0] && dmpi->w*(dmpi->bpp>>3)==dmpi->stride[0]){
|
|
|
|
// no stride conversion needed
|
2007-09-13 18:36:04 +00:00
|
|
|
switch(IMGFMT_RGB_DEPTH(dmpi->imgfmt)){
|
2002-04-21 17:22:37 +00:00
|
|
|
case 15:
|
2007-09-13 18:36:04 +00:00
|
|
|
if (IMGFMT_IS_BGR(dmpi->imgfmt))
|
2002-08-30 11:18:20 +00:00
|
|
|
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]);
|
2002-04-21 17:22:37 +00:00
|
|
|
break;
|
|
|
|
case 16:
|
2007-09-13 18:36:04 +00:00
|
|
|
if (IMGFMT_IS_BGR(dmpi->imgfmt))
|
2002-08-30 11:18:20 +00:00
|
|
|
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]);
|
2002-04-21 17:22:37 +00:00
|
|
|
break;
|
|
|
|
case 24:
|
2007-09-13 18:36:04 +00:00
|
|
|
if (IMGFMT_IS_BGR(dmpi->imgfmt))
|
2008-10-25 00:07:59 +00:00
|
|
|
palette8topacked24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
|
2002-08-30 11:18:20 +00:00
|
|
|
else
|
2008-10-25 00:07:59 +00:00
|
|
|
palette8topacked24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
|
2002-04-21 17:22:37 +00:00
|
|
|
break;
|
|
|
|
case 32:
|
2007-09-13 18:36:04 +00:00
|
|
|
if (IMGFMT_IS_BGR(dmpi->imgfmt))
|
2008-10-25 00:07:59 +00:00
|
|
|
palette8topacked32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
|
2002-08-30 11:18:20 +00:00
|
|
|
else
|
2008-10-25 00:07:59 +00:00
|
|
|
palette8topacked32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
|
2002-04-21 17:22:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int y;
|
|
|
|
for(y=0;y<mpi->h;y++){
|
|
|
|
unsigned char* src=mpi->planes[0]+y*mpi->stride[0];
|
|
|
|
unsigned char* dst=dmpi->planes[0]+y*dmpi->stride[0];
|
2007-09-13 18:36:04 +00:00
|
|
|
switch(IMGFMT_RGB_DEPTH(dmpi->imgfmt)){
|
2002-04-21 17:22:37 +00:00
|
|
|
case 15:
|
2007-09-13 18:36:04 +00:00
|
|
|
if (IMGFMT_IS_BGR(dmpi->imgfmt))
|
2002-08-30 11:18:20 +00:00
|
|
|
palette8tobgr15(src,dst,mpi->w,mpi->planes[1]);
|
|
|
|
else
|
|
|
|
palette8torgb15(src,dst,mpi->w,mpi->planes[1]);
|
|
|
|
break;
|
2002-04-21 17:22:37 +00:00
|
|
|
case 16:
|
2007-09-13 18:36:04 +00:00
|
|
|
if (IMGFMT_IS_BGR(dmpi->imgfmt))
|
2002-08-30 11:18:20 +00:00
|
|
|
palette8tobgr16(src,dst,mpi->w,mpi->planes[1]);
|
|
|
|
else
|
|
|
|
palette8torgb16(src,dst,mpi->w,mpi->planes[1]);
|
|
|
|
break;
|
2002-04-21 17:22:37 +00:00
|
|
|
case 24:
|
2007-09-13 18:36:04 +00:00
|
|
|
if (IMGFMT_IS_BGR(dmpi->imgfmt))
|
2008-10-25 00:07:59 +00:00
|
|
|
palette8topacked24(src,dst,mpi->w,mpi->planes[1]);
|
2002-08-30 11:18:20 +00:00
|
|
|
else
|
2008-10-25 00:07:59 +00:00
|
|
|
palette8topacked24(src,dst,mpi->w,mpi->planes[1]);
|
2002-08-30 11:18:20 +00:00
|
|
|
break;
|
2002-04-21 17:22:37 +00:00
|
|
|
case 32:
|
2007-09-13 18:36:04 +00:00
|
|
|
if (IMGFMT_IS_BGR(dmpi->imgfmt))
|
2008-10-25 00:07:59 +00:00
|
|
|
palette8topacked32(src,dst,mpi->w,mpi->planes[1]);
|
2002-08-30 11:18:20 +00:00
|
|
|
else
|
2008-10-25 00:07:59 +00:00
|
|
|
palette8topacked32(src,dst,mpi->w,mpi->planes[1]);
|
2002-08-30 11:18:20 +00:00
|
|
|
break;
|
2002-04-21 17:22:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-12-26 11:11:41 +00:00
|
|
|
mpi->planes[1] = old_palette;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-03-21 21:26:42 +00:00
|
|
|
return vf_next_put_image(vf,dmpi, pts);
|
2002-04-21 17:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================//
|
|
|
|
|
2008-04-24 02:49:44 +00:00
|
|
|
static int query_format(struct vf_instance* vf, unsigned int fmt){
|
2002-04-21 17:22:37 +00:00
|
|
|
int best=find_best(vf,fmt);
|
|
|
|
if(!best) return 0; // no match
|
|
|
|
return vf->next->query_format(vf->next,best);
|
|
|
|
}
|
|
|
|
|
2004-10-14 15:09:35 +00:00
|
|
|
static void uninit(vf_instance_t *vf) {
|
|
|
|
free(vf->priv);
|
|
|
|
}
|
|
|
|
|
2010-02-21 13:40:49 +00:00
|
|
|
static int vf_open(vf_instance_t *vf, char *args){
|
2002-05-30 00:26:23 +00:00
|
|
|
unsigned int i;
|
2002-04-21 17:22:37 +00:00
|
|
|
vf->config=config;
|
2004-10-14 15:09:35 +00:00
|
|
|
vf->uninit=uninit;
|
2002-04-21 17:22:37 +00:00
|
|
|
vf->put_image=put_image;
|
|
|
|
vf->query_format=query_format;
|
|
|
|
vf->priv=malloc(sizeof(struct vf_priv_s));
|
2002-08-30 11:18:20 +00:00
|
|
|
memset(vf->priv, 0, sizeof(struct vf_priv_s));
|
2002-05-30 00:26:23 +00:00
|
|
|
for(i=0;i<256;i++) gray_pal[i]=0x01010101*i;
|
2002-08-30 11:18:20 +00:00
|
|
|
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
|
|
|
|
{
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_VFILTER, MSGL_WARN, "[VF_FORMAT] Unknown format name: '%s'.\n", args);
|
2008-05-16 00:23:02 +00:00
|
|
|
return 0;
|
2002-08-30 11:18:20 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-21 17:22:37 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-12-02 14:57:15 +00:00
|
|
|
const vf_info_t vf_info_palette = {
|
2002-04-21 17:22:37 +00:00
|
|
|
"8bpp indexed (using palette) -> BGR 15/16/24/32 conversion",
|
|
|
|
"palette",
|
2002-08-30 11:18:20 +00:00
|
|
|
"A'rpi & Alex",
|
2002-04-21 17:22:37 +00:00
|
|
|
"",
|
2010-02-21 13:40:49 +00:00
|
|
|
vf_open,
|
2003-03-15 18:01:02 +00:00
|
|
|
NULL
|
2002-04-21 17:22:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================//
|