changeset 7755:7637b72ef1f9

new filter: 1bpp - converts 1bpp image to yuv/rgb 8/16/32 bpp
author arpi
date Wed, 16 Oct 2002 18:40:03 +0000
parents 0568245deeb8
children 77076fb29637
files libmpcodecs/Makefile libmpcodecs/vf.c libmpcodecs/vf_1bpp.c
diffstat 3 files changed, 188 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/Makefile	Wed Oct 16 16:51:03 2002 +0000
+++ b/libmpcodecs/Makefile	Wed Oct 16 18:40:03 2002 +0000
@@ -6,7 +6,7 @@
 
 AUDIO_SRCS=dec_audio.c ad.c ad_liba52.c ad_acm.c ad_alaw.c ad_dk3adpcm.c ad_dshow.c ad_dvdpcm.c ad_ffmpeg.c ad_hwac3.c ad_imaadpcm.c ad_mp3lib.c ad_msadpcm.c ad_pcm.c ad_roqaudio.c ad_msgsm.c ad_faad.c ad_libvorbis.c ad_libmad.c ad_realaud.c ad_libdv.c
 VIDEO_SRCS=dec_video.c vd.c vd_null.c vd_realvid.c vd_cinepak.c vd_qtrpza.c vd_ffmpeg.c vd_dshow.c vd_vfw.c vd_vfwex.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_mpegpes.c vd_svq1.c vd_xvid.c vd_libdv.c vd_lcl.c vd_mtga.c
-VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c vf_lavc.c vf_dvbscale.c vf_cropdetect.c vf_test.c vf_noise.c vf_yvu9.c vf_rectangle.c vf_lavcdeint.c vf_eq.c vf_eq2.c vf_halfpack.c vf_dint.c
+VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c vf_lavc.c vf_dvbscale.c vf_cropdetect.c vf_test.c vf_noise.c vf_yvu9.c vf_rectangle.c vf_lavcdeint.c vf_eq.c vf_eq2.c vf_halfpack.c vf_dint.c vf_1bpp.c
 ENCODER_SRCS=ve.c ve_divx4.c ve_lavc.c ve_vfw.c ve_rawrgb.c ve_libdv.c ve_xvid.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 native/svq1.c
 
--- a/libmpcodecs/vf.c	Wed Oct 16 16:51:03 2002 +0000
+++ b/libmpcodecs/vf.c	Wed Oct 16 18:40:03 2002 +0000
@@ -42,6 +42,7 @@
 extern vf_info_t vf_info_eq2;
 extern vf_info_t vf_info_halfpack;
 extern vf_info_t vf_info_dint;
+extern vf_info_t vf_info_1bpp;
 
 char** vo_plugin_args=(char**) NULL;
 
@@ -77,6 +78,7 @@
     &vf_info_eq2,
     &vf_info_halfpack,
     &vf_info_dint,
+    &vf_info_1bpp,
     NULL
 };
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpcodecs/vf_1bpp.c	Wed Oct 16 18:40:03 2002 +0000
@@ -0,0 +1,185 @@
+#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_Y800,
+    IMGFMT_Y8,
+    IMGFMT_BGR8,
+    IMGFMT_RGB8,
+
+    IMGFMT_YVU9,
+    IMGFMT_411P,
+    IMGFMT_YV12,
+    IMGFMT_I420,
+    IMGFMT_IYUV,
+    IMGFMT_422P,
+    IMGFMT_444P,
+    
+    IMGFMT_YUY2,
+    IMGFMT_BGR15,
+    IMGFMT_RGB15,
+    IMGFMT_BGR16,
+    IMGFMT_RGB16,
+
+    IMGFMT_BGR32,
+    IMGFMT_RGB32,
+
+//    IMGFMT_BGR24,
+//    IMGFMT_RGB24,
+    0
+};
+
+static unsigned int find_best(struct vf_instance_s* vf){
+    unsigned int best=0;
+    int ret;
+    unsigned int* p=bgr_list;
+    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&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;
+}
+
+//===========================================================================//
+
+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){
+    if (!vf->priv->fmt)
+	vf->priv->fmt=find_best(vf);
+    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 int bittab[8]={128,64,32,16,8,4,2,1};
+
+static void convert(mp_image_t *mpi, mp_image_t *dmpi, int value0, int value1,int bpp){
+    int y;
+    for(y=0;y<mpi->h;y++){
+	unsigned char* src=mpi->planes[0]+mpi->stride[0]*y;
+	switch(bpp){
+	case 1: {
+	    unsigned char* dst=dmpi->planes[0]+dmpi->stride[0]*y;
+	    int x;
+	    for(x=0;x<mpi->w;x++)
+		dst[x]=(src[x>>3]&bittab[x&7]) ? value1 : value0;
+	    break; }
+	case 2: {
+	    uint16_t* dst=(uint16_t*)(dmpi->planes[0]+dmpi->stride[0]*y);
+	    int x;
+	    for(x=0;x<mpi->w;x++)
+		dst[x]=(src[x>>3]&bittab[x&7]) ? value1 : value0;
+	    break; }
+	case 4: {
+	    uint32_t* dst=(uint32_t*)(dmpi->planes[0]+dmpi->stride[0]*y);
+	    int x;
+	    for(x=0;x<mpi->w;x++)
+		dst[x]=(src[x>>3]&bittab[x&7]) ? value1 : value0;
+	    break; }
+	}
+    }
+}
+
+static int 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);
+
+    switch(dmpi->imgfmt){
+    case IMGFMT_Y800:
+    case IMGFMT_Y8:
+    case IMGFMT_BGR8:
+    case IMGFMT_RGB8:
+	convert(mpi,dmpi,0,255,1);
+	break;
+    case IMGFMT_YVU9:
+    case IMGFMT_411P:
+    case IMGFMT_YV12:
+    case IMGFMT_I420:
+    case IMGFMT_IYUV:
+    case IMGFMT_422P:
+    case IMGFMT_444P:
+	convert(mpi,dmpi,0,255,1);
+	memset(dmpi->planes[1],128,dmpi->stride[1]*dmpi->chroma_height);
+	memset(dmpi->planes[2],128,dmpi->stride[2]*dmpi->chroma_height);
+	break;
+    case IMGFMT_YUY2:
+	convert(mpi,dmpi,0x8000,0x80ff,2);
+	break;
+    case IMGFMT_BGR15:
+    case IMGFMT_RGB15:
+	convert(mpi,dmpi,0,0x7fff,2);
+	break;
+    case IMGFMT_BGR16:
+    case IMGFMT_RGB16:
+	convert(mpi,dmpi,0,0xffff,2);
+	break;
+    case IMGFMT_BGR32:
+    case IMGFMT_RGB32:
+	convert(mpi,dmpi,0,0x00ffffff,4);
+	break;
+    default:
+	mp_msg(MSGT_VFILTER,MSGL_ERR,"Unhandled format: 0x%X\n",dmpi->imgfmt);
+	return NULL;
+    }
+
+    return vf_next_put_image(vf,dmpi);
+}
+
+//===========================================================================//
+
+static int query_format(struct vf_instance_s* vf, unsigned int fmt){
+    int best;
+    if(fmt!=IMGFMT_RGB1 && fmt!=IMGFMT_BGR1) return 0;
+    best=find_best(vf);
+    if(!best) return 0; // no match
+    return vf->next->query_format(vf->next,best);
+}
+
+static int open(vf_instance_t *vf, char* args){
+    unsigned int i;
+    vf->config=config;
+    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));
+    return 1;
+}
+
+vf_info_t vf_info_1bpp = {
+    "1bpp bitmap -> YUV/BGR 8/15/16/32 conversion",
+    "1bpp",
+    "A'rpi",
+    "",
+    open
+};
+
+//===========================================================================//