summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Haas <[email protected]>2023-10-31 12:55:26 +0100
committerNiklas Haas <[email protected]>2023-11-09 12:53:35 +0100
commitcf60046cdcdb67fce8cea11c4dbab5bb8f931430 (patch)
treef43505f477d6e10687b3251df22fdabec277c000
parent5d5bb77af11eb6e9bea8b5eb5f1ecba10c72dcfd (diff)
avfilter/vf_scale: tag output color space
When using vf_scale to force a specific output color space, also tag this on the AVFrame. (Mirroring existing logic for output range) Move the sanity fix for RGB after the new assignment, to avoid leaking bogus YUV colorspace metadata for RGB spaces.
-rw-r--r--libavfilter/vf_scale.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index fb8e6a2b76..b45035907b 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -799,18 +799,6 @@ scale:
out->width = outlink->w;
out->height = outlink->h;
- // Sanity checks:
- // 1. If the output is RGB, set the matrix coefficients to RGB.
- // 2. If the output is not RGB and we've got the RGB/XYZ (identity)
- // matrix configured, unset the matrix.
- // In theory these should be in swscale itself as the AVFrame
- // based API gets in, so that not every swscale API user has
- // to go through duplicating such sanity checks.
- if (av_pix_fmt_desc_get(out->format)->flags & AV_PIX_FMT_FLAG_RGB)
- out->colorspace = AVCOL_SPC_RGB;
- else if (out->colorspace == AVCOL_SPC_RGB)
- out->colorspace = AVCOL_SPC_UNSPECIFIED;
-
if (scale->output_is_pal)
avpriv_set_systematic_pal2((uint32_t*)out->data[1], outlink->format == AV_PIX_FMT_PAL8 ? AV_PIX_FMT_BGR8 : outlink->format);
@@ -857,8 +845,22 @@ scale:
brightness, contrast, saturation);
out->color_range = out_full ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
+ if (scale->out_color_matrix != AVCOL_SPC_UNSPECIFIED)
+ out->colorspace = scale->out_color_matrix;
}
+ // Sanity checks:
+ // 1. If the output is RGB, set the matrix coefficients to RGB.
+ // 2. If the output is not RGB and we've got the RGB/XYZ (identity)
+ // matrix configured, unset the matrix.
+ // In theory these should be in swscale itself as the AVFrame
+ // based API gets in, so that not every swscale API user has
+ // to go through duplicating such sanity checks.
+ if (av_pix_fmt_desc_get(out->format)->flags & AV_PIX_FMT_FLAG_RGB)
+ out->colorspace = AVCOL_SPC_RGB;
+ else if (out->colorspace == AVCOL_SPC_RGB)
+ out->colorspace = AVCOL_SPC_UNSPECIFIED;
+
av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,
(int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
(int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,