Skip to content

Commit

Permalink
getRelative multiplier as runtime parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSaw committed Apr 26, 2021
1 parent 6b59807 commit 631610d
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 126 deletions.
39 changes: 20 additions & 19 deletions src/modm/ui/color/brightness.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#include <stdint.h>

#include <modm/io/iostream.hpp>
#include <concepts>
#include <modm/io/iostream.hpp>

#include "hsv.hpp"
#include "rgb.hpp"
Expand All @@ -36,12 +36,13 @@ class HsvT;
class Rgb565;

/**
* Brightness, used with grayscale and monochrome displays, dimmed leds, brightness sensors
* @brief Brightness as unsigned integral. Add's the math for conversion to and from
* Color-Types. Use with: Grayscale Buffers, Dimmed LEDs, Brightness sensors
*
* @author Thomas Sommer
*
* \author Thomas Sommer
*
* \tparam T Unsigned Int for storing the brightness
* \ingroup modm_ui_color
* \tparam T Unsigned integral for the brightness-value
* @ingroup modm_ui_color
*/

template<std::unsigned_integral T = uint8_t>
Expand All @@ -52,37 +53,37 @@ class BrightnessT

constexpr BrightnessT() = default;

constexpr BrightnessT(T value) : value(value)
{}
constexpr BrightnessT(T value) : value(value) {}

/**
* Convertion Constructor for RGB Color
*
* \param rgb RGB Color
* @param rgb RGB Color
*/
template<std::unsigned_integral _T>
constexpr BrightnessT(RgbT<_T> rgb)
: value((0.2125 * float(rgb.red)) + (0.7154 * float(rgb.green)) + (0.0721 * float(rgb.blue)))
template<std::unsigned_integral U>
constexpr BrightnessT(RgbT<U> rgb)
: value((0.2125 * float(rgb.red)) + (0.7154 * float(rgb.green)) +
(0.0721 * float(rgb.blue)))
{}

/**
* Convertion Constructor for HSV Color
*
* \param hsv HSV Color
* @param hsv HSV Color
*/
template<std::unsigned_integral _T>
constexpr BrightnessT(HsvT<_T> hsv) : value(hsv.value)
template<std::unsigned_integral U>
constexpr BrightnessT(HsvT<U> hsv) : value(hsv.value)
{}

/**
* Convertion Constructor for RGB565 Color
*
* \param rgb565 RGB565 Color
* @param rgb565 RGB565 Color
*/
constexpr BrightnessT(Rgb565 rgb565) : BrightnessT<T>(RgbT<uint8_t>(rgb565))
{}
constexpr BrightnessT(Rgb565 rgb565) : BrightnessT<T>(RgbT<uint8_t>(rgb565)) {}

constexpr bool operator==(const BrightnessT<T> &other) const = default;
constexpr bool
operator==(const BrightnessT<T> &other) const = default;
};

/// @ingroup modm_ui_color
Expand Down
28 changes: 14 additions & 14 deletions src/modm/ui/color/hsv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class BrightnessT;
class Rgb565;

/**
* Color in HSV Colorspace
* @brief Color in HSV Colorspace
*
* @author Martin Rosekeit, Fabian Greif, Niklas Hauser, David Hebbeker, Thomas Sommer
* @ingroup modm_ui_color
* @author Martin Rosekeit, Fabian Greif, Niklas Hauser, David Hebbeker, Thomas Sommer
* @ingroup modm_ui_color
*/

// TODO conecpt to only allow unsigned int or float
Expand All @@ -62,42 +62,42 @@ class HsvT
/**
* Convertion Constructor for RGB Color
*
* \param rgb RGB Color
* @param rgb RGB Color
*/
template<std::unsigned_integral _T>
constexpr HsvT(const RgbT<_T>& rgb);
template<std::unsigned_integral U>
constexpr HsvT(const RgbT<U>& rgb);

/**
* Convertion Constructor for Brightness
*
* \param brightness Brightness 'Color'-object
* @param brightness Brightness 'Color'-object
*/
template<std::unsigned_integral _T>
constexpr HsvT(const BrightnessT<_T> gray) : hue(0), saturation(0), value(gray.value)
template<std::unsigned_integral U>
constexpr HsvT(const BrightnessT<U> gray) : hue(0), saturation(0), value(gray.value)
{}

/**
* Convertion Constructor for RGB565 Color
*
* \param rgb565 RGB565 Color
* @param rgb565 RGB565 Color
*/
constexpr HsvT(const Rgb565& rgb565) : HsvT(RgbT<uint8_t>(rgb565)) {}

constexpr bool
operator==(const HsvT<T>& other) const = default;

private:
template<std::unsigned_integral _T>
template<std::unsigned_integral U>
friend IOStream&
operator<<(IOStream& os, const HsvT<_T>&);
operator<<(IOStream& os, const HsvT<U>&);
};

/// @ingroup modm_ui_color
using Hsv = HsvT<>;

template<std::unsigned_integral _T>
template<std::unsigned_integral U>
IOStream&
operator<<(IOStream& os, const color::HsvT<_T>& color);
operator<<(IOStream& os, const color::HsvT<U>& color);

} // namespace color
} // namespace modm
Expand Down
8 changes: 4 additions & 4 deletions src/modm/ui/color/hsv_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
* @param rgb
*/
template<std::unsigned_integral T>
template<std::unsigned_integral _T>
constexpr modm::color::HsvT<T>::HsvT(const modm::color::RgbT<_T> &rgb)
template<std::unsigned_integral U>
constexpr modm::color::HsvT<T>::HsvT(const modm::color::RgbT<U> &rgb)
{
using CalcType = float;
const CalcType maxValue = std::numeric_limits<T>::max();
Expand Down Expand Up @@ -70,9 +70,9 @@ constexpr modm::color::HsvT<T>::HsvT(const modm::color::RgbT<_T> &rgb)
saturation = _diff / _max * maxValue;
}

template<std::unsigned_integral _T>
template<std::unsigned_integral U>
modm::IOStream &
modm::color::operator<<(modm::IOStream &os, const modm::color::HsvT<_T> &color)
modm::color::operator<<(modm::IOStream &os, const modm::color::HsvT<U> &color)
{
os << color.hue << "\t" << color.saturation << "\t" << color.value;
return os;
Expand Down
Loading

0 comments on commit 631610d

Please sign in to comment.