diff mbox series

[FFmpeg-devel] avfilter/vf_zscale: Don't make assumptions about zimg's range enums

Message ID AM7PR03MB666088FCF946EAAFB41B16998FDD9@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Headers show
Series [FFmpeg-devel] avfilter/vf_zscale: Don't make assumptions about zimg's range enums
Related show

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

Andreas Rheinhardt Sept. 17, 2021, 10:33 p.m. UTC
zimg's color range enum values are off-by-one compared to ours;
therefore the code just adds one when converting from theirs to ours.
Yet this is not how one should deal with enums; use a switch instead.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavfilter/vf_zscale.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Paul B Mahol Sept. 18, 2021, 10:26 a.m. UTC | #1
lgtm
diff mbox series

Patch

diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
index 06a025e6e6..aff4e8c762 100644
--- a/libavfilter/vf_zscale.c
+++ b/libavfilter/vf_zscale.c
@@ -460,6 +460,17 @@  static int convert_range(enum AVColorRange color_range)
     return ZIMG_RANGE_LIMITED;
 }
 
+static int convert_range_from_zimg(enum zimg_pixel_range_e color_range)
+{
+    switch (color_range) {
+    case ZIMG_RANGE_LIMITED:
+        return AVCOL_RANGE_MPEG;
+    case ZIMG_RANGE_FULL:
+        return AVCOL_RANGE_JPEG;
+    }
+    return AVCOL_RANGE_UNSPECIFIED;
+}
+
 static void format_init(zimg_image_format *format, AVFrame *frame, const AVPixFmtDescriptor *desc,
                         int colorspace, int primaries, int transfer, int range, int location)
 {
@@ -617,7 +628,7 @@  static int filter_frame(AVFilterLink *link, AVFrame *in)
             out->color_primaries = (int)s->dst_format.color_primaries;
 
         if (s->range != -1)
-            out->color_range = (int)s->dst_format.pixel_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;
@@ -676,7 +687,7 @@  static int filter_frame(AVFilterLink *link, AVFrame *in)
         out->color_primaries = (int)s->dst_format.color_primaries;
 
     if (s->range != -1)
-        out->color_range = (int)s->dst_format.pixel_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;