[FFmpeg-devel] [PATCH] lsws: add and use use_pal field in ff_sws_format_entries

Stefano Sabatini stefano.sabatini-lala at poste.it
Thu Jul 28 13:27:21 CEST 2011


Change the usePal() macro accordingly, and add an hasPal() macro to
distinguish when the format *uses* a palette internally, and *has* a
palette in data.
---
 libswscale/swscale_internal.h |    4 +++-
 libswscale/swscale_unscaled.c |    4 ++--
 libswscale/utils.c            |   18 +++++++++---------
 3 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index e39bb31..39e1f54 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -59,6 +59,7 @@ struct SwsContext;
 
 typedef struct SwsFormatEntry {
     int is_supported_in, is_supported_out;
+    int use_pal; ///< use palette internally
 } SwsFormatEntry;
 
 extern const SwsFormatEntry ff_sws_format_entries[];
@@ -660,7 +661,8 @@ const char *sws_format_name(enum PixelFormat format);
         || (x)==PIX_FMT_Y400A       \
         || isAnyRGB(x)              \
     )
-#define usePal(x) ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) || (x) == PIX_FMT_GRAY8A)
+#define usePal(x) (ff_sws_format_entries[x].use_pal)
+#define hasPal(x) (av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL)
 
 extern const uint64_t ff_dither4[2];
 extern const uint64_t ff_dither8[2];
diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
index 7ffe84a..09f9d1c 100644
--- a/libswscale/swscale_unscaled.c
+++ b/libswscale/swscale_unscaled.c
@@ -662,7 +662,7 @@ static void reset_ptr(const uint8_t* src[], int format)
     if(!isPlanarYUV(format)) {
         src[3]=src[2]=NULL;
 
-        if (!usePal(format))
+        if (!hasPal(format))
             src[1]= NULL;
     }
 }
@@ -798,7 +798,7 @@ int sws_scale(struct SwsContext *c, const uint8_t* const srcSlice[],
         int dstStride2[4]= {-dstStride[0], -dstStride[1], -dstStride[2], -dstStride[3]};
 
         src2[0] += (srcSliceH-1)*srcStride[0];
-        if (!usePal(c->srcFormat))
+        if (!hasPal(c->srcFormat))
             src2[1] += ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[1];
         src2[2] += ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[2];
         src2[3] += (srcSliceH-1)*srcStride[3];
diff --git a/libswscale/utils.c b/libswscale/utils.c
index bcbab9a..f7605a6 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -75,21 +75,21 @@ const SwsFormatEntry ff_sws_format_entries[PIX_FMT_NB] = {
     [PIX_FMT_YUV444P]     = { 1 , 1 },
     [PIX_FMT_YUV410P]     = { 1 , 1 },
     [PIX_FMT_YUV411P]     = { 1 , 1 },
-    [PIX_FMT_GRAY8]       = { 1 , 1 },
+    [PIX_FMT_GRAY8]       = { 1 , 1, .use_pal = 1 },
     [PIX_FMT_MONOWHITE]   = { 1 , 1 },
     [PIX_FMT_MONOBLACK]   = { 1 , 1 },
-    [PIX_FMT_PAL8]        = { 1 , 0 },
+    [PIX_FMT_PAL8]        = { 1 , 0, .use_pal = 1 },
     [PIX_FMT_YUVJ420P]    = { 1 , 1 },
     [PIX_FMT_YUVJ422P]    = { 1 , 1 },
     [PIX_FMT_YUVJ444P]    = { 1 , 1 },
     [PIX_FMT_UYVY422]     = { 1 , 1 },
     [PIX_FMT_UYYVYY411]   = { 0 , 0 },
-    [PIX_FMT_BGR8]        = { 1 , 1 },
-    [PIX_FMT_BGR4]        = { 0 , 1 },
-    [PIX_FMT_BGR4_BYTE]   = { 1 , 1 },
-    [PIX_FMT_RGB8]        = { 1 , 1 },
-    [PIX_FMT_RGB4]        = { 0 , 1 },
-    [PIX_FMT_RGB4_BYTE]   = { 1 , 1 },
+    [PIX_FMT_BGR8]        = { 1 , 1, .use_pal = 1 },
+    [PIX_FMT_BGR4]        = { 0 , 1, .use_pal = 1 },
+    [PIX_FMT_BGR4_BYTE]   = { 1 , 1, .use_pal = 1 },
+    [PIX_FMT_RGB8]        = { 1 , 1, .use_pal = 1 },
+    [PIX_FMT_RGB4]        = { 0 , 1, .use_pal = 1 },
+    [PIX_FMT_RGB4_BYTE]   = { 1 , 1, .use_pal = 1 },
     [PIX_FMT_NV12]        = { 1 , 1 },
     [PIX_FMT_NV21]        = { 1 , 1 },
     [PIX_FMT_ARGB]        = { 1 , 1 },
@@ -121,7 +121,7 @@ const SwsFormatEntry ff_sws_format_entries[PIX_FMT_NB] = {
     [PIX_FMT_RGB444BE]    = { 0 , 1 },
     [PIX_FMT_BGR444LE]    = { 0 , 1 },
     [PIX_FMT_BGR444BE]    = { 0 , 1 },
-    [PIX_FMT_GRAY8A]      = { 1 , 0 },
+    [PIX_FMT_GRAY8A]      = { 1 , 0, .use_pal = 1 },
     [PIX_FMT_BGR48BE]     = { 1 , 1 },
     [PIX_FMT_BGR48LE]     = { 1 , 1 },
     [PIX_FMT_YUV420P9BE]  = { 1 , 1 },
-- 
1.7.2.5



More information about the ffmpeg-devel mailing list