Chris@376: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@376: Chris@376: /* Chris@376: Sonic Visualiser Chris@376: An audio file viewer and annotation editor. Chris@376: Centre for Digital Music, Queen Mary, University of London. Chris@376: This file copyright 2006-2007 Chris Cannam and QMUL. Chris@376: Chris@376: This program is free software; you can redistribute it and/or Chris@376: modify it under the terms of the GNU General Public License as Chris@376: published by the Free Software Foundation; either version 2 of the Chris@376: License, or (at your option) any later version. See the file Chris@376: COPYING included with this distribution for more information. Chris@376: */ Chris@376: Chris@1199: #ifndef SV_COLOUR_MAPPER_H Chris@1199: #define SV_COLOUR_MAPPER_H Chris@376: Chris@376: #include Chris@376: #include Chris@376: #include Chris@1199: #include Chris@376: Chris@376: /** Chris@376: * A class for mapping intensity values onto various colour maps. Chris@376: */ Chris@1071: class ColourMapper Chris@376: { Chris@376: public: Chris@1362: ColourMapper(int map, Chris@1362: bool inverted, Chris@1362: double minValue, Chris@1362: double maxValue); Chris@1071: ~ColourMapper(); Chris@1071: Chris@1362: ColourMapper(const ColourMapper &) =default; Chris@1362: ColourMapper &operator=(const ColourMapper &) =default; Chris@376: Chris@1362: enum ColourMap { Chris@1017: Green, Chris@376: Sunset, Chris@376: WhiteOnBlack, Chris@376: BlackOnWhite, Chris@1017: Cherry, Chris@1017: Wasp, Chris@1017: Ice, Chris@376: FruitSalad, Chris@376: Banded, Chris@376: Highlight, Chris@536: Printer, Chris@1362: HighGain, Chris@1362: BlueOnBlack, Chris@1362: Cividis, Chris@1362: Magma Chris@376: }; Chris@376: Chris@376: int getMap() const { return m_map; } Chris@1362: bool isInverted() const { return m_inverted; } Chris@902: double getMinValue() const { return m_min; } Chris@902: double getMaxValue() const { return m_max; } Chris@376: Chris@1362: /** Chris@1362: * Return the number of known colour maps. Chris@1362: */ Chris@376: static int getColourMapCount(); Chris@376: Chris@1362: /** Chris@1362: * Return a human-readable label for the colour map with the given Chris@1362: * index. This may have been subject to translation. Chris@1362: */ Chris@1362: static QString getColourMapLabel(int n); Chris@1362: Chris@1362: /** Chris@1362: * Return a machine-readable id string for the colour map with the Chris@1362: * given index. This is not translated and is intended for use in Chris@1362: * file I/O. Chris@1362: */ Chris@1362: static QString getColourMapId(int n); Chris@1362: Chris@1362: /** Chris@1362: * Return the index for the colour map with the given Chris@1362: * machine-readable id string, or -1 if the id is not recognised. Chris@1362: */ Chris@1362: static int getColourMapById(QString id); Chris@1362: Chris@1362: /** Chris@1362: * Older versions of colour-handling code save and reload colour Chris@1362: * maps by numerical index and can't properly handle situations in Chris@1362: * which the index order changes between releases, or new indices Chris@1362: * are added. So when we save a colour map by id, we should also Chris@1362: * save a compatibility value that can be re-read by such Chris@1362: * code. This value is an index into the series of colours used by Chris@1362: * pre-3.2 SV code, namely (Default/Green, Sunset, WhiteOnBlack, Chris@1362: * BlackOnWhite, RedOnBlue, YellowOnBlack, BlueOnBlack, Chris@1362: * FruitSalad, Banded, Highlight, Printer, HighGain). It should Chris@1362: * represent the closest equivalent to the current colour scheme Chris@1362: * available in that set. This function returns that index. Chris@1362: */ Chris@1362: static int getBackwardCompatibilityColourMap(int n); Chris@1362: Chris@1362: /** Chris@1362: * Map the given value to a colour. The value will be clamped to Chris@1362: * the range minValue to maxValue (where both are drawn from the Chris@1362: * constructor arguments). Chris@1362: */ Chris@902: QColor map(double value) const; Chris@376: Chris@1362: /** Chris@1362: * Return a colour that contrasts somewhat with the colours in the Chris@1362: * map, so as to be used for cursors etc. Chris@1362: */ Chris@1362: QColor getContrastingColour() const; Chris@1362: Chris@1362: /** Chris@1362: * Return true if the colour map is intended to be placed over a Chris@1362: * light background, false otherwise. This is typically true if Chris@1362: * the colours corresponding to higher values are darker than Chris@1362: * those corresponding to lower values. Chris@1362: */ Chris@376: bool hasLightBackground() const; Chris@376: Chris@1362: /** Chris@1362: * Return a pixmap of the given size containing a preview swatch Chris@1362: * for the colour map. Chris@1362: */ Chris@1199: QPixmap getExamplePixmap(QSize size) const; Chris@1199: Chris@376: protected: Chris@376: int m_map; Chris@1362: bool m_inverted; Chris@902: double m_min; Chris@902: double m_max; Chris@376: }; Chris@376: Chris@376: #endif Chris@376: