From patchwork Tue Mar 31 13:51:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 18543 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 64DD144BA5E for ; Tue, 31 Mar 2020 16:58:53 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5427268B1AA; Tue, 31 Mar 2020 16:58:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6A42768B1A2 for ; Tue, 31 Mar 2020 16:58:46 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id z14so2137138wmf.0 for ; Tue, 31 Mar 2020 06:58:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=GHMiqkMvEv+FCD1MMlD3A5aGxu8e7uvsbK44c7mlxUg=; b=eG7WyrOyN+Wv7AEYd7jYfYuBfOAwYG9pd/4exQa6kQ6swAixIRg5GmQZaZHmGAjISL gO0V/6r3Lj4g5ZHYREtPRrWXEzMC0IPB+q0Lz74tnDQM/NMWUXTBroS1C6xYM2ZPx7hN WKMQyCfXHuz8nQnDuA9fTkQ56Epmoubv2YQviq8GPLLuQQLK5HqxneMLiQsrTRcew7Dm uwNlg8qO2mPNOw+P3RG41VPkTutvFnm4Jx99cO/7+kMB9/JPWxAeVGHOCicKJj8naczi SUmGDLc0UblJ80R/O9/9HSm2kEovrgMT/XYH0or0C7rUeH6snSCtFjGTvibiXhGj6HUC eRYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=GHMiqkMvEv+FCD1MMlD3A5aGxu8e7uvsbK44c7mlxUg=; b=kC/QDcGzSb9JePAlNNP+5hSYxB44+E/dxaJoWJS2IsOPvY8GqsK/T2ZFAhsKd8zScN +e5HYyeztAjxk0d12YptBoPUesv1xUvZE/QPdFZpsyDWjNShPY6j/tkl1h8jWq5gC+9D szDjILLhYuowe1l+7tTJ0lGOmVOIuxbyASBnewx3mP54FKGv9De/BIZVqBZss6R26JU9 zw/bYLopBAvf1vMul3YE43gTmpFRZNsKU3M34I+Pbm85ZGHLlhUYSPExi6iaEJuvbks0 9aueUVWlf3MflBniR9j4HuqTPbBkHq1z2g8b9oPrIL31rCYDvk5rTFPGC9kFMPhiytd9 VffQ== X-Gm-Message-State: ANhLgQ0vHmpSnKtPJmdxDe11wliQyZQNFRqWLhoR0i6gcKIahO/gSR/H qMqNw20RfSd9xXA34gVJlQqh8Ej9 X-Google-Smtp-Source: ADFU+vvE1hERNkg77H2TQercsLJui0DhJoZdLAIOtZ80QA8Z+eTQcF11hd9Ao1Ac4iUrYJR4AHW5lA== X-Received: by 2002:a1c:2007:: with SMTP id g7mr3625710wmg.70.1585662677392; Tue, 31 Mar 2020 06:51:17 -0700 (PDT) Received: from localhost.localdomain ([37.244.237.154]) by smtp.gmail.com with ESMTPSA id q8sm28518739wrc.8.2020.03.31.06.51.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 06:51:16 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Tue, 31 Mar 2020 15:51:05 +0200 Message-Id: <20200331135106.32490-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_v360: add lagrange interpolation X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- doc/filters.texi | 2 ++ libavfilter/v360.h | 1 + libavfilter/vf_v360.c | 56 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index 44d41a87cf..8827aac316 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -19105,6 +19105,8 @@ Nearest neighbour. @item line @item linear Bilinear interpolation. +@item lagrange +Lagrange interpolation. @item cube @item cubic Bicubic interpolation. diff --git a/libavfilter/v360.h b/libavfilter/v360.h index f2f1a47144..1d4098e5c1 100644 --- a/libavfilter/v360.h +++ b/libavfilter/v360.h @@ -57,6 +57,7 @@ enum Projections { enum InterpMethod { NEAREST, BILINEAR, + LAGRANGE, BICUBIC, LANCZOS, SPLINE16, diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c index 54d4d23825..ca8e55e32c 100644 --- a/libavfilter/vf_v360.c +++ b/libavfilter/vf_v360.c @@ -112,6 +112,7 @@ static const AVOption v360_options[] = { { "nearest", "nearest neighbour", 0, AV_OPT_TYPE_CONST, {.i64=NEAREST}, 0, 0, FLAGS, "interp" }, { "line", "bilinear interpolation", 0, AV_OPT_TYPE_CONST, {.i64=BILINEAR}, 0, 0, FLAGS, "interp" }, { "linear", "bilinear interpolation", 0, AV_OPT_TYPE_CONST, {.i64=BILINEAR}, 0, 0, FLAGS, "interp" }, + { "lagrange", "lagrange interpolation", 0, AV_OPT_TYPE_CONST, {.i64=LAGRANGE}, 0, 0, FLAGS, "interp" }, { "cube", "bicubic interpolation", 0, AV_OPT_TYPE_CONST, {.i64=BICUBIC}, 0, 0, FLAGS, "interp" }, { "cubic", "bicubic interpolation", 0, AV_OPT_TYPE_CONST, {.i64=BICUBIC}, 0, 0, FLAGS, "interp" }, { "lanc", "lanczos interpolation", 0, AV_OPT_TYPE_CONST, {.i64=LANCZOS}, 0, 0, FLAGS, "interp" }, @@ -313,9 +314,11 @@ static int remap##ws##_##bits##bit_slice(AVFilterContext *ctx, void *arg, int jo DEFINE_REMAP(1, 8) DEFINE_REMAP(2, 8) +DEFINE_REMAP(3, 8) DEFINE_REMAP(4, 8) DEFINE_REMAP(1, 16) DEFINE_REMAP(2, 16) +DEFINE_REMAP(3, 16) DEFINE_REMAP(4, 16) #define DEFINE_REMAP_LINE(ws, bits, div) \ @@ -346,8 +349,10 @@ static void remap##ws##_##bits##bit_line_c(uint8_t *dst, int width, const uint8_ } DEFINE_REMAP_LINE(2, 8, 1) +DEFINE_REMAP_LINE(3, 8, 1) DEFINE_REMAP_LINE(4, 8, 1) DEFINE_REMAP_LINE(2, 16, 2) +DEFINE_REMAP_LINE(3, 16, 2) DEFINE_REMAP_LINE(4, 16, 2) void ff_v360_init(V360Context *s, int depth) @@ -359,6 +364,9 @@ void ff_v360_init(V360Context *s, int depth) case BILINEAR: s->remap_line = depth <= 8 ? remap2_8bit_line_c : remap2_16bit_line_c; break; + case LAGRANGE: + s->remap_line = depth <= 8 ? remap3_8bit_line_c : remap3_16bit_line_c; + break; case BICUBIC: case LANCZOS: case SPLINE16: @@ -417,6 +425,47 @@ static void bilinear_kernel(float du, float dv, const XYRemap *rmap, ker[3] = lrintf( du * dv * 16385.f); } +/** + * Calculate 1-dimensional lagrange coefficients. + * + * @param t relative coordinate + * @param coeffs coefficients + */ +static inline void calculate_lagrange_coeffs(float t, float *coeffs) +{ + coeffs[0] = (t - 1.f) * (t - 2.f) * 0.5f; + coeffs[1] = -t * (t - 2.f); + coeffs[2] = t * (t - 1.f) * 0.5f; +} + +/** + * Calculate kernel for lagrange interpolation. + * + * @param du horizontal relative coordinate + * @param dv vertical relative coordinate + * @param rmap calculated 4x4 window + * @param u u remap data + * @param v v remap data + * @param ker ker remap data + */ +static void lagrange_kernel(float du, float dv, const XYRemap *rmap, + int16_t *u, int16_t *v, int16_t *ker) +{ + float du_coeffs[3]; + float dv_coeffs[3]; + + calculate_lagrange_coeffs(du, du_coeffs); + calculate_lagrange_coeffs(dv, dv_coeffs); + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + u[i * 3 + j] = rmap->u[i+1][j+1]; + v[i * 3 + j] = rmap->v[i+1][j+1]; + ker[i * 3 + j] = lrintf(du_coeffs[j] * dv_coeffs[i] * 16385.f); + } + } +} + /** * Calculate 1-dimensional cubic coefficients. * @@ -3689,6 +3738,13 @@ static int config_output(AVFilterLink *outlink) sizeof_uv = sizeof(int16_t) * s->elements; sizeof_ker = sizeof(int16_t) * s->elements; break; + case LAGRANGE: + s->calculate_kernel = lagrange_kernel; + s->remap_slice = depth <= 8 ? remap3_8bit_slice : remap3_16bit_slice; + s->elements = 3 * 3; + sizeof_uv = sizeof(int16_t) * s->elements; + sizeof_ker = sizeof(int16_t) * s->elements; + break; case BICUBIC: s->calculate_kernel = bicubic_kernel; s->remap_slice = depth <= 8 ? remap4_8bit_slice : remap4_16bit_slice;