/* SPDX-License-Identifier: BSD-2-Clause */ /* * Copyright (C) 2019, Raspberry Pi Ltd * * Piecewise linear functions interface */ #pragma once #include #include #include #include #include #include #include "libcamera/internal/yaml_parser.h" #include "vector.h" namespace libcamera { namespace ipa { class Pwl { public: using Point = Vector; struct Interval { Interval(double _start, double _end) : start(_start), end(_end) {} bool contains(double value) { return value >= start && value <= end; } double clamp(double value) { return std::clamp(value, start, end); } double length() const { return end - start; } double start, end; }; Pwl(); Pwl(const std::vector &points); Pwl(std::vector &&points); int readYaml(const libcamera::YamlObject ¶ms); void append(double x, double y, double eps = 1e-6); bool empty() const { return points_.empty(); } size_t size() const { return points_.size(); } Interval domain() const; Interval range() const; double eval(double x, int *span = nullptr, bool updateSpan = true) const; std::pair inverse(double eps = 1e-6) const; Pwl compose(const Pwl &other, double eps = 1e-6) const; void map(std::function f) const; static Pwl combine(const Pwl &pwl0, const Pwl &pwl1, std::function f, double eps = 1e-6); Pwl &operator*=(double d); std::string toString() const; private: static void map2(const Pwl &pwl0, const Pwl &pwl1, std::function f); void prepend(double x, double y, double eps = 1e-6); int findSpan(double x, int span) const; std::vector points_; }; } /* namespace ipa */ } /* namespace libcamera */