[FFmpeg-cvslog] r27817 - in trunk/libswscale: rgb2rgb.c rgb2rgb.h swscale.c

vitor subversion
Thu Oct 23 21:13:11 CEST 2008


Author: vitor
Date: Thu Oct 23 21:13:11 2008
New Revision: 27817

Log:
Fix broken palette8to*.


Modified:
   trunk/libswscale/rgb2rgb.c
   trunk/libswscale/rgb2rgb.h
   trunk/libswscale/swscale.c

Modified: trunk/libswscale/rgb2rgb.c
==============================================================================
--- trunk/libswscale/rgb2rgb.c	(original)
+++ trunk/libswscale/rgb2rgb.c	Thu Oct 23 21:13:11 2008
@@ -213,84 +213,23 @@ void sws_rgb2rgb_init(int flags){
 }
 
 /**
- * Palette is assumed to contain BGR32.
+ * Convert the palette to the same packet 32-bit format as the palette
  */
-void palette8torgb32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
+void palette8topacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
 {
     long i;
 
-/*
-    for (i=0; i<num_pixels; i++)
-        ((unsigned *)dst)[i] = ((unsigned *)palette)[src[i]];
-*/
-
-    for (i=0; i<num_pixels; i++)
-    {
-        #ifdef WORDS_BIGENDIAN
-            dst[3]= palette[src[i]*4+2];
-            dst[2]= palette[src[i]*4+1];
-            dst[1]= palette[src[i]*4+0];
-        #else
-        //FIXME slow?
-            dst[0]= palette[src[i]*4+2];
-            dst[1]= palette[src[i]*4+1];
-            dst[2]= palette[src[i]*4+0];
-            //dst[3]= 0; /* do we need this cleansing? */
-        #endif
-        dst+= 4;
-    }
-}
-
-void palette8tobgr32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
-{
-    long i;
     for (i=0; i<num_pixels; i++)
-    {
-        #ifdef WORDS_BIGENDIAN
-            dst[3]= palette[src[i]*4+0];
-            dst[2]= palette[src[i]*4+1];
-            dst[1]= palette[src[i]*4+2];
-        #else
-            //FIXME slow?
-            dst[0]= palette[src[i]*4+0];
-            dst[1]= palette[src[i]*4+1];
-            dst[2]= palette[src[i]*4+2];
-            //dst[3]= 0; /* do we need this cleansing? */
-        #endif
-
-        dst+= 4;
-    }
+        ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i]];
 }
 
 /**
- * Palette is assumed to contain BGR32.
+ * Palette format: ABCD -> dst format: ABC
  */
-void palette8torgb24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
+void palette8topacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
 {
     long i;
-/*
-    Writes 1 byte too much and might cause alignment issues on some architectures?
-    for (i=0; i<num_pixels; i++)
-        ((unsigned *)(&dst[i*3])) = ((unsigned *)palette)[src[i]];
-*/
-    for (i=0; i<num_pixels; i++)
-    {
-        //FIXME slow?
-        dst[0]= palette[src[i]*4+2];
-        dst[1]= palette[src[i]*4+1];
-        dst[2]= palette[src[i]*4+0];
-        dst+= 3;
-    }
-}
 
-void palette8tobgr24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
-{
-    long i;
-/*
-    Writes 1 byte too much and might cause alignment issues on some architectures?
-    for (i=0; i<num_pixels; i++)
-        ((unsigned *)(&dst[i*3])) = ((unsigned *)palette)[src[i]];
-*/
     for (i=0; i<num_pixels; i++)
     {
         //FIXME slow?

Modified: trunk/libswscale/rgb2rgb.h
==============================================================================
--- trunk/libswscale/rgb2rgb.h	(original)
+++ trunk/libswscale/rgb2rgb.h	Thu Oct 23 21:13:11 2008
@@ -61,10 +61,8 @@ extern void rgb15tobgr15(const uint8_t *
 extern void bgr8torgb8  (const uint8_t *src, uint8_t *dst, long src_size);
 
 
-extern void palette8torgb32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
-extern void palette8tobgr32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
-extern void palette8torgb24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
-extern void palette8tobgr24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
+extern void palette8topacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
+extern void palette8topacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
 extern void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
 extern void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
 extern void palette8torgb15(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);

Modified: trunk/libswscale/swscale.c
==============================================================================
--- trunk/libswscale/swscale.c	(original)
+++ trunk/libswscale/swscale.c	Thu Oct 23 21:13:11 2008
@@ -1729,10 +1729,12 @@ static int pal2rgbWrapper(SwsContext *c,
                sws_format_name(srcFormat), sws_format_name(dstFormat));
 
     switch(dstFormat){
-    case PIX_FMT_RGB32: conv = palette8torgb32; break;
-    case PIX_FMT_BGR32: conv = palette8tobgr32; break;
-    case PIX_FMT_RGB24: conv = palette8torgb24; break;
-    case PIX_FMT_BGR24: conv = palette8tobgr24; break;
+    case PIX_FMT_RGB32  : conv = palette8topacked32; break;
+    case PIX_FMT_BGR32  : conv = palette8topacked32; break;
+    case PIX_FMT_BGR32_1: conv = palette8topacked32; break;
+    case PIX_FMT_RGB32_1: conv = palette8topacked32; break;
+    case PIX_FMT_RGB24  : conv = palette8topacked24; break;
+    case PIX_FMT_BGR24  : conv = palette8topacked24; break;
     default: av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
                     sws_format_name(srcFormat), sws_format_name(dstFormat)); break;
     }
@@ -2343,8 +2345,10 @@ SwsContext *sws_getContext(int srcW, int
 
         if ((usePal(srcFormat) && (
                  dstFormat == PIX_FMT_RGB32 ||
+                 dstFormat == PIX_FMT_RGB32_1 ||
                  dstFormat == PIX_FMT_RGB24 ||
                  dstFormat == PIX_FMT_BGR32 ||
+                 dstFormat == PIX_FMT_BGR32_1 ||
                  dstFormat == PIX_FMT_BGR24)))
              c->swScale= pal2rgbWrapper;
 
@@ -2739,7 +2743,34 @@ int sws_scale(SwsContext *c, uint8_t* sr
             u= av_clip_uint8((RU*r + GU*g + BU*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT);
             v= av_clip_uint8((RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT);
             c->pal_yuv[i]= y + (u<<8) + (v<<16);
-            c->pal_rgb[i]= b + (g<<8) + (r<<16);
+
+
+            switch(c->dstFormat) {
+            case PIX_FMT_BGR32:
+#ifndef WORDS_BIGENDIAN
+            case PIX_FMT_RGB24:
+#endif
+                c->pal_rgb[i]=  r + (g<<8) + (b<<16);
+                break;
+            case PIX_FMT_BGR32_1:
+#ifdef  WORDS_BIGENDIAN
+            case PIX_FMT_BGR24:
+#endif
+                c->pal_rgb[i]= (r + (g<<8) + (b<<16)) << 8;
+                break;
+            case PIX_FMT_RGB32_1:
+#ifdef  WORDS_BIGENDIAN
+            case PIX_FMT_RGB24:
+#endif
+                c->pal_rgb[i]= (b + (g<<8) + (r<<16)) << 8;
+                break;
+            case PIX_FMT_RGB32:
+#ifndef WORDS_BIGENDIAN
+            case PIX_FMT_BGR24:
+#endif
+            default:
+                c->pal_rgb[i]=  b + (g<<8) + (r<<16);
+            }
         }
     }
 




More information about the ffmpeg-cvslog mailing list