#pragma once // STL includes #include /// Transform for a single color byte value /// /// Transforms are applied in the following order: /// 1) a threshold is applied. All values below threshold will be set to zero /// 2) gamma color correction is applied /// 3) the output value is scaled from the [0:1] to [blacklevel:whitelevel] /// 4) finally, in case of a weird choice of parameters, the output is clamped between [0:1] /// /// All configuration values are doubles and assume the color value to be between 0 and 1 class ColorTransform { public: /// @brief Default constructor ColorTransform(); /// @brief Constructor /// @param threshold /// @param gamma /// @param blacklevel /// @param whitelevel ColorTransform(double threshold, double gamma, double blacklevel, double whitelevel); /// @brief Destructor ~ColorTransform(); /// @return The current threshold value double getThreshold() const; /// @param threshold New threshold value void setThreshold(double threshold); /// @return The current gamma value double getGamma() const; /// @param gamma New gamma value void setGamma(double gamma); /// @return The current blacklevel value double getBlacklevel() const; /// @param blacklevel New blacklevel value void setBlacklevel(double blacklevel); /// @return The current whitelevel value double getWhitelevel() const; /// @param whitelevel New whitelevel value void setWhitelevel(double whitelevel); /// @brief Transform the given byte value /// @param input The input color byte /// @return The transformed byte value uint8_t transform(uint8_t input) const { return _mapping[input]; } private: /// @brief (re)-initilize the color mapping void initializeMapping(); private: double _threshold; double _gamma; double _blacklevel; double _whitelevel; uint8_t _mapping[256]; };