histogram.cpp 5.36 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 17
Histogram::Histogram(QWidget *parent) :
    AbstractGfxScopeWidget(false, parent)
Simon Eugster's avatar
Simon Eugster committed
18
{
19
    ui = new Ui::Histogram_UI();
Simon Eugster's avatar
Simon Eugster committed
20 21
    ui->setupUi(this);

22 23 24

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

    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);

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

Vincent PINON's avatar
Vincent PINON committed
40 41 42 43 44 45 46 47
    connect(ui->cbY, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
    connect(ui->cbS, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
    connect(ui->cbR, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
    connect(ui->cbG, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
    connect(ui->cbB, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
    connect(m_aUnscaled, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
    connect(m_aRec601, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
    connect(m_aRec709, SIGNAL(toggled(bool)), this, SLOT(forceUpdateScope()));
48

Simon Eugster's avatar
Simon Eugster committed
49
    init();
50
    m_histogramGenerator = new HistogramGenerator();
Simon Eugster's avatar
Simon Eugster committed
51 52
}

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

Simon Eugster's avatar
Simon Eugster committed
64 65
void Histogram::readConfig()
{
66
    AbstractGfxScopeWidget::readConfig();
Simon Eugster's avatar
Simon Eugster committed
67 68 69 70

    KSharedConfigPtr config = KGlobal::config();
    KConfigGroup scopeConfig(config, configName());
    ui->cbY->setChecked(scopeConfig.readEntry("yEnabled", true));
Simon Eugster's avatar
Simon Eugster committed
71
    ui->cbS->setChecked(scopeConfig.readEntry("sEnabled", false));
Simon Eugster's avatar
Simon Eugster committed
72 73 74
    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
75 76
    m_aRec601->setChecked(scopeConfig.readEntry("rec601", false));
    m_aRec709->setChecked(!m_aRec601->isChecked());
Simon Eugster's avatar
Simon Eugster committed
77 78 79 80 81 82 83
}

void Histogram::writeConfig()
{
    KSharedConfigPtr config = KGlobal::config();
    KConfigGroup scopeConfig(config, configName());
    scopeConfig.writeEntry("yEnabled", ui->cbY->isChecked());
Simon Eugster's avatar
Simon Eugster committed
84
    scopeConfig.writeEntry("sEnabled", ui->cbS->isChecked());
Simon Eugster's avatar
Simon Eugster committed
85 86 87
    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
88
    scopeConfig.writeEntry("rec601", m_aRec601->isChecked());
Simon Eugster's avatar
Simon Eugster committed
89 90 91
    scopeConfig.sync();
}

92 93 94 95
QString Histogram::widgetName() const
{
    return QString::fromLatin1("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();
}
Laurent Montel's avatar
Laurent Montel committed
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();
}
Laurent Montel's avatar
Laurent Montel committed
137 138

#include "histogram.moc"