From patchwork Mon Dec 7 18:01:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10601 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C512EBDB1F for ; Mon, 7 Dec 2020 18:02:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8F3C367E6B; Mon, 7 Dec 2020 19:02:24 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="ZjDcB23c"; dkim-atps=neutral Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CC2F667E6A for ; Mon, 7 Dec 2020 19:02:22 +0100 (CET) Received: by mail-ed1-x535.google.com with SMTP id u19so14720216edx.2 for ; Mon, 07 Dec 2020 10:02:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QxO4QgtZgd2HaiyXhTe2SCFiVm9KpKHiGeJ8yVR92K4=; b=ZjDcB23cp0M7qGXQvW80SA3lyCjOvPJwaQ8SsN+1WdcEIznHlagGb6+9BiQmJRZywp RvluOF/OB4W302If/7bWA3sNysG4mxeRtj4dGPBNqOThmlqXyOR1VlmN7dS9X408929Z i4OUKuYl3wmmzv4V8R02Ed9dMODRDLXg8G9Extq40i+P+wVG7mtA+rgLUcZ+hFz0uFm1 8j3IEltOvUgeeFhbm0oT5WJgMp89x6lHqAT32wF2QjTPhtlAAB7ZSPQQoKmKacwwu5E1 3wJMhnb6i39k64cT59cI03eE8iRvlBOzBo+Mp0FdrlWbrg9hY0YZHLPwSNBU1pkovP72 BOKQ== 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=QxO4QgtZgd2HaiyXhTe2SCFiVm9KpKHiGeJ8yVR92K4=; b=uink8xEBgyGG6xGD+IdHjZTH8tjNN/T00kKOUcxUb+LxkCsxGqR48kyvXb1sWO3rTa f7I93ds46WoYvAdCfvR8bUJf2IcbApznpZFLgjyCSDpAoqDv0DclbTFUNArjn+jn4OZy +SRXVITn5qe6ciN5BdnADwZyySgM81l86czALgsMorcrD9LgBsMwEAlAiTRYn13KwE6Q D854FNOlzNsfrVlD5QZ7JGpovjVGBKj1i2cMbvVz0RT3m2FjYf6k+NTq7kdSo8xakdze L9/MA189H6sH6rC2UrBkM0Kn0d+z7igjQ6+2RnsUaXNwzzQhy+nFnQ3SRdZW+vFeNdOs H0uA== X-Gm-Message-State: AOAM531MrRmh6N5WKxTq7NgzzX7yzyWciAWdaAAZ+k1NhQSsiyfXhN6f mweUmmP+4JpMccTUXkr9DJ/vZ++fxsdUf65u X-Google-Smtp-Source: ABdhPJwi7lNf0P3p6b8180GGqt/UWHjYZQcK31xlvqeOMCX23bq/18HCvR55yhloQ3mQZqeJ3I99yg== X-Received: by 2002:a05:6402:21c7:: with SMTP id bi7mr21822788edb.54.1607364142004; Mon, 07 Dec 2020 10:02:22 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id be6sm14657977edb.29.2020.12.07.10.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 10:02:16 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Dec 2020 18:01:19 +0000 Message-Id: <20201207180121.6374-5-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201207180121.6374-1-david.plowman@raspberrypi.com> References: <20201207180121.6374-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/6] src: ipa: raspberrypi: Compute inverse of piecewise linear function X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a method to the piecewise linear function (Pwl) class to compute the inverse of a given Pwl. If the input function is non-monotonic we can only produce a best effort "pseudo" inverse, and we signal this to the caller. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Laurent Pinchart --- src/ipa/raspberrypi/controller/pwl.cpp | 27 ++++++++++++++++++++++++++ src/ipa/raspberrypi/controller/pwl.hpp | 3 +++ 2 files changed, 30 insertions(+) diff --git a/src/ipa/raspberrypi/controller/pwl.cpp b/src/ipa/raspberrypi/controller/pwl.cpp index aa134a1f..70206418 100644 --- a/src/ipa/raspberrypi/controller/pwl.cpp +++ b/src/ipa/raspberrypi/controller/pwl.cpp @@ -114,6 +114,33 @@ Pwl::PerpType Pwl::Invert(Point const &xy, Point &perp, int &span, return PerpType::None; } +Pwl Pwl::Inverse(bool *true_inverse, const double eps) const +{ + bool appended = false, prepended = false, neither = false; + Pwl inverse; + + for (Point const &p : points_) { + if (inverse.Empty()) + inverse.Append(p.y, p.x, eps); + else if (p.y > inverse.points_.back().x - eps) { + inverse.Append(p.y, p.x, eps); + appended = true; + } else if (p.y < inverse.points_.front().x + eps) { + inverse.Prepend(p.y, p.x, eps); + prepended = true; + } else + neither = true; + } + + // This is not a proper inverse if we found ourselves putting points + // onto both ends of the inverse, or if there were points that couldn't + // go on either. + if (true_inverse) + *true_inverse = !(neither || (appended && prepended)); + + return inverse; +} + Pwl Pwl::Compose(Pwl const &other, const double eps) const { double this_x = points_[0].x, this_y = points_[0].y; diff --git a/src/ipa/raspberrypi/controller/pwl.hpp b/src/ipa/raspberrypi/controller/pwl.hpp index 4f168551..484672f6 100644 --- a/src/ipa/raspberrypi/controller/pwl.hpp +++ b/src/ipa/raspberrypi/controller/pwl.hpp @@ -80,6 +80,9 @@ public: }; PerpType Invert(Point const &xy, Point &perp, int &span, const double eps = 1e-6) const; + // Compute the inverse function. Indicate if it is a proper (true) + // inverse, or only a best effort (e.g. input was non-monotonic). + Pwl Inverse(bool *true_inverse = nullptr, const double eps = 1e-6) const; // Compose two Pwls together, doing "this" first and "other" after. Pwl Compose(Pwl const &other, const double eps = 1e-6) const; // Apply function to (x,y) values at every control point.