changeset 7783:29c059774519

exporting palette for 4/8bpp modes
author arpi
date Thu, 17 Oct 2002 21:53:30 +0000
parents 4f6bbaf09dbc
children cb552fdb7b8a
files libmpcodecs/vf_scale.c
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/vf_scale.c	Thu Oct 17 21:32:35 2002 +0000
+++ b/libmpcodecs/vf_scale.c	Thu Oct 17 21:53:30 2002 +0000
@@ -19,6 +19,7 @@
     int param;
     unsigned int fmt;
     SwsContext *ctx;
+    unsigned char* palette;
 };
 
 extern int opt_screen_size_x;
@@ -162,6 +163,32 @@
     }
     vf->priv->fmt=best;
 
+    if(vf->priv->palette){
+	free(vf->priv->palette);
+	vf->priv->palette=NULL;
+    }
+    switch(best){
+    case IMGFMT_BGR8: {
+      /* set 332 palette for 8 bpp */
+	int i;
+	vf->priv->palette=malloc(4*256);
+	for(i=0; i<256; i++){
+	    vf->priv->palette[4*i+0]=4*(i&3)*21;
+	    vf->priv->palette[4*i+1]=4*((i>>2)&7)*9;
+	    vf->priv->palette[4*i+2]=4*((i>>5)&7)*9;
+	}
+	break; }
+    case IMGFMT_BGR4: {
+	int i;
+	vf->priv->palette=malloc(4*16);
+	for(i=0; i<16; i++){
+	    vf->priv->palette[4*i+0]=4*(i&1)*63;
+	    vf->priv->palette[4*i+1]=4*((i>>1)&3)*21;
+	    vf->priv->palette[4*i+2]=4*((i>>3)&1)*63;
+	}
+	break; }
+    }
+
     if(!opt_screen_size_x && !opt_screen_size_y){
 	d_width=d_width*vf->priv->w/width;
 	d_height=d_height*vf->priv->h/height;
@@ -184,6 +211,8 @@
 	dmpi->qscale=mpi->qscale;
 	dmpi->qstride=mpi->qstride;
     }
+
+    if(vf->priv->palette) dmpi->planes[1]=vf->priv->palette; // export palette!
     
     return vf_next_put_image(vf,dmpi);
 }
@@ -237,6 +266,7 @@
     vf->priv->h=-1;
     vf->priv->v_chr_drop=0;
     vf->priv->param=0;
+    vf->priv->palette=NULL;
     if(args) sscanf(args, "%d:%d:%d:%d",
     &vf->priv->w,
     &vf->priv->h,