]> git.sesse.net Git - kdenlive/blobdiff - src/colorplaneexport.cpp
waveform display
[kdenlive] / src / colorplaneexport.cpp
index 95a2ab68fa47eed40d5744a92ea16ef207f9af77..5f55e52d390bcb4cd4ba7f22d359489c9f7edc09 100644 (file)
@@ -25,8 +25,11 @@ ColorPlaneExport::ColorPlaneExport(QWidget *parent) :
     tResX->setText("800");
     tResY->setText("800");
 
-    cbColorspace->addItem(i18n("YUV"), QVariant(CPE_YUV));
-    cbColorspace->addItem(i18n("Modified YUV (Chroma)"), QVariant(CPE_YUV_MOD));
+    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);
 
@@ -43,8 +46,9 @@ ColorPlaneExport::ColorPlaneExport(QWidget *parent) :
     connect(kurlrequester, SIGNAL(textChanged(QString)), this, SLOT(slotValidate()));
     connect(sliderColor, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateDisplays()));
     connect(sliderScaling, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateDisplays()));
+    connect(cbColorspace, SIGNAL(currentIndexChanged(int)), this, SLOT(slotColormodeChanged()));
 
-    kurlrequester->setText("/tmp/yuv-plane.png");
+    kurlrequester->setUrl(KUrl("/tmp/yuv-plane.png"));
 
     slotColormodeChanged();
     slotValidate();
@@ -55,12 +59,60 @@ ColorPlaneExport::~ColorPlaneExport()
     delete m_colorTools;
 }
 
+
+
+///// Helper functions /////
+
+void ColorPlaneExport::enableSliderScaling(const bool &enable)
+{
+    sliderScaling->setEnabled(enable);
+    lblScaling->setEnabled(enable);
+    lblScaleNr->setEnabled(enable);
+}
+
+void ColorPlaneExport::enableSliderColor(const bool &enable)
+{
+    sliderColor->setEnabled(enable);
+    lblSliderName->setEnabled(enable);
+    lblColNr->setEnabled(enable);
+}
+
+void ColorPlaneExport::enableCbVariant(const bool &enable)
+{
+   cbVariant->setEnabled(enable);
+   lblVariant->setEnabled(enable);
+   if (!enable) {
+       while (cbVariant->count() > 0) {
+           cbVariant->removeItem(0);
+       }
+   }
+}
+
+
+
+///// Slots /////
+
 void ColorPlaneExport::slotUpdateDisplays()
 {
     m_scaling = 1 - (float)sliderScaling->value()/100;
 
-    lblScaleNr->setText("0..." + QString::number(m_scaling, 'f', 2));
-    lblColNr->setText(QString::number(sliderColor->value()));
+    switch(cbColorspace->itemData(cbColorspace->currentIndex()).toInt()){
+    case CPE_RGB_CURVE:
+        lblScaleNr->setText(QChar(0xb1) + QString::number(sliderScaling->value(), 'f', 2));;
+        break;
+    default:
+        lblScaleNr->setText("0..." + QString::number(m_scaling, 'f', 2));
+        break;
+    }
+
+    switch (cbColorspace->itemData(cbColorspace->currentIndex()).toInt()) {
+    case CPE_YUV_Y:
+        lblColNr->setText(i18n("%1°", QString::number(sliderColor->value())));
+        break;
+    default:
+        lblColNr->setText(QString::number(sliderColor->value()));
+        break;
+    }
 
     lblSize->setText(i18n("%1 px", QVariant(tResX->text()).toInt()*QVariant(tResY->text()).toInt()));
 }
@@ -97,7 +149,7 @@ void ColorPlaneExport::slotExportPlane()
     qDebug() << "Lower: " << lower;
     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->setText(kurlrequester->text() + ".png");
+            kurlrequester->setUrl(KUrl(kurlrequester->text() + ".png"));
         }
     }
     QImage img;
@@ -106,23 +158,70 @@ void ColorPlaneExport::slotExportPlane()
     case CPE_YUV:
         img = m_colorTools->yuvColorWheel(size, sliderColor->value(), m_scaling, false, false);
         break;
+    case CPE_YUV_Y:
+        img = m_colorTools->yuvVerticalPlane(size, sliderColor->value(), m_scaling);
+        break;
     case CPE_YUV_MOD:
         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()),
+                                          (double)sliderScaling->value()/255);
+        break;
+    case CPE_YPbPr:
+        img = m_colorTools->yPbPrColorWheel(size, sliderColor->value(), m_scaling, false);
+        break;
     }
     img.save(kurlrequester->text());
 }
 
 void ColorPlaneExport::slotColormodeChanged()
 {
+    qDebug() << "Color mode changed to " << cbColorspace->itemData(cbColorspace->currentIndex()).toInt();
     switch (cbColorspace->itemData(cbColorspace->currentIndex()).toInt()) {
     case CPE_YUV:
     case CPE_YUV_MOD:
-        sliderColor->setVisible(true);
+    case CPE_YPbPr:
+        enableSliderScaling(true);
+        enableSliderColor(true);
+        enableCbVariant(false);
         sliderColor->setRange(0,255);
+        sliderColor->setPageStep(128);
+        lblSliderName->setText(i18n("Y value"));
+        lblSliderName->setToolTip(i18n("The Y value describes the brightness of the colors."));
+        break;
+    case CPE_YUV_Y:
+        qDebug() << "Changing slider range.";
+        enableSliderScaling(true);
+        enableSliderColor(true);
+        enableCbVariant(false);
+        sliderColor->setMaximum(321);
+        sliderColor->setRange(0,179);
+        sliderColor->setPageStep(90);
+        lblSliderName->setText(i18n("UV angle"));
+        lblSliderName->setToolTip(i18n("Angle through the UV plane, with all possible Y values."));
+        break;
+    case CPE_RGB_CURVE:
+        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;
     default:
-        sliderColor->setVisible(false);
+        enableSliderScaling(false);
+        enableSliderColor(false);
+        enableCbVariant(true);
+        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();
 }