summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-04-21 17:22:37 +0000
committerarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-04-21 17:22:37 +0000
commit260f6aec1d537de8e85e58b8a03c31183c939e0d (patch)
tree1fcddd14c55f36f8495fcff9a944b1100a71b495
parent08465f819d20030aebfaafa2d19a7a132e0d489f (diff)
downloadmpv-260f6aec1d537de8e85e58b8a03c31183c939e0d.tar.bz2
mpv-260f6aec1d537de8e85e58b8a03c31183c939e0d.tar.xz
8bpp paletted -> 15/16/24/32 converter
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@5775 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r--libmpcodecs/Makefile2
-rw-r--r--libmpcodecs/vf.c2
-rw-r--r--libmpcodecs/vf_palette.c137
3 files changed, 140 insertions, 1 deletions
diff --git a/libmpcodecs/Makefile b/libmpcodecs/Makefile
index 87f1922c29..39dc92ecd7 100644
--- a/libmpcodecs/Makefile
+++ b/libmpcodecs/Makefile
@@ -6,7 +6,7 @@ LIBNAME2 = libmpencoders.a
AUDIO_SRCS=dec_audio.c ad.c ad_a52.c ad_acm.c ad_alaw.c ad_dk3adpcm.c ad_dk4adpcm.c ad_dshow.c ad_dvdpcm.c ad_ffmpeg.c ad_hwac3.c ad_imaadpcm.c ad_mp3.c ad_msadpcm.c ad_pcm.c ad_roqaudio.c ad_msgsm.c ad_faad.c ad_vorbis.c ad_libmad.c
VIDEO_SRCS=dec_video.c vd.c vd_null.c vd_cinepak.c vd_qtrpza.c vd_ffmpeg.c vd_dshow.c vd_vfw.c vd_odivx.c vd_divx4.c vd_raw.c vd_xanim.c vd_msvidc.c vd_fli.c vd_qtrle.c vd_qtsmc.c vd_roqvideo.c vd_cyuv.c vd_nuv.c vd_libmpeg2.c vd_msrle.c vd_huffyuv.c vd_zlib.c vd_mpegpes.c
-VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_fame.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c
+VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_fame.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c
ENCODER_SRCS=ve.c ve_divx4.c ve_lavc.c ve_vfw.c ve_rawrgb.c ve_libdv.c
NATIVE_SRCS=native/RTjpegN.c native/cinepak.c native/cyuv.c native/fli.c native/minilzo.c native/msvidc.c native/nuppelvideo.c native/qtrle.c native/qtrpza.c native/qtsmc.c native/roqav.c native/xa_gsm.c
diff --git a/libmpcodecs/vf.c b/libmpcodecs/vf.c
index 7cd7707ced..fb48e4f7b6 100644
--- a/libmpcodecs/vf.c
+++ b/libmpcodecs/vf.c
@@ -21,6 +21,7 @@ extern vf_info_t vf_info_flip;
extern vf_info_t vf_info_rgb2bgr;
extern vf_info_t vf_info_rotate;
extern vf_info_t vf_info_mirror;
+extern vf_info_t vf_info_palette;
char** vo_plugin_args=(char**) NULL;
@@ -39,6 +40,7 @@ static vf_info_t* filter_list[]={
&vf_info_rgb2bgr,
&vf_info_rotate,
&vf_info_mirror,
+ &vf_info_palette,
NULL
};
diff --git a/libmpcodecs/vf_palette.c b/libmpcodecs/vf_palette.c
new file mode 100644
index 0000000000..96810b70b2
--- /dev/null
+++ b/libmpcodecs/vf_palette.c
@@ -0,0 +1,137 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "../config.h"
+#include "../mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "../postproc/rgb2rgb.h"
+
+//===========================================================================//
+
+static unsigned int bgr_list[]={
+ IMGFMT_BGR32,
+ IMGFMT_BGR24,
+ IMGFMT_BGR16,
+ IMGFMT_BGR15,
+ NULL
+};
+static unsigned int rgb_list[]={
+ IMGFMT_RGB32,
+ IMGFMT_RGB24,
+ IMGFMT_RGB16,
+ IMGFMT_RGB15,
+ NULL
+};
+
+static unsigned int find_best(struct vf_instance_s* vf, unsigned int fmt){
+ unsigned int best=0;
+ int ret;
+ unsigned int* p;
+ 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);
+ 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
+ ++p;
+ }
+ return best;
+}
+
+//===========================================================================//
+
+struct vf_priv_s {
+ unsigned int fmt;
+};
+
+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){
+ // 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);
+}
+
+static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){
+ mp_image_t *dmpi;
+
+ // 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->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]);
+ break;
+ case 16:
+ 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]);
+ break;
+ case 32:
+ palette8torgb32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
+ 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];
+ switch(dmpi->imgfmt&255){
+ case 15:
+ palette8torgb15(src,dst,mpi->w,mpi->planes[1]);break;
+ case 16:
+ palette8torgb16(src,dst,mpi->w,mpi->planes[1]);break;
+ case 24:
+ palette8torgb24(src,dst,mpi->w,mpi->planes[1]);break;
+ case 32:
+ palette8torgb32(src,dst,mpi->w,mpi->planes[1]);break;
+ }
+ }
+ }
+
+ vf_next_put_image(vf,dmpi);
+}
+
+//===========================================================================//
+
+static int query_format(struct vf_instance_s* vf, unsigned int fmt){
+ int best=find_best(vf,fmt);
+ if(!best) return 0; // no match
+ return vf->next->query_format(vf->next,best);
+}
+
+static int open(vf_instance_t *vf, char* args){
+ vf->config=config;
+ vf->put_image=put_image;
+ vf->query_format=query_format;
+ vf->priv=malloc(sizeof(struct vf_priv_s));
+ return 1;
+}
+
+vf_info_t vf_info_palette = {
+ "8bpp indexed (using palette) -> BGR 15/16/24/32 conversion",
+ "palette",
+ "A'rpi",
+ "",
+ open
+};
+
+//===========================================================================//