From 110cea8f3b680a056267727eb3057e4cb380d761 Mon Sep 17 00:00:00 2001 From: "Simon A. Eugster" Date: Thu, 22 Jul 2010 20:32:59 +0000 Subject: [PATCH] Levels displaying min/max values of YRGB svn path=/trunk/kdenlive/; revision=4625 --- src/colorcorrection/levelsgenerator.cpp | 131 ++++++++++++------------ src/colorcorrection/levelsgenerator.h | 18 +++- src/levels.cpp | 2 +- 3 files changed, 83 insertions(+), 68 deletions(-) diff --git a/src/colorcorrection/levelsgenerator.cpp b/src/colorcorrection/levelsgenerator.cpp index 7a216aaa..3f2c1b81 100644 --- a/src/colorcorrection/levelsgenerator.cpp +++ b/src/colorcorrection/levelsgenerator.cpp @@ -19,7 +19,8 @@ LevelsGenerator::LevelsGenerator() { } -QImage LevelsGenerator::calculateLevels(const QSize ¶deSize, const QImage &image, const int &components, const uint &accelFactor) const +QImage LevelsGenerator::calculateLevels(const QSize ¶deSize, const QImage &image, const int &components, + const bool &unscaled, const uint &accelFactor) const { qDebug() << "Levels rect size is: " << paradeSize.width() << "/" << paradeSize.height(); if (paradeSize.height() <= 0 || paradeSize.width() <= 0) { @@ -69,104 +70,102 @@ QImage LevelsGenerator::calculateLevels(const QSize ¶deSize, const QImage &i } const int d = 20; // Distance for text - const int partH = (wh-4*d)/nParts; + const int partH = (wh-nParts*d)/nParts; const float scaling = (float)partH/(byteCount >> 7); + const int dist = 40; int wy = 0; // Drawing position - int partY; // Vertical position for the dots QImage levels(paradeSize, QImage::Format_ARGB32); - QImage component(256, partH, QImage::Format_ARGB32); QPainter davinci(&levels); + davinci.setPen(QColor(220, 220, 220, 255)); levels.fill(qRgba(0, 0, 0, 0)); if (drawY) { qDebug() << "Drawing Y at " << wy << " with height " << partH; - component.fill(qRgba(0, 0, 0, 0)); - - for (int x = 0; x < 256; x++) { - // Calculate the height of the curve at position x - partY = scaling*y[x]; - - // Invert the y axis - if (partY > partH-1) { partY = partH-1; } - partY = partH-1 - partY; - - for (int k = partH-1; k >= partY; k--) { - component.setPixel(x, k, qRgba(220, 220, 210, 255)); - } - } - - davinci.drawImage(0, wy, component.scaled(ww, component.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation)); + drawComponentFull(&davinci, y, scaling, QRect(0, wy, ww, partH + dist), QColor(220, 220, 210, 255), dist, unscaled); wy += partH + d; } if (drawR) { qDebug() << "Drawing R at " << wy << " with height " << partH; - component.fill(qRgba(0, 0, 0, 0)); - - for (int x = 0; x < 256; x++) { - // Calculate the height of the curve at position x - partY = scaling*r[x]; - - // Invert the y axis - if (partY > partH-1) { partY = partH-1; } - partY = partH-1 - partY; - - for (int k = partH-1; k >= partY; k--) { - component.setPixel(x, k, qRgba(255, 128, 0, 255)); - } - } - - davinci.drawImage(0, wy, component.scaled(ww, component.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation)); + drawComponentFull(&davinci, r, scaling, QRect(0, wy, ww, partH + dist), QColor(255, 128, 0, 255), dist, unscaled); wy += partH + d; } if (drawG) { qDebug() << "Drawing G at " << wy << " with height " << partH; - component.fill(qRgba(0, 0, 0, 0)); + drawComponentFull(&davinci, r, scaling, QRect(0, wy, ww, partH + dist), QColor(128, 255, 0, 255), dist, unscaled); + wy += partH + d; + } - for (int x = 0; x < 256; x++) { - // Calculate the height of the curve at position x - partY = scaling*g[x]; + if (drawB) { + qDebug() << "Drawing B at " << wy << " with height " << partH; + drawComponentFull(&davinci, r, scaling, QRect(0, wy, ww, partH + dist), QColor(0, 128, 255, 255), dist, unscaled); - // Invert the y axis - if (partY > partH-1) { partY = partH-1; } - partY = partH-1 - partY; + wy += partH + d; + } - for (int k = partH-1; k >= partY; k--) { - component.setPixel(x, k, qRgba(128, 255, 0, 255)); - } - } + return levels; +} - davinci.drawImage(0, wy, component.scaled(ww, component.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation)); +QImage LevelsGenerator::drawComponent(const int *y, const QSize &size, const float &scaling, const QColor &color, const bool &unscaled) const +{ + QImage component(255, size.height(), QImage::Format_ARGB32); + component.fill(qRgba(0, 0, 0, 0)); - wy += partH + d; - } + const int partH = size.height(); + int partY; - if (drawB) { - qDebug() << "Drawing B at " << wy << " with height " << partH; - component.fill(qRgba(0, 0, 0, 0)); + for (int x = 0; x < 256; x++) { + // Calculate the height of the curve at position x + partY = scaling*y[x]; - for (int x = 0; x < 256; x++) { - // Calculate the height of the curve at position x - partY = scaling*b[x]; + // Invert the y axis + if (partY > partH-1) { partY = partH-1; } + partY = partH-1 - partY; - // Invert the y axis - if (partY > partH-1) { partY = partH-1; } - partY = partH-1 - partY; + for (int k = partH-1; k >= partY; k--) { + component.setPixel(x, k, color.rgba()); + } + } + if (unscaled && size.width() >= component.width()) { + return component; + } else { + return component.scaled(size, Qt::IgnoreAspectRatio, Qt::FastTransformation); + } +} - for (int k = partH-1; k >= partY; k--) { - component.setPixel(x, k, qRgba(0, 128, 255, 255)); - } +void LevelsGenerator::drawComponentFull(QPainter *davinci, const int *y, const float &scaling, const QRect &rect, + const QColor &color, const int &textSpace, const bool &unscaled) const +{ + QImage component = drawComponent(y, rect.size() - QSize(0, textSpace), scaling, color, unscaled); + davinci->drawImage(rect.topLeft(), component); + + int min = 0; + for (int x = 0; x < 256; x++) { + min = x; + if (y[x] > 0) { + break; + } + } + int max = 255; + for (int x = 255; x >= 0; x--) { + max = x; + if (y[x] > 0) { + break; } + } - davinci.drawImage(0, wy, component.scaled(ww, component.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation)); + const int textY = rect.bottom()-textSpace+15; + const int dist = 40; + const int cw = component.width(); - wy += partH + d; - } + davinci->drawText(0, textY, "min"); + davinci->drawText(dist, textY, QString::number(min, 'f', 0)); - return levels; + davinci->drawText(cw-dist-30, textY, "max"); + davinci->drawText(cw-30, textY, QString::number(max, 'f', 0)); } diff --git a/src/colorcorrection/levelsgenerator.h b/src/colorcorrection/levelsgenerator.h index 3f77c4cc..0628fcef 100644 --- a/src/colorcorrection/levelsgenerator.h +++ b/src/colorcorrection/levelsgenerator.h @@ -13,15 +13,31 @@ #include +class QColor; class QImage; +class QPainter; +class QRect; class QSize; class LevelsGenerator : public QObject { public: LevelsGenerator(); - QImage calculateLevels(const QSize ¶deSize, const QImage &image, const int &components, const uint &accelFactor = 1) const; + + /** + Calculates a levels display from the input image. + components are OR-ed LevelsGenerator::Components flags and decide with components (Y, R, G, B) to paint. + unscaled = true leaves the width at 256 if the widget is wider (to avoid scaling). */ + QImage calculateLevels(const QSize ¶deSize, const QImage &image, const int &components, const bool &unscaled, + const uint &accelFactor = 1) const; + + QImage drawComponent(const int *y, const QSize &size, const float &scaling, const QColor &color, const bool &unscaled) const; + + void drawComponentFull(QPainter *davinci, const int *y, const float &scaling, const QRect &rect, + const QColor &color, const int &textSpace, const bool &unscaled) const; + enum Components { ComponentY = 1<<0, ComponentR = 1<<1, ComponentG = 1<<2, ComponentB = 1<<3 }; + }; #endif // LEVELSGENERATOR_H diff --git a/src/levels.cpp b/src/levels.cpp index 84ab527b..4ab37633 100644 --- a/src/levels.cpp +++ b/src/levels.cpp @@ -66,7 +66,7 @@ QImage Levels::renderScope(uint accelFactor) | (ui->cbB->isChecked() ? 1 : 0) * LevelsGenerator::ComponentB; QImage levels = m_levelsGenerator->calculateLevels(m_scopeRect.size(), m_activeRender->extractFrame(m_activeRender->seekFramePosition()), - componentFlags, accelFactor); + componentFlags, false, accelFactor); emit signalScopeRenderingFinished(0, 1); return levels; -- 2.39.2