<div dir="ltr"><div dir="ltr">Hi David,<div><br></div><div>Thank you for your patch.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 7 Dec 2020 at 18:02, David Plowman <<a href="mailto:david.plowman@raspberrypi.com">david.plowman@raspberrypi.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Add a method to the piecewise linear function (Pwl) class to compute<br>
the inverse of a given Pwl. If the input function is non-monotonic we<br>
can only produce a best effort "pseudo" inverse, and we signal this to<br>
the caller.<br>
<br>
Signed-off-by: David Plowman <<a href="mailto:david.plowman@raspberrypi.com" target="_blank">david.plowman@raspberrypi.com</a>><br></blockquote><div><br></div><div>Reviewed-by: Naushir Patuck <<a href="mailto:naush@raspberrypi.com">naush@raspberrypi.com</a>></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
 src/ipa/raspberrypi/controller/pwl.cpp | 27 ++++++++++++++++++++++++++<br>
 src/ipa/raspberrypi/controller/pwl.hpp |  3 +++<br>
 2 files changed, 30 insertions(+)<br>
<br>
diff --git a/src/ipa/raspberrypi/controller/pwl.cpp b/src/ipa/raspberrypi/controller/pwl.cpp<br>
index aa134a1f..70206418 100644<br>
--- a/src/ipa/raspberrypi/controller/pwl.cpp<br>
+++ b/src/ipa/raspberrypi/controller/pwl.cpp<br>
@@ -114,6 +114,33 @@ Pwl::PerpType Pwl::Invert(Point const &xy, Point &perp, int &span,<br>
        return PerpType::None;<br>
 }<br>
<br>
+Pwl Pwl::Inverse(bool *true_inverse, const double eps) const<br>
+{<br>
+       bool appended = false, prepended = false, neither = false;<br>
+       Pwl inverse;<br>
+<br>
+       for (Point const &p : points_) {<br>
+               if (inverse.Empty())<br>
+                       inverse.Append(p.y, p.x, eps);<br>
+               else if (p.y > inverse.points_.back().x - eps) {<br>
+                       inverse.Append(p.y, p.x, eps);<br>
+                       appended = true;<br>
+               } else if (p.y < inverse.points_.front().x + eps) {<br>
+                       inverse.Prepend(p.y, p.x, eps);<br>
+                       prepended = true;<br>
+               } else<br>
+                       neither = true;<br>
+       }<br>
+<br>
+       // This is not a proper inverse if we found ourselves putting points<br>
+       // onto both ends of the inverse, or if there were points that couldn't<br>
+       // go on either.<br>
+       if (true_inverse)<br>
+               *true_inverse = !(neither || (appended && prepended));<br>
+<br>
+       return inverse;<br>
+}<br>
+<br>
 Pwl Pwl::Compose(Pwl const &other, const double eps) const<br>
 {<br>
        double this_x = points_[0].x, this_y = points_[0].y;<br>
diff --git a/src/ipa/raspberrypi/controller/pwl.hpp b/src/ipa/raspberrypi/controller/pwl.hpp<br>
index 4f168551..484672f6 100644<br>
--- a/src/ipa/raspberrypi/controller/pwl.hpp<br>
+++ b/src/ipa/raspberrypi/controller/pwl.hpp<br>
@@ -80,6 +80,9 @@ public:<br>
        };<br>
        PerpType Invert(Point const &xy, Point &perp, int &span,<br>
                        const double eps = 1e-6) const;<br>
+       // Compute the inverse function. Indicate if it is a proper (true)<br>
+       // inverse, or only a best effort (e.g. input was non-monotonic).<br>
+       Pwl Inverse(bool *true_inverse = nullptr, const double eps = 1e-6) const;<br>
        // Compose two Pwls together, doing "this" first and "other" after.<br>
        Pwl Compose(Pwl const &other, const double eps = 1e-6) const;<br>
        // Apply function to (x,y) values at every control point.<br>
-- <br>
2.20.1<br>
<br>
_______________________________________________<br>
libcamera-devel mailing list<br>
<a href="mailto:libcamera-devel@lists.libcamera.org" target="_blank">libcamera-devel@lists.libcamera.org</a><br>
<a href="https://lists.libcamera.org/listinfo/libcamera-devel" rel="noreferrer" target="_blank">https://lists.libcamera.org/listinfo/libcamera-devel</a><br>
</blockquote></div></div>