]> git.sesse.net Git - kdenlive/commitdiff
Background color plane for Hueshift added
authorSimon A. Eugster <simon.eu@gmail.com>
Mon, 21 Feb 2011 16:05:48 +0000 (16:05 +0000)
committerSimon A. Eugster <simon.eu@gmail.com>
Mon, 21 Feb 2011 16:05:48 +0000 (16:05 +0000)
http://www.kdenlive.org/mantis/view.php?id=1997

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

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

index 5f55e52d390bcb4cd4ba7f22d359489c9f7edc09..37c1ee4f267feeb0bfba3fc29704b505b4ffcfbe 100644 (file)
@@ -9,9 +9,13 @@
  ***************************************************************************/
 
 #include "colorplaneexport.h"
-#include <QDebug>
 #include <KMessageBox>
 
+//#define DEBUG_CTE
+#ifdef DEBUG_CTE
+#include <QDebug>
+#endif
+
 const QString EXTENSION_PNG = ".png";
 const int SCALE_RANGE = 80;
 
@@ -30,6 +34,7 @@ ColorPlaneExport::ColorPlaneExport(QWidget *parent) :
     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));
+    cbColorspace->addItem(i18n("HSV Hue Shift"), QVariant(ColorPlaneExport::CPE_HSV_HUESHIFT));
 
     sliderColor->setSliderPosition(128);
 
@@ -100,6 +105,9 @@ void ColorPlaneExport::slotUpdateDisplays()
     case CPE_RGB_CURVE:
         lblScaleNr->setText(QChar(0xb1) + QString::number(sliderScaling->value(), 'f', 2));;
         break;
+    case CPE_HSV_HUESHIFT:
+        lblScaleNr->setText(QString::number(sliderScaling->value()));
+        break;
     default:
         lblScaleNr->setText("0..." + QString::number(m_scaling, 'f', 2));
         break;
@@ -130,7 +138,9 @@ void ColorPlaneExport::slotValidate()
     }
     if (ok) {
         ok = kurlrequester->text().trimmed().length() > 0;
+#ifdef DEBUG_CPE
         qDebug() << "File given: " << ok;
+#endif
     }
 
     if (ok) {
@@ -144,9 +154,13 @@ void ColorPlaneExport::slotValidate()
 
 void ColorPlaneExport::slotExportPlane()
 {
+#ifdef DEBUG_CPE
     qDebug() << "Exporting plane now to " <<  kurlrequester->text();
+#endif
     QString lower = kurlrequester->text().toLower();
+#ifdef DEBUG_CPE
     qDebug() << "Lower: " << lower;
+#endif
     if (!lower.endsWith(".png") && !lower.endsWith(".jpg") && !lower.endsWith(".tif") && !lower.endsWith(".tiff")) {
         if (KMessageBox::questionYesNo(this, i18n("File has no extension. Add extension (%1)?", EXTENSION_PNG)) == KMessageBox::Yes) {
             kurlrequester->setUrl(KUrl(kurlrequester->text() + ".png"));
@@ -171,13 +185,20 @@ void ColorPlaneExport::slotExportPlane()
     case CPE_YPbPr:
         img = m_colorTools->yPbPrColorWheel(size, sliderColor->value(), m_scaling, false);
         break;
+    case CPE_HSV_HUESHIFT:
+        img = m_colorTools->hsvHueShiftPlane(size, sliderColor->value(), sliderScaling->value(), -180, 180);
+        break;
     }
     img.save(kurlrequester->text());
 }
 
 void ColorPlaneExport::slotColormodeChanged()
 {
+#ifdef DEBUG_CPE
     qDebug() << "Color mode changed to " << cbColorspace->itemData(cbColorspace->currentIndex()).toInt();
+#endif
+    lblScaling->setText(i18n("Scaling"));
+    sliderScaling->setInvertedAppearance(true);
     switch (cbColorspace->itemData(cbColorspace->currentIndex()).toInt()) {
     case CPE_YUV:
     case CPE_YUV_MOD:
@@ -191,7 +212,9 @@ void ColorPlaneExport::slotColormodeChanged()
         lblSliderName->setToolTip(i18n("The Y value describes the brightness of the colors."));
         break;
     case CPE_YUV_Y:
+#ifdef DEBUG_CPE
         qDebug() << "Changing slider range.";
+#endif
         enableSliderScaling(true);
         enableSliderColor(true);
         enableCbVariant(false);
@@ -212,6 +235,18 @@ void ColorPlaneExport::slotColormodeChanged()
         cbVariant->addItem(i18n("Blue"), QVariant(ColorTools::COL_B));
         cbVariant->addItem(i18n("Luma"), QVariant(ColorTools::COL_Luma));
         break;
+    case CPE_HSV_HUESHIFT:
+        enableSliderScaling(true);
+        enableSliderColor(true);
+        enableCbVariant(false);
+        sliderScaling->setRange(0,255);
+        sliderScaling->setValue(200);
+        sliderScaling->setInvertedAppearance(false);
+        sliderColor->setRange(0,255);
+        sliderColor->setValue(200);
+        lblSliderName->setText(i18n("HSV Saturation"));
+        lblScaling->setText(i18n("HSV Value"));
+        break;
     default:
         enableSliderScaling(false);
         enableSliderColor(false);
index 96384276e4569c45e20ff5e4602b577802f09a0a..f4eeebdc1891083d232160ddaada02feac344c7c 100644 (file)
@@ -28,7 +28,7 @@ public:
     ColorPlaneExport(QWidget *parent = 0);
     ~ColorPlaneExport();
 
-    enum COLOR_EXPORT_MODE { CPE_YUV, CPE_YUV_Y, CPE_YUV_MOD, CPE_RGB_CURVE, CPE_YPbPr };
+    enum COLOR_EXPORT_MODE { CPE_YUV, CPE_YUV_Y, CPE_YUV_MOD, CPE_RGB_CURVE, CPE_YPbPr, CPE_HSV_HUESHIFT };
 
 private:
     ColorTools *m_colorTools;
index eeb659829a90c325a1f5df7d1d043e617b2a5249..d42d12b3e1cda8a53caa13645beb7d025b249cf5 100644 (file)
 
 #include <math.h>
 #include "colortools.h"
+#include <QColor>
+
+//#define DEBUG_CT
+#ifdef DEBUG_CT
+#include <QDebug>
+#endif
 
 ColorTools::ColorTools()
 {
@@ -241,6 +247,44 @@ QImage ColorTools::yPbPrColorWheel(const QSize &size, const unsigned char &Y, co
     return wheel;
 }
 
+QImage ColorTools::hsvHueShiftPlane(const QSize &size, const uint &S, const uint &V, const int &MIN, const int &MAX)
+{
+    Q_ASSERT(size.width() > 0);
+    Q_ASSERT(size.height() > 0);
+    Q_ASSERT(MAX > MIN);
+
+    QImage plane(size, QImage::Format_ARGB32);
+
+#ifdef DEBUG_CT
+    qDebug() << "Requested: Saturation " << S << ", Value " << V;
+    QColor colTest(-1, 256, 257);
+    qDebug() << "-1 mapped to " << colTest.red() << ", 256 to " << colTest.green() << ", 257 to " << colTest.blue();
+#endif
+
+    QColor col(0, 0, 0);
+
+    const int hueValues = MAX-MIN;
+
+    float hue, huediff;
+    int newhue;
+    for (int x = 0; x < size.width(); x++) {
+        for (int y = 0; y < size.height(); y++) {
+            hue = x/(size.width() - 1.0) * 359;
+            huediff = (1.0f - y/(size.height() - 1.0)) * hueValues + MIN;
+//            qDebug() << "hue: " << hue << ", huediff: " << huediff;
+
+            newhue = hue + huediff + 360; // Avoid negative numbers. Rest (>360) will be mapped correctly.
+
+            col.setHsv(newhue, S, V);
+            plane.setPixel(x, y, col.rgba());
+
+        }
+    }
+
+    return plane;
+
+}
+
 
 
 
index adfbd634ec8a639b4fcc2d5bb09391f9a2ccbf5f..af79f7fc656308a1571bb53f780cc6acc4d4f4f9 100644 (file)
@@ -18,7 +18,6 @@
 #include <QImage>
 
 
-
 class ColorTools : public QObject
 {
     Q_OBJECT
@@ -62,6 +61,13 @@ public:
       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);
+    /**
+     @brief Draws a HSV plane with Hue on the x axis and hue difference on the y axis.
+     This is for the Bézier Curves widget which allows to change the hue (y) of a certain hue.
+     For the value ranges see:
+     http://doc.qt.nokia.com/latest/qcolor.html#the-hsv-color-model
+     */
+    static QImage hsvHueShiftPlane(const QSize &size, const uint &S, const uint &V, const int &MIN, const int &MAX);
 
 signals:
     void signalYuvWheelCalculationFinished();