Commit afda774c authored by Tomaz  Canabrava's avatar Tomaz Canabrava Committed by Jean-Baptiste Mardelle

Prevent overflow in while setting the values

Differential Revision: https://phabricator.kde.org/D18193
parent 81441d4b
......@@ -18,6 +18,15 @@
#include "kdenlive_debug.h"
#endif
namespace {
double preventOverflow(double value)
{
return value < 0 ? 0
: value > 255 ? 255
: value;
}
}
ColorTools::ColorTools(QObject *parent)
: QObject(parent)
{
......@@ -34,7 +43,7 @@ QImage ColorTools::yuvColorWheel(const QSize &size, int Y, float scaling, bool m
wheel.fill(qRgba(0, 0, 0, 0));
}
double dr, dg, db, dv, dmax;
double dr, dg, db, dv;
double ru, rv, rr;
const int w = size.width();
const int h = size.height();
......@@ -69,14 +78,7 @@ QImage ColorTools::yuvColorWheel(const QSize &size, int Y, float scaling, bool m
if (modifiedVersion) {
// Scale the RGB values down, or up, to max 255
dmax = fabs(dr);
if (fabs(dg) > dmax) {
dmax = fabs(dg);
}
if (fabs(db) > dmax) {
dmax = fabs(db);
}
dmax = 255 / dmax;
const double dmax = 255 / std::max({fabs(dr), fabs(dg), fabs(db)});
dr *= dmax;
dg *= dmax;
......@@ -87,24 +89,9 @@ QImage ColorTools::yuvColorWheel(const QSize &size, int Y, float scaling, bool m
// 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;
}
dr = preventOverflow(dr);
dg = preventOverflow(dg);
db = preventOverflow(db);
wheel.setPixel(u, (h - v - 1), qRgba(dr, dg, db, 255));
}
......@@ -136,27 +123,9 @@ QImage ColorTools::yuvVerticalPlane(const QSize &size, int angle, float scaling)
Y = (double)255 * y / h;
// See yuv2rgb, yuvColorWheel
dr = Y + 290.8 * dv;
dg = Y - 100.6 * du - 148 * dv;
db = Y + 517.2 * du;
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;
}
dr = preventOverflow(Y + 290.8 * dv);
dg = preventOverflow(Y - 100.6 * du - 148 * dv);
db = preventOverflow(Y + 517.2 * du);
plane.setPixel(uv, (h - y - 1), qRgba(dr, dg, db, 255));
}
......@@ -287,32 +256,9 @@ QImage ColorTools::yPbPrColorWheel(const QSize &size, int Y, float scaling, bool
}
// 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 intersecting 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;
}
dr = preventOverflow(Y + 357.5 * dpR);
dg = preventOverflow(Y - 87.75 * dpB - 182.1 * dpR);
db = preventOverflow(Y + 451.86 * dpB);
wheel.setPixel(b, (h - r - 1), qRgba(dr, dg, db, 255));
}
......
......@@ -42,46 +42,42 @@ void HideTitleBars::slotShowTitleBars(bool show)
for (int i = 0; i < docks.count(); ++i) {
QDockWidget *dock = docks.at(i);
QWidget *bar = dock->titleBarWidget();
if (show) {
if (dock->isFloating()) {
if (bar) {
dock->setTitleBarWidget(nullptr);
delete bar;
}
continue;
}
// Since Qt 5.6 we only display title bar in non tabbed dockwidgets
QList<QDockWidget *> docked = pCore->window()->tabifiedDockWidgets(dock);
if (docked.isEmpty()) {
if (bar) {
dock->setTitleBarWidget(nullptr);
delete bar;
}
continue;
} else {
bool hasVisibleDockSibling = false;
for (QDockWidget *sub : docked) {
if (sub->toggleViewAction()->isChecked()) {
// we have another docked widget, so tabs are visible and can be used instead of title bars
hasVisibleDockSibling = true;
break;
}
}
if (!hasVisibleDockSibling) {
if (bar) {
dock->setTitleBarWidget(nullptr);
delete bar;
}
continue;
}
}
if (!bar) {
dock->setTitleBarWidget(new QWidget);
auto handleRemoveBar = [&dock, &bar]() -> void {
if (bar) {
dock->setTitleBarWidget(nullptr);
delete bar;
}
} else {
};
if (!show) {
if (!dock->isFloating() && (bar == nullptr)) {
dock->setTitleBarWidget(new QWidget);
dock->setTitleBarWidget(new QWidget());
}
continue;
}
if (dock->isFloating()) {
handleRemoveBar();
continue;
}
// Since Qt 5.6 we only display title bar in non tabbed dockwidgets
QList<QDockWidget *> docked = pCore->window()->tabifiedDockWidgets(dock);
if (docked.isEmpty()) {
handleRemoveBar();
continue;
}
const bool hasVisibleDockSibling = std::find_if(std::begin(docked), std::end(docked),
[](QDockWidget *sub) { return sub->toggleViewAction()->isChecked(); }) != std::end(docked);;
if (!hasVisibleDockSibling) {
handleRemoveBar();
continue;
}
if (!bar) {
dock->setTitleBarWidget(new QWidget());
}
}
KdenliveSettings::setShowtitlebars(show);
......
......@@ -170,8 +170,8 @@ void MainWindow::init()
QStringList availableStyles = QStyleFactory::keys();
if (KdenliveSettings::widgetstyle().isEmpty()) {
// First run
QStringList incompatibleStyles;
incompatibleStyles << QStringLiteral("GTK+") << QStringLiteral("windowsvista") << QStringLiteral("windowsxp");
QStringList incompatibleStyles = {QStringLiteral("GTK+"), QStringLiteral("windowsvista"), QStringLiteral("windowsxp")};
if (incompatibleStyles.contains(desktopStyle, Qt::CaseInsensitive)) {
if (availableStyles.contains(QStringLiteral("breeze"), Qt::CaseInsensitive)) {
// Auto switch to Breeze theme
......@@ -432,8 +432,7 @@ void MainWindow::init()
setupGUI(KXmlGuiWindow::ToolBar | KXmlGuiWindow::StatusBar | KXmlGuiWindow::Save | KXmlGuiWindow::Create);
if (firstRun) {
QScreen *current = QApplication::primaryScreen();
if (current) {
if (QScreen *current = QApplication::primaryScreen()) {
if (current->availableSize().height() < 1000) {
resize(current->availableSize());
} else {
......@@ -1488,15 +1487,17 @@ void MainWindow::setupActions()
addAction(QStringLiteral("add_project_note"), i18n("Add Project Note"), pCore->projectManager(), SLOT(slotAddProjectNote()), QIcon::fromTheme(QStringLiteral("bookmark")));
QHash<QString, QAction *> actions;
actions.insert(QStringLiteral("locate"), locateClip);
actions.insert(QStringLiteral("reload"), reloadClip);
actions.insert(QStringLiteral("duplicate"), duplicateClip);
actions.insert(QStringLiteral("proxy"), proxyClip);
actions.insert(QStringLiteral("properties"), clipProperties);
actions.insert(QStringLiteral("open"), openClip);
actions.insert(QStringLiteral("delete"), deleteClip);
actions.insert(QStringLiteral("folder"), addFolder);
QHash<QString, QAction *> actions({
{ QStringLiteral("locate"), locateClip },
{ QStringLiteral("reload"), reloadClip },
{ QStringLiteral("duplicate"), duplicateClip },
{ QStringLiteral("proxy"), proxyClip },
{ QStringLiteral("properties"), clipProperties },
{ QStringLiteral("open"), openClip },
{ QStringLiteral("delete"), deleteClip },
{ QStringLiteral("folder"), addFolder }
});
pCore->bin()->setupMenu(addClips, addClip, actions);
// Setup effects and transitions actions.
......
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