Gradient.h 981 B

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