]> git.sesse.net Git - kdenlive/blobdiff - src/colorplaneexport.cpp
Const'ref
[kdenlive] / src / colorplaneexport.cpp
index 2ed27b0593781af8516dd59838d9a0be8ebcb6c2..b4daaa54ccbc13557a15a6fe204481f521e86a80 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;
 
@@ -25,10 +29,13 @@ 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));
+    cbColorspace->addItem(i18n("HSV Hue Shift"), QVariant(ColorPlaneExport::CPE_HSV_HUESHIFT));
+    cbColorspace->addItem(i18n("HSV Saturation"), QVariant(ColorPlaneExport::CPE_HSV_SATURATION));
 
     sliderColor->setSliderPosition(128);
 
@@ -62,21 +69,21 @@ ColorPlaneExport::~ColorPlaneExport()
 
 ///// Helper functions /////
 
-void ColorPlaneExport::enableSliderScaling(const bool &enable)
+void ColorPlaneExport::enableSliderScaling(bool enable)
 {
     sliderScaling->setEnabled(enable);
     lblScaling->setEnabled(enable);
     lblScaleNr->setEnabled(enable);
 }
 
-void ColorPlaneExport::enableSliderColor(const bool &enable)
+void ColorPlaneExport::enableSliderColor(bool enable)
 {
     sliderColor->setEnabled(enable);
     lblSliderName->setEnabled(enable);
     lblColNr->setEnabled(enable);
 }
 
-void ColorPlaneExport::enableCbVariant(const bool &enable)
+void ColorPlaneExport::enableCbVariant(bool enable)
 {
    cbVariant->setEnabled(enable);
    lblVariant->setEnabled(enable);
@@ -95,7 +102,17 @@ void ColorPlaneExport::slotUpdateDisplays()
 {
     m_scaling = 1 - (float)sliderScaling->value()/100;
 
-    lblScaleNr->setText("0..." + QString::number(m_scaling, 'f', 2));
+    switch(cbColorspace->itemData(cbColorspace->currentIndex()).toInt()){
+    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;
+    }
 
     switch (cbColorspace->itemData(cbColorspace->currentIndex()).toInt()) {
     case CPE_YUV_Y:
@@ -106,7 +123,7 @@ void ColorPlaneExport::slotUpdateDisplays()
         break;
     }
 
-    lblSize->setText(i18n("%1 px", QVariant(tResX->text()).toInt()*QVariant(tResY->text()).toInt()));
+    lblSize->setText(i18n("%1 px", tResX->text().toInt()*tResY->text().toInt()));
 }
 
 void ColorPlaneExport::slotValidate()
@@ -122,7 +139,9 @@ void ColorPlaneExport::slotValidate()
     }
     if (ok) {
         ok = kurlrequester->text().trimmed().length() > 0;
+#ifdef DEBUG_CPE
         qDebug() << "File given: " << ok;
+#endif
     }
 
     if (ok) {
@@ -136,15 +155,20 @@ 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"));
         }
     }
     QImage img;
+    QColor col;
     QSize size(QVariant(tResX->text()).toInt(), QVariant(tResY->text()).toInt());
     switch (cbColorspace->itemData(cbColorspace->currentIndex()).toInt()) {
     case CPE_YUV:
@@ -157,18 +181,36 @@ void ColorPlaneExport::slotExportPlane()
         img = m_colorTools->yuvColorWheel(size, sliderColor->value(), m_scaling, true, false);
         break;
     case CPE_RGB_CURVE:
-        img = m_colorTools->rgbCurvePlane(size, (ColorTools::ColorsRGB) (cbVariant->itemData(cbVariant->currentIndex()).toInt()));
+        img = m_colorTools->rgbCurvePlane(size, (ColorTools::ColorsRGB) (cbVariant->itemData(cbVariant->currentIndex()).toInt()),
+                                          (double)sliderScaling->value()/255);
+        break;
+    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;
+    case CPE_HSV_SATURATION:
+        col.setHsv(0, 0, sliderColor->value());
+        img = m_colorTools->hsvCurvePlane(size, col, ColorTools::COM_H, ColorTools::COM_S);
         break;
+    default:
+        Q_ASSERT(false);
     }
     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:
+    case CPE_YPbPr:
         enableSliderScaling(true);
         enableSliderColor(true);
         enableCbVariant(false);
@@ -178,7 +220,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);
@@ -189,7 +233,35 @@ void ColorPlaneExport::slotColormodeChanged()
         lblSliderName->setToolTip(i18n("Angle through the UV plane, with all possible Y values."));
         break;
     case CPE_RGB_CURVE:
-        // deliberately fall through
+        enableSliderScaling(true);
+        enableSliderColor(false);
+        enableCbVariant(true);
+        sliderScaling->setRange(1,255);
+        sliderScaling->setValue(255);
+        cbVariant->addItem(i18n("Red"), QVariant(ColorTools::COL_R));
+        cbVariant->addItem(i18n("Green"), QVariant(ColorTools::COL_G));
+        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;
+    case CPE_HSV_SATURATION:
+        enableSliderScaling(false);
+        enableSliderColor(true);
+        sliderColor->setRange(0, 255);
+        sliderColor->setValue(200);
+        lblSliderName->setText(i18n("HSV Value"));
+        break;
     default:
         enableSliderScaling(false);
         enableSliderColor(false);
@@ -197,8 +269,11 @@ void ColorPlaneExport::slotColormodeChanged()
         cbVariant->addItem(i18n("Red"), QVariant(ColorTools::COL_R));
         cbVariant->addItem(i18n("Green"), QVariant(ColorTools::COL_G));
         cbVariant->addItem(i18n("Blue"), QVariant(ColorTools::COL_B));
+        cbVariant->addItem(i18n("Luma"), QVariant(ColorTools::COL_Luma));
         break;
     }
     this->update();
     slotUpdateDisplays();
 }
+
+#include "colorplaneexport.moc"