***************************************************************************/
#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;
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));
sliderColor->setSliderPosition(128);
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;
}
if (ok) {
ok = kurlrequester->text().trimmed().length() > 0;
+#ifdef DEBUG_CPE
qDebug() << "File given: " << ok;
+#endif
}
if (ok) {
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"));
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;
}
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:
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);
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;
default:
enableSliderScaling(false);
enableSliderColor(false);
#include <math.h>
#include "colortools.h"
+#include <QColor>
+
+//#define DEBUG_CT
+#ifdef DEBUG_CT
+#include <QDebug>
+#endif
ColorTools::ColorTools()
{
return wheel;
}
+QImage ColorTools::hsvHueShiftPlane(const QSize &size, const uint &S, const uint &V, const int &MIN, const int &MAX)
+{
+ Q_ASSERT(size.width() > 0);
+ Q_ASSERT(size.height() > 0);
+ Q_ASSERT(MAX > MIN);
+
+ QImage plane(size, QImage::Format_ARGB32);
+
+#ifdef DEBUG_CT
+ qDebug() << "Requested: Saturation " << S << ", Value " << V;
+ QColor colTest(-1, 256, 257);
+ qDebug() << "-1 mapped to " << colTest.red() << ", 256 to " << colTest.green() << ", 257 to " << colTest.blue();
+#endif
+
+ QColor col(0, 0, 0);
+
+ const int hueValues = MAX-MIN;
+
+ float hue, huediff;
+ int newhue;
+ for (int x = 0; x < size.width(); x++) {
+ 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;
+
+ newhue = hue + huediff + 360; // Avoid negative numbers. Rest (>360) will be mapped correctly.
+
+ col.setHsv(newhue, S, V);
+ plane.setPixel(x, y, col.rgba());
+
+ }
+ }
+
+ return plane;
+
+}
+
#include <QImage>
-
class ColorTools : public QObject
{
Q_OBJECT
See also: http://de.wikipedia.org/wiki/YPbPr-Farbmodell and http://www.poynton.com/ColorFAQ.html
*/
QImage yPbPrColorWheel(const QSize &size, const unsigned char &Y, const float &scaling, const bool &circleOnly);
+ /**
+ @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.
+ 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);
signals:
void signalYuvWheelCalculationFinished();