diff options
| author | Vasile Vilvoiu <vasi.vilvoiu@gmail.com> | 2020-12-29 19:33:03 +0200 |
|---|---|---|
| committer | Vasile Vilvoiu <vasi.vilvoiu@gmail.com> | 2020-12-29 19:33:03 +0200 |
| commit | 26293db40f8ac62f3971e0e9dbbc0bf3439e61c0 (patch) | |
| tree | 218c93aba851c3c3123e9e72d25c974aa65cfd52 /src/color-map.hpp | |
Initial commit
Diffstat (limited to 'src/color-map.hpp')
| -rw-r--r-- | src/color-map.hpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/color-map.hpp b/src/color-map.hpp new file mode 100644 index 0000000..2878652 --- /dev/null +++ b/src/color-map.hpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2020-2021 Vasile Vilvoiu <vasi.vilvoiu@gmail.com> + * + * specgram is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See LICENSE for details. + */ + +#ifndef _COLOR_MAP_HPP_ +#define _COLOR_MAP_HPP_ + +#include "input-parser.hpp" + +#include <vector> +#include <memory> +#include <cstdint> +#include <SFML/Graphics.hpp> + +enum class ColorMapType { + /* MATLAB jet map */ + kJet, + + /* bicolor maps */ + kGray, + kPurple, + kBlue, + kGreen, + kOrange, + kRed, + + /* custom; bg->color */ + kCustom +}; + +class ColorMap { +protected: + ColorMap() = default; + +public: + ColorMap(const ColorMap&) = default; + + static std::unique_ptr<ColorMap> FromType(ColorMapType type, + const sf::Color& bg_color, + const sf::Color& custom_color); + + virtual std::vector<uint8_t> Map(const RealWindow& input) const = 0; + std::vector<uint8_t> Gradient(std::size_t width) const; +}; + +class InterpolationColorMap : public ColorMap { +private: + const std::vector<sf::Color> colors_; + const std::vector<double> values_; + + std::vector<uint8_t> GetColor(double value) const; + +protected: + InterpolationColorMap(const std::vector<sf::Color>& colors, const std::vector<double>& vals); + +public: + InterpolationColorMap() = delete; + + std::vector<uint8_t> Map(const std::vector<double>& input) const override; +}; + +class TwoColorMap : public InterpolationColorMap { +public: + TwoColorMap(const sf::Color& c1, const sf::Color& c2); +}; + +class ThreeColorMap : public InterpolationColorMap { +public: + ThreeColorMap(const sf::Color& c1, const sf::Color& c2, const sf::Color& c3); +}; + +class JetColorMap : public InterpolationColorMap { +public: + JetColorMap(); +}; + +#endif
\ No newline at end of file |
