[Mplayer-cvslog] CVS: main/libmpcodecs vf_palette.c,1.5,1.6

Alex Beregszaszi alex at mplayerhq.hu
Fri Aug 30 13:18:23 CEST 2002


Update of /cvsroot/mplayer/main/libmpcodecs
In directory mail:/var/tmp.root/cvs-serv15752

Modified Files:
	vf_palette.c 
Log Message:
added bgr support and support for forcing output format

Index: vf_palette.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/vf_palette.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- vf_palette.c	28 Aug 2002 22:45:44 -0000	1.5
+++ vf_palette.c	30 Aug 2002 11:18:20 -0000	1.6
@@ -41,8 +41,8 @@
     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 @@
 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 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 @@
 	    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 @@
     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
 };




More information about the MPlayer-cvslog mailing list