[FFmpeg-devel] avfilter/vf_scale: Set full range for RGB formats

Submitted by Michael Niedermayer on April 4, 2018, 1:43 a.m.

Details

Message ID 20180404014352.28442-1-michael@niedermayer.cc
State New
Headers show

Commit Message

Michael Niedermayer April 4, 2018, 1:43 a.m.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavfilter/vf_scale.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index f741419e7e..bd5c63aa9b 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -406,6 +406,7 @@  static int filter_frame(AVFilterLink *link, AVFrame *in)
     AVFilterLink *outlink = link->dst->outputs[0];
     AVFrame *out;
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
+    const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format);
     char buf[32];
     int in_range;
 
@@ -496,7 +497,11 @@  static int filter_frame(AVFilterLink *link, AVFrame *in)
                                      table, out_full,
                                      brightness, contrast, saturation);
 
-        out->color_range = out_full ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
+        // color_range describes YUV, it is undefined for RGB
+        if ((out_desc->flags & AV_PIX_FMT_FLAG_RGB) && out_desc->nb_components != 1) {
+            out->color_range = AVCOL_RANGE_JPEG;
+        } else
+            out->color_range = out_full ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
     }
 
     av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,