changeset 22975:c91bb8f1cd85

convert palette to yuv instead of converting each pixel after pal->rgb
author michael
date Sun, 15 Apr 2007 00:53:32 +0000
parents 30341a2c2179
children d581a6ba2d9c
files libswscale/swscale.c libswscale/swscale_template.c
diffstat 2 files changed, 25 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/libswscale/swscale.c	Sat Apr 14 10:52:40 2007 +0000
+++ b/libswscale/swscale.c	Sun Apr 15 00:53:32 2007 +0000
@@ -2438,6 +2438,9 @@
  */
 int sws_scale(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
                            int srcSliceH, uint8_t* dst[], int dstStride[]){
+        int i;
+        uint8_t* src2[4]= {src[0], src[1], src[2]};
+        uint32_t pal[256];
 	if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) {
 	    av_log(c, AV_LOG_ERROR, "swScaler: slices start in the middle!\n");
 	    return 0;
@@ -2446,24 +2449,38 @@
 	    if (srcSliceY == 0) c->sliceDir = 1; else c->sliceDir = -1;
 	}
 
+        if(c->srcFormat == PIX_FMT_PAL8){
+                for(i=0; i<256; i++){
+                        int p= ((uint32_t*)(src[1]))[i];
+                        int r= (p>>16)&0xFF;
+                        int g= (p>> 8)&0xFF;
+                        int b=  p     &0xFF;
+                        int y= av_clip_uint8(((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16 );
+                        int u= av_clip_uint8(((RU*r + GU*g + BU*b)>>RGB2YUV_SHIFT) + 128);
+                        int v= av_clip_uint8(((RV*r + GV*g + BV*b)>>RGB2YUV_SHIFT) + 128);
+                        pal[i]= y + (u<<8) + (v<<16);
+                }
+                src2[1]= pal;
+        }
+
 	// copy strides, so they can safely be modified
 	if (c->sliceDir == 1) {
-            uint8_t* src2[4]= {src[0], src[1], src[2]};
 	    // slices go from top to bottom
 	    int srcStride2[4]= {srcStride[0], srcStride[1], srcStride[2]};
 	    int dstStride2[4]= {dstStride[0], dstStride[1], dstStride[2]};
 	    return c->swScale(c, src2, srcStride2, srcSliceY, srcSliceH, dst, dstStride2);
 	} else {
 	    // slices go from bottom to top => we flip the image internally
-	    uint8_t* src2[4]= {src[0] + (srcSliceH-1)*srcStride[0],
-			       src[1] + ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[1],
-			       src[2] + ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[2]
-	    };
 	    uint8_t* dst2[4]= {dst[0] + (c->dstH-1)*dstStride[0],
 			       dst[1] + ((c->dstH>>c->chrDstVSubSample)-1)*dstStride[1],
 			       dst[2] + ((c->dstH>>c->chrDstVSubSample)-1)*dstStride[2]};
 	    int srcStride2[4]= {-srcStride[0], -srcStride[1], -srcStride[2]};
 	    int dstStride2[4]= {-dstStride[0], -dstStride[1], -dstStride[2]};
+
+            src2[0] += (srcSliceH-1)*srcStride[0];
+            if(c->srcFormat != PIX_FMT_PAL8)
+                    src2[1] += ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[1];
+            src2[2] += ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[2];
 	    
 	    return c->swScale(c, src2, srcStride2, c->srcH-srcSliceY-srcSliceH, srcSliceH, dst2, dstStride2);
 	}
--- a/libswscale/swscale_template.c	Sat Apr 14 10:52:40 2007 +0000
+++ b/libswscale/swscale_template.c	Sun Apr 15 00:53:32 2007 +0000
@@ -2285,11 +2285,8 @@
 	for(i=0; i<width; i++)
 	{
 		int d= src[i];
-		int b= pal[d]     &0xFF;
-		int g=(pal[d]>>8 )&0xFF;
-		int r= pal[d]>>16;
 
-		dst[i]= ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16;
+		dst[i]= pal[d] & 0xFF;
 	}
 }
 
@@ -2302,12 +2299,9 @@
 		int d0= src1[2*i  ];
 		int d1= src1[2*i+1];
                 int p = (pal[d0]&0xFF00FF) + (pal[d1]&0xFF00FF);
-                int g = (pal[d0]+pal[d1]-p)>>8;
-                int b= p&0x1FF;
-                int r= p>>16;
 
-		dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1)) + 128;
-		dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128;
+		dstU[i]= (pal[d0]+pal[d1]-p)>>9;
+		dstV[i]= p>>17;
 	}
 }