From f3b94ec94002c9557ecd2c32dc619d7ddb3fba0c Mon Sep 17 00:00:00 2001 From: Tomas Farago Date: Wed, 11 Dec 2019 14:57:08 +0100 Subject: flatten: average two middle values on even depth --- src/ufo-flatten-task.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ufo-flatten-task.c b/src/ufo-flatten-task.c index 36c45e7..c59e2be 100644 --- a/src/ufo-flatten-task.c +++ b/src/ufo-flatten-task.c @@ -136,7 +136,12 @@ ufo_flatten_task_process (UfoTask *task, tmp[i] = in_mem[i * width * height + y * width + x]; qsort ((gpointer) tmp, depth, sizeof(gfloat), cmp_float); - out_mem[y * width + x] = tmp[depth / 2]; + if (depth % 2) { + out_mem[y * width + x] = tmp[depth / 2]; + } else { + /* Average two middle values if depth is even */ + out_mem[y * width + x] = (tmp[depth / 2] + tmp[depth / 2 - 1]) / 2.0f; + } } } -- cgit v1.2.1