[FFmpeg-devel] [PATCH 4/6] avcodec/apng: Add blending support for non-alpha pixel formats

Donny Yang work at kota.moe
Tue Jun 2 17:49:25 CEST 2015


Signed-off-by: Donny Yang <work at kota.moe>
---
 libavcodec/pngdec.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 90bf725..1f5c433 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -58,6 +58,7 @@ typedef struct PNGDecContext {
     int channels;
     int bits_per_pixel;
     int bpp;
+    int has_trns;
 
     uint8_t *image_buf;
     int image_linesize;
@@ -727,6 +728,8 @@ static int decode_trns_chunk(AVCodecContext *avctx, PNGDecContext *s,
     }
     bytestream2_skip(&s->gb, 4);     /* crc */
 
+    s->has_trns = 1;
+
     return 0;
 }
 
@@ -843,6 +846,18 @@ static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s,
         s->dispose_op = APNG_DISPOSE_OP_NONE;
     }
 
+    if (s->dispose_op == APNG_BLEND_OP_OVER && !s->has_trns && (
+            avctx->pix_fmt == AV_PIX_FMT_RGB24 ||
+            avctx->pix_fmt == AV_PIX_FMT_RGB48BE ||
+            avctx->pix_fmt == AV_PIX_FMT_PAL8 ||
+            avctx->pix_fmt == AV_PIX_FMT_GRAY8 ||
+            avctx->pix_fmt == AV_PIX_FMT_GRAY16BE ||
+            avctx->pix_fmt == AV_PIX_FMT_MONOBLACK
+        )) {
+        // APNG_DISPOSE_OP_OVER is the same as APNG_DISPOSE_OP_SOURCE when there is no alpha channel
+        s->dispose_op = APNG_BLEND_OP_SOURCE;
+    }
+
     return 0;
 }
 
-- 
2.4.0


More information about the ffmpeg-devel mailing list