Color.cpp 639 B

12345678910111213141516171819202122232425
  1. #include "Color.h"
  2. #include <cmath>
  3. #include <algorithm>
  4. const static float cGamma = 1.0f;
  5. RGBColor::RGBColor(const RGBColorf& rgb)
  6. {
  7. float cr = std::clamp(rgb.r, 0.0f, 1.0f);
  8. float cg = std::clamp(rgb.g, 0.0f, 1.0f);
  9. float cb = std::clamp(rgb.b, 0.0f, 1.0f);
  10. const float invGamma = 1.0f / cGamma;
  11. r = uint8_t(::powf(cr, invGamma) * 255.0f);
  12. g = uint8_t(::powf(cg, invGamma) * 255.0f);
  13. b = uint8_t(::powf(cb, invGamma) * 255.0f);
  14. }
  15. RGBColorf::RGBColorf(const RGBColor& srgb)
  16. {
  17. r = ::powf(srgb.r / 255.0f, cGamma);
  18. g = ::powf(srgb.g / 255.0f, cGamma);
  19. b = ::powf(srgb.b / 255.0f, cGamma);
  20. }