changeset 22218:ff7aa2aecb9d

pal8 input this is not optimized or anything (that is easy to add just use the existing unscaled converters if possible ...)
author michael
date Fri, 16 Feb 2007 21:17:15 +0000
parents ba8959b13a1a
children 7f6edf51bc14
files libswscale/swscale.c libswscale/swscale_template.c
diffstat 2 files changed, 54 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libswscale/swscale.c	Fri Feb 16 19:18:52 2007 +0000
+++ b/libswscale/swscale.c	Fri Feb 16 21:17:15 2007 +0000
@@ -22,7 +22,7 @@
  */
 
 /*
-  supported Input formats: YV12, I420/IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8/Y800, YVU9/IF09
+  supported Input formats: YV12, I420/IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8/Y800, YVU9/IF09, PAL8
   supported output formats: YV12, I420/IYUV, YUY2, UYVY, {BGR,RGB}{1,4,8,15,16,24,32}, Y8/Y800, YVU9/IF09
   {BGR,RGB}{1,4,8,15,16} support dithering
   
@@ -107,7 +107,8 @@
 			|| (x)==PIX_FMT_BGR32|| (x)==PIX_FMT_RGB24|| (x)==PIX_FMT_RGB565|| (x)==PIX_FMT_RGB555\
 			|| (x)==PIX_FMT_GRAY8 || (x)==PIX_FMT_YUV410P\
 			|| (x)==PIX_FMT_GRAY16BE || (x)==PIX_FMT_GRAY16LE\
-			|| (x)==PIX_FMT_YUV444P || (x)==PIX_FMT_YUV422P || (x)==PIX_FMT_YUV411P)
+			|| (x)==PIX_FMT_YUV444P || (x)==PIX_FMT_YUV422P || (x)==PIX_FMT_YUV411P\
+			|| (x)==PIX_FMT_PAL8 || (x)==PIX_FMT_BGR8 || (x)==PIX_FMT_RGB8)
 #define isSupportedOut(x) ((x)==PIX_FMT_YUV420P || (x)==PIX_FMT_YUYV422 || (x)==PIX_FMT_UYVY422\
 			|| (x)==PIX_FMT_YUV444P || (x)==PIX_FMT_YUV422P || (x)==PIX_FMT_YUV411P\
 			|| isRGB(x) || isBGR(x)\
--- a/libswscale/swscale_template.c	Fri Feb 16 19:18:52 2007 +0000
+++ b/libswscale/swscale_template.c	Fri Feb 16 21:17:15 2007 +0000
@@ -2279,6 +2279,38 @@
 	}
 }
 
+static inline void RENAME(palToY)(uint8_t *dst, uint8_t *src, int width, uint32_t *pal)
+{
+	int i;
+	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;
+	}
+}
+
+static inline void RENAME(palToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width, uint32_t *pal)
+{
+	int i;
+        assert(src1 == src2);
+	for(i=0; i<width; i++)
+	{
+		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;
+	}
+}
+
 // Bilinear / Bicubic scaling
 static inline void RENAME(hScale)(int16_t *dst, int dstW, uint8_t *src, int srcW, int xInc,
 				  int16_t *filter, int16_t *filterPos, long filterSize)
@@ -2467,7 +2499,7 @@
 				   int flags, int canMMX2BeUsed, int16_t *hLumFilter,
 				   int16_t *hLumFilterPos, int hLumFilterSize, void *funnyYCode, 
 				   int srcFormat, uint8_t *formatConvBuffer, int16_t *mmx2Filter,
-				   int32_t *mmx2FilterPos)
+				   int32_t *mmx2FilterPos, uint8_t *pal)
 {
     if(srcFormat==PIX_FMT_YUYV422 || srcFormat==PIX_FMT_GRAY16BE)
     {
@@ -2519,6 +2551,11 @@
 	RENAME(rgb15ToY)(formatConvBuffer, src, srcW);
 	src= formatConvBuffer;
     }
+    else if(srcFormat==PIX_FMT_RGB8 || srcFormat==PIX_FMT_BGR8 || srcFormat==PIX_FMT_PAL8)
+    {
+	RENAME(palToY)(formatConvBuffer, src, srcW, pal);
+	src= formatConvBuffer;
+    }
 
 #ifdef HAVE_MMX
 	// use the new MMX scaler if the mmx2 can't be used (its faster than the x86asm one)
@@ -2664,7 +2701,7 @@
 				   int srcW, int xInc, int flags, int canMMX2BeUsed, int16_t *hChrFilter,
 				   int16_t *hChrFilterPos, int hChrFilterSize, void *funnyUVCode,
 				   int srcFormat, uint8_t *formatConvBuffer, int16_t *mmx2Filter,
-				   int32_t *mmx2FilterPos)
+				   int32_t *mmx2FilterPos, uint8_t *pal)
 {
     if(srcFormat==PIX_FMT_YUYV422)
     {
@@ -2730,6 +2767,12 @@
     {
     	return;
     }
+    else if(srcFormat==PIX_FMT_RGB8 || srcFormat==PIX_FMT_BGR8 || srcFormat==PIX_FMT_PAL8)
+    {
+	RENAME(palToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW, pal);
+	src1= formatConvBuffer;
+	src2= formatConvBuffer+2048;
+    }
 
 #ifdef HAVE_MMX
 	// use the new MMX scaler if the mmx2 can't be used (its faster than the x86asm one)
@@ -2932,6 +2975,7 @@
 	const int chrSrcSliceY= srcSliceY >> c->chrSrcVSubSample;
 	const int chrSrcSliceH= -((-srcSliceH) >> c->chrSrcVSubSample);
 	int lastDstY;
+        uint8_t *pal=NULL;
 
 	/* vars whch will change and which we need to storw back in the context */
 	int dstY= c->dstY;
@@ -2941,6 +2985,7 @@
 	int lastInChrBuf= c->lastInChrBuf;
 	
 	if(isPacked(c->srcFormat)){
+                pal= src[1];
 		src[0]=
 		src[1]=
 		src[2]= src[0];
@@ -3026,7 +3071,7 @@
 				RENAME(hyscale)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc,
 						flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize,
 						funnyYCode, c->srcFormat, formatConvBuffer, 
-						c->lumMmx2Filter, c->lumMmx2FilterPos);
+						c->lumMmx2Filter, c->lumMmx2FilterPos, pal);
 				lastInLumBuf++;
 			}
 			while(lastInChrBuf < lastChrSrcY)
@@ -3043,7 +3088,7 @@
 					RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, chrSrcW, chrXInc,
 						flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize,
 						funnyUVCode, c->srcFormat, formatConvBuffer, 
-						c->chrMmx2Filter, c->chrMmx2FilterPos);
+						c->chrMmx2Filter, c->chrMmx2FilterPos, pal);
 				lastInChrBuf++;
 			}
 			//wrap buf index around to stay inside the ring buffer
@@ -3068,7 +3113,7 @@
 				RENAME(hyscale)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc,
 						flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize,
 						funnyYCode, c->srcFormat, formatConvBuffer, 
-						c->lumMmx2Filter, c->lumMmx2FilterPos);
+						c->lumMmx2Filter, c->lumMmx2FilterPos, pal);
 				lastInLumBuf++;
 			}
 			while(lastInChrBuf+1 < (chrSrcSliceY + chrSrcSliceH))
@@ -3084,7 +3129,7 @@
 					RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, chrSrcW, chrXInc,
 						flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize,
 						funnyUVCode, c->srcFormat, formatConvBuffer, 
-						c->chrMmx2Filter, c->chrMmx2FilterPos);
+						c->chrMmx2Filter, c->chrMmx2FilterPos, pal);
 				lastInChrBuf++;
 			}
 			//wrap buf index around to stay inside the ring buffer