From: Niklas Haas via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Niklas Haas <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PR] avutil/imgutils: two minor cleanup commits (PR #22238)
Date: Sat, 21 Feb 2026 12:00:03 -0000
Message-ID: <177167520445.25.15218072951556380874@29965ddac10e> (raw)
PR #22238 opened by Niklas Haas (haasn)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22238
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22238.patch
Spotted while wading through the mess that is all of our many divergent plane allocation implementations.
>From 0f5e09a5ea99793f6e271565546f80c543627da6 Mon Sep 17 00:00:00 2001
From: Niklas Haas <git@haasn.dev>
Date: Fri, 20 Feb 2026 20:43:42 +0100
Subject: [PATCH 1/2] avutil/imgutils: eliminate dead code
This condition is impossible to satisfy:
if (desc->flags & AV_PIX_FMT_FLAG_PAL && pointers[1] &&
pointers[1] - pointers[0] > linesizes[0] * h)
Specifically, pointers[1] - pointers[0] is equal by definition of
av_image_fill_pointers() to:
sizes[0] = (size_t)h * linesizes[0]; // via av_image_fill_plane_sizes()
data[1] = data[0] + sizes[0];
So it's impossible for there to be extra padding between the planes unless
something drastic changes, which is unlikely at this stage.
---
libavutil/imgutils.c | 7 -------
1 file changed, 7 deletions(-)
diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c
index 8ff8a6be41..ae671e005f 100644
--- a/libavutil/imgutils.c
+++ b/libavutil/imgutils.c
@@ -261,13 +261,6 @@ int av_image_alloc(uint8_t *pointers[4], int linesizes[4],
}
}
- if (desc->flags & AV_PIX_FMT_FLAG_PAL && pointers[1] &&
- pointers[1] - pointers[0] > linesizes[0] * h) {
- /* zero-initialize the padding before the palette */
- memset(pointers[0] + linesizes[0] * h, 0,
- pointers[1] - pointers[0] - linesizes[0] * h);
- }
-
return ret;
}
--
2.52.0
>From a452b87121e5e81510683859e855708fa697431b Mon Sep 17 00:00:00 2001
From: Niklas Haas <git@haasn.dev>
Date: Sat, 21 Feb 2026 12:50:45 +0100
Subject: [PATCH 2/2] avutil/imgutils: always correctly align palette formats
There is literally no reason to error out here when we can just trivially
increase the alignment requirement. As far as I can tell, there is no
wording or documentation for av_image_alloc() that says "align=0" should
guarantee tightly packed data.
---
libavutil/imgutils.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c
index ae671e005f..9ccd62bfa6 100644
--- a/libavutil/imgutils.c
+++ b/libavutil/imgutils.c
@@ -227,6 +227,9 @@ int av_image_alloc(uint8_t *pointers[4], int linesizes[4],
if (!desc)
return AVERROR(EINVAL);
+ if (desc->flags & AV_PIX_FMT_FLAG_PAL)
+ align = FFMAX(align, sizeof(uint32_t));
+
if ((ret = av_image_check_size(w, h, 0, NULL)) < 0)
return ret;
if ((ret = av_image_fill_linesizes(linesizes, pix_fmt, align>7 ? FFALIGN(w, 8) : w)) < 0)
@@ -252,14 +255,8 @@ int av_image_alloc(uint8_t *pointers[4], int linesizes[4],
av_free(buf);
return ret;
}
- if (desc->flags & AV_PIX_FMT_FLAG_PAL) {
+ if (desc->flags & AV_PIX_FMT_FLAG_PAL)
avpriv_set_systematic_pal2((uint32_t*)pointers[1], pix_fmt);
- if (align < 4) {
- av_log(NULL, AV_LOG_ERROR, "Formats with a palette require a minimum alignment of 4\n");
- av_free(buf);
- return AVERROR(EINVAL);
- }
- }
return ret;
}
--
2.52.0
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2026-02-21 15:52 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=177167520445.25.15218072951556380874@29965ddac10e \
--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