Chris@1068
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@1068
|
2
|
Chris@1068
|
3 /*
|
Chris@1068
|
4 Sonic Visualiser
|
Chris@1068
|
5 An audio file viewer and annotation editor.
|
Chris@1068
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@1068
|
7 This file copyright 2006-2016 Chris Cannam and QMUL.
|
Chris@1068
|
8
|
Chris@1068
|
9 This program is free software; you can redistribute it and/or
|
Chris@1068
|
10 modify it under the terms of the GNU General Public License as
|
Chris@1068
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@1068
|
12 License, or (at your option) any later version. See the file
|
Chris@1068
|
13 COPYING included with this distribution for more information.
|
Chris@1068
|
14 */
|
Chris@1068
|
15
|
Chris@1068
|
16 #ifndef COLOUR_SCALE_H
|
Chris@1068
|
17 #define COLOUR_SCALE_H
|
Chris@1068
|
18
|
Chris@1068
|
19 #include "ColourMapper.h"
|
Chris@1068
|
20
|
Chris@1105
|
21 enum class ColourScaleType {
|
Chris@1105
|
22 Linear,
|
Chris@1105
|
23 Meter,
|
Chris@1105
|
24 Log,
|
Chris@1105
|
25 Phase,
|
Chris@1105
|
26 PlusMinusOne,
|
Chris@1105
|
27 Absolute
|
Chris@1105
|
28 };
|
Chris@1105
|
29
|
Chris@1068
|
30 /**
|
Chris@1068
|
31 * Map values within a range onto a set of colours, with a given
|
Chris@1068
|
32 * distribution (linear, log etc) and optional colourmap rotation.
|
Chris@1068
|
33 */
|
Chris@1068
|
34 class ColourScale
|
Chris@1068
|
35 {
|
Chris@1068
|
36 public:
|
Chris@1070
|
37 struct Parameters {
|
Chris@1266
|
38 Parameters() : colourMap(0), scaleType(ColourScaleType::Linear),
|
Chris@1362
|
39 minValue(0.0), maxValue(1.0), inverted(false),
|
Chris@1266
|
40 threshold(0.0), gain(1.0), multiple(1.0) { }
|
Chris@1070
|
41
|
Chris@1266
|
42 /** A colour map index as used by ColourMapper */
|
Chris@1266
|
43 int colourMap;
|
Chris@1266
|
44
|
Chris@1266
|
45 /** Distribution for the scale */
|
Chris@1266
|
46 ColourScaleType scaleType;
|
Chris@1266
|
47
|
Chris@1266
|
48 /** Minimum value in source range */
|
Chris@1266
|
49 double minValue;
|
Chris@1266
|
50
|
Chris@1266
|
51 /** Maximum value in source range. Must be > minValue */
|
Chris@1266
|
52 double maxValue;
|
Chris@1070
|
53
|
Chris@1362
|
54 /** Whether the colour scale should be mapped inverted */
|
Chris@1362
|
55 bool inverted;
|
Chris@1362
|
56
|
Chris@1266
|
57 /** Threshold below which every value is mapped to background
|
Chris@1266
|
58 pixel 0 */
|
Chris@1266
|
59 double threshold;
|
Chris@1070
|
60
|
Chris@1266
|
61 /** Gain to apply before thresholding, mapping, and clamping */
|
Chris@1266
|
62 double gain;
|
Chris@1137
|
63
|
Chris@1137
|
64 /** Multiple to apply after thresholding and mapping. In most
|
Chris@1137
|
65 * cases the gain parameter is the one you want instead of
|
Chris@1137
|
66 * this, but this can be used for example with Log scale to
|
Chris@1137
|
67 * produce the log of some power of the original value,
|
Chris@1137
|
68 * e.g. multiple = 2 gives log(x^2). */
|
Chris@1137
|
69 double multiple;
|
Chris@1070
|
70 };
|
Chris@1070
|
71
|
Chris@1068
|
72 /**
|
Chris@1070
|
73 * Create a ColourScale with the given parameters.
|
Chris@1068
|
74 *
|
Chris@1068
|
75 * Note that some parameters may be ignored for some scale
|
Chris@1068
|
76 * distribution settings. For example, min and max are ignored for
|
Chris@1068
|
77 * PlusMinusOneScale and PhaseColourScale and threshold and gain
|
Chris@1068
|
78 * are ignored for PhaseColourScale.
|
Chris@1068
|
79 */
|
Chris@1070
|
80 ColourScale(Parameters parameters);
|
Chris@1071
|
81 ~ColourScale();
|
Chris@1068
|
82
|
Chris@1071
|
83 ColourScale(const ColourScale &) = default;
|
Chris@1071
|
84 ColourScale &operator=(const ColourScale &) = default;
|
Chris@1079
|
85
|
Chris@1079
|
86 /**
|
Chris@1079
|
87 * Return the general type of scale this is.
|
Chris@1079
|
88 */
|
Chris@1105
|
89 ColourScaleType getScale() const;
|
Chris@1071
|
90
|
Chris@1068
|
91 /**
|
Chris@1068
|
92 * Return a pixel number (in the range 0-255 inclusive)
|
Chris@1068
|
93 * corresponding to the given value. The pixel 0 is used only for
|
Chris@1068
|
94 * values below the threshold supplied in the constructor. All
|
Chris@1068
|
95 * other values are mapped onto the range 1-255.
|
Chris@1068
|
96 */
|
Chris@1079
|
97 int getPixel(double value) const;
|
Chris@1068
|
98
|
Chris@1068
|
99 /**
|
Chris@1068
|
100 * Return the colour for the given pixel number (which must be in
|
Chris@1068
|
101 * the range 0-255). The pixel 0 is always the background
|
Chris@1068
|
102 * colour. Other pixels are mapped taking into account the given
|
Chris@1068
|
103 * colourmap rotation (which is also a value in the range 0-255).
|
Chris@1068
|
104 */
|
Chris@1079
|
105 QColor getColourForPixel(int pixel, int rotation) const;
|
Chris@1068
|
106
|
Chris@1068
|
107 /**
|
Chris@1068
|
108 * Return the colour corresponding to the given value. This is
|
Chris@1068
|
109 * equivalent to getColourForPixel(getPixel(value), rotation).
|
Chris@1068
|
110 */
|
Chris@1079
|
111 QColor getColour(double value, int rotation) const {
|
Chris@1266
|
112 return getColourForPixel(getPixel(value), rotation);
|
Chris@1068
|
113 }
|
Chris@1068
|
114
|
Chris@1068
|
115 private:
|
Chris@1070
|
116 Parameters m_params;
|
Chris@1068
|
117 ColourMapper m_mapper;
|
Chris@1068
|
118 double m_mappedMin;
|
Chris@1068
|
119 double m_mappedMax;
|
Chris@1068
|
120 static int m_maxPixel;
|
Chris@1068
|
121 };
|
Chris@1068
|
122
|
Chris@1068
|
123 #endif
|