diff mbox series

[FFmpeg-devel,1/2] avfilter/vf_zscale: deduplicate output color information setting

Message ID 20211027222024.53018-1-jeebjp@gmail.com
State Accepted
Commit cd1d09e81b53d47380b494acd3432fd4abb3c17b
Headers show
Series [FFmpeg-devel,1/2] avfilter/vf_zscale: deduplicate output color information setting | expand

Checks

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

Commit Message

Jan Ekström Oct. 27, 2021, 10:20 p.m. UTC
This way a piece of logic is not missed in one location or the other,
such as the case with chroma location outside the if.
---
 libavfilter/vf_zscale.c | 45 ++++++++++++++++++-----------------------
 1 file changed, 20 insertions(+), 25 deletions(-)

Comments

Jan Ekström Oct. 28, 2021, 8:17 p.m. UTC | #1
On Thu, Oct 28, 2021 at 1:24 AM Paul B Mahol <onemda@gmail.com> wrote:
>
> lgtm

Thanks for the reviews, applied these patches as
cd1d09e81b53d47380b494acd3432fd4abb3c17b and
27c0dd55609daf440a7744e96ac20c119bbeb80f .

Jan
diff mbox series

Patch

diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
index 3f7dba489a..439c0c8548 100644
--- a/libavfilter/vf_zscale.c
+++ b/libavfilter/vf_zscale.c
@@ -554,6 +554,24 @@  fail:
     return ret;
 }
 
+static void update_output_color_information(ZScaleContext *s, AVFrame *frame)
+{
+    if (s->colorspace != -1)
+        frame->colorspace = (int)s->dst_format.matrix_coefficients;
+
+    if (s->primaries != -1)
+        frame->color_primaries = (int)s->dst_format.color_primaries;
+
+    if (s->range != -1)
+        frame->color_range = convert_range_from_zimg(s->dst_format.pixel_range);
+
+    if (s->trc != -1)
+        frame->color_trc = (int)s->dst_format.transfer_characteristics;
+
+    if (s->chromal != -1)
+        frame->chroma_location = (int)s->dst_format.chroma_location - 1;
+}
+
 static int filter_frame(AVFilterLink *link, AVFrame *in)
 {
     ZScaleContext *s = link->dst->priv;
@@ -621,20 +639,7 @@  static int filter_frame(AVFilterLink *link, AVFrame *in)
         format_init(&s->dst_format, out, odesc, s->colorspace,
                     s->primaries, s->trc, s->range, s->chromal);
 
-        if (s->colorspace != -1)
-            out->colorspace = (int)s->dst_format.matrix_coefficients;
-
-        if (s->primaries != -1)
-            out->color_primaries = (int)s->dst_format.color_primaries;
-
-        if (s->range != -1)
-            out->color_range = convert_range_from_zimg(s->dst_format.pixel_range);
-
-        if (s->trc != -1)
-            out->color_trc = (int)s->dst_format.transfer_characteristics;
-
-        if (s->chromal != -1)
-            out->chroma_location = (int)s->dst_format.chroma_location - 1;
+        update_output_color_information(s, out);
 
         ret = graph_build(&s->graph, &s->params, &s->src_format, &s->dst_format,
                           &s->tmp, &s->tmp_size);
@@ -680,17 +685,7 @@  static int filter_frame(AVFilterLink *link, AVFrame *in)
         }
     }
 
-    if (s->colorspace != -1)
-        out->colorspace = (int)s->dst_format.matrix_coefficients;
-
-    if (s->primaries != -1)
-        out->color_primaries = (int)s->dst_format.color_primaries;
-
-    if (s->range != -1)
-        out->color_range = convert_range_from_zimg(s->dst_format.pixel_range);
-
-    if (s->trc != -1)
-        out->color_trc = (int)s->dst_format.transfer_characteristics;
+    update_output_color_information(s, out);
 
     av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,
               (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,