# HG changeset patch # User Chris Cannam # Date 1449068498 0 # Node ID 2a85ab180d08d990d778ae9c9f3be5cca4a5adb1 # Parent 7242fe160c19015cf79440223b2f998236ea205f Experimentation with colour schemes and mappings diff -r 7242fe160c19 -r 2a85ab180d08 layer/ColourMapper.cpp --- a/layer/ColourMapper.cpp Wed Nov 18 12:08:33 2015 +0000 +++ b/layer/ColourMapper.cpp Wed Dec 02 15:01:38 2015 +0000 @@ -21,6 +21,47 @@ #include "base/Debug.h" +#include + +using namespace std; + +static vector ylGnBuS { +// this is ylGnBu 9 +// "#f7fcf0","#e0f3db","#ccebc5","#a8ddb5","#7bccc4","#4eb3d3","#2b8cbe","#0868ac","#084081" + + "#ffffff", "#ffff00", "#f7fcf0","#e0f3db","#ccebc5","#a8ddb5","#7bccc4","#4eb3d3","#2b8cbe","#0868ac","#084081","#042040" + +// this is PuOr 11 +// "#7f3b08","#b35806","#e08214","#fdb863","#fee0b6","#f7f7f7","#d8daeb","#b2abd2","#8073ac","#542788","#2d004b" + }; + + +static vector convertStrings(const vector &strs) +{ + vector converted; + for (const auto &s: strs) converted.push_back(QColor(s)); + reverse(converted.begin(), converted.end()); + return converted; +} + +static vector ylGnBu = convertStrings(ylGnBuS); + +static void +mapDiscrete(double norm, vector &colours, double &r, double &g, double &b) +{ + int n = colours.size(); + double m = norm * (n-1); + if (m >= n-1) { colours[n-1].getRgbF(&r, &g, &b, 0); return; } + if (m <= 0) { colours[0].getRgbF(&r, &g, &b, 0); return; } + int base(int(floor(m))); + double prop0 = (base + 1.0) - m, prop1 = m - base; + QColor c0(colours[base]), c1(colours[base+1]); + r = c0.redF() * prop0 + c1.redF() * prop1; + g = c0.greenF() * prop0 + c1.greenF() * prop1; + b = c0.blueF() * prop0 + c1.blueF() * prop1; + cerr << "mapDiscrete: norm " << norm << " -> " << r << "," << g << "," << b << endl; +} + ColourMapper::ColourMapper(int map, double min, double max) : QObject(), m_map(map), @@ -41,7 +82,7 @@ int ColourMapper::getColourMapCount() { - return 12; + return 13; } QString @@ -63,6 +104,7 @@ case Highlight: return tr("Highlight"); case Printer: return tr("Printer"); case HighGain: return tr("High Gain"); + case YlGnBu: return tr("YlGnBu"); } return tr(""); @@ -207,6 +249,10 @@ hsv = false; */ break; + + case YlGnBu: + hsv = false; + mapDiscrete(norm, ylGnBu, r, g, b); } if (hsv) { diff -r 7242fe160c19 -r 2a85ab180d08 layer/ColourMapper.h --- a/layer/ColourMapper.h Wed Nov 18 12:08:33 2015 +0000 +++ b/layer/ColourMapper.h Wed Dec 02 15:01:38 2015 +0000 @@ -44,7 +44,8 @@ Banded, Highlight, Printer, - HighGain + HighGain, + YlGnBu, }; int getMap() const { return m_map; }