From 55fc4cfc56fa01993530deb889f6ad990aeb057f Mon Sep 17 00:00:00 2001 From: "Simon A. Eugster" Date: Sat, 12 Mar 2011 16:14:38 +0000 Subject: [PATCH] HSV color plane generalized svn path=/trunk/kdenlive/; revision=5489 --- src/colorplaneexport.cpp | 4 ++- src/colortools.cpp | 59 +++++++++++++++++++++++++++++++++++----- src/colortools.h | 7 +++-- 3 files changed, 60 insertions(+), 10 deletions(-) diff --git a/src/colorplaneexport.cpp b/src/colorplaneexport.cpp index 107cd4e7..84fe1f06 100644 --- a/src/colorplaneexport.cpp +++ b/src/colorplaneexport.cpp @@ -168,6 +168,7 @@ void ColorPlaneExport::slotExportPlane() } } QImage img; + QColor col; QSize size(QVariant(tResX->text()).toInt(), QVariant(tResY->text()).toInt()); switch (cbColorspace->itemData(cbColorspace->currentIndex()).toInt()) { case CPE_YUV: @@ -190,7 +191,8 @@ void ColorPlaneExport::slotExportPlane() 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); + col.setHsv(0, 0, sliderColor->value()); + img = m_colorTools->hsvCurvePlane(size, col, ColorTools::COM_H, ColorTools::COM_S); break; default: Q_ASSERT(false); diff --git a/src/colortools.cpp b/src/colortools.cpp index a1df69ed..c01dc5ac 100644 --- a/src/colortools.cpp +++ b/src/colortools.cpp @@ -285,31 +285,76 @@ 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) +QImage ColorTools::hsvCurvePlane(const QSize &size, const QColor &baseColor, const ComponentsHSV &xVariant, const ComponentsHSV &yVariant) { Q_ASSERT(size.width() > 0); Q_ASSERT(size.height() > 0); - Q_ASSERT(MAX > MIN); - Q_ASSERT(MIN >= 0); + + int xMax, yMax; + + switch(xVariant) { + case COM_H: + xMax = 360; + break; + case COM_S: + case COM_V: + xMax = 256; + break; + } + + switch (yVariant) { + case COM_H: + yMax = 360; + break; + case COM_S: + case COM_V: + yMax = 256; + break; + } + QImage plane(size, QImage::Format_ARGB32); QColor col(0, 0, 0); - float hue, sat; + float hue, sat, val; + hue = baseColor.hueF(); + sat = baseColor.saturationF(); + val = baseColor.valueF(); for (int x = 0; x < size.width(); x++) { - hue = 359 * x / (size.width()-1.0); + switch (xVariant) { + case COM_H: + hue = x / (size.width()-1.0); + break; + case COM_S: + sat = x / (size.width()-1.0); + break; + case COM_V: + val = x / (size.width()-1.0); + break; + } for (int y = 0; y < size.height(); y++) { - sat = (1 - y/(size.height()-1.0)) * (MAX-MIN) + MIN; + switch (yVariant) { + case COM_H: + hue = 1.0 - y / (size.height()-1.0); + break; + case COM_S: + sat = 1.0 - y / (size.height()-1.0); + break; + case COM_V: + val = 1.0 - y / (size.height()-1.0); + break; + } - col.setHsv(hue, sat, V); + col.setHsvF(hue, sat, val); plane.setPixel(x, y, col.rgba()); } } return plane; + } diff --git a/src/colortools.h b/src/colortools.h index f1e29bd6..2bd84b16 100644 --- a/src/colortools.h +++ b/src/colortools.h @@ -27,6 +27,8 @@ public: enum ColorsRGB { COL_R, COL_G, COL_B, COL_A, COL_Luma, COL_RGB }; + enum ComponentsHSV { COM_H, COM_S, COM_V }; + /** @brief Draws a UV plane with given Y value. scaling defines how far to zoom in (or out). Lower value = zoom in. @@ -71,10 +73,11 @@ public: static QImage hsvHueShiftPlane(const QSize &size, const uint &S, const uint &V, const int &MIN, const int &MAX); /** - Basic HSV saturation plane. + Basic HSV plane with two components varying on the x and y axis. + If both components are the same, then the y axis will be considered. 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); + static QImage hsvCurvePlane(const QSize &size, const QColor &baseColor, const ComponentsHSV &xVariant, const ComponentsHSV &yVariant); signals: void signalYuvWheelCalculationFinished(); -- 2.39.2