]> git.sesse.net Git - kdenlive/commitdiff
Waveform:
authorSimon A. Eugster <simon.eu@gmail.com>
Mon, 16 Aug 2010 09:49:33 +0000 (09:49 +0000)
committerSimon A. Eugster <simon.eu@gmail.com>
Mon, 16 Aug 2010 09:49:33 +0000 (09:49 +0000)
* New paint mode (yellow)
* Remember configuration
* Debug output disabled

svn path=/trunk/kdenlive/; revision=4729

src/colorcorrection/waveformgenerator.cpp
src/colorcorrection/waveformgenerator.h
src/waveform.cpp
src/waveform.h

index 633a2211135326eb99ea398a0acfeb234f0ebcf2..735215dd9bfeba42ff7297c0e72628181294e679 100644 (file)
@@ -9,7 +9,6 @@
  ***************************************************************************/
 
 #include <QColor>
-#include <QDebug>
 #include <QImage>
 #include <QPainter>
 #include <QSize>
@@ -27,7 +26,8 @@ WaveformGenerator::~WaveformGenerator()
 {
 }
 
-QImage WaveformGenerator::calculateWaveform(const QSize &waveformSize, const QImage &image, const bool &drawAxis, const uint &accelFactor)
+QImage WaveformGenerator::calculateWaveform(const QSize &waveformSize, const QImage &image, WaveformGenerator::PaintMode paintMode,
+                                            const bool &drawAxis, const uint &accelFactor)
 {
     Q_ASSERT(accelFactor >= 1);
 
@@ -41,8 +41,6 @@ QImage WaveformGenerator::calculateWaveform(const QSize &waveformSize, const QIm
 
     } else {
 
-        qDebug() << "Waveform calculation started.";
-
         // Fill with transparent color
         wave.fill(qRgba(0,0,0,0));
 
@@ -63,6 +61,8 @@ QImage WaveformGenerator::calculateWaveform(const QSize &waveformSize, const QIm
         const float hPrediv = (float)(wh-1)/255;
         const float wPrediv = (float)(ww-1)/(iw-1);
 
+        const float brightnessAdjustment = accelFactor * ((float) ww*wh/(byteCount>>3));
+
         const uchar *bits = image.bits();
         const uint stepsize = 4*accelFactor;
 
@@ -79,8 +79,16 @@ QImage WaveformGenerator::calculateWaveform(const QSize &waveformSize, const QIm
             wavePoint = QPoint((int)dx, (int)(wh-1 - dy));
 
             waveCol = QRgb(wave.pixel(wavePoint));
-            wave.setPixel(wavePoint, qRgba(CHOP255(9 + qRed(waveCol)), CHOP255(36 + qGreen(waveCol)),
-                                           CHOP255(18 + qBlue(waveCol)), 255));
+            switch (paintMode) {
+            case PaintMode_Green:
+                wave.setPixel(wavePoint, qRgba(CHOP255(9 + qRed(waveCol)), CHOP255(36 + qGreen(waveCol)),
+                                               CHOP255(18 + qBlue(waveCol)), 255));
+                break;
+            default:
+                wave.setPixel(wavePoint, qRgba(255, 242,
+                                               0, CHOP255(brightnessAdjustment*10+qAlpha(waveCol))));
+                break;
+            }
 
             bits += stepsize;
             x += stepsize;
@@ -99,14 +107,12 @@ QImage WaveformGenerator::calculateWaveform(const QSize &waveformSize, const QIm
                     wave.setPixel(x,dy, qRgba(CHOP255(150+qRed(opx)), 255,
                                               CHOP255(200+qBlue(opx)), CHOP255(32+qAlpha(opx))));
                 }
-                //davinci.drawLine(0, dy, ww-1, dy);
             }
         }
 
     }
 
     uint diff = time.elapsed();
-//    qDebug() << "Waveform calculation ended. Time taken: " << diff << " ms. Sending signal now.";
     emit signalCalculationFinished(wave, diff);
 
     return wave;
index 531c482000b8e707ee58cfeb194dbaa204397420..97c57c8cd7244e600911044b48165a3908dd2d42 100644 (file)
@@ -20,10 +20,13 @@ class WaveformGenerator : public QObject
     Q_OBJECT
 
 public:
+    enum PaintMode { PaintMode_Green, PaintMode_Yellow };
+
     WaveformGenerator();
     ~WaveformGenerator();
 
-    QImage calculateWaveform(const QSize &waveformSize, const QImage &image, const bool &drawAxis, const uint &accelFactor = 1);
+    QImage calculateWaveform(const QSize &waveformSize, const QImage &image, WaveformGenerator::PaintMode paintMode,
+                             const bool &drawAxis, const uint &accelFactor = 1);
 
 signals:
     void signalCalculationFinished(QImage image, const uint &ms);
index aaf8d0824a6a2405f2dc116ff9e708307cb4ad9c..794603b66a21c482a92d3373b11bf2f968c56cbb 100644 (file)
@@ -23,16 +23,43 @@ Waveform::Waveform(Monitor *projMonitor, Monitor *clipMonitor, QWidget *parent)
 {
     ui = new Ui::Waveform_UI();
     ui->setupUi(this);
-    init();
 
+    ui->paintMode->addItem(i18n("Yellow"), QVariant(WaveformGenerator::PaintMode_Yellow));
+    ui->paintMode->addItem(i18n("Green"), QVariant(WaveformGenerator::PaintMode_Green));
+
+
+    bool b = true;
+    b &= connect(ui->paintMode, SIGNAL(currentIndexChanged(int)), this, SLOT(forceUpdateScope()));
+    Q_ASSERT(b);
+
+
+    init();
     m_waveformGenerator = new WaveformGenerator();
 }
 
 Waveform::~Waveform()
 {
+    writeConfig();
+
     delete m_waveformGenerator;
 }
 
+void Waveform::readConfig()
+{
+    AbstractScopeWidget::readConfig();
+
+    KSharedConfigPtr config = KGlobal::config();
+    KConfigGroup scopeConfig(config, configName());
+    ui->paintMode->setCurrentIndex(scopeConfig.readEntry("paintmode", 0));
+}
+
+void Waveform::writeConfig()
+{
+    KSharedConfigPtr config = KGlobal::config();
+    KConfigGroup scopeConfig(config, configName());
+    scopeConfig.writeEntry("paintmode", ui->paintMode->currentIndex());
+    scopeConfig.sync();
+}
 
 
 QRect Waveform::scopeRect()
@@ -64,8 +91,9 @@ QImage Waveform::renderScope(uint accelFactor, QImage qimage)
     QTime start = QTime::currentTime();
     start.start();
 
-    QImage wave = m_waveformGenerator->calculateWaveform(scopeRect().size(),
-                                                         qimage, true, accelFactor);
+    int paintmode = ui->paintMode->itemData(ui->paintMode->currentIndex()).toInt();
+    QImage wave = m_waveformGenerator->calculateWaveform(scopeRect().size(), qimage, (WaveformGenerator::PaintMode) paintmode,
+                                                         true, accelFactor);
 
     emit signalScopeRenderingFinished(start.elapsed(), 1);
     return wave;
index d1e3735f887f0f8bc5545ffb2227e8b5f5c475ec..b88607a1e0350a90ee2a2070c294196b748059a3 100644 (file)
@@ -27,6 +27,10 @@ public:
 
     virtual QString widgetName() const;
 
+protected:
+    virtual void readConfig();
+    void writeConfig();
+
 private:
     Ui::Waveform_UI *ui;