diff mbox series

[FFmpeg-devel,2/2] avfilter/vf_zscale: fix mapping of zimg_chroma_location_e to AVChromaLocation

Message ID 20211027222024.53018-2-jeebjp@gmail.com
State Accepted
Commit 27c0dd55609daf440a7744e96ac20c119bbeb80f
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
The AVChromaLocation values are one higher than zimg's, not one
lower as the undefined value is set to zero (as opposed to zimg's
-1).
---
 libavfilter/vf_zscale.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jan Ekström Oct. 28, 2021, 9:52 a.m. UTC | #1
On Thu, Oct 28, 2021 at 1:25 AM Paul B Mahol <onemda@gmail.com> wrote:
>
> probably fine

This can be verified by specifying - say - chromal topleft, and seeing
that the ffmpeg.c Output: bit right now would end up being "left"
(most likely). While if you apply this, you should get "topleft".

Technically if the values were unsanitized, having a mapping function
like we have the other way would be better, but since the code already
utilized +/- 1... I went with that way of just fixing the logic to go
the right way.

For verification of the internal values, something like the following
can be utilized:

diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
index 1288c5efc1..50df90e9ec 100644
--- a/libavfilter/vf_zscale.c
+++ b/libavfilter/vf_zscale.c
@@ -126,6 +126,8 @@ typedef struct ZScaleContext {
     enum AVColorPrimaries in_primaries, out_primaries;
     enum AVColorRange in_range, out_range;
     enum AVChromaLocation in_chromal, out_chromal;
+
+    int lel;
 } ZScaleContext;

 static av_cold int init(AVFilterContext *ctx)
@@ -687,6 +689,12 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)

     update_output_color_information(s, out);

+    av_log_once(s, AV_LOG_VERBOSE, AV_LOG_TRACE, &(s->lel),
+                "output frame chroma location: %s "
+                "(s->chromal: %d, dst_format.chroma_location: %d)\n",
+                av_chroma_location_name(out->chroma_location),
+                s->chromal, s->dst_format.chroma_location);
+
     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,
diff mbox series

Patch

diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
index 439c0c8548..1288c5efc1 100644
--- a/libavfilter/vf_zscale.c
+++ b/libavfilter/vf_zscale.c
@@ -569,7 +569,7 @@  static void update_output_color_information(ZScaleContext *s, AVFrame *frame)
         frame->color_trc = (int)s->dst_format.transfer_characteristics;
 
     if (s->chromal != -1)
-        frame->chroma_location = (int)s->dst_format.chroma_location - 1;
+        frame->chroma_location = (int)s->dst_format.chroma_location + 1;
 }
 
 static int filter_frame(AVFilterLink *link, AVFrame *in)