histogram.cpp 5.45 KB
Newer Older
Simon Eugster's avatar
Simon Eugster committed
1 2 3 4 5 6 7 8 9 10
/***************************************************************************
 *   Copyright (C) 2010 by Simon Andreas Eugster (simon.eu@gmail.com)      *
 *   This file is part of kdenlive. See www.kdenlive.org.                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

11
#include <QMenu>
Simon Eugster's avatar
Simon Eugster committed
12
#include <QTime>
13
#include "colorcorrection/histogramgenerator.h"
14
#include "histogram.h"
Simon Eugster's avatar
Simon Eugster committed
15 16
#include "renderer.h"

17 18
Histogram::Histogram(MonitorManager *manager, QWidget *parent) :
    AbstractGfxScopeWidget(manager, false, parent)
Simon Eugster's avatar
Simon Eugster committed
19
{
20
    ui = new Ui::Histogram_UI();
Simon Eugster's avatar
Simon Eugster committed
21 22
    ui->setupUi(this);

23 24 25

    m_aUnscaled = new QAction(i18n("Unscaled"), this);
    m_aUnscaled->setCheckable(true);
Simon Eugster's avatar
Simon Eugster committed
26 27 28 29 30 31 32 33 34

    m_aRec601 = new QAction(i18n("Rec. 601"), this);
    m_aRec601->setCheckable(true);
    m_aRec709 = new QAction(i18n("Rec. 709"), this);
    m_aRec709->setCheckable(true);
    m_agRec = new QActionGroup(this);
    m_agRec->addAction(m_aRec601);
    m_agRec->addAction(m_aRec709);

35 36
    m_menu->addSeparator();
    m_menu->addAction(m_aUnscaled);
Simon Eugster's avatar
Simon Eugster committed
37 38 39
    m_menu->addSeparator()->setText(i18n("Luma mode"));
    m_menu->addAction(m_aRec601);
    m_menu->addAction(m_aRec709);
40

Simon Eugster's avatar
Simon Eugster committed
41 42
    bool b = true;
    b &= connect(ui->cbY, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
Simon Eugster's avatar
Simon Eugster committed
43
    b &= connect(ui->cbS, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
Simon Eugster's avatar
Simon Eugster committed
44 45 46
    b &= connect(ui->cbR, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
    b &= connect(ui->cbG, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
    b &= connect(ui->cbB, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
47
    b &= connect(m_aUnscaled, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
Simon Eugster's avatar
Simon Eugster committed
48 49
    b &= connect(m_aRec601, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
    b &= connect(m_aRec709, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
Simon Eugster's avatar
Simon Eugster committed
50
    Q_ASSERT(b);
51

Simon Eugster's avatar
Simon Eugster committed
52
    init();
53
    m_histogramGenerator = new HistogramGenerator();
Simon Eugster's avatar
Simon Eugster committed
54 55
}

56
Histogram::~Histogram()
Simon Eugster's avatar
Simon Eugster committed
57
{
Simon Eugster's avatar
Simon Eugster committed
58
    writeConfig();
59
    delete m_histogramGenerator;
Simon Eugster's avatar
Simon Eugster committed
60
    delete ui;
61
    delete m_aUnscaled;
Simon Eugster's avatar
Simon Eugster committed
62 63 64
    delete m_aRec601;
    delete m_aRec709;
    delete m_agRec;
Simon Eugster's avatar
Simon Eugster committed
65 66
}

Simon Eugster's avatar
Simon Eugster committed
67 68
void Histogram::readConfig()
{
69
    AbstractGfxScopeWidget::readConfig();
Simon Eugster's avatar
Simon Eugster committed
70 71 72 73

    KSharedConfigPtr config = KGlobal::config();
    KConfigGroup scopeConfig(config, configName());
    ui->cbY->setChecked(scopeConfig.readEntry("yEnabled", true));
Simon Eugster's avatar
Simon Eugster committed
74
    ui->cbS->setChecked(scopeConfig.readEntry("sEnabled", false));
Simon Eugster's avatar
Simon Eugster committed
75 76 77
    ui->cbR->setChecked(scopeConfig.readEntry("rEnabled", true));
    ui->cbG->setChecked(scopeConfig.readEntry("gEnabled", true));
    ui->cbB->setChecked(scopeConfig.readEntry("bEnabled", true));
Simon Eugster's avatar
Simon Eugster committed
78 79
    m_aRec601->setChecked(scopeConfig.readEntry("rec601", false));
    m_aRec709->setChecked(!m_aRec601->isChecked());
Simon Eugster's avatar
Simon Eugster committed
80 81 82 83 84 85 86
}

void Histogram::writeConfig()
{
    KSharedConfigPtr config = KGlobal::config();
    KConfigGroup scopeConfig(config, configName());
    scopeConfig.writeEntry("yEnabled", ui->cbY->isChecked());
Simon Eugster's avatar
Simon Eugster committed
87
    scopeConfig.writeEntry("sEnabled", ui->cbS->isChecked());
Simon Eugster's avatar
Simon Eugster committed
88 89 90
    scopeConfig.writeEntry("rEnabled", ui->cbR->isChecked());
    scopeConfig.writeEntry("gEnabled", ui->cbG->isChecked());
    scopeConfig.writeEntry("bEnabled", ui->cbB->isChecked());
Simon Eugster's avatar
Simon Eugster committed
91
    scopeConfig.writeEntry("rec601", m_aRec601->isChecked());
Simon Eugster's avatar
Simon Eugster committed
92 93 94
    scopeConfig.sync();
}

95
QString Histogram::widgetName() const { return QString("Histogram"); }
Simon Eugster's avatar
Simon Eugster committed
96

97 98 99
bool Histogram::isHUDDependingOnInput() const { return false; }
bool Histogram::isScopeDependingOnInput() const { return true; }
bool Histogram::isBackgroundDependingOnInput() const { return false; }
Simon Eugster's avatar
Simon Eugster committed
100

101
QRect Histogram::scopeRect()
Simon Eugster's avatar
Simon Eugster committed
102
{
Simon Eugster's avatar
Simon Eugster committed
103
    //qDebug() << "According to the spacer, the top left point is " << ui->verticalSpacer->geometry().x() << "/" << ui->verticalSpacer->geometry().y();
Simon Eugster's avatar
Simon Eugster committed
104 105 106 107
    QPoint topleft(offset, offset+ ui->verticalSpacer->geometry().y());
    return QRect(topleft, this->rect().size() - QSize(topleft.x() + offset, topleft.y() + offset));
}

108
QImage Histogram::renderHUD(uint)
Simon Eugster's avatar
Simon Eugster committed
109 110 111 112
{
    emit signalHUDRenderingFinished(0, 1);
    return QImage();
}
113
QImage Histogram::renderGfxScope(uint accelFactor, const QImage qimage)
Simon Eugster's avatar
Simon Eugster committed
114 115 116 117
{
    QTime start = QTime::currentTime();
    start.start();

118
    const int componentFlags =   (ui->cbY->isChecked() ? 1 : 0) * HistogramGenerator::ComponentY
Simon Eugster's avatar
Simon Eugster committed
119
                               | (ui->cbS->isChecked() ? 1 : 0) * HistogramGenerator::ComponentSum
120 121 122
                               | (ui->cbR->isChecked() ? 1 : 0) * HistogramGenerator::ComponentR
                               | (ui->cbG->isChecked() ? 1 : 0) * HistogramGenerator::ComponentG
                               | (ui->cbB->isChecked() ? 1 : 0) * HistogramGenerator::ComponentB;
Simon Eugster's avatar
Simon Eugster committed
123

Simon Eugster's avatar
Simon Eugster committed
124 125 126 127
    HistogramGenerator::Rec rec = m_aRec601->isChecked() ? HistogramGenerator::Rec_601 : HistogramGenerator::Rec_709;

    QImage histogram = m_histogramGenerator->calculateHistogram(m_scopeRect.size(), qimage, componentFlags,
                                                                rec, m_aUnscaled->isChecked(), accelFactor);
Simon Eugster's avatar
Simon Eugster committed
128

129
    emit signalScopeRenderingFinished(start.elapsed(), accelFactor);
130
    return histogram;
Simon Eugster's avatar
Simon Eugster committed
131
}
132
QImage Histogram::renderBackground(uint)
Simon Eugster's avatar
Simon Eugster committed
133 134 135 136
{
    emit signalBackgroundRenderingFinished(0, 1);
    return QImage();
}