1.2.16
by Jonathan Riddell
Import upstream version 0.10.0~beta7 |
1 |
/* ============================================================
|
2 |
*
|
|
3 |
* This file is a part of digiKam project
|
|
4 |
* http://www.digikam.org
|
|
5 |
*
|
|
6 |
* Date : 2004-07-16
|
|
7 |
* Description : digiKam image editor to adjust Hue, Saturation,
|
|
8 |
* and Lightness of picture.
|
|
9 |
*
|
|
10 |
* Copyright (C) 2004-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
|
|
11 |
*
|
|
12 |
* This program is free software; you can redistribute it
|
|
13 |
* and/or modify it under the terms of the GNU General
|
|
14 |
* Public License as published by the Free Software Foundation;
|
|
15 |
* either version 2, or (at your option)
|
|
16 |
* any later version.
|
|
17 |
*
|
|
18 |
* This program is distributed in the hope that it will be useful,
|
|
19 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21 |
* GNU General Public License for more details.
|
|
22 |
*
|
|
23 |
* ============================================================ */
|
|
24 |
||
25 |
||
26 |
#include "hsltool.h" |
|
27 |
#include "hsltool.moc" |
|
28 |
||
29 |
// Qt includes.
|
|
30 |
||
31 |
#include <QColor> |
|
32 |
#include <QFrame> |
|
33 |
#include <QGridLayout> |
|
34 |
#include <QGroupBox> |
|
35 |
#include <QHBoxLayout> |
|
36 |
#include <QLabel> |
|
37 |
#include <QPixmap> |
|
38 |
#include <QPushButton> |
|
39 |
#include <QTimer> |
|
40 |
#include <QToolButton> |
|
41 |
||
42 |
// KDE includes.
|
|
43 |
||
44 |
#include <kapplication.h> |
|
45 |
#include <kcolordialog.h> |
|
46 |
#include <kcombobox.h> |
|
47 |
#include <kconfig.h> |
|
48 |
#include <kcursor.h> |
|
49 |
#include <kglobal.h> |
|
50 |
#include <khuesaturationselect.h> |
|
51 |
#include <klocale.h> |
|
52 |
#include <kstandarddirs.h> |
|
53 |
#include <kvbox.h> |
|
54 |
||
55 |
// LibKDcraw includes.
|
|
56 |
||
57 |
#include <libkdcraw/rnuminput.h> |
|
58 |
||
59 |
// Local includes.
|
|
60 |
||
61 |
#include "colorgradientwidget.h" |
|
62 |
#include "dimg.h" |
|
63 |
#include "editortoolsettings.h" |
|
64 |
#include "hslmodifier.h" |
|
65 |
#include "imageiface.h" |
|
66 |
#include "imagewidget.h" |
|
67 |
#include "hspreviewwidget.h" |
|
68 |
#include "histogramwidget.h" |
|
69 |
#include "histogrambox.h" |
|
70 |
||
71 |
using namespace KDcrawIface; |
|
72 |
using namespace Digikam; |
|
73 |
||
74 |
namespace DigikamImagesPluginCore |
|
75 |
{
|
|
76 |
||
77 |
HSLTool::HSLTool(QObject* parent) |
|
78 |
: EditorTool(parent) |
|
79 |
{
|
|
80 |
setObjectName("adjusthsl"); |
|
81 |
setToolName(i18n("Hue / Saturation / Lightness")); |
|
82 |
setToolIcon(SmallIcon("adjusthsl")); |
|
83 |
setToolHelp("hsladjusttool.anchor"); |
|
84 |
||
85 |
m_destinationPreviewData = 0; |
|
86 |
||
87 |
m_previewWidget = new ImageWidget("hsladjust Tool", 0, |
|
88 |
i18n("Here you can see the image " |
|
89 |
"Hue/Saturation/Lightness adjustments preview. "
|
|
90 |
"You can pick color on image "
|
|
91 |
"to see the color level corresponding on histogram.")); |
|
92 |
setToolView(m_previewWidget); |
|
93 |
||
94 |
// -------------------------------------------------------------
|
|
95 |
||
96 |
m_gboxSettings = new EditorToolSettings(EditorToolSettings::Default| |
|
97 |
EditorToolSettings::Ok| |
|
98 |
EditorToolSettings::Cancel, |
|
99 |
EditorToolSettings::Histogram); |
|
100 |
||
101 |
QGridLayout* gridSettings = new QGridLayout(m_gboxSettings->plainPage()); |
|
102 |
||
103 |
// -------------------------------------------------------------
|
|
104 |
||
105 |
m_HSSelector = new KHueSaturationSelector(m_gboxSettings->plainPage()); |
|
106 |
m_HSSelector->setWhatsThis(i18n("Select the hue and saturation adjustments of the image.")); |
|
107 |
m_HSSelector->setMinimumSize(256, 142); |
|
108 |
||
109 |
m_HSPreview = new HSPreviewWidget(m_gboxSettings->plainPage(), m_gboxSettings->spacingHint()); |
|
110 |
m_HSPreview->setWhatsThis(i18n("You can see here a color preview of the hue and " |
|
111 |
"saturation adjustments.")); |
|
112 |
m_HSPreview->setMinimumSize(256, 15); |
|
113 |
||
114 |
QLabel *label2 = new QLabel(i18n("Hue:"), m_gboxSettings->plainPage()); |
|
115 |
m_hInput = new RDoubleNumInput(m_gboxSettings->plainPage()); |
|
116 |
m_hInput->setDecimals(0); |
|
117 |
m_hInput->input()->setRange(-180.0, 180.0, 1.0, true); |
|
118 |
m_hInput->setDefaultValue(0.0); |
|
119 |
m_hInput->setWhatsThis(i18n("Set here the hue adjustment of the image.")); |
|
120 |
||
121 |
QLabel *label3 = new QLabel(i18n("Saturation:"), m_gboxSettings->plainPage()); |
|
122 |
m_sInput = new RDoubleNumInput(m_gboxSettings->plainPage()); |
|
123 |
m_sInput->setDecimals(2); |
|
124 |
m_sInput->input()->setRange(-100.0, 100.0, 0.01, true); |
|
125 |
m_sInput->setDefaultValue(0.0); |
|
126 |
m_sInput->setWhatsThis(i18n("Set here the saturation adjustment of the image.")); |
|
127 |
||
128 |
QLabel *label4 = new QLabel(i18n("Lightness:"), m_gboxSettings->plainPage()); |
|
129 |
m_lInput = new RDoubleNumInput(m_gboxSettings->plainPage()); |
|
130 |
m_lInput->setDecimals(2); |
|
131 |
m_lInput->input()->setRange(-100.0, 100.0, 0.01, true); |
|
132 |
m_lInput->setDefaultValue(0.0); |
|
133 |
m_lInput->setWhatsThis(i18n("Set here the lightness adjustment of the image.")); |
|
134 |
||
135 |
// -------------------------------------------------------------
|
|
136 |
||
137 |
gridSettings->addWidget(m_HSSelector, 0, 0, 1, 5); |
|
138 |
gridSettings->addWidget(m_HSPreview, 1, 0, 1, 5); |
|
139 |
gridSettings->addWidget(label2, 2, 0, 1, 5); |
|
140 |
gridSettings->addWidget(m_hInput, 3, 0, 1, 5); |
|
141 |
gridSettings->addWidget(label3, 4, 0, 1, 5); |
|
142 |
gridSettings->addWidget(m_sInput, 5, 0, 1, 5); |
|
143 |
gridSettings->addWidget(label4, 6, 0, 1, 5); |
|
144 |
gridSettings->addWidget(m_lInput, 7, 0, 1, 5); |
|
145 |
gridSettings->setRowStretch(8, 10); |
|
146 |
gridSettings->setMargin(m_gboxSettings->spacingHint()); |
|
147 |
gridSettings->setSpacing(m_gboxSettings->spacingHint()); |
|
148 |
||
149 |
setToolSettings(m_gboxSettings); |
|
150 |
init(); |
|
151 |
||
152 |
// -------------------------------------------------------------
|
|
153 |
||
154 |
connect(m_HSSelector, SIGNAL(valueChanged(int, int)), |
|
155 |
this, SLOT(slotHSChanged(int, int))); |
|
156 |
||
157 |
connect(m_previewWidget, SIGNAL(spotPositionChangedFromTarget( const Digikam::DColor &, const QPoint & )), |
|
158 |
this, SLOT(slotColorSelectedFromTarget( const Digikam::DColor & ))); |
|
159 |
||
160 |
connect(m_hInput, SIGNAL(valueChanged (double)), |
|
161 |
this, SLOT(slotTimer())); |
|
162 |
||
163 |
connect(m_hInput, SIGNAL(valueChanged (double)), |
|
164 |
this, SLOT(slotHChanged(double))); |
|
165 |
||
166 |
connect(m_sInput, SIGNAL(valueChanged (double)), |
|
167 |
this, SLOT(slotTimer())); |
|
168 |
||
169 |
connect(m_sInput, SIGNAL(valueChanged (double)), |
|
170 |
this, SLOT(slotSChanged(double))); |
|
171 |
||
172 |
connect(m_lInput, SIGNAL(valueChanged (double)), |
|
173 |
this, SLOT(slotTimer())); |
|
174 |
||
175 |
connect(m_previewWidget, SIGNAL(signalResized()), |
|
176 |
this, SLOT(slotEffect())); |
|
177 |
||
178 |
// -------------------------------------------------------------
|
|
179 |
||
180 |
m_gboxSettings->enableButton(EditorToolSettings::Ok, false); |
|
181 |
}
|
|
182 |
||
183 |
HSLTool::~HSLTool() |
|
184 |
{
|
|
185 |
if (m_destinationPreviewData) |
|
186 |
delete [] m_destinationPreviewData; |
|
187 |
}
|
|
188 |
||
189 |
void HSLTool::slotColorSelectedFromTarget(const DColor &color) |
|
190 |
{
|
|
191 |
m_gboxSettings->histogramBox()->histogram()->setHistogramGuideByColor(color); |
|
192 |
}
|
|
193 |
||
194 |
void HSLTool::slotHSChanged(int h, int s) |
|
195 |
{
|
|
196 |
double hue = double(h); |
|
197 |
if (h >= 180 && h <= 359) |
|
198 |
hue = double(h) - 359.0; |
|
199 |
||
200 |
double sat = ((double)s * (200.0/255.0)) - 100.0; |
|
201 |
||
202 |
m_hInput->blockSignals(true); |
|
203 |
m_sInput->blockSignals(true); |
|
204 |
m_hInput->setValue(hue); |
|
205 |
m_sInput->setValue(sat); |
|
206 |
m_hInput->blockSignals(false); |
|
207 |
m_sInput->blockSignals(false); |
|
208 |
slotTimer(); |
|
209 |
}
|
|
210 |
||
211 |
void HSLTool::slotHChanged(double h) |
|
212 |
{
|
|
213 |
int hue = int(h); |
|
214 |
if (h >= -180 && h < 0) |
|
215 |
hue = int(h) + 359; |
|
216 |
||
217 |
m_HSSelector->blockSignals(true); |
|
218 |
m_HSSelector->setXValue(hue); |
|
219 |
m_HSSelector->blockSignals(false); |
|
220 |
}
|
|
221 |
||
222 |
void HSLTool::slotSChanged(double s) |
|
223 |
{
|
|
224 |
int sat = (int)((s + 100.0) * (255.0/200.0)); |
|
225 |
||
226 |
m_HSSelector->blockSignals(true); |
|
227 |
m_HSSelector->setYValue(sat); |
|
228 |
m_HSSelector->blockSignals(false); |
|
229 |
}
|
|
230 |
||
231 |
void HSLTool::readSettings() |
|
232 |
{
|
|
233 |
KSharedConfig::Ptr config = KGlobal::config(); |
|
234 |
KConfigGroup group = config->group("hsladjust Tool"); |
|
235 |
||
236 |
m_gboxSettings->histogramBox()->setChannel(group.readEntry("Histogram Channel", |
|
237 |
(int)EditorToolSettings::LuminosityChannel)); |
|
238 |
m_gboxSettings->histogramBox()->setScale(group.readEntry("Histogram Scale", |
|
239 |
(int)HistogramWidget::LogScaleHistogram)); |
|
240 |
||
241 |
m_hInput->setValue(group.readEntry("HueAdjustment", m_hInput->defaultValue())); |
|
242 |
m_sInput->setValue(group.readEntry("SaturationAdjustment", m_sInput->defaultValue())); |
|
243 |
m_lInput->setValue(group.readEntry("LighnessAdjustment", m_lInput->defaultValue())); |
|
244 |
slotHChanged(m_hInput->value()); |
|
245 |
slotSChanged(m_sInput->value()); |
|
246 |
}
|
|
247 |
||
248 |
void HSLTool::writeSettings() |
|
249 |
{
|
|
250 |
KSharedConfig::Ptr config = KGlobal::config(); |
|
251 |
KConfigGroup group = config->group("hsladjust Tool"); |
|
252 |
group.writeEntry("Histogram Channel", m_gboxSettings->histogramBox()->channel()); |
|
253 |
group.writeEntry("Histogram Scale", m_gboxSettings->histogramBox()->scale()); |
|
254 |
group.writeEntry("HueAdjustment", m_hInput->value()); |
|
255 |
group.writeEntry("SaturationAdjustment", m_sInput->value()); |
|
256 |
group.writeEntry("LighnessAdjustment", m_lInput->value()); |
|
1.2.19
by Luka Renko
Import upstream version 0.10.0~rc2 |
257 |
m_previewWidget->writeSettings(); |
1.2.16
by Jonathan Riddell
Import upstream version 0.10.0~beta7 |
258 |
config->sync(); |
259 |
}
|
|
260 |
||
261 |
void HSLTool::slotResetSettings() |
|
262 |
{
|
|
263 |
m_hInput->blockSignals(true); |
|
264 |
m_sInput->blockSignals(true); |
|
265 |
m_lInput->blockSignals(true); |
|
266 |
||
267 |
m_hInput->slotReset(); |
|
268 |
m_sInput->slotReset(); |
|
269 |
m_lInput->slotReset(); |
|
270 |
||
271 |
slotHChanged(m_hInput->defaultValue()); |
|
272 |
slotSChanged(m_sInput->defaultValue()); |
|
273 |
||
274 |
m_hInput->blockSignals(false); |
|
275 |
m_sInput->blockSignals(false); |
|
276 |
m_lInput->blockSignals(false); |
|
277 |
||
278 |
slotEffect(); |
|
279 |
}
|
|
280 |
||
281 |
void HSLTool::slotEffect() |
|
282 |
{
|
|
283 |
kapp->setOverrideCursor( Qt::WaitCursor ); |
|
284 |
||
285 |
double hu = m_hInput->value(); |
|
286 |
double sa = m_sInput->value(); |
|
287 |
double lu = m_lInput->value(); |
|
288 |
||
289 |
m_gboxSettings->enableButton(EditorToolSettings::Ok, |
|
290 |
(hu != 0.0 || sa != 0.0 || lu != 0.0)); |
|
291 |
||
292 |
m_HSPreview->setHS(hu, sa); |
|
293 |
m_gboxSettings->histogramBox()->histogram()->stopHistogramComputation(); |
|
294 |
||
295 |
if (m_destinationPreviewData) |
|
296 |
delete [] m_destinationPreviewData; |
|
297 |
||
298 |
ImageIface* iface = m_previewWidget->imageIface(); |
|
299 |
m_destinationPreviewData = iface->getPreviewImage(); |
|
300 |
int w = iface->previewWidth(); |
|
301 |
int h = iface->previewHeight(); |
|
302 |
bool a = iface->previewHasAlpha(); |
|
303 |
bool sb = iface->previewSixteenBit(); |
|
304 |
||
305 |
DImg preview(w, h, sb, a, m_destinationPreviewData); |
|
306 |
HSLModifier cmod; |
|
307 |
cmod.setHue(hu); |
|
308 |
cmod.setSaturation(sa); |
|
309 |
cmod.setLightness(lu); |
|
310 |
cmod.applyHSL(preview); |
|
311 |
iface->putPreviewImage(preview.bits()); |
|
312 |
||
313 |
m_previewWidget->updatePreview(); |
|
314 |
||
315 |
// Update histogram.
|
|
316 |
||
317 |
memcpy(m_destinationPreviewData, preview.bits(), preview.numBytes()); |
|
318 |
m_gboxSettings->histogramBox()->histogram()->updateData(m_destinationPreviewData, w, h, sb, 0, 0, 0, false); |
|
319 |
||
320 |
kapp->restoreOverrideCursor(); |
|
321 |
}
|
|
322 |
||
323 |
void HSLTool::finalRendering() |
|
324 |
{
|
|
325 |
kapp->setOverrideCursor( Qt::WaitCursor ); |
|
326 |
||
327 |
double hu = m_hInput->value(); |
|
328 |
double sa = m_sInput->value(); |
|
329 |
double lu = m_lInput->value(); |
|
330 |
||
331 |
ImageIface* iface = m_previewWidget->imageIface(); |
|
332 |
uchar *data = iface->getOriginalImage(); |
|
333 |
int w = iface->originalWidth(); |
|
334 |
int h = iface->originalHeight(); |
|
335 |
bool a = iface->originalHasAlpha(); |
|
336 |
bool sb = iface->originalSixteenBit(); |
|
337 |
DImg original(w, h, sb, a, data); |
|
338 |
delete [] data; |
|
339 |
||
340 |
HSLModifier cmod; |
|
341 |
cmod.setHue(hu); |
|
342 |
cmod.setSaturation(sa); |
|
343 |
cmod.setLightness(lu); |
|
344 |
cmod.applyHSL(original); |
|
345 |
||
346 |
iface->putOriginalImage(i18n("HSL Adjustments"), original.bits()); |
|
347 |
kapp->restoreOverrideCursor(); |
|
348 |
}
|
|
349 |
||
350 |
} // namespace DigikamImagesPluginCore |
|
351 |