From ae737e30b1f84df6fa5f9bc9d293f2addd80fb0a Mon Sep 17 00:00:00 2001
From: Marc-Antoine Arnaud <arnaud.marcantoine@gmail.com>
Date: Wed, 8 Nov 2017 15:15:12 +0100
Subject: [PATCH] avfilter: fix stride for g_eq
Content-Type: text/x-patch; charset="utf-8"

---
 libavfilter/vf_geq.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/libavfilter/vf_geq.c b/libavfilter/vf_geq.c
index 85e88be092..af04864d0a 100644
--- a/libavfilter/vf_geq.c
+++ b/libavfilter/vf_geq.c
@@ -241,6 +241,7 @@ typedef struct ThreadData {
     int height;
     int width;
     int plane;
+    int linesize;
 } ThreadData;
 
 static int slice_geq_filter(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@@ -250,7 +251,8 @@ static int slice_geq_filter(AVFilterContext *ctx, void *arg, int jobnr, int nb_j
     const int height = td->height;
     const int width = td->width;
     const int plane = td->plane;
-    const int slice_start = (height *  jobnr   ) / nb_jobs;
+    const int linesize = td->linesize;
+    const int slice_start = (height *  jobnr) / nb_jobs;
     const int slice_end = (height * (jobnr+1)) / nb_jobs;
     int x, y;
     uint8_t *ptr;
@@ -267,26 +269,26 @@ static int slice_geq_filter(AVFilterContext *ctx, void *arg, int jobnr, int nb_j
 
     if (geq->depth == 8) {
         for (y = slice_start; y < slice_end; y++) {
-            ptr = geq->dst + width * y;
+            ptr = geq->dst + linesize * y;
             values[VAR_Y] = y;
 
             for (x = 0; x < width; x++) {
                 values[VAR_X] = x;
                 ptr[x] = av_expr_eval(geq->e[plane], values, geq);
             }
-            ptr += width;
+            ptr += linesize;
         }
     }
     else {
         for (y = slice_start; y < slice_end; y++) {
-            ptr16 = geq->dst16 + width * y;
+            ptr16 = geq->dst16 + linesize * y;
             values[VAR_Y] = y;
 
             for (x = 0; x < width; x++) {
                 values[VAR_X] = x;
                 ptr16[x] = av_expr_eval(geq->e[plane], values, geq);
             }
-            ptr16 += width;
+            ptr16 += linesize;
         }
     }
 
@@ -321,6 +323,7 @@ static int geq_filter_frame(AVFilterLink *inlink, AVFrame *in)
 
         geq->dst = out->data[plane];
         geq->dst16 = (uint16_t*)out->data[plane];
+        const int linesize = out->linesize[plane];
 
         geq->values[VAR_W]  = width;
         geq->values[VAR_H]  = height;
@@ -330,6 +333,7 @@ static int geq_filter_frame(AVFilterLink *inlink, AVFrame *in)
         td.width = width;
         td.height = height;
         td.plane = plane;
+        td.linesize = linesize;
 
         ctx->internal->execute(ctx, slice_geq_filter, &td, NULL, FFMIN(height, nb_threads));
     }
-- 
2.15.0

