Commit 110cea8f authored by Simon Eugster's avatar Simon Eugster
Browse files

Levels displaying min/max values of YRGB

svn path=/trunk/kdenlive/; revision=4625
parent a52b7572
...@@ -19,7 +19,8 @@ LevelsGenerator::LevelsGenerator() ...@@ -19,7 +19,8 @@ LevelsGenerator::LevelsGenerator()
{ {
} }
QImage LevelsGenerator::calculateLevels(const QSize &paradeSize, const QImage &image, const int &components, const uint &accelFactor) const QImage LevelsGenerator::calculateLevels(const QSize &paradeSize, const QImage &image, const int &components,
const bool &unscaled, const uint &accelFactor) const
{ {
qDebug() << "Levels rect size is: " << paradeSize.width() << "/" << paradeSize.height(); qDebug() << "Levels rect size is: " << paradeSize.width() << "/" << paradeSize.height();
if (paradeSize.height() <= 0 || paradeSize.width() <= 0) { if (paradeSize.height() <= 0 || paradeSize.width() <= 0) {
...@@ -69,104 +70,102 @@ QImage LevelsGenerator::calculateLevels(const QSize &paradeSize, const QImage &i ...@@ -69,104 +70,102 @@ QImage LevelsGenerator::calculateLevels(const QSize &paradeSize, const QImage &i
} }
const int d = 20; // Distance for text 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 float scaling = (float)partH/(byteCount >> 7);
const int dist = 40;
int wy = 0; // Drawing position int wy = 0; // Drawing position
int partY; // Vertical position for the dots
QImage levels(paradeSize, QImage::Format_ARGB32); QImage levels(paradeSize, QImage::Format_ARGB32);
QImage component(256, partH, QImage::Format_ARGB32);
QPainter davinci(&levels); QPainter davinci(&levels);
davinci.setPen(QColor(220, 220, 220, 255));
levels.fill(qRgba(0, 0, 0, 0)); levels.fill(qRgba(0, 0, 0, 0));
if (drawY) { if (drawY) {
qDebug() << "Drawing Y at " << wy << " with height " << partH; qDebug() << "Drawing Y at " << wy << " with height " << partH;
component.fill(qRgba(0, 0, 0, 0)); drawComponentFull(&davinci, y, scaling, QRect(0, wy, ww, partH + dist), QColor(220, 220, 210, 255), dist, unscaled);
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));
wy += partH + d; wy += partH + d;
} }
if (drawR) { if (drawR) {
qDebug() << "Drawing R at " << wy << " with height " << partH; qDebug() << "Drawing R at " << wy << " with height " << partH;
component.fill(qRgba(0, 0, 0, 0)); drawComponentFull(&davinci, r, scaling, QRect(0, wy, ww, partH + dist), QColor(255, 128, 0, 255), dist, unscaled);
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));
wy += partH + d; wy += partH + d;
} }
if (drawG) { if (drawG) {
qDebug() << "Drawing G at " << wy << " with height " << partH; 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++) { if (drawB) {
// Calculate the height of the curve at position x qDebug() << "Drawing B at " << wy << " with height " << partH;
partY = scaling*g[x]; drawComponentFull(&davinci, r, scaling, QRect(0, wy, ww, partH + dist), QColor(0, 128, 255, 255), dist, unscaled);
// Invert the y axis wy += partH + d;
if (partY > partH-1) { partY = partH-1; } }
partY = partH-1 - partY;
for (int k = partH-1; k >= partY; k--) { return levels;
component.setPixel(x, k, qRgba(128, 255, 0, 255)); }
}
}
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) { for (int x = 0; x < 256; x++) {
qDebug() << "Drawing B at " << wy << " with height " << partH; // Calculate the height of the curve at position x
component.fill(qRgba(0, 0, 0, 0)); partY = scaling*y[x];
for (int x = 0; x < 256; x++) { // Invert the y axis
// Calculate the height of the curve at position x if (partY > partH-1) { partY = partH-1; }
partY = scaling*b[x]; partY = partH-1 - partY;
// Invert the y axis for (int k = partH-1; k >= partY; k--) {
if (partY > partH-1) { partY = partH-1; } component.setPixel(x, k, color.rgba());
partY = partH-1 - partY; }
}
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--) { void LevelsGenerator::drawComponentFull(QPainter *davinci, const int *y, const float &scaling, const QRect &rect,
component.setPixel(x, k, qRgba(0, 128, 255, 255)); 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));
} }
...@@ -13,15 +13,31 @@ ...@@ -13,15 +13,31 @@
#include <QObject> #include <QObject>
class QColor;
class QImage; class QImage;
class QPainter;
class QRect;
class QSize; class QSize;
class LevelsGenerator : public QObject class LevelsGenerator : public QObject
{ {
public: public:
LevelsGenerator(); LevelsGenerator();
QImage calculateLevels(const QSize &paradeSize, 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 &paradeSize, 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 }; enum Components { ComponentY = 1<<0, ComponentR = 1<<1, ComponentG = 1<<2, ComponentB = 1<<3 };
}; };
#endif // LEVELSGENERATOR_H #endif // LEVELSGENERATOR_H
...@@ -66,7 +66,7 @@ QImage Levels::renderScope(uint accelFactor) ...@@ -66,7 +66,7 @@ QImage Levels::renderScope(uint accelFactor)
| (ui->cbB->isChecked() ? 1 : 0) * LevelsGenerator::ComponentB; | (ui->cbB->isChecked() ? 1 : 0) * LevelsGenerator::ComponentB;
QImage levels = m_levelsGenerator->calculateLevels(m_scopeRect.size(), m_activeRender->extractFrame(m_activeRender->seekFramePosition()), QImage levels = m_levelsGenerator->calculateLevels(m_scopeRect.size(), m_activeRender->extractFrame(m_activeRender->seekFramePosition()),
componentFlags, accelFactor); componentFlags, false, accelFactor);
emit signalScopeRenderingFinished(0, 1); emit signalScopeRenderingFinished(0, 1);
return levels; return levels;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment