From bea187213f3356420e9385401ccda1c3cfb454ec Mon Sep 17 00:00:00 2001 From: "Simon A. Eugster" Date: Sat, 17 Jul 2010 20:55:55 +0000 Subject: [PATCH] Color Tools * YPbPr wheel added * Slightly faster if exporting full YUV plane (not filling with transparent color anymore at the beginning) Vectorscope * YPbPr added as option for background export * Box Layout improved, scales now svn path=/trunk/kdenlive/; revision=4592 --- src/CMakeLists.txt | 2 + src/colorplaneexport.cpp | 13 ++- src/colorplaneexport.h | 4 +- src/colortools.cpp | 71 ++++++++++++- src/colortools.h | 9 +- src/vectorscope.cpp | 2 +- src/waveform.cpp | 11 ++ src/waveform.h | 19 ++++ src/widgets/vectorscope_ui.ui | 178 ++++++++++++++----------------- src/widgets/waveform_ui.ui | 191 ++++++++++++++++++++++++++++++++++ 10 files changed, 387 insertions(+), 113 deletions(-) create mode 100644 src/waveform.cpp create mode 100644 src/waveform.h create mode 100644 src/widgets/waveform_ui.ui diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7319b63c..f2ef96c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -91,6 +91,7 @@ kde4_add_ui_files(kdenlive_UI widgets/urlval_ui.ui widgets/vectorscope_ui.ui widgets/colorplaneexport_ui.ui + widgets/waveform_ui.ui ) set(kdenlive_SRCS @@ -196,6 +197,7 @@ set(kdenlive_SRCS colorplaneexport.cpp colortools.cpp rebuildgroupcommand.cpp + waveform.cpp ) add_definitions( ${KDE4_DEFINITIONS} ) diff --git a/src/colorplaneexport.cpp b/src/colorplaneexport.cpp index 2ed27b05..b37efd76 100644 --- a/src/colorplaneexport.cpp +++ b/src/colorplaneexport.cpp @@ -25,10 +25,11 @@ 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)); sliderColor->setSliderPosition(128); @@ -159,6 +160,9 @@ void ColorPlaneExport::slotExportPlane() case CPE_RGB_CURVE: img = m_colorTools->rgbCurvePlane(size, (ColorTools::ColorsRGB) (cbVariant->itemData(cbVariant->currentIndex()).toInt())); break; + case CPE_YPbPr: + img = m_colorTools->yPbPrColorWheel(size, sliderColor->value(), m_scaling, false); + break; } img.save(kurlrequester->text()); } @@ -169,6 +173,7 @@ void ColorPlaneExport::slotColormodeChanged() switch (cbColorspace->itemData(cbColorspace->currentIndex()).toInt()) { case CPE_YUV: case CPE_YUV_MOD: + case CPE_YPbPr: enableSliderScaling(true); enableSliderColor(true); enableCbVariant(false); diff --git a/src/colorplaneexport.h b/src/colorplaneexport.h index 48225586..96384276 100644 --- a/src/colorplaneexport.h +++ b/src/colorplaneexport.h @@ -22,15 +22,13 @@ class ColorPlaneExport_UI; -enum COLOR_EXPORT_MODE { CPE_YUV, CPE_YUV_Y, CPE_YUV_MOD, CPE_RGB_CURVE }; - class ColorPlaneExport : public QDialog, public Ui::ColorPlaneExport_UI { Q_OBJECT public: ColorPlaneExport(QWidget *parent = 0); ~ColorPlaneExport(); -protected: + enum COLOR_EXPORT_MODE { CPE_YUV, CPE_YUV_Y, CPE_YUV_MOD, CPE_RGB_CURVE, CPE_YPbPr }; private: ColorTools *m_colorTools; diff --git a/src/colortools.cpp b/src/colortools.cpp index 70772cb5..c0cd5b73 100644 --- a/src/colortools.cpp +++ b/src/colortools.cpp @@ -24,7 +24,9 @@ QImage ColorTools::yuvColorWheel(const QSize &size, const unsigned char &Y, cons qCritical("ERROR: Size of the color wheel must not be 0!"); return wheel; } - wheel.fill(qRgba(0,0,0,0)); + if (circleOnly) { + wheel.fill(qRgba(0,0,0,0)); + } double dr, dg, db, du, dv, dmax; double ru, rv, rr; @@ -86,7 +88,7 @@ QImage ColorTools::yuvColorWheel(const QSize &size, const unsigned char &Y, cons } } - emit signalWheelCalculationFinished(); + emit signalYuvWheelCalculationFinished(); return wheel; } @@ -146,10 +148,10 @@ QImage ColorTools::rgbCurvePlane(const QSize &size, const ColorsRGB &color) double dcol, dval; for (int x = 0; x < w; x++) { - dval = (double)255*x/w; + dval = (double)255*x/(w-1); for (int y = 0; y < h; y++) { - dcol = (double)255*y/h; + dcol = (double)255*y/(h-1); if (color == ColorTools::COL_R) { plane.setPixel(x, (h-y-1), qRgb(dcol, dval, dval)); @@ -164,6 +166,67 @@ QImage ColorTools::rgbCurvePlane(const QSize &size, const ColorsRGB &color) return plane; } +QImage ColorTools::yPbPrColorWheel(const QSize &size, const unsigned char &Y, const float &scaling, const bool &circleOnly) +{ + + QImage wheel(size, QImage::Format_ARGB32); + if (size.width() == 0 || size.height() == 0) { + qCritical("ERROR: Size of the color wheel must not be 0!"); + return wheel; + } + if (circleOnly) { + wheel.fill(qRgba(0,0,0,0)); + } + + double dr, dg, db, dpB, dpR; + double rB, rR, rr; + const int w = size.width(); + const int h = size.height(); + const float w2 = (float)w/2; + const float h2 = (float)h/2; + + for (int b = 0; b < w; b++) { + // Transform pB from {0,...,w} to [-0.5,0.5] + dpB = (double) b/(w-1) - .5; + dpB = scaling*dpB; + + for (int r = 0; r < h; r++) { + dpR = (double) r/(h-1) - .5; + dpR = scaling*dpR; + + if (circleOnly) { + // see yuvColorWheel + rB = b - w2; + rR = r - h2; + rr = rB*rB/(w2*w2) + rR*rR/(h2*h2); + if (rr > 1) { + continue; + } + } + + // Calculate the RGB values from YPbPr + dr = Y + 357.5*dpR; + dg = Y - 87.75*dpB - 182.1*dpR; + db = Y + 451.86*dpB; + + // Avoid overflows (which would generate intersting patterns). + // Note that not all possible (y,u,v) values with u,v \in [-1,1] + // have a correct RGB representation, therefore some RGB values + // may exceed {0,...,255}. + if (dr < 0) dr = 0; + if (dg < 0) dg = 0; + if (db < 0) db = 0; + if (dr > 255) dr = 255; + if (dg > 255) dg = 255; + if (db > 255) db = 255; + + wheel.setPixel(b, (h-r-1), qRgba(dr, dg, db, 255)); + } + } + + return wheel; +} + diff --git a/src/colortools.h b/src/colortools.h index 7ba17916..1b2eb1a2 100644 --- a/src/colortools.h +++ b/src/colortools.h @@ -52,9 +52,16 @@ public: in equal terms (linear as well) on the x axis. */ QImage rgbCurvePlane(const QSize &size, const ColorTools::ColorsRGB &color); + /** + @brief Draws a YPbPr plane with Pb on the x axis and Pr on the y axis. + Y is the Y value to use. + scaling defines how far to zoom in (or out). Lower value = zoom in. + 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); signals: - void signalWheelCalculationFinished(); + void signalYuvWheelCalculationFinished(); }; #endif // COLORTOOLS_H diff --git a/src/vectorscope.cpp b/src/vectorscope.cpp index 6c6e0aab..75639d3b 100644 --- a/src/vectorscope.cpp +++ b/src/vectorscope.cpp @@ -101,7 +101,7 @@ Vectorscope::Vectorscope(Monitor *projMonitor, Monitor *clipMonitor, QWidget *pa connect(backgroundMode, SIGNAL(currentIndexChanged(int)), this, SLOT(slotBackgroundChanged())); connect(cbMagnify, SIGNAL(stateChanged(int)), this, SLOT(slotMagnifyChanged())); connect(this, SIGNAL(signalScopeCalculationFinished(uint,uint)), this, SLOT(slotScopeCalculationFinished(uint,uint))); - connect(m_colorTools, SIGNAL(signalWheelCalculationFinished()), this, SLOT(slotWheelCalculationFinished())); + connect(m_colorTools, SIGNAL(signalYuvWheelCalculationFinished()), this, SLOT(slotWheelCalculationFinished())); connect(paintMode, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateScope())); connect(cbAutoRefresh, SIGNAL(stateChanged(int)), this, SLOT(slotUpdateScope())); diff --git a/src/waveform.cpp b/src/waveform.cpp new file mode 100644 index 00000000..0b6affb0 --- /dev/null +++ b/src/waveform.cpp @@ -0,0 +1,11 @@ +#include "waveform.h" + +Waveform::Waveform(QWidget *parent) : + QWidget(parent) +{ + setupUi(this); +} + +Waveform::~Waveform() +{ +} diff --git a/src/waveform.h b/src/waveform.h new file mode 100644 index 00000000..1f403f95 --- /dev/null +++ b/src/waveform.h @@ -0,0 +1,19 @@ +#ifndef WAVEFORM_H +#define WAVEFORM_H + +#include + +#include "ui_waveform_ui.h" + +class Waveform_UI; + +class Waveform : public QWidget, public Ui::Waveform_UI { + Q_OBJECT + +public: + Waveform(QWidget *parent = 0); + ~Waveform(); + +}; + +#endif // WAVEFORM_H diff --git a/src/widgets/vectorscope_ui.ui b/src/widgets/vectorscope_ui.ui index 1039c591..8084ba6c 100644 --- a/src/widgets/vectorscope_ui.ui +++ b/src/widgets/vectorscope_ui.ui @@ -197,106 +197,84 @@ Form - - - - 0 - 0 - 401 - 101 - - - - - QLayout::SetDefaultConstraint - - - 5 - - - 5 - - - 5 - - - - - - - 10 - - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - - - - - Paint mode - - - - - - - Background - - - - - - - - - - - Magnify - - - - - - - Auto-Refresh - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - + + + + + + + 10 + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + + + + + Paint mode + + + + + + + Background + + + + + + + + + + + Magnify + + + + + + + Auto-Refresh + + + + + + + + + + + Qt::Vertical + + + + 20 + 344 + + + + + diff --git a/src/widgets/waveform_ui.ui b/src/widgets/waveform_ui.ui new file mode 100644 index 00000000..5e7f852c --- /dev/null +++ b/src/widgets/waveform_ui.ui @@ -0,0 +1,191 @@ + + + Waveform_UI + + + + 0 + 0 + 400 + 300 + + + + + + + + + 250 + 238 + 226 + + + + + + + 40 + 40 + 39 + + + + + + + 250 + 238 + 226 + + + + + + + 250 + 238 + 226 + + + + + + + 40 + 40 + 39 + + + + + + + 40 + 40 + 39 + + + + + + + + + 250 + 238 + 226 + + + + + + + 40 + 40 + 39 + + + + + + + 250 + 238 + 226 + + + + + + + 250 + 238 + 226 + + + + + + + 40 + 40 + 39 + + + + + + + 40 + 40 + 39 + + + + + + + + + 146 + 145 + 144 + + + + + + + 40 + 40 + 39 + + + + + + + 165 + 164 + 164 + + + + + + + 151 + 150 + 149 + + + + + + + 40 + 40 + 39 + + + + + + + 40 + 40 + 39 + + + + + + + + Form + + + + + -- 2.39.2