]> git.sesse.net Git - kdenlive/commitdiff
HSV color plane generalized
authorSimon A. Eugster <simon.eu@gmail.com>
Sat, 12 Mar 2011 16:14:38 +0000 (16:14 +0000)
committerSimon A. Eugster <simon.eu@gmail.com>
Sat, 12 Mar 2011 16:14:38 +0000 (16:14 +0000)
svn path=/trunk/kdenlive/; revision=5489

src/colorplaneexport.cpp
src/colortools.cpp
src/colortools.h

index 107cd4e7b1ca77d86c0b75f54757d90046b589e0..84fe1f0690319d10b9f8425f50c2df3a10ca3ab9 100644 (file)
@@ -168,6 +168,7 @@ void ColorPlaneExport::slotExportPlane()
         }
     }
     QImage img;
         }
     }
     QImage img;
+    QColor col;
     QSize size(QVariant(tResX->text()).toInt(), QVariant(tResY->text()).toInt());
     switch (cbColorspace->itemData(cbColorspace->currentIndex()).toInt()) {
     case CPE_YUV:
     QSize size(QVariant(tResX->text()).toInt(), QVariant(tResY->text()).toInt());
     switch (cbColorspace->itemData(cbColorspace->currentIndex()).toInt()) {
     case CPE_YUV:
@@ -190,7 +191,8 @@ void ColorPlaneExport::slotExportPlane()
         img = m_colorTools->hsvHueShiftPlane(size, sliderColor->value(), sliderScaling->value(), -180, 180);
         break;
     case CPE_HSV_SATURATION:
         img = m_colorTools->hsvHueShiftPlane(size, sliderColor->value(), sliderScaling->value(), -180, 180);
         break;
     case CPE_HSV_SATURATION:
-        img = m_colorTools->hsvSaturationPlane(size, sliderColor->value(), 0, 255);
+        col.setHsv(0, 0, sliderColor->value());
+        img = m_colorTools->hsvCurvePlane(size, col, ColorTools::COM_H, ColorTools::COM_S);
         break;
     default:
         Q_ASSERT(false);
         break;
     default:
         Q_ASSERT(false);
index a1df69ed208a6214d7f9e60358d3da8edf0e07e5..c01dc5ac6f723476766eaef158dfbd4a56e2b9b8 100644 (file)
@@ -285,31 +285,76 @@ QImage ColorTools::hsvHueShiftPlane(const QSize &size, const uint &S, const uint
 
 }
 
 
 }
 
-QImage ColorTools::hsvSaturationPlane(const QSize &size, const uint &V, const int &MIN, const int &MAX)
+QImage ColorTools::hsvCurvePlane(const QSize &size, const QColor &baseColor, const ComponentsHSV &xVariant, const ComponentsHSV &yVariant)
 {
     Q_ASSERT(size.width() > 0);
     Q_ASSERT(size.height() > 0);
 {
     Q_ASSERT(size.width() > 0);
     Q_ASSERT(size.height() > 0);
-    Q_ASSERT(MAX > MIN);
-    Q_ASSERT(MIN >= 0);
+
+    int xMax, yMax;
+
+    switch(xVariant) {
+    case COM_H:
+        xMax = 360;
+        break;
+    case COM_S:
+    case COM_V:
+        xMax = 256;
+        break;
+    }
+
+    switch (yVariant) {
+    case COM_H:
+        yMax = 360;
+        break;
+    case COM_S:
+    case COM_V:
+        yMax = 256;
+        break;
+    }
+
 
     QImage plane(size, QImage::Format_ARGB32);
 
     QColor col(0, 0, 0);
 
 
     QImage plane(size, QImage::Format_ARGB32);
 
     QColor col(0, 0, 0);
 
-    float hue, sat;
+    float hue, sat, val;
+    hue = baseColor.hueF();
+    sat = baseColor.saturationF();
+    val = baseColor.valueF();
 
     for (int x = 0; x < size.width(); x++) {
 
     for (int x = 0; x < size.width(); x++) {
-        hue = 359 * x / (size.width()-1.0);
+        switch (xVariant) {
+        case COM_H:
+            hue = x / (size.width()-1.0);
+            break;
+        case COM_S:
+            sat = x / (size.width()-1.0);
+            break;
+        case COM_V:
+            val = x / (size.width()-1.0);
+            break;
+        }
         for (int y = 0; y < size.height(); y++) {
         for (int y = 0; y < size.height(); y++) {
-            sat = (1 - y/(size.height()-1.0)) * (MAX-MIN) + MIN;
+            switch (yVariant) {
+            case COM_H:
+                hue = 1.0 - y / (size.height()-1.0);
+                break;
+            case COM_S:
+                sat = 1.0 - y / (size.height()-1.0);
+                break;
+            case COM_V:
+                val = 1.0 - y / (size.height()-1.0);
+                break;
+            }
 
 
-            col.setHsv(hue, sat, V);
+            col.setHsvF(hue, sat, val);
 
             plane.setPixel(x, y, col.rgba());
         }
     }
 
     return plane;
 
             plane.setPixel(x, y, col.rgba());
         }
     }
 
     return plane;
+
 }
 
 
 }
 
 
index f1e29bd6880b838d18e0a28aca98b42ee7c3029b..2bd84b1619c2f855cadd47f08266c84305c1e6f7 100644 (file)
@@ -27,6 +27,8 @@ public:
 
     enum ColorsRGB { COL_R, COL_G, COL_B, COL_A, COL_Luma, COL_RGB };
 
 
     enum ColorsRGB { COL_R, COL_G, COL_B, COL_A, COL_Luma, COL_RGB };
 
+    enum ComponentsHSV { COM_H, COM_S, COM_V };
+
     /**
       @brief Draws a UV plane with given Y value.
       scaling defines how far to zoom in (or out). Lower value = zoom in.
     /**
       @brief Draws a UV plane with given Y value.
       scaling defines how far to zoom in (or out). Lower value = zoom in.
@@ -71,10 +73,11 @@ public:
     static QImage hsvHueShiftPlane(const QSize &size, const uint &S, const uint &V, const int &MIN, const int &MAX);
 
     /**
     static QImage hsvHueShiftPlane(const QSize &size, const uint &S, const uint &V, const int &MIN, const int &MAX);
 
     /**
-      Basic HSV saturation plane.
+      Basic HSV plane with two components varying on the x and y axis.
+      If both components are the same, then the y axis will be considered.
       MIN/MAX give the minimum/maximum saturation, usually 0..255.
       */
       MIN/MAX give the minimum/maximum saturation, usually 0..255.
       */
-    static QImage hsvSaturationPlane(const QSize &size, const uint &V, const int &MIN, const int &MAX);
+    static QImage hsvCurvePlane(const QSize &size, const QColor &baseColor, const ComponentsHSV &xVariant, const ComponentsHSV &yVariant);
 
 signals:
     void signalYuvWheelCalculationFinished();
 
 signals:
     void signalYuvWheelCalculationFinished();