Skip to content

Commit

Permalink
HSV renderer for the woverview widget
Browse files Browse the repository at this point in the history
  • Loading branch information
xorik committed Jun 20, 2013
1 parent d482e9c commit 1f3d43b
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ def sources(self, build):
"widget/wstatuslight.cpp",
"widget/woverview.cpp",
"widget/woverviewlmh.cpp",
"widget/woverviewhsv.cpp",
"widget/wspinny.cpp",
"widget/wskincolor.cpp",
"widget/wabstractcontrol.cpp",
Expand Down
123 changes: 123 additions & 0 deletions src/widget/woverviewhsv.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#include "woverviewhsv.h"

#include "util/timer.h"

#include "waveform/waveform.h"

WOverviewHSV::WOverviewHSV(const char *pGroup, ConfigObject<ConfigValue>* pConfig, QWidget * parent)
: WOverview(pGroup, pConfig, parent) {
}

bool WOverviewHSV::drawNextPixmapPart() {
ScopedTimer t("WOverview::drawNextPixmapPart");

//qDebug() << "WOverview::drawNextPixmapPart() - m_waveform" << m_waveform;

int currentCompletion;

if (!m_pWaveform) {
return false;
}

const int dataSize = m_pWaveform->getDataSize();
if (dataSize == 0 ) {
return false;
}

if (!m_pWaveformSourceImage) {
//waveform pixmap twice the height of the viewport to be scalable by total_gain
//we keep full range waveform data to scale it on paint
m_pWaveformSourceImage = new QImage(dataSize / 2, 2 * 255, QImage::Format_ARGB32_Premultiplied);
m_pWaveformSourceImage->fill(QColor(0,0,0,0).value());
}

const int waveformCompletion = m_pWaveform->getCompletion(); // always multiple of 2
// test if there is some new to draw (at least of pixel width)
const int completionIncrement = waveformCompletion - m_actualCompletion;

int visiblePixelIncrement = completionIncrement * width() / dataSize;
if (completionIncrement < 2 || visiblePixelIncrement == 0) {
return false;
}

if (!m_pWaveform->getMutex()->tryLock()) {
return false;
}

const int nextCompletion = m_actualCompletion + completionIncrement;

//qDebug() << "WOverview::drawNextPixmapPart() - nextCompletion:" << nextCompletion
// << "m_actualCompletion:" << m_actualCompletion
// << "waveformCompletion:" << waveformCompletion
// << "completionIncrement:" << completionIncrement;


QPainter painter(m_pWaveformSourceImage);
painter.translate(0.0,(double)m_pWaveformSourceImage->height()/2.0);

// Get HSV of low color
double h,s,v;
m_signalColors.getLowColor().getHsvF(&h,&s,&v);

QColor color;
float lo, hi, total;

unsigned char maxLow[2] = {0, 0};
unsigned char maxHigh[2] = {0, 0};
unsigned char maxMid[2] = {0, 0};
unsigned char maxAll[2] = {0, 0};

for (currentCompletion = m_actualCompletion;
currentCompletion < nextCompletion; currentCompletion += 2) {
maxAll[0] = m_pWaveform->getAll(currentCompletion);
maxAll[1] = m_pWaveform->getAll(currentCompletion+1);
if (maxAll[0] || maxAll[1]) {
maxLow[0] = m_pWaveform->getLow(currentCompletion);
maxLow[1] = m_pWaveform->getLow(currentCompletion+1);
maxMid[0] = m_pWaveform->getMid(currentCompletion);
maxMid[1] = m_pWaveform->getMid(currentCompletion+1);
maxHigh[0] = m_pWaveform->getHigh(currentCompletion);
maxHigh[1] = m_pWaveform->getHigh(currentCompletion+1);

total = (maxLow[0] + maxLow[1] + maxMid[0] + maxMid[1] + maxHigh[0] + maxHigh[1]) * 1.2;

// prevent division by zero
if( total > 0 )
{
// Normalize low and high (mid not need, because it not change the color)
lo = (maxLow[0] + maxLow[1]) / total;
hi = (maxHigh[0] + maxHigh[1]) / total;
}
else
lo = hi = 0.0;

// Set color
color.setHsvF(h, 1.0-hi, 1.0-lo);

painter.setPen(color);
painter.drawLine(QPoint(currentCompletion / 2, -maxAll[0]),
QPoint(currentCompletion / 2, maxAll[1]));
}
}

//evaluate waveform ratio peak

for (currentCompletion = m_actualCompletion;
currentCompletion < nextCompletion; currentCompletion += 2) {
m_waveformPeak = math_max(m_waveformPeak, (float)m_pWaveform->getAll(currentCompletion));
m_waveformPeak = math_max(m_waveformPeak, (float)m_pWaveform->getAll(currentCompletion+1));
}

m_actualCompletion = nextCompletion;
m_waveformImageScaled = QImage();
m_diffGain = 0;

//test if the complete waveform is done
if (m_actualCompletion >= dataSize - 2) {
m_pixmapDone = true;
//qDebug() << "m_waveformPeakRatio" << m_waveformPeak;
}

m_pWaveform->getMutex()->unlock();
return true;
}
15 changes: 15 additions & 0 deletions src/widget/woverviewhsv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef WOVERVIEWHSV_H
#define WOVERVIEWHSV_H

#include "widget/woverview.h"

class WOverviewHSV : public WOverview
{
public:
WOverviewHSV(const char *pGroup, ConfigObject<ConfigValue>* pConfig, QWidget * parent);

private:
virtual bool drawNextPixmapPart();
};

#endif // WOVERVIEWHSV_H

0 comments on commit 1f3d43b

Please sign in to comment.