[FFmpeg-devel] [PATCH] Initialize full palette.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Wed Jan 18 22:44:10 CET 2012


This fixes FATE warnings since swscale always
processes the full palette even when only some
entries are used.
However there must also be some real issues in the
ansi and cdgraphics decoders, since their output
changes even though only palette entries change that
are supposed to be unused.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
---
 libavcodec/ansi.c         |    2 ++
 libavcodec/avs.c          |    6 ++++++
 libavcodec/cdgraphics.c   |    8 +++++++-
 libavcodec/tmv.c          |    1 +
 tests/ref/fate/ansi       |    6 +++---
 tests/ref/fate/cdgraphics |   32 ++++++++++++++++----------------
 6 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/libavcodec/ansi.c b/libavcodec/ansi.c
index ebcc288..5828ef2 100644
--- a/libavcodec/ansi.c
+++ b/libavcodec/ansi.c
@@ -229,6 +229,7 @@ static int execute_code(AVCodecContext * avctx, int c)
             }
             s->frame.pict_type           = AV_PICTURE_TYPE_I;
             s->frame.palette_has_changed = 1;
+            memset(s->frame.data[1], 0, AVPALETTE_SIZE);
             memcpy(s->frame.data[1], ff_cga_palette, 16 * 4);
             erase_screen(avctx);
         } else if (c == 'l') {
@@ -326,6 +327,7 @@ static int decode_frame(AVCodecContext *avctx,
     }
     s->frame.pict_type           = AV_PICTURE_TYPE_I;
     s->frame.palette_has_changed = 1;
+    memset(s->frame.data[1], 0, AVPALETTE_SIZE);
     memcpy(s->frame.data[1], ff_cga_palette, 16 * 4);
 
     while(buf < buf_end) {
diff --git a/libavcodec/avs.c b/libavcodec/avs.c
index 05cb815..6089a8e 100644
--- a/libavcodec/avs.c
+++ b/libavcodec/avs.c
@@ -25,6 +25,7 @@
 
 typedef struct {
     AVFrame picture;
+    int first_frame;
 } AvsContext;
 
 typedef enum {
@@ -63,6 +64,10 @@ avs_decode_frame(AVCodecContext * avctx,
         av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
         return -1;
     }
+    if (avs->first_frame) {
+        memset(avs->picture.data[1], 0, AVPALETTE_SIZE);
+        avs->first_frame = 0;
+    }
     p->reference = 3;
     p->pict_type = AV_PICTURE_TYPE_P;
     p->key_frame = 0;
@@ -162,6 +167,7 @@ static av_cold int avs_decode_init(AVCodecContext * avctx)
     AvsContext *const avs = avctx->priv_data;
     avctx->pix_fmt = PIX_FMT_PAL8;
     avcodec_get_frame_defaults(&avs->picture);
+    avs->first_frame = 1;
     return 0;
 }
 
diff --git a/libavcodec/cdgraphics.c b/libavcodec/cdgraphics.c
index b87ca1d..600a1f7 100644
--- a/libavcodec/cdgraphics.c
+++ b/libavcodec/cdgraphics.c
@@ -66,6 +66,7 @@ typedef struct CDGraphicsContext {
     AVFrame frame;
     int hscroll;
     int vscroll;
+    int first_frame;
 } CDGraphicsContext;
 
 static void cdg_init_frame(AVFrame *frame)
@@ -83,6 +84,7 @@ static av_cold int cdg_decode_init(AVCodecContext *avctx)
     CDGraphicsContext *cc = avctx->priv_data;
 
     cdg_init_frame(&cc->frame);
+    cc->first_frame = 1;
 
     avctx->width   = CDG_FULL_WIDTH;
     avctx->height  = CDG_FULL_HEIGHT;
@@ -238,7 +240,7 @@ static void cdg_scroll(CDGraphicsContext *cc, uint8_t *data,
     if (!hinc && !vinc)
         return;
 
-    memcpy(new_frame->data[1], cc->frame.data[1], CDG_PALETTE_SIZE * 4);
+    memcpy(new_frame->data[1], cc->frame.data[1], AVPALETTE_SIZE);
 
     for (y = FFMAX(0, vinc); y < FFMIN(CDG_FULL_HEIGHT + vinc, CDG_FULL_HEIGHT); y++)
         memcpy(out + FFMAX(0, hinc) + stride * y,
@@ -286,6 +288,10 @@ static int cdg_decode_frame(AVCodecContext *avctx,
         av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
         return ret;
     }
+    if (cc->first_frame) {
+        memset(cc->frame.data[1], 0, AVPALETTE_SIZE);
+        cc->first_frame = 0;
+    }
 
     command = bytestream_get_byte(&buf);
     inst    = bytestream_get_byte(&buf);
diff --git a/libavcodec/tmv.c b/libavcodec/tmv.c
index 7eb9b69..bcca44f 100644
--- a/libavcodec/tmv.c
+++ b/libavcodec/tmv.c
@@ -64,6 +64,7 @@ static int tmv_decode_frame(AVCodecContext *avctx, void *data,
     dst                = tmv->pic.data[0];
 
     tmv->pic.palette_has_changed = 1;
+    memset(tmv->pic.data[1], 0, AVPALETTE_SIZE);
     memcpy(tmv->pic.data[1], ff_cga_palette, 16 * 4);
 
     for (y = 0; y < char_rows; y++) {
diff --git a/tests/ref/fate/ansi b/tests/ref/fate/ansi
index bb9f35f..09c51a4 100644
--- a/tests/ref/fate/ansi
+++ b/tests/ref/fate/ansi
@@ -1,6 +1,6 @@
-0, 0, 768000, 0x3032d0de
-0, 3600, 768000, 0xc3be5922
-0, 7200, 768000, 0xf530c476
+0, 0, 768000, 0x772dd3d0
+0, 3600, 768000, 0xd7dab1d1
+0, 7200, 768000, 0x0e56f2d3
 0, 10800, 768000, 0x11c1fb8e
 0, 14400, 768000, 0x72d12da9
 0, 18000, 768000, 0x39c7a70d
diff --git a/tests/ref/fate/cdgraphics b/tests/ref/fate/cdgraphics
index 10873fd..5f6eb39 100644
--- a/tests/ref/fate/cdgraphics
+++ b/tests/ref/fate/cdgraphics
@@ -1,19 +1,19 @@
-0, 0, 194400, 0xd919c635
-0, 300, 194400, 0xd919c635
-0, 600, 194400, 0x516a1007
-0, 900, 194400, 0x516a1007
-0, 1200, 194400, 0x516a1007
-0, 1500, 194400, 0x516a1007
-0, 1800, 194400, 0x516a1007
-0, 2100, 194400, 0x516a1007
-0, 2400, 194400, 0x516a1007
-0, 2700, 194400, 0x516a1007
-0, 3000, 194400, 0x516a1007
-0, 3300, 194400, 0x516a1007
-0, 3600, 194400, 0x516a1007
-0, 3900, 194400, 0x516a1007
-0, 4200, 194400, 0x516a1007
-0, 4500, 194400, 0x516a1007
+0, 0, 194400, 0x00000000
+0, 300, 194400, 0x00000000
+0, 600, 194400, 0x8036fcfc
+0, 900, 194400, 0x8036fcfc
+0, 1200, 194400, 0x8036fcfc
+0, 1500, 194400, 0x8036fcfc
+0, 1800, 194400, 0x8036fcfc
+0, 2100, 194400, 0x8036fcfc
+0, 2400, 194400, 0x8036fcfc
+0, 2700, 194400, 0x8036fcfc
+0, 3000, 194400, 0x8036fcfc
+0, 3300, 194400, 0x8036fcfc
+0, 3600, 194400, 0x8036fcfc
+0, 3900, 194400, 0x8036fcfc
+0, 4200, 194400, 0x8036fcfc
+0, 4500, 194400, 0x8036fcfc
 0, 4800, 194400, 0x46ad80da
 0, 5100, 194400, 0x46ad80da
 0, 5400, 194400, 0x46ad80da
-- 
1.7.8.3



More information about the ffmpeg-devel mailing list