From patchwork Fri Mar 19 11:53:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Playfair Cal X-Patchwork-Id: 26487 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 A0CE044B518 for ; Fri, 19 Mar 2021 14:01:35 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7B3C068819D; Fri, 19 Mar 2021 14:01:35 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D7425688126 for ; Fri, 19 Mar 2021 14:01:28 +0200 (EET) Received: by mail-pf1-f169.google.com with SMTP id l3so5740804pfc.7 for ; Fri, 19 Mar 2021 05:01:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BWcKzWX338/NBKp8CMVHCUyygwJa0uc8cgPDJVbFKTU=; b=BWnbIuHe+g331SrCPKKXBw4n4a7pEtYxQldof4qKcaOvAvwh9pWrftB38A1mSGvUbE FANPKNFwA4c6FDPgkEQnfL9kJlkWH2IRwDhIomV850Cm1QQw5q+vb2GCj0xq2D29X/Qp 19XaQ67h5cu6kA+yd/9BmUTWni2GaW4w0L2MlmmCEtzdS4w1uCvJtJywqt/TNcuhNjwO u6SC4vqCZIb3spL+F4Z2suGUaCKarWJ0I/96iXI13PoAF5VsXRc3CfuMkWkIdaCgXHWd Uhjl3Afp6gt6nlxoO88oLm/BYAs3vjoPb8uS0kjbo9GTrQYoIG0JhT0+S7QglGn9T5cF 2D6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BWcKzWX338/NBKp8CMVHCUyygwJa0uc8cgPDJVbFKTU=; b=HYha/G3IVTdcH4gQJxgAwCqA6WatJEiJ4HJLqNTSFELBbJ+72rnPZ+d/LH20Kcjync 5ZSbIGf29742RQX/bQolOKCfeut4OR4MkHZCgWG9rPamTT0y1zVS/Qh0AN58hN19G7D5 fWIQT1iXMawDbVB5YGCOXlUcDbS64LLvdwiqpLP43Xr4qVEb82T7H7nbWk8JHBr/EjI7 rXko822y8xhHK2S1KB3aKbLvVvD2TNYGOO0Di2LM+HWDuJx6N6mbMv404g8FC6rurHFU 94jFkcU/6VvA4paoj6AYRvO/jsaJ4hOA0xpxbkFTa4na3P8IftS+9ZLbRHoojA1rhF8z GUCA== X-Gm-Message-State: AOAM531WQv5SHG5+dFUY6MiHtFVORR87FdS7f9BO+YAt21dmQ1XlzCXY YmsJDQwHS6NboSWmLKlG1m4vQbBUwzzppQ== X-Google-Smtp-Source: ABdhPJxy7M4vj4R1LnO3jgkOD3a9VdIisM9MkneyRWvXxrkNUJ8gRUQLI18BVyoJ/jnvBWrznzGXTA== X-Received: by 2002:a05:6a00:2b4:b029:1f6:6f37:ef92 with SMTP id q20-20020a056a0002b4b02901f66f37ef92mr8724106pfs.56.1616154841447; Fri, 19 Mar 2021 04:54:01 -0700 (PDT) Received: from localhost.localdomain (110-175-121-4.static.tpgi.com.au. [110.175.121.4]) by smtp.gmail.com with ESMTPSA id gk12sm5205365pjb.44.2021.03.19.04.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 04:54:00 -0700 (PDT) From: Daniel Playfair Cal To: ffmpeg-devel@ffmpeg.org Date: Fri, 19 Mar 2021 22:53:54 +1100 Message-Id: <20210319115354.943985-1-daniel.playfair.cal@gmail.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <277993> References: <277993> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] vf_v360: fix (i)flat_range for fisheye projection 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 Cc: Daniel Playfair Cal Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This changes the iflat_range and flat_range values for the fisheye projection so that they indicate the maximum angle between an observed point and the center (direction the camera is facing). This matches the meaning of those variables in the flat projection. Signed-off-by: Daniel Playfair Cal --- This version avoids the use of double literals. libavfilter/vf_v360.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c index 94473cd5b3..d4f0836937 100644 --- a/libavfilter/vf_v360.c +++ b/libavfilter/vf_v360.c @@ -2807,9 +2807,8 @@ static int prepare_fisheye_out(AVFilterContext *ctx) { V360Context *s = ctx->priv; - s->flat_range[0] = s->h_fov / 180.f; - s->flat_range[1] = s->v_fov / 180.f; - + s->flat_range[0] = 0.5 * s->h_fov * M_PI / 180.f; + s->flat_range[1] = 0.5 * s->v_fov * M_PI / 180.f; return 0; } @@ -2827,8 +2826,8 @@ static int fisheye_to_xyz(const V360Context *s, int i, int j, int width, int height, float *vec) { - const float uf = s->flat_range[0] * ((2.f * i) / width - 1.f); - const float vf = s->flat_range[1] * ((2.f * j + 1.f) / height - 1.f); + const float uf = 2.f * s->flat_range[0] / M_PI * ((2.f * i) / width - 1.f); + const float vf = 2.f * s->flat_range[1] / M_PI * ((2.f * j + 1.f) / height - 1.f); const float phi = atan2f(vf, uf); const float theta = M_PI_2 * (1.f - hypotf(uf, vf)); @@ -2858,8 +2857,8 @@ static int prepare_fisheye_in(AVFilterContext *ctx) { V360Context *s = ctx->priv; - s->iflat_range[0] = s->ih_fov / 180.f; - s->iflat_range[1] = s->iv_fov / 180.f; + s->iflat_range[0] = 0.5 * s->ih_fov * M_PI / 180.f; + s->iflat_range[1] = 0.5 * s->iv_fov * M_PI / 180.f; return 0; } @@ -2882,10 +2881,10 @@ static int xyz_to_fisheye(const V360Context *s, { const float h = hypotf(vec[0], vec[1]); const float lh = h > 0.f ? h : 1.f; - const float phi = atan2f(h, vec[2]) / M_PI; + const float phi = atan2f(h, vec[2]); - float uf = vec[0] / lh * phi / s->iflat_range[0]; - float vf = vec[1] / lh * phi / s->iflat_range[1]; + float uf = 0.5f * vec[0] / lh * phi / s->iflat_range[0]; + float vf = 0.5f * vec[1] / lh * phi / s->iflat_range[1]; const int visible = hypotf(uf, vf) <= 0.5f; int ui, vi;