From a0782da90d2e491e2f1ec9ad8a114883fb2e02b4 Mon Sep 17 00:00:00 2001 From: "Simon A. Eugster" Date: Tue, 22 Feb 2011 14:19:03 +0000 Subject: [PATCH] HSV Saturation plane added svn path=/trunk/kdenlive/; revision=5452 --- src/colorplaneexport.cpp | 13 +++++++++++++ src/colorplaneexport.h | 2 +- src/colortools.cpp | 29 ++++++++++++++++++++++++++++- src/colortools.h | 7 +++++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/colorplaneexport.cpp b/src/colorplaneexport.cpp index 37c1ee4f..107cd4e7 100644 --- a/src/colorplaneexport.cpp +++ b/src/colorplaneexport.cpp @@ -35,6 +35,7 @@ ColorPlaneExport::ColorPlaneExport(QWidget *parent) : 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); @@ -188,6 +189,11 @@ void ColorPlaneExport::slotExportPlane() case CPE_HSV_HUESHIFT: 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); + break; + default: + Q_ASSERT(false); } img.save(kurlrequester->text()); } @@ -247,6 +253,13 @@ void ColorPlaneExport::slotColormodeChanged() 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); diff --git a/src/colorplaneexport.h b/src/colorplaneexport.h index f4eeebdc..36816c24 100644 --- a/src/colorplaneexport.h +++ b/src/colorplaneexport.h @@ -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, CPE_HSV_HUESHIFT }; + enum COLOR_EXPORT_MODE { CPE_YUV, CPE_YUV_Y, CPE_YUV_MOD, CPE_RGB_CURVE, CPE_YPbPr, CPE_HSV_HUESHIFT, CPE_HSV_SATURATION }; private: ColorTools *m_colorTools; diff --git a/src/colortools.cpp b/src/colortools.cpp index d42d12b3..a1df69ed 100644 --- a/src/colortools.cpp +++ b/src/colortools.cpp @@ -268,8 +268,8 @@ QImage ColorTools::hsvHueShiftPlane(const QSize &size, const uint &S, const uint float hue, huediff; int newhue; for (int x = 0; x < size.width(); x++) { + hue = x/(size.width() - 1.0) * 359; 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; @@ -285,6 +285,33 @@ 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) +{ + Q_ASSERT(size.width() > 0); + Q_ASSERT(size.height() > 0); + Q_ASSERT(MAX > MIN); + Q_ASSERT(MIN >= 0); + + QImage plane(size, QImage::Format_ARGB32); + + QColor col(0, 0, 0); + + float hue, sat; + + for (int x = 0; x < size.width(); x++) { + hue = 359 * x / (size.width()-1.0); + for (int y = 0; y < size.height(); y++) { + sat = (1 - y/(size.height()-1.0)) * (MAX-MIN) + MIN; + + col.setHsv(hue, sat, V); + + plane.setPixel(x, y, col.rgba()); + } + } + + return plane; +} + diff --git a/src/colortools.h b/src/colortools.h index af79f7fc..f1e29bd6 100644 --- a/src/colortools.h +++ b/src/colortools.h @@ -64,11 +64,18 @@ public: /** @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. + MIN/MAX give the minimum/maximum hue difference, e.g. -128,+128. 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); + /** + Basic HSV saturation plane. + 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); + signals: void signalYuvWheelCalculationFinished(); }; -- 2.39.5