comparison layer/ColourScale.h @ 1148:c0d841cb8ab9 tony-2.0-integration

Merge latest SV 3.0 branch code
author Chris Cannam
date Fri, 19 Aug 2016 15:58:57 +0100
parents 4e7ed3252d80
children a34a2a25907c
comparison
equal deleted inserted replaced
1009:96cf499fad62 1148:c0d841cb8ab9
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 enum class ColourScaleType {
22 Linear,
23 Meter,
24 Log,
25 Phase,
26 PlusMinusOne,
27 Absolute
28 };
29
30 /**
31 * Map values within a range onto a set of colours, with a given
32 * distribution (linear, log etc) and optional colourmap rotation.
33 */
34 class ColourScale
35 {
36 public:
37 struct Parameters {
38 Parameters() : colourMap(0), scaleType(ColourScaleType::Linear),
39 minValue(0.0), maxValue(1.0),
40 threshold(0.0), gain(1.0), multiple(1.0) { }
41
42 /** A colour map index as used by ColourMapper */
43 int colourMap;
44
45 /** Distribution for the scale */
46 ColourScaleType scaleType;
47
48 /** Minimum value in source range */
49 double minValue;
50
51 /** Maximum value in source range. Must be > minValue */
52 double maxValue;
53
54 /** Threshold below which every value is mapped to background
55 pixel 0 */
56 double threshold;
57
58 /** Gain to apply before thresholding, mapping, and clamping */
59 double gain;
60
61 /** Multiple to apply after thresholding and mapping. In most
62 * cases the gain parameter is the one you want instead of
63 * this, but this can be used for example with Log scale to
64 * produce the log of some power of the original value,
65 * e.g. multiple = 2 gives log(x^2). */
66 double multiple;
67 };
68
69 /**
70 * Create a ColourScale with the given parameters.
71 *
72 * Note that some parameters may be ignored for some scale
73 * distribution settings. For example, min and max are ignored for
74 * PlusMinusOneScale and PhaseColourScale and threshold and gain
75 * are ignored for PhaseColourScale.
76 */
77 ColourScale(Parameters parameters);
78 ~ColourScale();
79
80 ColourScale(const ColourScale &) = default;
81 ColourScale &operator=(const ColourScale &) = default;
82
83 /**
84 * Return the general type of scale this is.
85 */
86 ColourScaleType getScale() const;
87
88 /**
89 * Return a pixel number (in the range 0-255 inclusive)
90 * corresponding to the given value. The pixel 0 is used only for
91 * values below the threshold supplied in the constructor. All
92 * other values are mapped onto the range 1-255.
93 */
94 int getPixel(double value) const;
95
96 /**
97 * Return the colour for the given pixel number (which must be in
98 * the range 0-255). The pixel 0 is always the background
99 * colour. Other pixels are mapped taking into account the given
100 * colourmap rotation (which is also a value in the range 0-255).
101 */
102 QColor getColourForPixel(int pixel, int rotation) const;
103
104 /**
105 * Return the colour corresponding to the given value. This is
106 * equivalent to getColourForPixel(getPixel(value), rotation).
107 */
108 QColor getColour(double value, int rotation) const {
109 return getColourForPixel(getPixel(value), rotation);
110 }
111
112 private:
113 Parameters m_params;
114 ColourMapper m_mapper;
115 double m_mappedMin;
116 double m_mappedMax;
117 static int m_maxPixel;
118 };
119
120 #endif