1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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
|