Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: hassanhany via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: hassanhany <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PR] disabling background disposal for non alpha formats (PR #21414)
Date: Thu, 08 Jan 2026 20:41:54 -0000
Message-ID: <176790491463.25.11408923085079381721@4457048688e7> (raw)

PR #21414 opened by hassanhany
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21414
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21414.patch

this is in relation to Trac ticket 9602 which was reopened 2 weeks ago where the issue was there were gray bars in apng rgb24 (and other non alpha based formats) this PR fixes it by disabling the background disposal operation for non alpha formats since it relies on transparency as defined by the spec "APNG_DISPOSE_OP_BACKGROUND: the frame's region of the output buffer is to be cleared to fully transparent black before rendering the next frame." Building FFmpeg with this patch produces the correct output, removing the gray bars,


>From 253901b2b72889878d8bbe69c66c898fdfc011f4 Mon Sep 17 00:00:00 2001
From: "U-DESKTOP-70DF2U5\\GIGABYT" <hassanhanyrashad@gmail.com>
Date: Thu, 8 Jan 2026 21:04:52 +0200
Subject: [PATCH] disabling background disposal for non alpha formats

---
 libavcodec/pngenc.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
index e627bf83fc..808fac6a38 100644
--- a/libavcodec/pngenc.c
+++ b/libavcodec/pngenc.c
@@ -39,7 +39,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/rational.h"
 #include "libavutil/stereo3d.h"
-
+#include "libavutil/pixdesc.h"
 #include <zlib.h>
 
 #define IOBUF_SIZE 4096
@@ -885,7 +885,8 @@ static int apng_encode_frame(AVCodecContext *avctx, const AVFrame *pict,
     size_t best_bytestream_size = SIZE_MAX;
     APNGFctlChunk last_fctl_chunk = *best_last_fctl_chunk;
     APNGFctlChunk fctl_chunk = *best_fctl_chunk;
-
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pict->format);
+    
     if (avctx->frame_num == 0) {
         best_fctl_chunk->width = pict->width;
         best_fctl_chunk->height = pict->height;
@@ -919,7 +920,11 @@ static int apng_encode_frame(AVCodecContext *avctx, const AVFrame *pict,
         // 0: APNG_DISPOSE_OP_NONE
         // 1: APNG_DISPOSE_OP_BACKGROUND
         // 2: APNG_DISPOSE_OP_PREVIOUS
-
+        if(last_fctl_chunk.dispose_op==APNG_DISPOSE_OP_BACKGROUND) {
+            if(!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) {
+                continue;
+            }
+        }
         for (fctl_chunk.blend_op = 0; fctl_chunk.blend_op < 2; ++fctl_chunk.blend_op) {
             // 0: APNG_BLEND_OP_SOURCE
             // 1: APNG_BLEND_OP_OVER
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2026-01-08 20:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=176790491463.25.11408923085079381721@4457048688e7 \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=code@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git