]> git.sesse.net Git - kdenlive/commitdiff
RGB Parade changes:
authorSimon A. Eugster <simon.eu@gmail.com>
Tue, 31 Aug 2010 14:58:16 +0000 (14:58 +0000)
committerSimon A. Eugster <simon.eu@gmail.com>
Tue, 31 Aug 2010 14:58:16 +0000 (14:58 +0000)
* Added a line through the mouse position to display the value
* Neutral paint mode White added
* Paint mode RGB2 removed, looked bad

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

src/colorcorrection/rgbparadegenerator.cpp
src/colorcorrection/rgbparadegenerator.h
src/histogram.cpp
src/rgbparade.cpp
src/waveform.cpp

index 222749c3333cb86d32f8e6d2cc20f1c49e3061c1..b3edd1bb7d31765a984df2f449d613ee9abdaa98 100644 (file)
@@ -21,6 +21,10 @@ const QColor RGBParadeGenerator::colHighlight(255, 245, 235, 255);
 const QColor RGBParadeGenerator::colLight(200, 200, 200, 255);
 const QColor RGBParadeGenerator::colSoft(150, 150, 150, 255);
 
+
+const uchar RGBParadeGenerator::distRight(40);
+const uchar RGBParadeGenerator::distBottom(40);
+
 RGBParadeGenerator::RGBParadeGenerator()
 {
 }
@@ -52,20 +56,12 @@ QImage RGBParadeGenerator::calculateRGBParade(const QSize &paradeSize, const QIm
         const uint byteCount = iw*ih;
 
         const uchar offset = 10;
-        const uchar right = 40;
-        const uchar bottom = 40;
-        const int partW = (ww - 2*offset - right) / 3;
-        const int partH = wh - bottom;
+        const int partW = (ww - 2*offset - distRight) / 3;
+        const int partH = wh - distBottom;
 
         // To get constant brightness, independant of acceleration factor and input image size
         // Must be a float because the acceleration factor can be high, leading to <1 expected px per px.
-        const float avgPxPerPx = ((float)(image.width() * image.height()) / (500*partW*accelFactor));
-        const float weaken = (avgPxPerPx == 0) ? 1 : (float)4/avgPxPerPx;
-        const int vh = weaken*27;
-        const int vm = weaken*18;
-        const int vl = weaken*9;
-
-        // Divide by 3 because of the 3 components
+        // Divide by 3 because of the 3 components.
         const float brightnessAdjustment = accelFactor * ((float) ww*wh/(byteCount>>3)) / 3;
 
         uchar minR = 255, minG = 255, minB = 255, maxR = 0, maxG = 0, maxB = 0, r, g, b;
@@ -73,7 +69,7 @@ QImage RGBParadeGenerator::calculateRGBParade(const QSize &paradeSize, const QIm
 //                << " with an acceleration factor of " << accelFactor;
 
 
-        QImage unscaled(ww-right, 256, QImage::Format_ARGB32);
+        QImage unscaled(ww-distRight, 256, QImage::Format_ARGB32);
         unscaled.fill(qRgba(0, 0, 0, 0));
 
         const float wPrediv = (float)(partW-1)/(iw-1);
@@ -93,36 +89,33 @@ QImage RGBParadeGenerator::calculateRGBParade(const QSize &paradeSize, const QIm
             paradePoint = QPoint((int)dx, r);
             paradeCol = QRgb(unscaled.pixel(paradePoint));
             switch(paintMode) {
-            case PaintMode_RGB2:
-                unscaled.setPixel(paradePoint, qRgba(CHOP255(vh + qRed(paradeCol)), CHOP255(vm + qGreen(paradeCol)),
-                                                     CHOP255(vl + qBlue(paradeCol)), 255));
+            case PaintMode_RGB:
+                unscaled.setPixel(paradePoint, qRgba(255,10,10, CHOP255(brightnessAdjustment*16 + qAlpha(paradeCol))));
                 break;
             default:
-                unscaled.setPixel(paradePoint, qRgba(255,0,0, CHOP255(brightnessAdjustment*16 + qAlpha(paradeCol))));
+                unscaled.setPixel(paradePoint, qRgba(255,255,255, CHOP255(brightnessAdjustment*16 + qAlpha(paradeCol))));
                 break;
             }
 
             paradePoint = QPoint((int) (dx + partW + offset), g);
             paradeCol = QRgb(unscaled.pixel(paradePoint));
             switch(paintMode) {
-            case PaintMode_RGB2:
-                unscaled.setPixel(paradePoint, qRgba(CHOP255(vl + qRed(paradeCol)), CHOP255(vh + qGreen(paradeCol)),
-                                               CHOP255(vm + qBlue(paradeCol)), 255));
+            case PaintMode_RGB:
+                unscaled.setPixel(paradePoint, qRgba(10,255,10, CHOP255(brightnessAdjustment*16 + qAlpha(paradeCol))));
                 break;
             default:
-                unscaled.setPixel(paradePoint, qRgba(0,255,0, CHOP255(brightnessAdjustment*16 + qAlpha(paradeCol))));
+                unscaled.setPixel(paradePoint, qRgba(255,255,255, CHOP255(brightnessAdjustment*16 + qAlpha(paradeCol))));
                 break;
             }
 
             paradePoint = QPoint((int) (dx + 2*partW + 2*offset), b);
             paradeCol = QRgb(unscaled.pixel(paradePoint));
             switch(paintMode) {
-            case PaintMode_RGB2:
-                unscaled.setPixel(paradePoint, qRgba(CHOP255(vm + qRed(paradeCol)), CHOP255(vl + qGreen(paradeCol)),
-                                               CHOP255(vh + qBlue(paradeCol)), 255));
+            case PaintMode_RGB:
+                unscaled.setPixel(paradePoint, qRgba(10,10,255, CHOP255(brightnessAdjustment*16 + qAlpha(paradeCol))));
                 break;
             default:
-                unscaled.setPixel(paradePoint, qRgba(0,0,255, CHOP255(brightnessAdjustment*16 + qAlpha(paradeCol))));
+                unscaled.setPixel(paradePoint, qRgba(255,255,255, CHOP255(brightnessAdjustment*16 + qAlpha(paradeCol))));
                 break;
             }
 
@@ -147,7 +140,7 @@ QImage RGBParadeGenerator::calculateRGBParade(const QSize &paradeSize, const QIm
             QRgb opx;
             for (uint i = 0; i <= 10; i++) {
                 dy = (float)i/10 * (partH-1);
-                for (uint x = 0; x < ww-right; x++) {
+                for (uint x = 0; x < ww-distRight; x++) {
                     opx = parade.pixel(x, dy);
                     parade.setPixel(x,dy, qRgba(CHOP255(150+qRed(opx)), 255,
                                               CHOP255(200+qBlue(opx)), CHOP255(32+qAlpha(opx))));
@@ -190,8 +183,8 @@ QImage RGBParadeGenerator::calculateRGBParade(const QSize &paradeSize, const QIm
         davinci.drawText(partW + offset + d,       wh-20, QString::number(maxG, 'f', 0));
         davinci.drawText(2*partW + 2*offset + d,   wh-20, QString::number(maxB, 'f', 0));
 
-        davinci.drawText(ww-right+5,            10,      "255");
-        davinci.drawText(ww-right+5,            partH+5,  "0");
+        davinci.drawText(ww-distRight+5,            10,      "255");
+        davinci.drawText(ww-distRight+5,            partH+5,  "0");
 
 
 
index 50b98c9117467f989f418b9969d84f8cb34b3b8f..17a3752b0970024c7f5af76294847f538494d81d 100644 (file)
@@ -19,7 +19,7 @@ class QSize;
 class RGBParadeGenerator : public QObject
 {
 public:
-    enum PaintMode { PaintMode_RGB, PaintMode_RGB2 };
+    enum PaintMode { PaintMode_RGB, PaintMode_White };
 
     RGBParadeGenerator();
     QImage calculateRGBParade(const QSize &paradeSize, const QImage &image, const RGBParadeGenerator::PaintMode paintMode,
@@ -28,6 +28,9 @@ public:
     static const QColor colHighlight;
     static const QColor colLight;
     static const QColor colSoft;
+
+    static const uchar distRight;
+    static const uchar distBottom;
 };
 
 #endif // RGBPARADEGENERATOR_H
index 8529aa45ad7036048c181e27bd1d8a32c45288a9..fe24ee6b093bec03bf1a61d7f41d6605ac97d1e5 100644 (file)
@@ -15,7 +15,7 @@
 #include "renderer.h"
 
 Histogram::Histogram(Monitor *projMonitor, Monitor *clipMonitor, QWidget *parent) :
-    AbstractScopeWidget(projMonitor, clipMonitor, parent)
+    AbstractScopeWidget(projMonitor, clipMonitor, false, parent)
 {
     ui = new Ui::Histogram_UI();
     ui->setupUi(this);
index c14ac9a0cc70c1d3e44495442b6ca836093ca6f8..7e0ca385caf1146a7e4017783ad30f086ca8a483 100644 (file)
@@ -9,6 +9,7 @@
  ***************************************************************************/
 
 #include <QMenu>
+#include <QPainter>
 #include <QRect>
 #include <QTime>
 #include "renderer.h"
 #include "rgbparadegenerator.h"
 
 RGBParade::RGBParade(Monitor *projMonitor, Monitor *clipMonitor, QWidget *parent) :
-        AbstractScopeWidget(projMonitor, clipMonitor, parent)
+        AbstractScopeWidget(projMonitor, clipMonitor, true, parent)
 {
     ui = new Ui::RGBParade_UI();
     ui->setupUi(this);
 
     ui->paintMode->addItem(i18n("RGB"), QVariant(RGBParadeGenerator::PaintMode_RGB));
-    ui->paintMode->addItem(i18n("RGB 2"), QVariant(RGBParadeGenerator::PaintMode_RGB2));
+    ui->paintMode->addItem(i18n("White"), QVariant(RGBParadeGenerator::PaintMode_White));
 
     bool b = true;
 
@@ -38,7 +39,7 @@ RGBParade::RGBParade(Monitor *projMonitor, Monitor *clipMonitor, QWidget *parent
     b &= connect(m_aGradRef, SIGNAL(changed()), this, SLOT(forceUpdateScope()));
 
     b &= connect(ui->paintMode, SIGNAL(currentIndexChanged(int)), this, SLOT(forceUpdateScope()));
-
+    b &= connect(this, SIGNAL(signalMousePositionChanged()), this, SLOT(forceUpdateHUD()));
     Q_ASSERT(b);
 
     m_rgbParadeGenerator = new RGBParadeGenerator();
@@ -85,7 +86,32 @@ QRect RGBParade::scopeRect()
     return QRect(topleft, QPoint(this->size().width() - offset, this->size().height() - offset));
 }
 
-QImage RGBParade::renderHUD(uint) { return QImage(); }
+QImage RGBParade::renderHUD(uint)
+{
+    if (scopeRect().height() > 0 && m_mouseWithinWidget) {
+        QImage hud(m_scopeRect.size(), QImage::Format_ARGB32);
+        hud.fill(qRgba(0,0,0,0));
+
+        QPainter davinci(&hud);
+        davinci.setPen(penLight);
+
+        int x = scopeRect().width()-30;
+        int y = m_mousePos.y() - scopeRect().y();
+
+        // Draw a horizontal line through the current mouse position
+        // and show the value of the waveform there
+        davinci.drawLine(0, y, scopeRect().size().width()-RGBParadeGenerator::distRight, y);
+
+        int val = 255*(1-((float)y/(scopeRect().height()-RGBParadeGenerator::distBottom)));
+        davinci.drawText(x, scopeRect().height()/2, QVariant(val).toString());
+
+        emit signalHUDRenderingFinished(1, 1);
+        return hud;
+    } else {
+        emit signalHUDRenderingFinished(1, 1);
+        return QImage();
+    }
+}
 QImage RGBParade::renderScope(uint accelerationFactor, QImage qimage)
 {
     QTime start = QTime::currentTime();
index 035b29102d799414beb0eaac8ba6538d36a3d6c9..cb7dcf5c15b96744b6afdfa8e0b2ca240663bdfc 100644 (file)
@@ -107,15 +107,18 @@ QImage Waveform::renderHUD(uint)
 {
     QImage hud(m_scopeRect.size(), QImage::Format_ARGB32);
     hud.fill(qRgba(0,0,0,0));
-    QPainter davinci(&hud);
 
+    QPainter davinci(&hud);
     davinci.setPen(penLight);
 
     int x = scopeRect().width()-m_textWidth.width()+3;
     int y = m_mousePos.y() - scopeRect().y();
 
     if (scopeRect().height() > 0 && m_mouseWithinWidget) {
+        // Draw a horizontal line through the current mouse position
+        // and show the value of the waveform there
         davinci.drawLine(0, y, scopeRect().size().width()-m_textWidth.width(), y);
+
         int val = 255*(1-(float)y/scopeRect().height());
         davinci.drawText(x, scopeRect().height()/2, QVariant(val).toString());
     }