Mercurial > hg > svgui
comparison layer/ColourScale.h @ 1068:521f7e8b0559 spectrogram-minor-refactor
Introduce ColourScale to handle colour mapping for both spectrogram and colour 3d plot layers
author | Chris Cannam |
---|---|
date | Thu, 23 Jun 2016 14:42:37 +0100 |
parents | |
children | 27163db978d8 |
comparison
equal
deleted
inserted
replaced
1067:6eb9e032e708 | 1068:521f7e8b0559 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006-2016 Chris Cannam and QMUL. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #ifndef COLOUR_SCALE_H | |
17 #define COLOUR_SCALE_H | |
18 | |
19 #include "ColourMapper.h" | |
20 | |
21 /** | |
22 * Map values within a range onto a set of colours, with a given | |
23 * distribution (linear, log etc) and optional colourmap rotation. | |
24 */ | |
25 class ColourScale | |
26 { | |
27 public: | |
28 enum Scale { | |
29 LinearColourScale, | |
30 MeterColourScale, | |
31 LogColourScale, | |
32 PhaseColourScale, | |
33 PlusMinusOneScale, | |
34 AbsoluteScale | |
35 }; | |
36 | |
37 /** | |
38 * Create a ColourScale with the given parameters: | |
39 * | |
40 * @param colourMap A colour map index as used by ColourMapper | |
41 * @param scale Distribution for the scale | |
42 * @param minValue Minimum value in range | |
43 * @param maxValue Maximum value in range. Must be > minValue | |
44 * @param threshold Threshold below which every value is mapped to | |
45 * background pixel 0 | |
46 * @param gain Gain to apply before clamping and mapping, typically 1 | |
47 * | |
48 * Note that some parameters may be ignored for some scale | |
49 * distribution settings. For example, min and max are ignored for | |
50 * PlusMinusOneScale and PhaseColourScale and threshold and gain | |
51 * are ignored for PhaseColourScale. | |
52 */ | |
53 ColourScale(int colourMap, | |
54 Scale scale, | |
55 double minValue, | |
56 double maxValue, | |
57 double threshold, | |
58 double gain); | |
59 | |
60 /** | |
61 * Return a pixel number (in the range 0-255 inclusive) | |
62 * corresponding to the given value. The pixel 0 is used only for | |
63 * values below the threshold supplied in the constructor. All | |
64 * other values are mapped onto the range 1-255. | |
65 */ | |
66 int getPixel(double value); | |
67 | |
68 /** | |
69 * Return the colour for the given pixel number (which must be in | |
70 * the range 0-255). The pixel 0 is always the background | |
71 * colour. Other pixels are mapped taking into account the given | |
72 * colourmap rotation (which is also a value in the range 0-255). | |
73 */ | |
74 QColor getColourForPixel(int pixel, int rotation); | |
75 | |
76 /** | |
77 * Return the colour corresponding to the given value. This is | |
78 * equivalent to getColourForPixel(getPixel(value), rotation). | |
79 */ | |
80 QColor getColour(double value, int rotation) { | |
81 return getColourForPixel(getPixel(value), rotation); | |
82 } | |
83 | |
84 private: | |
85 ColourMapper m_mapper; | |
86 Scale m_scale; | |
87 double m_min; | |
88 double m_max; | |
89 double m_mappedMin; | |
90 double m_mappedMax; | |
91 double m_threshold; | |
92 double m_gain; | |
93 static int m_maxPixel; | |
94 }; | |
95 | |
96 #endif |