]> git.sesse.net Git - kdenlive/blob - src/histogram.cpp
64c307a871918edc019a793984c27f7906dc8976
[kdenlive] / src / histogram.cpp
1 /***************************************************************************
2  *   Copyright (C) 2010 by Simon Andreas Eugster (simon.eu@gmail.com)      *
3  *   This file is part of kdenlive. See www.kdenlive.org.                  *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  ***************************************************************************/
10
11 #include <QMenu>
12 #include <QTime>
13 #include "histogramgenerator.h"
14 #include "histogram.h"
15 #include "renderer.h"
16
17 Histogram::Histogram(Monitor *projMonitor, Monitor *clipMonitor, QWidget *parent) :
18     AbstractScopeWidget(projMonitor, clipMonitor, parent)
19 {
20     ui = new Ui::Histogram_UI();
21     ui->setupUi(this);
22
23     ui->cbY->setChecked(true);
24     ui->cbR->setChecked(true);
25     ui->cbG->setChecked(true);
26     ui->cbB->setChecked(true);
27
28
29     m_aUnscaled = new QAction(i18n("Unscaled"), this);
30     m_aUnscaled->setCheckable(true);
31     m_menu->addSeparator();
32     m_menu->addAction(m_aUnscaled);
33
34     bool b = true;
35     b &= connect(ui->cbY, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
36     b &= connect(ui->cbR, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
37     b &= connect(ui->cbG, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
38     b &= connect(ui->cbB, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
39     b &= connect(m_aUnscaled, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
40     Q_ASSERT(b);
41
42 }
43
44 Histogram::~Histogram()
45 {
46     delete ui;
47     delete m_aUnscaled;
48 }
49
50 QString Histogram::widgetName() const { return QString("Histogram"); }
51
52 bool Histogram::isHUDDependingOnInput() const { return false; }
53 bool Histogram::isScopeDependingOnInput() const { return true; }
54 bool Histogram::isBackgroundDependingOnInput() const { return false; }
55
56 QRect Histogram::scopeRect()
57 {
58     qDebug() << "According to the spacer, the top left point is " << ui->verticalSpacer->geometry().x() << "/" << ui->verticalSpacer->geometry().y();
59     QPoint topleft(offset, offset+ ui->verticalSpacer->geometry().y());
60     return QRect(topleft, this->rect().size() - QSize(topleft.x() + offset, topleft.y() + offset));
61 }
62
63 QImage Histogram::renderHUD(uint)
64 {
65     emit signalHUDRenderingFinished(0, 1);
66     return QImage();
67 }
68 QImage Histogram::renderScope(uint accelFactor, QImage qimage)
69 {
70     QTime start = QTime::currentTime();
71     start.start();
72
73     const int componentFlags =   (ui->cbY->isChecked() ? 1 : 0) * HistogramGenerator::ComponentY
74                                | (ui->cbR->isChecked() ? 1 : 0) * HistogramGenerator::ComponentR
75                                | (ui->cbG->isChecked() ? 1 : 0) * HistogramGenerator::ComponentG
76                                | (ui->cbB->isChecked() ? 1 : 0) * HistogramGenerator::ComponentB;
77
78     QImage histogram = m_histogramGenerator->calculateHistogram(m_scopeRect.size(), qimage,
79                                                        componentFlags, m_aUnscaled->isChecked(), accelFactor);
80
81     emit signalScopeRenderingFinished(start.elapsed(), accelFactor);
82     return histogram;
83 }
84 QImage Histogram::renderBackground(uint)
85 {
86     emit signalBackgroundRenderingFinished(0, 1);
87     return QImage();
88 }