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@1068
|
21 /**
|
Chris@1068
|
22 * Map values within a range onto a set of colours, with a given
|
Chris@1068
|
23 * distribution (linear, log etc) and optional colourmap rotation.
|
Chris@1068
|
24 */
|
Chris@1068
|
25 class ColourScale
|
Chris@1068
|
26 {
|
Chris@1068
|
27 public:
|
Chris@1068
|
28 enum Scale {
|
Chris@1068
|
29 LinearColourScale,
|
Chris@1068
|
30 MeterColourScale,
|
Chris@1068
|
31 LogColourScale,
|
Chris@1068
|
32 PhaseColourScale,
|
Chris@1068
|
33 PlusMinusOneScale,
|
Chris@1068
|
34 AbsoluteScale
|
Chris@1068
|
35 };
|
Chris@1068
|
36
|
Chris@1068
|
37 /**
|
Chris@1068
|
38 * Create a ColourScale with the given parameters:
|
Chris@1068
|
39 *
|
Chris@1068
|
40 * @param colourMap A colour map index as used by ColourMapper
|
Chris@1068
|
41 * @param scale Distribution for the scale
|
Chris@1068
|
42 * @param minValue Minimum value in range
|
Chris@1068
|
43 * @param maxValue Maximum value in range. Must be > minValue
|
Chris@1068
|
44 * @param threshold Threshold below which every value is mapped to
|
Chris@1068
|
45 * background pixel 0
|
Chris@1068
|
46 * @param gain Gain to apply before clamping and mapping, typically 1
|
Chris@1068
|
47 *
|
Chris@1068
|
48 * Note that some parameters may be ignored for some scale
|
Chris@1068
|
49 * distribution settings. For example, min and max are ignored for
|
Chris@1068
|
50 * PlusMinusOneScale and PhaseColourScale and threshold and gain
|
Chris@1068
|
51 * are ignored for PhaseColourScale.
|
Chris@1068
|
52 */
|
Chris@1068
|
53 ColourScale(int colourMap,
|
Chris@1068
|
54 Scale scale,
|
Chris@1068
|
55 double minValue,
|
Chris@1068
|
56 double maxValue,
|
Chris@1068
|
57 double threshold,
|
Chris@1068
|
58 double gain);
|
Chris@1068
|
59
|
Chris@1068
|
60 /**
|
Chris@1068
|
61 * Return a pixel number (in the range 0-255 inclusive)
|
Chris@1068
|
62 * corresponding to the given value. The pixel 0 is used only for
|
Chris@1068
|
63 * values below the threshold supplied in the constructor. All
|
Chris@1068
|
64 * other values are mapped onto the range 1-255.
|
Chris@1068
|
65 */
|
Chris@1068
|
66 int getPixel(double value);
|
Chris@1068
|
67
|
Chris@1068
|
68 /**
|
Chris@1068
|
69 * Return the colour for the given pixel number (which must be in
|
Chris@1068
|
70 * the range 0-255). The pixel 0 is always the background
|
Chris@1068
|
71 * colour. Other pixels are mapped taking into account the given
|
Chris@1068
|
72 * colourmap rotation (which is also a value in the range 0-255).
|
Chris@1068
|
73 */
|
Chris@1068
|
74 QColor getColourForPixel(int pixel, int rotation);
|
Chris@1068
|
75
|
Chris@1068
|
76 /**
|
Chris@1068
|
77 * Return the colour corresponding to the given value. This is
|
Chris@1068
|
78 * equivalent to getColourForPixel(getPixel(value), rotation).
|
Chris@1068
|
79 */
|
Chris@1068
|
80 QColor getColour(double value, int rotation) {
|
Chris@1068
|
81 return getColourForPixel(getPixel(value), rotation);
|
Chris@1068
|
82 }
|
Chris@1068
|
83
|
Chris@1068
|
84 private:
|
Chris@1068
|
85 ColourMapper m_mapper;
|
Chris@1068
|
86 Scale m_scale;
|
Chris@1068
|
87 double m_min;
|
Chris@1068
|
88 double m_max;
|
Chris@1068
|
89 double m_mappedMin;
|
Chris@1068
|
90 double m_mappedMax;
|
Chris@1068
|
91 double m_threshold;
|
Chris@1068
|
92 double m_gain;
|
Chris@1068
|
93 static int m_maxPixel;
|
Chris@1068
|
94 };
|
Chris@1068
|
95
|
Chris@1068
|
96 #endif
|