Pre-calculate color map

Huge time savings in spectrogram generation.
Bit hacky at the moment with hard-coded size scattered everywhere.
Plan is to rejig this for custom color maps in the future, ref #4
This commit is contained in:
Mike Walters
2015-09-11 00:16:55 +01:00
parent 33d1bbd920
commit 4eb33aef1e
2 changed files with 7 additions and 1 deletions

View File

@@ -16,6 +16,11 @@ Spectrogram::Spectrogram()
zoomLevel = 0;
powerMax = 0.0f;
powerMin = -50.0f;
for (int i = 0; i < 256; i++) {
float p = (float)i / 256;
colormap[i] = QColor::fromHsvF(p * 0.83f, 1.0, 1.0 - p).rgba();
}
}
Spectrogram::~Spectrogram()
@@ -68,7 +73,7 @@ void Spectrogram::paintEvent(QPaintEvent *event)
float normPower = (line[x] - powerMax) * -1.0f / powerRange;
normPower = clamp(normPower, 0.0f, 1.0f);
image.setPixel(x, y, QColor::fromHsvF(normPower * 0.83f, 1.0, 1.0 - normPower).rgba());
image.setPixel(x, y, colormap[(uint8_t)(normPower * (256 - 1))]);
}
}