+static int filter16_roberts(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+{
+ ConvolutionContext *s = ctx->priv;
+ ThreadData *td = arg;
+ AVFrame *in = td->in;
+ AVFrame *out = td->out;
+ const int plane = td->plane;
+ const int peak = (1 << s->depth) - 1;
+ const int stride = in->linesize[plane] / 2;
+ const int bstride = s->bstride;
+ const int height = s->planeheight[plane];
+ const int width = s->planewidth[plane];
+ const int slice_start = (height * jobnr) / nb_jobs;
+ const int slice_end = (height * (jobnr+1)) / nb_jobs;
+ const uint16_t *src = (const uint16_t *)in->data[plane] + slice_start * stride;
+ uint16_t *dst = (uint16_t *)out->data[plane] + slice_start * (out->linesize[plane] / 2);
+ const float scale = s->scale;
+ const float delta = s->delta;
+ uint16_t *p0 = (uint16_t *)s->bptrs[jobnr] + 16;
+ uint16_t *p1 = p0 + bstride;
+ uint16_t *p2 = p1 + bstride;
+ uint16_t *orig = p0, *end = p2;
+ int y, x;
+
+ line_copy16(p0, src + stride * (slice_start == 0 ? 1 : -1), width, 1);
+ line_copy16(p1, src, width, 1);
+
+ for (y = slice_start; y < slice_end; y++) {
+ src += stride * (y < height - 1 ? 1 : -1);
+ line_copy16(p2, src, width, 1);
+
+ for (x = 0; x < width; x++) {
+ int suma = p0[x - 1] * 1 +
+ p1[x ] * -1;
+ int sumb = p0[x ] * 1 +
+ p1[x - 1] * -1;
+
+ dst[x] = av_clip(sqrt(suma*suma + sumb*sumb) * scale + delta, 0, peak);
+ }
+
+ p0 = p1;
+ p1 = p2;
+ p2 = (p2 == end) ? orig: p2 + bstride;
+ dst += out->linesize[plane] / 2;
+ }
+
+ return 0;
+}
+