[FFmpeg-cvslog] webp: Fix alpha initialisation

Mark Thompson git at videolan.org
Thu Dec 28 02:03:59 EET 2017


ffmpeg | branch: master | Mark Thompson <sw at jkqxz.net> | Thu Oct 26 00:18:42 2017 +0100| [57623cba1301ee7874687dd7e04c611051638e9d] | committer: Mark Thompson

webp: Fix alpha initialisation

ff_get_format() in the next patch will reject formats which aren't in the
offered list, so the hack in 7cb9296db872c4221453e5411f242ebcfca62664 is
no longer valid.  Change the hack by adding a new field in the VP8 decoder
context to indicate that it's actually WebP and don't call ff_get_format()
at all in that case.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=57623cba1301ee7874687dd7e04c611051638e9d
---

 libavcodec/vp8.c  |  4 +++-
 libavcodec/vp8.h  |  1 +
 libavcodec/webp.c | 16 +++++-----------
 3 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index 6d1a399304..5c0b4749ad 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -2515,7 +2515,9 @@ int vp78_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     if (ret < 0)
         goto err;
 
-    if (!is_vp7 && s->pix_fmt == AV_PIX_FMT_NONE) {
+    if (s->actually_webp) {
+        // avctx->pix_fmt already set in caller.
+    } else if (!is_vp7 && s->pix_fmt == AV_PIX_FMT_NONE) {
         enum AVPixelFormat pix_fmts[] = {
 #if CONFIG_VP8_VAAPI_HWACCEL
             AV_PIX_FMT_VAAPI,
diff --git a/libavcodec/vp8.h b/libavcodec/vp8.h
index 1870705ad2..1bf7561d05 100644
--- a/libavcodec/vp8.h
+++ b/libavcodec/vp8.h
@@ -140,6 +140,7 @@ typedef struct VP8Context {
     VP8ThreadData *thread_data;
     AVCodecContext *avctx;
     enum AVPixelFormat pix_fmt;
+    int actually_webp;
 
     VP8Frame *framep[4];
     VP8Frame *next_framep[4];
diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index 18d68e9140..0e769c307d 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -1288,16 +1288,6 @@ static int vp8_lossy_decode_alpha(AVCodecContext *avctx, AVFrame *p,
     return 0;
 }
 
-static enum AVPixelFormat webp_get_format(AVCodecContext *avctx,
-                                          const enum AVPixelFormat *formats)
-{
-    WebPContext *s = avctx->priv_data;
-    if (s->has_alpha)
-        return AV_PIX_FMT_YUVA420P;
-    else
-        return AV_PIX_FMT_YUV420P;
-}
-
 static int vp8_lossy_decode_frame(AVCodecContext *avctx, AVFrame *p,
                                   int *got_frame, uint8_t *data_start,
                                   unsigned int data_size)
@@ -1309,7 +1299,11 @@ static int vp8_lossy_decode_frame(AVCodecContext *avctx, AVFrame *p,
     if (!s->initialized) {
         ff_vp8_decode_init(avctx);
         s->initialized = 1;
-        avctx->get_format = webp_get_format;
+        s->v.actually_webp = 1;
+        if (s->has_alpha)
+            avctx->pix_fmt = AV_PIX_FMT_YUVA420P;
+        else
+            avctx->pix_fmt = AV_PIX_FMT_YUV420P;
     }
     s->lossless = 0;
 



More information about the ffmpeg-cvslog mailing list