X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fcolorplaneexport.cpp;h=b4daaa54ccbc13557a15a6fe204481f521e86a80;hb=c3302003093710ee247ad84c0fe2ef3c579d417f;hp=d773486d7ee470787c658fc0f24f4af5dc5479df;hpb=c471a29fcef185bffaff48c4185588f4a8416ca4;p=kdenlive diff --git a/src/colorplaneexport.cpp b/src/colorplaneexport.cpp index d773486d..b4daaa54 100644 --- a/src/colorplaneexport.cpp +++ b/src/colorplaneexport.cpp @@ -9,9 +9,13 @@ ***************************************************************************/ #include "colorplaneexport.h" -#include #include +//#define DEBUG_CTE +#ifdef DEBUG_CTE +#include +#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); @@ -47,7 +54,7 @@ ColorPlaneExport::ColorPlaneExport(QWidget *parent) : 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(); @@ -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,18 +102,28 @@ 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: - lblColNr->setText(i18n("%1 °", QString::number(sliderColor->value()))); + 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())); + 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->setText(kurlrequester->text() + ".png"); + 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"