From: Zhao Zhili <quinkblack-at-foxmail.com@ffmpeg.org>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH 01/12] avutil/frame: add AVFrame.alpha_mode
Date: Thu, 20 Feb 2025 16:53:58 +0800
Message-ID: <tencent_50209FE2AB154E9570C42D949A6240709A08@qq.com> (raw)
In-Reply-To: <20250219204550.2826561-1-ffmpeg@haasn.xyz>
> On Feb 20, 2025, at 04:45, Niklas Haas <ffmpeg@haasn.xyz> wrote:
>
> From: Niklas Haas <git@haasn.dev>
>
> FFmpeg currently handles alpha in a quasi-arbitrary way. Some filters/codecs
> assume alpha is premultiplied, others assume it is independent. If there is
> to be any hope for order in this chaos, we need to start by defining an enum
> for the possible range of values.
> ---
> doc/APIchanges | 4 ++++
> libavutil/frame.c | 2 ++
> libavutil/frame.h | 7 +++++++
> libavutil/pixdesc.c | 27 +++++++++++++++++++++++++++
> libavutil/pixdesc.h | 10 ++++++++++
> libavutil/pixfmt.h | 10 ++++++++++
> libavutil/version.h | 2 +-
> 7 files changed, 61 insertions(+), 1 deletion(-)
>
> diff --git a/doc/APIchanges b/doc/APIchanges
> index ac506f4b56..601013b018 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -2,6 +2,10 @@ The last version increases of all libraries were on 2024-03-07
>
> API changes, most recent first:
>
> +2025-02-xx - xxxxxxxxxx - lavu 59.58.100 - frame.h pixfmt.h
> + Add AVAlphaMode, AVFrame.alpha_mode, av_alpha_mode_name() and
> + av_alpha_mode_from_name().
> +
> 2025-02-xx - xxxxxxxxxx - lavu 59.57.100 - log.h
> Add flags AV_LOG_PRINT_TIME and AV_LOG_PRINT_DATETIME.
>
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index 492b467ebd..cc906dbe21 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -84,6 +84,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
> frame->colorspace = AVCOL_SPC_UNSPECIFIED;
> frame->color_range = AVCOL_RANGE_UNSPECIFIED;
> frame->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
> + frame->alpha_mode = AVALPHA_MODE_UNSPECIFIED;
> frame->flags = 0;
> }
>
> @@ -364,6 +365,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
> dst->colorspace = src->colorspace;
> dst->color_range = src->color_range;
> dst->chroma_location = src->chroma_location;
> + dst->alpha_mode = src->alpha_mode;
>
> av_dict_copy(&dst->metadata, src->metadata, 0);
>
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index 49260ae2dd..6e53135d27 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -822,6 +822,13 @@ typedef struct AVFrame {
> * Duration of the frame, in the same units as pts. 0 if unknown.
> */
> int64_t duration;
> +
> + /**
> + * Indicates how the alpha channel of the video is to be handled.
> + * - encoding: Set by user
> + * - decoding: Set by libavcodec
> + */
> + enum AVAlphaMode alpha_mode;
> } AVFrame;
>
>
> diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
> index 6fe83cd16b..f4eb3d5074 100644
> --- a/libavutil/pixdesc.c
> +++ b/libavutil/pixdesc.c
> @@ -3152,6 +3152,12 @@ static const char * const chroma_location_names[] = {
> [AVCHROMA_LOC_BOTTOM] = "bottom",
> };
>
> +static const char * const alpha_mode_names[] = {
> + [AVALPHA_MODE_UNSPECIFIED] = "unspecified",
> + [AVALPHA_MODE_PREMULTIPLIED] = "premultiplied",
> + [AVALPHA_MODE_STRAIGHT] = "straight",
> +};
> +
> static enum AVPixelFormat get_pix_fmt_internal(const char *name)
> {
> enum AVPixelFormat pix_fmt;
> @@ -3685,3 +3691,24 @@ enum AVChromaLocation av_chroma_location_pos_to_enum(int xpos, int ypos)
> }
> return AVCHROMA_LOC_UNSPECIFIED;
> }
> +
> +const char *av_alpha_mode_name(enum AVAlphaMode mode)
> +{
> + return (unsigned) mode < AVALPHA_MODE_NB ?
> + alpha_mode_names[mode] : NULL;
> +}
> +
> +enum AVAlphaMode av_alpha_mode_from_name(const char *name)
> +{
> + int i;
> +
> + for (i = 0; i < FF_ARRAY_ELEMS(alpha_mode_names); i++) {
> + if (!alpha_mode_names[i])
> + continue;
It’s very unlikely to have a hole in alpha_mode_names, so the check can be removed.
Maybe add an assert here.
> +
> + if (av_strstart(name, alpha_mode_names[i], NULL))
> + return i;
> + }
> +
> + return AVERROR(EINVAL);
> +}
> diff --git a/libavutil/pixdesc.h b/libavutil/pixdesc.h
> index ba2f632814..0cc70eb64c 100644
> --- a/libavutil/pixdesc.h
> +++ b/libavutil/pixdesc.h
> @@ -291,6 +291,16 @@ int av_chroma_location_enum_to_pos(int *xpos, int *ypos, enum AVChromaLocation p
> */
> enum AVChromaLocation av_chroma_location_pos_to_enum(int xpos, int ypos);
>
> +/**
> + * @return the name for provided alpha mode or NULL if unknown.
> + */
> +const char *av_alpha_mode_name(enum AVAlphaMode mode);
> +
> +/**
> + * @return the AVAlphaMode value for name or an AVError if not found.
> + */
> +enum AVAlphaMode av_alpha_mode_from_name(const char *name);
> +
> /**
> * Return the pixel format corresponding to name.
> *
> diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h
> index a64d40ad07..8af64a383d 100644
> --- a/libavutil/pixfmt.h
> +++ b/libavutil/pixfmt.h
> @@ -760,4 +760,14 @@ enum AVChromaLocation {
> AVCHROMA_LOC_NB ///< Not part of ABI
> };
>
> +/**
> + * Correlation between the alpha channel and color values.
> + */
> +enum AVAlphaMode {
> + AVALPHA_MODE_UNSPECIFIED = 0, ///< Unknown alpha handling, or no alpha channel
> + AVALPHA_MODE_PREMULTIPLIED = 1, ///< Alpha channel is multiplied into color values
> + AVALPHA_MODE_STRAIGHT = 2, ///< Alpha channel is independent of color values
> + AVALPHA_MODE_NB ///< Not part of ABI
> +};
> +
> #endif /* AVUTIL_PIXFMT_H */
> diff --git a/libavutil/version.h b/libavutil/version.h
> index ee4a36cb17..4b584fd569 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -79,7 +79,7 @@
> */
>
> #define LIBAVUTIL_VERSION_MAJOR 59
> -#define LIBAVUTIL_VERSION_MINOR 57
> +#define LIBAVUTIL_VERSION_MINOR 58
> #define LIBAVUTIL_VERSION_MICRO 100
>
> #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
> --
> 2.47.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2025-02-20 8:55 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-19 20:45 Niklas Haas
2025-02-19 20:45 ` [FFmpeg-devel] [PATCH 02/12] fftools/ffprobe: add support for AVFrame.alpha_mode Niklas Haas
2025-02-19 20:45 ` [FFmpeg-devel] [PATCH 03/12] avfilter/vf_showinfo: print alpha mode when relevant Niklas Haas
2025-02-19 20:45 ` [FFmpeg-devel] [PATCH 04/12] avcodec/avcodec: add AVCodecContext.alpha_mode Niklas Haas
2025-02-19 21:04 ` James Almer
2025-02-19 21:18 ` Niklas Haas
2025-02-19 20:45 ` [FFmpeg-devel] [PATCH 05/12] avcodec/encode: enforce alpha mode compatibility at encode time Niklas Haas
2025-02-19 20:45 ` [FFmpeg-devel] [PATCH 06/12] avcodec/png: set correct alpha mode Niklas Haas
2025-02-19 20:45 ` [FFmpeg-devel] [PATCH 07/12] fftools/ffmpeg_enc: forward frame alpha mode to encoder Niklas Haas
2025-02-22 2:44 ` mypopy
2025-02-19 20:45 ` [FFmpeg-devel] [PATCH 08/12] avfilter/vf_premultiply: tag correct alpha mode on result Niklas Haas
2025-02-19 20:45 ` [FFmpeg-devel] [PATCH 09/12] avfilter/vf_alphamerge: tag correct alpha mode Niklas Haas
2025-02-19 20:45 ` [FFmpeg-devel] [PATCH 10/12] avfilter/vf_overlay: respect alpha mode tagging by default Niklas Haas
2025-02-19 20:45 ` [FFmpeg-devel] [PATCH 11/12] avfilter/vf_setparams: add alpha_mode parameter Niklas Haas
2025-02-19 20:45 ` [FFmpeg-devel] [PATCH 12/12] avfilter/vf_libplacebo: add an alpha_mode setting Niklas Haas
2025-02-20 8:53 ` Zhao Zhili [this message]
2025-02-20 9:39 ` [FFmpeg-devel] [PATCH 01/12] avutil/frame: add AVFrame.alpha_mode Nicolas George
2025-02-20 11:25 ` Niklas Haas
2025-02-28 8:51 ` Nicolas George
2025-02-27 17:52 ` Niklas Haas
2025-02-28 8:53 ` Nicolas George
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=tencent_50209FE2AB154E9570C42D949A6240709A08@qq.com \
--to=quinkblack-at-foxmail.com@ffmpeg.org \
--cc=ffmpeg-devel@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