#include <cmath>
-#include <QColor>
-#include <QDebug>
#include <QImage>
#include <QPainter>
#include <QSize>
}
QImage WaveformGenerator::calculateWaveform(const QSize &waveformSize, const QImage &image, WaveformGenerator::PaintMode paintMode,
- const bool &drawAxis, WaveformGenerator::Rec rec, const uint &accelFactor)
+ bool drawAxis, WaveformGenerator::Rec rec, uint accelFactor)
{
Q_ASSERT(accelFactor >= 1);
- QTime time;
- time.start();
+ //QTime time;
+ //time.start();
QImage wave(waveformSize, QImage::Format_ARGB32);
const uint byteCount = iw*ih;
uint waveValues[waveformSize.width()][waveformSize.height()];
- for (int i = 0; i < waveformSize.width(); i++) {
+ for (int i = 0; i < waveformSize.width(); ++i) {
for (int j = 0; j < waveformSize.height(); j++) {
waveValues[i][j] = 0;
}
// Must be a float because the acceleration factor can be high, leading to <1 expected px per px.
const float pixelDepth = (float)((byteCount>>2) / accelFactor)/(ww*wh);
const float gain = 255/(8*pixelDepth);
- qDebug() << "Pixel depth: expected " << pixelDepth << "; Gain: using " << gain << " (acceleration: " << accelFactor << "x)";
+ //qDebug() << "Pixel depth: expected " << pixelDepth << "; Gain: using " << gain << " (acceleration: " << accelFactor << "x)";
// Subtract 1 from sizes because we start counting from 0.
const float wPrediv = (float)(ww-1)/(iw-1);
const uchar *bits = image.bits();
- const uchar *bitsStart = bits;
+ const int bpp = image.depth() / 8;
- for (uint i = 0, x = 0; i < byteCount; i += 4) {
+ for (uint i = 0, x = 0; i < byteCount; i += bpp) {
- Q_ASSERT(bits < bitsStart + byteCount);
+ Q_ASSERT(bits < image.bits() + byteCount);
col = (QRgb *)bits;
dx = x*wPrediv;
waveValues[(int)dx][(int)dy]++;
- bits += 4;
- x += 4;
+ bits += bpp;
+ x += bpp;
if (x > iw) {
x -= iw;
if (accelFactor > 1) {
- bits += 4*iw*(accelFactor-1);
- i += 4*iw*(accelFactor-1);
+ bits += bpp*iw*(accelFactor-1);
+ i += bpp*iw*(accelFactor-1);
}
}
}
switch (paintMode) {
case PaintMode_Green:
- for (int i = 0; i < waveformSize.width(); i++) {
+ for (int i = 0; i < waveformSize.width(); ++i) {
for (int j = 0; j < waveformSize.height(); j++) {
// Logarithmic scale. Needs fine tuning by hand, but looks great.
wave.setPixel(i, waveformSize.height()-j-1, qRgba(CHOP255(52*log(0.1*gain*waveValues[i][j])),
}
break;
case PaintMode_Yellow:
- for (int i = 0; i < waveformSize.width(); i++) {
+ for (int i = 0; i < waveformSize.width(); ++i) {
for (int j = 0; j < waveformSize.height(); j++) {
wave.setPixel(i, waveformSize.height()-j-1, qRgba(255,242,0, CHOP255(gain*waveValues[i][j])));
}
}
break;
default:
- for (int i = 0; i < waveformSize.width(); i++) {
+ for (int i = 0; i < waveformSize.width(); ++i) {
for (int j = 0; j < waveformSize.height(); j++) {
wave.setPixel(i, waveformSize.height()-j-1, qRgba(255,255,255, CHOP255(2*gain*waveValues[i][j])));
}
QRgb opx;
davinci.setPen(qRgba(150,255,200,32));
davinci.setCompositionMode(QPainter::CompositionMode_Overlay);
- for (uint i = 0; i <= 10; i++) {
+ for (uint i = 0; i <= 10; ++i) {
dy = (float)i/10 * (wh-1);
for (uint x = 0; x < ww; x++) {
opx = wave.pixel(x, dy);
}
- uint diff = time.elapsed();
- emit signalCalculationFinished(wave, diff);
+ //uint diff = time.elapsed();
+ //emit signalCalculationFinished(wave, diff);
return wave;
}
#undef CHOP255
+
+#include "waveformgenerator.moc"