diff mbox series

[FFmpeg-devel] lavfi/vf_libplacebo: add RGB colorspace sanity

Message ID 20230521135420.15319-1-ffmpeg@haasn.xyz
State Accepted
Commit f66280182acb03604df2ef58c623b4fa39c56444
Headers show
Series [FFmpeg-devel] lavfi/vf_libplacebo: add RGB colorspace sanity | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Niklas Haas May 21, 2023, 1:54 p.m. UTC
From: Niklas Haas <git@haasn.dev>

Explicitly forbid using a non-RGB colorspace with RGB pixel format or
vice versa. This mirrors identical logic from vf_scale.
---
 libavfilter/vf_libplacebo.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Niklas Haas May 22, 2023, 8:35 a.m. UTC | #1
On Sun, 21 May 2023 15:54:20 +0200 Niklas Haas <ffmpeg@haasn.xyz> wrote:
> From: Niklas Haas <git@haasn.dev>
> 
> Explicitly forbid using a non-RGB colorspace with RGB pixel format or
> vice versa. This mirrors identical logic from vf_scale.
> ---
>  libavfilter/vf_libplacebo.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
> index f26d0126beb..e5af2693293 100644
> --- a/libavfilter/vf_libplacebo.c
> +++ b/libavfilter/vf_libplacebo.c
> @@ -695,6 +695,13 @@ static int output_frame_mix(AVFilterContext *ctx,
>      if (s->color_primaries >= 0)
>          out->color_primaries = s->color_primaries;
>  
> +    /* Sanity colorspace overrides */
> +    if (outdesc->flags & AV_PIX_FMT_FLAG_RGB) {
> +        out->colorspace = AVCOL_SPC_RGB;
> +    } else if (out->colorspace == AVCOL_SPC_RGB) {
> +        out->colorspace = AVCOL_SPC_UNSPECIFIED;
> +    }
> +
>      changed_csp = ref->colorspace      != out->colorspace     ||
>                    ref->color_range     != out->color_range    ||
>                    ref->color_trc       != out->color_trc      ||
> -- 
> 2.40.1
> 

Merged as f66280182acb03604df2ef58c623b4fa39c56444
diff mbox series

Patch

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index f26d0126beb..e5af2693293 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -695,6 +695,13 @@  static int output_frame_mix(AVFilterContext *ctx,
     if (s->color_primaries >= 0)
         out->color_primaries = s->color_primaries;
 
+    /* Sanity colorspace overrides */
+    if (outdesc->flags & AV_PIX_FMT_FLAG_RGB) {
+        out->colorspace = AVCOL_SPC_RGB;
+    } else if (out->colorspace == AVCOL_SPC_RGB) {
+        out->colorspace = AVCOL_SPC_UNSPECIFIED;
+    }
+
     changed_csp = ref->colorspace      != out->colorspace     ||
                   ref->color_range     != out->color_range    ||
                   ref->color_trc       != out->color_trc      ||