comparison layer/SpectrogramLayer.cpp @ 196:22c99c8aa1e0

* Add separate colour mapping unit; use it in spectrogram (colour 3d plot to follow) * Add another colour scheme resembling that of a noted commercial application
author Chris Cannam
date Wed, 31 Jan 2007 12:13:47 +0000
parents 57c2350a8c40
children 6b023411087b
comparison
equal deleted inserted replaced
195:4a3bdde1ef13 196:22c99c8aa1e0
20 #include "base/AudioLevel.h" 20 #include "base/AudioLevel.h"
21 #include "base/Window.h" 21 #include "base/Window.h"
22 #include "base/Pitch.h" 22 #include "base/Pitch.h"
23 #include "base/Preferences.h" 23 #include "base/Preferences.h"
24 #include "base/RangeMapper.h" 24 #include "base/RangeMapper.h"
25 #include "ColourMapper.h"
25 26
26 #include <QPainter> 27 #include <QPainter>
27 #include <QImage> 28 #include <QImage>
28 #include <QPixmap> 29 #include <QPixmap>
29 #include <QRect> 30 #include <QRect>
51 m_colourRotation(0), 52 m_colourRotation(0),
52 m_minFrequency(10), 53 m_minFrequency(10),
53 m_maxFrequency(8000), 54 m_maxFrequency(8000),
54 m_initialMaxFrequency(8000), 55 m_initialMaxFrequency(8000),
55 m_colourScale(dBColourScale), 56 m_colourScale(dBColourScale),
56 m_colourScheme(DefaultColours), 57 m_colourScheme(0),
57 m_frequencyScale(LinearFrequencyScale), 58 m_frequencyScale(LinearFrequencyScale),
58 m_binDisplay(AllBins), 59 m_binDisplay(AllBins),
59 m_normalizeColumns(false), 60 m_normalizeColumns(false),
60 m_normalizeVisibleArea(false), 61 m_normalizeVisibleArea(false),
61 m_lastEmittedZoomStep(-1), 62 m_lastEmittedZoomStep(-1),
246 deft = (int)m_colourScale; 247 deft = (int)m_colourScale;
247 248
248 } else if (name == "Colour") { 249 } else if (name == "Colour") {
249 250
250 *min = 0; 251 *min = 0;
251 *max = 6; 252 *max = ColourMapper::getColourMapCount() - 1;
252 253
253 deft = (int)m_colourScheme; 254 deft = m_colourScheme;
254 255
255 } else if (name == "Window Size") { 256 } else if (name == "Window Size") {
256 257
257 *min = 0; 258 *min = 0;
258 *max = 10; 259 *max = 10;
341 QString 342 QString
342 SpectrogramLayer::getPropertyValueLabel(const PropertyName &name, 343 SpectrogramLayer::getPropertyValueLabel(const PropertyName &name,
343 int value) const 344 int value) const
344 { 345 {
345 if (name == "Colour") { 346 if (name == "Colour") {
346 switch (value) { 347 return ColourMapper::getColourMapName(value);
347 default:
348 case 0: return tr("Default");
349 case 1: return tr("White on Black");
350 case 2: return tr("Black on White");
351 case 3: return tr("Red on Blue");
352 case 4: return tr("Yellow on Black");
353 case 5: return tr("Blue on Black");
354 case 6: return tr("Fruit Salad");
355 }
356 } 348 }
357 if (name == "Colour Scale") { 349 if (name == "Colour Scale") {
358 switch (value) { 350 switch (value) {
359 default: 351 default:
360 case 0: return tr("Linear"); 352 case 0: return tr("Linear");
451 if (value == -50) setThreshold(0.0); 443 if (value == -50) setThreshold(0.0);
452 else setThreshold(AudioLevel::dB_to_multiplier(value)); 444 else setThreshold(AudioLevel::dB_to_multiplier(value));
453 } else if (name == "Colour Rotation") { 445 } else if (name == "Colour Rotation") {
454 setColourRotation(value); 446 setColourRotation(value);
455 } else if (name == "Colour") { 447 } else if (name == "Colour") {
456 switch (value) { 448 setColourScheme(value);
457 default:
458 case 0: setColourScheme(DefaultColours); break;
459 case 1: setColourScheme(WhiteOnBlack); break;
460 case 2: setColourScheme(BlackOnWhite); break;
461 case 3: setColourScheme(RedOnBlue); break;
462 case 4: setColourScheme(YellowOnBlack); break;
463 case 5: setColourScheme(BlueOnBlack); break;
464 case 6: setColourScheme(Rainbow); break;
465 }
466 } else if (name == "Window Size") { 449 } else if (name == "Window Size") {
467 setWindowSize(32 << value); 450 setWindowSize(32 << value);
468 } else if (name == "Window Increment") { 451 } else if (name == "Window Increment") {
469 setWindowHopLevel(value); 452 setWindowHopLevel(value);
470 } else if (name == "Zero Padding") { 453 } else if (name == "Zero Padding") {
796 { 779 {
797 return m_colourScale; 780 return m_colourScale;
798 } 781 }
799 782
800 void 783 void
801 SpectrogramLayer::setColourScheme(ColourScheme scheme) 784 SpectrogramLayer::setColourScheme(int scheme)
802 { 785 {
803 if (m_colourScheme == scheme) return; 786 if (m_colourScheme == scheme) return;
804 787
805 invalidatePixmapCaches(); 788 invalidatePixmapCaches();
806 789
808 setColourmap(); 791 setColourmap();
809 792
810 emit layerParametersChanged(); 793 emit layerParametersChanged();
811 } 794 }
812 795
813 SpectrogramLayer::ColourScheme 796 int
814 SpectrogramLayer::getColourScheme() const 797 SpectrogramLayer::getColourScheme() const
815 { 798 {
816 return m_colourScheme; 799 return m_colourScheme;
817 } 800 }
818 801
1011 void 994 void
1012 SpectrogramLayer::setColourmap() 995 SpectrogramLayer::setColourmap()
1013 { 996 {
1014 int formerRotation = m_colourRotation; 997 int formerRotation = m_colourRotation;
1015 998
1016 if (m_colourScheme == BlackOnWhite) { 999 if (m_colourScheme == (int)ColourMapper::BlackOnWhite) {
1017 m_colourMap.setColour(NO_VALUE, Qt::white); 1000 m_colourMap.setColour(NO_VALUE, Qt::white);
1018 } else { 1001 } else {
1019 m_colourMap.setColour(NO_VALUE, Qt::black); 1002 m_colourMap.setColour(NO_VALUE, Qt::black);
1020 } 1003 }
1021 1004
1005 ColourMapper mapper(m_colourScheme, 1.f, 256.f);
1006
1022 for (int pixel = 1; pixel < 256; ++pixel) { 1007 for (int pixel = 1; pixel < 256; ++pixel) {
1023 1008
1024 QColor colour; 1009 m_colourMap.setColour(pixel, mapper.map(pixel));
1025 int hue, px; 1010 }
1026 1011
1027 switch (m_colourScheme) { 1012 m_crosshairColour = mapper.getContrastingColour();
1028
1029 default:
1030 case DefaultColours:
1031 hue = 256 - pixel;
1032 colour = QColor::fromHsv(hue, pixel/2 + 128, pixel);
1033 m_crosshairColour = QColor(255, 150, 50);
1034 // m_crosshairColour = QColor::fromHsv(240, 160, 255);
1035 break;
1036
1037 case WhiteOnBlack:
1038 colour = QColor(pixel, pixel, pixel);
1039 m_crosshairColour = Qt::red;
1040 break;
1041
1042 case BlackOnWhite:
1043 colour = QColor(256-pixel, 256-pixel, 256-pixel);
1044 m_crosshairColour = Qt::darkGreen;
1045 break;
1046
1047 case RedOnBlue:
1048 colour = QColor(pixel > 128 ? (pixel - 128) * 2 : 0, 0,
1049 pixel < 128 ? pixel : (256 - pixel));
1050 m_crosshairColour = Qt::green;
1051 break;
1052
1053 case YellowOnBlack:
1054 px = 256 - pixel;
1055 colour = QColor(px < 64 ? 255 - px/2 :
1056 px < 128 ? 224 - (px - 64) :
1057 px < 192 ? 160 - (px - 128) * 3 / 2 :
1058 256 - px,
1059 pixel,
1060 pixel / 4);
1061 m_crosshairColour = QColor::fromHsv(240, 255, 255);
1062 break;
1063
1064 case BlueOnBlack:
1065 colour = QColor::fromHsv
1066 (240, pixel > 226 ? 256 - (pixel - 226) * 8 : 255,
1067 (pixel * pixel) / 255);
1068 m_crosshairColour = Qt::red;
1069 break;
1070
1071 case Rainbow:
1072 hue = 250 - pixel;
1073 if (hue < 0) hue += 256;
1074 colour = QColor::fromHsv(pixel, 255, 255);
1075 m_crosshairColour = Qt::white;
1076 break;
1077 }
1078
1079 m_colourMap.setColour(pixel, colour);
1080 }
1081 1013
1082 m_colourRotation = 0; 1014 m_colourRotation = 0;
1083 rotateColourmap(m_colourRotation - formerRotation); 1015 rotateColourmap(m_colourRotation - formerRotation);
1084 m_colourRotation = formerRotation; 1016 m_colourRotation = formerRotation;
1085 } 1017 }
1732 } 1664 }
1733 1665
1734 void 1666 void
1735 SpectrogramLayer::paint(View *v, QPainter &paint, QRect rect) const 1667 SpectrogramLayer::paint(View *v, QPainter &paint, QRect rect) const
1736 { 1668 {
1737 if (m_colourScheme == BlackOnWhite) { 1669 if (m_colourScheme == (int)ColourMapper::BlackOnWhite) {
1738 v->setLightBackground(true); 1670 v->setLightBackground(true);
1739 } else { 1671 } else {
1740 v->setLightBackground(false); 1672 v->setLightBackground(false);
1741 } 1673 }
1742 1674
3062 2994
3063 ColourScale colourScale = (ColourScale) 2995 ColourScale colourScale = (ColourScale)
3064 attributes.value("colourScale").toInt(&ok); 2996 attributes.value("colourScale").toInt(&ok);
3065 if (ok) setColourScale(colourScale); 2997 if (ok) setColourScale(colourScale);
3066 2998
3067 ColourScheme colourScheme = (ColourScheme) 2999 int colourScheme = attributes.value("colourScheme").toInt(&ok);
3068 attributes.value("colourScheme").toInt(&ok);
3069 if (ok) setColourScheme(colourScheme); 3000 if (ok) setColourScheme(colourScheme);
3070 3001
3071 int colourRotation = attributes.value("colourRotation").toInt(&ok); 3002 int colourRotation = attributes.value("colourRotation").toInt(&ok);
3072 if (ok) setColourRotation(colourRotation); 3003 if (ok) setColourRotation(colourRotation);
3073 3004