Gradient.h 806 B

123456789101112131415161718192021222324252627282930313233
  1. #ifndef GRADIENT_H
  2. #define GRADIENT_H
  3. #include <vector>
  4. #include "Color.h"
  5. #include <tuple>
  6. #include <cinttypes>
  7. class Gradient
  8. {
  9. /// the colors of this gradient stored in linear RGB format
  10. /// so they can be easily interpolated
  11. std::vector<RGBColor> colors;
  12. float max;
  13. public:
  14. Gradient(void);
  15. Gradient(const std::vector<std::pair<RGBColor, float>>&, int precalcSteps = 10000);
  16. static Gradient defaultGradient(void);
  17. /*!
  18. * \brief get a color at a specific position in this gradient
  19. * \param x the position
  20. * \return the color in sRGB format
  21. */
  22. RGBColor get(float x) const;
  23. private:
  24. static RGBColor lerpColors(RGBColor a, RGBColor b, float val);
  25. std::tuple<RGBColor, RGBColor, float> getNeighbors(float x) const;
  26. };
  27. #endif // GRADIENT_H