1 /***************************************************************************
2 * Copyright (C) 2010 by Simon Andreas Eugster (simon.eu@gmail.com) *
3 * This file is part of kdenlive. See www.kdenlive.org. *
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 ***************************************************************************/
13 #include "colorcorrection/histogramgenerator.h"
14 #include "histogram.h"
16 Histogram::Histogram(QWidget *parent) :
17 AbstractGfxScopeWidget(false, parent)
19 ui = new Ui::Histogram_UI();
23 m_aUnscaled = new QAction(i18n("Unscaled"), this);
24 m_aUnscaled->setCheckable(true);
26 m_aRec601 = new QAction(i18n("Rec. 601"), this);
27 m_aRec601->setCheckable(true);
28 m_aRec709 = new QAction(i18n("Rec. 709"), this);
29 m_aRec709->setCheckable(true);
30 m_agRec = new QActionGroup(this);
31 m_agRec->addAction(m_aRec601);
32 m_agRec->addAction(m_aRec709);
34 m_menu->addSeparator();
35 m_menu->addAction(m_aUnscaled);
36 m_menu->addSeparator()->setText(i18n("Luma mode"));
37 m_menu->addAction(m_aRec601);
38 m_menu->addAction(m_aRec709);
41 b &= connect(ui->cbY, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
42 b &= connect(ui->cbS, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
43 b &= connect(ui->cbR, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
44 b &= connect(ui->cbG, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
45 b &= connect(ui->cbB, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
46 b &= connect(m_aUnscaled, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
47 b &= connect(m_aRec601, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
48 b &= connect(m_aRec709, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
52 m_histogramGenerator = new HistogramGenerator();
55 Histogram::~Histogram()
58 delete m_histogramGenerator;
66 void Histogram::readConfig()
68 AbstractGfxScopeWidget::readConfig();
70 KSharedConfigPtr config = KGlobal::config();
71 KConfigGroup scopeConfig(config, configName());
72 ui->cbY->setChecked(scopeConfig.readEntry("yEnabled", true));
73 ui->cbS->setChecked(scopeConfig.readEntry("sEnabled", false));
74 ui->cbR->setChecked(scopeConfig.readEntry("rEnabled", true));
75 ui->cbG->setChecked(scopeConfig.readEntry("gEnabled", true));
76 ui->cbB->setChecked(scopeConfig.readEntry("bEnabled", true));
77 m_aRec601->setChecked(scopeConfig.readEntry("rec601", false));
78 m_aRec709->setChecked(!m_aRec601->isChecked());
81 void Histogram::writeConfig()
83 KSharedConfigPtr config = KGlobal::config();
84 KConfigGroup scopeConfig(config, configName());
85 scopeConfig.writeEntry("yEnabled", ui->cbY->isChecked());
86 scopeConfig.writeEntry("sEnabled", ui->cbS->isChecked());
87 scopeConfig.writeEntry("rEnabled", ui->cbR->isChecked());
88 scopeConfig.writeEntry("gEnabled", ui->cbG->isChecked());
89 scopeConfig.writeEntry("bEnabled", ui->cbB->isChecked());
90 scopeConfig.writeEntry("rec601", m_aRec601->isChecked());
94 QString Histogram::widgetName() const
96 return QString::fromLatin1("Histogram");
99 bool Histogram::isHUDDependingOnInput() const { return false; }
100 bool Histogram::isScopeDependingOnInput() const { return true; }
101 bool Histogram::isBackgroundDependingOnInput() const { return false; }
103 QRect Histogram::scopeRect()
105 //qDebug() << "According to the spacer, the top left point is " << ui->verticalSpacer->geometry().x() << "/" << ui->verticalSpacer->geometry().y();
106 QPoint topleft(offset, offset+ ui->verticalSpacer->geometry().y());
107 return QRect(topleft, this->rect().size() - QSize(topleft.x() + offset, topleft.y() + offset));
110 QImage Histogram::renderHUD(uint)
112 emit signalHUDRenderingFinished(0, 1);
115 QImage Histogram::renderGfxScope(uint accelFactor, const QImage &qimage)
117 QTime start = QTime::currentTime();
120 const int componentFlags = (ui->cbY->isChecked() ? 1 : 0) * HistogramGenerator::ComponentY
121 | (ui->cbS->isChecked() ? 1 : 0) * HistogramGenerator::ComponentSum
122 | (ui->cbR->isChecked() ? 1 : 0) * HistogramGenerator::ComponentR
123 | (ui->cbG->isChecked() ? 1 : 0) * HistogramGenerator::ComponentG
124 | (ui->cbB->isChecked() ? 1 : 0) * HistogramGenerator::ComponentB;
126 HistogramGenerator::Rec rec = m_aRec601->isChecked() ? HistogramGenerator::Rec_601 : HistogramGenerator::Rec_709;
128 QImage histogram = m_histogramGenerator->calculateHistogram(m_scopeRect.size(), qimage, componentFlags,
129 rec, m_aUnscaled->isChecked(), accelFactor);
131 emit signalScopeRenderingFinished(start.elapsed(), accelFactor);
134 QImage Histogram::renderBackground(uint)
136 emit signalBackgroundRenderingFinished(0, 1);
140 #include "histogram.moc"