1 /*
2  *  Copyright (c) 2019 Dmitry Kazakov <dimula73@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #include "VideoHDRMetadataOptionsDialog.h"
21 #include "ui_VideoHDRMetadataOptionsDialog.h"
22 
23 #include "KisHDRMetadataOptions.h"
24 
VideoHDRMetadataOptionsDialog(QWidget * parent)25 VideoHDRMetadataOptionsDialog::VideoHDRMetadataOptionsDialog(QWidget *parent)
26     : QDialog(parent),
27     ui(new Ui::VideoHDRMetadataOptionsDialog)
28 {
29     ui->setupUi(this);
30 
31     connect(ui->btnBox, SIGNAL(accepted()), this, SLOT(accept()));
32     connect(ui->btnBox, SIGNAL(rejected()), this, SLOT(reject()));
33 
34     ui->cmbMasterDisplay->addItem(i18n("Rec. 2100 PQ"), "p2100-pq");
35     ui->cmbMasterDisplay->addItem(i18n("DCI-P3 D65"), "dci-p3-d65");
36     ui->cmbMasterDisplay->addItem(i18n("Custom"), "custom");
37 
38     connect(ui->cmbMasterDisplay, SIGNAL(currentIndexChanged(int)), SLOT(slotPredefinedDisplayIdChanged()));
39 }
40 
~VideoHDRMetadataOptionsDialog()41 VideoHDRMetadataOptionsDialog::~VideoHDRMetadataOptionsDialog()
42 {
43     delete ui;
44 }
45 
setHDRMetadataOptions(const KisHDRMetadataOptions & options)46 void VideoHDRMetadataOptionsDialog::setHDRMetadataOptions(const KisHDRMetadataOptions &options)
47 {
48     ui->dblRedX->setValue(options.redX);
49     ui->dblRedY->setValue(options.redY);
50 
51     ui->dblGreenX->setValue(options.greenX);
52     ui->dblGreenY->setValue(options.greenY);
53 
54     ui->dblBlueX->setValue(options.blueX);
55     ui->dblBlueY->setValue(options.blueY);
56 
57     ui->dblWhiteX->setValue(options.whiteX);
58     ui->dblWhiteY->setValue(options.whiteY);
59 
60     ui->dblMinLuminance->setValue(options.minLuminance);
61     ui->dblMaxLuminance->setValue(options.maxLuminance);
62 
63     ui->intMaxCLL->setValue(options.maxCLL);
64     ui->intMaxFALL->setValue(options.maxFALL);
65 
66     int index = ui->cmbMasterDisplay->findData(options.predefinedMasterDisplayId);
67     if (index < 0) {
68         index = ui->cmbMasterDisplay->findData("custom");
69     }
70     ui->cmbMasterDisplay->setCurrentIndex(index);
71 
72     slotPredefinedDisplayIdChanged();
73 }
74 
hdrMetadataOptions() const75 KisHDRMetadataOptions VideoHDRMetadataOptionsDialog::hdrMetadataOptions() const
76 {
77     KisHDRMetadataOptions options;
78 
79     ui->dblRedX->setValue(options.redX);
80     options.redY = ui->dblRedY->value();
81 
82     options.greenX = ui->dblGreenX->value();
83     options.greenY = ui->dblGreenY->value();
84 
85     options.blueX = ui->dblBlueX->value();
86     options.blueY = ui->dblBlueY->value();
87 
88     options.whiteX = ui->dblWhiteX->value();
89     options.whiteY = ui->dblWhiteY->value();
90 
91     options.minLuminance = ui->dblMinLuminance->value();
92     options.maxLuminance = ui->dblMaxLuminance->value();
93 
94     options.maxCLL = ui->intMaxCLL->value();
95     options.maxFALL = ui->intMaxFALL->value();
96 
97     options.predefinedMasterDisplayId = ui->cmbMasterDisplay->currentData().toString();
98 
99     return options;
100 }
101 
slotPredefinedDisplayIdChanged()102 void VideoHDRMetadataOptionsDialog::slotPredefinedDisplayIdChanged()
103 {
104     const QString displayId = ui->cmbMasterDisplay->currentData().toString();
105 
106     if (displayId == "p2100-pq") {
107         ui->grpCustomDisplay->setEnabled(false);
108 
109         ui->dblRedX->setValue(0.708);
110         ui->dblRedY->setValue(0.292);
111 
112         ui->dblGreenX->setValue(0.170);
113         ui->dblGreenY->setValue(0.797);
114 
115         ui->dblBlueX->setValue(0.131);
116         ui->dblBlueY->setValue(0.046);
117 
118         ui->dblWhiteX->setValue(0.3127);
119         ui->dblWhiteY->setValue(0.3290);
120 
121         ui->dblMinLuminance->setValue(0.005);
122         ui->dblMaxLuminance->setValue(1000);
123 
124     } else if (displayId == "dci-p3-d65") {
125         ui->grpCustomDisplay->setEnabled(false);
126 
127         ui->dblRedX->setValue(0.680);
128         ui->dblRedY->setValue(0.320);
129 
130         ui->dblGreenX->setValue(0.265);
131         ui->dblGreenY->setValue(0.690);
132 
133         ui->dblBlueX->setValue(0.150);
134         ui->dblBlueY->setValue(0.060);
135 
136         ui->dblWhiteX->setValue(0.3127);
137         ui->dblWhiteY->setValue(0.3290);
138 
139         ui->dblMinLuminance->setValue(0.005);
140         ui->dblMaxLuminance->setValue(1000);
141 
142     } else {
143         ui->grpCustomDisplay->setEnabled(true);
144     }
145 
146 }
147