]> git.sesse.net Git - kdenlive/commitdiff
Color Tools
authorSimon A. Eugster <simon.eu@gmail.com>
Sat, 17 Jul 2010 20:55:55 +0000 (20:55 +0000)
committerSimon A. Eugster <simon.eu@gmail.com>
Sat, 17 Jul 2010 20:55:55 +0000 (20:55 +0000)
* YPbPr wheel added
* Slightly faster if exporting full YUV plane (not filling with transparent color anymore at the beginning)
Vectorscope
* YPbPr added as option for background export
* Box Layout improved, scales now

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

src/CMakeLists.txt
src/colorplaneexport.cpp
src/colorplaneexport.h
src/colortools.cpp
src/colortools.h
src/vectorscope.cpp
src/waveform.cpp [new file with mode: 0644]
src/waveform.h [new file with mode: 0644]
src/widgets/vectorscope_ui.ui
src/widgets/waveform_ui.ui [new file with mode: 0644]

index 7319b63c509e979f912fe586ca6b3400e0831329..f2ef96c2c8e8c9fe00750dc38bb83465bbb4de6f 100644 (file)
@@ -91,6 +91,7 @@ kde4_add_ui_files(kdenlive_UI
   widgets/urlval_ui.ui
   widgets/vectorscope_ui.ui
   widgets/colorplaneexport_ui.ui
+  widgets/waveform_ui.ui
 )
 
 set(kdenlive_SRCS
@@ -196,6 +197,7 @@ set(kdenlive_SRCS
   colorplaneexport.cpp
   colortools.cpp
   rebuildgroupcommand.cpp
+  waveform.cpp
 )
 
 add_definitions( ${KDE4_DEFINITIONS} )
index 2ed27b0593781af8516dd59838d9a0be8ebcb6c2..b37efd76355a2ef2ab25123db953c93e14af977a 100644 (file)
@@ -25,10 +25,11 @@ ColorPlaneExport::ColorPlaneExport(QWidget *parent) :
     tResX->setText("800");
     tResY->setText("800");
 
-    cbColorspace->addItem(i18n("YUV UV plane"), QVariant(CPE_YUV));
-    cbColorspace->addItem(i18n("YUV Y plane"), QVariant(CPE_YUV_Y));
-    cbColorspace->addItem(i18n("Modified YUV (Chroma)"), QVariant(CPE_YUV_MOD));
-    cbColorspace->addItem(i18n("RGB plane, one component varying"), QVariant(CPE_RGB_CURVE));
+    cbColorspace->addItem(i18n("YUV UV plane"), QVariant(ColorPlaneExport::CPE_YUV));
+    cbColorspace->addItem(i18n("YUV Y plane"), QVariant(ColorPlaneExport::CPE_YUV_Y));
+    cbColorspace->addItem(i18n("Modified YUV (Chroma)"), QVariant(ColorPlaneExport::CPE_YUV_MOD));
+    cbColorspace->addItem(i18n("YCbCr CbCr plane"), QVariant(ColorPlaneExport::CPE_YPbPr));
+    cbColorspace->addItem(i18n("RGB plane, one component varying"), QVariant(ColorPlaneExport::CPE_RGB_CURVE));
 
     sliderColor->setSliderPosition(128);
 
@@ -159,6 +160,9 @@ void ColorPlaneExport::slotExportPlane()
     case CPE_RGB_CURVE:
         img = m_colorTools->rgbCurvePlane(size, (ColorTools::ColorsRGB) (cbVariant->itemData(cbVariant->currentIndex()).toInt()));
         break;
+    case CPE_YPbPr:
+        img = m_colorTools->yPbPrColorWheel(size, sliderColor->value(), m_scaling, false);
+        break;
     }
     img.save(kurlrequester->text());
 }
@@ -169,6 +173,7 @@ void ColorPlaneExport::slotColormodeChanged()
     switch (cbColorspace->itemData(cbColorspace->currentIndex()).toInt()) {
     case CPE_YUV:
     case CPE_YUV_MOD:
+    case CPE_YPbPr:
         enableSliderScaling(true);
         enableSliderColor(true);
         enableCbVariant(false);
index 48225586a2cca8b39e43e0013ab8ba582b3a7c13..96384276e4569c45e20ff5e4602b577802f09a0a 100644 (file)
 
 class ColorPlaneExport_UI;
 
-enum COLOR_EXPORT_MODE { CPE_YUV, CPE_YUV_Y, CPE_YUV_MOD, CPE_RGB_CURVE };
-
 class ColorPlaneExport : public QDialog, public Ui::ColorPlaneExport_UI {
     Q_OBJECT
 public:
     ColorPlaneExport(QWidget *parent = 0);
     ~ColorPlaneExport();
 
-protected:
+    enum COLOR_EXPORT_MODE { CPE_YUV, CPE_YUV_Y, CPE_YUV_MOD, CPE_RGB_CURVE, CPE_YPbPr };
 
 private:
     ColorTools *m_colorTools;
index 70772cb5578df173c04d59a5df129ed584444bea..c0cd5b73464ebbac73b4e9cf3865a75e575c6e90 100644 (file)
@@ -24,7 +24,9 @@ QImage ColorTools::yuvColorWheel(const QSize &size, const unsigned char &Y, cons
         qCritical("ERROR: Size of the color wheel must not be 0!");
         return wheel;
     }
-    wheel.fill(qRgba(0,0,0,0));
+    if (circleOnly) {
+        wheel.fill(qRgba(0,0,0,0));
+    }
 
     double dr, dg, db, du, dv, dmax;
     double ru, rv, rr;
@@ -86,7 +88,7 @@ QImage ColorTools::yuvColorWheel(const QSize &size, const unsigned char &Y, cons
         }
     }
 
-    emit signalWheelCalculationFinished();
+    emit signalYuvWheelCalculationFinished();
     return wheel;
 }
 
@@ -146,10 +148,10 @@ QImage ColorTools::rgbCurvePlane(const QSize &size, const ColorsRGB &color)
     double dcol, dval;
 
     for (int x = 0; x < w; x++) {
-        dval = (double)255*x/w;
+        dval = (double)255*x/(w-1);
 
         for (int y = 0; y < h; y++) {
-            dcol = (double)255*y/h;
+            dcol = (double)255*y/(h-1);
 
             if (color == ColorTools::COL_R) {
                 plane.setPixel(x, (h-y-1), qRgb(dcol, dval, dval));
@@ -164,6 +166,67 @@ QImage ColorTools::rgbCurvePlane(const QSize &size, const ColorsRGB &color)
     return plane;
 }
 
+QImage ColorTools::yPbPrColorWheel(const QSize &size, const unsigned char &Y, const float &scaling, const bool &circleOnly)
+{
+
+    QImage wheel(size, QImage::Format_ARGB32);
+    if (size.width() == 0 || size.height() == 0) {
+        qCritical("ERROR: Size of the color wheel must not be 0!");
+        return wheel;
+    }
+    if (circleOnly) {
+        wheel.fill(qRgba(0,0,0,0));
+    }
+
+    double dr, dg, db, dpB, dpR;
+    double rB, rR, rr;
+    const int w = size.width();
+    const int h = size.height();
+    const float w2 = (float)w/2;
+    const float h2 = (float)h/2;
+
+    for (int b = 0; b < w; b++) {
+        // Transform pB from {0,...,w} to [-0.5,0.5]
+        dpB = (double) b/(w-1) - .5;
+        dpB = scaling*dpB;
+
+        for (int r = 0; r < h; r++) {
+            dpR = (double) r/(h-1) - .5;
+            dpR = scaling*dpR;
+
+            if (circleOnly) {
+                // see yuvColorWheel
+                rB = b - w2;
+                rR = r - h2;
+                rr = rB*rB/(w2*w2) + rR*rR/(h2*h2);
+                if (rr > 1) {
+                    continue;
+                }
+            }
+
+            // Calculate the RGB values from YPbPr
+            dr = Y + 357.5*dpR;
+            dg = Y - 87.75*dpB - 182.1*dpR;
+            db = Y + 451.86*dpB;
+
+            // Avoid overflows (which would generate intersting patterns).
+            // Note that not all possible (y,u,v) values with u,v \in [-1,1]
+            // have a correct RGB representation, therefore some RGB values
+            // may exceed {0,...,255}.
+            if (dr < 0) dr = 0;
+            if (dg < 0) dg = 0;
+            if (db < 0) db = 0;
+            if (dr > 255) dr = 255;
+            if (dg > 255) dg = 255;
+            if (db > 255) db = 255;
+
+            wheel.setPixel(b, (h-r-1), qRgba(dr, dg, db, 255));
+        }
+    }
+
+    return wheel;
+}
+
 
 
 
index 7ba179167b69927a2ac798c22a45bfb539e73f31..1b2eb1a21d18d5841f41608602557a3a4e8b6d44 100644 (file)
@@ -52,9 +52,16 @@ public:
       in equal terms (linear as well) on the x axis.
      */
     QImage rgbCurvePlane(const QSize &size, const ColorTools::ColorsRGB &color);
+    /**
+      @brief Draws a YPbPr plane with Pb on the x axis and Pr on the y axis.
+      Y is the Y value to use.
+      scaling defines how far to zoom in (or out). Lower value = zoom in.
+      See also: http://de.wikipedia.org/wiki/YPbPr-Farbmodell and http://www.poynton.com/ColorFAQ.html
+     */
+    QImage yPbPrColorWheel(const QSize &size, const unsigned char &Y, const float &scaling, const bool &circleOnly);
 
 signals:
-    void signalWheelCalculationFinished();
+    void signalYuvWheelCalculationFinished();
 };
 
 #endif // COLORTOOLS_H
index 6c6e0aab590f2457744ebcc65b947d8fb85f6a57..75639d3bdd58bf1a2f30b16e7ed74280b60ca118 100644 (file)
@@ -101,7 +101,7 @@ Vectorscope::Vectorscope(Monitor *projMonitor, Monitor *clipMonitor, QWidget *pa
     connect(backgroundMode, SIGNAL(currentIndexChanged(int)), this, SLOT(slotBackgroundChanged()));
     connect(cbMagnify, SIGNAL(stateChanged(int)), this, SLOT(slotMagnifyChanged()));
     connect(this, SIGNAL(signalScopeCalculationFinished(uint,uint)), this, SLOT(slotScopeCalculationFinished(uint,uint)));
-    connect(m_colorTools, SIGNAL(signalWheelCalculationFinished()), this, SLOT(slotWheelCalculationFinished()));
+    connect(m_colorTools, SIGNAL(signalYuvWheelCalculationFinished()), this, SLOT(slotWheelCalculationFinished()));
     connect(paintMode, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateScope()));
     connect(cbAutoRefresh, SIGNAL(stateChanged(int)), this, SLOT(slotUpdateScope()));
 
diff --git a/src/waveform.cpp b/src/waveform.cpp
new file mode 100644 (file)
index 0000000..0b6affb
--- /dev/null
@@ -0,0 +1,11 @@
+#include "waveform.h"
+
+Waveform::Waveform(QWidget *parent) :
+    QWidget(parent)
+{
+    setupUi(this);
+}
+
+Waveform::~Waveform()
+{
+}
diff --git a/src/waveform.h b/src/waveform.h
new file mode 100644 (file)
index 0000000..1f403f9
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef WAVEFORM_H
+#define WAVEFORM_H
+
+#include <QWidget>
+
+#include "ui_waveform_ui.h"
+
+class Waveform_UI;
+
+class Waveform : public QWidget, public Ui::Waveform_UI {
+    Q_OBJECT
+
+public:
+    Waveform(QWidget *parent = 0);
+    ~Waveform();
+
+};
+
+#endif // WAVEFORM_H
index 1039c591d817855fa8c8571655aedcc271bba697..8084ba6c69984ed15c26e0e262cd257bbd31d25e 100644 (file)
   <property name="windowTitle">
    <string>Form</string>
   </property>
-  <widget class="QWidget" name="gridLayoutWidget">
-   <property name="geometry">
-    <rect>
-     <x>0</x>
-     <y>0</y>
-     <width>401</width>
-     <height>101</height>
-    </rect>
-   </property>
-   <layout class="QGridLayout" name="gridLayout">
-    <property name="sizeConstraint">
-     <enum>QLayout::SetDefaultConstraint</enum>
-    </property>
-    <property name="leftMargin">
-     <number>5</number>
-    </property>
-    <property name="topMargin">
-     <number>5</number>
-    </property>
-    <property name="rightMargin">
-     <number>5</number>
-    </property>
-    <item row="1" column="0">
-     <layout class="QVBoxLayout" name="controlsArea">
-      <item>
-       <layout class="QGridLayout" name="gridLayout_2">
-        <property name="horizontalSpacing">
-         <number>10</number>
-        </property>
-        <item row="1" column="1">
-         <widget class="QComboBox" name="paintMode">
-          <property name="sizePolicy">
-           <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
-            <horstretch>0</horstretch>
-            <verstretch>0</verstretch>
-           </sizepolicy>
-          </property>
-         </widget>
-        </item>
-        <item row="2" column="1">
-         <widget class="QComboBox" name="backgroundMode">
-          <property name="sizePolicy">
-           <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
-            <horstretch>0</horstretch>
-            <verstretch>0</verstretch>
-           </sizepolicy>
-          </property>
-         </widget>
-        </item>
-        <item row="1" column="0">
-         <widget class="QLabel" name="lblPaintMode">
-          <property name="text">
-           <string>Paint mode</string>
-          </property>
-         </widget>
-        </item>
-        <item row="2" column="0">
-         <widget class="QLabel" name="lblBackground">
-          <property name="text">
-           <string>Background</string>
-          </property>
-         </widget>
-        </item>
-       </layout>
-      </item>
-      <item>
-       <layout class="QHBoxLayout" name="horizontalLayout">
-        <item>
-         <widget class="QCheckBox" name="cbMagnify">
-          <property name="text">
-           <string>Magnify</string>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <widget class="QCheckBox" name="cbAutoRefresh">
-          <property name="text">
-           <string>Auto-Refresh</string>
-          </property>
-         </widget>
-        </item>
-       </layout>
-      </item>
-     </layout>
-    </item>
-    <item row="2" column="0">
-     <spacer name="verticalSpacer">
-      <property name="orientation">
-       <enum>Qt::Vertical</enum>
-      </property>
-      <property name="sizeHint" stdset="0">
-       <size>
-        <width>20</width>
-        <height>40</height>
-       </size>
-      </property>
-     </spacer>
-    </item>
-   </layout>
-  </widget>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <layout class="QVBoxLayout" name="controlsArea">
+     <item>
+      <layout class="QGridLayout" name="gridLayout_2">
+       <property name="horizontalSpacing">
+        <number>10</number>
+       </property>
+       <item row="1" column="1">
+        <widget class="QComboBox" name="paintMode">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+        </widget>
+       </item>
+       <item row="2" column="1">
+        <widget class="QComboBox" name="backgroundMode">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="0">
+        <widget class="QLabel" name="lblPaintMode">
+         <property name="text">
+          <string>Paint mode</string>
+         </property>
+        </widget>
+       </item>
+       <item row="2" column="0">
+        <widget class="QLabel" name="lblBackground">
+         <property name="text">
+          <string>Background</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout">
+       <item>
+        <widget class="QCheckBox" name="cbMagnify">
+         <property name="text">
+          <string>Magnify</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QCheckBox" name="cbAutoRefresh">
+         <property name="text">
+          <string>Auto-Refresh</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+    </layout>
+   </item>
+   <item row="1" column="0">
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>344</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+  </layout>
  </widget>
  <resources/>
  <connections/>
diff --git a/src/widgets/waveform_ui.ui b/src/widgets/waveform_ui.ui
new file mode 100644 (file)
index 0000000..5e7f852
--- /dev/null
@@ -0,0 +1,191 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Waveform_UI</class>
+ <widget class="QWidget" name="Waveform_UI">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="palette">
+   <palette>
+    <active>
+     <colorrole role="WindowText">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>250</red>
+        <green>238</green>
+        <blue>226</blue>
+       </color>
+      </brush>
+     </colorrole>
+     <colorrole role="Button">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>40</red>
+        <green>40</green>
+        <blue>39</blue>
+       </color>
+      </brush>
+     </colorrole>
+     <colorrole role="Text">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>250</red>
+        <green>238</green>
+        <blue>226</blue>
+       </color>
+      </brush>
+     </colorrole>
+     <colorrole role="ButtonText">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>250</red>
+        <green>238</green>
+        <blue>226</blue>
+       </color>
+      </brush>
+     </colorrole>
+     <colorrole role="Base">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>40</red>
+        <green>40</green>
+        <blue>39</blue>
+       </color>
+      </brush>
+     </colorrole>
+     <colorrole role="Window">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>40</red>
+        <green>40</green>
+        <blue>39</blue>
+       </color>
+      </brush>
+     </colorrole>
+    </active>
+    <inactive>
+     <colorrole role="WindowText">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>250</red>
+        <green>238</green>
+        <blue>226</blue>
+       </color>
+      </brush>
+     </colorrole>
+     <colorrole role="Button">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>40</red>
+        <green>40</green>
+        <blue>39</blue>
+       </color>
+      </brush>
+     </colorrole>
+     <colorrole role="Text">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>250</red>
+        <green>238</green>
+        <blue>226</blue>
+       </color>
+      </brush>
+     </colorrole>
+     <colorrole role="ButtonText">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>250</red>
+        <green>238</green>
+        <blue>226</blue>
+       </color>
+      </brush>
+     </colorrole>
+     <colorrole role="Base">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>40</red>
+        <green>40</green>
+        <blue>39</blue>
+       </color>
+      </brush>
+     </colorrole>
+     <colorrole role="Window">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>40</red>
+        <green>40</green>
+        <blue>39</blue>
+       </color>
+      </brush>
+     </colorrole>
+    </inactive>
+    <disabled>
+     <colorrole role="WindowText">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>146</red>
+        <green>145</green>
+        <blue>144</blue>
+       </color>
+      </brush>
+     </colorrole>
+     <colorrole role="Button">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>40</red>
+        <green>40</green>
+        <blue>39</blue>
+       </color>
+      </brush>
+     </colorrole>
+     <colorrole role="Text">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>165</red>
+        <green>164</green>
+        <blue>164</blue>
+       </color>
+      </brush>
+     </colorrole>
+     <colorrole role="ButtonText">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>151</red>
+        <green>150</green>
+        <blue>149</blue>
+       </color>
+      </brush>
+     </colorrole>
+     <colorrole role="Base">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>40</red>
+        <green>40</green>
+        <blue>39</blue>
+       </color>
+      </brush>
+     </colorrole>
+     <colorrole role="Window">
+      <brush brushstyle="SolidPattern">
+       <color alpha="255">
+        <red>40</red>
+        <green>40</green>
+        <blue>39</blue>
+       </color>
+      </brush>
+     </colorrole>
+    </disabled>
+   </palette>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>