Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] apng: fix rgb24 blending bug for non-alpha frames
@ 2026-01-02 11:29 Hassan Hany via ffmpeg-devel
  2026-01-05 16:12 ` [FFmpeg-devel] " Michael Niedermayer via ffmpeg-devel
  0 siblings, 1 reply; 4+ messages in thread
From: Hassan Hany via ffmpeg-devel @ 2026-01-02 11:29 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: U-DESKTOP-70DF2U5\GIGABYT

From: "U-DESKTOP-70DF2U5\\GIGABYT" <hassanhanyrashad@gmail.com>

Delta frame optimization in APNG encoder caused gray bars for RGB24 frames.
This patch disables delta optimization for non-alpha frames, ensuring correct
rendering. Delta optimization is preserved for RGBA frames.

Fixes: trac Ticket #9602

Signed-off-by: U-DESKTOP-70DF2U5\GIGABYT <hassanhanyrashad@gmail.com>
---
This bug caused visible artifacts such as gray bars in non-alpha 
pixel formats such as RGB24 or GRAY. This patch disabled delta frame
optimization only for non alpha channels. the output size increased
from 512kb to 1.1mb on the test sample but correctness was restored
and the relevant APNG FATE tests were ran and no regression occurred
 libavcodec/pngenc.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
index e627bf83fc..3e46363b00 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
@@ -894,6 +894,19 @@ static int apng_encode_frame(AVCodecContext *avctx, const AVFrame *pict,
         best_fctl_chunk->blend_op = APNG_BLEND_OP_SOURCE;
         return encode_frame(avctx, pict);
     }
+    
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pict->format);
+        
+    if(!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)){
+         best_fctl_chunk->width = pict->width;
+         best_fctl_chunk->height = pict->height;
+         best_fctl_chunk->x_offset = 0;
+         best_fctl_chunk->y_offset = 0;
+         best_fctl_chunk->blend_op = APNG_BLEND_OP_SOURCE;
+         best_fctl_chunk->dispose_op = APNG_DISPOSE_OP_NONE;
+          return encode_frame(avctx, pict);
+         } 
+    
 
     diffFrame = av_frame_alloc();
     if (!diffFrame)
-- 
2.52.0

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [FFmpeg-devel] Re: [PATCH] apng: fix rgb24 blending bug for non-alpha frames
  2026-01-02 11:29 [FFmpeg-devel] [PATCH] apng: fix rgb24 blending bug for non-alpha frames Hassan Hany via ffmpeg-devel
@ 2026-01-05 16:12 ` Michael Niedermayer via ffmpeg-devel
  2026-01-06 14:15   ` hassan hany via ffmpeg-devel
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Niedermayer via ffmpeg-devel @ 2026-01-05 16:12 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Michael Niedermayer


[-- Attachment #1.1: Type: text/plain, Size: 2509 bytes --]


On Fri, Jan 02, 2026 at 01:29:32PM +0200, Hassan Hany via ffmpeg-devel wrote:
> From: "U-DESKTOP-70DF2U5\\GIGABYT" <hassanhanyrashad@gmail.com>
> 
> Delta frame optimization in APNG encoder caused gray bars for RGB24 frames.
> This patch disables delta optimization for non-alpha frames, ensuring correct
> rendering. Delta optimization is preserved for RGBA frames.
> 
> Fixes: trac Ticket #9602
> 
> Signed-off-by: U-DESKTOP-70DF2U5\GIGABYT <hassanhanyrashad@gmail.com>
> ---
> This bug caused visible artifacts such as gray bars in non-alpha 
> pixel formats such as RGB24 or GRAY. This patch disabled delta frame
> optimization only for non alpha channels. the output size increased
> from 512kb to 1.1mb on the test sample but correctness was restored
> and the relevant APNG FATE tests were ran and no regression occurred
>  libavcodec/pngenc.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
> index e627bf83fc..3e46363b00 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
> @@ -894,6 +894,19 @@ static int apng_encode_frame(AVCodecContext *avctx, const AVFrame *pict,
>          best_fctl_chunk->blend_op = APNG_BLEND_OP_SOURCE;
>          return encode_frame(avctx, pict);
>      }
> +    
> +    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pict->format);
> +        
> +    if(!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)){
> +         best_fctl_chunk->width = pict->width;
> +         best_fctl_chunk->height = pict->height;
> +         best_fctl_chunk->x_offset = 0;
> +         best_fctl_chunk->y_offset = 0;
> +         best_fctl_chunk->blend_op = APNG_BLEND_OP_SOURCE;
> +         best_fctl_chunk->dispose_op = APNG_DISPOSE_OP_NONE;
> +          return encode_frame(avctx, pict);
> +         } 
> +    

This looks like a hack not like a bugfix
besides the indention is wrong and there are tabs

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If the United States is serious about tackling the national security threats 
related to an insecure 5G network, it needs to rethink the extent to which it
values corporate profits and government espionage over security.-Bruce Schneier

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 163 bytes --]

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [FFmpeg-devel] Re: [PATCH] apng: fix rgb24 blending bug for non-alpha frames
  2026-01-05 16:12 ` [FFmpeg-devel] " Michael Niedermayer via ffmpeg-devel
@ 2026-01-06 14:15   ` hassan hany via ffmpeg-devel
  2026-01-08  2:33     ` Michael Niedermayer via ffmpeg-devel
  0 siblings, 1 reply; 4+ messages in thread
From: hassan hany via ffmpeg-devel @ 2026-01-06 14:15 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: hassan hany

[-- Attachment #1: Type: text/plain, Size: 3414 bytes --]

Okay well I looked into it and it turns out that just disabling the dispose
background operation for non alpha formats just fixes the issue and
produces a 504kb APNG  that is correct with no gray bars  (currently ffmpeg
produces a broken 503kb one) now reading the spec it does say "

   - 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."
   and we don't have transparency in non alpha formats


On Mon, Jan 5, 2026 at 6:13 PM Michael Niedermayer via ffmpeg-devel <
ffmpeg-devel@ffmpeg.org> wrote:

>
> On Fri, Jan 02, 2026 at 01:29:32PM +0200, Hassan Hany via ffmpeg-devel
> wrote:
> > From: "U-DESKTOP-70DF2U5\\GIGABYT" <hassanhanyrashad@gmail.com>
> >
> > Delta frame optimization in APNG encoder caused gray bars for RGB24
> frames.
> > This patch disables delta optimization for non-alpha frames, ensuring
> correct
> > rendering. Delta optimization is preserved for RGBA frames.
> >
> > Fixes: trac Ticket #9602
> >
> > Signed-off-by: U-DESKTOP-70DF2U5\GIGABYT <hassanhanyrashad@gmail.com>
> > ---
> > This bug caused visible artifacts such as gray bars in non-alpha
> > pixel formats such as RGB24 or GRAY. This patch disabled delta frame
> > optimization only for non alpha channels. the output size increased
> > from 512kb to 1.1mb on the test sample but correctness was restored
> > and the relevant APNG FATE tests were ran and no regression occurred
> >  libavcodec/pngenc.c | 15 ++++++++++++++-
> >  1 file changed, 14 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
> > index e627bf83fc..3e46363b00 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
> > @@ -894,6 +894,19 @@ static int apng_encode_frame(AVCodecContext *avctx,
> const AVFrame *pict,
> >          best_fctl_chunk->blend_op = APNG_BLEND_OP_SOURCE;
> >          return encode_frame(avctx, pict);
> >      }
> > +
> > +    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pict->format);
> > +
> > +    if(!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)){
> > +         best_fctl_chunk->width = pict->width;
> > +         best_fctl_chunk->height = pict->height;
> > +         best_fctl_chunk->x_offset = 0;
> > +         best_fctl_chunk->y_offset = 0;
> > +         best_fctl_chunk->blend_op = APNG_BLEND_OP_SOURCE;
> > +         best_fctl_chunk->dispose_op = APNG_DISPOSE_OP_NONE;
> > +          return encode_frame(avctx, pict);
> > +         }
> > +
>
> This looks like a hack not like a bugfix
> besides the indention is wrong and there are tabs
>
> thx
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> If the United States is serious about tackling the national security
> threats
> related to an insecure 5G network, it needs to rethink the extent to which
> it
> values corporate profits and government espionage over security.-Bruce
> Schneier
> _______________________________________________
> ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
> To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
>

[-- Attachment #2: 0001-avcodec-apngenc-disable-background-disposal-for-non-.patch --]
[-- Type: application/octet-stream, Size: 1690 bytes --]

[-- Attachment #3: Type: text/plain, Size: 163 bytes --]

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [FFmpeg-devel] Re: [PATCH] apng: fix rgb24 blending bug for non-alpha frames
  2026-01-06 14:15   ` hassan hany via ffmpeg-devel
@ 2026-01-08  2:33     ` Michael Niedermayer via ffmpeg-devel
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Niedermayer via ffmpeg-devel @ 2026-01-08  2:33 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Michael Niedermayer


[-- Attachment #1.1: Type: text/plain, Size: 6477 bytes --]

Hi Hassan

On Tue, Jan 06, 2026 at 04:15:52PM +0200, hassan hany via ffmpeg-devel wrote:
> Okay well I looked into it and it turns out that just disabling the dispose
> background operation for non alpha formats just fixes the issue and
> produces a 504kb APNG  that is correct with no gray bars  (currently ffmpeg
> produces a broken 503kb one) now reading the spec it does say "
> 
>    - 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."
>    and we don't have transparency in non alpha formats

the patch fixing this should be against master not against your previous patch
also you may want to submit it to code.ffmpeg.org

thx

> 
> 
> On Mon, Jan 5, 2026 at 6:13 PM Michael Niedermayer via ffmpeg-devel <
> ffmpeg-devel@ffmpeg.org> wrote:
> 
> >
> > On Fri, Jan 02, 2026 at 01:29:32PM +0200, Hassan Hany via ffmpeg-devel
> > wrote:
> > > From: "U-DESKTOP-70DF2U5\\GIGABYT" <hassanhanyrashad@gmail.com>
> > >
> > > Delta frame optimization in APNG encoder caused gray bars for RGB24
> > frames.
> > > This patch disables delta optimization for non-alpha frames, ensuring
> > correct
> > > rendering. Delta optimization is preserved for RGBA frames.
> > >
> > > Fixes: trac Ticket #9602
> > >
> > > Signed-off-by: U-DESKTOP-70DF2U5\GIGABYT <hassanhanyrashad@gmail.com>
> > > ---
> > > This bug caused visible artifacts such as gray bars in non-alpha
> > > pixel formats such as RGB24 or GRAY. This patch disabled delta frame
> > > optimization only for non alpha channels. the output size increased
> > > from 512kb to 1.1mb on the test sample but correctness was restored
> > > and the relevant APNG FATE tests were ran and no regression occurred
> > >  libavcodec/pngenc.c | 15 ++++++++++++++-
> > >  1 file changed, 14 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
> > > index e627bf83fc..3e46363b00 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
> > > @@ -894,6 +894,19 @@ static int apng_encode_frame(AVCodecContext *avctx,
> > const AVFrame *pict,
> > >          best_fctl_chunk->blend_op = APNG_BLEND_OP_SOURCE;
> > >          return encode_frame(avctx, pict);
> > >      }
> > > +
> > > +    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pict->format);
> > > +
> > > +    if(!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)){
> > > +         best_fctl_chunk->width = pict->width;
> > > +         best_fctl_chunk->height = pict->height;
> > > +         best_fctl_chunk->x_offset = 0;
> > > +         best_fctl_chunk->y_offset = 0;
> > > +         best_fctl_chunk->blend_op = APNG_BLEND_OP_SOURCE;
> > > +         best_fctl_chunk->dispose_op = APNG_DISPOSE_OP_NONE;
> > > +          return encode_frame(avctx, pict);
> > > +         }
> > > +
> >
> > This looks like a hack not like a bugfix
> > besides the indention is wrong and there are tabs
> >
> > thx
> >
> > [...]
> > --
> > Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> >
> > If the United States is serious about tackling the national security
> > threats
> > related to an insecure 5G network, it needs to rethink the extent to which
> > it
> > values corporate profits and government espionage over security.-Bruce
> > Schneier
> > _______________________________________________
> > ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
> > To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
> >

>  pngenc.c |   15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)
> 91fbbe797e2361746d404905b52e881444161f53  /var0001-avcodec-apngenc-disable-background-disposal-for-non-.patch
> From dd17f2d1037b529ee64f5a69a88c90b4f36033f5 Mon Sep 17 00:00:00 2001
> From: "U-DESKTOP-70DF2U5\\GIGABYT" <hassanhanyrashad@gmail.com>
> Date: Tue, 6 Jan 2026 15:39:51 +0200
> Subject: [PATCH] avcodec/apngenc: disable background disposal for non-alpha
>  formats
> 
> ---
>  libavcodec/pngenc.c | 15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
> index 3e46363b00..adf5c1009e 100644
> --- a/libavcodec/pngenc.c
> +++ b/libavcodec/pngenc.c
> @@ -897,16 +897,6 @@ static int apng_encode_frame(AVCodecContext *avctx, const AVFrame *pict,
>      
>      const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pict->format);
>          
> -    if(!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)){
> -         best_fctl_chunk->width = pict->width;
> -         best_fctl_chunk->height = pict->height;
> -         best_fctl_chunk->x_offset = 0;
> -         best_fctl_chunk->y_offset = 0;
> -         best_fctl_chunk->blend_op = APNG_BLEND_OP_SOURCE;
> -         best_fctl_chunk->dispose_op = APNG_DISPOSE_OP_NONE;
> -          return encode_frame(avctx, pict);
> -         } 
> -    
>  
>      diffFrame = av_frame_alloc();
>      if (!diffFrame)
> @@ -932,6 +922,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
> -- 
> 2.52.0
> 

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


-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Modern terrorism, a quick summary: Need oil, start war with country that
has oil, kill hundread thousand in war. Let country fall into chaos,
be surprised about raise of fundamantalists. Drop more bombs, kill more
people, be surprised about them taking revenge and drop even more bombs
and strip your own citizens of their rights and freedoms. to be continued

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 163 bytes --]

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-01-08  2:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-02 11:29 [FFmpeg-devel] [PATCH] apng: fix rgb24 blending bug for non-alpha frames Hassan Hany via ffmpeg-devel
2026-01-05 16:12 ` [FFmpeg-devel] " Michael Niedermayer via ffmpeg-devel
2026-01-06 14:15   ` hassan hany via ffmpeg-devel
2026-01-08  2:33     ` Michael Niedermayer via ffmpeg-devel

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