mirror of
https://github.com/miek/inspectrum.git
synced 2026-03-04 23:44:22 +01:00
Map power to HSV
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
Spectrogram::Spectrogram()
|
||||
{
|
||||
inputSource = new InputSource("/home/mike/Downloads/hubsan-chopped.cfile", 1024);
|
||||
powerMax = 0.0f;
|
||||
powerRange = 40.0f;
|
||||
resize(inputSource->GetWidth(), inputSource->GetHeight());
|
||||
}
|
||||
|
||||
@@ -17,6 +19,62 @@ Spectrogram::~Spectrogram()
|
||||
delete inputSource;
|
||||
}
|
||||
|
||||
template <class T> const T& clamp (const T& value, const T& min, const T& max) {
|
||||
return std::min(max, std::max(min, value));
|
||||
}
|
||||
|
||||
void HSVtoRGB( float *r, float *g, float *b, float h, float s, float v )
|
||||
{
|
||||
int i;
|
||||
float f, p, q, t;
|
||||
|
||||
if( s == 0 ) {
|
||||
// achromatic (grey)
|
||||
*r = *g = *b = v;
|
||||
return;
|
||||
}
|
||||
|
||||
h /= 60; // sector 0 to 5
|
||||
i = floor( h );
|
||||
f = h - i; // factorial part of h
|
||||
p = v * ( 1 - s );
|
||||
q = v * ( 1 - s * f );
|
||||
t = v * ( 1 - s * ( 1 - f ) );
|
||||
|
||||
switch( i ) {
|
||||
case 0:
|
||||
*r = v;
|
||||
*g = t;
|
||||
*b = p;
|
||||
break;
|
||||
case 1:
|
||||
*r = q;
|
||||
*g = v;
|
||||
*b = p;
|
||||
break;
|
||||
case 2:
|
||||
*r = p;
|
||||
*g = v;
|
||||
*b = t;
|
||||
break;
|
||||
case 3:
|
||||
*r = p;
|
||||
*g = q;
|
||||
*b = v;
|
||||
break;
|
||||
case 4:
|
||||
*r = t;
|
||||
*g = p;
|
||||
*b = v;
|
||||
break;
|
||||
default: // case 5:
|
||||
*r = v;
|
||||
*g = p;
|
||||
*b = q;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Spectrogram::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QElapsedTimer timer;
|
||||
@@ -37,8 +95,13 @@ void Spectrogram::paintEvent(QPaintEvent *event)
|
||||
QImage image(width, height, QImage::Format_RGB32);
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
uint8_t pixel = data[y*width + x] * -3;
|
||||
image.setPixel(x, y, qRgb(0, 0, pixel));
|
||||
float normPower = (data[y*width + x] - powerMax) * -1.0f / powerRange;
|
||||
normPower = clamp(normPower, 0.0f, 1.0f);
|
||||
|
||||
float red, green, blue;
|
||||
HSVtoRGB(&red, &green, &blue, normPower * 300.0f, 1, 1 - normPower);
|
||||
|
||||
image.setPixel(x, y, qRgb(red * 255, green * 255, blue * 255));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,4 +119,4 @@ void Spectrogram::setFFTSize(int size)
|
||||
inputSource->setFFTSize(size);
|
||||
update();
|
||||
resize(inputSource->GetWidth(), inputSource->GetHeight());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user